ofctl_v1_*: Use str_to_int instead of builtin int

This patch fixes lib/ofctl_v1_* to use the utility function str_to_int()
instead of the builtin function int().
With this change, lib/ofctl_v1_* can convert the user input values into
integer even if non-decimal string values (e.g. hexadecimal "0x80").

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
IWASE Yusuke
2017-02-09 16:44:35 +09:00
committed by FUJITA Tomonori
parent 83bf7fae1d
commit dffb3d3cf6
6 changed files with 262 additions and 251 deletions

View File

@@ -83,7 +83,7 @@ def to_action(dic, ofp, parser, action_type, util):
return actions[action_type]() return actions[action_type]()
elif action_type in need_ethertype: elif action_type in need_ethertype:
ethertype = int(dic.get('ethertype')) ethertype = str_to_int(dic.get('ethertype'))
return need_ethertype[action_type](ethertype) return need_ethertype[action_type](ethertype)
elif action_type == OUTPUT: elif action_type == OUTPUT:
@@ -92,7 +92,7 @@ def to_action(dic, ofp, parser, action_type, util):
return parser.OFPActionOutput(out_port, max_len) return parser.OFPActionOutput(out_port, max_len)
elif action_type == SET_MPLS_TTL: 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) return parser.OFPActionSetMplsTtl(mpls_ttl)
elif action_type == SET_QUEUE: elif action_type == SET_QUEUE:
@@ -104,7 +104,7 @@ def to_action(dic, ofp, parser, action_type, util):
return parser.OFPActionGroup(group_id) return parser.OFPActionGroup(group_id)
elif action_type == SET_NW_TTL: 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) return parser.OFPActionSetNwTtl(nw_ttl)
elif action_type == SET_FIELD: elif action_type == SET_FIELD:
@@ -113,9 +113,9 @@ def to_action(dic, ofp, parser, action_type, util):
return parser.OFPActionSetField(**{field: value}) return parser.OFPActionSetField(**{field: value})
elif action_type == 'COPY_FIELD': elif action_type == 'COPY_FIELD':
n_bits = int(dic.get('n_bits')) n_bits = str_to_int(dic.get('n_bits'))
src_offset = int(dic.get('src_offset')) src_offset = str_to_int(dic.get('src_offset'))
dst_offset = int(dic.get('dst_offset')) dst_offset = str_to_int(dic.get('dst_offset'))
oxm_ids = [parser.OFPOxmId(str(dic.get('src_oxm_id'))), oxm_ids = [parser.OFPOxmId(str(dic.get('src_oxm_id'))),
parser.OFPOxmId(str(dic.get('dst_oxm_id')))] parser.OFPOxmId(str(dic.get('dst_oxm_id')))]
return parser.OFPActionCopyField( return parser.OFPActionCopyField(
@@ -124,14 +124,14 @@ def to_action(dic, ofp, parser, action_type, util):
elif action_type == 'METER': elif action_type == 'METER':
if hasattr(parser, 'OFPActionMeter'): if hasattr(parser, 'OFPActionMeter'):
# OpenFlow 1.5 or later # 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) return parser.OFPActionMeter(meter_id)
else: else:
# OpenFlow 1.4 or earlier # OpenFlow 1.4 or earlier
return None return None
elif action_type == EXPERIMENTER: elif action_type == EXPERIMENTER:
experimenter = int(dic.get('experimenter')) experimenter = str_to_int(dic.get('experimenter'))
data_type = dic.get('data_type', 'ascii') data_type = dic.get('data_type', 'ascii')
if data_type not in ('ascii', 'base64'): if data_type not in ('ascii', 'base64'):
@@ -182,14 +182,14 @@ def to_match_vid(value, ofpvid_present):
else: else:
if '/' in value: if '/' in value:
val = value.split('/') val = value.split('/')
return int(val[0], 0), int(val[1], 0) return str_to_int(val[0]), str_to_int(val[1])
else: else:
if value.isdigit(): if value.isdigit():
# described as decimal string value # described as decimal string value
return int(value, 10) | ofpvid_present return int(value, 10) | ofpvid_present
return int(value, 0) return str_to_int(value)
def to_match_masked_int(value): def to_match_masked_int(value):

View File

@@ -27,6 +27,7 @@ LOG = logging.getLogger('ryu.lib.ofctl_v1_0')
DEFAULT_TIMEOUT = 1.0 # TODO:XXX DEFAULT_TIMEOUT = 1.0 # TODO:XXX
UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_0) UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_0)
str_to_int = ofctl_utils.str_to_int
def to_actions(dp, acts): def to_actions(dp, acts):
@@ -39,13 +40,13 @@ def to_actions(dp, acts):
# NOTE: The reason of this magic number (0xffe5) # NOTE: The reason of this magic number (0xffe5)
# is because there is no good constant in of1.0. # is because there is no good constant in of1.0.
# The same value as OFPCML_MAX of of1.2 and of1.3 is used. # 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)) actions.append(dp.ofproto_parser.OFPActionOutput(port, max_len))
elif action_type == 'SET_VLAN_VID': 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)) actions.append(dp.ofproto_parser.OFPActionVlanVid(vlan_vid))
elif action_type == 'SET_VLAN_PCP': 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)) actions.append(dp.ofproto_parser.OFPActionVlanPcp(vlan_pcp))
elif action_type == 'STRIP_VLAN': elif action_type == 'STRIP_VLAN':
actions.append(dp.ofproto_parser.OFPActionStripVlan()) actions.append(dp.ofproto_parser.OFPActionStripVlan())
@@ -62,13 +63,13 @@ def to_actions(dp, acts):
nw_dst = ipv4_to_int(a.get('nw_dst')) nw_dst = ipv4_to_int(a.get('nw_dst'))
actions.append(dp.ofproto_parser.OFPActionSetNwDst(nw_dst)) actions.append(dp.ofproto_parser.OFPActionSetNwDst(nw_dst))
elif action_type == 'SET_NW_TOS': 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)) actions.append(dp.ofproto_parser.OFPActionSetNwTos(nw_tos))
elif action_type == 'SET_TP_SRC': 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)) actions.append(dp.ofproto_parser.OFPActionSetTpSrc(tp_src))
elif action_type == 'SET_TP_DST': 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)) actions.append(dp.ofproto_parser.OFPActionSetTpDst(tp_dst))
elif action_type == 'ENQUEUE': elif action_type == 'ENQUEUE':
port = UTIL.ofp_port_from_user( port = UTIL.ofp_port_from_user(
@@ -162,19 +163,19 @@ def to_match(dp, attrs):
dl_dst = haddr_to_bin(value) dl_dst = haddr_to_bin(value)
wildcards &= ~ofp.OFPFW_DL_DST wildcards &= ~ofp.OFPFW_DL_DST
elif key == 'dl_vlan': elif key == 'dl_vlan':
dl_vlan = int(value) dl_vlan = str_to_int(value)
wildcards &= ~ofp.OFPFW_DL_VLAN wildcards &= ~ofp.OFPFW_DL_VLAN
elif key == 'dl_vlan_pcp': elif key == 'dl_vlan_pcp':
dl_vlan_pcp = int(value) dl_vlan_pcp = str_to_int(value)
wildcards &= ~ofp.OFPFW_DL_VLAN_PCP wildcards &= ~ofp.OFPFW_DL_VLAN_PCP
elif key == 'dl_type': elif key == 'dl_type':
dl_type = int(value) dl_type = str_to_int(value)
wildcards &= ~ofp.OFPFW_DL_TYPE wildcards &= ~ofp.OFPFW_DL_TYPE
elif key == 'nw_tos': elif key == 'nw_tos':
nw_tos = int(value) nw_tos = str_to_int(value)
wildcards &= ~ofp.OFPFW_NW_TOS wildcards &= ~ofp.OFPFW_NW_TOS
elif key == 'nw_proto': elif key == 'nw_proto':
nw_proto = int(value) nw_proto = str_to_int(value)
wildcards &= ~ofp.OFPFW_NW_PROTO wildcards &= ~ofp.OFPFW_NW_PROTO
elif key == 'nw_src': elif key == 'nw_src':
ip = value.split('/') ip = value.split('/')
@@ -197,10 +198,10 @@ def to_match(dp, attrs):
~ofp.OFPFW_NW_DST_MASK ~ofp.OFPFW_NW_DST_MASK
wildcards &= v wildcards &= v
elif key == 'tp_src': elif key == 'tp_src':
tp_src = int(value) tp_src = str_to_int(value)
wildcards &= ~ofp.OFPFW_TP_SRC wildcards &= ~ofp.OFPFW_TP_SRC
elif key == 'tp_dst': elif key == 'tp_dst':
tp_dst = int(value) tp_dst = str_to_int(value)
wildcards &= ~ofp.OFPFW_TP_DST wildcards &= ~ofp.OFPFW_TP_DST
else: else:
LOG.error("unknown match name %s, %s, %d", key, value, len(key)) 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: if port is None:
port = dp.ofproto.OFPP_ALL port = dp.ofproto.OFPP_ALL
else: else:
port = int(str(port), 0) port = str_to_int(port)
if queue_id is None: if queue_id is None:
queue_id = dp.ofproto.OFPQ_ALL queue_id = dp.ofproto.OFPQ_ALL
else: else:
queue_id = int(str(queue_id), 0) queue_id = str_to_int(queue_id)
stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port, stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port,
queue_id) queue_id)
@@ -332,7 +333,7 @@ def get_flow_stats(dp, waiters, flow=None):
flow.get('out_port', dp.ofproto.OFPP_NONE)) flow.get('out_port', dp.ofproto.OFPP_NONE))
# Note: OpenFlow does not allow to filter flow entries by priority, # Note: OpenFlow does not allow to filter flow entries by priority,
# but for efficiency, ofctl provides the way to do it. # 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( stats = dp.ofproto_parser.OFPFlowStatsRequest(
dp, 0, match, table_id, out_port) dp, 0, match, table_id, out_port)
@@ -445,7 +446,7 @@ def get_port_stats(dp, waiters, port=None):
if port is None: if port is None:
port = dp.ofproto.OFPP_NONE port = dp.ofproto.OFPP_NONE
else: else:
port = int(str(port), 0) port = str_to_int(port)
stats = dp.ofproto_parser.OFPPortStatsRequest( stats = dp.ofproto_parser.OFPPortStatsRequest(
dp, 0, port) dp, 0, port)
@@ -498,16 +499,16 @@ def get_port_desc(dp, waiters):
def mod_flow_entry(dp, flow, cmd): def mod_flow_entry(dp, flow, cmd):
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
priority = int(flow.get('priority', priority = str_to_int(
dp.ofproto.OFP_DEFAULT_PRIORITY)) flow.get('priority', dp.ofproto.OFP_DEFAULT_PRIORITY))
buffer_id = UTIL.ofp_buffer_from_user( buffer_id = UTIL.ofp_buffer_from_user(
flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER)) flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER))
out_port = UTIL.ofp_port_from_user( out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_NONE)) flow.get('out_port', dp.ofproto.OFPP_NONE))
flags = int(flow.get('flags', 0)) flags = str_to_int(flow.get('flags', 0))
idle_timeout = int(flow.get('idle_timeout', 0)) idle_timeout = str_to_int(flow.get('idle_timeout', 0))
hard_timeout = int(flow.get('hard_timeout', 0)) hard_timeout = str_to_int(flow.get('hard_timeout', 0))
actions = to_actions(dp, flow.get('actions', [])) actions = to_actions(dp, flow.get('actions', []))
match = to_match(dp, flow.get('match', {})) match = to_match(dp, flow.get('match', {}))
@@ -536,9 +537,9 @@ def delete_flow_entry(dp):
def mod_port_behavior(dp, port_config): def mod_port_behavior(dp, port_config):
port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0)) port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0))
hw_addr = str(port_config.get('hw_addr')) hw_addr = str(port_config.get('hw_addr'))
config = int(port_config.get('config', 0)) config = str_to_int(port_config.get('config', 0))
mask = int(port_config.get('mask', 0)) mask = str_to_int(port_config.get('mask', 0))
advertise = int(port_config.get('advertise')) advertise = str_to_int(port_config.get('advertise'))
port_mod = dp.ofproto_parser.OFPPortMod( port_mod = dp.ofproto_parser.OFPPortMod(
dp, port_no, hw_addr, config, mask, advertise) dp, port_no, hw_addr, config, mask, advertise)

