|
1
|
|
|
""" |
|
2
|
|
|
Module to process OpenFlow 1.3 packet manipulation |
|
3
|
|
|
""" |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
1 |
|
from kytos.core import KytosEvent, log |
|
7
|
1 |
|
from napps.amlight.sdntrace import settings |
|
8
|
1 |
|
from pyof.foundation.network_types import Ethernet |
|
9
|
1 |
|
from pyof.v0x04.common.action import ActionOutput |
|
10
|
1 |
|
from pyof.v0x04.controller2switch.packet_out import PacketOut |
|
11
|
1 |
|
from napps.kytos.of_core.msg_prios import of_msg_prio |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
1 |
View Code Duplication |
def packet_in(event, packet_in_msg): |
|
|
|
|
|
|
15
|
|
|
""" Process OpenFlow 1.3 PacketIn messages |
|
16
|
|
|
|
|
17
|
|
|
Args: |
|
18
|
|
|
event: PacketIN event |
|
19
|
|
|
packet_in_msg: PacketIn msg |
|
20
|
|
|
Return: |
|
21
|
|
|
ethernet: PacketIn data |
|
22
|
|
|
in_port: in_port |
|
23
|
|
|
switch: OpenFlow datapath |
|
24
|
|
|
0, 0, 0 if it is not a trace probe |
|
25
|
|
|
""" |
|
26
|
|
|
|
|
27
|
1 |
|
ethernet = Ethernet() |
|
28
|
1 |
|
ethernet.unpack(packet_in_msg.data.value) |
|
29
|
|
|
|
|
30
|
1 |
|
if settings.COLOR_VALUE in ethernet.source.value: |
|
31
|
1 |
|
log.debug("OpenFlow 1.3 PacketIn Trace Msg Received") |
|
32
|
|
|
|
|
33
|
1 |
|
in_port = event.message.in_port |
|
34
|
1 |
|
switch = event.source.switch |
|
35
|
1 |
|
return ethernet, in_port, switch |
|
36
|
|
|
|
|
37
|
1 |
|
log.debug("PacketIn is not a Data Trace Probe") |
|
38
|
1 |
|
return 0, 0, 0 |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
1 |
|
def send_packet_out(controller, switch, port, data): |
|
42
|
|
|
""" Just prepare the PacketOut to be used by the Tracer. |
|
43
|
|
|
|
|
44
|
|
|
Args: |
|
45
|
|
|
controller: Kytos controller |
|
46
|
|
|
switch: OpenFlow datapath |
|
47
|
|
|
port: in_port |
|
48
|
|
|
data: Ethernet frame |
|
49
|
|
|
Return: |
|
50
|
|
|
output_action = ActionOutput |
|
51
|
|
|
""" |
|
52
|
1 |
|
output_action = ActionOutput() |
|
53
|
1 |
|
output_action.port = settings.OFPP_TABLE_13 |
|
54
|
|
|
|
|
55
|
1 |
|
packet_out = PacketOut() |
|
56
|
1 |
|
packet_out.actions.append(output_action) |
|
57
|
1 |
|
packet_out.in_port = port |
|
58
|
1 |
|
packet_out.data = bytes(data) |
|
59
|
|
|
|
|
60
|
1 |
|
event_out = KytosEvent( |
|
61
|
|
|
name='kytos/of_lldp.messages.out.ofpt_packet_out', |
|
62
|
|
|
priority=of_msg_prio(packet_out.header.message_type.value), |
|
63
|
|
|
content={'destination': switch.connection, |
|
64
|
|
|
'message': packet_out} |
|
65
|
|
|
) |
|
66
|
1 |
|
log.debug('PacketOut %s sent' % event_out.content) |
|
67
|
|
|
controller.buffers.msg_out.put(event_out) |
|
68
|
|
|
|