Пример #1
0
 def __init__(self, node, spec):
     super().__init__(api.ObjectTypes.MIRROR, node)
     self.Id = next(ResmgrClient[node].MirrorSessionIdAllocator)
     self.GID("MirrorSession%d" % self.Id)
     self.UUID = utils.PdsUuid(self.Id, self.ObjType)
     ################# PUBLIC ATTRIBUTES OF MIRROR OBJECT #####################
     self.SnapLen = getattr(spec, 'snaplen', 100)
     self.SpanType = getattr(spec, 'spantype', 'RSPAN')
     if self.SpanType == "RSPAN":
         self.Interface = getattr(spec, 'interface')
         self.UplinkIfUUID = utils.PdsUuid(self.Interface)
         self.VlanId = getattr(spec, 'vlanid', 1)
     elif self.SpanType == "ERSPAN":
         self.ErSpanType = utils.GetErspanProtocolType(getattr(spec, 'erspantype', \
                                                               topo.ErspanProtocolTypes.ERSPAN_TYPE_NONE))
         self.VPCId = getattr(spec, 'vpcid', 1)
         self.ErSpanDstType = getattr(spec, 'erspandsttype', 'tep')
         self.TunnelId = getattr(spec, 'tunnelid')
         if self.ErSpanDstType == 'ip' and (hasattr(spec, 'dstip')):
             self.DstIP = ipaddress.ip_address(getattr(spec, 'dstip'))
         else:
             tunobj = tunnel.client.GetTunnelObject(node, self.TunnelId)
             self.DstIP = ipaddress.ip_address(tunobj.RemoteIP)
         self.SpanID = int(getattr(spec, 'spanid'))
         self.Dscp = getattr(spec, 'dscp', 0)
         self.VlanStripEn = getattr(spec, 'vlanstripen', False)
     else:
         assert (0)
     self.Status = MirrorSessionStatus()
     self.Stats = MirrorSessionStats()
     ################# PRIVATE ATTRIBUTES OF MIRROR OBJECT #####################
     self.DeriveOperInfo()
     self.Show()
     return
Пример #2
0
    def ModifyHostInterface(self, hostifidx=None):
        if not utils.IsNetAgentMode():
            return False

        if utils.IsDryRun():
            return True

        if len(self.HostIfUuid) != 0:
            #dissociate this from subnet first
            InterfaceClient.UpdateHostInterfaces(self.Node, [self], True)

        if hostifidx == None:
            self.HostIfIdx = [InterfaceClient.GetHostInterface(self.Node)]
        else:
            self.HostIfIdx = [hostifidx]
        node_uuid = EzAccessStoreClient[self.Node].GetNodeUuid(self.Node)
        self.HostIfUuid = []
        for ifidx in self.HostIfIdx:
            self.HostIfUuid.append(utils.PdsUuid(ifidx, node_uuid=node_uuid))

        vnicObjs = list(
            filter(lambda x: (x.ObjType == api.ObjectTypes.VNIC),
                   self.Children))
        for vnic in vnicObjs:
            vnic.HostIfIdx = self.HostIfIdx[0]
            vnic.HostIfUuid = utils.PdsUuid(vnic.HostIfIdx,
                                            node_uuid=node_uuid)

        InterfaceClient.UpdateHostInterfaces(self.Node, [self])
        return True
Пример #3
0
 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
Пример #4
0
    def __init__(self, node, spec):
        super().__init__(api.ObjectTypes.SECURITY_PROFILE, node)
        if hasattr(spec, 'origin'):
            self.SetOrigin(spec.origin)
        ############### PUBLIC ATTRIBUTES OF SECURITY PROFILE OBJECT ###############
        if (hasattr(spec, 'id')):
            self.SecurityProfileId = spec.id
        else:
            self.SecurityProfileId = 1
        self.GID('SecurityProfile%d'%self.SecurityProfileId)
        self.UUID = utils.PdsUuid(self.SecurityProfileId, self.ObjType)
        self.ConnTrackEn = getattr(spec, 'conntrack', False)
        deffwaction = getattr(spec, 'deffwaction', 'allow')
        self.DefaultFWAction = utils.GetRpcSecurityRuleAction(deffwaction)
        self.TCPIdleTimeout = getattr(spec, 'tcpidletimeout', 600)
        self.UDPIdleTimeout = getattr(spec, 'udpidletimeout', 120)
        self.ICMPIdleTimeout = getattr(spec, 'icmpidletimeout', 15)
        self.OtherIdleTimeout = getattr(spec, 'otheridletimeout', 90)
        self.TCPCnxnSetupTimeout = getattr(spec, 'tcpsyntimeout', 10)
        self.TCPHalfCloseTimeout = getattr(spec, 'tcphalfclosetimeout', 120)
        self.TCPCloseTimeout = getattr(spec, 'tcpclosetimeout', 15)
        self.TCPDropTimeout = getattr(spec, 'tcpdroptimeout', 90)
        self.UDPDropTimeout = getattr(spec, 'udpdroptimeout', 60)
        self.ICMPDropTimeout = getattr(spec, 'icmpdroptimeout', 30)
        self.OtherDropTimeout = getattr(spec, 'otherdroptimeout', 60)

       ############### PRIVATE ATTRIBUTES OF SECURITY_PROFILE OBJECT ###############
        self.__spec = spec
        self.DeriveOperInfo()
        self.Mutable = utils.IsUpdateSupported()
        self.Show()
        return
