Beispiel #1
0
def _get_ports():
    return [
        PhyPort(port_no=65534,
                hw_addr=HWAddress('0e:d3:98:a5:30:47'),
                name='s1',
                config=PortConfig.OFPPC_PORT_DOWN,
                state=PortState.OFPPS_LINK_DOWN,
                curr=0,
                advertised=0,
                supported=0,
                peer=0),
        PhyPort(port_no=1,
                hw_addr=HWAddress('0a:54:cf:fc:4e:6d'),
                name='s1-eth1',
                config=0,
                state=PortState.OFPPS_STP_LISTEN,
                curr=0x000000c0,
                advertised=0,
                supported=0,
                peer=0),
        PhyPort(port_no=2,
                hw_addr=HWAddress('f6:b6:ab:cc:f8:4f'),
                name='s1-eth2',
                config=0,
                state=PortState.OFPPS_STP_LISTEN,
                curr=0x000000c0,
                advertised=0,
                supported=0,
                peer=0)
    ]
 def setUp(self):
     """Basic setup for test."""
     self.message = PhyPort()
     self.message.port_no = 1
     self.message.hw_addr = HWAddress('9a:da:11:8a:f4:0c')
     self.message.name = 's1-eth1'
     self.message.state = PortState.OFPPS_STP_LISTEN
     self.message.curr = (PortFeatures.OFPPF_10GB_FD
                          | PortFeatures.OFPPF_COPPER)
Beispiel #3
0
 def setUp(self):
     """Basic setup for test."""
     self.message = PhyPort()
     self.message.port_no = 2
     self.message.hw_addr = '1a:2b:3c:4d:5e:6f'
     self.message.name = bytes('X' * OFP_MAX_PORT_NAME_LEN, 'utf-8')
     self.message.config = PortConfig.OFPPC_NO_STP
     self.message.state = PortState.OFPPS_STP_FORWARD
     self.message.curr = PortFeatures.OFPPF_10GB_FD
     self.message.advertised = PortFeatures.OFPPF_PAUSE
     self.message.supported = PortFeatures.OFPPF_AUTONEG
     self.message.peer = PortFeatures.OFPPF_AUTONEG
Beispiel #4
0
class TestPhyPort(TestCase):
    """Test PhyPort."""

    def setUp(self):
        """Basic setup for test."""
        self.message = PhyPort()
        self.message.port_no = 2
        self.message.hw_addr = '1a:2b:3c:4d:5e:6f'
        self.message.name = bytes('X' * OFP_MAX_PORT_NAME_LEN, 'utf-8')
        self.message.config = PortConfig.OFPPC_NO_STP
        self.message.state = PortState.OFPPS_STP_FORWARD
        self.message.curr = PortFeatures.OFPPF_10GB_FD
        self.message.advertised = PortFeatures.OFPPF_PAUSE
        self.message.supported = PortFeatures.OFPPF_AUTONEG
        self.message.peer = PortFeatures.OFPPF_AUTONEG

    def test_get_size(self):
        """[Common/PhyPort] - size 48."""
        self.assertEqual(self.message.get_size(), 48)

    @skip('Not yet implemented')
    def test_pack(self):
        """[Common/PhyPort] - packing."""
        pass

    @skip('Not yet implemented')
    def test_unpack(self):
        """[Common/PhyPort] - unpacking."""
        pass
Beispiel #5
0
 def addPort(self, port_no=0, hw_addr="", port_name="", port_config=0, port_state=PortState.OFPPS_STP_LISTEN, port_curr=0, port_advertised=0, port_supported=0, port_peer=0):
   if(port_no == 0):
     port_no = randint(30000,65534)
   if(hw_addr == ""):
     hw_addr = sdnpwn.generateRandomMacAddress(self.switch_vendor_ouid)
   if(port_name == ""):
     port_name = "OF Port " + str(randint(1,10000))
   
   initQueueID = randint(30000,65534)
                     
   port = PhyPort(port_no=port_no,
                  hw_addr=HWAddress(hw_addr),
                  name=port_name,
                  #config=PortConfig.OFPC_PORT_DOWN,
                  #state=PortState.OFPPS_LINK_DOWN,
                  config=port_config,
                  state=port_state,
                  curr=port_curr,
                  advertised=port_advertised,
                  supported=port_supported,
                  peer=port_peer)
   self.switch_ports.append(port)
   self.switch_features["ports"] = self.switch_ports
   self.switch_stats["port"][str(port_no)] = PortStats(port_no=port_no, rx_packets=0, tx_packets=0, rx_bytes=0, tx_bytes=0,
                                                    rx_dropped=0, tx_dropped=0, rx_errors=0, tx_errors=0, rx_frame_err=0, 
                                                    rx_over_err=0, rx_crc_err=0, collisions=0)
   
   self.switch_stats["queue"][str(port_no) + ":" + str(initQueueID)] = QueueStats(port_no=port_no, queue_id=initQueueID, tx_bytes=0, tx_packets=0, tx_errors=0)
