On Sat, May 19, 2012 at 10:07:55PM +0900, FUJITA Tomonori wrote: > On Fri, 18 May 2012 10:22:09 +0900 (JST) > FUJITA Tomonori <[email protected]> wrote: > > > On Fri, 18 May 2012 10:01:21 +0900 > > Isaku Yamahata <[email protected]> wrote: > > > >> On Thu, May 17, 2012 at 11:28:36PM +0900, FUJITA Tomonori wrote: > >>> OFPStatsReply needs to handle variable-length bodys (flow stats) so > >>> having two parsers (parser_stats_body_array and parser_stats_body) > >>> doesn't make sense. Just kill parser_stats_body_array(). > >> > >> The returned type for struct ofp_stats_request are classified in 2 cases. > >> > >> - single sturct > >> struct ofp_desc_stats > >> > >> - array of struct > >> struct ofp_flow_stats, struct ofp_aggregate_stats_reply > >> struct ofp_port_stats, struct ofp_queue_stats > > > > Yeah, and I don't see any problem about always handling struct as an > > array. ofp_desc_stats is just a single array. > > ok, if we had better to keep the data structure for ofp_desc_stats, > how about the following?
Looks good. Reviewed-by: Isaku Yamahata <[email protected]> > = > From 0326b4ca547dace469165a121aa75094ac67d501 Mon Sep 17 00:00:00 2001 > From: FUJITA Tomonori <[email protected]> > Date: Sat, 19 May 2012 21:50:42 +0900 > Subject: [PATCH] Kill parser_stats_body_array method in OFPFlowStats class > > OFPStatsReply needs to handle variable-length bodys so having two > parsers (parser_stats_body_array and parser_stats_body) doesn't make > sense. Just kill parser_stats_body_array(). > > cls_stats_body_cls_size is also pointless since OFPStatsReply needs to > handle variable-length bodys. OFPStatsReply class needs to know if a > stats class is array or not. So register_stats_type takes > 'body_single_struct' instead of body_cls_size. We need to change this > scheme if we need to handle VendorStats in the same way (both array > and single struct). But currently we don't even have any VendorStats > implementation so let's invent something more complicated when it > becomes necessary. > > Signed-off-by: FUJITA Tomonori <[email protected]> > --- > ryu/ofproto/ofproto_v1_0_parser.py | 29 ++++++++++++----------------- > 1 files changed, 12 insertions(+), 17 deletions(-) > > diff --git a/ryu/ofproto/ofproto_v1_0_parser.py > b/ryu/ofproto/ofproto_v1_0_parser.py > index ad7a893..b7c8638 100644 > --- a/ryu/ofproto/ofproto_v1_0_parser.py > +++ b/ryu/ofproto/ofproto_v1_0_parser.py > @@ -1260,12 +1260,12 @@ class OFPStatsReply(MsgBase): > _STATS_MSG_TYPES = {} > > @staticmethod > - def register_stats_type(body_cls_size=0): > + def register_stats_type(body_single_struct=False): > def _register_stats_type(cls): > assert cls.cls_stats_type is not None > assert cls.cls_stats_type not in OFPStatsReply._STATS_MSG_TYPES > assert cls.cls_stats_body_cls is not None > - cls.cls_stats_body_cls_size = body_cls_size > + cls.cls_body_single_struct = body_single_struct > OFPStatsReply._STATS_MSG_TYPES[cls.cls_stats_type] = cls > return cls > return _register_stats_type > @@ -1277,22 +1277,17 @@ class OFPStatsReply(MsgBase): > self.body = None > > @classmethod > - def parser_stats_body_array(cls, buf, msg_len, offset, entry_size): > + def parser_stats_body(cls, buf, msg_len, offset): > body_cls = cls.cls_stats_body_cls > body = [] > while offset < msg_len: > entry = body_cls.parser(buf, offset) > body.append(entry) > offset += entry.length > - return body > - > - @classmethod > - def parser_stats_body(cls, buf, msg_len, offset): > - if cls.cls_stats_body_cls_size == 0: > - return cls.cls_stats_body_cls.parser(buf, offset) > > - return cls.parser_stats_body_array(buf, msg_len, offset, > - cls.cls_stats_body_cls_size) > + if cls.cls_body_single_struct: > + return body[0] > + return body > > @classmethod > def parser_stats(cls, datapath, version, msg_type, msg_len, xid, buf): > @@ -1316,7 +1311,7 @@ class OFPStatsReply(MsgBase): > return msg > > > [email protected]_stats_type() > [email protected]_stats_type(body_single_struct=True) > @_set_stats_type(ofproto_v1_0.OFPST_DESC, OFPDescStats) > @_set_msg_type(ofproto_v1_0.OFPT_STATS_REPLY) > class OFPDescStatsReply(OFPStatsReply): > @@ -1324,7 +1319,7 @@ class OFPDescStatsReply(OFPStatsReply): > super(OFPDescStatsReply, self).__init__(datapath) > > > [email protected]_stats_type(ofproto_v1_0.OFP_FLOW_STATS_SIZE) > [email protected]_stats_type() > @_set_stats_type(ofproto_v1_0.OFPST_FLOW, OFPFlowStats) > @_set_msg_type(ofproto_v1_0.OFPT_STATS_REPLY) > class OFPFlowStatsReply(OFPStatsReply): > @@ -1332,7 +1327,7 @@ class OFPFlowStatsReply(OFPStatsReply): > super(OFPFlowStatsReply, self).__init__(datapath) > > > [email protected]_stats_type(ofproto_v1_0.OFP_AGGREGATE_STATS_REPLY_SIZE) > [email protected]_stats_type() > @_set_stats_type(ofproto_v1_0.OFPST_AGGREGATE, OFPAggregateStats) > @_set_msg_type(ofproto_v1_0.OFPT_STATS_REPLY) > class OFPAggregateStatsReply(OFPStatsReply): > @@ -1340,7 +1335,7 @@ class OFPAggregateStatsReply(OFPStatsReply): > super(OFPAggregateStatsReply, self).__init__(datapath) > > > [email protected]_stats_type(ofproto_v1_0.OFP_TABLE_STATS_SIZE) > [email protected]_stats_type() > @_set_stats_type(ofproto_v1_0.OFPST_TABLE, OFPTableStats) > @_set_msg_type(ofproto_v1_0.OFPT_STATS_REPLY) > class OFPTableStatsReply(OFPStatsReply): > @@ -1348,7 +1343,7 @@ class OFPTableStatsReply(OFPStatsReply): > super(OFPTableStatsReply, self).__init__(datapath) > > > [email protected]_stats_type(ofproto_v1_0.OFP_PORT_STATS_SIZE) > [email protected]_stats_type() > @_set_stats_type(ofproto_v1_0.OFPST_PORT, OFPPortStats) > @_set_msg_type(ofproto_v1_0.OFPT_STATS_REPLY) > class OFPPortStatsReply(OFPStatsReply): > @@ -1356,7 +1351,7 @@ class OFPPortStatsReply(OFPStatsReply): > super(OFPPortStatsReply, self).__init__(datapath) > > > [email protected]_stats_type(ofproto_v1_0.OFP_QUEUE_STATS_SIZE) > [email protected]_stats_type() > @_set_stats_type(ofproto_v1_0.OFPST_QUEUE, OFPQueueStats) > @_set_msg_type(ofproto_v1_0.OFPT_STATS_REPLY) > class OFPQueueStatsReply(OFPStatsReply): > -- > 1.7.4.4 > -- yamahata ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
