Beispiel #1
0
 def setUpClass(cls):
     # set up topology used for all traffic matrix tests
     cls.G = fnss.glp_topology(n=50, m=1, m0=10, p=0.2, beta=-2, seed=1)
     fnss.set_capacities_random(cls.G, {
         10: 0.5,
         20: 0.3,
         40: 0.2
     },
                                capacity_unit='Mbps')
     fnss.set_delays_constant(cls.G, 2, delay_unit='ms')
     fnss.set_weights_inverse_capacity(cls.G)
     for node in [2, 4, 6]:
         fnss.add_stack(cls.G, node, 'tcp', {
             'protocol': 'cubic',
             'rcvwnd': 1024
         })
     for node in [2, 4]:
         fnss.add_application(cls.G, node, 'client', {
             'rate': 100,
             'user-agent': 'fnss'
         })
     fnss.add_application(cls.G, 2, 'server', {
         'port': 80,
         'active': True,
         'user-agent': 'fnss'
     })
Beispiel #2
0
 def test_add_get_remove_applications(self):
     for v in self.topo.nodes_iter():
         self.assertEqual([], fnss.get_application_names(self.topo, v))
     fnss.add_application(self.topo, 10, self.app_1_name, self.app_1_props)
     self.assertEqual([self.app_1_name],
                      fnss.get_application_names(self.topo, 10))
     self.assertEqual(self.app_1_props,
                      fnss.get_application_properties(self.topo, 10, 
                                                 self.app_1_name))
     fnss.add_application(self.topo, 10, self.app_1_name, self.app_2_props)
     self.assertEqual([self.app_1_name],
                      fnss.get_application_names(self.topo, 10))
     self.assertEqual(self.app_2_props,
                      fnss.get_application_properties(self.topo, 10,
                                                 self.app_1_name))
     fnss.add_application(self.topo, 10, self.app_2_name, self.app_2_props)
     self.assertEqual(set([self.app_1_name, self.app_2_name]),
                      set(fnss.get_application_names(self.topo, 10)))
     self.assertEqual(self.app_2_props,
                      fnss.get_application_properties(self.topo, 10,
                                                 self.app_1_name))
     self.assertEqual(self.app_2_props,
                      fnss.get_application_properties(self.topo, 10,
                                                 self.app_2_name))
     fnss.remove_application(self.topo, 10, self.app_2_name)
     self.assertEqual([self.app_1_name],
                      fnss.get_application_names(self.topo, 10))
     fnss.remove_application(self.topo, 10, self.app_1_name)
     self.assertEqual([], fnss.get_application_names(self.topo, 10))
     fnss.add_application(self.topo, 10, self.app_1_name, self.app_1_props)
     fnss.add_application(self.topo, 10, self.app_2_name, self.app_1_props)
     fnss.remove_application(self.topo, 10)
     self.assertEqual([], fnss.get_application_names(self.topo, 10))
Beispiel #3
0
 def test_add_get_remove_applications(self):
     for v in self.topo.nodes():
         self.assertEqual([], fnss.get_application_names(self.topo, v))
     fnss.add_application(self.topo, 10, self.app_1_name, self.app_1_props)
     self.assertEqual([self.app_1_name],
                      fnss.get_application_names(self.topo, 10))
     self.assertEqual(self.app_1_props,
                      fnss.get_application_properties(self.topo, 10,
                                                 self.app_1_name))
     fnss.add_application(self.topo, 10, self.app_1_name, self.app_2_props)
     self.assertEqual([self.app_1_name],
                      fnss.get_application_names(self.topo, 10))
     self.assertEqual(self.app_2_props,
                      fnss.get_application_properties(self.topo, 10,
                                                 self.app_1_name))
     fnss.add_application(self.topo, 10, self.app_2_name, self.app_2_props)
     self.assertEqual(set([self.app_1_name, self.app_2_name]),
                      set(fnss.get_application_names(self.topo, 10)))
     self.assertEqual(self.app_2_props,
                      fnss.get_application_properties(self.topo, 10,
                                                 self.app_1_name))
     self.assertEqual(self.app_2_props,
                      fnss.get_application_properties(self.topo, 10,
                                                 self.app_2_name))
     fnss.remove_application(self.topo, 10, self.app_2_name)
     self.assertEqual([self.app_1_name],
                      fnss.get_application_names(self.topo, 10))
     fnss.remove_application(self.topo, 10, self.app_1_name)
     self.assertEqual([], fnss.get_application_names(self.topo, 10))
     fnss.add_application(self.topo, 10, self.app_1_name, self.app_1_props)
     fnss.add_application(self.topo, 10, self.app_2_name, self.app_1_props)
     fnss.remove_application(self.topo, 10)
     self.assertEqual([], fnss.get_application_names(self.topo, 10))
Beispiel #4
0
 def test_clear_applications(self):
     for v in self.topo.nodes():
         fnss.add_application(self.topo, v,
                              self.app_1_name, self.app_1_props)
         fnss.add_application(self.topo, v,
                              self.app_2_name, self.app_2_props)
     fnss.clear_applications(self.topo)
     for v in self.topo.nodes():
         self.assertEqual([], fnss.get_application_names(self.topo, v))
