mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-05-08 22:06:10 +02:00
ofctl_v1_*: Use utility functions of ofctl_utils
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:
parent
dffb3d3cf6
commit
d2a97b16aa
@ -21,6 +21,7 @@ import six
|
||||
|
||||
from ryu.lib import dpid
|
||||
from ryu.lib import hub
|
||||
from ryu.ofproto import ofproto_v1_2
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -71,13 +72,15 @@ def to_action(dic, ofp, parser, action_type, util):
|
||||
COPY_TTL_IN: parser.OFPActionCopyTtlIn,
|
||||
DEC_MPLS_TTL: parser.OFPActionDecMplsTtl,
|
||||
POP_VLAN: parser.OFPActionPopVlan,
|
||||
DEC_NW_TTL: parser.OFPActionDecNwTtl,
|
||||
POP_PBB: parser.OFPActionPopPbb}
|
||||
DEC_NW_TTL: parser.OFPActionDecNwTtl}
|
||||
if ofp.OFP_VERSION > ofproto_v1_2.OFP_VERSION:
|
||||
actions[POP_PBB] = parser.OFPActionPopPbb
|
||||
|
||||
need_ethertype = {PUSH_VLAN: parser.OFPActionPushVlan,
|
||||
PUSH_MPLS: parser.OFPActionPushMpls,
|
||||
POP_MPLS: parser.OFPActionPopMpls,
|
||||
PUSH_PBB: parser.OFPActionPushPbb}
|
||||
POP_MPLS: parser.OFPActionPopMpls}
|
||||
if ofp.OFP_VERSION > ofproto_v1_2.OFP_VERSION:
|
||||
need_ethertype[PUSH_PBB] = parser.OFPActionPushPbb
|
||||
|
||||
if action_type in actions:
|
||||
return actions[action_type]()
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -314,8 +314,7 @@ def match_to_str(ofmatch):
|
||||
mask = match_field['OXMTlv']['mask']
|
||||
value = match_field['OXMTlv']['value']
|
||||
if key == 'dl_vlan':
|
||||
value = ofctl_utils.match_vid_to_str(value, mask,
|
||||
ofproto_v1_3.OFPVID_PRESENT)
|
||||
value = match_vid_to_str(value, mask)
|
||||
elif key == 'in_port':
|
||||
value = UTIL.ofp_port_to_user(value)
|
||||
else:
|
||||
@ -326,6 +325,11 @@ def match_to_str(ofmatch):
|
||||
return match
|
||||
|
||||
|
||||
def match_vid_to_str(value, mask):
|
||||
return ofctl_utils.match_vid_to_str(
|
||||
value, mask, ofproto_v1_3.OFPVID_PRESENT)
|
||||
|
||||
|
||||
def wrap_dpid_dict(dp, value, to_user=True):
|
||||
if to_user:
|
||||
return {str(dp.id): value}
|
||||
|
||||
@ -214,8 +214,7 @@ def match_to_str(ofmatch):
|
||||
mask = match_field['OXMTlv']['mask']
|
||||
value = match_field['OXMTlv']['value']
|
||||
if key == 'vlan_vid':
|
||||
value = ofctl_utils.match_vid_to_str(value, mask,
|
||||
ofproto_v1_4.OFPVID_PRESENT)
|
||||
value = match_vid_to_str(value, mask)
|
||||
elif key == 'in_port':
|
||||
value = UTIL.ofp_port_to_user(value)
|
||||
else:
|
||||
@ -226,6 +225,11 @@ def match_to_str(ofmatch):
|
||||
return match
|
||||
|
||||
|
||||
def match_vid_to_str(value, mask):
|
||||
return ofctl_utils.match_vid_to_str(
|
||||
value, mask, ofproto_v1_4.OFPVID_PRESENT)
|
||||
|
||||
|
||||
def wrap_dpid_dict(dp, value, to_user=True):
|
||||
if to_user:
|
||||
return {str(dp.id): value}
|
||||
|
||||
@ -219,8 +219,7 @@ def match_to_str(ofmatch):
|
||||
mask = match_field['OXMTlv']['mask']
|
||||
value = match_field['OXMTlv']['value']
|
||||
if key == 'vlan_vid':
|
||||
value = ofctl_utils.match_vid_to_str(value, mask,
|
||||
ofproto_v1_5.OFPVID_PRESENT)
|
||||
value = match_vid_to_str(value, mask)
|
||||
elif key == 'in_port':
|
||||
value = UTIL.ofp_port_to_user(value)
|
||||
elif key == 'packet_type':
|
||||
@ -233,6 +232,11 @@ def match_to_str(ofmatch):
|
||||
return match
|
||||
|
||||
|
||||
def match_vid_to_str(value, mask):
|
||||
return ofctl_utils.match_vid_to_str(
|
||||
value, mask, ofproto_v1_5.OFPVID_PRESENT)
|
||||
|
||||
|
||||
def wrap_dpid_dict(dp, value, to_user=True):
|
||||
if to_user:
|
||||
return {str(dp.id): value}
|
||||
@ -1102,5 +1106,6 @@ def set_role(dp, role):
|
||||
role_request = dp.ofproto_parser.OFPRoleRequest(dp, r, 0)
|
||||
ofctl_utils.send_msg(dp, role_request, LOG)
|
||||
|
||||
|
||||
# NOTE(jkoelker) Alias common funcitons
|
||||
send_experimenter = ofctl_utils.send_experimenter
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user