Exemple #1
0
    def test_DoubleSend(self):
        """ Test for no routing out same interface twice for paused messages """
        # from n1 to n2,g1, route requests on local, should deliver out t11 for g1,  and then out t11 again for n1 but be squelched
        msg = self.newMsg()
        msg.dstnodes = ['n2']
        msg._receivedon = self.router.transportMap[0]

        request = {'add': ['g1'], 'count': 1, 'checksum': listChecksum(['g1'])}
        rtmsg1 = MAGIMessage(src="ignore",
                             groups=["__NEIGH__"],
                             docks=[GroupRouter.DOCK],
                             data=yaml.safe_dump(request))
        rtmsg1._receivedon = self.transports[11]

        rtmsg2 = MAGIMessage(src="n2",
                             groups=["__ALL__"],
                             docks=[NodeRouter.DOCK],
                             data=yaml.safe_dump({'response': True}))
        rtmsg2._receivedon = self.transports[11]

        self.push(rtmsg1)
        self.push(msg)
        self.push(rtmsg2)

        self._checkForMessageOnlyIn("data", yaml.safe_dump({'request': 'n2'}),
                                    [10, 11, 12])
        self._checkForMessageOnlyIn("msgid", 1234, [11])
        msgcount = len(self.transports[11].outmessages)
        self.assert_(
            msgcount == 2,
            "Should only be 1 request and 1 message in t11 queue, found %d" %
            msgcount)
        self.assert_(self.router.rxqueue.empty(),
                     "Local receive queue should be empty")
        self.commonAssert()
Exemple #2
0
    def test_MultiRoute(self):
        """ Test multiple routes with loopback """
        # from local to g1, no route requests, should deliver out t11 for g1, t12 for g2, not back to local as that was source
        request = {'add': ['g1'], 'count': 1, 'checksum': listChecksum(['g1'])}
        rtmsg1 = MAGIMessage(src="n1",
                             groups=["__NEIGH__"],
                             docks=[GroupRouter.DOCK],
                             data=yaml.safe_dump(request))
        rtmsg1._receivedon = self.transports[11]

        request = {'add': ['g2'], 'count': 1, 'checksum': listChecksum(['g2'])}
        rtmsg2 = MAGIMessage(src="n2",
                             groups=["__NEIGH__"],
                             docks=[GroupRouter.DOCK],
                             data=yaml.safe_dump(request))
        rtmsg2._receivedon = self.transports[12]

        msg = self.newMsg()
        msg.dstnodes = []
        msg._receivedon = self.router.transportMap[0]

        self.router.routers[0].groupRequest(
            GroupRequest("join", "g1", "default"))
        self.push(rtmsg1)
        self.push(rtmsg2)
        self.push(msg)

        self._checkForMessageOnlyIn("dstdocks", ['RouteRequest'], [])
        self._checkForMessageOnlyIn("msgid", 1234, [11, 12])
        self.assertEquals(
            self.router.rxqueue.qsize(), 1,
            "Local receive queue should have an incoming message")
        self.commonAssert()
	def test_remoteGroup(self):
		""" Test message with a remote group and transport down """
		addother = { 'add': ['othergroup'], 'count': 1, 'checksum': listChecksum(['othergroup']) }
		rtmsg1 = MAGIMessage(groups=[GroupRouter.ONEHOPNODES], contenttype=MAGIMessage.YAML, docks=[GroupRouter.DOCK], data=yaml.safe_dump(addother))
		rtmsg1._receivedon = self.transports[2]

		adddead = { 'add': ['deadgroup'], 'count': 2, 'checksum': listChecksum(['deadgroup', 'othergroup']) }
		rtmsg2 = MAGIMessage(groups=[GroupRouter.ONEHOPNODES], contenttype=MAGIMessage.YAML, docks=[GroupRouter.DOCK], data=yaml.safe_dump(adddead))
		rtmsg2._receivedon = self.transports[2]

		msg = MAGIMessage(groups=["othergroup"])
		msg._receivedon = self.transports[1]
 
		# Local joins mygroup, on transport2 they join othergroup and deadgroup, message enters on transport1 for othergroup
		self.router.groupRequest(GroupRequest("join", "mygroup", "default"))
		self.router.processIN([rtmsg1], time.time())
		self.router.processIN([rtmsg2], time.time())
		fds = self.router.routeMessage(msg)
		self.assertEqual(fds, set([2]))

		# Now transport is flagged as down, same message should route to nowhere
		self.router.transportRemoved(2, self.transports[2])
		msg._appendedto = set()
		fds = self.router.routeMessage(msg)
		self.assertEqual(fds, set())