View File

@@ -28,6 +28,7 @@ LOG = logging.getLogger('ryu.lib.ofctl_v1_2')
DEFAULT_TIMEOUT = 1.0 DEFAULT_TIMEOUT = 1.0
UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_2) UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_2)
str_to_int = ofctl_utils.str_to_int
def to_action(dp, dic): def to_action(dp, dic):
@@ -44,20 +45,20 @@ def to_action(dp, dic):
elif action_type == 'COPY_TTL_IN': elif action_type == 'COPY_TTL_IN':
result = parser.OFPActionCopyTtlIn() result = parser.OFPActionCopyTtlIn()
elif action_type == 'SET_MPLS_TTL': 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) result = parser.OFPActionSetMplsTtl(mpls_ttl)
elif action_type == 'DEC_MPLS_TTL': elif action_type == 'DEC_MPLS_TTL':
result = parser.OFPActionDecMplsTtl() result = parser.OFPActionDecMplsTtl()
elif action_type == 'PUSH_VLAN': elif action_type == 'PUSH_VLAN':
ethertype = int(dic.get('ethertype')) ethertype = str_to_int(dic.get('ethertype'))
result = parser.OFPActionPushVlan(ethertype) result = parser.OFPActionPushVlan(ethertype)
elif action_type == 'POP_VLAN': elif action_type == 'POP_VLAN':
result = parser.OFPActionPopVlan() result = parser.OFPActionPopVlan()
elif action_type == 'PUSH_MPLS': elif action_type == 'PUSH_MPLS':
ethertype = int(dic.get('ethertype')) ethertype = str_to_int(dic.get('ethertype'))
result = parser.OFPActionPushMpls(ethertype) result = parser.OFPActionPushMpls(ethertype)
elif action_type == 'POP_MPLS': elif action_type == 'POP_MPLS':
ethertype = int(dic.get('ethertype')) ethertype = str_to_int(dic.get('ethertype'))
result = parser.OFPActionPopMpls(ethertype) result = parser.OFPActionPopMpls(ethertype)
elif action_type == 'SET_QUEUE': elif action_type == 'SET_QUEUE':
queue_id = UTIL.ofp_queue_from_user(dic.get('queue_id')) 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')) group_id = UTIL.ofp_group_from_user(dic.get('group_id'))
result = parser.OFPActionGroup(group_id) result = parser.OFPActionGroup(group_id)
elif action_type == 'SET_NW_TTL': 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) result = parser.OFPActionSetNwTtl(nw_ttl)
elif action_type == 'DEC_NW_TTL': elif action_type == 'DEC_NW_TTL':
result = parser.OFPActionDecNwTtl() result = parser.OFPActionDecNwTtl()
@@ -112,8 +113,8 @@ def to_actions(dp, acts):
table_id = UTIL.ofp_table_from_user(a.get('table_id')) table_id = UTIL.ofp_table_from_user(a.get('table_id'))
inst.append(parser.OFPInstructionGotoTable(table_id)) inst.append(parser.OFPInstructionGotoTable(table_id))
elif action_type == 'WRITE_METADATA': elif action_type == 'WRITE_METADATA':
metadata = ofctl_utils.str_to_int(a.get('metadata')) metadata = str_to_int(a.get('metadata'))
metadata_mask = (ofctl_utils.str_to_int(a['metadata_mask']) metadata_mask = (str_to_int(a['metadata_mask'])
if 'metadata_mask' in a if 'metadata_mask' in a
else parser.UINT64_MAX) else parser.UINT64_MAX)
inst.append( inst.append(
@@ -208,50 +209,50 @@ def actions_to_str(instructions):
def to_match(dp, attrs): def to_match(dp, attrs):
convert = {'in_port': UTIL.ofp_port_from_user, convert = {'in_port': UTIL.ofp_port_from_user,
'in_phy_port': int, 'in_phy_port': str_to_int,
'metadata': to_match_masked_int, 'metadata': to_match_masked_int,
'dl_dst': to_match_eth, 'dl_dst': to_match_eth,
'dl_src': to_match_eth, 'dl_src': to_match_eth,
'eth_dst': to_match_eth, 'eth_dst': to_match_eth,
'eth_src': to_match_eth, 'eth_src': to_match_eth,
'dl_type': int, 'dl_type': str_to_int,
'eth_type': int, 'eth_type': str_to_int,
'dl_vlan': to_match_vid, 'dl_vlan': to_match_vid,
'vlan_vid': to_match_vid, 'vlan_vid': to_match_vid,
'vlan_pcp': int, 'vlan_pcp': str_to_int,
'ip_dscp': int, 'ip_dscp': str_to_int,
'ip_ecn': int, 'ip_ecn': str_to_int,
'nw_proto': int, 'nw_proto': str_to_int,
'ip_proto': int, 'ip_proto': str_to_int,
'nw_src': to_match_ip, 'nw_src': to_match_ip,
'nw_dst': to_match_ip, 'nw_dst': to_match_ip,
'ipv4_src': to_match_ip, 'ipv4_src': to_match_ip,
'ipv4_dst': to_match_ip, 'ipv4_dst': to_match_ip,
'tp_src': int, 'tp_src': str_to_int,
'tp_dst': int, 'tp_dst': str_to_int,
'tcp_src': int, 'tcp_src': str_to_int,
'tcp_dst': int, 'tcp_dst': str_to_int,
'udp_src': int, 'udp_src': str_to_int,
'udp_dst': int, 'udp_dst': str_to_int,
'sctp_src': int, 'sctp_src': str_to_int,
'sctp_dst': int, 'sctp_dst': str_to_int,
'icmpv4_type': int, 'icmpv4_type': str_to_int,
'icmpv4_code': int, 'icmpv4_code': str_to_int,
'arp_op': int, 'arp_op': str_to_int,
'arp_spa': to_match_ip, 'arp_spa': to_match_ip,
'arp_tpa': to_match_ip, 'arp_tpa': to_match_ip,
'arp_sha': to_match_eth, 'arp_sha': to_match_eth,
'arp_tha': to_match_eth, 'arp_tha': to_match_eth,
'ipv6_src': to_match_ip, 'ipv6_src': to_match_ip,
'ipv6_dst': to_match_ip, 'ipv6_dst': to_match_ip,
'ipv6_flabel': int, 'ipv6_flabel': str_to_int,
'icmpv6_type': int, 'icmpv6_type': str_to_int,
'icmpv6_code': int, 'icmpv6_code': str_to_int,
'ipv6_nd_target': to_match_ip, 'ipv6_nd_target': to_match_ip,
'ipv6_nd_sll': to_match_eth, 'ipv6_nd_sll': to_match_eth,
'ipv6_nd_tll': to_match_eth, 'ipv6_nd_tll': to_match_eth,
'mpls_label': int, 'mpls_label': str_to_int,
'mpls_tc': int} 'mpls_tc': str_to_int}
keys = {'dl_dst': 'eth_dst', keys = {'dl_dst': 'eth_dst',
'dl_src': 'eth_src', 'dl_src': 'eth_src',
@@ -416,12 +417,12 @@ def get_queue_stats(dp, waiters, port=None, queue_id=None):
if port is None: if port is None:
port = ofp.OFPP_ANY port = ofp.OFPP_ANY
else: else:
port = int(str(port), 0) port = str_to_int(port)
if queue_id is None: if queue_id is None:
queue_id = ofp.OFPQ_ALL queue_id = ofp.OFPQ_ALL
else: else:
queue_id = int(str(queue_id), 0) queue_id = str_to_int(queue_id)
stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, port, stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, port,
queue_id, 0) queue_id, 0)
@@ -446,7 +447,7 @@ def get_queue_config(dp, waiters, port=None):
if port is None: if port is None:
port = ofp.OFPP_ANY port = ofp.OFPP_ANY
else: 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) stats = dp.ofproto_parser.OFPQueueGetConfigRequest(dp, port)
msgs = [] msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG) 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)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) flow.get('out_group', dp.ofproto.OFPG_ANY))
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
match = to_match(dp, flow.get('match', {})) match = to_match(dp, flow.get('match', {}))
# Note: OpenFlow does not allow to filter flow entries by priority, # Note: OpenFlow does not allow to filter flow entries by priority,
# but for efficiency, ofctl provides the way to do it. # 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( stats = dp.ofproto_parser.OFPFlowStatsRequest(
dp, table_id, out_port, out_group, cookie, cookie_mask, match) 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)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) flow.get('out_group', dp.ofproto.OFPG_ANY))
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
match = to_match(dp, flow.get('match', {})) match = to_match(dp, flow.get('match', {}))
stats = dp.ofproto_parser.OFPAggregateStatsRequest( stats = dp.ofproto_parser.OFPAggregateStatsRequest(
@@ -685,7 +686,7 @@ def get_port_stats(dp, waiters, port=None):
if port is None: if port is None:
port = dp.ofproto.OFPP_ANY port = dp.ofproto.OFPP_ANY
else: else:
port = int(str(port), 0) port = str_to_int(port)
stats = dp.ofproto_parser.OFPPortStatsRequest( stats = dp.ofproto_parser.OFPPortStatsRequest(
dp, port, 0) dp, port, 0)
@@ -717,7 +718,7 @@ def get_group_stats(dp, waiters, group_id=None):
if group_id is None: if group_id is None:
group_id = dp.ofproto.OFPG_ALL group_id = dp.ofproto.OFPG_ALL
else: else:
group_id = int(str(group_id), 0) group_id = str_to_int(group_id)
stats = dp.ofproto_parser.OFPGroupStatsRequest( stats = dp.ofproto_parser.OFPGroupStatsRequest(
dp, group_id, 0) dp, group_id, 0)
@@ -863,19 +864,19 @@ def get_port_desc(dp, waiters):
def mod_flow_entry(dp, flow, cmd): def mod_flow_entry(dp, flow, cmd):
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0)) table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0))
idle_timeout = int(flow.get('idle_timeout', 0)) idle_timeout = str_to_int(flow.get('idle_timeout', 0))
hard_timeout = int(flow.get('hard_timeout', 0)) hard_timeout = str_to_int(flow.get('hard_timeout', 0))
priority = int(flow.get('priority', 0)) priority = str_to_int(flow.get('priority', 0))
buffer_id = UTIL.ofp_buffer_from_user( buffer_id = UTIL.ofp_buffer_from_user(
flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER)) flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER))
out_port = UTIL.ofp_port_from_user( out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_ANY)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) 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', {})) match = to_match(dp, flow.get('match', {}))
inst = to_actions(dp, flow.get('actions', [])) inst = to_actions(dp, flow.get('actions', []))
@@ -902,9 +903,11 @@ def mod_group_entry(dp, group, cmd):
buckets = [] buckets = []
for bucket in group.get('buckets', []): for bucket in group.get('buckets', []):
weight = int(bucket.get('weight', 0)) weight = str_to_int(bucket.get('weight', 0))
watch_port = int(bucket.get('watch_port', dp.ofproto.OFPP_ANY)) watch_port = str_to_int(
watch_group = int(bucket.get('watch_group', dp.ofproto.OFPG_ANY)) bucket.get('watch_port', dp.ofproto.OFPP_ANY))
watch_group = str_to_int(
bucket.get('watch_group', dp.ofproto.OFPG_ANY))
actions = [] actions = []
for dic in bucket.get('actions', []): for dic in bucket.get('actions', []):
action = to_action(dp, dic) action = to_action(dp, dic)
@@ -922,9 +925,9 @@ def mod_group_entry(dp, group, cmd):
def mod_port_behavior(dp, port_config): def mod_port_behavior(dp, port_config):
port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0)) port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0))
hw_addr = str(port_config.get('hw_addr')) hw_addr = str(port_config.get('hw_addr'))
config = int(port_config.get('config', 0)) config = str_to_int(port_config.get('config', 0))
mask = int(port_config.get('mask', 0)) mask = str_to_int(port_config.get('mask', 0))
advertise = int(port_config.get('advertise')) advertise = str_to_int(port_config.get('advertise'))
port_mod = dp.ofproto_parser.OFPPortMod( port_mod = dp.ofproto_parser.OFPPortMod(
dp, port_no, hw_addr, config, mask, advertise) dp, port_no, hw_addr, config, mask, advertise)

