def runTest(self): tenant_name = 't1' tenantData = Tenant(tenant_name) tenantData.delete_tenant(tenant_name) tenantData.build_tenant() egp_group = "g1" egp_cfg = {} egpDelData = Egp(egp_cfg) egpDelData.delete_configByGroup(egp_group) egp_cfg = {} egp_cfg['tenant'] = tenant_name egp_cfg['name'] = egp_group egp_cfg['mac'] = ["46:E4:3C:A4:17:C8/ff:ff:ff:ff:ff:ff"] egpData = Egp(egp_cfg).build_group() actual_port = egpData.get_group() chkData = actual_port["groups"][0] egp_mac = egp_cfg['mac'][0] chk_mac = chkData["macAddresses"][0] assert(egp_mac.lower() == chk_mac.lower() ), "Cannot get mac of egp config" assert(egp_cfg['name'] == chkData["name"] ), "Cannot get name of egp config" egpDelData.delete_configByGroup(egp_group) actual_port = egpData.get_group() assert([] == actual_port["groups"] ), "Cannot delete group of EGP config"
def runTest(self): tenant_name = 't1' segment_name = "s2" tenantData = Tenant(tenant_name) tenantData.delete_tenant(tenant_name) time.sleep(5) tenantData.build_tenant() segment_cfg = { "name": segment_name, "type": "vlan", "vlan_id": "2", "ip_address": [] } tenantData.segment(name=segment_cfg["name"], type=segment_cfg["type"], vlan_id=segment_cfg["vlan_id"], ip_address=segment_cfg["ip_address"]) tenantData.build_segment() segmentData = tenantData.get_segmentByTenant(tenant_name) segmentData = segmentData["tenantSegments"][0] assert (segment_cfg['name'] == segmentData['name']) assert (segment_cfg['type'] == segmentData['type']) assert (segment_cfg['vlan_id'] == str(segmentData['value'])) #print("debug: cfg.leaf0['portA'].name ", cfg.leaf0['portA'].name) SegmentMemberData = tenantData.segment_member( SegmentMember(segment_name, cfg.leaf0['id']).ports([cfg.leaf0['portA'].name])) ## SegmentMemberData = tenantData.segment_member(SegmentMemberData) tenantData.build_segment() actual_port = tenantData.get_segmentMemberById(tenant_name, segment_name, cfg.leaf0['id']) assert (cfg.leaf0['portA'].name == actual_port["segment_members"][0] ["ports"][0]) endpoint_cfg = {} endpoint_cfg['tenant'] = tenant_name endpoint_cfg['segment'] = segment_name endpoint_cfg['mac'] = "46:E4:3C:A4:17:C8" endpoint_cfg['ip_addresses'] = ["127.0.0.1"] endpoint_cfg['locations'] = [{ "device_id": cfg.leaf0['id'], "port": str(cfg.leaf0["front_port_A"]) }] endpointData = Endpoint(endpoint_cfg).build() time.sleep(5) actual_port = endpointData.get_configBySegment_Mac( segment_name, endpoint_cfg['mac']) chkData = actual_port["hosts"][0] assert (endpoint_cfg['mac'] == chkData["mac"] ), "Cannot get mac of endpoint config" assert (endpoint_cfg['ip_addresses'] == chkData["ip_addresses"] ), "Cannot get ip_addresses of endpoint config" tenantData.delete_tenant(tenant_name)
def runTest(self): tenant_name = 't1' tenantData = Tenant(tenant_name) tenantData.delete_tenant(tenant_name) tenantData.build_tenant() egp_group1 = "g1" egp_group2 = "g2" egp_cfg = {} egpDelData = Egp(egp_cfg) egpDelData.delete_configByGroup(egp_group1) egpDelData.delete_configByGroup(egp_group2) egp_cfg = {} egp_cfg['tenant'] = tenant_name egp_cfg['name'] = egp_group1 egp_cfg['mac'] = ["46:E4:3C:A4:17:C8/ff:ff:ff:ff:ff:ff"] egpData = Egp(egp_cfg).build_group() actual_port = egpData.get_groupByName(egp_group1) egp_mac = egp_cfg['mac'][0] chk_mac = actual_port["macAddresses"][0] assert(egp_mac.lower() == chk_mac.lower() ), "Cannot get mac of egp config" assert(egp_cfg['name'] == actual_port["name"] ), "Cannot get name of egp config" egp_cfg = {} egp_cfg['tenant'] = tenant_name egp_cfg['name'] = egp_group2 egp_cfg['mac'] = ["00:00:00:11:22:33/FF:FF:FF:FF:FF:FF"] egpData = Egp(egp_cfg).build_group() actual_port = egpData.get_groupByName(egp_group2) egp_mac = egp_cfg['mac'][0] chk_mac = actual_port["macAddresses"][0] assert(egp_mac.lower() == chk_mac.lower() ), "Cannot get mac of egp config" assert(egp_cfg['name'] == actual_port["name"] ), "Cannot get name of egp config"
def runTest(self): ports = sorted(config["port_map"].keys()) d_ip = "192.168.1.111" t_ip = "192.168.1.10" vlan_id = 2 tenant_name = 't1' segment_name = "s1" tenantData = Tenant(tenant_name) tenantData.delete_tenant(tenant_name) time.sleep(3) tenantData.build_tenant() segment_cfg = { "name": segment_name, "type": "vlan", "vlan_id": "{}".format(vlan_id), "ip_address": ["{}".format(d_ip)] } tenantData.segment(name=segment_cfg["name"], type=segment_cfg["type"], vlan_id=segment_cfg["vlan_id"], ip_address=segment_cfg["ip_address"]) tenantData.build_segment() time.sleep(5) segmentData = tenantData.get_segmentByTenant(tenant_name) segmentData = segmentData["tenantSegments"][0] assert (segment_cfg['name'] == segmentData['name']) assert (segment_cfg['type'] == segmentData['type']) assert (segment_cfg['vlan_id'] == str(segmentData['value'])) a_name = cfg.leaf0['portA'].name.replace("untag", "tag") b_name = cfg.leaf0['portB'].name.replace("untag", "tag") SegmentMemberData = tenantData.segment_member( SegmentMember(segment_name, cfg.leaf0['id']).ports([a_name, b_name])) tenantData.build_segment() time.sleep(5) actual_port = tenantData.get_segmentMemberById(tenant_name, segment_name, cfg.leaf0['id']) assert ( a_name in actual_port["segment_members"][0]["ports"]), "Not found port A" assert ( b_name in actual_port["segment_members"][0]["ports"]), "Not found port A" # manual setup mac manualMac = "46:E4:3C:A4:17:C8" manualIp = ["127.0.0.1"] endpoint_cfg = {} endpoint_cfg['tenant'] = tenant_name endpoint_cfg['segment'] = segment_name endpoint_cfg['mac'] = manualMac endpoint_cfg['ip_addresses'] = manualIp endpoint_cfg['locations'] = [{ "device_id": cfg.leaf0['id'], "port": str(cfg.leaf0["front_port_A"]) }] endpointData = Endpoint(endpoint_cfg).build() time.sleep(3) actual_port = endpointData.get_configBySegment_Mac( segment_name, endpoint_cfg['mac']) chkData = actual_port["hosts"][0] assert (endpoint_cfg['mac'] == chkData["mac"] ), "Cannot get mac of endpoint config(before reboot)" assert (endpoint_cfg['ip_addresses'] == chkData["ip_addresses"] ), "Cannot get ip_addresses of endpoint config(before reboot)" tenant_logical_router_cfg = {"name": "r1", "interfaces": ["s1"]} tlr = TenantLogicalRouterApi( TenantLogicalRouterCfg(tenant_logical_router_cfg)) assert (tlr.retrieve() == []) tlr.create(tenant='t1') result = tlr.retrieve() assert (result[0]['name'] == tenant_logical_router_cfg['name']) assert ( result[0]['interfaces'] == tenant_logical_router_cfg['interfaces']) assert (result[0]['tenant'] == 't1') # tlr.delete() time.sleep(10) pkt_from_p0_to_dut = simple_arp_packet( pktlen=68, vlan_vid=vlan_id, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host0['mac'], ip_snd=t_ip, ip_tgt=d_ip, hw_snd=cfg.host0['mac'], hw_tgt='00:00:00:00:00:00', ) expected_pkt = simple_eth_vlan_type_packet( pktlen=12, eth_type=0x0806, vlan_vid=vlan_id, eth_dst=cfg.host0['mac'], eth_src=cfg.spine0['mac'], ) for i in range(15): self.dataplane.send(ports[0], str(pkt_from_p0_to_dut)) wait_for_seconds(1) verify_packet(self, str(expected_pkt), ports[0]) # verify_no_packet(self, str(expected_pkt), ports[1]) time.sleep(50) endpoint_cfg = {} endpointData = Endpoint(endpoint_cfg) actual_port = endpointData.get() for portNum in actual_port["hosts"]: if portNum["mac"] == cfg.host0['mac']: # assert(t_ip == portNum["ip_addresses"][0] # ), "Cannot get ip_addresses of endpoint config" if t_ip == portNum["ip_addresses"][0]: break elif portNum["mac"] == actual_port["hosts"][ len(actual_port["hosts"]) - 1]["mac"]: assert (False), "Not found endpoint mac error" expected_pkt = simple_eth_vlan_packet( pktlen=64, vlan_vid=vlan_id, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host1['mac'], ) for i in range(15): self.dataplane.send(ports[1], str(expected_pkt)) wait_for_seconds(1) verify_packet(self, str(expected_pkt), ports[0]) time.sleep(50) actual_port = endpointData.get() for portNum in actual_port["hosts"]: if portNum["mac"] == cfg.host1['mac']: # assert('0.0.0.0' == portNum["ip_addresses"][0] # ), "Cannot get ip_addresses of endpoint config" if '0.0.0.0' == portNum["ip_addresses"][0]: break elif portNum["mac"] == actual_port["hosts"][ len(actual_port["hosts"]) - 1]["mac"]: assert (False), "Not found endpoint mac error(no ip)" # reboot rebootTest = RebootSwitch(cfg.leaf0['id']) rebootTest.reboot() rebootTest = RebootSwitch(cfg.leaf1['id']) rebootTest.reboot() time.sleep(330) expected_pkt = simple_eth_vlan_packet( pktlen=64, vlan_vid=vlan_id, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host1['mac'], ) for i in range(15): self.dataplane.send(ports[1], str(expected_pkt)) wait_for_seconds(1) verify_packet(self, str(expected_pkt), ports[0]) time.sleep(50) actual_port = endpointData.get() for portNum in actual_port["hosts"]: if portNum["mac"] == cfg.host1['mac']: assert ('0.0.0.0' == portNum["ip_addresses"][0] ), "Cannot get ip_addresses of endpoint config" break elif portNum["mac"] == actual_port["hosts"][ len(actual_port["hosts"]) - 1]["mac"]: assert (False), "Not found endpoint mac error(no ip)" actual_port = endpointData.get_configBySegment_Mac( segment_name, manualMac) chkData = actual_port["hosts"][0] assert (manualMac == chkData["mac"] ), "Cannot get mac of endpoint config(after reboot)" assert (manualIp == chkData["ip_addresses"] ), "Cannot get ip_addresses of endpoint config(after reboot)" # sned packet pkt_from_p0_to_dut = simple_arp_packet( pktlen=68, vlan_vid=vlan_id, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host0['mac'], ip_snd=t_ip, ip_tgt=d_ip, hw_snd=cfg.host0['mac'], hw_tgt='00:00:00:00:00:00', ) expected_pkt = simple_eth_vlan_type_packet( pktlen=12, eth_type=0x0806, vlan_vid=vlan_id, eth_dst=cfg.host0['mac'], eth_src=cfg.spine0['mac'], ) for i in range(15): self.dataplane.send(ports[0], str(pkt_from_p0_to_dut)) wait_for_seconds(1) #verify_packet(self, str(expected_pkt), ports[0]) #verify_no_packet(self, str(expected_pkt), ports[1]) time.sleep(50) endpoint_cfg = {} endpointData = Endpoint(endpoint_cfg) actual_port = endpointData.get() for portNum in actual_port["hosts"]: if portNum["mac"] == cfg.host0['mac']: assert ( t_ip == portNum["ip_addresses"][0] ), "Cannot get ip_addresses of endpoint config(after reboot)" break elif portNum["mac"] == actual_port["hosts"][ len(actual_port["hosts"]) - 1]["mac"]: assert (False), "Not found endpoint mac error(after reboot)" endpoint_cfg = {} endpointData = Endpoint(endpoint_cfg) endpointData.delete_configByTenant_Segment_Mac(tenant_name, segment_name, cfg.host0['mac']) endpointData.delete_configByTenant_Segment_Mac(tenant_name, segment_name, cfg.host1['mac']) endpointData.delete_configByTenant_Segment_Mac("unknown", "unknown", cfg.host0['mac']) endpointData.delete_configByTenant_Segment_Mac("unknown", "unknown", cfg.host1['mac']) tlr.delete() tenantData = Tenant(tenant_name) tenantData.delete_segment(segment_name) tenantData.delete_tenant(tenant_name)
def runTest(self): ports = sorted(config["port_map"].keys()) d_ip = "192.168.1.111" t_ip = "192.168.1.10" vlan_id = 2 tenant_name = 't1' segment_name = "s1" tenantData = Tenant(tenant_name) tenantData.delete_tenant(tenant_name) time.sleep(3) tenantData.build_tenant() segment_cfg = { "name": segment_name, "type": "vlan", "vlan_id": "{}".format(vlan_id), "ip_address": ["{}".format(d_ip)] } tenantData.segment(name=segment_cfg["name"], type=segment_cfg["type"], vlan_id=segment_cfg["vlan_id"], ip_address=segment_cfg["ip_address"]) tenantData.build_segment() time.sleep(5) segmentData = tenantData.get_segmentByTenant(tenant_name) segmentData = segmentData["tenantSegments"][0] assert (segment_cfg['name'] == segmentData['name']) assert (segment_cfg['type'] == segmentData['type']) assert (segment_cfg['vlan_id'] == str(segmentData['value'])) a_name = cfg.leaf0['portA'].name.replace("untag", "tag") b_name = cfg.leaf0['portB'].name.replace("untag", "tag") SegmentMemberData = tenantData.segment_member( SegmentMember(segment_name, cfg.leaf0['id']).ports([a_name, b_name])) tenantData.build_segment() time.sleep(5) tenant_logical_router_cfg = {"name": "r1", "interfaces": ["s1"]} tlr = TenantLogicalRouterApi( TenantLogicalRouterCfg(tenant_logical_router_cfg)) assert (tlr.retrieve() == []) tlr.create(tenant='t1') result = tlr.retrieve() assert (result[0]['name'] == tenant_logical_router_cfg['name']) assert ( result[0]['interfaces'] == tenant_logical_router_cfg['interfaces']) assert (result[0]['tenant'] == 't1') time.sleep(10) pkt_from_p0_to_dut = simple_arp_packet( pktlen=68, vlan_vid=vlan_id, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host0['mac'], ip_snd=t_ip, ip_tgt=d_ip, hw_snd=cfg.host0['mac'], hw_tgt='00:00:00:00:00:00', ) expected_pkt = simple_eth_vlan_type_packet( pktlen=12, eth_type=0x0806, vlan_vid=vlan_id, eth_dst=cfg.host0['mac'], eth_src=cfg.spine0['mac'], ) for i in range(15): self.dataplane.send(ports[0], str(pkt_from_p0_to_dut)) wait_for_seconds(1) verify_packet(self, str(expected_pkt), ports[0]) # verify_no_packet(self, str(expected_pkt), ports[1]) time.sleep(50) endpoint_cfg = {} endpointData = Endpoint(endpoint_cfg) actual_port = endpointData.get() for portNum in actual_port["hosts"]: if portNum["mac"] == cfg.host0['mac']: assert (t_ip == portNum["ip_addresses"][0] ), "Cannot get ip_addresses of endpoint config" break elif portNum["mac"] == actual_port["hosts"][ len(actual_port["hosts"]) - 1]["mac"]: assert (False), "Not found endpoint mac error" expected_pkt = simple_eth_vlan_packet( pktlen=64, vlan_vid=vlan_id, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host1['mac'], ) for i in range(15): self.dataplane.send(ports[1], str(expected_pkt)) wait_for_seconds(1) verify_packet(self, str(expected_pkt), ports[0]) time.sleep(50) actual_port = endpointData.get() for portNum in actual_port["hosts"]: if portNum["mac"] == cfg.host1['mac']: assert ('0.0.0.0' == portNum["ip_addresses"][0] ), "Cannot get ip_addresses of endpoint config" break elif portNum["mac"] == actual_port["hosts"][ len(actual_port["hosts"]) - 1]["mac"]: assert (False), "Not found endpoint mac error(no ip)" endpoint_cfg = {} endpointData = Endpoint(endpoint_cfg) endpointData.delete_configByTenant_Segment_Mac(tenant_name, segment_name, cfg.host0['mac']) endpointData.delete_configByTenant_Segment_Mac(tenant_name, segment_name, cfg.host1['mac']) tlr.delete()
def runTest(self): ports = sorted(config["port_map"].keys()) d_ip1 = "192.168.1.111" t_ip1 = "192.168.1.10" vlan_id1 = 2 tenant_name1 = 't1' segment_name1 = "s1" tenantData = Tenant(tenant_name1) tenantData.delete_tenant(tenant_name1) time.sleep(3) tenantData.build_tenant() segment_cfg = { "name": segment_name1, "type": "vlan", "vlan_id": "{}".format(vlan_id1), "ip_address": ["{}".format(d_ip1)] } tenantData.segment(name=segment_cfg["name"], type=segment_cfg["type"], vlan_id=segment_cfg["vlan_id"], ip_address=segment_cfg["ip_address"]) tenantData.build_segment() time.sleep(3) segmentData = tenantData.get_segmentByTenant(tenant_name1) segmentData = segmentData["tenantSegments"][0] assert (segment_cfg['name'] == segmentData['name']) assert (segment_cfg['type'] == segmentData['type']) assert (segment_cfg['vlan_id'] == str(segmentData['value'])) leaf0_a_name = cfg.leaf0['portA'].name.replace("untag", "tag") SegmentMemberData = tenantData.segment_member( SegmentMember(segment_name1, cfg.leaf0['id']).ports([leaf0_a_name])) tenantData.build_segment() time.sleep(3) d_ip2 = "192.168.3.111" t_ip2 = "192.168.3.10" vlan_id2 = 3 tenant_name2 = 't2' segment_name2 = "s2" tenantData = Tenant(tenant_name2) tenantData.delete_tenant(tenant_name2) time.sleep(3) tenantData.build_tenant() segment_cfg = { "name": segment_name2, "type": "vlan", "vlan_id": "{}".format(vlan_id2), "ip_address": ["{}".format(d_ip2)] } tenantData.segment(name=segment_cfg["name"], type=segment_cfg["type"], vlan_id=segment_cfg["vlan_id"], ip_address=segment_cfg["ip_address"]) tenantData.build_segment() time.sleep(3) segmentData = tenantData.get_segmentByTenant(tenant_name2) segmentData = segmentData["tenantSegments"][0] assert (segment_cfg['name'] == segmentData['name']) assert (segment_cfg['type'] == segmentData['type']) assert (segment_cfg['vlan_id'] == str(segmentData['value'])) leaf1_a_name = cfg.leaf1['portA'].name.replace("untag", "tag") SegmentMemberData = tenantData.segment_member( SegmentMember(segment_name2, cfg.leaf1['id']).ports([leaf1_a_name])) tenantData.build_segment() time.sleep(3) tenant_logical_router_cfg1 = {"name": "r1", "interfaces": ["s1"]} tlr1 = TenantLogicalRouterApi( TenantLogicalRouterCfg(tenant_logical_router_cfg1)) tenant_logical_router_cfg2 = {"name": "r2", "interfaces": ["s2"]} tlr2 = TenantLogicalRouterApi( TenantLogicalRouterCfg(tenant_logical_router_cfg2)) assert (tlr1.retrieve() == []) tlr1.create(tenant='t1') result = tlr1.retrieve() assert (result[0]['name'] == tenant_logical_router_cfg1['name']) assert (result[0]['interfaces'] == tenant_logical_router_cfg1['interfaces']) assert (result[0]['tenant'] == 't1') time.sleep(10) tlr2.create(tenant='t2') result = tlr2.retrieve() for chkData in result: if chkData["name"] == tenant_logical_router_cfg2['name']: #assert(result[0]['name'] == tenant_logical_router_cfg2['name']) assert (chkData['interfaces'] == tenant_logical_router_cfg2['interfaces']) assert (chkData['tenant'] == 't2') elif chkData["name"] == result[len(result) - 1]["name"]: assert (False), "Not found logical route name" time.sleep(10) # host0 ping pkt_from_p0_to_dut = simple_arp_packet(pktlen=68, vlan_vid=vlan_id1, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host0['mac'], ip_snd=t_ip1, ip_tgt=d_ip1, hw_snd=cfg.host0['mac'], hw_tgt='00:00:00:00:00:00') expected_pkt = simple_eth_vlan_type_packet( pktlen=12, eth_type=0x0806, vlan_vid=vlan_id1, eth_dst=cfg.host0['mac'], eth_src=cfg.spine0['mac'], ) for i in range(15): self.dataplane.send(ports[0], str(pkt_from_p0_to_dut)) wait_for_seconds(1) verify_packet(self, str(expected_pkt), ports[0]) verify_no_packet(self, str(expected_pkt), ports[1]) # host1 ping pkt_from_p2_to_dut = simple_arp_packet(pktlen=68, vlan_vid=vlan_id2, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host2['mac'], ip_snd=t_ip2, ip_tgt=d_ip2, hw_snd=cfg.host2['mac'], hw_tgt='00:00:00:00:00:00') expected_pkt = simple_eth_vlan_type_packet( pktlen=12, eth_type=0x0806, vlan_vid=vlan_id2, eth_dst=cfg.host2['mac'], eth_src=cfg.spine0['mac'], ) for i in range(15): self.dataplane.send(ports[2], str(pkt_from_p2_to_dut)) wait_for_seconds(1) verify_packet(self, str(expected_pkt), ports[2]) verify_no_packet(self, str(expected_pkt), ports[3]) egp_group_1 = "g1" egp_group_2 = "g2" egp_cfg = {} egpDelData = Egp(egp_cfg) egpDelData.delete_configByPolicy("p1") egpDelData.delete_configByPolicy("p2") egpDelData.delete_configByGroup(egp_group_1) egpDelData.delete_configByGroup(egp_group_2) egp_cfg['tenant'] = tenant_name1 egp_cfg['name'] = egp_group_1 egp_cfg['mac'] = ["{}/ff:ff:ff:ff:ff:ff".format(cfg.host0['mac'])] egpData = Egp(egp_cfg).build_group() actual_port = egpData.get_groupByName(egp_group_1) egp_mac = egp_cfg['mac'][0] chk_mac = actual_port["macAddresses"][0] assert ( egp_mac.lower() == chk_mac.lower()), "Cannot get mac of egp config" assert (egp_cfg['name'] == actual_port["name"] ), "Cannot get name of egp config" egp_cfg['tenant'] = tenant_name2 egp_cfg['name'] = egp_group_2 egp_cfg['mac'] = ["{}/ff:ff:ff:ff:ff:ff".format(cfg.host2['mac'])] egpData = Egp(egp_cfg).build_group() actual_port = egpData.get_groupByName(egp_group_2) egp_mac = egp_cfg['mac'][0] chk_mac = actual_port["macAddresses"][0] assert ( egp_mac.lower() == chk_mac.lower()), "Cannot get mac of egp config" assert (egp_cfg['name'] == actual_port["name"] ), "Cannot get name of egp config" egp_policy = "p1" egp_p_cfg = {} egp_p_cfg['tenant'] = tenant_name1 egp_p_cfg['apply_to'] = egp_group_1 egp_p_cfg['policy_name'] = egp_policy egp_p_cfg['timeRangeDays'] = 127 egp_p_cfg['timeRangeStart'] = 0 egp_p_cfg['timeRangeEnd'] = 23 egp_p_cfg['rules'] = [{ "match": { "dst_mac": "{}/FF:FF:FF:FF:FF:FF".format("ff:ff:ff:ff:ff:ff"), "vlan_id": "{}".format(vlan_id1), "ether_type": "0x0806" }, "action": "deny" }] egpData = Egp(egp_p_cfg).build_policy() actual_port = egpData.get_policyByName(egp_policy) chkData = actual_port assert (egp_p_cfg['policy_name'] == chkData["name"] ), "Cannot get policy name of egp config" assert (egp_p_cfg['timeRangeDays'] == chkData["timeRangeDays"] ), "Cannot get timeRangeDays of policy config" assert (egp_p_cfg['timeRangeStart'] == chkData["timeRangeStart"] ), "Cannot get timeRangeStart of policy config" assert (egp_p_cfg['timeRangeEnd'] == chkData["timeRangeEnd"] ), "Cannot get timeRangeEnd of policy config" assert (egp_p_cfg['rules'][0]["match"]["vlan_id"] == chkData['rules'] [0]["match"]["vid"]), "Cannot get vlan_id of policy config" assert (egp_p_cfg['rules'][0]["action"] == chkData['rules'][0] ["action"]), "Cannot get action of policy config" time.sleep(10) egp_policy = "p2" egp_p_cfg = {} egp_p_cfg['tenant'] = tenant_name2 egp_p_cfg['apply_to'] = egp_group_2 egp_p_cfg['policy_name'] = egp_policy egp_p_cfg['timeRangeDays'] = 127 egp_p_cfg['timeRangeStart'] = 0 egp_p_cfg['timeRangeEnd'] = 23 egp_p_cfg['rules'] = [{ "match": { "dst_mac": "{}/FF:FF:FF:FF:FF:FF".format("ff:ff:ff:ff:ff:ff"), "vlan_id": "{}".format(vlan_id2), "ether_type": "0x0806" }, "action": "deny" }] egpData = Egp(egp_p_cfg).build_policy() actual_port = egpData.get_policyByName(egp_policy) chkData = actual_port assert (egp_p_cfg['policy_name'] == chkData["name"] ), "Cannot get policy name of egp config" assert (egp_p_cfg['timeRangeDays'] == chkData["timeRangeDays"] ), "Cannot get timeRangeDays of policy config" assert (egp_p_cfg['timeRangeStart'] == chkData["timeRangeStart"] ), "Cannot get timeRangeStart of policy config" assert (egp_p_cfg['timeRangeEnd'] == chkData["timeRangeEnd"] ), "Cannot get timeRangeEnd of policy config" assert (egp_p_cfg['rules'][0]["match"]["vlan_id"] == chkData['rules'] [0]["match"]["vid"]), "Cannot get vlan_id of policy config" assert (egp_p_cfg['rules'][0]["action"] == chkData['rules'][0] ["action"]), "Cannot get action of policy config" time.sleep(10) # host0 ping pkt_from_p0_to_dut = simple_arp_packet(pktlen=68, vlan_vid=vlan_id1, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host0['mac'], ip_snd=t_ip1, ip_tgt=d_ip1, hw_snd=cfg.host0['mac'], hw_tgt='00:00:00:00:00:00') expected_pkt1 = simple_eth_vlan_type_packet( pktlen=12, eth_type=0x0806, vlan_vid=vlan_id1, eth_dst=cfg.host0['mac'], eth_src=cfg.spine0['mac'], ) for i in range(15): self.dataplane.send(ports[0], str(pkt_from_p0_to_dut)) wait_for_seconds(1) verify_no_packet(self, str(expected_pkt1), ports[0]) # host2 ping pkt_from_p2_to_dut = simple_arp_packet(pktlen=68, vlan_vid=vlan_id2, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host2['mac'], ip_snd=t_ip2, ip_tgt=d_ip2, hw_snd=cfg.host2['mac'], hw_tgt='00:00:00:00:00:00') expected_pkt2 = simple_eth_vlan_type_packet( pktlen=12, eth_type=0x0806, vlan_vid=vlan_id2, eth_dst=cfg.host2['mac'], eth_src=cfg.spine0['mac'], ) for i in range(15): self.dataplane.send(ports[2], str(pkt_from_p2_to_dut)) wait_for_seconds(1) verify_no_packet(self, str(expected_pkt2), ports[2]) # reboot rebootTest = RebootSwitch(cfg.leaf0['id']) rebootTest.reboot() rebootTest = RebootSwitch(cfg.leaf1['id']) rebootTest.reboot() time.sleep(240) # host0 ping for i in range(15): self.dataplane.send(ports[0], str(pkt_from_p0_to_dut)) wait_for_seconds(1) verify_no_packet(self, str(expected_pkt1), ports[0]) # host2 ping for i in range(15): self.dataplane.send(ports[2], str(pkt_from_p2_to_dut)) wait_for_seconds(1) verify_no_packet(self, str(expected_pkt2), ports[2]) tenantData = Tenant(tenant_name1) tenantData.delete_tenant(tenant_name1) tenantData = Tenant(tenant_name2) tenantData.delete_tenant(tenant_name2) egpDelData.delete_configByPolicy("p1") egpDelData.delete_configByPolicy("p2") egpDelData.delete_configByGroup(egp_group_1) egpDelData.delete_configByGroup(egp_group_2) tlr1.delete() tlr2.delete()
def runTest(self): ports = sorted(config["port_map"].keys()) d_ip = "192.168.1.111" t_ip = "192.168.1.10" vlan_id = 2 tenant_name = 't1' segment_name = "s1" tenantData = Tenant(tenant_name) tenantData.delete_tenant(tenant_name) time.sleep(3) tenantData.build_tenant() segment_cfg = { "name": segment_name, "type": "vlan", "vlan_id": "{}".format(vlan_id), "ip_address": ["{}".format(d_ip)] } tenantData.segment(name=segment_cfg["name"], type=segment_cfg["type"], vlan_id=segment_cfg["vlan_id"], ip_address=segment_cfg["ip_address"]) tenantData.build_segment() time.sleep(3) segmentData = tenantData.get_segmentByTenant(tenant_name) segmentData = segmentData["tenantSegments"][0] assert (segment_cfg['name'] == segmentData['name']) assert (segment_cfg['type'] == segmentData['type']) assert (segment_cfg['vlan_id'] == str(segmentData['value'])) a_name = cfg.leaf0['portA'].name.replace("untag", "tag") b_name = cfg.leaf0['portB'].name.replace("untag", "tag") SegmentMemberData = tenantData.segment_member( SegmentMember(segment_name, cfg.leaf0['id']).ports([a_name, b_name])) tenantData.build_segment() time.sleep(3) tenant_logical_router_cfg = {"name": "r1", "interfaces": ["s1"]} tlr = TenantLogicalRouterApi( TenantLogicalRouterCfg(tenant_logical_router_cfg)) assert (tlr.retrieve() == []) tlr.create(tenant='t1') result = tlr.retrieve() assert (result[0]['name'] == tenant_logical_router_cfg['name']) assert ( result[0]['interfaces'] == tenant_logical_router_cfg['interfaces']) assert (result[0]['tenant'] == 't1') time.sleep(30) pkt_from_p0_to_dut = simple_arp_packet(pktlen=68, vlan_vid=vlan_id, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host0['mac'], ip_snd=t_ip, ip_tgt=d_ip, hw_snd=cfg.host0['mac'], hw_tgt='00:00:00:00:00:00') expected_pkt = simple_eth_vlan_type_packet( pktlen=12, eth_type=0x0806, vlan_vid=vlan_id, eth_dst=cfg.host0['mac'], eth_src=cfg.spine0['mac'], ) for i in range(15): self.dataplane.send(ports[0], str(pkt_from_p0_to_dut)) wait_for_seconds(1) verify_packet(self, str(expected_pkt), ports[0]) verify_no_packet(self, str(expected_pkt), ports[1]) egp_group = "g1" egp_policy = "p1" egp_cfg = {} egpDelData = Egp(egp_cfg) egpDelData.delete_configByPolicy(egp_policy) egpDelData.delete_configByGroup(egp_group) egp_cfg['tenant'] = tenant_name egp_cfg['name'] = egp_group #egp_cfg['mac'] = ["{}/ff:ff:ff:00:00:00".format(cfg.spine0['mac'])] egp_cfg['mac'] = ["{}/ff:ff:ff:00:00:00".format(cfg.host0['mac'])] egpData = Egp(egp_cfg).build_group() actual_port = egpData.get_group() chkData = actual_port["groups"][0] egp_mac = egp_cfg['mac'][0] chk_mac = chkData["macAddresses"][0] assert ( egp_mac.lower() == chk_mac.lower()), "Cannot get mac of egp config" assert (egp_cfg['name'] == chkData["name"] ), "Cannot get name of egp config" egp_p_cfg = {} egp_p_cfg['tenant'] = tenant_name egp_p_cfg['apply_to'] = egp_group egp_p_cfg['policy_name'] = egp_policy egp_p_cfg['timeRangeDays'] = 127 egp_p_cfg['timeRangeStart'] = 0 egp_p_cfg['timeRangeEnd'] = 23 egp_p_cfg['rules'] = [{ "match": { # "src_ip": "{}".format(t_ip) # "dst_mac": "{}/FF:FF:FF:FF:FF:FF".format(cfg.host0['mac']), "dst_mac": "{}/FF:FF:FF:FF:FF:FF".format("ff:ff:ff:ff:ff:ff"), "vlan_id": "{}".format(vlan_id), "ether_type": "0x0806" }, "action": "deny" }] egpData = Egp(egp_p_cfg).build_policy() actual_port = egpData.get_policy() chkData = actual_port["policies"][0] assert (egp_p_cfg['policy_name'] == chkData["name"] ), "Cannot get policy name of egp config" assert (egp_p_cfg['timeRangeDays'] == chkData["timeRangeDays"] ), "Cannot get timeRangeDays of policy config" assert (egp_p_cfg['timeRangeStart'] == chkData["timeRangeStart"] ), "Cannot get timeRangeStart of policy config" assert (egp_p_cfg['timeRangeEnd'] == chkData["timeRangeEnd"] ), "Cannot get timeRangeEnd of policy config" # assert(egp_p_cfg['rules'][0]["match"]["src_ip"] == chkData['rules'][0]["match"]["srcIp"] # ), "Cannot get vlan_id of policy config" assert (egp_p_cfg['rules'][0]["action"] == chkData['rules'][0] ["action"]), "Cannot get action of policy config" time.sleep(30) expected_pkt = simple_eth_vlan_type_packet( pktlen=12, eth_type=0x0806, vlan_vid=vlan_id, eth_dst=cfg.host0['mac'], eth_src=cfg.spine0['mac'], ) for i in range(15): self.dataplane.send(ports[0], str(pkt_from_p0_to_dut)) wait_for_seconds(1) verify_no_packet(self, str(expected_pkt), ports[0]) #verify_packet(self, str(expected_pkt), ports[0]) tlr.delete()
def runTest(self): egp_cfg = {} egp_cfg['device-id'] = cfg.leaf0['id'] egpData = Egp(egp_cfg) actual_port = egpData.get_policy() assert("policies" in actual_port), "Cannot get EGP config" tenant_name = 't1' tenantData = Tenant(tenant_name) tenantData.delete_tenant(tenant_name) tenantData.build_tenant() egp_group1 = "g1" egp_group2 = "g2" egp_cfg = {} egpDelData = Egp(egp_cfg) egpDelData.delete_configByPolicy("p1") egpDelData.delete_configByPolicy("p2") egpDelData.delete_configByGroup(egp_group1) egpDelData.delete_configByGroup(egp_group2) egp_group = "g1" egp_cfg = {} egp_cfg['tenant'] = tenant_name egp_cfg['name'] = egp_group egp_cfg['mac'] = ["46:E4:3C:A4:17:C8/ff:ff:ff:ff:ff:ff"] egpData = Egp(egp_cfg).build_group() actual_port = egpData.get_group() chkData = actual_port["groups"][0] egp_mac = egp_cfg['mac'][0] chk_mac = chkData["macAddresses"][0] assert(egp_mac.lower() == chk_mac.lower() ), "Cannot get mac of egp config" assert(egp_cfg['name'] == chkData["name"] ), "Cannot get name of egp config" egp_policy = "p1" egp_p_cfg = {} egp_p_cfg['tenant'] = tenant_name egp_p_cfg['apply_to'] = egp_group egp_p_cfg['policy_name'] = egp_policy egp_p_cfg['timeRangeDays'] = 62 egp_p_cfg['timeRangeStart'] = 0 egp_p_cfg['timeRangeEnd'] = 23 egp_p_cfg['rules'] = [ { "match": { "vlan_id": "2" }, "action": "deny" } ] egpData = Egp(egp_p_cfg).build_policy() actual_port = egpData.get_policyByName(egp_policy) chkData = actual_port assert(egp_p_cfg['policy_name'] == chkData["name"] ), "Cannot get policy name of egp config" assert(egp_p_cfg['timeRangeDays'] == chkData["timeRangeDays"] ), "Cannot get timeRangeDays of policy config" assert(egp_p_cfg['timeRangeStart'] == chkData["timeRangeStart"] ), "Cannot get timeRangeStart of policy config" assert(egp_p_cfg['timeRangeEnd'] == chkData["timeRangeEnd"] ), "Cannot get timeRangeEnd of policy config" assert(egp_p_cfg['rules'][0]["match"]["vlan_id"] == chkData['rules'][0]["match"]["vid"] ), "Cannot get vlan_id of policy config" assert(egp_p_cfg['rules'][0]["action"] == chkData['rules'][0]["action"] ), "Cannot get action of policy config" egp_policy = "p2" egp_p_cfg = {} egp_p_cfg['tenant'] = tenant_name egp_p_cfg['apply_to'] = egp_group egp_p_cfg['policy_name'] = egp_policy egp_p_cfg['timeRangeDays'] = 62 egp_p_cfg['timeRangeStart'] = 0 egp_p_cfg['timeRangeEnd'] = 23 egp_p_cfg['rules'] = [ { "match": { "ether_type": "0x0800" }, "action": "deny" } ] egpData = Egp(egp_p_cfg).build_policy() actual_port = egpData.get_policyByName(egp_policy) chkData = actual_port assert(egp_p_cfg['policy_name'] == chkData["name"] ), "Cannot get policy name of egp config" assert(egp_p_cfg['timeRangeDays'] == chkData["timeRangeDays"] ), "Cannot get timeRangeDays of policy config" assert(egp_p_cfg['timeRangeStart'] == chkData["timeRangeStart"] ), "Cannot get timeRangeStart of policy config" assert(egp_p_cfg['timeRangeEnd'] == chkData["timeRangeEnd"] ), "Cannot get timeRangeEnd of policy config" assert(egp_p_cfg['rules'][0]["match"]["ether_type"] == chkData['rules'][0]["match"]["etherType"] ), "Cannot get ether_type of policy config" assert(egp_p_cfg['rules'][0]["action"] == chkData['rules'][0]["action"] ), "Cannot get action of policy config" egp_group1 = "g1" egp_group2 = "g2" egp_cfg = {} egpDelData = Egp(egp_cfg) egpDelData.delete_configByPolicy("p1") egpDelData.delete_configByPolicy("p2") egpDelData.delete_configByGroup(egp_group1) egpDelData.delete_configByGroup(egp_group2)