Exemple #4
0
    def test_BasicRoute(self):
        """ Test basic functionality of routeMessage in router core"""
        # local to n1, route request out all external, response on t10, route out t10, then response on t11, paused messages send out t11
        rtmsg = MAGIMessage(src="n1",
                            groups=["__ALL__"],
                            docks=[NodeRouter.DOCK],
                            data=yaml.safe_dump({'response': True}))
        rtmsg._receivedon = self.transports[10]
        rtmsg2 = MAGIMessage(src="n2",
                             groups=["__ALL__"],
                             docks=[NodeRouter.DOCK],
                             data=yaml.safe_dump({'response': True}))
        rtmsg2._receivedon = self.transports[11]

        msg = self.newMsg()
        msg._receivedon = self.router.transportMap[0]

        self.push(rtmsg)
        self.push(msg)

        self._checkForMessageOnlyIn("data", yaml.safe_dump({'request': 'n1'}),
                                    [])  # got response before msg, no requests
        self._checkForMessageOnlyIn("data", yaml.safe_dump({'request': 'n2'}),
                                    [10, 11, 12])  # want to know about n2
        self._checkForMessageOnlyIn("msgid", 1234, [10])
        self.assert_(self.router.rxqueue.empty(),
                     "Local receive queue should be empty"
                     )  # locally not n1,n2 or a member of g1 or g2
        self.commonAssert()

        self.router.transportMap[10].outmessages = []  # clear
        self.push(rtmsg2)
        self._checkForMessageOnlyIn("msgid", 1234, [11])
	def test_multipleRoutes(self):
		""" Test for multiple nodes including localhost as one """
		msg = MAGIMessage(nodes=["unknown","mynode"])
		msg._receivedon = self.transports[2]

		rtmsg = MAGIMessage(src="unknown", groups=["__ALL__"], docks=[NodeRouter.DOCK], data=yaml.safe_dump({'response':True}))
		rtmsg._receivedon = self.transports[1]

		self.router.processIN([rtmsg], time.time())
		fds = self.router.routeMessage(msg)
		self.assertEqual(fds, set([0,1]))
    def test_multipleRoutes(self):
        """ Test for multiple nodes including localhost as one """
        msg = MAGIMessage(nodes=["unknown", "mynode"])
        msg._receivedon = self.transports[2]

        rtmsg = MAGIMessage(src="unknown",
                            groups=["__ALL__"],
                            docks=[NodeRouter.DOCK],
                            data=yaml.safe_dump({'response': True}))
        rtmsg._receivedon = self.transports[1]

        self.router.processIN([rtmsg], time.time())
        fds = self.router.routeMessage(msg)
        self.assertEqual(fds, set([0, 1]))
