1
|
|
|
"""Test Match abstraction for v0x01 and v0x04.""" |
2
|
|
|
import unittest |
3
|
|
|
|
4
|
|
|
from pyof.v0x01.common.flow_match import Match as OFMatch01 |
5
|
|
|
from pyof.v0x04.common.flow_match import Match as OFMatch04 |
6
|
|
|
|
7
|
|
|
from napps.kytos.of_core.v0x01.flow import Match as Match01 |
8
|
|
|
from napps.kytos.of_core.v0x04.flow import Match as Match04 |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class TestMatch(unittest.TestCase): |
12
|
|
|
"""Tests for the Match class.""" |
13
|
|
|
|
14
|
|
|
EXPECTED = {'in_port': 1, |
15
|
|
|
'dl_src': '11:22:33:44:55:66', |
16
|
|
|
'dl_dst': 'aa:bb:cc:dd:ee:ff', |
17
|
|
|
'dl_vlan': 2, |
18
|
|
|
'dl_vlan_pcp': 3, |
19
|
|
|
'dl_type': 4, |
20
|
|
|
'nw_proto': 5, |
21
|
|
|
'nw_src': '1.2.3.4/32', |
22
|
|
|
'nw_dst': '5.6.7.0/24', |
23
|
|
|
'tp_src': 6, |
24
|
|
|
'tp_dst': 7} |
25
|
|
|
|
26
|
|
|
def test_all_fields(self): |
27
|
|
|
"""Test all match fields from and to dict.""" |
28
|
|
|
for match_class in Match01, Match04: |
29
|
|
|
with self.subTest(match_class=match_class): |
30
|
|
|
match = match_class.from_dict(self.EXPECTED) |
31
|
|
|
actual = match.as_dict() |
32
|
|
|
self.assertDictEqual(self.EXPECTED, actual) |
33
|
|
|
|
34
|
|
|
def test_of_match(self): |
35
|
|
|
"""Test convertion between Match and OFMatch.""" |
36
|
|
|
match_01 = Match01.from_dict(self.EXPECTED) |
37
|
|
|
match_04 = Match04.from_dict(self.EXPECTED) |
38
|
|
|
of_match_01 = match_01.as_of_match() |
39
|
|
|
of_match_04 = match_04.as_of_match() |
40
|
|
|
match_01_converted = Match01.from_of_match(of_match_01) |
41
|
|
|
match_04_converted = Match04.from_of_match(of_match_04) |
42
|
|
|
self.assertIsInstance(of_match_01, OFMatch01) |
43
|
|
|
self.assertIsInstance(of_match_04, OFMatch04) |
44
|
|
|
self.assertIsInstance(match_01_converted, Match01) |
45
|
|
|
self.assertIsInstance(match_04_converted, Match04) |
46
|
|
|
|