def test_sent_pause_frames(self, env): """ @brief Verify that device doesn't flood received pause frames when flow control mode is configured. @steps -# Configure FlowControl on switch ports. -# Send PFC frames to the switch. -# Verify PFC frames are not flooded. @endsteps """ # Define active ports ports = env.get_ports([['tg1', 'sw1', 3], ]) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, ports) # Wait until ports will be in forwarding state. helpers.wait_until_stp_state(switch_instance=env.switch[1], mode="RSTP", state="Forwarding", port=ports[('sw1', 'tg1')][1], timeout=120) helpers.wait_until_stp_state(switch_instance=env.switch[1], mode="RSTP", state="Forwarding", port=ports[('sw1', 'tg1')][2], timeout=120) helpers.wait_until_stp_state(switch_instance=env.switch[1], mode="RSTP", state="Forwarding", port=ports[('sw1', 'tg1')][3], timeout=120) # Configure stream of pause frame. pause_frame = ({"Ethernet": {"dst": "01:80:C2:00:00:01", "src": "00:00:00:00:01:44", "type": 0x8808}}, {"Pause": {"opcode": 0x0001, "ptime": 1}}) stream = env.tg[1].set_stream(pause_frame, count=10, iface=ports[('tg1', 'sw1')][1]) sniff_ports = list(ports[('tg1', 'sw1')].values()) # Configure flow control values for all active ports. env.switch[1].ui.set_flow_control_type([ports[('sw1', 'tg1')][1], ports[('sw1', 'tg1')][2], ports[('sw1', 'tg1')][3]], control_type='RxTx') # Start capture env.tg[1].start_sniff(sniff_ports, sniffing_time=5) # Send pause frame from the TG port 1. env.tg[1].send_stream(stream) data = env.tg[1].stop_sniff(sniff_ports) helpers.print_sniffed_data_brief(data) # Verify that Pause Frames are not forwarded from tested ports. params = ({'layer': "Ethernet", 'field': "dst", 'value': "01:80:C2:00:00:01".lower()}, ) assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[0], params=params, sniff_data=data, tg=env.tg[1])) == 0, \ "Pause Frames are forwarded from port 1 when PF traffic is sent" assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[1], params=params, sniff_data=data, tg=env.tg[1])) == 0, \ "Pause Frames are forwarded from port 2 when PF traffic is sent" assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[2], params=params, sniff_data=data, tg=env.tg[1])) == 0, \ "Pause Frames are forwarded from port 3 when PF traffic is sent"
def test_acl_statistics(self, env): """ @brief Simple ACL test for ACL Statistics @steps -# Configure ACL: drop all packets. -# Configure ACL: allow packets with Ethernet.dst=00:00:00:01:01:01. -# Create stream with Ethernet.dst=00:00:00:01:01:01. -# Create stream with Ethernet.dst=00:00:00:03:03:03. -# Send streams. -# Get ACL Statistics. -# Verify Statistics has been updated with correct values. @endsteps """ # Get active ports: use four ports for test case active_ports = env.get_ports([ ['tg1', 'sw1', 4], ]) device_ports = list(active_ports[('sw1', 'tg1')].values()) sniff_ports = list(active_ports[('tg1', 'sw1')].values()) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, active_ports) self.suite_logger.debug("Disable STP.") env.switch[1].ui.configure_spanning_tree(enable='Disabled') # Configure ACL: drop all packets; # allow only packets with Ethernet.dst=00:00:00:01:01:01 self.suite_logger.debug("Create ACLs") # Configure ACL Expression in format (id, expression, mask, value) expressions = [(1, 'SrcMac', '00:00:00:00:00:00', '00:00:00:00:00:00'), (2, 'DstMac', 'FF:FF:FF:FF:FF:FF', '00:00:00:01:01:01')] # Configure ACL Action in format (id, action, params) # Additional 'Count' action should be added in order to update ACL Statistics actions = [(1, 'Drop', ''), (1, 'Count', ''), (2, 'Allow', ''), (2, 'Count', '')] # Configure ACL Rule in format # (id, expression_id, action_id, stage, enabled, priority) rules = [(1, 1, 1, 'Ingress', 'Enabled', 0), (2, 2, 2, 'Ingress', 'Enabled', 0)] # Create ACLs on device's ports try: env.switch[1].ui.create_acl(ports=device_ports, expressions=expressions, actions=actions, rules=rules) except Exception as err: # Exception in configuration self.suite_logger.debug('ACL configuration failed: %s' % err) pytest.fail('ACL configuration failed') # Wait some time for proper switch behavior time.sleep(1) # Generate test traffic packet_1 = ({ "Ethernet": { "dst": "00:00:00:01:01:01", "src": "00:00:00:02:02:02" } }, { "IP": {} }, { "TCP": {} }) packet_2 = ({ "Ethernet": { "dst": "00:00:00:03:03:03", "src": "00:00:00:04:04:04" } }, { "IP": {} }, { "TCP": {} }) # Send packets to the first port count_2 = 5 count_1 = 10 packet_size = 100 stream_1 = env.tg[1].set_stream(packet_1, count=count_2, iface=sniff_ports[0], required_size=packet_size) stream_2 = env.tg[1].set_stream(packet_2, count=count_1, iface=sniff_ports[0], required_size=packet_size) streams = [stream_1, stream_2] self.suite_logger.debug("Start the capture and send the test traffic") # Start capture env.tg[1].start_sniff(sniff_ports, sniffing_time=10) # Send generated streams env.tg[1].start_streams(streams) # Stop capture env.tg[1].stop_sniff(sniff_ports) # Stop traffic env.tg[1].stop_streams() self.suite_logger.debug("Verify ACl Statistics is updated " "according to the created ACLs") # Get ACL Statistics statistics = env.switch[1].ui.get_table_acl("ACLStatistics") # Get statistics for first ACL Rule stat_1 = [x for x in statistics if x["ruleId"] == 1][0] # Verify statistics assert stat_1["matchPkts"] == count_1 assert stat_1["matchOctets"] == count_1 * packet_size # Get statistics for second ACL Rule stat_1 = [x for x in statistics if x["ruleId"] == 2][0] # Verify statistics assert stat_1["matchPkts"] == count_2 assert stat_1["matchOctets"] == count_2 * packet_size
def test_rxtx_flow_control(self, env): """ @brief Verify that "RxTx" flow control manages traffic correctly. @steps -# Configure FlowControl on switch ports in 'RxTx' mode. -# Send stream of unicast packets with 50% rate to the port 1. -# Send stream of unicast packets with 50% rate to the port 2. -# Send PFC frames to the port 3. -# Verify that line rate on TG port 3 decreases after pause frames with middle quanta are sending @endsteps """ self.suite_logger.info("Define variables for test execution") pause_frame_rate = 30 quanta_value = 4096 # Define active ports ports = env.get_ports([['tg1', 'sw1', 3], ]) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, ports) # Wait until ports will be in forwarding state. helpers.wait_until_stp_state(switch_instance=env.switch[1], mode="RSTP", state="Forwarding", port=ports[('sw1', 'tg1')][1], timeout=120) helpers.wait_until_stp_state(switch_instance=env.switch[1], mode="RSTP", state="Forwarding", port=ports[('sw1', 'tg1')][2], timeout=120) helpers.wait_until_stp_state(switch_instance=env.switch[1], mode="RSTP", state="Forwarding", port=ports[('sw1', 'tg1')][3], timeout=120) # Configure two streams of unicast packets. packet_1 = ({"Ethernet": {"dst": "00:00:00:00:00:33", "src": "00:00:00:00:00:11", "type": 0x0800}}, {"IP": {}}) packet_2 = ({"Ethernet": {"dst": "00:00:00:00:00:33", "src": "00:00:00:00:00:22", "type": 0x0800}}, {"IP": {}}) stream_1 = env.tg[1].set_stream(packet_1, iface=ports[('tg1', 'sw1')][1], rate=50, continuous=True) stream_2 = env.tg[1].set_stream(packet_2, iface=ports[('tg1', 'sw1')][2], rate=50, continuous=True) sniff_ports = list(ports[('tg1', 'sw1')].values()) # Configure flow control values for all active ports. env.switch[1].ui.set_flow_control_type([ports[('sw1', 'tg1')][1], ports[('sw1', 'tg1')][2], ports[('sw1', 'tg1')][3]], control_type='RxTx') # Enable Flow Control on TG port 1 and port 2 env.tg[1].set_flow_control(ports[('tg1', 'sw1')][1], True) env.tg[1].set_flow_control(ports[('tg1', 'sw1')][2], True) # Send stream of unicast packets from TG port 1. env.tg[1].start_streams([stream_1, stream_2, ]) time.sleep(3) # Configure stream of pause frames pause_frame = ({"Ethernet": {"dst": "01:80:C2:00:00:01", "src": "00:00:00:00:01:44", "type": 0x8808}}, {"Pause": {"opcode": 0x0001, "ptime": quanta_value}}) stream = env.tg[1].set_stream(pause_frame, iface=ports[('tg1', 'sw1')][3], rate=pause_frame_rate, continuous=True) # Send stream of pause frames from TG port 2. env.tg[1].start_streams([stream, ]) time.sleep(3) self.suite_logger.debug("Start sniffer for detecting pause frames") env.tg[1].start_sniff(sniff_ports, sniffing_time=5, filter_layer='PAUSE') time.sleep(5) # Define transmit rate limits on TG port 1 and port 2 after sending pause frames to "RxTx" flow control port. tx_test_rate1 = env.tg[1].get_port_txrate(ports[('tg1', 'sw1')][1]) tx_test_rate2 = env.tg[1].get_port_txrate(ports[('tg1', 'sw1')][2]) # Define receive rate limit on TG port 3 after sending pause frames to "RxTx" flow control port. rx_test_rate3 = env.tg[1].get_port_rxrate(ports[('tg1', 'sw1')][3]) self.suite_logger.debug("Stop sniffer") data = env.tg[1].stop_sniff(sniff_ports) # Stop streams of unicast packets and pause frames. env.tg[1].stop_streams([stream_1, stream_2, stream, ]) # Verify that pause frames are not forwarded from tested ports. params = ({'layer': "Ethernet", 'field': "src", 'value': "00:00:00:00:01:44"}, ) assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[0], params=params, sniff_data=data, tg=env.tg[1])) == 0, \ "Pause Frames are forwarded from port 1 when 'RxTx' is configured on all tested ports." assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[1], params=params, sniff_data=data, tg=env.tg[1])) == 0, \ "Pause Frames are forwarded from port 2 when 'RxTx' is configured on all tested ports." assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[2], params=params, sniff_data=data, tg=env.tg[1])) == 0, \ "Pause Frames are forwarded from port 3 when 'RxTx' is configured on all tested ports." # Verify that line rate on TG port 3 decreases after pause frames with middle quanta are sending. if self.rate_decreasing(pf_rate=pause_frame_rate, quanta=quanta_value, pause_frame_size=64, full_rate=self.full_rate(sw_instance=env.switch[1], tested_port=ports[('sw1', 'tg1')][3], frame_size=64), actual_rate=rx_test_rate3): self.suite_logger.debug("Line rate decreases properly when stream of pause frames with middle quanta is sent to 'RxTx' port.") else: pytest.fail("Line rate is not decreased properly when stream of pause frames with middle quanta is sent to 'RxTx' port.") # Verify that transmit line rate on TG port 1 is decreased according to configured "RxTx" flow control on all tested ports. if not abs(tx_test_rate1 - (rx_test_rate3 // 2)) <= rx_test_rate3 // 2 * 101 // 100: pytest.fail("Transmit line rate is not decreased accordingly to detected overflow on 'RxTx' egress port.") # Verify that transmit line rate on TG port 2 is decreased according to configured "RxTx" flow control on all tested ports. if not abs(tx_test_rate2 - (rx_test_rate3 // 2)) <= rx_test_rate3 / 2 * 101 // 100: pytest.fail("Transmit line rate is not decreased accordingly to detected overflow on 'RxTx' egress port.")
def test_switch_ports_operations(self, env): """ @brief Simple operations with ports. """ # Get active ports. # JSON setup file contain info about links between devices # env.get_ports - returns dictionary of ports in format # {link_key: ports_dict} # where # link_key is a list of device's acronymes # ports_dict contains real port names (IDs) from JSON file # Example: # {('sw1', 'tg1'): {1: 24, 2: 25}, ('tg1', 'sw1'): {1: 'eth1', 2: 'eth2'}} # where switch's port 24 is connected to the traffic generator's port 'eth1', etc. # Get 4 links between switch and tg active_ports = env.get_ports([['tg1', 'sw1', 4], ]) # Disable all ports and enabling only necessary ports: # helpers module contains special methods to operate with ports # Set all switch ports into Admin Down state # in order to omit traffic from other connections helpers.set_all_ports_admin_disabled(env.switch) # Enable only links used in current test case helpers.set_ports_admin_enabled(env.switch, active_ports) self.suite_logger.debug("Create Static FDB") # Create static Fdb record for second port in configuration mac = "00:00:00:11:11:11" # Get second port of device port_2 = active_ports[('sw1', 'tg1')][2] env.switch[1].ui.create_static_macs(port=port_2, vlans=[1], macs=[mac]) # Generate test traffic packet_1 = ({"Ethernet": {"dst": "00:00:00:11:11:11", "src": "00:00:00:02:02:02"}}, {"IP": {}}, {"TCP": {}}) packet_2 = ({"Ethernet": {"dst": "00:00:00:03:03:03", "src": "00:00:00:04:04:04"}}, {"IP": {}}, {"TCP": {}}) # Send packets to the first port # Get first port of TG port_tg_2 = active_ports[('tg1', 'sw1')][1] stream_1 = env.tg[1].set_stream(packet_1, count=1, iface=port_tg_2) stream_2 = env.tg[1].set_stream(packet_2, count=1, iface=port_tg_2) streams = [stream_1, stream_2] self.suite_logger.debug("Start the capture and send the test traffic") # Start capture # Configure ports for capture (get all TG ports sniff_ports = list(active_ports[('tg1', 'sw1')].values()) env.tg[1].start_sniff(sniff_ports, sniffing_time=10) # Send generated streams env.tg[1].start_streams(streams) # Stop capture data = env.tg[1].stop_sniff(sniff_ports) # Stop traffic env.tg[1].stop_streams(streams) # Print captured data helpers.print_sniffed_data_brief(data) self.suite_logger.debug("Verify traffic is processed according to the FDB records") # Get packets from the captured data # Verify first packet is sent only to second port params_1 = [{"layer": "Ethernet", "field": 'dst', "value": '00:00:00:11:11:11'}, {"layer": "Ethernet", "field": 'src', "value": '00:00:00:02:02:02'}] assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[1], params=params_1, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received" assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[2], params=params_1, sniff_data=data, tg=env.tg[1])) == 0, \ "Packet is received" assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[3], params=params_1, sniff_data=data, tg=env.tg[1])) == 0, \ "Packet is received" # Verify second packet is flooded params_1 = [{"layer": "Ethernet", "field": 'dst', "value": '00:00:00:03:03:03'}, {"layer": "Ethernet", "field": 'src', "value": '00:00:00:04:04:04'}] assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[1], params=params_1, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received" assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[2], params=params_1, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received" assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[3], params=params_1, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received"
def test_acl_traffic(self, env): """ @brief Simple ACL test with traffic @steps -# Configure ACL: drop all packets. -# Configure ACL: allow packets with Ethernet.dst=00:00:00:01:01:01. -# Create stream with Ethernet.dst=00:00:00:01:01:01. -# Create stream with Ethernet.dst=00:00:00:03:03:03. -# Send streams. -# Verify first stream is flooded. -# Verify second stream is discarded. @endsteps """ # Get active ports: use four ports for test case active_ports = env.get_ports([ ['tg1', 'sw1', 4], ]) device_ports = list(active_ports[('sw1', 'tg1')].values()) sniff_ports = list(active_ports[('tg1', 'sw1')].values()) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, active_ports) self.suite_logger.debug("Disable STP.") env.switch[1].ui.configure_spanning_tree(enable='Disabled') # Configure ACL: drop all packets; # allow only packets with Ethernet.dst=00:00:00:01:01:01 # Configure ACL Expression in format (id, expression, mask, value) self.suite_logger.debug("Create ACLs") expressions = [(1, 'SrcMac', '00:00:00:00:00:00', '00:00:00:00:00:00'), (2, 'DstMac', 'FF:FF:FF:FF:FF:FF', '00:00:00:01:01:01')] # Configure ACL Action in format (id, action, params) actions = [(1, 'Drop', ''), (2, 'Allow', '')] # Configure ACL Rule in format # (id, expression_id, action_id, stage, enabled, priority) rules = [(1, 1, 1, 'Ingress', 'Enabled', 0), (2, 2, 2, 'Ingress', 'Enabled', 0)] # Create ACLs on device's ports try: env.switch[1].ui.create_acl(ports=device_ports, expressions=expressions, actions=actions, rules=rules) except Exception as err: # Exception in configuration self.suite_logger.debug('ACL configuration failed: %s' % err) pytest.fail('ACL configuration failed') # Wait some time for proper switch behavior time.sleep(1) # Generate test traffic packet_1 = ({ "Ethernet": { "dst": "00:00:00:01:01:01", "src": "00:00:00:02:02:02" } }, { "IP": {} }, { "TCP": {} }) packet_2 = ({ "Ethernet": { "dst": "00:00:00:03:03:03", "src": "00:00:00:04:04:04" } }, { "IP": {} }, { "TCP": {} }) # Send packets to the first port stream_1 = env.tg[1].set_stream(packet_1, count=1, iface=sniff_ports[0]) stream_2 = env.tg[1].set_stream(packet_2, count=1, iface=sniff_ports[0]) streams = [stream_1, stream_2] # Start capture self.suite_logger.debug("Start the capture and send the test traffic") env.tg[1].start_sniff(sniff_ports, sniffing_time=10) # Send generated streams env.tg[1].start_streams(streams) # Stop capture data = env.tg[1].stop_sniff(sniff_ports) # Stop traffic env.tg[1].stop_streams() # Print captured data helpers.print_sniffed_data_brief(data) # Get packets from the captured data self.suite_logger.debug( "Verify traffic is processed according to the ACLs") # Verify first packet is flooded params_1 = [{ "layer": "Ethernet", "field": 'dst', "value": '00:00:00:01:01:01' }, { "layer": "Ethernet", "field": 'src', "value": '00:00:00:02:02:02' }] assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[1], params=params_1, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received" assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[2], params=params_1, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received" assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[3], params=params_1, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received" # Verify second packet is dropped params_1 = [{ "layer": "Ethernet", "field": 'dst', "value": '00:00:00:03:03:03' }, { "layer": "Ethernet", "field": 'src', "value": '00:00:00:04:04:04' }] assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[1], params=params_1, sniff_data=data, tg=env.tg[1])) == 0, \ "Packet is flooded" assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[2], params=params_1, sniff_data=data, tg=env.tg[1])) == 0, \ "Packet is flooded" assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[3], params=params_1, sniff_data=data, tg=env.tg[1])) == 0, \ "Packet is flooded"
def test_ospf_hello_packets(self, env): """ @brief Verify OSPF hello packet has correct fields after OSPF protocol initialization. @steps -# Add Vlan 100, set pvid on ports 1 to 100 -# Configure OSPF on DUT (area 0.0.0.0) -# Create Route Interface (10.0.1.0 on vlan 100) -# Add Route Interface to the OSPF Area -# Start capture for OSPF Hello packets -# Verify OSPF Hello packets were received @endsteps """ # Define ports. ports = env.get_ports([['tg1', 'sw1', 1], ]) sniff_ports = [ports[('tg1', 'sw1')][1], ] # Disabling all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, ports, wait_status=True) # Disable STP env.switch[1].ui.configure_spanning_tree(enable='Disabled') # Enable Routing. env.switch[1].ui.configure_routing(routing='Enabled', ospf='Enabled') # Configuring general OSPF parameters for four switches. env.switch[1].ui.configure_ospf_router(logAdjacencyChanges='Enabled', routerId='1.1.1.1') # Create test VLAN 100. env.switch[1].ui.create_vlans(vlans=[100]) # Deleting ports from default VLAN. env.switch[1].ui.delete_vlan_ports(ports=[ports[('sw1', 'tg1')][1]], vlans=[1]) # Adding ports to created test VLANs. env.switch[1].ui.create_vlan_ports(ports=[ports[('sw1', 'tg1')][1], ], vlans=[100], tagged='Tagged') # Set pvid for VLANs ports. env.switch[1].ui.modify_ports(ports=[ports[('sw1', 'tg1')][1], ], pvid=100) # Configuring general OSPF Area parameters. env.switch[1].ui.create_ospf_area('0.0.0.0') # Adding OSPF route intefaces. env.switch[1].ui.create_route_interface(100, '10.0.1.1/24', ip_type='InterVlan', bandwidth=1000, mtu=1500, status='Enabled', vrf=0, mode='ip') env.switch[1].ui.create_network_2_area(network='10.0.1.1/24', area='0.0.0.0', mode='Disabled') # Start sniffer env.tg[1].start_sniff(sniff_ports, sniffing_time=35) # Stop sniffer. data = env.tg[1].stop_sniff(sniff_ports) # Verify Ethernet and IP header of OSPF Hello packet. route_mac = env.switch[1].ui.get_table_route_interface()[0]['mac'] # Verify source MAC address belongs to route interface. assert sniff_ports[0] in data, 'OSPF Hello packets are not received!' check_pac_fields = False i = 0 packet_time = [] for packet in data[sniff_ports[0]]: # Verify source MAC address belongs to route interface. if env.tg[1].check_packet_field(packet, layer="Ethernet", field="src", value=route_mac.lower()): # Verify destination MAC is 01:00:5E:00:00:05. if env.tg[1].check_packet_field(packet, layer="Ethernet", field="dst", value="01:00:5E:00:00:05"): # Verify correct VLAN Tag. assert env.tg[1].check_packet_field(packet, layer="Dot1Q", field="vlan", value=100) # Verify source IP belongs to Route Interface. assert env.tg[1].check_packet_field(packet, layer="IP", field="src", value="10.0.1.1") # Verify destination IP is 224.0.0.5. assert env.tg[1].check_packet_field(packet, layer="IP", field="dst", value="224.0.0.5") # Verify OSPF header: OSPF version = 2. assert env.tg[1].check_packet_field(packet, layer="OSPF_Hdr", field="version", value=2) # Verify OSPF header: Message type = 1. assert env.tg[1].check_packet_field(packet, layer="OSPF_Hdr", field="type", value=1) # Verify OSPF header: Correct Router ID of the originating router. assert env.tg[1].check_packet_field(packet, layer="OSPF_Hdr", field="src", value="1.1.1.1") # Verify OSPF header: The Area ID of the originating router interface. assert env.tg[1].check_packet_field(packet, layer="OSPF_Hdr", field="area", value="0.0.0.0") # Verify Hello part: The address mask of the originating interface. assert env.tg[1].check_packet_field(packet, layer="OSPF_Hello", field="mask", value="255.255.255.0") # Verify Hello part: The HelloInterval of the originating interface. assert env.tg[1].check_packet_field(packet, layer="OSPF_Hello", field="hellointerval", value=10) # Verify Hello part: The RouterDeadInterval of the originating interface. assert env.tg[1].check_packet_field(packet, layer="OSPF_Hello", field="deadinterval", value=40) # Verify Hello part: The Router Priority. assert env.tg[1].check_packet_field(packet, layer="OSPF_Hello", field="prio", value=1) # Verify Hello part: The DR and BDR assert env.tg[1].check_packet_field(packet, layer="OSPF_Hello", field="backup", value="0.0.0.0") assert env.tg[1].check_packet_field(packet, layer="OSPF_Hello", field="router", value="0.0.0.0") # Verify Hello part: Five flag bits signifying optional capabilities. assert env.tg[1].check_packet_field(packet, layer="OSPF_Hello", field="options", value=0x02) packet_time.insert(i, packet.time) i += 1 check_pac_fields = True assert check_pac_fields, "Received OSPF Hello packet is inccorect." # Verify time delay between hello packets is 10 seconds by default. hello_interval = packet_time[2] - packet_time[1] self.suite_logger.debug("Delay between hello packets is {} (should be 10 secconds)".format(hello_interval)) assert int(hello_interval) in range(9, 11), "Delay between hello packets is incorrect"
def test_qinq_vlan_mapping(self, env): """ @brief Verify that customer unmapped packet is received on correct port if provider mapped packet from one Vlan to another is send (Using Vlan Mapping) @steps -# Configure Vlans 200 and 300 on ports 1 and 2. -# Configure port 1 as CustomerMapped. -# Configure port 2 as ProviderMapped. -# Configure Vlan Mapping for port 1, customer vlan 20, provider vlan 200. -# Configure Vlan Mapping for port 1, customer vlan 30, provider vlan 300. -# Send packet with vlan 200 to the port 1. -# Send packet with vlan 300 to the port 1. -# Verify that packets are received on port 2 with correct customer Vlan IDs. @endsteps """ destination_mac = "00:80:C2:04:00:00" source_mac = "00:00:00:00:02:22" destination_mac1 = "00:80:C2:02:00:00" source_mac1 = "00:00:00:00:00:42" vlan_id_customer1 = 20 vlan_id_customer2 = 30 vlan_id_provider1 = 200 vlan_id_provider2 = 300 tp_id_2 = 33024 vlan_priority_customer = 2 vlan_priority_provider = 4 ports = env.get_ports([['tg1', 'sw1', 2], ]) sniff_ports = list(ports[('tg1', 'sw1')].values()) # Disable all ports and enable only necessary ones helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, ports) port_id_customer = ports[('sw1', 'tg1')][1] port_id_provider = ports[('sw1', 'tg1')][2] # Disable STP env.switch[1].ui.configure_spanning_tree(enable='Disabled') # Generate two vlans env.switch[1].ui.create_vlans(vlans=[vlan_id_provider1, vlan_id_provider2]) # Add second port to provider vlans env.switch[1].ui.create_vlan_ports(ports=[port_id_provider], vlans=[vlan_id_provider1, vlan_id_provider2], tagged='Tagged') # Add customer port to provider vlans env.switch[1].ui.create_vlan_ports(ports=[port_id_customer], vlans=[vlan_id_provider1, vlan_id_provider2], tagged='Tagged') # Add entries about customer and provider in port table env.switch[1].ui.configure_qinq_ports([port_id_provider], mode='ProviderMapped') env.switch[1].ui.configure_qinq_ports([port_id_provider], tpid=37120) env.switch[1].ui.configure_qinq_ports([port_id_customer], mode='CustomerMapped') env.switch[1].ui.configure_qinq_ports([port_id_customer], tpid=33024) # Set options for vlan mapping env.switch[1].ui.configure_qinq_vlan_mapping([port_id_customer], vlan_id_customer1, vlan_priority_customer, vlan_id_provider1, vlan_priority_provider) env.switch[1].ui.configure_qinq_vlan_mapping([port_id_customer], vlan_id_customer2, vlan_priority_customer, vlan_id_provider2, vlan_priority_provider) # Define packets packet_definition = ({"Ethernet": {"dst": destination_mac, "src": source_mac, "type": 0x9100}}, {"Dot1Q": {"vlan": vlan_id_provider1, "type": 0x0800, "prio": vlan_priority_provider}}, {"IP": {}}) packet_definition1 = ({"Ethernet": {"dst": destination_mac1, "src": source_mac1, "type": 0x9100}}, {"Dot1Q": {"vlan": vlan_id_provider2, "type": 0x0800, "prio": vlan_priority_provider}}, {"IP": {}}) # Wait some time to add all rows to tables time.sleep(1) # Start sniffer env.tg[1].start_sniff(sniff_ports, sniffing_time=10) # Send one packet to the test port. stream_id = env.tg[1].set_stream(packet_definition, count=1, iface=ports[('tg1', 'sw1')][2]) stream_id_1 = env.tg[1].set_stream(packet_definition1, count=1, iface=ports[('tg1', 'sw1')][2]) env.tg[1].start_streams([stream_id, stream_id_1]) data = env.tg[1].stop_sniff(sniff_ports) env.tg[1].stop_streams([stream_id, stream_id_1]) helpers.print_sniffed_data_brief(data) # Verify that customer unmapped packet will be received # in correct port if it is send provider mapped packet assert sniff_ports[0] in list(data.keys()), "No packet on expected port" params = [{"layer": "Ethernet", "field": 'dst', "value": destination_mac.lower()}] packet = helpers.get_packet_from_the_port(sniff_port=sniff_ports[0], params=params, sniff_data=data, tg=env.tg[1])[0] assert env.tg[1].check_packet_field(packet=packet, layer="Ethernet", field="type", value=tp_id_2), "Type field value isn't equal to expected" assert env.tg[1].check_packet_field(packet=packet, layer="Dot1Q", field="vlan", value=vlan_id_customer1), "Vlan field value isn't equal to expected" assert env.tg[1].check_packet_field(packet=packet, layer="Dot1Q", field="prio", value=vlan_priority_customer), "Prio field value isn't equal to expected" assert env.tg[1].check_packet_field(packet=packet, layer="Dot1Q", field="type", value=2048), "Type field value isn't equal to expected" params = [{"layer": "Ethernet", "field": 'dst', "value": destination_mac1.lower()}] packet = helpers.get_packet_from_the_port(sniff_port=sniff_ports[0], params=params, sniff_data=data, tg=env.tg[1])[0] assert env.tg[1].check_packet_field(packet=packet, layer="Ethernet", field="type", value=tp_id_2), "Type field value isn't equal to expected" assert env.tg[1].check_packet_field(packet=packet, layer="Dot1Q", field="vlan", value=vlan_id_customer2), "Vlan field value isn't equal to expected" assert env.tg[1].check_packet_field(packet=packet, layer="Dot1Q", field="prio", value=vlan_priority_customer), "Prio field value isn't equal to expected" assert env.tg[1].check_packet_field(packet=packet, layer="Dot1Q", field="type", value=2048), "Type field value isn't equal to expected"
def test_lacp_frames(self, env): """ @brief Verify that correct LACP frames are transmitted from the configured dynamic LAG @steps -# Add each pair of device ports to separate LAGs -# Wait time until LAG transit to defaulted state -# Sniff for LACP frames on each LAG port -# Verify that device transmits properly formed LACP DUs @endsteps """ slow_protocols_mac = "01:80:c2:00:00:02" ports = env.get_ports([ ['tg1', 'sw1', 4], ]) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, ports) # Disable STP env.switch[1].ui.configure_spanning_tree(enable='Disabled') dut_mac = env.switch[1].ui.get_table_bridge_info(param="macAddress") sysprio = env.switch[1].ui.get_table_link_aggregation()[0]["priority"] max_delay = env.switch[1].ui.get_table_link_aggregation( )[0]["collectorMaxDelay"] lacp_ethertype = 0x8809 # Configure LAGs lag_config = { ports[("sw1", "tg1")][1]: { 'key': 0, 'portprio': 4096 }, ports[("sw1", "tg1")][2]: { 'key': 0, 'portprio': 4096 }, ports[("sw1", "tg1")][3]: { 'key': 1, 'portprio': 8192 }, ports[("sw1", "tg1")][4]: { 'key': 1, 'portprio': 8192 } } env.switch[1].ui.create_lag(lag=3800, key=0, lag_type='Dynamic', hash_mode='None') env.switch[1].ui.create_lag_ports( ports=[ports[("sw1", "tg1")][1], ports[("sw1", "tg1")][2]], lag=3800, priority=4096, lag_mode='Active', key=0, timeout='Short') env.switch[1].ui.create_lag(lag=3801, key=1, lag_type='Dynamic', hash_mode='None') env.switch[1].ui.create_lag_ports( ports=[ports[("sw1", "tg1")][3], ports[("sw1", "tg1")][4]], lag=3801, priority=8192, lag_mode='Active', key=1, timeout='Short') self.suite_logger.debug("Wait time to transit to defaulted state") time.sleep(5) sniff_tg_ports = list(ports[("tg1", "sw1")].values()) env.tg[1].start_sniff(sniff_tg_ports, sniffing_time=30, dst_filter=slow_protocols_mac) self.suite_logger.debug("Get Actor and Partner operStates.") states = defaultdict(dict) states[ports[("sw1", "tg1")][1]]['actor'] = [ x for x in env.switch[1].ui.get_table_lags_local_ports(lag=3800) if x['portId'] == ports[("sw1", "tg1")][1] ][0]['actorOperPortState'] states[ports[("sw1", "tg1")][1]]['partner'] = [ x for x in env.switch[1].ui.get_table_lags_remote_ports(lag=3800) if x['portId'] == ports[("sw1", "tg1")][1] ][0]['partnerOperPortState'] states[ports[("sw1", "tg1")][2]]['actor'] = [ x for x in env.switch[1].ui.get_table_lags_local_ports(lag=3800) if x['portId'] == ports[("sw1", "tg1")][2] ][0]['actorOperPortState'] states[ports[("sw1", "tg1")][2]]['partner'] = [ x for x in env.switch[1].ui.get_table_lags_remote_ports(lag=3800) if x['portId'] == ports[("sw1", "tg1")][2] ][0]['partnerOperPortState'] states[ports[("sw1", "tg1")][3]]['actor'] = [ x for x in env.switch[1].ui.get_table_lags_local_ports(lag=3801) if x['portId'] == ports[("sw1", "tg1")][3] ][0]['actorOperPortState'] states[ports[("sw1", "tg1")][3]]['partner'] = [ x for x in env.switch[1].ui.get_table_lags_remote_ports(lag=3801) if x['portId'] == ports[("sw1", "tg1")][3] ][0]['partnerOperPortState'] states[ports[("sw1", "tg1")][4]]['actor'] = [ x for x in env.switch[1].ui.get_table_lags_local_ports(lag=3801) if x['portId'] == ports[("sw1", "tg1")][4] ][0]['actorOperPortState'] states[ports[("sw1", "tg1")][4]]['partner'] = [ x for x in env.switch[1].ui.get_table_lags_remote_ports(lag=3801) if x['portId'] == ports[("sw1", "tg1")][4] ][0]['partnerOperPortState'] data = env.tg[1].stop_sniff(sniff_tg_ports) helpers.print_sniffed_data_brief(data) self.suite_logger.debug( "Verify that correct LACP frames are sent from each LAG port.") for index in range(1, 5): tg_port = ports[("tg1", "sw1")][index] sw_port = ports[("sw1", "tg1")][index] try: assert data[ tg_port], "No LACP frames sniffed on %s port".format( tg_port) except KeyError: pytest.fail("No LACP frame sniffed on %s port" % tg_port) for lacp_frame in data[tg_port]: prt_state = [ int(bit_val) for bit_val in states[sw_port]["partner"] ] partner_tlv = { "type": 2, "length": 20, "sysprio": 32768, "sys": "00:00:00:00:00:00", "key": 0, "portprio": 32768, "port": 1, "expired": prt_state[0], "defaulted": prt_state[1], "distribute": prt_state[2], "collect": prt_state[3], "synch": prt_state[4], "aggregate": prt_state[5], "timeout": prt_state[6], "activity": prt_state[7], "reserved": "\x00" * 3 } act_state = [ int(bit_val) for bit_val in states[sw_port]["actor"] ] expected_layers = { "Ethernet": { "src": dut_mac, "type": lacp_ethertype }, "LACP": { "version": 1, "subtype": 1 }, "LACPActorInfoTlv": { "type": 1, "length": 20, "sysprio": sysprio, "sys": dut_mac, "key": lag_config[sw_port]['key'], "portprio": lag_config[sw_port]["portprio"], "port": sw_port, "expired": act_state[0], "defaulted": act_state[1], "distribute": act_state[2], "collect": act_state[3], "synch": act_state[4], "aggregate": act_state[5], "timeout": act_state[6], "activity": act_state[7], "reserved": "\x00" * 3 }, "LACPPartnerInfoTlv": partner_tlv, "LACPCollectorInfoTlv": { "type": 3, "length": 16, "maxdelay": max_delay, "reserved": "\x00" * 12 }, "LACPTerminatorTlv": { "type": 0, "length": 0 }, "LACPReserved": { "reserved": "\x00" * 50 } } failures = [] for layer in expected_layers: for field, expected_value in expected_layers[layer].items( ): pack_value = env.tg[1].get_packet_field( lacp_frame, layer, field) try: if isinstance(pack_value, str): assert pack_value.lower() == expected_value.lower(), \ "Incorrect {} field {} value transmitted in LACP frame: {}".format(layer[4:], field, pack_value) else: assert pack_value == expected_value, "Incorrect {} field {} value transmitted in LACP frame: {}".format( layer[4:], field, pack_value) except AssertionError as err: failures.append("%s" % err) if failures: pytest.fail("\n".join(failures))
def test_static_route_one_ports_two_vlans(self, env): """ @brief Verify static route behaviour upon one port with two VLANs. @steps -# Configure Vlans 12 and 34 on port 1. -# Set pvid 12 for port 1. -# Create Route Interface 20.0.12.1/24 on Vlan 12. -# Create Route Interface 20.0.34.1/24 on Vlan 34. -# Create Static Route 10.10.10.0/24 with nexthop 20.0.34.5. -# Verify ARP request 'who has 20.0.34.5' received. -# Send ARP reply. -# Send IP packet with IP.dst 10.10.10.101 to the port 1. -# Verify IP packet is routed to the port 1. @endsteps """ ports = env.get_ports([['tg1', 'sw1', 1], ]) port_1 = ports[('sw1', 'tg1')][1] # Disabling all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch, wait_status=True) helpers.set_ports_admin_enabled(env.switch, ports, wait_status=True) # Disable STP env.switch[1].ui.configure_spanning_tree(enable='Disabled') # Define active ports for sniffing. sniff_ports = [ports[('tg1', 'sw1')][1], ] # Enable Routing. env.switch[1].ui.configure_routing(routing='Enabled', ospf=None) # Create test VLAN 10. env.switch[1].ui.create_vlans(vlans=[12, 34]) # Delete port 1 from default VLAN. env.switch[1].ui.delete_vlan_ports(ports=[port_1], vlans=[1]) # Add port 1 to created test VLANs. env.switch[1].ui.create_vlan_ports(ports=[port_1], vlans=[12, 34], tagged='Tagged') # Set proper pvid for port 1 env.switch[1].ui.modify_ports(ports=[port_1], pvid=12) # Add route interfaces. env.switch[1].ui.create_route_interface(12, '20.0.12.1/24', ip_type='InterVlan', bandwidth=1000, mtu=1500, status='Enabled', vrf=0, mode='ip') env.switch[1].ui.create_route_interface(34, '20.0.34.1/24', ip_type='InterVlan', bandwidth=1000, mtu=1500, status='Enabled', vrf=0, mode='ip') # Start sniffer env.tg[1].start_sniff(sniff_ports, sniffing_time=10) # Add Static route. env.switch[1].ui.create_static_route(ip='10.10.10.0/24', nexthop='20.0.34.5', network='20.0.34.1/24', distance=-1, mode='ip') # Get sniffer data data = env.tg[1].stop_sniff(sniff_ports) helpers.print_sniffed_data_brief(data) # Verify who-has "20.0.34.5" ARP requests received. params_1 = [{"layer": "Ethernet", "field": 'dst', "value": 'ff:ff:ff:ff:ff:ff'}, {"layer": "ARP", "field": 'pdst', "value": '20.0.34.5'}] assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[0], params=params_1, sniff_data=data, tg=env.tg[1])) >= 1, \ "Packet is not received" # Get routers MAC. route_mac = env.switch[1].ui.get_table_route_interface()[0]['mac'] # Send ARP reply to port 2. arp_reply = ({"Ethernet": {"src": "00:00:14:00:22:05", "dst": route_mac.lower(), "type": 0x8100}}, {"Dot1Q": {"vlan": 34}}, {"ARP": {"op": 2, "sha": "00:00:14:00:22:05", "tha": route_mac, "tpa": "20.0.34.1", "spa": "20.0.34.5"}}, ) stream_id = env.tg[1].set_stream(arp_reply, count=1, iface=ports[('tg1', 'sw1')][1]) env.tg[1].send_stream(stream_id) time.sleep(2) # Verify ARP entry has been added arp_table = env.switch[1].ui.get_table_arp(mode='arp') assert self.is_arp_added(arps=arp_table, mac='00:00:14:00:22:05', ip='20.0.34.5'), 'ARP entry was not added' # Start sniffer env.tg[1].start_sniff(sniff_ports, sniffing_time=10) # Send to switch port 1 untagged IP packet with destination IP 10.10.10.101. packet_definition = ({"Ethernet": {"src": "00:00:20:00:10:65", "dst": route_mac, "type": 0x0800}}, {"IP": {"src": "20.0.12.101", "dst": "10.10.10.101", "p": 17}}, {"UDP": {"dport": 23, "sport": 23}}) stream_id = env.tg[1].set_stream(packet_definition, count=1, iface=ports[('tg1', 'sw1')][1]) env.tg[1].send_stream(stream_id) # Stop sniffer data = env.tg[1].stop_sniff(sniff_ports) helpers.print_sniffed_data_brief(data) # Verify that TG port 1 receive IP packet with destination 10.10.10.101 params_2 = [{"layer": "Ethernet", "field": 'dst', "value": '00:00:14:00:22:05'}, {"layer": "Ethernet", "field": 'src', "value": route_mac.lower()}, {"layer": "IP", "field": 'src', "value": '20.0.12.101'}, {"layer": "IP", "field": 'dst', "value": '10.10.10.101'}, {"layer": "Dot1Q", "field": 'vlan', "value": 34}] assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[0], params=params_2, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received"
def test_qos_dot1q_strict_mode(self, env): """ @brief Verify that packets with Dot1p higher priority displace packets with Dot1p lower priority by Strict schedule mode @steps -# Set Dot1p trust mode value on ingress port 1 and port 2. -# Set Strict sched mode value on egress port 3. -# Send two streams with different Dot1p priorities. -# Verify that packets with Dot1p higher priority displace packets with Dot1p lower priority @endsteps """ prio_higher = 6 prio_lower = 4 src_1 = "00:00:00:00:01:11" src_2 = "00:00:00:00:02:22" dst_3 = "00:00:00:00:03:33" # Define active ports ports = env.get_ports([ ['sw1', 'tg1', 3], ]) device_ports = list(ports[('sw1', 'tg1')].values()) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, ports) # Disable Flow Control functionality env.switch[1].ui.modify_ports(device_ports, flowControl='None') for port in device_ports: env.switch[1].ui.wait_for_port_status(port, 'flowControl', 'None', 10) # Disable Cut Through functionality env.switch[1].ui.modify_ports(device_ports, cutThrough='Disabled') for port in device_ports: env.switch[1].ui.wait_for_port_status(port, 'cutThrough', 'Disabled', 10) # SetUp multicast and broadcast rate limits env.switch[1].ui.modify_ports(device_ports, setPortAttr="mcast_rate", attrVal=0) env.switch[1].ui.modify_ports(device_ports, setPortAttr="bcast_rate", attrVal=0) # Define packets with different Dot1p tags. packet_1 = ({ "Ethernet": { "dst": dst_3, "src": src_1, "type": 0x8100 } }, { "Dot1Q": { "vlan": 1, "type": 0x0800, "prio": prio_higher } }, { "IP": {} }) packet_2 = ({ "Ethernet": { "dst": dst_3, "src": src_2, "type": 0x8100 } }, { "Dot1Q": { "vlan": 1, "type": 0x0800, "prio": prio_lower } }, { "IP": {} }) stream_1 = env.tg[1].set_stream(packet_1, iface=ports[('tg1', 'sw1')][1], rate=100, continuous=True) stream_2 = env.tg[1].set_stream(packet_2, iface=ports[('tg1', 'sw1')][2], rate=100, continuous=True) # Set Dot1p trust mode value on ingress port_1 and port_2. env.switch[1].ui.configure_port_cos( ports=[device_ports[0], device_ports[1]], trustMode="Dot1p") # Verify values have been changed for port in [device_ports[0], device_ports[1]]: port_qos_trust_mode = env.switch[ 1].ui.get_table_ports_qos_scheduling(port=port) assert port_qos_trust_mode['trustMode'] == "Dot1p", \ 'Trust mode value is not set to "Dot1p" for port %s' % port # Set Strict sched mode value on egress port_3. env.switch[1].ui.configure_port_cos(ports=[ device_ports[2], ], schedMode="Strict") # Verify value has been changed port_qos_3_sched_mode = env.switch[ 1].ui.get_table_ports_qos_scheduling(port=device_ports[2]) assert port_qos_3_sched_mode['schedMode'] == "Strict", \ 'Strict sched mode is not set on port %s' % ports[('sw1', 'tg1')][3] # Set Tagged value on egress port_3. env.switch[1].ui.modify_vlan_ports(ports=[ device_ports[2], ], vlans=[ 1, ], tagged="Tagged") # Add Static MAC entry for egress port_3 definition. env.switch[1].ui.create_static_macs(device_ports[2], [ 1, ], [ dst_3, ]) # Set QoS statistic type for Dot1p definition on the TG port_3. env.tg[1].set_qos_stat_type(ports[('tg1', 'sw1')][3], "VLAN") # Need to wait until device generates all ICMP packets. time.sleep(5) # Send streams of packets with Dot1p priorities from the TG port_1 and port_2. env.tg[1].clear_statistics([ ports[('tg1', 'sw1')][1], ports[('tg1', 'sw1')][2], ports[('tg1', 'sw1')][3], ]) env.tg[1].start_sniff([ ports[('tg1', 'sw1')][3], ], filter_layer="Dot1Q.IP", src_filter=src_1, dst_filter=dst_3) env.tg[1].start_streams([ stream_1, stream_2, ]) time.sleep(10) # Stop sending streams from TG port_1 and port_2. env.tg[1].stop_streams([ stream_1, stream_2, ]) time.sleep(0.5) env.tg[1].stop_sniff([ ports[('tg1', 'sw1')][3], ], drop_packets=True) # Get count of sent packets on the TG port_1 and port_2. sent_count_stream_1 = env.tg[1].get_sent_frames_count( ports[('tg1', 'sw1')][1], ) # Get count of received packets with Dot1p higher priority on TG port_3. dot1p_count_stream_1 = env.tg[1].get_qos_frames_count( ports[('tg1', 'sw1')][3], prio_higher) if dot1p_count_stream_1 not in list( range(sent_count_stream_1, sent_count_stream_1 * 101 // 100)): pytest.fail( "Packets with Dot1p higher priority are lost when default mapping is configured." ) # Verify that filtered count of packets on TG port_3 is correct. filtered_count_stream_1 = env.tg[1].get_filtered_frames_count( ports[('tg1', 'sw1')][3], ) if filtered_count_stream_1 != dot1p_count_stream_1: pytest.fail( "Filter packets statistic has incorrect count of packets!") # Verify that not used queues don't receive any packets. if not self.not_used_cos_statistics(tg_instance=env.tg[1], prio_value_1=prio_higher, prio_value_2=prio_lower, iface=ports[('tg1', 'sw1')][3]): pytest.fail("Not used CoS statistics received unexpected packets!")
def test_multicast_traffic(self, env): """ @brief Verify that multicast traffic is forwarded according to the L2Multicast table. @steps -# Create Vlan 2. -# Add ports 1 and 2 into the created Vlan as Tagged. -# Create Multicast record with MAC '01:88:88:88:88:01' in Vlan 1 for port 2. -# Create Multicast record with MAC '01:88:88:88:88:02' in Vlan 2 for port 2. -# Send packet with Ethernet.dst '01:88:88:88:88:01' to the port 1 -# Verify packet is forwarded to the port 2 -# Send packet with Ethernet.dst '01:88:88:88:88:01' to the port 3 -# Verify packet is forwarded to the port 2 -# Send packet with Ethernet.dst '01:88:88:88:88:02' and Vlan 2 to the port 3 -# Verify packet is forwarded to the port 2 -# Send packet with Ethernet.dst '01:88:88:88:88:02' and Vlan 2 to the port 4 -# Verify packet is forwarded to the port 2 @endsteps """ # Set active ports ports = env.get_ports([ ['tg1', 'sw1', 4], ]) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, ports) self.suite_logger.debug("Disable STP.") env.switch[1].ui.configure_spanning_tree(enable='Disabled') # Add Vlans: env.switch[1].ui.create_vlans(vlans=[2]) # Add ports to vlans env.switch[1].ui.create_vlan_ports( ports=[ports[('sw1', 'tg1')][1], ports[('sw1', 'tg1')][2]], vlans=[2], tagged='Tagged') # Add multicast records env.switch[1].ui.create_multicast(port=ports[('sw1', 'tg1')][2], vlans=[1], macs=['01:88:88:88:88:01']) env.switch[1].ui.create_multicast(port=ports[('sw1', 'tg1')][2], vlans=[2], macs=['01:88:88:88:88:02']) # Configure multicast streams packet_1 = ({ 'Ethernet': { 'src': '00:11:11:11:11:11', 'dst': '01:88:88:88:88:01' } }, { 'IP': {} }) packet_2 = ({ 'Ethernet': { 'src': '00:11:11:11:11:11', 'dst': '01:88:88:88:88:02', 'type': 0x8100 } }, { 'Dot1Q': { 'vlan': 2 } }, { 'IP': {} }) stream_1 = env.tg[1].set_stream(packet_1, count=1, iface=ports[('tg1', 'sw1')][1]) stream_2 = env.tg[1].set_stream(packet_2, count=1, iface=ports[('tg1', 'sw1')][1]) stream_3 = env.tg[1].set_stream(packet_1, count=1, iface=ports[('tg1', 'sw1')][3]) stream_4 = env.tg[1].set_stream(packet_2, count=1, iface=ports[('tg1', 'sw1')][4]) sniff_ports = list(ports[('tg1', 'sw1')].values()) # Send stream 1 env.tg[1].start_sniff(sniff_ports, sniffing_time=5) env.tg[1].send_stream(stream_1) data = env.tg[1].stop_sniff(sniff_ports) # Print sniffed data helpers.print_sniffed_data_brief(data) # Verify that packet_1 is forwarded to the port 2 params = ({ "layer": 'Ethernet', "field": 'dst', "value": '01:88:88:88:88:01' }, ) assert len(helpers.get_packet_from_the_port(ports[('tg1', 'sw1')][2], params, data, env.tg[1])) == 1, \ "Multicast packet is not forwarded on port 2" assert len(helpers.get_packet_from_the_port(ports[('tg1', 'sw1')][3], params, data, env.tg[1])) == 0, \ "Multicast packet is forwarded on port 3" assert len(helpers.get_packet_from_the_port(ports[('tg1', 'sw1')][4], params, data, env.tg[1])) == 0, \ "Multicast packet is forwarded on port 4" # Send stream 2 env.tg[1].start_sniff(sniff_ports, sniffing_time=5) env.tg[1].send_stream(stream_2) data = env.tg[1].stop_sniff(sniff_ports) # Print sniffed data helpers.print_sniffed_data_brief(data) # Verify that packet_2 is forwarded to the port 2 params = ({ "layer": 'Ethernet', "field": 'dst', "value": '01:88:88:88:88:02' }, ) assert len(helpers.get_packet_from_the_port(ports[('tg1', 'sw1')][2], params, data, env.tg[1])) == 1, \ "Multicast packet is not forwarded on port 2" assert len(helpers.get_packet_from_the_port(ports[('tg1', 'sw1')][3], params, data, env.tg[1])) == 0, \ "Multicast packet is forwarded on port 3" assert len(helpers.get_packet_from_the_port(ports[('tg1', 'sw1')][4], params, data, env.tg[1])) == 0, \ "Multicast packet is forwarded on port 4" # Send stream 3 env.tg[1].start_sniff(sniff_ports, sniffing_time=5) env.tg[1].send_stream(stream_3) data = env.tg[1].stop_sniff(sniff_ports) # Print sniffed data helpers.print_sniffed_data_brief(data) # Verify that packet_3 is forwarded to the port 2 params = ({ "layer": 'Ethernet', "field": 'dst', "value": '01:88:88:88:88:01' }, ) assert len(helpers.get_packet_from_the_port(ports[('tg1', 'sw1')][2], params, data, env.tg[1])) == 1, \ "Multicast packet is not forwarded on port 2" assert len(helpers.get_packet_from_the_port(ports[('tg1', 'sw1')][1], params, data, env.tg[1])) == 0, \ "Multicast packet is forwarded on port 1" assert len(helpers.get_packet_from_the_port(ports[('tg1', 'sw1')][4], params, data, env.tg[1])) == 0, \ "Multicast packet is forwarded on port 4" # Send stream 4 env.tg[1].start_sniff(sniff_ports, sniffing_time=5) env.tg[1].send_stream(stream_4) data = env.tg[1].stop_sniff(sniff_ports) # Print sniffed data helpers.print_sniffed_data_brief(data) # Verify that packet_4 is forwarded to the port 2 params = ({ "layer": 'Ethernet', "field": 'dst', "value": '01:88:88:88:88:02' }, ) assert len(helpers.get_packet_from_the_port(ports[('tg1', 'sw1')][2], params, data, env.tg[1])) == 1, \ "Multicast packet is not forwarded on port 2" assert len(helpers.get_packet_from_the_port(ports[('tg1', 'sw1')][3], params, data, env.tg[1])) == 0, \ "Multicast packet is forwarded on port 3" assert len(helpers.get_packet_from_the_port(ports[('tg1', 'sw1')][1], params, data, env.tg[1])) == 0, \ "Multicast packet is forwarded on port 1"
def test_dynamic_arp_traffic(self, env): """ @brief Verify that traffic is processed according to the learned Dynamic ARP. @steps -# Perform device preconfiguration. -# Send IP traffic. -# Verify ARP request has been sent. -# Send ARP reply. -# Send IP packets, related to the ARP record, to the first port. -# Verify IP packet is routed. @endsteps """ # Perform device preconfiguration: add vlan and route interface # Get active ports: use two ports for test case ports = env.get_ports([['tg1', 'sw1', 2], ]) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, ports) self.suite_logger.debug("Disable STP.") env.switch[1].ui.configure_spanning_tree(enable='Disabled') self.suite_logger.debug("Perform test preconfiguration") env.switch[1].ui.create_vlans(vlans=[10, 20]) env.switch[1].ui.create_vlan_ports(ports=[ports[('sw1', 'tg1')][1], ], vlans=[10], tagged='Untagged') env.switch[1].ui.create_vlan_ports(ports=[ports[('sw1', 'tg1')][2], ], vlans=[20], tagged='Untagged') env.switch[1].ui.modify_ports(ports=[ports[('sw1', 'tg1')][1], ], pvid=10) env.switch[1].ui.modify_ports(ports=[ports[('sw1', 'tg1')][2], ], pvid=20) env.switch[1].ui.configure_routing(routing='Enabled', ospf=None) env.switch[1].ui.create_route_interface(10, '10.10.10.1/24', ip_type='InterVlan', bandwidth=1000, mtu=1500, status='Enabled', vrf=0, mode='ip') env.switch[1].ui.create_route_interface(20, '20.20.20.1/24', ip_type='InterVlan', bandwidth=1000, mtu=1500, status='Enabled', vrf=0, mode='ip') # Generate test traffic route_mac = env.switch[1].ui.get_table_route_interface()[0]['mac'] packet_1 = ({"Ethernet": {"dst": route_mac, "src": "00:00:0a:0a:0a:0a", "type": 0x8100}}, {"Dot1Q": {"vlan": 10}}, {"IP": {"dst": '20.20.20.20', "src": '10.10.10.10'}}, {"TCP": {}}) # Send packets to the first port stream = env.tg[1].set_stream(packet_1, count=1, iface=ports[('tg1', 'sw1')][1]) self.suite_logger.debug("Start the capture and send the test traffic") # Start capture env.tg[1].start_sniff([ports[('tg1', 'sw1')][2]], sniffing_time=10) # Send generated streams env.tg[1].send_stream(stream) # Stop capture data = env.tg[1].stop_sniff([ports[('tg1', 'sw1')][2]]) # Print captured data helpers.print_sniffed_data_brief(data) self.suite_logger.debug("Verify ARP request has been sent") # Get packets from the captured data params_1 = [{"layer": "Ethernet", "field": 'dst', "value": 'ff:ff:ff:ff:ff:ff'}, {"layer": "Ethernet", "field": 'src', "value": route_mac.lower()}, {"layer": "ARP", "field": 'op', "value": 1}, {"layer": "ARP", "field": 'tpa', "value": '20.20.20.20'}, {"layer": "ARP", "field": 'spa', "value": '20.20.20.1'}] assert len(helpers.get_packet_from_the_port(sniff_port=ports[('tg1', 'sw1')][2], params=params_1, sniff_data=data, tg=env.tg[1])) >= 1, \ "Packet is not received" # Send ARP reply arp_reply = ({"Ethernet": {"dst": route_mac, "src": "00:00:14:14:14:14", "type": 0x8100}}, {"Dot1Q": {"vlan": 20}}, {"ARP": {"op": 2, "sha": "00:00:14:14:14:14", "tha": route_mac, "spa": "20.20.20.20", "tpa": "20.20.20.1"}}) arp_stream = env.tg[1].set_stream(arp_reply, count=1, iface=ports[('tg1', 'sw1')][2]) env.tg[1].send_stream(arp_stream) # Verify ARP entry has been added arp_table = env.switch[1].ui.get_table_arp(mode='arp') assert self.is_arp_added(arps=arp_table, mac='00:00:14:14:14:14', ip='20.20.20.20'), 'ARP entry was not added' self.suite_logger.debug("Start the capture and send the test traffic") # Start capture env.tg[1].start_sniff([ports[('tg1', 'sw1')][2]], sniffing_time=10) # Send generated streams env.tg[1].send_stream(stream) # Stop capture data = env.tg[1].stop_sniff([ports[('tg1', 'sw1')][2]]) # Print captured data helpers.print_sniffed_data_brief(data) self.suite_logger.debug("Verify traffic is processed according to the ARP records") # Get packets from the captured data params_1 = [{"layer": "Ethernet", "field": 'dst', "value": '00:00:14:14:14:14'}, {"layer": "Ethernet", "field": 'src', "value": route_mac.lower()}, {"layer": "IP", "field": 'dst', "value": '20.20.20.20'}, {"layer": "IP", "field": 'src', "value": '10.10.10.10'}] assert len(helpers.get_packet_from_the_port(sniff_port=ports[('tg1', 'sw1')][2], params=params_1, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received"
def test_lag_traffic(self, env): """ @brief Verify that port can be added to(removed from) static LAG @steps -# Create static LAG. -# Add two ports into LAG -# Send traffic to the first LAG member. -# Verify traffic is forwarded only from non-LAG members. @endsteps """ # Get active ports: use four ports for test case active_ports = env.get_ports([['tg1', 'sw1', 3], ]) device_ports = list(active_ports[('sw1', 'tg1')].values()) sniff_ports = list(active_ports[('tg1', 'sw1')].values()) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) # Disable STP globally in order to avoid traffic loop env.switch[1].ui.configure_spanning_tree(enable="Disabled") helpers.set_ports_admin_enabled(env.switch, active_ports) # Create static LAG entry env.switch[1].ui.create_lag(lag=3800, key=0, lag_type='Static', hash_mode='None') # Add port into the LAG env.switch[1].ui.create_lag_ports(ports=device_ports[:2], lag=3800, key=0) env.switch[1].ui.wait_for_port_value_to_change( ports=[3800] + device_ports[:2], port_parameter='operationalStatus', value='Up') # Generate test traffic packet = ({"Ethernet": {"dst": "00:00:11:11:11:11", "src": "00:00:02:02:02:02"}}, {"IP": {}}, {"TCP": {}}) # Send packets to the first port stream = env.tg[1].set_stream(packet, count=1, iface=sniff_ports[0]) self.suite_logger.debug("Start the capture and send the test traffic") # Start capture env.tg[1].start_sniff(sniff_ports, sniffing_time=5) # Send generated streams env.tg[1].send_stream(stream) # Stop capture data = env.tg[1].stop_sniff(sniff_ports) # Print captured data helpers.print_sniffed_data_brief(data) # Get packets from the captured data # Verify first packet is sent only to second port params = [{"layer": "Ethernet", "field": 'dst', "value": '00:00:11:11:11:11'}, {"layer": "Ethernet", "field": 'src', "value": '00:00:02:02:02:02'}] #Traffic should be forwarded from non-LAG members assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[2], params=params, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received" # Traffic should not be forwarded from LAG members assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[1], params=params, sniff_data=data, tg=env.tg[1])) == 0, \ "Packet is received"
def test_qinq_vlan_stacking(self, env): """ @brief Verify that packet sent without double-tag from one Vlan to another is received on the correct port with double-tag (Vlan Stacking) @steps -# Configure Vlan 10 on port 1. -# Configure Vlan 100 on ports 1 and 2. -# Configure port 1 as CustomerStacked. -# Configure port 2 as ProviderStacked. -# Configure Vlan Stacking for port 1, provider vlan 100. -# Send packet with vlan 10 to the port 1. -# Verify that packet is double tagged on port 2 @endsteps """ destination_mac = "01:00:5E:00:01:05" source_mac = "00:00:00:00:08:22" vlan_id_customer = 10 vlan_id_provider = 100 vlan_priority_customer = 5 vlan_priority_provider = 6 ports = env.get_ports([['tg1', 'sw1', 2], ]) sniff_ports = list(ports[('tg1', 'sw1')].values()) # Disable all ports and enabling only necessary ones helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, ports) port_id_customer = ports[('sw1', 'tg1')][1] port_id_provider = ports[('sw1', 'tg1')][2] # Disable STP env.switch[1].ui.configure_spanning_tree(enable='Disabled') # Generate customer and provider vlans env.switch[1].ui.create_vlans(vlans=[vlan_id_customer, vlan_id_provider]) # Add port to customer vlan env.switch[1].ui.create_vlan_ports(ports=[port_id_customer], vlans=[vlan_id_customer], tagged='Tagged') # Add port to provider vlan env.switch[1].ui.create_vlan_ports(ports=[port_id_provider], vlans=[vlan_id_provider], tagged='Tagged') # Add customer port to provider vlan env.switch[1].ui.create_vlan_ports(ports=[port_id_customer], vlans=[vlan_id_provider], tagged='Untagged') # Add entries about customer and provider to ports table env.switch[1].ui.configure_qinq_ports([port_id_customer], mode='CustomerStacked') env.switch[1].ui.configure_qinq_ports([port_id_customer], tpid=33024) env.switch[1].ui.configure_qinq_ports([port_id_provider], mode='ProviderStacked') env.switch[1].ui.configure_qinq_ports([port_id_provider], tpid=37120) # Set options for vlan stacking env.switch[1].ui.configure_qinq_vlan_stacking([port_id_customer], vlan_id_provider, vlan_priority_provider) # Define packet without double tag packet_definition = ({"Ethernet": {"dst": destination_mac, "src": source_mac, "type": 0x8100}}, {"Dot1Q": {"vlan": vlan_id_customer, "type": 0x0800, "prio": vlan_priority_customer}}, {"IP": {}}) #Wait some time to add all rows to tables time.sleep(1) # Start sniffer env.tg[1].start_sniff(sniff_ports, sniffing_time=10) # Send one packet to the test port stream_id = env.tg[1].set_stream(packet_definition, count=1, iface=ports[('tg1', 'sw1')][1]) env.tg[1].send_stream(stream_id) data = env.tg[1].stop_sniff(sniff_ports) helpers.print_sniffed_data_brief(data) # Verify that packet is sending without double-tag from one Vlan # to another it will be received in correct port with double-tag assert sniff_ports[1] in list(data.keys()), "No packet on expected port" params = [{"layer": "Ethernet", "field": 'src', "value": source_mac.lower()}] packet = helpers.get_packet_from_the_port(sniff_port=sniff_ports[1], params=params, sniff_data=data, tg=env.tg[1])[0] assert env.tg[1].check_packet_field(packet=packet, layer="Ethernet", field="type", value=37120), \ "Field value isn't equal to expected" assert env.tg[1].check_packet_field(packet=packet, layer="Dot1Q", field="vlan", value=vlan_id_provider), \ "Vlan field value isn't equal to expected" assert env.tg[1].check_packet_field(packet=packet, layer="Dot1Q", field="prio", value=vlan_priority_provider), \ "Prio field value isn't equal to expected" layers = env.tg[1].packet_dictionary(packet) dot1q_counter = len([x for x in layers if "Dot1Q" in x]) assert dot1q_counter == 2
def test_vlan_traffic(self, env): """ @brief Verify that traffic is processed according to the configured Vlan @steps -# Create new Vlan. -# Add two ports into Vlan -# Send traffic to the first Vlan port. -# Verify traffic is forwarded only from second Vlan port. @endsteps """ # Get active ports: use four ports for test case active_ports = env.get_ports([ ['tg1', 'sw1', 3], ]) device_ports = list(active_ports[('sw1', 'tg1')].values()) sniff_ports = list(active_ports[('tg1', 'sw1')].values()) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, active_ports) self.suite_logger.debug("Disable STP.") env.switch[1].ui.configure_spanning_tree(enable='Disabled') # Create new Vlan env.switch[1].ui.create_vlans(vlans=[ 20, ]) # Add port into the Vlan env.switch[1].ui.create_vlan_ports(ports=device_ports[:2], vlans=[20], tagged='Untagged') # Generate test traffic packet = ({ "Ethernet": { "dst": "00:00:11:11:11:11", "src": "00:00:02:02:02:02", "type": 0x8100 } }, { 'Dot1Q': { 'vlan': 20 } }, { "IP": {} }, { "TCP": {} }) # Send packets to the first port stream = env.tg[1].set_stream(packet, count=1, iface=sniff_ports[0]) self.suite_logger.debug("Start the capture and send the test traffic") # Start capture env.tg[1].start_sniff(sniff_ports, sniffing_time=5) # Send generated streams env.tg[1].send_stream(stream) # Stop capture data = env.tg[1].stop_sniff(sniff_ports) # Print captured data helpers.print_sniffed_data_brief(data) # Get packets from the captured data # Verify first packet is sent only to second port params = [{ "layer": "Ethernet", "field": 'dst', "value": '00:00:11:11:11:11' }, { "layer": "Ethernet", "field": 'src', "value": '00:00:02:02:02:02' }] #Traffic should be forwarded from Vlan ports assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[1], params=params, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received" # Traffic should not be forwarded from non-Vlan ports assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[2], params=params, sniff_data=data, tg=env.tg[1])) == 0, \ "Packet is received"
def test_static_route_two_ports_in_one_vlan(self, env): """ @brief Verify traffic forwarding upon two port on one VLAN and one Router Interface. @steps -# Configure Vlan 10 on ports 1 and 2. -# Create Route Interface 20.0.10.1/24 on Vlan 10. -# Create Static Route 10.10.10.0/24 with nexthop 20.0.10.2. -# Verify ARP request 'who has 20.0.10.2' received on port 2. -# Send ARP reply. -# Send IP packet with IP.dst 10.10.10.101 to the port 1. -# Verify IP packet is routed to the port 2. @endsteps """ # Define active ports. ports = env.get_ports([['tg1', 'sw1', 2], ]) port_1 = ports[('sw1', 'tg1')][1] port_2 = ports[('sw1', 'tg1')][2] # Disabling all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch, wait_status=True) helpers.set_ports_admin_enabled(env.switch, ports, wait_status=True) # Define active ports for sniffing. sniff_ports = [ports[('tg1', 'sw1')][1], ports[('tg1', 'sw1')][2]] # Disable STP env.switch[1].ui.configure_spanning_tree(enable='Disabled') # Enable Routing. env.switch[1].ui.configure_routing(routing='Enabled', ospf=None) # Create test VLAN 10. env.switch[1].ui.create_vlans(vlans=[10]) # Add port 1 and port 3 to created test VLAN. env.switch[1].ui.create_vlan_ports(ports=[port_1, port_2], vlans=[10], tagged='Tagged') # Add route interface. env.switch[1].ui.create_route_interface(10, '20.0.10.1/24', ip_type='InterVlan', bandwidth=1000, mtu=1500, status='Enabled', vrf=0, mode='ip') # Start sniffer env.tg[1].start_sniff(sniff_ports, sniffing_time=10) # Add Static route. env.switch[1].ui.create_static_route(ip='10.10.10.0/24', nexthop='20.0.10.2', network='20.0.10.1/24', distance=-1, mode='ip') # Get sniffer data data = env.tg[1].stop_sniff(sniff_ports) helpers.print_sniffed_data_brief(data) # Verify who-has "20.0.10.2" ARP requests received. params_1 = [{"layer": "Ethernet", "field": 'dst', "value": 'ff:ff:ff:ff:ff:ff'}, {"layer": "ARP", "field": 'tpa', "value": '20.0.10.2'}] assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[1], params=params_1, sniff_data=data, tg=env.tg[1])) >= 1, \ "Packet is not received" # Get routers MAC. route_mac = env.switch[1].ui.get_table_route_interface()[0]['mac'] # Send ARP reply to port 2. arp_reply = ({"Ethernet": {"src": "00:00:14:00:0a:02", "dst": route_mac.lower(), "type": 0x8100}}, {"Dot1Q": {"vlan": 10}}, {"ARP": {"op": 2, "sha": "00:00:14:00:0a:02", "tha": route_mac, "tpa": "20.0.10.1", "spa": "20.0.10.2"}}, ) stream_id = env.tg[1].set_stream(arp_reply, count=1, iface=ports[('tg1', 'sw1')][2]) env.tg[1].send_stream(stream_id) time.sleep(2) # Verify ARP entry has been added arp_table = env.switch[1].ui.get_table_arp(mode='arp') assert self.is_arp_added(arps=arp_table, mac='00:00:14:00:0a:02', ip='20.0.10.2'), 'ARP entry was not added' # Start sniffer env.tg[1].start_sniff(sniff_ports, sniffing_time=10) # Send packet with source IP 20.0.10.101 and destination IP 10.10.10.101. packet_definition = ({"Ethernet": {"src": "00:00:10:00:02:65", "dst": route_mac, "type": 0x8100}}, {"Dot1Q": {"vlan": 10}}, {"IP": {"src": "20.0.10.101", "dst": "10.10.10.101", "p": 17}}, {"UDP": {"dport": 23, "sport": 23}}) stream_id = env.tg[1].set_stream(packet_definition, count=1, iface=ports[('tg1', 'sw1')][1]) env.tg[1].send_stream(stream_id) # Stop sniffer data = env.tg[1].stop_sniff(sniff_ports) helpers.print_sniffed_data_brief(data) # Verify packet with destination 10.10.10.101 is not forwarded back to port 1. params_2 = [{"layer": "IP", "field": 'dst', "value": '10.10.10.101'}, {"layer": "IP", "field": 'src', "value": '20.0.10.101'}, {"layer": "Ethernet", "field": 'src', "value": route_mac.lower()}] assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[0], params=params_2, sniff_data=data, tg=env.tg[1])) == 0, \ "Packet is received" # Verify packet is received from port 2. assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[1], params=params_2, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received"
def test_routes_table_max_records_count_same_area_traffic_2_ports(self, env): """ @brief Verify that Routes table accommodates at least 1k entries using OSPF routes @steps -# Add Vlans 100 and 200, set pvid on ports 1 and 2 to 100 and 200 -# Configure OSPF on DUT (area 0.0.0.0) -# Create Route Interfaces (10.1.0.0 on vlan 100, 10.2.0.0 on vlan 200) -# Configure OSPF router 2.2.2.2 with 512 routes in route range in IxNetwork on port 1 -# Configure OSPF router 3.3.3.3 with 512 routes in route range in IxNetwork on port 2 -# Start OSPF on IxNetwork -# Wait for DUT's'Route table has 1k records -# Create bidirectional traffic item with src in routes on port 1 and dst in routes from port 2 -# Start traffic on IxNetwork -# Verify traffic loss is not observed @endsteps """ ports = env.get_ports([['tg1', 'sw1', 2], ]) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, ports) # Disable STP env.switch[1].ui.configure_spanning_tree(enable='Disabled') # =================================== Configure device ===================================================== # Add entry to Vlans Table env.switch[1].ui.create_vlans(vlans=[100, 200]) env.switch[1].ui.delete_vlan_ports(ports=[ports[('sw1', 'tg1')][1], ports[('sw1', 'tg1')][2]], vlans=[1]) env.switch[1].ui.create_vlan_ports(ports=[ports[('sw1', 'tg1')][1], ], vlans=[100], tagged='Untagged') env.switch[1].ui.create_vlan_ports(ports=[ports[('sw1', 'tg1')][2], ], vlans=[200], tagged='Untagged') # Setting Primary VLAN ID for ports env.switch[1].ui.modify_ports(ports=[ports[('sw1', 'tg1')][1], ], pvid=100) env.switch[1].ui.modify_ports(ports=[ports[('sw1', 'tg1')][2], ], pvid=200) # Configuring general OSPF params env.switch[1].ui.configure_routing(routing='Enabled', ospf='Enabled') env.switch[1].ui.configure_ospf_router(logAdjacencyChanges='Enabled', routerId='1.1.1.1') # Adding default OSPF area env.switch[1].ui.create_ospf_area('0.0.0.0') # Adding OSPF route intefaces env.switch[1].ui.create_route_interface(100, '10.1.0.1/24', ip_type='InterVlan', bandwidth=1000, mtu=1500, status='Enabled', vrf=0, mode='ip') env.switch[1].ui.create_route_interface(200, '10.2.0.1/24', ip_type='InterVlan', bandwidth=1000, mtu=1500, status='Enabled', vrf=0, mode='ip') # "OSPF Networks 2 Area" env.switch[1].ui.create_network_2_area(network='10.1.0.1/24', area='0.0.0.0', mode='Disabled') env.switch[1].ui.create_network_2_area(network='10.2.0.1/24', area='0.0.0.0', mode='Disabled') # =================================== Configure IxNetwork ===================================================== tgport1 = ports[('tg1', 'sw1')][1] tgport2 = ports[('tg1', 'sw1')][2] increment_count = 512 session_handle_1 = env.tg[1].OSPF.config(tgport1, reset=True, mode="create", mac_address_init="0000.0a01.0002", intf_ip_addr="10.1.0.2", router_id="2.2.2.2", area_id="0.0.0.0", router_priority=1, neighbor_intf_ip_addr="10.1.0.1", lsa_discard_mode=0, enable_dr_bdr=1, mtu=1500, session_type="ospfv2") env.tg[1].OSPF.topology_route_config(session_handle_1, summary_number_of_prefix=increment_count, summary_prefix_start='192.168.1.1', summary_prefix_length=24, summary_prefix_metric=20, summary_route_type="another_area", type="summary_routes") session_handle_2 = env.tg[1].OSPF.config(tgport2, reset=True, mode="create", mac_address_init="0000.0a02.0002", intf_ip_addr="10.2.0.2", router_id="3.3.3.3", area_id="0.0.0.0", router_priority=1, neighbor_intf_ip_addr="10.2.0.1", lsa_discard_mode=0, enable_dr_bdr=1, mtu=1500, session_type="ospfv2") env.tg[1].OSPF.topology_route_config(session_handle_2, summary_number_of_prefix=increment_count, summary_prefix_start='193.168.1.1', summary_prefix_length=24, summary_prefix_metric=20, summary_route_type="another_area", type="summary_routes") env.tg[1].OSPF.ospf_control(session_handle_1) env.tg[1].OSPF.ospf_control(session_handle_2) # Wait some time for Route table loading self._wait_for_route_table_loading(env.switch[1], 600, 1024) # =================================== Generate traffic ===================================================== env.tg[1].traffic_config(mode='create', transmit_mode='continuous', src_dest_mesh='fully', route_mesh='one_to_one', circuit_type='none', circuit_endpoint_type='ipv4', emulation_src_handle="$%s" % (session_handle_1, ), emulation_dst_handle="$%s" % (session_handle_2, ), rate_percent=99, length_mode='fixed', frame_size=64) env.tg[1].traffic_control(action='run') time.sleep(60) env.tg[1].traffic_control(action='stop') time.sleep(15) env.tg[1].traffic_stats(tgport1) env.tg[1].traffic_stats(tgport2) # Get statistics send_1 = int(env.tg[1].traffic_dictionary[tgport1]['stats']['aggregate']['tx']['total_pkts']) send_2 = int(env.tg[1].traffic_dictionary[tgport2]['stats']['aggregate']['tx']['total_pkts']) receive_1 = int(env.tg[1].traffic_dictionary[tgport1]['stats']['aggregate']['rx']['total_pkts']) receive_2 = int(env.tg[1].traffic_dictionary[tgport2]['stats']['aggregate']['rx']['total_pkts']) assert 0 < receive_2 - send_1 < 40, "Packet loss is observed" assert 0 < receive_1 - send_2 < 40, "Packet loss is observed"
def test_statistics(self, env): """ @brief Verify that proper Statistics value updated during specific traffic is processed @steps -# Clear all statistics. -# Send 100 unicast frames. -# Verify proper Statistics values. @endsteps """ # Get active ports: use four ports for test case active_ports = env.get_ports([ ['tg1', 'sw1', 3], ]) device_ports = list(active_ports[('sw1', 'tg1')].values()) sniff_ports = list(active_ports[('tg1', 'sw1')].values()) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, active_ports) self.suite_logger.debug("Disable STP.") env.switch[1].ui.configure_spanning_tree(enable='Disabled') # Generate test traffic packet = ({ "Ethernet": { "dst": "00:00:11:11:11:11", "src": "00:00:02:02:02:02" } }, { "IP": {} }, { "TCP": {} }) # Send packets to the second port stream = env.tg[1].set_stream(packet, count=100, iface=sniff_ports[1]) # Clear all Statistics env.switch[1].ui.clear_statistics() # Get initial Statistics values port_0_tx = env.switch[1].ui.get_table_statistics( port=device_ports[0], stat_name='IfOutUcastPkts') port_1_rx = env.switch[1].ui.get_table_statistics( port=device_ports[1], stat_name='IfInUcastPkts') port_2_tx = env.switch[1].ui.get_table_statistics( port=device_ports[2], stat_name='IfOutUcastPkts') self.suite_logger.debug("Send the test traffic") env.tg[1].send_stream(stream) # Wait for Statistics to be updated time.sleep(15) # Get Statistics port_0_tx_end = env.switch[1].ui.get_table_statistics( port=device_ports[0], stat_name='IfOutUcastPkts') port_1_rx_end = env.switch[1].ui.get_table_statistics( port=device_ports[1], stat_name='IfInUcastPkts') port_2_tx_end = env.switch[1].ui.get_table_statistics( port=device_ports[2], stat_name='IfOutUcastPkts') # Verify Statistics values assert int(port_1_rx_end) - int( port_1_rx) == 100, 'Rx Statistics is wrong' assert int(port_0_tx_end) - int( port_0_tx) == 100, 'Tx Statistics is wrong' assert int(port_2_tx_end) - int( port_2_tx) == 100, 'Tx Statistics is wrong'
def test_mirroring_traffic(self, env): """ @brief Verify that simple Mirroring session can be created and deleted @steps -# Create simple mirroring session. -# Create static Fdb entry -# Send traffic that match created Fdb. -# Verify traffic is forwarded. -# Verify traffic is mirrored. @endsteps """ # Get active ports: use four ports for test case active_ports = env.get_ports([['tg1', 'sw1', 3], ]) device_ports = list(active_ports[('sw1', 'tg1')].values()) sniff_ports = list(active_ports[('tg1', 'sw1')].values()) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, active_ports) self.suite_logger.debug("Disable STP.") env.switch[1].ui.configure_spanning_tree(enable='Disabled') self.suite_logger.debug("Create Static FDB") # Create static Fdb record for second port mac = "00:00:00:11:11:11" env.switch[1].ui.create_static_macs(port=device_ports[1], vlans=[1], macs=[mac]) # Create simple mirroring session env.switch[1].ui.create_mirror_session(device_ports[0], device_ports[2], 'IngressAndEgress') # Generate test traffic packet = ({"Ethernet": {"dst": "00:00:00:11:11:11", "src": "00:00:00:02:02:02", "type": 0x8100}}, {"Dot1Q": {"vlan": 1}}, {"IP": {}}, {"TCP": {}}) # Send packets to the first port stream = env.tg[1].set_stream(packet, count=1, iface=sniff_ports[0]) self.suite_logger.debug("Start the capture and send the test traffic") # Start capture env.tg[1].start_sniff(sniff_ports, sniffing_time=10) # Send generated streams env.tg[1].send_stream(stream) # Stop capture data = env.tg[1].stop_sniff(sniff_ports) # Print captured data helpers.print_sniffed_data_brief(data) self.suite_logger.debug("Verify traffic is processed according to the FDB record") # Get packets from the captured data # Verify first packet is sent only to second port params_1 = [{"layer": "Ethernet", "field": 'dst', "value": '00:00:00:11:11:11'}, {"layer": "Ethernet", "field": 'src', "value": '00:00:00:02:02:02'}] assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[1], params=params_1, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received" # Verify ingress packet is mirrored params_2 = [{"layer": "Ethernet", "field": 'dst', "value": '00:00:00:11:11:11'}, {"layer": "Ethernet", "field": 'src', "value": '00:00:00:02:02:02'}, {"layer": "Dot1Q", "field": 'vlan', "value": 1}] assert len(helpers.get_packet_from_the_port(sniff_port=sniff_ports[2], params=params_2, sniff_data=data, tg=env.tg[1])) == 1, \ "Packet is not received"
def test_pfc_inhibit_traffic_of_max_sized_frames(self, env, type_of_pfc_config): """ @brief Verify that the DUT inhibits the transmission of max_sized frames when a PFC frame is received with quanta value equal to 1000. @steps -# Connect device with TG -# Configure egress port to accept PFC configurations -# Send DCBX PFC tlv to egress port: pfc enabled for 1 priority -# Configure Dot1p PortsQoS trust mode on ingress ports -# Create Static MAC entry to redirect traffic to egress port -# Transmit priority 1 traffic of max_sized frames from ingress ports -# Transmit pause frames with quanta value 1000 for 1 priority to egress port -# Verify that traffic rate is decreased according to sent pause frames @endsteps """ decrease_rate = 40 ports = env.get_ports([ ['tg1', 'sw1', 3], ]) # Disable all ports and enabling only necessary ones: helpers.set_all_ports_admin_disabled(env.switch) helpers.set_ports_admin_enabled(env.switch, ports) env.switch[1].ui.create_vlans([ 20, ]) env.switch[1].ui.create_vlan_ports( iter(ports[('sw1', 'tg1')].values()), [20], 'Tagged') egress_link = ports[('sw1', 'tg1')][1] egress_tg_port = ports[("tg1", "sw1")][1] ingress_tg_ports = [ports[("tg1", "sw1")][2], ports[("tg1", "sw1")][3]] # Create StaticMac env.switch[1].ui.create_static_macs(ports[('sw1', 'tg1')][1], [ 20, ], [ '00:00:02:02:02:02', ]) if type_of_pfc_config == 'Dcbx': self.configure_dcbx_pfc(env.switch[1], env.tg[1], ports) elif type_of_pfc_config == 'Manual': self.configure_pfc_manually_without_frame_sending( env.switch[1], iter(ports[('sw1', 'tg1')].values()), 1) pause_frame = self.build_pause_frame(src_mac='00:00:02:02:02:02') max_pause_frame_rate = self.get_packets_count_in_traffic_rate( env.tg[1], egress_tg_port, pause_frame, rate=100, size=64) # define priority tagged traffic to transmit through egress port streams = [] tgport_prio_dict = {} iter_ingress_ports = iter(ingress_tg_ports) packet = ({ "Ethernet": { "src": "00:11:11:11:11:12", "dst": '00:00:02:02:02:02' } }, { "Dot1Q": { "prio": 1, "type": 0x0800, "vlan": 20 } }, { "IP": {} }, { "UDP": {} }) for tg_port in iter_ingress_ports: streams.append(env.tg[1].set_stream(packet, iface=tg_port, continuous=True, rate=100, required_size=1518)) tgport_prio_dict[tg_port] = 1 env.tg[1].start_streams(streams) # Wait time to get sustainable traffic rate value time.sleep(2) initial_traffic_rate = env.tg[1].get_port_rxrate(egress_tg_port) env.tg[1].stop_streams() env.tg[1].clear_statistics(ingress_tg_ports + [egress_tg_port]) env.tg[1].set_qos_stat_type(egress_tg_port, "VLAN") self.suite_logger.debug("Start sending Pause frames to egress port") port_speed = env.switch[1].ui.get_table_ports( ports=[ egress_link, ], all_params=True)[0]["speed"] pause_frame_rate = self.get_pause_frames_rate_to_halt_traffic( quanta=1000, port_speed=port_speed, decrease_rate=decrease_rate, max_pause_frame_rate=max_pause_frame_rate) pause_stream = env.tg[1].set_stream(pause_frame, iface=egress_tg_port, continuous=True, rate=pause_frame_rate) env.tg[1].start_sniff([ egress_tg_port, ]) env.tg[1].start_streams([ pause_stream, ] + streams) time.sleep(2) self.suite_logger.debug( "Check port rate after transmitting pause frames") delay_rates = [] end_time = time.time() + 15 while time.time() <= end_time: # Check port rate each 5 seconds after transmitting pause frames actual_traffic_rate = env.tg[1].get_port_rxrate(egress_tg_port) delay_rates.append({ "actual_rate": actual_traffic_rate, "delay_rate": (initial_traffic_rate - actual_traffic_rate) * 100. / initial_traffic_rate }) time.sleep(5) env.tg[1].stop_sniff([ egress_tg_port, ], drop_packets=True) env.tg[1].stop_streams() self.suite_logger.debug( "Verify that traffic rate is decreased according to sent pause frames" ) for rate in delay_rates: assert abs( rate["delay_rate"] - decrease_rate ) <= 3, "Traffic rate is not decreased according to sent pause frames"