From 45fa75afba7a709f3a0151f844beed18c16b7a2d Mon Sep 17 00:00:00 2001 From: OHMURA Kei Date: Sun, 28 Apr 2013 11:24:44 +0900 Subject: of1.0: add nx_aggregate_stats support Signed-off-by: OHMURA Kei Signed-off-by: FUJITA Tomonori --- ryu/ofproto/ofproto_v1_0.py | 10 ++++++++++ ryu/ofproto/ofproto_v1_0_parser.py | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/ryu/ofproto/ofproto_v1_0.py b/ryu/ofproto/ofproto_v1_0.py index ca6e384a..1b4c4143 100644 --- a/ryu/ofproto/ofproto_v1_0.py +++ b/ryu/ofproto/ofproto_v1_0.py @@ -669,6 +669,16 @@ NX_FLOW_STATS_PACK_STR = '!HBxIIHHHHHHQQQ' NX_FLOW_STATS_SIZE = 48 assert calcsize(NX_FLOW_STATS_PACK_STR) == NX_FLOW_STATS_SIZE +NX_AGGREGATE_STATS_REQUEST_PACK_STR = '!2HB3x' +NX_AGGREGATE_STATS_REQUEST_SIZE = 8 +assert (calcsize(NX_AGGREGATE_STATS_REQUEST_PACK_STR) == + NX_AGGREGATE_STATS_REQUEST_SIZE) + +NX_AGGREGATE_STATS_REPLY_PACK_STR = '!QQI4x' +NX_AGGREGATE_STATS_REPLY_SIZE = 24 +assert (calcsize(NX_AGGREGATE_STATS_REPLY_PACK_STR) == + NX_AGGREGATE_STATS_REPLY_SIZE) + def nxm_header__(vendor, field, hasmask, length): return (vendor << 16) | (field << 9) | (hasmask << 8) | length diff --git a/ryu/ofproto/ofproto_v1_0_parser.py b/ryu/ofproto/ofproto_v1_0_parser.py index 5b476818..af6428d6 100644 --- a/ryu/ofproto/ofproto_v1_0_parser.py +++ b/ryu/ofproto/ofproto_v1_0_parser.py @@ -1092,6 +1092,18 @@ class NXFlowStats(object): return nxflow_stats +class NXAggregateStats(collections.namedtuple('NXAggregateStats', ( + 'packet_count', 'byte_count', 'flow_count'))): + @classmethod + def parser(cls, buf, offset): + agg = struct.unpack_from( + ofproto_v1_0.NX_AGGREGATE_STATS_REPLY_PACK_STR, buf, offset) + stats = cls(*agg) + stats.length = ofproto_v1_0.NX_AGGREGATE_STATS_REPLY_SIZE + + return stats + + class OFPQueuePropHeader(object): _QUEUE_PROPERTIES = {} @@ -1932,6 +1944,13 @@ class NXFlowStatsReply(NXStatsReply): super(NXFlowStatsReply, self).__init__(datapath) +@NXStatsReply.register_nx_stats_type() +@_set_stats_type(ofproto_v1_0.NXST_AGGREGATE, NXAggregateStats) +class NXAggregateStatsReply(NXStatsReply): + def __init__(self, datapath): + super(NXAggregateStatsReply, self).__init__(datapath) + + # # controller-to-switch message # serializer only @@ -2225,3 +2244,25 @@ class NXFlowStatsRequest(NXStatsRequest): ofproto_v1_0.NX_FLOW_STATS_REQUEST_PACK_STR, self.buf, ofproto_v1_0.NX_STATS_MSG_SIZE, self.out_port, self.match_len, self.table_id) + + +class NXAggregateStatsRequest(NXStatsRequest): + def __init__(self, datapath, flags, out_port, table_id, rule=None): + super(NXAggregateStatsRequest, self).__init__( + datapath, flags, ofproto_v1_0.NXST_AGGREGATE) + self.out_port = out_port + self.table_id = table_id + self.rule = rule + self.match_len = 0 + + def _serialize_vendor_stats_body(self): + if self.rule is not None: + offset = ofproto_v1_0.NX_STATS_MSG_SIZE + \ + ofproto_v1_0.NX_AGGREGATE_STATS_REQUEST_SIZE + self.match_len = nx_match.serialize_nxm_match( + self.rule, self.buf, offset) + + msg_pack_into( + ofproto_v1_0.NX_AGGREGATE_STATS_REQUEST_PACK_STR, + self.buf, ofproto_v1_0.NX_STATS_MSG_SIZE, self.out_port, + self.match_len, self.table_id) -- cgit v1.2.3