diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-08-17 15:54:07 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-19 13:29:33 +0900 |
commit | c14a63575c62addaf96c78f4de9aef6e3c430f0f (patch) | |
tree | 272698e91435a7cd0a765dee37069096f4052501 /table/table_manager.go | |
parent | 22b43f7ae7daf381520a529157be4c71c11c2bc8 (diff) |
table: withdraw self-generated vrfed routes when a vrf deleted
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table/table_manager.go')
-rw-r--r-- | table/table_manager.go | 42 |
1 files changed, 42 insertions, 0 deletions
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) |