Exemple #7
0
    def test_RouteBack(self):
        """ Test for no routing out same interface if routeresponse comes from there """
        # from n1 to n2,g1,g2 , send node request, get response on interface it came in out, don't send back that way, just drop
        msg = self.newMsg()
        msg.dstnodes = ['n2']
        msg._receivedon = self.transports[10]

        rtmsg = MAGIMessage(src="n2",
                            groups=["__ALL__"],
                            docks=[NodeRouter.DOCK],
                            data=yaml.safe_dump({'response': True}))
        rtmsg._receivedon = self.transports[10]

        logging.disable(30)  # disable warning for no route, expected
        self.push(msg)
        logging.disable(0)
        self.assertEquals(
            1, len(self.router.processors[6].pausedMessages['n2']
                   ))  # BIG DEPENDENCY ON PROCESSOR ORDERING in this test
        self.push(rtmsg)
        self.assertEquals(0,
                          len(self.router.processors[6].pausedMessages['n2']))

        self._checkForMessageOnlyIn("data", yaml.safe_dump({'request': 'n2'}),
                                    [10, 11, 12])
        self._checkForMessageOnlyIn("msgid", 1234, [])
        self.assert_(self.router.rxqueue.empty(),
                     "Local receive queue should be empty"
                     )  # routerdock message absorbed by router processor
        self.commonAssert()
	def test_routeNoBackwards(self):
		""" Test route and request without sending back out initial receiving interface """
		msg = MAGIMessage(nodes=["unknown"])
		msg._receivedon = self.transports[1]

		rtmsg = MAGIMessage(src="unknown", groups=["__ALL__"], docks=[NodeRouter.DOCK], data=yaml.safe_dump({'response':True}))
		rtmsg._receivedon = self.transports[1]

		# Attempt to route message, should have nowhere to go
		fds = self.router.routeMessage(msg)
		self.assertEqual(fds, set([]))
		self._checkForMessageOnlyIn('data', yaml.safe_dump({'request':'unknown'}), [1, 2])

		# Get a route response and check for proper queing
		self.router.processIN([rtmsg], time.time())
		self._checkForMessageOnlyIn('dstnodes', ['unknown'], [])
	def test_requestSquelch(self):
		""" Test to make sure squelching of requests occurs """
		msg1 = MAGIMessage(nodes=["unknown"], data='1')
		msg1._receivedon = self.transports[1]

		msg2 = MAGIMessage(nodes=["unknown"], data='2')
		msg2._receivedon = self.transports[1]

		# Two messages for unknown, only one request should be queued
		fds = self.router.routeMessage(msg1)
		self.assertEqual(fds, set([]))
		fds = self.router.routeMessage(msg2)
		self.assertEqual(fds, set([]))
		self._checkForMessageOnlyIn('data', yaml.safe_dump({'request':'unknown'}), [1, 2])
		self._checkMessagesInEquals(1, 1)
		self._checkMessagesInEquals(2, 1)
Exemple #10
0
 def _incomingGroupResend(self, fd, src):
     request = {'resend': True}
     msg = MAGIMessage(src=src,
                       contenttype=MAGIMessage.YAML,
                       docks=[GroupRouter.DOCK],
                       data=yaml.safe_dump(request))
     msg._receivedon = self.transports[fd]
     self.router.processIN([msg], time.time())
	def test_RequestResponse(self):
		""" Test basic response to a request """
		rtmsg = MAGIMessage(src="unknown", groups=["__ALL__"], docks=[NodeRouter.DOCK], data=yaml.safe_dump({'request':'mynode'}))
		rtmsg._receivedon = self.transports[1]
		self.router.processIN([rtmsg], time.time())
		self.assertEquals(1, len(self.store.outgoing))
		self.assertEquals(set([NodeRouter.DOCK]), self.store.outgoing[0].dstdocks)
		self.assert_('response' in yaml.load(self.store.outgoing[0].data))
