diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..1e50ce1fe049a730dec90379d334ca7fefa26602 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.raw filter=lfs diff=lfs merge=lfs -text diff --git a/benchmarks/bgp/decode_real_full_feed/AS8881.raw b/benchmarks/bgp/decode_real_full_feed/AS8881.raw new file mode 100644 index 0000000000000000000000000000000000000000..a1249d5cca0270b3ad5fae344fcfce64504a423f --- /dev/null +++ b/benchmarks/bgp/decode_real_full_feed/AS8881.raw @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3881daddbdef448f52c50cbb6fd93d0d677d2d3c45816f69bb2d0ddc5d0f506 +size 12282584 diff --git a/benchmarks/bgp/decode_real_full_feed/main.go b/benchmarks/bgp/decode_real_full_feed/main.go new file mode 100644 index 0000000000000000000000000000000000000000..acd99cb9687717e21aec96fae9511ebbfe17a809 --- /dev/null +++ b/benchmarks/bgp/decode_real_full_feed/main.go @@ -0,0 +1,144 @@ +package main + +import ( + "bytes" + "flag" + "fmt" + "io/ioutil" + "os" + "runtime/pprof" + "time" + + "github.com/bio-routing/bio-rd/protocols/bgp/packet" + + log "github.com/sirupsen/logrus" +) + +var ( + nRuns = flag.Int("runs", 1, "# runs") +) + +type task struct { + num int + raw *bytes.Buffer + msg *packet.BGPMessage +} + +func main() { + flag.Parse() + + updates := make([][]*bytes.Buffer, *nRuns) + for i := 0; i < *nRuns; i++ { + updates[i] = make([]*bytes.Buffer, 0) + } + + raw, err := ioutil.ReadFile("AS8881.raw") + if err != nil { + log.Errorf("Unable to open PCAP file: %v", err) + os.Exit(1) + } + + msgs := extractBGPMessages(raw) + for _, msg := range msgs { + for i := 0; i < *nRuns; i++ { + updates[i] = append(updates[i], bytes.NewBuffer(msg)) + } + } + + c := len(updates[0]) + + fmt.Printf("Decoding %d BGP messages\n", c) + + buf := bytes.NewBuffer(nil) + err = pprof.StartCPUProfile(buf) + if err != nil { + panic(err) + } + + dco := &packet.DecodeOptions{ + Use32BitASN: true, + } + + start := time.Now().UnixNano() + + nlriCount := 0 + for j := 0; j < *nRuns; j++ { + for i := 0; i < c; i++ { + msg, err := packet.Decode(updates[j][i], dco) + if err != nil { + fmt.Printf("Unable to decode msg %d: %v\n", i, err) + continue + } + + if msg.Header.Type == 2 { + n := msg.Body.(*packet.BGPUpdate).NLRI + for { + if n == nil { + break + } + + nlriCount++ + + n = n.Next + } + } + } + } + fmt.Printf("NLRIs: %d\n", nlriCount) + + end := time.Now().UnixNano() + + d := end - start + pprof.StopCPUProfile() + fmt.Printf("decoding updates took %d ms\n", d/1000000) + + ioutil.WriteFile("profile.pprof", buf.Bytes(), 0644) + + x := bytes.NewBuffer(nil) + pprof.WriteHeapProfile(x) + + ioutil.WriteFile("heap.pprof", x.Bytes(), 0644) +} + +func hexDump(input []byte) string { + s := "" + for _, x := range input { + s += fmt.Sprintf("%x ", x) + } + + return s +} + +func extractBGPMessages(input []byte) [][]byte { + fmt.Printf("Extracting BGP messages from %d bytes\n", len(input)) + ret := make([][]byte, 0) + + //fmt.Printf("Data: %v\n", input[0:24]) + l := len(input) + i := 0 + for { + if i+17 > l { + break + } + + for j := 0; j < 16; j++ { + if input[i+j] != 255 { + panic(fmt.Sprintf("Invalid BGP marker: (%d+%d=%d): %s", i, j, i+j, hexDump(input[i:i+16]))) + } + } + + msgLen := uint16(input[i+16])*256 + uint16(input[i+17]) + + ret = append(ret, input[i:i+int(msgLen)]) + + if msgLen == 0 { + panic(msgLen) + } + + i += int(msgLen) + } + + fmt.Printf("Done\n") + + return ret +} diff --git a/benchmarks/bgp/learning/main.go b/benchmarks/bgp/learning/main.go index 9d06bc2d1d45160b6300b0dd90f0cb6db5dc7e81..814dbbbb1fcfece734c56b81dc5d1eb5ad7ac451 100644 --- a/benchmarks/bgp/learning/main.go +++ b/benchmarks/bgp/learning/main.go @@ -149,8 +149,8 @@ func main() { AdminEnabled: true, LocalAS: 65200, PeerAS: 200, - PeerAddress: bnet.IPv4FromOctets(172, 17, 0, 3), - LocalAddress: bnet.IPv4FromOctets(169, 254, 200, 0), + PeerAddress: bnet.IPv4FromOctets(172, 17, 0, 3).Ptr(), + LocalAddress: bnet.IPv4FromOctets(169, 254, 200, 0).Ptr(), ReconnectInterval: time.Second * 15, HoldTime: time.Second * 90, KeepAlive: time.Second * 30, diff --git a/benchmarks/pfxcache/main.go b/benchmarks/pfxcache/main.go index c652c1240aa2548371dfbfe0ea9cf811902b96b2..d40958e70548e94aed8617247656deb7c40ab5a9 100644 --- a/benchmarks/pfxcache/main.go +++ b/benchmarks/pfxcache/main.go @@ -16,7 +16,6 @@ func main() { for j := 0; j < 255; j++ { for k := 0; k < 11; k++ { addr := bnet.IPv4FromOctets(uint8(k)+1, uint8(i), uint8(j), 0) - addr.Dedup() pfxs = append(pfxs, bnet.NewPfx(addr, 24).Dedup()) } diff --git a/cmd/bio-rd/config/bgp.go b/cmd/bio-rd/config/bgp.go index bd94a00f55712e43fe6f2ed993c3f4d8e0133f3c..156f622a50922b0f350ec75d58450da9f43bae57 100644 --- a/cmd/bio-rd/config/bgp.go +++ b/cmd/bio-rd/config/bgp.go @@ -52,7 +52,7 @@ func (bg *BGPGroup) load(localAS uint32, policyOptions *PolicyOptions) error { return errors.Wrap(err, "Unable to parse BGP local address") } - bg.LocalAddressIP = a + bg.LocalAddressIP = a.Dedup() } if bg.HoldTime == 0 { @@ -146,14 +146,14 @@ func (bn *BGPNeighbor) load(po *PolicyOptions) error { return errors.Wrap(err, "Unable to parse BGP local address") } - bn.LocalAddressIP = a + bn.LocalAddressIP = a.Dedup() b, err := bnet.IPFromString(bn.PeerAddress) if err != nil { return errors.Wrap(err, "Unable to parse BGP peer address") } - bn.PeerAddressIP = b + bn.PeerAddressIP = b.Dedup() bn.HoldTimeDuration = time.Second * time.Duration(bn.HoldTime) for i := range bn.Import { diff --git a/cmd/bio-rd/config/policy.go b/cmd/bio-rd/config/policy.go index b295743c2495574bca2282f2add66ff7bd792d51..c9efff1575aea30c9e930b528ef927a5e595194a 100644 --- a/cmd/bio-rd/config/policy.go +++ b/cmd/bio-rd/config/policy.go @@ -161,7 +161,7 @@ func (pst *PolicyStatementTerm) toFilterTerm() (*filter.Term, error) { return nil, errors.Wrap(err, "Invalid next_hop address") } - a = append(a, actions.NewSetNextHopAction(addr)) + a = append(a, actions.NewSetNextHopAction(addr.Dedup())) } if pst.Then.Accept { diff --git a/config/server_test.go b/config/server_test.go index 85919d1047e0ee966ef0c4b80344d2d240cc7d08..e674c197125565623795d79d588a295bd54e38e1 100644 --- a/config/server_test.go +++ b/config/server_test.go @@ -105,16 +105,16 @@ func TestAddrIsGreater(t *testing.T) { { name: "::7d2:0:0:0:1c8 higher than ::7d1:0:0:0:1c8", args: args{ - a: bnet.IPv6(2002, 456).Bytes(), - b: bnet.IPv6(2001, 456).Bytes(), + a: bnet.IPv6(2002, 456).Ptr().Bytes(), + b: bnet.IPv6(2001, 456).Ptr().Bytes(), }, want: true, }, { name: "::7d1:0:0:0:1c8 higher than ::7d2:0:0:0:1c8", args: args{ - a: bnet.IPv6(2001, 456).Bytes(), - b: bnet.IPv6(2002, 456).Bytes(), + a: bnet.IPv6(2001, 456).Ptr().Bytes(), + b: bnet.IPv6(2002, 456).Ptr().Bytes(), }, want: false, }, diff --git a/examples/bgp/main_ipv4.go b/examples/bgp/main_ipv4.go index 243fa0acc565e9423e04e2e790dccab8639ac1cd..6b7a9395a4ecfe1f70cba6b58c362cdd47f30978 100644 --- a/examples/bgp/main_ipv4.go +++ b/examples/bgp/main_ipv4.go @@ -38,8 +38,8 @@ func startServer(b server.BGPServer, v *vrf.VRF) { AdminEnabled: true, LocalAS: 65200, PeerAS: 65300, - PeerAddress: bnet.IPv4FromOctets(172, 17, 0, 3), - LocalAddress: bnet.IPv4FromOctets(169, 254, 200, 0), + PeerAddress: bnet.IPv4FromOctets(172, 17, 0, 3).Ptr(), + LocalAddress: bnet.IPv4FromOctets(169, 254, 200, 0).Ptr(), ReconnectInterval: time.Second * 15, HoldTime: time.Second * 90, KeepAlive: time.Second * 30, @@ -60,8 +60,8 @@ func startServer(b server.BGPServer, v *vrf.VRF) { AdminEnabled: true, LocalAS: 65200, PeerAS: 65100, - PeerAddress: bnet.IPv4FromOctets(172, 17, 0, 2), - LocalAddress: bnet.IPv4FromOctets(169, 254, 100, 1), + PeerAddress: bnet.IPv4FromOctets(172, 17, 0, 2).Ptr(), + LocalAddress: bnet.IPv4FromOctets(169, 254, 100, 1).Ptr(), ReconnectInterval: time.Second * 15, HoldTime: time.Second * 90, KeepAlive: time.Second * 30, diff --git a/examples/bmp/main_bmp.go b/examples/bmp/main_bmp.go index d16e4a6f38780c859de019d299c811db419f6187..95ceee1676f52b0a59d53b5f1c88b7dbac0ef7d8 100644 --- a/examples/bmp/main_bmp.go +++ b/examples/bmp/main_bmp.go @@ -35,7 +35,7 @@ func main() { } fmt.Printf("looking up 185.65.240.100\n") - for _, r := range rib4.LPM(bnet.NewPfx(bnet.IPv4FromOctets(185, 65, 240, 100), 32)) { + for _, r := range rib4.LPM(bnet.NewPfx(bnet.IPv4FromOctets(185, 65, 240, 100), 32).Ptr()) { fmt.Printf("Pfx: %s\n", r.Prefix().String()) for _, p := range r.Paths() { fmt.Printf(" %s\n", p.String()) @@ -43,7 +43,7 @@ func main() { } fmt.Printf("is 8.8.8.8 in closednet?\n") - x := rib4.LPM(bnet.NewPfx(bnet.IPv4FromOctets(8, 8, 8, 8), 32)) + x := rib4.LPM(bnet.NewPfx(bnet.IPv4FromOctets(8, 8, 8, 8), 32).Ptr()) if len(x) == 0 { fmt.Printf("Nope\n") } else { @@ -51,7 +51,7 @@ func main() { } fmt.Printf("is 185.65.240.100 in closednet?\n") - x = rib4.LPM(bnet.NewPfx(bnet.IPv4FromOctets(185, 65, 240, 0), 32)) + x = rib4.LPM(bnet.NewPfx(bnet.IPv4FromOctets(185, 65, 240, 0), 32).Ptr()) if len(x) == 0 { fmt.Printf("Nope\n") } else { diff --git a/examples/kernel/main.go b/examples/kernel/main.go index 7d198d00912ed65d55cc56db125725c9cfee43b8..f6b3f548ed144552e5c94c21d90c154dcc9ecaa3 100644 --- a/examples/kernel/main.go +++ b/examples/kernel/main.go @@ -19,10 +19,10 @@ func main() { } rib4 := vrf.IPv4UnicastRIB() - rib4.AddPath(bnet.NewPfx(bnet.IPv4FromOctets(8, 8, 8, 0), 24), &route.Path{ + rib4.AddPath(bnet.NewPfx(bnet.IPv4FromOctets(8, 8, 8, 0), 24).Ptr(), &route.Path{ Type: route.StaticPathType, StaticPath: &route.StaticPath{ - NextHop: bnet.IPv4FromOctets(127, 0, 0, 1), + NextHop: bnet.IPv4FromOctets(127, 0, 0, 1).Ptr(), }, }) diff --git a/go.sum b/go.sum index b964fb419c0f4d3ae0b53c11a5345431d51d303d..772a6cbf53b8136c1e8d673fbe977120dd47fc13 100644 --- a/go.sum +++ b/go.sum @@ -68,6 +68,7 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME= github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= diff --git a/net/ip.go b/net/ip.go index da20b57145c506236927c4d3fd0c8b4c578459a5..a9223fe400aca86e68bcf4fb3a21051478105d59 100644 --- a/net/ip.go +++ b/net/ip.go @@ -5,7 +5,6 @@ import ( "net" api "github.com/bio-routing/bio-rd/net/api" - "github.com/google/btree" ) // IP represents an IPv4 or IPv6 address @@ -16,10 +15,15 @@ type IP struct { } // Dedup gets a copy of IP from the cache -func (ip *IP) Dedup() *IP { +func (ip IP) Dedup() *IP { return ipc.get(ip) } +// Ptr returns a pointer to ip +func (ip IP) Ptr() *IP { + return &ip +} + // IPFromProtoIP creates an IP address from a proto IP func IPFromProtoIP(addr api.IP) *IP { return &IP{ @@ -30,7 +34,7 @@ func IPFromProtoIP(addr api.IP) *IP { } // ToProto converts an IP to a proto IP -func (ip *IP) ToProto() *api.IP { +func (ip IP) ToProto() *api.IP { ver := api.IP_IPv6 if ip.isLegacy { ver = api.IP_IPv4 @@ -54,21 +58,21 @@ func (ip *IP) Higher() uint64 { } // IPv4 returns a new `IP` representing an IPv4 address -func IPv4(val uint32) *IP { - return &IP{ +func IPv4(val uint32) IP { + return IP{ lower: uint64(val), isLegacy: true, } } // IPv4FromOctets returns an IPv4 address for the given 4 octets -func IPv4FromOctets(o1, o2, o3, o4 uint8) *IP { +func IPv4FromOctets(o1, o2, o3, o4 uint8) IP { return IPv4(uint32(o1)<<24 + uint32(o2)<<16 + uint32(o3)<<8 + uint32(o4)) } // IPv6 returns a new `IP` representing an IPv6 address -func IPv6(higher, lower uint64) *IP { - return &IP{ +func IPv6(higher, lower uint64) IP { + return IP{ higher: higher, lower: lower, isLegacy: false, @@ -76,14 +80,32 @@ func IPv6(higher, lower uint64) *IP { } // IPv6FromBlocks returns an IPv6 address for the given 8 blocks -func IPv6FromBlocks(b1, b2, b3, b4, b5, b6, b7, b8 uint16) *IP { +func IPv6FromBlocks(b1, b2, b3, b4, b5, b6, b7, b8 uint16) IP { return IPv6( uint64(uint64(b1)<<48+uint64(b2)<<32+uint64(b3)<<16+uint64(b4)), uint64(uint64(b5)<<48+uint64(b6)<<32+uint64(b7)<<16+uint64(b8))) } +// IPv4FromBytes creates an IPv4 Address from one or more bytes. Missing bytes are filled with zero bytes. +func IPv4FromBytes(b []byte) IP { + switch len(b) { + case 0: + return IPv4FromOctets(0, 0, 0, 0) + case 1: + return IPv4FromOctets(b[0], 0, 0, 0) + case 2: + return IPv4FromOctets(b[0], b[1], 0, 0) + case 3: + return IPv4FromOctets(b[0], b[1], b[2], 0) + case 4: + return IPv4FromOctets(b[0], b[1], b[2], b[3]) + } + + return IP{} +} + // IPFromBytes returns an IP address for a byte slice -func IPFromBytes(b []byte) (*IP, error) { +func IPFromBytes(b []byte) (IP, error) { if len(b) == 4 { return IPv4FromOctets(b[0], b[1], b[2], b[3]), nil } @@ -100,14 +122,14 @@ func IPFromBytes(b []byte) (*IP, error) { uint16(b[14])<<8+uint16(b[15])), nil } - return nil, fmt.Errorf("byte slice has an invalid length. Expected either 4 (IPv4) or 16 (IPv6) bytes but got: %d", len(b)) + return IP{}, fmt.Errorf("byte slice has an invalid length. Expected either 4 (IPv4) or 16 (IPv6) bytes but got: %d", len(b)) } // IPFromString returns an IP address for a given string -func IPFromString(str string) (*IP, error) { +func IPFromString(str string) (IP, error) { ip := net.ParseIP(str) if ip == nil { - return nil, fmt.Errorf("%s is not a valid IP address", str) + return IP{}, fmt.Errorf("%s is not a valid IP address", str) } ip4 := ip.To4() @@ -123,11 +145,6 @@ func (ip *IP) Equal(other *IP) bool { return *ip == *other } -// Less compares ips for use in btree.Btree -func (ip *IP) Less(other btree.Item) bool { - return ip.Compare(other.(*IP)) == -1 -} - // Compare compares two IP addresses (returns 0 if equal, -1 if `ip` is smaller than `other`, 1 if `ip` is greater than `other`) func (ip *IP) Compare(other *IP) int8 { if ip.higher > other.higher { diff --git a/net/ip_cache.go b/net/ip_cache.go index a38d9ed3df6974b65e9e57cb28c3043db122ac12..8936f32d44a9d31a4ae6194e083a1731a126ecc4 100644 --- a/net/ip_cache.go +++ b/net/ip_cache.go @@ -2,12 +2,10 @@ package net import ( "sync" - - "github.com/google/btree" ) const ( - ipCacheBTreeGrade = 3500 + ipCachePreAlloc = 1500000 ) var ( @@ -19,28 +17,29 @@ func init() { } type ipCache struct { + cache map[IP]*IP cacheMu sync.Mutex - tree *btree.BTree } func newIPCache() *ipCache { return &ipCache{ - tree: btree.New(ipCacheBTreeGrade), + cache: make(map[IP]*IP, ipCachePreAlloc), } } -func (ipc *ipCache) get(addr *IP) *IP { +func (ipc *ipCache) get(addr IP) *IP { ipc.cacheMu.Lock() - item := ipc.tree.Get(addr) - if item != nil { + if a, exists := ipc.cache[addr]; exists { ipc.cacheMu.Unlock() - - return item.(*IP) + return a } - ipc.tree.ReplaceOrInsert(addr) + ipc._set(addr) ipc.cacheMu.Unlock() + return ipc.cache[addr] +} - return addr +func (ipc *ipCache) _set(addr IP) { + ipc.cache[addr] = &addr } diff --git a/net/ip_test.go b/net/ip_test.go index 0612c55c723e60fc5411be486d3c9dc799ef0356..fb666ca23c8af8e78a01d9f2dde4f23f0c835f0b 100644 --- a/net/ip_test.go +++ b/net/ip_test.go @@ -50,7 +50,7 @@ func TestHigher(t *testing.T) { func TestIPVersion(t *testing.T) { tests := []struct { name string - ip *IP + ip IP expected bool }{ { @@ -225,7 +225,7 @@ func TestCompare(t *testing.T) { func TestIPString(t *testing.T) { tests := []struct { - ip *IP + ip IP expected string }{ { @@ -262,7 +262,7 @@ func TestIPString(t *testing.T) { func TestBytes(t *testing.T) { tests := []struct { name string - ip *IP + ip IP expected []byte }{ { @@ -288,12 +288,12 @@ func TestIPv4FromOctets(t *testing.T) { tests := []struct { name string octets []uint8 - expected *IP + expected IP }{ { name: "172.217.16.195", octets: []uint8{172, 217, 16, 195}, - expected: &IP{ + expected: IP{ higher: 0, lower: 2899906755, isLegacy: true, @@ -302,7 +302,7 @@ func TestIPv4FromOctets(t *testing.T) { { name: "0.0.0.0", octets: []uint8{0, 0, 0, 0}, - expected: &IP{ + expected: IP{ higher: 0, lower: 0, isLegacy: true, @@ -311,7 +311,7 @@ func TestIPv4FromOctets(t *testing.T) { { name: "255.255.255.255", octets: []uint8{255, 255, 255, 255}, - expected: &IP{ + expected: IP{ higher: 0, lower: math.MaxUint32, isLegacy: true, @@ -330,7 +330,7 @@ func TestIPv6FromBlocks(t *testing.T) { tests := []struct { name string blocks []uint16 - expected *IP + expected IP }{ { name: "IPv6 2001:678:1E0:1234:5678:DEAD:BEEF:CAFE", @@ -344,7 +344,7 @@ func TestIPv6FromBlocks(t *testing.T) { 0xbeef, 0xcafe, }, - expected: &IP{ + expected: IP{ higher: 2306131596687708724, lower: 6230974922281175806, }, @@ -370,13 +370,13 @@ func TestIPFromBytes(t *testing.T) { tests := []struct { name string bytes []byte - expected *IP + expected IP wantFail bool }{ { name: "IPV4: 172.217.16.195", bytes: []byte{172, 217, 16, 195}, - expected: &IP{ + expected: IP{ higher: 0, lower: 2899906755, isLegacy: true, @@ -385,7 +385,7 @@ func TestIPFromBytes(t *testing.T) { { name: "IPV6: IPv6 2001:678:1E0:1234:5678:DEAD:BEEF:CAFE", bytes: []byte{0x20, 0x01, 0x06, 0x78, 0x01, 0xE0, 0x12, 0x34, 0x56, 0x78, 0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE}, - expected: &IP{ + expected: IP{ higher: 2306131596687708724, lower: 6230974922281175806, }, @@ -404,6 +404,13 @@ func TestIPFromBytes(t *testing.T) { t.Fatalf("Expected test to fail, but did not") } + if test.wantFail { + if err == nil { + t.Fatalf("Unexpected success") + } + return + } + assert.Equal(t, test.expected, ip) }) } @@ -412,7 +419,7 @@ func TestIPFromBytes(t *testing.T) { func TestToNetIP(t *testing.T) { tests := []struct { name string - ip *IP + ip IP expected net.IP }{ { @@ -445,7 +452,7 @@ func TestToNetIP(t *testing.T) { func TestBitAtPosition(t *testing.T) { tests := []struct { name string - input *IP + input IP position uint8 expected bool }{ @@ -521,7 +528,7 @@ func TestIPFromString(t *testing.T) { tests := []struct { name string input string - expected *IP + expected IP wantFail bool }{ { @@ -563,7 +570,7 @@ func TestIPFromString(t *testing.T) { func TestSizeBytes(t *testing.T) { tests := []struct { name string - input *IP + input IP expected uint8 }{ { diff --git a/net/prefix.go b/net/prefix.go index 4cfc7ac493170f867c0962deaf44fa9d34747a61..a8f72035b7fb430ce82f35293eda7be4e33b5761 100644 --- a/net/prefix.go +++ b/net/prefix.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/bio-routing/bio-rd/net/api" - "github.com/google/btree" "github.com/pkg/errors" ) @@ -18,29 +17,15 @@ type Prefix struct { pfxlen uint8 } -// Dedup gets a copy of Prefix from the cache -func (p *Prefix) Dedup() *Prefix { +// Dedup gets a copy of Prefix from the cache. +// If Prefix is not in the cache it gets added. +func (p Prefix) Dedup() *Prefix { return pfxc.get(p) } -// Less compares prefixes for use in btree.Btree -func (p *Prefix) Less(other btree.Item) bool { - switch p.addr.Compare(other.(*Prefix).addr) { - case 0: - return p.pfxlen < other.(*Prefix).pfxlen - case -1: - return true - case 1: - return false - } - - return false -} - -// DedupWithIP gets a copy of Prefix from the cache and dedups the IP part -func (p *Prefix) DedupWithIP() *Prefix { - p.addr = p.addr.Dedup() - return pfxc.get(p) +// Ptr returns a pointer to p +func (p Prefix) Ptr() *Prefix { + return &p } // NewPrefixFromProtoPrefix creates a Prefix from a proto Prefix @@ -69,13 +54,13 @@ func PrefixFromString(s string) (*Prefix, error) { } return &Prefix{ - addr: ip, + addr: ip.Dedup(), pfxlen: uint8(l), }, nil } // ToProto converts prefix to proto prefix -func (p *Prefix) ToProto() *api.Prefix { +func (p Prefix) ToProto() *api.Prefix { return &api.Prefix{ Address: p.addr.ToProto(), Pfxlen: uint32(p.pfxlen), @@ -83,9 +68,9 @@ func (p *Prefix) ToProto() *api.Prefix { } // NewPfx creates a new Prefix -func NewPfx(addr *IP, pfxlen uint8) *Prefix { - return &Prefix{ - addr: addr, +func NewPfx(addr IP, pfxlen uint8) Prefix { + return Prefix{ + addr: addr.Dedup(), pfxlen: pfxlen, } } @@ -96,7 +81,7 @@ func NewPfxFromIPNet(ipNet *gonet.IPNet) *Prefix { ip, _ := IPFromBytes(ipNet.IP) return &Prefix{ - addr: ip, + addr: ip.Dedup(), pfxlen: uint8(ones), } } @@ -193,7 +178,7 @@ func (pfx *Prefix) Equal(x *Prefix) bool { } // GetSupernet gets the next common supernet of pfx and x -func (pfx *Prefix) GetSupernet(x *Prefix) *Prefix { +func (pfx *Prefix) GetSupernet(x *Prefix) Prefix { if pfx.addr.isLegacy { return pfx.supernetIPv4(x) } @@ -201,7 +186,7 @@ func (pfx *Prefix) GetSupernet(x *Prefix) *Prefix { return pfx.supernetIPv6(x) } -func (pfx *Prefix) supernetIPv4(x *Prefix) *Prefix { +func (pfx *Prefix) supernetIPv4(x *Prefix) Prefix { maxPfxLen := min(pfx.pfxlen, x.pfxlen) - 1 a := pfx.addr.ToUint32() >> (32 - maxPfxLen) b := x.addr.ToUint32() >> (32 - maxPfxLen) @@ -212,13 +197,13 @@ func (pfx *Prefix) supernetIPv4(x *Prefix) *Prefix { maxPfxLen-- } - return &Prefix{ - addr: IPv4(a << (32 - maxPfxLen)), + return Prefix{ + addr: IPv4(a << (32 - maxPfxLen)).Dedup(), pfxlen: maxPfxLen, } } -func (pfx *Prefix) supernetIPv6(x *Prefix) *Prefix { +func (pfx *Prefix) supernetIPv6(x *Prefix) Prefix { maxPfxLen := min(pfx.pfxlen, x.pfxlen) a := pfx.addr.BitAtPosition(1) diff --git a/net/prefix_cache.go b/net/prefix_cache.go index 5f17f8672e80470e1fd5b364d15464c070785301..3b6795730e3bedad8ddd4472c7ec75c9077e0dd2 100644 --- a/net/prefix_cache.go +++ b/net/prefix_cache.go @@ -2,12 +2,10 @@ package net import ( "sync" - - "github.com/google/btree" ) const ( - prefixCacheBTreeGrade = 3500 + prefixCachePreAlloc = 1500000 ) var ( @@ -19,27 +17,30 @@ func init() { } type pfxCache struct { + cache map[Prefix]*Prefix cacheMu sync.Mutex - tree *btree.BTree } func newPfxCache() *pfxCache { return &pfxCache{ - tree: btree.New(prefixCacheBTreeGrade), + cache: make(map[Prefix]*Prefix, prefixCachePreAlloc), } } -func (pfxc *pfxCache) get(pfx *Prefix) *Prefix { +func (pfxc *pfxCache) get(pfx Prefix) *Prefix { + pfx.addr = pfx.addr.Dedup() pfxc.cacheMu.Lock() - item := pfxc.tree.Get(pfx) - if item != nil { + if p, exists := pfxc.cache[pfx]; exists { pfxc.cacheMu.Unlock() - return item.(*Prefix) + return p } - pfxc.tree.ReplaceOrInsert(pfx) + pfxc._set(pfx) pfxc.cacheMu.Unlock() + return pfxc.cache[pfx] +} - return pfx +func (pfxc *pfxCache) _set(pfx Prefix) { + pfxc.cache[pfx] = &pfx } diff --git a/net/prefix_test.go b/net/prefix_test.go index 0c76deee67e9be2534e7a19d77dba6e10bba17b6..8fb2c99daa663284fcbd3219d1bb8bd2198661d1 100644 --- a/net/prefix_test.go +++ b/net/prefix_test.go @@ -11,7 +11,7 @@ import ( func TestGetIPNet(t *testing.T) { tests := []struct { name string - pfx *Prefix + pfx Prefix expected *gonet.IPNet }{ { @@ -40,7 +40,7 @@ func TestNewPfxFromIPNet(t *testing.T) { tests := []struct { name string ipNet *gonet.IPNet - expected *Prefix + expected Prefix }{ { name: "Some Prefix", @@ -53,19 +53,19 @@ func TestNewPfxFromIPNet(t *testing.T) { } for _, test := range tests { res := NewPfxFromIPNet(test.ipNet) - assert.Equal(t, test.expected, res, test.name) + assert.Equal(t, test.expected, *res, test.name) } } func TestPrefixToProto(t *testing.T) { tests := []struct { name string - pfx *Prefix + pfx Prefix expected *api.Prefix }{ { name: "IPv4", - pfx: &Prefix{ + pfx: Prefix{ addr: &IP{ lower: 200, isLegacy: true, @@ -82,7 +82,7 @@ func TestPrefixToProto(t *testing.T) { }, { name: "IPv6", - pfx: &Prefix{ + pfx: Prefix{ addr: &IP{ higher: 100, lower: 200, @@ -111,7 +111,7 @@ func TestNewPrefixFromProtoPrefix(t *testing.T) { tests := []struct { name string proto api.Prefix - expected *Prefix + expected Prefix }{ { name: "IPv4", @@ -123,7 +123,7 @@ func TestNewPrefixFromProtoPrefix(t *testing.T) { }, Pfxlen: 24, }, - expected: &Prefix{ + expected: Prefix{ addr: &IP{ higher: 0, lower: 2000, @@ -142,7 +142,7 @@ func TestNewPrefixFromProtoPrefix(t *testing.T) { }, Pfxlen: 64, }, - expected: &Prefix{ + expected: Prefix{ addr: &IP{ higher: 1000, lower: 2000, @@ -155,13 +155,13 @@ func TestNewPrefixFromProtoPrefix(t *testing.T) { for _, test := range tests { res := NewPrefixFromProtoPrefix(test.proto) - assert.Equal(t, test.expected, res, test.name) + assert.Equal(t, test.expected, *res, test.name) } } func TestNewPfx(t *testing.T) { p := NewPfx(IPv4(123), 11) - if *p.addr != *IPv4(123) || p.pfxlen != 11 { + if *p.addr != IPv4(123) || p.pfxlen != 11 { t.Errorf("NewPfx() failed: Unexpected values") } } @@ -169,8 +169,8 @@ func TestNewPfx(t *testing.T) { func TestAddr(t *testing.T) { tests := []struct { name string - pfx *Prefix - expected *IP + pfx Prefix + expected IP }{ { name: "Test 1", @@ -181,14 +181,14 @@ func TestAddr(t *testing.T) { for _, test := range tests { res := test.pfx.Addr() - assert.Equal(t, res, test.expected, "Unexpected result for test %s", test.name) + assert.Equal(t, *res, test.expected, "Unexpected result for test %s", test.name) } } func TestPfxlen(t *testing.T) { tests := []struct { name string - pfx *Prefix + pfx Prefix expected uint8 }{ { @@ -214,75 +214,75 @@ func TestGetSupernet(t *testing.T) { { name: "Supernet of 10.0.0.0 and 11.100.123.0 -> 10.0.0.0/7", a: &Prefix{ - addr: IPv4FromOctets(10, 0, 0, 0), + addr: IPv4FromOctets(10, 0, 0, 0).Ptr(), pfxlen: 8, }, b: &Prefix{ - addr: IPv4FromOctets(11, 100, 123, 0), + addr: IPv4FromOctets(11, 100, 123, 0).Ptr(), pfxlen: 24, }, expected: &Prefix{ - addr: IPv4FromOctets(10, 0, 0, 0), + addr: IPv4FromOctets(10, 0, 0, 0).Dedup(), pfxlen: 7, }, }, { name: "Supernet of 10.0.0.0 and 192.168.0.0 -> 0.0.0.0/0", a: &Prefix{ - addr: IPv4FromOctets(10, 0, 0, 0), + addr: IPv4FromOctets(10, 0, 0, 0).Ptr(), pfxlen: 8, }, b: &Prefix{ - addr: IPv4FromOctets(192, 168, 0, 0), + addr: IPv4FromOctets(192, 168, 0, 0).Ptr(), pfxlen: 24, }, expected: &Prefix{ - addr: IPv4(0), + addr: IPv4(0).Dedup(), pfxlen: 0, }, }, { name: "Supernet of 2001:678:1e0:100:23::/64 and 2001:678:1e0:1ff::/64 -> 2001:678:1e0:100::/56", a: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 0x23, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 0x23, 0, 0, 0).Ptr(), pfxlen: 64, }, b: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x1ff, 0, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x1ff, 0, 0, 0, 0).Ptr(), pfxlen: 64, }, expected: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 0, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 0, 0, 0, 0).Dedup(), pfxlen: 56, }, }, { name: "Supernet of 2001:678:1e0::/128 and 2001:678:1e0::1/128 -> 2001:678:1e0:100::/127", a: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0).Ptr(), pfxlen: 128, }, b: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 1), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 1).Ptr(), pfxlen: 128, }, expected: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0).Dedup(), pfxlen: 127, }, }, { name: "Supernet of all ones and all zeros -> ::/0", a: &Prefix{ - addr: IPv6FromBlocks(0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF), + addr: IPv6FromBlocks(0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF).Ptr(), pfxlen: 128, }, b: &Prefix{ - addr: IPv6(0, 0), + addr: IPv6(0, 0).Ptr(), pfxlen: 128, }, expected: &Prefix{ - addr: IPv6FromBlocks(0, 0, 0, 0, 0, 0, 0, 0), + addr: IPv6FromBlocks(0, 0, 0, 0, 0, 0, 0, 0).Dedup(), pfxlen: 0, }, }, @@ -293,7 +293,7 @@ func TestGetSupernet(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { s := test.a.GetSupernet(test.b) - assert.Equal(t, test.expected, s) + assert.Equal(t, *test.expected, s) }) } } @@ -306,132 +306,132 @@ func TestContains(t *testing.T) { }{ { a: &Prefix{ - addr: IPv4(0), + addr: IPv4(0).Ptr(), pfxlen: 0, }, b: &Prefix{ - addr: IPv4(100), + addr: IPv4(100).Ptr(), pfxlen: 24, }, expected: true, }, { a: &Prefix{ - addr: IPv4(100), + addr: IPv4(100).Ptr(), pfxlen: 24, }, b: &Prefix{ - addr: IPv4(0), + addr: IPv4(0).Ptr(), pfxlen: 0, }, expected: false, }, { a: &Prefix{ - addr: IPv4(167772160), + addr: IPv4(167772160).Ptr(), pfxlen: 8, }, b: &Prefix{ - addr: IPv4(167772160), + addr: IPv4(167772160).Ptr(), pfxlen: 9, }, expected: true, }, { a: &Prefix{ - addr: IPv4(167772160), + addr: IPv4(167772160).Ptr(), pfxlen: 8, }, b: &Prefix{ - addr: IPv4(174391040), + addr: IPv4(174391040).Ptr(), pfxlen: 24, }, expected: true, }, { a: &Prefix{ - addr: IPv4(167772160), + addr: IPv4(167772160).Ptr(), pfxlen: 8, }, b: &Prefix{ - addr: IPv4(184549377), + addr: IPv4(184549377).Ptr(), pfxlen: 24, }, expected: false, }, { a: &Prefix{ - addr: IPv4(167772160), + addr: IPv4(167772160).Ptr(), pfxlen: 8, }, b: &Prefix{ - addr: IPv4(191134464), + addr: IPv4(191134464).Ptr(), pfxlen: 24, }, expected: false, }, { a: &Prefix{ - addr: IPv4FromOctets(169, 0, 0, 0), + addr: IPv4FromOctets(169, 0, 0, 0).Ptr(), pfxlen: 25, }, b: &Prefix{ - addr: IPv4FromOctets(169, 1, 1, 0), + addr: IPv4FromOctets(169, 1, 1, 0).Ptr(), pfxlen: 26, }, expected: false, }, { a: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0).Ptr(), pfxlen: 48, }, expected: true, b: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 0, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 0, 0, 0, 0).Ptr(), pfxlen: 56, }, }, { a: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x200, 0, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x200, 0, 0, 0, 0).Ptr(), pfxlen: 56, }, b: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 0, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 0, 0, 0, 0).Ptr(), pfxlen: 64, }, expected: false, }, { a: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x200, 0, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x200, 0, 0, 0, 0).Ptr(), pfxlen: 65, }, b: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 0, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 0, 0, 0, 0).Ptr(), pfxlen: 64, }, expected: false, }, { a: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 100, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 100, 0, 0, 0).Ptr(), pfxlen: 72, }, b: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 100, 0, 0, 1), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 100, 0, 0, 1).Ptr(), pfxlen: 127, }, expected: true, }, { a: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 100, 0, 0, 0), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 100, 0, 0, 0).Ptr(), pfxlen: 126, }, b: &Prefix{ - addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 100, 0, 100, 1), + addr: IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 100, 0, 100, 1).Ptr(), pfxlen: 127, }, expected: false, @@ -486,14 +486,14 @@ func TestEqual(t *testing.T) { }{ { name: "Equal PFXs", - a: NewPfx(IPv4(100), 8), - b: NewPfx(IPv4(100), 8), + a: NewPfx(IPv4(100), 8).Ptr(), + b: NewPfx(IPv4(100), 8).Ptr(), expected: true, }, { name: "Unequal PFXs", - a: NewPfx(IPv4(100), 8), - b: NewPfx(IPv4(200), 8), + a: NewPfx(IPv4(100), 8).Ptr(), + b: NewPfx(IPv4(200), 8).Ptr(), expected: false, }, } @@ -507,7 +507,7 @@ func TestEqual(t *testing.T) { func TestString(t *testing.T) { tests := []struct { name string - pfx *Prefix + pfx Prefix expected string }{ { diff --git a/protocols/bgp/packet/decoder.go b/protocols/bgp/packet/decoder.go index 9d62716e89af2d5e11651e314d67ee0143fdf8f8..9dc12f05a98785ec2e5bd4ed3558cf267476f29d 100644 --- a/protocols/bgp/packet/decoder.go +++ b/protocols/bgp/packet/decoder.go @@ -45,7 +45,7 @@ func decodeMsgBody(buf *bytes.Buffer, msgType uint8, l uint16, opt *DecodeOption func decodeUpdateMsg(buf *bytes.Buffer, l uint16, opt *DecodeOptions) (*BGPUpdate, error) { msg := &BGPUpdate{} - err := decode.Decode(buf, []interface{}{&msg.WithdrawnRoutesLen}) + err := decode.DecodeUint16(buf, &msg.WithdrawnRoutesLen) if err != nil { return msg, err } @@ -55,7 +55,7 @@ func decodeUpdateMsg(buf *bytes.Buffer, l uint16, opt *DecodeOptions) (*BGPUpdat return msg, err } - err = decode.Decode(buf, []interface{}{&msg.TotalPathAttrLen}) + err = decode.DecodeUint16(buf, &msg.TotalPathAttrLen) if err != nil { return msg, err } @@ -352,40 +352,35 @@ func isValidIdentifier(id uint32) bool { func decodeHeader(buf *bytes.Buffer) (*BGPHeader, error) { hdr := &BGPHeader{} - marker := make([]byte, MarkerLen) - n, err := buf.Read(marker) - if err != nil { - return hdr, BGPError{ - ErrorCode: Cease, - ErrorSubCode: 0, - ErrorStr: fmt.Sprintf("Failed to read from buffer: %v", err.Error()), - } - } - - if n != MarkerLen { - return hdr, BGPError{ - ErrorCode: Cease, - ErrorSubCode: 0, - ErrorStr: fmt.Sprintf("Unable to read marker"), + for i := 0; i < MarkerLen; i++ { + b, err := buf.ReadByte() + if err != nil { + return hdr, BGPError{ + ErrorCode: Cease, + ErrorSubCode: 0, + ErrorStr: fmt.Sprintf("Failed to read from buffer: %v", err), + } } - } - for i := range marker { - if marker[i] != 255 { + if b != 0xff { return nil, BGPError{ ErrorCode: MessageHeaderError, ErrorSubCode: ConnectionNotSync, - ErrorStr: fmt.Sprintf("Invalid marker: %v", marker), + ErrorStr: fmt.Sprintf("Invalid marker"), } } } - fields := []interface{}{ - &hdr.Length, - &hdr.Type, + err := decode.DecodeUint16(buf, &hdr.Length) + if err != nil { + return hdr, BGPError{ + ErrorCode: Cease, + ErrorSubCode: 0, + ErrorStr: fmt.Sprintf("%v", err.Error()), + } } - err = decode.Decode(buf, fields) + err = decode.DecodeUint8(buf, &hdr.Type) if err != nil { return hdr, BGPError{ ErrorCode: Cease, diff --git a/protocols/bgp/packet/decoder_test.go b/protocols/bgp/packet/decoder_test.go index eb73fd86ea1cc2ef266c21c1562d368c4221b4b3..3d20077bade01feca9b8c71d05f00e38761bed85 100644 --- a/protocols/bgp/packet/decoder_test.go +++ b/protocols/bgp/packet/decoder_test.go @@ -210,9 +210,9 @@ func TestDecode(t *testing.T) { Body: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16).Ptr(), }, }, }, @@ -428,9 +428,9 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16).Ptr(), }, }, }, @@ -465,9 +465,9 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16).Ptr(), }, }, TotalPathAttrLen: 23, @@ -499,7 +499,7 @@ func TestDecodeUpdateMsg(t *testing.T) { ExtendedLength: false, Length: 4, TypeCode: 3, - Value: net.IPv4FromOctets(10, 20, 30, 40), + Value: net.IPv4FromOctets(10, 20, 30, 40).Ptr(), }, }, }, @@ -577,9 +577,9 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16).Ptr(), }, }, TotalPathAttrLen: 27, @@ -623,7 +623,7 @@ func TestDecodeUpdateMsg(t *testing.T) { ExtendedLength: false, Length: 4, TypeCode: 3, - Value: bnet.IPv4FromOctets(10, 11, 12, 13), + Value: bnet.IPv4FromOctets(10, 11, 12, 13).Ptr(), }, }, }, @@ -666,9 +666,9 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16).Ptr(), }, }, TotalPathAttrLen: 34, @@ -711,7 +711,7 @@ func TestDecodeUpdateMsg(t *testing.T) { ExtendedLength: false, Length: 4, TypeCode: 3, - Value: bnet.IPv4FromOctets(10, 11, 12, 13), + Value: bnet.IPv4FromOctets(10, 11, 12, 13).Ptr(), Next: &PathAttribute{ Optional: false, Transitive: false, @@ -768,9 +768,9 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16).Ptr(), }, }, TotalPathAttrLen: 41, @@ -812,7 +812,7 @@ func TestDecodeUpdateMsg(t *testing.T) { ExtendedLength: false, Length: 4, TypeCode: 3, - Value: bnet.IPv4FromOctets(10, 11, 12, 13), + Value: bnet.IPv4FromOctets(10, 11, 12, 13).Ptr(), Next: &PathAttribute{ Optional: false, Transitive: false, @@ -882,9 +882,9 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16).Ptr(), }, }, TotalPathAttrLen: 44, @@ -926,7 +926,7 @@ func TestDecodeUpdateMsg(t *testing.T) { ExtendedLength: false, Length: 4, TypeCode: 3, - Value: bnet.IPv4FromOctets(10, 11, 12, 13), + Value: bnet.IPv4FromOctets(10, 11, 12, 13).Ptr(), Next: &PathAttribute{ Optional: false, Transitive: false, @@ -1012,9 +1012,9 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16).Ptr(), }, }, TotalPathAttrLen: 53, @@ -1056,7 +1056,7 @@ func TestDecodeUpdateMsg(t *testing.T) { ExtendedLength: false, Length: 4, TypeCode: 3, - Value: bnet.IPv4FromOctets(10, 11, 12, 13), + Value: bnet.IPv4FromOctets(10, 11, 12, 13).Ptr(), Next: &PathAttribute{ Optional: false, Transitive: false, @@ -1089,7 +1089,7 @@ func TestDecodeUpdateMsg(t *testing.T) { TypeCode: 7, Value: types.Aggregator{ ASN: uint16(258), - Address: bnet.IPv4FromOctets(10, 11, 12, 13).ToUint32(), + Address: bnet.IPv4FromOctets(10, 11, 12, 13).Ptr().ToUint32(), }, }, }, @@ -1099,7 +1099,7 @@ func TestDecodeUpdateMsg(t *testing.T) { }, }, NLRI: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(11, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), }, }, }, diff --git a/protocols/bgp/packet/helper.go b/protocols/bgp/packet/helper.go index 5e47b02c846a99e80bcf960dc200f158e423c326..83209063b32704798560e41ab1f8cb59acae61fe 100644 --- a/protocols/bgp/packet/helper.go +++ b/protocols/bgp/packet/helper.go @@ -27,6 +27,10 @@ func deserializePrefix(b []byte, pfxLen uint8, afi uint16) (*bnet.Prefix, error) return nil, fmt.Errorf("could not parse prefix of length %d. Expected %d bytes, got %d", pfxLen, numBytes, len(b)) } + if afi == IPv4AFI { + return bnet.NewPfx(bnet.IPv4FromBytes(b), pfxLen).Dedup(), nil + } + ipBytes := make([]byte, afiAddrLenBytes[afi]) copy(ipBytes, b) @@ -35,5 +39,5 @@ func deserializePrefix(b []byte, pfxLen uint8, afi uint16) (*bnet.Prefix, error) return nil, err } - return bnet.NewPfx(ip.Dedup(), pfxLen).Dedup(), nil + return bnet.NewPfx(ip, pfxLen).Dedup(), nil } diff --git a/protocols/bgp/packet/mp_reach_nlri.go b/protocols/bgp/packet/mp_reach_nlri.go index fac00135159067f9861e48cd5d79d9a6c6da6c88..65a63c507f34223fae8a9bc97d6e9425f3606321 100644 --- a/protocols/bgp/packet/mp_reach_nlri.go +++ b/protocols/bgp/packet/mp_reach_nlri.go @@ -64,11 +64,11 @@ func deserializeMultiProtocolReachNLRI(b []byte, addPath bool) (MultiProtocolRea fmt.Errorf("Failed to decode next hop IP: expected %d bytes for NLRI, only %d remaining", nextHopLength, budget) } - n.NextHop, err = bnet.IPFromBytes(variable[:nextHopLength]) + nh, err := bnet.IPFromBytes(variable[:nextHopLength]) if err != nil { return MultiProtocolReachNLRI{}, errors.Wrap(err, "Failed to decode next hop IP") } - n.NextHop = n.NextHop.Dedup() + n.NextHop = nh.Dedup() budget -= int(nextHopLength) if budget == 0 { diff --git a/protocols/bgp/packet/mp_reach_nlri_test.go b/protocols/bgp/packet/mp_reach_nlri_test.go index a4878cf7d161c03fa0947d238f2203707e6c369d..81e6c5b4ff33bb96f11f33f029fb90e6dedbed08 100644 --- a/protocols/bgp/packet/mp_reach_nlri_test.go +++ b/protocols/bgp/packet/mp_reach_nlri_test.go @@ -20,9 +20,9 @@ func TestSerializeMultiProtocolReachNLRI(t *testing.T) { nlri: MultiProtocolReachNLRI{ AFI: IPv6AFI, SAFI: UnicastSAFI, - NextHop: bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0x2), + NextHop: bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0x2).Dedup(), NLRI: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2600, 0x6, 0xff05, 0, 0, 0, 0, 0), 48), + Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2600, 0x6, 0xff05, 0, 0, 0, 0, 0), 48).Dedup(), }, }, expected: []byte{ @@ -38,9 +38,9 @@ func TestSerializeMultiProtocolReachNLRI(t *testing.T) { nlri: MultiProtocolReachNLRI{ AFI: IPv6AFI, SAFI: UnicastSAFI, - NextHop: bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0x2), + NextHop: bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0x2).Dedup(), NLRI: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2600, 0x6, 0xff05, 0, 0, 0, 0, 0), 48), + Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2600, 0x6, 0xff05, 0, 0, 0, 0, 0), 48).Dedup(), PathIdentifier: 100, }, }, diff --git a/protocols/bgp/packet/mp_unreach_nlri_test.go b/protocols/bgp/packet/mp_unreach_nlri_test.go index a550f3b3a02f5314c5430e000263a061af680385..246b55e64648af4170750bf1b15a18dd86bf2355 100644 --- a/protocols/bgp/packet/mp_unreach_nlri_test.go +++ b/protocols/bgp/packet/mp_unreach_nlri_test.go @@ -21,7 +21,7 @@ func TestSerializeMultiProtocolUnreachNLRI(t *testing.T) { AFI: IPv6AFI, SAFI: UnicastSAFI, NLRI: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2620, 0x110, 0x9000, 0, 0, 0, 0, 0), 44), + Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2620, 0x110, 0x9000, 0, 0, 0, 0, 0), 44).Dedup(), }, }, expected: []byte{ @@ -37,7 +37,7 @@ func TestSerializeMultiProtocolUnreachNLRI(t *testing.T) { SAFI: UnicastSAFI, NLRI: &NLRI{ PathIdentifier: 100, - Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2620, 0x110, 0x9000, 0, 0, 0, 0, 0), 44), + Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2620, 0x110, 0x9000, 0, 0, 0, 0, 0), 44).Dedup(), }, }, expected: []byte{ diff --git a/protocols/bgp/packet/nlri_test.go b/protocols/bgp/packet/nlri_test.go index e9e786bc77299bedbc5320fc3801ceb135c4a904..e59a4f62dc151cfc471f57cd41d5223d05872c5f 100644 --- a/protocols/bgp/packet/nlri_test.go +++ b/protocols/bgp/packet/nlri_test.go @@ -24,11 +24,11 @@ func TestDecodeNLRIs(t *testing.T) { }, wantFail: false, expected: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 24), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 24).Dedup(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Dedup(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(172, 16, 0, 0), 17), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(172, 16, 0, 0), 17).Dedup(), }, }, }, @@ -75,7 +75,7 @@ func TestDecodeNLRIv6(t *testing.T) { }, wantFail: false, expected: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0, 0, 0, 0, 0, 0, 0, 0), 0), + Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0, 0, 0, 0, 0, 0, 0, 0), 0).Dedup(), }, }, } @@ -111,7 +111,7 @@ func TestDecodeNLRI(t *testing.T) { }, wantFail: false, expected: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 24), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 24).Dedup(), }, }, { @@ -121,7 +121,7 @@ func TestDecodeNLRI(t *testing.T) { }, wantFail: false, expected: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 128), 25), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 128), 25).Dedup(), }, }, { @@ -148,7 +148,7 @@ func TestDecodeNLRI(t *testing.T) { wantFail: false, expected: &NLRI{ PathIdentifier: 10, - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 24), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 24).Dedup(), }, }, { @@ -160,7 +160,7 @@ func TestDecodeNLRI(t *testing.T) { wantFail: false, expected: &NLRI{ PathIdentifier: 256, - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 128), 25), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 128), 25).Dedup(), }, }, { @@ -262,21 +262,21 @@ func TestNLRISerialize(t *testing.T) { { name: "Test #1", nlri: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(1, 2, 3, 0), 25), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(1, 2, 3, 0), 25).Dedup(), }, expected: []byte{25, 1, 2, 3, 0}, }, { name: "Test #2", nlri: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(1, 2, 3, 0), 24), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(1, 2, 3, 0), 24).Dedup(), }, expected: []byte{24, 1, 2, 3}, }, { name: "Test #3", nlri: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(100, 200, 128, 0), 17), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(100, 200, 128, 0), 17).Dedup(), }, expected: []byte{17, 100, 200, 128}, }, @@ -284,7 +284,7 @@ func TestNLRISerialize(t *testing.T) { name: "with add-path #1", nlri: &NLRI{ PathIdentifier: 100, - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(1, 2, 3, 0), 25), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(1, 2, 3, 0), 25).Dedup(), }, addPath: true, expected: []byte{0, 0, 0, 100, 25, 1, 2, 3, 0}, @@ -293,7 +293,7 @@ func TestNLRISerialize(t *testing.T) { name: "with add-path #2", nlri: &NLRI{ PathIdentifier: 100, - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(1, 2, 3, 0), 24), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(1, 2, 3, 0), 24).Dedup(), }, addPath: true, expected: []byte{0, 0, 0, 100, 24, 1, 2, 3}, @@ -302,7 +302,7 @@ func TestNLRISerialize(t *testing.T) { name: "with add-path #3", nlri: &NLRI{ PathIdentifier: 100, - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(100, 200, 128, 0), 17), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(100, 200, 128, 0), 17).Dedup(), }, addPath: true, expected: []byte{0, 0, 0, 100, 17, 100, 200, 128}, diff --git a/protocols/bgp/packet/path_attribute_flags.go b/protocols/bgp/packet/path_attribute_flags.go index 47a5ef61c4911f848997dc930e0bc67beca3f789..8c74b3c96a057ed6b45e476c2a15d9dee2769a8f 100644 --- a/protocols/bgp/packet/path_attribute_flags.go +++ b/protocols/bgp/packet/path_attribute_flags.go @@ -8,7 +8,8 @@ import ( func decodePathAttrFlags(buf *bytes.Buffer, pa *PathAttribute) error { flags := uint8(0) - err := decode.Decode(buf, []interface{}{&flags}) + + err := decode.DecodeUint8(buf, &flags) if err != nil { return err } diff --git a/protocols/bgp/packet/path_attributes.go b/protocols/bgp/packet/path_attributes.go index 4269519faf4d34b7acffc3bb4567393d454c5307..e1b155ec9e3396060db0cfdd513d3af2bc0d383a 100644 --- a/protocols/bgp/packet/path_attributes.go +++ b/protocols/bgp/packet/path_attributes.go @@ -82,7 +82,7 @@ func decodePathAttr(buf *bytes.Buffer, opt *DecodeOptions) (pa *PathAttribute, c } consumed++ - err = decode.Decode(buf, []interface{}{&pa.TypeCode}) + err = decode.DecodeUint8(buf, &pa.TypeCode) if err != nil { return nil, consumed, err } @@ -222,7 +222,7 @@ func (pa *PathAttribute) decodeOrigin(buf *bytes.Buffer) error { origin := uint8(0) p := uint16(0) - err := decode.Decode(buf, []interface{}{&origin}) + err := decode.DecodeUint8(buf, &origin) if err != nil { return errors.Wrap(err, "Unable to decode") } @@ -234,16 +234,22 @@ func (pa *PathAttribute) decodeOrigin(buf *bytes.Buffer) error { } func (pa *PathAttribute) decodeASPath(buf *bytes.Buffer, asnLength uint8) error { - pa.Value = make(types.ASPath, 0) + pa.Value = make(types.ASPath, 0, 1) p := uint16(0) for p < pa.Length { segment := types.ASPathSegment{} count := uint8(0) - err := decode.Decode(buf, []interface{}{&segment.Type, &count}) + err := decode.DecodeUint8(buf, &segment.Type) if err != nil { return err } + + err = decode.DecodeUint8(buf, &count) + if err != nil { + return err + } + p += 2 if segment.Type != types.ASSet && segment.Type != types.ASSequence { @@ -283,7 +289,7 @@ func (pa *PathAttribute) decodeASN(buf *bytes.Buffer, asnSize uint8) (asn uint32 func (pa *PathAttribute) decode4ByteASN(buf *bytes.Buffer) (asn uint32, err error) { asn4 := uint32(0) - err = decode.Decode(buf, []interface{}{&asn4}) + err = decode.DecodeUint32(buf, &asn4) if err != nil { return 0, err } @@ -292,13 +298,13 @@ func (pa *PathAttribute) decode4ByteASN(buf *bytes.Buffer) (asn uint32, err erro } func (pa *PathAttribute) decode2ByteASN(buf *bytes.Buffer) (asn uint32, err error) { - asn4 := uint16(0) - err = decode.Decode(buf, []interface{}{&asn4}) + asn2 := uint16(0) + err = decode.DecodeUint16(buf, &asn2) if err != nil { return 0, err } - return uint32(asn4), nil + return uint32(asn2), nil } func (pa *PathAttribute) decodeNextHop(buf *bytes.Buffer) error { @@ -313,11 +319,25 @@ func (pa *PathAttribute) decodeNextHop(buf *bytes.Buffer) error { } func (pa *PathAttribute) decodeMED(buf *bytes.Buffer) error { - return pa.decodeUint32(buf, "MED") + med := uint32(0) + err := decode.DecodeUint32(buf, &med) + if err != nil { + return err + } + + pa.Value = med + return nil } func (pa *PathAttribute) decodeLocalPref(buf *bytes.Buffer) error { - return pa.decodeUint32(buf, "local pref") + lp := uint32(0) + err := decode.DecodeUint32(buf, &lp) + if err != nil { + return err + } + + pa.Value = lp + return nil } func (pa *PathAttribute) decodeAggregator(buf *bytes.Buffer) error { @@ -437,17 +457,19 @@ func (pa *PathAttribute) decodeClusterList(buf *bytes.Buffer) error { func (pa *PathAttribute) setLength(buf *bytes.Buffer) (int, error) { bytesRead := 0 if pa.ExtendedLength { - err := decode.Decode(buf, []interface{}{&pa.Length}) + err := decode.DecodeUint16(buf, &pa.Length) if err != nil { return 0, err } + bytesRead = 2 } else { x := uint8(0) - err := decode.Decode(buf, []interface{}{&x}) + err := decode.DecodeUint8(buf, &x) if err != nil { return 0, err } + pa.Length = uint16(x) bytesRead = 1 } @@ -473,11 +495,14 @@ func dumpNBytes(buf *bytes.Buffer, n uint16) error { if n <= 0 { return nil } - dump := make([]byte, n) - err := decode.Decode(buf, []interface{}{&dump}) - if err != nil { - return err + + for i := uint16(0); i < n; i++ { + _, err := buf.ReadByte() + if err != nil { + return err + } } + return nil } diff --git a/protocols/bgp/packet/path_attributes_test.go b/protocols/bgp/packet/path_attributes_test.go index 9d62873c6368950a8961c247e0f1590b95d2e4f4..1d8c0e7469a20ea2dc8e80be17e14bd225120525 100644 --- a/protocols/bgp/packet/path_attributes_test.go +++ b/protocols/bgp/packet/path_attributes_test.go @@ -53,7 +53,7 @@ func TestDecodePathAttrs(t *testing.T) { Next: &PathAttribute{ TypeCode: 3, Length: 4, - Value: bnet.IPv4FromOctets(10, 20, 30, 40), + Value: bnet.IPv4FromOctets(10, 20, 30, 40).Ptr(), }, }, }, @@ -215,7 +215,7 @@ func TestDecodePathAttr(t *testing.T) { Partial: false, ExtendedLength: false, TypeCode: OriginatorIDAttr, - Value: bnet.IPv4FromOctets(1, 2, 3, 4).ToUint32(), + Value: bnet.IPv4FromOctets(1, 2, 3, 4).Ptr().ToUint32(), }, }, { @@ -232,7 +232,7 @@ func TestDecodePathAttr(t *testing.T) { Optional: true, Length: 4, Value: &types.ClusterList{ - bnet.IPv4FromOctets(1, 1, 1, 1).ToUint32(), + bnet.IPv4FromOctets(1, 1, 1, 1).Ptr().ToUint32(), }, }, }, @@ -250,7 +250,7 @@ func TestDecodePathAttr(t *testing.T) { Optional: true, Length: 8, Value: &types.ClusterList{ - bnet.IPv4FromOctets(1, 2, 3, 4).ToUint32(), bnet.IPv4FromOctets(8, 8, 8, 8).ToUint32(), + bnet.IPv4FromOctets(1, 2, 3, 4).Ptr().ToUint32(), bnet.IPv4FromOctets(8, 8, 8, 8).Ptr().ToUint32(), }, }, }, @@ -489,7 +489,7 @@ func TestDecodeNextHop(t *testing.T) { wantFail: false, expected: &PathAttribute{ Length: 4, - Value: bnet.IPv4FromOctets(10, 20, 30, 40), + Value: bnet.IPv4FromOctets(10, 20, 30, 40).Ptr(), }, }, { @@ -658,7 +658,7 @@ func TestDecodeAggregator(t *testing.T) { Length: 6, Value: types.Aggregator{ ASN: 222, - Address: bnet.IPv4FromOctets(10, 20, 30, 40).ToUint32(), + Address: bnet.IPv4FromOctets(10, 20, 30, 40).Ptr().ToUint32(), }, }, }, @@ -864,7 +864,7 @@ func TestDecodeClusterList(t *testing.T) { expected: &PathAttribute{ Length: 4, Value: &types.ClusterList{ - bnet.IPv4FromOctets(1, 1, 1, 1).ToUint32(), + bnet.IPv4FromOctets(1, 1, 1, 1).Ptr().ToUint32(), }, }, }, @@ -877,7 +877,7 @@ func TestDecodeClusterList(t *testing.T) { expected: &PathAttribute{ Length: 8, Value: &types.ClusterList{ - bnet.IPv4FromOctets(1, 2, 3, 4).ToUint32(), bnet.IPv4FromOctets(8, 8, 8, 8).ToUint32(), + bnet.IPv4FromOctets(1, 2, 3, 4).Ptr().ToUint32(), bnet.IPv4FromOctets(8, 8, 8, 8).Ptr().ToUint32(), }, }, }, @@ -946,9 +946,9 @@ func TestDecodeMultiProtocolReachNLRI(t *testing.T) { Value: MultiProtocolReachNLRI{ AFI: IPv6AFI, SAFI: UnicastSAFI, - NextHop: bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0x2), + NextHop: bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0x2).Ptr(), NLRI: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2600, 0x6, 0xff05, 0, 0, 0, 0, 0), 48), + Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2600, 0x6, 0xff05, 0, 0, 0, 0, 0), 48).Ptr(), }, }, }, @@ -982,7 +982,7 @@ func TestDecodeMultiProtocolReachNLRI(t *testing.T) { Value: MultiProtocolReachNLRI{ AFI: IPv6AFI, SAFI: UnicastSAFI, - NextHop: bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0x2), + NextHop: bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0x2).Ptr(), }, }, }, @@ -1056,7 +1056,7 @@ func TestDecodeMultiProtocolUnreachNLRI(t *testing.T) { AFI: IPv6AFI, SAFI: UnicastSAFI, NLRI: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2620, 0x110, 0x9000, 0, 0, 0, 0, 0), 44), + Prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2620, 0x110, 0x9000, 0, 0, 0, 0, 0), 44).Ptr(), }, }, }, @@ -1368,7 +1368,7 @@ func TestSerializeNextHop(t *testing.T) { name: "Test #1", input: &PathAttribute{ TypeCode: NextHopAttr, - Value: bnet.IPv4FromOctets(100, 110, 120, 130), + Value: bnet.IPv4FromOctets(100, 110, 120, 130).Ptr(), }, expected: []byte{64, 3, 4, 100, 110, 120, 130}, expectedLen: 7, @@ -1503,7 +1503,7 @@ func TestSerializeAggregator(t *testing.T) { TypeCode: AggregatorAttr, Value: types.Aggregator{ ASN: 174, - Address: bnet.IPv4FromOctets(10, 20, 30, 40).ToUint32(), + Address: bnet.IPv4FromOctets(10, 20, 30, 40).Ptr().ToUint32(), }, }, expected: []byte{ @@ -1722,7 +1722,7 @@ func TestSerializeOriginatorID(t *testing.T) { name: "Valid OriginatorID", input: &PathAttribute{ TypeCode: OriginatorIDAttr, - Value: bnet.IPv4FromOctets(1, 1, 1, 1).ToUint32(), + Value: bnet.IPv4FromOctets(1, 1, 1, 1).Ptr().ToUint32(), }, expected: []byte{ setOptional(uint8(0)), // Attribute flags @@ -1768,7 +1768,7 @@ func TestSerializeClusterList(t *testing.T) { input: &PathAttribute{ TypeCode: ClusterListAttr, Value: &types.ClusterList{ - bnet.IPv4FromOctets(1, 1, 1, 1).ToUint32(), + bnet.IPv4FromOctets(1, 1, 1, 1).Ptr().ToUint32(), }, }, expected: []byte{ @@ -1784,8 +1784,8 @@ func TestSerializeClusterList(t *testing.T) { input: &PathAttribute{ TypeCode: ClusterListAttr, Value: &types.ClusterList{ - bnet.IPv4FromOctets(1, 1, 1, 1).ToUint32(), - bnet.IPv4FromOctets(192, 168, 23, 42).ToUint32(), + bnet.IPv4FromOctets(1, 1, 1, 1).Ptr().ToUint32(), + bnet.IPv4FromOctets(192, 168, 23, 42).Ptr().ToUint32(), }, }, expected: []byte{ @@ -1887,7 +1887,7 @@ func TestSerialize(t *testing.T) { name: "Withdraw only", msg: &BGPUpdate{ WithdrawnRoutes: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(100, 110, 120, 0), 24), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(100, 110, 120, 0), 24).Ptr(), }, }, expected: []byte{ @@ -1903,7 +1903,7 @@ func TestSerialize(t *testing.T) { name: "NLRI only", msg: &BGPUpdate{ NLRI: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(100, 110, 128, 0), 17), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(100, 110, 128, 0), 17).Ptr(), }, }, expected: []byte{ @@ -1941,9 +1941,9 @@ func TestSerialize(t *testing.T) { name: "Full test", msg: &BGPUpdate{ WithdrawnRoutes: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16).Ptr(), }, }, PathAttributes: &PathAttribute{ @@ -1963,7 +1963,7 @@ func TestSerialize(t *testing.T) { }, Next: &PathAttribute{ TypeCode: NextHopAttr, - Value: bnet.IPv4FromOctets(10, 20, 30, 40), + Value: bnet.IPv4FromOctets(10, 20, 30, 40).Ptr(), Next: &PathAttribute{ TypeCode: MEDAttr, Value: uint32(100), @@ -1976,7 +1976,7 @@ func TestSerialize(t *testing.T) { TypeCode: AggregatorAttr, Value: types.Aggregator{ ASN: 200, - Address: bnet.IPv4FromOctets(10, 20, 30, 40).ToUint32(), + Address: bnet.IPv4FromOctets(10, 20, 30, 40).Ptr().ToUint32(), }, }, }, @@ -1986,9 +1986,9 @@ func TestSerialize(t *testing.T) { }, }, NLRI: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(8, 8, 8, 0), 24), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(8, 8, 8, 0), 24).Ptr(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(185, 65, 240, 0), 22), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(185, 65, 240, 0), 22).Ptr(), }, }, }, @@ -2084,7 +2084,7 @@ func TestSerializeAddPath(t *testing.T) { msg: &BGPUpdate{ WithdrawnRoutes: &NLRI{ PathIdentifier: 257, - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(100, 110, 120, 0), 24), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(100, 110, 120, 0), 24).Ptr(), }, }, expected: []byte{ @@ -2102,7 +2102,7 @@ func TestSerializeAddPath(t *testing.T) { msg: &BGPUpdate{ NLRI: &NLRI{ PathIdentifier: 257, - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(100, 110, 128, 0), 17), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(100, 110, 128, 0), 17).Ptr(), }, }, expected: []byte{ @@ -2141,9 +2141,9 @@ func TestSerializeAddPath(t *testing.T) { name: "Full test", msg: &BGPUpdate{ WithdrawnRoutes: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16).Ptr(), }, }, PathAttributes: &PathAttribute{ @@ -2163,7 +2163,7 @@ func TestSerializeAddPath(t *testing.T) { }, Next: &PathAttribute{ TypeCode: NextHopAttr, - Value: bnet.IPv4FromOctets(10, 20, 30, 40), + Value: bnet.IPv4FromOctets(10, 20, 30, 40).Ptr(), Next: &PathAttribute{ TypeCode: MEDAttr, Value: uint32(100), @@ -2176,7 +2176,7 @@ func TestSerializeAddPath(t *testing.T) { TypeCode: AggregatorAttr, Value: types.Aggregator{ ASN: 200, - Address: bnet.IPv4FromOctets(10, 20, 30, 40).ToUint32(), + Address: bnet.IPv4FromOctets(10, 20, 30, 40).Ptr().ToUint32(), }, }, }, @@ -2186,9 +2186,9 @@ func TestSerializeAddPath(t *testing.T) { }, }, NLRI: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(8, 8, 8, 0), 24), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(8, 8, 8, 0), 24).Ptr(), Next: &NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(185, 65, 240, 0), 22), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(185, 65, 240, 0), 22).Ptr(), }, }, }, diff --git a/protocols/bgp/server/bgp_api_test.go b/protocols/bgp/server/bgp_api_test.go index 879b6d4657ff4105391b481a587ffe7307f9577e..0192dc94739446c04472c762d411bd9b93a8dc17 100644 --- a/protocols/bgp/server/bgp_api_test.go +++ b/protocols/bgp/server/bgp_api_test.go @@ -56,7 +56,7 @@ func TestDumpRIBInOut(t *testing.T) { srv: &bgpServer{ peers: &peerManager{ peers: map[bnet.IP]*peer{ - *bnet.IPv4FromOctets(10, 0, 0, 0): { + bnet.IPv4FromOctets(10, 0, 0, 0): { fsms: []*FSM{ 0: { ipv4Unicast: &fsmAddressFamily{ @@ -85,13 +85,13 @@ func TestDumpRIBInOut(t *testing.T) { srv: &bgpServer{ peers: &peerManager{ peers: map[bnet.IP]*peer{ - *bnet.IPv4FromOctets(10, 0, 0, 0): { - addr: bnet.IPv4(123), + bnet.IPv4FromOctets(10, 0, 0, 0): { + addr: bnet.IPv4(123).Ptr(), fsms: []*FSM{ 0: { ipv4Unicast: &fsmAddressFamily{ adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, 0, 0, true), - adjRIBOut: adjRIBOut.New(nil, &routingtable.Neighbor{Type: route.BGPPathType, RouteServerClient: true, Address: bnet.IPv4(0)}, filter.NewAcceptAllFilterChain(), false), + adjRIBOut: adjRIBOut.New(nil, &routingtable.Neighbor{Type: route.BGPPathType, RouteServerClient: true, Address: bnet.IPv4(0).Ptr()}, filter.NewAcceptAllFilterChain(), false), }, }, }, @@ -101,13 +101,13 @@ func TestDumpRIBInOut(t *testing.T) { }, }, addRoutes: []*route.Route{ - route.NewRoute(bnet.NewPfx(bnet.IPv4FromOctets(20, 0, 0, 0), 16), &route.Path{ + route.NewRoute(bnet.NewPfx(bnet.IPv4FromOctets(20, 0, 0, 0), 16).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ OriginatorID: 1, - NextHop: bnet.IPv4FromOctets(100, 100, 100, 100), - Source: bnet.IPv4FromOctets(100, 100, 100, 100), + NextHop: bnet.IPv4FromOctets(100, 100, 100, 100).Ptr(), + Source: bnet.IPv4FromOctets(100, 100, 100, 100).Ptr(), }, }, }), @@ -145,13 +145,13 @@ func TestDumpRIBInOut(t *testing.T) { srv: &bgpServer{ peers: &peerManager{ peers: map[bnet.IP]*peer{ - *bnet.IPv4FromOctets(10, 0, 0, 0): { - addr: bnet.IPv4(123), + bnet.IPv4FromOctets(10, 0, 0, 0): { + addr: bnet.IPv4(123).Ptr(), fsms: []*FSM{ 0: { ipv4Unicast: &fsmAddressFamily{ adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), 0, 0, true), - adjRIBOut: adjRIBOut.New(nil, &routingtable.Neighbor{Type: route.BGPPathType, RouteServerClient: true, Address: bnet.IPv4(123)}, filter.NewAcceptAllFilterChain(), false), + adjRIBOut: adjRIBOut.New(nil, &routingtable.Neighbor{Type: route.BGPPathType, RouteServerClient: true, Address: bnet.IPv4(123).Ptr()}, filter.NewAcceptAllFilterChain(), false), }, }, }, @@ -161,13 +161,13 @@ func TestDumpRIBInOut(t *testing.T) { }, }, addRoutes: []*route.Route{ - route.NewRoute(bnet.NewPfx(bnet.IPv4FromOctets(20, 0, 0, 0), 16), &route.Path{ + route.NewRoute(bnet.NewPfx(bnet.IPv4FromOctets(20, 0, 0, 0), 16).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ OriginatorID: 1, - NextHop: bnet.IPv4FromOctets(100, 100, 100, 100), - Source: bnet.IPv4FromOctets(100, 100, 100, 100), + NextHop: bnet.IPv4FromOctets(100, 100, 100, 100).Ptr(), + Source: bnet.IPv4FromOctets(100, 100, 100, 100).Ptr(), LocalPref: 1000, MED: 2000, }, @@ -252,7 +252,7 @@ func TestDumpRIBInOut(t *testing.T) { for _, test := range tests { for _, r := range test.addRoutes { for _, p := range r.Paths() { - test.apisrv.srv.(*bgpServer).peers.peers[*bnet.IPv4FromOctets(10, 0, 0, 0)].fsms[0].ipv4Unicast.adjRIBIn.AddPath(r.Prefix(), p) + test.apisrv.srv.(*bgpServer).peers.peers[bnet.IPv4FromOctets(10, 0, 0, 0)].fsms[0].ipv4Unicast.adjRIBIn.AddPath(r.Prefix(), p) } } @@ -298,7 +298,7 @@ func TestDumpRIBInOut(t *testing.T) { for _, test := range tests { for _, r := range test.addRoutes { for _, p := range r.Paths() { - test.apisrv.srv.(*bgpServer).peers.peers[*bnet.IPv4FromOctets(10, 0, 0, 0)].fsms[0].ipv4Unicast.adjRIBOut.AddPath(r.Prefix(), p) + test.apisrv.srv.(*bgpServer).peers.peers[bnet.IPv4FromOctets(10, 0, 0, 0)].fsms[0].ipv4Unicast.adjRIBOut.AddPath(r.Prefix(), p) } } diff --git a/protocols/bgp/server/bmp_router.go b/protocols/bgp/server/bmp_router.go index 19ae4441426ba2197a1fa389e8e946484f2fc926..01a5952813210b610b4cc85213a3e954225469fc 100644 --- a/protocols/bgp/server/bmp_router.go +++ b/protocols/bgp/server/bmp_router.go @@ -279,8 +279,8 @@ func (r *Router) processPeerUpNotification(msg *bmppkt.PeerUpNotification) error isBMP: true, peer: &peer{ routerID: sentOpen.BGPIdentifier, - addr: peerAddress, - localAddr: localAddress, + addr: peerAddress.Dedup(), + localAddr: localAddress.Dedup(), peerASN: msg.PerPeerHeader.PeerAS, localASN: uint32(sentOpen.ASN), ipv4: &peerAddressFamily{}, diff --git a/protocols/bgp/server/bmp_server_test.go b/protocols/bgp/server/bmp_server_test.go index 49dadd6951e0594bfec68d2b0315a954b930f3a4..7f8c605eb2f7d3e54974d2ac3181b00dc44805e3 100644 --- a/protocols/bgp/server/bmp_server_test.go +++ b/protocols/bgp/server/bmp_server_test.go @@ -270,7 +270,7 @@ func TestBMPServer(t *testing.T) { return } - route := lr.Get(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8)) + route := lr.Get(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr()) if route == nil { t.Errorf("Expected route not found") return @@ -303,7 +303,7 @@ func TestBMPServer(t *testing.T) { return } - route = lr.Get(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8)) + route = lr.Get(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr()) if route != nil { t.Errorf("Unexpected route found") return diff --git a/protocols/bgp/server/fsm_established.go b/protocols/bgp/server/fsm_established.go index 15bbe7877a87e8a6aa73c1042370317523ed1199..c21ef2235d9e6cb7c20af95e27b5c5b50c44ac78 100644 --- a/protocols/bgp/server/fsm_established.go +++ b/protocols/bgp/server/fsm_established.go @@ -81,7 +81,7 @@ func (s *establishedState) init() error { IBGP: s.fsm.peer.localASN == s.fsm.peer.peerASN, LocalASN: s.fsm.peer.localASN, RouteServerClient: s.fsm.peer.routeServerClient, - LocalAddress: localAddr, + LocalAddress: localAddr.Dedup(), RouteReflectorClient: s.fsm.peer.routeReflectorClient, ClusterID: s.fsm.peer.clusterID, } diff --git a/protocols/bgp/server/fsm_test.go b/protocols/bgp/server/fsm_test.go index 35e5e4bb726fb8dae1499a49edf5eab49ef249cf..6dfc54ff97830ba06af67ef34de0cdd56f16c00c 100644 --- a/protocols/bgp/server/fsm_test.go +++ b/protocols/bgp/server/fsm_test.go @@ -15,8 +15,8 @@ import ( // TestFSM255UpdatesIPv4 emulates receiving 255 BGP updates and withdraws. Checks route counts. func TestFSM255UpdatesIPv4(t *testing.T) { fsmA := newFSM(&peer{ - addr: bnet.IPv4FromOctets(169, 254, 100, 100), - routerID: bnet.IPv4FromOctets(1, 1, 1, 1).ToUint32(), + addr: bnet.IPv4FromOctets(169, 254, 100, 100).Ptr(), + routerID: bnet.IPv4FromOctets(1, 1, 1, 1).Ptr().ToUint32(), ipv4: &peerAddressFamily{ rib: locRIB.New("inet.0"), importFilterChain: filter.NewAcceptAllFilterChain(), @@ -134,8 +134,8 @@ func TestFSM255UpdatesIPv4(t *testing.T) { // TestFSM255UpdatesIPv6 emulates receiving 255 BGP updates and withdraws. Checks route counts. func TestFSM255UpdatesIPv6(t *testing.T) { fsmA := newFSM(&peer{ - addr: bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0xffff, 0, 0, 0, 1), - routerID: bnet.IPv4FromOctets(1, 1, 1, 1).ToUint32(), + addr: bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0xffff, 0, 0, 0, 1).Ptr(), + routerID: bnet.IPv4FromOctets(1, 1, 1, 1).Ptr().ToUint32(), ipv6: &peerAddressFamily{ rib: locRIB.New("inet6.0"), importFilterChain: filter.NewAcceptAllFilterChain(), diff --git a/protocols/bgp/server/metrics_service_test.go b/protocols/bgp/server/metrics_service_test.go index 9415c6331426994ed8c0932c4d59dc0c4e89f767..029dbb79131a6de48775fccf5b4954cbd2a2c164 100644 --- a/protocols/bgp/server/metrics_service_test.go +++ b/protocols/bgp/server/metrics_service_test.go @@ -35,7 +35,7 @@ func TestMetrics(t *testing.T) { peer: &peer{ peerASN: 202739, localASN: 201701, - addr: bnet.IPv4(100), + addr: bnet.IPv4(100).Ptr(), ipv4: &peerAddressFamily{}, ipv6: &peerAddressFamily{}, vrf: vrf, @@ -50,7 +50,7 @@ func TestMetrics(t *testing.T) { expected: &metrics.BGPMetrics{ Peers: []*metrics.BGPPeerMetrics{ { - IP: bnet.IPv4(100), + IP: bnet.IPv4(100).Ptr(), ASN: 202739, LocalASN: 201701, UpdatesReceived: 3, @@ -82,7 +82,7 @@ func TestMetrics(t *testing.T) { peer: &peer{ peerASN: 202739, localASN: 201701, - addr: bnet.IPv4(100), + addr: bnet.IPv4(100).Ptr(), ipv4: &peerAddressFamily{}, ipv6: &peerAddressFamily{}, vrf: vrf, @@ -91,7 +91,7 @@ func TestMetrics(t *testing.T) { expected: &metrics.BGPMetrics{ Peers: []*metrics.BGPPeerMetrics{ { - IP: bnet.IPv4(100), + IP: bnet.IPv4(100).Ptr(), ASN: 202739, LocalASN: 201701, VRF: "inet.0", @@ -115,7 +115,7 @@ func TestMetrics(t *testing.T) { peer: &peer{ peerASN: 202739, localASN: 201701, - addr: bnet.IPv4(100), + addr: bnet.IPv4(100).Ptr(), ipv4: &peerAddressFamily{}, ipv6: &peerAddressFamily{}, vrf: vrf, @@ -124,7 +124,7 @@ func TestMetrics(t *testing.T) { expected: &metrics.BGPMetrics{ Peers: []*metrics.BGPPeerMetrics{ { - IP: bnet.IPv4(100), + IP: bnet.IPv4(100).Ptr(), ASN: 202739, LocalASN: 201701, VRF: "inet.0", @@ -148,7 +148,7 @@ func TestMetrics(t *testing.T) { peer: &peer{ peerASN: 202739, localASN: 201701, - addr: bnet.IPv4(100), + addr: bnet.IPv4(100).Ptr(), ipv4: &peerAddressFamily{}, ipv6: &peerAddressFamily{}, vrf: vrf, @@ -157,7 +157,7 @@ func TestMetrics(t *testing.T) { expected: &metrics.BGPMetrics{ Peers: []*metrics.BGPPeerMetrics{ { - IP: bnet.IPv4(100), + IP: bnet.IPv4(100).Ptr(), ASN: 202739, LocalASN: 201701, VRF: "inet.0", @@ -181,7 +181,7 @@ func TestMetrics(t *testing.T) { peer: &peer{ peerASN: 202739, localASN: 201701, - addr: bnet.IPv4(100), + addr: bnet.IPv4(100).Ptr(), ipv4: &peerAddressFamily{}, ipv6: &peerAddressFamily{}, vrf: vrf, @@ -190,7 +190,7 @@ func TestMetrics(t *testing.T) { expected: &metrics.BGPMetrics{ Peers: []*metrics.BGPPeerMetrics{ { - IP: bnet.IPv4(100), + IP: bnet.IPv4(100).Ptr(), ASN: 202739, LocalASN: 201701, VRF: "inet.0", @@ -214,7 +214,7 @@ func TestMetrics(t *testing.T) { peer: &peer{ peerASN: 202739, localASN: 201701, - addr: bnet.IPv4(100), + addr: bnet.IPv4(100).Ptr(), ipv4: &peerAddressFamily{}, ipv6: &peerAddressFamily{}, vrf: vrf, @@ -223,7 +223,7 @@ func TestMetrics(t *testing.T) { expected: &metrics.BGPMetrics{ Peers: []*metrics.BGPPeerMetrics{ { - IP: bnet.IPv4(100), + IP: bnet.IPv4(100).Ptr(), ASN: 202739, LocalASN: 201701, VRF: "inet.0", @@ -248,7 +248,7 @@ func TestMetrics(t *testing.T) { peer: &peer{ peerASN: 202739, localASN: 201701, - addr: bnet.IPv4(100), + addr: bnet.IPv4(100).Ptr(), ipv4: &peerAddressFamily{}, ipv6: &peerAddressFamily{}, vrf: vrf, @@ -256,7 +256,7 @@ func TestMetrics(t *testing.T) { expected: &metrics.BGPMetrics{ Peers: []*metrics.BGPPeerMetrics{ { - IP: bnet.IPv4(100), + IP: bnet.IPv4(100).Ptr(), ASN: 202739, LocalASN: 201701, VRF: "inet.0", diff --git a/protocols/bgp/server/peer_manager_test.go b/protocols/bgp/server/peer_manager_test.go index cad435b70daf91897aaa2bf3e3bdd3815d5825c4..e0a09cd3bae3b2cb9394428a523032eee45a34be 100644 --- a/protocols/bgp/server/peer_manager_test.go +++ b/protocols/bgp/server/peer_manager_test.go @@ -9,7 +9,7 @@ import ( ) func TestAdd(t *testing.T) { - ip := bnet.IPv4FromOctets(192, 168, 0, 1) + ip := bnet.IPv4FromOctets(192, 168, 0, 1).Ptr() p := &peer{ addr: ip, } @@ -22,7 +22,7 @@ func TestAdd(t *testing.T) { } func TestRemove(t *testing.T) { - ip := bnet.IPv4FromOctets(192, 168, 0, 1) + ip := bnet.IPv4FromOctets(192, 168, 0, 1).Ptr() p := &peer{ addr: ip, } @@ -36,7 +36,7 @@ func TestRemove(t *testing.T) { } func TestGet(t *testing.T) { - ip := bnet.IPv4FromOctets(192, 168, 0, 1) + ip := bnet.IPv4FromOctets(192, 168, 0, 1).Ptr() p := &peer{ addr: ip, } @@ -50,10 +50,10 @@ func TestGet(t *testing.T) { func TestList(t *testing.T) { p1 := &peer{ - addr: bnet.IPv4FromOctets(192, 168, 0, 1), + addr: bnet.IPv4FromOctets(192, 168, 0, 1).Ptr(), } p2 := &peer{ - addr: bnet.IPv4FromOctets(192, 168, 0, 2), + addr: bnet.IPv4FromOctets(192, 168, 0, 2).Ptr(), } m := newPeerManager() diff --git a/protocols/bgp/server/server.go b/protocols/bgp/server/server.go index 7b4483b1eb873ff6acd0b7608dd43f1d84431ca1..a31a3589aae4479d89370dd21c59a99821a83c92 100644 --- a/protocols/bgp/server/server.go +++ b/protocols/bgp/server/server.go @@ -158,7 +158,7 @@ func (b *bgpServer) incomingConnectionWorker() { c := <-b.acceptCh peerAddr, _ := bnetutils.BIONetIPFromAddr(c.RemoteAddr().String()) - peer := b.peers.get(peerAddr) + peer := b.peers.get(peerAddr.Dedup()) if peer == nil { c.Close() log.WithFields(log.Fields{ diff --git a/protocols/bgp/server/update_helper_test.go b/protocols/bgp/server/update_helper_test.go index 3b8ec458dd0df0d18357ac210d4f1afacbc30d33..858af85b0d27ef739263810e7308607aad18ccb3 100644 --- a/protocols/bgp/server/update_helper_test.go +++ b/protocols/bgp/server/update_helper_test.go @@ -48,9 +48,9 @@ func TestSerializeAndSendUpdate(t *testing.T) { testUpdate: &packet.BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &packet.NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), Next: &packet.NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16).Ptr(), }, }, }, @@ -76,9 +76,9 @@ func TestSerializeAndSendUpdate(t *testing.T) { testUpdate: &packet.BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &packet.NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), Next: &packet.NLRI{ - Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16), + Prefix: bnet.NewPfx(bnet.IPv4FromOctets(192, 168, 0, 0), 16).Ptr(), }, }, }, diff --git a/protocols/bgp/server/update_sender_test.go b/protocols/bgp/server/update_sender_test.go index 528eb698189da34520c8567506c3118df271906e..d2e438ccdc69e3db2798f86a11904dad9f9afe16 100644 --- a/protocols/bgp/server/update_sender_test.go +++ b/protocols/bgp/server/update_sender_test.go @@ -38,17 +38,17 @@ func TestSender(t *testing.T) { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 100, - NextHop: bnet.IPv4(0), - Source: bnet.IPv4(0), + NextHop: bnet.IPv4(0).Ptr(), + Source: bnet.IPv4(0).Ptr(), }, ASPath: &types.ASPath{}, }, }, pfxs: []*bnet.Prefix{ - bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), - bnet.NewPfx(bnet.IPv4FromOctets(11, 0, 0, 0), 8), - bnet.NewPfx(bnet.IPv4FromOctets(12, 0, 0, 0), 8), - bnet.NewPfx(bnet.IPv4FromOctets(13, 0, 0, 0), 32), + bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), + bnet.NewPfx(bnet.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), + bnet.NewPfx(bnet.IPv4FromOctets(12, 0, 0, 0), 8).Ptr(), + bnet.NewPfx(bnet.IPv4FromOctets(13, 0, 0, 0), 32).Ptr(), }, }, { @@ -57,17 +57,17 @@ func TestSender(t *testing.T) { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 200, - NextHop: bnet.IPv4(0), - Source: bnet.IPv4(0), + NextHop: bnet.IPv4(0).Ptr(), + Source: bnet.IPv4(0).Ptr(), }, ASPath: &types.ASPath{}, }, }, pfxs: []*bnet.Prefix{ - bnet.NewPfx(bnet.IPv4FromOctets(20, 0, 0, 0), 8), - bnet.NewPfx(bnet.IPv4FromOctets(21, 0, 0, 0), 8), - bnet.NewPfx(bnet.IPv4FromOctets(22, 0, 0, 0), 8), - bnet.NewPfx(bnet.IPv4FromOctets(23, 0, 0, 0), 8), + bnet.NewPfx(bnet.IPv4FromOctets(20, 0, 0, 0), 8).Ptr(), + bnet.NewPfx(bnet.IPv4FromOctets(21, 0, 0, 0), 8).Ptr(), + bnet.NewPfx(bnet.IPv4FromOctets(22, 0, 0, 0), 8).Ptr(), + bnet.NewPfx(bnet.IPv4FromOctets(23, 0, 0, 0), 8).Ptr(), }, }, }, @@ -111,17 +111,17 @@ func TestSender(t *testing.T) { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 100, - NextHop: bnet.IPv4(0), - Source: bnet.IPv4(0), + NextHop: bnet.IPv4(0).Ptr(), + Source: bnet.IPv4(0).Ptr(), }, ASPath: &types.ASPath{}, }, }, pfxs: []*bnet.Prefix{ - bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), - bnet.NewPfx(bnet.IPv4FromOctets(11, 0, 0, 0), 8), - bnet.NewPfx(bnet.IPv4FromOctets(12, 0, 0, 0), 8), - bnet.NewPfx(bnet.IPv4FromOctets(13, 0, 0, 0), 32), + bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), + bnet.NewPfx(bnet.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), + bnet.NewPfx(bnet.IPv4FromOctets(12, 0, 0, 0), 8).Ptr(), + bnet.NewPfx(bnet.IPv4FromOctets(13, 0, 0, 0), 32).Ptr(), }, }, { @@ -130,17 +130,17 @@ func TestSender(t *testing.T) { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 200, - NextHop: bnet.IPv4(0), - Source: bnet.IPv4(0), + NextHop: bnet.IPv4(0).Ptr(), + Source: bnet.IPv4(0).Ptr(), }, ASPath: &types.ASPath{}, }, }, pfxs: []*bnet.Prefix{ - bnet.NewPfx(bnet.IPv4FromOctets(20, 0, 0, 0), 8), - bnet.NewPfx(bnet.IPv4FromOctets(21, 0, 0, 0), 8), - bnet.NewPfx(bnet.IPv4FromOctets(22, 0, 0, 0), 8), - bnet.NewPfx(bnet.IPv4FromOctets(23, 0, 0, 0), 8), + bnet.NewPfx(bnet.IPv4FromOctets(20, 0, 0, 0), 8).Ptr(), + bnet.NewPfx(bnet.IPv4FromOctets(21, 0, 0, 0), 8).Ptr(), + bnet.NewPfx(bnet.IPv4FromOctets(22, 0, 0, 0), 8).Ptr(), + bnet.NewPfx(bnet.IPv4FromOctets(23, 0, 0, 0), 8).Ptr(), }, }, }, @@ -200,8 +200,8 @@ func TestSender(t *testing.T) { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 100, - NextHop: bnet.IPv4(0), - Source: bnet.IPv4(0), + NextHop: bnet.IPv4(0).Ptr(), + Source: bnet.IPv4(0).Ptr(), }, ASPath: &types.ASPath{}, }, @@ -374,8 +374,8 @@ func TestSender(t *testing.T) { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 100, - NextHop: bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 2), - Source: bnet.IPv6(0, 0), + NextHop: bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 2).Ptr(), + Source: bnet.IPv6(0, 0).Ptr(), }, ASPath: &types.ASPath{}, }, @@ -901,7 +901,7 @@ func TestSender(t *testing.T) { for _, test := range tests { fsmA := newFSM(&peer{ - addr: bnet.IPv4FromOctets(169, 254, 100, 100), + addr: bnet.IPv4FromOctets(169, 254, 100, 100).Ptr(), }) rib := locRIB.New("inet6.0") @@ -940,9 +940,9 @@ func TestSender(t *testing.T) { var pfx *bnet.Prefix if test.afi == packet.IPv6AFI { - pfx = bnet.NewPfx(bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0), 48) + pfx = bnet.NewPfx(bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0), 48).Ptr() } else { - pfx = bnet.NewPfx(bnet.IPv4FromOctets(10, 0, uint8(x), uint8(y)), 32) + pfx = bnet.NewPfx(bnet.IPv4FromOctets(10, 0, uint8(x), uint8(y)), 32).Ptr() } updateSender.AddPath(pfx, pathPfx.path) @@ -990,7 +990,7 @@ func TestWithdrawPrefix(t *testing.T) { afi: packet.IPv4AFI, multiProtocol: false, addPathTX: routingtable.ClientOptions{MaxPaths: 10}, - prefix: bnet.NewPfx(bnet.IPv4(1413010532), 24), + prefix: bnet.NewPfx(bnet.IPv4(1413010532), 24).Ptr(), path: &route.Path{ Type: route.StaticPathType, }, @@ -1002,7 +1002,7 @@ func TestWithdrawPrefix(t *testing.T) { afi: packet.IPv4AFI, multiProtocol: false, addPathTX: routingtable.ClientOptions{MaxPaths: 10}, - prefix: bnet.NewPfx(bnet.IPv4(1413010532), 24), + prefix: bnet.NewPfx(bnet.IPv4(1413010532), 24).Ptr(), path: &route.Path{ Type: route.BGPPathType, }, @@ -1014,7 +1014,7 @@ func TestWithdrawPrefix(t *testing.T) { afi: packet.IPv4AFI, multiProtocol: false, addPathTX: routingtable.ClientOptions{MaxPaths: 10}, - prefix: bnet.NewPfx(bnet.IPv4(1413010532), 24), + prefix: bnet.NewPfx(bnet.IPv4(1413010532), 24).Ptr(), path: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ @@ -1038,7 +1038,7 @@ func TestWithdrawPrefix(t *testing.T) { afi: packet.IPv4AFI, multiProtocol: false, addPathTX: routingtable.ClientOptions{BestOnly: true}, - prefix: bnet.NewPfx(bnet.IPv4(1413010532), 24), + prefix: bnet.NewPfx(bnet.IPv4(1413010532), 24).Ptr(), path: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ @@ -1061,7 +1061,7 @@ func TestWithdrawPrefix(t *testing.T) { afi: packet.IPv6AFI, multiProtocol: true, addPathTX: routingtable.ClientOptions{BestOnly: true}, - prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2804, 0x148c, 0, 0, 0, 0, 0, 0), 32), + prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2804, 0x148c, 0, 0, 0, 0, 0, 0), 32).Ptr(), path: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{}, @@ -1085,7 +1085,7 @@ func TestWithdrawPrefix(t *testing.T) { afi: packet.IPv6AFI, multiProtocol: true, addPathTX: routingtable.ClientOptions{MaxPaths: 10}, - prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2804, 0x148c, 0, 0, 0, 0, 0, 0), 32), + prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2804, 0x148c, 0, 0, 0, 0, 0, 0), 32).Ptr(), path: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ @@ -1112,7 +1112,7 @@ func TestWithdrawPrefix(t *testing.T) { afi: packet.IPv6AFI, multiProtocol: false, addPathTX: routingtable.ClientOptions{BestOnly: true}, - prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2804, 0x148c, 0, 0, 0, 0, 0, 0), 32), + prefix: bnet.NewPfx(bnet.IPv6FromBlocks(0x2804, 0x148c, 0, 0, 0, 0, 0, 0), 32).Ptr(), path: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ diff --git a/protocols/bmp/server/router.go b/protocols/bmp/server/router.go deleted file mode 100644 index 27906afa8312bedef61f741819dc0440ad945eba..0000000000000000000000000000000000000000 --- a/protocols/bmp/server/router.go +++ /dev/null @@ -1,62 +0,0 @@ -package server - -import ( - "net" - "time" - - "github.com/bio-routing/bio-rd/protocols/bmp/packet" - "github.com/bio-routing/bio-rd/routingtable/locRIB" - "github.com/bio-routing/bio-rd/routingtable/vrf" - log "github.com/sirupsen/logrus" -) - -type router struct { - address net.IP - port uint16 - con net.Conn - reconnectTimeMin int - reconnectTimeMax int - reconnectTime int - reconnectTimer *time.Timer - rib4 *locRIB.LocRIB - rib6 *locRIB.LocRIB - vrfs []*vrf.VRF - msgCounter uint64 -} - -func (r *router) serve() { - for { - msg, err := recvMsg(r.con) - if err != nil { - log.Errorf("Unable to get message: %v", err) - return - } - r.msgCounter++ - - bmpMsg, err := packet.Decode(msg) - if err != nil { - log.Errorf("Unable to decode BMP message: %v", err) - return - } - - if r.msgCounter == 1 { - if bmpMsg.MsgType() != packet.InitiationMessageType { - log.Errorf("Invalid message type of first message (%d) for neighbor %s", bmpMsg.MsgType(), r.address.String()) - return - } - } - - switch bmpMsg.MsgType() { - case packet.TerminationMessageType: - log.Infof("BMP neighbor %s has sent a termination message", r.address.String()) - return - case packet.RouteMonitoringType: - r.processRouteMonitoringMsg(bmpMsg.(*packet.RouteMonitoringMsg)) - return - } - } -} - -func (r *router) processRouteMonitoringMsg(m *packet.RouteMonitoringMsg) { - -} diff --git a/protocols/bmp/server/server.go b/protocols/bmp/server/server.go deleted file mode 100644 index 413598b706d6e7abfe0f70877a4757256fb407bd..0000000000000000000000000000000000000000 --- a/protocols/bmp/server/server.go +++ /dev/null @@ -1,97 +0,0 @@ -package server - -import ( - "fmt" - "io" - "net" - "sync" - "time" - - "github.com/bio-routing/bio-rd/protocols/bgp/packet" - "github.com/bio-routing/bio-rd/routingtable/locRIB" - "github.com/bio-routing/bio-rd/routingtable/vrf" - "github.com/bio-routing/tflow2/convert" - "github.com/pkg/errors" - log "github.com/sirupsen/logrus" -) - -const ( - defaultBufferLen = 4096 -) - -// BMPServer represents a BMP speaker -type BMPServer struct { - routers map[string]*router - routersMu sync.RWMutex - reconnectTime uint -} - -// NewServer creates a new BMP server -func NewServer() *BMPServer { - return &BMPServer{ - routers: make(map[string]*router), - } -} - -// AddRouter adds a BMP session to a router to the BMP server -func (b *BMPServer) AddRouter(addr net.IP, port uint16, rib4 *locRIB.LocRIB, rib6 *locRIB.LocRIB) { - r := &router{ - address: addr, - port: port, - reconnectTimeMin: 30, // Suggested by RFC 7854 - reconnectTimeMax: 720, // Suggested by RFC 7854 - reconnectTimer: time.NewTimer(time.Duration(0)), - rib4: rib4, - rib6: rib6, - vrfs: make([]*vrf.VRF, 0), - } - - b.routersMu.Lock() - b.routers[fmt.Sprintf("%s:%d", r.address.String(), r.port)] = r - b.routersMu.Unlock() - - go func(r *router) { - for { - <-r.reconnectTimer.C - c, err := net.Dial("tcp", fmt.Sprintf("%s:%d", r.address.String(), r.port)) - if err != nil { - log.Infof("Unable to connect to BMP router: %v", err) - if r.reconnectTime == 0 { - r.reconnectTime = r.reconnectTimeMin - } else if r.reconnectTime < r.reconnectTimeMax { - r.reconnectTime *= 2 - } - r.reconnectTimer = time.NewTimer(time.Second * time.Duration(r.reconnectTime)) - continue - } - - r.reconnectTime = 0 - r.con = c - r.serve() - r.con.Close() - } - }(r) -} - -func recvMsg(c net.Conn) (msg []byte, err error) { - buffer := make([]byte, defaultBufferLen) - _, err = io.ReadFull(c, buffer[0:packet.MinLen]) - if err != nil { - return nil, errors.Wrap(err, "Read failed") - } - - l := convert.Uint32b(buffer[1:3]) - if l > defaultBufferLen { - tmp := buffer - buffer = make([]byte, l) - copy(buffer, tmp) - } - - toRead := l - _, err = io.ReadFull(c, buffer[packet.MinLen:toRead]) - if err != nil { - return nil, errors.Wrap(err, "Read failed") - } - - return buffer, nil -} diff --git a/protocols/device/device_test.go b/protocols/device/device_test.go index e743226cda16238111bf052636208c9816a6a30e..171506a6ed47f4391b00b353540cca44cbd16e9c 100644 --- a/protocols/device/device_test.go +++ b/protocols/device/device_test.go @@ -18,13 +18,13 @@ func TestDeviceCopy(t *testing.T) { dev: &Device{ Name: "Foo", Addrs: []*bnet.Prefix{ - bnet.NewPfx(bnet.IPv4(100), 8), + bnet.NewPfx(bnet.IPv4(100), 8).Ptr(), }, }, expected: &Device{ Name: "Foo", Addrs: []*bnet.Prefix{ - bnet.NewPfx(bnet.IPv4(100), 8), + bnet.NewPfx(bnet.IPv4(100), 8).Ptr(), }, }, }, @@ -32,7 +32,7 @@ func TestDeviceCopy(t *testing.T) { for _, test := range tests { copy := test.dev.copy() - test.dev.addAddr(bnet.NewPfx(bnet.IPv4(200), 8)) + test.dev.addAddr(bnet.NewPfx(bnet.IPv4(200), 8).Ptr()) assert.Equalf(t, test.expected, copy, "Test %q", test.name) } } @@ -48,16 +48,16 @@ func TestDeviceDelAddr(t *testing.T) { name: "Test #1", dev: &Device{ Addrs: []*bnet.Prefix{ - bnet.NewPfx(bnet.IPv4(100), 8), - bnet.NewPfx(bnet.IPv4(200), 8), - bnet.NewPfx(bnet.IPv4(300), 8), + bnet.NewPfx(bnet.IPv4(100), 8).Ptr(), + bnet.NewPfx(bnet.IPv4(200), 8).Ptr(), + bnet.NewPfx(bnet.IPv4(300), 8).Ptr(), }, }, - delete: bnet.NewPfx(bnet.IPv4(200), 8), + delete: bnet.NewPfx(bnet.IPv4(200), 8).Ptr(), expected: &Device{ Addrs: []*bnet.Prefix{ - bnet.NewPfx(bnet.IPv4(100), 8), - bnet.NewPfx(bnet.IPv4(300), 8), + bnet.NewPfx(bnet.IPv4(100), 8).Ptr(), + bnet.NewPfx(bnet.IPv4(300), 8).Ptr(), }, }, }, @@ -65,16 +65,16 @@ func TestDeviceDelAddr(t *testing.T) { name: "Test #2", dev: &Device{ Addrs: []*bnet.Prefix{ - bnet.NewPfx(bnet.IPv4(100), 8), - bnet.NewPfx(bnet.IPv4(200), 8), - bnet.NewPfx(bnet.IPv4(300), 8), + bnet.NewPfx(bnet.IPv4(100), 8).Ptr(), + bnet.NewPfx(bnet.IPv4(200), 8).Ptr(), + bnet.NewPfx(bnet.IPv4(300), 8).Ptr(), }, }, - delete: bnet.NewPfx(bnet.IPv4(100), 8), + delete: bnet.NewPfx(bnet.IPv4(100), 8).Ptr(), expected: &Device{ Addrs: []*bnet.Prefix{ - bnet.NewPfx(bnet.IPv4(200), 8), - bnet.NewPfx(bnet.IPv4(300), 8), + bnet.NewPfx(bnet.IPv4(200), 8).Ptr(), + bnet.NewPfx(bnet.IPv4(300), 8).Ptr(), }, }, }, @@ -97,14 +97,14 @@ func TestDeviceAddAddr(t *testing.T) { name: "Test #1", dev: &Device{ Addrs: []*bnet.Prefix{ - bnet.NewPfx(bnet.IPv4(100), 8), + bnet.NewPfx(bnet.IPv4(100), 8).Ptr(), }, }, - input: bnet.NewPfx(bnet.IPv4(200), 8), + input: bnet.NewPfx(bnet.IPv4(200), 8).Ptr(), expected: &Device{ Addrs: []*bnet.Prefix{ - bnet.NewPfx(bnet.IPv4(100), 8), - bnet.NewPfx(bnet.IPv4(200), 8), + bnet.NewPfx(bnet.IPv4(100), 8).Ptr(), + bnet.NewPfx(bnet.IPv4(200), 8).Ptr(), }, }, }, diff --git a/protocols/fib/fib.go b/protocols/fib/fib.go deleted file mode 100644 index a1b64fe25ad082928fd4156937476f303336dd80..0000000000000000000000000000000000000000 --- a/protocols/fib/fib.go +++ /dev/null @@ -1,44 +0,0 @@ -package fib - -import ( - "github.com/bio-routing/bio-rd/config" - "github.com/bio-routing/bio-rd/routingtable/locRIB" -) - -// FIB is forwarding information base -type FIB struct { - locRib *locRIB.LocRIB - - //writer *NetlinkWriter - //reader *NetlinkReader -} - -// NewFIB creates a new Netlink object and returns the pointer to it -func NewFIB(options *config.Netlink, locRib *locRIB.LocRIB) *FIB { - - n := &FIB{ - locRib: locRib, - //writer: NewNetlinkWriter(options), - //reader: NewNetlinkReader(options), - } - return n -} - -// Start the Netlink module -func (f *FIB) Start() { - // connect all RIBs - /*options := routingtable.ClientOptions{ - BestOnly: false, - EcmpOnly: false, - MaxPaths: ^uint(0), // max int - }*/ - - // 1. from locRib to Kernel - //f.locRib.RegisterWithOptions(n.writer, options) - - // 2. from Kernel to locRib - //f.reader.clientManager.RegisterWithOptions(n.locRib, options) - - // Listen for new routes from kernel - //go n.reader.Read() -} diff --git a/protocols/fib/fib_linux.go b/protocols/fib/fib_linux.go deleted file mode 100644 index 1448d39f6d0b2118dc338cd421df7e61181b5f1c..0000000000000000000000000000000000000000 --- a/protocols/fib/fib_linux.go +++ /dev/null @@ -1,138 +0,0 @@ -package fib - -import ( - "fmt" - - bnet "github.com/bio-routing/bio-rd/net" - "github.com/bio-routing/bio-rd/route" - "github.com/vishvananda/netlink" -) - -const ( - ProtoUnspec = 0 // unspec (from /etc/iproute2/rt_protos) - ProtoRedirect = 1 // redirect (from /etc/iproute2/rt_protos) - ProtoKernel = 2 // kernel (from /etc/iproute2/rt_protos) - ProtoBoot = 3 // boot (from /etc/iproute2/rt_protos) - ProtoStatic = 4 // static (from /etc/iproute2/rt_protos) - ProtoZebra = 11 // zebra (from /etc/iproute2/rt_protos) - ProtoBird = 12 // bird (from /etc/iproute2/rt_protos) - ProtoDHCP = 16 // dhcp (from /etc/iproute2/rt_protos) - ProtoBio = 45 // bio -) - -// NetlinkRouteDiff gets the list of elements contained by a but not b -func NetlinkRouteDiff(a, b []netlink.Route) []netlink.Route { - ret := make([]netlink.Route, 0) - - for _, pa := range a { - if !netlinkRoutesContains(pa, b) { - ret = append(ret, pa) - } - } - - return ret -} - -func netlinkRoutesContains(needle netlink.Route, haystack []netlink.Route) bool { - for i := range haystack { - if netlinkRouteEquals(&needle, &haystack[i]) { - return true - } - } - - return false -} - -func netlinkRouteEquals(a, b *netlink.Route) bool { - aMaskSize, aMaskBits := a.Dst.Mask.Size() - bMaskSize, bMaskBits := b.Dst.Mask.Size() - - return a.LinkIndex == b.LinkIndex && - a.ILinkIndex == b.ILinkIndex && - a.Scope == b.Scope && - - a.Dst.IP.Equal(b.Dst.IP) && - aMaskSize == bMaskSize && - aMaskBits == bMaskBits && - - a.Src.Equal(b.Src) && - a.Gw.Equal(b.Gw) && - - a.Protocol == b.Protocol && - a.Priority == b.Priority && - a.Table == b.Table && - a.Type == b.Type && - a.Tos == b.Tos && - a.Flags == b.Flags && - a.MTU == b.MTU && - a.AdvMSS == b.AdvMSS -} - -// NewNlPathFromRoute creates a new route.FIBPath object from a netlink.Route object -func NewPathsFromNlRoute(r netlink.Route, kernel bool) (*bnet.Prefix, []*route.Path, error) { - var src *bnet.IP - var dst *bnet.Prefix - - if r.Src == nil && r.Dst == nil { - return nil, nil, fmt.Errorf("Cannot create NlPath, since source and destination are both nil") - } - - if r.Src == nil && r.Dst != nil { - dst = bnet.NewPfxFromIPNet(r.Dst) - if dst.Addr().IsIPv4() { - src = bnet.IPv4(0) - } else { - src = bnet.IPv6(0, 0) - } - } - - if r.Src != nil && r.Dst == nil { - src, _ = bnet.IPFromBytes(r.Src) - if src.IsIPv4() { - dst = bnet.NewPfx(bnet.IPv4(0), 0) - } else { - dst = bnet.NewPfx(bnet.IPv6(0, 0), 0) - } - } - - if r.Src != nil && r.Dst != nil { - src, _ = bnet.IPFromBytes(r.Src) - dst = bnet.NewPfxFromIPNet(r.Dst) - } - - paths := make([]*route.Path, 0) - - if len(r.MultiPath) > 0 { - for _, multiPath := range r.MultiPath { - nextHop, _ := bnet.IPFromBytes(multiPath.Gw) - paths = append(paths, &route.Path{ - Type: route.FIBPathType, - FIBPath: &route.FIBPath{ - Src: src, - NextHop: nextHop, - Priority: r.Priority, - Protocol: r.Protocol, - Type: r.Type, - Table: r.Table, - Kernel: kernel, - }, - }) - } - } else { - nextHop, _ := bnet.IPFromBytes(r.Gw) - paths = append(paths, &route.Path{ - Type: route.FIBPathType, - FIBPath: &route.FIBPath{ - Src: src, - NextHop: nextHop, - Priority: r.Priority, - Protocol: r.Protocol, - Type: r.Type, - Table: r.Table, - Kernel: kernel, - }, - }) - } - - return dst, paths, nil -} diff --git a/protocols/fib/fib_linux_test.go b/protocols/fib/fib_linux_test.go deleted file mode 100644 index 28a0a589dd79cb640b2998d96ece6c14c585a5a1..0000000000000000000000000000000000000000 --- a/protocols/fib/fib_linux_test.go +++ /dev/null @@ -1,393 +0,0 @@ -package fib - -import ( - "net" - "testing" - - bnet "github.com/bio-routing/bio-rd/net" - "github.com/bio-routing/bio-rd/route" - "github.com/stretchr/testify/assert" - "github.com/vishvananda/netlink" -) - -func TestNetlinkRouteDiff(t *testing.T) { - tests := []struct { - name string - left []netlink.Route - right []netlink.Route - expected []netlink.Route - }{ - { - name: "Equal", - left: []netlink.Route{ - { - Dst: &net.IPNet{ - IP: net.IPv4(10, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 1, - }, - { - Dst: &net.IPNet{ - IP: net.IPv4(20, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 2, - }, - }, - right: []netlink.Route{ - { - Dst: &net.IPNet{ - IP: net.IPv4(10, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 1, - }, - { - Dst: &net.IPNet{ - IP: net.IPv4(20, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 2, - }, - }, - expected: []netlink.Route{}, - }, { - name: "Left empty", - left: []netlink.Route{}, - right: []netlink.Route{ - { - Dst: &net.IPNet{ - IP: net.IPv4(10, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 1, - }, - { - Dst: &net.IPNet{ - IP: net.IPv4(20, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 2, - }, - }, - expected: []netlink.Route{}, - }, { - name: "Right empty", - left: []netlink.Route{ - { - Dst: &net.IPNet{ - IP: net.IPv4(10, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 1, - }, - { - Dst: &net.IPNet{ - IP: net.IPv4(20, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 2, - }, - }, - right: []netlink.Route{}, - expected: []netlink.Route{ - { - Dst: &net.IPNet{ - IP: net.IPv4(10, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 1, - }, - { - Dst: &net.IPNet{ - IP: net.IPv4(20, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 2, - }, - }, - }, { - name: "Diff", - left: []netlink.Route{ - { - Dst: &net.IPNet{ - IP: net.IPv4(10, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 1, - }, - { - Dst: &net.IPNet{ - IP: net.IPv4(20, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 2, - }, - }, - right: []netlink.Route{ - { - Dst: &net.IPNet{ - IP: net.IPv4(10, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 1, - }, - }, - expected: []netlink.Route{ - { - Dst: &net.IPNet{ - IP: net.IPv4(20, 0, 0, 1), - Mask: net.IPv4Mask(255, 0, 0, 0), - }, - Table: 2, - }, - }, - }, - } - - for _, test := range tests { - res := NetlinkRouteDiff(test.left, test.right) - assert.Equal(t, test.expected, res) - } - -} - -func TestNewPathsFromNetlinkRoute(t *testing.T) { - tests := []struct { - name string - source netlink.Route - expectedPfx *bnet.Prefix - expectedPaths []*route.Path - expectError bool - }{ - { - name: "Simple", - source: netlink.Route{ - Dst: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).GetIPNet(), - Src: bnet.IPv4(456).Bytes(), - Gw: bnet.IPv4(789).Bytes(), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - }, - expectedPfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), - expectedPaths: []*route.Path{ - { - Type: route.FIBPathType, - FIBPath: &route.FIBPath{ - Src: bnet.IPv4(456), - NextHop: bnet.IPv4(789), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - Kernel: true, - }, - }, - }, - expectError: false, - }, - { - name: "Multiple nexthop", - source: netlink.Route{ - Dst: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).GetIPNet(), - Src: bnet.IPv4(456).Bytes(), - MultiPath: []*netlink.NexthopInfo{ - { - LinkIndex: 1, - Hops: 1, - Gw: bnet.IPv4(123).Bytes(), - Flags: 0, - NewDst: nil, - Encap: nil, - }, { - LinkIndex: 2, - Hops: 1, - Gw: bnet.IPv4(345).Bytes(), - Flags: 0, - NewDst: nil, - Encap: nil, - }, - }, - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - }, - expectedPfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), - expectedPaths: []*route.Path{ - { - Type: route.FIBPathType, - FIBPath: &route.FIBPath{ - Src: bnet.IPv4(456), - NextHop: bnet.IPv4(123), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - Kernel: true, - }, - }, { - Type: route.FIBPathType, - FIBPath: &route.FIBPath{ - Src: bnet.IPv4(456), - NextHop: bnet.IPv4(345), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - Kernel: true, - }, - }, - }, - expectError: false, - }, - { - name: "No source but destination", - source: netlink.Route{ - Dst: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).GetIPNet(), - Gw: bnet.IPv4(789).Bytes(), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - }, - expectedPfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), - expectedPaths: []*route.Path{ - { - Type: route.FIBPathType, - FIBPath: &route.FIBPath{ - Src: bnet.IPv4(0), - NextHop: bnet.IPv4(789), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - Kernel: true, - }, - }, - }, - expectError: false, - }, - { - name: "Source but no destination", - source: netlink.Route{ - Src: bnet.IPv4(456).Bytes(), - Gw: bnet.IPv4(789).Bytes(), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - }, - expectedPfx: bnet.NewPfx(bnet.IPv4FromOctets(0, 0, 0, 0), 0), - expectedPaths: []*route.Path{ - { - Type: route.FIBPathType, - FIBPath: &route.FIBPath{ - Src: bnet.IPv4(456), - NextHop: bnet.IPv4(789), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - Kernel: true, - }, - }, - }, - expectError: false, - }, - { - name: "No source but no destination", - source: netlink.Route{ - Gw: bnet.IPv4(789).Bytes(), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - }, - expectedPfx: nil, - expectedPaths: []*route.Path{}, - expectError: true, - }, - { - name: "No source but destination IPv6", - source: netlink.Route{ - Dst: bnet.NewPfx(bnet.IPv6(2001, 0), 48).GetIPNet(), - Gw: bnet.IPv6(2001, 123).Bytes(), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - }, - expectedPfx: bnet.NewPfx(bnet.IPv6(2001, 0), 48), - expectedPaths: []*route.Path{ - { - Type: route.FIBPathType, - FIBPath: &route.FIBPath{ - Src: bnet.IPv6(0, 0), - NextHop: bnet.IPv6(2001, 123), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - Kernel: true, - }, - }, - }, - expectError: false, - }, - { - name: "Source but no destination IPv6", - source: netlink.Route{ - Src: bnet.IPv6(2001, 456).Bytes(), - Gw: bnet.IPv6(2001, 789).Bytes(), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - }, - expectedPfx: bnet.NewPfx(bnet.IPv6(0, 0), 0), - expectedPaths: []*route.Path{ - { - Type: route.FIBPathType, - FIBPath: &route.FIBPath{ - Src: bnet.IPv6(2001, 456), - NextHop: bnet.IPv6(2001, 789), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - Kernel: true, - }, - }, - }, - expectError: false, - }, - { - name: "no source no destination", - source: netlink.Route{ - Gw: bnet.IPv4(123).Bytes(), - Protocol: ProtoKernel, - Priority: 1, - Table: 254, - Type: 1, - }, - expectedPfx: bnet.NewPfx(bnet.IPv4(0), 0), - expectedPaths: []*route.Path{{}}, - expectError: true, - }, - } - - for _, test := range tests { - pfx, paths, err := NewPathsFromNlRoute(test.source, true) - if test.expectError { - assert.Error(t, err) - } else { - assert.NoError(t, err) - assert.Equalf(t, test.expectedPaths, paths, test.name) - assert.Equalf(t, test.expectedPfx, pfx, test.name) - } - } -} diff --git a/protocols/fib/reader_linux.go b/protocols/fib/reader_linux.go deleted file mode 100644 index 5160440d9332ba9fec7a2e2994f7c5047ecacab4..0000000000000000000000000000000000000000 --- a/protocols/fib/reader_linux.go +++ /dev/null @@ -1,264 +0,0 @@ -package fib - -import ( - "fmt" - "sync" - "time" - - "github.com/bio-routing/bio-rd/config" - "github.com/bio-routing/bio-rd/net" - bnet "github.com/bio-routing/bio-rd/net" - "github.com/bio-routing/bio-rd/route" - "github.com/bio-routing/bio-rd/routingtable" - "github.com/bio-routing/bio-rd/routingtable/filter" - log "github.com/sirupsen/logrus" - "github.com/vishvananda/netlink" -) - -// Constants for IP family -const ( - IPFamily4 int = 4 // IPv4 - IPFamily6 int = 6 // IPv6 -) - -// NetlinkReader reads routes from the Linux Kernel and propagates them to the locRIB -type NetlinkReader struct { - clientManager *routingtable.ClientManager - options *config.Netlink - filter filter.Chain - - mu sync.RWMutex - routes []netlink.Route -} - -// NewNetlinkReader creates a new reader object and returns the pointer to it -func NewNetlinkReader(options *config.Netlink) *NetlinkReader { - nr := &NetlinkReader{ - options: options, - filter: options.ImportFilterChain, - } - - nr.clientManager = routingtable.NewClientManager(nr) - - return nr -} - -// ClientCount is here to satisfy an interface -func (nr *NetlinkReader) ClientCount() uint64 { - return 0 -} - -// Dump is here to fulfill an interface -func (nr *NetlinkReader) Dump() []*route.Route { - return nil -} - -// Read reads routes from the kernel -func (nr *NetlinkReader) Read() { - // Start fetching the kernel routes after the hold time - time.Sleep(nr.options.HoldTime) - - for { - // Family doesn't matter. I only filter by the rt_table here - routes, err := netlink.RouteListFiltered(IPFamily4, &netlink.Route{Table: int(nr.options.RoutingTable)}, netlink.RT_FILTER_TABLE) - if err != nil { - log.WithError(err).Panic("Failed to read routes from kernel") - } - - nr.propagateChanges(routes) - - nr.mu.Lock() - nr.routes = routes - - log.Debugf("NetlinkRouteDiff: %d", len(NetlinkRouteDiff(nr.routes, routes))) - nr.mu.Unlock() - - time.Sleep(nr.options.UpdateInterval) - } -} - -// propagate changes to all subscribed clients -func (nr *NetlinkReader) propagateChanges(routes []netlink.Route) { - nr.removePathsFromClients(routes) - nr.addPathsToClients(routes) -} - -// Add given paths to clients -func (nr *NetlinkReader) addPathsToClients(routes []netlink.Route) { - // If there were no routes yet, just skip this function. There's nothing to add - if len(routes) == 0 { - return - } - - // only advertise changed routes - nr.mu.RLock() - advertise := NetlinkRouteDiff(routes, nr.routes) - nr.mu.RUnlock() - - for _, client := range nr.clientManager.Clients() { - for _, r := range advertise { - if isBioRoute(r) { - log.WithFields(routeLogFields(r)).Debug("Skipping bio route") - continue - } - - // create pfx and path from route - pfx, paths, err := NewPathsFromNlRoute(r, true) - if err != nil { - log.WithError(err).WithFields(log.Fields{ - "prefix": pfx.String(), - }).Error("Unable to create path") - continue - } - - for _, path := range paths { - var p *route.Path - if nr.filter != nil { - var reject bool - p, reject := nr.filter.Process(pfx, path) - if reject { - log.WithError(err).WithFields(log.Fields{ - "prefix": pfx.String(), - "path": p.String(), - }).Debug("Skipping route due to filter") - continue - } - } - - log.WithFields(log.Fields{ - "pfx": pfx, - "path": p, - }).Debug("NetlinkReader - client.AddPath") - client.AddPath(pfx, p) - } - } - } -} - -// Remove given paths from clients -func (nr *NetlinkReader) removePathsFromClients(routes []netlink.Route) { - nr.mu.RLock() - - // If there were no routes yet, just skip this function. There's nothing to delete - if len(nr.routes) == 0 { - nr.mu.RUnlock() - return - } - - // only withdraw changed routes - withdraw := NetlinkRouteDiff(nr.routes, routes) - nr.mu.RUnlock() - - for _, client := range nr.clientManager.Clients() { - for _, r := range withdraw { - if isBioRoute(r) { - log.WithFields(routeLogFields(r)).Debug("Skipping bio route") - continue - } - - // create pfx and path from route - pfx, paths, err := NewPathsFromNlRoute(r, true) - if err != nil { - log.WithError(err).WithFields(log.Fields{ - "prefix": pfx.String(), - }).Error("Unable to create path") - continue - } - - for _, path := range paths { - var p *route.Path - if nr.filter != nil { - var reject bool - p, reject = nr.filter.Process(pfx, path) - if reject { - log.WithError(err).WithFields(log.Fields{ - "prefix": pfx.String(), - "path": p.String(), - }).Debug("Skipping route due to filter") - continue - } - } - - log.WithFields(log.Fields{ - "pfx": pfx, - "path": p, - }).Debug("NetlinkReader - client.RemovePath") - client.RemovePath(pfx, p) - } - } - } -} - -// Is route a BIO-Written route? -func isBioRoute(r netlink.Route) bool { - return uint32(r.Protocol) == route.ProtoBio -} - -func routeLogFields(route netlink.Route) log.Fields { - return log.Fields{ - "LinkIndex": route.LinkIndex, - "ILinkIndex": route.ILinkIndex, - "Scope": route.Scope, - "Dst": route.Dst, - "Src": route.Src, - "Gw": route.Gw, - "MultiPath": route.MultiPath, - "Protocol": route.Protocol, - "Priority": route.Priority, - "Table": route.Table, - "Type": route.Type, - "Tos": route.Tos, - "Flags": route.Flags, - "MPLSDst": route.MPLSDst, - "NewDst": route.NewDst, - "Encap": route.Encap, - "MTU": route.MTU, - "AdvMSS": route.AdvMSS, - } -} - -// AddPath is Not supported -func (nr *NetlinkReader) AddPath(*bnet.Prefix, *route.Path) error { - return fmt.Errorf("Not supported") -} - -// RemovePath is Not supported -func (nr *NetlinkReader) RemovePath(*bnet.Prefix, *route.Path) bool { - return false -} - -// UpdateNewClient is currently not supported -func (nr *NetlinkReader) UpdateNewClient(routingtable.RouteTableClient) error { - return fmt.Errorf("Not supported") -} - -// Register is currently not supported -func (nr *NetlinkReader) Register(routingtable.RouteTableClient) { -} - -// Unregister is Not supported -func (nr *NetlinkReader) Unregister(routingtable.RouteTableClient) { -} - -// RouteCount returns the number of routes stored in the internal routing table -func (nr *NetlinkReader) RouteCount() int64 { - nr.mu.RLock() - defer nr.mu.RUnlock() - - return int64(len(nr.routes)) -} - -// ReplaceFilterChain is here to fulfill an interface -func (nr *NetlinkReader) ReplaceFilterChain(c filter.Chain) { - -} - -// ReplacePath is here to fulfill an interface -func (nr *NetlinkReader) ReplacePath(*net.Prefix, *route.Path, *route.Path) { - -} - -// RefreshRoute is here to fultill an interface -func (nr *NetlinkReader) RefreshRoute(*net.Prefix, []*route.Path) { - -} diff --git a/protocols/fib/writer_linux.go b/protocols/fib/writer_linux.go deleted file mode 100644 index a26365bc3f84df6d023b2a87270172f933a3807d..0000000000000000000000000000000000000000 --- a/protocols/fib/writer_linux.go +++ /dev/null @@ -1,199 +0,0 @@ -package fib - -import ( - "fmt" - "sync" - - "github.com/bio-routing/bio-rd/config" - bnet "github.com/bio-routing/bio-rd/net" - "github.com/bio-routing/bio-rd/route" - "github.com/bio-routing/bio-rd/routingtable" - "github.com/bio-routing/bio-rd/routingtable/filter" - "github.com/pkg/errors" - log "github.com/sirupsen/logrus" - "github.com/vishvananda/netlink" -) - -// NetlinkWriter is a locRIB subscriber which serializes routes from the locRIB to the Linux Kernel routing stack -type NetlinkWriter struct { - options *config.Netlink - filter filter.Chain - - // Routingtable for buffering, to ensure no double writes (a.k.a rtnetlink: file exists) - mu sync.RWMutex - pathTable map[bnet.Prefix][]*route.Path -} - -// NewNetlinkWriter creates a new NetlinkWriter object and returns the pointer to it -func NewNetlinkWriter(options *config.Netlink) *NetlinkWriter { - return &NetlinkWriter{ - options: options, - filter: options.ExportFilterChain, - pathTable: make(map[bnet.Prefix][]*route.Path), - } -} - -// UpdateNewClient Not supported for NetlinkWriter, since the writer is not observable -func (nw *NetlinkWriter) UpdateNewClient(routingtable.RouteTableClient) error { - return fmt.Errorf("Not supported") -} - -// Register Not supported for NetlinkWriter, since the writer is not observable -func (nw *NetlinkWriter) Register(routingtable.RouteTableClient) { - log.Error("Not supported") -} - -// RegisterWithOptions Not supported, since the writer is not observable -func (nw *NetlinkWriter) RegisterWithOptions(routingtable.RouteTableClient, routingtable.ClientOptions) { - log.Error("Not supported") -} - -// Unregister is not supported, since the writer is not observable -func (nw *NetlinkWriter) Unregister(routingtable.RouteTableClient) { - log.Error("Not supported") -} - -// RouteCount returns the number of stored routes -func (nw *NetlinkWriter) RouteCount() int64 { - nw.mu.RLock() - defer nw.mu.RUnlock() - return int64(len(nw.pathTable)) -} - -// AddPath adds a path to the Kernel using netlink. This function is triggered by the loc_rib, cause we are subscribed as client in the loc_rib -func (nw *NetlinkWriter) AddPath(pfx bnet.Prefix, path *route.Path) error { - // check if for this prefix already a route is existing - existingPaths, ok := nw.pathTable[pfx] - - // if no route exists, add that route - if existingPaths == nil || !ok { - nw.pathTable[pfx] = []*route.Path{path} - return nw.addKernel(pfx) - } - - // if the new path is already in, don't do anything - for _, ePath := range existingPaths { - if ePath.Equal(path) { - return nil - } - } - - // if newly added path is a ecmp path to the existing paths, add it - if path.ECMP(existingPaths[0]) { - nw.removeKernel(pfx, existingPaths) - existingPaths = append(existingPaths, path) - nw.pathTable[pfx] = existingPaths - - return nw.addKernel(pfx) - } - - // if newly added path is no ecmp path to the existing ones, remove all old and only add the new - nw.removeKernel(pfx, existingPaths) - nw.pathTable[pfx] = []*route.Path{path} - return nw.addKernel(pfx) - -} - -// RemovePath removes a path from the Kernel using netlink This function is triggered by the loc_rib, cause we are subscribed as client in the loc_rib -func (nw *NetlinkWriter) RemovePath(pfx bnet.Prefix, path *route.Path) bool { - // check if for this prefix already a route is existing - existingPaths, ok := nw.pathTable[pfx] - - // if no route exists, nothing to do - if existingPaths == nil || !ok { - return true - } - - // if the new path is already in: remove - removeIdx := 0 - remove := false - for idx, ePath := range existingPaths { - if ePath.Equal(path) { - removeIdx = idx - - remove = true - err := nw.removeKernel(pfx, []*route.Path{path}) - if err != nil { - log.WithError(err).Errorf("Error while removing path %s for prefix %s", path.String(), pfx.String()) - remove = false - } - - break - } - } - - if remove { - existingPaths = append(existingPaths[:removeIdx], existingPaths[removeIdx+1:]...) - nw.pathTable[pfx] = existingPaths - } - - return true -} - -// Add pfx/path to kernel -func (nw *NetlinkWriter) addKernel(pfx bnet.Prefix) error { - route, err := nw.createRoute(pfx, nw.pathTable[pfx]) - if err != nil { - return fmt.Errorf("Could not create Route: %v", err.Error()) - } - - log.WithFields(log.Fields{ - "Prefix": pfx.String(), - "Table": route.Table, - }).Debug("AddPath to netlink") - - err = netlink.RouteAdd(route) - if err != nil { - log.Errorf("Error while adding route: %v", err) - return errors.Wrap(err, "Error while adding route") - } - - return nil -} - -// remove pfx/path from kernel -func (nw *NetlinkWriter) removeKernel(pfx bnet.Prefix, paths []*route.Path) error { - route, err := nw.createRoute(pfx, nw.pathTable[pfx]) - if err != nil { - return fmt.Errorf("Could not create Route: %v", err.Error()) - } - - log.WithFields(log.Fields{ - "Prefix": pfx.String(), - }).Debug("Remove from netlink") - - err = netlink.RouteDel(route) - if err != nil { - return errors.Wrap(err, "Error while removing route") - } - - return nil -} - -// create a route from a prefix and a path -func (nw *NetlinkWriter) createRoute(pfx bnet.Prefix, paths []*route.Path) (*netlink.Route, error) { - route := &netlink.Route{ - Dst: pfx.GetIPNet(), - Table: int(nw.options.RoutingTable), // config dependent - Protocol: route.ProtoBio, - } - - multiPath := make([]*netlink.NexthopInfo, 0) - - for _, path := range paths { - nextHop := &netlink.NexthopInfo{ - Gw: path.NextHop().Bytes(), - } - multiPath = append(multiPath, nextHop) - } - - if len(multiPath) == 1 { - route.Gw = multiPath[0].Gw - } else if len(multiPath) > 1 { - route.MultiPath = multiPath - } else { - return nil, fmt.Errorf("No destination address specified. At least one NextHop has to be specified in path") - } - - return route, nil -} diff --git a/protocols/kernel/kernel_darwin.go b/protocols/kernel/kernel_darwin.go new file mode 100644 index 0000000000000000000000000000000000000000..fb330b5d61ecd16cf839bb11c09244b1e19a25b1 --- /dev/null +++ b/protocols/kernel/kernel_darwin.go @@ -0,0 +1,7 @@ +package kernel + +import "errors" + +func (k *Kernel) init() error { + return errors.New("Not implemented for Darwin") +} diff --git a/protocols/kernel/kernel_linux.go b/protocols/kernel/kernel_linux.go index eebf4752564aca5c37d684227a3e56a3b10ba93b..ac4b49a352fe88c82a2807ffcb7f63a9602c4826 100644 --- a/protocols/kernel/kernel_linux.go +++ b/protocols/kernel/kernel_linux.go @@ -27,10 +27,6 @@ func (k *Kernel) init() error { return nil } -func (k *Kernel) uninit() error { - return k.osKernel.uninit() -} - type linuxKernel struct { h *netlink.Handle routes map[*bnet.Prefix]struct{} diff --git a/protocols/kernel/kernel_windows.go b/protocols/kernel/kernel_windows.go new file mode 100644 index 0000000000000000000000000000000000000000..8d00cde1d20dfcb195c67128f2d7efbddb07aeb3 --- /dev/null +++ b/protocols/kernel/kernel_windows.go @@ -0,0 +1,7 @@ +package kernel + +import "errors" + +func (k *Kernel) init() error { + return errors.New("Not implemented for Windows") +} diff --git a/route/bgp_path.go b/route/bgp_path.go index 2b5fe6a11b7f115f6678b2454151f789fe0460d8..2fd6e907259578abffc0c94e0d8bf80c4c70daf2 100644 --- a/route/bgp_path.go +++ b/route/bgp_path.go @@ -40,9 +40,10 @@ type BGPPathA struct { // NewBGPPathA creates a new BGPPathA func NewBGPPathA() *BGPPathA { + defaultAddr := bnet.IPv4(0) return &BGPPathA{ - NextHop: bnet.IPv4(0), - Source: bnet.IPv4(0), + NextHop: &defaultAddr, + Source: &defaultAddr, } } diff --git a/route/bgp_path_test.go b/route/bgp_path_test.go index 97449b3df7832eee104b2363df3fcc220b705feb..fb2340f46accb992f2ff1bc91605e58536127eb9 100644 --- a/route/bgp_path_test.go +++ b/route/bgp_path_test.go @@ -58,8 +58,8 @@ func TestBGPPathFromProtoBGPPath(t *testing.T) { PathIdentifier: 100, BGPPathA: &BGPPathA{ BGPIdentifier: 123, - Source: bnet.IPv4FromOctets(10, 0, 0, 2), - NextHop: bnet.IPv4FromOctets(10, 0, 0, 1), + Source: bnet.IPv4FromOctets(10, 0, 0, 2).Ptr(), + NextHop: bnet.IPv4FromOctets(10, 0, 0, 1).Ptr(), LocalPref: 1000, Origin: 1, EBGP: true, @@ -116,15 +116,15 @@ func TestBGPSelect(t *testing.T) { p: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 200, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, q: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 100, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, expected: 1, @@ -134,15 +134,15 @@ func TestBGPSelect(t *testing.T) { p: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 100, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, q: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 200, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, expected: -1, @@ -152,15 +152,15 @@ func TestBGPSelect(t *testing.T) { p: &BGPPath{ ASPathLen: 100, BGPPathA: &BGPPathA{ - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, q: &BGPPath{ ASPathLen: 200, BGPPathA: &BGPPathA{ - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, expected: 1, @@ -170,15 +170,15 @@ func TestBGPSelect(t *testing.T) { p: &BGPPath{ ASPathLen: 200, BGPPathA: &BGPPathA{ - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, q: &BGPPath{ ASPathLen: 100, BGPPathA: &BGPPathA{ - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, expected: -1, @@ -188,15 +188,15 @@ func TestBGPSelect(t *testing.T) { p: &BGPPath{ BGPPathA: &BGPPathA{ Origin: 1, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, q: &BGPPath{ BGPPathA: &BGPPathA{ Origin: 2, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, expected: 1, @@ -206,15 +206,15 @@ func TestBGPSelect(t *testing.T) { p: &BGPPath{ BGPPathA: &BGPPathA{ Origin: 2, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, q: &BGPPath{ BGPPathA: &BGPPathA{ Origin: 1, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, expected: -1, @@ -224,15 +224,15 @@ func TestBGPSelect(t *testing.T) { p: &BGPPath{ BGPPathA: &BGPPathA{ MED: 1, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, q: &BGPPath{ BGPPathA: &BGPPathA{ MED: 2, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, expected: 1, @@ -242,15 +242,15 @@ func TestBGPSelect(t *testing.T) { p: &BGPPath{ BGPPathA: &BGPPathA{ MED: 2, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, q: &BGPPath{ BGPPathA: &BGPPathA{ MED: 1, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, expected: -1, @@ -260,15 +260,15 @@ func TestBGPSelect(t *testing.T) { p: &BGPPath{ BGPPathA: &BGPPathA{ EBGP: true, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, q: &BGPPath{ BGPPathA: &BGPPathA{ EBGP: false, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, expected: 1, @@ -278,15 +278,15 @@ func TestBGPSelect(t *testing.T) { p: &BGPPath{ BGPPathA: &BGPPathA{ EBGP: false, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, q: &BGPPath{ BGPPathA: &BGPPathA{ EBGP: true, - Source: bnet.IPv4(0), - NextHop: bnet.IPv4(0), + Source: bnet.IPv4(0).Ptr(), + NextHop: bnet.IPv4(0).Ptr(), }, }, expected: -1, @@ -509,8 +509,8 @@ func TestLength(t *testing.T) { }, BGPPathA: &BGPPathA{ OriginatorID: 10, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, expected: 54, @@ -533,8 +533,8 @@ func TestBGPPathString(t *testing.T) { BGPPathA: &BGPPathA{ EBGP: true, OriginatorID: 23, - NextHop: net.IPv6(0, 0), - Source: net.IPv6(0, 0), + NextHop: net.IPv6(0, 0).Ptr(), + Source: net.IPv6(0, 0).Ptr(), }, ASPath: &types.ASPath{}, ClusterList: &types.ClusterList{10, 20}, diff --git a/route/path_test.go b/route/path_test.go index 5e42ef90fa9f16cfb703903c34fb1bee7e314439..3ec287e2e6f72b931a9c459edbf2d67348e056cd 100644 --- a/route/path_test.go +++ b/route/path_test.go @@ -21,31 +21,31 @@ func TestPathNextHop(t *testing.T) { Type: BGPPathType, BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ - NextHop: bnet.IPv4(123), + NextHop: bnet.IPv4(123).Ptr(), }, }, }, - expected: bnet.IPv4(123), + expected: bnet.IPv4(123).Ptr(), }, { name: "Static Path", p: &Path{ Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4(456), + NextHop: bnet.IPv4(456).Ptr(), }, }, - expected: bnet.IPv4(456), + expected: bnet.IPv4(456).Ptr(), }, { name: "Netlink Path", p: &Path{ Type: FIBPathType, FIBPath: &FIBPath{ - NextHop: bnet.IPv4(1000), + NextHop: bnet.IPv4(1000).Ptr(), }, }, - expected: bnet.IPv4(1000), + expected: bnet.IPv4(1000).Ptr(), }, } @@ -131,13 +131,13 @@ func TestSelect(t *testing.T) { p: &Path{ Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), }, }, q: &Path{ Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), }, }, expected: 0, @@ -163,15 +163,15 @@ func TestSelect(t *testing.T) { p: &Path{ Type: FIBPathType, FIBPath: &FIBPath{ - NextHop: net.IPv4(0), - Src: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Src: net.IPv4(0).Ptr(), }, }, q: &Path{ Type: FIBPathType, FIBPath: &FIBPath{ - NextHop: net.IPv4(0), - Src: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Src: net.IPv4(0).Ptr(), }, }, expected: 0, @@ -352,12 +352,12 @@ func TestNewNlPath(t *testing.T) { Type: BGPPathType, BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ - NextHop: bnet.IPv4(123), + NextHop: bnet.IPv4(123).Ptr(), }, }, }, expected: &FIBPath{ - NextHop: bnet.IPv4(123), + NextHop: bnet.IPv4(123).Ptr(), Protocol: ProtoBio, }, }, @@ -394,8 +394,8 @@ func TestECMP(t *testing.T) { LocalPref: 100, MED: 1, Origin: 123, - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPathLen: 10, }, @@ -407,8 +407,8 @@ func TestECMP(t *testing.T) { LocalPref: 100, MED: 1, Origin: 123, - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPathLen: 10, }, @@ -423,8 +423,8 @@ func TestECMP(t *testing.T) { LocalPref: 100, MED: 1, Origin: 123, - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPathLen: 10, }, @@ -436,8 +436,8 @@ func TestECMP(t *testing.T) { LocalPref: 100, MED: 1, Origin: 123, - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPathLen: 5, }, @@ -449,8 +449,8 @@ func TestECMP(t *testing.T) { left: &Path{ Type: FIBPathType, FIBPath: &FIBPath{ - Src: bnet.IPv4(123), - NextHop: bnet.IPv4(123), + Src: bnet.IPv4(123).Ptr(), + NextHop: bnet.IPv4(123).Ptr(), Priority: 1, Protocol: 1, Type: 1, @@ -460,8 +460,8 @@ func TestECMP(t *testing.T) { right: &Path{ Type: FIBPathType, FIBPath: &FIBPath{ - Src: bnet.IPv4(123), - NextHop: bnet.IPv4(123), + Src: bnet.IPv4(123).Ptr(), + NextHop: bnet.IPv4(123).Ptr(), Priority: 1, Protocol: 1, Type: 1, @@ -475,8 +475,8 @@ func TestECMP(t *testing.T) { left: &Path{ Type: FIBPathType, FIBPath: &FIBPath{ - Src: bnet.IPv4(123), - NextHop: bnet.IPv4(123), + Src: bnet.IPv4(123).Ptr(), + NextHop: bnet.IPv4(123).Ptr(), Priority: 1, Protocol: 1, Type: 1, @@ -486,8 +486,8 @@ func TestECMP(t *testing.T) { right: &Path{ Type: FIBPathType, FIBPath: &FIBPath{ - Src: bnet.IPv4(123), - NextHop: bnet.IPv4(123), + Src: bnet.IPv4(123).Ptr(), + NextHop: bnet.IPv4(123).Ptr(), Priority: 2, Protocol: 1, Type: 1, @@ -501,13 +501,13 @@ func TestECMP(t *testing.T) { left: &Path{ Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4(123), + NextHop: bnet.IPv4(123).Ptr(), }, }, right: &Path{ Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4(123), + NextHop: bnet.IPv4(123).Ptr(), }, }, ecmp: true, @@ -516,13 +516,13 @@ func TestECMP(t *testing.T) { left: &Path{ Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4(123), + NextHop: bnet.IPv4(123).Ptr(), }, }, right: &Path{ Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4(345), + NextHop: bnet.IPv4(345).Ptr(), }, }, // ECMP is always true for staticPath @@ -546,15 +546,15 @@ func TestFIBPathSelect(t *testing.T) { { name: "equal", left: &FIBPath{ - NextHop: bnet.IPv4(123), - Src: bnet.IPv4(234), + NextHop: bnet.IPv4(123).Ptr(), + Src: bnet.IPv4(234).Ptr(), Priority: 1, Protocol: 1, Table: 1, }, right: &FIBPath{ - NextHop: bnet.IPv4(123), - Src: bnet.IPv4(234), + NextHop: bnet.IPv4(123).Ptr(), + Src: bnet.IPv4(234).Ptr(), Priority: 1, Protocol: 1, Table: 1, @@ -564,61 +564,61 @@ func TestFIBPathSelect(t *testing.T) { { name: "nextHop smaller", left: &FIBPath{ - NextHop: bnet.IPv4(1), - Src: bnet.IPv4(234), + NextHop: bnet.IPv4(1).Ptr(), + Src: bnet.IPv4(234).Ptr(), }, right: &FIBPath{ - NextHop: bnet.IPv4(2), - Src: bnet.IPv4(234), + NextHop: bnet.IPv4(2).Ptr(), + Src: bnet.IPv4(234).Ptr(), }, expected: -1, }, { name: "nextHop bigger", left: &FIBPath{ - NextHop: bnet.IPv4(2), - Src: bnet.IPv4(234), + NextHop: bnet.IPv4(2).Ptr(), + Src: bnet.IPv4(234).Ptr(), }, right: &FIBPath{ - NextHop: bnet.IPv4(1), - Src: bnet.IPv4(234), + NextHop: bnet.IPv4(1).Ptr(), + Src: bnet.IPv4(234).Ptr(), }, expected: 1, }, { name: "src smaller", left: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(1), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(1).Ptr(), }, right: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(2), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(2).Ptr(), }, expected: -1, }, { name: "src bigger", left: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(2), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(2).Ptr(), }, right: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(1), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(1).Ptr(), }, expected: 1, }, { name: "priority smaller", left: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(234), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(234).Ptr(), Priority: 1, }, right: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(234), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(234).Ptr(), Priority: 2, }, expected: -1, @@ -626,13 +626,13 @@ func TestFIBPathSelect(t *testing.T) { { name: "priority bigger", left: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(234), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(234).Ptr(), Priority: 2, }, right: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(234), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(234).Ptr(), Priority: 1, }, expected: 1, @@ -640,13 +640,13 @@ func TestFIBPathSelect(t *testing.T) { { name: "protocol smaller", left: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(234), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(234).Ptr(), Protocol: 1, }, right: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(234), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(234).Ptr(), Protocol: 2, }, expected: -1, @@ -654,13 +654,13 @@ func TestFIBPathSelect(t *testing.T) { { name: "protocol bigger", left: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(234), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(234).Ptr(), Protocol: 2, }, right: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(234), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(234).Ptr(), Protocol: 1, }, expected: 1, @@ -668,13 +668,13 @@ func TestFIBPathSelect(t *testing.T) { { name: "table smaller", left: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(234), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(234).Ptr(), Table: 1, }, right: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(234), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(234).Ptr(), Table: 2, }, expected: -1, @@ -682,13 +682,13 @@ func TestFIBPathSelect(t *testing.T) { { name: "table bigger", left: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(234), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(234).Ptr(), Table: 2, }, right: &FIBPath{ - NextHop: net.IPv4(0), - Src: bnet.IPv4(234), + NextHop: net.IPv4(0).Ptr(), + Src: bnet.IPv4(234).Ptr(), Table: 1, }, expected: 1, diff --git a/route/route.go b/route/route.go index 74c9b98df6a1e8d42bf09a645586563222e7fc9c..7875ea27704ad82c2762db7ca8476f27d0d33bb3 100644 --- a/route/route.go +++ b/route/route.go @@ -43,7 +43,7 @@ func NewRoute(pfx *net.Prefix, p *Path) *Route { } if p == nil { - r.paths = make([]*Path, 0) + r.paths = make([]*Path, 0, 2) return r } diff --git a/route/route_test.go b/route/route_test.go index 3a7842e866f56e46a803854ec001558cdc53e494..059835b19c75f14c7e86762f64d8ea5da862f105 100644 --- a/route/route_test.go +++ b/route/route_test.go @@ -18,13 +18,13 @@ func TestNewRoute(t *testing.T) { }{ { name: "BGP Path", - pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), path: &Path{ Type: BGPPathType, BGPPath: &BGPPath{}, }, expected: &Route{ - pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), paths: []*Path{ { Type: BGPPathType, @@ -35,9 +35,9 @@ func TestNewRoute(t *testing.T) { }, { name: "Empty Path", - pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), expected: &Route{ - pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), paths: []*Path{}, }, }, @@ -58,9 +58,9 @@ func TestPrefix(t *testing.T) { { name: "Prefix", route: &Route{ - pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), }, - expected: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + expected: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), }, } @@ -79,9 +79,9 @@ func TestAddr(t *testing.T) { { name: "Prefix", route: &Route{ - pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), }, - expected: bnet.IPv4(0xa000000), + expected: bnet.IPv4(0xa000000).Ptr(), }, } @@ -100,7 +100,7 @@ func TestPfxlen(t *testing.T) { { name: "Prefix", route: &Route{ - pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), }, expected: 8, }, @@ -121,7 +121,7 @@ func TestAddPath(t *testing.T) { }{ { name: "Regular BGP path", - route: NewRoute(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), &Path{ + route: NewRoute(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &Path{ Type: BGPPathType, BGPPath: &BGPPath{}, }), @@ -130,7 +130,7 @@ func TestAddPath(t *testing.T) { BGPPath: &BGPPath{}, }, expected: &Route{ - pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), paths: []*Path{ { Type: BGPPathType, @@ -145,13 +145,13 @@ func TestAddPath(t *testing.T) { }, { name: "Nil path", - route: NewRoute(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), &Path{ + route: NewRoute(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &Path{ Type: BGPPathType, BGPPath: &BGPPath{}, }), newPath: nil, expected: &Route{ - pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), + pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), paths: []*Path{ { Type: BGPPathType, @@ -183,8 +183,8 @@ func TestRouteRemovePath(t *testing.T) { BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 100, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, @@ -193,8 +193,8 @@ func TestRouteRemovePath(t *testing.T) { BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 200, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, @@ -203,8 +203,8 @@ func TestRouteRemovePath(t *testing.T) { BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 300, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, @@ -214,8 +214,8 @@ func TestRouteRemovePath(t *testing.T) { BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 200, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, @@ -225,8 +225,8 @@ func TestRouteRemovePath(t *testing.T) { BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 100, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, @@ -235,8 +235,8 @@ func TestRouteRemovePath(t *testing.T) { BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 300, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, @@ -250,8 +250,8 @@ func TestRouteRemovePath(t *testing.T) { BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 10, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, @@ -260,8 +260,8 @@ func TestRouteRemovePath(t *testing.T) { BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 20, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, @@ -271,8 +271,8 @@ func TestRouteRemovePath(t *testing.T) { BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 50, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, @@ -282,8 +282,8 @@ func TestRouteRemovePath(t *testing.T) { BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 10, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, @@ -292,8 +292,8 @@ func TestRouteRemovePath(t *testing.T) { BGPPath: &BGPPath{ BGPPathA: &BGPPathA{ LocalPref: 20, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, @@ -316,7 +316,7 @@ func TestCopy(t *testing.T) { { name: "", route: &Route{ - pfx: bnet.NewPfx(bnet.IPv4(1000), 8), + pfx: bnet.NewPfx(bnet.IPv4(1000), 8).Ptr(), ecmpPaths: 2, paths: []*Path{ { @@ -325,7 +325,7 @@ func TestCopy(t *testing.T) { }, }, expected: &Route{ - pfx: bnet.NewPfx(bnet.IPv4(1000), 8), + pfx: bnet.NewPfx(bnet.IPv4(1000), 8).Ptr(), ecmpPaths: 2, paths: []*Path{ { @@ -373,7 +373,7 @@ func TestBestPath(t *testing.T) { { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4(32), + NextHop: bnet.IPv4(32).Ptr(), }, }, }, @@ -381,7 +381,7 @@ func TestBestPath(t *testing.T) { expected: &Path{ Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4(32), + NextHop: bnet.IPv4(32).Ptr(), }, }, }, @@ -411,13 +411,13 @@ func TestECMPPaths(t *testing.T) { { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4(32), + NextHop: bnet.IPv4(32).Ptr(), }, }, { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4(32), + NextHop: bnet.IPv4(32).Ptr(), }, }, }, @@ -426,13 +426,13 @@ func TestECMPPaths(t *testing.T) { { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4(32), + NextHop: bnet.IPv4(32).Ptr(), }, }, { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4(32), + NextHop: bnet.IPv4(32).Ptr(), }, }, }, @@ -451,37 +451,37 @@ func TestRouteEqual(t *testing.T) { }{ { a: &Route{ - pfx: net.NewPfx(net.IPv4(0), 0), + pfx: net.NewPfx(net.IPv4(0), 0).Ptr(), ecmpPaths: 2, paths: []*Path{ { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4FromOctets(192, 168, 0, 1), + NextHop: bnet.IPv4FromOctets(192, 168, 0, 1).Ptr(), }, }, { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4FromOctets(192, 168, 1, 1), + NextHop: bnet.IPv4FromOctets(192, 168, 1, 1).Ptr(), }, }, }, }, b: &Route{ - pfx: net.NewPfx(net.IPv4(0), 0), + pfx: net.NewPfx(net.IPv4(0), 0).Ptr(), ecmpPaths: 2, paths: []*Path{ { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4FromOctets(192, 168, 0, 1), + NextHop: bnet.IPv4FromOctets(192, 168, 0, 1).Ptr(), }, }, { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4FromOctets(192, 168, 1, 1), + NextHop: bnet.IPv4FromOctets(192, 168, 1, 1).Ptr(), }, }, }, @@ -489,37 +489,37 @@ func TestRouteEqual(t *testing.T) { equal: true, }, { a: &Route{ - pfx: net.NewPfx(net.IPv4(0), 0), + pfx: net.NewPfx(net.IPv4(0), 0).Ptr(), ecmpPaths: 2, paths: []*Path{ { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4FromOctets(192, 168, 0, 1), + NextHop: bnet.IPv4FromOctets(192, 168, 0, 1).Ptr(), }, }, { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4FromOctets(192, 168, 1, 1), + NextHop: bnet.IPv4FromOctets(192, 168, 1, 1).Ptr(), }, }, }, }, b: &Route{ - pfx: net.NewPfx(net.IPv4(0), 0), + pfx: net.NewPfx(net.IPv4(0), 0).Ptr(), ecmpPaths: 2, paths: []*Path{ { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4FromOctets(192, 168, 1, 1), + NextHop: bnet.IPv4FromOctets(192, 168, 1, 1).Ptr(), }, }, { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4FromOctets(192, 168, 2, 1), + NextHop: bnet.IPv4FromOctets(192, 168, 2, 1).Ptr(), }, }, }, @@ -528,31 +528,31 @@ func TestRouteEqual(t *testing.T) { }, { a: &Route{ - pfx: net.NewPfx(net.IPv4(0), 0), + pfx: net.NewPfx(net.IPv4(0), 0).Ptr(), ecmpPaths: 2, paths: []*Path{ { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4FromOctets(192, 168, 0, 1), + NextHop: bnet.IPv4FromOctets(192, 168, 0, 1).Ptr(), }, }, { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4FromOctets(192, 168, 1, 1), + NextHop: bnet.IPv4FromOctets(192, 168, 1, 1).Ptr(), }, }, }, }, b: &Route{ - pfx: net.NewPfx(net.IPv4(0), 0), + pfx: net.NewPfx(net.IPv4(0), 0).Ptr(), ecmpPaths: 2, paths: []*Path{ { Type: StaticPathType, StaticPath: &StaticPath{ - NextHop: bnet.IPv4FromOctets(192, 168, 1, 1), + NextHop: bnet.IPv4FromOctets(192, 168, 1, 1).Ptr(), }, }, }, diff --git a/routingtable/adjRIBIn/adj_rib_in_test.go b/routingtable/adjRIBIn/adj_rib_in_test.go index aa6a266cf18480d8780eaa514fccb927729ec566..4987332b9c0c188097a2b3925ced4b30433a7de1 100644 --- a/routingtable/adjRIBIn/adj_rib_in_test.go +++ b/routingtable/adjRIBIn/adj_rib_in_test.go @@ -12,8 +12,8 @@ import ( ) func TestAddPath(t *testing.T) { - routerID := net.IPv4FromOctets(1, 1, 1, 1).ToUint32() - clusterID := net.IPv4FromOctets(2, 2, 2, 2).ToUint32() + routerID := net.IPv4FromOctets(1, 1, 1, 1).Ptr().ToUint32() + clusterID := net.IPv4FromOctets(2, 2, 2, 2).Ptr().ToUint32() tests := []struct { name string @@ -26,7 +26,7 @@ func TestAddPath(t *testing.T) { { name: "Add route", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -38,7 +38,7 @@ func TestAddPath(t *testing.T) { removePfx: nil, removePath: nil, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -51,46 +51,46 @@ func TestAddPath(t *testing.T) { { name: "Overwrite routes", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 100, - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 100, - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), }, - removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), removePath: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 100, - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 100, - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), @@ -99,7 +99,7 @@ func TestAddPath(t *testing.T) { { name: "Add route with our RouterID as OriginatorID", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 32), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 32).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -114,7 +114,7 @@ func TestAddPath(t *testing.T) { { name: "Add route with our ClusterID within ClusterList", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 32), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 32).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -133,7 +133,7 @@ func TestAddPath(t *testing.T) { name: "Add route (with BGP add path)", addPath: true, routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -141,7 +141,7 @@ func TestAddPath(t *testing.T) { }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -153,7 +153,7 @@ func TestAddPath(t *testing.T) { removePfx: nil, removePath: nil, expected: []*route.Route{ - route.NewRouteAddPath(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), []*route.Path{ + route.NewRouteAddPath(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), []*route.Path{ { Type: route.BGPPathType, BGPPath: &route.BGPPath{ @@ -181,7 +181,7 @@ func TestAddPath(t *testing.T) { adjRIBIn.clientManager.RegisterWithOptions(mc, routingtable.ClientOptions{BestOnly: true}) for _, route := range test.routes { - adjRIBIn.AddPath(route.Prefix(), route.Paths()[0]) + adjRIBIn.AddPath(route.Prefix().Ptr(), route.Paths()[0]) } if test.removePath != nil { @@ -213,57 +213,57 @@ func TestRemovePath(t *testing.T) { name: "Remove an a path from existing route", addPath: true, routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ PathIdentifier: 100, BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ PathIdentifier: 200, BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ PathIdentifier: 300, BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), }, - removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), removePath: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ PathIdentifier: 200, BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }, expected: []*route.Route{ - route.NewRouteAddPath(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), []*route.Path{ + route.NewRouteAddPath(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), []*route.Path{ { Type: route.BGPPathType, BGPPath: &route.BGPPath{ PathIdentifier: 100, BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }, @@ -272,8 +272,8 @@ func TestRemovePath(t *testing.T) { BGPPath: &route.BGPPath{ PathIdentifier: 300, BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }, @@ -284,60 +284,60 @@ func TestRemovePath(t *testing.T) { { name: "Remove an existing route", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), }, - removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), removePath: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), @@ -347,51 +347,51 @@ func TestRemovePath(t *testing.T) { { name: "Remove non existing route", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), }, - removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), removePath: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(20, 0, 0, 0), - Source: net.IPv4FromOctets(20, 0, 0, 0), + NextHop: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), + Source: net.IPv4FromOctets(20, 0, 0, 0).Ptr(), }, }, }), @@ -403,7 +403,7 @@ func TestRemovePath(t *testing.T) { for _, test := range tests { adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), 1, 2, test.addPath) for _, route := range test.routes { - adjRIBIn.AddPath(route.Prefix(), route.Paths()[0]) + adjRIBIn.AddPath(route.Prefix().Ptr(), route.Paths()[0]) } mc := routingtable.NewRTMockClient() @@ -434,29 +434,29 @@ func TestUnregister(t *testing.T) { adjRIBIn.Register(mc) pfxs := []*net.Prefix{ - net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 16), - net.NewPfx(net.IPv4FromOctets(10, 0, 1, 0), 24), + net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 16).Ptr(), + net.NewPfx(net.IPv4FromOctets(10, 0, 1, 0), 24).Ptr(), } paths := []*route.Path{ { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(192, 168, 0, 0), + NextHop: net.IPv4FromOctets(192, 168, 0, 0).Ptr(), }, }, }, { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(192, 168, 2, 1), + NextHop: net.IPv4FromOctets(192, 168, 2, 1).Ptr(), }, }, }, { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(192, 168, 3, 1), + NextHop: net.IPv4FromOctets(192, 168, 3, 1).Ptr(), }, }, }, diff --git a/routingtable/adjRIBOut/adj_rib_out_test.go b/routingtable/adjRIBOut/adj_rib_out_test.go index dc10507ed188cee9637977c0ce66dcbf2391be23..e11d7e6a1545c9f9c8637061271feb1f5fe6c485 100644 --- a/routingtable/adjRIBOut/adj_rib_out_test.go +++ b/routingtable/adjRIBOut/adj_rib_out_test.go @@ -17,8 +17,8 @@ import ( func TestBestPathOnlyEBGP(t *testing.T) { neighborBestOnlyEBGP := &routingtable.Neighbor{ Type: route.BGPPathType, - LocalAddress: net.IPv4FromOctets(127, 0, 0, 1), - Address: net.IPv4FromOctets(127, 0, 0, 2), + LocalAddress: net.IPv4FromOctets(127, 0, 0, 1).Ptr(), + Address: net.IPv4FromOctets(127, 0, 0, 2).Ptr(), IBGP: false, LocalASN: 41981, RouteServerClient: false, @@ -36,18 +36,18 @@ func TestBestPathOnlyEBGP(t *testing.T) { { name: "Add a valid route", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{}, }, }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -56,7 +56,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { MED: 0, EBGP: false, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -77,7 +77,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { { name: "Try to remove unpresent route", routesRemove: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -86,7 +86,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { MED: 1, EBGP: false, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -105,7 +105,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -114,7 +114,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { MED: 0, EBGP: false, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -135,7 +135,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { { name: "Remove route added in first step", routesRemove: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -144,7 +144,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { MED: 0, EBGP: false, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -166,12 +166,12 @@ func TestBestPathOnlyEBGP(t *testing.T) { { name: "Try to add route with NO_EXPORT community set", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, Communities: &types.Communities{ types.WellKnownCommunityNoExport, @@ -184,12 +184,12 @@ func TestBestPathOnlyEBGP(t *testing.T) { { name: "Try to add route with NO_ADVERTISE community set", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, Communities: &types.Communities{ types.WellKnownCommunityNoAdvertise, @@ -203,19 +203,19 @@ func TestBestPathOnlyEBGP(t *testing.T) { { name: "Re-add valid route again", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{}, }, }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -224,7 +224,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { MED: 0, EBGP: false, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -245,7 +245,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { { name: "Try to remove route with NO_EXPORT community set", routesRemove: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -254,7 +254,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { MED: 0, EBGP: false, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -275,7 +275,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -284,7 +284,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { MED: 0, EBGP: false, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -305,18 +305,18 @@ func TestBestPathOnlyEBGP(t *testing.T) { { name: "Try to remove non-existent prefix", routesRemove: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 23, 42, 0), 24), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 23, 42, 0), 24).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -325,7 +325,7 @@ func TestBestPathOnlyEBGP(t *testing.T) { MED: 0, EBGP: false, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -348,11 +348,11 @@ func TestBestPathOnlyEBGP(t *testing.T) { for i, test := range tests { fmt.Printf("Running eBGP best only test #%d: %s\n", i+1, test.name) for _, route := range test.routesAdd { - adjRIBOut.AddPath(route.Prefix(), route.Paths()[0]) + adjRIBOut.AddPath(route.Prefix().Ptr(), route.Paths()[0]) } for _, route := range test.routesRemove { - adjRIBOut.RemovePath(route.Prefix(), route.Paths()[0]) + adjRIBOut.RemovePath(route.Prefix().Ptr(), route.Paths()[0]) } assert.Equal(t, test.expected, adjRIBOut.rt.Dump()) @@ -367,8 +367,8 @@ func TestBestPathOnlyEBGP(t *testing.T) { func TestBestPathOnlyIBGP(t *testing.T) { neighborBestOnlyEBGP := &routingtable.Neighbor{ Type: route.BGPPathType, - LocalAddress: net.IPv4FromOctets(127, 0, 0, 1), - Address: net.IPv4FromOctets(127, 0, 0, 2), + LocalAddress: net.IPv4FromOctets(127, 0, 0, 1).Ptr(), + Address: net.IPv4FromOctets(127, 0, 0, 2).Ptr(), IBGP: true, LocalASN: 41981, RouteServerClient: false, @@ -386,12 +386,12 @@ func TestBestPathOnlyIBGP(t *testing.T) { { name: "Add an iBGP route (without success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }), @@ -402,13 +402,13 @@ func TestBestPathOnlyIBGP(t *testing.T) { { name: "Add an eBGP route (with success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ EBGP: true, - NextHop: net.IPv4FromOctets(1, 2, 3, 4), - Source: net.IPv4(0), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -423,16 +423,16 @@ func TestBestPathOnlyIBGP(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -453,16 +453,16 @@ func TestBestPathOnlyIBGP(t *testing.T) { { name: "Try to remove slightly different route", routesRemove: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 1, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -481,16 +481,16 @@ func TestBestPathOnlyIBGP(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -511,13 +511,13 @@ func TestBestPathOnlyIBGP(t *testing.T) { { name: "Remove route added in 2nd step", routesRemove: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ EBGP: true, - NextHop: net.IPv4FromOctets(1, 2, 3, 4), - Source: net.IPv4(0), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -537,12 +537,12 @@ func TestBestPathOnlyIBGP(t *testing.T) { { name: "Try to add route with NO_EXPORT community set (without success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, Communities: &types.Communities{ types.WellKnownCommunityNoExport, @@ -555,12 +555,12 @@ func TestBestPathOnlyIBGP(t *testing.T) { { name: "Try to add route with NO_ADVERTISE community set (without success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, Communities: &types.Communities{ types.WellKnownCommunityNoAdvertise, @@ -575,11 +575,11 @@ func TestBestPathOnlyIBGP(t *testing.T) { for i, test := range testSteps { fmt.Printf("Running iBGP best only test #%d: %s\n", i+1, test.name) for _, route := range test.routesAdd { - adjRIBOut.AddPath(route.Prefix(), route.Paths()[0]) + adjRIBOut.AddPath(route.Prefix().Ptr(), route.Paths()[0]) } for _, route := range test.routesRemove { - adjRIBOut.RemovePath(route.Prefix(), route.Paths()[0]) + adjRIBOut.RemovePath(route.Prefix().Ptr(), route.Paths()[0]) } assert.Equal(t, test.expected, adjRIBOut.rt.Dump()) @@ -598,13 +598,13 @@ func TestBestPathOnlyIBGP(t *testing.T) { func TestBestPathOnlyRRClient(t *testing.T) { neighborBestOnlyRR := &routingtable.Neighbor{ Type: route.BGPPathType, - LocalAddress: net.IPv4FromOctets(127, 0, 0, 1), - Address: net.IPv4FromOctets(127, 0, 0, 2), + LocalAddress: net.IPv4FromOctets(127, 0, 0, 1).Ptr(), + Address: net.IPv4FromOctets(127, 0, 0, 2).Ptr(), IBGP: true, LocalASN: 41981, RouteServerClient: false, RouteReflectorClient: true, - ClusterID: net.IPv4FromOctets(2, 2, 2, 2).ToUint32(), + ClusterID: net.IPv4FromOctets(2, 2, 2, 2).Ptr().ToUint32(), } adjRIBOut := New(nil, neighborBestOnlyRR, filter.NewAcceptAllFilterChain(), false) @@ -619,24 +619,24 @@ func TestBestPathOnlyRRClient(t *testing.T) { { name: "Add an iBGP route (with success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{}, }, }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{}, ClusterList: &types.ClusterList{ @@ -650,13 +650,13 @@ func TestBestPathOnlyRRClient(t *testing.T) { { name: "Add an eBGP route (replacing previous iBGP route)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ EBGP: true, - NextHop: net.IPv4FromOctets(1, 2, 3, 4), - Source: net.IPv4(0), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -671,16 +671,16 @@ func TestBestPathOnlyRRClient(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -704,16 +704,16 @@ func TestBestPathOnlyRRClient(t *testing.T) { { name: "Try to remove slightly different route", routesRemove: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 1, // Existing route has MED 0 EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -732,16 +732,16 @@ func TestBestPathOnlyRRClient(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -765,16 +765,16 @@ func TestBestPathOnlyRRClient(t *testing.T) { { name: "Remove route added in 2nd step", routesRemove: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -799,12 +799,12 @@ func TestBestPathOnlyRRClient(t *testing.T) { { name: "Try to add route with NO_ADVERTISE community set (without success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, Communities: &types.Communities{ types.WellKnownCommunityNoAdvertise, @@ -818,12 +818,12 @@ func TestBestPathOnlyRRClient(t *testing.T) { { name: "Try to add route with NO_EXPORT community set (with success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, Communities: &types.Communities{ types.WellKnownCommunityNoExport, @@ -832,7 +832,7 @@ func TestBestPathOnlyRRClient(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -840,8 +840,8 @@ func TestBestPathOnlyRRClient(t *testing.T) { MED: 0, EBGP: false, LocalPref: 0, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, ASPathLen: 0, Communities: &types.Communities{ @@ -859,7 +859,7 @@ func TestBestPathOnlyRRClient(t *testing.T) { { name: "Remove NO_EXPORT route added before", routesRemove: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -867,8 +867,8 @@ func TestBestPathOnlyRRClient(t *testing.T) { MED: 0, EBGP: false, LocalPref: 0, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, ASPathLen: 0, Communities: &types.Communities{ @@ -887,13 +887,13 @@ func TestBestPathOnlyRRClient(t *testing.T) { { name: "Add route with one entry in ClusterList and OriginatorID set (with success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ OriginatorID: 42, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, ClusterList: &types.ClusterList{ 23, @@ -902,7 +902,7 @@ func TestBestPathOnlyRRClient(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ ASPathLen: 0, @@ -911,9 +911,9 @@ func TestBestPathOnlyRRClient(t *testing.T) { MED: 0, EBGP: false, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), OriginatorID: 42, - NextHop: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), }, UnknownAttributes: nil, PathIdentifier: 0, @@ -931,11 +931,11 @@ func TestBestPathOnlyRRClient(t *testing.T) { for i, test := range tests { fmt.Printf("Running RR client best only test #%d: %s\n", i+1, test.name) for _, route := range test.routesAdd { - adjRIBOut.AddPath(route.Prefix(), route.Paths()[0]) + adjRIBOut.AddPath(route.Prefix().Ptr(), route.Paths()[0]) } for _, route := range test.routesRemove { - adjRIBOut.RemovePath(route.Prefix(), route.Paths()[0]) + adjRIBOut.RemovePath(route.Prefix().Ptr(), route.Paths()[0]) } assert.Equal(t, test.expected, adjRIBOut.rt.Dump()) @@ -954,8 +954,8 @@ func TestBestPathOnlyRRClient(t *testing.T) { func TestAddPathIBGP(t *testing.T) { neighborBestOnlyEBGP := &routingtable.Neighbor{ Type: route.BGPPathType, - LocalAddress: net.IPv4FromOctets(127, 0, 0, 1), - Address: net.IPv4FromOctets(127, 0, 0, 2), + LocalAddress: net.IPv4FromOctets(127, 0, 0, 1).Ptr(), + Address: net.IPv4FromOctets(127, 0, 0, 2).Ptr(), IBGP: true, LocalASN: 41981, RouteServerClient: false, @@ -973,12 +973,12 @@ func TestAddPathIBGP(t *testing.T) { { name: "Add an iBGP route (without success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }), @@ -989,13 +989,13 @@ func TestAddPathIBGP(t *testing.T) { { name: "Add an eBGP route (with success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ EBGP: true, - Source: net.IPv4(0), - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1010,16 +1010,16 @@ func TestAddPathIBGP(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1040,16 +1040,16 @@ func TestAddPathIBGP(t *testing.T) { { name: "Try to remove slightly different route", routesRemove: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 1, // MED of route present in table is 0 EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1068,16 +1068,16 @@ func TestAddPathIBGP(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1098,13 +1098,13 @@ func TestAddPathIBGP(t *testing.T) { { name: "Remove route added in 2nd step", routesRemove: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ EBGP: true, - Source: net.IPv4(0), - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1124,12 +1124,12 @@ func TestAddPathIBGP(t *testing.T) { { name: "Try to add route with NO_EXPORT community set (without success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), }, Communities: &types.Communities{ types.WellKnownCommunityNoExport, @@ -1143,12 +1143,12 @@ func TestAddPathIBGP(t *testing.T) { { name: "Try to add route with NO_EXPORT community set (without success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), }, Communities: &types.Communities{ types.WellKnownCommunityNoAdvertise, @@ -1164,13 +1164,13 @@ func TestAddPathIBGP(t *testing.T) { { name: "Readd an eBGP route (with success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ EBGP: true, - NextHop: net.IPv4FromOctets(1, 2, 3, 4), - Source: net.IPv4(0), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1185,16 +1185,16 @@ func TestAddPathIBGP(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1215,13 +1215,13 @@ func TestAddPathIBGP(t *testing.T) { { name: "Add 2nd path to existing one with different NH (with success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ EBGP: true, - NextHop: net.IPv4FromOctets(2, 3, 4, 5), - Source: net.IPv4(0), + NextHop: net.IPv4FromOctets(2, 3, 4, 5).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1236,17 +1236,17 @@ func TestAddPathIBGP(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRouteAddPath(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), []*route.Path{ + route.NewRouteAddPath(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), []*route.Path{ { Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1265,12 +1265,12 @@ func TestAddPathIBGP(t *testing.T) { Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(2, 3, 4, 5), + NextHop: net.IPv4FromOctets(2, 3, 4, 5).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1291,13 +1291,13 @@ func TestAddPathIBGP(t *testing.T) { { name: "Remove 2nd path added above", routesRemove: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ EBGP: true, - NextHop: net.IPv4FromOctets(2, 3, 4, 5), - Source: net.IPv4(0), + NextHop: net.IPv4FromOctets(2, 3, 4, 5).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1312,16 +1312,16 @@ func TestAddPathIBGP(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1342,13 +1342,13 @@ func TestAddPathIBGP(t *testing.T) { { name: "Re-add 2nd path to existing one with different NH (with success)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ EBGP: true, - NextHop: net.IPv4FromOctets(3, 4, 5, 6), - Source: net.IPv4(0), + NextHop: net.IPv4FromOctets(3, 4, 5, 6).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1363,17 +1363,17 @@ func TestAddPathIBGP(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRouteAddPath(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), []*route.Path{ + route.NewRouteAddPath(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), []*route.Path{ { Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1392,12 +1392,12 @@ func TestAddPathIBGP(t *testing.T) { Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(3, 4, 5, 6), + NextHop: net.IPv4FromOctets(3, 4, 5, 6).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1418,13 +1418,13 @@ func TestAddPathIBGP(t *testing.T) { { name: "Add 3rd path to existing ones, containing NO_EXPORT community (successful)", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ EBGP: true, - NextHop: net.IPv4FromOctets(4, 5, 6, 7), - Source: net.IPv4(0), + NextHop: net.IPv4FromOctets(4, 5, 6, 7).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1442,17 +1442,17 @@ func TestAddPathIBGP(t *testing.T) { }), }, expected: []*route.Route{ - route.NewRouteAddPath(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), []*route.Path{ + route.NewRouteAddPath(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), []*route.Path{ { Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(1, 2, 3, 4), + NextHop: net.IPv4FromOctets(1, 2, 3, 4).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1471,12 +1471,12 @@ func TestAddPathIBGP(t *testing.T) { Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(3, 4, 5, 6), + NextHop: net.IPv4FromOctets(3, 4, 5, 6).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1495,12 +1495,12 @@ func TestAddPathIBGP(t *testing.T) { Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4FromOctets(4, 5, 6, 7), + NextHop: net.IPv4FromOctets(4, 5, 6, 7).Ptr(), Origin: 0, MED: 0, EBGP: true, LocalPref: 0, - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1525,13 +1525,13 @@ func TestAddPathIBGP(t *testing.T) { { name: "Add 4th path to existing ones, containing NO_ADVERTISE community", routesAdd: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ EBGP: true, - NextHop: net.IPv4FromOctets(5, 6, 7, 8), - Source: net.IPv4(0), + NextHop: net.IPv4FromOctets(5, 6, 7, 8).Ptr(), + Source: net.IPv4(0).Ptr(), }, ASPath: &types.ASPath{ types.ASPathSegment{ @@ -1556,11 +1556,11 @@ func TestAddPathIBGP(t *testing.T) { for i, test := range tests { fmt.Printf("Running iBGP AddPath test #%d: %s\n", i+1, test.name) for _, route := range test.routesAdd { - adjRIBOut.AddPath(route.Prefix(), route.Paths()[0]) + adjRIBOut.AddPath(route.Prefix().Ptr(), route.Paths()[0]) } for _, route := range test.routesRemove { - adjRIBOut.RemovePath(route.Prefix(), route.Paths()[0]) + adjRIBOut.RemovePath(route.Prefix().Ptr(), route.Paths()[0]) } if !assert.Equalf(t, test.expected, adjRIBOut.rt.Dump(), "Test %q", test.name) { diff --git a/routingtable/adjRIBOut/path_id_manager_test.go b/routingtable/adjRIBOut/path_id_manager_test.go index 7be75ae5ef5b6876b1e47210347b9d42b96ae1c9..25816d7e04402a94c5fbed641aca20e94a8a91aa 100644 --- a/routingtable/adjRIBOut/path_id_manager_test.go +++ b/routingtable/adjRIBOut/path_id_manager_test.go @@ -36,8 +36,8 @@ X: for i := 0; i < test.count; i++ { _, err := m.addPath(&route.Path{BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), LocalPref: uint32(i), }, }}) @@ -73,8 +73,8 @@ func TestReleasePath(t *testing.T) { { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 0, }, }, @@ -82,8 +82,8 @@ func TestReleasePath(t *testing.T) { { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 1, }, }, @@ -91,8 +91,8 @@ func TestReleasePath(t *testing.T) { { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 2, }, }, @@ -100,8 +100,8 @@ func TestReleasePath(t *testing.T) { }, release: &route.Path{BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 2, }, }}, @@ -109,8 +109,8 @@ func TestReleasePath(t *testing.T) { { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 0, }, }, @@ -118,8 +118,8 @@ func TestReleasePath(t *testing.T) { { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 1, }, }, @@ -132,8 +132,8 @@ func TestReleasePath(t *testing.T) { { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 0, }, }, @@ -141,8 +141,8 @@ func TestReleasePath(t *testing.T) { { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 1, }, }, @@ -150,8 +150,8 @@ func TestReleasePath(t *testing.T) { { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 2, }, }, @@ -159,8 +159,8 @@ func TestReleasePath(t *testing.T) { }, release: &route.Path{BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 5, }, }}, @@ -168,8 +168,8 @@ func TestReleasePath(t *testing.T) { { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 0, }, }, @@ -177,8 +177,8 @@ func TestReleasePath(t *testing.T) { { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 1, }, }, @@ -186,8 +186,8 @@ func TestReleasePath(t *testing.T) { { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), LocalPref: 2, }, }, diff --git a/routingtable/filter/actions/as_path_prepend_action_test.go b/routingtable/filter/actions/as_path_prepend_action_test.go index cc925e32d809538c2b0b5317a985bcc85fa40109..93f600af0b3053fb3f6da07c0c7a3b34906b5249 100644 --- a/routingtable/filter/actions/as_path_prepend_action_test.go +++ b/routingtable/filter/actions/as_path_prepend_action_test.go @@ -56,7 +56,7 @@ func TestAppendPath(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { a := NewASPathPrependAction(12345, test.times) - res := a.Do(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + res := a.Do(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ BGPPath: test.bgpPath, }) diff --git a/routingtable/filter/actions/set_local_pref_action_test.go b/routingtable/filter/actions/set_local_pref_action_test.go index 3025b6cbe8941838ae771bef74a1532da77fd78f..c653724948f281ba0a14ce61fb0c48b21161f4c2 100644 --- a/routingtable/filter/actions/set_local_pref_action_test.go +++ b/routingtable/filter/actions/set_local_pref_action_test.go @@ -31,7 +31,7 @@ func TestSetLocalPref(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { a := NewSetLocalPrefAction(150) - res := a.Do(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + res := a.Do(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ BGPPath: test.bgpPath, }) diff --git a/routingtable/filter/actions/set_nexthop_action_test.go b/routingtable/filter/actions/set_nexthop_action_test.go index 3b4f8aeaafde97bcbf74079d19284b68f15452f1..a1409541cb72d82b6be7300e5363fcb94c513916 100644 --- a/routingtable/filter/actions/set_nexthop_action_test.go +++ b/routingtable/filter/actions/set_nexthop_action_test.go @@ -23,17 +23,17 @@ func TestSetNextHopTest(t *testing.T) { name: "modify path", bgpPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ - NextHop: bnet.IPv4FromOctets(192, 168, 1, 1), + NextHop: bnet.IPv4FromOctets(192, 168, 1, 1).Ptr(), }, }, - expected: bnet.IPv4FromOctets(100, 64, 2, 1), + expected: bnet.IPv4FromOctets(100, 64, 2, 1).Ptr(), }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - a := NewSetNextHopAction(bnet.IPv4FromOctets(100, 64, 2, 1)) - res := a.Do(net.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + a := NewSetNextHopAction(bnet.IPv4FromOctets(100, 64, 2, 1).Ptr()) + res := a.Do(net.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ BGPPath: test.bgpPath, }) diff --git a/routingtable/filter/filter_test.go b/routingtable/filter/filter_test.go index cf3f31f0828ccb5ea4d8e1a91bad856e19d5e229..08595c56916913c714322913a04b35a14876b584 100644 --- a/routingtable/filter/filter_test.go +++ b/routingtable/filter/filter_test.go @@ -20,7 +20,7 @@ func TestProcessTerms(t *testing.T) { }{ { name: "accept", - prefix: net.NewPfx(net.IPv4(0), 0), + prefix: net.NewPfx(net.IPv4(0), 0).Ptr(), path: &route.Path{}, term: &Term{ then: []actions.Action{ @@ -32,7 +32,7 @@ func TestProcessTerms(t *testing.T) { }, { name: "reject", - prefix: net.NewPfx(net.IPv4(0), 0), + prefix: net.NewPfx(net.IPv4(0), 0).Ptr(), path: &route.Path{}, term: &Term{ then: []actions.Action{ @@ -44,7 +44,7 @@ func TestProcessTerms(t *testing.T) { }, { name: "accept before reject", - prefix: net.NewPfx(net.IPv4(0), 0), + prefix: net.NewPfx(net.IPv4(0), 0).Ptr(), path: &route.Path{}, term: &Term{ then: []actions.Action{ @@ -57,7 +57,7 @@ func TestProcessTerms(t *testing.T) { }, { name: "modified", - prefix: net.NewPfx(net.IPv4(0), 0), + prefix: net.NewPfx(net.IPv4(0), 0).Ptr(), path: &route.Path{}, term: &Term{ then: []actions.Action{ diff --git a/routingtable/filter/helper_test.go b/routingtable/filter/helper_test.go index 83cd47ab9b45076925e921137c13250096cc74db..ee2a70c88794b998114ee245f21d809e2f2cb505 100644 --- a/routingtable/filter/helper_test.go +++ b/routingtable/filter/helper_test.go @@ -11,13 +11,13 @@ import ( func TestNewAcceptAllFilter(t *testing.T) { f := NewAcceptAllFilter() - res := f.Process(net.NewPfx(net.IPv4(0), 0), &route.Path{}) + res := f.Process(net.NewPfx(net.IPv4(0), 0).Ptr(), &route.Path{}) assert.Equal(t, false, res.Reject) } func TestNewDrainFilter(t *testing.T) { f := NewDrainFilter() - res := f.Process(net.NewPfx(net.IPv4(0), 0), &route.Path{}) + res := f.Process(net.NewPfx(net.IPv4(0), 0).Ptr(), &route.Path{}) assert.Equal(t, true, res.Reject) } diff --git a/routingtable/filter/route_filter_test.go b/routingtable/filter/route_filter_test.go index 6bd9c9693cc2eac9ee5c95e8ace6f8c6523b90f2..eba58771c0614ed7f3ec7d426f38a70998c0dacc 100644 --- a/routingtable/filter/route_filter_test.go +++ b/routingtable/filter/route_filter_test.go @@ -18,56 +18,56 @@ func TestInRange(t *testing.T) { }{ { name: "matches and in range (22-24)", - prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 1, 0), 23), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 22), + prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 1, 0), 23).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 22).Ptr(), begin: 22, end: 24, expected: true, }, { name: "matches begin of range (22-24)", - prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 22), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 22), + prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 22).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 22).Ptr(), begin: 22, end: 24, expected: true, }, { name: "matches end of range (22-24)", - prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 22), + prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 22).Ptr(), begin: 22, end: 24, expected: true, }, { name: "matches begin and end of range (24-24)", - prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 24), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 24).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 24).Ptr(), begin: 24, end: 24, expected: true, }, { name: "smaller (22-24)", - prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 16), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 4, 0), 22), + prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 16).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 4, 0), 22).Ptr(), begin: 22, end: 24, expected: false, }, { name: "longer (22-24)", - prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 128), 25), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 22), + prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 128), 25).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 22).Ptr(), begin: 22, end: 24, expected: false, }, { name: "does not match", - prefix: net.NewPfx(net.IPv4FromOctets(2, 0, 0, 0), 23), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 22), + prefix: net.NewPfx(net.IPv4FromOctets(2, 0, 0, 0), 23).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 0, 0), 22).Ptr(), expected: false, }, } @@ -89,32 +89,32 @@ func TestExact(t *testing.T) { }{ { name: "matches (0.0.0.0/0)", - prefix: net.NewPfx(net.IPv4(0), 0), - pattern: net.NewPfx(net.IPv4(0), 0), + prefix: net.NewPfx(net.IPv4(0), 0).Ptr(), + pattern: net.NewPfx(net.IPv4(0), 0).Ptr(), expected: true, }, { name: "matches (192.168.0.0)", - prefix: net.NewPfx(net.IPv4FromOctets(192, 168, 1, 1), 24), - pattern: net.NewPfx(net.IPv4FromOctets(192, 168, 1, 1), 24), + prefix: net.NewPfx(net.IPv4FromOctets(192, 168, 1, 1), 24).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(192, 168, 1, 1), 24).Ptr(), expected: true, }, { name: "does not match", - prefix: net.NewPfx(net.IPv4FromOctets(1, 0, 0, 0), 8), - pattern: net.NewPfx(net.IPv4FromOctets(0, 0, 0, 0), 0), + prefix: net.NewPfx(net.IPv4FromOctets(1, 0, 0, 0), 8).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(0, 0, 0, 0), 0).Ptr(), expected: false, }, { name: "longer", - prefix: net.NewPfx(net.IPv4FromOctets(1, 0, 0, 0), 8), - pattern: net.NewPfx(net.IPv4FromOctets(1, 0, 0, 0), 7), + prefix: net.NewPfx(net.IPv4FromOctets(1, 0, 0, 0), 8).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 0, 0, 0), 7).Ptr(), expected: false, }, { name: "lesser", - prefix: net.NewPfx(net.IPv4FromOctets(1, 0, 0, 0), 7), - pattern: net.NewPfx(net.IPv4FromOctets(1, 0, 0, 0), 8), + prefix: net.NewPfx(net.IPv4FromOctets(1, 0, 0, 0), 7).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 0, 0, 0), 8).Ptr(), expected: false, }, } @@ -136,20 +136,20 @@ func TestOrLonger(t *testing.T) { }{ { name: "longer", - prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 128), 25), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 128), 25).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24).Ptr(), expected: true, }, { name: "exact", - prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24).Ptr(), expected: true, }, { name: "lesser", - prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 23), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 23).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24).Ptr(), expected: false, }, } @@ -171,20 +171,20 @@ func TestLonger(t *testing.T) { }{ { name: "longer", - prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 128), 25), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 128), 25).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24).Ptr(), expected: true, }, { name: "exact", - prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24).Ptr(), expected: false, }, { name: "lesser", - prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 23), - pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 23).Ptr(), + pattern: net.NewPfx(net.IPv4FromOctets(1, 2, 3, 0), 24).Ptr(), expected: false, }, } diff --git a/routingtable/filter/term_condition_test.go b/routingtable/filter/term_condition_test.go index 540d5cdf92e7e8475c5b00927d7a5b2cbd0793c3..989fd3791a1896adaf875b702d849c07c1f66ed6 100644 --- a/routingtable/filter/term_condition_test.go +++ b/routingtable/filter/term_condition_test.go @@ -22,90 +22,90 @@ func TestMatches(t *testing.T) { }{ { name: "one prefix matches in prefix list, no route filters set", - prefix: net.NewPfx(net.IPv4FromOctets(127, 0, 0, 1), 8), + prefix: net.NewPfx(net.IPv4FromOctets(127, 0, 0, 1), 8).Ptr(), prefixLists: []*PrefixList{ - NewPrefixList(net.NewPfx(net.IPv4FromOctets(127, 0, 0, 1), 8)), + NewPrefixList(net.NewPfx(net.IPv4FromOctets(127, 0, 0, 1), 8).Ptr()), }, expected: true, }, { name: "one prefix in prefix list and no match, no route filters set", - prefix: net.NewPfx(net.IPv4FromOctets(127, 0, 0, 1), 8), + prefix: net.NewPfx(net.IPv4FromOctets(127, 0, 0, 1), 8).Ptr(), prefixLists: []*PrefixList{ - NewPrefixList(net.NewPfx(net.IPv4(0), 32)), + NewPrefixList(net.NewPfx(net.IPv4(0), 32).Ptr()), }, expected: false, }, { name: "one prefix of 2 matches in prefix list, no route filters set", - prefix: net.NewPfx(net.IPv4FromOctets(127, 0, 0, 1), 8), + prefix: net.NewPfx(net.IPv4FromOctets(127, 0, 0, 1), 8).Ptr(), prefixLists: []*PrefixList{ - NewPrefixList(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8)), - NewPrefixList(net.NewPfx(net.IPv4FromOctets(127, 0, 0, 1), 8)), + NewPrefixList(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr()), + NewPrefixList(net.NewPfx(net.IPv4FromOctets(127, 0, 0, 1), 8).Ptr()), }, expected: true, }, { name: "no prefixes in prefix list, only route filter matches", - prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24).Ptr(), routeFilters: []*RouteFilter{ - NewRouteFilter(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), NewLongerMatcher()), + NewRouteFilter(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), NewLongerMatcher()), }, expected: true, }, { name: "no prefixes in prefix list, one route filter matches", - prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24).Ptr(), routeFilters: []*RouteFilter{ - NewRouteFilter(net.NewPfx(net.IPv4FromOctets(8, 0, 0, 0), 8), NewLongerMatcher()), - NewRouteFilter(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), NewLongerMatcher()), + NewRouteFilter(net.NewPfx(net.IPv4FromOctets(8, 0, 0, 0), 8).Ptr(), NewLongerMatcher()), + NewRouteFilter(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), NewLongerMatcher()), }, expected: true, }, { name: "no prefixes in prefix list, one of many route filters matches", - prefix: net.NewPfx(net.IPv4FromOctets(127, 0, 0, 1), 8), + prefix: net.NewPfx(net.IPv4FromOctets(127, 0, 0, 1), 8).Ptr(), routeFilters: []*RouteFilter{ - NewRouteFilter(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), NewLongerMatcher()), + NewRouteFilter(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), NewLongerMatcher()), }, expected: false, }, { name: "no match in prefix list, no macht in route filter", - prefix: net.NewPfx(net.IPv4FromOctets(9, 9, 9, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(9, 9, 9, 0), 24).Ptr(), prefixLists: []*PrefixList{ - NewPrefixList(net.NewPfx(net.IPv4FromOctets(8, 0, 0, 0), 8)), + NewPrefixList(net.NewPfx(net.IPv4FromOctets(8, 0, 0, 0), 8).Ptr()), }, routeFilters: []*RouteFilter{ - NewRouteFilter(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), NewLongerMatcher()), + NewRouteFilter(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), NewLongerMatcher()), }, expected: false, }, { name: "one prefix in prefixlist, one route filter, only prefix list matches", - prefix: net.NewPfx(net.IPv4FromOctets(8, 8, 8, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(8, 8, 8, 0), 24).Ptr(), prefixLists: []*PrefixList{ - NewPrefixList(net.NewPfx(net.IPv4FromOctets(8, 0, 0, 0), 8)), + NewPrefixList(net.NewPfx(net.IPv4FromOctets(8, 0, 0, 0), 8).Ptr()), }, routeFilters: []*RouteFilter{ - NewRouteFilter(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), NewLongerMatcher()), + NewRouteFilter(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), NewLongerMatcher()), }, expected: false, }, { name: "one prefix in prefixlist, one route filter, only route filter matches", - prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24).Ptr(), prefixLists: []*PrefixList{ - NewPrefixList(net.NewPfx(net.IPv4FromOctets(8, 0, 0, 0), 8)), + NewPrefixList(net.NewPfx(net.IPv4FromOctets(8, 0, 0, 0), 8).Ptr()), }, routeFilters: []*RouteFilter{ - NewRouteFilter(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), NewLongerMatcher()), + NewRouteFilter(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), NewLongerMatcher()), }, expected: false, }, { name: "community matches", - prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24).Ptr(), bgpPath: &route.BGPPath{ Communities: &types.Communities{65538, 196612, 327686}, // (1,2) (3,4) (5,6) }, @@ -116,7 +116,7 @@ func TestMatches(t *testing.T) { }, { name: "community does not match", - prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24).Ptr(), bgpPath: &route.BGPPath{ Communities: &types.Communities{65538, 196612, 327686}, // (1,2) (3,4) (5,6) }, @@ -127,7 +127,7 @@ func TestMatches(t *testing.T) { }, { name: "community filter, bgp path is nil", - prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24).Ptr(), communityFilters: []*CommunityFilter{ {196608}, // (3,0) }, @@ -135,7 +135,7 @@ func TestMatches(t *testing.T) { }, { name: "large community matches", - prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24).Ptr(), bgpPath: &route.BGPPath{ LargeCommunities: &types.LargeCommunities{ { @@ -163,7 +163,7 @@ func TestMatches(t *testing.T) { }, { name: "large community does not match", - prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24).Ptr(), bgpPath: &route.BGPPath{}, largeCommunityFilters: []*LargeCommunityFilter{ { @@ -178,7 +178,7 @@ func TestMatches(t *testing.T) { }, { name: "large community filter, bgp path is nil", - prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24), + prefix: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 24).Ptr(), largeCommunityFilters: []*LargeCommunityFilter{ { types.LargeCommunity{ diff --git a/routingtable/filter/term_test.go b/routingtable/filter/term_test.go index 1cb981265429f0910a165a6a169d69bda5f745e0..3c8661fc629fda976a93b349836fe4562a892498 100644 --- a/routingtable/filter/term_test.go +++ b/routingtable/filter/term_test.go @@ -34,7 +34,7 @@ func TestProcess(t *testing.T) { }{ { name: "empty from", - prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8), + prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8).Ptr(), path: &route.Path{}, from: []*TermCondition{}, then: []actions.Action{ @@ -45,11 +45,11 @@ func TestProcess(t *testing.T) { }, { name: "from matches", - prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8), + prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8).Ptr(), path: &route.Path{}, from: []*TermCondition{ NewTermConditionWithPrefixLists( - NewPrefixList(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8))), + NewPrefixList(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8).Ptr())), }, then: []actions.Action{ &actions.AcceptAction{}, @@ -59,11 +59,11 @@ func TestProcess(t *testing.T) { }, { name: "from does not match", - prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8), + prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8).Ptr(), path: &route.Path{}, from: []*TermCondition{ NewTermConditionWithPrefixLists( - NewPrefixList(net.NewPfx(net.IPv4(0), 32))), + NewPrefixList(net.NewPfx(net.IPv4(0), 32).Ptr())), }, then: []actions.Action{ &actions.AcceptAction{}, @@ -73,11 +73,11 @@ func TestProcess(t *testing.T) { }, { name: "modified", - prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8), + prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8).Ptr(), path: &route.Path{}, from: []*TermCondition{ NewTermConditionWithPrefixLists( - NewPrefixList(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8))), + NewPrefixList(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8).Ptr())), }, then: []actions.Action{ &mockAction{}, @@ -87,11 +87,11 @@ func TestProcess(t *testing.T) { }, { name: "modified and accepted (2 actions)", - prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8), + prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8).Ptr(), path: &route.Path{}, from: []*TermCondition{ NewTermConditionWithRouteFilters( - NewRouteFilter(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8), NewExactMatcher())), + NewRouteFilter(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8).Ptr(), NewExactMatcher())), }, then: []actions.Action{ &mockAction{}, @@ -102,13 +102,13 @@ func TestProcess(t *testing.T) { }, { name: "one of the prefix filters matches", - prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8), + prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8).Ptr(), path: &route.Path{}, from: []*TermCondition{ { prefixLists: []*PrefixList{ - NewPrefixListWithMatcher(NewExactMatcher(), net.NewPfx(net.IPv4(0), 32)), - NewPrefixList(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8)), + NewPrefixListWithMatcher(NewExactMatcher(), net.NewPfx(net.IPv4(0), 32).Ptr()), + NewPrefixList(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8).Ptr()), }, }, }, diff --git a/routingtable/locRIB/loc_rib_test.go b/routingtable/locRIB/loc_rib_test.go index 9ae30194d69426055f9e9d9931600e83bb6310ac..9fc68d3e7977ac3695ef78113e613a96563bd420 100644 --- a/routingtable/locRIB/loc_rib_test.go +++ b/routingtable/locRIB/loc_rib_test.go @@ -9,7 +9,7 @@ import ( ) type pfxPath struct { - pfx *bnet.Prefix + pfx bnet.Prefix path *route.Path } @@ -37,7 +37,7 @@ func TestContainsPfxPath(t *testing.T) { path: &route.Path{ Type: route.StaticPathType, StaticPath: &route.StaticPath{ - NextHop: bnet.IPv4(2), + NextHop: bnet.IPv4(2).Ptr(), }, }, }, @@ -56,7 +56,7 @@ func TestContainsPfxPath(t *testing.T) { path: &route.Path{ Type: route.StaticPathType, StaticPath: &route.StaticPath{ - NextHop: bnet.IPv4(2), + NextHop: bnet.IPv4(2).Ptr(), }, }, }, @@ -66,7 +66,7 @@ func TestContainsPfxPath(t *testing.T) { path: &route.Path{ Type: route.StaticPathType, StaticPath: &route.StaticPath{ - NextHop: bnet.IPv4(2), + NextHop: bnet.IPv4(2).Ptr(), }, }, }, @@ -76,21 +76,24 @@ func TestContainsPfxPath(t *testing.T) { for i, tc := range testCases { rib := New("inet.0") for _, p := range tc.in { - err := rib.AddPath(p.pfx, p.path) + err := rib.AddPath(&p.pfx, p.path) assert.Nil(t, err, "could not fill rib in testcase %v", i) } - contains := rib.ContainsPfxPath(tc.check.pfx, tc.check.path) + contains := rib.ContainsPfxPath(&tc.check.pfx, tc.check.path) assert.Equal(t, tc.expected, contains, "mismatch in testcase %v", i) } } func TestLocRIB_RemovePathUnknown(t *testing.T) { rib := New("inet.0") - assert.True(t, rib.RemovePath(bnet.NewPfx(bnet.IPv4(1), 32), - &route.Path{ - Type: route.StaticPathType, - StaticPath: &route.StaticPath{ - NextHop: bnet.IPv4(2), - }, - })) + assert.True( + t, + rib.RemovePath( + bnet.NewPfx(bnet.IPv4(1), 32).Ptr(), + &route.Path{ + Type: route.StaticPathType, + StaticPath: &route.StaticPath{ + NextHop: bnet.IPv4(2).Ptr(), + }, + })) } diff --git a/routingtable/table_test.go b/routingtable/table_test.go index 27747939df9ca58382ba60d2960dd6520a5264ca..c2da0f665e9e17c360e4adb938322677120d9421 100644 --- a/routingtable/table_test.go +++ b/routingtable/table_test.go @@ -18,19 +18,19 @@ func TestAddPath(t *testing.T) { { name: "10/8 and 11/8", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), nil), }, expected: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7).Ptr(), nil), dummy: true, skip: 7, l: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), skip: 0, }, h: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), nil), skip: 0, }, }, @@ -39,10 +39,10 @@ func TestAddPath(t *testing.T) { { name: "Insert first node", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), }, expected: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), skip: 8, }, expectedCount: 1, @@ -50,13 +50,13 @@ func TestAddPath(t *testing.T) { { name: "Insert duplicate node", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), }, expected: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), skip: 8, }, expectedCount: 1, @@ -64,18 +64,18 @@ func TestAddPath(t *testing.T) { { name: "Insert triangle", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9).Ptr(), nil), }, expected: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), skip: 8, l: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), nil), }, h: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9).Ptr(), nil), }, }, expectedCount: 3, @@ -83,18 +83,18 @@ func TestAddPath(t *testing.T) { { name: "Insert disjunct prefixes", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), }, expected: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7).Ptr(), nil), skip: 7, dummy: true, l: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), }, h: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), skip: 16, }, }, @@ -103,28 +103,28 @@ func TestAddPath(t *testing.T) { { name: "Insert disjunct prefixes plus one child low", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), }, expected: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7).Ptr(), nil), skip: 7, dummy: true, l: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), l: &node{ skip: 1, - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), l: &node{ skip: 1, - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), }, }, }, h: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), skip: 16, }, }, @@ -133,32 +133,32 @@ func TestAddPath(t *testing.T) { { name: "Insert disjunct prefixes plus one child high", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 128), 25), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 128), 25).Ptr(), nil), }, expected: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7).Ptr(), nil), skip: 7, dummy: true, l: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), l: &node{ skip: 1, - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), l: &node{ skip: 1, - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), }, }, }, h: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), skip: 16, h: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 128), 25), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 128), 25).Ptr(), nil), }, }, }, @@ -167,33 +167,33 @@ func TestAddPath(t *testing.T) { { name: "Insert disjunct prefixes plus one child high #2", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 128), 25), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 128), 25).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), }, expected: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7).Ptr(), nil), skip: 7, dummy: true, l: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), l: &node{ skip: 1, - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), l: &node{ skip: 1, - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), }, }, }, h: &node{ skip: 16, - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), h: &node{ skip: 0, - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 128), 25), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 128), 25).Ptr(), nil), }, }, }, @@ -202,33 +202,33 @@ func TestAddPath(t *testing.T) { { name: "Insert disjunct prefixes plus one child high #3", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 128), 25), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 128), 25).Ptr(), nil), }, expected: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7).Ptr(), nil), skip: 7, dummy: true, l: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), l: &node{ skip: 1, - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), l: &node{ skip: 1, - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), }, }, }, h: &node{ skip: 16, - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), h: &node{ skip: 0, - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 128), 25), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 128), 25).Ptr(), nil), }, }, }, @@ -237,18 +237,18 @@ func TestAddPath(t *testing.T) { { name: "Insert triangle #2", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), nil), }, expected: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), skip: 8, l: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), nil), }, h: &node{ - route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), nil), + route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9).Ptr(), nil), }, }, expectedCount: 3, @@ -276,67 +276,67 @@ func TestGet(t *testing.T) { { name: "Test 1: Search pfx and dump route + more specifics", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), }, - needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), - expected: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), + expected: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), }, { name: "Test 2: Search pfx and don't dump more specifics", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), }, - needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), - expected: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), + needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), + expected: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), }, { name: "Test 3: Empty table", routes: []*route.Route{}, - needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 32), + needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 32).Ptr(), expected: nil, }, { name: "Test 4: Get Dummy", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), }, - needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7), + needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7).Ptr(), expected: nil, }, { name: "Test 5", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), }, - needle: net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), - expected: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), + needle: net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), + expected: route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), }, { name: "Test 4: Get nonexistent #1", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), }, - needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), + needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), expected: nil, }, { name: "Test 4: Get nonexistent #2", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), }, - needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), + needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), expected: nil, }, } @@ -368,22 +368,22 @@ func TestGetLonger(t *testing.T) { { name: "Test 1: Search pfx and dump route + more specifics", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), }, - needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), }, }, { name: "Test 2: Empty root", routes: nil, - needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), expected: []*route.Route{}, }, } @@ -416,36 +416,36 @@ func TestLPM(t *testing.T) { { name: "LPM for non-existent route", routes: []*route.Route{}, - needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 32), + needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 32).Ptr(), expected: nil, }, { name: "Positive LPM test", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), }, - needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 32), + needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 32).Ptr(), expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), }, }, { name: "Exact match", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 100, 123, 0), 24).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 12).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), }, - needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), + needle: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), nil), + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 10).Ptr(), nil), }, }, } @@ -471,26 +471,26 @@ func TestRemovePath(t *testing.T) { { name: "Remove a path that is the only one for a prefix", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: route.NewBGPPathA(), }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: route.NewBGPPathA(), }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: route.NewBGPPathA(), }, }), }, - removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), removePath: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ @@ -498,13 +498,13 @@ func TestRemovePath(t *testing.T) { }, }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: route.NewBGPPathA(), }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: route.NewBGPPathA(), @@ -516,68 +516,68 @@ func TestRemovePath(t *testing.T) { { name: "Remove a path that is one of two for a prefix", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1000, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 2000, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: route.NewBGPPathA(), }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: route.NewBGPPathA(), }, }), }, - removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), removePath: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1000, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 2000, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: route.NewBGPPathA(), }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: route.NewBGPPathA(), @@ -621,7 +621,7 @@ func TestReplacePath(t *testing.T) { }{ /*{ name: "replace in empty table", - replacePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + replacePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), replacePath: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ @@ -629,7 +629,7 @@ func TestReplacePath(t *testing.T) { }, }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: route.NewBGPPathA(), @@ -641,56 +641,56 @@ func TestReplacePath(t *testing.T) { { name: "replace not existing prefix with multiple paths", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1001, NextHop: net.IPv4(101), - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1002, NextHop: net.IPv4(100), - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, }, }), }, - replacePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + replacePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), replacePath: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1000, - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1000, - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }), - newMultiPathRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + newMultiPathRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1001, NextHop: net.IPv4(101), - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, }, }, &route.Path{ @@ -699,7 +699,7 @@ func TestReplacePath(t *testing.T) { BGPPathA: &route.BGPPathA{ LocalPref: 1002, NextHop: net.IPv4(100), - Source: net.IPv4(0), + Source: net.IPv4(0).Ptr(), }, }, }), @@ -709,76 +709,76 @@ func TestReplacePath(t *testing.T) { { name: "replace existing prefix with multiple paths", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1, - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 2, - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1001, - NextHop: net.IPv4(101), - Source: net.IPv4(0), + NextHop: net.IPv4(101).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1002, - NextHop: net.IPv4(102), - Source: net.IPv4(0), + NextHop: net.IPv4(102).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }), }, - replacePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + replacePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), replacePath: &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1000, - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }, expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1000, - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }), - newMultiPathRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + newMultiPathRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1001, - NextHop: net.IPv4(101), - Source: net.IPv4(0), + NextHop: net.IPv4(101).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }, &route.Path{ @@ -786,8 +786,8 @@ func TestReplacePath(t *testing.T) { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1002, - NextHop: net.IPv4(102), - Source: net.IPv4(0), + NextHop: net.IPv4(102).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }), @@ -798,8 +798,8 @@ func TestReplacePath(t *testing.T) { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1, - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }, @@ -808,8 +808,8 @@ func TestReplacePath(t *testing.T) { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 2, - NextHop: net.IPv4(0), - Source: net.IPv4(0), + NextHop: net.IPv4(0).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }, @@ -843,14 +843,14 @@ func TestRemovePrefix(t *testing.T) { }{ { name: "remove in empty table", - removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), expected: []*route.Route{}, expectedOld: nil, }, { name: "remove not exist prefix", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -859,19 +859,19 @@ func TestRemovePrefix(t *testing.T) { }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1002, - NextHop: net.IPv4(100), + NextHop: net.IPv4(100).Ptr(), }, }, }), }, - removePfx: net.NewPfx(net.IPv4FromOctets(12, 0, 0, 0), 8), + removePfx: net.NewPfx(net.IPv4FromOctets(12, 0, 0, 0), 8).Ptr(), expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -880,12 +880,12 @@ func TestRemovePrefix(t *testing.T) { }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1002, - NextHop: net.IPv4(100), + NextHop: net.IPv4(100).Ptr(), }, }, }), @@ -895,7 +895,7 @@ func TestRemovePrefix(t *testing.T) { { name: "remove not existing more specific prefix", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -904,19 +904,19 @@ func TestRemovePrefix(t *testing.T) { }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1002, - NextHop: net.IPv4(100), + NextHop: net.IPv4(100).Ptr(), }, }, }), }, - removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), + removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9).Ptr(), expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -925,12 +925,12 @@ func TestRemovePrefix(t *testing.T) { }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1002, - NextHop: net.IPv4(100), + NextHop: net.IPv4(100).Ptr(), }, }, }), @@ -940,7 +940,7 @@ func TestRemovePrefix(t *testing.T) { { name: "remove not existing more less prefix", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -949,19 +949,19 @@ func TestRemovePrefix(t *testing.T) { }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1002, - NextHop: net.IPv4(100), + NextHop: net.IPv4(100).Ptr(), }, }, }), }, - removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7), + removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 7).Ptr(), expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ @@ -970,12 +970,12 @@ func TestRemovePrefix(t *testing.T) { }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1002, - NextHop: net.IPv4(100), + NextHop: net.IPv4(100).Ptr(), }, }, }), @@ -985,46 +985,46 @@ func TestRemovePrefix(t *testing.T) { { name: "remove existing prefix", routes: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 2, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }), - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1002, - NextHop: net.IPv4(100), - Source: net.IPv4(0), + NextHop: net.IPv4(100).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }), }, - removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), + removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8).Ptr(), expected: []*route.Route{ - route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8), &route.Path{ + route.NewRoute(net.NewPfx(net.IPv4FromOctets(11, 0, 0, 0), 8).Ptr(), &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1002, - NextHop: net.IPv4(100), - Source: net.IPv4(0), + NextHop: net.IPv4(100).Ptr(), + Source: net.IPv4(0).Ptr(), }, }, }), @@ -1035,8 +1035,8 @@ func TestRemovePrefix(t *testing.T) { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 1, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, @@ -1045,8 +1045,8 @@ func TestRemovePrefix(t *testing.T) { BGPPath: &route.BGPPath{ BGPPathA: &route.BGPPathA{ LocalPref: 2, - Source: net.IPv4(0), - NextHop: net.IPv4(0), + Source: net.IPv4(0).Ptr(), + NextHop: net.IPv4(0).Ptr(), }, }, }, diff --git a/routingtable/trie.go b/routingtable/trie.go index deab03c409f699024b0b847ec0d1b28a71ea1fbc..8fdb3ab22522c47a59ce59cb59beb47c83c278d7 100644 --- a/routingtable/trie.go +++ b/routingtable/trie.go @@ -169,7 +169,7 @@ func (n *node) newSuperNode(pfx *net.Prefix, p *route.Path) *node { pfxLenDiff := n.route.Pfxlen() - superNet.Pfxlen() skip := n.skip - pfxLenDiff - pseudoNode := newNode(superNet, nil, skip, true) + pseudoNode := newNode(&superNet, nil, skip, true) pseudoNode.insertChildren(n, pfx, p) return pseudoNode } diff --git a/routingtable/update_helper_test.go b/routingtable/update_helper_test.go index 32b936a96d2f813904db5f71aca07a25b68a61cf..c545e35afbc7c4def154c73cf968ac37b4429527 100644 --- a/routingtable/update_helper_test.go +++ b/routingtable/update_helper_test.go @@ -26,7 +26,7 @@ func TestShouldPropagateUpdate(t *testing.T) { communities: "(1,2)", neighbor: Neighbor{ Type: route.BGPPathType, - Address: bnet.IPv4FromOctets(192, 168, 1, 1), + Address: bnet.IPv4FromOctets(192, 168, 1, 1).Ptr(), }, expected: false, }, @@ -73,13 +73,13 @@ func TestShouldPropagateUpdate(t *testing.T) { comms = append(comms, com) } - pfx := bnet.NewPfx(bnet.IPv4(0), 32) + pfx := bnet.NewPfx(bnet.IPv4(0), 32).Ptr() pa := &route.Path{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ Communities: &comms, BGPPathA: &route.BGPPathA{ - Source: bnet.IPv4FromOctets(192, 168, 1, 1), + Source: bnet.IPv4FromOctets(192, 168, 1, 1).Ptr(), }, }, } diff --git a/routingtable/vrf/metrics_test.go b/routingtable/vrf/metrics_test.go index 1cb2af75ca610784b0543ac680ea16a37f85486d..4c22b147eadbea2de0cc4abeabde144d615f76a3 100644 --- a/routingtable/vrf/metrics_test.go +++ b/routingtable/vrf/metrics_test.go @@ -15,13 +15,13 @@ import ( func TestMetrics(t *testing.T) { r := NewVRFRegistry() green := r.CreateVRFIfNotExists("green", 0) - green.IPv4UnicastRIB().AddPath(bnet.NewPfx(bnet.IPv4FromOctets(8, 0, 0, 0), 8), &route.Path{}) - green.IPv4UnicastRIB().AddPath(bnet.NewPfx(bnet.IPv4FromOctets(8, 0, 0, 0), 16), &route.Path{}) - green.IPv6UnicastRIB().AddPath(bnet.NewPfx(bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0), 48), &route.Path{}) + green.IPv4UnicastRIB().AddPath(bnet.NewPfx(bnet.IPv4FromOctets(8, 0, 0, 0), 8).Ptr(), &route.Path{}) + green.IPv4UnicastRIB().AddPath(bnet.NewPfx(bnet.IPv4FromOctets(8, 0, 0, 0), 16).Ptr(), &route.Path{}) + green.IPv6UnicastRIB().AddPath(bnet.NewPfx(bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0, 0, 0, 0, 0), 48).Ptr(), &route.Path{}) red := r.CreateVRFIfNotExists("red", 1) - red.IPv6UnicastRIB().AddPath(bnet.NewPfx(bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 0, 0, 0, 0), 64), &route.Path{}) - red.IPv6UnicastRIB().AddPath(bnet.NewPfx(bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x200, 0, 0, 0, 0), 64), &route.Path{}) + red.IPv6UnicastRIB().AddPath(bnet.NewPfx(bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x100, 0, 0, 0, 0), 64).Ptr(), &route.Path{}) + red.IPv6UnicastRIB().AddPath(bnet.NewPfx(bnet.IPv6FromBlocks(0x2001, 0x678, 0x1e0, 0x200, 0, 0, 0, 0), 64).Ptr(), &route.Path{}) expected := []*metrics.VRFMetrics{ { diff --git a/util/decode/decode.go b/util/decode/decode.go index 44489fbc5f753db4ea42976ad5df1795ed70288d..d32e2933272b85d7291ebeb2a8b9e9afd0d33220 100644 --- a/util/decode/decode.go +++ b/util/decode/decode.go @@ -18,3 +18,53 @@ func Decode(buf *bytes.Buffer, fields []interface{}) error { } return nil } + +func DecodeUint8(buf *bytes.Buffer, x *uint8) error { + y, err := buf.ReadByte() + if err != nil { + return err + } + + *x = y + return nil +} + +func DecodeUint16(buf *bytes.Buffer, x *uint16) error { + a, err := buf.ReadByte() + if err != nil { + return err + } + + b, err := buf.ReadByte() + if err != nil { + return err + } + + *x = uint16(a)*256 + uint16(b) + return nil +} + +func DecodeUint32(buf *bytes.Buffer, x *uint32) error { + a, err := buf.ReadByte() + if err != nil { + return err + } + + b, err := buf.ReadByte() + if err != nil { + return err + } + + c, err := buf.ReadByte() + if err != nil { + return err + } + + d, err := buf.ReadByte() + if err != nil { + return err + } + + *x = uint32(a)*256*256*256 + uint32(b)*256*256*256 + uint32(c)*256 + uint32(d) + return nil +} diff --git a/util/net/net_addr.go b/util/net/net_addr.go index c74c551b472c83b68f4972602a3e5088ab815b8a..4ec7ec56fb00bf41135bcd5def21e0d6a3f8f44c 100644 --- a/util/net/net_addr.go +++ b/util/net/net_addr.go @@ -7,10 +7,10 @@ import ( ) // BIONetIPFromAddr retrives the IP from an net.Addr and returns the IP in BIO's internal IP type -func BIONetIPFromAddr(hostPort string) (*bnet.IP, error) { +func BIONetIPFromAddr(hostPort string) (bnet.IP, error) { host, _, err := net.SplitHostPort(hostPort) if err != nil { - return nil, err + return bnet.IP{}, err } return bnet.IPFromString(host) diff --git a/util/net/net_addr_test.go b/util/net/net_addr_test.go index 79e847997e81b70f835979affdf28480df66366a..bd479fcc28523a81ce38d9edcfb39ae68a6618e7 100644 --- a/util/net/net_addr_test.go +++ b/util/net/net_addr_test.go @@ -11,7 +11,7 @@ func TestBIONetIPFromAddr(t *testing.T) { tests := []struct { name string hostPort string - expected *bnet.IP + expected bnet.IP wantFail bool }{ {