diff options
-rw-r--r-- | gobgp/cmd/common.go | 7 | ||||
-rw-r--r-- | gobgp/cmd/global.go | 2 | ||||
-rw-r--r-- | gobgp/lib/path.go | 2 | ||||
-rw-r--r-- | packet/bgp.go | 28 | ||||
-rw-r--r-- | packet/bgp_test.go | 8 | ||||
-rw-r--r-- | packet/validate_test.go | 4 | ||||
-rw-r--r-- | policy/policy.go | 4 | ||||
-rw-r--r-- | policy/policy_test.go | 187 | ||||
-rw-r--r-- | server/server.go | 4 | ||||
-rw-r--r-- | server/zclient.go | 2 | ||||
-rw-r--r-- | table/destination_test.go | 22 | ||||
-rw-r--r-- | table/message.go | 15 | ||||
-rw-r--r-- | table/message_test.go | 4 | ||||
-rw-r--r-- | table/path.go | 11 | ||||
-rw-r--r-- | table/path_test.go | 64 | ||||
-rw-r--r-- | table/table_manager.go | 14 | ||||
-rw-r--r-- | table/table_manager_test.go | 256 | ||||
-rw-r--r-- | table/table_test.go | 18 |
18 files changed, 253 insertions, 399 deletions
diff --git a/gobgp/cmd/common.go b/gobgp/cmd/common.go index 3e3f6fca..50b22fa9 100644 --- a/gobgp/cmd/common.go +++ b/gobgp/cmd/common.go @@ -159,9 +159,10 @@ type Path struct { func ApiStruct2Path(p *api.Path) (*Path, error) { var nlri bgp.AddrPrefixInterface - if len(p.Nlri) > 0 { - nlri = &bgp.NLRInfo{} - err := nlri.DecodeFromBytes(p.Nlri) + data := p.Nlri + if len(data) > 0 { + nlri = &bgp.IPAddrPrefix{} + err := nlri.DecodeFromBytes(data) if err != nil { return nil, err } diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go index d82bb1cf..d351148d 100644 --- a/gobgp/cmd/global.go +++ b/gobgp/cmd/global.go @@ -396,7 +396,7 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) { return nil, fmt.Errorf("invalid ipv4 prefix") } nexthop = "0.0.0.0" - nlri = bgp.NewNLRInfo(uint8(ones), ip.String()) + nlri = bgp.NewIPAddrPrefix(uint8(ones), ip.String()) } else { if ip.To16() == nil { return nil, fmt.Errorf("invalid ipv6 prefix") diff --git a/gobgp/lib/path.go b/gobgp/lib/path.go index f55bf96d..d749eb6a 100644 --- a/gobgp/lib/path.go +++ b/gobgp/lib/path.go @@ -73,7 +73,7 @@ func decode_path(p *C.path) *C.char { var nlri bgp.AddrPrefixInterface if p.nlri.len > 0 { buf = []byte(C.GoStringN(p.nlri.value, p.nlri.len)) - nlri = &bgp.NLRInfo{} + nlri = &bgp.IPAddrPrefix{} err := nlri.DecodeFromBytes(buf) if err != nil { return nil diff --git a/packet/bgp.go b/packet/bgp.go index 0e46ae5e..1b07ec33 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -743,10 +743,6 @@ func NewIPv6AddrPrefix(length uint8, prefix string) *IPv6AddrPrefix { } } -type WithdrawnRoute struct { - IPAddrPrefix -} - const ( BGP_RD_TWO_OCTET_AS = iota BGP_RD_IPV4_ADDRESS @@ -5279,22 +5275,12 @@ func GetPathAttribute(data []byte) (PathAttributeInterface, error) { return &PathAttributeUnknown{}, nil } -type NLRInfo struct { - IPAddrPrefix -} - -func NewNLRInfo(length uint8, prefix string) *NLRInfo { - return &NLRInfo{ - IPAddrPrefix: *NewIPAddrPrefix(length, prefix), - } -} - type BGPUpdate struct { WithdrawnRoutesLen uint16 - WithdrawnRoutes []WithdrawnRoute + WithdrawnRoutes []*IPAddrPrefix TotalPathAttributeLen uint16 PathAttributes []PathAttributeInterface - NLRI []NLRInfo + NLRI []*IPAddrPrefix } func (msg *BGPUpdate) DecodeFromBytes(data []byte) error { @@ -5316,9 +5302,9 @@ func (msg *BGPUpdate) DecodeFromBytes(data []byte) error { return NewMessageError(eCode, eSubCode, nil, "withdrawn route length exceeds message length") } - msg.WithdrawnRoutes = []WithdrawnRoute{} + msg.WithdrawnRoutes = make([]*IPAddrPrefix, 0, msg.WithdrawnRoutesLen) for routelen := msg.WithdrawnRoutesLen; routelen > 0; { - w := WithdrawnRoute{} + w := &IPAddrPrefix{} err := w.DecodeFromBytes(data) if err != nil { return err @@ -5362,9 +5348,9 @@ func (msg *BGPUpdate) DecodeFromBytes(data []byte) error { msg.PathAttributes = append(msg.PathAttributes, p) } - msg.NLRI = []NLRInfo{} + msg.NLRI = make([]*IPAddrPrefix, 0) for restlen := len(data); restlen > 0; { - n := NLRInfo{} + n := &IPAddrPrefix{} err := n.DecodeFromBytes(data) if err != nil { return err @@ -5414,7 +5400,7 @@ func (msg *BGPUpdate) Serialize() ([]byte, error) { return buf, nil } -func NewBGPUpdateMessage(withdrawnRoutes []WithdrawnRoute, pathattrs []PathAttributeInterface, nlri []NLRInfo) *BGPMessage { +func NewBGPUpdateMessage(withdrawnRoutes []*IPAddrPrefix, pathattrs []PathAttributeInterface, nlri []*IPAddrPrefix) *BGPMessage { return &BGPMessage{ Header: BGPHeader{Type: BGP_MSG_UPDATE}, Body: &BGPUpdate{0, withdrawnRoutes, 0, pathattrs, nlri}, diff --git a/packet/bgp_test.go b/packet/bgp_test.go index 74fcb510..20664ba0 100644 --- a/packet/bgp_test.go +++ b/packet/bgp_test.go @@ -37,9 +37,9 @@ func open() *BGPMessage { } func update() *BGPMessage { - w1 := WithdrawnRoute{*NewIPAddrPrefix(23, "121.1.3.2")} - w2 := WithdrawnRoute{*NewIPAddrPrefix(17, "100.33.3.0")} - w := []WithdrawnRoute{w1, w2} + w1 := NewIPAddrPrefix(23, "121.1.3.2") + w2 := NewIPAddrPrefix(17, "100.33.3.0") + w := []*IPAddrPrefix{w1, w2} aspath1 := []AsPathParamInterface{ NewAsPathParam(2, []uint16{1000}), @@ -142,7 +142,7 @@ func update() *BGPMessage { }, }, } - n := []NLRInfo{*NewNLRInfo(24, "13.2.3.1")} + n := []*IPAddrPrefix{NewIPAddrPrefix(24, "13.2.3.1")} return NewBGPUpdateMessage(w, p, n) } diff --git a/packet/validate_test.go b/packet/validate_test.go index 2f007c44..6309c74d 100644 --- a/packet/validate_test.go +++ b/packet/validate_test.go @@ -18,7 +18,7 @@ func bgpupdate() *BGPMessage { NewPathAttributeNextHop("192.168.1.1"), } - n := []NLRInfo{*NewNLRInfo(24, "10.10.10.0")} + n := []*IPAddrPrefix{NewIPAddrPrefix(24, "10.10.10.0")} return NewBGPUpdateMessage(nil, p, n) } @@ -35,7 +35,7 @@ func bgpupdateV6() *BGPMessage { NewPathAttributeAsPath(aspath), NewPathAttributeMpReachNLRI("1023::", mp_nlri), } - return NewBGPUpdateMessage(nil, p, []NLRInfo{}) + return NewBGPUpdateMessage(nil, p, nil) } func Test_Validate_CapV4(t *testing.T) { diff --git a/policy/policy.go b/policy/policy.go index 5d0c3b9a..eb3bad4b 100644 --- a/policy/policy.go +++ b/policy/policy.go @@ -1413,8 +1413,8 @@ func ipPrefixCalculate(path *table.Path, cPrefix Prefix) bool { switch rf { case bgp.RF_IPv4_UC: - pAddr = path.GetNlri().(*bgp.NLRInfo).IPAddrPrefix.Prefix - pMasklen = path.GetNlri().(*bgp.NLRInfo).IPAddrPrefix.Length + pAddr = path.GetNlri().(*bgp.IPAddrPrefix).Prefix + pMasklen = path.GetNlri().(*bgp.IPAddrPrefix).Length case bgp.RF_IPv6_UC: pAddr = path.GetNlri().(*bgp.IPv6AddrPrefix).Prefix pMasklen = path.GetNlri().(*bgp.IPv6AddrPrefix).Length diff --git a/policy/policy_test.go b/policy/policy_test.go index 069f2dad..b0406f47 100644 --- a/policy/policy_test.go +++ b/policy/policy_test.go @@ -45,9 +45,8 @@ func TestPrefixCalcurateNoRange(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // test pl1, _ := NewPrefix("10.10.0.0/24", "") @@ -70,9 +69,8 @@ func TestPrefixCalcurateAddress(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // test pl1, _ := NewPrefix("10.11.0.0/16", "21..24") @@ -92,9 +90,8 @@ func TestPrefixCalcurateLength(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // test pl1, _ := NewPrefix("10.10.64.0/24", "21..24") @@ -114,9 +111,8 @@ func TestPrefixCalcurateLengthRange(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // test pl1, _ := NewPrefix("10.10.0.0/16", "21..23") @@ -141,9 +137,7 @@ func TestPrefixCalcurateNoRangeIPv6(t *testing.T) { mpreach := bgp.NewPathAttributeMpReachNLRI("2001::192:168:50:1", mpnlri) med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{mpreach, origin, aspath, med} - nlri := []bgp.NLRInfo{} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nil) path := table.ProcessMessage(updateMsg, peer)[0] // test pl1, _ := NewPrefix("2001:123:123::/48", "") @@ -167,9 +161,7 @@ func TestPrefixCalcurateAddressIPv6(t *testing.T) { mpreach := bgp.NewPathAttributeMpReachNLRI("2001::192:168:50:1", mpnlri) med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{mpreach, origin, aspath, med} - nlri := []bgp.NLRInfo{} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nil) path := table.ProcessMessage(updateMsg, peer)[0] // test pl1, _ := NewPrefix("2001:123:128::/48", "64..80") @@ -190,9 +182,7 @@ func TestPrefixCalcurateLengthIPv6(t *testing.T) { mpreach := bgp.NewPathAttributeMpReachNLRI("2001::192:168:50:1", mpnlri) med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{mpreach, origin, aspath, med} - nlri := []bgp.NLRInfo{} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nil) path := table.ProcessMessage(updateMsg, peer)[0] // test pl1, _ := NewPrefix("2001:123:123:64::/64", "64..80") @@ -213,9 +203,7 @@ func TestPrefixCalcurateLengthRangeIPv6(t *testing.T) { mpreach := bgp.NewPathAttributeMpReachNLRI("2001::192:168:50:1", mpnlri) med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{mpreach, origin, aspath, med} - nlri := []bgp.NLRInfo{} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nil) path := table.ProcessMessage(updateMsg, peer)[0] // test pl1, _ := NewPrefix("2001:123:123::/48", "62..63") @@ -238,9 +226,8 @@ func TestPolicyNotMatch(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy @@ -271,9 +258,8 @@ func TestPolicyMatchAndReject(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") @@ -304,9 +290,8 @@ func TestPolicyMatchAndAccept(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") @@ -337,9 +322,8 @@ func TestPolicyRejectOnlyPrefixSet(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.1.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.1.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.1.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path1 := table.ProcessMessage(updateMsg, peer)[0] peer = &table.PeerInfo{AS: 65002, Address: net.ParseIP("10.0.2.2")} @@ -349,9 +333,8 @@ func TestPolicyRejectOnlyPrefixSet(t *testing.T) { nexthop = bgp.NewPathAttributeNextHop("10.0.2.2") med = bgp.NewPathAttributeMultiExitDisc(0) pathAttributes = []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri = []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.9.2.102")} - withdrawnRoutes = []bgp.WithdrawnRoute{} - updateMsg = bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri = []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.9.2.102")} + updateMsg = bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path2 := table.ProcessMessage(updateMsg, peer)[0] // create policy @@ -386,9 +369,8 @@ func TestPolicyRejectOnlyNeighborSet(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.1.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.1.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.1.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path1 := table.ProcessMessage(updateMsg, peer)[0] peer = &table.PeerInfo{AS: 65002, Address: net.ParseIP("10.0.2.2")} @@ -398,9 +380,8 @@ func TestPolicyRejectOnlyNeighborSet(t *testing.T) { nexthop = bgp.NewPathAttributeNextHop("10.0.2.2") med = bgp.NewPathAttributeMultiExitDisc(0) pathAttributes = []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri = []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.2.102")} - withdrawnRoutes = []bgp.WithdrawnRoute{} - updateMsg = bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri = []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.2.102")} + updateMsg = bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path2 := table.ProcessMessage(updateMsg, peer)[0] // create policy @@ -435,9 +416,8 @@ func TestPolicyDifferentRoutefamilyOfPathAndPolicy(t *testing.T) { nexthopIPv4 := bgp.NewPathAttributeNextHop("10.0.0.1") medIPv4 := bgp.NewPathAttributeMultiExitDisc(0) pathAttributesIPv4 := []bgp.PathAttributeInterface{originIPv4, aspathIPv4, nexthopIPv4, medIPv4} - nlriIPv4 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutesIPv4 := []bgp.WithdrawnRoute{} - updateMsgIPv4 := bgp.NewBGPUpdateMessage(withdrawnRoutesIPv4, pathAttributesIPv4, nlriIPv4) + nlriIPv4 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsgIPv4 := bgp.NewBGPUpdateMessage(nil, pathAttributesIPv4, nlriIPv4) pathIPv4 := table.ProcessMessage(updateMsgIPv4, peerIPv4)[0] // create path ipv6 peerIPv6 := &table.PeerInfo{AS: 65001, Address: net.ParseIP("2001::192:168:50:1")} @@ -448,9 +428,7 @@ func TestPolicyDifferentRoutefamilyOfPathAndPolicy(t *testing.T) { mpreachIPv6 := bgp.NewPathAttributeMpReachNLRI("2001::192:168:50:1", mpnlriIPv6) medIPv6 := bgp.NewPathAttributeMultiExitDisc(0) pathAttributesIPv6 := []bgp.PathAttributeInterface{mpreachIPv6, originIPv6, aspathIPv6, medIPv6} - nlriIPv6 := []bgp.NLRInfo{} - withdrawnRoutesIPv6 := []bgp.WithdrawnRoute{} - updateMsgIPv6 := bgp.NewBGPUpdateMessage(withdrawnRoutesIPv6, pathAttributesIPv6, nlriIPv6) + updateMsgIPv6 := bgp.NewBGPUpdateMessage(nil, pathAttributesIPv6, nil) pathIPv6 := table.ProcessMessage(updateMsgIPv6, peerIPv6)[0] // create policy psIPv4 := createPrefixSet("psIPv4", "10.10.0.0/16", "21..24") @@ -496,9 +474,8 @@ func TestAsPathLengthConditionEvaluate(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) table.UpdatePathAttrs4ByteAs(updateMsg.Body.(*bgp.BGPUpdate)) path := table.ProcessMessage(updateMsg, peer)[0] @@ -546,9 +523,8 @@ func TestAsPathLengthConditionWithOtherCondition(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) table.UpdatePathAttrs4ByteAs(updateMsg.Body.(*bgp.BGPUpdate)) path := table.ProcessMessage(updateMsg, peer)[0] @@ -595,9 +571,8 @@ func TestAsPathConditionEvaluate(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg1 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg1 := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) table.UpdatePathAttrs4ByteAs(updateMsg1.Body.(*bgp.BGPUpdate)) path1 := table.ProcessMessage(updateMsg1, peer)[0] @@ -606,7 +581,7 @@ func TestAsPathConditionEvaluate(t *testing.T) { } aspath2 := bgp.NewPathAttributeAsPath(aspathParam2) pathAttributes = []bgp.PathAttributeInterface{origin, aspath2, nexthop, med} - updateMsg2 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + updateMsg2 := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) table.UpdatePathAttrs4ByteAs(updateMsg2.Body.(*bgp.BGPUpdate)) path2 := table.ProcessMessage(updateMsg2, peer)[0] @@ -703,9 +678,8 @@ func TestMultipleAsPathConditionEvaluate(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg1 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg1 := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) table.UpdatePathAttrs4ByteAs(updateMsg1.Body.(*bgp.BGPUpdate)) path1 := table.ProcessMessage(updateMsg1, peer)[0] @@ -887,9 +861,8 @@ func TestAsPathConditionWithOtherCondition(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) table.UpdatePathAttrs4ByteAs(updateMsg.Body.(*bgp.BGPUpdate)) path := table.ProcessMessage(updateMsg, peer)[0] @@ -949,9 +922,8 @@ func TestCommunityConditionEvaluate(t *testing.T) { 0xFFFFFF03}) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, communities} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg1 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg1 := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) table.UpdatePathAttrs4ByteAs(updateMsg1.Body.(*bgp.BGPUpdate)) path1 := table.ProcessMessage(updateMsg1, peer)[0] @@ -1096,9 +1068,8 @@ func TestCommunityConditionEvaluateWithOtherCondition(t *testing.T) { 0xFFFFFF02, 0xFFFFFF03}) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, communities} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) table.UpdatePathAttrs4ByteAs(updateMsg.Body.(*bgp.BGPUpdate)) path := table.ProcessMessage(updateMsg, peer)[0] @@ -1174,9 +1145,8 @@ func TestPolicyMatchAndAddCommunities(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") @@ -1219,9 +1189,8 @@ func TestPolicyMatchAndReplaceCommunities(t *testing.T) { stringToCommunityValue("65001:200"), }) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, communities} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") @@ -1266,9 +1235,8 @@ func TestPolicyMatchAndRemoveCommunities(t *testing.T) { stringToCommunityValue(community2), }) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, communities} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") @@ -1310,9 +1278,8 @@ func TestPolicyMatchAndClearCommunities(t *testing.T) { stringToCommunityValue(community2), }) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, communities} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") @@ -1415,9 +1382,8 @@ func TestExtCommunityConditionEvaluate(t *testing.T) { extCommunities := bgp.NewPathAttributeExtendedCommunities(ec) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, extCommunities} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg1 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg1 := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) table.UpdatePathAttrs4ByteAs(updateMsg1.Body.(*bgp.BGPUpdate)) path1 := table.ProcessMessage(updateMsg1, peer)[0] @@ -1617,9 +1583,8 @@ func TestExtCommunityConditionEvaluateWithOtherCondition(t *testing.T) { extCommunities := bgp.NewPathAttributeExtendedCommunities(ec) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, extCommunities} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) table.UpdatePathAttrs4ByteAs(updateMsg.Body.(*bgp.BGPUpdate)) path := table.ProcessMessage(updateMsg, peer)[0] @@ -1691,9 +1656,8 @@ func TestPolicyMatchAndReplaceMed(t *testing.T) { med := bgp.NewPathAttributeMultiExitDisc(100) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") @@ -1735,9 +1699,8 @@ func TestPolicyMatchAndAddingMed(t *testing.T) { med := bgp.NewPathAttributeMultiExitDisc(100) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") @@ -1779,9 +1742,8 @@ func TestPolicyMatchAndAddingMedOverFlow(t *testing.T) { med := bgp.NewPathAttributeMultiExitDisc(1) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") @@ -1825,9 +1787,8 @@ func TestPolicyMatchAndSubtractMed(t *testing.T) { med := bgp.NewPathAttributeMultiExitDisc(100) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") @@ -1871,9 +1832,8 @@ func TestPolicyMatchAndSubtractMedUnderFlow(t *testing.T) { med := bgp.NewPathAttributeMultiExitDisc(100) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") @@ -1916,9 +1876,8 @@ func TestPolicyMatchWhenPathHaveNotMed(t *testing.T) { nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := table.ProcessMessage(updateMsg, peer)[0] // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") @@ -1960,9 +1919,8 @@ func TestPolicyAsPathPrepend(t *testing.T) { med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) body := updateMsg.Body.(*bgp.BGPUpdate) table.UpdatePathAttrs4ByteAs(body) @@ -2005,9 +1963,8 @@ func TestPolicyAsPathPrependLastAs(t *testing.T) { med := bgp.NewPathAttributeMultiExitDisc(0) pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.0.101")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) body := updateMsg.Body.(*bgp.BGPUpdate) table.UpdatePathAttrs4ByteAs(body) diff --git a/server/server.go b/server/server.go index 298505f5..2cb0d29e 100644 --- a/server/server.go +++ b/server/server.go @@ -956,7 +956,7 @@ func (server *BgpServer) handleModPathRequest(grpcReq *GrpcRequest) []*table.Pat path = arg.Path if len(path.Nlri) > 0 { - nlri = &bgp.NLRInfo{} + nlri = &bgp.IPAddrPrefix{} err := nlri.DecodeFromBytes(path.Nlri) if err != nil { result.ResponseErr = err @@ -1021,7 +1021,7 @@ func (server *BgpServer) handleModPathRequest(grpcReq *GrpcRequest) []*table.Pat switch rf { case bgp.RF_IPv4_UC: - n := nlri.(*bgp.NLRInfo) + n := nlri.(*bgp.IPAddrPrefix) nlri = bgp.NewLabeledVPNIPAddrPrefix(n.Length, n.Prefix.String(), *bgp.NewMPLSLabelStack(), vrf.Rd) case bgp.RF_IPv6_UC: n := nlri.(*bgp.IPv6AddrPrefix) diff --git a/server/zclient.go b/server/zclient.go index 7a1a2cb5..e1937a6f 100644 --- a/server/zclient.go +++ b/server/zclient.go @@ -115,7 +115,7 @@ func createPathFromIPRouteMessage(m *zebra.Message, peerInfo *table.PeerInfo) *t }).Debugf("create path from ip route message.") if isV4 { - nlri = bgp.NewNLRInfo(body.PrefixLength, body.Prefix.String()) + nlri = bgp.NewIPAddrPrefix(body.PrefixLength, body.Prefix.String()) nexthop := bgp.NewPathAttributeNextHop(body.Nexthops[0].String()) pattr = append(pattr, nexthop) } else { diff --git a/table/destination_test.go b/table/destination_test.go index f46851f9..abf1c652 100644 --- a/table/destination_test.go +++ b/table/destination_test.go @@ -51,14 +51,14 @@ func TestDestinationGetRouteFamily(t *testing.T) { } func TestDestinationSetNlri(t *testing.T) { dd := &Destination{} - nlri := bgp.NewNLRInfo(24, "13.2.3.1") + nlri := bgp.NewIPAddrPrefix(24, "13.2.3.1") dd.setNlri(nlri) r_nlri := dd.GetNlri() assert.Equal(t, r_nlri, nlri) } func TestDestinationGetNlri(t *testing.T) { dd := &Destination{} - nlri := bgp.NewNLRInfo(24, "10.110.123.1") + nlri := bgp.NewIPAddrPrefix(24, "10.110.123.1") dd.setNlri(nlri) r_nlri := dd.GetNlri() assert.Equal(t, r_nlri, nlri) @@ -124,7 +124,7 @@ func DestCreatePath(peerD []*PeerInfo) []*Path { nlriList := updateMsgD.NLRI pathAttributes := updateMsgD.PathAttributes nlri_info := nlriList[0] - pathD[i] = NewPath(peerD[i], &nlri_info, false, pathAttributes, false, time.Now(), false) + pathD[i] = NewPath(peerD[i], nlri_info, false, pathAttributes, false, time.Now(), false) } return pathD } @@ -144,9 +144,8 @@ func updateMsgD1() *bgp.BGPMessage { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) UpdatePathAttrs4ByteAs(updateMsg.Body.(*bgp.BGPUpdate)) return updateMsg } @@ -166,9 +165,8 @@ func updateMsgD2() *bgp.BGPMessage { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "20.20.20.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "20.20.20.0")} + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) UpdatePathAttrs4ByteAs(updateMsg.Body.(*bgp.BGPUpdate)) return updateMsg } @@ -186,9 +184,9 @@ func updateMsgD3() *bgp.BGPMessage { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "30.30.30.0")} - w1 := bgp.WithdrawnRoute{*bgp.NewIPAddrPrefix(23, "40.40.40.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{w1} + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "30.30.30.0")} + w1 := bgp.NewIPAddrPrefix(23, "40.40.40.0") + withdrawnRoutes := []*bgp.IPAddrPrefix{w1} updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) UpdatePathAttrs4ByteAs(updateMsg.Body.(*bgp.BGPUpdate)) return updateMsg diff --git a/table/message.go b/table/message.go index 0066fc36..3ec0ef62 100644 --- a/table/message.go +++ b/table/message.go @@ -132,23 +132,22 @@ func createUpdateMsgFromPath(path *Path, msg *bgp.BGPMessage) *bgp.BGPMessage { rf := path.GetRouteFamily() if rf == bgp.RF_IPv4_UC { + nlri := path.GetNlri().(*bgp.IPAddrPrefix) if path.IsWithdraw { - draw := path.GetNlri().(*bgp.WithdrawnRoute) if msg != nil { u := msg.Body.(*bgp.BGPUpdate) - u.WithdrawnRoutes = append(u.WithdrawnRoutes, *draw) + u.WithdrawnRoutes = append(u.WithdrawnRoutes, nlri) return nil } else { - return bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{*draw}, []bgp.PathAttributeInterface{}, []bgp.NLRInfo{}) + return bgp.NewBGPUpdateMessage([]*bgp.IPAddrPrefix{nlri}, nil, nil) } } else { - nlri := path.GetNlri().(*bgp.NLRInfo) if msg != nil { u := msg.Body.(*bgp.BGPUpdate) - u.NLRI = append(u.NLRI, *nlri) + u.NLRI = append(u.NLRI, nlri) } else { pathAttrs := path.GetPathAttrs() - return bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttrs, []bgp.NLRInfo{*nlri}) + return bgp.NewBGPUpdateMessage(nil, pathAttrs, []*bgp.IPAddrPrefix{nlri}) } } } else { @@ -163,7 +162,7 @@ func createUpdateMsgFromPath(path *Path, msg *bgp.BGPMessage) *bgp.BGPMessage { idx, attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) reach := attr.(*bgp.PathAttributeMpReachNLRI) clonedAttrs[idx] = bgp.NewPathAttributeMpUnreachNLRI(reach.Value) - return bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, clonedAttrs, []bgp.NLRInfo{}) + return bgp.NewBGPUpdateMessage(nil, clonedAttrs, nil) } } else { if msg != nil { @@ -177,7 +176,7 @@ func createUpdateMsgFromPath(path *Path, msg *bgp.BGPMessage) *bgp.BGPMessage { // might merge path to this message in // the future so let's clone anyway. clonedAttrs := cloneAttrSlice(path.GetPathAttrs()) - return bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, clonedAttrs, []bgp.NLRInfo{}) + return bgp.NewBGPUpdateMessage(nil, clonedAttrs, nil) } } } diff --git a/table/message_test.go b/table/message_test.go index d72fa833..67a1da87 100644 --- a/table/message_test.go +++ b/table/message_test.go @@ -36,8 +36,8 @@ func updateMsg1(as []uint16) *bgp.BGPMessage { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - return bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + return bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) } func TestAsPathAsTrans(t *testing.T) { diff --git a/table/path.go b/table/path.go index eba3340a..386d39c3 100644 --- a/table/path.go +++ b/table/path.go @@ -207,21 +207,12 @@ func (path *Path) MarshalJSON() ([]byte, error) { // create new PathAttributes func (path *Path) Clone(isWithdraw bool) *Path { - nlri := path.nlri - if path.GetRouteFamily() == bgp.RF_IPv4_UC && isWithdraw { - if path.IsWithdraw { - nlri = path.nlri - } else { - nlri = &bgp.WithdrawnRoute{path.nlri.(*bgp.NLRInfo).IPAddrPrefix} - } - } - newPathAttrs := make([]bgp.PathAttributeInterface, len(path.pathAttrs)) for i, v := range path.pathAttrs { newPathAttrs[i] = v } - p := NewPath(path.source, nlri, isWithdraw, newPathAttrs, false, path.timestamp, path.NoImplicitWithdraw) + p := NewPath(path.source, path.nlri, isWithdraw, newPathAttrs, false, path.timestamp, path.NoImplicitWithdraw) p.Validation = path.Validation return p } diff --git a/table/path_test.go b/table/path_test.go index 7fca310f..1f2311f5 100644 --- a/table/path_test.go +++ b/table/path_test.go @@ -41,7 +41,7 @@ func TestPathGetSource(t *testing.T) { } func TestPathGetNlri(t *testing.T) { - nlri := bgp.NewNLRInfo(24, "13.2.3.2") + nlri := bgp.NewIPAddrPrefix(24, "13.2.3.2") pd := &Path{ nlri: nlri, } @@ -72,7 +72,7 @@ func TestPathCreatePath(t *testing.T) { nlriList := updateMsgP.NLRI pathAttributes := updateMsgP.PathAttributes nlri_info := nlriList[0] - path := NewPath(peerP[0], &nlri_info, false, pathAttributes, false, time.Now(), false) + path := NewPath(peerP[0], nlri_info, false, pathAttributes, false, time.Now(), false) assert.NotNil(t, path) } @@ -112,13 +112,12 @@ func TestASPathLen(t *testing.T) { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - bgpmsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) update := bgpmsg.Body.(*bgp.BGPUpdate) UpdatePathAttrs4ByteAs(update) peer := PathCreatePeer() - p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) + p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) assert.Equal(10, p.GetAsPathLen()) } @@ -139,13 +138,12 @@ func TestPathPrependAsnToExistingSeqAttr(t *testing.T) { nexthop, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - bgpmsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) update := bgpmsg.Body.(*bgp.BGPUpdate) UpdatePathAttrs4ByteAs(update) peer := PathCreatePeer() - p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) + p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) p.PrependAsn(65000, 1) assert.Equal([]uint32{65000, 65001, 65002, 65003, 65004, 65005}, p.GetAsSeqList()) @@ -162,13 +160,12 @@ func TestPathPrependAsnToNewAsPathAttr(t *testing.T) { nexthop, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - bgpmsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) update := bgpmsg.Body.(*bgp.BGPUpdate) UpdatePathAttrs4ByteAs(update) peer := PathCreatePeer() - p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) + p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) asn := uint32(65000) p.PrependAsn(asn, 1) @@ -191,13 +188,12 @@ func TestPathPrependAsnToNewAsPathSeq(t *testing.T) { nexthop, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - bgpmsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) update := bgpmsg.Body.(*bgp.BGPUpdate) UpdatePathAttrs4ByteAs(update) peer := PathCreatePeer() - p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) + p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) asn := uint32(65000) p.PrependAsn(asn, 1) @@ -222,13 +218,12 @@ func TestPathPrependAsnToEmptyAsPathAttr(t *testing.T) { nexthop, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - bgpmsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) update := bgpmsg.Body.(*bgp.BGPUpdate) UpdatePathAttrs4ByteAs(update) peer := PathCreatePeer() - p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) + p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) asn := uint32(65000) p.PrependAsn(asn, 1) @@ -259,13 +254,12 @@ func TestPathPrependAsnToFullPathAttr(t *testing.T) { nexthop, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - bgpmsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) update := bgpmsg.Body.(*bgp.BGPUpdate) UpdatePathAttrs4ByteAs(update) peer := PathCreatePeer() - p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) + p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) expected := []uint32{65000, 65000} for _, v := range asns { @@ -294,7 +288,7 @@ func PathCreatePath(peerP []*PeerInfo) []*Path { nlriList := updateMsgP.NLRI pathAttributes := updateMsgP.PathAttributes nlri_info := nlriList[0] - pathP[i] = NewPath(peerP[i], &nlri_info, false, pathAttributes, false, time.Now(), false) + pathP[i] = NewPath(peerP[i], nlri_info, false, pathAttributes, false, time.Now(), false) } return pathP } @@ -314,9 +308,8 @@ func updateMsgP1() *bgp.BGPMessage { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + return bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) } func updateMsgP2() *bgp.BGPMessage { @@ -334,9 +327,8 @@ func updateMsgP2() *bgp.BGPMessage { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "20.20.20.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "20.20.20.0")} + return bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) } func updateMsgP3() *bgp.BGPMessage { origin := bgp.NewPathAttributeOrigin(0) @@ -352,8 +344,8 @@ func updateMsgP3() *bgp.BGPMessage { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "30.30.30.0")} - w1 := bgp.WithdrawnRoute{*bgp.NewIPAddrPrefix(23, "40.40.40.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{w1} + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "30.30.30.0")} + w1 := bgp.NewIPAddrPrefix(23, "40.40.40.0") + withdrawnRoutes := []*bgp.IPAddrPrefix{w1} return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) } diff --git a/table/table_manager.go b/table/table_manager.go index 75b68b03..4477182b 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -29,11 +29,8 @@ func nlri2Path(m *bgp.BGPMessage, p *PeerInfo, now time.Time) []*Path { updateMsg := m.Body.(*bgp.BGPUpdate) pathAttributes := updateMsg.PathAttributes pathList := make([]*Path, 0) - for _, nlri_info := range updateMsg.NLRI { - // define local variable to pass nlri's address to CreatePath - var nlri bgp.NLRInfo = nlri_info - // create Path object - path := NewPath(p, &nlri, false, pathAttributes, false, now, false) + for _, nlri := range updateMsg.NLRI { + path := NewPath(p, nlri, false, pathAttributes, false, now, false) pathList = append(pathList, path) } return pathList @@ -43,11 +40,8 @@ func withdraw2Path(m *bgp.BGPMessage, p *PeerInfo, now time.Time) []*Path { updateMsg := m.Body.(*bgp.BGPUpdate) pathAttributes := updateMsg.PathAttributes pathList := make([]*Path, 0) - for _, nlriWithdraw := range updateMsg.WithdrawnRoutes { - // define local variable to pass nlri's address to CreatePath - var w bgp.WithdrawnRoute = nlriWithdraw - // create withdrawn Path object - path := NewPath(p, &w, true, pathAttributes, false, now, false) + for _, nlri := range updateMsg.WithdrawnRoutes { + path := NewPath(p, nlri, true, pathAttributes, false, now, false) pathList = append(pathList, path) } return pathList diff --git a/table/table_manager_test.go b/table/table_manager_test.go index 08791867..404ab553 100644 --- a/table/table_manager_test.go +++ b/table/table_manager_test.go @@ -183,9 +183,8 @@ func TestProcessBGPUpdate_1_select_high_localpref_ipv4(t *testing.T) { pathAttributes1 := []bgp.PathAttributeInterface{ origin1, aspath1, nexthop1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) // high localpref message origin2 := bgp.NewPathAttributeOrigin(0) @@ -197,9 +196,8 @@ func TestProcessBGPUpdate_1_select_high_localpref_ipv4(t *testing.T) { pathAttributes2 := []bgp.PathAttributeInterface{ origin2, aspath2, nexthop2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -267,9 +265,7 @@ func TestProcessBGPUpdate_1_select_high_localpref_ipv6(t *testing.T) { mp_reach1, origin1, aspath1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) origin2 := bgp.NewPathAttributeOrigin(0) aspath2 := createAsPathAttribute([]uint32{65100, 65000}) @@ -282,9 +278,7 @@ func TestProcessBGPUpdate_1_select_high_localpref_ipv6(t *testing.T) { mp_reach2, origin2, aspath2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -353,9 +347,8 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv4(t *testing.T) { pathAttributes1 := []bgp.PathAttributeInterface{ origin1, aspath1, nexthop1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) // high localpref message origin2 := bgp.NewPathAttributeOrigin(0) @@ -367,9 +360,8 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv4(t *testing.T) { pathAttributes2 := []bgp.PathAttributeInterface{ origin2, aspath2, nexthop2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -439,9 +431,7 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv6(t *testing.T) { mp_reach1, origin1, aspath1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) origin2 := bgp.NewPathAttributeOrigin(0) aspath2 := createAsPathAttribute([]uint32{}) @@ -454,9 +444,7 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv6(t *testing.T) { mp_reach2, origin2, aspath2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -642,9 +630,8 @@ func TestProcessBGPUpdate_4_select_low_origin_ipv4(t *testing.T) { pathAttributes1 := []bgp.PathAttributeInterface{ origin1, aspath1, nexthop1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) // high origin message origin2 := bgp.NewPathAttributeOrigin(0) @@ -656,9 +643,8 @@ func TestProcessBGPUpdate_4_select_low_origin_ipv4(t *testing.T) { pathAttributes2 := []bgp.PathAttributeInterface{ origin2, aspath2, nexthop2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -726,9 +712,7 @@ func TestProcessBGPUpdate_4_select_low_origin_ipv6(t *testing.T) { mp_reach1, origin1, aspath1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) origin2 := bgp.NewPathAttributeOrigin(0) aspath2 := createAsPathAttribute([]uint32{65100, 65000}) @@ -741,9 +725,7 @@ func TestProcessBGPUpdate_4_select_low_origin_ipv6(t *testing.T) { mp_reach2, origin2, aspath2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -812,9 +794,8 @@ func TestProcessBGPUpdate_5_select_low_med_ipv4(t *testing.T) { pathAttributes1 := []bgp.PathAttributeInterface{ origin1, aspath1, nexthop1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) // high origin message origin2 := bgp.NewPathAttributeOrigin(0) @@ -826,9 +807,8 @@ func TestProcessBGPUpdate_5_select_low_med_ipv4(t *testing.T) { pathAttributes2 := []bgp.PathAttributeInterface{ origin2, aspath2, nexthop2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -896,9 +876,7 @@ func TestProcessBGPUpdate_5_select_low_med_ipv6(t *testing.T) { mp_reach1, origin1, aspath1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) origin2 := bgp.NewPathAttributeOrigin(0) aspath2 := createAsPathAttribute([]uint32{65100, 65000}) @@ -911,9 +889,7 @@ func TestProcessBGPUpdate_5_select_low_med_ipv6(t *testing.T) { mp_reach2, origin2, aspath2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -983,9 +959,8 @@ func TestProcessBGPUpdate_6_select_ebgp_path_ipv4(t *testing.T) { pathAttributes1 := []bgp.PathAttributeInterface{ origin1, aspath1, nexthop1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) // high origin message origin2 := bgp.NewPathAttributeOrigin(0) @@ -997,9 +972,8 @@ func TestProcessBGPUpdate_6_select_ebgp_path_ipv4(t *testing.T) { pathAttributes2 := []bgp.PathAttributeInterface{ origin2, aspath2, nexthop2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -1067,9 +1041,7 @@ func TestProcessBGPUpdate_6_select_ebgp_path_ipv6(t *testing.T) { mp_reach1, origin1, aspath1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) origin2 := bgp.NewPathAttributeOrigin(0) aspath2 := createAsPathAttribute([]uint32{65100, 65200}) @@ -1082,9 +1054,7 @@ func TestProcessBGPUpdate_6_select_ebgp_path_ipv6(t *testing.T) { mp_reach2, origin2, aspath2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -1156,9 +1126,8 @@ func TestProcessBGPUpdate_7_select_low_routerid_path_ipv4(t *testing.T) { pathAttributes1 := []bgp.PathAttributeInterface{ origin1, aspath1, nexthop1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) // high origin message origin2 := bgp.NewPathAttributeOrigin(0) @@ -1170,9 +1139,8 @@ func TestProcessBGPUpdate_7_select_low_routerid_path_ipv4(t *testing.T) { pathAttributes2 := []bgp.PathAttributeInterface{ origin2, aspath2, nexthop2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -1240,9 +1208,7 @@ func TestProcessBGPUpdate_7_select_low_routerid_path_ipv6(t *testing.T) { mp_reach1, origin1, aspath1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) origin2 := bgp.NewPathAttributeOrigin(0) aspath2 := createAsPathAttribute([]uint32{65100, 65200}) @@ -1255,9 +1221,7 @@ func TestProcessBGPUpdate_7_select_low_routerid_path_ipv6(t *testing.T) { mp_reach2, origin2, aspath2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -1327,9 +1291,8 @@ func TestProcessBGPUpdate_8_withdraw_path_ipv4(t *testing.T) { pathAttributes1 := []bgp.PathAttributeInterface{ origin1, aspath1, nexthop1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) // path 2 origin2 := bgp.NewPathAttributeOrigin(0) @@ -1341,9 +1304,8 @@ func TestProcessBGPUpdate_8_withdraw_path_ipv4(t *testing.T) { pathAttributes2 := []bgp.PathAttributeInterface{ origin2, aspath2, nexthop2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -1396,9 +1358,9 @@ func TestProcessBGPUpdate_8_withdraw_path_ipv4(t *testing.T) { assert.Equal(t, expectedNexthop, path.GetNexthop().String()) //withdraw path - w1 := bgp.WithdrawnRoute{*bgp.NewIPAddrPrefix(24, "10.10.10.0")} - w := []bgp.WithdrawnRoute{w1} - bgpMessage3 := bgp.NewBGPUpdateMessage(w, []bgp.PathAttributeInterface{}, []bgp.NLRInfo{}) + w1 := bgp.NewIPAddrPrefix(24, "10.10.10.0") + w := []*bgp.IPAddrPrefix{w1} + bgpMessage3 := bgp.NewBGPUpdateMessage(w, nil, nil) pList, err = tm.ProcessUpdate(peer2, bgpMessage3) assert.Equal(t, 1, len(pList)) @@ -1434,9 +1396,7 @@ func TestProcessBGPUpdate_8_mpunreach_path_ipv6(t *testing.T) { mp_reach1, origin1, aspath1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) origin2 := bgp.NewPathAttributeOrigin(0) aspath2 := createAsPathAttribute([]uint32{65100, 65000}) @@ -1449,9 +1409,7 @@ func TestProcessBGPUpdate_8_mpunreach_path_ipv6(t *testing.T) { mp_reach2, origin2, aspath2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -1530,8 +1488,7 @@ func TestProcessBGPUpdate_8_mpunreach_path_ipv6(t *testing.T) { //mpunreach path mp_unreach := createMpUNReach("2001:123:123:1::", 64) - bgpMessage3 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, - []bgp.PathAttributeInterface{mp_unreach}, []bgp.NLRInfo{}) + bgpMessage3 := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{mp_unreach}, nil) pList, err = tm.ProcessUpdate(peer2, bgpMessage3) assert.Equal(t, 1, len(pList)) @@ -1568,13 +1525,13 @@ func TestProcessBGPUpdate_bestpath_lost_ipv4(t *testing.T) { pathAttributes1 := []bgp.PathAttributeInterface{ origin1, aspath1, nexthop1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - bgpMessage1 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes1, nlri1) + nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) // path 1 withdraw - w1 := bgp.WithdrawnRoute{*bgp.NewIPAddrPrefix(24, "10.10.10.0")} - w := []bgp.WithdrawnRoute{w1} - bgpMessage1_w := bgp.NewBGPUpdateMessage(w, []bgp.PathAttributeInterface{}, []bgp.NLRInfo{}) + w1 := bgp.NewIPAddrPrefix(24, "10.10.10.0") + w := []*bgp.IPAddrPrefix{w1} + bgpMessage1_w := bgp.NewBGPUpdateMessage(w, nil, nil) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -1640,9 +1597,7 @@ func TestProcessBGPUpdate_bestpath_lost_ipv6(t *testing.T) { mp_reach1, origin1, aspath1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -1652,8 +1607,7 @@ func TestProcessBGPUpdate_bestpath_lost_ipv6(t *testing.T) { // path1 mpunreach mp_unreach := createMpUNReach("2001:123:123:1::", 64) - bgpMessage1_w := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, - []bgp.PathAttributeInterface{mp_unreach}, []bgp.NLRInfo{}) + bgpMessage1_w := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{mp_unreach}, nil) pList, err = tm.ProcessUpdate(peer1, bgpMessage1_w) assert.Equal(t, 1, len(pList)) @@ -1715,9 +1669,8 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv4(t *testing.T) { pathAttributes1 := []bgp.PathAttributeInterface{ origin1, aspath1, nexthop1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) // path 1 from same peer but short AS_PATH origin2 := bgp.NewPathAttributeOrigin(0) @@ -1729,9 +1682,8 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv4(t *testing.T) { pathAttributes2 := []bgp.PathAttributeInterface{ origin2, aspath2, nexthop2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -1800,9 +1752,7 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv6(t *testing.T) { mp_reach1, origin1, aspath1, med1, localpref1, } - nlri1 := []bgp.NLRInfo{} - withdrawnRoutes1 := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) origin2 := bgp.NewPathAttributeOrigin(0) aspath2 := createAsPathAttribute([]uint32{65000, 65100}) @@ -1815,9 +1765,7 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv6(t *testing.T) { mp_reach2, origin2, aspath2, med2, localpref2, } - nlri2 := []bgp.NLRInfo{} - withdrawnRoutes2 := []bgp.WithdrawnRoute{} - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -1952,38 +1900,38 @@ func TestProcessBGPUpdate_multiple_nlri_ipv4(t *testing.T) { // path1 pathAttributes1 := createPathAttr([]uint32{65000, 65100, 65200}, "192.168.50.1") - nlri1 := []bgp.NLRInfo{ - *bgp.NewNLRInfo(24, "10.10.10.0"), - *bgp.NewNLRInfo(24, "20.20.20.0"), - *bgp.NewNLRInfo(24, "30.30.30.0"), - *bgp.NewNLRInfo(24, "40.40.40.0"), - *bgp.NewNLRInfo(24, "50.50.50.0")} - bgpMessage1 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes1, nlri1) + nlri1 := []*bgp.IPAddrPrefix{ + bgp.NewIPAddrPrefix(24, "10.10.10.0"), + bgp.NewIPAddrPrefix(24, "20.20.20.0"), + bgp.NewIPAddrPrefix(24, "30.30.30.0"), + bgp.NewIPAddrPrefix(24, "40.40.40.0"), + bgp.NewIPAddrPrefix(24, "50.50.50.0")} + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) // path2 pathAttributes2 := createPathAttr([]uint32{65000, 65100, 65300}, "192.168.50.1") - nlri2 := []bgp.NLRInfo{ - *bgp.NewNLRInfo(24, "11.11.11.0"), - *bgp.NewNLRInfo(24, "22.22.22.0"), - *bgp.NewNLRInfo(24, "33.33.33.0"), - *bgp.NewNLRInfo(24, "44.44.44.0"), - *bgp.NewNLRInfo(24, "55.55.55.0")} - bgpMessage2 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes2, nlri2) + nlri2 := []*bgp.IPAddrPrefix{ + bgp.NewIPAddrPrefix(24, "11.11.11.0"), + bgp.NewIPAddrPrefix(24, "22.22.22.0"), + bgp.NewIPAddrPrefix(24, "33.33.33.0"), + bgp.NewIPAddrPrefix(24, "44.44.44.0"), + bgp.NewIPAddrPrefix(24, "55.55.55.0")} + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) // path3 pathAttributes3 := createPathAttr([]uint32{65000, 65100, 65400}, "192.168.50.1") - nlri3 := []bgp.NLRInfo{ - *bgp.NewNLRInfo(24, "77.77.77.0"), - *bgp.NewNLRInfo(24, "88.88.88.0"), + nlri3 := []*bgp.IPAddrPrefix{ + bgp.NewIPAddrPrefix(24, "77.77.77.0"), + bgp.NewIPAddrPrefix(24, "88.88.88.0"), } - bgpMessage3 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes3, nlri3) + bgpMessage3 := bgp.NewBGPUpdateMessage(nil, pathAttributes3, nlri3) // path4 pathAttributes4 := createPathAttr([]uint32{65000, 65100, 65500}, "192.168.50.1") - nlri4 := []bgp.NLRInfo{ - *bgp.NewNLRInfo(24, "99.99.99.0"), + nlri4 := []*bgp.IPAddrPrefix{ + bgp.NewIPAddrPrefix(24, "99.99.99.0"), } - bgpMessage4 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes4, nlri4) + bgpMessage4 := bgp.NewBGPUpdateMessage(nil, pathAttributes4, nlri4) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -2100,7 +2048,7 @@ func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) { bgp.NewIPv6AddrPrefix(64, "2001:123:1250:11::"), }) pathAttributes1 = append(pathAttributes1, mpreach1) - bgpMessage1 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes1, []bgp.NLRInfo{}) + bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) // path2 pathAttributes2 := createPathAttr([]uint32{65000, 65100, 65300}) @@ -2112,7 +2060,7 @@ func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) { bgp.NewIPv6AddrPrefix(64, "2001:123:1255:11::"), }) pathAttributes2 = append(pathAttributes2, mpreach2) - bgpMessage2 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes2, []bgp.NLRInfo{}) + bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) // path3 pathAttributes3 := createPathAttr([]uint32{65000, 65100, 65400}) @@ -2121,7 +2069,7 @@ func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) { bgp.NewIPv6AddrPrefix(64, "2001:123:1288:11::"), }) pathAttributes3 = append(pathAttributes3, mpreach3) - bgpMessage3 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes3, []bgp.NLRInfo{}) + bgpMessage3 := bgp.NewBGPUpdateMessage(nil, pathAttributes3, nil) // path4 pathAttributes4 := createPathAttr([]uint32{65000, 65100, 65500}) @@ -2129,7 +2077,7 @@ func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) { bgp.NewIPv6AddrPrefix(64, "2001:123:1299:11::"), }) pathAttributes4 = append(pathAttributes4, mpreach4) - bgpMessage4 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes4, []bgp.NLRInfo{}) + bgpMessage4 := bgp.NewBGPUpdateMessage(nil, pathAttributes4, nil) peer1 := peerR1() pList, err := tm.ProcessUpdate(peer1, bgpMessage1) @@ -2190,18 +2138,17 @@ func TestProcessBGPUpdate_Timestamp(t *testing.T) { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} adjRib := NewAdjRib([]bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC}) - m1 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + m1 := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) peer := peerR1() pList1 := ProcessMessage(m1, peer) path1 := pList1[0] t1 := path1.timestamp adjRib.UpdateIn(pList1) - m2 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + m2 := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) pList2 := ProcessMessage(m2, peer) //path2 := pList2[0].(*IPv4Path) //t2 = path2.timestamp @@ -2219,7 +2166,7 @@ func TestProcessBGPUpdate_Timestamp(t *testing.T) { med2, } - m3 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes2, nlri) + m3 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri) pList3 := ProcessMessage(m3, peer) t3 := pList3[0].GetTimestamp() adjRib.UpdateIn(pList3) @@ -2244,10 +2191,9 @@ func update_fromR1() *bgp.BGPMessage { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} - return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + return bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) } func update_fromR1_ipv6() *bgp.BGPMessage { @@ -2266,9 +2212,7 @@ func update_fromR1_ipv6() *bgp.BGPMessage { aspath, med, } - nlri := []bgp.NLRInfo{} - withdrawnRoutes := []bgp.WithdrawnRoute{} - return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + return bgp.NewBGPUpdateMessage(nil, pathAttributes, nil) } func update_fromR2() *bgp.BGPMessage { @@ -2286,9 +2230,8 @@ func update_fromR2() *bgp.BGPMessage { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "20.20.20.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "20.20.20.0")} + return bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) } func update_fromR2_ipv6() *bgp.BGPMessage { @@ -2305,9 +2248,7 @@ func update_fromR2_ipv6() *bgp.BGPMessage { aspath, med, } - nlri := []bgp.NLRInfo{} - withdrawnRoutes := []bgp.WithdrawnRoute{} - return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + return bgp.NewBGPUpdateMessage(nil, pathAttributes, nil) } func createAsPathAttribute(ases []uint32) *bgp.PathAttributeAsPath { @@ -2340,9 +2281,8 @@ func update_fromR2viaR1() *bgp.BGPMessage { nexthop, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "20.20.20.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "20.20.20.0")} + return bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) } func update_fromR2viaR1_ipv6() *bgp.BGPMessage { @@ -2359,8 +2299,6 @@ func update_fromR2viaR1_ipv6() *bgp.BGPMessage { aspath, med, } - nlri := []bgp.NLRInfo{} - withdrawnRoutes := []bgp.WithdrawnRoute{} - return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + return bgp.NewBGPUpdateMessage(nil, pathAttributes, nil) } diff --git a/table/table_test.go b/table/table_test.go index 0ece7568..f957cef1 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -107,7 +107,7 @@ func TableCreatePath(peerT []*PeerInfo) []*Path { nlriList := updateMsgT.NLRI pathAttributes := updateMsgT.PathAttributes nlri_info := nlriList[0] - pathT[i] = NewPath(peerT[i], &nlri_info, false, pathAttributes, false, time.Now(), false) + pathT[i] = NewPath(peerT[i], nlri_info, false, pathAttributes, false, time.Now(), false) } return pathT } @@ -127,9 +127,8 @@ func updateMsgT1() *bgp.BGPMessage { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} + return bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) } func updateMsgT2() *bgp.BGPMessage { @@ -147,9 +146,8 @@ func updateMsgT2() *bgp.BGPMessage { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "20.20.20.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{} - return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "20.20.20.0")} + return bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) } func updateMsgT3() *bgp.BGPMessage { origin := bgp.NewPathAttributeOrigin(0) @@ -165,8 +163,8 @@ func updateMsgT3() *bgp.BGPMessage { med, } - nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "30.30.30.0")} - w1 := bgp.WithdrawnRoute{*bgp.NewIPAddrPrefix(23, "40.40.40.0")} - withdrawnRoutes := []bgp.WithdrawnRoute{w1} + nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "30.30.30.0")} + w1 := bgp.NewIPAddrPrefix(23, "40.40.40.0") + withdrawnRoutes := []*bgp.IPAddrPrefix{w1} return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) } |