diff options
author | Yusuke Iwase <iwase.yusuke0@gmail.com> | 2015-09-09 10:18:28 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-09-10 11:14:58 +0900 |
commit | f5932480c544c3b3018f8cfd0875adb3edb79d5e (patch) | |
tree | cddaed14920dc46c5672ea3e732a72c1ef952bf4 | |
parent | 23b2fc4b41a755ab1f9b7918c5d45f24291183d4 (diff) |
ofproto_parser: Unify str representation of MsgBase
This patch unifies str representation of MsgBase into comma-separated
array of 'key=value' style.
before:
version: 0x1 msg_type 0x0 xid 0x660a4ade OFPHello()
after:
version=0x1,msg_type=0x0,msg_len=0x8,xid=0x660a4ade,OFPHello()
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/ofproto/ofproto_parser.py | 8 | ||||
-rw-r--r-- | ryu/tests/unit/ofproto/test_ofproto_parser.py | 24 |
2 files changed, 15 insertions, 17 deletions
diff --git a/ryu/ofproto/ofproto_parser.py b/ryu/ofproto/ofproto_parser.py index 40495034..360e938c 100644 --- a/ryu/ofproto/ofproto_parser.py +++ b/ryu/ofproto/ofproto_parser.py @@ -171,10 +171,10 @@ class MsgBase(StringifyMixin): def __str__(self): def hexify(x): - return str(None) if x is None else '0x%x' % x - buf = 'version: %s msg_type %s xid %s ' % (hexify(self.version), - hexify(self.msg_type), - hexify(self.xid)) + return hex(x) if isinstance(x, int) else x + buf = 'version=%s,msg_type=%s,msg_len=%s,xid=%s,' %\ + (hexify(self.version), hexify(self.msg_type), + hexify(self.msg_len), hexify(self.xid)) return buf + StringifyMixin.__str__(self) @classmethod diff --git a/ryu/tests/unit/ofproto/test_ofproto_parser.py b/ryu/tests/unit/ofproto/test_ofproto_parser.py index 7f2d6048..bc3c1fd1 100644 --- a/ryu/tests/unit/ofproto/test_ofproto_parser.py +++ b/ryu/tests/unit/ofproto/test_ofproto_parser.py @@ -185,20 +185,18 @@ class TestMsgBase(unittest.TestCase): eq_(buffer(buf), res.buf) # test __str__() - list_ = ('version:', 'msg_type', 'xid') + list_ = ('version', 'msg_type', 'msg_len', 'xid') check = {} - str_ = str(res) - str_ = str_.rsplit() - - i = 0 - for s in str_: - if s in list_: - check[str_[i]] = str_[i + 1] - i += 1 - - eq_(hex(ofproto_v1_0.OFP_VERSION).find(check['version:']), 0) - eq_(hex(ofproto_v1_0.OFPT_HELLO).find(check['msg_type']), 0) - eq_(hex(xid).find(check['xid']), 0) + for s in str(res).rsplit(','): + if '=' in s: + (k, v,) = s.rsplit('=') + if k in list_: + check[k] = v + + eq_(hex(ofproto_v1_0.OFP_VERSION), check['version']) + eq_(hex(ofproto_v1_0.OFPT_HELLO), check['msg_type']) + eq_(hex(msg_len), check['msg_len']) + eq_(hex(xid), check['xid']) return True |