Пример #5
0
 def __init__(self, node, parent, spec):
     super().__init__(api.ObjectTypes.NEXTHOPGROUP, node)
     if hasattr(spec, 'origin'):
         self.SetOrigin(spec.origin)
     elif (EzAccessStoreClient[node].IsDeviceOverlayRoutingEnabled()):
         self.SetOrigin('discovered')
     ################# PUBLIC ATTRIBUTES OF NEXTHOPGROUP OBJECT ############
     if (hasattr(spec, 'id')):
         self.Id = spec.id
     else:
         self.Id = next(ResmgrClient[node].NexthopGroupIdAllocator)
     self.GID('NexthopGroup%d' % self.Id)
     self.UUID = utils.PdsUuid(self.Id, self.ObjType)
     self.Nexthops = {}
     self.DualEcmp = utils.IsDualEcmp(spec)
     self.Type = nh_pb2.NEXTHOP_GROUP_TYPE_NONE
     if spec.type == 'overlay':
         self.Type = nh_pb2.NEXTHOP_GROUP_TYPE_OVERLAY_ECMP
         self.NumNexthops = ResmgrClient[
             node].OverlayNumNexthopsAllocator.rrnext()
     elif spec.type == 'underlay':
         self.Type = nh_pb2.NEXTHOP_GROUP_TYPE_UNDERLAY_ECMP
         self.NumNexthops = ResmgrClient[
             node].UnderlayNumNexthopsAllocator.rrnext()
     self.Mutable = utils.IsUpdateSupported()
     self.Status = NexthopGroupStatus()
     self.DeriveOperInfo()
     self.Show()
     return
Пример #6
0
    def ValidateLearntMacEntries(self, node, ret, cli_op):
        if utils.IsDryRun(): return True
        if not ret:
            logger.error("pdsctl show learn mac cmd failed")
            return False
        # split output per object
        mac_entries = cli_op.split("---")
        for mac in mac_entries:
            yamlOp = utils.LoadYaml(mac)
            if not yamlOp:
                continue
            yamlOp = yamlOp['macentry']['entryauto']
            mac_key = yamlOp['key']['macaddr']
            subnet_uuid = utils.GetYamlSpecAttr(yamlOp['key'], 'subnetid')
            vnic_uuid_str = utils.List2UuidStr(
                utils.GetYamlSpecAttr(yamlOp, 'vnicid'))

            # verifying if the info learnt is expected from config
            vnic_obj = self.GetVnicByL2MappingKey(node, mac_key, subnet_uuid,
                                                  0)
            if vnic_obj == None:
                logger.error(
                    f"vnic not found in client object store for key {mac_key} {subnet_uuid}{0}"
                )
                return False

            # verifying if VNIC has been programmed correctly by Learn
            args = "--id " + vnic_uuid_str
            ret, op = utils.RunPdsctlShowCmd(node, "vnic", args, True)
            if not ret:
                logger.error(f"show vnic failed for vnic id {vnic_uuid_str}")
                return False
            cmdop = op.split("---")
            logger.info("Num entries returned for vnic show id %s is %s" %
                        (vnic_uuid_str, (len(cmdop) - 1)))
            for vnic_entry in cmdop:
                yamlOp = utils.LoadYaml(vnic_entry)
                if not yamlOp:
                    continue
                vnic_spec = yamlOp['spec']
                hostif = vnic_spec['hostif']
                if utils.PdsUuid(
                        hostif).GetUuid() != vnic_obj.HostIfUuid.GetUuid():
                    logger.error(
                        f"host interface did not match for {vnic_uuid_str}")
                    return False
                if vnic_spec['macaddress'] != vnic_obj.MACAddr.getnum():
                    logger.error(
                        f"mac address did not match for {vnic_uuid_str}")
                    return False

                logger.info(
                    "Found VNIC %s entry for learn MAC MAC:%s, Subnet:%s, VNIC:%s "
                    %
                    (utils.List2UuidStr(utils.GetYamlSpecAttr(
                        vnic_spec, 'id')), vnic_obj.MACAddr.get(),
                     vnic_obj.SUBNET.UUID, vnic_uuid_str))
        return True
