build.backends.openflow13   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 67
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Functions

Rating   Name   Duplication   Size   Complexity  
A packet_in() 0 25 2
A send_packet_out() 0 27 1
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
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 1
def send_packet_out(controller, switch, port, data):
41
    """ Just prepare the PacketOut to be used by the Tracer.
42
43
    Args:
44
        controller: Kytos controller
45
        switch: OpenFlow datapath
46
        port: in_port
47
        data: Ethernet frame
48
    Return:
49
        output_action = ActionOutput
50
    """
51 1
    output_action = ActionOutput()
52 1
    output_action.port = settings.OFPP_TABLE_13
53
54 1
    packet_out = PacketOut()
55 1
    packet_out.actions.append(output_action)
56 1
    packet_out.in_port = port
57 1
    packet_out.data = bytes(data)
58
59 1
    event_out = KytosEvent(
60
        name='kytos/of_lldp.messages.out.ofpt_packet_out',
61
        priority=of_msg_prio(packet_out.header.message_type.value),
62
        content={'destination': switch.connection,
63
                 'message': packet_out}
64
    )
65
    log.debug('PacketOut %s sent' % event_out.content)
66
    controller.buffers.msg_out.put(event_out)