summaryrefslogtreecommitdiffhomepage
path: root/server/server.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-08-17 15:54:07 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-19 13:29:33 +0900
commitc14a63575c62addaf96c78f4de9aef6e3c430f0f (patch)
tree272698e91435a7cd0a765dee37069096f4052501 /server/server.go
parent22b43f7ae7daf381520a529157be4c71c11c2bc8 (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 'server/server.go')
-rw-r--r--server/server.go48
1 files changed, 15 insertions, 33 deletions
diff --git a/server/server.go b/server/server.go
index 11fd807a..db1ce6d7 100644
--- a/server/server.go
+++ b/server/server.go
@@ -967,13 +967,11 @@ ERR:
}
-func (server *BgpServer) handleVrfMod(arg *api.ModVrfArguments) error {
- vrfs := server.localRibMap[GLOBAL_RIB_NAME].rib.Vrfs
+func (server *BgpServer) handleVrfMod(arg *api.ModVrfArguments) ([]*table.Path, error) {
+ manager := server.localRibMap[GLOBAL_RIB_NAME].rib
+ var msgs []*table.Path
switch arg.Operation {
case api.Operation_ADD:
- if _, ok := vrfs[arg.Vrf.Name]; ok {
- return fmt.Errorf("vrf %s already exists", arg.Vrf.Name)
- }
rd := bgp.GetRouteDistinguisher(arg.Vrf.Rd)
f := func(bufs [][]byte) ([]bgp.ExtendedCommunityInterface, error) {
ret := make([]bgp.ExtendedCommunityInterface, 0, len(bufs))
@@ -988,42 +986,26 @@ func (server *BgpServer) handleVrfMod(arg *api.ModVrfArguments) error {
}
importRt, err := f(arg.Vrf.ImportRt)
if err != nil {
- return err
+ return nil, err
}
exportRt, err := f(arg.Vrf.ImportRt)
if err != nil {
- return err
+ return nil, err
}
- log.WithFields(log.Fields{
- "Topic": "Vrf",
- "Key": arg.Vrf.Name,
- "Rd": rd,
- "ImportRt": importRt,
- "ExportRt": exportRt,
- }).Debugf("add vrf")
- vrfs[arg.Vrf.Name] = &table.Vrf{
- Name: arg.Vrf.Name,
- Rd: rd,
- ImportRt: importRt,
- ExportRt: exportRt,
+ err = manager.AddVrf(arg.Vrf.Name, rd, importRt, exportRt)
+ if err != nil {
+ return nil, err
}
case api.Operation_DEL:
- if _, ok := vrfs[arg.Vrf.Name]; !ok {
- return fmt.Errorf("vrf %s not found", arg.Vrf.Name)
+ var err error
+ msgs, err = manager.DeleteVrf(arg.Vrf.Name)
+ if err != nil {
+ return nil, err
}
- vrf := vrfs[arg.Vrf.Name]
- log.WithFields(log.Fields{
- "Topic": "Vrf",
- "Key": vrf.Name,
- "Rd": vrf.Rd,
- "ImportRt": vrf.ImportRt,
- "ExportRt": vrf.ExportRt,
- }).Debugf("delete vrf")
- delete(vrfs, arg.Vrf.Name)
default:
- return fmt.Errorf("unknown operation:", arg.Operation)
+ return nil, fmt.Errorf("unknown operation:", arg.Operation)
}
- return nil
+ return msgs, nil
}
func (server *BgpServer) handleVrfRequest(req *GrpcRequest) []*table.Path {
@@ -1074,7 +1056,7 @@ func (server *BgpServer) handleVrfRequest(req *GrpcRequest) []*table.Path {
goto END
case REQ_VRF_MOD:
arg := req.Data.(*api.ModVrfArguments)
- result.ResponseErr = server.handleVrfMod(arg)
+ msgs, result.ResponseErr = server.handleVrfMod(arg)
default:
result.ResponseErr = fmt.Errorf("unknown request type:", req.RequestType)
}