Пример #7
0
 def Dup(self):
     dupObj = copy.copy(self)
     dupObj.NexthopId = next(ResmgrClient[
         self.Node].NexthopIdAllocator) + Resmgr.BaseDuplicateIdAllocator
     dupObj.GID('DupNexthop%d' % dupObj.NexthopId)
     dupObj.UUID = utils.PdsUuid(dupObj.NexthopId, dupObj.ObjType)
     dupObj.Interim = True
     self.Duplicate = dupObj
     return dupObj
Пример #8
0
    def ChangeSubnet(self, vnic, new_subnet):
        logger.info(
            f"Changing subnet for {vnic} {vnic.SUBNET} => {new_subnet}")
        # Handle child/parent relationship
        old_subnet = vnic.SUBNET
        old_subnet.DeleteChild(vnic)
        new_subnet.AddChild(vnic)
        vnic.SUBNET = new_subnet
        vnic.Vnid = vnic.SUBNET.Vnid

        if not utils.IsDryRun():
            node_uuid = EzAccessStoreClient[new_subnet.Node].GetNodeUuid(
                new_subnet.Node)
            vnic.HostIfIdx = vnic.SUBNET.HostIfIdx[0]
            vnic.HostIfUuid = utils.PdsUuid(vnic.HostIfIdx,
                                            node_uuid=node_uuid)

        # Handle node change scenario
        if old_subnet.Node != new_subnet.Node:
            # Delete VNIC from old node
            del self.Objs[vnic.Node][vnic.VnicId]
            del self.__l2mapping_objs[vnic.Node][(vnic.MACAddr.getnum(),
                                                  vnic.SUBNET.UUID.GetUuid(),
                                                  vnic.VlanId())]
            vnic.Node = new_subnet.Node
            self.Objs[vnic.Node].update({vnic.VnicId: vnic})
            self.__l2mapping_objs[vnic.Node].update({
                (vnic.MACAddr.getnum(), vnic.SUBNET.UUID.GetUuid(),
                 vnic.VlanId()):
                vnic
            })

            # Move children to new Node
            for lmap in vnic.Children:
                # Operate only on lmapping objects
                if lmap.GetObjectType() != api.ObjectTypes.LMAPPING:
                    continue

                # Move lmap entry to new Node
                lmapping.client.ChangeNode(lmap, new_subnet.Node)

                # Destroy rmap entry in new subnet
                rmap = new_subnet.GetRemoteMappingObjectByIp(lmap.IP)
                assert (rmap)
                rmap.Destroy()

                # Add rmap entry in old subnet
                mac = "macaddr/%s" % vnic.MACAddr.get()
                rmap_spec = {}
                rmap_spec['rmacaddr'] = objects.TemplateFieldObject(mac)
                rmap_spec['ripaddr'] = lmap.IP
                ipversion = utils.IP_VERSION_6 if lmap.AddrFamily == 'IPV6' else utils.IP_VERSION_4
                rmapClient.GenerateObj(old_subnet.Node, old_subnet, rmap_spec,
                                       ipversion)
        return
Пример #9
0
 def __init__(self, node, parent, spec):
     super().__init__(api.ObjectTypes.NEXTHOP, node)
     if hasattr(spec, 'origin'):
         self.SetOrigin(spec.origin)
     elif (EzAccessStoreClient[node].IsDeviceOverlayRoutingEnabled()):
         self.SetOrigin('discovered')
     ################# PUBLIC ATTRIBUTES OF NEXTHOP OBJECT #####################
     if (hasattr(spec, 'id')):
         self.NexthopId = spec.id
     else:
         self.NexthopId = next(ResmgrClient[node].NexthopIdAllocator)
     self.GID('Nexthop%d' % self.NexthopId)
     self.UUID = utils.PdsUuid(self.NexthopId, self.ObjType)
     self.VPC = parent
     nh_type = getattr(spec, 'type', 'ip')
     self.DualEcmp = utils.IsDualEcmp(spec)
     if nh_type == 'ip':
         self.__type = topo.NhType.IP
         self.PfxSel = parent.PfxSel
         self.IPAddr = {}
         self.IPAddr[0] = next(
             ResmgrClient[node].NexthopIpV4AddressAllocator)
         self.IPAddr[1] = next(
             ResmgrClient[node].NexthopIpV6AddressAllocator)
         self.VlanId = next(ResmgrClient[node].NexthopVlanIdAllocator)
         if (hasattr(spec, 'macaddress')):
             self.MACAddr = spec.macaddress
         else:
             self.MACAddr = ResmgrClient[node].NexthopMacAllocator.get()
     elif nh_type == 'underlay':
         self.__type = topo.NhType.UNDERLAY
         self.L3Interface = InterfaceClient.GetL3UplinkInterface(node)
         self.L3InterfaceId = self.L3Interface.InterfaceId
         if (hasattr(spec, 'macaddress')):
             self.underlayMACAddr = spec.macaddress
         else:
             self.underlayMACAddr = ResmgrClient[
                 node].NexthopMacAllocator.get()
     elif nh_type == 'overlay':
         self.__type = topo.NhType.OVERLAY
         if self.DualEcmp:
             self.TunnelId = ResmgrClient[
                 node].UnderlayECMPTunAllocator.rrnext().Id
         elif (hasattr(spec, 'tunnelid')):
             self.TunnelId = spec.tunnelid
         else:
             self.TunnelId = ResmgrClient[node].UnderlayTunAllocator.rrnext(
             ).Id
     else:
         self.__type = topo.NhType.NONE
     self.Mutable = utils.IsUpdateSupported()
     self.Status = NexthopStatus()
     self.DeriveOperInfo()
     self.Show()
     return