Exemple #12
0
    def test_localGroup(self):
        """ Test message with a local group """
        msg = MAGIMessage(groups=["mygroup"])
        msg._receivedon = self.transports[1]

        # Local joins mygroup, message enters on transport1 for mygroup
        self.router.groupRequest(GroupRequest("join", "mygroup", "default"))
        fds = self.router.routeMessage(msg)
        self.assertEqual(fds, set([0]))
	def test_localGroup(self):
		""" Test message with a local group """
		msg = MAGIMessage(groups=["mygroup"])
		msg._receivedon = self.transports[1]
 
		# Local joins mygroup, message enters on transport1 for mygroup
		self.router.groupRequest(GroupRequest("join", "mygroup", "default"))
		fds = self.router.routeMessage(msg)
		self.assertEqual(fds, set([0]))
    def test_requestSquelch(self):
        """ Test to make sure squelching of requests occurs """
        msg1 = MAGIMessage(nodes=["unknown"], data='1')
        msg1._receivedon = self.transports[1]

        msg2 = MAGIMessage(nodes=["unknown"], data='2')
        msg2._receivedon = self.transports[1]

        # Two messages for unknown, only one request should be queued
        fds = self.router.routeMessage(msg1)
        self.assertEqual(fds, set([]))
        fds = self.router.routeMessage(msg2)
        self.assertEqual(fds, set([]))
        self._checkForMessageOnlyIn('data',
                                    yaml.safe_dump({'request': 'unknown'}),
                                    [1, 2])
        self._checkMessagesInEquals(1, 1)
        self._checkMessagesInEquals(2, 1)
	def test_routeUnknown(self):
		""" Test route without a destination node  """
		msg = MAGIMessage(src="thesrc", nodes=["unknown"])
		msg.msgid = 12345
		msg._receivedon = self.transports[1]

		rtmsg = MAGIMessage(src="unknown", groups=["__ALL__"], docks=[NodeRouter.DOCK], data=yaml.safe_dump({'response':True}))
		rtmsg._receivedon = self.transports[2]

		# Attempt to route message, should have nowhere to go
		fds = self.router.routeMessage(msg)
		self.assertEqual(fds, set([]))
		self._checkForMessageOnlyIn('data', yaml.safe_dump({'request':'unknown'}), [1, 2])

		# Get a route response and check for proper queing, original header information should stay intact when sending paused
		self.router.processIN([rtmsg], time.time())
		self._checkForMessageOnlyIn('dstnodes', set(['unknown']), [2])
		self._checkForMessageOnlyIn('src', "thesrc", [2])
		self._checkForMessageOnlyIn('msgid', 12345, [2])
 def test_RequestResponse(self):
     """ Test basic response to a request """
     rtmsg = MAGIMessage(src="unknown",
                         groups=["__ALL__"],
                         docks=[NodeRouter.DOCK],
                         data=yaml.safe_dump({'request': 'mynode'}))
     rtmsg._receivedon = self.transports[1]
     self.router.processIN([rtmsg], time.time())
     self.assertEquals(1, len(self.store.outgoing))
     self.assertEquals(set([NodeRouter.DOCK]),
                       self.store.outgoing[0].dstdocks)
     self.assert_('response' in yaml.load(self.store.outgoing[0].data))
    def test_routeNoBackwards(self):
        """ Test route and request without sending back out initial receiving interface """
        msg = MAGIMessage(nodes=["unknown"])
        msg._receivedon = self.transports[1]

        rtmsg = MAGIMessage(src="unknown",
                            groups=["__ALL__"],
                            docks=[NodeRouter.DOCK],
                            data=yaml.safe_dump({'response': True}))
        rtmsg._receivedon = self.transports[1]

        # Attempt to route message, should have nowhere to go
        fds = self.router.routeMessage(msg)
        self.assertEqual(fds, set([]))
        self._checkForMessageOnlyIn('data',
                                    yaml.safe_dump({'request': 'unknown'}),
                                    [1, 2])

        # Get a route response and check for proper queing
        self.router.processIN([rtmsg], time.time())
        self._checkForMessageOnlyIn('dstnodes', ['unknown'], [])
Exemple #18
0
 def _incomingGroupList(self, fd, src, grouplist):
     self.neighbors[fd][src] = set(grouplist)
     request = {
         'set': grouplist,
         'count': len(self.neighbors[fd][src]),
         'checksum': listChecksum(self.neighbors[fd][src])
     }
     msg = MAGIMessage(src=src,
                       contenttype=MAGIMessage.YAML,
                       docks=[GroupRouter.DOCK],
                       data=yaml.safe_dump(request))
     msg._receivedon = self.transports[fd]
     self.router.processIN([msg], time.time())
Exemple #19
0
    def test_remoteGroup(self):
        """ Test message with a remote group and transport down """
        addother = {
            'add': ['othergroup'],
            'count': 1,
            'checksum': listChecksum(['othergroup'])
        }
        rtmsg1 = MAGIMessage(groups=[GroupRouter.ONEHOPNODES],
                             contenttype=MAGIMessage.YAML,
                             docks=[GroupRouter.DOCK],
                             data=yaml.safe_dump(addother))
        rtmsg1._receivedon = self.transports[2]

        adddead = {
            'add': ['deadgroup'],
            'count': 2,
            'checksum': listChecksum(['deadgroup', 'othergroup'])
        }
        rtmsg2 = MAGIMessage(groups=[GroupRouter.ONEHOPNODES],
                             contenttype=MAGIMessage.YAML,
                             docks=[GroupRouter.DOCK],
                             data=yaml.safe_dump(adddead))
        rtmsg2._receivedon = self.transports[2]

        msg = MAGIMessage(groups=["othergroup"])
        msg._receivedon = self.transports[1]

        # Local joins mygroup, on transport2 they join othergroup and deadgroup, message enters on transport1 for othergroup
        self.router.groupRequest(GroupRequest("join", "mygroup", "default"))
        self.router.processIN([rtmsg1], time.time())
        self.router.processIN([rtmsg2], time.time())
        fds = self.router.routeMessage(msg)
        self.assertEqual(fds, set([2]))

        # Now transport is flagged as down, same message should route to nowhere
        self.router.transportRemoved(2, self.transports[2])
        msg._appendedto = set()
        fds = self.router.routeMessage(msg)
        self.assertEqual(fds, set())
