1
|
|
|
"""Tests for high-level Flow of OpenFlow 1.0 and 1.3.""" |
2
|
|
|
import unittest |
3
|
|
|
|
4
|
|
|
from pyof.v0x01.controller2switch.flow_mod import FlowMod as OFFlow01 |
5
|
|
|
from pyof.v0x04.controller2switch.flow_mod import FlowMod as OFFlow04 |
6
|
|
|
|
7
|
|
|
from kytos.core.switch import Switch |
8
|
|
|
from napps.kytos.of_core.v0x01.flow import Flow as Flow01 |
9
|
|
|
from napps.kytos.of_core.v0x04.flow import Flow as Flow04 |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class TestFlow(unittest.TestCase): |
13
|
|
|
"""Test OF flow abstraction.""" |
14
|
|
|
|
15
|
|
|
SWITCH = Switch('dpid') |
16
|
|
|
EXPECTED = {'id': '1ce5d08a46496fcb856cb603a5bfa00f', |
17
|
|
|
'switch': SWITCH.id, |
18
|
|
|
'table_id': 1, |
19
|
|
|
'match': { |
20
|
|
|
'dl_src': '11:22:33:44:55:66' |
21
|
|
|
}, |
22
|
|
|
'priority': 2, |
23
|
|
|
'idle_timeout': 3, |
24
|
|
|
'hard_timeout': 4, |
25
|
|
|
'cookie': 5, |
26
|
|
|
'actions': [ |
27
|
|
|
{'action_type': 'set_vlan', |
28
|
|
|
'vlan_id': 6}], |
29
|
|
|
'stats': {}} |
30
|
|
|
|
31
|
|
|
def test_flow_mod(self): |
32
|
|
|
"""Convert a dict to flow and vice-versa.""" |
33
|
|
|
for flow_class in Flow01, Flow04: |
34
|
|
|
with self.subTest(flow_class=flow_class): |
35
|
|
|
flow = flow_class.from_dict(self.EXPECTED, self.SWITCH) |
36
|
|
|
actual = flow.as_dict() |
37
|
|
|
self.assertDictEqual(self.EXPECTED, actual) |
38
|
|
|
|
39
|
|
|
def test_of_flow_mod(self): |
40
|
|
|
"""Test convertion from Flow to OFFlow.""" |
41
|
|
|
flow_mod_01 = Flow01.from_dict(self.EXPECTED, self.SWITCH) |
42
|
|
|
flow_mod_04 = Flow04.from_dict(self.EXPECTED, self.SWITCH) |
43
|
|
|
of_flow_mod_01 = flow_mod_01.as_of_add_flow_mod() |
44
|
|
|
of_flow_mod_04 = flow_mod_04.as_of_delete_flow_mod() |
45
|
|
|
self.assertIsInstance(of_flow_mod_01, OFFlow01) |
46
|
|
|
self.assertIsInstance(of_flow_mod_04, OFFlow04) |
47
|
|
|
|