Пример #10
0
 def __init__(self, node, port, mode, state='UP'):
     ################# PUBLIC ATTRIBUTES OF PORT OBJECT #####################
     self.Node = node
     self.PortId = next(ResmgrClient[node].PortIdAllocator)
     self.GID("Port ID:%s" % self.PortId)
     self.Port = port
     self.EthIfIndex = topo.PortToEthIfIdx(self.PortId)
     self.UUID = utils.PdsUuid(self.EthIfIndex)
     self.Mode = mode
     self.AdminState = state
     ################# PRIVATE ATTRIBUTES OF PORT OBJECT #####################
     self.Show()
     return
Пример #11
0
 def GetGrpcSvcMappingCreateMessage(self, cookie):
     grpcmsg = service_pb2.SvcMappingRequest()
     grpcmsg.BatchCtxt.BatchCookie = cookie
     spec = grpcmsg.Request.add()
     svc_uuid = utils.PdsUuid(self.MappingId, api.ObjectTypes.SVCMAPPING)
     spec.Id = svc_uuid.GetUuid()
     spec.Key.VPCId = self.VNIC.SUBNET.VPC.GetKey()
     utils.GetRpcIPAddr(self.IPAddr, spec.Key.BackendIP)
     spec.Key.BackendPort = self.LBPort
     utils.GetRpcIPAddr(self.SvcIPAddr, spec.IPAddr)
     spec.SvcPort = self.SvcPort
     utils.GetRpcIPAddr(self.ProviderIPAddr, spec.ProviderIP)
     return grpcmsg
Пример #12
0
 def __init__(self, node, vpc, dhcprelaySpec):
     super().__init__(api.ObjectTypes.DHCP_RELAY, node)
     self.ServerIps = []
     self.AgentIps = []
     self.Id = next(ResmgrClient[node].DhcpIdAllocator)
     self.GID("Dhcp%d" % self.Id)
     self.UUID = utils.PdsUuid(self.Id, self.ObjType)
     ########## PUBLIC ATTRIBUTES OF DHCPRELAY CONFIG OBJECT ##############
     self.Vpc = vpc
     for dhcpobj in dhcprelaySpec:
         self.ServerIps.append(ipaddress.ip_address(dhcpobj.serverip))
         self.AgentIps.append(ipaddress.ip_address(dhcpobj.agentip))
     ########## PRIVATE ATTRIBUTES OF DHCPRELAY CONFIG OBJECT #############
     self.Show()
     return
Пример #13
0
 def __init__(self, node, parent, af, routes, routetype, tunobj, vpcpeerid,
              spec):
     super().__init__(api.ObjectTypes.ROUTE, node)
     self.Class = RouteTableObject
     if hasattr(spec, 'origin'):
         self.SetOrigin(spec.origin)
     elif (EzAccessStoreClient[node].IsDeviceOverlayRoutingEnabled()):
         self.SetOrigin('discovered')
     ################# PUBLIC ATTRIBUTES OF ROUTE TABLE OBJECT #####################
     if af == utils.IP_VERSION_6:
         self.RouteTblId = next(ResmgrClient[node].V6RouteTableIdAllocator)
         self.AddrFamily = 'IPV6'
         self.NEXTHOP = NexthopClient.GetV6Nexthop(node, parent.VPCId)
     else:
         self.RouteTblId = next(ResmgrClient[node].V4RouteTableIdAllocator)
         self.AddrFamily = 'IPV4'
         self.NEXTHOP = NexthopClient.GetV4Nexthop(node, parent.VPCId)
     self.GID('RouteTable%d' % self.RouteTblId)
     if af == utils.IP_VERSION_4:
         parent.V4RouteTableName = self.GID()
     self.UUID = utils.PdsUuid(self.RouteTblId, self.ObjType)
     self.routes = routes
     self.MeterEn = False
     for r in routes.values():
         if r.MeterEn:
             self.MeterEn = True
             break
     self.TUNNEL = tunobj
     self.NhGroup = None
     self.DualEcmp = utils.IsDualEcmp(spec)
     self.PriorityType = getattr(spec, "priority", None)
     if self.TUNNEL:
         self.TunnelId = self.TUNNEL.Id
         self.TunEncap = tunobj.Encap
     else:
         self.TunnelId = 0
     self.NexthopId = self.NEXTHOP.NexthopId if self.NEXTHOP else 0
     self.VPCId = parent.VPCId
     self.VPC = parent
     self.Label = 'NETWORKING'
     self.RouteType = routetype  # used for lpm route cases
     self.PeerVPCId = vpcpeerid
     self.AppPort = ResmgrClient[node].TransportDstPort
     self.Mutable = utils.IsUpdateSupported()
     ##########################################################################
     self.DeriveOperInfo(spec)
     self.Show()
     return
