|
1
|
|
|
"""Packet in message tests.""" |
|
2
|
|
|
from pyof.v0x04.asynchronous.packet_in import PacketIn, PacketInReason |
|
3
|
|
|
from pyof.v0x04.common.constants import OFP_NO_BUFFER |
|
4
|
|
|
from pyof.v0x04.common.flow_match import ( |
|
5
|
|
|
Match, MatchType, OxmClass, OxmOfbMatchField, OxmTLV) |
|
6
|
|
|
from pyof.v0x04.common.port import PortNo |
|
7
|
|
|
from tests.test_struct import TestStruct |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class TestPacketInRaw(TestStruct): |
|
11
|
|
|
"""Test PacketIn using a dump file.""" |
|
12
|
|
|
|
|
13
|
|
|
@classmethod |
|
14
|
|
|
def setUpClass(cls): |
|
15
|
|
|
"""Configure raw file and its object in parent class (TestDump).""" |
|
16
|
|
|
super().setUpClass() |
|
17
|
|
|
super().set_raw_dump_file('v0x04', 'ofpt_packet_in') |
|
18
|
|
|
super().set_raw_dump_object(PacketIn, xid=0, buffer_id=OFP_NO_BUFFER, |
|
19
|
|
|
total_len=90, |
|
20
|
|
|
reason=PacketInReason.OFPR_ACTION, |
|
21
|
|
|
table_id=0, cookie=0x0000000000000000, |
|
22
|
|
|
match=_new_match(), data=_get_data()) |
|
23
|
|
|
super().set_minimum_size(34) |
|
24
|
|
|
|
|
25
|
|
|
def test_valid_physical_in_port(self): |
|
26
|
|
|
"""Physical port limits from 1.3.0 spec.""" |
|
27
|
|
|
try: |
|
28
|
|
|
msg = self.get_raw_dump().read() |
|
29
|
|
|
except FileNotFoundError: |
|
30
|
|
|
raise self.skipTest('No raw dump file found.') |
|
31
|
|
|
else: |
|
32
|
|
|
max_valid = int(PortNo.OFPP_MAX.value) - 1 |
|
33
|
|
|
msg = self.get_raw_object() |
|
34
|
|
|
if msg.in_port in (1, max_valid): |
|
35
|
|
|
self.assertTrue(msg.is_valid()) |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
def _new_match(): |
|
39
|
|
|
"""Crate new Match instance.""" |
|
40
|
|
|
oxmtlv = OxmTLV(oxm_class=OxmClass.OFPXMC_OPENFLOW_BASIC, |
|
41
|
|
|
oxm_field=OxmOfbMatchField.OFPXMT_OFB_IN_PORT, |
|
42
|
|
|
oxm_hasmask=False, oxm_value=b'\x00\x00\x00\x02') |
|
43
|
|
|
return Match(match_type=MatchType.OFPMT_OXM, |
|
44
|
|
|
oxm_match_fields=[oxmtlv]) |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
def _get_data(): |
|
48
|
|
|
"""Return data for PacketIn object.""" |
|
49
|
|
|
data = b'\x33\x33\x00\x00\x00\x16\x92\xfd\x3d\x2a\x06\x0c\x86\xdd\x60\x00' |
|
50
|
|
|
data += b'\x00\x00\x00\x24\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
|
51
|
|
|
data += b'\x00\x00\x00\x00\x00\x00\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00' |
|
52
|
|
|
data += b'\x00\x00\x00\x00\x00\x16\x3a\x00\x05\x02\x00\x00\x01\x00\x8f\x00' |
|
53
|
|
|
data += b'\x69\x54\x00\x00\x00\x01\x04\x00\x00\x00\xff\x02\x00\x00\x00\x00' |
|
54
|
|
|
data += b'\x00\x00\x00\x00\x00\x01\xff\x2a\x06\x0c' |
|
55
|
|
|
return data |
|
56
|
|
|
|