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.py140
1 files changed, 22 insertions, 118 deletions
diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py
index 6363e517..e5e0a63c 100644
--- a/ryu/lib/ofctl_v1_2.py
+++ b/ryu/lib/ofctl_v1_2.py
@@ -34,51 +34,8 @@ str_to_int = ofctl_utils.str_to_int
def to_action(dp, dic):
ofp = dp.ofproto
parser = dp.ofproto_parser
-
action_type = dic.get('type')
- if action_type == 'OUTPUT':
- out_port = UTIL.ofp_port_from_user(dic.get('port', ofp.OFPP_ANY))
- max_len = UTIL.ofp_cml_from_user(dic.get('max_len', ofp.OFPCML_MAX))
- result = parser.OFPActionOutput(out_port, max_len)
- elif action_type == 'COPY_TTL_OUT':
- result = parser.OFPActionCopyTtlOut()
- elif action_type == 'COPY_TTL_IN':
- result = parser.OFPActionCopyTtlIn()
- elif action_type == 'SET_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 = str_to_int(dic.get('ethertype'))
- result = parser.OFPActionPushVlan(ethertype)
- elif action_type == 'POP_VLAN':
- result = parser.OFPActionPopVlan()
- elif action_type == 'PUSH_MPLS':
- ethertype = str_to_int(dic.get('ethertype'))
- result = parser.OFPActionPushMpls(ethertype)
- elif action_type == 'POP_MPLS':
- 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'))
- result = parser.OFPActionSetQueue(queue_id)
- elif action_type == 'GROUP':
- group_id = UTIL.ofp_group_from_user(dic.get('group_id'))
- result = parser.OFPActionGroup(group_id)
- elif action_type == 'SET_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()
- elif action_type == 'SET_FIELD':
- field = dic.get('field')
- value = dic.get('value')
- result = parser.OFPActionSetField(**{field: value})
- else:
- result = None
-
- return result
+ return ofctl_utils.to_action(dic, ofp, parser, action_type, UTIL)
def to_actions(dp, acts):
@@ -210,11 +167,11 @@ def actions_to_str(instructions):
def to_match(dp, attrs):
convert = {'in_port': UTIL.ofp_port_from_user,
'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,
+ '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': str_to_int,
'eth_type': str_to_int,
'dl_vlan': to_match_vid,
@@ -224,10 +181,10 @@ def to_match(dp, attrs):
'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,
+ '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': str_to_int,
'tp_dst': str_to_int,
'tcp_src': str_to_int,
@@ -239,18 +196,18 @@ def to_match(dp, attrs):
'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,
+ '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': 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,
+ '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': str_to_int,
'mpls_tc': str_to_int}
@@ -296,55 +253,8 @@ def to_match(dp, attrs):
return dp.ofproto_parser.OFPMatch(**kwargs)
-def to_match_eth(value):
- if '/' in value:
- value = value.split('/')
- return value[0], value[1]
- else:
- return value
-
-
-def to_match_ip(value):
- if '/' in value:
- (ip_addr, ip_mask) = value.split('/')
- if ip_mask.isdigit():
- ip = netaddr.ip.IPNetwork(value)
- ip_addr = str(ip.ip)
- ip_mask = str(ip.netmask)
- return ip_addr, ip_mask
- else:
- return value
-
-
def to_match_vid(value):
- # NOTE: If "vlan_id/dl_vlan" field is described as decimal int value
- # (and decimal string value), it is treated as values of
- # VLAN tag, and OFPVID_PRESENT(0x1000) bit is automatically
- # applied. OTOH, If it is described as hexadecimal string,
- # treated as values of oxm_value (including OFPVID_PRESENT
- # bit), and OFPVID_PRESENT bit is NOT automatically applied.
- if isinstance(value, int):
- # described as decimal int value
- return value | ofproto_v1_2.OFPVID_PRESENT
- else:
- if '/' in value:
- val = value.split('/')
- return int(val[0], 0), int(val[1], 0)
- else:
- if value.isdigit():
- # described as decimal string value
- return int(value, 10) | ofproto_v1_2.OFPVID_PRESENT
- else:
- return int(value, 0)
-
-
-def to_match_masked_int(value):
- if isinstance(value, str) and '/' in value:
- value = value.split('/')
- return (ofctl_utils.str_to_int(value[0]),
- ofctl_utils.str_to_int(value[1]))
- else:
- return ofctl_utils.str_to_int(value)
+ return ofctl_utils.to_match_vid(value, ofproto_v1_2.OFPVID_PRESENT)
def match_to_str(ofmatch):
@@ -384,14 +294,8 @@ def match_to_str(ofmatch):
def match_vid_to_str(value, mask):
- if mask is not None:
- value = '0x%04x/0x%04x' % (value, mask)
- else:
- if value & ofproto_v1_2.OFPVID_PRESENT:
- value = str(value & ~ofproto_v1_2.OFPVID_PRESENT)
- else:
- value = '0x%04x' % value
- return value
+ return ofctl_utils.match_vid_to_str(
+ value, mask, ofproto_v1_2.OFPVID_PRESENT)
def get_desc_stats(dp, waiters):