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