Пример #14
0
 def __init__(self, node, parent, af, rules):
     super().__init__(api.ObjectTypes.METER, node)
     ################# PUBLIC ATTRIBUTES OF METER OBJECT #####################
     self.VPCId = parent.VPCId
     if af == utils.IP_VERSION_6:
         self.MeterId = next(ResmgrClient[node].V6MeterIdAllocator)
         self.AddrFamily = 'IPV6'
     else:
         self.MeterId = next(ResmgrClient[node].V4MeterIdAllocator)
         self.AddrFamily = 'IPV4'
     self.GID('Meter%d'%self.MeterId)
     self.UUID = utils.PdsUuid(self.MeterId, self.ObjType)
     self.Rules = rules
     self.DeriveOperInfo()
     self.Show()
     return
Пример #15
0
    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
Пример #16
0
 def __init__(self, node, af, rules):
     super().__init__(api.ObjectTypes.TAG, node)
     ################# PUBLIC ATTRIBUTES OF TAG TABLE OBJECT #####################
     if af == utils.IP_VERSION_6:
         self.TagTblId = next(ResmgrClient[node].V6TagIdAllocator)
         self.AddrFamily = 'IPV6'
         self.GID('IPv6TagTbl%d' % self.TagTblId)
     else:
         self.TagTblId = next(ResmgrClient[node].V4TagIdAllocator)
         self.AddrFamily = 'IPV4'
         self.GID('IPv4TagTbl%d' % self.TagTblId)
     self.UUID = utils.PdsUuid(self.TagTblId, self.ObjType)
     self.Rules = rules
     ##########################################################################
     self.DeriveOperInfo()
     self.Show()
     return
Пример #17
0
 def __init__(self, node, device, parent, spec):
     super().__init__(api.ObjectTypes.IPSEC_DECRYPT_SA, node)
     if (hasattr(spec, 'id')):
         self.Id = spec.id
     else:
         self.Id = next(ResmgrClient[node].IpsecDecryptSAIdAllocator)
     self.GID('IpsecDecryptSA%d'%self.Id)
     self.UUID = utils.PdsUuid(self.Id, self.ObjType)
     self.VPC = parent
     self.DEVICE = device
     self.Protocol = ipsec_pb2.IPSEC_PROTOCOL_ESP
     self.AuthAlgo = ipsec_pb2.AUTHENTICATION_ALGORITHM_AES_GCM
     self.AuthKey = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
     self.EncAlgo = ipsec_pb2.ENCRYPTION_ALGORITHM_AES_GCM_256
     self.EncKey = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
     self.Spi = self.Id
     self.Salt = 0xbbbbbbbb
Пример #18
0
    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
Пример #19
0
 def __init__(self, node, spec):
     super().__init__(api.ObjectTypes.BGP, node)
     self.BatchUnaware = True
     self.Id = next(ResmgrClient[node].BgpIdAllocator)
     self.GID("BGP%d" % self.Id)
     self.UUID = utils.PdsUuid(self.Id, api.ObjectTypes.BGP)
     self.Mutable = utils.IsUpdateSupported()
     self.LocalASN = getattr(spec, "localasn", 0)
     # If loopback ip exists in testbed json, use that,
     # else use from cfgyaml
     self.RouterId = utils.GetNodeLoopbackIp(node)
     if not self.RouterId:
         self.RouterId = ipaddress.ip_address(getattr(spec, "routerid", 0))
     self.RouterId = int(self.RouterId)
     self.ClusterId = getattr(spec, "clusterid", 0)
     self.KeepAliveInterval = topo.KEEPALIVE_INTERVAL
     self.HoldTime = topo.HOLD_TIME
     self.Show()
     return
Пример #20
0
 def __init__(self, node, spec):
     super().__init__(api.ObjectTypes.POLICER, node)
     if hasattr(spec, 'origin'):
         self.SetOrigin(spec.origin)
     ############### PUBLIC ATTRIBUTES OF POLICER OBJECT ###################
     if hasattr(spec, 'id'):
         self.PolicerId = spec.id
     else:
         self.PolicerId = next(ResmgrClient[node].PolicerIdAllocator)
     self.type = spec.type
     self.direction = spec.direction
     self.rate = spec.rate
     self.burst = spec.burst
     self.token_refresh_rate = 4000
     self.GID('Policer%d'%self.PolicerId)
     self.UUID = utils.PdsUuid(self.PolicerId, api.ObjectTypes.POLICER)
     self.DeriveOperInfo()
     self.Show()
     return
