Пример #1
0
 def __init__(self, node_id=None, location=None, node_parameters=None, protocol_manager=None):
     """
     Constructor.
     node_id - The node unique identifier
     location - The location of the node
     node_parameters - Extra parameters passed to the node
     protocol_manager - The protocol manager that manages all DsrNodes
     """
     Node.__init__(self, location=location, node_id=node_id, node_parameters=node_parameters)
     self.protocol_manager = protocol_manager
     self.time_counter = 0
Пример #2
0
    def setUp(self):
        self.node_a = Node(node_id="1")
        self.node_b = Node(node_id="2")
        self.node_c = Node(node_id="3")
        self.few_nodes = {}
        self.many_nodes = {}

        few_nodes_list = Node.generate_nodes(3, Node, node_parameters={}, protocol_manager=None)
        for node in few_nodes_list:
            self.few_nodes[node.id] = node

        many_nodes_list = Node.generate_nodes(300, Node, node_parameters={}, protocol_manager=None)
        for node in many_nodes_list:
            self.many_nodes[node.id] = node

        self.plane_1 = Plane(10, 20)
        self.plane_2 = Plane(30, 30)
Пример #3
0
    def test_broadcast_message(self):
        destination_list = [2]
        node_with_power = Node(node_id="1", location=self.location_a, power=10)

        broadcast_message = BroadcastMessage(sender=node_with_power, emit_location=self.location_a, function_to_call=TestMessages.an_example_function,
                                                     arguments={})

        self.assertEqual(broadcast_message.power, 10)
Пример #4
0
 def __init__(self, node_id=None, location=None, node_parameters=None, protocol_manager=None):
     """
     Constructor.
     node_id - The node unique identifier
     location - The location of the node
     node_parameters - Extra parameters passed to the node
     protocol_manager - The protocol manager that manages all BfgNodes
     """
     Node.__init__(self, location=location, node_id=node_id, node_parameters=node_parameters)
     self.query_id = 0
     self.responded_queries = {}
     self.responded_dsr_queries = []
     self.asked_queries = []
     self.direct_neighbours_ids = []
     self.time_counter = 0
     self.protocol_manager = protocol_manager
     self.queries_completed = []
     self.heat_mem = [bloom.ErbBloomFilter(m=CONST_B, k=CONST_N_HASHES) for x in xrange(CONST_CARD_P)]
     self.tunnel_mem = [bloom.ErbBloomFilter(m=CONST_B, k=CONST_N_HASHES) for x in xrange(CONST_CARD_P)]
    def setUp(self):
        location_a = Location(5, 3)
        node_a = Node(node_id="1", location=location_a)
        arguments_a = {'arg_1': 1, 'arg_2': 2, 'arg_3': 3}
        self.asynchronous_event_1 = AsynchronousEvent(
            node_id=node_a.id,
            function_to_call=self.an_example_function,
            arguments=arguments_a)

        location_b = Location(1, 2)
        node_b = Node(node_id="1", location=location_b)
        arguments_b = {'arg_1': 5, 'arg_2': 4, 'arg_3': 3}
        self.asynchronous_event_2 = AsynchronousEvent(
            node_id=node_b.id,
            function_to_call=self.an_example_function,
            arguments=arguments_b)

        self.simulator_event_1 = SimulatorEvent(arguments=arguments_a)
        self.simulator_event_2 = SimulatorEvent(arguments=arguments_b)

        self.event_broker = EventBroker()
Пример #6
0
    def setUp(self):
        self.location_a = Location(5, 3)
        self.node_a = Node(node_id="1", location=self.location_a)
        self.arguments_a = {'arg_1':1, 'arg_2':2, 'arg_3':3}
        self.message_a = Message(sender=self.node_a, emit_location=self.location_a, \
                                          function_to_call=self.an_example_function, arguments=self.arguments_a)

        self.location_b = Location(1, 2)
        self.message_b = Message(sender=self.node_a, emit_location=self.location_b, \
                                          function_to_call=self.an_example_function, arguments=self.arguments_a)

        self.message_broker = MessageBroker()
Пример #7
0
    def test_direct_message(self):
        node_b = Node(node_id="2", location=self.location_b)
        destination_list = [node_b.id]

        direct_message = DirectMessage(sender=self.node_a, emit_location=self.location_a, function_to_call=self.an_example_function,
                                                     arguments={}, destination_list=destination_list)

        self.assertEqual(direct_message.destination_list, destination_list)

        ret = direct_message.run(all_nodes={self.node_a.id:self.node_a, node_b.id:node_b}, plane=None)

        self.assertFalse(ret['messages'])
        self.assertFalse(ret['asynchronous'])
        self.assertFalse(ret['simulator'])
Пример #8
0
    def __init__(self, simulation_parameters):
        """
        Constructor.

        simulation_parameters - The parameters to be used to run this simulation
        """
        self.type_of_nodes = simulation_parameters.config_p['type_of_nodes']
        self._max_cycles = simulation_parameters.config_p['max_cycles']

        self.number_messages_out = 0
        self.number_messages_in = 0

        self.number_asynchronous_events = 0
        self.number_simulation_events = 0

        self.all_nodes = {}
        self.time = 0

        self.protocol_manager = \
                simulation_parameters.config_p['protocol_manager'](protocol_arguments=simulation_parameters.protocol_p)

        self.event_broker = EventBroker()
        self.message_broker = MessageBroker()

        node_parameters = simulation_parameters.node_p
        type_of_nodes = simulation_parameters.config_p['type_of_nodes']
        events_to_launch = simulation_parameters.config_p['events']

        # If the simulator is generating the plane
        if not 'scenario_file' in simulation_parameters.plane_p:
            generated_nodes = Node.generate_nodes(number_to_generate=simulation_parameters.plane_p['number_of_nodes'], \
                                                  type_of_nodes=type_of_nodes, node_parameters=node_parameters, \
                                                  protocol_manager=self.protocol_manager)
            for node in generated_nodes:
                self.all_nodes[node.id] = node
            self.plane = Plane.generate_plane(all_nodes=self.all_nodes, plane_parameters=simulation_parameters.plane_p)

        # If the simulator is loading the plane from a file
        else:
            (self.all_nodes, self.plane) = Plane.load_plane(plane_parameters=simulation_parameters.plane_p, \
                                                            node_parameters=simulation_parameters.node_p, \
                                                            type_of_nodes=self.type_of_nodes, \
                                                            protocol_manager=self.protocol_manager)
        #Now putt the events to launch in the event broker
        for event in events_to_launch:
            self.event_broker.add_asynchronous_event(event)
Пример #9
0
    def test_node_generation(self):
        generated_nodes = Node.generate_nodes(20, Node, protocol_manager=None)
        self.assertEqual(len(generated_nodes), 20)

        for n in generated_nodes:
            self.assert_(isinstance(n, Node))