1
|
|
|
""" Tests for /backends/openflow10.py """ |
2
|
|
|
from unittest import TestCase |
3
|
|
|
from unittest.mock import MagicMock |
4
|
|
|
|
5
|
|
|
from napps.amlight.sdntrace import settings |
6
|
|
|
from napps.amlight.sdntrace.backends.openflow10 import ( |
7
|
|
|
packet_in, |
8
|
|
|
send_packet_out, |
9
|
|
|
) |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
# pylint: disable=too-many-public-methods, too-many-lines |
13
|
|
|
class TestOpenflow10(TestCase): |
14
|
|
|
"""Unit tests for /backends/openflow10.py functions.""" |
15
|
|
|
|
16
|
|
View Code Duplication |
def test_packet_in_with_color(self): |
|
|
|
|
17
|
|
|
"""Test packet in with color ee:ee:ee:ee:ee:01.""" |
18
|
|
|
raw = b"\x00\x15\xaf\xd58\x98\xee\xee\xee\xee\xee\x01\x08\x00testdata" |
19
|
|
|
# Ethernet(destination='00:15:af:d5:38:98', |
20
|
|
|
# source='ee:ee:ee:ee:ee:01', ether_type=0x800, |
21
|
|
|
# data=b'testdata') |
22
|
|
|
packet_in_msg = MagicMock() |
23
|
|
|
packet_in_msg.data.value = raw |
24
|
|
|
packet_in_msg.in_port.value = 1 |
25
|
|
|
|
26
|
|
|
event = MagicMock() |
27
|
|
|
event.source.switch = "ee:ee:ee:ee:ee:01" |
28
|
|
|
|
29
|
|
|
ethernet, in_port, switch = packet_in(event, packet_in_msg) |
30
|
|
|
|
31
|
|
|
self.assertEqual(ethernet.source.value, "ee:ee:ee:ee:ee:01") |
32
|
|
|
self.assertEqual(in_port, 1) |
33
|
|
|
self.assertEqual(switch, "ee:ee:ee:ee:ee:01") |
34
|
|
|
|
35
|
|
View Code Duplication |
def test_normal_packet_in(self): |
|
|
|
|
36
|
|
|
"""Test packet in without color.""" |
37
|
|
|
raw = b"\x00\x15\xaf\xd58\x98\x00\x1f:>\x9a\xcf\x08\x00testdata" |
38
|
|
|
# Ethernet(destination='00:15:af:d5:38:98', |
39
|
|
|
# source='00:1f:3a:3e:9a:cf', ether_type=0x800, |
40
|
|
|
# data=b'testdata') |
41
|
|
|
packet_in_msg = MagicMock() |
42
|
|
|
packet_in_msg.data.value = raw |
43
|
|
|
packet_in_msg.in_port.value = 1 |
44
|
|
|
|
45
|
|
|
event = MagicMock() |
46
|
|
|
event.source.switch = "00:1f:3a:3e:9a:cf" |
47
|
|
|
|
48
|
|
|
ethernet, in_port, switch = packet_in(event, packet_in_msg) |
49
|
|
|
|
50
|
|
|
self.assertEqual(ethernet, 0) |
51
|
|
|
self.assertEqual(in_port, 0) |
52
|
|
|
self.assertEqual(switch, 0) |
53
|
|
|
|
54
|
|
View Code Duplication |
def test_packet_out_with_color(self): |
|
|
|
|
55
|
|
|
"""Test packet in with color ee:ee:ee:ee:ee:01.""" |
56
|
|
|
data = b"\x00\x15\xaf\xd58\x98\xee\xee\xee\xee\xee\x01\x08\x00testdata" |
57
|
|
|
# Ethernet(destination='00:15:af:d5:38:98', |
58
|
|
|
# source='ee:ee:ee:ee:ee:01', ether_type=0x800, |
59
|
|
|
# data=b'testdata') |
60
|
|
|
controller = MagicMock() |
61
|
|
|
switch = MagicMock() |
62
|
|
|
switch.connection.value = "00:15:af:d5:38:98" |
63
|
|
|
port = 1 |
64
|
|
|
|
65
|
|
|
send_packet_out(controller, switch, port, data) |
66
|
|
|
|
67
|
|
|
# Verify that the controller sent the packet_out |
68
|
|
|
controller.buffers.msg_out.put.assert_called_once() |
69
|
|
|
called_event = controller.buffers.msg_out.put.call_args.args[0] |
70
|
|
|
|
71
|
|
|
# Verify the packet_out values |
72
|
|
|
self.assertEqual( |
73
|
|
|
called_event.name, "kytos/of_lldp.messages.out.ofpt_packet_out" |
74
|
|
|
) |
75
|
|
|
self.assertEqual( |
76
|
|
|
called_event.content["destination"].value, switch.connection.value |
77
|
|
|
) |
78
|
|
|
self.assertEqual(called_event.content["message"].in_port, port) |
79
|
|
|
self.assertEqual(called_event.content["message"].data, data) |
80
|
|
|
self.assertEqual( |
81
|
|
|
called_event.content["message"].actions[0].port, |
82
|
|
|
settings.OFPP_TABLE, |
83
|
|
|
) |
84
|
|
|
|