Пример #21
0
    def __init__(self, node, spec, type):
        super().__init__(api.ObjectTypes.INTERFACE, node)
        super().SetOrigin(getattr(spec, 'origin', None))

        if hasattr(spec, 'iid'):
            self.InterfaceId = spec.iid
        else:
            self.InterfaceId = next(ResmgrClient[node].InterfaceIdAllocator)

        self.Type = type
        if hasattr(spec, 'uuid'):
            self.UUID = spec.uuid
        else:
            self.UUID = utils.PdsUuid(self.InterfaceId, self.ObjType)
        self.IfName = getattr(spec, 'ifname', None)
        self.AdminState = getattr(spec, 'ifadminstatus', None)
        self.MacAddr = getattr(spec, 'macaddress', None)
        self.VPCId = getattr(spec, 'vpcid', None)
        self.VrfName = None
        self.TxPolicer = None
        if hasattr(spec, 'vrfname'):
            self.VrfName = spec.vrfname
        elif self.VPCId:
            self.VrfName = f'Vpc{self.VPCId}'

        # Following attributes are valid only for netagent mode
        self.Speed = ''
        self.MTU = topo.MTU
        self.PauseSpec = InterfaceSpec_()
        self.PauseSpec.Type = 'DISABLE'
        self.PauseSpec.TxPauseEnabled = False
        self.PauseSpec.RxPauseEnabled = False

        self.Status = InterfaceStatus()
        self.Mutable = utils.IsUpdateSupported()
        if self.IfName:
            self.GID(f'{self.IfName}')
        else:
            self.GID(
                f'{topo.INTFTYPE2STR.get(type)}Interface{self.InterfaceId:08x}'
            )
        return
Пример #22
0
 def __init__(self,
              node,
              parent,
              prefix,
              port_lo,
              port_hi,
              proto,
              addr_type,
              threshold=0):
     super().__init__(api.ObjectTypes.NAT, node)
     self.Id = next(ResmgrClient[node].NatPoolIdAllocator)
     self.GID('NatPortBlock%d' % self.Id)
     self.UUID = utils.PdsUuid(self.Id, self.ObjType)
     self.VPC = parent
     self.Prefix = prefix
     self.PortLo = port_lo
     self.PortHi = port_hi
     self.ProtoName = proto
     self.ProtoNum = utils.GetIPProtoByName(proto)
     self.AddrType = addr_type
     self.Threshold = threshold
Пример #23
0
 def UpdateImplicit(self):
     if 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)
     for vpcinst in resp:
         if (not (vpcinst['spec']['vrf-type'] == 'INFRA')):
             continue
         uuid_str = vpcinst['meta']['uuid']
         self.UUID = utils.PdsUuid(bytes.fromhex(uuid_str.replace('-','')),\
                 self.ObjType)
         ms = getattr(vpcinst['spec'], 'router-mac', '00:00:00:00:00:00')
         self.VirtualRouterMACAddr = objects.MacAddressBase(string=ms)
         self.FabricEncap.SetVnid(
             int(getattr(vpcinst['spec'], 'vxlan-vni',
                         '0')))  #assuming vxlan
         self.Tenant = vpcinst['meta']['tenant']
         self.Namespace = vpcinst['meta']['namespace']
         self.GID(vpcinst['meta']['name'])
     return
Пример #24
0
    def __generate_host_interfaces_iota(self, node, topospec):
        cmd_op = self.ReadLifs(node)

        if utils.IsDryRun():
            return
        for lif in cmd_op:
            lif_yaml = utils.LoadYaml(lif)
            if not lif_yaml:
                continue
            lif_spec = lif_yaml['spec']
            lif_status = lif_yaml['status']
            intf_type = lif_spec['type']
            spec = InterfaceSpec_()
            spec.iid = utils.LifIfIndex2HostIfIndex(lif_status['ifindex'])
            node_mac = 0
            for x in lif_spec['id'][-6:]:
                node_mac = ((node_mac << 8) | x)
            spec.uuid = utils.PdsUuid(spec.iid, node_uuid=node_mac)
            spec.ifname = lif_status['name']
            spec.macaddress = objects.MacAddressBase(
                integer=lif_spec['macaddress'])
            spec.origin = 'implicitly-created'
            spec.txpolicer = False
            if hasattr(topospec, 'hostinterface'):
                if getattr(topospec.hostinterface, 'txpolicer', False) == True:
                    spec.txpolicer = True

            if intf_type == types_pb2.LIF_TYPE_INBAND_MGMT:
                inb_mgmtif = InbandMgmtInterfaceObject(node, spec)
                self.__inband_mgmt_ifs[node].update(
                    {inb_mgmtif.GetInterfaceName(): inb_mgmtif})
            elif intf_type == types_pb2.LIF_TYPE_HOST:
                hostif = HostInterfaceObject(node, spec)
                self.__hostifs[node].update({hostif.InterfaceId: hostif})
        if self.__hostifs[node]:
            self.__hostifs_iter[node] = utils.rrobiniter(
                sorted(self.__hostifs[node].keys()))
        return
