def GetERSPANSrcMac(testcase, inpkt, args=None): mirrorObj = __get_mirror_object(testcase, args) if not mirrorObj or mirrorObj.SpanType != 'ERSPAN': return "00:00:00:00:00:00" # underlay vpc, return TEP MAC spanvpc = vpc.client.GetVpcObject(mirrorObj.Node, mirrorObj.VPCId) if spanvpc.IsUnderlayVPC(): if mirrorObj.ErSpanDstType == 'tep': spantunnel = utils.GetConfigObjectById(ObjectTypes.TUNNEL, mirrorObj.TunnelId) if spantunnel.IsUnderlay(): nh = spantunnel.NEXTHOP l3if = nh.L3Interface return l3if.GetInterfaceMac().get() elif spanvpc.IsTenantVPC() and mirrorObj.ErSpanDstType == 'ip': lmappingclient = utils.GetClientObject(ObjectTypes.LMAPPING) lmapping = lmappingclient.GetLMapObjByEpIpKey(mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) rmappingclient = utils.GetClientObject(ObjectTypes.RMAPPING) rmapping = rmappingclient.GetRMapObjByEpIpKey(mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) if lmapping != None: return lmapping.VNIC.SUBNET.GetVRMacAddr() elif rmapping != None: return rmapping.SUBNET.GetVRMacAddr() return "00:00:00:00:00:00"
def GetERSPANDstMac(testcase, packet, args=None): mirrorObj = __get_mirror_object(testcase, args) if not mirrorObj or mirrorObj.SpanType != 'ERSPAN': return "00:00:00:00:00:00" # underlay vpc, return TEP MAC spanvpc = vpc.client.GetVpcObject(mirrorObj.Node, mirrorObj.VPCId) if spanvpc.IsUnderlayVPC(): if mirrorObj.ErSpanDstType == 'tep': spantunnel = utils.GetConfigObjectById(ObjectTypes.TUNNEL, mirrorObj.TunnelId) return str(spantunnel.NEXTHOP.GetUnderlayMacAddr()) elif mirrorObj.ErSpanDstType == 'ip': return "00:00:00:00:00:00" elif spanvpc.IsTenantVPC() and mirrorObj.ErSpanDstType == 'ip': lmappingclient = utils.GetClientObject(ObjectTypes.LMAPPING) lmapping = lmappingclient.GetLMapObjByEpIpKey(mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) rmappingclient = utils.GetClientObject(ObjectTypes.RMAPPING) rmapping = rmappingclient.GetRMapObjByEpIpKey(mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) if lmapping != None: return lmapping.VNIC.MACAddr elif rmapping != None: return rmapping.MACAddr return "00:00:00:00:00:00"
def GetSPANPortID(testcase, args=None): mirrorObj = __get_mirror_object(testcase, args) if not mirrorObj: return topo.PortTypes.NONE if mirrorObj.SpanType == 'RSPAN': return utils.GetPortIDfromInterface(mirrorObj.Interface) elif mirrorObj.SpanType == 'ERSPAN': spanvpc = vpc.client.GetVpcObject(mirrorObj.Node, mirrorObj.VPCId) spantunnel = None nh = None if spanvpc.IsUnderlayVPC() and mirrorObj.ErSpanDstType == 'tep': spantunnel = utils.GetConfigObjectById(ObjectTypes.TUNNEL, mirrorObj.TunnelId) elif spanvpc.IsTenantVPC() and mirrorObj.ErSpanDstType == 'ip': rmappingclient = utils.GetClientObject(ObjectTypes.RMAPPING) rmapping = rmappingclient.GetRMapObjByEpIpKey( mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) if rmapping != None: spantunnel = rmapping.TUNNEL if spantunnel != None and spantunnel.IsUnderlay(): nh = spantunnel.NEXTHOP if nh != None: l3if = nh.L3Interface return utils.GetPortIDfromInterface(l3if.EthIfIdx) return topo.PortTypes.NONE
def GetERSPANVxlanVniFromMapping(testcase, inpkt, args=None): mirrorObj = __get_mirror_object(testcase, args) if not mirrorObj or mirrorObj.SpanType != 'ERSPAN': return 0 spanvpc = vpc.client.GetVpcObject(mirrorObj.Node, mirrorObj.VPCId) if spanvpc.IsTenantVPC() and mirrorObj.ErSpanDstType == 'ip': rmappingclient = utils.GetClientObject(ObjectTypes.RMAPPING) rmapping = rmappingclient.GetRMapObjByEpIpKey(mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) if rmapping != None: return rmapping.SUBNET.FabricEncap.Value return 0
def GetERSPANTunnelIPFromMapping(testcase, inpkt, args=None): mirrorObj = __get_mirror_object(testcase, args) if not mirrorObj or mirrorObj.SpanType != 'ERSPAN': return "0" spanvpc = vpc.client.GetVpcObject(mirrorObj.Node, mirrorObj.VPCId) if spanvpc.IsTenantVPC() and mirrorObj.ErSpanDstType == 'ip': rmappingclient = utils.GetClientObject(ObjectTypes.RMAPPING) rmapping = rmappingclient.GetRMapObjByEpIpKey(mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) if rmapping != None: return str(rmapping.TUNNEL.RemoteIPAddr) return "0"
def GetERSPANOuterVlanID(testcase, packet, args=None): mirrorObj = __get_mirror_object(testcase, args) if not mirrorObj or mirrorObj.SpanType != 'ERSPAN': return 0 # underlay vpc, return TEP MAC spanvpc = vpc.client.GetVpcObject(mirrorObj.Node, mirrorObj.VPCId) if spanvpc.IsTenantVPC() and mirrorObj.ErSpanDstType == 'ip': lmappingclient = utils.GetClientObject(ObjectTypes.LMAPPING) lmapping = lmappingclient.GetLMapObjByEpIpKey(mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) if lmapping != None and lmapping.VNIC.VnicEncap.Type == "dot1q": return lmapping.VNIC.VlanId() return 0
def GetERSPANRingFromMapping(testcase, args=None): mirrorObj = __get_mirror_object(testcase, args) if not mirrorObj or mirrorObj.SpanType != 'ERSPAN': return None spanvpc = vpc.client.GetVpcObject(mirrorObj.Node, mirrorObj.VPCId) if spanvpc.IsTenantVPC() and mirrorObj.ErSpanDstType == 'ip': lmappingclient = utils.GetClientObject(ObjectTypes.LMAPPING) lmapping = lmappingclient.GetLMapObjByEpIpKey(mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) if lmapping != None: hostIf = lmapping.VNIC.SUBNET.HostIf return hostIf.lif.GetQt(args.qid) return None
def GetERSPANSrcIP(testcase, packet, args=None): mirrorObj = __get_mirror_object(testcase, args) if not mirrorObj or mirrorObj.SpanType != "ERSPAN": return "0" spanvpc = vpc.client.GetVpcObject(mirrorObj.Node, mirrorObj.VPCId) if spanvpc.IsUnderlayVPC(): if mirrorObj.ErSpanDstType == 'tep': spantunnel = utils.GetConfigObjectById(ObjectTypes.TUNNEL, mirrorObj.TunnelId) return str(spantunnel.LocalIPAddr) elif spanvpc.IsTenantVPC() and mirrorObj.ErSpanDstType == 'ip': lmappingclient = utils.GetClientObject(ObjectTypes.LMAPPING) lmapping = lmappingclient.GetLMapObjByEpIpKey(mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) rmappingclient = utils.GetClientObject(ObjectTypes.RMAPPING) rmapping = rmappingclient.GetRMapObjByEpIpKey(mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) if lmapping != None: return str(lmapping.VNIC.SUBNET.VirtualRouterIPAddr[1]) elif rmapping != None: return rmapping.SUBNET.GetIPv4VRIP() return "0"
def GetERSPANType3TemplateFromMapping(testcase, inpkt, args=None): mirrorObj = __get_mirror_object(testcase, args) if not mirrorObj or mirrorObj.SpanType == "RSPAN": return testcase.packets.Get('ERSPAN_MIRROR_PKT_' + args.direction + '_' + 'BASE') if mirrorObj.SpanType == "ERSPAN": spanvpc = vpc.client.GetVpcObject(mirrorObj.Node, mirrorObj.VPCId) if spanvpc.IsTenantVPC() and mirrorObj.ErSpanDstType == 'ip': lmappingclient = utils.GetClientObject(ObjectTypes.LMAPPING) lmapping = lmappingclient.GetLMapObjByEpIpKey( mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) if lmapping != None and lmapping.VNIC.VnicEncap.Type == 'dot1q': return testcase.packets.Get(mirrorObj.SpanType + '_QTAG_MIRROR_PKT_' + args.direction + '_' + 'BASE') return testcase.packets.Get(mirrorObj.SpanType + '_MIRROR_PKT_' + args.direction + '_' + 'BASE')
def GetERSPANUnderlayRemoteMac(testcase, inpkt, args=None): mirrorObj = __get_mirror_object(testcase, args) if not mirrorObj or mirrorObj.SpanType != 'ERSPAN': return "00:00:00:00:00:00" spanvpc = vpc.client.GetVpcObject(mirrorObj.Node, mirrorObj.VPCId) if spanvpc.IsTenantVPC() and mirrorObj.ErSpanDstType == 'ip': rmappingclient = utils.GetClientObject(ObjectTypes.RMAPPING) rmapping = rmappingclient.GetRMapObjByEpIpKey(mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) if rmapping != None: tunnel = rmapping.TUNNEL nh = None if tunnel != None and tunnel.IsUnderlay(): nh = tunnel.NEXTHOP if nh != None: return nh.underlayMACAddr.get() return "00:00:00:00:00:00"
def GetExpectedPacket(testcase, args): mirrorObj = __get_mirror_object(testcase, args) if not mirrorObj: return None if mirrorObj.SpanType == "RSPAN": return testcase.packets.Get(mirrorObj.SpanType + '_MIRROR_PKT_' + args.direction + '_' + str(args.id)) elif mirrorObj.SpanType == "ERSPAN": spanvpc = vpc.client.GetVpcObject(mirrorObj.Node, mirrorObj.VPCId) if spanvpc.IsUnderlayVPC(): return testcase.packets.Get(mirrorObj.SpanType + '_MIRROR_PKT_' + args.direction + '_' + str(args.id)) elif spanvpc.IsTenantVPC() and mirrorObj.ErSpanDstType == 'ip': rmappingclient = utils.GetClientObject(ObjectTypes.RMAPPING) rmapping = rmappingclient.GetRMapObjByEpIpKey( mirrorObj.Node, str(mirrorObj.DstIP), spanvpc.UUID.GetUuid()) # Remove args.direction after adding RX packets if rmapping != None and args.direction == 'TX': return testcase.packets.Get(mirrorObj.SpanType + '_TENANT_REMOTE' + '_MIRROR_PKT_' + args.direction + '_' + str(args.id)) return None