@@ -6,14 +6,15 @@ import (
66 "time"
77
88 bnet "github.com/bio-routing/bio-rd/net"
9+ "github.com/stretchr/testify/assert"
910)
1011
1112func TestBMPServer (t * testing.T ) {
1213 srv := NewServer (BMPServerConfig {
1314 KeepalivePeriod : time .Second ,
1415 })
1516
16- rtr := newRouter (net.IP {10 , 0 , 255 , 1 }, 30119 , false , & adjRIBInFactory {})
17+ rtr := newRouter (net.IP {10 , 0 , 255 , 1 }, 30119 , false , & adjRIBInFactory {}, [] uint32 { 13335 } )
1718 _ , pipe := net .Pipe ()
1819 rtr .con = pipe
1920 srv .routers [rtr .address .String ()] = rtr
@@ -176,6 +177,97 @@ func TestBMPServer(t *testing.T) {
176177 }
177178 rtr .processMsg (peerUpC )
178179
180+ peerUpD := []byte {
181+ 3 , // Version
182+ 0 , 0 , 0 , 126 , // Length
183+ 3 , // Msg Type (peer up)
184+
185+ 0 , // Peer Type (global instance peer)
186+ 0 , // Peer Flags
187+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // Peer Distinguisher
188+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 1 , 2 , 100 , // Peer Address (10.1.2.100)
189+ 0 , 0 , 52 , 23 , // Peer AS = 13335
190+ 0 , 0 , 0 , 233 , // Peer BGP ID = 240
191+ 0 , 0 , 0 , 0 , // Timestamp seconds
192+ 0 , 0 , 0 , 0 , // Timestamp microseconds
193+
194+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 1 , 2 , 200 , // Local Address (10.1.2.200)
195+ 0 , 222 , // Local Port
196+ 0 , 179 , // Remote Port
197+
198+ // Sent OPEN
199+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , // Marker
200+ 0 , 29 , // Length
201+ 1 , // Type (OPEN)
202+ 4 , // BGP Version
203+ 0 , 100 , // ASN
204+ 0 , 180 , // Hold Time
205+ 1 , 0 , 0 , 100 , // BGP ID
206+ 0 , // Ops Param Len
207+
208+ // Received OPEN
209+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , // Marker
210+ 0 , 29 , // Length
211+ 1 , // Type (OPEN)
212+ 4 , // BGP Version
213+ 0 , 233 , // ASN
214+ 0 , 180 , // Hold Time
215+ 1 , 0 , 0 , 222 , // BGP ID
216+ 0 , // Ops Param Len
217+ }
218+ rtr .processMsg (peerUpD )
219+
220+ assert .Equal (t , rtr .ignoredPeers , map [bnet.IP ]struct {}{
221+ bnet .IPv4FromOctets (10 , 1 , 2 , 100 ): {},
222+ })
223+
224+ updateD1 := []byte {
225+ 3 , // Version
226+ 0 , 0 , 0 , 100 , // Length
227+ 0 , // Msg Type (route monitoring)
228+
229+ 0 , // Peer Type (global instance peer)
230+ 0b01100000 , // Peer Flags
231+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 123 , // Peer Distinguisher
232+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 1 , 2 , 100 , // Peer Address (10.1.2.100)
233+ 0 , 0 , 0 , 200 , // Peer AS = 200
234+ 0 , 0 , 0 , 200 , // Peer BGP ID = 200
235+ 0 , 0 , 0 , 0 , // Timestamp seconds
236+ 0 , 0 , 0 , 0 , // Timestamp microseconds
237+
238+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , // Marker
239+ 0 , 52 , // Length
240+ 2 , // Type (UPDATE)
241+
242+ 0 , 0 , // Withdraw length
243+ 0 , 27 , // Total Path Attribute Length
244+
245+ 0 , // Attribute flags
246+ 3 , // Attribute Type code (Next Hop)
247+ 4 , // Length
248+ 10 , 0 , 0 , 0 ,
249+
250+ 255 , // Attribute flags
251+ 1 , // Attribute Type code (ORIGIN)
252+ 0 , 1 , // Length
253+ 2 , // INCOMPLETE
254+
255+ 0 , // Attribute flags
256+ 2 , // Attribute Type code (AS Path)
257+ 12 , // Length
258+ 2 , // Type = AS_SEQUENCE
259+ 2 , // Path Segment Length
260+ 59 , 65 , // AS15169
261+ 12 , 248 , // AS3320
262+ 1 , // Type = AS_SET
263+ 2 , // Path Segment Length
264+ 59 , 65 , // AS15169
265+ 12 , 248 , // AS3320
266+
267+ 8 , 20 , // 20.0.0.0/8
268+ }
269+ rtr .processMsg (updateD1 )
270+
179271 aaaaVRFs = aaaa .GetVRFs ()
180272 if len (aaaaVRFs ) != 2 {
181273 t .Errorf ("Unexpected VRF count for router AAAA: %d" , len (aaaaVRFs ))
0 commit comments