View File

@@ -30,6 +30,7 @@ LOG = logging.getLogger('ryu.lib.ofctl_v1_3')
DEFAULT_TIMEOUT = 1.0 DEFAULT_TIMEOUT = 1.0
UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_3) UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_3)
str_to_int = ofctl_utils.str_to_int
def to_action(dp, dic): 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')) table_id = UTIL.ofp_table_from_user(a.get('table_id'))
inst.append(parser.OFPInstructionGotoTable(table_id)) inst.append(parser.OFPInstructionGotoTable(table_id))
elif action_type == 'WRITE_METADATA': elif action_type == 'WRITE_METADATA':
metadata = ofctl_utils.str_to_int(a.get('metadata')) metadata = str_to_int(a.get('metadata'))
metadata_mask = (ofctl_utils.str_to_int(a['metadata_mask']) metadata_mask = (str_to_int(a['metadata_mask'])
if 'metadata_mask' in a if 'metadata_mask' in a
else parser.UINT64_MAX) else parser.UINT64_MAX)
inst.append( inst.append(
@@ -192,51 +193,51 @@ def actions_to_str(instructions):
def to_match(dp, attrs): def to_match(dp, attrs):
convert = {'in_port': UTIL.ofp_port_from_user, 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, 'metadata': ofctl_utils.to_match_masked_int,
'dl_dst': ofctl_utils.to_match_eth, 'dl_dst': ofctl_utils.to_match_eth,
'dl_src': ofctl_utils.to_match_eth, 'dl_src': ofctl_utils.to_match_eth,
'eth_dst': ofctl_utils.to_match_eth, 'eth_dst': ofctl_utils.to_match_eth,
'eth_src': ofctl_utils.to_match_eth, 'eth_src': ofctl_utils.to_match_eth,
'dl_type': int, 'dl_type': str_to_int,
'eth_type': int, 'eth_type': str_to_int,
'dl_vlan': to_match_vid, 'dl_vlan': to_match_vid,
'vlan_vid': to_match_vid, 'vlan_vid': to_match_vid,
'vlan_pcp': int, 'vlan_pcp': str_to_int,
'ip_dscp': int, 'ip_dscp': str_to_int,
'ip_ecn': int, 'ip_ecn': str_to_int,
'nw_proto': int, 'nw_proto': str_to_int,
'ip_proto': int, 'ip_proto': str_to_int,
'nw_src': ofctl_utils.to_match_ip, 'nw_src': ofctl_utils.to_match_ip,
'nw_dst': ofctl_utils.to_match_ip, 'nw_dst': ofctl_utils.to_match_ip,
'ipv4_src': ofctl_utils.to_match_ip, 'ipv4_src': ofctl_utils.to_match_ip,
'ipv4_dst': ofctl_utils.to_match_ip, 'ipv4_dst': ofctl_utils.to_match_ip,
'tp_src': int, 'tp_src': str_to_int,
'tp_dst': int, 'tp_dst': str_to_int,
'tcp_src': int, 'tcp_src': str_to_int,
'tcp_dst': int, 'tcp_dst': str_to_int,
'udp_src': int, 'udp_src': str_to_int,
'udp_dst': int, 'udp_dst': str_to_int,
'sctp_src': int, 'sctp_src': str_to_int,
'sctp_dst': int, 'sctp_dst': str_to_int,
'icmpv4_type': int, 'icmpv4_type': str_to_int,
'icmpv4_code': int, 'icmpv4_code': str_to_int,
'arp_op': int, 'arp_op': str_to_int,
'arp_spa': ofctl_utils.to_match_ip, 'arp_spa': ofctl_utils.to_match_ip,
'arp_tpa': ofctl_utils.to_match_ip, 'arp_tpa': ofctl_utils.to_match_ip,
'arp_sha': ofctl_utils.to_match_eth, 'arp_sha': ofctl_utils.to_match_eth,
'arp_tha': ofctl_utils.to_match_eth, 'arp_tha': ofctl_utils.to_match_eth,
'ipv6_src': ofctl_utils.to_match_ip, 'ipv6_src': ofctl_utils.to_match_ip,
'ipv6_dst': ofctl_utils.to_match_ip, 'ipv6_dst': ofctl_utils.to_match_ip,
'ipv6_flabel': int, 'ipv6_flabel': str_to_int,
'icmpv6_type': int, 'icmpv6_type': str_to_int,
'icmpv6_code': int, 'icmpv6_code': str_to_int,
'ipv6_nd_target': ofctl_utils.to_match_ip, 'ipv6_nd_target': ofctl_utils.to_match_ip,
'ipv6_nd_sll': ofctl_utils.to_match_eth, 'ipv6_nd_sll': ofctl_utils.to_match_eth,
'ipv6_nd_tll': ofctl_utils.to_match_eth, 'ipv6_nd_tll': ofctl_utils.to_match_eth,
'mpls_label': int, 'mpls_label': str_to_int,
'mpls_tc': int, 'mpls_tc': str_to_int,
'mpls_bos': int, 'mpls_bos': str_to_int,
'pbb_isid': ofctl_utils.to_match_masked_int, 'pbb_isid': ofctl_utils.to_match_masked_int,
'tunnel_id': ofctl_utils.to_match_masked_int, 'tunnel_id': ofctl_utils.to_match_masked_int,
'ipv6_exthdr': 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: if port is None:
port = ofp.OFPP_ANY port = ofp.OFPP_ANY
else: else:
port = int(str(port), 0) port = str_to_int(port)
if queue_id is None: if queue_id is None:
queue_id = ofp.OFPQ_ALL queue_id = ofp.OFPQ_ALL
else: else:
queue_id = int(str(queue_id), 0) queue_id = str_to_int(queue_id)
stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port, stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port,
queue_id) queue_id)
@@ -387,7 +388,7 @@ def get_queue_config(dp, waiters, port=None, to_user=True):
if port is None: if port is None:
port = ofp.OFPP_ANY port = ofp.OFPP_ANY
else: 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) stats = dp.ofproto_parser.OFPQueueGetConfigRequest(dp, port)
msgs = [] msgs = []
ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG) 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 {} flow = flow if flow else {}
table_id = UTIL.ofp_table_from_user( table_id = UTIL.ofp_table_from_user(
flow.get('table_id', dp.ofproto.OFPTT_ALL)) 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( out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_ANY)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) flow.get('out_group', dp.ofproto.OFPG_ANY))
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
match = to_match(dp, flow.get('match', {})) match = to_match(dp, flow.get('match', {}))
# Note: OpenFlow does not allow to filter flow entries by priority, # Note: OpenFlow does not allow to filter flow entries by priority,
# but for efficiency, ofctl provides the way to do it. # 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( stats = dp.ofproto_parser.OFPFlowStatsRequest(
dp, flags, table_id, out_port, out_group, cookie, cookie_mask, 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 {} flow = flow if flow else {}
table_id = UTIL.ofp_table_from_user( table_id = UTIL.ofp_table_from_user(
flow.get('table_id', dp.ofproto.OFPTT_ALL)) 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( out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_ANY)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) flow.get('out_group', dp.ofproto.OFPG_ANY))
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
match = to_match(dp, flow.get('match', {})) match = to_match(dp, flow.get('match', {}))
stats = dp.ofproto_parser.OFPAggregateStatsRequest( stats = dp.ofproto_parser.OFPAggregateStatsRequest(
@@ -655,7 +656,7 @@ def get_port_stats(dp, waiters, port=None, to_user=True):
if port is None: if port is None:
port = dp.ofproto.OFPP_ANY port = dp.ofproto.OFPP_ANY
else: else:
port = int(str(port), 0) port = str_to_int(port)
stats = dp.ofproto_parser.OFPPortStatsRequest( stats = dp.ofproto_parser.OFPPortStatsRequest(
dp, 0, port) dp, 0, port)
@@ -695,7 +696,7 @@ def get_meter_stats(dp, waiters, meter_id=None, to_user=True):
if meter_id is None: if meter_id is None:
meter_id = dp.ofproto.OFPM_ALL meter_id = dp.ofproto.OFPM_ALL
else: else:
meter_id = int(str(meter_id), 0) meter_id = str_to_int(meter_id)
stats = dp.ofproto_parser.OFPMeterStatsRequest( stats = dp.ofproto_parser.OFPMeterStatsRequest(
dp, 0, meter_id) 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: if meter_id is None:
meter_id = dp.ofproto.OFPM_ALL meter_id = dp.ofproto.OFPM_ALL
else: else:
meter_id = int(str(meter_id), 0) meter_id = str_to_int(meter_id)
stats = dp.ofproto_parser.OFPMeterConfigStatsRequest( stats = dp.ofproto_parser.OFPMeterConfigStatsRequest(
dp, 0, meter_id) 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: if group_id is None:
group_id = dp.ofproto.OFPG_ALL group_id = dp.ofproto.OFPG_ALL
else: else:
group_id = int(str(group_id), 0) group_id = str_to_int(group_id)
stats = dp.ofproto_parser.OFPGroupStatsRequest( stats = dp.ofproto_parser.OFPGroupStatsRequest(
dp, 0, group_id) dp, 0, group_id)
@@ -1042,19 +1043,19 @@ def get_port_desc(dp, waiters, to_user=True):
def mod_flow_entry(dp, flow, cmd): def mod_flow_entry(dp, flow, cmd):
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0)) table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0))
idle_timeout = int(flow.get('idle_timeout', 0)) idle_timeout = str_to_int(flow.get('idle_timeout', 0))
hard_timeout = int(flow.get('hard_timeout', 0)) hard_timeout = str_to_int(flow.get('hard_timeout', 0))
priority = int(flow.get('priority', 0)) priority = str_to_int(flow.get('priority', 0))
buffer_id = UTIL.ofp_buffer_from_user( buffer_id = UTIL.ofp_buffer_from_user(
flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER)) flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER))
out_port = UTIL.ofp_port_from_user( out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_ANY)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) 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', {})) match = to_match(dp, flow.get('match', {}))
inst = to_actions(dp, flow.get('actions', [])) inst = to_actions(dp, flow.get('actions', []))
@@ -1089,18 +1090,18 @@ def mod_meter_entry(dp, meter, cmd):
bands = [] bands = []
for band in meter.get('bands', []): for band in meter.get('bands', []):
band_type = band.get('type') band_type = band.get('type')
rate = int(band.get('rate', 0)) rate = str_to_int(band.get('rate', 0))
burst_size = int(band.get('burst_size', 0)) burst_size = str_to_int(band.get('burst_size', 0))
if band_type == 'DROP': if band_type == 'DROP':
bands.append( bands.append(
dp.ofproto_parser.OFPMeterBandDrop(rate, burst_size)) dp.ofproto_parser.OFPMeterBandDrop(rate, burst_size))
elif band_type == 'DSCP_REMARK': 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( bands.append(
dp.ofproto_parser.OFPMeterBandDscpRemark( dp.ofproto_parser.OFPMeterBandDscpRemark(
rate, burst_size, prec_level)) rate, burst_size, prec_level))
elif band_type == 'EXPERIMENTER': elif band_type == 'EXPERIMENTER':
experimenter = int(band.get('experimenter', 0)) experimenter = str_to_int(band.get('experimenter', 0))
bands.append( bands.append(
dp.ofproto_parser.OFPMeterBandExperimenter( dp.ofproto_parser.OFPMeterBandExperimenter(
rate, burst_size, experimenter)) rate, burst_size, experimenter))
@@ -1128,9 +1129,11 @@ def mod_group_entry(dp, group, cmd):
buckets = [] buckets = []
for bucket in group.get('buckets', []): for bucket in group.get('buckets', []):
weight = int(bucket.get('weight', 0)) weight = str_to_int(bucket.get('weight', 0))
watch_port = int(bucket.get('watch_port', dp.ofproto.OFPP_ANY)) watch_port = str_to_int(
watch_group = int(bucket.get('watch_group', dp.ofproto.OFPG_ANY)) bucket.get('watch_port', dp.ofproto.OFPP_ANY))
watch_group = str_to_int(
bucket.get('watch_group', dp.ofproto.OFPG_ANY))
actions = [] actions = []
for dic in bucket.get('actions', []): for dic in bucket.get('actions', []):
action = to_action(dp, dic) action = to_action(dp, dic)
@@ -1148,9 +1151,9 @@ def mod_group_entry(dp, group, cmd):
def mod_port_behavior(dp, port_config): def mod_port_behavior(dp, port_config):
port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0)) port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0))
hw_addr = str(port_config.get('hw_addr')) hw_addr = str(port_config.get('hw_addr'))
config = int(port_config.get('config', 0)) config = str_to_int(port_config.get('config', 0))
mask = int(port_config.get('mask', 0)) mask = str_to_int(port_config.get('mask', 0))
advertise = int(port_config.get('advertise')) advertise = str_to_int(port_config.get('advertise'))
port_mod = dp.ofproto_parser.OFPPortMod( port_mod = dp.ofproto_parser.OFPPortMod(
dp, port_no, hw_addr, config, mask, advertise) dp, port_no, hw_addr, config, mask, advertise)

