Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ansible/module_utils/port_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ def get_port_alias_to_name_map(hwsku, asic_id=None):
port_alias_asic_map["Eth%d-ASIC%d"%(i-1, int(asic_id))] = "Ethernet%d"%((asic_offset + i -1) *4)
port_alias_to_name_map["Eth%d-ASIC%d"%((backplane_offset+i), int(asic_id))] = "Ethernet-BP%d"%((asic_offset + i -1) *4)
port_alias_asic_map["Eth%d-ASIC%d"%((backplane_offset+i), int(asic_id))] = "Ethernet-BP%d"%((asic_offset + i -1) *4)
else:
for i in range(1,65):
port_alias_to_name_map["Ethernet1/%d" % i] = "Ethernet%d" % ((i - 1) * 4)
else:
for i in range(0, 128, 4):
port_alias_to_name_map["Ethernet%d" % i] = "Ethernet%d" % i
Expand Down
20 changes: 18 additions & 2 deletions ansible/roles/test/files/ptftests/fib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def setUp(self):
- ip_options enable ip option header in ipv4 pkts. Default: False(disable)
- src_vid vlan tag id of src pkts. Default: None(untag)
- dst_vid vlan tag id of dst pkts. Default: None(untag)
- ignore_ttl: mask the ttl field in the expected packet
'''
self.dataplane = ptf.dataplane_instance

Expand Down Expand Up @@ -131,6 +132,8 @@ def setUp(self):
self.src_ports = self.test_params.get('src_ports', None)
if not self.src_ports:
self.src_ports = [int(port) for port in self.ptf_test_port_map.keys()]

self.ignore_ttl = self.test_params.get('ignore_ttl', False)

def check_ip_ranges(self, ipv4=True):
for dut_index, fib in enumerate(self.fibs):
Expand Down Expand Up @@ -262,14 +265,21 @@ def check_ipv4_route(self, src_port, dst_ip_addr, dst_port_list):
masked_exp_pkt = Mask(exp_pkt)
masked_exp_pkt.set_do_not_care_scapy(scapy.Ether, "dst")

# mask the chksum also if masking the ttl
if self.ignore_ttl:
masked_exp_pkt.set_do_not_care_scapy(scapy.IP, "ttl")
masked_exp_pkt.set_do_not_care_scapy(scapy.IP, "chksum")
masked_exp_pkt.set_do_not_care_scapy(scapy.TCP, "chksum")

send_packet(self, src_port, pkt)
logging.info('Sent Ether(src={}, dst={})/IP(src={}, dst={})/TCP(sport={}, dport={})'\
logging.info('Sent Ether(src={}, dst={})/IP(src={}, dst={})/TCP(sport={}, dport={}) on port {}'\
.format(pkt.src,
pkt.dst,
pkt['IP'].src,
pkt['IP'].dst,
sport,
dport))
dport,
src_port))
logging.info('Expect Ether(src={}, dst={})/IP(src={}, dst={})/TCP(sport={}, dport={})'\
.format(exp_router_mac,
'any',
Expand Down Expand Up @@ -325,6 +335,12 @@ def check_ipv6_route(self, src_port, dst_ip_addr, dst_port_list):
masked_exp_pkt = Mask(exp_pkt)
masked_exp_pkt.set_do_not_care_scapy(scapy.Ether,"dst")

# mask the chksum also if masking the ttl
if self.ignore_ttl:
masked_exp_pkt.set_do_not_care_scapy(scapy.IPv6, "hlim")
masked_exp_pkt.set_do_not_care_scapy(scapy.IPv6, "chksum")
masked_exp_pkt.set_do_not_care_scapy(scapy.TCP, "chksum")

send_packet(self, src_port, pkt)
logging.info('Sent Ether(src={}, dst={})/IPv6(src={}, dst={})/TCP(sport={}, dport={})'\
.format(pkt.src,
Expand Down
23 changes: 19 additions & 4 deletions ansible/roles/test/files/ptftests/hash_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def setUp(self):
self.balancing_range = self.test_params.get('balancing_range', self.DEFAULT_BALANCING_RANGE)
self.balancing_test_times = self.test_params.get('balancing_test_times', self.BALANCING_TEST_TIMES)

self.ignore_ttl = self.test_params.get('ignore_ttl', False)

def get_src_and_exp_ports(self, dst_ip):
while True:
src_port = int(random.choice(self.src_ports))
Expand Down Expand Up @@ -217,15 +219,22 @@ def check_ipv4_route(self, hash_key, src_port, dst_port_list):
exp_pkt['IP'].proto = ip_proto
masked_exp_pkt = Mask(exp_pkt)
masked_exp_pkt.set_do_not_care_scapy(scapy.Ether, "dst")
# mask the chksum also if masking the ttl
if self.ignore_ttl:
masked_exp_pkt.set_do_not_care_scapy(scapy.IP, "ttl")
masked_exp_pkt.set_do_not_care_scapy(scapy.IP, "chksum")
masked_exp_pkt.set_do_not_care_scapy(scapy.TCP, "chksum")


send_packet(self, src_port, pkt)
logging.info('Sent Ether(src={}, dst={})/IP(src={}, dst={})/TCP(sport={}, dport={})'\
logging.info('Sent Ether(src={}, dst={})/IP(src={}, dst={})/TCP(sport={}, dport={} on port {})'\
.format(pkt.src,
pkt.dst,
pkt['IP'].src,
pkt['IP'].dst,
sport,
dport))
dport,
src_port))
logging.info('Expect Ether(src={}, dst={})/IP(src={}, dst={})/TCP(sport={}, dport={})'\
.format(exp_router_mac,
'any',
Expand Down Expand Up @@ -284,15 +293,21 @@ def check_ipv6_route(self, hash_key, src_port, dst_port_list):

masked_exp_pkt = Mask(exp_pkt)
masked_exp_pkt.set_do_not_care_scapy(scapy.Ether,"dst")
# mask the chksum also if masking the ttl
if self.ignore_ttl:
masked_exp_pkt.set_do_not_care_scapy(scapy.IPv6, "hlim")
masked_exp_pkt.set_do_not_care_scapy(scapy.IPv6, "chksum")
masked_exp_pkt.set_do_not_care_scapy(scapy.TCP, "chksum")

send_packet(self, src_port, pkt)
logging.info('Sent Ether(src={}, dst={})/IPv6(src={}, dst={})/TCP(sport={}, dport={})'\
logging.info('Sent Ether(src={}, dst={})/IPv6(src={}, dst={})/TCP(sport={}, dport={} on port {})'\
.format(pkt.src,
pkt.dst,
pkt['IPv6'].src,
pkt['IPv6'].dst,
sport,
dport))
dport,
src_port))
logging.info('Expect Ether(src={}, dst={})/IPv6(src={}, dst={})/TCP(sport={}, dport={})'\
.format(exp_router_mac,
'any',
Expand Down
44 changes: 40 additions & 4 deletions tests/common/devices/sonic_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def __init__(self, sonichost, asic_index):
"""
self.sonichost = sonichost
self.asic_index = asic_index
self._ns_arg = ""
self.ns_arg = ""
if self.sonichost.is_multi_asic:
self.namespace = "{}{}".format(NAMESPACE_PREFIX, self.asic_index)
self.cli_ns_option = "-n {}".format(self.namespace)
self._ns_arg = "sudo ip netns exec {} ".format(self.namespace)
self.ns_arg = "sudo ip netns exec {} ".format(self.namespace)
else:
# set the namespace to DEFAULT_NAMESPACE(None) for single asic
self.namespace = DEFAULT_NAMESPACE
Expand Down Expand Up @@ -214,6 +214,42 @@ def is_service_running(self, service_name, docker_name):
)
return self.sonichost.is_service_running(service_name, docker_name)

def ping_v4(self, ipv4, count=1):
"""
Returns 'True' if ping to IP address works, else 'False'
Args:
IPv4 address

Returns:
True or False
"""
try:
socket.inet_aton(ipv4)
except socket.error:
raise Exception("Invalid IPv4 address {}".format(ipv4))

try:
self.sonichost.shell("{}ping -q -c{} {} > /dev/null".format(
self.ns_arg, count, ipv4
))
except RunAnsibleModuleFail:
return False
return True

def is_backend_portchannel(self, port_channel):
mg_facts = self.sonichost.minigraph_facts(
host = self.sonichost.hostname
)['ansible_facts']
if port_channel in mg_facts["minigraph_portchannels"]:
port_name = next(
iter(
mg_facts["minigraph_portchannels"][port_channel]["members"]
)
)
if "Ethernet-BP" not in port_name:
return False
return True

def get_active_ip_interfaces(self):
"""
Return a dict of active IP (Ethernet or PortChannel) interfaces, with
Expand Down Expand Up @@ -242,7 +278,7 @@ def bgp_drop_rule(self, ip_version, state="present"):
check_opt = "-C INPUT"
cmd = (
"{}/sbin/{} -t filter {{}} -p tcp -j DROP --destination-port bgp"
).format(self._ns_arg, ipcmd)
).format(self.ns_arg, ipcmd)

check_cmd = cmd.format(check_opt)
run_cmd = cmd.format(run_opt)
Expand Down Expand Up @@ -312,7 +348,7 @@ def command(self, cmdstr):
if not self.sonichost.is_multi_asic or self.namespace == DEFAULT_NAMESPACE:
return self.sonichost.command(cmdstr)

cmdstr = "sudo ip netns exec {} ".format(self.namespace) + cmdstr
cmdstr = "sudo ip netns exec {} {}".format(self.namespace, cmdstr)

return self.sonichost.command(cmdstr)

Expand Down
14 changes: 8 additions & 6 deletions tests/common/dualtor/mux_simulator_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ def mux_server_url(request, tbinfo):
Returns:
str: The address of mux simulator server + vmset_name, like http://10.0.0.64:8080/mux/vms17-8
"""
server = tbinfo['server']
vmset_name = tbinfo['group-name']
inv_files = request.config.option.ansible_inventory
ip = utilities.get_test_server_vars(inv_files, server).get('ansible_host')
port = utilities.get_group_visible_vars(inv_files, server).get('mux_simulator_port')
return "http://{}:{}/mux/{}".format(ip, port, vmset_name)
if 'dualtor' in tbinfo['topo']['name']:
server = tbinfo['server']
vmset_name = tbinfo['group-name']
inv_files = request.config.option.ansible_inventory
ip = utilities.get_test_server_vars(inv_files, server).get('ansible_host')
port = utilities.get_group_visible_vars(inv_files, server).get('mux_simulator_port')
return "http://{}:{}/mux/{}".format(ip, port, vmset_name)
return ""

@pytest.fixture(scope='module')
def url(mux_server_url, duthost, tbinfo):
Expand Down
Loading