summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorShinpei Muraoka <shinpei.muraoka@gmail.com>2016-08-22 10:02:28 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-08-25 13:30:45 +0900
commitcb4c0b87dbc87b16f91a9f9377a8638a922058e0 (patch)
tree1048c5f3fde302f6fe12cfadcfd4da4088c20950
parent59ea6a5231b443bfb1ef8e46eb0eed41622e7bd5 (diff)
ofproto: Enable to specify packet library for OFPPacketOut.data
So far if you set the packet library to OFPPacketOut.data, error occurred. This patch will be able to set the packet library in OFPPacketOut.data. Signed-off-by: Shinpei Muraoka <shinpei.muraoka@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/ofproto/ofproto_v1_0_parser.py30
-rw-r--r--ryu/ofproto/ofproto_v1_2_parser.py31
-rw-r--r--ryu/ofproto/ofproto_v1_3_parser.py31
-rw-r--r--ryu/ofproto/ofproto_v1_4_parser.py31
-rw-r--r--ryu/ofproto/ofproto_v1_5_parser.py31
5 files changed, 139 insertions, 15 deletions
diff --git a/ryu/ofproto/ofproto_v1_0_parser.py b/ryu/ofproto/ofproto_v1_0_parser.py
index a34564b5..1c10bdae 100644
--- a/ryu/ofproto/ofproto_v1_0_parser.py
+++ b/ryu/ofproto/ofproto_v1_0_parser.py
@@ -19,7 +19,8 @@ Decoder/Encoder implementations of OpenFlow 1.0.
"""
import struct
-import binascii
+import base64
+
import six
import netaddr
@@ -27,6 +28,7 @@ from ryu.ofproto.ofproto_parser import StringifyMixin, MsgBase
from ryu.lib import addrconv
from ryu.lib import ip
from ryu.lib import mac
+from ryu.lib.packet import packet
from ryu.lib.pack_utils import msg_pack_into
from ryu.ofproto import nx_match
from ryu.ofproto import ofproto_common
@@ -2605,7 +2607,8 @@ class OFPPacketOut(MsgBase):
buffer_id ID assigned by datapath (0xffffffff if none).
in_port Packet's input port (OFPP_NONE if none).
actions ist of ``OFPAction*`` instance.
- data Packet data.
+ data Packet data of a binary type value or
+ an instances of packet.Packet.
================ ======================================================
Example::
@@ -2644,12 +2647,33 @@ class OFPPacketOut(MsgBase):
if self.data is not None:
assert self.buffer_id == 0xffffffff
- self.buf += self.data
+ if isinstance(self.data, packet.Packet):
+ self.data.serialize()
+ self.buf += self.data.data
+ else:
+ self.buf += self.data
msg_pack_into(ofproto.OFP_PACKET_OUT_PACK_STR,
self.buf, ofproto.OFP_HEADER_SIZE,
self.buffer_id, self.in_port, self._actions_len)
+ @classmethod
+ def from_jsondict(cls, dict_, decode_string=base64.b64decode,
+ **additional_args):
+ if isinstance(dict_['data'], dict):
+ data = dict_.pop('data')
+ ins = super(OFPPacketOut, cls).from_jsondict(dict_,
+ decode_string,
+ **additional_args)
+ ins.data = packet.Packet.from_jsondict(data['Packet'])
+ dict_['data'] = data
+ else:
+ ins = super(OFPPacketOut, cls).from_jsondict(dict_,
+ decode_string,
+ **additional_args)
+
+ return ins
+
@_register_parser
@_set_msg_type(ofproto.OFPT_FLOW_MOD)
diff --git a/ryu/ofproto/ofproto_v1_2_parser.py b/ryu/ofproto/ofproto_v1_2_parser.py
index b755499c..ddb56f3f 100644
--- a/ryu/ofproto/ofproto_v1_2_parser.py
+++ b/ryu/ofproto/ofproto_v1_2_parser.py
@@ -18,12 +18,15 @@
Decoder/Encoder implementations of OpenFlow 1.2.
"""
-import six
import struct
+import base64
+
+import six
from ryu.lib import addrconv
from ryu.lib import mac
from ryu.lib.pack_utils import msg_pack_into
+from ryu.lib.packet import packet
from ryu import utils
from ryu.ofproto.ofproto_parser import StringifyMixin, MsgBase
from ryu.ofproto import ether
@@ -818,7 +821,8 @@ class OFPPacketOut(MsgBase):
buffer_id ID assigned by datapath (OFP_NO_BUFFER if none)
in_port Packet's input port or ``OFPP_CONTROLLER``
actions list of OpenFlow action class
- data Packet data
+ data Packet data of a binary type value or
+ an instances of packet.Packet.
================ ======================================================
Example::
@@ -855,12 +859,33 @@ class OFPPacketOut(MsgBase):
if self.data is not None:
assert self.buffer_id == 0xffffffff
- self.buf += self.data
+ if isinstance(self.data, packet.Packet):
+ self.data.serialize()
+ self.buf += self.data.data
+ else:
+ self.buf += self.data
msg_pack_into(ofproto.OFP_PACKET_OUT_PACK_STR,
self.buf, ofproto.OFP_HEADER_SIZE,
self.buffer_id, self.in_port, self.actions_len)
+ @classmethod
+ def from_jsondict(cls, dict_, decode_string=base64.b64decode,
+ **additional_args):
+ if isinstance(dict_['data'], dict):
+ data = dict_.pop('data')
+ ins = super(OFPPacketOut, cls).from_jsondict(dict_,
+ decode_string,
+ **additional_args)
+ ins.data = packet.Packet.from_jsondict(data['Packet'])
+ dict_['data'] = data
+ else:
+ ins = super(OFPPacketOut, cls).from_jsondict(dict_,
+ decode_string,
+ **additional_args)
+
+ return ins
+
@_register_parser
@_set_msg_type(ofproto.OFPT_FLOW_MOD)
diff --git a/ryu/ofproto/ofproto_v1_3_parser.py b/ryu/ofproto/ofproto_v1_3_parser.py
index 067ae19c..99c4a47b 100644
--- a/ryu/ofproto/ofproto_v1_3_parser.py
+++ b/ryu/ofproto/ofproto_v1_3_parser.py
@@ -40,12 +40,15 @@ The following extensions are not implemented yet.
- EXT-192-v Vacancy events Extension
"""
-import six
import struct
+import base64
+
+import six
from ryu.lib import addrconv
from ryu.lib import mac
from ryu.lib.pack_utils import msg_pack_into
+from ryu.lib.packet import packet
from ryu import utils
from ryu.ofproto.ofproto_parser import StringifyMixin, MsgBase
from ryu.ofproto import ether
@@ -2503,7 +2506,8 @@ class OFPPacketOut(MsgBase):
buffer_id ID assigned by datapath (OFP_NO_BUFFER if none)
in_port Packet's input port or ``OFPP_CONTROLLER``
actions list of OpenFlow action class
- data Packet data
+ data Packet data of a binary type value or
+ an instances of packet.Packet.
================ ======================================================
Example::
@@ -2538,12 +2542,33 @@ class OFPPacketOut(MsgBase):
if self.data is not None:
assert self.buffer_id == 0xffffffff
- self.buf += self.data
+ if isinstance(self.data, packet.Packet):
+ self.data.serialize()
+ self.buf += self.data.data
+ else:
+ self.buf += self.data
msg_pack_into(ofproto.OFP_PACKET_OUT_PACK_STR,
self.buf, ofproto.OFP_HEADER_SIZE,
self.buffer_id, self.in_port, self.actions_len)
+ @classmethod
+ def from_jsondict(cls, dict_, decode_string=base64.b64decode,
+ **additional_args):
+ if isinstance(dict_['data'], dict):
+ data = dict_.pop('data')
+ ins = super(OFPPacketOut, cls).from_jsondict(dict_,
+ decode_string,
+ **additional_args)
+ ins.data = packet.Packet.from_jsondict(data['Packet'])
+ dict_['data'] = data
+ else:
+ ins = super(OFPPacketOut, cls).from_jsondict(dict_,
+ decode_string,
+ **additional_args)
+
+ return ins
+
@_register_parser
@_set_msg_type(ofproto.OFPT_FLOW_MOD)
diff --git a/ryu/ofproto/ofproto_v1_4_parser.py b/ryu/ofproto/ofproto_v1_4_parser.py
index 50acb3b7..31379c85 100644
--- a/ryu/ofproto/ofproto_v1_4_parser.py
+++ b/ryu/ofproto/ofproto_v1_4_parser.py
@@ -18,11 +18,14 @@
Decoder/Encoder implementations of OpenFlow 1.4.
"""
-import six
import struct
+import base64
+
+import six
from ryu.lib import addrconv
from ryu.lib.pack_utils import msg_pack_into
+from ryu.lib.packet import packet
from ryu import utils
from ryu.ofproto.ofproto_parser import StringifyMixin, MsgBase, MsgInMsgBase
from ryu.ofproto import ether
@@ -4171,7 +4174,8 @@ class OFPPacketOut(MsgBase):
buffer_id ID assigned by datapath (OFP_NO_BUFFER if none)
in_port Packet's input port or ``OFPP_CONTROLLER``
actions list of OpenFlow action class
- data Packet data
+ data Packet data of a binary type value or
+ an instances of packet.Packet.
================ ======================================================
Example::
@@ -4206,12 +4210,33 @@ class OFPPacketOut(MsgBase):
if self.data is not None:
assert self.buffer_id == 0xffffffff
- self.buf += self.data
+ if isinstance(self.data, packet.Packet):
+ self.data.serialize()
+ self.buf += self.data.data
+ else:
+ self.buf += self.data
msg_pack_into(ofproto.OFP_PACKET_OUT_PACK_STR,
self.buf, ofproto.OFP_HEADER_SIZE,
self.buffer_id, self.in_port, self.actions_len)
+ @classmethod
+ def from_jsondict(cls, dict_, decode_string=base64.b64decode,
+ **additional_args):
+ if isinstance(dict_['data'], dict):
+ data = dict_.pop('data')
+ ins = super(OFPPacketOut, cls).from_jsondict(dict_,
+ decode_string,
+ **additional_args)
+ ins.data = packet.Packet.from_jsondict(data['Packet'])
+ dict_['data'] = data
+ else:
+ ins = super(OFPPacketOut, cls).from_jsondict(dict_,
+ decode_string,
+ **additional_args)
+
+ return ins
+
@_register_parser
@_set_msg_type(ofproto.OFPT_FLOW_MOD)
diff --git a/ryu/ofproto/ofproto_v1_5_parser.py b/ryu/ofproto/ofproto_v1_5_parser.py
index c6fe9867..d34ae0f8 100644
--- a/ryu/ofproto/ofproto_v1_5_parser.py
+++ b/ryu/ofproto/ofproto_v1_5_parser.py
@@ -18,11 +18,14 @@
Decoder/Encoder implementations of OpenFlow 1.5.
"""
-import six
import struct
+import base64
+
+import six
from ryu.lib import addrconv
from ryu.lib.pack_utils import msg_pack_into
+from ryu.lib.packet import packet
from ryu import utils
from ryu.ofproto.ofproto_parser import StringifyMixin, MsgBase, MsgInMsgBase
from ryu.ofproto import ether
@@ -5015,7 +5018,8 @@ class OFPPacketOut(MsgBase):
match Instance of ``OFPMatch``
(``in_port`` is mandatory in the match field)
actions list of OpenFlow action class
- data Packet data
+ data Packet data of a binary type value or
+ an instances of packet.Packet.
================ ======================================================
Example::
@@ -5057,7 +5061,11 @@ class OFPPacketOut(MsgBase):
if self.buffer_id == ofproto.OFP_NO_BUFFER:
assert self.data is not None
- self.buf += self.data
+ if isinstance(self.data, packet.Packet):
+ self.data.serialize()
+ self.buf += self.data.data
+ else:
+ self.buf += self.data
else:
assert self.data is None
@@ -5065,6 +5073,23 @@ class OFPPacketOut(MsgBase):
self.buf, ofproto.OFP_HEADER_SIZE,
self.buffer_id, self.actions_len)
+ @classmethod
+ def from_jsondict(cls, dict_, decode_string=base64.b64decode,
+ **additional_args):
+ if isinstance(dict_['data'], dict):
+ data = dict_.pop('data')
+ ins = super(OFPPacketOut, cls).from_jsondict(dict_,
+ decode_string,
+ **additional_args)
+ ins.data = packet.Packet.from_jsondict(data['Packet'])
+ dict_['data'] = data
+ else:
+ ins = super(OFPPacketOut, cls).from_jsondict(dict_,
+ decode_string,
+ **additional_args)
+
+ return ins
+
@_register_parser
@_set_msg_type(ofproto.OFPT_FLOW_MOD)