summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ryu/ofproto/ofproto_v1_0_parser.py68
1 files changed, 42 insertions, 26 deletions
diff --git a/ryu/ofproto/ofproto_v1_0_parser.py b/ryu/ofproto/ofproto_v1_0_parser.py
index 8bca9e9a..ebb74c1d 100644
--- a/ryu/ofproto/ofproto_v1_0_parser.py
+++ b/ryu/ofproto/ofproto_v1_0_parser.py
@@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import collections
import struct
import binascii
@@ -79,7 +78,7 @@ def _set_msg_reply(msg_reply):
# common structures
#
-class OFPPhyPort(collections.namedtuple('OFPPhyPort', (
+class OFPPhyPort(ofproto_parser.namedtuple('OFPPhyPort', (
'port_no', 'hw_addr', 'name', 'config', 'state', 'curr', 'advertised',
'supported', 'peer'))):
@@ -196,6 +195,8 @@ class OFPMatch(StringifyMixin):
class OFPActionHeader(StringifyMixin):
+ _base_attributes = ['type', 'len']
+
def __init__(self, type_, len_):
self.type = type_
self.len = len_
@@ -970,7 +971,7 @@ class NXActionFinTimeout(NXActionHeader):
return cls(fin_idle_timeout, fin_hard_timeout)
-class OFPDescStats(collections.namedtuple('OFPDescStats', (
+class OFPDescStats(ofproto_parser.namedtuple('OFPDescStats', (
'mfr_desc', 'hw_desc', 'sw_desc', 'serial_num', 'dp_desc'))):
@classmethod
def parser(cls, buf, offset):
@@ -1031,7 +1032,7 @@ class OFPFlowStats(StringifyMixin):
return flow_stats
-class OFPAggregateStats(collections.namedtuple('OFPAggregateStats', (
+class OFPAggregateStats(ofproto_parser.namedtuple('OFPAggregateStats', (
'packet_count', 'byte_count', 'flow_count'))):
@classmethod
def parser(cls, buf, offset):
@@ -1042,7 +1043,7 @@ class OFPAggregateStats(collections.namedtuple('OFPAggregateStats', (
return stats
-class OFPTableStats(collections.namedtuple('OFPTableStats', (
+class OFPTableStats(ofproto_parser.namedtuple('OFPTableStats', (
'table_id', 'name', 'wildcards', 'max_entries', 'active_count',
'lookup_count', 'matched_count'))):
@classmethod
@@ -1054,7 +1055,7 @@ class OFPTableStats(collections.namedtuple('OFPTableStats', (
return stats
-class OFPPortStats(collections.namedtuple('OFPPortStats', (
+class OFPPortStats(ofproto_parser.namedtuple('OFPPortStats', (
'port_no', 'rx_packets', 'tx_packets', 'rx_bytes', 'tx_bytes',
'rx_dropped', 'tx_dropped', 'rx_errors', 'tx_errors',
'rx_frame_err', 'rx_over_err', 'rx_crc_err', 'collisions'))):
@@ -1067,7 +1068,7 @@ class OFPPortStats(collections.namedtuple('OFPPortStats', (
return stats
-class OFPQueueStats(collections.namedtuple('OFPQueueStats', (
+class OFPQueueStats(ofproto_parser.namedtuple('OFPQueueStats', (
'port_no', 'queue_id', 'tx_bytes', 'tx_packets', 'tx_errors'))):
@classmethod
def parser(cls, buf, offset):
@@ -1078,8 +1079,8 @@ class OFPQueueStats(collections.namedtuple('OFPQueueStats', (
return stats
-class OFPVendorStats(collections.namedtuple('OFPVendorStats',
- ('specific_data'))):
+class OFPVendorStats(ofproto_parser.namedtuple('OFPVendorStats',
+ ('specific_data'))):
@classmethod
def parser(cls, buf, offset):
stats = cls(buf[offset:])
@@ -1141,7 +1142,7 @@ class NXFlowStats(StringifyMixin):
return nxflow_stats
-class NXAggregateStats(collections.namedtuple('NXAggregateStats', (
+class NXAggregateStats(ofproto_parser.namedtuple('NXAggregateStats', (
'packet_count', 'byte_count', 'flow_count'))):
@classmethod
def parser(cls, buf, offset):
@@ -1248,11 +1249,11 @@ class OFPHello(MsgBase):
@_register_parser
@_set_msg_type(ofproto_v1_0.OFPT_ERROR)
class OFPErrorMsg(MsgBase):
- def __init__(self, datapath):
+ def __init__(self, datapath, type_=None, code=None, data=None):
super(OFPErrorMsg, self).__init__(datapath)
- self.type = None
- self.code = None
- self.data = None
+ self.type = type_
+ self.code = code
+ self.data = data
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
@@ -1274,9 +1275,9 @@ class OFPErrorMsg(MsgBase):
@_register_parser
@_set_msg_type(ofproto_v1_0.OFPT_ECHO_REQUEST)
class OFPEchoRequest(MsgBase):
- def __init__(self, datapath):
+ def __init__(self, datapath, data=None):
super(OFPEchoRequest, self).__init__(datapath)
- self.data = None
+ self.data = data
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
@@ -1293,9 +1294,9 @@ class OFPEchoRequest(MsgBase):
@_register_parser
@_set_msg_type(ofproto_v1_0.OFPT_ECHO_REPLY)
class OFPEchoReply(MsgBase):
- def __init__(self, datapath):
+ def __init__(self, datapath, data=None):
super(OFPEchoReply, self).__init__(datapath)
- self.data = None
+ self.data = data
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
@@ -1609,8 +1610,15 @@ class NXTSetControllerId(NiciraHeader):
@_register_parser
@_set_msg_type(ofproto_v1_0.OFPT_FEATURES_REPLY)
class OFPSwitchFeatures(MsgBase):
- def __init__(self, datapath):
+ def __init__(self, datapath, datapath_id=None, n_buffers=None,
+ n_tables=None, capabilities=None, actions=None, ports=None):
super(OFPSwitchFeatures, self).__init__(datapath)
+ self.datapath_id = datapath_id
+ self.n_buffers = n_buffers
+ self.n_tables = n_tables
+ self.capabilities = capabilities
+ self.actions = actions
+ self.ports = ports
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
@@ -1640,8 +1648,10 @@ class OFPSwitchFeatures(MsgBase):
@_register_parser
@_set_msg_type(ofproto_v1_0.OFPT_PORT_STATUS)
class OFPPortStatus(MsgBase):
- def __init__(self, datapath):
+ def __init__(self, datapath, reason=None, desc=None):
super(OFPPortStatus, self).__init__(datapath)
+ self.reason = reason
+ self.desc = desc
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
@@ -1658,8 +1668,14 @@ class OFPPortStatus(MsgBase):
@_register_parser
@_set_msg_type(ofproto_v1_0.OFPT_PACKET_IN)
class OFPPacketIn(MsgBase):
- def __init__(self, datapath):
+ def __init__(self, datapath, buffer_id=None, total_len=None, in_port=None,
+ reason=None, data=None):
super(OFPPacketIn, self).__init__(datapath)
+ self.buffer_id = buffer_id
+ self.total_len = total_len
+ self.in_port = in_port
+ self.reason = reason
+ self.data = data
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
@@ -2015,22 +2031,22 @@ class OFPPacketOut(MsgBase):
super(OFPPacketOut, self).__init__(datapath)
self.buffer_id = buffer_id
self.in_port = in_port
- self.actions_len = None
+ self._actions_len = None
self.actions = actions
self.data = data
def _serialize_body(self):
assert self.buffer_id is not None
assert self.in_port is not None
- assert self.actions_len is None
+ assert self._actions_len is None
assert self.actions is not None
- self.actions_len = 0
+ self._actions_len = 0
offset = ofproto_v1_0.OFP_PACKET_OUT_SIZE
for a in self.actions:
a.serialize(self.buf, offset)
offset += a.len
- self.actions_len += a.len
+ self._actions_len += a.len
if self.data is not None:
assert self.buffer_id == 0xffffffff
@@ -2038,7 +2054,7 @@ class OFPPacketOut(MsgBase):
msg_pack_into(ofproto_v1_0.OFP_PACKET_OUT_PACK_STR,
self.buf, ofproto_v1_0.OFP_HEADER_SIZE,
- self.buffer_id, self.in_port, self.actions_len)
+ self.buffer_id, self.in_port, self._actions_len)
@_set_msg_type(ofproto_v1_0.OFPT_FLOW_MOD)