View File

@@ -25,6 +25,7 @@ LOG = logging.getLogger(__name__)
DEFAULT_TIMEOUT = 1.0 DEFAULT_TIMEOUT = 1.0
UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_4) UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_4)
str_to_int = ofctl_utils.str_to_int
def to_action(dp, dic): def to_action(dp, dic):
@@ -68,18 +69,18 @@ def to_instructions(dp, insts):
instructions.append( instructions.append(
parser.OFPInstructionActions(ofp.OFPIT_CLEAR_ACTIONS, [])) parser.OFPInstructionActions(ofp.OFPIT_CLEAR_ACTIONS, []))
elif inst_type == 'GOTO_TABLE': 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)) instructions.append(parser.OFPInstructionGotoTable(table_id))
elif inst_type == 'WRITE_METADATA': elif inst_type == 'WRITE_METADATA':
metadata = ofctl_utils.str_to_int(i.get('metadata')) metadata = str_to_int(i.get('metadata'))
metadata_mask = (ofctl_utils.str_to_int(i['metadata_mask']) metadata_mask = (str_to_int(i['metadata_mask'])
if 'metadata_mask' in i if 'metadata_mask' in i
else parser.UINT64_MAX) else parser.UINT64_MAX)
instructions.append( instructions.append(
parser.OFPInstructionWriteMetadata( parser.OFPInstructionWriteMetadata(
metadata, metadata_mask)) metadata, metadata_mask))
elif inst_type == 'METER': 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)) instructions.append(parser.OFPInstructionMeter(meter_id))
else: else:
LOG.error('Unknown instruction type: %s', inst_type) LOG.error('Unknown instruction type: %s', inst_type)
@@ -127,46 +128,46 @@ def instructions_to_str(instructions):
def to_match(dp, attrs): def to_match(dp, attrs):
convert = {'in_port': UTIL.ofp_port_from_user, 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, 'metadata': ofctl_utils.to_match_masked_int,
'eth_dst': ofctl_utils.to_match_eth, 'eth_dst': ofctl_utils.to_match_eth,
'eth_src': 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_vid': to_match_vid,
'vlan_pcp': int, 'vlan_pcp': str_to_int,
'ip_dscp': int, 'ip_dscp': str_to_int,
'ip_ecn': int, 'ip_ecn': str_to_int,
'ip_proto': int, 'ip_proto': str_to_int,
'ipv4_src': ofctl_utils.to_match_ip, 'ipv4_src': ofctl_utils.to_match_ip,
'ipv4_dst': ofctl_utils.to_match_ip, 'ipv4_dst': ofctl_utils.to_match_ip,
'tcp_src': int, 'tcp_src': str_to_int,
'tcp_dst': int, 'tcp_dst': str_to_int,
'udp_src': int, 'udp_src': str_to_int,
'udp_dst': int, 'udp_dst': str_to_int,
'sctp_src': int, 'sctp_src': str_to_int,
'sctp_dst': int, 'sctp_dst': str_to_int,
'icmpv4_type': int, 'icmpv4_type': str_to_int,
'icmpv4_code': int, 'icmpv4_code': str_to_int,
'arp_op': int, 'arp_op': str_to_int,
'arp_spa': ofctl_utils.to_match_ip, 'arp_spa': ofctl_utils.to_match_ip,
'arp_tpa': ofctl_utils.to_match_ip, 'arp_tpa': ofctl_utils.to_match_ip,
'arp_sha': ofctl_utils.to_match_eth, 'arp_sha': ofctl_utils.to_match_eth,
'arp_tha': ofctl_utils.to_match_eth, 'arp_tha': ofctl_utils.to_match_eth,
'ipv6_src': ofctl_utils.to_match_ip, 'ipv6_src': ofctl_utils.to_match_ip,
'ipv6_dst': ofctl_utils.to_match_ip, 'ipv6_dst': ofctl_utils.to_match_ip,
'ipv6_flabel': int, 'ipv6_flabel': str_to_int,
'icmpv6_type': int, 'icmpv6_type': str_to_int,
'icmpv6_code': int, 'icmpv6_code': str_to_int,
'ipv6_nd_target': ofctl_utils.to_match_ip, 'ipv6_nd_target': ofctl_utils.to_match_ip,
'ipv6_nd_sll': ofctl_utils.to_match_eth, 'ipv6_nd_sll': ofctl_utils.to_match_eth,
'ipv6_nd_tll': ofctl_utils.to_match_eth, 'ipv6_nd_tll': ofctl_utils.to_match_eth,
'mpls_label': int, 'mpls_label': str_to_int,
'mpls_tc': int, 'mpls_tc': str_to_int,
'mpls_bos': int, 'mpls_bos': str_to_int,
'pbb_isid': ofctl_utils.to_match_masked_int, 'pbb_isid': ofctl_utils.to_match_masked_int,
'tunnel_id': ofctl_utils.to_match_masked_int, 'tunnel_id': ofctl_utils.to_match_masked_int,
'ipv6_exthdr': 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', keys = {'dl_dst': 'eth_dst',
'dl_src': 'eth_src', 'dl_src': 'eth_src',
@@ -314,17 +315,17 @@ def get_flow_stats(dp, waiters, flow=None, to_user=True):
flow = flow if flow else {} flow = flow if flow else {}
table_id = UTIL.ofp_table_from_user( table_id = UTIL.ofp_table_from_user(
flow.get('table_id', dp.ofproto.OFPTT_ALL)) 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( out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_ANY)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) flow.get('out_group', dp.ofproto.OFPG_ANY))
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
match = to_match(dp, flow.get('match', {})) match = to_match(dp, flow.get('match', {}))
# Note: OpenFlow does not allow to filter flow entries by priority, # Note: OpenFlow does not allow to filter flow entries by priority,
# but for efficiency, ofctl provides the way to do it. # 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( stats = dp.ofproto_parser.OFPFlowStatsRequest(
dp, flags, table_id, out_port, out_group, cookie, cookie_mask, 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 {} flow = flow if flow else {}
table_id = UTIL.ofp_table_from_user( table_id = UTIL.ofp_table_from_user(
flow.get('table_id', dp.ofproto.OFPTT_ALL)) 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( out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_ANY)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) flow.get('out_group', dp.ofproto.OFPG_ANY))
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
match = to_match(dp, flow.get('match', {})) match = to_match(dp, flow.get('match', {}))
stats = dp.ofproto_parser.OFPAggregateStatsRequest( 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): def mod_flow_entry(dp, flow, cmd):
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0)) table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0))
idle_timeout = int(flow.get('idle_timeout', 0)) idle_timeout = str_to_int(flow.get('idle_timeout', 0))
hard_timeout = int(flow.get('hard_timeout', 0)) hard_timeout = str_to_int(flow.get('hard_timeout', 0))
priority = int(flow.get('priority', 0)) priority = str_to_int(flow.get('priority', 0))
buffer_id = UTIL.ofp_buffer_from_user( buffer_id = UTIL.ofp_buffer_from_user(
flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER)) flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER))
out_port = UTIL.ofp_port_from_user( out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_ANY)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) flow.get('out_group', dp.ofproto.OFPG_ANY))
importance = int(flow.get('importance', 0)) importance = str_to_int(flow.get('importance', 0))
flags = int(flow.get('flags', 0)) flags = str_to_int(flow.get('flags', 0))
match = to_match(dp, flow.get('match', {})) match = to_match(dp, flow.get('match', {}))
inst = to_instructions(dp, flow.get('instructions', [])) inst = to_instructions(dp, flow.get('instructions', []))
@@ -857,18 +858,18 @@ def mod_meter_entry(dp, meter, cmd):
bands = [] bands = []
for band in meter.get('bands', []): for band in meter.get('bands', []):
band_type = band.get('type') band_type = band.get('type')
rate = int(band.get('rate', 0)) rate = str_to_int(band.get('rate', 0))
burst_size = int(band.get('burst_size', 0)) burst_size = str_to_int(band.get('burst_size', 0))
if band_type == 'DROP': if band_type == 'DROP':
bands.append( bands.append(
dp.ofproto_parser.OFPMeterBandDrop(rate, burst_size)) dp.ofproto_parser.OFPMeterBandDrop(rate, burst_size))
elif band_type == 'DSCP_REMARK': 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( bands.append(
dp.ofproto_parser.OFPMeterBandDscpRemark( dp.ofproto_parser.OFPMeterBandDscpRemark(
rate, burst_size, prec_level)) rate, burst_size, prec_level))
elif band_type == 'EXPERIMENTER': elif band_type == 'EXPERIMENTER':
experimenter = int(band.get('experimenter', 0)) experimenter = str_to_int(band.get('experimenter', 0))
bands.append( bands.append(
dp.ofproto_parser.OFPMeterBandExperimenter( dp.ofproto_parser.OFPMeterBandExperimenter(
rate, burst_size, experimenter)) rate, burst_size, experimenter))
@@ -892,9 +893,11 @@ def mod_group_entry(dp, group, cmd):
buckets = [] buckets = []
for bucket in group.get('buckets', []): for bucket in group.get('buckets', []):
weight = int(bucket.get('weight', 0)) weight = str_to_int(bucket.get('weight', 0))
watch_port = int(bucket.get('watch_port', dp.ofproto.OFPP_ANY)) watch_port = str_to_int(
watch_group = int(bucket.get('watch_group', dp.ofproto.OFPG_ANY)) bucket.get('watch_port', dp.ofproto.OFPP_ANY))
watch_group = str_to_int(
bucket.get('watch_group', dp.ofproto.OFPG_ANY))
actions = [] actions = []
for dic in bucket.get('actions', []): for dic in bucket.get('actions', []):
action = to_action(dp, dic) action = to_action(dp, dic)
@@ -914,8 +917,8 @@ def mod_port_behavior(dp, port_config):
parser = dp.ofproto_parser parser = dp.ofproto_parser
port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0)) port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0))
hw_addr = str(port_config.get('hw_addr')) hw_addr = str(port_config.get('hw_addr'))
config = int(port_config.get('config', 0)) config = str_to_int(port_config.get('config', 0))
mask = int(port_config.get('mask', 0)) mask = str_to_int(port_config.get('mask', 0))
properties = port_config.get('properties') properties = port_config.get('properties')
prop = [] prop = []

