def _test_extract_and_reconstruct_as_path(
            self, path_attributes, ex_as_path_value,
            ex_aggregator_as_number, ex_aggregator_addr):
        # Prepare test data
        update_msg = bgp.BGPUpdate(path_attributes=path_attributes)
        _peer = peer.Peer(None, None, None, None, None)

        # Test
        _peer._extract_and_reconstruct_as_path(update_msg)

        umsg_pattrs = update_msg.pathattr_map
        as_path_attr = umsg_pattrs.get(
            bgp.BGP_ATTR_TYPE_AS_PATH, None)
        as4_path_attr = umsg_pattrs.get(
            bgp.BGP_ATTR_TYPE_AS4_PATH, None)
        aggregator_attr = umsg_pattrs.get(
            bgp.BGP_ATTR_TYPE_AGGREGATOR, None)
        as4_aggregator_attr = umsg_pattrs.get(
            bgp.BGP_ATTR_TYPE_AS4_AGGREGATOR, None)

        eq_(ex_as_path_value, as_path_attr.value)
        eq_(None, as4_path_attr)
        eq_(ex_aggregator_as_number, aggregator_attr.as_number)
        eq_(ex_aggregator_addr, aggregator_attr.addr)
        eq_(None, as4_aggregator_attr)
Esempio n. 2
0
 def test_update1(self):
     msg = bgp.BGPUpdate()
     binmsg = msg.serialize()
     msg2, rest = bgp.BGPMessage.parser(binmsg)
     eq_(str(msg), str(msg2))
     eq_(len(msg), 23)
     eq_(rest, '')
Esempio n. 3
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, '')
Esempio n. 4
0
 def test_route_monitoring(self):
     update = bgp.BGPUpdate()
     msg = bmp.BMPRouteMonitoring(bgp_update=update,
                                  peer_type=bmp.BMP_PEER_TYPE_GLOBAL,
                                  is_post_policy=True,
                                  peer_distinguisher=0,
                                  peer_address='192.0.2.1',
                                  peer_as=30000,
                                  peer_bgp_id='192.0.2.1',
                                  timestamp=self._time())
     binmsg = msg.serialize()
     msg2, rest = bmp.BMPMessage.parser(binmsg)
     eq_(msg.to_jsondict(), msg2.to_jsondict())
     eq_(rest, b'')
 def create_non_best_packet(self, mac_dst, mac_src, ip_dst, ip_src,
                            idNonBest, best):
     _eth = ethernet.ethernet(dst=mac_dst,
                              src=mac_src,
                              ethertype=ether.ETH_TYPE_IP)
     _ip = ipv4.ipv4(identification=1111,
                     flags=2,
                     ttl=64,
                     proto=6,
                     src=ip_src,
                     dst=ip_dst)
     _tcp = tcp.tcp(dst_port=179)
     _nlri = []
     _nlri.append(self.bgp_nlri)
     _pattrs = self.create_path_attr_bgp(idNonBest=idNonBest, best=best)
     _bgp = bgp.BGPUpdate(path_attributes=_pattrs, nlri=_nlri)
     p = packet.Packet()
     p.add_protocol(_eth)
     p.add_protocol(_ip)
     p.add_protocol(_tcp)
     p.add_protocol(_bgp)
     p.serialize()
     return p
