|
1
|
|
|
"""Packet out message tests.""" |
|
2
|
|
|
from pyof.foundation.exceptions import ValidationError |
|
3
|
|
|
from pyof.v0x01.common.action import ActionOutput, ListOfActions |
|
4
|
|
|
from pyof.v0x01.common.phy_port import Port |
|
5
|
|
|
from pyof.v0x01.controller2switch.packet_out import PacketOut |
|
6
|
|
|
from tests.test_struct import TestMsgDumpFile |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class TestPacketOut(TestMsgDumpFile): |
|
10
|
|
|
"""Packet out message tests (also those in :class:`.TestDump`). |
|
11
|
|
|
|
|
12
|
|
|
Attributes: |
|
13
|
|
|
message (PacketOut): The message configured in :meth:`setUpClass`. |
|
14
|
|
|
""" |
|
15
|
|
|
|
|
16
|
|
|
dumpfile = 'v0x01/ofpt_packet_out.dat' |
|
17
|
|
|
|
|
18
|
|
|
actions = ListOfActions(items=ActionOutput(port=1, max_length=0)) |
|
19
|
|
|
data = b'\x01# \x00\x00\x01\xd2A\xc6.*@\x88\xcc\x02\x07\x07dpi' |
|
20
|
|
|
data += b'd:1\x04\x02\x021\x06\x02\x00x\x0c\x06dpid:1\x00\x00' |
|
21
|
|
|
obj = PacketOut(xid=8, buffer_id=4294967295, |
|
22
|
|
|
in_port=Port.OFPP_NONE, data=data, |
|
23
|
|
|
actions=actions) |
|
24
|
|
|
min_size = 16 |
|
25
|
|
|
|
|
26
|
|
|
def _get_new_obj(self, port): |
|
27
|
|
|
return PacketOut(xid=8, buffer_id=4294967295, |
|
28
|
|
|
in_port=port, data=self.data, |
|
29
|
|
|
actions=self.actions) |
|
30
|
|
|
|
|
31
|
|
|
def test_valid_virtual_in_ports(self): |
|
32
|
|
|
"""Valid virtual ports as defined in 1.0.1 spec.""" |
|
33
|
|
|
valid = (Port.OFPP_LOCAL, Port.OFPP_CONTROLLER, Port.OFPP_NONE) |
|
34
|
|
|
for in_port in valid: |
|
35
|
|
|
obj = self._get_new_obj(in_port) |
|
36
|
|
|
self.assertTrue(obj.is_valid()) |
|
37
|
|
|
|
|
38
|
|
|
def test_invalid_virtual_in_ports(self): |
|
39
|
|
|
"""Invalid virtual ports as defined in 1.0.1 spec.""" |
|
40
|
|
|
invalid = (Port.OFPP_IN_PORT, Port.OFPP_TABLE, Port.OFPP_NORMAL, |
|
41
|
|
|
Port.OFPP_FLOOD, Port.OFPP_ALL) |
|
42
|
|
|
for in_port in invalid: |
|
43
|
|
|
obj = self._get_new_obj(in_port) |
|
44
|
|
|
self.assertFalse(obj.is_valid()) |
|
45
|
|
|
self.assertRaises(ValidationError, obj.validate) |
|
46
|
|
|
|
|
47
|
|
|
def test_valid_physical_in_ports(self): |
|
48
|
|
|
"""Physical port limits from 1.0.0 spec.""" |
|
49
|
|
|
max_valid = int(Port.OFPP_MAX.value) - 1 |
|
50
|
|
|
for in_port in (1, max_valid): |
|
51
|
|
|
obj = self._get_new_obj(in_port) |
|
52
|
|
|
self.assertTrue(obj.is_valid()) |
|
53
|
|
|
|
|
54
|
|
|
def test_invalid_physical_in_port(self): |
|
55
|
|
|
"""Physical port limits from 1.0.0 spec.""" |
|
56
|
|
|
max_valid = int(Port.OFPP_MAX.value) - 1 |
|
57
|
|
|
for in_port in (-1, 0, max_valid + 1, max_valid + 2): |
|
58
|
|
|
obj = self._get_new_obj(in_port) |
|
59
|
|
|
self.assertFalse(obj.is_valid()) |
|
60
|
|
|
self.assertRaises(ValidationError, obj.validate) |
|
61
|
|
|
|