|
1
|
|
|
"""Testing PhyPort structure.""" |
|
2
|
|
|
import os |
|
3
|
|
|
from unittest import TestCase |
|
4
|
|
|
|
|
5
|
|
|
from pyof.foundation.basic_types import HWAddress |
|
6
|
|
|
from pyof.foundation.constants import OFP_MAX_PORT_NAME_LEN |
|
7
|
|
|
from pyof.v0x01.common.phy_port import ( |
|
8
|
|
|
PhyPort, PortConfig, PortFeatures, PortState) |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class TestPhyPort(TestCase): |
|
12
|
|
|
"""Test PhyPort.""" |
|
13
|
|
|
|
|
14
|
|
|
def setUp(self): |
|
15
|
|
|
"""Basic setup for test.""" |
|
16
|
|
|
self.message = PhyPort() |
|
17
|
|
|
self.message.port_no = 1 |
|
18
|
|
|
self.message.hw_addr = HWAddress('9a:da:11:8a:f4:0c') |
|
19
|
|
|
self.message.name = 's1-eth1' |
|
20
|
|
|
self.message.state = PortState.OFPPS_STP_LISTEN |
|
21
|
|
|
self.message.curr = (PortFeatures.OFPPF_10GB_FD | |
|
22
|
|
|
PortFeatures.OFPPF_COPPER) |
|
23
|
|
|
|
|
24
|
|
|
def test_get_size(self): |
|
25
|
|
|
"""[Common/PhyPort] - size 48.""" |
|
26
|
|
|
self.assertEqual(self.message.get_size(), 48) |
|
27
|
|
|
|
|
28
|
|
|
def test_pack(self): |
|
29
|
|
|
"""[Common/PhyPort] - packing.""" |
|
30
|
|
|
data = b'\x00\x01\x9a\xda\x11\x8a\xf4\x0cs1-eth1\x00\x00\x00\x00\x00' |
|
31
|
|
|
data += 15 * b'\x00' |
|
32
|
|
|
data += b'\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
|
33
|
|
|
self.assertEqual(self.message.pack(), data) |
|
34
|
|
|
|
|
35
|
|
|
def test_unpack(self): |
|
36
|
|
|
"""[Common/PhyPort] - unpacking.""" |
|
37
|
|
|
filename = os.path.join(os.path.dirname(os.path.realpath('__file__')), |
|
38
|
|
|
'raw/v0x01/ofpt_port_status.dat') |
|
39
|
|
|
f = open(filename, 'rb') |
|
40
|
|
|
f.seek(16, 1) |
|
41
|
|
|
self.message.unpack(f.read(48)) |
|
42
|
|
|
|
|
43
|
|
|
self.assertEqual(self.message.port_no, 1) |
|
44
|
|
|
self.assertEqual(self.message.hw_addr, '9a:da:11:8a:f4:0c') |
|
45
|
|
|
self.assertEqual(self.message.name, 's1-eth1') |
|
46
|
|
|
self.assertEqual(self.message.state, PortState.OFPPS_STP_LISTEN) |
|
47
|
|
|
self.assertEqual(self.message.curr, (PortFeatures.OFPPF_10GB_FD | |
|
48
|
|
|
PortFeatures.OFPPF_COPPER)) |
|
49
|
|
|
|
|
50
|
|
|
f.close() |
|
51
|
|
|
|