diff options
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 18 | ||||
-rw-r--r-- | table/destination_test.go | 8 | ||||
-rw-r--r-- | table/path.go | 22 | ||||
-rw-r--r-- | table/path_test.go | 4 | ||||
-rw-r--r-- | table/table.go | 10 | ||||
-rw-r--r-- | table/table_manager.go | 63 | ||||
-rw-r--r-- | table/table_manager_test.go | 6 | ||||
-rw-r--r-- | table/table_test.go | 2 |
8 files changed, 50 insertions, 83 deletions
diff --git a/table/destination.go b/table/destination.go index 4bb77ae7..84643959 100644 --- a/table/destination.go +++ b/table/destination.go @@ -45,13 +45,13 @@ type PeerInfo struct { ID net.IP VersionNum int LocalID net.IP - RF RouteFamily + RF bgp.RouteFamily } type Destination interface { Calculate(localAsn uint32) (Path, string, error) - getRouteFamily() RouteFamily - setRouteFamily(ROUTE_FAMILY RouteFamily) + getRouteFamily() bgp.RouteFamily + setRouteFamily(ROUTE_FAMILY bgp.RouteFamily) getNlri() bgp.AddrPrefixInterface setNlri(nlri bgp.AddrPrefixInterface) getBestPathReason() string @@ -71,7 +71,7 @@ type Destination interface { } type DestinationDefault struct { - ROUTE_FAMILY RouteFamily + ROUTE_FAMILY bgp.RouteFamily nlri bgp.AddrPrefixInterface knownPathList []Path withdrawList []Path @@ -83,7 +83,7 @@ type DestinationDefault struct { func NewDestinationDefault(nlri bgp.AddrPrefixInterface) *DestinationDefault { destination := &DestinationDefault{} - destination.ROUTE_FAMILY = RF_IPv4_UC + destination.ROUTE_FAMILY = bgp.RF_IPv4_UC destination.nlri = nlri destination.knownPathList = make([]Path, 0) destination.withdrawList = make([]Path, 0) @@ -105,11 +105,11 @@ func (dd *DestinationDefault) MarshalJSON() ([]byte, error) { }) } -func (dd *DestinationDefault) getRouteFamily() RouteFamily { +func (dd *DestinationDefault) getRouteFamily() bgp.RouteFamily { return dd.ROUTE_FAMILY } -func (dd *DestinationDefault) setRouteFamily(ROUTE_FAMILY RouteFamily) { +func (dd *DestinationDefault) setRouteFamily(ROUTE_FAMILY bgp.RouteFamily) { dd.ROUTE_FAMILY = ROUTE_FAMILY } @@ -816,7 +816,7 @@ type IPv4Destination struct { func NewIPv4Destination(nlri bgp.AddrPrefixInterface) *IPv4Destination { ipv4Destination := &IPv4Destination{} ipv4Destination.DestinationDefault = NewDestinationDefault(nlri) - ipv4Destination.DestinationDefault.ROUTE_FAMILY = RF_IPv4_UC + ipv4Destination.DestinationDefault.ROUTE_FAMILY = bgp.RF_IPv4_UC //need Processing return ipv4Destination } @@ -834,7 +834,7 @@ type IPv6Destination struct { func NewIPv6Destination(nlri bgp.AddrPrefixInterface) *IPv6Destination { ipv6Destination := &IPv6Destination{} ipv6Destination.DestinationDefault = NewDestinationDefault(nlri) - ipv6Destination.DestinationDefault.ROUTE_FAMILY = RF_IPv6_UC + ipv6Destination.DestinationDefault.ROUTE_FAMILY = bgp.RF_IPv6_UC //need Processing return ipv6Destination } diff --git a/table/destination_test.go b/table/destination_test.go index 29534c04..b3482839 100644 --- a/table/destination_test.go +++ b/table/destination_test.go @@ -40,15 +40,15 @@ func TestDestinationNewIPv6(t *testing.T) { func TestDestinationSetRouteFamily(t *testing.T) { dd := &DestinationDefault{} - dd.setRouteFamily(RF_IPv4_UC) + dd.setRouteFamily(bgp.RF_IPv4_UC) rf := dd.getRouteFamily() - assert.Equal(t, rf, RF_IPv4_UC) + assert.Equal(t, rf, bgp.RF_IPv4_UC) } func TestDestinationGetRouteFamily(t *testing.T) { dd := &DestinationDefault{} - dd.setRouteFamily(RF_IPv6_UC) + dd.setRouteFamily(bgp.RF_IPv6_UC) rf := dd.getRouteFamily() - assert.Equal(t, rf, RF_IPv6_UC) + assert.Equal(t, rf, bgp.RF_IPv6_UC) } func TestDestinationSetNlri(t *testing.T) { dd := &DestinationDefault{} diff --git a/table/path.go b/table/path.go index 1ccbb1a2..6c628448 100644 --- a/table/path.go +++ b/table/path.go @@ -28,7 +28,7 @@ type Path interface { String() string GetPathAttrs() []bgp.PathAttributeInterface GetPathAttr(bgp.BGPAttrType) (int, bgp.PathAttributeInterface) - GetRouteFamily() RouteFamily + GetRouteFamily() bgp.RouteFamily setSource(source *PeerInfo) getSource() *PeerInfo setNexthop(nexthop net.IP) @@ -47,7 +47,7 @@ type Path interface { } type PathDefault struct { - routeFamily RouteFamily + routeFamily bgp.RouteFamily source *PeerInfo nexthop net.IP sourceVerNum int @@ -58,7 +58,7 @@ type PathDefault struct { isBest bool } -func NewPathDefault(rf RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP, isWithdraw bool, pattrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *PathDefault { +func NewPathDefault(rf bgp.RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP, isWithdraw bool, pattrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *PathDefault { if !isWithdraw && pattrs == nil { log.Error("Need to provide nexthop and patattrs for path that is not a withdraw.") @@ -133,7 +133,7 @@ func (pd *PathDefault) Clone(isWithdraw bool) Path { return CreatePath(pd.source, nlri, copiedAttrs, isWithdraw) } -func (pd *PathDefault) GetRouteFamily() RouteFamily { +func (pd *PathDefault) GetRouteFamily() bgp.RouteFamily { return pd.routeFamily } @@ -235,7 +235,7 @@ func (pi *PathDefault) getPrefix() net.IP { // create Path object based on route family func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, attrs []bgp.PathAttributeInterface, isWithdraw bool) Path { - rf := RouteFamily(int(nlri.AFI())<<16 | int(nlri.SAFI())) + rf := bgp.RouteFamily(int(nlri.AFI())<<16 | int(nlri.SAFI())) log.Debugf("afi: %d, safi: %d ", int(nlri.AFI()), nlri.SAFI()) var path Path var sourceVerNum int = 1 @@ -245,11 +245,11 @@ func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, attrs []bgp.Path } switch rf { - case RF_IPv4_UC: - log.Debugf("RouteFamily : %s", RF_IPv4_UC.String()) + case bgp.RF_IPv4_UC: + log.Debugf("RouteFamily : %s", bgp.RF_IPv4_UC.String()) path = NewIPv4Path(source, nlri, sourceVerNum, isWithdraw, attrs, false) - case RF_IPv6_UC: - log.Debugf("RouteFamily : %s", RF_IPv6_UC.String()) + case bgp.RF_IPv6_UC: + log.Debugf("RouteFamily : %s", bgp.RF_IPv6_UC.String()) path = NewIPv6Path(source, nlri, sourceVerNum, isWithdraw, attrs, false) } return path @@ -264,7 +264,7 @@ type IPv4Path struct { func NewIPv4Path(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, isWithdraw bool, attrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *IPv4Path { ipv4Path := &IPv4Path{} - ipv4Path.PathDefault = NewPathDefault(RF_IPv4_UC, source, nlri, sourceVerNum, nil, isWithdraw, attrs, medSetByTargetNeighbor) + ipv4Path.PathDefault = NewPathDefault(bgp.RF_IPv4_UC, source, nlri, sourceVerNum, nil, isWithdraw, attrs, medSetByTargetNeighbor) if !isWithdraw { _, nexthop_attr := ipv4Path.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) ipv4Path.nexthop = nexthop_attr.(*bgp.PathAttributeNextHop).Value @@ -285,7 +285,7 @@ type IPv6Path struct { func NewIPv6Path(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, isWithdraw bool, attrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *IPv6Path { ipv6Path := &IPv6Path{} - ipv6Path.PathDefault = NewPathDefault(RF_IPv6_UC, source, nlri, sourceVerNum, nil, isWithdraw, attrs, medSetByTargetNeighbor) + ipv6Path.PathDefault = NewPathDefault(bgp.RF_IPv6_UC, source, nlri, sourceVerNum, nil, isWithdraw, attrs, medSetByTargetNeighbor) if !isWithdraw { _, mpattr := ipv6Path.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) ipv6Path.nexthop = mpattr.(*bgp.PathAttributeMpReachNLRI).Nexthop diff --git a/table/path_test.go b/table/path_test.go index 786dad26..51fe6328 100644 --- a/table/path_test.go +++ b/table/path_test.go @@ -57,9 +57,9 @@ func TestPathIPv6GetDefault(t *testing.T) { } func TestPathGetRouteFamily(t *testing.T) { - pd := &PathDefault{routeFamily: RF_IPv6_UC} + pd := &PathDefault{routeFamily: bgp.RF_IPv6_UC} rf := pd.GetRouteFamily() - assert.Equal(t, rf, RF_IPv6_UC) + assert.Equal(t, rf, bgp.RF_IPv6_UC) } func TestPathSetSource(t *testing.T) { diff --git a/table/table.go b/table/table.go index 7021f025..5981ca46 100644 --- a/table/table.go +++ b/table/table.go @@ -37,14 +37,14 @@ type Table interface { } type TableDefault struct { - ROUTE_FAMILY RouteFamily + ROUTE_FAMILY bgp.RouteFamily destinations map[string]Destination //need SignalBus } func NewTableDefault(scope_id int) *TableDefault { table := &TableDefault{} - table.ROUTE_FAMILY = RF_IPv4_UC + table.ROUTE_FAMILY = bgp.RF_IPv4_UC table.destinations = make(map[string]Destination) return table @@ -63,7 +63,7 @@ func (td *TableDefault) MarshalJSON() ([]byte, error) { }) } -func (td *TableDefault) GetRoutefamily() RouteFamily { +func (td *TableDefault) GetRoutefamily() bgp.RouteFamily { return td.ROUTE_FAMILY } @@ -204,7 +204,7 @@ type IPv4Table struct { func NewIPv4Table(scope_id int) *IPv4Table { ipv4Table := &IPv4Table{} ipv4Table.TableDefault = NewTableDefault(scope_id) - ipv4Table.TableDefault.ROUTE_FAMILY = RF_IPv4_UC + ipv4Table.TableDefault.ROUTE_FAMILY = bgp.RF_IPv4_UC //need Processing return ipv4Table } @@ -238,7 +238,7 @@ type IPv6Table struct { func NewIPv6Table(scope_id int) *IPv6Table { ipv6Table := &IPv6Table{} ipv6Table.TableDefault = NewTableDefault(scope_id) - ipv6Table.TableDefault.ROUTE_FAMILY = RF_IPv6_UC + ipv6Table.TableDefault.ROUTE_FAMILY = bgp.RF_IPv6_UC //need Processing return ipv6Table } diff --git a/table/table_manager.go b/table/table_manager.go index 4a0c70d6..3d056b08 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -21,39 +21,6 @@ import ( "time" ) -type RouteFamily int - -const ( - RF_IPv4_UC RouteFamily = bgp.RF_IPv4_UC - RF_IPv6_UC RouteFamily = bgp.RF_IPv6_UC - RF_IPv4_VPN RouteFamily = bgp.RF_IPv4_VPN - RF_IPv6_VPN RouteFamily = bgp.RF_IPv6_VPN - RF_IPv4_MPLS RouteFamily = bgp.RF_IPv4_MPLS - RF_IPv6_MPLS RouteFamily = bgp.RF_IPv6_MPLS - RF_RTC_UC RouteFamily = bgp.RF_RTC_UC -) - -func (rf RouteFamily) String() string { - switch rf { - case RF_IPv4_UC: - return "RF_IPv4_UC" - case RF_IPv6_UC: - return "RF_IPv6_UC" - case RF_IPv4_VPN: - return "RF_IPv4_VPN" - case RF_IPv6_VPN: - return "RF_IPv6_VPN" - case RF_IPv4_MPLS: - return "RF_IPv4_MPLS" - case RF_IPv6_MPLS: - return "RF_IPv6_MPLS" - case RF_RTC_UC: - return "RF_RTC_UC" - default: - return "Unknown" - } -} - type ProcessMessage struct { innerMessage *bgp.BGPMessage fromPeer *PeerInfo @@ -153,15 +120,15 @@ func (p *ProcessMessage) ToPathList() []Path { } type TableManager struct { - Tables map[RouteFamily]Table + Tables map[bgp.RouteFamily]Table localAsn uint32 } func NewTableManager() *TableManager { t := &TableManager{} - t.Tables = make(map[RouteFamily]Table) - t.Tables[RF_IPv4_UC] = NewIPv4Table(0) - t.Tables[RF_IPv6_UC] = NewIPv6Table(0) + t.Tables = make(map[bgp.RouteFamily]Table) + t.Tables[bgp.RF_IPv4_UC] = NewIPv4Table(0) + t.Tables[bgp.RF_IPv6_UC] = NewIPv6Table(0) return t } @@ -259,23 +226,23 @@ func (manager *TableManager) ProcessUpdate(fromPeer *PeerInfo, message *bgp.BGPM } type AdjRib struct { - adjRibIn map[RouteFamily]map[string]*ReceivedRoute - adjRibOut map[RouteFamily]map[string]*ReceivedRoute + adjRibIn map[bgp.RouteFamily]map[string]*ReceivedRoute + adjRibOut map[bgp.RouteFamily]map[string]*ReceivedRoute } func NewAdjRib() *AdjRib { r := &AdjRib{ - adjRibIn: make(map[RouteFamily]map[string]*ReceivedRoute), - adjRibOut: make(map[RouteFamily]map[string]*ReceivedRoute), + adjRibIn: make(map[bgp.RouteFamily]map[string]*ReceivedRoute), + adjRibOut: make(map[bgp.RouteFamily]map[string]*ReceivedRoute), } - r.adjRibIn[RF_IPv4_UC] = make(map[string]*ReceivedRoute) - r.adjRibIn[RF_IPv6_UC] = make(map[string]*ReceivedRoute) - r.adjRibOut[RF_IPv4_UC] = make(map[string]*ReceivedRoute) - r.adjRibOut[RF_IPv6_UC] = make(map[string]*ReceivedRoute) + r.adjRibIn[bgp.RF_IPv4_UC] = make(map[string]*ReceivedRoute) + r.adjRibIn[bgp.RF_IPv6_UC] = make(map[string]*ReceivedRoute) + r.adjRibOut[bgp.RF_IPv4_UC] = make(map[string]*ReceivedRoute) + r.adjRibOut[bgp.RF_IPv6_UC] = make(map[string]*ReceivedRoute) return r } -func (adj *AdjRib) update(rib map[RouteFamily]map[string]*ReceivedRoute, pathList []Path) { +func (adj *AdjRib) update(rib map[bgp.RouteFamily]map[string]*ReceivedRoute, pathList []Path) { for _, path := range pathList { rf := path.GetRouteFamily() key := path.getPrefix().String() @@ -307,11 +274,11 @@ func (adj *AdjRib) getPathList(rib map[string]*ReceivedRoute) []Path { return pathList } -func (adj *AdjRib) GetInPathList(rf RouteFamily) []Path { +func (adj *AdjRib) GetInPathList(rf bgp.RouteFamily) []Path { return adj.getPathList(adj.adjRibIn[rf]) } -func (adj *AdjRib) GetOutPathList(rf RouteFamily) []Path { +func (adj *AdjRib) GetOutPathList(rf bgp.RouteFamily) []Path { return adj.getPathList(adj.adjRibOut[rf]) } diff --git a/table/table_manager_test.go b/table/table_manager_test.go index f3a146a9..95634bd6 100644 --- a/table/table_manager_test.go +++ b/table/table_manager_test.go @@ -2091,7 +2091,7 @@ func TestProcessBGPUpdate_multiple_nlri_ipv4(t *testing.T) { assert.NoError(t, err) // check table - table := tm.Tables[RF_IPv4_UC] + table := tm.Tables[bgp.RF_IPv4_UC] assert.Equal(t, 13, len(table.getDestinations())) } @@ -2234,7 +2234,7 @@ func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) { assert.NoError(t, err) // check table - table := tm.Tables[RF_IPv6_UC] + table := tm.Tables[bgp.RF_IPv6_UC] assert.Equal(t, 13, len(table.getDestinations())) } @@ -2257,7 +2257,7 @@ func TestModifyPathAttribute(t *testing.T) { original := mx1.Value mx1.Value++ - table := tm.Tables[RF_IPv4_UC] + table := tm.Tables[bgp.RF_IPv4_UC] dest := table.getDestination(table.tableKey(path0.GetNlri()).String()).(*IPv4Destination) path2 := dest.getKnownPathList() _, attr2 := path2[0].GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) diff --git a/table/table_test.go b/table/table_test.go index 8a347d30..6e392e93 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -72,7 +72,7 @@ func TestTableDeleteDest(t *testing.T) { func TestTableGetRouteFamily(t *testing.T) { ipv4t := NewIPv4Table(0) rf := ipv4t.GetRoutefamily() - assert.Equal(t, rf, RF_IPv4_UC) + assert.Equal(t, rf, bgp.RF_IPv4_UC) } func TestTableSetDestinations(t *testing.T) { |