Exemple #20
0
	def test_BasicRoute(self):
		""" Test basic functionality of routeMessage in router core"""
		# local to n1, route request out all external, response on t10, route out t10, then response on t11, paused messages send out t11
		rtmsg = MAGIMessage(src="n1", groups=["__ALL__"], docks=[NodeRouter.DOCK], data=yaml.safe_dump({'response':True}))
		rtmsg._receivedon = self.transports[10]
		rtmsg2 = MAGIMessage(src="n2", groups=["__ALL__"], docks=[NodeRouter.DOCK], data=yaml.safe_dump({'response':True}))
		rtmsg2._receivedon = self.transports[11]

		msg = self.newMsg()
		msg._receivedon = self.router.transportMap[0]

		self.push(rtmsg)
		self.push(msg)

		self._checkForMessageOnlyIn("data", yaml.safe_dump({'request':'n1'}), [])  # got response before msg, no requests
		self._checkForMessageOnlyIn("data", yaml.safe_dump({'request':'n2'}), [10,11,12]) # want to know about n2
		self._checkForMessageOnlyIn("msgid", 1234, [10])
		self.assert_(self.router.rxqueue.empty(), "Local receive queue should be empty")  # locally not n1,n2 or a member of g1 or g2
		self.commonAssert()

		self.router.transportMap[10].outmessages = [] # clear
		self.push(rtmsg2)
		self._checkForMessageOnlyIn("msgid", 1234, [11])
Exemple #21
0
	def test_MultiRoute(self):
		""" Test multiple routes with loopback """
		# from local to g1, no route requests, should deliver out t11 for g1, t12 for g2, not back to local as that was source
		request = { 'add': ['g1'], 'count': 1, 'checksum': listChecksum(['g1']) }
		rtmsg1 = MAGIMessage(src="n1", groups=["__NEIGH__"], docks=[GroupRouter.DOCK], data=yaml.safe_dump(request))
		rtmsg1._receivedon = self.transports[11]

		request = { 'add': ['g2'], 'count': 1, 'checksum': listChecksum(['g2']) }
		rtmsg2 = MAGIMessage(src="n2", groups=["__NEIGH__"], docks=[GroupRouter.DOCK], data=yaml.safe_dump(request))
		rtmsg2._receivedon = self.transports[12]

		msg = self.newMsg()
		msg.dstnodes = []
		msg._receivedon = self.router.transportMap[0]

		self.router.routers[0].groupRequest(GroupRequest("join", "g1", "default"))
		self.push(rtmsg1)
		self.push(rtmsg2)
		self.push(msg)

		self._checkForMessageOnlyIn("dstdocks", ['RouteRequest'], [])
		self._checkForMessageOnlyIn("msgid", 1234, [11, 12])
		self.assertEquals(self.router.rxqueue.qsize(), 1, "Local receive queue should have an incoming message")
		self.commonAssert()
