Example #1
0
    def test_dsr_protocol_manager(self):
        dsr_protocol = DsrProtocolManager({'origin_ids':["1", "2"], 'destiny_ids':["3"], 'number_of_routes_to_find':2})

        message_broker = MessageBroker()
        event_broker = EventBroker()

        dsr_protocol.manage(time=10, all_nodes=[], message_broker=message_broker, event_broker=event_broker)
        self.assertEqual(len(event_broker.asynchronous_events), 1)

        event = event_broker.get_asynchronous_event()
        self.assertEqual(event.arguments['origin_id'], "1")
        self.assertEqual(event.arguments['destiny_id'], "3")

        dsr_protocol.manage(time=11, all_nodes=[], message_broker=message_broker, event_broker=event_broker)
        self.assertEqual(len(event_broker.asynchronous_events), 1)

        event = event_broker.get_asynchronous_event()
        self.assertEqual(event.arguments['origin_id'], "2")
        self.assertEqual(event.arguments['destiny_id'], "3")

        dsr_protocol.manage(time=10, all_nodes=[], message_broker=message_broker, event_broker=event_broker)
        self.assertEqual(len(event_broker.asynchronous_events), 0)
Example #2
0
    def test_dsr_routes_to_find(self):
        dsr_protocol = DsrProtocolManager({'origin_ids':["1", "2"], 'destiny_ids':["3"], 'number_of_routes_to_find':4})

        message_broker = MessageBroker()
        event_broker = EventBroker()

        dsr_protocol.manage(time=10, all_nodes=[], message_broker=message_broker, event_broker=event_broker)
        self.assertEqual(len(event_broker.asynchronous_events), 1)

        dsr_protocol.manage(time=11, all_nodes=[], message_broker=message_broker, event_broker=event_broker)
        self.assertEqual(len(event_broker.asynchronous_events), 2)

        dsr_protocol.manage(time=10, all_nodes=[], message_broker=message_broker, event_broker=event_broker)
        self.assertEqual(len(event_broker.asynchronous_events), 3)

        dsr_protocol.manage(time=10, all_nodes=[], message_broker=message_broker, event_broker=event_broker)
        self.assertEqual(len(event_broker.asynchronous_events), 4)

        dsr_protocol.manage(time=10, all_nodes=[], message_broker=message_broker, event_broker=event_broker)
        self.assertEqual(len(event_broker.asynchronous_events), 4)