From 7a2b3951160804c6895714621099168e8e56aa74 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Sat, 26 Dec 2015 19:24:46 -0800 Subject: add MOD_PATH API Handle only one route unlike MOD_PATHS API. When the API returns an uuid when a route is created. The uuid can be used to remove the route later. Signed-off-by: FUJITA Tomonori --- server/server.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) (limited to 'server/server.go') diff --git a/server/server.go b/server/server.go index 893229c2..670deee4 100644 --- a/server/server.go +++ b/server/server.go @@ -26,6 +26,7 @@ import ( "github.com/osrg/gobgp/packet" "github.com/osrg/gobgp/table" "github.com/osrg/gobgp/zebra" + "github.com/satori/go.uuid" "net" "os" "strconv" @@ -1203,6 +1204,58 @@ func (server *BgpServer) Api2PathList(resource api.Resource, name string, ApiPat } func (server *BgpServer) handleModPathRequest(grpcReq *GrpcRequest) []*table.Path { + var err error + var uuidBytes []byte + paths := make([]*table.Path, 0, 1) + arg, ok := grpcReq.Data.(*api.ModPathArguments) + if !ok { + err = fmt.Errorf("type assertion failed") + } + + if err == nil { + switch arg.Operation { + case api.Operation_DEL: + if len(arg.Uuid) > 0 { + path := func() *table.Path { + for _, rf := range server.globalRib.GetRFlist() { + for _, path := range server.globalRib.GetPathList(table.GLOBAL_RIB_NAME, rf) { + if len(path.Uuid) > 0 && bytes.Equal(path.Uuid, arg.Uuid) { + return path + } + } + } + return nil + }() + if path != nil { + paths = append(paths, path.Clone(path.Owner, true)) + } else { + err = fmt.Errorf("Can't find a specified path") + } + break + } + arg.Path.IsWithdraw = true + fallthrough + case api.Operation_ADD: + paths, err = server.Api2PathList(arg.Resource, arg.Name, []*api.Path{arg.Path}) + if err == nil { + u := uuid.NewV4() + uuidBytes = u.Bytes() + paths[0].Uuid = uuidBytes + } + } + } + result := &GrpcResponse{ + ResponseErr: err, + Data: &api.ModPathResponse{ + Uuid: uuidBytes, + }, + } + grpcReq.ResponseCh <- result + close(grpcReq.ResponseCh) + return paths +} + +func (server *BgpServer) handleModPathsRequest(grpcReq *GrpcRequest) []*table.Path { var err error var paths []*table.Path arg, ok := grpcReq.Data.(*api.ModPathsArguments) @@ -1531,14 +1584,18 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { Data: d, } close(grpcReq.ResponseCh) - case REQ_MOD_PATHS: + case REQ_MOD_PATH: pathList := server.handleModPathRequest(grpcReq) + if len(pathList) > 0 { + msgs, _ = server.propagateUpdate(nil, pathList) + } + case REQ_MOD_PATHS: + pathList := server.handleModPathsRequest(grpcReq) if len(pathList) > 0 { msgs, _ = server.propagateUpdate(nil, pathList) grpcReq.ResponseCh <- &GrpcResponse{} close(grpcReq.ResponseCh) } - case REQ_NEIGHBORS: results := make([]*GrpcResponse, len(server.neighborMap)) i := 0 -- cgit v1.2.3