diff options
-rw-r--r-- | api/grpc_server.go | 1 | ||||
-rw-r--r-- | api/util.go | 1 | ||||
-rw-r--r-- | server/server.go | 29 | ||||
-rw-r--r-- | table/path.go | 16 |
4 files changed, 22 insertions, 25 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go index 30934cda..cec1c272 100644 --- a/api/grpc_server.go +++ b/api/grpc_server.go @@ -392,7 +392,6 @@ func ToPathApi(path *table.Path) *Path { Stale: path.IsStale(), IsFromExternal: path.IsFromExternal(), NoImplicitWithdraw: path.NoImplicitWithdraw(), - Uuid: path.UUID().Bytes(), IsNexthopInvalid: path.IsNexthopInvalid, Identifier: nlri.PathIdentifier(), LocalIdentifier: nlri.PathLocalIdentifier(), diff --git a/api/util.go b/api/util.go index 9a16bef5..177b48a9 100644 --- a/api/util.go +++ b/api/util.go @@ -134,7 +134,6 @@ func (p *Path) ToNativePath(option ...ToNativeOption) (*table.Path, error) { UnmatchedLength: NewROAListFromApiStructList(p.ValidationDetail.UnmatchedLength), }) path.MarkStale(p.Stale) - path.SetUUID(p.Uuid) path.IsNexthopInvalid = p.IsNexthopInvalid return path, nil } diff --git a/server/server.go b/server/server.go index d533dc60..15b95073 100644 --- a/server/server.go +++ b/server/server.go @@ -24,6 +24,7 @@ import ( "time" "github.com/eapache/channels" + uuid "github.com/satori/go.uuid" log "github.com/sirupsen/logrus" "github.com/osrg/gobgp/config" @@ -115,6 +116,7 @@ type BgpServer struct { zclient *zebraClient bmpManager *bmpClientManager mrtManager *mrtManager + uuidMap map[uuid.UUID]string } func NewBgpServer() *BgpServer { @@ -126,6 +128,7 @@ func NewBgpServer() *BgpServer { roaManager: roaManager, mgmtCh: make(chan *mgmtOp, 1), watcherMap: make(map[WatchEventType][]*Watcher), + uuidMap: make(map[uuid.UUID]string), } s.bmpManager = newBmpClientManager(s) s.mrtManager = newMrtManager(s) @@ -1262,14 +1265,19 @@ func (server *BgpServer) fixupApiPath(vrfId string, pathList []*table.Path) erro return nil } +func pathTokey(path *table.Path) string { + return fmt.Sprintf("%d:%s", path.GetNlri().PathIdentifier(), path.GetNlri().String()) +} + func (s *BgpServer) AddPath(vrfId string, pathList []*table.Path) (uuidBytes []byte, err error) { err = s.mgmtOperation(func() error { if err := s.fixupApiPath(vrfId, pathList); err != nil { return err } if len(pathList) == 1 { - pathList[0].AssignNewUUID() - uuidBytes = pathList[0].UUID().Bytes() + path := pathList[0] + id, _ := uuid.NewV4() + s.uuidMap[id] = pathTokey(path) } s.propagateUpdate(nil, pathList) return nil @@ -1277,15 +1285,21 @@ func (s *BgpServer) AddPath(vrfId string, pathList []*table.Path) (uuidBytes []b return } -func (s *BgpServer) DeletePath(uuid []byte, f bgp.RouteFamily, vrfId string, pathList []*table.Path) error { +func (s *BgpServer) DeletePath(uuidBytes []byte, f bgp.RouteFamily, vrfId string, pathList []*table.Path) error { return s.mgmtOperation(func() error { deletePathList := make([]*table.Path, 0) - if len(uuid) > 0 { + if len(uuidBytes) > 0 { // Delete locally generated path which has the given UUID path := func() *table.Path { - for _, path := range s.globalRib.GetPathList(table.GLOBAL_RIB_NAME, 0, s.globalRib.GetRFlist()) { - if path.IsLocal() && len(path.UUID()) > 0 && bytes.Equal(path.UUID().Bytes(), uuid) { - return path + id, _ := uuid.FromBytes(uuidBytes) + if key, ok := s.uuidMap[id]; !ok { + return nil + } else { + for _, path := range s.globalRib.GetPathList(table.GLOBAL_RIB_NAME, 0, s.globalRib.GetRFlist()) { + if path.IsLocal() && key == pathTokey(path) { + delete(s.uuidMap, id) + return path + } } } return nil @@ -1305,6 +1319,7 @@ func (s *BgpServer) DeletePath(uuid []byte, f bgp.RouteFamily, vrfId string, pat deletePathList = append(deletePathList, path.Clone(true)) } } + s.uuidMap = make(map[uuid.UUID]string) } else { if err := s.fixupApiPath(vrfId, pathList); err != nil { return err diff --git a/table/path.go b/table/path.go index b36f07eb..f6024ebc 100644 --- a/table/path.go +++ b/table/path.go @@ -28,8 +28,6 @@ import ( log "github.com/sirupsen/logrus" - uuid "github.com/satori/go.uuid" - "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet/bgp" ) @@ -95,7 +93,6 @@ type originInfo struct { timestamp int64 validation *Validation key string - uuid uuid.UUID noImplicitWithdraw bool isFromExternal bool eor bool @@ -379,18 +376,6 @@ func (path *Path) SetIsFromExternal(y bool) { path.OriginInfo().isFromExternal = y } -func (path *Path) UUID() uuid.UUID { - return path.OriginInfo().uuid -} - -func (path *Path) SetUUID(id []byte) { - path.OriginInfo().uuid = uuid.FromBytesOrNil(id) -} - -func (path *Path) AssignNewUUID() { - path.OriginInfo().uuid, _ = uuid.NewV4() -} - func (path *Path) GetRouteFamily() bgp.RouteFamily { return bgp.AfiSafiToRouteFamily(path.OriginInfo().nlri.AFI(), path.OriginInfo().nlri.SAFI()) } @@ -1092,7 +1077,6 @@ func (path *Path) MarshalJSON() ([]byte, error) { SourceID: path.GetSource().ID, NeighborIP: path.GetSource().Address, Stale: path.IsStale(), - UUID: path.UUID().String(), ID: path.GetNlri().PathIdentifier(), }) } |