Exemple #1
0
 def updateNow(self, timeout = 60):
     """
     Performs the actual updating process.
     """
     from g4dsconfigurationcontroller import getRoutingController
     from communitymanager import getMemberManager, getCommunityManager
     
     peerList = {}   # the dict here is a bit chicky - but the simpliest way to avoid duplicates
     # get the ids of connected gateways and download their routing tables
     for communityid in getMemberManager().getLocalMember().getCommunityIds():
         comm = getCommunityManager().getCommunity(communityid)
         for gw in comm.getSourceGateways():
             if gw.getMemberId() != getMemberManager().getLocalMember().getId():
                 peerList[gw.getMemberId()] = None
     
     peerList = peerList.keys()
     for peerId in peerList:
         routesRemote = getRoutingController().downloadRoutingTable(peerId, timeout = timeout)
         
         from routingtablemanager import getRoutingTableManager
         import thread
         thread.start_new_thread(getRoutingTableManager().applyRoutingTableFromNode, (peerId, routesRemote))
     
     from g4dslogging import getDefaultLogger, ROUTING_TABLE_UPDATED
     getDefaultLogger().newMessage(ROUTING_TABLE_UPDATED, 'Routing table updated')
Exemple #2
0
    def dispatch(self, message, incomingmessageid):
        """
        Unwrappes the message and tries to deliver directly, or if not possible through another routing hop.
        """
##        print "\tRouting Dispatcher: Received something to pass on."
        from g4dslogging import getDefaultLogger, COMMUNICATION_INCOMING_MSG_DETAILS
        getDefaultLogger().newMessage(COMMUNICATION_INCOMING_MSG_DETAILS, '-- Control Msg - SS: Routing Engine')

        from messagewrapper import getControlMessageWrapper
        action, sucess, args, unwrapped = getControlMessageWrapper().unwrapSSRoutingMessage(message)
        destination = args['destination']
        protocol = args['protocol']
        community = args['community']

        from authorisationcontroller import getAuthorisationController
        from messagehandler import getMessageContextController
        sourceCommunity = getMessageContextController().getValue(incomingmessageid, 'communityid')
##        # let's check, whether the sender of this message is allowed to route into the community
##        if not getAuthorisationController().validate(getMessageContextController().getValue(incomingmessageid, 'senderid'), 
##            sourceCommunity, 'g4ds.routing.route'):
##            return
        
        from communitymanager import getMemberManager
        # check first, whether we are the final receipient
        if getMemberManager().getLocalMember().getId() == destination:
            # great stuff - pass it to the global dispatcher
            from messagehandler import getGlobalDispatcher
            getGlobalDispatcher().dispatch(protocol, unwrapped)
        else:
            args = {}
            args['destination'] = destination
            args['protocol'] = protocol
            args['community'] = community
            from messagewrapper import getControlMessageWrapper
            wrapped, doc, element = getControlMessageWrapper().wrapSSRoutingMessage('1', args = args, data = unwrapped)
            from g4dsconfigurationcontroller import getOutgoingControlMessagesHandler, CONTROL_ROUTER
            # check, whether we can reach the dest community directly
            try:
                getMemberManager().getLocalMember().getCommunityIds().index(community)
                # great to know; but are we allowed this action?
                if not getAuthorisationController().validate(getMemberManager().getLocalMember().getId(), community, 'g4ds.routing.route'):
                    raise ValueError('I am in the dest community; but I am not allowed to route into it. Let us try to find somebody else.')
                # unfortunately, we can only check the dest tc with the access control - let's check for scr / dest combination additionally
                for gw in getMemberManager().getLocalMember().getGateways():
                    if gw.getSourceCommunityId() == sourceCommunity and gw.getDestinationCommunityId() == community:
                        getOutgoingControlMessagesHandler().sendMessage(destination, CONTROL_ROUTER, "Routing message", wrapped, communityid = community)
                raise ValueError('I am in the dest community; but I am not allowed to route into it. Let us try to find somebody else.')
            except ValueError, msg:
                # ok - looks like we can only pass it on to the next hop
                gateway_member_id, peercommunity, hops = getRoutingTableManager().getNexthopForCommunity(community)
                # are we allowed this action then?
                if not getAuthorisationController().validate(getMemberManager().getLocalMember().getId(), peercommunity, 'g4ds.routing.route'):
                    return
                # ah, fair enough - is it also allowed for the combination src TC / dst TC?
                for gw in getMemberManager().getLocalMember().getGateways():
                    if gw.getSourceCommunityId() == sourceCommunity and gw.getDestinationCommunityId() == peercommunity:
                        getOutgoingControlMessagesHandler().sendMessage(gateway_member_id, CONTROL_ROUTER, "Routing message", wrapped, communityid = peercommunity)
Exemple #3
0
    def _assembleRoutingMessage(self, message, endpoint):
        
        final_destination = endpoint.getMemberId()
        community = endpoint.getCommunityId()
        from communicationmanager import getProtocolManager
        protocolname = getProtocolManager().getProtocol(endpoint.getProtocolId()).getName()
        gateway_member_id, peercommunity, hops = getRoutingTableManager().getNexthopForCommunity(endpoint.getCommunityId())
        args = {}
        args['destination'] = final_destination
        args['protocol'] = protocolname
        args['community'] = community
        from messagewrapper import getControlMessageWrapper
        wrapped, tmp, tmp1 = getControlMessageWrapper().wrapSSRoutingMessage('1', args = args, data = message)

        from g4dslogging import getDefaultLogger, COMMUNICATION_OUTGOING_MSG_DETAILS
        getDefaultLogger().newMessage(COMMUNICATION_OUTGOING_MSG_DETAILS, '-- Routing details: Gateway (%s | %s)' %(gateway_member_id, peercommunity))
        getDefaultLogger().newMessage(COMMUNICATION_OUTGOING_MSG_DETAILS, '-- Size of Data %d chars' %(len(message)))

        from g4dsconfigurationcontroller import getOutgoingControlMessagesHandler, CONTROL_ROUTER
        getOutgoingControlMessagesHandler().sendMessage(gateway_member_id, CONTROL_ROUTER, "Routing message", wrapped, communityid = peercommunity)
Exemple #4
0
            
        _printAction(1, "Load up permission policies into memory")
        from authorisationcontroller import getAuthorisationController
##        getAuthorisationController()
        try:
            getAuthorisationController()                     # start listening on all endpoints
            _finishActionLine()
##        except Exception, msg:
        except KeyError, msg:
            _finishActionLine(SUCESS_NEG)
            _printAction(2, str(msg))
            _finishActionLine(SUCESS_NEG)            

        _printAction(1, "Loading routing table into memory")
        from routingtablemanager import getRoutingTableManager
        getRoutingTableManager()
        _finishActionLine()

        _printAction(1, "Enable dynamic routing")
        from dynamicrouting import getRoutingTableUpdater
        from errorhandling import G4dsRuntimeException
        try:
            getRoutingTableUpdater()
            _finishActionLine()
        except G4dsRuntimeException, msg:
            _finishActionLine(SUCESS_SKIP)
        
        _printAction(0, "G4DS running")
        _finishActionLine()
        print "*" * 90 + "\n"