1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
use std::{net::IpAddr, str::FromStr, sync::Arc, time::Instant};
use bytes::Bytes;
use chrono::Utc;
use inetnum::{addr::Prefix, asn::Asn};
//use roto::types::builtin::SourceId;
//use roto::types::{
// builtin::{BuiltinTypeValue, NlriStatus, RouteContext},
// typevalue::TypeValue,
//};
use routecore::bmp::message::{Message as BmpMsg, PerPeerHeader};
use crate::{
bgp::encode::{mk_per_peer_header, Announcements, Prefixes},
common::status_reporter::AnyStatusReporter,
payload::{Payload, RotondaRoute, Update},
roto_runtime::types::RouteContext,
tests::util::internal::get_testable_metrics_snapshot,
units::bmp_tcp_in::{
metrics::BmpTcpInMetrics,
state_machine::{
machine::{BmpState, PeerAware},
processing::MessageType,
states::{dumping::Dumping, updating::Updating},
},
status_reporter::BmpTcpInStatusReporter,
},
};
use super::{
machine::{BmpStateDetails, PeerStates},
metrics::BmpStateMachineMetrics,
processing::ProcessingResult,
};
const TEST_ROUTER_SYS_NAME: &str = "test-router";
const TEST_ROUTER_SYS_DESC: &str = "test-desc";
#[test]
fn initiate() {
// Given a processor in the Initiate phase
let processor = mk_test_processor();
// When it processes a BMP initiation message
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let res = processor.process_msg(Instant::now(), initiation_msg_buf, None);
// Then the phase is unchanged but the sysName and sysDesc are updated
assert!(matches!(res.message_type, MessageType::StateTransition));
assert!(matches!(res.next_state, BmpState::Dumping(_)));
if let BmpState::Dumping(next_state) = &res.next_state {
let Dumping {
sys_name,
sys_desc,
peer_states,
..
} = &next_state.details;
assert_eq!(sys_name, TEST_ROUTER_SYS_NAME);
assert_eq!(sys_desc, TEST_ROUTER_SYS_DESC);
assert!(peer_states.is_empty());
}
}
#[test]
fn terminate() {
// Given
let processor = mk_test_processor();
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let termination_msg_buf = mk_termination_msg();
let processor = processor
.process_msg(Instant::now(), initiation_msg_buf, None)
.next_state;
// When
let res =
processor.process_msg(Instant::now(), termination_msg_buf, None);
// Then
assert!(matches!(res.message_type, MessageType::StateTransition));
assert!(matches!(res.next_state, BmpState::Terminated(_)));
// Check the metrics
let processor = res.next_state;
assert_metrics(
&processor,
("Terminated", [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
);
// ^ 1 connected router
}
#[test]
fn statistics_report() {
// Given
let processor = mk_test_processor();
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let (pph, peer_up_msg_buf, _real_pph) =
mk_peer_up_notification_msg_without_rfc4724_support(
"127.0.0.1",
12345,
);
let stats_report_msg_buf = mk_statistics_report_msg(&pph);
let processor = processor
.process_msg(Instant::now(), initiation_msg_buf, None)
.next_state;
// When
let processor = processor
.process_msg(Instant::now(), peer_up_msg_buf, None)
.next_state;
let res =
processor.process_msg(Instant::now(), stats_report_msg_buf, None);
// Then
assert!(matches!(res.message_type, MessageType::Other));
assert!(matches!(res.next_state, BmpState::Dumping(_)));
// Check the metrics
let processor = res.next_state;
assert_metrics(&processor, ("Dumping", [1, 0, 0, 0, 0, 0, 1, 0, 0, 0]));
// ^ 1 connected router
// ^ 1 up peer
}
#[test]
fn peer_up_with_eor_capable_peer() {
// Given
let processor = mk_test_processor();
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let (_, peer_up_msg_buf) =
mk_eor_capable_peer_up_notification_msg("127.0.0.1", 12345);
let processor = processor
.process_msg(Instant::now(), initiation_msg_buf, None)
.next_state;
assert!(
matches!(&processor, BmpState::Dumping(BmpStateDetails::<Dumping> { details, .. }) if details.peer_states.is_empty())
);
// When
let res = processor.process_msg(Instant::now(), peer_up_msg_buf, None);
// Then
assert!(matches!(res.message_type, MessageType::Other));
assert!(matches!(res.next_state, BmpState::Dumping(_)));
if let BmpState::Dumping(next_state) = &res.next_state {
let Dumping { peer_states, .. } = &next_state.details;
assert_eq!(peer_states.num_peer_configs(), 1);
let pph = peer_states.get_peers().next().unwrap();
assert_eq!(peer_states.is_peer_eor_capable(pph), Some(true));
assert_eq!(peer_states.num_pending_eors(), 0); // zero because we have to see a route announcement to know which (S)AFI an EoR is expected for
}
// Check the metrics
let processor = res.next_state;
assert_metrics(&processor, ("Dumping", [1, 0, 0, 0, 0, 0, 1, 0, 1, 0]));
// ^ 1 connected router
// ^ 1 up peer
// and the peer is EoR capable ^
}
#[test]
fn duplicate_peer_up() {
// Given
let processor = mk_test_processor();
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let (_, peer_up_msg_1_buf, _) =
mk_peer_up_notification_msg_without_rfc4724_support(
"127.0.0.1",
12345,
);
let (_, peer_up_msg_2_buf, _) =
mk_peer_up_notification_msg_without_rfc4724_support(
"127.0.0.1",
12345,
);
let processor = processor
.process_msg(Instant::now(), initiation_msg_buf, None)
.next_state;
assert!(
matches!(&processor, BmpState::Dumping(BmpStateDetails::<Dumping> { details, .. }) if details.peer_states.is_empty())
);
// When
let processor = processor
.process_msg(Instant::now(), peer_up_msg_1_buf, None)
.next_state;
let res = processor.process_msg(Instant::now(), peer_up_msg_2_buf, None);
// Then
assert!(matches!(res.next_state, BmpState::Dumping(_)));
assert_invalid_msg_starts_with(
&res,
"PeerUpNotification received for peer that is already 'up'",
);
// Check the metrics
let processor = res.next_state;
assert_metrics(
&processor,
("Dumping", [1, 0, 0, 0, 1, 0, 1, 0, 0, 0]),
// ^ 1 connected router
// ^ 1 peer up
// ^ 1 unprocessable BMP message
);
}
#[test]
fn peer_up_route_monitoring_peer_down() {
// Given a BMP state machine in the Dumping state with no known peers
let processor = mk_test_processor();
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let (pph_1, peer_up_msg_1_buf, _) =
mk_peer_up_notification_msg_without_rfc4724_support(
"127.0.0.1",
12345,
);
let (pph_2, peer_up_msg_2_buf, real_pph_2) =
mk_peer_up_notification_msg_without_rfc4724_support(
"127.0.0.2",
12345,
);
let route_mon_msg_buf = mk_route_monitoring_msg(&pph_2);
let ipv6_route_mon_msg_buf = mk_ipv6_route_monitoring_msg(&pph_2);
let route_withdraw_msg_buf = mk_route_monitoring_withdrawal_msg(&pph_2);
let peer_down_msg_1_buf = mk_peer_down_notification_msg(&pph_1);
let peer_down_msg_2_buf = mk_peer_down_notification_msg(&pph_2);
let processor = processor
.process_msg(Instant::now(), initiation_msg_buf, None)
.next_state;
assert!(
matches!(&processor, BmpState::Dumping(BmpStateDetails::<Dumping> { details, .. }) if details.peer_states.is_empty())
);
// When the state machine processes the initiate and peer up notifications
let processor = processor
.process_msg(Instant::now(), peer_up_msg_1_buf, None)
.next_state;
let res = processor.process_msg(Instant::now(), peer_up_msg_2_buf, None);
// Then the state should remain unchanged
assert!(matches!(res.next_state, BmpState::Dumping(_)));
assert!(matches!(res.message_type, MessageType::Other));
let processor = res.next_state;
// And there should now be two known peers
assert_eq!(get_unique_peer_up_count(&processor), 2);
// Check the metrics
assert_metrics(&processor, ("Dumping", [1, 0, 0, 0, 0, 0, 2, 0, 0, 0]));
// ^ 1 connected router
// ^ 2 up peers
// When the state machine processes a peer down notification for a peer that announced no routes
let res =
processor.process_msg(Instant::now(), peer_down_msg_1_buf, None);
// Then the state should remain unchanged
assert!(matches!(res.next_state, BmpState::Dumping(_)));
// Because the BMP unit does not keep track of what was announced by every
// peer, it always sends out a withdraw-all (in forms of a RoutingUpdate)
// to the East.
assert!(matches!(
res.message_type,
MessageType::RoutingUpdate { .. }
));
let processor = res.next_state;
// Check the metrics
assert_metrics(&processor, ("Dumping", [1, 0, 0, 0, 0, 0, 1, 0, 0, 0]));
// ^ now only 1 peer up
// When the state machine processes a couple of route announcements
let processor = processor
.process_msg(Instant::now(), route_mon_msg_buf.clone(), None)
.next_state;
let res = processor.process_msg(Instant::now(), route_mon_msg_buf, None);
// Then the state should remain unchanged
// And the number of announced prefixes should increase by 2
assert!(matches!(res.next_state, BmpState::Dumping(_)));
// BMP itself does not store the prefixes anymore, so ignore
// get_announced_prefix_count:
//assert_eq!(get_announced_prefix_count(&res.next_state, &real_pph_2), 2);
let processor = res.next_state;
// Check the metrics
assert_metrics(
&processor,
("Dumping", [1, 2, 0, 0, 0, 2, /*2,*/ 1, 0, 0, 0]),
);
// ^ 2 routes announced
// /*^ for 2 prefixes*/
// both of which were stored ^
// And when one of the routes is withdrawn
let res = processor.process_msg(
Instant::now(),
route_withdraw_msg_buf.clone(),
None,
);
// Then the state should remain unchanged
// And the number of announced prefixes should decrease by 1, but this is
// not tracked anymore by the BMP unit.
assert!(matches!(res.next_state, BmpState::Dumping(_)));
//assert_eq!(get_announced_prefix_count(&res.next_state, &real_pph_2), 1);
let processor = res.next_state;
// Check the metrics
assert_metrics(
&processor,
("Dumping", [1, 2, 0, 0, 0, 2, /*1,*/ 1, 0, 0, 1]),
);
// one withdrawal ^
// and now only 1 prefix is stored ^
// Unless it is a not-before-announced/already-withdrawn route
let res =
processor.process_msg(Instant::now(), route_withdraw_msg_buf, None);
// Then the number of announced prefixes should remain unchanged
assert!(matches!(res.next_state, BmpState::Dumping(_)));
//assert_eq!(get_announced_prefix_count(&res.next_state, &real_pph_2), 1);
let processor = res.next_state;
// Check the metrics
assert_metrics(
&processor,
("Dumping", [1, 2, 0, 0, 0, 2, /*1,*/ 1, 0, 0, 2]),
);
// another withdrawal ^
// And when a peer down notification for the other peer is received
let res =
processor.process_msg(Instant::now(), peer_down_msg_2_buf, None);
// Then the state should remain unchanged
assert!(matches!(res.next_state, BmpState::Dumping(_)));
// And a routing update to withdraw the remaining announced routes for the downed peer should be issued
assert!(matches!(
res.message_type,
MessageType::RoutingUpdate { .. }
));
if let MessageType::RoutingUpdate { update } = res.message_type {
assert!(matches!(update, Update::Withdraw(1, None)));
} else {
unreachable!();
}
// And there should no longer be any known peers
let processor = res.next_state;
if let BmpState::Dumping(processor) = &processor {
assert!(processor.details.peer_states.is_empty());
} else {
unreachable!();
}
// Check the metrics
assert_metrics(&processor, ("Dumping", [1, 2, 0, 0, 0, 2, 0, 0, 0, 2]));
// ^ all peers are down
}
#[test]
fn peer_down_without_peer_up() {
// Given
let processor = mk_test_processor();
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let (pph, _) =
mk_eor_capable_peer_up_notification_msg("127.0.0.1", 12345);
let peer_down_msg_buf = mk_peer_down_notification_msg(&pph);
let processor = processor
.process_msg(Instant::now(), initiation_msg_buf, None)
.next_state;
assert!(
matches!(&processor, BmpState::Dumping(BmpStateDetails::<Dumping> { details, .. }) if details.peer_states.is_empty())
);
// When
let res = processor.process_msg(Instant::now(), peer_down_msg_buf, None);
// Then
assert!(matches!(res.next_state, BmpState::Dumping(_)));
assert_invalid_msg_starts_with(
&res,
"PeerDownNotification received for peer that was not 'up'",
);
// Check the metrics
let processor = res.next_state;
assert_metrics(&processor, ("Dumping", [1, 0, 0, 0, 1, 0, 0, 0, 0, 0]));
// ^ 1 connected router
// ^ 1 unprocessable BMP message
}
#[test]
fn peer_up_different_peer_down() {
// Given a BMP state machine in the Dumping state with no known peers
let processor = mk_test_processor();
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let (pph_up, peer_up_msg_buf, _) =
mk_peer_up_notification_msg_without_rfc4724_support(
"127.0.0.1",
12345,
);
let (pph_down, _, _) =
mk_peer_up_notification_msg_without_rfc4724_support(
"127.0.0.2",
54321,
);
let peer_down_msg_buf = mk_peer_down_notification_msg(&pph_down);
assert_ne!(&pph_up, &pph_down);
let processor = processor
.process_msg(Instant::now(), initiation_msg_buf, None)
.next_state;
assert!(
matches!(&processor, BmpState::Dumping(BmpStateDetails::<Dumping> { details, .. }) if details.peer_states.is_empty())
);
// When the state machine processes a peer up notification
let res = processor.process_msg(Instant::now(), peer_up_msg_buf, None);
// Then the state should remain unchanged
assert!(matches!(res.next_state, BmpState::Dumping(_)));
assert!(matches!(res.message_type, MessageType::Other));
// And there should now be one known peer
let processor = res.next_state;
assert_eq!(get_unique_peer_up_count(&processor), 1);
// When the state machine processes a peer down notification for a different peer
let res = processor.process_msg(Instant::now(), peer_down_msg_buf, None);
// Then the state should remain unchanged
assert!(matches!(res.next_state, BmpState::Dumping(_)));
// And there should still be one known peer
assert_eq!(get_unique_peer_up_count(&res.next_state), 1);
// And the message should be considered invalid
assert_invalid_msg_starts_with(
&res,
"PeerDownNotification received for peer that was not 'up'",
);
// Check the metrics
let processor = res.next_state;
assert_metrics(&processor, ("Dumping", [1, 0, 0, 0, 1, 0, 1, 0, 0, 0]));
// ^ 1 connected router
// ^ 1 up peer
// ^ 1 unprocessable BMP message
}
#[ignore = "withdrawals are not signalled via UDPATE PDUs anymore"]
#[test]
fn peer_down_spreads_withdrawals_across_multiple_bgp_updates_if_needed() {
/*
// Given a BMP state machine in the Dumping state with no known peers
let processor = mk_test_processor();
// And some simulated BMP messages
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let (pph, peer_up_msg_buf, real_pph) =
mk_peer_up_notification_msg_without_rfc4724_support(
"127.0.0.1",
12345,
);
// Including a large number of prefix announcements
const NUM_PREFIXES: usize = 256 * 10;
let mut route_mon_msg_bufs = Vec::with_capacity(NUM_PREFIXES);
'outer: for b in 0..256 {
for c in 0..256 {
for d in 0..256 {
if route_mon_msg_bufs.len() == NUM_PREFIXES {
break 'outer;
} else {
let announcements = Announcements::from_str(&format!(
"e [123,456,789] 10.0.0.1 BLACKHOLE,123:44 127.{b}.{c}.{d}/32"
))
.unwrap();
route_mon_msg_bufs.push(
mk_route_monitoring_msg_with_details(
&pph,
&Prefixes::default(),
&announcements,
&[],
),
);
}
}
}
}
let peer_down_msg_buf = mk_peer_down_notification_msg(&pph);
// When the state machine processes the initiate and peer up notifications
let processor = processor
.process_msg(Utc::now(), initiation_msg_buf, None)
.next_state;
let res = processor.process_msg(Utc::now(), peer_up_msg_buf, None);
// Then the state should remain unchanged
assert!(matches!(res.next_state, BmpState::Dumping(_)));
assert!(matches!(res.message_type, MessageType::Other));
let mut processor = res.next_state;
// And there should now be one known peer
assert_eq!(get_unique_peer_up_count(&processor), 1);
// When the state machine processes the route announcements
for (i, route_mon_msg_buf) in route_mon_msg_bufs.into_iter().enumerate() {
let res = processor.process_msg(Utc::now(), route_mon_msg_buf, None);
// Then the state should remain unchanged
// And the number of announced prefixes should increase
assert!(matches!(res.next_state, BmpState::Dumping(_)));
assert_eq!(
get_announced_prefix_count(&res.next_state, &real_pph),
i + 1
);
processor = res.next_state;
}
// Check the metrics
assert_metrics(
&processor,
(
"Dumping",
[
1, // 1 connected router
NUM_PREFIXES, // Many announcements seen
0,
0,
0,
NUM_PREFIXES, // Many prefixes received
NUM_PREFIXES, // Many prefixes stored
1, // 1 peer up
0,
0,
0,
],
),
);
// And when a peer down notification is received
let res = processor.process_msg(Utc::now(), peer_down_msg_buf, None);
// Then the state should remain unchanged
assert!(matches!(res.next_state, BmpState::Dumping(_)));
// And a routing update to withdraw the remaining announced routes for the downed peer should be issued
assert!(matches!(
res.message_type,
MessageType::RoutingUpdate { .. }
));
if let MessageType::RoutingUpdate { update } = res.message_type {
assert!(matches!(update, Update::Bulk(_)));
if let Update::Bulk(mut bulk) = update {
// Verify that the update had too many payload items to fit inline into the SmallVec and so it had to
// spill over on to the heap.
assert!(bulk.spilled());
let mut expected_roto_prefixes =
Vec::<TypeValue>::with_capacity(NUM_PREFIXES);
'outer: for b in 0..256 {
for c in 0..256 {
for d in 0..256 {
if expected_roto_prefixes.len() == NUM_PREFIXES {
break 'outer;
} else {
expected_roto_prefixes.push(
Prefix::from_str(&format!(
"127.{b}.{c}.{d}/32"
))
.unwrap()
.into(),
);
}
}
}
}
#[allow(clippy::mutable_key_type)]
let mut distinct_bgp_updates_seen =
std::collections::HashSet::new();
let mut distinct_prefixes_seen = std::collections::HashSet::new();
let mut num_withdrawals_seen = 0;
for Payload {
rx_value: value,
..
} in bulk.drain(..)
{
if let TypeValue::Builtin(BuiltinTypeValue::Route(route)) =
value
{
// If we haven't seen this BGP UPDATE before we assume it
// contains only withdrawals that we haven't seen before,
// so count them and check the total at the end is what
// we expect. Don't do a contains() check against route.
// raw_message as its PartialEq impl compares a RotondaId
// which at the time of writing is not set to be unique
// per generated BGP UPDATE withdrawal message, instead
// compare the actual underlying BGP UPDATE.
let bgp_update_bytes =
route.raw_message.clone();
if !distinct_bgp_updates_seen.contains(&bgp_update_bytes)
{
num_withdrawals_seen += route
.raw_message
.0
.withdrawals()
.unwrap()
.count();
// This route may reference the same underlying BGP UPDATE
// withdrawal message as other routes in the bulk update.
// We want to keep track of how many distinct BGP UPDATE
// messages the bulk update set refers to.
distinct_bgp_updates_seen.insert(bgp_update_bytes);
}
let materialized_route = MaterializedRoute2::from(route);
let route = materialized_route.route.unwrap();
let found_pfx = route.prefix.as_ref().unwrap();
let position = expected_roto_prefixes
.iter()
.position(|pfx| pfx == found_pfx)
.unwrap();
expected_roto_prefixes.remove(position);
assert_eq!(
materialized_route.status,
RouteStatus::Withdrawn
);
// This route withdraws a single prefix that should not
// have been seen in one of the bulk update routes that
// we already processed.
assert!(distinct_prefixes_seen.insert(found_pfx.clone()));
} else {
panic!("Expected TypeValue::Builtin(BuiltinTypeValue::Route(_)");
}
}
// All prefixes should have been seen
assert!(expected_roto_prefixes.is_empty());
// More than one BGP UPDATE is expected as NUM_PREFIXES don't fit in 4096 bytes
assert!(distinct_bgp_updates_seen.len() > 1);
// The sum of prefixes withdrawn across the set of distinct BGP UPDATE messages
// should be the same as the number of prefixes that were expected to be withdrawn.
assert_eq!(NUM_PREFIXES, distinct_prefixes_seen.len());
assert_eq!(NUM_PREFIXES, num_withdrawals_seen);
}
} else {
unreachable!();
}
// And there should no longer be any known peers
let processor = res.next_state;
if let BmpState::Dumping(processor) = &processor {
assert!(processor.details.peer_states.is_empty());
} else {
unreachable!();
}
// Check the metrics
assert_metrics(
&processor,
(
"Dumping",
[
1, // 1 connected router
NUM_PREFIXES, // Many announcements seen
0,
0,
0,
NUM_PREFIXES, // Many prefixes received
0, // But no longer stored
0, // And no longer any peers up
0,
0,
0, // And ZERO withdrawals seen because
// we did not receive a BGP UPDATE
// containing withdrawals but instead
// withdrew the routes internally in
// response to a peer down event.
],
),
);
*/
}
#[test]
fn end_of_rib_ipv4_for_a_single_peer() {
// Given
let processor = mk_test_processor();
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let (pph, peer_up_msg_buf) =
mk_eor_capable_peer_up_notification_msg("127.0.0.1", 12345);
let route_mon_msg_buf = mk_route_monitoring_msg(&pph);
let eor_msg_buf = mk_route_monitoring_end_of_rib_msg(&pph);
let processor = processor
.process_msg(Instant::now(), initiation_msg_buf, None)
.next_state;
// When
let res = processor.process_msg(Instant::now(), peer_up_msg_buf, None);
// Then there should be one up peer but no pending EoRs
assert!(matches!(res.next_state, BmpState::Dumping(_)));
if let BmpState::Updating(next_state) = &res.next_state {
let Updating { peer_states, .. } = &next_state.details;
assert_eq!(peer_states.num_peer_configs(), 1);
assert_eq!(peer_states.num_pending_eors(), 0);
}
// Check the metrics
let processor = res.next_state;
assert_metrics(&processor, ("Dumping", [1, 0, 0, 0, 0, 0, 1, 0, 1, 0]));
// ^ 1 connected router
// ^ 1 up peer
// and the peer is EoR capable ^
// And when a route announcement is received
let res = processor.process_msg(Instant::now(), route_mon_msg_buf, None);
// Then there should be one up peer and one pending EoR
assert!(matches!(res.next_state, BmpState::Dumping(_)));
if let BmpState::Dumping(next_state) = &res.next_state {
let Dumping { peer_states, .. } = &next_state.details;
assert_eq!(peer_states.num_peer_configs(), 1);
assert_eq!(peer_states.num_pending_eors(), 1);
} else {
panic!("Expected to be in the DUMPING state");
}
// Check the metrics
let processor = res.next_state;
assert_metrics(
&processor,
("Dumping", [1, 1, 0, 0, 0, 1, /*1,*/ 1, 1, 1, 0]),
);
// ^ 1 announcement was received
// 1 prefix was received ^
// /*and 1 prefix was stored ^*/
// and one peer has pending EoRs ^
// And when an EoR is received
let res = processor.process_msg(Instant::now(), eor_msg_buf, None);
// Then
assert!(matches!(res.message_type, MessageType::StateTransition));
assert!(matches!(res.next_state, BmpState::Updating(_)));
if let BmpState::Updating(next_state) = &res.next_state {
let Updating { peer_states, .. } = &next_state.details;
assert_eq!(peer_states.num_peer_configs(), 1);
assert_eq!(peer_states.num_pending_eors(), 0);
} else {
panic!("Expected to be in the UPDATING state");
}
// Check the metrics
let processor = res.next_state;
assert_metrics(
&processor,
("Updating", [1, 1, 0, 0, 0, 1, /*1,*/ 1, 0, 1, 0]),
);
// ^ The phase changed
// And no peers have pending EoRs ^
}
#[test]
fn route_monitoring_from_unknown_peer() {
// Given
let processor = mk_test_processor();
let pph = mk_per_peer_header("127.0.0.1", 12345);
let route_mon_msg_buf = mk_route_monitoring_msg(&pph);
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let processor = processor
.process_msg(Instant::now(), initiation_msg_buf, None)
.next_state;
// When a route announcement is received
let res = processor.process_msg(Instant::now(), route_mon_msg_buf, None);
// Check the result of processing the message
assert!(matches!(res.next_state, BmpState::Dumping(_)));
assert_invalid_msg_starts_with(
&res,
"RouteMonitoring message received for peer that is not 'up'",
);
// Check the metrics
let processor = res.next_state;
assert_metrics(&processor, ("Dumping", [1, 0, 0, 1, 1, 0, 0, 0, 0, 0]));
// ^ 0 announcements because the msg was rejected!
// ^ 1 BGP UPDATE was from an unknown peer
// ^ 1 unprocessable BMP message
}
#[test]
#[ignore = "to do"]
fn end_of_rib_ipv6_for_a_single_peer() {}
#[test]
#[ignore = "to do"]
fn end_of_rib_for_all_pending_peers() {}
#[test]
#[ignore = "TODO: Routecore should error out on update messages bgp_update() message"]
fn route_monitoring_invalid_message() {
// Given
let processor = mk_test_processor();
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let (pph, peer_up_msg_buf, _) =
mk_peer_up_notification_msg_without_rfc4724_support(
"127.0.0.1",
65530,
);
let announcements = Announcements::from_str(
"e [123,456,789] 10.0.0.1 BLACKHOLE,123:44 127.0.0.1/32",
)
.unwrap();
// The following hex bytes represent the MP_REACH_NLRI attribute, with an invalid AFI.
//
// 0xFFFF is a reserved AFI number according to the IANA registry and so causes an unknown (S)AFI error from
// the routecore BGP parsing code.
//
// See:
// - https://datatracker.ietf.org/doc/html/rfc2858#section-2
// - https://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2
let invalid_mp_reach_nlri_attr = hex::decode(
"900e0024FFFF4604C0A800010001190001C0A8000100070003030303030303030100\
000000000000",
)
.unwrap();
let route_mon_msg_buf = mk_route_monitoring_msg_with_details(
&pph,
&Prefixes::default(),
&announcements,
&invalid_mp_reach_nlri_attr,
);
let processor = processor
.process_msg(Instant::now(), initiation_msg_buf, None)
.next_state;
// When
let processor = processor
.process_msg(Instant::now(), peer_up_msg_buf, None)
.next_state;
let res = processor.process_msg(Instant::now(), route_mon_msg_buf, None);
println!("res {:#?}", res);
// Then
assert!(matches!(res.next_state, BmpState::Dumping(_)));
assert_invalid_msg_starts_with(
&res,
"Invalid BMP RouteMonitoring BGP \
UPDATE message. One or more elements in the NLRI(s) cannot be parsed",
);
// Check the metrics
let processor = res.next_state;
assert_metrics(&processor, ("Dumping", [1, 0, 0, 0, 1, 0, 1, 0, 0, 0]));
// ^ 1 connected router
// ^ 0 announcements because the msg was rejected!
// ^ 1 unprocessable BMP message
// ^ 1 up peer
}
#[test]
#[ignore = "to do"]
fn route_monitoring_announce_route() {
// Given
let processor = mk_test_processor();
let initiation_msg_buf =
mk_initiation_msg(TEST_ROUTER_SYS_NAME, TEST_ROUTER_SYS_DESC);
let (pph, peer_up_msg_buf, _) =
mk_peer_up_notification_msg_without_rfc4724_support(
"127.0.0.1",
12345,
);
let route_mon_msg_buf = mk_route_monitoring_msg(&pph);
let processor = processor
.process_msg(Instant::now(), initiation_msg_buf, None)
.next_state;
// When
let processor = processor
.process_msg(Instant::now(), peer_up_msg_buf, None)
.next_state;
let res = processor.process_msg(Instant::now(), route_mon_msg_buf, None);
// Then
assert!(matches!(res.next_state, BmpState::Dumping(_)));
assert!(matches!(
res.message_type,
MessageType::RoutingUpdate { .. }
));
if let MessageType::RoutingUpdate { update } = res.message_type {
assert!(matches!(update, Update::Bulk(_)));
if let Update::Bulk(updates) = &update {
assert_eq!(updates.len(), 1);
//if let Payload {
// rx_value:
// TypeValue::Builtin(BuiltinTypeValue::PrefixRoute(route)),
// context: RouteContext::Fresh(ctx),
// ..
//} = &updates[0]
if let Payload {
//rx_value: RotondaRoute(route),
context: RouteContext::Fresh(ctx),
..
} = &updates[0]
{
assert_eq!(
//route.peer_ip().unwrap(),
ctx.provenance().peer_ip,
IpAddr::from_str("127.0.0.1").unwrap()
);
//assert_eq!(route.peer_asn().unwrap(), Asn::from_u32(12345));
assert_eq!(ctx.provenance().peer_asn, Asn::from_u32(12345));
//assert_eq!(
// route.router_id().unwrap().as_str(),
// TEST_ROUTER_SYS_NAME
//);
} else {
panic!("Expected a route");
}
} else {
panic!("Expected a bulk update");
}
}
}
#[test]
#[ignore = "to do"]
fn route_monitoring_withdraw_route() {}
#[test]
#[ignore = "to do"]
fn ignore_asns() {}
#[test]
#[ignore = "to do"]
fn full_lifecycle_happy_flow() {
// Single peer that supports End-of-RIB for which we receive peer up,
// then the initial dump including End-of-RIB, then a route monitoring
// announce, a withdraw, followed by peer down and then terminate.
}
#[test]
#[ignore = "to do"]
fn full_lifecycle_multiple_peers_no_interleaved_peer_up_and_route_monitoring()
{
}
#[test]
#[ignore = "to do"]
fn full_lifecycle_multiple_peers_interleaved_peer_up_and_route_monitoring() {
// From: https://www.rfc-editor.org/rfc/rfc7854.html#section-9
//
// "9. Using BMP
//
// Once the BMP session is established, route monitoring starts
// dumping the current snapshot as well as incremental changes
// simultaneously.
//
// It is fine to have these operations occur concurrently. If the
// initial dump visits a route and subsequently a withdraw is
// received, this will be forwarded to the monitoring station that
// would have to correlate and reflect the deletion of that route
// in its internal state. This is an operation that a monitoring
// station would need to support, regardless.
//
// If the router receives a withdraw for a prefix even before the
// peer dump procedure visits that prefix, then the router would
// clean up that route from its internal state and will not forward
// it to the monitoring station. In this case, the monitoring
// station may receive a bogus withdraw it can safely ignore."
}
#[test]
#[ignore = "to do"]
fn full_lifecycle_incremental_update_before_end_of_rib() {}
#[test]
#[ignore = "to do"]
fn route_attribute_changes() {
// From: https://www.rfc-editor.org/rfc/rfc7854.html#section-5
//
// "5. Route Monitoring
//
// ...
//
// When a change occurs to a route, such as an attribute change,
// the router must update the monitoring station with the new
// attribute. As discussed above, it MAY generate either an update
// with the L flag clear, with it set, or two updates, one with the
// L flag clear and the other with the L flag set. When a route is
// withdrawn by a peer, a corresponding withdraw is sent to the
// monitoring station. The withdraw MUST have its L flag set to
// correspond to that of any previous announcement; if the route in
// question was previously announced with L flag both clear and
// set, the withdraw MUST similarly be sent twice, with L flag
// clear and set. Multiple changed routes MAY be grouped into a
// single BGP UPDATE PDU when feasible, exactly as in the standard
// BGP protocol."
}
// --- Test helpers -----------------------------------------------------------------------------------------------
// RFC 4724 Graceful Restart Mechanism for BGP
// BMP uses the End-of-RIB feature of RFC 4724.
fn mk_peer_up_notification_msg_without_rfc4724_support(
peer_ip: &str,
peer_as: u32,
) -> (
crate::bgp::encode::PerPeerHeader,
BmpMsg<Bytes>,
PerPeerHeader<Bytes>,
) {
let pph = mk_per_peer_header(peer_ip, peer_as);
let (bmp_msg, real_pph) = mk_peer_up_notification_msg(&pph, false);
(pph, bmp_msg, real_pph)
}
fn mk_eor_capable_peer_up_notification_msg(
peer_ip: &str,
peer_as: u32,
) -> (crate::bgp::encode::PerPeerHeader, BmpMsg<Bytes>) {
let pph = mk_per_peer_header(peer_ip, peer_as);
let (bmp_msg, _) = mk_peer_up_notification_msg(&pph, true);
(pph, bmp_msg)
}
fn mk_peer_up_notification_msg(
pph: &crate::bgp::encode::PerPeerHeader,
eor_capable: bool,
) -> (BmpMsg<Bytes>, PerPeerHeader<Bytes>) {
let bytes = crate::bgp::encode::mk_peer_up_notification_msg(
pph,
"10.0.0.1".parse().unwrap(),
11019,
4567,
111,
222,
0,
0,
vec![],
eor_capable,
);
let bmp_msg = BmpMsg::from_octets(bytes).unwrap();
let real_pph = match &bmp_msg {
BmpMsg::PeerUpNotification(msg) => msg.per_peer_header(),
_ => unreachable!(),
};
(bmp_msg, real_pph)
}
fn mk_peer_down_notification_msg(
pph: &crate::bgp::encode::PerPeerHeader,
) -> BmpMsg<Bytes> {
BmpMsg::from_octets(crate::bgp::encode::mk_peer_down_notification_msg(
pph,
))
.unwrap()
}
fn mk_route_monitoring_msg(
pph: &crate::bgp::encode::PerPeerHeader,
) -> BmpMsg<Bytes> {
let announcements = Announcements::from_str(
"e [123,456,789] 10.0.0.1 BLACKHOLE,123:44 127.0.0.1/32",
)
.unwrap();
BmpMsg::from_octets(crate::bgp::encode::mk_route_monitoring_msg(
pph,
&Prefixes::default(),
&announcements,
&[],
))
.unwrap()
}
fn mk_ipv6_route_monitoring_msg(
pph: &crate::bgp::encode::PerPeerHeader,
) -> BmpMsg<Bytes> {
let announcements = Announcements::from_str(
"e [123,456,789] 2001:2000:3080:e9c::1 BLACKHOLE,123:44 2001:2000:3080:e9c::2/128",
)
.unwrap();
BmpMsg::from_octets(crate::bgp::encode::mk_route_monitoring_msg(
pph,
&Prefixes::default(),
&announcements,
&[],
))
.unwrap()
}
fn mk_route_monitoring_end_of_rib_msg(
pph: &crate::bgp::encode::PerPeerHeader,
) -> BmpMsg<Bytes> {
BmpMsg::from_octets(crate::bgp::encode::mk_route_monitoring_msg(
pph,
&Prefixes::default(),
&Announcements::default(),
&[],
))
.unwrap()
}
fn mk_route_monitoring_withdrawal_msg(
pph: &crate::bgp::encode::PerPeerHeader,
) -> BmpMsg<Bytes> {
let prefixes = Prefixes::from_str("127.0.0.1/32").unwrap();
BmpMsg::from_octets(crate::bgp::encode::mk_route_monitoring_msg(
pph,
&prefixes,
&Announcements::None,
&[],
))
.unwrap()
}
fn _mk_ipv6_route_monitoring_withdrawal_msg(
pph: &crate::bgp::encode::PerPeerHeader,
) -> Bytes {
let prefixes = Prefixes::from_str("2001:2000:3080:e9c::2/128").unwrap();
crate::bgp::encode::mk_route_monitoring_msg(
pph,
&prefixes,
&Announcements::None,
&[],
)
}
fn mk_statistics_report_msg(
pph: &crate::bgp::encode::PerPeerHeader,
) -> BmpMsg<Bytes> {
BmpMsg::from_octets(crate::bgp::encode::mk_statistics_report_msg(pph))
.unwrap()
}
fn mk_test_processor() -> BmpState {
//let addr = "127.0.0.1:1818".parse().unwrap();
let gate = crate::comms::Gate::default();
let bmp_tcp_in_metrics = Arc::new(BmpTcpInMetrics::new(&gate));
let bmp_state_machine_metrics = Arc::new(BmpStateMachineMetrics::new());
let status_reporter =
Arc::new(BmpTcpInStatusReporter::new("mock", bmp_tcp_in_metrics));
let ingress_id = 1;
BmpState::new(
//SourceId::SocketAddr(addr),
ingress_id,
//Arc::new("test-router".to_string()),
Arc::new(ingress_id.to_string()),
status_reporter,
bmp_state_machine_metrics,
Arc::default(),
)
}
fn get_unique_peer_up_count(processor: &BmpState) -> usize {
get_peer_states(processor).num_peer_configs()
}
fn get_announced_prefix_count(
processor: &BmpState,
pph: &PerPeerHeader<Bytes>,
) -> usize {
get_peer_states(processor)
.get_announced_prefixes(pph)
.unwrap()
.len()
}
fn get_peer_states(processor: &BmpState) -> &PeerStates {
match processor {
BmpState::Dumping(v) => &v.details.peer_states,
BmpState::Updating(v) => &v.details.peer_states,
_ => unreachable!(),
}
}
fn mk_initiation_msg(sys_name: &str, sys_descr: &str) -> BmpMsg<Bytes> {
BmpMsg::from_octets(crate::bgp::encode::mk_initiation_msg(
sys_name, sys_descr,
))
.unwrap()
}
fn mk_termination_msg() -> BmpMsg<Bytes> {
BmpMsg::from_octets(crate::bgp::encode::mk_termination_msg()).unwrap()
}
#[allow(clippy::vec_init_then_push)]
fn mk_route_monitoring_msg_with_details(
pph: &crate::bgp::encode::PerPeerHeader,
withdrawals: &Prefixes,
announcements: &Announcements,
extra_path_attributes: &[u8],
) -> BmpMsg<Bytes> {
BmpMsg::from_octets(crate::bgp::encode::mk_route_monitoring_msg(
pph,
withdrawals,
announcements,
extra_path_attributes,
))
.unwrap()
}
#[rustfmt::skip]
fn query_metrics(
metrics: &Arc<dyn crate::metrics::Source>,
) -> (String, [usize; 10]) {
let metrics = get_testable_metrics_snapshot(metrics);
let label = ("router", "1");
(
metrics.with_label::<String>("bmp_state_machine_state", label),
[
metrics.with_name::<usize>("bmp_num_connected_routers"),
metrics.with_label::<usize>("bmp_state_num_announcements", label),
metrics.with_label::<usize>("bmp_state_num_bgp_updates_reparsed_due_to_incorrect_header_flags", label),
metrics.with_label::<usize>("bmp_state_num_bmp_route_monitoring_msgs_with_unknown_peer", label),
metrics.with_label::<usize>("bmp_state_num_unprocessable_bmp_messages", label),
metrics.with_label::<usize>("bmp_state_num_received_prefixes", label),
//metrics.with_label::<usize>("bmp_state_num_stored_prefixes", label),
metrics.with_label::<usize>("bmp_state_num_up_peers", label),
metrics.with_label::<usize>("bmp_state_num_up_peers_with_pending_eors", label),
metrics.with_label::<usize>("bmp_state_num_up_peers_eor_capable", label),
metrics.with_label::<usize>("bmp_state_num_withdrawals", label)
]
)
}
fn assert_metrics(processor: &BmpState, expected: (&str, [usize; 10])) {
let metrics = processor.status_reporter().unwrap().metrics().unwrap();
let actual = query_metrics(&metrics);
let mut expected = (expected.0.to_string(), expected.1);
// Until https://github.com/NLnetLabs/rotonda/pull/55 is merged we have
// to expect that metric:
// bmp_state_num_bgp_updates_with_recoverable_parsing_failure_for_known_peer
// has the unexpected value 1 instead of 0. Once merged we can revert
// this temporary work around.
if expected.1[2] != actual.1[2] {
eprintln!("WARNING: Temporarily overriding expected value for metric `bmp_state_num_bgp_updates_with_recoverable_parsing_failure_for_known_peer` due to pending PR https://github.com/NLnetLabs/rotonda/pull/55.");
expected.1[2] = actual.1[2];
}
assert_eq!(actual, expected, "actual (left) != expected (right)");
}
fn assert_invalid_msg_starts_with(
res: &ProcessingResult,
expected_start: &str,
) {
if let MessageType::InvalidMessage { err, .. } = &res.message_type {
if !err.starts_with(expected_start) {
assert_eq!(expected_start, err);
}
} else {
panic!(
"Expected an InvalidMessage result, instead got: {:?}",
res.message_type
);
}
}