def test_port_order(self): """Test port order extension & port order option""" port_order = [3, 2, 1, 0] extended = FaucetFakeOFTopoGenerator.extend_port_order(port_order, max_length=8) self.assertEqual(extended, [3, 2, 1, 0, 7, 6, 5, 4]) port_order = [1, 2, 3, 4, 0] extended = FaucetFakeOFTopoGenerator.extend_port_order(port_order, max_length=10) self.assertEqual(extended, [1, 2, 3, 4, 0, 6, 7, 8, 9, 5]) host_links = {0: [0], 1: [1]} host_vlans = {0: 0, 1: 0} switch_links = [(0, 1)] link_vlans = {(0, 1): [0]} port_order = [3, 2, 1, 0] expected_ports = [self.START_PORT + port for port in port_order] topo = FaucetFakeOFTopoGenerator('', '', '', 2, False, host_links, host_vlans, switch_links, link_vlans, start_port=self.START_PORT, port_order=port_order, get_serialno=self.get_serialno) s1_name = topo.switches_by_id[0] s1_ports = list(topo.ports[s1_name].keys()) self.assertEqual(s1_ports, expected_ports[:2]) s2_name = topo.switches_by_id[1] s2_ports = list(topo.ports[s2_name].keys()) self.assertEqual(s2_ports, expected_ports[:2])
def test_link_port_map(self): """Test correctly generated link port map""" host_links = {0: [0], 1: [1]} host_vlans = {0: 0, 1: 0} switch_links = [(0, 1), (0, 1), (1, 2)] link_vlans = {edge: None for edge in switch_links} topo = FaucetFakeOFTopoGenerator('', '', '', 2, False, host_links, host_vlans, switch_links, link_vlans, start_port=self.START_PORT, port_order=self.PORT_ORDER, get_serialno=self.get_serialno) link_port_maps = topo._create_link_port_map() # pylint: disable=protected-access self.assertEqual(link_port_maps, { (0, 1): [5, 6], (1, 0): [5, 6], (1, 2): [7], (2, 1): [5] })
def test_host_options(self): """Test the topology correctly provides mininet host options""" host_options = { 0: { 'inNamespace': True, 'ip': '127.0.0.1' }, 1: { 'cls': self.FakeExtendedHost } } host_links = {0: [0], 1: [0]} host_vlans = {0: 0, 1: None} switch_links = [] link_vlans = {} topo = FaucetFakeOFTopoGenerator('', '', '', 2, False, host_links, host_vlans, switch_links, link_vlans, host_options=host_options, start_port=self.START_PORT, port_order=self.PORT_ORDER, get_serialno=self.get_serialno) for host_id, opts in host_options.items(): info = topo.nodeInfo(topo.hosts_by_id[host_id]) for key, value in opts.items(): self.assertIn(key, info) self.assertEqual(value, info[key])
def test_build(self): """Test the topology is built correctly""" host_links = {0: [0], 1: [1]} host_vlans = {0: 0, 1: [0, 1]} switch_links = [(0, 1), (0, 1), (0, 1)] link_vlans = {(0, 1): [0, 1]} topo = FaucetFakeOFTopoGenerator('', '', '', 2, False, host_links, host_vlans, switch_links, link_vlans, start_port=self.START_PORT, port_order=self.PORT_ORDER, get_serialno=self.get_serialno) self.assertEqual(len(topo.dpids_by_id), 2) self.assertEqual(len(topo.hosts_by_id), 2) self.assertEqual(len(topo.switches_by_id), 2) _, host_port_maps, link_port_maps = topo.create_port_maps() self.assertEqual(len(link_port_maps[(0, 1)]), 3) self.assertEqual(len(host_port_maps[0]), 1) self.assertEqual(len(host_port_maps[1]), 1) host0, host1 = topo.hosts_by_id.values() dp0, dp1 = topo.switches_by_id.values() links = topo.links() self.assertIn((dp0, host0), links) self.assertIn((dp1, host1), links) self.assertIn((dp0, dp1), links) self.assertEqual(links.count((dp0, dp1)), 3)
def test_host_port_map(self): """Test correctly generated host port map""" host_links = {0: [0, 2], 1: [1]} host_vlans = {0: 0, 1: 0} switch_links = [(0, 1), (0, 1), (1, 2)] link_vlans = {edge: None for edge in switch_links} topo = FaucetFakeOFTopoGenerator( '', '', '', 2, False, host_links, host_vlans, switch_links, link_vlans, start_port=self.START_PORT, port_order=self.PORT_ORDER, get_serialno=self.get_serialno) host_port_maps = topo._create_host_port_map() self.assertEqual( host_port_maps, {0: {0: [7], 2: [6]}, 1: {1: [8]}})
def test_hw_build(self): """Test the topology is built with hardware requirements""" host_links = {0: [0], 1: [1]} host_vlans = {0: 0, 1: 0} switch_links = [(0, 1)] link_vlans = {(0, 1): [0]} hw_dpid = 0x123 hw_ports = {1: 'p1', 2: 'p2', 3: 'p3', 4: 'p4', 5: 'p5', 6: 'p6'} topo = FaucetFakeOFTopoGenerator('', '', '', 2, False, host_links, host_vlans, switch_links, link_vlans, hw_dpid=hw_dpid, hw_ports=hw_ports, start_port=self.START_PORT, port_order=self.PORT_ORDER, get_serialno=self.get_serialno) self.assertEqual(topo.dpids_by_id[0], hw_dpid) self.assertEqual(list(topo.ports[topo.switches_by_id[0]].keys()), [1, 2])
def test_start_port(self): """Test the topology start port parameter option""" start_port = 55 host_links = {0: [0], 1: [1]} host_vlans = {0: 0, 1: 0} switch_links = [(0, 1)] link_vlans = {(0, 1): [0]} port_order = [3, 2, 1, 0] expected_ports = [start_port + port for port in port_order] topo = FaucetFakeOFTopoGenerator('', '', '', 2, False, host_links, host_vlans, switch_links, link_vlans, start_port=start_port, port_order=port_order, get_serialno=self.get_serialno) s1_name, s2_name = topo.switches_by_id.values() h1_name, h2_name = topo.hosts_by_id.values() self.assertEqual(topo.ports[s1_name][expected_ports[0]][0], s2_name) self.assertEqual(topo.ports[s2_name][expected_ports[0]][0], s1_name) self.assertEqual(topo.ports[s1_name][expected_ports[1]][0], h1_name) self.assertEqual(topo.ports[s2_name][expected_ports[1]][0], h2_name)
def create_topo_config(self, network_graph): """Return topo object and a simple stack config generated from network_graph""" host_links = {} host_vlans = {} dp_options = {} host_n = 0 for dp_i in network_graph.nodes(): for _ in range(self.NUM_HOSTS): a_vlans = random.randint(0, self.NUM_VLANS - 1) b_vlans = random.randint(0, self.NUM_VLANS - 1) min_vlans = min(a_vlans, b_vlans) max_vlans = max(a_vlans, b_vlans) is_tagged = random.choice([True, False]) if is_tagged: if min_vlans != max_vlans: vlans = list(range(min_vlans, max_vlans)) else: vlans = [min_vlans] host_links[host_n] = [dp_i] host_vlans[host_n] = vlans host_n += 1 else: for v_i in range(min_vlans, max_vlans): host_links[host_n] = [dp_i] host_vlans[host_n] = v_i host_n += 1 dp_options[dp_i] = {'hardware': 'GenericTFM'} if dp_i == 0: dp_options[dp_i]['stack'] = {'priority': 1} switch_links = list( network_graph.edges()) * self.SWITCH_TO_SWITCH_LINKS link_vlans = {link: None for link in switch_links} topo = FaucetFakeOFTopoGenerator('ovstype', 'portsock', 'testname', self.NUM_DPS, False, host_links, host_vlans, switch_links, link_vlans, start_port=self.START_PORT, port_order=self.PORT_ORDER, get_serialno=self.get_serialno) config = topo.get_config(self.NUM_VLANS, dp_options=dp_options) return topo, config
def create_config(network_graph, stack=True): """Return topo object and a simple stack config generated from network_graph""" host_links = {} host_vlans = {} dp_options = {} host_n = 0 for dp_i in network_graph.nodes(): for _ in range(num_hosts): for v_i in range(num_vlans): host_links[host_n] = [dp_i] host_vlans[host_n] = v_i host_n += 1 dp_options[dp_i] = {'hardware': 'GenericTFM'} if dp_i == 0 and stack: dp_options[dp_i]['stack'] = {'priority': 1} switch_links = list(network_graph.edges()) * 2 if stack: link_vlans = {link: None for link in switch_links} else: link_vlans = { link: list(range(num_vlans)) for link in switch_links } topo = FaucetFakeOFTopoGenerator('ovstype', 'portsock', 'testname', len(network_graph.nodes()), False, host_links, host_vlans, switch_links, link_vlans, start_port=1, port_order=[0, 1, 2, 3], get_serialno=get_serialno) config = topo.get_config(num_vlans, dp_options=dp_options) return config
def test_no_links(self): """Test single switch topology""" host_links = {0: [0]} host_vlans = {0: 0} switch_links = {} link_vlans = {} topo = FaucetFakeOFTopoGenerator( '', '', '', 2, False, host_links, host_vlans, switch_links, link_vlans, start_port=self.START_PORT, port_order=self.PORT_ORDER, get_serialno=self.get_serialno) self.assertEqual(len(topo.hosts()), 1) self.assertEqual(len(topo.switches()), 1) self.assertEqual(len(topo.links()), 1) host_name = topo.hosts_by_id[0] switch_name = topo.switches_by_id[0] self.assertEqual((switch_name, host_name), topo.links()[0])