Exemple #22
0
	def test_DoubleSend(self):
		""" Test for no routing out same interface twice for paused messages """
		# from n1 to n2,g1, route requests on local, should deliver out t11 for g1,  and then out t11 again for n1 but be squelched
		msg = self.newMsg()
		msg.dstnodes = ['n2']
		msg._receivedon = self.router.transportMap[0]

		request = { 'add': ['g1'], 'count': 1, 'checksum': listChecksum(['g1']) }
		rtmsg1 = MAGIMessage(src="ignore", groups=["__NEIGH__"], docks=[GroupRouter.DOCK], data=yaml.safe_dump(request))
		rtmsg1._receivedon = self.transports[11]

		rtmsg2 = MAGIMessage(src="n2", groups=["__ALL__"], docks=[NodeRouter.DOCK], data=yaml.safe_dump({'response':True}))
		rtmsg2._receivedon = self.transports[11]

		self.push(rtmsg1)
		self.push(msg)
		self.push(rtmsg2)

		self._checkForMessageOnlyIn("data", yaml.safe_dump({'request':'n2'}), [10, 11, 12])
		self._checkForMessageOnlyIn("msgid", 1234, [11])
		msgcount = len(self.transports[11].outmessages)
		self.assert_(msgcount == 2, "Should only be 1 request and 1 message in t11 queue, found %d" % msgcount)
		self.assert_(self.router.rxqueue.empty(), "Local receive queue should be empty")
		self.commonAssert()
    def test_routeUnknown(self):
        """ Test route without a destination node  """
        msg = MAGIMessage(src="thesrc", nodes=["unknown"])
        msg.msgid = 12345
        msg._receivedon = self.transports[1]

        rtmsg = MAGIMessage(src="unknown",
                            groups=["__ALL__"],
                            docks=[NodeRouter.DOCK],
                            data=yaml.safe_dump({'response': True}))
        rtmsg._receivedon = self.transports[2]

        # Attempt to route message, should have nowhere to go
        fds = self.router.routeMessage(msg)
        self.assertEqual(fds, set([]))
        self._checkForMessageOnlyIn('data',
                                    yaml.safe_dump({'request': 'unknown'}),
                                    [1, 2])

        # Get a route response and check for proper queing, original header information should stay intact when sending paused
        self.router.processIN([rtmsg], time.time())
        self._checkForMessageOnlyIn('dstnodes', set(['unknown']), [2])
        self._checkForMessageOnlyIn('src', "thesrc", [2])
        self._checkForMessageOnlyIn('msgid', 12345, [2])
