1#################################### bgp.py ################################## 2% Regression tests for the bgp module 3 4+ Default configuration 5 6= OLD speaker (see RFC 6793) 7bgp_module_conf.use_2_bytes_asn = True 8 9################################ BGPNLRI_IPv4 ################################ 10+ BGPNLRI_IPv4 class tests 11 12= BGPNLRI_IPv4 - Instantiation 13raw(BGPNLRI_IPv4()) == b'\x00' 14 15= BGPNLRI_IPv4 - Instantiation with specific values (1) 16raw(BGPNLRI_IPv4(prefix = '255.255.255.255/32')) == b' \xff\xff\xff\xff' 17 18= BGPNLRI_IPv4 - Instantiation with specific values (2) 19raw(BGPNLRI_IPv4(prefix = '0.0.0.0/0')) == b'\x00' 20 21= BGPNLRI_IPv4 - Instantiation with specific values (3) 22raw(BGPNLRI_IPv4(prefix = '192.0.2.0/24')) == b'\x18\xc0\x00\x02' 23 24= BGPNLRI_IPv4 - Basic dissection 25nlri = BGPNLRI_IPv4(b'\x00') 26nlri.prefix == '0.0.0.0/0' 27 28= BGPNLRI_IPv4 - Dissection with specific values 29nlri = BGPNLRI_IPv4(b'\x18\xc0\x00\x02') 30nlri.prefix == '192.0.2.0/24' 31 32 33################################ BGPNLRI_IPv6 ################################ 34+ BGPNLRI_IPv6 class tests 35 36= BGPNLRI_IPv6 - Instantiation 37raw(BGPNLRI_IPv6()) == b'\x00' 38 39= BGPNLRI_IPv6 - Instantiation with specific values (1) 40raw(BGPNLRI_IPv6(prefix = '::/0')) == b'\x00' 41 42= BGPNLRI_IPv6 - Instantiation with specific values (2) 43raw(BGPNLRI_IPv6(prefix = '2001:db8::/32')) == b' \x01\r\xb8' 44 45= BGPNLRI_IPv6 - Basic dissection 46nlri = BGPNLRI_IPv6(b'\x00') 47nlri.prefix == '::/0' 48 49= BGPNLRI_IPv6 - Dissection with specific values 50nlri = BGPNLRI_IPv6(b' \x01\r\xb8') 51nlri.prefix == '2001:db8::/32' 52 53 54#################################### BGP ##################################### 55+ BGP class tests 56 57= BGP - Instantiation (Should be a KEEPALIVE) 58m = BGP() 59assert raw(m) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04' 60assert m.type == BGP.KEEPALIVE_TYPE 61 62= BGP - Instantiation with specific values (1) 63raw(BGP(type = 0)) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x00' 64 65= BGP - Instantiation with specific values (2) 66raw(BGP(type = 1)) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x01' 67 68= BGP - Instantiation with specific values (3) 69raw(BGP(type = 2)) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x02' 70 71= BGP - Instantiation with specific values (4) 72raw(BGP(type = 3)) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x03' 73 74= BGP - Instantiation with specific values (5) 75raw(BGP(type = 4)) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04' 76 77= BGP - Instantiation with specific values (6) 78raw(BGP(type = 5)) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x05' 79 80= BGP - Basic dissection 81h = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04') 82assert h.type == BGP.KEEPALIVE_TYPE 83assert h.len == 19 84 85= BGP - Dissection with specific values 86h = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x01') 87assert h.type == BGP.OPEN_TYPE 88assert h.len == 19 89 90############################### BGPKeepAlive ################################# 91+ BGPKeepAlive class tests 92 93= BGPKeepAlive - Instantiation (by default, should be a "generic" capability) 94raw(BGPKeepAlive()) 95raw(BGPKeepAlive()) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04' 96 97= BGPKeepAlive - Swallowing tests: combined BGPKeepAlive 98o = BGPKeepAlive() 99m=IP(src="12.0.0.1",dst="12.0.0.2")/TCP(dport=54321)/BGP(raw(o)*2) 100m.show() 101assert isinstance(m[BGPKeepAlive].payload, BGPKeepAlive) 102assert m[BGPKeepAlive].payload.marker == 0xffffffffffffffffffffffffffffffff 103 104############################### BGPCapability ################################# 105+ BGPCapability class tests 106 107= BGPCapability - Instantiation (by default, should be a "generic" capability) 108raw(BGPCapability()) 109raw(BGPCapability()) == b'\x00\x00' 110 111= BGPCapability - Instantiation with specific values (1) 112c = BGPCapability(code = 70) 113assert raw(c) == b'F\x00' 114 115= BGPCapability - Check exception 116from scapy.contrib.bgp import _BGPInvalidDataException 117try: 118 BGPCapability("\x00") 119 False 120except _BGPInvalidDataException: 121 True 122 123= BGPCapability - Test haslayer() 124assert BGPCapFourBytesASN().haslayer(BGPCapability) 125assert BGPCapability in BGPCapFourBytesASN() 126 127= BGPCapability - Test getlayer() 128assert isinstance(BGPCapFourBytesASN().getlayer(BGPCapability), BGPCapFourBytesASN) 129assert isinstance(BGPCapFourBytesASN()[BGPCapability], BGPCapFourBytesASN) 130 131= BGPCapability - sessions (1) 132p = IP()/TCP()/BGPCapability() 133l = PacketList(p) 134s = l.sessions() # Crashed on commit: e42ecdc54556c4852ca06b1a6da6c1ccbf3f522e 135assert len(s) == 1 136 137= BGPCapability - sessions (2) 138p = IP()/UDP()/BGPCapability() 139l = PacketList(p) 140s = l.sessions() # Crashed on commit: e42ecdc54556c4852ca06b1a6da6c1ccbf3f522e 141assert len(s) == 1 142 143 144############################ BGPCapMultiprotocol ############################## 145+ BGPCapMultiprotocol class tests 146 147= BGPCapMultiprotocol - Inheritance 148c = BGPCapMultiprotocol() 149assert isinstance(c, BGPCapability) 150 151= BGPCapMultiprotocol - Instantiation 152raw(BGPCapMultiprotocol()) == b'\x01\x04\x00\x00\x00\x00' 153 154= BGPCapMultiprotocol - Instantiation with specific values (1) 155raw(BGPCapMultiprotocol(afi = 1, safi = 1)) == b'\x01\x04\x00\x01\x00\x01' 156 157= BGPCapMultiprotocol - Instantiation with specific values (2) 158raw(BGPCapMultiprotocol(afi = 2, safi = 1)) == b'\x01\x04\x00\x02\x00\x01' 159 160= BGPCapMultiprotocol - Dissection with specific values 161c = BGPCapMultiprotocol(b'\x01\x04\x00\x02\x00\x01') 162assert c.code == 1 163assert c.length == 4 164assert c.afi == 2 165assert c.reserved == 0 166assert c.safi == 1 167 168############################### BGPCapORFBlock ############################### 169+ BGPCapORFBlock class tests 170 171= BGPCapORFBlock - Instantiation 172raw(BGPCapORFBlock()) == b'\x00\x00\x00\x00\x00' 173 174= BGPCapORFBlock - Instantiation with specific values (1) 175raw(BGPCapORFBlock(afi = 1, safi = 1)) == b'\x00\x01\x00\x01\x00' 176 177= BGPCapORFBlock - Instantiation with specific values (2) 178raw(BGPCapORFBlock(afi = 2, safi = 1)) == b'\x00\x02\x00\x01\x00' 179 180= BGPCapORFBlock - Basic dissection 181c = BGPCapORFBlock(b'\x00\x00\x00\x00\x00') 182c.afi == 0 and c.reserved == 0 and c.safi == 0 and c.orf_number == 0 183 184= BGPCapORFBlock - Dissection with specific values 185c = BGPCapORFBlock(b'\x00\x02\x00\x01\x00') 186c.afi == 2 and c.reserved == 0 and c.safi == 1 and c.orf_number == 0 187 188 189############################# BGPCapORFBlock.ORF ############################## 190+ BGPCapORFBlock.ORF class tests 191 192= BGPCapORFBlock.ORF - Instantiation 193raw(BGPCapORFBlock.ORFTuple()) == b'\x00\x00' 194 195= BGPCapORFBlock.ORF - Instantiation with specific values (1) 196raw(BGPCapORFBlock.ORFTuple(orf_type = 64, send_receive = 3)) == b'@\x03' 197 198= BGPCapORFBlock.ORF - Basic dissection 199c = BGPCapORFBlock.ORFTuple(b'\x00\x00') 200c.orf_type == 0 and c.send_receive == 0 201 202= BGPCapORFBlock.ORF - Dissection with specific values 203c = BGPCapORFBlock.ORFTuple(b'@\x03') 204c.orf_type == 64 and c.send_receive == 3 205 206 207################################# BGPCapORF ################################### 208+ BGPCapORF class tests 209 210= BGPCapORF - Inheritance 211c = BGPCapORF() 212assert isinstance(c, BGPCapability) 213 214= BGPCapORF - Instantiation 215raw(BGPCapORF()) == b'\x03\x00' 216 217= BGPCapORF - Instantiation with specific values (1) 218raw(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' 219 220= BGPCapORF - Instantiation with specific values (2) 221raw(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' 222 223= BGPCapORF - Basic dissection 224c = BGPCapORF(b'\x03\x00') 225c.code == 3 and c.length == 0 226 227= BGPCapORF - Dissection with specific values 228c = 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)])]) 229c.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 230 231= BGPCapORF - Dissection 232p = BGPCapORF(b'\x03\x07\x00\x01\x00\x01\x01@\x03') 233assert len(p.orf) == 1 234 235 236####################### BGPCapGracefulRestart.GRTuple ######################### 237+ BGPCapGracefulRestart.GRTuple class tests 238 239= BGPCapGracefulRestart.GRTuple - Instantiation 240raw(BGPCapGracefulRestart.GRTuple()) == b'\x00\x00\x00\x00' 241 242= BGPCapGracefulRestart.GRTuple - Instantiation with specific values 243raw(BGPCapGracefulRestart.GRTuple(afi = 1, safi = 1, flags = 128)) == b'\x00\x01\x01\x80' 244 245= BGPCapGracefulRestart.GRTuple - Basic dissection 246c = BGPCapGracefulRestart.GRTuple(b'\x00\x00\x00\x00') 247c.afi == 0 and c.safi == 0 and c.flags == 0 248 249= BGPCapGracefulRestart.GRTuple - Dissection with specific values 250c = BGPCapGracefulRestart.GRTuple(b'\x00\x01\x01\x80') 251c.afi == 1 and c.safi == 1 and c.flags == 128 252 253 254########################### BGPCapGracefulRestart ############################# 255+ BGPCapGracefulRestart class tests 256 257= BGPCapGracefulRestart - Inheritance 258c = BGPCapGracefulRestart() 259assert isinstance(c, BGPCapGracefulRestart) 260 261= BGPCapGracefulRestart - Instantiation 262raw(BGPCapGracefulRestart()) == b'@\x02\x00\x00' 263 264= BGPCapGracefulRestart - Instantiation with specific values (1) 265raw(BGPCapGracefulRestart(restart_time = 120, entries = [BGPCapGracefulRestart.GRTuple(afi = 1, safi = 1)])) == b'@\x06\x00x\x00\x01\x01\x00' 266 267= BGPCapGracefulRestart - Instantiation with specific values (2) 268raw(BGPCapGracefulRestart(restart_time = 120, entries = [BGPCapGracefulRestart.GRTuple(afi = 1, safi = 1)])) == b'@\x06\x00x\x00\x01\x01\x00' 269 270= BGPCapGracefulRestart - Instantiation with specific values (3) 271raw(BGPCapGracefulRestart(restart_time = 120, entries = [BGPCapGracefulRestart.GRTuple(afi = 1, safi = 1, flags = 128)])) == b'@\x06\x00x\x00\x01\x01\x80' 272 273= BGPCapGracefulRestart - Instantiation with specific values (4) 274raw(BGPCapGracefulRestart(restart_time = 120, restart_flags = 0x8, entries = [BGPCapGracefulRestart.GRTuple(afi = 1, safi = 1, flags = 128)])) == b'@\x06\x80x\x00\x01\x01\x80' 275 276= BGPCapGracefulRestart - Basic dissection 277c = BGPCapGracefulRestart(b'@\x02\x00\x00') 278c.code == 64 and c.restart_flags == 0 and c.restart_time == 0 279 280= BGPCapGracefulRestart - Dissection with specific values 281c = BGPCapGracefulRestart(b'@\x06\x80x\x00\x01\x01\x80') 282c.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 283 284 285############################ BGPCapFourBytesASN ############################### 286+ BGPCapFourBytesASN class tests 287 288= BGPCapFourBytesASN - Inheritance 289c = BGPCapFourBytesASN() 290assert isinstance(c, BGPCapFourBytesASN) 291 292= BGPCapFourBytesASN - Instantiation 293raw(BGPCapFourBytesASN()) == b'A\x04\x00\x00\x00\x00' 294 295= BGPCapFourBytesASN - Instantiation with specific values (1) 296raw(BGPCapFourBytesASN(asn = 6555555)) == b'A\x04\x00d\x07\xa3' 297 298= BGPCapFourBytesASN - Instantiation with specific values (2) 299raw(BGPCapFourBytesASN(asn = 4294967295)) == b'A\x04\xff\xff\xff\xff' 300 301= BGPCapFourBytesASN - Basic dissection 302c = BGPCapFourBytesASN(b'A\x04\x00\x00\x00\x00') 303c.code == 65 and c.length == 4 and c.asn == 0 304 305= BGPCapFourBytesASN - Dissection with specific values 306c = BGPCapFourBytesASN(b'A\x04\xff\xff\xff\xff') 307c.code == 65 and c.length == 4 and c.asn == 4294967295 308 309 310####################### BGPAuthenticationInformation ########################## 311+ BGPAuthenticationInformation class tests 312 313= BGPAuthenticationInformation - Instantiation 314raw(BGPAuthenticationInformation()) == b'\x00' 315 316= BGPAuthenticationInformation - Basic dissection 317c = BGPAuthenticationInformation(b'\x00') 318c.authentication_code == 0 and not c.authentication_data 319 320 321################################# BGPOptParam ################################# 322+ BGPOptParam class tests 323 324= BGPOptParam - Instantiation 325raw(BGPOptParam()) == b'\x02\x00' 326 327= BGPOptParam - Instantiation with specific values (1) 328raw(BGPOptParam(param_type = 1)) == b'\x01\x00' 329raw(BGPOptParam(param_type = 1, param_value = BGPAuthenticationInformation())) == b'\x01\x00' 330 331= BGPOptParam - Instantiation with specific values (2) 332raw(BGPOptParam(param_type = 2)) == b'\x02\x00' 333 334= BGPOptParam - Instantiation with specific values (3) 335raw(BGPOptParam(param_type = 2, param_value = BGPCapFourBytesASN(asn = 4294967295))) == b'\x02\x06A\x04\xff\xff\xff\xff' 336 337= BGPOptParam - Instantiation with specific values (4) 338raw(BGPOptParam(param_type = 2, param_value = BGPCapability(code = 127))) == b'\x02\x02\x7f\x00' 339 340= BGPOptParam - Instantiation with specific values (5) 341raw(BGPOptParam(param_type = 2, param_value = BGPCapability(code = 255))) == b'\x02\x02\xff\x00' 342 343= BGPOptParam - Basic dissection 344p = BGPOptParam(b'\x02\x00') 345p.param_type == 2 and p.param_length == 0 346 347= BGPOptParam - Dissection with specific values 348p = BGPOptParam(b'\x02\x06A\x04\xff\xff\xff\xff') 349p.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 350 351 352################################### BGPOpen ################################### 353+ BGPOpen class tests 354 355= BGPOpen - Instantiation 356raw(BGPOpen()) == b'\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00' 357 358= BGPOpen - Instantiation with specific values (1) 359raw(BGPOpen(my_as = 64501, bgp_id = "192.0.2.1")) == b'\x04\xfb\xf5\x00\x00\xc0\x00\x02\x01\x00' 360 361= BGPOpen - Instantiation with specific values (2) 362opt = BGPOptParam(param_value = BGPCapMultiprotocol(afi = 1, safi = 1)) 363raw(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' 364 365= BGPOpen - Instantiation with specific values (3) 366cap = BGPOptParam(param_value = BGPCapMultiprotocol(afi = 1, safi = 1)) 367capabilities = [cap] 368cap = BGPOptParam(param_value = BGPCapability(code = 128)) 369capabilities.append(cap) 370cap = BGPOptParam(param_value = BGPCapability(code = 2)) 371capabilities.append(cap) 372cap = BGPOptParam(param_value = BGPCapGracefulRestart(restart_time = 120, entries = [BGPCapGracefulRestart.GRTuple(afi = 1, safi= 1, flags = 128)])) 373capabilities.append(cap) 374cap = BGPOptParam(param_value = BGPCapFourBytesASN(asn = 64503)) 375capabilities.append(cap) 376raw(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' 377 378= BGPOpen - Dissection with specific values (1) 379m = 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') 380assert BGPHeader in m and BGPOpen in m 381assert m.len == 63 382assert m.type == BGP.OPEN_TYPE 383assert m.version == 4 384assert m.my_as == 64503 385assert m.hold_time == 30 386assert m.bgp_id == "192.168.100.3" 387assert m.opt_param_len == 34 388assert isinstance(m.opt_params[0].param_value, BGPCapMultiprotocol) 389assert isinstance(m.opt_params[1].param_value, BGPCapability) 390assert isinstance(m.opt_params[2].param_value, BGPCapability) 391assert isinstance(m.opt_params[3].param_value, BGPCapGracefulRestart) 392 393= BGPOpen - Dissection with specific values (2) (followed by a KEEPALIVE) 394messages = 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' 395m = BGP(messages) 396raw(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' 397 398= BGPOpen - Dissection with specific values (3) 399m = 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') 400assert BGPHeader in m and BGPOpen in m 401 402= BGPOpen - Dissection with specific values (4) 403m = 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') 404assert BGPHeader in m and BGPOpen in m 405 406 407################################# BGPPAOrigin ################################# 408+ BGPPAOrigin class tests 409 410= BGPPAOrigin - Instantiation 411raw(BGPPAOrigin()) == b'\x00' 412 413= BGPPAOrigin - Instantiation with specific values 414raw(BGPPAOrigin(origin = 1)) == b'\x01' 415 416= BGPPAOrigin - Dissection 417a = BGPPAOrigin(b'\x00') 418a.origin == 0 419 420 421################################ BGPPAASPath ################################## 422+ BGPPAASPath class tests 423 424= BGPPAASPath - Instantiation 425raw(BGPPAASPath()) == b'' 426 427= BGPPAASPath - Instantiation with specific values (1) 428raw(BGPPAASPath(segments = [BGPPAASPath.ASPathSegment(segment_type = 2, segment_value = [64496, 64497, 64498])])) == b'\x02\x03\xfb\xf0\xfb\xf1\xfb\xf2' 429 430= BGPPAASPath - Instantiation with specific values (2) 431raw(BGPPAASPath(segments = [BGPPAASPath.ASPathSegment(segment_type = 1, segment_value = [64496, 64497, 64498])])) == b'\x01\x03\xfb\xf0\xfb\xf1\xfb\xf2' 432 433= BGPPAASPath - Instantiation with specific values (3) 434raw(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' 435 436= BGPPAASPath - Dissection (1) 437a = BGPPAASPath(b'\x02\x03\xfb\xf0\xfb\xf1\xfb\xf2') 438a.segments[0].segment_type == 2 and a.segments[0].segment_length == 3 and a.segments[0].segment_value == [64496, 64497, 64498] 439 440= BGPPAASPath - Dissection (2) 441a = BGPPAASPath(b'\x01\x03\xfb\xf0\xfb\xf1\xfb\xf2\x02\x05\xfb\xf4\xfb\xf5\xfb\xf6\xfb\xf6\xfb\xf7') 442a.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] 443 444 445############################### BGPPANextHop ################################## 446+ BGPPANextHop class tests 447 448= BGPPANextHop - Instantiation 449raw(BGPPANextHop()) == b'\x00\x00\x00\x00' 450 451= BGPPANextHop - Instantiation with specific values 452raw(BGPPANextHop(next_hop = "192.0.2.1")) == b'\xc0\x00\x02\x01' 453 454= BGPPANextHop - Basic dissection 455a = BGPPANextHop(b'\x00\x00\x00\x00') 456a.next_hop == "0.0.0.0" 457 458= BGPPANextHop - Dissection with specific values 459a = BGPPANextHop(b'\xc0\x00\x02\x01') 460a.next_hop == '192.0.2.1' 461 462 463############################ BGPPAMultiExitDisc ############################## 464+ BGPPAMultiExitDisc class tests 465 466= BGPPAMultiExitDisc - Instantiation 467raw(BGPPAMultiExitDisc()) == b'\x00\x00\x00\x00' 468 469= BGPPAMultiExitDisc - Instantiation with specific values (1) 470raw(BGPPAMultiExitDisc(med = 4)) == b'\x00\x00\x00\x04' 471 472= BGPPAMultiExitDisc - Basic dissection 473a = BGPPAMultiExitDisc(b'\x00\x00\x00\x00') 474a.med == 0 475 476 477############################## BGPPALocalPref ################################ 478+ BGPPALocalPref class tests 479 480= BGPPALocalPref - Instantiation 481raw(BGPPALocalPref()) == b'\x00\x00\x00\x00' 482 483= BGPPALocalPref - Instantiation with specific values (1) 484raw(BGPPALocalPref(local_pref = 110)) == b'\x00\x00\x00n' 485 486= BGPPALocalPref - Basic dissection 487a = BGPPALocalPref(b'\x00\x00\x00n') 488a.local_pref == 110 489 490 491############################## BGPPAAggregator ############################### 492+ BGPPAAggregator class tests 493 494= BGPPAAggregator - Instantiation 495raw(BGPPAAggregator()) == b'\x00\x00\x00\x00\x00\x00' 496 497= BGPPAAggregator - Instantiation with specific values (1) 498raw(BGPPAAggregator(aggregator_asn = 64500, speaker_address = "192.0.2.1")) == b'\xfb\xf4\xc0\x00\x02\x01' 499 500= BGPPAAggregator - Dissection 501a = BGPPAAggregator(b'\xfb\xf4\xc0\x00\x02\x01') 502a.aggregator_asn == 64500 and a.speaker_address == "192.0.2.1" 503 504 505############################## BGPPACommunity ################################ 506+ BGPPACommunity class tests 507 508= BGPPACommunity - Basic instantiation 509raw(BGPPACommunity()) == b'\x00\x00\x00\x00' 510 511= BGPPACommunity - Instantiation with specific value 512raw(BGPPACommunity(community = 0xFFFFFF01)) == b'\xff\xff\xff\x01' 513 514= BGPPACommunity - Dissection 515a = BGPPACommunity(b'\xff\xff\xff\x01') 516a.community == 0xFFFFFF01 517 518 519############################ BGPPAOriginatorID ############################### 520+ BGPPAOriginatorID class tests 521 522= BGPPAOriginatorID - Basic instantiation 523raw(BGPPAOriginatorID()) == b'\x00\x00\x00\x00' 524 525= BGPPAOriginatorID - Instantiation with specific value 526raw(BGPPAOriginatorID(originator_id = '192.0.2.1')) == b'\xc0\x00\x02\x01' 527 528= BGPPAOriginatorID - Dissection 529a = BGPPAOriginatorID(b'\xc0\x00\x02\x01') 530a.originator_id == "192.0.2.1" 531 532 533############################ BGPPAClusterList ################################ 534+ BGPPAClusterList class tests 535 536= BGPPAClusterList - Basic instantiation 537raw(BGPPAClusterList()) == b'' 538 539= BGPPAClusterList - Instantiation with specific values 540raw(BGPPAClusterList(cluster_list = [150000, 165465465, 132132])) == b'\x00\x02I\xf0\t\xdc\xcdy\x00\x02\x04$' 541 542= BGPPAClusterList - Dissection 543a = BGPPAClusterList(b'\x00\x02I\xf0\t\xdc\xcdy\x00\x02\x04$') 544a.cluster_list[0] == 150000 and a.cluster_list[1] == 165465465 and a.cluster_list[2] == 132132 545 546 547########################### BGPPAMPReachNLRI ############################### 548+ BGPPAMPReachNLRI class tests 549 550= BGPPAMPReachNLRI - Instantiation 551raw(BGPPAMPReachNLRI()) == b'\x00\x00\x00\x00\x00' 552 553= BGPPAMPReachNLRI - Instantiation with specific values (1) 554raw(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' 555 556= BGPPAMPReachNLRI - Dissection (1) 557a = 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') 558a.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" 559 560= BGPPAMPReachNLRI - Dissection (2) 561a = 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') 562a.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" 563 564 565############################# BGPPAMPUnreachNLRI ############################# 566+ BGPPAMPUnreachNLRI class tests 567 568= BGPPAMPUnreachNLRI - Instantiation 569raw(BGPPAMPUnreachNLRI()) == b'\x00\x00\x00' 570 571= BGPPAMPUnreachNLRI - Instantiation with specific values (1) 572raw(BGPPAMPUnreachNLRI(afi = 2, safi = 1)) == b'\x00\x02\x01' 573 574= BGPPAMPUnreachNLRI - Instantiation with specific values (2) 575raw(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' 576 577= BGPPAMPUnreachNLRI - Dissection (1) 578a = BGPPAMPUnreachNLRI(b'\x00\x02\x01') 579a.afi == 2 and a.safi == 1 580 581= BGPPAMPUnreachNLRI - Dissection (2) 582a = 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') 583a.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" 584 585 586############################# BGPPAAS4Aggregator ############################# 587+ BGPPAAS4Aggregator class tests 588 589= BGPPAAS4Aggregator - Instantiation 590raw(BGPPAAS4Aggregator()) == b'\x00\x00\x00\x00\x00\x00\x00\x00' 591 592= BGPPAAS4Aggregator - Instantiation with specific values 593raw(BGPPAAS4Aggregator(aggregator_asn = 644566565, speaker_address = "192.0.2.1")) == b'&kN%\xc0\x00\x02\x01' 594 595= BGPPAAS4Aggregator - Dissection 596a = BGPPAAS4Aggregator(b'&kN%\xc0\x00\x02\x01') 597a.aggregator_asn == 644566565 and a.speaker_address == "192.0.2.1" 598 599 600############################# BGPPALargeCommunity ############################ 601+ BGPPALargeCommunity class tests 602 603= BGPPALargeCommunity - Instantiation 604raw(BGPPALargeCommunity()) == b'' 605 606= BGPPALargeCommunity - Instantiation with specific values 607raw(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' 608 609= BGPPALargeCommunity - Dissection 610a = BGPPALargeCommunity(b'\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00') 611a.segments[0].global_administrator == 161 and a.segments[0].local_data_part1 == 0 and a.segments[0].local_data_part2 == 0 612 613 614################################ BGPPathAttr ################################# 615+ BGPPathAttr class tests 616 617= BGPPathAttr - Instantiation 618raw(BGPPathAttr()) == b'\x80\x00\x00' 619 620= BGPPathAttr - Instantiation with specific values (1) 621raw(BGPPathAttr(type_code = 1, attribute = BGPPAOrigin(origin = 0))) 622 623= BGPPathAttr - Instantiation with specific values (2) 624raw(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' 625 626= BGPPathAttr - Instantiation with specific values (3) 627 628raw(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' 629 630= BGPPathAttr - Dissection (1) 631a = 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') 632a.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" 633 634= BGPPathAttr - advanced 635b = BGPPathAttr(type_code=0x10, attribute=BGPPAExtComms(extended_communities=[ 636 BGPPAExtCommunity(value=BGPPAExtCommTwoOctetASSpecific()), 637 BGPPAExtCommunity(value=BGPPAExtCommIPv4AddressSpecific()), 638 BGPPAExtCommunity(value=BGPPAExtCommFourOctetASSpecific()), 639 BGPPAExtCommunity(value=BGPPAExtCommOpaque()), 640 BGPPAExtCommunity(value=BGPPAExtCommTrafficMarking()), 641 BGPPAExtCommunity(value=BGPPAExtCommRedirectIPv4()), 642 BGPPAExtCommunity(value=BGPPAExtCommRedirectAS4Byte()), 643 ])) 644b = BGPPathAttr(raw(b)) 645cls_list = [x.value.__class__ for x in b.attribute.extended_communities] 646assert cls_list == [BGPPAExtCommTwoOctetASSpecific, BGPPAExtCommIPv4AddressSpecific, BGPPAExtCommFourOctetASSpecific, BGPPAExtCommOpaque, 647 BGPPAExtCommTrafficMarking, BGPPAExtCommRedirectIPv4, BGPPAExtCommRedirectAS4Byte] 648b.show() 649 650################################# BGPUpdate ################################## 651+ BGPUpdate class tests 652 653= BGPUpdate - Instantiation 654raw(BGPUpdate()) == b'\x00\x00\x00\x00' 655 656= BGPUpdate - Dissection (1) 657bgp_module_conf.use_2_bytes_asn = True 658m = 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') 659assert BGPHeader in m and BGPUpdate in m 660assert m.withdrawn_routes_len == 25 661assert m.withdrawn_routes[0].prefix == "192.168.150.0/24" 662assert m.withdrawn_routes[5].prefix == "192.168.26.0/24" 663assert m.path_attr_len == 0 664 665= BGPUpdate - Behave like a NEW speaker (RFC 6793) - Dissection (2) 666bgp_module_conf.use_2_bytes_asn = False 667m = 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') 668assert BGPHeader in m and BGPUpdate in m 669assert m.path_attr[1].attribute.segments[0].segment_value == [64506] 670assert m.path_attr[4].attribute.community == 0xFFFFFF01 671assert m.nlri[0].prefix == "192.168.1.0/24" 672 673 674 675= BGPUpdate - Dissection (MP_REACH_NLRI) 676m = 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') 677assert BGPHeader in m and BGPUpdate in m 678assert m.path_attr[2].attribute.afi == 2 679assert m.path_attr[2].attribute.safi == 1 680assert m.path_attr[2].attribute.nh_addr_len == 32 681assert m.path_attr[2].attribute.nh_v6_global == "fe80::fac0:100:15de:1581" 682assert m.path_attr[2].attribute.nh_v6_link_local == "fe80::fac0:100:15de:1581" 683assert m.path_attr[2].attribute.nlri[0].prefix == "400::/6" 684assert m.nlri == [] 685 686= BGPUpdate - Dissection (MP_UNREACH_NLRI) 687m = 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') 688assert BGPHeader in m and BGPUpdate in m 689assert m.path_attr[0].attribute.afi == 2 690assert m.path_attr[0].attribute.safi == 1 691assert m.path_attr[0].attribute.afi_safi_specific.withdrawn_routes[0].prefix == "6000::/3" 692assert m.nlri == [] 693 694= BGPUpdate - Dissection (with BGP Additional Path) 695m = 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') 696assert m.withdrawn_routes[0].nlri_path_id == 2 697assert len(m.withdrawn_routes) == 21 698assert m.withdrawn_routes[-1].sprintf("%prefix%") == "10.233.25.132/32" 699assert len(m.getlayer(BGPUpdate, 2).path_attr) == 4 700assert m.getlayer(BGPUpdate, 2).nlri[0].nlri_path_id == 2 701assert m.getlayer(BGPUpdate, 2).nlri[0].sprintf("%prefix%") == "10.233.0.22/32" 702 703= BGPUpdate - with BGPHeader 704p = BGP(raw(BGPHeader()/BGPUpdate())) 705assert BGPHeader in p and BGPUpdate in p 706 707 708########## BGPNotification Class ################################### 709+ BGPNotification class tests 710 711= BGPNotification - Instantiation 712raw(BGPNotification()) == b'\x00\x00' 713 714= BGPNotification - Dissection (Administratively Reset) 715m = BGP(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x15\x03\x06\x04') 716m.type == BGP.NOTIFICATION_TYPE and m.error_code == 6 and m.error_subcode == 4 717 718= BGPNotification - Dissection (Bad Peer AS) 719m = 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') 720m.type == BGP.NOTIFICATION_TYPE and m.error_code == 2 and m.error_subcode == 2 721 722= BGPNotification - Dissection (Attribute Flags Error) 723m = 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') 724m.type == BGP.NOTIFICATION_TYPE and m.error_code == 3 and m.error_subcode == 4 725 726 727########## BGPRouteRefresh Class ################################### 728+ BGPRouteRefresh class tests 729 730= BGPRouteRefresh - Instantiation 731raw(BGPRouteRefresh()) == b'\x00\x01\x00\x01' 732 733= BGPRouteRefresh - Instantiation with specific values 734raw(BGPRouteRefresh(afi = 1, safi = 1)) == b'\x00\x01\x00\x01' 735 736= BGPRouteRefresh - Dissection (1) 737m = 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') 738m.type == BGP.ROUTEREFRESH_TYPE and m.len == 23 and m.afi == 2 and m.subtype == 0 and m.safi == 1 739 740 741= BGPRouteRefresh - Dissection (2) - With ORFs 742m = 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') 743assert m.type == BGP.ROUTEREFRESH_TYPE 744assert m.len == 46 745assert m.afi == 1 746assert m.subtype == 0 747assert m.safi == 1 748assert m.orf_data[0].when_to_refresh == 1 749assert m.orf_data[0].orf_type == 128 750assert m.orf_data[0].orf_len == 19 751assert len(m.orf_data[0].entries) == 2 752assert m.orf_data[0].entries[0].action == 0 753assert m.orf_data[0].entries[0].match == 1 754assert m.orf_data[0].entries[0].prefix.prefix == "1.1.0.0/21" 755assert m.orf_data[0].entries[1].action == 0 756assert m.orf_data[0].entries[1].match == 0 757assert m.orf_data[0].entries[1].prefix.prefix == "0.0.0.0/0" 758 759= BGPRouteRefresh - Dissection (3) - bad ORFS (GH3345) 760m = BGPRouteRefresh(b'\x00\x01\x00\x01\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00') 761assert m.orf_data.orf_type == 0 762assert m.orf_data.entries[0].load == b'\x00\x00\x00\x00\x00\x00\x00' 763 764########## BGPCapGeneric fuzz() ################################### 765+ BGPCapGeneric fuzz() 766 767= BGPCapGeneric fuzz() 768for i in range(10): 769 assert isinstance(raw(fuzz(BGPCapGeneric())), bytes) 770