コード例 #1
0
 def test_create_ack(self):
     # Test creating an acknowledgement packet for a packet
     pak = Packet()
     # Fake nodeid for acknowledgement
     nodeID = "testNodeId"
     newAck = pak.create_ack(nodeID)
     self.assertIsNotNone(newAck)
     self.assertTrue(newAck.IsAcknowledgement)
     # Should have the same SequenceNumber
     self.assertEqual(newAck.SequenceNumber, pak.SequenceNumber)
     self.assertEqual(newAck.SenderID, nodeID)
コード例 #2
0
 def test_create_ack(self):
     # Test creating an acknowledgement packet for a packet
     pak = Packet()
     # Fake nodeid for acknowledgement
     nodeID = "testNodeId"
     newAck = pak.create_ack(nodeID)
     self.assertIsNotNone(newAck)
     self.assertTrue(newAck.IsAcknowledgement)
     # Should have the same SequenceNumber
     self.assertEquals(newAck.SequenceNumber, pak.SequenceNumber)
     self.assertEquals(newAck.SenderID, nodeID)
コード例 #3
0
    def test_gossip_ack_good(self):
        # Test sending acknowledgements
        core = self._setup(8808)
        pak = Packet()
        newNode = self._create_node(8809)
        core.add_node(newNode)
        newNode.is_peer = True
        core._send_ack(pak, newNode)

        # Add pak to PendingAckMap
        msg = self._create_msg()
        pak.add_message(msg, newNode, newNode, 0)
        core.PendingAckMap[pak.SequenceNumber] = pak
        ack = pak.create_ack(newNode.Identifier)
        core._handle_ack(ack)
        stats = core.PacketStats.get_stats(["AcksReceived"])
        self.assertEqual(stats["AcksReceived"], 1)
コード例 #4
0
 def test_gossip_datagram_recieved_ack(self):
     # Test that datagramReceived handles acknowledgements correctly
     core = self._setup(9004)
     peer = self._create_node(9005)
     peer2 = self._create_node(9006)
     core.add_node(peer)
     core.add_node(peer2)
     msg = self._create_msg()
     pak = Packet()
     pak.add_message(msg, peer, peer2, 0)
     newPak = pak.create_ack(peer2.Identifier)
     data = newPak.pack()
     core.PendingAckMap[0] = pak
     # send ack
     core.datagramReceived(data, "localhost:9001")
     stats = core.PacketStats.get_stats(["AcksReceived"])
     self.assertEqual(stats["AcksReceived"], 1)
コード例 #5
0
    def test_gossip_ack_good(self):
        # Test sending acknowledgements
        core = self._setup(8808)
        pak = Packet()
        newNode = self._create_node(8809)
        core.add_node(newNode)
        newNode.is_peer = True
        core._send_ack(pak, newNode)

        # Add pak to PendingAckMap
        msg = self._create_msg()
        pak.add_message(msg, newNode, newNode, 0)
        core.PendingAckMap[pak.SequenceNumber] = pak
        ack = pak.create_ack(newNode.Identifier)
        core._handle_ack(ack)
        stats = core.PacketStats.get_stats(["AcksReceived"])
        self.assertEqual(stats["AcksReceived"], 1)
コード例 #6
0
 def test_gossip_datagram_recieved_ack(self):
     # Test that datagramReceived handles acknowledgements correctly
     core = self._setup(9004)
     peer = self._create_node(9005)
     peer2 = self._create_node(9006)
     core.add_node(peer)
     core.add_node(peer2)
     msg = self._create_msg()
     pak = Packet()
     pak.add_message(msg, peer, peer2, 0)
     newPak = pak.create_ack(peer2.Identifier)
     data = newPak.pack()
     core.PendingAckMap[0] = pak
     # send ack
     core.datagramReceived(data, "localhost:9001")
     stats = core.PacketStats.get_stats(["AcksReceived"])
     self.assertEqual(stats["AcksReceived"], 1)
コード例 #7
0
    def test_gossip_ack_unknown_packet(self):
        # Test behavior of sending a packet incorrectly
        core = self._setup(8810)
        pak = Packet()
        newNode = self._create_node(8811)
        core.add_node(newNode)
        # Ignore acks from unexpected packets not in PendingAckMap
        core._handle_ack(pak)
        stats = core.PacketStats.get_stats(["AcksReceived"])
        self.assertEqual(stats["AcksReceived"], 0)

        badNode = self._create_node(8812)
        core.add_node(badNode)
        # Test behavior of receiving an ack with bad Identifier
        # Will print out two warnings
        msg = self._create_msg()
        pak.add_message(msg, newNode, newNode, 0)
        core.PendingAckMap[pak.SequenceNumber] = pak
        ack = pak.create_ack(newNode.Identifier)
        pak.DestinationID = badNode.Identifier
        core._handle_ack(pak)
        stats = core.PacketStats.get_stats(["AcksReceived"])
        self.assertEqual(stats["AcksReceived"], 0)
コード例 #8
0
    def test_gossip_ack_unknown_packet(self):
        # Test behavior of sending a packet incorrectly
        core = self._setup(8810)
        pak = Packet()
        newNode = self._create_node(8811)
        core.add_node(newNode)
        # Ignore acks from unexpected packets not in PendingAckMap
        core._handle_ack(pak)
        stats = core.PacketStats.get_stats(["AcksReceived"])
        self.assertEqual(stats["AcksReceived"], 0)

        badNode = self._create_node(8812)
        core.add_node(badNode)
        # Test behavior of receiving an ack with bad Identifier
        # Will print out two warnings
        msg = self._create_msg()
        pak.add_message(msg, newNode, newNode, 0)
        core.PendingAckMap[pak.SequenceNumber] = pak
        ack = pak.create_ack(newNode.Identifier)
        pak.DestinationID = badNode.Identifier
        core._handle_ack(pak)
        stats = core.PacketStats.get_stats(["AcksReceived"])
        self.assertEqual(stats["AcksReceived"], 0)