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
|
#################################### bgp.py ##################################
% Regression tests for the bgp module
+ Default configuration
= OLD speaker (see RFC 6793)
bgp_module_conf.use_2_bytes_asn = True
################################ BGPNLRI_IPv4 ################################
+ BGPNLRI_IPv4 class tests
= BGPNLRI_IPv4 - Instantiation
raw(BGPNLRI_IPv4()) == b'\x00'
= BGPNLRI_IPv4 - Instantiation with specific values (1)
raw(BGPNLRI_IPv4(prefix = '255.255.255.255/32')) == b' \xff\xff\xff\xff'
= BGPNLRI_IPv4 - Instantiation with specific values (2)
raw(BGPNLRI_IPv4(prefix = '0.0.0.0/0')) == b'\x00'
= BGPNLRI_IPv4 - Instantiation with specific values (3)
raw(BGPNLRI_IPv4(prefix = '192.0.2.0/24')) == b'\x18\xc0\x00\x02'
= BGPNLRI_IPv4 - Basic dissection
nlri = BGPNLRI_IPv4(b'\x00')
nlri.prefix == '0.0.0.0/0'
= BGPNLRI_IPv4 - Dissection with specific values
nlri = BGPNLRI_IPv4(b'\x18\xc0\x00\x02')
nlri.prefix == '192.0.2.0/24'
################################ BGPNLRI_IPv6 ################################
+ BGPNLRI_IPv6 class tests
= BGPNLRI_IPv6 - Instantiation
raw(BGPNLRI_IPv6()) == b'\x00'
= BGPNLRI_IPv6 - Instantiation with specific values (1)
raw(BGPNLRI_IPv6(prefix = '::/0')) == b'\x00'
= BGPNLRI_IPv6 - Instantiation with specific values (2)
raw(BGPNLRI_IPv6(prefix = '2001:db8::/32')) == b' \x01\r\xb8'
= BGPNLRI_IPv6 - Basic dissection
nlri = BGPNLRI_IPv6(b'\x00')
nlri.prefix == '::/0'
= BGPNLRI_IPv6 - Dissection with specific values
nlri = BGPNLRI_IPv6(b' \x01\r\xb8')
nlri.prefix == '2001:db8::/32'
#################################### BGP #####################################
+ BGP class tests
= BGP - Instantiation (Should be a KEEPALIVE)
m = BGP()
assert raw(m) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04'
assert m.type == BGP.KEEPALIVE_TYPE
= BGP - Instantiation with specific values (1)
raw(BGP(type = 0)) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x00'
= BGP - Instantiation with specific values (2)
raw(BGP(type = 1)) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x01'
= BGP - Instantiation with specific values (3)
raw(BGP(type = 2)) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x02'
= BGP - Instantiation with specific values (4)
raw(BGP(type = 3)) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x03'
= BGP - Instantiation with specific values (5)
raw(BGP(type = 4)) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04'
= BGP - Instantiation with specific values (6)
raw(BGP(type = 5)) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x05'
= BGP - Basic dissection
h = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04')
assert h.type == BGP.KEEPALIVE_TYPE
assert h.len == 19
= BGP - Dissection with specific values
h = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x01')
assert h.type == BGP.OPEN_TYPE
assert h.len == 19
############################### BGPKeepAlive #################################
+ BGPKeepAlive class tests
= BGPKeepAlive - Instantiation (by default, should be a "generic" capability)
raw(BGPKeepAlive())
raw(BGPKeepAlive()) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04'
= BGPKeepAlive - Swallowing tests: combined BGPKeepAlive
o = BGPKeepAlive()
m=IP(src="12.0.0.1",dst="12.0.0.2")/TCP(dport=54321)/BGP(raw(o)*2)
m.show()
assert isinstance(m[BGPKeepAlive].payload, BGPKeepAlive)
assert m[BGPKeepAlive].payload.marker == 0xffffffffffffffffffffffffffffffff
############################### BGPCapability #################################
+ BGPCapability class tests
= BGPCapability - Instantiation (by default, should be a "generic" capability)
raw(BGPCapability())
raw(BGPCapability()) == b'\x00\x00'
= BGPCapability - Instantiation with specific values (1)
c = BGPCapability(code = 70)
assert raw(c) == b'F\x00'
= BGPCapability - Check exception
from scapy.contrib.bgp import _BGPInvalidDataException
try:
BGPCapability("\x00")
False
except _BGPInvalidDataException:
True
= BGPCapability - Test haslayer()
assert BGPCapFourBytesASN().haslayer(BGPCapability)
assert BGPCapability in BGPCapFourBytesASN()
= BGPCapability - Test getlayer()
assert isinstance(BGPCapFourBytesASN().getlayer(BGPCapability), BGPCapFourBytesASN)
assert isinstance(BGPCapFourBytesASN()[BGPCapability], BGPCapFourBytesASN)
= BGPCapability - sessions (1)
p = IP()/TCP()/BGPCapability()
l = PacketList(p)
s = l.sessions() # Crashed on commit: e42ecdc54556c4852ca06b1a6da6c1ccbf3f522e
assert len(s) == 1
= BGPCapability - sessions (2)
p = IP()/UDP()/BGPCapability()
l = PacketList(p)
s = l.sessions() # Crashed on commit: e42ecdc54556c4852ca06b1a6da6c1ccbf3f522e
assert len(s) == 1
############################ BGPCapMultiprotocol ##############################
+ BGPCapMultiprotocol class tests
= BGPCapMultiprotocol - Inheritance
c = BGPCapMultiprotocol()
assert isinstance(c, BGPCapability)
= BGPCapMultiprotocol - Instantiation
raw(BGPCapMultiprotocol()) == b'\x01\x04\x00\x00\x00\x00'
= BGPCapMultiprotocol - Instantiation with specific values (1)
raw(BGPCapMultiprotocol(afi = 1, safi = 1)) == b'\x01\x04\x00\x01\x00\x01'
= BGPCapMultiprotocol - Instantiation with specific values (2)
raw(BGPCapMultiprotocol(afi = 2, safi = 1)) == b'\x01\x04\x00\x02\x00\x01'
= BGPCapMultiprotocol - Dissection with specific values
c = BGPCapMultiprotocol(b'\x01\x04\x00\x02\x00\x01')
assert c.code == 1
assert c.length == 4
assert c.afi == 2
assert c.reserved == 0
assert c.safi == 1
############################### BGPCapORFBlock ###############################
+ BGPCapORFBlock class tests
= BGPCapORFBlock - Instantiation
raw(BGPCapORFBlock()) == b'\x00\x00\x00\x00\x00'
= BGPCapORFBlock - Instantiation with specific values (1)
raw(BGPCapORFBlock(afi = 1, safi = 1)) == b'\x00\x01\x00\x01\x00'
= BGPCapORFBlock - Instantiation with specific values (2)
raw(BGPCapORFBlock(afi = 2, safi = 1)) == b'\x00\x02\x00\x01\x00'
= BGPCapORFBlock - Basic dissection
c = BGPCapORFBlock(b'\x00\x00\x00\x00\x00')
c.afi == 0 and c.reserved == 0 and c.safi == 0 and c.orf_number == 0
= BGPCapORFBlock - Dissection with specific values
c = BGPCapORFBlock(b'\x00\x02\x00\x01\x00')
c.afi == 2 and c.reserved == 0 and c.safi == 1 and c.orf_number == 0
############################# BGPCapORFBlock.ORF ##############################
+ BGPCapORFBlock.ORF class tests
= BGPCapORFBlock.ORF - Instantiation
raw(BGPCapORFBlock.ORFTuple()) == b'\x00\x00'
= BGPCapORFBlock.ORF - Instantiation with specific values (1)
raw(BGPCapORFBlock.ORFTuple(orf_type = 64, send_receive = 3)) == b'@\x03'
= BGPCapORFBlock.ORF - Basic dissection
c = BGPCapORFBlock.ORFTuple(b'\x00\x00')
c.orf_type == 0 and c.send_receive == 0
= BGPCapORFBlock.ORF - Dissection with specific values
c = BGPCapORFBlock.ORFTuple(b'@\x03')
c.orf_type == 64 and c.send_receive == 3
################################# BGPCapORF ###################################
+ BGPCapORF class tests
= BGPCapORF - Inheritance
c = BGPCapORF()
assert isinstance(c, BGPCapability)
= BGPCapORF - Instantiation
raw(BGPCapORF()) == b'\x03\x00'
= BGPCapORF - Instantiation with specific values (1)
raw(BGPCapORF(orf = [BGPCapORFBlock(afi = 1, safi = 1, entries = [BGPCapORFBlock.ORFTuple(orf_type = 64, send_receive = 3)])])) == b'\x03\x07\x00\x01\x00\x01\x01@\x03'
= BGPCapORF - Instantiation with specific values (2)
raw(BGPCapORF(orf = [BGPCapORFBlock(afi = 1, safi = 1, entries = [BGPCapORFBlock.ORFTuple(orf_type = 64, send_receive = 3)]), BGPCapORFBlock(afi = 2, safi = 1, entries = [BGPCapORFBlock.ORFTuple(orf_type = 64, send_receive = 3)])])) == b'\x03\x0e\x00\x01\x00\x01\x01@\x03\x00\x02\x00\x01\x01@\x03'
= BGPCapORF - Basic dissection
c = BGPCapORF(b'\x03\x00')
c.code == 3 and c.length == 0
= BGPCapORF - Dissection with specific values
c = BGPCapORF(orf = [BGPCapORFBlock(afi = 1, safi = 1, entries = [BGPCapORFBlock.ORFTuple(orf_type = 64, send_receive = 3)]), BGPCapORFBlock(afi = 2, safi = 1, entries = [BGPCapORFBlock.ORFTuple(orf_type = 64, send_receive = 3)])])
c.code == 3 and c.orf[0].afi == 1 and c.orf[0].safi == 1 and c.orf[0].entries[0].orf_type == 64 and c.orf[0].entries[0].send_receive == 3 and c.orf[1].afi == 2 and c.orf[1].safi == 1 and c.orf[1].entries[0].orf_type == 64 and c.orf[1].entries[0].send_receive == 3
= BGPCapORF - Dissection
p = BGPCapORF(b'\x03\x07\x00\x01\x00\x01\x01@\x03')
assert len(p.orf) == 1
####################### BGPCapGracefulRestart.GRTuple #########################
+ BGPCapGracefulRestart.GRTuple class tests
= BGPCapGracefulRestart.GRTuple - Instantiation
raw(BGPCapGracefulRestart.GRTuple()) == b'\x00\x00\x00\x00'
= BGPCapGracefulRestart.GRTuple - Instantiation with specific values
raw(BGPCapGracefulRestart.GRTuple(afi = 1, safi = 1, flags = 128)) == b'\x00\x01\x01\x80'
= BGPCapGracefulRestart.GRTuple - Basic dissection
c = BGPCapGracefulRestart.GRTuple(b'\x00\x00\x00\x00')
c.afi == 0 and c.safi == 0 and c.flags == 0
= BGPCapGracefulRestart.GRTuple - Dissection with specific values
c = BGPCapGracefulRestart.GRTuple(b'\x00\x01\x01\x80')
c.afi == 1 and c.safi == 1 and c.flags == 128
########################### BGPCapGracefulRestart #############################
+ BGPCapGracefulRestart class tests
= BGPCapGracefulRestart - Inheritance
c = BGPCapGracefulRestart()
assert isinstance(c, BGPCapGracefulRestart)
= BGPCapGracefulRestart - Instantiation
raw(BGPCapGracefulRestart()) == b'@\x02\x00\x00'
= BGPCapGracefulRestart - Instantiation with specific values (1)
raw(BGPCapGracefulRestart(restart_time = 120, entries = [BGPCapGracefulRestart.GRTuple(afi = 1, safi = 1)])) == b'@\x06\x00x\x00\x01\x01\x00'
= BGPCapGracefulRestart - Instantiation with specific values (2)
raw(BGPCapGracefulRestart(restart_time = 120, entries = [BGPCapGracefulRestart.GRTuple(afi = 1, safi = 1)])) == b'@\x06\x00x\x00\x01\x01\x00'
= BGPCapGracefulRestart - Instantiation with specific values (3)
raw(BGPCapGracefulRestart(restart_time = 120, entries = [BGPCapGracefulRestart.GRTuple(afi = 1, safi = 1, flags = 128)])) == b'@\x06\x00x\x00\x01\x01\x80'
= BGPCapGracefulRestart - Instantiation with specific values (4)
raw(BGPCapGracefulRestart(restart_time = 120, restart_flags = 0x8, entries = [BGPCapGracefulRestart.GRTuple(afi = 1, safi = 1, flags = 128)])) == b'@\x06\x80x\x00\x01\x01\x80'
= BGPCapGracefulRestart - Basic dissection
c = BGPCapGracefulRestart(b'@\x02\x00\x00')
c.code == 64 and c.restart_flags == 0 and c.restart_time == 0
= BGPCapGracefulRestart - Dissection with specific values
c = BGPCapGracefulRestart(b'@\x06\x80x\x00\x01\x01\x80')
c.code == 64 and c.restart_time == 120 and c.restart_flags == 0x8 and c.entries[0].afi == 1 and c.entries[0].safi == 1 and c.entries[0].flags == 128
############################ BGPCapFourBytesASN ###############################
+ BGPCapFourBytesASN class tests
= BGPCapFourBytesASN - Inheritance
c = BGPCapFourBytesASN()
assert isinstance(c, BGPCapFourBytesASN)
= BGPCapFourBytesASN - Instantiation
raw(BGPCapFourBytesASN()) == b'A\x04\x00\x00\x00\x00'
= BGPCapFourBytesASN - Instantiation with specific values (1)
raw(BGPCapFourBytesASN(asn = 6555555)) == b'A\x04\x00d\x07\xa3'
= BGPCapFourBytesASN - Instantiation with specific values (2)
raw(BGPCapFourBytesASN(asn = 4294967295)) == b'A\x04\xff\xff\xff\xff'
= BGPCapFourBytesASN - Basic dissection
c = BGPCapFourBytesASN(b'A\x04\x00\x00\x00\x00')
c.code == 65 and c.length == 4 and c.asn == 0
= BGPCapFourBytesASN - Dissection with specific values
c = BGPCapFourBytesASN(b'A\x04\xff\xff\xff\xff')
c.code == 65 and c.length == 4 and c.asn == 4294967295
####################### BGPAuthenticationInformation ##########################
+ BGPAuthenticationInformation class tests
= BGPAuthenticationInformation - Instantiation
raw(BGPAuthenticationInformation()) == b'\x00'
= BGPAuthenticationInformation - Basic dissection
c = BGPAuthenticationInformation(b'\x00')
c.authentication_code == 0 and not c.authentication_data
################################# BGPOptParam #################################
+ BGPOptParam class tests
= BGPOptParam - Instantiation
raw(BGPOptParam()) == b'\x02\x00'
= BGPOptParam - Instantiation with specific values (1)
raw(BGPOptParam(param_type = 1)) == b'\x01\x00'
raw(BGPOptParam(param_type = 1, param_value = BGPAuthenticationInformation())) == b'\x01\x00'
= BGPOptParam - Instantiation with specific values (2)
raw(BGPOptParam(param_type = 2)) == b'\x02\x00'
= BGPOptParam - Instantiation with specific values (3)
raw(BGPOptParam(param_type = 2, param_value = BGPCapFourBytesASN(asn = 4294967295))) == b'\x02\x06A\x04\xff\xff\xff\xff'
= BGPOptParam - Instantiation with specific values (4)
raw(BGPOptParam(param_type = 2, param_value = BGPCapability(code = 127))) == b'\x02\x02\x7f\x00'
= BGPOptParam - Instantiation with specific values (5)
raw(BGPOptParam(param_type = 2, param_value = BGPCapability(code = 255))) == b'\x02\x02\xff\x00'
= BGPOptParam - Basic dissection
p = BGPOptParam(b'\x02\x00')
p.param_type == 2 and p.param_length == 0
= BGPOptParam - Dissection with specific values
p = BGPOptParam(b'\x02\x06A\x04\xff\xff\xff\xff')
p.param_type == 2 and p.param_length == 6 and p.param_value[0].code == 65 and p.param_value[0].length == 4 and p.param_value[0].asn == 4294967295
################################### BGPOpen ###################################
+ BGPOpen class tests
= BGPOpen - Instantiation
raw(BGPOpen()) == b'\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00'
= BGPOpen - Instantiation with specific values (1)
raw(BGPOpen(my_as = 64501, bgp_id = "192.0.2.1")) == b'\x04\xfb\xf5\x00\x00\xc0\x00\x02\x01\x00'
= BGPOpen - Instantiation with specific values (2)
opt = BGPOptParam(param_value = BGPCapMultiprotocol(afi = 1, safi = 1))
raw(BGPOpen(my_as = 64501, bgp_id = "192.0.2.1", opt_params = [opt])) == b'\x04\xfb\xf5\x00\x00\xc0\x00\x02\x01\x08\x02\x06\x01\x04\x00\x01\x00\x01'
= BGPOpen - Instantiation with specific values (3)
cap = BGPOptParam(param_value = BGPCapMultiprotocol(afi = 1, safi = 1))
capabilities = [cap]
cap = BGPOptParam(param_value = BGPCapability(code = 128))
capabilities.append(cap)
cap = BGPOptParam(param_value = BGPCapability(code = 2))
capabilities.append(cap)
cap = BGPOptParam(param_value = BGPCapGracefulRestart(restart_time = 120, entries = [BGPCapGracefulRestart.GRTuple(afi = 1, safi= 1, flags = 128)]))
capabilities.append(cap)
cap = BGPOptParam(param_value = BGPCapFourBytesASN(asn = 64503))
capabilities.append(cap)
raw(BGPOpen(my_as = 64503, bgp_id = "192.168.100.3", hold_time = 30, opt_params = capabilities)) == b'\x04\xfb\xf7\x00\x1e\xc0\xa8d\x03"\x02\x06\x01\x04\x00\x01\x00\x01\x02\x02\x80\x00\x02\x02\x02\x00\x02\x08@\x06\x00x\x00\x01\x01\x80\x02\x06A\x04\x00\x00\xfb\xf7'
= BGPOpen - Dissection with specific values (1)
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00?\x01\x04\xfb\xf7\x00\x1e\xc0\xa8d\x03"\x02\x06\x01\x04\x00\x01\x00\x01\x02\x02\x80\x00\x02\x02\x02\x00\x02\x08@\x06\x00x\x00\x01\x01\x80\x02\x06A\x04\x00\x00\xfb\xf7')
assert BGPHeader in m and BGPOpen in m
assert m.len == 63
assert m.type == BGP.OPEN_TYPE
assert m.version == 4
assert m.my_as == 64503
assert m.hold_time == 30
assert m.bgp_id == "192.168.100.3"
assert m.opt_param_len == 34
assert isinstance(m.opt_params[0].param_value, BGPCapMultiprotocol)
assert isinstance(m.opt_params[1].param_value, BGPCapability)
assert isinstance(m.opt_params[2].param_value, BGPCapability)
assert isinstance(m.opt_params[3].param_value, BGPCapGracefulRestart)
= BGPOpen - Dissection with specific values (2) (followed by a KEEPALIVE)
messages = b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00=\x01\x04\xfb\xf6\x00\xb4\xc0\xa8ze \x02\x06\x01\x04\x00\x01\x00\x01\x02\x06\x01\x04\x00\x02\x00\x01\x02\x02\x80\x00\x02\x02\x02\x00\x02\x06A\x04\x00\x00\xfb\xf6\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04'
m = BGP(messages)
raw(m) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00=\x01\x04\xfb\xf6\x00\xb4\xc0\xa8ze \x02\x06\x01\x04\x00\x01\x00\x01\x02\x06\x01\x04\x00\x02\x00\x01\x02\x02\x80\x00\x02\x02\x02\x00\x02\x06A\x04\x00\x00\xfb\xf6\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04'
= BGPOpen - Dissection with specific values (3)
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x8f\x01\x04\xfd\xe8\x00\xb4\n\xff\xff\x01r\x02\x06\x01\x04\x00\x01\x00\x84\x02\x06\x01\x04\x00\x19\x00A\x02\x06\x01\x04\x00\x02\x00\x02\x02\x06\x01\x04\x00\x01\x00\x02\x02\x06\x01\x04\x00\x02\x00\x80\x02\x06\x01\x04\x00\x01\x00\x80\x02\x06\x01\x04\x00\x01\x00B\x02\x06\x01\x04\x00\x02\x00\x01\x02\x06\x01\x04\x00\x02\x00\x04\x02\x06\x01\x04\x00\x01\x00\x01\x02\x06\x01\x04\x00\x01\x00\x04\x02\x02\x80\x00\x02\x02\x02\x00\x02\x04@\x02\x80x\x02\x02F\x00\x02\x06A\x04\x00\x00\xfd\xe8')
assert BGPHeader in m and BGPOpen in m
= BGPOpen - Dissection with specific values (4)
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x8f\x01\x04\xfd\xe8\x00\xb4\n\xff\xff\x02r\x02\x06\x01\x04\x00\x01\x00\x84\x02\x06\x01\x04\x00\x19\x00A\x02\x06\x01\x04\x00\x02\x00\x02\x02\x06\x01\x04\x00\x01\x00\x02\x02\x06\x01\x04\x00\x02\x00\x80\x02\x06\x01\x04\x00\x01\x00\x80\x02\x06\x01\x04\x00\x01\x00B\x02\x06\x01\x04\x00\x02\x00\x01\x02\x06\x01\x04\x00\x02\x00\x04\x02\x06\x01\x04\x00\x01\x00\x01\x02\x06\x01\x04\x00\x01\x00\x04\x02\x02\x80\x00\x02\x02\x02\x00\x02\x04@\x02\x00x\x02\x02F\x00\x02\x06A\x04\x00\x00\xfd\xe8')
assert BGPHeader in m and BGPOpen in m
################################# BGPPAOrigin #################################
+ BGPPAOrigin class tests
= BGPPAOrigin - Instantiation
raw(BGPPAOrigin()) == b'\x00'
= BGPPAOrigin - Instantiation with specific values
raw(BGPPAOrigin(origin = 1)) == b'\x01'
= BGPPAOrigin - Dissection
a = BGPPAOrigin(b'\x00')
a.origin == 0
################################ BGPPAASPath ##################################
+ BGPPAASPath class tests
= BGPPAASPath - Instantiation
raw(BGPPAASPath()) == b''
= BGPPAASPath - Instantiation with specific values (1)
raw(BGPPAASPath(segments = [BGPPAASPath.ASPathSegment(segment_type = 2, segment_value = [64496, 64497, 64498])])) == b'\x02\x03\xfb\xf0\xfb\xf1\xfb\xf2'
= BGPPAASPath - Instantiation with specific values (2)
raw(BGPPAASPath(segments = [BGPPAASPath.ASPathSegment(segment_type = 1, segment_value = [64496, 64497, 64498])])) == b'\x01\x03\xfb\xf0\xfb\xf1\xfb\xf2'
= BGPPAASPath - Instantiation with specific values (3)
raw(BGPPAASPath(segments = [BGPPAASPath.ASPathSegment(segment_type = 1, segment_value = [64496, 64497, 64498]), BGPPAASPath.ASPathSegment(segment_type = 2, segment_value = [64500, 64501, 64502, 64502, 64503])])) == b'\x01\x03\xfb\xf0\xfb\xf1\xfb\xf2\x02\x05\xfb\xf4\xfb\xf5\xfb\xf6\xfb\xf6\xfb\xf7'
= BGPPAASPath - Dissection (1)
a = BGPPAASPath(b'\x02\x03\xfb\xf0\xfb\xf1\xfb\xf2')
a.segments[0].segment_type == 2 and a.segments[0].segment_length == 3 and a.segments[0].segment_value == [64496, 64497, 64498]
= BGPPAASPath - Dissection (2)
a = BGPPAASPath(b'\x01\x03\xfb\xf0\xfb\xf1\xfb\xf2\x02\x05\xfb\xf4\xfb\xf5\xfb\xf6\xfb\xf6\xfb\xf7')
a.segments[0].segment_type == 1 and a.segments[0].segment_length == 3 and a.segments[0].segment_value == [64496, 64497, 64498] and a.segments[1].segment_type == 2 and a.segments[1].segment_length == 5 and a.segments[1].segment_value == [64500, 64501, 64502, 64502, 64503]
############################### BGPPANextHop ##################################
+ BGPPANextHop class tests
= BGPPANextHop - Instantiation
raw(BGPPANextHop()) == b'\x00\x00\x00\x00'
= BGPPANextHop - Instantiation with specific values
raw(BGPPANextHop(next_hop = "192.0.2.1")) == b'\xc0\x00\x02\x01'
= BGPPANextHop - Basic dissection
a = BGPPANextHop(b'\x00\x00\x00\x00')
a.next_hop == "0.0.0.0"
= BGPPANextHop - Dissection with specific values
a = BGPPANextHop(b'\xc0\x00\x02\x01')
a.next_hop == '192.0.2.1'
############################ BGPPAMultiExitDisc ##############################
+ BGPPAMultiExitDisc class tests
= BGPPAMultiExitDisc - Instantiation
raw(BGPPAMultiExitDisc()) == b'\x00\x00\x00\x00'
= BGPPAMultiExitDisc - Instantiation with specific values (1)
raw(BGPPAMultiExitDisc(med = 4)) == b'\x00\x00\x00\x04'
= BGPPAMultiExitDisc - Basic dissection
a = BGPPAMultiExitDisc(b'\x00\x00\x00\x00')
a.med == 0
############################## BGPPALocalPref ################################
+ BGPPALocalPref class tests
= BGPPALocalPref - Instantiation
raw(BGPPALocalPref()) == b'\x00\x00\x00\x00'
= BGPPALocalPref - Instantiation with specific values (1)
raw(BGPPALocalPref(local_pref = 110)) == b'\x00\x00\x00n'
= BGPPALocalPref - Basic dissection
a = BGPPALocalPref(b'\x00\x00\x00n')
a.local_pref == 110
############################## BGPPAAggregator ###############################
+ BGPPAAggregator class tests
= BGPPAAggregator - Instantiation
raw(BGPPAAggregator()) == b'\x00\x00\x00\x00\x00\x00'
= BGPPAAggregator - Instantiation with specific values (1)
raw(BGPPAAggregator(aggregator_asn = 64500, speaker_address = "192.0.2.1")) == b'\xfb\xf4\xc0\x00\x02\x01'
= BGPPAAggregator - Dissection
a = BGPPAAggregator(b'\xfb\xf4\xc0\x00\x02\x01')
a.aggregator_asn == 64500 and a.speaker_address == "192.0.2.1"
############################## BGPPACommunity ################################
+ BGPPACommunity class tests
= BGPPACommunity - Basic instantiation
raw(BGPPACommunity()) == b'\x00\x00\x00\x00'
= BGPPACommunity - Instantiation with specific value
raw(BGPPACommunity(community = 0xFFFFFF01)) == b'\xff\xff\xff\x01'
= BGPPACommunity - Dissection
a = BGPPACommunity(b'\xff\xff\xff\x01')
a.community == 0xFFFFFF01
############################ BGPPAOriginatorID ###############################
+ BGPPAOriginatorID class tests
= BGPPAOriginatorID - Basic instantiation
raw(BGPPAOriginatorID()) == b'\x00\x00\x00\x00'
= BGPPAOriginatorID - Instantiation with specific value
raw(BGPPAOriginatorID(originator_id = '192.0.2.1')) == b'\xc0\x00\x02\x01'
= BGPPAOriginatorID - Dissection
a = BGPPAOriginatorID(b'\xc0\x00\x02\x01')
a.originator_id == "192.0.2.1"
############################ BGPPAClusterList ################################
+ BGPPAClusterList class tests
= BGPPAClusterList - Basic instantiation
raw(BGPPAClusterList()) == b''
= BGPPAClusterList - Instantiation with specific values
raw(BGPPAClusterList(cluster_list = [150000, 165465465, 132132])) == b'\x00\x02I\xf0\t\xdc\xcdy\x00\x02\x04$'
= BGPPAClusterList - Dissection
a = BGPPAClusterList(b'\x00\x02I\xf0\t\xdc\xcdy\x00\x02\x04$')
a.cluster_list[0] == 150000 and a.cluster_list[1] == 165465465 and a.cluster_list[2] == 132132
########################### BGPPAMPReachNLRI ###############################
+ BGPPAMPReachNLRI class tests
= BGPPAMPReachNLRI - Instantiation
raw(BGPPAMPReachNLRI()) == b'\x00\x00\x00\x00\x00'
= BGPPAMPReachNLRI - Instantiation with specific values (1)
raw(BGPPAMPReachNLRI(afi=2, safi=1, nh_addr_len=16, nh_v6_addr = "2001:db8::2", nlri = [BGPNLRI_IPv6(prefix = "2001:db8:2::/64")])) == b'\x00\x02\x01\x10 \x01\r\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00@ \x01\r\xb8\x00\x02\x00\x00'
= BGPPAMPReachNLRI - Dissection (1)
a = BGPPAMPReachNLRI(b'\x00\x02\x01 \x01\r\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xfe\x80\x00\x00\x00\x00\x00\x00\xc0\x02\x0b\xff\xfe~\x00\x00\x00@ \x01\r\xb8\x00\x02\x00\x02@ \x01\r\xb8\x00\x02\x00\x01@ \x01\r\xb8\x00\x02\x00\x00')
a.afi == 2 and a.safi == 1 and a.nh_addr_len == 32 and a.nh_v6_global == "2001:db8::2" and a.nh_v6_link_local == "fe80::c002:bff:fe7e:0" and a.reserved == 0 and a.nlri[0].prefix == "2001:db8:2:2::/64" and a.nlri[1].prefix == "2001:db8:2:1::/64" and a.nlri[2].prefix == "2001:db8:2::/64"
= BGPPAMPReachNLRI - Dissection (2)
a = BGPPAMPReachNLRI(b'\x00\x02\x01 \xfe\x80\x00\x00\x00\x00\x00\x00\xfa\xc0\x01\x00\x15\xde\x15\x81\xfe\x80\x00\x00\x00\x00\x00\x00\xfa\xc0\x01\x00\x15\xde\x15\x81\x00\x06\x04\x05\x08\x04\x10\x03`\x03\x80\x03\xa0\x03\xc0\x04\xe0\x05\xf0\x06\xf8\t\xfe\x00\x16 \x01<\x08-\x07.\x040\x10?\xfe\x10 \x02\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00`\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff@\x01\x00\x00\x00\x00\x00\x00\x00\x17 \x01\x00 \x01\x00\x000 \x01\x00\x02\x00\x00 \x01\r\xb8\x1c \x01\x00\x10\x07\xfc\n\xfe\x80\x08\xff\n\xfe\xc0\x03 \x03@\x08_`\x00d\xff\x9b\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x08\x01\x07\x02')
a.afi == 2 and a.safi == 1 and a.nh_addr_len == 32 and a.nh_v6_global == "fe80::fac0:100:15de:1581" and a.nh_v6_link_local == "fe80::fac0:100:15de:1581" and a.reserved == 0 and a.nlri[0].prefix == "400::/6" and a.nlri[1].prefix == "800::/5" and raw(a.nlri[18]) == b'`\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff' and a.nlri[35].prefix == "200::/7"
############################# BGPPAMPUnreachNLRI #############################
+ BGPPAMPUnreachNLRI class tests
= BGPPAMPUnreachNLRI - Instantiation
raw(BGPPAMPUnreachNLRI()) == b'\x00\x00\x00'
= BGPPAMPUnreachNLRI - Instantiation with specific values (1)
raw(BGPPAMPUnreachNLRI(afi = 2, safi = 1)) == b'\x00\x02\x01'
= BGPPAMPUnreachNLRI - Instantiation with specific values (2)
raw(BGPPAMPUnreachNLRI(afi = 2, safi = 1, afi_safi_specific = BGPPAMPUnreachNLRI_IPv6(withdrawn_routes = [BGPNLRI_IPv6(prefix = "2001:db8:2::/64")]))) == b'\x00\x02\x01@ \x01\r\xb8\x00\x02\x00\x00'
= BGPPAMPUnreachNLRI - Dissection (1)
a = BGPPAMPUnreachNLRI(b'\x00\x02\x01')
a.afi == 2 and a.safi == 1
= BGPPAMPUnreachNLRI - Dissection (2)
a = BGPPAMPUnreachNLRI(b'\x00\x02\x01\x03`\x03\x80\x03\xa0\x03\xc0\x04\xe0\x05\xf0\x06\xf8\x10 \x02`\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff@\x01\x00\x00\x00\x00\x00\x00\x00\x17 \x01\x00 \x01\x00\x000 \x01\x00\x02\x00\x00 \x01\r\xb8\n\xfe\xc0\x07\xfc\n\xfe\x80\x1c \x01\x00\x10\x03 \x06\x04\x03@\x08_\x05\x08\x04\x10')
a.afi == 2 and a.safi == 1 and a.afi_safi_specific.withdrawn_routes[0].prefix == "6000::/3" and a.afi_safi_specific.withdrawn_routes[11].prefix == "2001::/32" and a.afi_safi_specific.withdrawn_routes[23].prefix == "1000::/4"
############################# BGPPAAS4Aggregator #############################
+ BGPPAAS4Aggregator class tests
= BGPPAAS4Aggregator - Instantiation
raw(BGPPAAS4Aggregator()) == b'\x00\x00\x00\x00\x00\x00\x00\x00'
= BGPPAAS4Aggregator - Instantiation with specific values
raw(BGPPAAS4Aggregator(aggregator_asn = 644566565, speaker_address = "192.0.2.1")) == b'&kN%\xc0\x00\x02\x01'
= BGPPAAS4Aggregator - Dissection
a = BGPPAAS4Aggregator(b'&kN%\xc0\x00\x02\x01')
a.aggregator_asn == 644566565 and a.speaker_address == "192.0.2.1"
############################# BGPPALargeCommunity ############################
+ BGPPALargeCommunity class tests
= BGPPALargeCommunity - Instantiation
raw(BGPPALargeCommunity()) == b''
= BGPPALargeCommunity - Instantiation with specific values
raw(BGPPALargeCommunity(segments=BGPLargeCommunitySegment(global_administrator=161,local_data_part1=0,local_data_part2=0))) == b'\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00'
= BGPPALargeCommunity - Dissection
a = BGPPALargeCommunity(b'\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00')
a.segments[0].global_administrator == 161 and a.segments[0].local_data_part1 == 0 and a.segments[0].local_data_part2 == 0
################################ BGPPathAttr #################################
+ BGPPathAttr class tests
= BGPPathAttr - Instantiation
raw(BGPPathAttr()) == b'\x80\x00\x00'
= BGPPathAttr - Instantiation with specific values (1)
raw(BGPPathAttr(type_code = 1, attribute = BGPPAOrigin(origin = 0)))
= BGPPathAttr - Instantiation with specific values (2)
raw(BGPPathAttr(type_code = 2, attribute = BGPPAASPath(segments = [BGPPAASPath.ASPathSegment(segment_type = 2, segment_value = [64501, 64501, 64501])]))) == b'\x80\x02\x08\x02\x03\xfb\xf5\xfb\xf5\xfb\xf5'
= BGPPathAttr - Instantiation with specific values (3)
raw(BGPPathAttr(type_code = 14, attribute = BGPPAMPReachNLRI(afi = 2, safi = 1, nh_addr_len = 16, nh_v6_addr = "2001:db8::2", nlri = [BGPNLRI_IPv6(prefix = "2001:db8:2::/64")]))) == b'\x80\x0e\x1e\x00\x02\x01\x10 \x01\r\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00@ \x01\r\xb8\x00\x02\x00\x00'
= BGPPathAttr - Dissection (1)
a = BGPPathAttr(b'\x90\x0f\x00X\x00\x02\x01\x03`\x03\x80\x03\xa0\x03\xc0\x04\xe0\x05\xf0\x06\xf8\x10 \x02`\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff@\x01\x00\x00\x00\x00\x00\x00\x00\x17 \x01\x00 \x01\x00\x000 \x01\x00\x02\x00\x00 \x01\r\xb8\n\xfe\xc0\x07\xfc\n\xfe\x80\x1c \x01\x00\x10\x03 \x06\x04\x03@\x08_\x05\x08\x04\x10')
a.type_flags == 0x90 and a.type_code == 15 and a.attr_ext_len == 88 and a.attribute.afi == 2 and a.attribute.safi == 1 and a.attribute.afi_safi_specific.withdrawn_routes[0].prefix == "6000::/3" and a.attribute.afi_safi_specific.withdrawn_routes[1].prefix == "8000::/3" and a.attribute.afi_safi_specific.withdrawn_routes[2].prefix == "a000::/3" and a.attribute.afi_safi_specific.withdrawn_routes[3].prefix == "c000::/3" and a.attribute.afi_safi_specific.withdrawn_routes[4].prefix == "e000::/4" and a.attribute.afi_safi_specific.withdrawn_routes[5].prefix == "f000::/5" and a.attribute.afi_safi_specific.withdrawn_routes[23].prefix == "1000::/4"
= BGPPathAttr - advanced
b = BGPPathAttr(type_code=0x10, attribute=BGPPAExtComms(extended_communities=[
BGPPAExtCommunity(value=BGPPAExtCommTwoOctetASSpecific()),
BGPPAExtCommunity(value=BGPPAExtCommIPv4AddressSpecific()),
BGPPAExtCommunity(value=BGPPAExtCommFourOctetASSpecific()),
BGPPAExtCommunity(value=BGPPAExtCommOpaque()),
BGPPAExtCommunity(value=BGPPAExtCommTrafficMarking()),
BGPPAExtCommunity(value=BGPPAExtCommRedirectIPv4()),
BGPPAExtCommunity(value=BGPPAExtCommRedirectAS4Byte()),
]))
b = BGPPathAttr(raw(b))
cls_list = [x.value.__class__ for x in b.attribute.extended_communities]
assert cls_list == [BGPPAExtCommTwoOctetASSpecific, BGPPAExtCommIPv4AddressSpecific, BGPPAExtCommFourOctetASSpecific, BGPPAExtCommOpaque,
BGPPAExtCommTrafficMarking, BGPPAExtCommRedirectIPv4, BGPPAExtCommRedirectAS4Byte]
b.show()
################################# BGPUpdate ##################################
+ BGPUpdate class tests
= BGPUpdate - Instantiation
raw(BGPUpdate()) == b'\x00\x00\x00\x00'
= BGPUpdate - Dissection (1)
bgp_module_conf.use_2_bytes_asn = True
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x000\x02\x00\x19\x18\xc0\xa8\x96\x18\x07\x07\x07\x18\xc63d\x18\xc0\xa8\x01\x19\x06\x06\x06\x00\x18\xc0\xa8\x1a\x00\x00')
assert BGPHeader in m and BGPUpdate in m
assert m.withdrawn_routes_len == 25
assert m.withdrawn_routes[0].prefix == "192.168.150.0/24"
assert m.withdrawn_routes[5].prefix == "192.168.26.0/24"
assert m.path_attr_len == 0
= BGPUpdate - Behave like a NEW speaker (RFC 6793) - Dissection (2)
bgp_module_conf.use_2_bytes_asn = False
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00=\x02\x00\x00\x00"@\x01\x01\x00@\x02\x06\x02\x01\x00\x00\xfb\xfa@\x03\x04\xc0\xa8\x10\x06\x80\x04\x04\x00\x00\x00\x00\xc0\x08\x04\xff\xff\xff\x01\x18\xc0\xa8\x01')
assert BGPHeader in m and BGPUpdate in m
assert m.path_attr[1].attribute.segments[0].segment_value == [64506]
assert m.path_attr[4].attribute.community == 0xFFFFFF01
assert m.nlri[0].prefix == "192.168.1.0/24"
= BGPUpdate - Dissection (MP_REACH_NLRI)
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\xd8\x02\x00\x00\x00\xc1@\x01\x01\x00@\x02\x06\x02\x01\x00\x00\xfb\xf6\x90\x0e\x00\xb0\x00\x02\x01 \xfe\x80\x00\x00\x00\x00\x00\x00\xfa\xc0\x01\x00\x15\xde\x15\x81\xfe\x80\x00\x00\x00\x00\x00\x00\xfa\xc0\x01\x00\x15\xde\x15\x81\x00\x06\x04\x05\x08\x04\x10\x03`\x03\x80\x03\xa0\x03\xc0\x04\xe0\x05\xf0\x06\xf8\t\xfe\x00\x16 \x01<\x08-\x07.\x040\x10?\xfe\x10 \x02\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00`\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff@\x01\x00\x00\x00\x00\x00\x00\x00\x17 \x01\x00 \x01\x00\x000 \x01\x00\x02\x00\x00 \x01\r\xb8\x1c \x01\x00\x10\x07\xfc\n\xfe\x80\x08\xff\n\xfe\xc0\x03 \x03@\x08_`\x00d\xff\x9b\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x08\x01\x07\x02')
assert BGPHeader in m and BGPUpdate in m
assert m.path_attr[2].attribute.afi == 2
assert m.path_attr[2].attribute.safi == 1
assert m.path_attr[2].attribute.nh_addr_len == 32
assert m.path_attr[2].attribute.nh_v6_global == "fe80::fac0:100:15de:1581"
assert m.path_attr[2].attribute.nh_v6_link_local == "fe80::fac0:100:15de:1581"
assert m.path_attr[2].attribute.nlri[0].prefix == "400::/6"
assert m.nlri == []
= BGPUpdate - Dissection (MP_UNREACH_NLRI)
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00s\x02\x00\x00\x00\\\x90\x0f\x00X\x00\x02\x01\x03`\x03\x80\x03\xa0\x03\xc0\x04\xe0\x05\xf0\x06\xf8\x10 \x02`\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff@\x01\x00\x00\x00\x00\x00\x00\x00\x17 \x01\x00 \x01\x00\x000 \x01\x00\x02\x00\x00 \x01\r\xb8\n\xfe\xc0\x07\xfc\n\xfe\x80\x1c \x01\x00\x10\x03 \x06\x04\x03@\x08_\x05\x08\x04\x10')
assert BGPHeader in m and BGPUpdate in m
assert m.path_attr[0].attribute.afi == 2
assert m.path_attr[0].attribute.safi == 1
assert m.path_attr[0].attribute.afi_safi_specific.withdrawn_routes[0].prefix == "6000::/3"
assert m.nlri == []
= BGPUpdate - Dissection (with BGP Additional Path)
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x17\x05\x00\x01\x01\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\xd0\x02\x00\xb9\x00\x00\x00\x02\x00\x00\x00\x00\x04 \n\xe9\x19\xb2\x00\x00\x00\x04 \n\xe9\x19\x90\x00\x00\x00\x04 \n\xe9\x19\x93\x00\x00\x00\x04 \n\xe9\x19\xbb\x00\x00\x00\x04 \n\xe9\x19\x9f\x00\x00\x00\x04 \n\xe9\x19\x8c\x00\x00\x00\x04 \n\xe9\x19\xb1\x00\x00\x00\x04 \n\xe9\x19\x8f\x00\x00\x00\x04 \n\xe9\x19\x98\x00\x00\x00\x04 \n\xe9\x19\x9b\x00\x00\x00\x04 \n\xe9\x19\x8b\x00\x00\x00\x04 \n\xe9\x19\xb3\x00\x00\x00\x04 \n\xe9\x19\x91\x00\x00\x00\x04 \n\xe9\x19\xb6\x00\x00\x00\x04 \n\xe9\x19\x94\x00\x00\x00\x04 \n\xe9\x19\x97\x00\x00\x00\x04 \n\xe9\x19\xbc\x00\x00\x00\x04 \n\xe9\x19\x9d\x00\x00\x00\x04 \n\xe9\x19\xa3\x00\x00\x00\x04 \n\xe9\x19\x84\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x005\x02\x00\x00\x00\x15@\x01\x01\x00@\x02\x00@\x03\x04\n\x16\x0cX@\x05\x04\x00\x00\x00d\x00\x00\x00\x02 \n\xe9\x00\x16\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x17\x05\x00\x01\x02\x01')
assert m.withdrawn_routes[0].nlri_path_id == 2
assert len(m.withdrawn_routes) == 21
assert m.withdrawn_routes[-1].sprintf("%prefix%") == "10.233.25.132/32"
assert len(m.getlayer(BGPUpdate, 2).path_attr) == 4
assert m.getlayer(BGPUpdate, 2).nlri[0].nlri_path_id == 2
assert m.getlayer(BGPUpdate, 2).nlri[0].sprintf("%prefix%") == "10.233.0.22/32"
= BGPUpdate - with BGPHeader
p = BGP(raw(BGPHeader()/BGPUpdate()))
assert BGPHeader in p and BGPUpdate in p
########## BGPNotification Class ###################################
+ BGPNotification class tests
= BGPNotification - Instantiation
raw(BGPNotification()) == b'\x00\x00'
= BGPNotification - Dissection (Administratively Reset)
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x15\x03\x06\x04')
m.type == BGP.NOTIFICATION_TYPE and m.error_code == 6 and m.error_subcode == 4
= BGPNotification - Dissection (Bad Peer AS)
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x17\x03\x02\x02\x00\x00')
m.type == BGP.NOTIFICATION_TYPE and m.error_code == 2 and m.error_subcode == 2
= BGPNotification - Dissection (Attribute Flags Error)
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x19\x03\x03\x04\x80\x01\x01\x00')
m.type == BGP.NOTIFICATION_TYPE and m.error_code == 3 and m.error_subcode == 4
########## BGPRouteRefresh Class ###################################
+ BGPRouteRefresh class tests
= BGPRouteRefresh - Instantiation
raw(BGPRouteRefresh()) == b'\x00\x01\x00\x01'
= BGPRouteRefresh - Instantiation with specific values
raw(BGPRouteRefresh(afi = 1, safi = 1)) == b'\x00\x01\x00\x01'
= BGPRouteRefresh - Dissection (1)
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x17\x05\x00\x02\x00\x01')
m.type == BGP.ROUTEREFRESH_TYPE and m.len == 23 and m.afi == 2 and m.subtype == 0 and m.safi == 1
= BGPRouteRefresh - Dissection (2) - With ORFs
m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00.\x05\x00\x01\x00\x01\x01\x80\x00\x13 \x00\x00\x00\x05\x18\x18\x15\x01\x01\x00\x00\x00\x00\x00\n\x00 \x00')
assert m.type == BGP.ROUTEREFRESH_TYPE
assert m.len == 46
assert m.afi == 1
assert m.subtype == 0
assert m.safi == 1
assert m.orf_data[0].when_to_refresh == 1
assert m.orf_data[0].orf_type == 128
assert m.orf_data[0].orf_len == 19
assert len(m.orf_data[0].entries) == 2
assert m.orf_data[0].entries[0].action == 0
assert m.orf_data[0].entries[0].match == 1
assert m.orf_data[0].entries[0].prefix.prefix == "1.1.0.0/21"
assert m.orf_data[0].entries[1].action == 0
assert m.orf_data[0].entries[1].match == 0
assert m.orf_data[0].entries[1].prefix.prefix == "0.0.0.0/0"
= BGPRouteRefresh - Dissection (3) - bad ORFS (GH3345)
m = BGPRouteRefresh(b'\x00\x01\x00\x01\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00')
assert m.orf_data.orf_type == 0
assert m.orf_data.entries[0].load == b'\x00\x00\x00\x00\x00\x00\x00'
########## BGPCapGeneric fuzz() ###################################
+ BGPCapGeneric fuzz()
= BGPCapGeneric fuzz()
for i in range(10):
assert isinstance(raw(fuzz(BGPCapGeneric())), bytes)
|