Example #1
0
 def test_update2(self):
     withdrawn_routes = [bgp.BGPWithdrawnRoute(length=0,
                                               addr='192.0.2.13'),
                         bgp.BGPWithdrawnRoute(length=1,
                                               addr='192.0.2.13'),
                         bgp.BGPWithdrawnRoute(length=3,
                                               addr='192.0.2.13'),
                         bgp.BGPWithdrawnRoute(length=7,
                                               addr='192.0.2.13'),
                         bgp.BGPWithdrawnRoute(length=32,
                                               addr='192.0.2.13')]
     mp_nlri = [
         bgp._BinAddrPrefix(32, 'efgh\0\0'),
         bgp._BinAddrPrefix(16, 'ij\0\0\0\0'),
     ]
     communities = [
         bgp.BGP_COMMUNITY_NO_EXPORT,
         bgp.BGP_COMMUNITY_NO_ADVERTISE,
     ]
     path_attributes = [
         bgp.BGPPathAttributeOrigin(value=1),
         bgp.BGPPathAttributeAsPath(value=[[1000], set([1001, 1002]),
                                           [1003, 1004]]),
         bgp.BGPPathAttributeNextHop(value='192.0.2.199'),
         bgp.BGPPathAttributeMultiExitDisc(value=2000000000),
         bgp.BGPPathAttributeLocalPref(value=1000000000),
         bgp.BGPPathAttributeAtomicAggregate(),
         bgp.BGPPathAttributeAggregator(as_number=40000,
                                        addr='192.0.2.99'),
         bgp.BGPPathAttributeCommunities(communities=communities),
         bgp.BGPPathAttributeAs4Path(value=[[1000000], set([1000001, 1002]),
                                            [1003, 1000004]]),
         bgp.BGPPathAttributeAs4Aggregator(as_number=100040000,
                                           addr='192.0.2.99'),
         bgp.BGPPathAttributeMpReachNLRI(afi=afi.IP, safi=safi.MPLS_VPN,
                                         next_hop='abcd',
                                         nlri=mp_nlri),
         bgp.BGPPathAttributeMpUnreachNLRI(afi=afi.IP, safi=safi.MPLS_VPN,
                                           withdrawn_routes=mp_nlri),
         bgp.BGPPathAttributeUnknown(flags=0, type_=100, value=300*'bar')
     ]
     nlri = [
         bgp.BGPNLRI(length=24, addr='203.0.113.1'),
         bgp.BGPNLRI(length=16, addr='203.0.113.0')
     ]
     msg = bgp.BGPUpdate(withdrawn_routes=withdrawn_routes,
                         path_attributes=path_attributes,
                         nlri=nlri)
     binmsg = msg.serialize()
     msg2, rest = bgp.BGPMessage.parser(binmsg)
     eq_(str(msg), str(msg2))
     ok_(len(msg) > 23)
     eq_(rest, '')
Example #2
0
 def test_update2(self):
     withdrawn_routes = [
         bgp.BGPWithdrawnRoute(length=0, addr='192.0.2.13'),
         bgp.BGPWithdrawnRoute(length=1, addr='192.0.2.13'),
         bgp.BGPWithdrawnRoute(length=3, addr='192.0.2.13'),
         bgp.BGPWithdrawnRoute(length=7, addr='192.0.2.13'),
         bgp.BGPWithdrawnRoute(length=32, addr='192.0.2.13')
     ]
     mp_nlri = [
         bgp._BinAddrPrefix(32, 'efgh\0\0'),
         bgp._BinAddrPrefix(16, 'ij\0\0\0\0'),
     ]
     communities = [
         bgp.BGP_COMMUNITY_NO_EXPORT,
         bgp.BGP_COMMUNITY_NO_ADVERTISE,
     ]
     path_attributes = [
         bgp.BGPPathAttributeOrigin(value=1),
         bgp.BGPPathAttributeAsPath(
             value=[[1000], set([1001, 1002]), [1003, 1004]]),
         bgp.BGPPathAttributeNextHop(value='192.0.2.199'),
         bgp.BGPPathAttributeMultiExitDisc(value=2000000000),
         bgp.BGPPathAttributeLocalPref(value=1000000000),
         bgp.BGPPathAttributeAtomicAggregate(),
         bgp.BGPPathAttributeAggregator(as_number=40000, addr='192.0.2.99'),
         bgp.BGPPathAttributeCommunities(communities=communities),
         bgp.BGPPathAttributeAs4Path(
             value=[[1000000],
                    set([1000001, 1002]), [1003, 1000004]]),
         bgp.BGPPathAttributeAs4Aggregator(as_number=100040000,
                                           addr='192.0.2.99'),
         bgp.BGPPathAttributeMpReachNLRI(afi=afi.IP,
                                         safi=safi.MPLS_VPN,
                                         next_hop='abcd',
                                         nlri=mp_nlri),
         bgp.BGPPathAttributeMpUnreachNLRI(afi=afi.IP,
                                           safi=safi.MPLS_VPN,
                                           withdrawn_routes=mp_nlri),
         bgp.BGPPathAttributeUnknown(flags=0, type_=100, value=300 * 'bar')
     ]
     nlri = [
         bgp.BGPNLRI(length=24, addr='203.0.113.1'),
         bgp.BGPNLRI(length=16, addr='203.0.113.0')
     ]
     msg = bgp.BGPUpdate(withdrawn_routes=withdrawn_routes,
                         path_attributes=path_attributes,
                         nlri=nlri)
     binmsg = msg.serialize()
     msg2, rest = bgp.BGPMessage.parser(binmsg)
     eq_(str(msg), str(msg2))
     ok_(len(msg) > 23)
     eq_(rest, '')
