Esempio n. 1
0
class TopologyUnitTest(unittest.TestCase):
    _io_loop = RecocoIOLoop()
    _io_ctor = _io_loop.create_worker_for_socket

    def setUp(self):
        class MockSwitch(SoftwareSwitch):
            _eventMixin_events = set([DpPacketOut])

            def __init__(self, dpid, ports):
                self.has_forwarded = False
                self.dpid = dpid
                self.ports = {}
                for port in ports:
                    self.ports[port.port_no] = port

            def process_packet(self, packet, in_port):
                self.has_forwarded = True

        def create_mock_switch(num_ports, switch_id):
            ports = []
            for port_no in range(1, num_ports + 1):
                port = ofp_phy_port(port_no=port_no,
                                    hw_addr=EthAddr("00:00:00:00:%02x:%02x" %
                                                    (switch_id, port_no)))
                # monkey patch an IP address onto the port for anteater purposes
                port.ip_addr = "1.1.%d.%d" % (switch_id, port_no)
                ports.append(port)
            return MockSwitch(switch_id, ports)

        self.g = Graph()
        self.switches = [create_mock_switch(2, 1), create_mock_switch(2, 2)]
        self.hosts = [
            Host([HostInterface(EthAddr("00:00:00:00:00:01"))], name="host1"),
            Host([HostInterface(EthAddr("00:00:00:00:00:02"))], name="host2")
        ]
        for switch in self.switches:
            self.g.add(switch)
        for host in self.hosts:
            self.g.add(host)
        self.g.link((self.switches[0], self.switches[0].ports[2]),
                    (self.switches[1], self.switches[1].ports[2]))
        self.g.link((self.hosts[0], self.hosts[0].interfaces[0]),
                    (self.switches[0], self.switches[0].ports[1]))
        self.g.link((self.hosts[1], self.hosts[1].interfaces[0]),
                    (self.switches[1], self.switches[1].ports[1]))
        topology = Topology.populate_from_topology(self.g)
        self.patch = BufferedPatchPanelForTopology(self.g)
        self.switches_calc = topology.switches
        self.hosts_calc = topology.hosts
        self.access_links = topology.access_links

    # Line 152 is throwing an exception! See:
    # https://github.com/noxrepo/pox/issues/36 for more information.
    def xxx_marked_as_broken_generakted_topology(self):
        self.assertEqual(len(self.access_links), len(self.hosts))
        self.assertEqual(len(self.hosts_calc), len(self.hosts))
        self.assertEqual(len(self.switches_calc), len(self.switches))
  def setUp(self):
    class MockSwitch(SwitchImpl):
      _eventMixin_events = set([DpPacketOut])

      def __init__(self, dpid, ports):
        self.has_forwarded = False
        self.dpid = dpid
        self.ports = {}
        for port in ports:
          self.ports[port.port_no] = port
      def process_packet(self, packet, in_port):
        self.has_forwarded = True
    def create_mock_switch(num_ports, switch_id):
      ports = []
      for port_no in range(1, num_ports+1):
        port = ofp_phy_port( port_no=port_no,
                             hw_addr=EthAddr("00:00:00:00:%02x:%02x" % (switch_id, port_no)) )
        # monkey patch an IP address onto the port for anteater purposes
        port.ip_addr = "1.1.%d.%d" % (switch_id, port_no)
        ports.append(port)
      return MockSwitch(switch_id, ports)
    self.g = Graph()
    self.switches = [create_mock_switch(2, 1), create_mock_switch(2, 2)]
    self.hosts = [Host([HostInterface(EthAddr("00:00:00:00:00:01"))], name="host1"),
                  Host([HostInterface(EthAddr("00:00:00:00:00:02"))], name="host2")]
    for switch in self.switches:
      self.g.add(switch)
    for host in self.hosts:
      self.g.add(host)
    self.g.link((self.switches[0], self.switches[0].ports[2]), (self.switches[1], self.switches[1].ports[2]))
    self.g.link((self.hosts[0], self.hosts[0].interfaces[0]), (self.switches[0], self.switches[0].ports[1]))
    self.g.link((self.hosts[1], self.hosts[1].interfaces[0]), (self.switches[1], self.switches[1].ports[1]))
    (self.patch, self.switches_calc, self.hosts_calc, self.access_links) = TopologyGenerator().populate_from_topology(self.g)