Beispiel #6
0
class TestPhyPort(TestCase):
    """Test PhyPort."""
    def setUp(self):
        """Basic setup for test."""
        self.message = PhyPort()
        self.message.port_no = 2
        self.message.hw_addr = '1a:2b:3c:4d:5e:6f'
        self.message.name = bytes('X' * OFP_MAX_PORT_NAME_LEN, 'utf-8')
        self.message.config = PortConfig.OFPPC_NO_STP
        self.message.state = PortState.OFPPS_STP_FORWARD
        self.message.curr = PortFeatures.OFPPF_10GB_FD
        self.message.advertised = PortFeatures.OFPPF_PAUSE
        self.message.supported = PortFeatures.OFPPF_AUTONEG
        self.message.peer = PortFeatures.OFPPF_AUTONEG

    def test_get_size(self):
        """[Common/PhyPort] - size 48."""
        self.assertEqual(self.message.get_size(), 48)

    @skip('Not yet implemented')
    def test_pack(self):
        """[Common/PhyPort] - packing."""
        pass

    @skip('Not yet implemented')
    def test_unpack(self):
        """[Common/PhyPort] - unpacking."""
        pass
Beispiel #7
0
def _new_portstatus():
    """Crate new PortStatus and PhyPort instances."""
    desc_name = 's1-eth1'
    desc = PhyPort(port_no=1,
                   hw_addr=HWAddress('9a:da:11:8a:f4:0c'),
                   name=desc_name,
                   state=PortState.OFPPS_STP_LISTEN,
                   curr=PortFeatures.OFPPF_10GB_FD | PortFeatures.OFPPF_COPPER)
    return PortStatus(xid=0,
                      reason=PortReason.OFPPR_MODIFY,
                      desc=desc)
Beispiel #8
0
 def setUp(self):
     """Basic setup for test."""
     self.message = PhyPort()
     self.message.port_no = 2
     self.message.hw_addr = '1a:2b:3c:4d:5e:6f'
     self.message.name = bytes('X' * OFP_MAX_PORT_NAME_LEN, 'utf-8')
     self.message.config = PortConfig.OFPPC_NO_STP
     self.message.state = PortState.OFPPS_STP_FORWARD
     self.message.curr = PortFeatures.OFPPF_10GB_FD
     self.message.advertised = PortFeatures.OFPPF_PAUSE
     self.message.supported = PortFeatures.OFPPF_AUTONEG
     self.message.peer = PortFeatures.OFPPF_AUTONEG
class TestPhyPort(TestCase):
    """Test PhyPort."""
    def setUp(self):
        """Basic setup for test."""
        self.message = PhyPort()
        self.message.port_no = 1
        self.message.hw_addr = HWAddress('9a:da:11:8a:f4:0c')
        self.message.name = 's1-eth1'
        self.message.state = PortState.OFPPS_STP_LISTEN
        self.message.curr = (PortFeatures.OFPPF_10GB_FD
                             | PortFeatures.OFPPF_COPPER)

    def test_get_size(self):
        """[Common/PhyPort] - size 48."""
        self.assertEqual(self.message.get_size(), 48)

    def test_pack(self):
        """[Common/PhyPort] - packing."""
        data = b'\x00\x01\x9a\xda\x11\x8a\xf4\x0cs1-eth1\x00\x00\x00\x00\x00'
        data += 15 * b'\x00'
        data += b'\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
        self.assertEqual(self.message.pack(), data)

    def test_unpack(self):
        """[Common/PhyPort] - unpacking."""
        filename = os.path.join(os.path.dirname(os.path.realpath('__file__')),
                                'raw/v0x01/ofpt_port_status.dat')
        f = open(filename, 'rb')
        f.seek(16, 1)
        self.message.unpack(f.read(48))

        self.assertEqual(self.message.port_no, 1)
        self.assertEqual(self.message.hw_addr, '9a:da:11:8a:f4:0c')
        self.assertEqual(self.message.name, 's1-eth1')
        self.assertEqual(self.message.state, PortState.OFPPS_STP_LISTEN)
        self.assertEqual(
            self.message.curr,
            (PortFeatures.OFPPF_10GB_FD | PortFeatures.OFPPF_COPPER))

        f.close()
def _new_portstatus():
    """Crate new PortStatus and PhyPort instances."""
    desc_name = 'X' * OFP_MAX_PORT_NAME_LEN
    desc = PhyPort(port_no=2,
                   hw_addr=HWAddress('0a:0a:12:12:10:10'),
                   name=desc_name,
                   config=PortConfig.OFPPC_NO_STP,
                   state=PortState.OFPPS_STP_FORWARD,
                   curr=PortFeatures.OFPPF_10GB_FD,
                   advertised=PortFeatures.OFPPF_PAUSE,
                   supported=PortFeatures.OFPPF_AUTONEG,
                   peer=PortFeatures.OFPPF_AUTONEG)
    return PortStatus(xid=1, reason=PortReason.OFPPR_ADD, desc=desc)
Beispiel #11
0
class PortStatus(GenericMessage):
    """A physical port has changed in the datapath."""

    #: :class:`~pyof.v0x01.common.header.Header`: OpenFlow Header
    header = Header(message_type=Type.OFPT_PORT_STATUS)
    reason = UBInt8(enum_ref=PortReason)
    #: Align to 32-bits.
    pad = Pad(7)
    desc = PhyPort()

    def __init__(self, xid=None, reason=None, desc=None):
        """Assign parameters to object attributes.

        Args:
            xid (int): Header's xid.
            reason (~pyof.v0x01.asynchronous.port_status.PortReason):
                Addition, deletion or modification.
            desc (PhyPort): Port description.
        """
        super().__init__(xid)
        self.reason = reason
        self.desc = desc