예제 #1
0
    def testEnclaveBridge(self):
        '''Create a node that can bridge between the enclaves
        
           Send a flooding message from it to 1 enclave and verify only nodes in that one got it
           
        '''
        authenticationPayload = "This is a test"
        
  
        # Build the bridge node
        (status, bridgeNode, observer) = yield TestUtils.startupClientNode(self.myIP, 12500, allEnclaves[0], self.bsNode1.nodeLocation)
        self.failUnless(status, 'testEnclave bridge could not join first bootstrap [%s]' % status)
        
        # Join the other enclave also.
        enableAutoDiscovery = True
        bootstrapNodeList = [ self.bsNode2.nodeLocation ]
        status = yield bridgeNode.joinEnclave(bootstrapNodeList, enableAutoDiscovery,  authenticationPayload, False, None)
        self.failUnless(status, 'testEnclave bridge could not join second bootstrap [%s]' % status)

        self.bridgeNode = bridgeNode # Store a reference
        
        
        # Send a flooding message to one enclave and verify only one got it.
        messageNum = random.randint(1,9999999)
        status = yield TestUtils.sendFlood(bridgeNode,messageNum, allEnclaves[0] )
        self.assertTrue(status,"sendFlood failed!")

        yield TestUtils.wait(3) # Wait for the messages to send
        
        # Check message counts
        status = TestUtils.didReceive(self.allNodeObservers, allEnclaves[0], messageNum, numNodes)
        self.assertTrue(status,"Nodes in enclave %s didn't all recv message")

        status = TestUtils.didNotReceive(self.allNodeObservers, allEnclaves[1], messageNum, numNodes)
        self.assertTrue(status,"Some Nodes in enclave %s did recv message")
        
                
예제 #2
0
    def testEnclaveFlooding(self):
        """Build 2 enclaves and test flooding to each and all."""
        global startingPort

        # Create Bootstrap
        port = 12345
        bootstrapNodeLocation = NodeLocation(None, self.myIP, port)
        allNodes = []
        allNodeObservers = []
        allBootstrapObservers = []
        self.allNodes = allNodes

        # Start a bootstrap node
        (status, bsNode, observer) = yield TestUtils.startupBootstrapNode(self.myIP, port, allEnclaves[0])
        self.assertTrue(status, "Could not build bootstrap node")
        allBootstrapObservers.append(observer)

        self.bsNode = bsNode

        # Join another enclave
        bootstrapNodeList = None
        enableAutoDiscovery = True
        status = yield self.bsNode.joinEnclave(
            bootstrapNodeList, enableAutoDiscovery, None, isBootstrapNode=True, enclaveStr=allEnclaves[1]
        )

        # Add X nodes to each enclave
        for enclave in allEnclaves:
            for _ in range(numNodes):
                # Add a node to the enclave
                (status, node, observer) = yield TestUtils.startupClientNode(
                    self.myIP, startingPort, enclave, bootstrapNodeLocation
                )
                self.assertTrue(status, "Could not startupClientNode")
                startingPort += 1
                allNodes.append(node)
                allNodeObservers.append(observer)

        # Wait for flooding to reach all the nodes
        waiter = ConnectivityCounter()
        numberOfNodes = len(allEnclaves) * numNodes
        yield waiter.waitForConnectivity(numberOfNodes, bsNode)  # Does not count bsNode itself.

        # Flood from bootstrap to all
        messageNum = random.randint(1, 9999999)
        status = yield TestUtils.sendFlood(bsNode, messageNum, "ALL")
        self.assertTrue(status, "sendFlood failed!")

        yield TestUtils.wait(3)  # Wait for the messages to send

        # Check message counts
        status = TestUtils.didReceive(allNodeObservers, "ALL", messageNum, numberOfNodes)
        self.assertTrue(status, "All nodes did not receive message")

        # Flood from bootstrap to single enclave
        messageNum = random.randint(1, 9999999)
        status = yield TestUtils.sendFlood(bsNode, messageNum, allEnclaves[0])
        self.assertTrue(status, "sendFlood failed!")

        yield TestUtils.wait(3)  # Wait for the messages to send

        # Check message counts
        status = TestUtils.didReceive(allNodeObservers, allEnclaves[0], messageNum, numNodes)
        self.assertTrue(status, "Nodes in enclave %s didn't all recv message")

        status = TestUtils.didNotReceive(allNodeObservers, allEnclaves[1], messageNum, numNodes)
        self.assertTrue(status, "Some Nodes in enclave %s did recv message")

        log.msg("\n\n\n TEST ARE ALL DONE \n\n\n")
        yield TestUtils.wait(60)

        # Stop everything
        for node in self.allNodes:
            yield node.leave()
        yield self.bsNode.leave()

        # Wait for all network timeouts to finish
        yield TestUtils.wait(Config.CONNECTION_CACHE_DELAY + 3)
        # self.flushLoggedErrors()

        defer.returnValue(True)