Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unpack from kytos/of_core/utils.py #285

Merged
merged 1 commit into from
Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions napps/kytos/of_core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from kytos.core.flow import Flow
from kytos.core.helpers import listen_to
from pyof.foundation.exceptions import UnpackException
from pyof.utils import unpack, PYOF_VERSION_LIBS

import pyof.v0x01.asynchronous.error_msg
import pyof.v0x01.common.header
Expand All @@ -28,7 +29,7 @@
from napps.kytos.of_core import settings
from napps.kytos.of_core.utils import (emit_message_in, emit_message_out,
GenericHello, NegotiationException,
of_slicer, unpack, pyof_version_libs)
of_slicer)


class Main(KytosNApp):
Expand Down Expand Up @@ -202,7 +203,7 @@ def handle_echo_request(self, event):
Event with echo request in message.
"""

pyof_lib = pyof_version_libs[event.source.protocol.version]
pyof_lib = PYOF_VERSION_LIBS[event.source.protocol.version]
echo_request = event.message
echo_reply = pyof_lib.symmetric.echo_reply.EchoReply(
xid=echo_request.header.xid,
Expand Down Expand Up @@ -281,7 +282,7 @@ def fail_negotiation(self, connection, hello_message):
self.controller.buffers.app.put(event_raw)

version = max(settings.OPENFLOW_VERSIONS)
pyof_lib = pyof_version_libs[version]
pyof_lib = PYOF_VERSION_LIBS[version]

error_message = pyof_lib.asynchronous.error_msg.ErrorMsg(
xid=hello_message.header.xid,
Expand All @@ -306,7 +307,7 @@ def handle_queued_openflow_echo_reply(self, event):
def send_features_request(self, destination):
"""Send a feature request to the switch."""
version = destination.protocol.version
pyof_lib = pyof_version_libs[version]
pyof_lib = PYOF_VERSION_LIBS[version]
features_request = pyof_lib.controller2switch.\
features_request.FeaturesRequest()
self.emit_message_out(destination, features_request)
Expand Down
25 changes: 0 additions & 25 deletions napps/kytos/of_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
from pyof.foundation.exceptions import PackException, UnpackException
from pyof.v0x01.common.header import Type as OFPTYPE

pyof_version_libs = {0x01: pyof_01,
0x04: pyof_04}


def of_slicer(remaining_data):
"""Slice a raw bytes into OpenFlow packets"""
data_len = len(remaining_data)
Expand All @@ -29,27 +25,6 @@ def of_slicer(remaining_data):
return pkts, remaining_data


def unpack(packet):
"""Unpacks the OpenFlow packet and returns a message."""
version = _unpack_int(packet[0])
try:
pyof_lib = pyof_version_libs[version]
except KeyError:
raise UnpackException('Version not supported')

try:
header = pyof_lib.common.header.Header()
header.unpack(packet[:8])
message = pyof_lib.common.utils.new_message_from_header(header)
binary_data = packet[8:]
if binary_data:
message.unpack(binary_data)
return message
except (UnpackException, ValueError) as e:
log.info('Could not unpack message: %s', packet)
raise UnpackException(e)


def _unpack_int(packet, offset=0, size=None):
if size is None:
if type(packet) == int:
Expand Down