diff options
author | Simon Horman <horms@verge.net.au> | 2014-01-29 12:06:17 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-01-29 12:43:25 +0900 |
commit | 58458a37db6fc1c1b06b4f9345e430aa21f19c0f (patch) | |
tree | 19796b68890756695bf0eac11fa555123cac0850 | |
parent | d2c7855c5446d133356f166b65d0fb1fa583ba9c (diff) |
Add OF1.4 group desc stats request and reply message support
Signed-off-by: Simon Horman <horms@verge.net.au>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/ofproto/ofproto_v1_4.py | 5 | ||||
-rw-r--r-- | ryu/ofproto/ofproto_v1_4_parser.py | 85 |
2 files changed, 90 insertions, 0 deletions
diff --git a/ryu/ofproto/ofproto_v1_4.py b/ryu/ofproto/ofproto_v1_4.py index 48526bf1..70f7b45f 100644 --- a/ryu/ofproto/ofproto_v1_4.py +++ b/ryu/ofproto/ofproto_v1_4.py @@ -1128,6 +1128,11 @@ OFP_BUCKET_COUNTER_PACK_STR = '!QQ' OFP_BUCKET_COUNTER_SIZE = 16 assert calcsize(OFP_BUCKET_COUNTER_PACK_STR) == OFP_BUCKET_COUNTER_SIZE +# struct ofp_group_desc_stats +OFP_GROUP_DESC_STATS_PACK_STR = '!HBxI' +OFP_GROUP_DESC_STATS_SIZE = 8 +assert calcsize(OFP_GROUP_DESC_STATS_PACK_STR) == OFP_GROUP_DESC_STATS_SIZE + # struct ofp_group_stats OFP_GROUP_STATS_PACK_STR = '!H2xII4xQQII' OFP_GROUP_STATS_SIZE = 40 diff --git a/ryu/ofproto/ofproto_v1_4_parser.py b/ryu/ofproto/ofproto_v1_4_parser.py index e09b83ed..b5716c96 100644 --- a/ryu/ofproto/ofproto_v1_4_parser.py +++ b/ryu/ofproto/ofproto_v1_4_parser.py @@ -1838,6 +1838,91 @@ class OFPGroupStatsReply(OFPMultipartReply): super(OFPGroupStatsReply, self).__init__(datapath, **kwargs) +class OFPGroupDescStats(StringifyMixin): + def __init__(self, type_=None, group_id=None, buckets=None, length=None): + super(OFPGroupDescStats, self).__init__() + self.type = type_ + self.group_id = group_id + self.buckets = buckets + + @classmethod + def parser(cls, buf, offset): + stats = cls() + + (stats.length, stats.type, stats.group_id) = struct.unpack_from( + ofproto.OFP_GROUP_DESC_STATS_PACK_STR, buf, offset) + offset += ofproto.OFP_GROUP_DESC_STATS_SIZE + + stats.buckets = [] + length = ofproto.OFP_GROUP_DESC_STATS_SIZE + while length < stats.length: + bucket = OFPBucket.parser(buf, offset) + stats.buckets.append(bucket) + + offset += bucket.len + length += bucket.len + + return stats + + +@_set_stats_type(ofproto.OFPMP_GROUP_DESC, OFPGroupDescStats) +@_set_msg_type(ofproto.OFPT_MULTIPART_REQUEST) +class OFPGroupDescStatsRequest(OFPMultipartRequest): + """ + Group description request message + + The controller uses this message to list the set of groups on a switch. + + ================ ====================================================== + Attribute Description + ================ ====================================================== + flags Zero or ``OFPMPF_REQ_MORE`` + ================ ====================================================== + + Example:: + + def send_group_desc_stats_request(self, datapath): + ofp = datapath.ofproto + ofp_parser = datapath.ofproto_parser + + req = ofp_parser.OFPGroupDescStatsRequest(datapath, 0) + datapath.send_msg(req) + """ + def __init__(self, datapath, flags, type_=None): + super(OFPGroupDescStatsRequest, self).__init__(datapath, flags) + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto.OFPMP_GROUP_DESC, OFPGroupDescStats) +@_set_msg_type(ofproto.OFPT_MULTIPART_REPLY) +class OFPGroupDescStatsReply(OFPMultipartReply): + """ + Group description reply message + + The switch responds with this message to a group description request. + + ================ ====================================================== + Attribute Description + ================ ====================================================== + body List of ``OFPGroupDescStats`` instance + ================ ====================================================== + + Example:: + + @set_ev_cls(ofp_event.EventOFPGroupDescStatsReply, MAIN_DISPATCHER) + def group_desc_stats_reply_handler(self, ev): + descs = [] + for stat in ev.msg.body: + descs.append('length=%d type=%d group_id=%d ' + 'buckets=%s' % + (stat.length, stat.type, stat.group_id, + stat.bucket)) + self.logger.debug('GroupDescStats: %s', groups) + """ + def __init__(self, datapath, type_=None, **kwargs): + super(OFPGroupDescStatsReply, self).__init__(datapath, **kwargs) + + class OFPGroupFeaturesStats(ofproto_parser.namedtuple('OFPGroupFeaturesStats', ('types', 'capabilities', 'max_groups', 'actions'))): |