summaryrefslogtreecommitdiffhomepage
path: root/ryu/lib/ofctl_v1_2.py
diff options
context:
space:
mode:
Diffstat (limited to 'ryu/lib/ofctl_v1_2.py')
-rw-r--r--ryu/lib/ofctl_v1_2.py109
1 files changed, 56 insertions, 53 deletions
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)