def CreateObjects(self, node): if EzAccessStoreClient[node].IsBitwMode(): logger.info(f"Skip Creating {self.ObjType.name} Objects in {node}") return if not utils.IsNetAgentMode(): cookie = utils.GetBatchCookie(node) if utils.IsL3InterfaceSupported(): cfgObjects = self.__uplinkl3ifs[node].values() # create l3 if for uplink interface logger.info( f"Creating {len(cfgObjects)} L3 {self.ObjType.name} Objects in {node}" ) msgs = list( map(lambda x: x.GetGrpcCreateMessage(cookie), cfgObjects)) api.client[node].Create(api.ObjectTypes.INTERFACE, msgs) list(map(lambda x: x.SetHwHabitant(True), cfgObjects)) if ((EzAccessStoreClient[node].IsDeviceOverlayRoutingEnabled() and utils.IsDol()) or (not EzAccessStoreClient[node].IsDeviceOverlayRoutingEnabled() and not utils.IsDol())): # create loopback interface lo_obj = self.__loopback_if[node] if lo_obj: logger.info( f"Creating 1 Loopback {self.ObjType.name} {lo_obj} Objects in {node}" ) lo_obj.Show() msgs = list( map(lambda x: x.GetGrpcCreateMessage(cookie), [lo_obj])) api.client[node].Create(api.ObjectTypes.INTERFACE, msgs) # create control interface ctrl_obj = self.__control_if[node] if ctrl_obj: logger.info( f"Creating 1 Control {self.ObjType.name} {ctrl_obj} Objects in {node}" ) ctrl_obj.Show() msgs = list( map(lambda x: x.GetGrpcCreateMessage(cookie), [ctrl_obj])) api.client[node].Create(api.ObjectTypes.INTERFACE, msgs) list(map(lambda x: x.SetHwHabitant(True), [ctrl_obj])) else: obj = self.__loopback_if[node] obj.Show() api.client[node].Update(api.ObjectTypes.INTERFACE, [obj]) return
def Create(self, spec=None): node = self.Node if utils.IsSkipSetup(): logger.info("Skip Creating objects in pds-agent for node ", node) return logger.info("Creating objects in pds-agent for node ", node) InterfaceClient.LoadHostDrivers(node) BatchClient.Start(node) DeviceClient.CreateObjects(node) if (EzAccessStoreClient[node].IsDeviceOverlayRoutingEnabled()): # Cannot extend batch across controlplane hijacked objects # when Overlay routing is enabled BatchClient.Commit(node) BatchClient.Start(node) InterfaceClient.CreateObjects(node) NexthopClient.CreateObjects(node) IpsecEncryptClient.CreateObjects(node) IpsecDecryptClient.CreateObjects(node) TunnelClient.CreateObjects(node) NHGroupClient.CreateObjects(node) VpcClient.CreateObjects(node) MirrorClient.CreateObjects(node) SecurityProfileClient.CreateObjects(node) BatchClient.Commit(node) if not utils.IsDol() and utils.IsNetAgentMode(): SubnetClient.UpdateHostInterfaces(node) OperEventClient.CreateObjects(node) # RmappingClient.OperateObjects(node, 'Create') return True
def SetupCfgFilesForUpgrade(self, spec=None): # For hardware nothing to setup specifically if not utils.IsDol(): return True if utils.IsDryRun(): return True mode = "hitless" self.failure_stage = None self.failure_reason = None args = "" if hasattr(spec, "UpgMode"): mode = getattr(spec, "UpgMode", "hitless") if hasattr(spec, "failure_stage"): self.failure_stage = getattr(spec, "failure_stage", None) if hasattr(spec, "failure_reason"): self.failure_reason = getattr(spec, "failure_reason", None) logger.info("Setup Upgrade Config Files for %s mode" % mode) logger.info("Setup Upgrade failure stage %s, failure reason %s" % (self.failure_stage, self.failure_reason)) if self.failure_stage != None and self.failure_reason != None: args = "%s %s" % (self.failure_stage, self.failure_reason) # For now cfg file setup done only for hitless mode if mode == "hitless": # setup hitless upgrade config files upg_setup_cmds = "apollo/test/tools/apulu/setup_hitless_upgrade_cfg_sim.sh %s" % args if not RunCmd(upg_setup_cmds, timeout=20, background=True): logger.error("Command Execution Failed: %s" % upg_setup_cmds) return False utils.Sleep(10) # setup is executed in the background. return True
def AutoUpdate(self): self.VirtualRouterMACAddr = ResmgrClient[ self.Node].VirtualRouterMacAllocator.get() if utils.IsDol(): hostIf = InterfaceClient.GetHostInterface(self.Node) if hostIf != None: self.HostIf = hostIf self.HostIfIdx = [utils.LifId2HostIfIndex(self.HostIf.lif.id)] self.HostIfUuid = [utils.PdsUuid(self.HostIfIdx[0]) ] if self.HostIfIdx[0] else [] self.V4RouteTableId = 0 # remove self from dependee list of those policies before updating it utils.ModifyPolicyDependency(self, True) self.IngV4SecurityPolicyIds = [ PolicyClient.GetIngV4SecurityPolicyId(self.Node, self.VPC.VPCId) ] self.EgV4SecurityPolicyIds = [ PolicyClient.GetEgV4SecurityPolicyId(self.Node, self.VPC.VPCId) ] utils.ModifyPolicyDependency(self, False) if self.IpV6Valid: self.VirtualRouterIPAddr[0] = self.AllocIPv6Address() self.VirtualRouterIPAddr[1] = self.AllocIPv4Address() self.IPAMname = None return
def ConnectToModel(self): # Add DUTNode check? if self.__connected: return if utils.IsDol(): from infra.asic.model import ModelConnector ModelConnector.ConfigDone() self.__connected = True return
def LoadHostDrivers(self, node): if not utils.IsDol(): return elif utils.IsSkipHostDriverLoad(): logger.info("Skip loading host drivers") return logger.info("Loading host drivers") hostintfs = self.__hostifs[node] for intf in hostintfs.values(): intf.ConfigureLifs() return
def GenerateHostInterfaces(self, node, topospec): if not utils.IsInterfaceSupported(): return if utils.IsReconfigInProgress(node): return if not utils.IsDol(): self.__generate_host_interfaces_iota(node, topospec) else: if hasattr(topospec, 'hostinterface'): self.__generate_host_interfaces_dol(node, topospec.hostinterface) return
def PdsctlRead(self, node): # read all via pdsctl # TODO: unify pdsctl code & get rid of this import if utils.IsDol(): import apollo.test.utils.pdsctl as pdsctl else: import iota.test.apulu.utils.pdsctl as pdsctl ret, op = pdsctl.GetObjects(node, self.GetPdsctlObjectName(), self.args) if not self.ValidatePdsctlRead(node, ret, op): logger.critical("Object validation failed for ", self.ObjType, ret, op) return False return True
def __init__(self, node, spec): super().__init__(node, spec, topo.InterfaceTypes.ETH) self.Network = '' self.RESTKey = None if utils.IsDol() and utils.IsHostLifSupported() and spec.lifns: self.obj_helper_lif = lif.LifObjectHelper(node) self.__generate_lifs(spec) self.UpdateImplicit() if spec.txpolicer: self.TxPolicer = PolicerClient.GetMatchingPolicerObject( node, 'egress') self.Show() return
def __init__(self, node, topospec, ip=None): super().__init__(topo.ObjectTypes.NODE, node) self.Node = node self.__topospec = topospec self.__connected = False self.ReconfigState = ReconfigState() self.NodeType = None if self.Node == EzAccessStore.GetDUTNode(): self.NodeType = 'DUT' agentapi.Init(node, ip) resmgr.Init(node) store.Init(node, self) if not utils.IsDol(): EzAccessStoreClient[self.Node].NodeObj = self
def PopulateSpec(self, grpcmsg): spec = grpcmsg.Request.add() spec.Id = self.GetKey() spec.AdminStatus = interface_pb2.IF_STATUS_UP spec.L3IfSpec.PortId = self.Port.GetUuid() # HAL automatically fetches the correct MAC on Naples from hardware # device register - overwriting with topo MAC breaks decap upon rx # from network if utils.IsDol(): spec.L3IfSpec.MACAddress = self.MacAddr.getnum() spec.L3IfSpec.VpcId = utils.PdsUuid.GetUUIDfromId( self.VPCId, api.ObjectTypes.VPC) utils.GetRpcIPPrefix(self.IpPrefix, spec.L3IfSpec.Prefix) utils.GetRpcIfIPPrefix(self.IfIpPrefix, spec.L3IfSpec.Prefix) return
def UpdateImplicit(self): if not utils.IsNetAgentMode(): return if utils.IsDol() and utils.IsDryRun(): return if not self.IsOriginImplicitlyCreated(): return # We need to read info from naples and update the DS resp = api.client[self.Node].GetHttp(self.ObjType) if not resp: return for ifinst in resp: if self.Type == topo.InterfaceTypes.L3: if (not ifinst['spec']['type'] == 'L3'): continue riid = ifinst['meta']['name'] if (self.InterfaceId != int(riid[len(riid) - 1])): continue elif self.Type == topo.InterfaceTypes.LOOPBACK: if (not ifinst['spec']['type'] == 'LOOPBACK'): continue elif self.Type == topo.InterfaceTypes.ETH: if (not ifinst['spec']['type'] == 'HOST_PF'): continue if (ifinst['status']['if-host-status']['host-ifname'] != self.IfName): continue else: continue # Found matching interface, get basic info uuid_str = ifinst['meta']['uuid'] self.UUID = utils.PdsUuid(bytes.fromhex(uuid_str.replace('-','')),\ self.ObjType) # instance found. Store meta info self.Tenant = ifinst['meta']['tenant'] self.Namespace = ifinst['meta']['namespace'] self.SetIfNameFromAgentData(ifinst['meta']['name']) # get ifinfo if 'ip-address' in ifinst['spec']: self.IpPrefix = ipaddress.ip_network(ifinst['spec']['ip-address'],\ False) if 'vrf-name' in ifinst['spec']: self.VrfName = ifinst['spec']['vrf-name'] return
def Generate(self, topospec): node = self.Node BatchClient.GenerateObjects(node, topospec) DeviceClient.GenerateObjects(node, topospec) PortClient.GenerateObjects(node, topospec) PolicerClient.GenerateObjects(node, topospec) InterfaceClient.GenerateHostInterfaces(node, topospec) MirrorClient.GenerateObjects(node, topospec) SecurityProfileClient.GenerateObjects(node, topospec) VpcClient.GenerateObjects(node, topospec) OperClient.GenerateObjects(node) OperEventClient.GenerateObjects(node) if utils.IsDol() and not utils.IsNetAgentMode(): UpgradeClient.GenerateObjects(node) NodeObject.__validate(node) return
def InitializeHostInterfaces(self): if not utils.IsDol(): return with open(utils.GetDeviceJsonPath(), 'r') as fp: obj = json.load(fp) lifbase = Resmgr.NICMGR_HOST_LIF_BASE lifcount = Resmgr.NICMGR_HOST_LIF_COUNT # read host interface info from device.json for ethdev in obj["eth_dev"]: if ethdev["type"] != 'host': continue ifname = ethdev["name"] intf = NicmgrInterface(ifname) intf.SetLifBase(lifbase) self.HostIfs.update({ifname: intf}) lifbase += lifcount if utils.IsInterfaceSupported(): self.InitializeHostMemMgr() self.ReadHostInterfaceInfo()
def __init__(self, node, spec): super().__init__(node, spec, topo.InterfaceTypes.L3) if hasattr(spec, 'origin'): self.SetOrigin(spec.origin) self.IpPrefix = None # In IOTA, get L3 interface IPs from testbed json file if present. # If not, then we'll use the one in the cfgyml. if EzAccessStoreClient[node].GetUnderlayIPs(): ifname = None if self.InterfaceId == 1: ifname = "Uplink0" elif self.InterfaceId == 2: ifname = "Uplink1" if ifname: self.IpPrefix = ipaddress.ip_network(EzAccessStoreClient[node].GetUnderlayIp(ifname) + "/" + \ EzAccessStoreClient[node].GetUnderlayMaskLen(ifname), False) self.IfIpPrefix = ipaddress.ip_interface(EzAccessStoreClient[node].GetUnderlayIp(ifname) + "/" + \ EzAccessStoreClient[node].GetUnderlayMaskLen(ifname)) logger.info( f"Configuring L3 Interface Id: {self.InterfaceId}" f"IP Prefix: {self.IpPrefix} IF IP Prefix: {self.IfIpPrefix}" ) if not self.IpPrefix: if hasattr(spec, 'ipprefix'): self.IpPrefix = ipaddress.ip_network( spec.ipprefix.replace('\\', '/'), False) self.IfIpPrefix = ipaddress.ip_interface( spec.ipprefix.replace('\\', '/')) else: self.IpPrefix = next(ResmgrClient[node].L3InterfaceIPv4PfxPool) self.IfIpPrefix = next( ResmgrClient[node].L3InterfaceIPv4PfxPool) self.EthIfIdx = getattr(spec, 'ethifidx', -1) if utils.IsDol(): node_uuid = None else: node_uuid = EzAccessStoreClient[node].GetNodeUuid(node) self.Port = utils.PdsUuid(self.EthIfIdx, node_uuid=node_uuid) self.PortNum = getattr(spec, 'port', -1) self.Encap = getattr(spec, 'encap', None) self.UpdateImplicit() self.Show() return
def IsReadSupported(self): if utils.IsNetAgentMode() and utils.IsDol(): # TODO: fix l3 intf return False return True
def __init__(self, node, parent, spec, poolid): super().__init__(api.ObjectTypes.SUBNET, node) if hasattr(spec, 'origin'): self.SetOrigin(spec.origin) parent.AddChild(self) ################# PUBLIC ATTRIBUTES OF SUBNET OBJECT ##################### if (hasattr(spec, 'id')): self.SubnetId = spec.id else: self.SubnetId = next(ResmgrClient[node].SubnetIdAllocator) self.GID('Subnet%d' % self.SubnetId) self.UUID = utils.PdsUuid(self.SubnetId, self.ObjType) self.VPC = parent self.PfxSel = parent.PfxSel self.IPPrefix = {} if getattr(spec, 'v6prefix', None) != None or \ getattr(spec, 'v6prefixlen', None) != None: self.IPPrefix[0] = parent.AllocIPv6SubnetPrefix(poolid) self.IpV6Valid = True else: self.IpV6Valid = False if getattr(spec, 'v4prefix', None) != None: self.IPPrefix[1] = ipaddress.ip_network( spec.v4prefix.replace('\\', '/')) else: self.IPPrefix[1] = parent.AllocIPv4SubnetPrefix(poolid) self.ToS = getattr(spec, 'tos', 0) self.VirtualRouterIPAddr = {} self.VirtualRouterMacAddr = None self.V4RouteTableId = route.client.GetRouteV4TableId( node, parent.VPCId) self.V6RouteTableId = route.client.GetRouteV6TableId( node, parent.VPCId) self.IngV4SecurityPolicyIds = utils.GetPolicies( self, spec, node, "V4", "ingress") self.IngV6SecurityPolicyIds = utils.GetPolicies( self, spec, node, "V6", "ingress") self.EgV4SecurityPolicyIds = utils.GetPolicies(self, spec, node, "V4", "egress") self.EgV6SecurityPolicyIds = utils.GetPolicies(self, spec, node, "V6", "egress") self.V4RouteTable = route.client.GetRouteV4Table( node, parent.VPCId, self.V4RouteTableId) self.V6RouteTable = route.client.GetRouteV6Table( node, parent.VPCId, self.V6RouteTableId) self.ToS = 0 self.IPAMname = 'Dhcp1' self.FabricEncap = base.Encap.ParseFromSpec( spec, "fabricencap", 'vxlan', next(ResmgrClient[node].VxlanIdAllocator)) # TODO: clean this host if logic self.HostIfIdx = [] if utils.IsDol(): self.HostIf = InterfaceClient.GetHostInterface(node) if self.HostIf: self.HostIfIdx.append( utils.LifId2HostIfIndex(self.HostIf.lif.id)) node_uuid = None else: self.HostIf = None hostifidx = getattr(spec, 'hostifidx', None) if hostifidx: if isinstance(hostifidx, list): for ifidx in hostifidx: self.HostIfIdx.append( utils.LifIfIndex2HostIfIndex(int(ifidx))) else: self.HostIfIdx.append(int(hostifidx)) elif getattr(spec, 'vnic', None): hostifidx = InterfaceClient.GetHostInterface(node) if hostifidx: self.HostIfIdx.append( utils.LifIfIndex2HostIfIndex(hostifidx)) node_uuid = EzAccessStoreClient[node].GetNodeUuid(node) self.HostIfUuid = [] for ifidx in self.HostIfIdx: self.HostIfUuid.append(utils.PdsUuid(ifidx, node_uuid=node_uuid)) # TODO: randomize maybe? if utils.IsNetAgentMode(): self.DHCPPolicyIds = list( map(lambda x: x.Id, DHCPRelayClient.Objects(node))) else: self.DHCPPolicyIds = getattr(spec, 'dhcppolicy', None) self.Status = SubnetStatus() ################# PRIVATE ATTRIBUTES OF SUBNET OBJECT ##################### if self.IpV6Valid: Resmgr.CreateIPv6AddrPoolForSubnet(self.SubnetId, self.IPPrefix[0]) Resmgr.CreateIPv4AddrPoolForSubnet(self.SubnetId, self.IPPrefix[1]) self.__set_vrouter_attributes(spec) self.DeriveOperInfo() self.Mutable = utils.IsUpdateSupported() self.GenerateChildren(node, spec) self.__fill_default_rules_in_policy(node) self.Show() return
def __init__(self, node, parent, spec, rxmirror, txmirror): super().__init__(api.ObjectTypes.VNIC, node) self.Class = VnicObject parent.AddChild(self) if hasattr(spec, 'origin'): self.SetOrigin(spec.origin) elif (EzAccessStoreClient[node].IsDeviceLearningEnabled()): self.SetOrigin('discovered') ################# PUBLIC ATTRIBUTES OF VNIC OBJECT ##################### if (hasattr(spec, 'id')): self.VnicId = spec.id else: self.VnicId = next(ResmgrClient[node].VnicIdAllocator) self.GID('Vnic%d' % self.VnicId) self.UUID = utils.PdsUuid(self.VnicId, self.ObjType) self.SUBNET = parent self.HostIfIdx = None self.HostIfUuid = None if utils.IsDol(): node_uuid = None else: node_uuid = EzAccessStoreClient[node].GetNodeUuid(node) hostifidx = getattr(spec, 'hostifidx', None) if hostifidx: self.HostIfIdx = utils.LifIfIndex2HostIfIndex(int(hostifidx)) elif len(parent.HostIfIdx) != 0: self.HostIfIdx = parent.HostIfIdx[0] if self.HostIfIdx: self.HostIfUuid = utils.PdsUuid(self.HostIfIdx, node_uuid=node_uuid) vmac = getattr(spec, 'vmac', None) if vmac: if isinstance(vmac, objects.MacAddressStep): self.MACAddr = vmac.get() elif vmac == 'usepfmac': # used in IOTA for workload interface hostif = InterfaceClient.FindHostInterface( node, self.HostIfIdx) if hostif != None: self.MACAddr = hostif.GetInterfaceMac() else: self.MACAddr = ResmgrClient[node].VnicMacAllocator.get() else: self.MACAddr = vmac else: self.MACAddr = Resmgr.VnicMacAllocator.get() self.VnicEncap = base.Encap.ParseFromSpec( spec, 'vnicencap', 'none', next(ResmgrClient[node].VnicVlanIdAllocator)) self.MplsSlot = next(ResmgrClient[node].VnicMplsSlotIdAllocator) if utils.IsDol(): self.Vnid = next(ResmgrClient[node].VxlanIdAllocator) else: self.Vnid = parent.FabricEncap.GetValue() self.SourceGuard = getattr(spec, 'srcguard', False) self.Primary = getattr(spec, 'primary', False) self.HostName = self.Node self.MaxSessions = getattr(spec, 'maxsessions', 0) self.MeterEn = getattr(spec, 'meteren', False) self.FlowLearnEn = getattr(spec, 'flowlearnen', True) self.SwitchVnic = getattr(spec, 'switchvnic', False) # TODO: clean this host if logic self.UseHostIf = getattr(spec, 'usehostif', True) self.RxMirror = rxmirror self.TxMirror = txmirror self.V4MeterId = MeterClient.GetV4MeterId(node, parent.VPC.VPCId) self.V6MeterId = MeterClient.GetV6MeterId(node, parent.VPC.VPCId) self.IngV4SecurityPolicyIds = [] self.IngV6SecurityPolicyIds = [] self.EgV4SecurityPolicyIds = [] self.EgV6SecurityPolicyIds = [] self.Status = VnicStatus() self.Stats = VnicStats() policerid = getattr(spec, 'rxpolicer', 0) self.RxPolicer = PolicerClient.GetPolicerObject(node, policerid) policerid = getattr(spec, 'txpolicer', 0) self.TxPolicer = PolicerClient.GetPolicerObject(node, policerid) ################# PRIVATE ATTRIBUTES OF VNIC OBJECT ##################### vnicPolicySpec = getattr(spec, 'policy', None) if vnicPolicySpec and utils.IsVnicPolicySupported(): self.IngV4SecurityPolicyIds = utils.GetPolicies( self, vnicPolicySpec, node, "V4", "ingress", False) self.IngV6SecurityPolicyIds = utils.GetPolicies( self, vnicPolicySpec, node, "V6", "ingress", False) self.EgV4SecurityPolicyIds = utils.GetPolicies( self, vnicPolicySpec, node, "V4", "egress", False) self.EgV6SecurityPolicyIds = utils.GetPolicies( self, vnicPolicySpec, node, "V6", "egress", False) self.DeriveOperInfo(node) self.Mutable = True if (utils.IsUpdateSupported() and self.IsOriginFixed()) else False self.VnicType = getattr(spec, 'vnictype', None) self.HasPublicIp = getattr(spec, 'public', False) remote_routes = getattr(spec, 'remoteroutes', []) self.RemoteRoutes = [] for remote_route in remote_routes: self.RemoteRoutes.append(remote_route.replace('\\', '/')) service_ips = getattr(spec, 'serviceips', []) self.ServiceIPs = [] for service_ip in service_ips: self.ServiceIPs.append(service_ip.replace('\\', '/')) self.Movable = getattr(spec, 'movable', False) self.DhcpEnabled = getattr(spec, 'dhcpenabled', False) self.Show() ############### CHILDREN OBJECT GENERATION # Generate MAPPING configuration lmapping.client.GenerateObjects(node, self, spec) return
def PdsctlRead(self, node): if utils.IsDol(): return super().PdsctlRead(node) # TODO: Fix IOTA stdout buffer size for route scale before enabling return True