Esempio n. 3
0
    def setUp(self):
        class MockSwitch(SoftwareSwitch):
            _eventMixin_events = set([DpPacketOut])

            def __init__(self, dpid, ports):
                self.has_forwarded = False
                self.dpid = dpid
                self.ports = {}
                for port in ports:
                    self.ports[port.port_no] = port

            def process_packet(self, packet, in_port):
                self.has_forwarded = True

        def create_mock_switch(num_ports, switch_id):
            ports = []
            for port_no in range(1, num_ports + 1):
                port = ofp_phy_port(port_no=port_no,
                                    hw_addr=EthAddr("00:00:00:00:%02x:%02x" %
                                                    (switch_id, port_no)))
                # monkey patch an IP address onto the port for anteater purposes
                port.ip_addr = "1.1.%d.%d" % (switch_id, port_no)
                ports.append(port)
            return MockSwitch(switch_id, ports)

        self.g = Graph()
        self.switches = [create_mock_switch(2, 1), create_mock_switch(2, 2)]
        self.hosts = [
            Host([HostInterface(EthAddr("00:00:00:00:00:01"))], name="host1"),
            Host([HostInterface(EthAddr("00:00:00:00:00:02"))], name="host2")
        ]
        for switch in self.switches:
            self.g.add(switch)
        for host in self.hosts:
            self.g.add(host)
        self.g.link((self.switches[0], self.switches[0].ports[2]),
                    (self.switches[1], self.switches[1].ports[2]))
        self.g.link((self.hosts[0], self.hosts[0].interfaces[0]),
                    (self.switches[0], self.switches[0].ports[1]))
        self.g.link((self.hosts[1], self.hosts[1].interfaces[0]),
                    (self.switches[1], self.switches[1].ports[1]))
        topology = Topology.populate_from_topology(self.g)
        self.patch = BufferedPatchPanelForTopology(self.g)
        self.switches_calc = topology.switches
        self.hosts_calc = topology.hosts
        self.access_links = topology.access_links
Esempio n. 4
0
class TopologyUnitTest(unittest.TestCase):
    _io_loop = RecocoIOLoop()
    _io_ctor = _io_loop.create_worker_for_socket

    def setUp(self):
        class MockSwitch(SoftwareSwitch):
            _eventMixin_events = set([DpPacketOut])

            def __init__(self, dpid, ports):
                self.has_forwarded = False
                self.dpid = dpid
                self.ports = {}
                for port in ports:
                    self.ports[port.port_no] = port

            def process_packet(self, packet, in_port):
                self.has_forwarded = True

        def create_mock_switch(num_ports, switch_id):
            ports = []
            for port_no in range(1, num_ports + 1):
                port = ofp_phy_port(port_no=port_no, hw_addr=EthAddr("00:00:00:00:%02x:%02x" % (switch_id, port_no)))
                # monkey patch an IP address onto the port for anteater purposes
                port.ip_addr = "1.1.%d.%d" % (switch_id, port_no)
                ports.append(port)
            return MockSwitch(switch_id, ports)

        self.g = Graph()
        self.switches = [create_mock_switch(2, 1), create_mock_switch(2, 2)]
        self.hosts = [
            Host([HostInterface(EthAddr("00:00:00:00:00:01"))], name="host1"),
            Host([HostInterface(EthAddr("00:00:00:00:00:02"))], name="host2"),
        ]
        for switch in self.switches:
            self.g.add(switch)
        for host in self.hosts:
            self.g.add(host)
        self.g.link((self.switches[0], self.switches[0].ports[2]), (self.switches[1], self.switches[1].ports[2]))
        self.g.link((self.hosts[0], self.hosts[0].interfaces[0]), (self.switches[0], self.switches[0].ports[1]))
        self.g.link((self.hosts[1], self.hosts[1].interfaces[0]), (self.switches[1], self.switches[1].ports[1]))
        topology = Topology.populate_from_topology(self.g)
        self.patch = BufferedPatchPanelForTopology(self.g)
        self.switches_calc = topology.switches
        self.hosts_calc = topology.hosts
        self.access_links = topology.access_links

    # Line 152 is throwing an exception! See:
    # https://github.com/noxrepo/pox/issues/36 for more information.
    def xxx_marked_as_broken_generakted_topology(self):
        self.assertEqual(len(self.access_links), len(self.hosts))
        self.assertEqual(len(self.hosts_calc), len(self.hosts))
        self.assertEqual(len(self.switches_calc), len(self.switches))