Esempio n. 1
0
 def _updateRegisteredAddress(self):
     if not self.connected(): return
     level = self._promiscuousMode
     listeningBlock = PlaygroundAddressBlock(*self._address.toParts())
     for i in range(level):
         listeningBlock.getParentBlock()
     self._linkTx.changeRegisteredAddress(str(listeningBlock))
Esempio n. 2
0
    def getOutboundLinks(self, source, sourcePort, destination,
                         destinationPort):
        outboundLinks = set([])
        if not PlaygroundAddressBlock.IsValidAddressString(destination):
            return outboundLinks
        if not self._switch:
            # there is no service in this location.
            return outboundLinks

        dstAddress = PlaygroundAddressBlock.FromString(destination)
        dstPrefix = dstAddress[0]

        # allow anyone connected to this router to receive messages
        # for aother prefix
        outboundLinks = self._switch.getOutboundLinks(source, sourcePort,
                                                      destination,
                                                      destinationPort)

        # but, if the dstPrefix is not the local prefix, get nexthop as an
        # additional link
        if dstPrefix != self._prefix and self._WAN:
            logger.debug(
                "Received message for prefix {}. My prefix is {}. Routing".
                format(dstPrefix, self._prefix))
            nextHop = self._WAN.nextHop(self._prefix, dstPrefix)
            logger.debug("Next hop is {}".format(nextHop))
            if nextHop:
                destination = "{}.0.0.0".format(nextHop)
                logger.debug("Adding routing links {}".format(
                    self._switch.getOutboundLinks(source, 0, destination, 0)))
                outboundLinks.update(
                    self._switch.getOutboundLinks(source, 0, destination, 0))
        return outboundLinks
Esempio n. 3
0
 def getOutboundLinks(self, source, sourcePort, destination,
                      destinationPort):
     outboundLinks = set([])
     if not PlaygroundAddressBlock.IsValidAddressString(destination):
         return outboundLinks
     pAddress = PlaygroundAddressBlock.FromString(destination)
     while pAddress:
         outboundLinks.update(
             self._addressToLinks.get(str(pAddress), set([])))
         pAddress = pAddress.getParentBlock()
     return outboundLinks
Esempio n. 4
0
 def getRoutingDevice(self, address):
     for route in self._config:
         if route == self.DEFAULT_ROUTE_KEY:
             continue
         routeAddressBlock = PlaygroundAddressBlock.FromString(route)
         if routeAddressBlock.isParentBlock(address):
             return self._config[route]
     return self._config.get(self.DEFAULT_ROUTE_KEY, None)
Esempio n. 5
0
    def registerLink(self, address, protocol):
        if not PlaygroundAddressBlock.IsValidAddressString(address):
            # drop bad addresses silently.
            return
        self.unregisterLink(protocol)

        if not address in self._addressToLinks:
            self._addressToLinks[address] = set([protocol])
        else:
            self._addressToLinks[address].add(protocol)

        self._linkToAddress[protocol] = address