| Total Complexity | 6 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 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 |