Пример #25
0
    def __init__(self, node, spec, peeraf_obj):
        super().__init__(api.ObjectTypes.BGP_PEER, node)
        self.BatchUnaware = True
        self.Id = next(ResmgrClient[node].BgpPeerIdAllocator)
        self.UUID = utils.PdsUuid(self.Id, api.ObjectTypes.BGP_PEER)
        self.GID("BGPPeer%d" % self.Id)
        self.State = getattr(spec, "adminstate", 0)
        self.PeerAddr = None
        self.LocalAddr = None
        self.RemoteASN = None
        if hasattr(spec, 'interface'):
            # override IPs and RemoteASN from testbed json
            self.LocalAddr = utils.GetNodeUnderlayIp(node, spec.interface)
            self.PeerAddr = utils.GetNodeUnderlayNexthop(node, spec.interface)
            self.RemoteASN = utils.GetNodeUnderlayBGPRemoteASN(
                node, spec.interface)
        if self.LocalAddr == None:
            self.LocalAddr = ipaddress.ip_address(
                getattr(spec, "localaddr", None))

        if self.PeerAddr == None:
            self.PeerAddr = ipaddress.ip_address(
                getattr(spec, "peeraddr", None))

        if self.RemoteASN == None:
            self.RemoteASN = getattr(spec, "remoteasn", 0)
        self.SendComm = getattr(spec, "sendcomm", False)
        self.SendExtComm = getattr(spec, "sendextcomm", False)
        self.RRClient = getattr(spec, "rrclient", None)
        self.ConnectRetry = getattr(spec, "connectretry", 0)
        self.HoldTime = getattr(spec, "holdtime", 0)
        self.KeepAlive = getattr(spec, "keepalive", 0)
        self.Password = ""
        self.Password = bytes(getattr(spec, "password", ""), 'utf-8')
        self.PeerAf = peeraf_obj
        self.Show()
        return
Пример #26
0
 def __init__(self, node, ipaddr, priority=0, nh_type="", nhid=0, nhgid=0, vpcid=0, \
         tunnelid=0, nat_type=None, service_nat_prefix=None, dnat_ip=None, \
         classpriority=0, meteren=False):
     super().__init__()
     self.Id = next(ResmgrClient[node].RouteIdAllocator)
     self.UUID = utils.PdsUuid(self.Id, api.ObjectTypes.ROUTE)
     self.ipaddr = ipaddr
     self.Priority = priority
     self.MeterEn = meteren
     self.ClassPriority = classpriority
     self.NextHopType = nh_type
     if self.NextHopType == "vpcpeer":
         self.PeerVPCId = vpcid
     elif self.NextHopType == "tep":
         self.TunnelId = tunnelid
     elif self.NextHopType == "nh":
         self.NexthopId = nhid
     elif self.NextHopType == "nhg":
         self.NexthopGroupId = nhgid
     if nat_type == "static":
         self.SNatAction = topo.NatActionTypes.STATIC
     elif nat_type == "napt":
         self.SNatAction = topo.NatActionTypes.NAPT
     elif nat_type == "service":
         self.SNatAction = topo.NatActionTypes.NAPT_SERVICE
     else:
         self.SNatAction = topo.NatActionTypes.NONE
     self.ServiceNatPrefix = None
     self.DstNatIp = None
     if service_nat_prefix:
         svc_nat_prefix = ipaddress.ip_network(
             service_nat_prefix.replace('\\', '/'))
         if svc_nat_prefix.overlaps(ipaddr):
             self.DstNatIp = dnat_ip
             self.ServiceNatPrefix = svc_nat_prefix
             self.SNatAction = topo.NatActionTypes.NAPT_SERVICE
Пример #27
0
    def __init__(self, node, spec, peerspec):
        super().__init__(api.ObjectTypes.BGP_PEER_AF, node)
        self.BatchUnaware = True
        self.Id = next(ResmgrClient[node].BgpPeerAfIdAllocator)
        self.UUID = utils.PdsUuid(self.Id, api.ObjectTypes.BGP_PEER_AF)
        self.GID("BGPPeerAf%d"%self.Id)
        self.PeerAddr = None
        self.LocalAddr = None
        if hasattr(peerspec, 'interface'):
            # override IPs from testbed json
            self.LocalAddr = utils.GetNodeUnderlayIp(node, peerspec.interface)
            self.PeerAddr = utils.GetNodeUnderlayNexthop(node, peerspec.interface)
        if self.LocalAddr == None:
            self.LocalAddr = ipaddress.ip_address(getattr(spec, "localaddr", "0.0.0.0"))

        if self.PeerAddr == None:
            self.PeerAddr = ipaddress.ip_address(getattr(spec, "peeraddr", "0.0.0.0"))
        self.Afi = getattr(spec, "afi", "ipv4")
        self.Safi = getattr(spec, "safi", "unicast")
        self.AfiStr = f"{self.Afi}-{self.Safi}"
        self.NexthopSelf = getattr(spec, "nexthopself", False)
        self.DefaultOrig = getattr(spec, "defaultorig", False)
        self.Show()
        return
