diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2016-05-10 14:29:40 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-05-13 22:25:21 +0900 |
commit | 9dd3b3ce4acde6398163cc01e5b2a0e176d56aa2 (patch) | |
tree | b21cd22049cffe923811f2a8e34214ed81f5ca99 | |
parent | c1047818d3ce907b8a606719d650a0a982a5645e (diff) |
ofctl_utils: Enhance user value conversion
Currently, OFCtlUtil._reserved_num_from_user() fails to convert
an user specified value when it is a numeric string.
This patch enhances this conversion to enable to convert an user
value as follows.
e.g.)
- Integer: 1 -> 1
- Numeric string: "1" -> 1
- Reserved number: "OFPP_ANY" -> 0xffffffff
- Invalid value: "foobar" -> "foobar" (do not conversion)
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/ofctl_utils.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/ryu/lib/ofctl_utils.py b/ryu/lib/ofctl_utils.py index b5fbc9b8..832baf0b 100644 --- a/ryu/lib/ofctl_utils.py +++ b/ryu/lib/ofctl_utils.py @@ -240,13 +240,18 @@ class OFCtlUtil(object): 'OFPQCFC_EPERM'] def _reserved_num_from_user(self, num, prefix): - if isinstance(num, int): - return num - else: - if num.startswith(prefix): - return getattr(self.ofproto, num) - else: - return getattr(self.ofproto, prefix + num.upper()) + try: + return str_to_int(num) + except ValueError: + try: + if num.startswith(prefix): + return getattr(self.ofproto, num.upper()) + else: + return getattr(self.ofproto, prefix + num.upper()) + except AttributeError: + LOG.warning( + "Cannot convert argument to reserved number: %s", num) + return num def _reserved_num_to_user(self, num, prefix): for k, v in self.ofproto.__dict__.items(): |