From 45762b0d9e78bb5b048c470e76d534c390de30a9 Mon Sep 17 00:00:00 2001 From: Yusuke Iwase Date: Mon, 30 Mar 2015 11:45:30 +0900 Subject: [PATCH] ofctl_v1_[23]: Ignore unkown match fields Currently, ofctl_v1_[23].py adds non-existing match fields when getting unknown match fields, then parser returns KeyError. This patch fixes ofctl_v1_[23].py to ignore unkown match fields and output error messages. Signed-off-by: IWASE Yusuke Signed-off-by: FUJITA Tomonori --- ryu/lib/ofctl_v1_2.py | 28 +++++++++++++++------------- ryu/lib/ofctl_v1_3.py | 28 +++++++++++++++------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py index 1c1ff5da..37f87924 100644 --- a/ryu/lib/ofctl_v1_2.py +++ b/ryu/lib/ofctl_v1_2.py @@ -251,23 +251,25 @@ def to_match(dp, attrs): kwargs = {} for key, value in attrs.items(): - if key in convert: - value = convert[key](value) if key in keys: # For old field name key = keys[key] - if key == 'tp_src' or key == 'tp_dst': - # TCP/UDP port - conv = {inet.IPPROTO_TCP: {'tp_src': 'tcp_src', - 'tp_dst': 'tcp_dst'}, - inet.IPPROTO_UDP: {'tp_src': 'udp_src', - 'tp_dst': 'udp_dst'}} - ip_proto = attrs.get('nw_proto', attrs.get('ip_proto', 0)) - key = conv[ip_proto][key] - kwargs[key] = value + if key in convert: + value = convert[key](value) + if key == 'tp_src' or key == 'tp_dst': + # TCP/UDP port + conv = {inet.IPPROTO_TCP: {'tp_src': 'tcp_src', + 'tp_dst': 'tcp_dst'}, + inet.IPPROTO_UDP: {'tp_src': 'udp_src', + 'tp_dst': 'udp_dst'}} + ip_proto = attrs.get('nw_proto', attrs.get('ip_proto', 0)) + key = conv[ip_proto][key] + kwargs[key] = value + else: + # others + kwargs[key] = value else: - # others - kwargs[key] = value + LOG.error('Unknown match field: %s', key) return dp.ofproto_parser.OFPMatch(**kwargs) diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py index 04bf76dc..84902069 100644 --- a/ryu/lib/ofctl_v1_3.py +++ b/ryu/lib/ofctl_v1_3.py @@ -272,23 +272,25 @@ def to_match(dp, attrs): kwargs = {} for key, value in attrs.items(): - if key in convert: - value = convert[key](value) if key in keys: # For old field name key = keys[key] - if key == 'tp_src' or key == 'tp_dst': - # TCP/UDP port - conv = {inet.IPPROTO_TCP: {'tp_src': 'tcp_src', - 'tp_dst': 'tcp_dst'}, - inet.IPPROTO_UDP: {'tp_src': 'udp_src', - 'tp_dst': 'udp_dst'}} - ip_proto = attrs.get('nw_proto', attrs.get('ip_proto', 0)) - key = conv[ip_proto][key] - kwargs[key] = value + if key in convert: + value = convert[key](value) + if key == 'tp_src' or key == 'tp_dst': + # TCP/UDP port + conv = {inet.IPPROTO_TCP: {'tp_src': 'tcp_src', + 'tp_dst': 'tcp_dst'}, + inet.IPPROTO_UDP: {'tp_src': 'udp_src', + 'tp_dst': 'udp_dst'}} + ip_proto = attrs.get('nw_proto', attrs.get('ip_proto', 0)) + key = conv[ip_proto][key] + kwargs[key] = value + else: + # others + kwargs[key] = value else: - # others - kwargs[key] = value + LOG.error('Unknown match field: %s', key) return dp.ofproto_parser.OFPMatch(**kwargs)