- dst_mac.replace(':', ''), src_mac.replace(':', ''), ether_type)).\
- rstrip('0')
+ dst_mac.replace(':', ''), src_mac.replace(':', ''),
+ ether_type))[0:end]
@staticmethod
def _build_ip_mask(proto='', src_ip='', dst_ip='', src_port='',
@staticmethod
def _build_ip_mask(proto='', src_ip='', dst_ip='', src_port='',
- proto, src_ip, dst_ip, src_port, dst_port)).rstrip('0')
+ proto, src_ip, dst_ip, src_port, dst_port))[0:end]
@staticmethod
def _build_ip6_mask(next_hdr='', src_ip='', dst_ip='', src_port='',
@staticmethod
def _build_ip6_mask(next_hdr='', src_ip='', dst_ip='', src_port='',
- next_hdr, src_ip, dst_ip, src_port, dst_port)).rstrip('0')
+ next_hdr, src_ip, dst_ip, src_port, dst_port))[0:end]
- dst_mac, src_mac, ether_type)).rstrip('0')
+ dst_mac.replace(':', ''), src_mac.replace(':', ''),
+ ether_type))[0:end]
@staticmethod
def _build_ip_match(proto=0, src_ip='', dst_ip='', src_port=0, dst_port=0):
@staticmethod
def _build_ip_match(proto=0, src_ip='', dst_ip='', src_port=0, dst_port=0):
return ('{!s:0>20}{!s:0>12}{!s:0>8}{!s:0>4}{!s:0>4}'.format(
hex(proto)[2:], src_ip, dst_ip, hex(src_port)[2:],
return ('{!s:0>20}{!s:0>12}{!s:0>8}{!s:0>4}{!s:0>4}'.format(
hex(proto)[2:], src_ip, dst_ip, hex(src_port)[2:],
@staticmethod
def _build_ip6_match(next_hdr=0, src_ip='', dst_ip='', src_port=0,
@staticmethod
def _build_ip6_match(next_hdr=0, src_ip='', dst_ip='', src_port=0,
"""Build IPv6 ACL match data in hexstring format.
:param next_hdr: Next header number with valid option "x".
"""Build IPv6 ACL match data in hexstring format.
:param next_hdr: Next header number with valid option "x".
return ('{!s:0>14}{!s:0>34}{!s:0>32}{!s:0>4}{!s:0>4}'.format(
hex(next_hdr)[2:], src_ip, dst_ip, hex(src_port)[2:],
return ('{!s:0>14}{!s:0>34}{!s:0>32}{!s:0>4}{!s:0>4}'.format(
hex(next_hdr)[2:], src_ip, dst_ip, hex(src_port)[2:],
@staticmethod
def _classify_add_del_table(node, is_add, mask, match_n_vectors=1,
@staticmethod
def _classify_add_del_table(node, is_add, mask, match_n_vectors=1,
- with PapiExecutor(node) as papi_exec:
- data = papi_exec.add(cmd, **args).get_replies(err_msg).\
- verify_reply(err_msg=err_msg)
+ with PapiSocketExecutor(node) as papi_exec:
+ reply = papi_exec.add(cmd, **args).get_reply(err_msg)
- return int(data["new_table_index"]), int(data["skip_n_vectors"]),\
- int(data["match_n_vectors"])
+ return int(reply["new_table_index"]), int(reply["skip_n_vectors"]),\
+ int(reply["match_n_vectors"])
@staticmethod
def _classify_add_del_session(node, is_add, table_index, match,
@staticmethod
def _classify_add_del_session(node, is_add, table_index, match,
- with PapiExecutor(node) as papi_exec:
- papi_exec.add(cmd, **args).get_replies(err_msg). \
- verify_reply(err_msg=err_msg)
+ with PapiSocketExecutor(node) as papi_exec:
+ papi_exec.add(cmd, **args).get_reply(err_msg)
- with PapiExecutor(node) as papi_exec:
- papi_exec.add(cmd, **args).get_replies(err_msg). \
- verify_reply(err_msg=err_msg)
+ with PapiSocketExecutor(node) as papi_exec:
+ papi_exec.add(cmd, **args).get_reply(err_msg)
@staticmethod
def _acl_interface_set_acl_list(node, sw_if_index, acl_type, acls):
@staticmethod
def _acl_interface_set_acl_list(node, sw_if_index, acl_type, acls):
err_msg = "Failed to set acl list for interface {idx} on host {host}".\
format(idx=sw_if_index, host=node['host'])
err_msg = "Failed to set acl list for interface {idx} on host {host}".\
format(idx=sw_if_index, host=node['host'])
- with PapiExecutor(node) as papi_exec:
- papi_exec.add(cmd, **args).get_replies(err_msg). \
- verify_reply(err_msg=err_msg)
+ with PapiSocketExecutor(node) as papi_exec:
+ papi_exec.add(cmd, **args).get_reply(err_msg)
@staticmethod
def _acl_add_replace(node, acl_idx, rules, tag=""):
@staticmethod
def _acl_add_replace(node, acl_idx, rules, tag=""):
- with PapiExecutor(node) as papi_exec:
- papi_exec.add(cmd, **args).get_replies(err_msg). \
- verify_reply(err_msg=err_msg)
+ with PapiSocketExecutor(node) as papi_exec:
+ papi_exec.add(cmd, **args).get_reply(err_msg)
@staticmethod
def vpp_creates_classify_table_l3(node, ip_version, direction, ip_addr):
@staticmethod
def vpp_creates_classify_table_l3(node, ip_version, direction, ip_addr):
ip4=Classify._build_ip_mask,
ip6=Classify._build_ip6_mask
)
ip4=Classify._build_ip_mask,
ip6=Classify._build_ip6_mask
)
- if ip_version == "ip4":
- ip_addr = binascii.hexlify(inet_aton(ip_addr))
- elif ip_version == "ip6":
- ip_addr = binascii.hexlify(inet_pton(AF_INET6, ip_addr))
+ if ip_version == "ip4" or ip_version == "ip6":
+ ip_addr = binascii.hexlify(ip_address(unicode(ip_addr)).packed)
- with PapiExecutor(node) as papi_exec:
- data = papi_exec.add(cmd, **args).get_replies(err_msg).\
- verify_reply(err_msg=err_msg)
-
- return data
+ with PapiSocketExecutor(node) as papi_exec:
+ reply = papi_exec.add(cmd, **args).get_reply(err_msg)
+ return reply
- with PapiExecutor(node) as papi_exec:
- dump = papi_exec.add("classify_session_dump", **args).\
- get_dump().reply[0]["api_reply"]["classify_session_details"]
+ with PapiSocketExecutor(node) as papi_exec:
+ details = papi_exec.add(cmd, **args).get_details()
@staticmethod
def set_acl_list_for_interface(node, interface, acl_type, acl_idx=None):
@staticmethod
def set_acl_list_for_interface(node, interface, acl_type, acl_idx=None):
- def add_replace_acl_multi_entries(node, acl_idx=None, rules=None):
+ def add_replace_acl_multi_entries(node, acl_idx=None, rules=None, tag=""):
"""Add a new ACL or replace the existing one. To replace an existing
ACL, pass the ID of this ACL.
:param node: VPP node to set ACL on.
:param acl_idx: ID of ACL. (Optional)
:param rules: Required rules. (Optional)
"""Add a new ACL or replace the existing one. To replace an existing
ACL, pass the ID of this ACL.
:param node: VPP node to set ACL on.
:param acl_idx: ID of ACL. (Optional)
:param rules: Required rules. (Optional)
"""
reg_ex_src_ip = re.compile(r'(src [0-9a-fA-F.:/\d{1,2}]*)')
reg_ex_dst_ip = re.compile(r'(dst [0-9a-fA-F.:/\d{1,2}]*)')
reg_ex_sport = re.compile(r'(sport \d{1,5})')
reg_ex_dport = re.compile(r'(dport \d{1,5})')
"""
reg_ex_src_ip = re.compile(r'(src [0-9a-fA-F.:/\d{1,2}]*)')
reg_ex_dst_ip = re.compile(r'(dst [0-9a-fA-F.:/\d{1,2}]*)')
reg_ex_sport = re.compile(r'(sport \d{1,5})')
reg_ex_dport = re.compile(r'(dport \d{1,5})')
groups = re.search(reg_ex_src_ip, rule)
if groups:
grp = groups.group(1).split(' ')[1].split('/')
groups = re.search(reg_ex_src_ip, rule)
if groups:
grp = groups.group(1).split(' ')[1].split('/')
acl_rule["src_ip_prefix_len"] = int(grp[1])
groups = re.search(reg_ex_dst_ip, rule)
if groups:
grp = groups.group(1).split(' ')[1].split('/')
acl_rule["src_ip_prefix_len"] = int(grp[1])
groups = re.search(reg_ex_dst_ip, rule)
if groups:
grp = groups.group(1).split(' ')[1].split('/')
acl_rule["dst_ip_prefix_len"] = int(grp[1])
groups = re.search(reg_ex_sport, rule)
acl_rule["dst_ip_prefix_len"] = int(grp[1])
groups = re.search(reg_ex_sport, rule)
port = int(groups.group(1).split(' ')[1])
acl_rule["srcport_or_icmptype_first"] = port
acl_rule["srcport_or_icmptype_last"] = port
port = int(groups.group(1).split(' ')[1])
acl_rule["srcport_or_icmptype_first"] = port
acl_rule["srcport_or_icmptype_last"] = port
groups = re.search(reg_ex_dport, rule)
if groups:
port = int(groups.group(1).split(' ')[1])
acl_rule["dstport_or_icmpcode_first"] = port
acl_rule["dstport_or_icmpcode_last"] = port
groups = re.search(reg_ex_dport, rule)
if groups:
port = int(groups.group(1).split(' ')[1])
acl_rule["dstport_or_icmpcode_first"] = port
acl_rule["dstport_or_icmpcode_last"] = port
- Classify._acl_add_replace(node, acl_idx=acl_idx, rules=acl_rules)
+ Classify._acl_add_replace(
+ node, acl_idx=acl_idx, rules=acl_rules, tag=tag)
groups = re.search(reg_ex_mac, rule)
if groups:
mac = groups.group(1).split(' ')[1].replace(':', '')
groups = re.search(reg_ex_mac, rule)
if groups:
mac = groups.group(1).split(' ')[1].replace(':', '')
groups = re.search(reg_ex_mask, rule)
if groups:
mask = groups.group(1).split(' ')[1].replace(':', '')
groups = re.search(reg_ex_mask, rule)
if groups:
mask = groups.group(1).split(' ')[1].replace(':', '')
groups = re.search(reg_ex_ip, rule)
if groups:
grp = groups.group(1).split(' ')[1].split('/')
groups = re.search(reg_ex_ip, rule)
if groups:
grp = groups.group(1).split(' ')[1].split('/')
@staticmethod
def add_del_macip_acl_interface(node, interface, action, acl_idx):
@staticmethod
def add_del_macip_acl_interface(node, interface, action, acl_idx):
- with PapiExecutor(node) as papi_exec:
- papi_exec.add(cmd, **args).get_replies(err_msg).\
- verify_reply(err_msg=err_msg)
+ with PapiSocketExecutor(node) as papi_exec:
+ papi_exec.add(cmd, **args).get_reply(err_msg)
cmd = 'macip_acl_interface_get'
err_msg = "Failed to get 'macip_acl_interface' on host {host}".format(
host=node['host'])
cmd = 'macip_acl_interface_get'
err_msg = "Failed to get 'macip_acl_interface' on host {host}".format(
host=node['host'])
- with PapiExecutor(node) as papi_exec:
- rpl = papi_exec.add(cmd).get_replies(err_msg).reply[0]["api_reply"]
- logger.info(rpl["macip_acl_interface_get_reply"])
+ with PapiSocketExecutor(node) as papi_exec:
+ reply = papi_exec.add(cmd).get_reply(err_msg)
+ logger.info(reply)