Passed
Push — master ( e932ef...36cf0a )
by Vinicius
02:30 queued 14s
created

build.backends.openflow10   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 37.88 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 30
dl 25
loc 66
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Functions

Rating   Name   Duplication   Size   Complexity  
A packet_in() 25 25 2
A send_packet_out() 0 26 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
"""
2
    Module to process OpenFlow 1.0 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.v0x01.common.action import ActionOutput
10 1
from pyof.v0x01.controller2switch.packet_out import PacketOut
11
12
13 1 View Code Duplication
def packet_in(event, packet_in_msg):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
14
    """ Process OpenFlow 1.0 PacketIn messages
15
16
    Args:
17
        event: PacketIN event
18
        packet_in_msg: PacketIn msg
19
    Return:
20
        ethernet: PacketIn data
21
        in_port: in_port
22
        switch: OpenFlow datapath
23
        0, 0, 0 if it is not a trace probe
24
    """
25
26 1
    ethernet = Ethernet()
27 1
    ethernet.unpack(packet_in_msg.data.value)
28
29 1
    if settings.COLOR_VALUE in ethernet.source.value:
30 1
        log.debug("OpenFlow 1.0 PacketIn Trace Msg Received")
31
32 1
        in_port = packet_in_msg.in_port.value
33 1
        switch = event.source.switch
34 1
        return ethernet, in_port, switch
35
36 1
    log.debug("PacketIn is not a Data Trace Probe")
37 1
    return 0, 0, 0
38
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
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 1
    event_out.name = 'kytos/of_lldp.messages.out.ofpt_packet_out'
61 1
    event_out.content = {'destination': switch.connection,
62
                         'message': packet_out}
63
64 1
    log.debug('PacketOut %s sent' % event_out.content)
65
    controller.buffers.msg_out.put(event_out)
66