Пример #1
0
def test_sourceRoute(expectedSourceRoute):
    '''
    This tests the following topology
    
    MOTE_A <- MOTE_B <- MOTE_C <- MOTE_D
    '''

    sourceRoute = SourceRoute.SourceRoute()
    topo = topology.topology()

    sourceRoute.dispatch(
        signal='updateParents',
        data=(tuple(MOTE_B), [MOTE_A]),
    )
    sourceRoute.dispatch(
        signal='updateParents',
        data=(tuple(MOTE_C), [MOTE_B]),
    )
    sourceRoute.dispatch(
        signal='updateParents',
        data=(tuple(MOTE_D), [MOTE_C]),
    )

    expectedDestination = json.loads(expectedSourceRoute)[0]
    expectedRoute = json.loads(expectedSourceRoute)[1]
    calculatedRoute = sourceRoute.getSourceRoute(expectedDestination)

    # log
    if log.isEnabledFor(logging.DEBUG):
        output = []
        output += ['\n']
        output += [
            'expectedDestination: {0}'.format(
                u.formatAddr(expectedDestination))
        ]
        output += ['expectedRoute:']
        for m in expectedRoute:
            output += ['- {0}'.format(u.formatAddr(m))]
        output += ['calculatedRoute:']
        for m in calculatedRoute:
            output += ['- {0}'.format(u.formatAddr(m))]
        output = '\n'.join(output)
        log.debug(output)

    assert calculatedRoute == expectedRoute
Пример #2
0
    def __init__(self):

        # log
        log.info("create instance")

        # store params

        # initialize parent class
        eventBusClient.eventBusClient.__init__(
            self,
            name='RPL',
            registrations=[
                {
                    'sender': self.WILDCARD,
                    'signal': 'networkPrefix',
                    'callback': self._networkPrefix_notif,
                },
                {
                    'sender': self.WILDCARD,
                    'signal': 'infoDagRoot',
                    'callback': self._infoDagRoot_notif,
                },
                {
                    'sender': self.WILDCARD,
                    'signal': 'getSourceRoute',
                    'callback': self._getSourceRoute_notif,
                },
            ])

        # local variables
        self.stateLock = threading.Lock()
        self.state = {}
        self.networkPrefix = None
        self.dagRootEui64 = None
        self.sourceRoute = SourceRoute.SourceRoute()
        self.latencyStats = {}

        # send a DIO periodically
        self._scheduleSendDIO(self.DIO_PERIOD)