View File

@@ -26,6 +26,7 @@ LOG = logging.getLogger(__name__)
DEFAULT_TIMEOUT = 1.0 DEFAULT_TIMEOUT = 1.0
UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_5) UTIL = ofctl_utils.OFCtlUtil(ofproto_v1_5)
str_to_int = ofctl_utils.str_to_int
def to_action(dp, dic): def to_action(dp, dic):
@@ -69,11 +70,11 @@ def to_instructions(dp, insts):
instructions.append( instructions.append(
parser.OFPInstructionActions(ofp.OFPIT_CLEAR_ACTIONS, [])) parser.OFPInstructionActions(ofp.OFPIT_CLEAR_ACTIONS, []))
elif inst_type == 'GOTO_TABLE': 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)) instructions.append(parser.OFPInstructionGotoTable(table_id))
elif inst_type == 'WRITE_METADATA': elif inst_type == 'WRITE_METADATA':
metadata = ofctl_utils.str_to_int(i.get('metadata')) metadata = str_to_int(i.get('metadata'))
metadata_mask = (ofctl_utils.str_to_int(i['metadata_mask']) metadata_mask = (str_to_int(i['metadata_mask'])
if 'metadata_mask' in i if 'metadata_mask' in i
else parser.UINT64_MAX) else parser.UINT64_MAX)
instructions.append( instructions.append(
@@ -129,48 +130,48 @@ def instructions_to_str(instructions):
def to_match(dp, attrs): def to_match(dp, attrs):
convert = {'in_port': UTIL.ofp_port_from_user, 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, 'metadata': ofctl_utils.to_match_masked_int,
'eth_dst': ofctl_utils.to_match_eth, 'eth_dst': ofctl_utils.to_match_eth,
'eth_src': 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_vid': to_match_vid,
'vlan_pcp': int, 'vlan_pcp': str_to_int,
'ip_dscp': int, 'ip_dscp': str_to_int,
'ip_ecn': int, 'ip_ecn': str_to_int,
'ip_proto': int, 'ip_proto': str_to_int,
'ipv4_src': ofctl_utils.to_match_ip, 'ipv4_src': ofctl_utils.to_match_ip,
'ipv4_dst': ofctl_utils.to_match_ip, 'ipv4_dst': ofctl_utils.to_match_ip,
'tcp_src': int, 'tcp_src': str_to_int,
'tcp_dst': int, 'tcp_dst': str_to_int,
'udp_src': int, 'udp_src': str_to_int,
'udp_dst': int, 'udp_dst': str_to_int,
'sctp_src': int, 'sctp_src': str_to_int,
'sctp_dst': int, 'sctp_dst': str_to_int,
'icmpv4_type': int, 'icmpv4_type': str_to_int,
'icmpv4_code': int, 'icmpv4_code': str_to_int,
'arp_op': int, 'arp_op': str_to_int,
'arp_spa': ofctl_utils.to_match_ip, 'arp_spa': ofctl_utils.to_match_ip,
'arp_tpa': ofctl_utils.to_match_ip, 'arp_tpa': ofctl_utils.to_match_ip,
'arp_sha': ofctl_utils.to_match_eth, 'arp_sha': ofctl_utils.to_match_eth,
'arp_tha': ofctl_utils.to_match_eth, 'arp_tha': ofctl_utils.to_match_eth,
'ipv6_src': ofctl_utils.to_match_ip, 'ipv6_src': ofctl_utils.to_match_ip,
'ipv6_dst': ofctl_utils.to_match_ip, 'ipv6_dst': ofctl_utils.to_match_ip,
'ipv6_flabel': int, 'ipv6_flabel': str_to_int,
'icmpv6_type': int, 'icmpv6_type': str_to_int,
'icmpv6_code': int, 'icmpv6_code': str_to_int,
'ipv6_nd_target': ofctl_utils.to_match_ip, 'ipv6_nd_target': ofctl_utils.to_match_ip,
'ipv6_nd_sll': ofctl_utils.to_match_eth, 'ipv6_nd_sll': ofctl_utils.to_match_eth,
'ipv6_nd_tll': ofctl_utils.to_match_eth, 'ipv6_nd_tll': ofctl_utils.to_match_eth,
'mpls_label': int, 'mpls_label': str_to_int,
'mpls_tc': int, 'mpls_tc': str_to_int,
'mpls_bos': int, 'mpls_bos': str_to_int,
'pbb_isid': ofctl_utils.to_match_masked_int, 'pbb_isid': ofctl_utils.to_match_masked_int,
'tunnel_id': ofctl_utils.to_match_masked_int, 'tunnel_id': ofctl_utils.to_match_masked_int,
'ipv6_exthdr': ofctl_utils.to_match_masked_int, 'ipv6_exthdr': ofctl_utils.to_match_masked_int,
'pbb_uca': int, 'pbb_uca': str_to_int,
'tcp_flags': int, 'tcp_flags': str_to_int,
'actset_output': int, 'actset_output': str_to_int,
'packet_type': ofctl_utils.to_match_packet_type} 'packet_type': ofctl_utils.to_match_packet_type}
keys = {'dl_dst': 'eth_dst', 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 {} flow = flow if flow else {}
table_id = UTIL.ofp_table_from_user( table_id = UTIL.ofp_table_from_user(
flow.get('table_id', dp.ofproto.OFPTT_ALL)) 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( out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_ANY)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) flow.get('out_group', dp.ofproto.OFPG_ANY))
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
match = to_match(dp, flow.get('match', {})) match = to_match(dp, flow.get('match', {}))
# Note: OpenFlow does not allow to filter flow entries by priority, # Note: OpenFlow does not allow to filter flow entries by priority,
# but for efficiency, ofctl provides the way to do it. # 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( stats = dp.ofproto_parser.OFPFlowDescStatsRequest(
dp, flags, table_id, out_port, out_group, cookie, cookie_mask, 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 {} flow = flow if flow else {}
table_id = UTIL.ofp_table_from_user( table_id = UTIL.ofp_table_from_user(
flow.get('table_id', dp.ofproto.OFPTT_ALL)) 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( out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_ANY)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) flow.get('out_group', dp.ofproto.OFPG_ANY))
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
match = to_match(dp, flow.get('match', {})) match = to_match(dp, flow.get('match', {}))
# Note: OpenFlow does not allow to filter flow entries by priority, # Note: OpenFlow does not allow to filter flow entries by priority,
# but for efficiency, ofctl provides the way to do it. # 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( stats = dp.ofproto_parser.OFPFlowStatsRequest(
dp, flags, table_id, out_port, out_group, cookie, cookie_mask, 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 {} flow = flow if flow else {}
table_id = UTIL.ofp_table_from_user( table_id = UTIL.ofp_table_from_user(
flow.get('table_id', dp.ofproto.OFPTT_ALL)) 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( out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_ANY)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) flow.get('out_group', dp.ofproto.OFPG_ANY))
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
match = to_match(dp, flow.get('match', {})) match = to_match(dp, flow.get('match', {}))
stats = dp.ofproto_parser.OFPAggregateStatsRequest( 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): def mod_flow_entry(dp, flow, cmd):
cookie = int(flow.get('cookie', 0)) cookie = str_to_int(flow.get('cookie', 0))
cookie_mask = int(flow.get('cookie_mask', 0)) cookie_mask = str_to_int(flow.get('cookie_mask', 0))
table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0)) table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0))
idle_timeout = int(flow.get('idle_timeout', 0)) idle_timeout = str_to_int(flow.get('idle_timeout', 0))
hard_timeout = int(flow.get('hard_timeout', 0)) hard_timeout = str_to_int(flow.get('hard_timeout', 0))
priority = int(flow.get('priority', 0)) priority = str_to_int(flow.get('priority', 0))
buffer_id = UTIL.ofp_buffer_from_user( buffer_id = UTIL.ofp_buffer_from_user(
flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER)) flow.get('buffer_id', dp.ofproto.OFP_NO_BUFFER))
out_port = UTIL.ofp_port_from_user( out_port = UTIL.ofp_port_from_user(
flow.get('out_port', dp.ofproto.OFPP_ANY)) flow.get('out_port', dp.ofproto.OFPP_ANY))
out_group = UTIL.ofp_group_from_user( out_group = UTIL.ofp_group_from_user(
flow.get('out_group', dp.ofproto.OFPG_ANY)) flow.get('out_group', dp.ofproto.OFPG_ANY))
importance = int(flow.get('importance', 0)) importance = str_to_int(flow.get('importance', 0))
flags = int(flow.get('flags', 0)) flags = str_to_int(flow.get('flags', 0))
match = to_match(dp, flow.get('match', {})) match = to_match(dp, flow.get('match', {}))
inst = to_instructions(dp, flow.get('instructions', [])) inst = to_instructions(dp, flow.get('instructions', []))
@@ -954,18 +955,18 @@ def mod_meter_entry(dp, meter, cmd):
bands = [] bands = []
for band in meter.get('bands', []): for band in meter.get('bands', []):
band_type = band.get('type') band_type = band.get('type')
rate = int(band.get('rate', 0)) rate = str_to_int(band.get('rate', 0))
burst_size = int(band.get('burst_size', 0)) burst_size = str_to_int(band.get('burst_size', 0))
if band_type == 'DROP': if band_type == 'DROP':
bands.append( bands.append(
dp.ofproto_parser.OFPMeterBandDrop(rate, burst_size)) dp.ofproto_parser.OFPMeterBandDrop(rate, burst_size))
elif band_type == 'DSCP_REMARK': 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( bands.append(
dp.ofproto_parser.OFPMeterBandDscpRemark( dp.ofproto_parser.OFPMeterBandDscpRemark(
rate, burst_size, prec_level)) rate, burst_size, prec_level))
elif band_type == 'EXPERIMENTER': elif band_type == 'EXPERIMENTER':
experimenter = int(band.get('experimenter', 0)) experimenter = str_to_int(band.get('experimenter', 0))
bands.append( bands.append(
dp.ofproto_parser.OFPMeterBandExperimenter( dp.ofproto_parser.OFPMeterBandExperimenter(
rate, burst_size, experimenter)) rate, burst_size, experimenter))
@@ -989,7 +990,7 @@ def mod_group_entry(dp, group, cmd):
LOG.error('Unknown group type: %s', group.get('type')) LOG.error('Unknown group type: %s', group.get('type'))
group_id = UTIL.ofp_group_from_user(group.get('group_id', 0)) 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: # Note:
# The list of group property types that are currently defined # 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', []): for bucket in group.get('buckets', []):
# get bucket_id in 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 # get actions in buckets
bucket_actions = [] 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 group_bp_type = t if t != group_bp_type else ofp.OFPGBPT_WEIGHT
if group_bp_type == 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( bucket_properties.append(
parser.OFPGroupBucketPropWeight( parser.OFPGroupBucketPropWeight(
type_=group_bp_type, weight=weight)) type_=group_bp_type, weight=weight))
elif group_bp_type == ofp.OFPGBPT_WATCH_PORT: 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( bucket_properties.append(
parser.OFPGroupBucketPropWatch( parser.OFPGroupBucketPropWatch(
type_=group_bp_type, watch=watch_port)) type_=group_bp_type, watch=watch_port))
elif group_bp_type == ofp.OFPGBPT_WATCH_GROUP: 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( bucket_properties.append(
parser.OFPGroupBucketPropWatch( parser.OFPGroupBucketPropWatch(
type_=group_bp_type, watch=watch_group)) type_=group_bp_type, watch=watch_group))
@@ -1065,8 +1066,8 @@ def mod_port_behavior(dp, port_config):
parser = dp.ofproto_parser parser = dp.ofproto_parser
port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0)) port_no = UTIL.ofp_port_from_user(port_config.get('port_no', 0))
hw_addr = str(port_config.get('hw_addr')) hw_addr = str(port_config.get('hw_addr'))
config = int(port_config.get('config', 0)) config = str_to_int(port_config.get('config', 0))
mask = int(port_config.get('mask', 0)) mask = str_to_int(port_config.get('mask', 0))
properties = port_config.get('properties') properties = port_config.get('properties')
prop = [] prop = []