@@ -160,6 +160,34 @@ def check_for_prefixes(expected_prefixes, bmp_log_type, policy, labels=None):
160
160
return True
161
161
162
162
163
+ def check_for_peer_message (expected_peers , bmp_log_type ):
164
+ """
165
+ Check for the presence of a peer up message for the peer
166
+ """
167
+ global SEQ
168
+ # we care only about the new messages
169
+ messages = [
170
+ m for m in sorted (get_bmp_messages (), key = lambda d : d ["seq" ]) if m ["seq" ] > SEQ
171
+ ]
172
+
173
+ # get the list of pairs (prefix, policy, seq) for the given message type
174
+ peers = [
175
+ m ["peer_ip" ]
176
+ for m in messages
177
+ if "peer_ip" in m .keys () and m ["bmp_log_type" ] == bmp_log_type
178
+ ]
179
+
180
+ # check for prefixes
181
+ for ep in expected_peers :
182
+ if ep not in peers :
183
+ msg = "The peer {} is not present in the {} log messages."
184
+ logger .debug (msg .format (ep , bmp_log_type ))
185
+ return False
186
+
187
+ SEQ = messages [- 1 ]["seq" ]
188
+ return True
189
+
190
+
163
191
def set_bmp_policy (tgen , node , asn , target , safi , policy , vrf = None ):
164
192
"""
165
193
Configure the bmp policy.
@@ -234,15 +262,11 @@ def vpn_prefixes(policy):
234
262
235
263
prefixes = ["172.31.10.1/32" , "2001::2222/128" ]
236
264
237
- if policy == PRE_POLICY :
238
- # labels are not yet supported in adj-RIB-in. Do not test for the moment
239
- labels = None
240
- else :
241
- # "label vpn export" value in r2/bgpd.conf
242
- labels = {
243
- "172.31.10.1/32" : 102 ,
244
- "2001::2222/128" : 105 ,
245
- }
265
+ # "label vpn export" value in r2/bgpd.conf
266
+ labels = {
267
+ "172.31.10.1/32" : 102 ,
268
+ "2001::2222/128" : 105 ,
269
+ }
246
270
247
271
# add prefixes
248
272
configure_prefixes (tgen , "r2" , 65502 , "unicast" , prefixes , vrf = "vrf1" )
@@ -280,6 +304,20 @@ def check_for_log_file():
280
304
assert success , "The BMP server is not logging"
281
305
282
306
307
+ def test_peer_up ():
308
+ """
309
+ Checking for BMP peers up messages
310
+ """
311
+
312
+ peers = ["192.168.0.2" , "192:168::2" ]
313
+
314
+ logger .info ("checking for BMP peers up messages" )
315
+
316
+ test_func = partial (check_for_peer_message , peers , "peer up" )
317
+ success , _ = topotest .run_and_expect (test_func , True , wait = 0.5 )
318
+ assert success , "Checking the updated prefixes has been failed !."
319
+
320
+
283
321
def test_bmp_bgp_unicast ():
284
322
"""
285
323
Add/withdraw bgp unicast prefixes and check the bmp logs.
@@ -302,6 +340,23 @@ def test_bmp_bgp_vpn():
302
340
vpn_prefixes (LOC_RIB )
303
341
304
342
343
+ def test_peer_down ():
344
+ """
345
+ Checking for BMP peers down messages
346
+ """
347
+ tgen = get_topogen ()
348
+
349
+ tgen .gears ["r2" ].vtysh_cmd ("clear bgp *" )
350
+
351
+ peers = ["192.168.0.2" , "192:168::2" ]
352
+
353
+ logger .info ("checking for BMP peers down messages" )
354
+
355
+ test_func = partial (check_for_peer_message , peers , "peer down" )
356
+ success , _ = topotest .run_and_expect (test_func , True , wait = 0.5 )
357
+ assert success , "Checking the updated prefixes has been failed !."
358
+
359
+
305
360
if __name__ == "__main__" :
306
361
args = ["-s" ] + sys .argv [1 :]
307
362
sys .exit (pytest .main (args ))
0 commit comments