File: test_phy_port.py

package info (click to toggle)
python-openflow 2021.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,224 kB
  • sloc: python: 6,906; sh: 4; makefile: 4
file content (50 lines) | stat: -rw-r--r-- 1,878 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Testing PhyPort structure."""
import os
from unittest import TestCase

from pyof.foundation.basic_types import HWAddress
from pyof.foundation.constants import OFP_MAX_PORT_NAME_LEN
from pyof.v0x01.common.phy_port import (
    PhyPort, PortConfig, PortFeatures, PortState)


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()