コード例 #1
0
def test_get_nodes():
    # Create contact plan object
    cp = ContactPlan(1000.1, 42.42)

    # Add nodes and contacts (both resulting in adding nodes to set)
    cp.add_node('testnode1')
    cp.add_contact('testnode2', 'testnode3', 0.0, 1.0)

    # Verify that all nodes were added properly
    assert cp.get_nodes() == ['testnode1', 'testnode2', 'testnode3']
コード例 #2
0
ファイル: DtnS.py プロジェクト: Mathnar/Tesi
def main():
    """Simulate basic scenario."""
    # Create simulation environment
    simulator = Simulator()

    # Generate empy contact plan
    contact_plan = ContactPlan(1, 50)

    # Add a single contact from node_a to node_b from 0s to 10s to the plan
    contact_plan.add_contact('node_a', 'node_b', 0, 10000)

    # Convert contact plan to contact graph
    contact_graph = ContactGraph(contact_plan)

    # Generate contact objects and register them
    for planned_contact in contact_plan.get_contacts():
        # Create a Contact simulation object based on the ContactPlan
        # information
        contact = Contact(planned_contact.from_time, planned_contact.to_time,
                          planned_contact.datarate, planned_contact.from_node,
                          planned_contact.to_node, planned_contact.delay)
        # Register the contact as a generator object in the simulation
        # environment
        simulator.register_contact(contact)

    # Generate node objects and register them
    for planned_node in contact_plan.get_nodes():
        # Generate contact list of node
        contact_list = contact_plan.get_outbound_contacts_of_node(planned_node)
        # Create a dict that maps the contact identifiers to Contact simulation
        # objects
        contact_dict = simulator.get_contact_dict(contact_list)
        # Create a node simulation object
        SimpleCGRNode(planned_node, contact_dict, cgr_basic.cgr, contact_graph,
                      simulator, [])

    # Generate packet generator(s) and register them
    generator = BatchPacketGenerator(
        1,  # Create one packet
        1000,  # Packet Size: 1000 Bytes
        ['node_a'],  # From 'node_a'
        ['node_b'],  # To 'node_b'
        [0])  # At simulation time 0s
    # Register the generator as a generator object in the simulation
    # environment
    simulator.register_generator(generator)

    # Run the simulation for 20 seconds (20000 ms)
    simulator.run_simulation(20000)
コード例 #3
0
def run_simulation(algorithm, source_list, destination_list):
    """Performs a simulation with a certain algorithm."""

    # Create simulation environment
    simulator = Simulator()

    # Generate contact plan from provided json file
    contact_plan = ContactPlan(1, 100, "tests/resources/tvg_g10_s10.json")

    # Convert contact plan to contact graph
    contact_graph = ContactGraph(contact_plan)

    # Create monitoring instance
    monitor = ReceptionMonitor(simulator.env)
    simulator.register_monitor(monitor)

    # Generate contact objects and register them
    for planned_contact in contact_plan.get_contacts():
        contact = Contact(planned_contact.from_time, planned_contact.to_time,
                          planned_contact.datarate, planned_contact.from_node,
                          planned_contact.to_node, planned_contact.delay)
        simulator.register_contact(contact)

    # Generate node objects and register them
    for planned_node in contact_plan.get_nodes():
        contact_list = contact_plan.get_outbound_contacts_of_node(planned_node)
        contact_dict = simulator.get_contact_dict(contact_list)
        SimpleCGRNode(planned_node, contact_dict, algorithm, contact_graph,
                      simulator, [])

    # Generate packet generator(s) and register them
    generator = BatchPacketGenerator(200, 10000, source_list, destination_list,
                                     [10.0])
    simulator.register_generator(generator)

    # Run the simulation
    simulator.run_simulation(48000000)

    # Return the monitored results
    return monitor.packet_dict