diff options
Diffstat (limited to 'table')
-rw-r--r-- | table/table.go | 25 | ||||
-rw-r--r-- | table/table_manager.go | 42 |
2 files changed, 67 insertions, 0 deletions
diff --git a/table/table.go b/table/table.go index a5f867d4..3bc5bb3f 100644 --- a/table/table.go +++ b/table/table.go @@ -69,6 +69,31 @@ func (t *Table) DeleteDestByPeer(peerInfo *PeerInfo) []*Destination { return changedDests } +func (t *Table) deletePathsByVrf(vrf *Vrf) []*Path { + pathList := make([]*Path, 0) + for _, dest := range t.destinations { + for _, p := range dest.GetKnownPathList() { + var rd bgp.RouteDistinguisherInterface + nlri := p.GetNlri() + switch nlri.(type) { + case *bgp.LabeledVPNIPAddrPrefix: + rd = nlri.(*bgp.LabeledVPNIPAddrPrefix).RD + case *bgp.LabeledVPNIPv6AddrPrefix: + rd = nlri.(*bgp.LabeledVPNIPv6AddrPrefix).RD + case *bgp.EVPNNLRI: + rd = nlri.(*bgp.EVPNNLRI).RD() + default: + return pathList + } + if p.IsLocal() && vrf.Rd.String() == rd.String() { + p.IsWithdraw = true + pathList = append(pathList, p) + } + } + } + return pathList +} + func (t *Table) deleteDestByNlri(nlri bgp.AddrPrefixInterface) *Destination { destinations := t.GetDestinations() dest := destinations[t.tableKey(nlri)] diff --git a/table/table_manager.go b/table/table_manager.go index 41630246..e44babe7 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -17,6 +17,7 @@ package table import ( "bytes" + "fmt" log "github.com/Sirupsen/logrus" "github.com/osrg/gobgp/packet" "net" @@ -134,6 +135,47 @@ func (manager *TableManager) OwnerName() string { return manager.owner } +func (manager *TableManager) AddVrf(name string, rd bgp.RouteDistinguisherInterface, importRt, exportRt []bgp.ExtendedCommunityInterface) error { + if _, ok := manager.Vrfs[name]; ok { + return fmt.Errorf("vrf %s already exists", name) + } + log.WithFields(log.Fields{ + "Topic": "Vrf", + "Key": name, + "Rd": rd, + "ImportRt": importRt, + "ExportRt": exportRt, + }).Debugf("add vrf") + manager.Vrfs[name] = &Vrf{ + Name: name, + Rd: rd, + ImportRt: importRt, + ExportRt: exportRt, + } + return nil + +} + +func (manager *TableManager) DeleteVrf(name string) ([]*Path, error) { + if _, ok := manager.Vrfs[name]; !ok { + return nil, fmt.Errorf("vrf %s not found", name) + } + msgs := make([]*Path, 0) + vrf := manager.Vrfs[name] + for _, t := range manager.Tables { + msgs = append(msgs, t.deletePathsByVrf(vrf)...) + } + log.WithFields(log.Fields{ + "Topic": "Vrf", + "Key": vrf.Name, + "Rd": vrf.Rd, + "ImportRt": vrf.ImportRt, + "ExportRt": vrf.ExportRt, + }).Debugf("delete vrf") + delete(manager.Vrfs, name) + return msgs, nil +} + func (manager *TableManager) calculate(destinationList []*Destination) ([]*Path, error) { newPaths := make([]*Path, 0) |