コード例 #1
0
ファイル: __init__.py プロジェクト: afeset/miner2-tools
class NeighborsContainer(object):
    """This class manages the network neighbor information"""
    def __init__(self, logger):
        self._log = logger.createLoggerSameModule(G_NAME_GROUP_NET_NEIGHBORS)

        self.blinkyNeighbors = None

        self.isApplicationInitiatedDiscoveryWrapperCreated = False
        self.applicationInitiatedDiscovery = ApplicationInitiatedDiscoveryContainer(
            self._log)

    def notifyAttachToBlinky(self, blinkyNeighbors):
        # --- /tech/network/ipv6/neighbors/application-initiated-discovery
        blinkyNeighbors.setCreateApplicationInitiatedDiscoveryFunctor(
            self.createApplicationInitiatedDiscovery)
        blinkyNeighbors.setDeleteApplicationInitiatedDiscoveryFunctor(
            self.deleteApplicationInitiatedDiscovery)
        self.blinkyNeighbors = blinkyNeighbors

    def createApplicationInitiatedDiscovery(
            self, phase, blinkyApplicationInitiatedDiscovery):
        self._log("create-application-initiated-discovery").debug3(
            "%s: blinkyApplicationInitiatedDiscovery=%s", phase,
            blinkyApplicationInitiatedDiscovery)
        if (phase.isPreparePrivate()):
            self.applicationInitiatedDiscovery = SimpleContainerWrapper(
                self._log,
                self.applicationInitiatedDiscovery,
                setOperDataFunctor=True)
            self.isApplicationInitiatedDiscoveryWrapperCreated = True
            self.applicationInitiatedDiscovery.attachToBlinky(
                blinkyApplicationInitiatedDiscovery)
        elif (phase.isCommitPublic()):
            self.applicationInitiatedDiscovery.attachToBlinkyOper()
        elif (phase.isAbortPrivate()):
            if self.isApplicationInitiatedDiscoveryWrapperCreated is True:
                self.applicationInitiatedDiscovery = self.applicationInitiatedDiscovery.realObject
        return ReturnCodes.kOk

    def deleteApplicationInitiatedDiscovery(self, phase):
        self._log("delete-application-initiated-discovery").debug3(
            "phase=%s", phase)
        if (phase.isCommitPrivate()):
            if self.isApplicationInitiatedDiscoveryWrapperCreated is True:
                self.applicationInitiatedDiscovery = self.applicationInitiatedDiscovery.realObject
        return ReturnCodes.kOk
コード例 #2
0
ファイル: __init__.py プロジェクト: afeset/miner2-tools
class NeighborsContainer(object):
    """This class manages the network neighbor information"""

    def __init__ (self, logger):
        self._log = logger.createLoggerSameModule(G_NAME_GROUP_NET_NEIGHBORS)

        self.blinkyNeighbors = None

        self.isApplicationInitiatedDiscoveryWrapperCreated = False
        self.applicationInitiatedDiscovery = ApplicationInitiatedDiscoveryContainer(self._log)

    def notifyAttachToBlinky(self, blinkyNeighbors):
        # --- /tech/network/ipv6/neighbors/application-initiated-discovery
        blinkyNeighbors.setCreateApplicationInitiatedDiscoveryFunctor(self.createApplicationInitiatedDiscovery)
        blinkyNeighbors.setDeleteApplicationInitiatedDiscoveryFunctor(self.deleteApplicationInitiatedDiscovery)
        self.blinkyNeighbors = blinkyNeighbors

    def createApplicationInitiatedDiscovery (self, phase, blinkyApplicationInitiatedDiscovery):
        self._log("create-application-initiated-discovery").debug3("%s: blinkyApplicationInitiatedDiscovery=%s", phase, blinkyApplicationInitiatedDiscovery)
        if (phase.isPreparePrivate()):
            self.applicationInitiatedDiscovery = SimpleContainerWrapper(self._log, self.applicationInitiatedDiscovery, 
                                                                        setOperDataFunctor=True)
            self.isApplicationInitiatedDiscoveryWrapperCreated = True
            self.applicationInitiatedDiscovery.attachToBlinky(blinkyApplicationInitiatedDiscovery)
        elif (phase.isCommitPublic()):
            self.applicationInitiatedDiscovery.attachToBlinkyOper()
        elif (phase.isAbortPrivate()):
            if self.isApplicationInitiatedDiscoveryWrapperCreated is True:
                self.applicationInitiatedDiscovery = self.applicationInitiatedDiscovery.realObject
        return ReturnCodes.kOk

    def deleteApplicationInitiatedDiscovery (self, phase):
        self._log("delete-application-initiated-discovery").debug3("phase=%s", phase)
        if (phase.isCommitPrivate()):
            if self.isApplicationInitiatedDiscoveryWrapperCreated is True:
                self.applicationInitiatedDiscovery = self.applicationInitiatedDiscovery.realObject
        return ReturnCodes.kOk