Exemple #24
0
	def test_RouteBack(self):
		""" Test for no routing out same interface if routeresponse comes from there """
		# from n1 to n2,g1,g2 , send node request, get response on interface it came in out, don't send back that way, just drop
		msg = self.newMsg()
		msg.dstnodes = ['n2']
		msg._receivedon = self.transports[10]
	
		rtmsg = MAGIMessage(src="n2", groups=["__ALL__"], docks=[NodeRouter.DOCK], data=yaml.safe_dump({'response':True}))
		rtmsg._receivedon = self.transports[10]

		logging.disable(30) # disable warning for no route, expected
		self.push(msg)
		logging.disable(0)
		self.assertEquals(1, len(self.router.processors[6].pausedMessages['n2']))  # BIG DEPENDENCY ON PROCESSOR ORDERING in this test
		self.push(rtmsg)
		self.assertEquals(0, len(self.router.processors[6].pausedMessages['n2']))

		self._checkForMessageOnlyIn("data", yaml.safe_dump({'request':'n2'}), [10, 11, 12])
		self._checkForMessageOnlyIn("msgid", 1234, [])
		self.assert_(self.router.rxqueue.empty(), "Local receive queue should be empty")  # routerdock message absorbed by router processor
		self.commonAssert()
	def test_GroupAckAggregation(self):
		""" Test aggregation of group acknowledgments """
		self.transports[3] = TestTransport(3)
		self.router.transportAdded(self.transports[3])
		self.neighbors = {0: {}, 1: {}, 2: {}, 3: {}}
		for k in self.transports:
			self.neighbors[k] = defaultdict(set)

		self._incomingGroupAdd(1, 'n11', ['g1', 'g2'])
		self._incomingGroupAdd(1, 'n12', ['g3'])

		self._incomingGroupAdd(2, 'n21', ['g1', 'g2'])
		self._incomingGroupAdd(2, 'n22', ['g1', 'g3'])
		self._checkGroupState()

		# Check the processing of a message with groups that wants an ack, verify data structure inside
		msg = MAGIMessage(src="n30", nodes=["n21"], groups=['g1', 'g3'])
		msg.msgid = 789
		msg.flags |= MAGIMessage.WANTACK
		msg._receivedon = self.transports[3]
		msg._routed = self.router.routeMessage(msg)

		self.assertEqual(msg._routed, set([1, 2]))
		out = self.router.processFWD([msg], time.time())
		self.assertEquals(out, [msg])

		key = ("n30", 789)
		self.assertEquals(self.router.ackHolds.keys(), [key])
		self.assertEquals(sorted(self.router.ackHolds[key].keys()),	['g1', 'g3'])
		self.assertEquals(self.router.ackHolds[key]['g1'][1],		set(['n11']))
		self.assertEquals(self.router.ackHolds[key]['g1'][2],		set(['n21', 'n22']))
		self.assertEquals(self.router.ackHolds[key]['g3'][1],		set(['n12']))
		self.assertEquals(self.router.ackHolds[key]['g3'][2],		set(['n22']))
		self.store.outgoing = []  # clear
		
		# from N11, ack stops here
		ack = msg.createAck("", ['g1']) 
		ack._receivedon = self.transports[1]
		ack.src = "n11"
		out = self.router.processFWD([ack], time.time())  # no group routing, only node routing
		self.assertEquals(self.router.ackHolds[key]['g1'].keys(),	[2]) # nothing left on transport 1 for g1
		self.assertEquals(0, len(out))

		# from N21, ack passes with n21 but no groups
		ack = msg.createAck("n21", ['g1']) 
		ack.src = "n21"
		ack._receivedon = self.transports[2]
		out = self.router.processFWD([ack], time.time())
		self.assertEquals(self.router.ackHolds[key]['g1'][2],		set(['n22']))
		self.assertEquals(1, len(out))
		self.assertEquals("n21", out[0].data)

		# from N22, ack passes with g1
		ack = msg.createAck("", ['g1', 'g3']) 
		ack.src = "n22"
		ack._receivedon = self.transports[2]
		out = self.router.processFWD([ack], time.time())
		self.assertEquals(self.router.ackHolds[key].keys(), ['g3'])  # g1 complete
		self.assertEquals(self.router.ackHolds[key]['g3'].keys(), [1]) # g3 is still active on transport 1
		self.assertEquals(1, len(out))
		self.assertEquals(",g1", out[0].data)

		# from N12, ack passes with g2
		ack = msg.createAck("", ['g3']) 
		ack.src = "n12"
		ack._receivedon = self.transports[1]
		out = self.router.processFWD([ack], time.time())
		self.assertEquals(self.router.ackHolds.keys(), [])  # all complete
		self.assertEquals(1, len(out))
		self.assertEquals(",g3", out[0].data)
	def test_routeNeighExt(self):
		""" Test internal message sent to NEIGH """
		msg = MAGIMessage(groups=[GroupRouter.ONEHOPNODES])
		msg._receivedon = self.transports[0]
		fds = self.router.routeMessage(msg)
		self.assertEqual(fds, set([1,2]))
Exemple #27
0
 def test_routeNone(self):
     """ Test message without any groups """
     msg = MAGIMessage(nodes=["somenode"])
     msg._receivedon = self.transports[1]
     fds = self.router.routeMessage(msg)
     self.assertEqual(fds, set([]))
Exemple #28
0
 def test_routeNeighExt(self):
     """ Test internal message sent to NEIGH """
     msg = MAGIMessage(groups=[GroupRouter.ONEHOPNODES])
     msg._receivedon = self.transports[0]
     fds = self.router.routeMessage(msg)
     self.assertEqual(fds, set([1, 2]))
Exemple #29
0
 def test_routeAll(self):
     """ Test route with a group ALL """
     msg = MAGIMessage(groups=[GroupRouter.ALLNODES])
     msg._receivedon = self.transports[1]
     fds = self.router.routeMessage(msg)
     self.assertEqual(fds, set([0, 1, 2]))