Beispiel #5
0
 def test_clear_applications(self):
     for v in self.topo.nodes():
         fnss.add_application(self.topo, v,
                              self.app_1_name, self.app_1_props)
         fnss.add_application(self.topo, v,
                              self.app_2_name, self.app_2_props)
     fnss.clear_applications(self.topo)
     for v in self.topo.nodes():
         self.assertEqual([], fnss.get_application_names(self.topo, v))
Beispiel #6
0
 def setUpClass(cls):
     # set up topology used for all traffic matrix tests
     cls.G = fnss.glp_topology(n=50, m=1, m0=10, p=0.2, beta=-2, seed=1)
     fnss.set_capacities_random(cls.G, {10: 0.5, 20: 0.3, 40: 0.2}, 
                           capacity_unit='Mbps')
     fnss.set_delays_constant(cls.G, 2, delay_unit='ms')
     fnss.set_weights_inverse_capacity(cls.G)
     for node in [2, 4, 6]:
         fnss.add_stack(cls.G, node, 'tcp', 
                       {'protocol': 'cubic', 'rcvwnd': 1024})
     for node in [2, 4]:
         fnss.add_application(cls.G, node, 'client', 
                             {'rate': 100, 'user-agent': 'fnss'})
     fnss.add_application(cls.G, 2, 'server', 
                        {'port': 80, 'active': True, 'user-agent': 'fnss'})
Beispiel #7
0
# set capacity of 10 Mbps in edge links and 40 Mbps in core links
fnss.set_capacities_constant(topology, 10, 'Mbps', edge_links)
fnss.set_capacities_constant(topology, 40, 'Mbps', core_links)

# Now we deploy a traffic sources on right bell and traffic receivers on left
# bell
node_types = nx.get_node_attributes(topology, 'type')
left_nodes = [
    nodes for nodes in node_types if node_types[nodes] == 'left_bell'
]
right_nodes = [
    nodes for nodes in node_types if node_types[nodes] == 'right_bell'
]

for node in left_nodes:
    fnss.add_application(topology, node, 'receiver', {})

for node in right_nodes:
    fnss.add_application(topology, node, 'source', {})


# now create a function that generate events
def rand_request(source_nodes, receiver_nodes):
    source = random.choice(source_nodes)
    receiver = random.choice(receiver_nodes)
    return {'source': source, 'receiver': receiver}


event_schedule = fnss.poisson_process_event_schedule(
    avg_interval=50,  # 50 ms
    t_start=0,  # starts at 0
Beispiel #8
0
=======================

This example shows how to generate a topology (a line in this case) and export
it to the ns-2 simulator
"""
import fnss

# create a line topology with 10 nodes
topology = fnss.line_topology(10)

# assign capacity of 10 Mbps to each link
fnss.set_capacities_constant(topology, 10, 'Mbps')

# assign delay of 2 ms to each link
fnss.set_delays_constant(topology, 2, 'ms')

# set buffers in each node (use packets, bytes not supported by ns-2)
fnss.set_buffer_sizes_bw_delay_prod(topology, 'packets', 1500)

# Add FTP application to first and last node of the line
tcp_stack_props = {'class': 'Agent/TCP', 'class_': 2, 'fid_': 1}
fnss.add_stack(topology, 0, 'tcp', tcp_stack_props)
fnss.add_stack(topology, 9, 'tcp', tcp_stack_props)

ftp_app_props = {'class': 'Application/FTP', 'type': 'FTP'}
fnss.add_application(topology, 0, 'ftp', ftp_app_props)
fnss.add_application(topology, 9, 'ftp', ftp_app_props)

# export topology to a Tcl script for ns-2
fnss.to_ns2(topology, 'ns2-script.tcl', stacks=True)
Beispiel #9
0
fnss.set_delays_constant(topology, 2, 'ms', core_links)

# set capacity of 10 Mbps in edge links and 40 Mbps in core links
fnss.set_capacities_constant(topology, 10, 'Mbps', edge_links)
fnss.set_capacities_constant(topology, 40, 'Mbps', core_links)

# Now we deploy a traffic sources on right bell and traffic receivers on left
# bell
node_types = nx.get_node_attributes(topology, 'type')
left_nodes = [nodes for nodes in node_types 
              if node_types[nodes] == 'left_bell']
right_nodes = [nodes for nodes in node_types 
              if node_types[nodes] == 'right_bell']

for node in left_nodes:
    fnss.add_application(topology, node, 'receiver', {})

for node in right_nodes:
    fnss.add_application(topology, node, 'source', {})
    
# now create a function that generate events
def rand_request(source_nodes, receiver_nodes):
    source = random.choice(source_nodes)
    receiver = random.choice(receiver_nodes)
    return {'source': source, 'receiver': receiver}

event_schedule = fnss.poisson_process_event_schedule(
                        avg_interval=50,                # 50 ms
                        t_start=0,                      # starts at 0
                        duration= 10*1000,              # 10 sec
                        t_unit='ms',                    # milliseconds