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

build.backends.of_parser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 51
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 6

2 Functions

Rating   Name   Duplication   Size   Complexity  
A process_packet_in() 0 18 3
A send_packet_out() 0 20 3
1
"""
2
    Module to transparently process OpenFlow requests,
3
"""
4
5
6 1
import napps.amlight.sdntrace.backends.openflow10 as openflow10
7 1
import napps.amlight.sdntrace.backends.openflow13 as openflow13
8 1
from kytos.core import log
9
10
11 1
def process_packet_in(event):
12
    """
13
14
    Args:
15
        event
16
    Return:
17
        ethernet: frame
18
        in_port: incoming port
19
        switch: incoming switch
20
    """
21 1
    of_version = event.content['message'].header.version
22 1
    if of_version.value == 1:
23 1
        return openflow10.packet_in(event, event.content['message'])
24 1
    elif of_version.value == 4:
25 1
        return openflow13.packet_in(event, event.content['message'])
26
27 1
    log.error("Invalid OpenFlow version")
28 1
    return 0, 0, 0
29
30
31 1
def send_packet_out(controller, switch, port, data):
32
    """ Just prepare and send a PacketOut used by
33
    the Tracer.
34
35
    Args:
36
        controller: Kytos controller
37
        switch: OpenFlow datapath
38
        port: in_port
39
        data: Ethernet frame
40
    """
41
42 1
    of_version = switch.features.header.version
43
44 1
    if of_version.value == 1:
45 1
        openflow10.send_packet_out(controller, switch, port, data)
46 1
    elif of_version.value == 4:
47 1
        openflow13.send_packet_out(controller, switch, port, data)
48
    else:
49 1
        log.error("Invalid OpenFlow version")
50
        return
51