Example #3
0
 def test_json2(self):
     withdrawn_routes = [bgp.BGPWithdrawnRoute(length=0,
                                               addr='192.0.2.13'),
                         bgp.BGPWithdrawnRoute(length=1,
                                               addr='192.0.2.13'),
                         bgp.BGPWithdrawnRoute(length=3,
                                               addr='192.0.2.13'),
                         bgp.BGPWithdrawnRoute(length=7,
                                               addr='192.0.2.13'),
                         bgp.BGPWithdrawnRoute(length=32,
                                               addr='192.0.2.13')]
     mp_nlri = [
         bgp._BinAddrPrefix(32, 'efgh\0\0'),
         bgp._BinAddrPrefix(16, 'ij\0\0\0\0'),
     ]
     communities = [
         bgp.BGP_COMMUNITY_NO_EXPORT,
         bgp.BGP_COMMUNITY_NO_ADVERTISE,
     ]
     ecommunities = [
         bgp.BGPTwoOctetAsSpecificExtendedCommunity(subtype=1,
                                                    as_number=65500,
                                                    local_administrator=
                                                    3908876543),
         bgp.BGPFourOctetAsSpecificExtendedCommunity(subtype=2,
                                                     as_number=10000000,
                                                     local_administrator=
                                                     59876),
         bgp.BGPIPv4AddressSpecificExtendedCommunity(subtype=3,
                                                     ipv4_address=
                                                     '192.0.2.1',
                                                     local_administrator=
                                                     65432),
         bgp.BGPOpaqueExtendedCommunity(opaque='abcdefg'),
         bgp.BGPUnknownExtendedCommunity(type_=99, value='abcdefg'),
     ]
     path_attributes = [
         bgp.BGPPathAttributeOrigin(value=1),
         bgp.BGPPathAttributeAsPath(value=[[1000], set([1001, 1002]),
                                           [1003, 1004]]),
         bgp.BGPPathAttributeNextHop(value='192.0.2.199'),
         bgp.BGPPathAttributeMultiExitDisc(value=2000000000),
         bgp.BGPPathAttributeLocalPref(value=1000000000),
         bgp.BGPPathAttributeAtomicAggregate(),
         bgp.BGPPathAttributeAggregator(as_number=40000,
                                        addr='192.0.2.99'),
         bgp.BGPPathAttributeCommunities(communities=communities),
         bgp.BGPPathAttributeExtendedCommunities(communities=ecommunities),
         bgp.BGPPathAttributeAs4Path(value=[[1000000], set([1000001, 1002]),
                                            [1003, 1000004]]),
         bgp.BGPPathAttributeAs4Aggregator(as_number=100040000,
                                           addr='192.0.2.99'),
         bgp.BGPPathAttributeMpReachNLRI(afi=afi.IP, safi=safi.MPLS_VPN,
                                         next_hop='abcd',
                                         nlri=mp_nlri),
         bgp.BGPPathAttributeMpUnreachNLRI(afi=afi.IP, safi=safi.MPLS_VPN,
                                           withdrawn_routes=mp_nlri),
         bgp.BGPPathAttributeUnknown(flags=0, type_=100, value=300*'bar')
     ]
     nlri = [
         bgp.BGPNLRI(length=24, addr='203.0.113.1'),
         bgp.BGPNLRI(length=16, addr='203.0.113.0')
     ]
     msg1 = bgp.BGPUpdate(withdrawn_routes=withdrawn_routes,
                          path_attributes=path_attributes,
                          nlri=nlri)
     jsondict = msg1.to_jsondict()
     msg2 = bgp.BGPUpdate.from_jsondict(jsondict['BGPUpdate'])
     eq_(str(msg1), str(msg2))