Пример #28
0
 def __init__(self, node, dhcpspec):
     super().__init__(api.ObjectTypes.DHCP_PROXY, node)
     if (hasattr(dhcpspec, 'id')):
         self.Id = dhcpspec.id
     else:
         self.Id = next(ResmgrClient[node].DhcpIdAllocator)
     self.GID("Dhcp%d" % self.Id)
     self.UUID = utils.PdsUuid(self.Id, self.ObjType)
     self.ntpserver = [
         ipaddress.IPv4Address(ntpserver)
         for ntpserver in dhcpspec.ntpserver
     ]
     self.serverip = ipaddress.IPv4Address(dhcpspec.serverip)
     self.routers = ipaddress.IPv4Address(dhcpspec.routers)
     self.dnsserver = [
         ipaddress.IPv4Address(dnsserver)
         for dnsserver in dhcpspec.dnsserver
     ]
     self.domainname = getattr(dhcpspec, 'domainname', None)
     self.filename = getattr(dhcpspec, 'filename', None)
     self.leasetimeout = getattr(dhcpspec, 'leasetimeout', 3600)
     self.interfacemtu = dhcpspec.interfacemtu
     self.Mutable = utils.IsUpdateSupported()
     return
Пример #29
0
    def __init__(self, node, parent, spec, tunobj, ipversion, count, l2=False):
        super().__init__(api.ObjectTypes.RMAPPING, node)
        parent.AddChild(self)
        if 'origin' in spec:
            self.SetOrigin(spec['origin'])
        elif (EzAccessStoreClient[node].IsDeviceOverlayRoutingEnabled()):
            self.SetOrigin('discovered')
        ################# PUBLIC ATTRIBUTES OF REMOTE MAPPING OBJECT ##########
        if 'id' in spec:
            self.MappingId = spec['id']
        else:
            self.MappingId = next(ResmgrClient[node].RemoteMappingIdAllocator)
        self.GID('RemoteMapping%d' % self.MappingId)
        self.UUID = utils.PdsUuid(self.MappingId, self.ObjType)
        self.SUBNET = parent
        if l2:
            self.TypeL2 = True
        else:
            self.TypeL2 = False
        if 'rmacaddr' in spec:
            self.MACAddr = spec['rmacaddr']
        else:
            self.MACAddr = ResmgrClient[node].RemoteMappingMacAllocator.get()
        self.TunID = tunobj.Id
        self.HasDefaultRoute = False
        if tunobj.IsWorkload():
            self.MplsSlot = next(tunobj.RemoteVnicMplsSlotIdAllocator)
            self.Vnid = next(tunobj.RemoteVnicVxlanIdAllocator)
        else:
            self.MplsSlot = 0
            self.Vnid = 0
        self.TUNNEL = tunobj
        if ipversion == utils.IP_VERSION_6:
            self.IPAddr = parent.AllocIPv6Address()
            self.AddrFamily = 'IPV6'
            if self.SUBNET.V6RouteTable:
                self.HasDefaultRoute = self.SUBNET.V6RouteTable.HasDefaultRoute
        else:
            if 'ripaddr' in spec:
                self.IPAddr = ipaddress.IPv4Address(spec['ripaddr'])
            else:
                self.IPAddr = parent.AllocIPv4Address()
            self.AddrFamily = 'IPV4'
            if self.SUBNET.V4RouteTable:
                self.HasDefaultRoute = self.SUBNET.V4RouteTable.HasDefaultRoute

        # Handle tags generation
        if spec.get("tag", False):
            tag_type = spec.get("tag_type", "overlapping")
            no_of_tags = spec.get("no_of_tags", 5)
            tags = spec.get("tags", [])
            self.GenerateTags(tag_type, no_of_tags, tags)

        # Provider IP can be v4 or v6
        self.ProviderIPAddr, self.TunFamily = EzAccessStoreClient[
            node].GetProviderIPAddr(count)
        self.ProviderIP = str(self.ProviderIPAddr)  # For testspec
        self.Label = 'NETWORKING'
        self.FlType = "MAPPING"
        self.IP = str(self.IPAddr)  # For testspec
        self.AppPort = ResmgrClient[node].TransportDstPort

        ################# PRIVATE ATTRIBUTES OF MAPPING OBJECT #####################
        self.DeriveOperInfo()
        self.Show()
        return
Пример #30
0
    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