1
|
|
|
"""Flow modification (add/delete) message tests.""" |
2
|
|
|
from pyof.v0x01.common.action import ActionOutput |
3
|
|
|
from pyof.v0x01.common.flow_match import Match |
4
|
|
|
from pyof.v0x01.common.phy_port import Port |
5
|
|
|
from pyof.v0x01.controller2switch.flow_mod import FlowMod, FlowModCommand |
6
|
|
|
from tests.unit.test_struct import TestStruct |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class TestFlowAdd(TestStruct): |
10
|
|
|
"""Flow addition message tests (also those in :class:`.TestDump`).""" |
11
|
|
|
|
12
|
|
|
@classmethod |
13
|
|
|
def setUpClass(cls): |
14
|
|
|
"""Configure raw file and its object in parent class (TestDump).""" |
15
|
|
|
super().setUpClass() |
16
|
|
|
super().set_raw_dump_file('v0x01', 'ofpt_flow_add') |
17
|
|
|
kwargs = _get_flowmod_kwargs(FlowModCommand.OFPFC_ADD) |
18
|
|
|
super().set_raw_dump_object(FlowMod, **kwargs) |
19
|
|
|
super().set_minimum_size(72) |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
class TestFlowDelete(TestStruct): |
23
|
|
|
"""Flow deletion message tests (also those in :class:`.TestDump`).""" |
24
|
|
|
|
25
|
|
|
@classmethod |
26
|
|
|
def setUpClass(cls): |
27
|
|
|
"""Configure raw file and its object in parent class (TestDump).""" |
28
|
|
|
super().setUpClass() |
29
|
|
|
super().set_raw_dump_file('v0x01', 'ofpt_flow_delete') |
30
|
|
|
kwargs = _get_flowmod_kwargs(FlowModCommand.OFPFC_DELETE) |
31
|
|
|
super().set_raw_dump_object(FlowMod, **kwargs) |
32
|
|
|
# No need to test minimum size again. |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
def _get_flowmod_kwargs(command): |
36
|
|
|
"""Return parameters for FlowMod object.""" |
37
|
|
|
return {'xid': 4, |
38
|
|
|
'command': command, |
39
|
|
|
'match': _get_match(), |
40
|
|
|
'cookie': 0, |
41
|
|
|
'idle_timeout': 0, |
42
|
|
|
'hard_timeout': 0, |
43
|
|
|
'priority': 32768, |
44
|
|
|
'buffer_id': 4294967295, |
45
|
|
|
'out_port': Port.OFPP_NONE, |
46
|
|
|
'flags': 0, |
47
|
|
|
'actions': _get_actions()} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
def _get_match(): |
51
|
|
|
"""Return a Match object.""" |
52
|
|
|
return Match() |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
def _get_actions(): |
56
|
|
|
"""Return a List of actions registered by flow object.""" |
57
|
|
|
action = ActionOutput(port=65533, max_length=65535) |
58
|
|
|
return [action] |
59
|
|
|
|