def test_tor_switch_downstream_standby(upper_tor_host, lower_tor_host, send_t1_to_server_with_action, toggle_all_simulator_ports_to_upper_tor, force_active_tor): """ Send downstream traffic to the standby ToR and perform switchover via CLI. Confirm switchover occurs and disruption lasts < 1 second """ send_t1_to_server_with_action( lower_tor_host, verify=True, delay=1, action=lambda: force_active_tor(lower_tor_host, 'all')) verify_tor_states(expected_active_host=lower_tor_host, expected_standby_host=upper_tor_host)
def test_tor_switch_upstream(upper_tor_host, lower_tor_host, send_server_to_t1_with_action, toggle_all_simulator_ports_to_upper_tor, force_active_tor): """ Send upstream traffic and perform switchover via CLI. Confirm switchover occurs and disruption lasts < 1 second """ send_server_to_t1_with_action( upper_tor_host, verify=True, delay=MUX_SIM_ALLOWED_DISRUPTION_SEC, action=lambda: force_active_tor(lower_tor_host, 'all')) verify_tor_states(expected_active_host=lower_tor_host, expected_standby_host=upper_tor_host)
def test_orchagent_slb( bgp_neighbors, constants, conn_graph_facts, force_active_tor, upper_tor_host, lower_tor_host, ptfadapter, ptfhost, setup_interfaces, toggle_all_simulator_ports_to_upper_tor, tbinfo, tunnel_traffic_monitor, vmhost ): def verify_bgp_session(duthost, bgp_neighbor): """Verify the bgp session to the DUT is established.""" bgp_facts = duthost.bgp_facts()["ansible_facts"] assert bgp_neighbor.ip in bgp_facts["bgp_neighbors"] assert bgp_facts["bgp_neighbors"][bgp_neighbor.ip]["state"] == "established" def verify_route(duthost, route, existing=True): """Verify the route's existence in the DUT.""" prefix = ipaddress.ip_network(route["prefix"]) existing_route = duthost.get_ip_route_info(dstip=prefix) if existing: assert route["nexthop"] in [str(_[0]) for _ in existing_route["nexthops"]] else: assert len(existing_route["nexthops"]) == 0 def verify_traffic(duthost, connection, route, is_duthost_active=True, is_route_existed=True): prefix = ipaddress.ip_network(route["prefix"]) dst_host = str(random.choice(list(prefix.hosts()))) pkt, exp_pkt = build_packet_to_server(duthost, ptfadapter, dst_host) ptf_t1_intf = random.choice(get_t1_ptf_ports(duthost, tbinfo)) ptf_t1_intf_index = int(ptf_t1_intf.strip("eth")) is_tunnel_traffic_existed = is_route_existed and not is_duthost_active is_server_traffic_existed = is_route_existed and is_duthost_active tunnel_innner_pkt = pkt[scapyall.IP].copy() tunnel_innner_pkt[scapyall.IP].ttl -= 1 tunnel_monitor = tunnel_traffic_monitor(duthost, existing=is_tunnel_traffic_existed, inner_packet=tunnel_innner_pkt) server_traffic_monitor = ServerTrafficMonitor( duthost, ptfhost, vmhost, tbinfo, connection["test_intf"], conn_graph_facts, exp_pkt, existing=is_server_traffic_existed ) with tunnel_monitor, server_traffic_monitor: testutils.send(ptfadapter, ptf_t1_intf_index, pkt, count=10) connections = setup_interfaces upper_tor_bgp_neighbor = bgp_neighbors["upper_tor"] lower_tor_bgp_neighbor = bgp_neighbors["lower_tor"] try: # STEP 1: create peer sessions with both ToRs lower_tor_bgp_neighbor.start_session() upper_tor_bgp_neighbor.start_session() time.sleep(constants.bgp_establish_sleep_interval) verify_bgp_session(upper_tor_host, upper_tor_bgp_neighbor) verify_bgp_session(lower_tor_host, lower_tor_bgp_neighbor) # STEP 2: announce a route to both ToRs upper_tor_bgp_neighbor.announce_route(constants.route) lower_tor_bgp_neighbor.announce_route(constants.route) time.sleep(constants.bgp_update_sleep_interval) verify_route(upper_tor_host, constants.route, existing=True) verify_route(lower_tor_host, constants.route, existing=True) # STEP 3: verify the route by sending some downstream traffic verify_traffic( upper_tor_host, connections["upper_tor"], constants.route, is_duthost_active=True, is_route_existed=True ) verify_traffic( lower_tor_host, connections["lower_tor"], constants.route, is_duthost_active=False, is_route_existed=True ) # STEP 4: withdraw the announced route to both ToRs upper_tor_bgp_neighbor.withdraw_route(constants.route) lower_tor_bgp_neighbor.withdraw_route(constants.route) time.sleep(constants.bgp_update_sleep_interval) verify_route(upper_tor_host, constants.route, existing=False) verify_route(lower_tor_host, constants.route, existing=False) # STEP 5: verify the route is removed by verifying that downstream traffic is dropped verify_traffic( upper_tor_host, connections["upper_tor"], constants.route, is_duthost_active=True, is_route_existed=False ) verify_traffic( lower_tor_host, connections["lower_tor"], constants.route, is_duthost_active=False, is_route_existed=False ) # STEP 6: toggle mux state change force_active_tor(lower_tor_host, 'all') time.sleep(constants.mux_state_change_sleep_interval) verify_bgp_session(upper_tor_host, upper_tor_bgp_neighbor) verify_bgp_session(lower_tor_host, lower_tor_bgp_neighbor) # STEP 7: announce the route to both ToRs after mux state change upper_tor_bgp_neighbor.announce_route(constants.route) lower_tor_bgp_neighbor.announce_route(constants.route) time.sleep(constants.bgp_update_sleep_interval) verify_route(upper_tor_host, constants.route, existing=True) verify_route(lower_tor_host, constants.route, existing=True) # STEP 8: verify the route by sending some downstream traffic verify_traffic( upper_tor_host, connections["upper_tor"], constants.route, is_duthost_active=False, is_route_existed=True ) verify_traffic( lower_tor_host, connections["lower_tor"], constants.route, is_duthost_active=True, is_route_existed=True ) # STEP 9: verify teardown upper_tor_bgp_neighbor.stop_session() verify_bgp_session(lower_tor_host, lower_tor_bgp_neighbor) verify_route(lower_tor_host, constants.route, existing=True) lower_tor_bgp_neighbor.stop_session() finally: upper_tor_bgp_neighbor.stop_session() lower_tor_bgp_neighbor.stop_session() upper_tor_host.shell("ip route flush %s" % constants.route["prefix"]) lower_tor_host.shell("ip route flush %s" % constants.route["prefix"])