コード例 #3
0
ファイル: __init__.py プロジェクト: afeset/miner2-tools
class ConnectivityCheck(object):
    """This class represents a connectivity check object"""

    def __init__ (self, logger, interfaceName):
        """Instantiate a new content connectivity check object.

        Args:
            logger

        Raises:
            None
        """

        self._log = logger.createLoggerSameModule(G_NAME_GROUP_NET_INTERFACES_CONNECTIVITY)

        self.interfaceName = interfaceName
        self.ipv4 = None
        self.ipv6 = None

        self.blinkyConnectivityCheck = None

#-----------------------------------------------------------------------------------------------------------------------  
    def __str__(self):
        strList = []
        strList.append("ipv4 connectivity: %s" % self.ipv4)
        strList.append("ipv6 connectivity: %s" % self.ipv6)

        return '\t'.join(strList) 

#-----------------------------------------------------------------------------------------------------------------------
    def notifyAttachToBlinky(self, blinkyConnectivityCheck):

        self._log("notify-attach-blinky").debug2("attach by blinky connectivity check")

        # ipv4
        blinkyConnectivityCheck.setCreateIpv4Functor(self.createIpv4)
        blinkyConnectivityCheck.setDeleteIpv4Functor(self.deleteIpv4)

        # ipv6
        blinkyConnectivityCheck.setCreateIpv6Functor(self.createIpv6)
        blinkyConnectivityCheck.setDeleteIpv6Functor(self.deleteIpv6)

        self.blinkyConnectivityCheck = blinkyConnectivityCheck

#-----------------------------------------------------------------------------------------------------------------------
    def setConfigErrorStr(self, msg):
        if self.blinkyConnectivityCheck:
            self.blinkyConnectivityCheck.setConfigErrorStr(msg)

#-----------------------------------------------------------------------------------------------------------------------
    def createIpv4(self, phase, blinkyIpv4):
        self._log("create-service-ipv4").debug2("phase=%s, blinkyIpv4=%s", phase, blinkyIpv4)

        if (phase.isPreparePrivate()):

            ipv4 = ip_service.Ipv4Connectivity(self._log, self.interfaceName)
            self.ipv4 = SimpleContainerWrapper(self._log, ipv4,
                                               setOperDataFunctor=True)
            self.ipv4.attachToBlinky(blinkyIpv4)

        elif (phase.isCommitPublic()):
            self.ipv4.attachToBlinkyOper()
        elif (phase.isAbortPrivate()):
            self.ipv4 = None

        return ReturnCodes.kOk

#-----------------------------------------------------------------------------------------------------------------------
    def deleteIpv4(self, phase):
        self._log("delete-service-ipv4").debug2("phase=%s", phase)

        if (phase.isCommitPrivate()):
            self.ipv4 = None

        return ReturnCodes.kOk

#-----------------------------------------------------------------------------------------------------------------------
    def createIpv6(self, phase, blinkyIpv6):
        self._log("create-service-ipv6").debug2("phase=%s, blinkyIpv6=%s", phase, blinkyIpv6)

        if (phase.isPreparePrivate()):

            ipv6 = ip_service.Ipv6Connectivity(self._log, self.interfaceName)
            self.ipv6 = SimpleContainerWrapper(self._log, ipv6,
                                               setOperDataFunctor=True)
            self.ipv6.attachToBlinky(blinkyIpv6)

        elif (phase.isCommitPublic()):
            self.ipv6.attachToBlinkyOper()
        elif (phase.isAbortPrivate()):
            self.ipv6 = None

        return ReturnCodes.kOk

#-----------------------------------------------------------------------------------------------------------------------
    def deleteIpv6(self, phase):
        self._log("delete-service-ipv6").debug2("phase=%s", phase)

        if (phase.isCommitPrivate()):
            self.ipv6 = None

        return ReturnCodes.kOk

#-----------------------------------------------------------------------------------------------------------------------
    def actionOnConnectivityCheck(self, osDevice, linkOperStatus, linkAdminStatus, defaultGateway, ipAddress, version=4):
        self._log("action-connectivity-check").debug4("%s: actionOnConnectivityCheck() was called ", self.interfaceName)

        if version == 4 and self.ipv4:
            self.ipv4.testConnectivityCheck(osDevice, linkOperStatus, linkAdminStatus, defaultGateway, ipAddress)
            
        if version == 6 and self.ipv6:
            self.ipv6.testConnectivityCheck(osDevice, linkOperStatus, linkAdminStatus, defaultGateway, ipAddress)  
            
#-----------------------------------------------------------------------------------------------------------------------
    def isConnectivityAvailable(self, version=4):

        isConnectivityAvailable = False

        if version == 4 and self.ipv4:
            isConnectivityAvailable = self.ipv4.isConnectivityAvailable()

        elif version == 6 and self.ipv6:
            isConnectivityAvailable = self.ipv6.isConnectivityAvailable()   

        return isConnectivityAvailable