Exemple #30
0
    def test_GroupAckAggregation(self):
        """ Test aggregation of group acknowledgments """
        self.transports[3] = TestTransport(3)
        self.router.transportAdded(self.transports[3])
        self.neighbors = {0: {}, 1: {}, 2: {}, 3: {}}
        for k in self.transports:
            self.neighbors[k] = defaultdict(set)

        self._incomingGroupAdd(1, 'n11', ['g1', 'g2'])
        self._incomingGroupAdd(1, 'n12', ['g3'])

        self._incomingGroupAdd(2, 'n21', ['g1', 'g2'])
        self._incomingGroupAdd(2, 'n22', ['g1', 'g3'])
        self._checkGroupState()

        # Check the processing of a message with groups that wants an ack, verify data structure inside
        msg = MAGIMessage(src="n30", nodes=["n21"], groups=['g1', 'g3'])
        msg.msgid = 789
        msg.flags |= MAGIMessage.WANTACK
        msg._receivedon = self.transports[3]
        msg._routed = self.router.routeMessage(msg)

        self.assertEqual(msg._routed, set([1, 2]))
        out = self.router.processFWD([msg], time.time())
        self.assertEquals(out, [msg])

        key = ("n30", 789)
        self.assertEquals(self.router.ackHolds.keys(), [key])
        self.assertEquals(sorted(self.router.ackHolds[key].keys()),
                          ['g1', 'g3'])
        self.assertEquals(self.router.ackHolds[key]['g1'][1], set(['n11']))
        self.assertEquals(self.router.ackHolds[key]['g1'][2],
                          set(['n21', 'n22']))
        self.assertEquals(self.router.ackHolds[key]['g3'][1], set(['n12']))
        self.assertEquals(self.router.ackHolds[key]['g3'][2], set(['n22']))
        self.store.outgoing = []  # clear

        # from N11, ack stops here
        ack = msg.createAck("", ['g1'])
        ack._receivedon = self.transports[1]
        ack.src = "n11"
        out = self.router.processFWD(
            [ack], time.time())  # no group routing, only node routing
        self.assertEquals(self.router.ackHolds[key]['g1'].keys(),
                          [2])  # nothing left on transport 1 for g1
        self.assertEquals(0, len(out))

        # from N21, ack passes with n21 but no groups
        ack = msg.createAck("n21", ['g1'])
        ack.src = "n21"
        ack._receivedon = self.transports[2]
        out = self.router.processFWD([ack], time.time())
        self.assertEquals(self.router.ackHolds[key]['g1'][2], set(['n22']))
        self.assertEquals(1, len(out))
        self.assertEquals("n21", out[0].data)

        # from N22, ack passes with g1
        ack = msg.createAck("", ['g1', 'g3'])
        ack.src = "n22"
        ack._receivedon = self.transports[2]
        out = self.router.processFWD([ack], time.time())
        self.assertEquals(self.router.ackHolds[key].keys(),
                          ['g3'])  # g1 complete
        self.assertEquals(self.router.ackHolds[key]['g3'].keys(),
                          [1])  # g3 is still active on transport 1
        self.assertEquals(1, len(out))
        self.assertEquals(",g1", out[0].data)

        # from N12, ack passes with g2
        ack = msg.createAck("", ['g3'])
        ack.src = "n12"
        ack._receivedon = self.transports[1]
        out = self.router.processFWD([ack], time.time())
        self.assertEquals(self.router.ackHolds.keys(), [])  # all complete
        self.assertEquals(1, len(out))
        self.assertEquals(",g3", out[0].data)
	def test_routeNone(self):
		""" Test message without any groups """
		msg = MAGIMessage(nodes=["somenode"])
		msg._receivedon = self.transports[1]
		fds = self.router.routeMessage(msg)
		self.assertEqual(fds, set([]))
	def _incomingGroupList(self, fd, src, grouplist):
		self.neighbors[fd][src] = set(grouplist)
		request = { 'set': grouplist, 'count': len(self.neighbors[fd][src]), 'checksum': listChecksum(self.neighbors[fd][src]) }
		msg = MAGIMessage(src=src, contenttype=MAGIMessage.YAML, docks=[GroupRouter.DOCK], data=yaml.safe_dump(request))
		msg._receivedon = self.transports[fd]
		self.router.processIN([msg], time.time())
	def _incomingGroupResend(self, fd, src):
		request = { 'resend': True }
		msg = MAGIMessage(src=src, contenttype=MAGIMessage.YAML, docks=[GroupRouter.DOCK], data=yaml.safe_dump(request))
		msg._receivedon = self.transports[fd]
		self.router.processIN([msg], time.time())
	def test_routeAll(self):
		""" Test route with a group ALL """
		msg = MAGIMessage(groups=[GroupRouter.ALLNODES])
		msg._receivedon = self.transports[1]
		fds = self.router.routeMessage(msg)
		self.assertEqual(fds, set([0,1,2]))