diff options
-rw-r--r-- | table/destination.go | 14 | ||||
-rw-r--r-- | table/path.go | 203 | ||||
-rw-r--r-- | table/path_test.go | 16 | ||||
-rw-r--r-- | table/table_manager_test.go | 363 |
4 files changed, 315 insertions, 281 deletions
diff --git a/table/destination.go b/table/destination.go index c71e4464..aeabfbd0 100644 --- a/table/destination.go +++ b/table/destination.go @@ -495,8 +495,8 @@ func compareByLocalPref(path1, path2 Path) Path { // // # Default local-pref values is 100 logger.Debugf("enter compareByLocalPref") - attribute1 := path1.getPathAttribute(bgp.BGP_ATTR_TYPE_LOCAL_PREF) - attribute2 := path2.getPathAttribute(bgp.BGP_ATTR_TYPE_LOCAL_PREF) + _, attribute1 := path1.GetPathAttr(bgp.BGP_ATTR_TYPE_LOCAL_PREF) + _, attribute2 := path2.GetPathAttr(bgp.BGP_ATTR_TYPE_LOCAL_PREF) if attribute1 == nil || attribute2 == nil { return nil @@ -546,8 +546,8 @@ func compareByASPath(path1, path2 Path) Path { // Shortest as-path length is preferred. If both path have same lengths, // we return None. logger.Debugf("enter compareByASPath") - attribute1 := path1.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH) - attribute2 := path2.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH) + _, attribute1 := path1.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + _, attribute2 := path2.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) asPath1 := attribute1.(*bgp.PathAttributeAsPath) asPath2 := attribute2.(*bgp.PathAttributeAsPath) @@ -583,8 +583,8 @@ func compareByOrigin(path1, path2 Path) Path { // IGP is preferred over EGP; EGP is preferred over Incomplete. // If both paths have same origin, we return None. logger.Debugf("enter compareByOrigin") - attribute1 := path1.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN) - attribute2 := path2.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN) + _, attribute1 := path1.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + _, attribute2 := path2.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) if attribute1 == nil || attribute2 == nil { logger.Error("it is not possible to compare origin are not present") @@ -617,7 +617,7 @@ func compareByMED(path1, path2 Path) Path { // like bgp always-compare-med logger.Debugf("enter compareByMED") getMed := func(path Path) uint32 { - attribute := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + _, attribute := path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) if attribute == nil { return 0 } diff --git a/table/path.go b/table/path.go index a5c08e8f..e7536f22 100644 --- a/table/path.go +++ b/table/path.go @@ -18,15 +18,16 @@ package table import ( "fmt" "github.com/osrg/gobgp/packet" - "github.com/osrg/gobgp/utils" + //"github.com/osrg/gobgp/utils" "net" + "reflect" ) type Path interface { String() string - getPathAttributeMap() *utils.OrderedMap - getPathAttribute(int) bgp.PathAttributeInterface - clone(forWithdrawal bool) Path + GetPathAttrs() []bgp.PathAttributeInterface + GetPathAttr(int) (int, bgp.PathAttributeInterface) + // clone(forWithdrawal bool) Path getRouteFamily() RouteFamily setSource(source *PeerInfo) getSource() *PeerInfo @@ -49,32 +50,20 @@ type PathDefault struct { sourceVerNum int withdraw bool nlri bgp.AddrPrefixInterface - pattrMap *utils.OrderedMap + pathAttrs []bgp.PathAttributeInterface medSetByTargetNeighbor bool } -func NewPathDefault(rf RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP, - isWithdraw bool, pattr *utils.OrderedMap, medSetByTargetNeighbor bool) *PathDefault { +func NewPathDefault(rf RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP, isWithdraw bool, pattrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *PathDefault { - if !isWithdraw && (pattr == nil || nexthop == nil) { + if !isWithdraw && pattrs == nil { logger.Error("Need to provide nexthop and patattrs for path that is not a withdraw.") return nil } path := &PathDefault{} path.routeFamily = rf - path.pattrMap = utils.NewOrderedMap() - if pattr != nil { - keyList := pattr.KeyLists() - for key := keyList.Front(); key != nil; key = key.Next() { - key := key.Value - val := pattr.Get(key) - e := path.pattrMap.Append(key, val) - if e != nil { - logger.Error(e) - } - } - } + path.pathAttrs = pattrs path.nlri = nlri path.source = source path.nexthop = nexthop @@ -132,46 +121,53 @@ func (pd *PathDefault) getMedSetByTargetNeighbor() bool { return pd.medSetByTargetNeighbor } -//Copy the entity -func (pd *PathDefault) getPathAttributeMap() *utils.OrderedMap { - cpPattr := utils.NewOrderedMap() - keyList := pd.pattrMap.KeyLists() - for key := keyList.Front(); key != nil; key = key.Next() { - key := key.Value - val := pd.pattrMap.Get(key) - e := cpPattr.Append(key, val) - if e != nil { - logger.Error(e) +func (pd *PathDefault) GetPathAttrs() []bgp.PathAttributeInterface { + return pd.pathAttrs +} + +func (pd *PathDefault) GetPathAttr(pattrType int) (int, bgp.PathAttributeInterface) { + attrMap := [bgp.BGP_ATTR_TYPE_AS4_AGGREGATOR + 1]reflect.Type{} + attrMap[bgp.BGP_ATTR_TYPE_ORIGIN] = reflect.TypeOf(&bgp.PathAttributeOrigin{}) + attrMap[bgp.BGP_ATTR_TYPE_AS_PATH] = reflect.TypeOf(&bgp.PathAttributeAsPath{}) + attrMap[bgp.BGP_ATTR_TYPE_NEXT_HOP] = reflect.TypeOf(&bgp.PathAttributeNextHop{}) + attrMap[bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC] = reflect.TypeOf(&bgp.PathAttributeMultiExitDisc{}) + attrMap[bgp.BGP_ATTR_TYPE_LOCAL_PREF] = reflect.TypeOf(&bgp.PathAttributeLocalPref{}) + attrMap[bgp.BGP_ATTR_TYPE_ATOMIC_AGGREGATE] = reflect.TypeOf(&bgp.PathAttributeAtomicAggregate{}) + attrMap[bgp.BGP_ATTR_TYPE_AGGREGATOR] = reflect.TypeOf(&bgp.PathAttributeAggregator{}) + attrMap[bgp.BGP_ATTR_TYPE_COMMUNITIES] = reflect.TypeOf(&bgp.PathAttributeCommunities{}) + attrMap[bgp.BGP_ATTR_TYPE_ORIGINATOR_ID] = reflect.TypeOf(&bgp.PathAttributeOriginatorId{}) + attrMap[bgp.BGP_ATTR_TYPE_CLUSTER_LIST] = reflect.TypeOf(&bgp.PathAttributeClusterList{}) + attrMap[bgp.BGP_ATTR_TYPE_MP_REACH_NLRI] = reflect.TypeOf(&bgp.PathAttributeMpReachNLRI{}) + attrMap[bgp.BGP_ATTR_TYPE_MP_UNREACH_NLRI] = reflect.TypeOf(&bgp.PathAttributeMpUnreachNLRI{}) + attrMap[bgp.BGP_ATTR_TYPE_EXTENDED_COMMUNITIES] = reflect.TypeOf(&bgp.PathAttributeExtendedCommunities{}) + attrMap[bgp.BGP_ATTR_TYPE_AS4_PATH] = reflect.TypeOf(&bgp.PathAttributeAs4Path{}) + attrMap[bgp.BGP_ATTR_TYPE_AS4_AGGREGATOR] = reflect.TypeOf(&bgp.PathAttributeAs4Aggregator{}) + + t := attrMap[pattrType] + for i, p := range pd.pathAttrs { + if t == reflect.TypeOf(p) { + return i, p } } - return cpPattr -} - -func (pd *PathDefault) getPathAttribute(pattrType int) bgp.PathAttributeInterface { - attr := pd.pattrMap.Get(pattrType) - if attr == nil { - logger.Debugf("Attribute Type %s is not found", AttributeType(pattrType)) - return nil - } - return attr.(bgp.PathAttributeInterface) -} - -func (pi *PathDefault) clone(forWithdrawal bool) Path { - pathAttrs := utils.NewOrderedMap() - if !forWithdrawal { - pathAttrs = pi.getPathAttributeMap() - } - def := NewPathDefault(pi.getRouteFamily(), pi.getSource(), pi.GetNlri(), pi.getSourceVerNum(), - pi.getNexthop(), forWithdrawal, pathAttrs, pi.getMedSetByTargetNeighbor()) - switch pi.getRouteFamily() { - case RF_IPv4_UC: - return &IPv4Path{PathDefault: def} - case RF_IPv6_UC: - return &IPv6Path{PathDefault: def} - default: - return def - } -} + return -1, nil +} + +// func (pi *PathDefault) clone(forWithdrawal bool) Path { +// pathAttrs := utils.NewOrderedMap() +// if !forWithdrawal { +// pathAttrs = pi.getPathAttributeMap() +// } +// def := NewPathDefault(pi.getRouteFamily(), pi.getSource(), pi.GetNlri(), pi.getSourceVerNum(), +// pi.getNexthop(), forWithdrawal, pathAttrs, pi.getMedSetByTargetNeighbor()) +// switch pi.getRouteFamily() { +// case RF_IPv4_UC: +// return &IPv4Path{PathDefault: def} +// case RF_IPv6_UC: +// return &IPv6Path{PathDefault: def} +// default: +// return def +// } +//} // return Path's string representation func (pi *PathDefault) String() string { @@ -179,7 +175,7 @@ func (pi *PathDefault) String() string { str = str + fmt.Sprintf(" NLRI: %s, ", pi.getPrefix().String()) str = str + fmt.Sprintf(" nexthop: %s, ", pi.getNexthop().String()) str = str + fmt.Sprintf(" withdraw: %s, ", pi.isWithdraw()) - str = str + fmt.Sprintf(" path attributes: %s, ", pi.getPathAttributeMap()) + //str = str + fmt.Sprintf(" path attributes: %s, ", pi.getPathAttributeMap()) return str } @@ -194,57 +190,11 @@ func (pi *PathDefault) getPrefix() net.IP { return nil } -func createPathAttributeMap(pathAttributes []bgp.PathAttributeInterface) *utils.OrderedMap { - - pathAttrMap := utils.NewOrderedMap() - for _, attr := range pathAttributes { - var err error - switch a := attr.(type) { - case *bgp.PathAttributeOrigin: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_ORIGIN, a) - case *bgp.PathAttributeAsPath: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_AS_PATH, a) - case *bgp.PathAttributeNextHop: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_NEXT_HOP, a) - case *bgp.PathAttributeMultiExitDisc: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC, a) - case *bgp.PathAttributeLocalPref: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_LOCAL_PREF, a) - case *bgp.PathAttributeAtomicAggregate: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_ATOMIC_AGGREGATE, a) - case *bgp.PathAttributeAggregator: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_AGGREGATOR, a) - case *bgp.PathAttributeCommunities: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_COMMUNITIES, a) - case *bgp.PathAttributeOriginatorId: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_ORIGINATOR_ID, a) - case *bgp.PathAttributeClusterList: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_CLUSTER_LIST, a) - case *bgp.PathAttributeMpReachNLRI: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI, a) - case *bgp.PathAttributeMpUnreachNLRI: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_MP_UNREACH_NLRI, a) - case *bgp.PathAttributeExtendedCommunities: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_EXTENDED_COMMUNITIES, a) - case *bgp.PathAttributeAs4Path: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_AS4_PATH, a) - case *bgp.PathAttributeAs4Aggregator: - err = pathAttrMap.Append(bgp.BGP_ATTR_TYPE_AS4_AGGREGATOR, a) - } - if err != nil { - return nil - } - } - return pathAttrMap -} - // create Path object based on route family -func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, - pathAttributes []bgp.PathAttributeInterface, isWithdraw bool) Path { +func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, attrs []bgp.PathAttributeInterface, isWithdraw bool) Path { rf := RouteFamily(int(nlri.AFI())<<16 | int(nlri.SAFI())) logger.Debugf("afi: %d, safi: %d ", int(nlri.AFI()), nlri.SAFI()) - pathAttrMap := createPathAttributeMap(pathAttributes) var path Path var sourceVerNum int = 1 @@ -255,27 +205,10 @@ func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, switch rf { case RF_IPv4_UC: logger.Debugf("RouteFamily : %s", RF_IPv4_UC.String()) - var nexthop net.IP - - if !isWithdraw { - nexthop_attr := pathAttrMap.Get(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) - nexthop = nexthop_attr.Value - } else { - nexthop = nil - } - - path = NewIPv4Path(source, nlri, sourceVerNum, nexthop, isWithdraw, pathAttrMap, false) + path = NewIPv4Path(source, nlri, sourceVerNum, isWithdraw, attrs, false) case RF_IPv6_UC: logger.Debugf("RouteFamily : %s", RF_IPv6_UC.String()) - var nexthop net.IP - - if !isWithdraw { - mpattr := pathAttrMap.Get(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) - nexthop = mpattr.Nexthop - } else { - nexthop = nil - } - path = NewIPv6Path(source, nlri, sourceVerNum, nexthop, isWithdraw, pathAttrMap, false) + path = NewIPv6Path(source, nlri, sourceVerNum, isWithdraw, attrs, false) } return path } @@ -287,10 +220,13 @@ type IPv4Path struct { *PathDefault } -func NewIPv4Path(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP, - isWithdraw bool, pattr *utils.OrderedMap, medSetByTargetNeighbor bool) *IPv4Path { +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, nexthop, isWithdraw, pattr, medSetByTargetNeighbor) + ipv4Path.PathDefault = NewPathDefault(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 + } return ipv4Path } @@ -305,10 +241,13 @@ type IPv6Path struct { *PathDefault } -func NewIPv6Path(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP, - isWithdraw bool, pattr *utils.OrderedMap, medSetByTargetNeighbor bool) *IPv6Path { +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, nexthop, isWithdraw, pattr, medSetByTargetNeighbor) + ipv6Path.PathDefault = NewPathDefault(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 + } return ipv6Path } @@ -331,6 +270,6 @@ func (ipv6p *IPv6Path) String() string { str = str + fmt.Sprintf(" NLRI: %s, ", ipv6p.getPrefix().String()) str = str + fmt.Sprintf(" nexthop: %s, ", ipv6p.getNexthop().String()) str = str + fmt.Sprintf(" withdraw: %s, ", ipv6p.isWithdraw()) - str = str + fmt.Sprintf(" path attributes: %s, ", ipv6p.getPathAttributeMap()) + //str = str + fmt.Sprintf(" path attributes: %s, ", ipv6p.getPathAttributeMap()) return str } diff --git a/table/path_test.go b/table/path_test.go index cc2ca1a7..3cd32d89 100644 --- a/table/path_test.go +++ b/table/path_test.go @@ -13,16 +13,14 @@ func TestPathNewIPv4(t *testing.T) { peerP := PathCreatePeer() msgP := PathCreateMSG(peerP) pathP := PathCreatePath(msgP) - ipv4p := NewIPv4Path(pathP[0].getSource(), pathP[0].GetNlri(), pathP[0].getSourceVerNum(), pathP[0].getNexthop(), - true, pathP[0].getPathAttributeMap(), pathP[0].getMedSetByTargetNeighbor()) + ipv4p := NewIPv4Path(pathP[0].getSource(), pathP[0].GetNlri(), pathP[0].getSourceVerNum(), true, pathP[0].GetPathAttrs(), pathP[0].getMedSetByTargetNeighbor()) assert.NotNil(t, ipv4p) } func TestPathNewIPv6(t *testing.T) { peerP := PathCreatePeer() msgP := PathCreateMSG(peerP) pathP := PathCreatePath(msgP) - ipv6p := NewIPv6Path(pathP[0].getSource(), pathP[0].GetNlri(), pathP[0].getSourceVerNum(), pathP[0].getNexthop(), - true, pathP[0].getPathAttributeMap(), pathP[0].getMedSetByTargetNeighbor()) + ipv6p := NewIPv6Path(pathP[0].getSource(), pathP[0].GetNlri(), pathP[0].getSourceVerNum(), true, pathP[0].GetPathAttrs(), pathP[0].getMedSetByTargetNeighbor()) assert.NotNil(t, ipv6p) } @@ -178,19 +176,11 @@ func TestPathGetAttribute(t *testing.T) { msgP := PathCreateMSG(peerP) pathP := PathCreatePath(msgP) nh := "192.168.50.1" - pa := pathP[0].getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP) + _, pa := pathP[0].GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) r_nh := pa.(*bgp.PathAttributeNextHop).Value.String() assert.Equal(t, r_nh, nh) } -func TestPathClone(t *testing.T) { - peerP := PathCreatePeer() - msgP := PathCreateMSG(peerP) - pathP := PathCreatePath(msgP) - clPath := pathP[0].clone(false) - assert.Equal(t, clPath, pathP[0]) -} - func PathCreatePeer() []*PeerInfo { peerP1 := &PeerInfo{VersionNum: 4, AS: 65000} peerP2 := &PeerInfo{VersionNum: 4, AS: 65001} diff --git a/table/table_manager_test.go b/table/table_manager_test.go index cea108df..c0abcd84 100644 --- a/table/table_manager_test.go +++ b/table/table_manager_test.go @@ -84,23 +84,27 @@ func TestProcessBGPUpdate_0_select_onlypath_ipv4(t *testing.T) { // check PathAttribute pathAttributes := bgpMessage.Body.(*bgp.BGPUpdate).PathAttributes expectedOrigin := pathAttributes[0] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedNexthopAttr := pathAttributes[2] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + pathNexthop := attr.(*bgp.PathAttributeNextHop) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, 4, path.getPathAttributeMap().Len()) + assert.Equal(t, 4, len(path.GetPathAttrs())) // check destination expectedPrefix := "10.10.10.0" @@ -132,23 +136,27 @@ func TestProcessBGPUpdate_0_select_onlypath_ipv6(t *testing.T) { pathAttributes := bgpMessage.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, 4, path.getPathAttributeMap().Len()) + assert.Equal(t, 4, len(path.GetPathAttrs())) // check destination expectedPrefix := "2001:123:123:1::" @@ -215,23 +223,27 @@ func TestProcessBGPUpdate_1_select_high_localpref_ipv4(t *testing.T) { // check PathAttribute pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedOrigin := pathAttributes[0] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedNexthopAttr := pathAttributes[2] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + pathNexthop := attr.(*bgp.PathAttributeNextHop) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes2), path.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) // check destination expectedPrefix := "10.10.10.0" @@ -300,23 +312,27 @@ func TestProcessBGPUpdate_1_select_high_localpref_ipv6(t *testing.T) { pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, 5, path.getPathAttributeMap().Len()) + assert.Equal(t, 5, len(path.GetPathAttrs())) // check destination expectedPrefix := "2001:123:123:1::" @@ -383,23 +399,27 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv4(t *testing.T) { // check PathAttribute pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedOrigin := pathAttributes[0] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedNexthopAttr := pathAttributes[2] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + pathNexthop := attr.(*bgp.PathAttributeNextHop) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes2), path.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) // check destination expectedPrefix := "10.10.10.0" @@ -468,23 +488,27 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv6(t *testing.T) { pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, 5, path.getPathAttributeMap().Len()) + assert.Equal(t, 5, len(path.GetPathAttrs())) // check destination expectedPrefix := "2001:123:123:1::" @@ -524,23 +548,27 @@ func TestProcessBGPUpdate_3_select_aspath_ipv4(t *testing.T) { // check PathAttribute pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedOrigin := pathAttributes[0] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedNexthopAttr := pathAttributes[2] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + pathNexthop := attr.(*bgp.PathAttributeNextHop) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, 4, path.getPathAttributeMap().Len()) + assert.Equal(t, 4, len(path.GetPathAttrs())) // check destination expectedPrefix := "20.20.20.0" @@ -580,23 +608,27 @@ func TestProcessBGPUpdate_3_select_aspath_ipv6(t *testing.T) { pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, 4, path.getPathAttributeMap().Len()) + assert.Equal(t, 4, len(path.GetPathAttrs())) // check destination expectedPrefix := "2002:223:123:1::" @@ -663,23 +695,27 @@ func TestProcessBGPUpdate_4_select_low_origin_ipv4(t *testing.T) { // check PathAttribute pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedOrigin := pathAttributes[0] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedNexthopAttr := pathAttributes[2] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + pathNexthop := attr.(*bgp.PathAttributeNextHop) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes2), path.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) // check destination expectedPrefix := "10.10.10.0" @@ -748,23 +784,27 @@ func TestProcessBGPUpdate_4_select_low_origin_ipv6(t *testing.T) { pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, 5, path.getPathAttributeMap().Len()) + assert.Equal(t, 5, len(path.GetPathAttrs())) // check destination expectedPrefix := "2001:123:123:1::" @@ -831,23 +871,27 @@ func TestProcessBGPUpdate_5_select_low_med_ipv4(t *testing.T) { // check PathAttribute pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedOrigin := pathAttributes[0] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedNexthopAttr := pathAttributes[2] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + pathNexthop := attr.(*bgp.PathAttributeNextHop) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes2), path.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) // check destination expectedPrefix := "10.10.10.0" @@ -916,23 +960,27 @@ func TestProcessBGPUpdate_5_select_low_med_ipv6(t *testing.T) { pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, 5, path.getPathAttributeMap().Len()) + assert.Equal(t, 5, len(path.GetPathAttrs())) // check destination expectedPrefix := "2001:123:123:1::" @@ -1001,23 +1049,27 @@ func TestProcessBGPUpdate_6_select_ebgp_path_ipv4(t *testing.T) { // check PathAttribute pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedOrigin := pathAttributes[0] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedNexthopAttr := pathAttributes[2] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + pathNexthop := attr.(*bgp.PathAttributeNextHop) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes2), path.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) // check destination expectedPrefix := "10.10.10.0" @@ -1087,23 +1139,27 @@ func TestProcessBGPUpdate_6_select_ebgp_path_ipv6(t *testing.T) { pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, 5, path.getPathAttributeMap().Len()) + assert.Equal(t, 5, len(path.GetPathAttrs())) // check destination expectedPrefix := "2001:123:123:1::" @@ -1174,23 +1230,27 @@ func TestProcessBGPUpdate_7_select_low_routerid_path_ipv4(t *testing.T) { // check PathAttribute pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedOrigin := pathAttributes[0] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedNexthopAttr := pathAttributes[2] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + pathNexthop := attr.(*bgp.PathAttributeNextHop) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes2), path.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) // check destination expectedPrefix := "10.10.10.0" @@ -1260,23 +1320,27 @@ func TestProcessBGPUpdate_7_select_low_routerid_path_ipv6(t *testing.T) { pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, 5, path.getPathAttributeMap().Len()) + assert.Equal(t, 5, len(path.GetPathAttrs())) // check destination expectedPrefix := "2001:123:123:1::" @@ -1345,23 +1409,27 @@ func TestProcessBGPUpdate_8_withdraw_path_ipv4(t *testing.T) { checkPattr := func(expected *bgp.BGPMessage, actual Path) { pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes expectedOrigin := pathAttributes[0] - pathOrigin := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr := actual.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedNexthopAttr := pathAttributes[2] - pathNexthop := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + pathNexthop := attr.(*bgp.PathAttributeNextHop) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedMed := pathAttributes[3] - pathMed := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes), path.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs())) } checkPattr(bgpMessage2, path) // check destination @@ -1453,19 +1521,23 @@ func TestProcessBGPUpdate_8_mpunreach_path_ipv6(t *testing.T) { pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute @@ -1473,22 +1545,26 @@ func TestProcessBGPUpdate_8_mpunreach_path_ipv6(t *testing.T) { pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes), path.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs())) } checkPattr(bgpMessage2, path) @@ -1571,23 +1647,27 @@ func TestProcessBGPUpdate_bestpath_lost_ipv4(t *testing.T) { checkPattr := func(expected *bgp.BGPMessage, actual Path) { pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes expectedOrigin := pathAttributes[0] - pathOrigin := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr := actual.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedNexthopAttr := pathAttributes[2] - pathNexthop := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + pathNexthop := attr.(*bgp.PathAttributeNextHop) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedMed := pathAttributes[3] - pathMed := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes), path.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs())) } checkPattr(bgpMessage1, path) @@ -1648,22 +1728,26 @@ func TestProcessBGPUpdate_bestpath_lost_ipv6(t *testing.T) { pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := actual.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes), path.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs())) } checkPattr(bgpMessage1, path) @@ -1734,23 +1818,27 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv4(t *testing.T) { checkPattr := func(expected *bgp.BGPMessage, actual Path) { pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes expectedOrigin := pathAttributes[0] - pathOrigin := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr := actual.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedNexthopAttr := pathAttributes[2] - pathNexthop := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + pathNexthop := attr.(*bgp.PathAttributeNextHop) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedMed := pathAttributes[3] - pathMed := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes), path.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs())) } checkPattr(bgpMessage2, path) // check destination @@ -1819,19 +1907,23 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv6(t *testing.T) { pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := path.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := path.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := path.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := path.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute @@ -1839,22 +1931,26 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv6(t *testing.T) { pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes expectedNexthopAttr := pathAttributes[0] - pathNexthop := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := actual.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[1] - pathOrigin := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[2] - pathAspath := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[3] - pathMed := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes), path.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs())) } checkPattr(bgpMessage2, path) @@ -1893,23 +1989,27 @@ func TestProcessBGPUpdate_multiple_nlri_ipv4(t *testing.T) { checkPattr := func(expected *bgp.BGPMessage, actual Path) { pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes expectedOrigin := pathAttributes[0] - pathOrigin := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr := actual.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedNexthopAttr := pathAttributes[2] - pathNexthop := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_NEXT_HOP).(*bgp.PathAttributeNextHop) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) + pathNexthop := attr.(*bgp.PathAttributeNextHop) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedMed := pathAttributes[3] - pathMed := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) // check PathAttribute length - assert.Equal(t, len(pathAttributes), actual.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes), len(actual.GetPathAttrs())) } checkBestPathResult := func(pType, prefix, nexthop string, p Path, m *bgp.BGPMessage) { @@ -2020,27 +2120,32 @@ func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) { checkPattr := func(expected *bgp.BGPMessage, actual Path) { pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes pathNexthop := pathAttributes[4] - expectedNexthopAttr := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI).(*bgp.PathAttributeMpReachNLRI) + _, attr := actual.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + expectedNexthopAttr := attr.(*bgp.PathAttributeMpReachNLRI) assert.Equal(t, expectedNexthopAttr, pathNexthop) expectedOrigin := pathAttributes[0] - pathOrigin := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_ORIGIN).(*bgp.PathAttributeOrigin) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) + pathOrigin := attr.(*bgp.PathAttributeOrigin) assert.Equal(t, expectedOrigin, pathOrigin) expectedAsPath := pathAttributes[1] - pathAspath := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_AS_PATH).(*bgp.PathAttributeAsPath) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + pathAspath := attr.(*bgp.PathAttributeAsPath) assert.Equal(t, expectedAsPath, pathAspath) expectedMed := pathAttributes[2] - pathMed := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC).(*bgp.PathAttributeMultiExitDisc) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) + pathMed := attr.(*bgp.PathAttributeMultiExitDisc) assert.Equal(t, expectedMed, pathMed) expectedLocalpref := pathAttributes[3] - localpref := actual.getPathAttribute(bgp.BGP_ATTR_TYPE_LOCAL_PREF).(*bgp.PathAttributeLocalPref) + _, attr = actual.GetPathAttr(bgp.BGP_ATTR_TYPE_LOCAL_PREF) + localpref := attr.(*bgp.PathAttributeLocalPref) assert.Equal(t, expectedLocalpref, localpref) // check PathAttribute length - assert.Equal(t, len(pathAttributes), actual.getPathAttributeMap().Len()) + assert.Equal(t, len(pathAttributes), len(actual.GetPathAttrs())) } |