Exemple #1
0
    def _get_v0x04_ifaces(*args, **kwargs):
        """Create a pair of v0x04 interfaces with optional extra arguments."""
        switch1 = Switch('dpid1')
        switch1.connection = Mock()
        switch1.connection.protocol.version = 0x04
        iface1 = Interface('interface1', 41, switch1, *args, **kwargs)

        switch2 = Switch('dpid2')
        switch2.connection = Mock()
        switch2.connection.protocol.version = 0x04
        iface2 = Interface('interface2', 42, switch2, *args, **kwargs)

        return iface1, iface2
Exemple #2
0
    def _get_v0x04_ifaces(*args, **kwargs):
        """Create a pair of v0x04 interfaces with optional extra arguments."""
        switch1 = Switch('dpid1')
        switch1.connection = Mock()
        switch1.connection.protocol.version = 0x04
        iface1 = Interface('interface1', 41, switch1, *args, **kwargs)

        switch2 = Switch('dpid2')
        switch2.connection = Mock()
        switch2.connection.protocol.version = 0x04
        iface2 = Interface('interface2', 42, switch2, *args, **kwargs)

        return iface1, iface2
Exemple #3
0
 def _get_v0x04_iface(*args, **kwargs):
     """Create a v0x04 interface object with optional extra arguments."""
     switch = Switch('dpid')
     switch.connection = Mock()
     switch.connection.protocol.version = 0x04
     switch.update_lastseen()
     return Interface('name', 42, switch, *args, **kwargs)
Exemple #4
0
    def test_switch_vlan_pool_options(self):
        """Test switch with the example from kytos.conf."""
        dpid = "00:00:00:00:00:00:00:01"
        vlan_pool_json = '{"00:00:00:00:00:00:00:01": {"1": [[1, 2], [5, 10]], \
            "4": [[3, 4]]}}'

        switch = Switch(dpid)
        self.controller.switches[dpid] = switch
        self.options.vlan_pool = vlan_pool_json
        switch.connection = Mock()
        switch.connection.protocol.version = 0x04
        self.controller.get_switch_or_create(dpid, switch.connection)

        port_id = 1
        intf = self.controller.switches[dpid].interfaces[port_id]
        tag_values = [tag.value for tag in intf.available_tags]
        self.assertEqual(tag_values, [1, 5, 6, 7, 8, 9])

        port_id = 4
        intf = self.controller.switches[dpid].interfaces[port_id]
        tag_values = [tag.value for tag in intf.available_tags]
        self.assertEqual(tag_values, [3])

        # this port number doesn't exist yet.
        port_7 = 7
        intf = Interface("test", port_7, switch)
        # no attr filters, so should associate as it is
        self.controller.switches[dpid].update_interface(intf)
        intf_obj = self.controller.switches[dpid].interfaces[port_7]
        self.assertEqual(intf_obj, intf)
        # assert default vlan_pool range (1, 4096)
        tag_values = [tag.value for tag in intf_obj.available_tags]
        self.assertEqual(tag_values, list(range(1, 4096)))
Exemple #5
0
def get_switch_mock(of_version,
                    connection_state=ConnectionState.NEW,
                    dpid="00:00:00:00:00:00:00:01"):
    """Return a switch mock."""
    switch = Switch(dpid)
    address = Mock()
    port = Mock()
    socket = Mock()
    switch.connection = Connection(address, port, socket)
    switch.connection.protocol.version = of_version
    switch.connection.state = connection_state
    return switch
Exemple #6
0
 def _get_v0x04_iface(*args, **kwargs):
     """Create a v0x04 interface object with optional extra arguments."""
     switch = Switch('dpid')
     switch.connection = Mock()
     switch.connection.protocol.version = 0x04
     return Interface('name', 42, switch, *args, **kwargs)