コード例 #1
0
 def _add_route_to_switch(self, host, loopback_address):
     subnet = get_subnet_from_ip_and_prefixlen(loopback_address, 64)
     dst = ip_str_to_addr(subnet)
     prefix = IpPrefix(ip=dst, prefixLength=64)
     nexthops = [ip_str_to_addr(next(host.ips()))]
     unicast_route = UnicastRoute(dest=prefix, nextHopAddrs=nexthops)
     return self._add_unicast_route(unicast_route)
コード例 #2
0
 def delete_routes(self, routes):
     uniRoutes = []
     for route in routes:
         ip, prefix = route.split("/")
         addr = utils.ip_to_binary(ip)
         uniRoutes.append(IpPrefix(ip=addr, prefixLength=prefix))
     self.client.deleteUnicastRoutes(self.client_id, uniRoutes)
コード例 #3
0
 def insert_routes(self, routes):
     uniRoutes = []
     for route in routes:
         ip, prefix = route.split("/")
         addr = utils.ip_to_binary(ip)
         ipRoute = IpPrefix(ip=addr, prefixLength=prefix)
         uniRoutes.append(UnicastRoute(dest=ipRoute, nextHopAddrs=self.nexthops))
     self.client.addUnicastRoutes(self.client_id, uniRoutes)
コード例 #4
0
    def _add_route_to_switch(self, host, loopback_address):
        subnet = get_subnet_from_ip_and_prefixlen(loopback_address, 64)
        dst = ip_str_to_addr(subnet)
        prefix = IpPrefix(ip=dst, prefixLength=64)
        nexthops = [ip_str_to_addr(next(host.ips()))]
        unicast_route = UnicastRoute(dest=prefix, nextHopAddrs=nexthops)

        with self.test_topology.switch_thrift() as client:
            client.addUnicastRoute(1, unicast_route)
        return unicast_route
コード例 #5
0
ファイル: test_l3_route.py プロジェクト: xzplink/fboss
 def test_basic_l3_route_install(self):
     # This route just needs to not ecplipse anything
     # in the test harness, e.g., the control channel
     ipRoute = IpPrefix(ip="1:2:3:4:5:6::", prefixLength=24)
     self.test_topology.min_hosts_or_skip(2)
     host1 = self.test_topology.hosts[0]
     host2 = self.test_topology.hosts[1]
     nextHops = [ip_str_to_addr(host2.ips[0])]
     route = UnicastRoute(dest=ipRoute, nextHopAddrs=nextHops)
     # Install the route
     with self.test_topology.switch_thrift as sw_client:
         sw_client.addUnicastRoute(self.client_id, route)
     target_intf = host2.intfs[0]
     beforePkt = make_packet(src_host=host1, dst_host=host2, ttl=32)
     afterPkt = make_packet(src_host=host1, dst_host=host2, ttl=31)
     # Now try the test packet
     with host2.thrift_client() as client2:
         with host1.thrift_client() as client1:
             client2.expect(target_intf, afterPkt)
             client1.sendPkt(beforePkt)
             client2.expectVerify(target_intf, afterPkt, timeout=1)
コード例 #6
0
    def test_update_route(self):
        dst = ip_str_to_addr("2804:6082:2040:97f::")
        prefix = IpPrefix(
            ip=dst,
            prefixLength=64)

        host = next(iter(self.test_topology.hosts()))
        ip = next(host.ips())
        nexthops = [ip_str_to_addr(ip)]

        unicast_route = UnicastRoute(dest=prefix, nextHopAddrs=nexthops)

        with self.test_topology.switch_thrift() as switch_client:
            fboss_routes = switch_client.getRouteTableByClient(
                self.NETLINK_MANAGER_CLIENT_ID)
            self.assertFalse(unicast_route in fboss_routes)

        with self.test_topology.netlink_manager_thrift() as netlink_client:
            response = netlink_client.addRoute(unicast_route, socket.AF_INET6)
            netlink_client._socket.close()
            self.assertEqual(response, 0)

        with self.test_topology.switch_thrift() as switch_client:
            fboss_routes = switch_client.getRouteTableByClient(
                self.NETLINK_MANAGER_CLIENT_ID)
            self.assertTrue(unicast_route in fboss_routes)

        with self.test_topology.netlink_manager_thrift() as netlink_client:
            response = netlink_client.deleteRoute(unicast_route, socket.AF_INET6)
            netlink_client._socket.close()
            self.assertEqual(response, 0)

        with self.test_topology.switch_thrift() as switch_client:
            fboss_routes = switch_client.getRouteTableByClient(
                self.NETLINK_MANAGER_CLIENT_ID)
            self.assertFalse(unicast_route in fboss_routes)
コード例 #7
0
def parse_prefix(prefix):
    network = ipaddress.ip_network(prefix)
    return IpPrefix(
        ip=BinaryAddress(addr=network.network_address.packed),
        prefixLength=network.prefixlen,
    )
コード例 #8
0
 def _get_prefix(self):
     str_test_ip = get_random_test_ipv6()
     prefixlen = 64
     str_subnet = get_subnet_from_ip_and_prefixlen(str_test_ip, prefixlen)
     binary_subnet = ip_str_to_addr(str_subnet)
     return IpPrefix(ip=binary_subnet, prefixLength=prefixlen)
コード例 #9
0
 def delete_route(self, route):
     ip, prefix = route.split("/")
     addr = utils.ip_to_binary(ip)
     ipRoute = IpPrefix(ip=addr, prefixLength=prefix)
     self.client.deleteUnicastRoute(self.client_id, ipRoute)
コード例 #10
0
 def insert_route(self, route):
     ip, prefix = route.split("/")
     addr = utils.ip_to_binary(ip)
     ipRoute = IpPrefix(ip=addr, prefixLength=prefix)
     uniRoute = UnicastRoute(dest=ipRoute, nextHopAddrs=self.nexthops)
     self.client.addUnicastRoute(self.client_id, uniRoute)
コード例 #11
0
def parse_prefix(args):
    network = ipaddr.IPNetwork(args.prefix)
    return IpPrefix(ip=BinaryAddress(addr=network.ip.packed),
                    prefixLength=network.prefixlen)