diff options
-rw-r--r-- | ryu/lib/ofctl_utils.py | 20 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_0.py | 53 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_2.py | 109 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_3.py | 117 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_4.py | 101 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_5.py | 113 |
6 files changed, 262 insertions, 251 deletions
diff --git a/ryu/lib/ofctl_utils.py b/ryu/lib/ofctl_utils.py index 91040131..1bf995da 100644 --- a/ryu/lib/ofctl_utils.py +++ b/ryu/lib/ofctl_utils.py @@ -83,7 +83,7 @@ def to_action(dic, ofp, parser, action_type, util): return actions[action_type]() elif action_type in need_ethertype: - ethertype = int(dic.get('ethertype')) + ethertype = str_to_int(dic.get('ethertype')) return need_ethertype[action_type](ethertype) elif action_type == OUTPUT: @@ -92,7 +92,7 @@ def to_action(dic, ofp, parser, action_type, util): return parser.OFPActionOutput(out_port, max_len) elif action_type == SET_MPLS_TTL: - mpls_ttl = int(dic.get('mpls_ttl')) + mpls_ttl = str_to_int(dic.get('mpls_ttl')) return parser.OFPActionSetMplsTtl(mpls_ttl) elif action_type == SET_QUEUE: @@ -104,7 +104,7 @@ def to_action(dic, ofp, parser, action_type, util): return parser.OFPActionGroup(group_id) elif action_type == SET_NW_TTL: - nw_ttl = int(dic.get('nw_ttl')) + nw_ttl = str_to_int(dic.get('nw_ttl')) return parser.OFPActionSetNwTtl(nw_ttl) elif action_type == SET_FIELD: @@ -113,9 +113,9 @@ def to_action(dic, ofp, parser, action_type, util): return parser.OFPActionSetField(**{field: value}) elif action_type == 'COPY_FIELD': - n_bits = int(dic.get('n_bits')) - src_offset = int(dic.get('src_offset')) - dst_offset = int(dic.get('dst_offset')) + n_bits = str_to_int(dic.get('n_bits')) + src_offset = str_to_int(dic.get('src_offset')) + dst_offset = str_to_int(dic.get('dst_offset')) oxm_ids = [parser.OFPOxmId(str(dic.get('src_oxm_id'))), parser.OFPOxmId(str(dic.get('dst_oxm_id')))] return parser.OFPActionCopyField( @@ -124,14 +124,14 @@ def to_action(dic, ofp, parser, action_type, util): elif action_type == 'METER': if hasattr(parser, 'OFPActionMeter'): # OpenFlow 1.5 or later - meter_id = int(dic.get('meter_id')) + meter_id = str_to_int(dic.get('meter_id')) return parser.OFPActionMeter(meter_id) else: # OpenFlow 1.4 or earlier return None elif action_type == EXPERIMENTER: - experimenter = int(dic.get('experimenter')) + experimenter = str_to_int(dic.get('experimenter')) data_type = dic.get('data_type', 'ascii') if data_type not in ('ascii', 'base64'): @@ -182,14 +182,14 @@ def to_match_vid(value, ofpvid_present): else: if '/' in value: val = value.split('/') - return int(val[0], 0), int(val[1], 0) + return str_to_int(val[0]), str_to_int(val[1]) else: if value.isdigit(): # described as decimal string value return int(value, 10) | ofpvid_present - return int(value, 0) + return str_to_int(value) def to_match_masked_int(value): diff --git a/ryu/lib/ofctl_v1_0.py b/ryu/lib/ofctl_v1_0.py index 6ef4a90b..b9a0823f 100644 --- a/ryu/lib/ofctl_v1_0.py +++ b/ryu/lib/ofctl_v1_0.py @@ -27,6 +27,7 @@ LOG = logging.getLogger('ryu.lib.ofctl_v1_0') DEFAULT_TIMEOUT = 1.0 # TODO:XXX UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_0) +str_to_int = ofctl_utils.str_to_int def to_actions(dp, acts): @@ -39,13 +40,13 @@ def to_actions(dp, acts): # NOTE: The reason of this magic number (0xffe5) # is because there is no good constant in of1.0. # The same value as OFPCML_MAX of of1.2 and of1.3 is used. - max_len = int(a.get('max_len', 0xffe5)) + max_len = str_to_int(a.get('max_len', 0xffe5)) actions.append(dp.ofproto_parser.OFPActionOutput(port, max_len)) elif action_type == 'SET_VLAN_VID': - vlan_vid = int(a.get('vlan_vid', 0xffff)) + vlan_vid = str_to_int(a.get('vlan_vid', 0xffff)) actions.append(dp.ofproto_parser.OFPActionVlanVid(vlan_vid)) elif action_type == 'SET_VLAN_PCP': - vlan_pcp = int(a.get('vlan_pcp', 0)) + vlan_pcp = str_to_int(a.get('vlan_pcp', 0)) actions.append(dp.ofproto_parser.OFPActionVlanPcp(vlan_pcp)) elif action_type == 'STRIP_VLAN': actions.append(dp.ofproto_parser.OFPActionStripVlan()) @@ -62,13 +63,13 @@ def to_actions(dp, acts): nw_dst = ipv4_to_int(a.get('nw_dst')) actions.append(dp.ofproto_parser.OFPActionSetNwDst(nw_dst)) elif action_type == 'SET_NW_TOS': - nw_tos = int(a.get('nw_tos', 0)) + nw_tos = str_to_int(a.get('nw_tos', 0)) actions.append(dp.ofproto_parser.OFPActionSetNwTos(nw_tos)) elif action_type == 'SET_TP_SRC': - tp_src = int(a.get('tp_src', 0)) + tp_src = str_to_int(a.get('tp_src', 0)) actions.append(dp.ofproto_parser.OFPActionSetTpSrc(tp_src)) elif action_type == 'SET_TP_DST': - tp_dst = int(a.get('tp_dst', 0)) + tp_dst = str_to_int(a.get('tp_dst', 0)) actions.append(dp.ofproto_parser.OFPActionSetTpDst(tp_dst)) elif action_type == 'ENQUEUE': port = UTIL.ofp_port_from_user( @@ -162,19 +163,19 @@ def to_match(dp, attrs): dl_dst = haddr_to_bin(value) wildcards &= ~ofp.OFPFW_DL_DST elif key == 'dl_vlan': - dl_vlan = int(value) + dl_vlan = str_to_int(value) wildcards &= ~ofp.OFPFW_DL_VLAN elif key == 'dl_vlan_pcp': - dl_vlan_pcp = int(value) + dl_vlan_pcp = str_to_int(value) wildcards &= ~ofp.OFPFW_DL_VLAN_PCP elif key == 'dl_type': - dl_type = int(value) + dl_type = str_to_int(value) wildcards &= ~ofp.OFPFW_DL_TYPE elif key == 'nw_tos': - nw_tos = int(value) + nw_tos = str_to_int(value) wildcards &= ~ofp.OFPFW_NW_TOS elif key == 'nw_proto': - nw_proto = int(value) + nw_proto = str_to_int(value) wildcards &= ~ofp.OFPFW_NW_PROTO elif key == 'nw_src': ip = value.split('/') @@ -197,10 +198,10 @@ def to_match(dp, attrs): ~ofp.OFPFW_NW_DST_MASK wildcards &= v elif key == 'tp_src': - tp_src = int(value) + tp_src = str_to_int(value) wildcards &= ~ofp.OFPFW_TP_SRC elif key == 'tp_dst': - tp_dst = int(value) + tp_dst = str_to_int(value) wildcards &= ~ofp.OFPFW_TP_DST else: LOG.error("unknown match name %s, %s, %d", key, value, len(key)) @@ -298,12 +299,12 @@ def get_queue_stats(dp, waiters, port=None, queue_id=None): if port is None: port = dp.ofproto.OFPP_ALL else: - port = int(str(port), 0) + port = str_to_int(port) if queue_id is None: queue_id = dp.ofproto.OFPQ_ALL else: - queue_id = int(str(queue_id), 0) + queue_id = str_to_int(queue_id) stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port, queue_id) @@ -332,7 +333,7 @@ def get_flow_stats(dp, waiters, flow=None): flow.get('out_port', dp.ofproto.OFPP_NONE)) # Note: OpenFlow does not allow to filter flow entries by priority, # but for efficiency, ofctl provides the way to do it. - priority = int(flow.get('priority', -1)) + priority = str_to_int(flow.get('priority', -1)) stats = dp.ofproto_parser.OFPFlowStatsRequest( dp, 0, match, table_id, out_port) @@ -445,7 +446,7 @@ def get_port_stats(dp, waiters, port=None): if port is None: port = dp.ofproto.OFPP_NONE else: - port = int(str(port), 0) + port = str_to_int(port) stats = dp.ofproto_parser.OFPPortStatsRequest( dp, 0, port) @@ -498,16 +499,16 @@ def get_port_desc(dp, waiters): def mod_flow_entry(dp, flow, cmd): - cookie = int(flow.get('cookie', 0)) - priority = int(flow.get('priority', - dp.ofproto.OFP_DEFAULT_PRIORITY)) + cookie = str_to_int(flow.get('cookie', 0)) + priority = str_to_int( + flow.get('priority', dp.ofproto.OFP_DEFAULT_PRIORITY)) buffer_id = UTIL.ofp_buffer_from_user( flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER)) out_port = UTIL.ofp_port_from_user( flow.get('out_port', dp.ofproto.OFPP_NONE)) - flags = int(flow.get('flags', 0)) - idle_timeout = int(flow.get('idle_timeout', 0)) - hard_timeout = int(flow.get('hard_timeout', 0)) + flags = str_to_int(flow.get('flags', 0)) + idle_timeout = str_to_int(flow.get('idle_timeout', 0)) + hard_timeout = str_to_int(flow.get('hard_timeout', 0)) actions = to_actions(dp, flow.get('actions', [])) match = to_match(dp, flow.get('match', {})) @@ -536,9 +537,9 @@ def delete_flow_entry(dp): def mod_port_behavior(dp, port_config): port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0)) hw_addr = str(port_config.get('hw_addr')) - config = int(port_config.get('config', 0)) - mask = int(port_config.get('mask', 0)) - advertise = int(port_config.get('advertise')) + config = str_to_int(port_config.get('config', 0)) + mask = str_to_int(port_config.get('mask', 0)) + advertise = str_to_int(port_config.get('advertise')) port_mod = dp.ofproto_parser.OFPPortMod( dp, port_no, hw_addr, config, mask, advertise) diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py index 998d5356..6363e517 100644 --- a/ryu/lib/ofctl_v1_2.py +++ b/ryu/lib/ofctl_v1_2.py @@ -28,6 +28,7 @@ LOG = logging.getLogger('ryu.lib.ofctl_v1_2') DEFAULT_TIMEOUT = 1.0 UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_2) +str_to_int = ofctl_utils.str_to_int def to_action(dp, dic): @@ -44,20 +45,20 @@ def to_action(dp, dic): elif action_type == 'COPY_TTL_IN': result = parser.OFPActionCopyTtlIn() elif action_type == 'SET_MPLS_TTL': - mpls_ttl = int(dic.get('mpls_ttl')) + mpls_ttl = str_to_int(dic.get('mpls_ttl')) result = parser.OFPActionSetMplsTtl(mpls_ttl) elif action_type == 'DEC_MPLS_TTL': result = parser.OFPActionDecMplsTtl() elif action_type == 'PUSH_VLAN': - ethertype = int(dic.get('ethertype')) + ethertype = str_to_int(dic.get('ethertype')) result = parser.OFPActionPushVlan(ethertype) elif action_type == 'POP_VLAN': result = parser.OFPActionPopVlan() elif action_type == 'PUSH_MPLS': - ethertype = int(dic.get('ethertype')) + ethertype = str_to_int(dic.get('ethertype')) result = parser.OFPActionPushMpls(ethertype) elif action_type == 'POP_MPLS': - ethertype = int(dic.get('ethertype')) + ethertype = str_to_int(dic.get('ethertype')) result = parser.OFPActionPopMpls(ethertype) elif action_type == 'SET_QUEUE': queue_id = UTIL.ofp_queue_from_user(dic.get('queue_id')) @@ -66,7 +67,7 @@ def to_action(dp, dic): group_id = UTIL.ofp_group_from_user(dic.get('group_id')) result = parser.OFPActionGroup(group_id) elif action_type == 'SET_NW_TTL': - nw_ttl = int(dic.get('nw_ttl')) + nw_ttl = str_to_int(dic.get('nw_ttl')) result = parser.OFPActionSetNwTtl(nw_ttl) elif action_type == 'DEC_NW_TTL': result = parser.OFPActionDecNwTtl() @@ -112,8 +113,8 @@ def to_actions(dp, acts): table_id = UTIL.ofp_table_from_user(a.get('table_id')) inst.append(parser.OFPInstructionGotoTable(table_id)) elif action_type == 'WRITE_METADATA': - metadata = ofctl_utils.str_to_int(a.get('metadata')) - metadata_mask = (ofctl_utils.str_to_int(a['metadata_mask']) + metadata = str_to_int(a.get('metadata')) + metadata_mask = (str_to_int(a['metadata_mask']) if 'metadata_mask' in a else parser.UINT64_MAX) inst.append( @@ -208,50 +209,50 @@ def actions_to_str(instructions): def to_match(dp, attrs): convert = {'in_port': UTIL.ofp_port_from_user, - 'in_phy_port': int, + 'in_phy_port': str_to_int, 'metadata': to_match_masked_int, 'dl_dst': to_match_eth, 'dl_src': to_match_eth, 'eth_dst': to_match_eth, 'eth_src': to_match_eth, - 'dl_type': int, - 'eth_type': int, + 'dl_type': str_to_int, + 'eth_type': str_to_int, 'dl_vlan': to_match_vid, 'vlan_vid': to_match_vid, - 'vlan_pcp': int, - 'ip_dscp': int, - 'ip_ecn': int, - 'nw_proto': int, - 'ip_proto': int, + 'vlan_pcp': str_to_int, + 'ip_dscp': str_to_int, + 'ip_ecn': str_to_int, + 'nw_proto': str_to_int, + 'ip_proto': str_to_int, 'nw_src': to_match_ip, 'nw_dst': to_match_ip, 'ipv4_src': to_match_ip, 'ipv4_dst': to_match_ip, - 'tp_src': int, - 'tp_dst': int, - 'tcp_src': int, - 'tcp_dst': int, - 'udp_src': int, - 'udp_dst': int, - 'sctp_src': int, - 'sctp_dst': int, - 'icmpv4_type': int, - 'icmpv4_code': int, - 'arp_op': int, + 'tp_src': str_to_int, + 'tp_dst': str_to_int, + 'tcp_src': str_to_int, + 'tcp_dst': str_to_int, + 'udp_src': str_to_int, + 'udp_dst': str_to_int, + 'sctp_src': str_to_int, + 'sctp_dst': str_to_int, + 'icmpv4_type': str_to_int, + 'icmpv4_code': str_to_int, + 'arp_op': str_to_int, 'arp_spa': to_match_ip, 'arp_tpa': to_match_ip, 'arp_sha': to_match_eth, 'arp_tha': to_match_eth, 'ipv6_src': to_match_ip, 'ipv6_dst': to_match_ip, - 'ipv6_flabel': int, - 'icmpv6_type': int, - 'icmpv6_code': int, + 'ipv6_flabel': str_to_int, + 'icmpv6_type': str_to_int, + 'icmpv6_code': str_to_int, 'ipv6_nd_target': to_match_ip, 'ipv6_nd_sll': to_match_eth, 'ipv6_nd_tll': to_match_eth, - 'mpls_label': int, - 'mpls_tc': int} + 'mpls_label': str_to_int, + 'mpls_tc': str_to_int} keys = {'dl_dst': 'eth_dst', 'dl_src': 'eth_src', @@ -416,12 +417,12 @@ def get_queue_stats(dp, waiters, port=None, queue_id=None): if port is None: port = ofp.OFPP_ANY else: - port = int(str(port), 0) + port = str_to_int(port) if queue_id is None: queue_id = ofp.OFPQ_ALL else: - queue_id = int(str(queue_id), 0) + queue_id = str_to_int(queue_id) stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, port, queue_id, 0) @@ -446,7 +447,7 @@ def get_queue_config(dp, waiters, port=None): if port is None: port = ofp.OFPP_ANY else: - port = UTIL.ofp_port_from_user(int(str(port), 0)) + port = UTIL.ofp_port_from_user(str_to_int(port)) stats = dp.ofproto_parser.OFPQueueGetConfigRequest(dp, port) msgs = [] ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG) @@ -490,12 +491,12 @@ def get_flow_stats(dp, waiters, flow=None): flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) match = to_match(dp, flow.get('match', {})) # Note: OpenFlow does not allow to filter flow entries by priority, # but for efficiency, ofctl provides the way to do it. - priority = int(flow.get('priority', -1)) + priority = str_to_int(flow.get('priority', -1)) stats = dp.ofproto_parser.OFPFlowStatsRequest( dp, table_id, out_port, out_group, cookie, cookie_mask, match) @@ -536,8 +537,8 @@ def get_aggregate_flow_stats(dp, waiters, flow=None): flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) match = to_match(dp, flow.get('match', {})) stats = dp.ofproto_parser.OFPAggregateStatsRequest( @@ -685,7 +686,7 @@ def get_port_stats(dp, waiters, port=None): if port is None: port = dp.ofproto.OFPP_ANY else: - port = int(str(port), 0) + port = str_to_int(port) stats = dp.ofproto_parser.OFPPortStatsRequest( dp, port, 0) @@ -717,7 +718,7 @@ def get_group_stats(dp, waiters, group_id=None): if group_id is None: group_id = dp.ofproto.OFPG_ALL else: - group_id = int(str(group_id), 0) + group_id = str_to_int(group_id) stats = dp.ofproto_parser.OFPGroupStatsRequest( dp, group_id, 0) @@ -863,19 +864,19 @@ def get_port_desc(dp, waiters): def mod_flow_entry(dp, flow, cmd): - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0)) - idle_timeout = int(flow.get('idle_timeout', 0)) - hard_timeout = int(flow.get('hard_timeout', 0)) - priority = int(flow.get('priority', 0)) + idle_timeout = str_to_int(flow.get('idle_timeout', 0)) + hard_timeout = str_to_int(flow.get('hard_timeout', 0)) + priority = str_to_int(flow.get('priority', 0)) buffer_id = UTIL.ofp_buffer_from_user( flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER)) out_port = UTIL.ofp_port_from_user( flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - flags = int(flow.get('flags', 0)) + flags = str_to_int(flow.get('flags', 0)) match = to_match(dp, flow.get('match', {})) inst = to_actions(dp, flow.get('actions', [])) @@ -902,9 +903,11 @@ def mod_group_entry(dp, group, cmd): buckets = [] for bucket in group.get('buckets', []): - weight = int(bucket.get('weight', 0)) - watch_port = int(bucket.get('watch_port', dp.ofproto.OFPP_ANY)) - watch_group = int(bucket.get('watch_group', dp.ofproto.OFPG_ANY)) + weight = str_to_int(bucket.get('weight', 0)) + watch_port = str_to_int( + bucket.get('watch_port', dp.ofproto.OFPP_ANY)) + watch_group = str_to_int( + bucket.get('watch_group', dp.ofproto.OFPG_ANY)) actions = [] for dic in bucket.get('actions', []): action = to_action(dp, dic) @@ -922,9 +925,9 @@ def mod_group_entry(dp, group, cmd): def mod_port_behavior(dp, port_config): port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0)) hw_addr = str(port_config.get('hw_addr')) - config = int(port_config.get('config', 0)) - mask = int(port_config.get('mask', 0)) - advertise = int(port_config.get('advertise')) + config = str_to_int(port_config.get('config', 0)) + mask = str_to_int(port_config.get('mask', 0)) + advertise = str_to_int(port_config.get('advertise')) port_mod = dp.ofproto_parser.OFPPortMod( dp, port_no, hw_addr, config, mask, advertise) diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py index 4d5a5a54..2fcfbaaf 100644 --- a/ryu/lib/ofctl_v1_3.py +++ b/ryu/lib/ofctl_v1_3.py @@ -30,6 +30,7 @@ LOG = logging.getLogger('ryu.lib.ofctl_v1_3') DEFAULT_TIMEOUT = 1.0 UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_3) +str_to_int = ofctl_utils.str_to_int def to_action(dp, dic): @@ -72,8 +73,8 @@ def to_actions(dp, acts): table_id = UTIL.ofp_table_from_user(a.get('table_id')) inst.append(parser.OFPInstructionGotoTable(table_id)) elif action_type == 'WRITE_METADATA': - metadata = ofctl_utils.str_to_int(a.get('metadata')) - metadata_mask = (ofctl_utils.str_to_int(a['metadata_mask']) + metadata = str_to_int(a.get('metadata')) + metadata_mask = (str_to_int(a['metadata_mask']) if 'metadata_mask' in a else parser.UINT64_MAX) inst.append( @@ -192,51 +193,51 @@ def actions_to_str(instructions): def to_match(dp, attrs): convert = {'in_port': UTIL.ofp_port_from_user, - 'in_phy_port': int, + 'in_phy_port': str_to_int, 'metadata': ofctl_utils.to_match_masked_int, 'dl_dst': ofctl_utils.to_match_eth, 'dl_src': ofctl_utils.to_match_eth, 'eth_dst': ofctl_utils.to_match_eth, 'eth_src': ofctl_utils.to_match_eth, - 'dl_type': int, - 'eth_type': int, + 'dl_type': str_to_int, + 'eth_type': str_to_int, 'dl_vlan': to_match_vid, 'vlan_vid': to_match_vid, - 'vlan_pcp': int, - 'ip_dscp': int, - 'ip_ecn': int, - 'nw_proto': int, - 'ip_proto': int, + 'vlan_pcp': str_to_int, + 'ip_dscp': str_to_int, + 'ip_ecn': str_to_int, + 'nw_proto': str_to_int, + 'ip_proto': str_to_int, 'nw_src': ofctl_utils.to_match_ip, 'nw_dst': ofctl_utils.to_match_ip, 'ipv4_src': ofctl_utils.to_match_ip, 'ipv4_dst': ofctl_utils.to_match_ip, - 'tp_src': int, - 'tp_dst': int, - 'tcp_src': int, - 'tcp_dst': int, - 'udp_src': int, - 'udp_dst': int, - 'sctp_src': int, - 'sctp_dst': int, - 'icmpv4_type': int, - 'icmpv4_code': int, - 'arp_op': int, + 'tp_src': str_to_int, + 'tp_dst': str_to_int, + 'tcp_src': str_to_int, + 'tcp_dst': str_to_int, + 'udp_src': str_to_int, + 'udp_dst': str_to_int, + 'sctp_src': str_to_int, + 'sctp_dst': str_to_int, + 'icmpv4_type': str_to_int, + 'icmpv4_code': str_to_int, + 'arp_op': str_to_int, 'arp_spa': ofctl_utils.to_match_ip, 'arp_tpa': ofctl_utils.to_match_ip, 'arp_sha': ofctl_utils.to_match_eth, 'arp_tha': ofctl_utils.to_match_eth, 'ipv6_src': ofctl_utils.to_match_ip, 'ipv6_dst': ofctl_utils.to_match_ip, - 'ipv6_flabel': int, - 'icmpv6_type': int, - 'icmpv6_code': int, + 'ipv6_flabel': str_to_int, + 'icmpv6_type': str_to_int, + 'icmpv6_code': str_to_int, 'ipv6_nd_target': ofctl_utils.to_match_ip, 'ipv6_nd_sll': ofctl_utils.to_match_eth, 'ipv6_nd_tll': ofctl_utils.to_match_eth, - 'mpls_label': int, - 'mpls_tc': int, - 'mpls_bos': int, + 'mpls_label': str_to_int, + 'mpls_tc': str_to_int, + 'mpls_bos': str_to_int, 'pbb_isid': ofctl_utils.to_match_masked_int, 'tunnel_id': ofctl_utils.to_match_masked_int, 'ipv6_exthdr': ofctl_utils.to_match_masked_int} @@ -355,12 +356,12 @@ def get_queue_stats(dp, waiters, port=None, queue_id=None, to_user=True): if port is None: port = ofp.OFPP_ANY else: - port = int(str(port), 0) + port = str_to_int(port) if queue_id is None: queue_id = ofp.OFPQ_ALL else: - queue_id = int(str(queue_id), 0) + queue_id = str_to_int(queue_id) stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port, queue_id) @@ -387,7 +388,7 @@ def get_queue_config(dp, waiters, port=None, to_user=True): if port is None: port = ofp.OFPP_ANY else: - port = UTIL.ofp_port_from_user(int(str(port), 0)) + port = UTIL.ofp_port_from_user(str_to_int(port)) stats = dp.ofproto_parser.OFPQueueGetConfigRequest(dp, port) msgs = [] ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG) @@ -440,17 +441,17 @@ def get_flow_stats(dp, waiters, flow=None, to_user=True): flow = flow if flow else {} table_id = UTIL.ofp_table_from_user( flow.get('table_id', dp.ofproto.OFPTT_ALL)) - flags = int(flow.get('flags', 0)) + flags = str_to_int(flow.get('flags', 0)) out_port = UTIL.ofp_port_from_user( flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) match = to_match(dp, flow.get('match', {})) # Note: OpenFlow does not allow to filter flow entries by priority, # but for efficiency, ofctl provides the way to do it. - priority = int(flow.get('priority', -1)) + priority = str_to_int(flow.get('priority', -1)) stats = dp.ofproto_parser.OFPFlowStatsRequest( dp, flags, table_id, out_port, out_group, cookie, cookie_mask, @@ -496,13 +497,13 @@ def get_aggregate_flow_stats(dp, waiters, flow=None, to_user=True): flow = flow if flow else {} table_id = UTIL.ofp_table_from_user( flow.get('table_id', dp.ofproto.OFPTT_ALL)) - flags = int(flow.get('flags', 0)) + flags = str_to_int(flow.get('flags', 0)) out_port = UTIL.ofp_port_from_user( flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) match = to_match(dp, flow.get('match', {})) stats = dp.ofproto_parser.OFPAggregateStatsRequest( @@ -655,7 +656,7 @@ def get_port_stats(dp, waiters, port=None, to_user=True): if port is None: port = dp.ofproto.OFPP_ANY else: - port = int(str(port), 0) + port = str_to_int(port) stats = dp.ofproto_parser.OFPPortStatsRequest( dp, 0, port) @@ -695,7 +696,7 @@ def get_meter_stats(dp, waiters, meter_id=None, to_user=True): if meter_id is None: meter_id = dp.ofproto.OFPM_ALL else: - meter_id = int(str(meter_id), 0) + meter_id = str_to_int(meter_id) stats = dp.ofproto_parser.OFPMeterStatsRequest( dp, 0, meter_id) @@ -790,7 +791,7 @@ def get_meter_config(dp, waiters, meter_id=None, to_user=True): if meter_id is None: meter_id = dp.ofproto.OFPM_ALL else: - meter_id = int(str(meter_id), 0) + meter_id = str_to_int(meter_id) stats = dp.ofproto_parser.OFPMeterConfigStatsRequest( dp, 0, meter_id) @@ -843,7 +844,7 @@ def get_group_stats(dp, waiters, group_id=None, to_user=True): if group_id is None: group_id = dp.ofproto.OFPG_ALL else: - group_id = int(str(group_id), 0) + group_id = str_to_int(group_id) stats = dp.ofproto_parser.OFPGroupStatsRequest( dp, 0, group_id) @@ -1042,19 +1043,19 @@ def get_port_desc(dp, waiters, to_user=True): def mod_flow_entry(dp, flow, cmd): - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0)) - idle_timeout = int(flow.get('idle_timeout', 0)) - hard_timeout = int(flow.get('hard_timeout', 0)) - priority = int(flow.get('priority', 0)) + idle_timeout = str_to_int(flow.get('idle_timeout', 0)) + hard_timeout = str_to_int(flow.get('hard_timeout', 0)) + priority = str_to_int(flow.get('priority', 0)) buffer_id = UTIL.ofp_buffer_from_user( flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER)) out_port = UTIL.ofp_port_from_user( flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - flags = int(flow.get('flags', 0)) + flags = str_to_int(flow.get('flags', 0)) match = to_match(dp, flow.get('match', {})) inst = to_actions(dp, flow.get('actions', [])) @@ -1089,18 +1090,18 @@ def mod_meter_entry(dp, meter, cmd): bands = [] for band in meter.get('bands', []): band_type = band.get('type') - rate = int(band.get('rate', 0)) - burst_size = int(band.get('burst_size', 0)) + rate = str_to_int(band.get('rate', 0)) + burst_size = str_to_int(band.get('burst_size', 0)) if band_type == 'DROP': bands.append( dp.ofproto_parser.OFPMeterBandDrop(rate, burst_size)) elif band_type == 'DSCP_REMARK': - prec_level = int(band.get('prec_level', 0)) + prec_level = str_to_int(band.get('prec_level', 0)) bands.append( dp.ofproto_parser.OFPMeterBandDscpRemark( rate, burst_size, prec_level)) elif band_type == 'EXPERIMENTER': - experimenter = int(band.get('experimenter', 0)) + experimenter = str_to_int(band.get('experimenter', 0)) bands.append( dp.ofproto_parser.OFPMeterBandExperimenter( rate, burst_size, experimenter)) @@ -1128,9 +1129,11 @@ def mod_group_entry(dp, group, cmd): buckets = [] for bucket in group.get('buckets', []): - weight = int(bucket.get('weight', 0)) - watch_port = int(bucket.get('watch_port', dp.ofproto.OFPP_ANY)) - watch_group = int(bucket.get('watch_group', dp.ofproto.OFPG_ANY)) + weight = str_to_int(bucket.get('weight', 0)) + watch_port = str_to_int( + bucket.get('watch_port', dp.ofproto.OFPP_ANY)) + watch_group = str_to_int( + bucket.get('watch_group', dp.ofproto.OFPG_ANY)) actions = [] for dic in bucket.get('actions', []): action = to_action(dp, dic) @@ -1148,9 +1151,9 @@ def mod_group_entry(dp, group, cmd): def mod_port_behavior(dp, port_config): port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0)) hw_addr = str(port_config.get('hw_addr')) - config = int(port_config.get('config', 0)) - mask = int(port_config.get('mask', 0)) - advertise = int(port_config.get('advertise')) + config = str_to_int(port_config.get('config', 0)) + mask = str_to_int(port_config.get('mask', 0)) + advertise = str_to_int(port_config.get('advertise')) port_mod = dp.ofproto_parser.OFPPortMod( dp, port_no, hw_addr, config, mask, advertise) diff --git a/ryu/lib/ofctl_v1_4.py b/ryu/lib/ofctl_v1_4.py index 219f99ff..a66df00c 100644 --- a/ryu/lib/ofctl_v1_4.py +++ b/ryu/lib/ofctl_v1_4.py @@ -25,6 +25,7 @@ LOG = logging.getLogger(__name__) DEFAULT_TIMEOUT = 1.0 UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_4) +str_to_int = ofctl_utils.str_to_int def to_action(dp, dic): @@ -68,18 +69,18 @@ def to_instructions(dp, insts): instructions.append( parser.OFPInstructionActions(ofp.OFPIT_CLEAR_ACTIONS, [])) elif inst_type == 'GOTO_TABLE': - table_id = int(i.get('table_id')) + table_id = str_to_int(i.get('table_id')) instructions.append(parser.OFPInstructionGotoTable(table_id)) elif inst_type == 'WRITE_METADATA': - metadata = ofctl_utils.str_to_int(i.get('metadata')) - metadata_mask = (ofctl_utils.str_to_int(i['metadata_mask']) + metadata = str_to_int(i.get('metadata')) + metadata_mask = (str_to_int(i['metadata_mask']) if 'metadata_mask' in i else parser.UINT64_MAX) instructions.append( parser.OFPInstructionWriteMetadata( metadata, metadata_mask)) elif inst_type == 'METER': - meter_id = int(i.get('meter_id')) + meter_id = str_to_int(i.get('meter_id')) instructions.append(parser.OFPInstructionMeter(meter_id)) else: LOG.error('Unknown instruction type: %s', inst_type) @@ -127,46 +128,46 @@ def instructions_to_str(instructions): def to_match(dp, attrs): convert = {'in_port': UTIL.ofp_port_from_user, - 'in_phy_port': int, + 'in_phy_port': str_to_int, 'metadata': ofctl_utils.to_match_masked_int, 'eth_dst': ofctl_utils.to_match_eth, 'eth_src': ofctl_utils.to_match_eth, - 'eth_type': int, + 'eth_type': str_to_int, 'vlan_vid': to_match_vid, - 'vlan_pcp': int, - 'ip_dscp': int, - 'ip_ecn': int, - 'ip_proto': int, + 'vlan_pcp': str_to_int, + 'ip_dscp': str_to_int, + 'ip_ecn': str_to_int, + 'ip_proto': str_to_int, 'ipv4_src': ofctl_utils.to_match_ip, 'ipv4_dst': ofctl_utils.to_match_ip, - 'tcp_src': int, - 'tcp_dst': int, - 'udp_src': int, - 'udp_dst': int, - 'sctp_src': int, - 'sctp_dst': int, - 'icmpv4_type': int, - 'icmpv4_code': int, - 'arp_op': int, + 'tcp_src': str_to_int, + 'tcp_dst': str_to_int, + 'udp_src': str_to_int, + 'udp_dst': str_to_int, + 'sctp_src': str_to_int, + 'sctp_dst': str_to_int, + 'icmpv4_type': str_to_int, + 'icmpv4_code': str_to_int, + 'arp_op': str_to_int, 'arp_spa': ofctl_utils.to_match_ip, 'arp_tpa': ofctl_utils.to_match_ip, 'arp_sha': ofctl_utils.to_match_eth, 'arp_tha': ofctl_utils.to_match_eth, 'ipv6_src': ofctl_utils.to_match_ip, 'ipv6_dst': ofctl_utils.to_match_ip, - 'ipv6_flabel': int, - 'icmpv6_type': int, - 'icmpv6_code': int, + 'ipv6_flabel': str_to_int, + 'icmpv6_type': str_to_int, + 'icmpv6_code': str_to_int, 'ipv6_nd_target': ofctl_utils.to_match_ip, 'ipv6_nd_sll': ofctl_utils.to_match_eth, 'ipv6_nd_tll': ofctl_utils.to_match_eth, - 'mpls_label': int, - 'mpls_tc': int, - 'mpls_bos': int, + 'mpls_label': str_to_int, + 'mpls_tc': str_to_int, + 'mpls_bos': str_to_int, 'pbb_isid': ofctl_utils.to_match_masked_int, 'tunnel_id': ofctl_utils.to_match_masked_int, 'ipv6_exthdr': ofctl_utils.to_match_masked_int, - 'pbb_uca': int} + 'pbb_uca': str_to_int} keys = {'dl_dst': 'eth_dst', 'dl_src': 'eth_src', @@ -314,17 +315,17 @@ def get_flow_stats(dp, waiters, flow=None, to_user=True): flow = flow if flow else {} table_id = UTIL.ofp_table_from_user( flow.get('table_id', dp.ofproto.OFPTT_ALL)) - flags = int(flow.get('flags', 0)) + flags = str_to_int(flow.get('flags', 0)) out_port = UTIL.ofp_port_from_user( flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) match = to_match(dp, flow.get('match', {})) # Note: OpenFlow does not allow to filter flow entries by priority, # but for efficiency, ofctl provides the way to do it. - priority = int(flow.get('priority', -1)) + priority = str_to_int(flow.get('priority', -1)) stats = dp.ofproto_parser.OFPFlowStatsRequest( dp, flags, table_id, out_port, out_group, cookie, cookie_mask, @@ -351,13 +352,13 @@ def get_aggregate_flow_stats(dp, waiters, flow=None, to_user=True): flow = flow if flow else {} table_id = UTIL.ofp_table_from_user( flow.get('table_id', dp.ofproto.OFPTT_ALL)) - flags = int(flow.get('flags', 0)) + flags = str_to_int(flow.get('flags', 0)) out_port = UTIL.ofp_port_from_user( flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) match = to_match(dp, flow.get('match', {})) stats = dp.ofproto_parser.OFPAggregateStatsRequest( @@ -813,20 +814,20 @@ def get_port_desc(dp, waiters, port_no=None, to_user=True): def mod_flow_entry(dp, flow, cmd): - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0)) - idle_timeout = int(flow.get('idle_timeout', 0)) - hard_timeout = int(flow.get('hard_timeout', 0)) - priority = int(flow.get('priority', 0)) + idle_timeout = str_to_int(flow.get('idle_timeout', 0)) + hard_timeout = str_to_int(flow.get('hard_timeout', 0)) + priority = str_to_int(flow.get('priority', 0)) buffer_id = UTIL.ofp_buffer_from_user( flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER)) out_port = UTIL.ofp_port_from_user( flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - importance = int(flow.get('importance', 0)) - flags = int(flow.get('flags', 0)) + importance = str_to_int(flow.get('importance', 0)) + flags = str_to_int(flow.get('flags', 0)) match = to_match(dp, flow.get('match', {})) inst = to_instructions(dp, flow.get('instructions', [])) @@ -857,18 +858,18 @@ def mod_meter_entry(dp, meter, cmd): bands = [] for band in meter.get('bands', []): band_type = band.get('type') - rate = int(band.get('rate', 0)) - burst_size = int(band.get('burst_size', 0)) + rate = str_to_int(band.get('rate', 0)) + burst_size = str_to_int(band.get('burst_size', 0)) if band_type == 'DROP': bands.append( dp.ofproto_parser.OFPMeterBandDrop(rate, burst_size)) elif band_type == 'DSCP_REMARK': - prec_level = int(band.get('prec_level', 0)) + prec_level = str_to_int(band.get('prec_level', 0)) bands.append( dp.ofproto_parser.OFPMeterBandDscpRemark( rate, burst_size, prec_level)) elif band_type == 'EXPERIMENTER': - experimenter = int(band.get('experimenter', 0)) + experimenter = str_to_int(band.get('experimenter', 0)) bands.append( dp.ofproto_parser.OFPMeterBandExperimenter( rate, burst_size, experimenter)) @@ -892,9 +893,11 @@ def mod_group_entry(dp, group, cmd): buckets = [] for bucket in group.get('buckets', []): - weight = int(bucket.get('weight', 0)) - watch_port = int(bucket.get('watch_port', dp.ofproto.OFPP_ANY)) - watch_group = int(bucket.get('watch_group', dp.ofproto.OFPG_ANY)) + weight = str_to_int(bucket.get('weight', 0)) + watch_port = str_to_int( + bucket.get('watch_port', dp.ofproto.OFPP_ANY)) + watch_group = str_to_int( + bucket.get('watch_group', dp.ofproto.OFPG_ANY)) actions = [] for dic in bucket.get('actions', []): action = to_action(dp, dic) @@ -914,8 +917,8 @@ def mod_port_behavior(dp, port_config): parser = dp.ofproto_parser port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0)) hw_addr = str(port_config.get('hw_addr')) - config = int(port_config.get('config', 0)) - mask = int(port_config.get('mask', 0)) + config = str_to_int(port_config.get('config', 0)) + mask = str_to_int(port_config.get('mask', 0)) properties = port_config.get('properties') prop = [] diff --git a/ryu/lib/ofctl_v1_5.py b/ryu/lib/ofctl_v1_5.py index 19f57b31..60934a33 100644 --- a/ryu/lib/ofctl_v1_5.py +++ b/ryu/lib/ofctl_v1_5.py @@ -26,6 +26,7 @@ LOG = logging.getLogger(__name__) DEFAULT_TIMEOUT = 1.0 UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_5) +str_to_int = ofctl_utils.str_to_int def to_action(dp, dic): @@ -69,11 +70,11 @@ def to_instructions(dp, insts): instructions.append( parser.OFPInstructionActions(ofp.OFPIT_CLEAR_ACTIONS, [])) elif inst_type == 'GOTO_TABLE': - table_id = int(i.get('table_id')) + table_id = str_to_int(i.get('table_id')) instructions.append(parser.OFPInstructionGotoTable(table_id)) elif inst_type == 'WRITE_METADATA': - metadata = ofctl_utils.str_to_int(i.get('metadata')) - metadata_mask = (ofctl_utils.str_to_int(i['metadata_mask']) + metadata = str_to_int(i.get('metadata')) + metadata_mask = (str_to_int(i['metadata_mask']) if 'metadata_mask' in i else parser.UINT64_MAX) instructions.append( @@ -129,48 +130,48 @@ def instructions_to_str(instructions): def to_match(dp, attrs): convert = {'in_port': UTIL.ofp_port_from_user, - 'in_phy_port': int, + 'in_phy_port': str_to_int, 'metadata': ofctl_utils.to_match_masked_int, 'eth_dst': ofctl_utils.to_match_eth, 'eth_src': ofctl_utils.to_match_eth, - 'eth_type': int, + 'eth_type': str_to_int, 'vlan_vid': to_match_vid, - 'vlan_pcp': int, - 'ip_dscp': int, - 'ip_ecn': int, - 'ip_proto': int, + 'vlan_pcp': str_to_int, + 'ip_dscp': str_to_int, + 'ip_ecn': str_to_int, + 'ip_proto': str_to_int, 'ipv4_src': ofctl_utils.to_match_ip, 'ipv4_dst': ofctl_utils.to_match_ip, - 'tcp_src': int, - 'tcp_dst': int, - 'udp_src': int, - 'udp_dst': int, - 'sctp_src': int, - 'sctp_dst': int, - 'icmpv4_type': int, - 'icmpv4_code': int, - 'arp_op': int, + 'tcp_src': str_to_int, + 'tcp_dst': str_to_int, + 'udp_src': str_to_int, + 'udp_dst': str_to_int, + 'sctp_src': str_to_int, + 'sctp_dst': str_to_int, + 'icmpv4_type': str_to_int, + 'icmpv4_code': str_to_int, + 'arp_op': str_to_int, 'arp_spa': ofctl_utils.to_match_ip, 'arp_tpa': ofctl_utils.to_match_ip, 'arp_sha': ofctl_utils.to_match_eth, 'arp_tha': ofctl_utils.to_match_eth, 'ipv6_src': ofctl_utils.to_match_ip, 'ipv6_dst': ofctl_utils.to_match_ip, - 'ipv6_flabel': int, - 'icmpv6_type': int, - 'icmpv6_code': int, + 'ipv6_flabel': str_to_int, + 'icmpv6_type': str_to_int, + 'icmpv6_code': str_to_int, 'ipv6_nd_target': ofctl_utils.to_match_ip, 'ipv6_nd_sll': ofctl_utils.to_match_eth, 'ipv6_nd_tll': ofctl_utils.to_match_eth, - 'mpls_label': int, - 'mpls_tc': int, - 'mpls_bos': int, + 'mpls_label': str_to_int, + 'mpls_tc': str_to_int, + 'mpls_bos': str_to_int, 'pbb_isid': ofctl_utils.to_match_masked_int, 'tunnel_id': ofctl_utils.to_match_masked_int, 'ipv6_exthdr': ofctl_utils.to_match_masked_int, - 'pbb_uca': int, - 'tcp_flags': int, - 'actset_output': int, + 'pbb_uca': str_to_int, + 'tcp_flags': str_to_int, + 'actset_output': str_to_int, 'packet_type': ofctl_utils.to_match_packet_type} keys = {'dl_dst': 'eth_dst', @@ -346,17 +347,17 @@ def get_flow_desc_stats(dp, waiters, flow=None, to_user=True): flow = flow if flow else {} table_id = UTIL.ofp_table_from_user( flow.get('table_id', dp.ofproto.OFPTT_ALL)) - flags = int(flow.get('flags', 0)) + flags = str_to_int(flow.get('flags', 0)) out_port = UTIL.ofp_port_from_user( flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) match = to_match(dp, flow.get('match', {})) # Note: OpenFlow does not allow to filter flow entries by priority, # but for efficiency, ofctl provides the way to do it. - priority = int(flow.get('priority', -1)) + priority = str_to_int(flow.get('priority', -1)) stats = dp.ofproto_parser.OFPFlowDescStatsRequest( dp, flags, table_id, out_port, out_group, cookie, cookie_mask, @@ -384,17 +385,17 @@ def get_flow_stats(dp, waiters, flow=None, to_user=True): flow = flow if flow else {} table_id = UTIL.ofp_table_from_user( flow.get('table_id', dp.ofproto.OFPTT_ALL)) - flags = int(flow.get('flags', 0)) + flags = str_to_int(flow.get('flags', 0)) out_port = UTIL.ofp_port_from_user( flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) match = to_match(dp, flow.get('match', {})) # Note: OpenFlow does not allow to filter flow entries by priority, # but for efficiency, ofctl provides the way to do it. - priority = int(flow.get('priority', -1)) + priority = str_to_int(flow.get('priority', -1)) stats = dp.ofproto_parser.OFPFlowStatsRequest( dp, flags, table_id, out_port, out_group, cookie, cookie_mask, @@ -421,13 +422,13 @@ def get_aggregate_flow_stats(dp, waiters, flow=None, to_user=True): flow = flow if flow else {} table_id = UTIL.ofp_table_from_user( flow.get('table_id', dp.ofproto.OFPTT_ALL)) - flags = int(flow.get('flags', 0)) + flags = str_to_int(flow.get('flags', 0)) out_port = UTIL.ofp_port_from_user( flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) match = to_match(dp, flow.get('match', {})) stats = dp.ofproto_parser.OFPAggregateStatsRequest( @@ -910,20 +911,20 @@ def get_port_desc(dp, waiters, port_no=None, to_user=True): def mod_flow_entry(dp, flow, cmd): - cookie = int(flow.get('cookie', 0)) - cookie_mask = int(flow.get('cookie_mask', 0)) + cookie = str_to_int(flow.get('cookie', 0)) + cookie_mask = str_to_int(flow.get('cookie_mask', 0)) table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0)) - idle_timeout = int(flow.get('idle_timeout', 0)) - hard_timeout = int(flow.get('hard_timeout', 0)) - priority = int(flow.get('priority', 0)) + idle_timeout = str_to_int(flow.get('idle_timeout', 0)) + hard_timeout = str_to_int(flow.get('hard_timeout', 0)) + priority = str_to_int(flow.get('priority', 0)) buffer_id = UTIL.ofp_buffer_from_user( flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER)) out_port = UTIL.ofp_port_from_user( flow.get('out_port', dp.ofproto.OFPP_ANY)) out_group = UTIL.ofp_group_from_user( flow.get('out_group', dp.ofproto.OFPG_ANY)) - importance = int(flow.get('importance', 0)) - flags = int(flow.get('flags', 0)) + importance = str_to_int(flow.get('importance', 0)) + flags = str_to_int(flow.get('flags', 0)) match = to_match(dp, flow.get('match', {})) inst = to_instructions(dp, flow.get('instructions', [])) @@ -954,18 +955,18 @@ def mod_meter_entry(dp, meter, cmd): bands = [] for band in meter.get('bands', []): band_type = band.get('type') - rate = int(band.get('rate', 0)) - burst_size = int(band.get('burst_size', 0)) + rate = str_to_int(band.get('rate', 0)) + burst_size = str_to_int(band.get('burst_size', 0)) if band_type == 'DROP': bands.append( dp.ofproto_parser.OFPMeterBandDrop(rate, burst_size)) elif band_type == 'DSCP_REMARK': - prec_level = int(band.get('prec_level', 0)) + prec_level = str_to_int(band.get('prec_level', 0)) bands.append( dp.ofproto_parser.OFPMeterBandDscpRemark( rate, burst_size, prec_level)) elif band_type == 'EXPERIMENTER': - experimenter = int(band.get('experimenter', 0)) + experimenter = str_to_int(band.get('experimenter', 0)) bands.append( dp.ofproto_parser.OFPMeterBandExperimenter( rate, burst_size, experimenter)) @@ -989,7 +990,7 @@ def mod_group_entry(dp, group, cmd): LOG.error('Unknown group type: %s', group.get('type')) group_id = UTIL.ofp_group_from_user(group.get('group_id', 0)) - command_bucket_id = int(group.get('command_bucket_id', 0)) + command_bucket_id = str_to_int(group.get('command_bucket_id', 0)) # Note: # The list of group property types that are currently defined @@ -1000,7 +1001,7 @@ def mod_group_entry(dp, group, cmd): for bucket in group.get('buckets', []): # get bucket_id in buckets - bucket_id = int(bucket.get('bucket_id', 0)) + bucket_id = str_to_int(bucket.get('bucket_id', 0)) # get actions in buckets bucket_actions = [] @@ -1017,17 +1018,17 @@ def mod_group_entry(dp, group, cmd): group_bp_type = t if t != group_bp_type else ofp.OFPGBPT_WEIGHT if group_bp_type == ofp.OFPGBPT_WEIGHT: - weight = int(p.get('weight', 0)) + weight = str_to_int(p.get('weight', 0)) bucket_properties.append( parser.OFPGroupBucketPropWeight( type_=group_bp_type, weight=weight)) elif group_bp_type == ofp.OFPGBPT_WATCH_PORT: - watch_port = int(p.get('watch', dp.ofproto.OFPP_ANY)) + watch_port = str_to_int(p.get('watch', dp.ofproto.OFPP_ANY)) bucket_properties.append( parser.OFPGroupBucketPropWatch( type_=group_bp_type, watch=watch_port)) elif group_bp_type == ofp.OFPGBPT_WATCH_GROUP: - watch_group = int(p.get('watch', dp.ofproto.OFPG_ANY)) + watch_group = str_to_int(p.get('watch', dp.ofproto.OFPG_ANY)) bucket_properties.append( parser.OFPGroupBucketPropWatch( type_=group_bp_type, watch=watch_group)) @@ -1065,8 +1066,8 @@ def mod_port_behavior(dp, port_config): parser = dp.ofproto_parser port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0)) hw_addr = str(port_config.get('hw_addr')) - config = int(port_config.get('config', 0)) - mask = int(port_config.get('mask', 0)) + config = str_to_int(port_config.get('config', 0)) + mask = str_to_int(port_config.get('mask', 0)) properties = port_config.get('properties') prop = [] |