#-----------------------------------------------------------------------------------------------------------------------
    def getConnectivityReason(self, version=4):

        connectivityReason = None

        if version == 4 and self.ipv4:
            connectivityReason = self.ipv4.getConnectivityReason()

        elif version == 6 and self.ipv6:
            connectivityReason = self.ipv6.getConnectivityReason()   

        return connectivityReason

#-----------------------------------------------------------------------------------------------------------------------
    def setMuteReporting(self, muteReporting):

        if self.ipv4:
            self.ipv4.setMuteReporting(muteReporting)

        if self.ipv6:
            self.ipv6.setMuteReporting(muteReporting)
コード例 #4
0
class DeliveryContainer(object):
    """This class represents a delivery container"""
    def __init__(self, logger, parent):
        """Instantiate a new content interface object.
        """

        self._log = logger
        self.parent = parent

        # data
        self.candidatePreferredDeliveryInterface = ""
        self.runningData = DeliveryData()

        self.ipv4 = None
        self.ipv6 = None

        self.blinkyDelivery = None

#-----------------------------------------------------------------------------------------------------------------------

    def __str__(self):
        return str(self.runningData)

#-----------------------------------------------------------------------------------------------------------------------

    def notifyAttachToBlinky(self, blinkyDelivery):
        self.blinkyDelivery = blinkyDelivery

        # ipv4
        blinkyDelivery.setCreateIpv4Functor(self.createIpv4)
        blinkyDelivery.setDeleteIpv4Functor(self.deleteIpv4)

        # ipv6
        blinkyDelivery.setCreateIpv6Functor(self.createIpv6)
        blinkyDelivery.setDeleteIpv6Functor(self.deleteIpv6)

        self._log("notify-attach-blinky").debug2(
            "%s: attach by blinky delivery", self.parent.name)

#-----------------------------------------------------------------------------------------------------------------------

    def setConfigErrorStr(self, msg):
        if self.blinkyDelivery:
            self.blinkyDelivery.setConfigErrorStr(msg)

#-----------------------------------------------------------------------------------------------------------------------

    def createIpv4(self, phase, blinkyIpv4):
        self._log("create-ipv4").debug2("%s: blinkyIpv4=%s", phase, blinkyIpv4)

        if (phase.isPreparePrivate()):

            ipv4 = DeliveryIpv4Status(self._log, self.parent)
            self.ipv4 = SimpleContainerWrapper(self._log,
                                               ipv4,
                                               setOperDataFunctor=True)
            self.ipv4.attachToBlinky(blinkyIpv4)

        elif (phase.isCommitPublic()):
            self.ipv4.attachToBlinkyOper()
        elif (phase.isAbortPrivate()):
            self.ipv4 = None

        return ReturnCodes.kOk

#-----------------------------------------------------------------------------------------------------------------------

    def deleteIpv4(self, phase):
        self._log("delete-ipv4").debug2("phase=%s", phase)

        if (phase.isCommitPrivate()):
            self.ipv4 = None

        return ReturnCodes.kOk

#-----------------------------------------------------------------------------------------------------------------------

    def createIpv6(self, phase, blinkyIpv6):
        self._log("create-ipv6").debug2("%s: blinkyIpv6=%s", phase, blinkyIpv6)

        if (phase.isPreparePrivate()):

            ipv6 = DeliveryIpv6Status(self._log, self.parent)
            self.ipv6 = SimpleContainerWrapper(self._log,
                                               ipv6,
                                               setOperDataFunctor=True)
            self.ipv6.attachToBlinky(blinkyIpv6)

        elif (phase.isCommitPublic()):
            self.ipv6.attachToBlinkyOper()
        elif (phase.isAbortPrivate()):
            self.ipv6 = None

        return ReturnCodes.kOk

#-----------------------------------------------------------------------------------------------------------------------

    def deleteIpv6(self, phase):
        self._log("delete-ipv6").debug2("phase=%s", phase)

        if (phase.isCommitPrivate()):
            self.ipv6 = None

        return ReturnCodes.kOk

#-----------------------------------------------------------------------------------------------------------------------

    def preparePrivateValueSet(self, data):
        self._log(
            "content-interface-delivery-prepare-private-value-set").debug4(
                "%s: prepare data - %s", self.parent.name, data)

        self.candidatePreferredDeliveryInterface = data.preferredDeliveryInterface

        return ReturnCodes.kOk

#-----------------------------------------------------------------------------------------------------------------------

    def abortPrivateValueSet(self, data):
        self._log("content-interface-delivery-abort-private-value-set").debug4(
            "%s: abort data - %s", self.parent.name, data)

        self.candidatePreferredDeliveryInterface = self.runningData.preferredDeliveryInterface

        return ReturnCodes.kOk

#-----------------------------------------------------------------------------------------------------------------------

    def commitPrivateValueSet(self, data):
        self._log(
            "content-interface-delivery-commit-private-value-set").debug4(
                "%s: commit data - %s", self.parent.name, data)

        # copy data
        self.runningData.copyFrom(data)

        return ReturnCodes.kOk