Esempio n. 6
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.LabelledVPNIPAddrPrefix(24,
                                     '192.0.9.0',
                                     route_dist='100:100',
                                     labels=[1, 2, 3]),
         bgp.LabelledVPNIPAddrPrefix(26,
                                     '192.0.10.192',
                                     route_dist='10.0.0.1:10000',
                                     labels=[5, 6, 7, 8]),
     ]
     mp_nlri2 = [
         bgp.LabelledIPAddrPrefix(24, '192.168.0.0', labels=[1, 2, 3])
     ]
     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.BGPPathAttributeOriginatorId(value='10.1.1.1'),
         bgp.BGPPathAttributeClusterList(value=['1.1.1.1', '2.2.2.2']),
         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='1.1.1.1',
                                         nlri=mp_nlri),
         bgp.BGPPathAttributeMpReachNLRI(afi=afi.IP,
                                         safi=safi.MPLS_LABEL,
                                         next_hop='1.1.1.1',
                                         nlri=mp_nlri2),
         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, '')
 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.LabelledVPNIPAddrPrefix(24, '192.0.9.0',
                                     route_dist='100:100',
                                     labels=[1, 2, 3]),
         bgp.LabelledVPNIPAddrPrefix(26, '192.0.10.192',
                                     route_dist='10.0.0.1:10000',
                                     labels=[5, 6, 7, 8]),
     ]
     mp_nlri2 = [
         bgp.LabelledIPAddrPrefix(24, '192.168.0.0', labels=[1, 2, 3])
     ]
     mp_nlri_v6 = [
         bgp.LabelledVPNIP6AddrPrefix(64, '2001:db8:1111::',
                                      route_dist='200:200',
                                      labels=[1, 2, 3]),
         bgp.LabelledVPNIP6AddrPrefix(64, '2001:db8:2222::',
                                      route_dist='10.0.0.1:10000',
                                      labels=[5, 6, 7, 8]),
     ]
     mp_nlri2_v6 = [
         bgp.LabelledIP6AddrPrefix(64, '2001:db8:3333::', labels=[1, 2, 3])
     ]
     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(subtype=13, opaque=b'abcdef'),
         bgp.BGPEncapsulationExtendedCommunity(
             subtype=0x0c, tunnel_type=10),
         bgp.BGPEvpnMacMobilityExtendedCommunity(
             subtype=0, flags=0xff, sequence_number=0x11223344),
         bgp.BGPEvpnEsiLabelExtendedCommunity(
             subtype=1, flags=0xff, label=b'\xFF\xFF\xFF'),
         bgp.BGPEvpnEsiLabelExtendedCommunity(
             subtype=1, flags=0xff, mpls_label=0xfffff),
         bgp.BGPEvpnEsiLabelExtendedCommunity(
             subtype=1, flags=0xff, vni=0xffffff),
         bgp.BGPEvpnEsImportRTExtendedCommunity(
             subtype=2, es_import="aa:bb:cc:dd:ee:ff"),
         bgp.BGPUnknownExtendedCommunity(type_=99, value=b'abcdefg'),
     ]
     path_attributes = [
         bgp.BGPPathAttributeOrigin(value=1),
         bgp.BGPPathAttributeAsPath(value=[[1000], {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.BGPPathAttributePmsiTunnel(
             pmsi_flags=1,
             tunnel_type=PMSI_TYPE_NO_TUNNEL_INFORMATION_PRESENT,
             label=b'\xFF\xFF\xFF'),
         bgp.BGPPathAttributePmsiTunnel(
             pmsi_flags=1,
             tunnel_type=PMSI_TYPE_NO_TUNNEL_INFORMATION_PRESENT,
             tunnel_id=None),
         bgp.BGPPathAttributePmsiTunnel(
             pmsi_flags=1,
             tunnel_type=PMSI_TYPE_INGRESS_REPLICATION,
             mpls_label=0xfffff,
             tunnel_id=bgp.PmsiTunnelIdIngressReplication(
                 tunnel_endpoint_ip="1.1.1.1")),
         bgp.BGPPathAttributePmsiTunnel(
             pmsi_flags=1,
             tunnel_type=PMSI_TYPE_INGRESS_REPLICATION,
             vni=0xffffff,
             tunnel_id=bgp.PmsiTunnelIdIngressReplication(
                 tunnel_endpoint_ip="aa:bb:cc::dd:ee:ff")),
         bgp.BGPPathAttributePmsiTunnel(
             pmsi_flags=1,
             tunnel_type=2,
             label=b'\xFF\xFF\xFF',
             tunnel_id=bgp.PmsiTunnelIdUnknown(value=b'test')),
         bgp.BGPPathAttributeAs4Path(value=[[1000000], {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='1.1.1.1',
                                         nlri=mp_nlri),
         bgp.BGPPathAttributeMpReachNLRI(afi=afi.IP, safi=safi.MPLS_LABEL,
                                         next_hop='1.1.1.1',
                                         nlri=mp_nlri2),
         bgp.BGPPathAttributeMpReachNLRI(afi=afi.IP6, safi=safi.MPLS_VPN,
                                         next_hop=['2001:db8::1'],
                                         nlri=mp_nlri_v6),
         bgp.BGPPathAttributeMpReachNLRI(afi=afi.IP6, safi=safi.MPLS_LABEL,
                                         next_hop=['2001:db8::1',
                                                   'fe80::1'],
                                         nlri=mp_nlri2_v6),
         bgp.BGPPathAttributeMpUnreachNLRI(afi=afi.IP, safi=safi.MPLS_VPN,
                                           withdrawn_routes=mp_nlri),
         bgp.BGPPathAttributeUnknown(flags=0, type_=100, value=300 * b'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))
Esempio n. 8
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.LabelledVPNIPAddrPrefix(24, '192.0.9.0',
                                     route_dist=100,
                                     labels=[1, 2, 3]),
         bgp.LabelledVPNIPAddrPrefix(26, '192.0.10.192',
                                     route_dist=4000000000,
                                     labels=[5, 6, 7, 8]),
     ]
     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))