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)
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)
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
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)
def test_fboss_port_stats_cmd(self): """ Test the 'fboss port stats' command Steps: - Query in/out bytes/packets port stats for a server port. - Run iperf traffic from server (port under test) to another server. - Query in/out bytes/packets port stats for same sever port. - Stat counters should have been incremented. """ self.test_topology.min_hosts_or_skip(2) host1 = self.test_topology.hosts()[0] host2 = self.test_topology.hosts()[1] host1_ip = next(host1.ips()) host1_binary_ip = ip_str_to_addr(host1_ip) # Get Port corresponding to the server ip address port1 = self.test_topology.get_switch_port_id_from_ip(host1_binary_ip) inBytes1, inPkts1, outBytes1, outPkts1 = self._get_port_stats(port1) run_iperf(host1, host2, host1_ip) inBytes2, inPkts2, outBytes2, outPkts2 = self._get_port_stats(port1) self.assertTrue(inBytes2 > inBytes1 and inPkts2 > inPkts1 and outBytes2 > outBytes1 and outPkts2 > outPkts1)
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)
def test_server_port_flap(self): number_of_flaps = 1 # Time for fboss to detect port down/up convergence_time_allowed = 10 # We use the command ifup to bring the interface back up again and it # typically has a 20s delay. delay_time_buffer = 22 # in seconds # Run the test for all hosts in the topology. for host in self.test_topology.hosts(): self.log.info("Testing host {}".format(host.name)) # IP address on the server. host_binary_ip = ip_str_to_addr(next(host.ips())) # Interface on server. host_if = next(iter(host.intfs())) switch_port_id = None self.log.debug("Running port flap test on - {}".format(host)) switch_port_id = self.test_topology.get_switch_port_id_from_ip( host_binary_ip) with self.test_topology.switch_thrift() as sw_client: port_info = sw_client.getPortInfo(switch_port_id) self.log.debug("Check that the port is up before test start.") self.assertEqual(port_info.operState, PortOperState.UP) thread = threading.Thread(target=self.threadFlapPort, args=(host_if, number_of_flaps, convergence_time_allowed, host)) thread.start() time.sleep(5) with self.test_topology.switch_thrift() as sw_client: port_info = sw_client.getPortInfo(switch_port_id) self.assertEqual(port_info.operState, PortOperState.DOWN) time.sleep(delay_time_buffer + convergence_time_allowed) with self.test_topology.switch_thrift() as sw_client: port_info = sw_client.getPortInfo(switch_port_id) self.assertEqual(port_info.operState, PortOperState.UP)
def test_server_port_flap(self): number_of_flaps = 1 # Time for fboss to detect port down/up convergence_time_allowed = 10 # We use the command ifup to bring the interface back up again and it # typically has a 20s delay. delay_time_buffer = 22 # in seconds # Run the test for all hosts in the topology. for host in self.test_topology.hosts(): self.log.info("Testing host {}".format(host.name)) # IP address on the server. host_binary_ip = ip_str_to_addr(next(host.ips())) # Interface on server. host_if = next(iter(host.intfs())) switch_port_id = None self.log.debug("Running port flap test on - {}".format(host)) switch_port_id = self.test_topology.get_switch_port_id_from_ip( host_binary_ip) with self.test_topology.switch_thrift() as sw_client: port_info = sw_client.getPortInfo(switch_port_id) self.log.debug("Check that the port is up before test start.") self.assertEqual(port_info.operState, PortOperState.UP) thread = threading.Thread(target=self.threadFlapPort, args=(host_if, number_of_flaps, convergence_time_allowed, host)) thread.start() time.sleep(5) with self.test_topology.switch_thrift() as sw_client: port_info = sw_client.getPortInfo(switch_port_id) self.assertEqual(port_info.operState, PortOperState.DOWN) time.sleep(delay_time_buffer + convergence_time_allowed) with self.test_topology.switch_thrift() as sw_client: port_info = sw_client.getPortInfo(switch_port_id) self.assertEqual(port_info.operState, PortOperState.UP)
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)
def _get_nexthops(self): host = self.test_topology.hosts()[0] ip = next(host.ips()) return [ip_str_to_addr(ip)]
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)
def _get_nexthops(self): host = self.test_topology.hosts()[0] ip = next(host.ips()) return [ip_str_to_addr(ip)]