예제 #1
0
 def test_static_traffic_matrix_parallel(self):
     # If number of edges is greater than 100, computation is parallelized
     G = fnss.full_mesh_topology(15)
     fnss.set_capacities_constant(G, 10, capacity_unit='Mbps')
     tm = fnss.static_traffic_matrix(G, 10, 8, max_u=0.9)
     self.assertAlmostEqual(0.9, max(fnss.link_loads(G, tm).values()))
     self.assertLessEqual(0, min(fnss.link_loads(G, tm).values()))
예제 #2
0
 def test_to_omnetpp_directed(self):
     t = fnss.DirectedTopology()
     t.add_path([1, 2, 3, 4])
     fnss.set_capacities_constant(t, 10, 'Gbps')
     fnss.set_delays_constant(t, 2, 'us')
     fnss.set_buffer_sizes_constant(t, 20, 'packets')
     fnss.to_omnetpp(t, path.join(TMP_DIR, 'omnetpp-dir.ned'))
예제 #3
0
파일: test_ns2.py 프로젝트: wangxi0414/fnss
 def test_to_ns2_directed(self):
     t = fnss.DirectedTopology()
     t.add_path([1, 2, 3, 4])
     fnss.set_capacities_constant(t, 10, 'Gbps')
     fnss.set_delays_constant(t, 2, 'us')
     fnss.set_buffer_sizes_constant(t, 20, 'packets')
     fnss.to_ns2(t, path.join(TMP_DIR, 'ns2-dir.tcl'), stacks=False)
예제 #4
0
 def test_static_traffic_matrix_parallel(self):
     # If number of edges is greater than 100, computation is parallelized
     G = fnss.full_mesh_topology(15)
     fnss.set_capacities_constant(G, 10, capacity_unit='Mbps')
     tm = fnss.static_traffic_matrix(G, 10, 8, max_u=0.9)
     self.assertAlmostEqual(0.9, max(fnss.link_loads(G, tm).values()))
     self.assertLessEqual(0, min(fnss.link_loads(G, tm).values()))
예제 #5
0
 def test_to_omnetpp_directed(self):
     t = fnss.DirectedTopology()
     t.add_path([1, 2, 3, 4])
     fnss.set_capacities_constant(t, 10, 'Gbps')
     fnss.set_delays_constant(t, 2, 'us')
     fnss.set_buffer_sizes_constant(t, 20, 'packets')
     fnss.to_omnetpp(t, path.join(TMP_DIR, 'omnetpp-dir.ned'))
예제 #6
0
 def test_to_mininet(self):
     t = fnss.Topology()
     t.add_path([1, 2, 3, 4])
     for n in (1, 4):
         t.node[n]['type'] = 'host'
     for n in (2, 3):
         t.node[n]['type'] = 'switch'
     fnss.set_capacities_constant(t, 10, 'Mbps')
     fnss.set_delays_constant(t, 10, 'ms')
     mn_topo = fnss.to_mininet(t, relabel_nodes=False)
     self.assertIsNotNone(mn_topo)
     hosts = mn_topo.hosts()
     switches = mn_topo.switches()
     for h in '1', '4':
         self.assertIn(h, hosts)
     for s in '2', '3':
         self.assertIn(s, switches)
     mn_topo = fnss.to_mininet(t, relabel_nodes=True)
     # Relabeling should be:
     # 1 -> h1
     # 2 -> s1
     # 3 -> s2
     # 4 -> h2
     self.assertIsNotNone(mn_topo)
     hosts = mn_topo.hosts()
     switches = mn_topo.switches()
     for h in 'h1', 'h2':
         self.assertIn(h, hosts)
     for s in 's1', 's2':
         self.assertIn(s, switches)
예제 #7
0
 def test_to_mininet(self):
     t = fnss.Topology()
     t.add_path([1, 2, 3, 4])
     for n in (1, 4):
         t.node[n]['type'] = 'host'
     for n in (2, 3):
         t.node[n]['type'] = 'switch'
     fnss.set_capacities_constant(t, 10, 'Mbps')
     fnss.set_delays_constant(t, 10, 'ms')
     mn_topo = fnss.to_mininet(t, relabel_nodes=False)
     self.assertIsNotNone(mn_topo)
     hosts = mn_topo.hosts()
     switches = mn_topo.switches()
     for h in '1', '4':
         self.assertIn(h, hosts)
     for s in '2', '3':
         self.assertIn(s, switches)
     mn_topo = fnss.to_mininet(t, relabel_nodes=True)
     # Relabeling should be:
     # 1 -> h1
     # 2 -> s1
     # 3 -> s2
     # 4 -> h2
     self.assertIsNotNone(mn_topo)
     hosts = mn_topo.hosts()
     switches = mn_topo.switches()
     for h in 'h1', 'h2':
         self.assertIn(h, hosts)
     for s in 's1', 's2':
         self.assertIn(s, switches)
예제 #8
0
파일: test_ns2.py 프로젝트: ccascone/fnss
 def test_to_ns2_directed(self):
     t = fnss.DirectedTopology()
     t.add_path([1,2,3,4])
     fnss.set_capacities_constant(t, 10, 'Gbps')
     fnss.set_delays_constant(t, 2, 'us')
     fnss.set_buffer_sizes_constant(t, 20, 'packets')
     fnss.to_ns2(t, path.join(TMP_DIR,'ns2-dir.tcl'), stacks=False)
예제 #9
0
 def test_buffer_sizes_bw_delay_prod_no_return_path(self):
     topo = fnss.DirectedTopology()
     topo.add_edge(1, 2, weight=1)
     topo.add_edge(1, 3, weight=1)
     topo.add_edge(3, 2, weight=1)
     fnss.set_capacities_constant(topo, 10)
     fnss.set_delays_constant(topo, 2)
     self.assertRaises(ValueError, fnss.set_buffer_sizes_bw_delay_prod, topo)
예제 #10
0
    def test_link_loads_ecmp(self):
        topo = fnss.ring_topology(5)
        topo.add_edge(1, 3)
        fnss.set_capacities_constant(topo, 100, capacity_unit='Mbps')
        tm = fnss.TrafficMatrix(volume_unit='Mbps')
        tm.add_flow(0, 1, 20)
        tm.add_flow(1, 0, 30)
        tm.add_flow(0, 2, 40)
        tm.add_flow(1, 4, 70)
        rm = {
            0: {
                0: [[0]],
                1: [[0, 1]],
                2: [[0, 1, 2]],
                3: [[0, 1, 3], [0, 4, 3]],
                4: [[0, 4]]
            },
            1: {
                0: [[1, 0]],
                1: [[1]],
                2: [[1, 2]],
                3: [[1, 3]],
                4: [[1, 3, 4], [1, 0, 4]]
            },
            2: {
                0: [[2, 1, 0]],
                1: [[2, 1]],
                2: [[2]],
                3: [[2, 3]],
                4: [[2, 3, 4]]
            },
            3: {
                0: [[3, 1, 0], [3, 4, 0]],
                1: [[3, 1]],
                2: [[3, 2]],
                3: [[3]],
                4: [[3, 4]]
            },
            4: {
                0: [[4, 0]],
                1: [[4, 0, 1], [4, 3, 1]],
                2: [[4, 3, 2]],
                3: [[4, 3]],
                4: [[4]]
            }
        }

        load = fnss.link_loads(topo, tm, routing_matrix=rm, ecmp=True)
        self.assertAlmostEqual(0.6, load[(0, 1)])
        self.assertAlmostEqual(0.65, load[(1, 0)])
        self.assertAlmostEqual(0.4, load[(1, 2)])
        self.assertAlmostEqual(0.0, load[(2, 1)])
        self.assertAlmostEqual(0.35, load[(0, 4)])
        self.assertAlmostEqual(0.35, load[(3, 4)])
        self.assertAlmostEqual(0.0, load[(4, 3)])
        self.assertAlmostEqual(0.0, load[(4, 0)])
        self.assertAlmostEqual(0.0, load[(2, 1)])
        self.assertAlmostEqual(0.0, load[(2, 3)])
예제 #11
0
 def test_validate_traffic_matrix_diff_units(self):
     topo = fnss.line_topology(2)
     fnss.set_capacities_constant(topo, 1, capacity_unit='Gbps')
     valid_tm = fnss.TrafficMatrix(volume_unit='Mbps')
     valid_tm.add_flow(0, 1, 999)
     self.assertTrue(fnss.validate_traffic_matrix(topo, valid_tm, validate_load=True))
     invalid_tm = fnss.TrafficMatrix(volume_unit='Mbps')
     invalid_tm.add_flow(0, 1, 1001)
     self.assertFalse(fnss.validate_traffic_matrix(topo, invalid_tm, validate_load=True))
예제 #12
0
 def test_validate_traffic_matrix_diff_units(self):
     topo = fnss.line_topology(2)
     fnss.set_capacities_constant(topo, 1, capacity_unit='Gbps')
     valid_tm = fnss.TrafficMatrix(volume_unit='Mbps')
     valid_tm.add_flow(0, 1, 999)
     self.assertTrue(fnss.validate_traffic_matrix(topo, valid_tm, validate_load=True))
     invalid_tm = fnss.TrafficMatrix(volume_unit='Mbps')
     invalid_tm.add_flow(0, 1, 1001)
     self.assertFalse(fnss.validate_traffic_matrix(topo, invalid_tm, validate_load=True))
예제 #13
0
    def test_link_loads_ecmp(self):
        topo = fnss.ring_topology(5)
        topo.add_edge(1, 3)
        fnss.set_capacities_constant(topo, 100, capacity_unit='Mbps')
        tm = fnss.TrafficMatrix(volume_unit='Mbps')
        tm.add_flow(0, 1, 20)
        tm.add_flow(1, 0, 30)
        tm.add_flow(0, 2, 40)
        tm.add_flow(1, 4, 70)
        rm = {0 :
                { 0: [[0]],
                  1: [[0, 1]],
                  2: [[0, 1, 2]],
                  3: [[0, 1, 3], [0, 4, 3]],
                  4: [[0, 4]]
                },
              1 :
                { 0: [[1, 0]],
                  1: [[1]],
                  2: [[1, 2]],
                  3: [[1, 3]],
                  4: [[1, 3, 4], [1, 0, 4]]
                },
              2 :
                { 0: [[2, 1, 0]],
                  1: [[2, 1]],
                  2: [[2]],
                  3: [[2, 3]],
                  4: [[2, 3, 4]]
                },
              3 :
                { 0: [[3, 1, 0], [3, 4, 0]],
                  1: [[3, 1]],
                  2: [[3, 2]],
                  3: [[3]],
                  4: [[3, 4]]
                },
              4 :
                { 0: [[4, 0]],
                  1: [[4, 0, 1], [4, 3, 1]],
                  2: [[4, 3, 2]],
                  3: [[4, 3]],
                  4: [[4]]
                }}

        load = fnss.link_loads(topo, tm, routing_matrix=rm, ecmp=True)
        self.assertAlmostEqual(0.6, load[(0, 1)])
        self.assertAlmostEqual(0.65, load[(1, 0)])
        self.assertAlmostEqual(0.4, load[(1, 2)])
        self.assertAlmostEqual(0.0, load[(2, 1)])
        self.assertAlmostEqual(0.35, load[(0, 4)])
        self.assertAlmostEqual(0.35, load[(3, 4)])
        self.assertAlmostEqual(0.0, load[(4, 3)])
        self.assertAlmostEqual(0.0, load[(4, 0)])
        self.assertAlmostEqual(0.0, load[(2, 1)])
        self.assertAlmostEqual(0.0, load[(2, 3)])
예제 #14
0
 def test_capacities_constant(self):
     odd_links = [(u, v) for (u, v) in self.topo.edges()
                  if (u + v) % 2 == 1]
     even_links = [(u, v) for (u, v) in self.topo.edges()
                   if (u + v) % 2 == 0]
     fnss.set_capacities_constant(self.topo, 2, 'Mbps', odd_links)
     fnss.set_capacities_constant(self.topo, 5000, 'Kbps', even_links)
     self.assertEqual('Mbps', self.topo.graph['capacity_unit'])
     self.assertTrue(all(self.topo.edge[u][v]['capacity'] in [2, 5] 
                      for (u, v) in self.topo.edges_iter()))
예제 #15
0
 def test_buffer_sizes_bw_delay_prod_unused_links(self):
     topo = fnss.Topology()
     topo.add_edge(1, 2, weight=100)
     topo.add_edge(2, 3, weight=1)
     topo.add_edge(3, 1, weight=1)
     fnss.set_capacities_constant(topo, 10)
     fnss.set_delays_constant(topo, 2)
     fnss.set_buffer_sizes_bw_delay_prod(topo)
     self.assertTrue(all((topo.adj[u][v]['buffer'] is not None
                      for (u, v) in topo.edges())))
예제 #16
0
 def test_fan_in_out_capacities_directed(self):
     dir_topology = fnss.DirectedTopology()
     dir_topology.add_edge(0, 1)
     dir_topology.add_edge(1, 0)
     dir_topology.add_edge(1, 2)
     dir_topology.add_edge(3, 2)
     fnss.set_capacities_constant(dir_topology, 10, 'Mbps')
     in_cap, out_cap = fnss.fan_in_out_capacities(dir_topology)
     self.assertEqual({0: 10, 1: 10, 2: 20, 3: 0}, in_cap)
     self.assertEqual({0: 10, 1: 20, 2: 0, 3: 10}, out_cap)
예제 #17
0
 def test_capacities_constant(self):
     odd_links = [(u, v) for (u, v) in self.topo.edges()
                  if (u + v) % 2 == 1]
     even_links = [(u, v) for (u, v) in self.topo.edges()
                   if (u + v) % 2 == 0]
     fnss.set_capacities_constant(self.topo, 2, 'Mbps', odd_links)
     fnss.set_capacities_constant(self.topo, 5000, 'Kbps', even_links)
     self.assertEqual('Mbps', self.topo.graph['capacity_unit'])
     self.assertTrue(all(self.topo.edge[u][v]['capacity'] in [2, 5] 
                      for (u, v) in self.topo.edges_iter()))
예제 #18
0
 def test_fan_in_out_capacities_directed(self):
     dir_topology = fnss.DirectedTopology()
     dir_topology.add_edge(0, 1)
     dir_topology.add_edge(1, 0)
     dir_topology.add_edge(1, 2)
     dir_topology.add_edge(3, 2)
     fnss.set_capacities_constant(dir_topology, 10, 'Mbps')
     in_cap, out_cap = fnss.fan_in_out_capacities(dir_topology)
     self.assertEquals({0: 10, 1: 10, 2: 20, 3: 0}, in_cap)
     self.assertEquals({0: 10, 1: 20, 2: 0, 3: 10}, out_cap)
예제 #19
0
 def test_buffers_size_link_bandwidth_default_size(self):
     topo = fnss.line_topology(4)
     fnss.set_capacities_constant(topo, 8, 'Mbps', [(0, 1)])
     fnss.set_capacities_constant(topo, 16, 'Mbps', [(1, 2)])
     fnss.set_buffer_sizes_link_bandwidth(topo, buffer_unit='bytes', default_size=10)
     self.assertEquals(topo.graph['buffer_unit'], 'bytes')
     self.assertEquals(topo.adj[0][1]['buffer'], 1000000)
     self.assertEquals(topo.adj[1][2]['buffer'], 2000000)
     self.assertEquals(topo.adj[2][3]['buffer'], 10)
     fnss.clear_buffer_sizes(topo)
     self.assertTrue('capacity' not in topo.adj[2][3])
     self.assertRaises(ValueError, fnss.set_buffer_sizes_link_bandwidth, topo)
예제 #20
0
 def test_validate_traffic_matrix(self):
     topology = fnss.DirectedTopology()
     topology.add_path([1, 2, 3])
     topology.add_path([3, 2, 1])
     topology.add_edge(3, 4)
     fnss.set_capacities_constant(topology, 1, 'Mbps')
     flows_valid_load = {1: {3: 0.4}, 2: {4: 0.3}}
     flows_invalid_load = {1: {3: 0.4}, 2: {4: 0.7}}
     flows_invalid_routes = {4: {1: 0.4}}
     flows_invalid_pairs = {5: {2: 0.1}}
     self.assertTrue(
         fnss.validate_traffic_matrix(topology,
                                      fnss.TrafficMatrix(
                                          'Mbps', flows_valid_load),
                                      validate_load=False))
     self.assertTrue(
         fnss.validate_traffic_matrix(topology,
                                      fnss.TrafficMatrix(
                                          'Mbps', flows_valid_load),
                                      validate_load=True))
     self.assertTrue(
         fnss.validate_traffic_matrix(topology,
                                      fnss.TrafficMatrix(
                                          'Mbps', flows_invalid_load),
                                      validate_load=False))
     self.assertFalse(
         fnss.validate_traffic_matrix(topology,
                                      fnss.TrafficMatrix(
                                          'Mbps', flows_invalid_load),
                                      validate_load=True))
     self.assertFalse(
         fnss.validate_traffic_matrix(topology,
                                      fnss.TrafficMatrix(
                                          'Mbps', flows_invalid_routes),
                                      validate_load=False))
     self.assertFalse(
         fnss.validate_traffic_matrix(topology,
                                      fnss.TrafficMatrix(
                                          'Mbps', flows_invalid_routes),
                                      validate_load=True))
     self.assertFalse(
         fnss.validate_traffic_matrix(topology,
                                      fnss.TrafficMatrix(
                                          'Mbps', flows_invalid_pairs),
                                      validate_load=False))
     self.assertFalse(
         fnss.validate_traffic_matrix(topology,
                                      fnss.TrafficMatrix(
                                          'Mbps', flows_invalid_pairs),
                                      validate_load=True))
예제 #21
0
 def test_link_loads(self):
     topo = fnss.ring_topology(5)
     fnss.set_capacities_constant(topo, 100, capacity_unit='Mbps')
     tm = fnss.TrafficMatrix(volume_unit='Mbps')
     tm.add_flow(0, 1, 20)
     tm.add_flow(1, 0, 30)
     tm.add_flow(0, 2, 40)
     tm.add_flow(1, 4, 70)
     tm.add_flow(4, 2, 50)
     load = fnss.link_loads(topo, tm)
     self.assertAlmostEqual(0.6, load[(0, 1)])
     self.assertAlmostEqual(1.0, load[(1, 0)])
     self.assertAlmostEqual(0.4, load[(1, 2)])
     self.assertAlmostEqual(0.0, load[(2, 1)])
     self.assertAlmostEqual(0.7, load[(0, 4)])
     self.assertAlmostEqual(0.5, load[(4, 3)])
예제 #22
0
 def test_link_loads(self):
     topo = fnss.ring_topology(5)
     fnss.set_capacities_constant(topo, 100, capacity_unit='Mbps')
     tm = fnss.TrafficMatrix(volume_unit='Mbps')
     tm.add_flow(0, 1, 20)
     tm.add_flow(1, 0, 30)
     tm.add_flow(0, 2, 40)
     tm.add_flow(1, 4, 70)
     tm.add_flow(4, 2, 50)
     load = fnss.link_loads(topo, tm)
     self.assertAlmostEqual(0.6, load[(0, 1)])
     self.assertAlmostEqual(1.0, load[(1, 0)])
     self.assertAlmostEqual(0.4, load[(1, 2)])
     self.assertAlmostEqual(0.0, load[(2, 1)])
     self.assertAlmostEqual(0.7, load[(0, 4)])
     self.assertAlmostEqual(0.5, load[(4, 3)])
예제 #23
0
파일: test_mn.py 프로젝트: brucespang/fnss
 def test_to_mininet(self):
     t = fnss.Topology()
     t.add_path([1, 2, 3, 4])
     for n in (1, 4):
         t.node[n]['type'] = 'host'
     for n in (2, 3):
         t.node[n]['type'] = 'switch'
     fnss.set_capacities_constant(t, 10, 'Mbps')
     fnss.set_delays_constant(t, 10, 'ms')
     mn_topo = fnss.to_mininet(t)
     self.assertIsNotNone(mn_topo)
     hosts = mn_topo.hosts()
     switches = mn_topo.switches()
     for h in '1', '4':
         self.assertIn(h, hosts)
     for s in '2', '3':
         self.assertIn(s, switches)
예제 #24
0
 def test_validate_traffic_matrix(self):
     topology = fnss.DirectedTopology()
     topology.add_path([1, 2, 3])
     topology.add_path([3, 2, 1])
     topology.add_edge(3, 4)
     fnss.set_capacities_constant(topology, 1, 'Mbps')
     flows_valid_load = {1: {3: 0.4}, 2: {4: 0.3}}
     flows_invalid_load = {1: {3: 0.4}, 2: {4: 0.7}}
     flows_invalid_routes = {4: {1: 0.4}}
     flows_invalid_pairs = {5: {2: 0.1}}
     self.assertTrue(fnss.validate_traffic_matrix(topology, fnss.TrafficMatrix('Mbps', flows_valid_load), validate_load=False))
     self.assertTrue(fnss.validate_traffic_matrix(topology, fnss.TrafficMatrix('Mbps', flows_valid_load), validate_load=True))
     self.assertTrue(fnss.validate_traffic_matrix(topology, fnss.TrafficMatrix('Mbps', flows_invalid_load), validate_load=False))
     self.assertFalse(fnss.validate_traffic_matrix(topology, fnss.TrafficMatrix('Mbps', flows_invalid_load), validate_load=True))
     self.assertFalse(fnss.validate_traffic_matrix(topology, fnss.TrafficMatrix('Mbps', flows_invalid_routes), validate_load=False))
     self.assertFalse(fnss.validate_traffic_matrix(topology, fnss.TrafficMatrix('Mbps', flows_invalid_routes), validate_load=True))
     self.assertFalse(fnss.validate_traffic_matrix(topology, fnss.TrafficMatrix('Mbps', flows_invalid_pairs), validate_load=False))
     self.assertFalse(fnss.validate_traffic_matrix(topology, fnss.TrafficMatrix('Mbps', flows_invalid_pairs), validate_load=True))
예제 #25
0
 def test_base_topology_class(self):
     weight = 2
     capacity = 3
     delay = 4
     buffer_size = 5
     topology = fnss.Topology()
     topology.add_path([1, 2, 3])
     fnss.set_weights_constant(topology, weight)
     fnss.set_capacities_constant(topology, capacity)
     fnss.set_delays_constant(topology, delay)
     fnss.set_buffer_sizes_constant(topology, buffer_size)
     weights = topology.weights()
     capacities = topology.capacities()
     delays = topology.delays()
     buffer_sizes = topology.buffers()
     for e in topology.edges_iter():
         self.assertEqual(weight, weights[e])
         self.assertEqual(capacity, capacities[e])
         self.assertEqual(delay, delays[e])
         self.assertEqual(buffer_size, buffer_sizes[e])
예제 #26
0
 def test_base_topology_class(self):
     weight = 2
     capacity = 3
     delay = 4
     buffer_size = 5
     topology = fnss.Topology()
     topology.add_path([1, 2, 3])
     fnss.set_weights_constant(topology, weight)
     fnss.set_capacities_constant(topology, capacity)
     fnss.set_delays_constant(topology, delay)
     fnss.set_buffer_sizes_constant(topology, buffer_size)
     weights = topology.weights()
     capacities = topology.capacities()
     delays = topology.delays()
     buffer_sizes = topology.buffers()
     for e in topology.edges():
         self.assertEqual(weight, weights[e])
         self.assertEqual(capacity, capacities[e])
         self.assertEqual(delay, delays[e])
         self.assertEqual(buffer_size, buffer_sizes[e])
예제 #27
0
# this return a dictionary of egdes and value of attribute type
# This function is provided by the NetworkX library.
# Since FNSS Topology and DirecteedTopology objects inherit from NetworkX's
# Graph and DiGraph, respectively, NetworkX functions can be used in FNSS too.
link_types = nx.get_edge_attributes(topology, 'type')
core_links = [links for links in link_types if link_types[links] == 'core']
edge_links = [links for links in link_types 
              if link_types[links] == 'right_bell' 
              or link_types[links] == 'left_bell']

# set delay equal to 1 ms in edge links and equal to 2 ms in core links
fnss.set_delays_constant(topology, 1, 'ms', edge_links)
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', {})
예제 #28
0
 def test_fan_in_out_capacities_undirected(self):
     topology = fnss.star_topology(3)
     fnss.set_capacities_constant(topology, 10, 'Mbps')
     in_cap, out_cap = fnss.fan_in_out_capacities(topology)
     self.assertEquals({0: 30, 1: 10, 2: 10, 3: 10}, in_cap)
     self.assertEquals(in_cap, out_cap)
예제 #29
0
from mininet.net import Mininet
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
from mininet.node import RemoteController
from mininet.cli import CLI

# Create FNSS topology. Let's create a simple datacenter topology
# This topology does not contain loops. If you want to use a topology with
# loops or multiple paths in Mininet you need to use a custom controller.
# More info here:
# https://github.com/mininet/mininet/wiki/Introduction-to-Mininet#multipath-routing
fnss_topo = fnss.two_tier_topology(n_core=1, n_edge=2, n_hosts=2)

# Set link attributes
fnss.set_capacities_constant(fnss_topo, 10, 'Mbps')
fnss.set_delays_constant(fnss_topo, 2, 'ms')
fnss.set_buffer_sizes_constant(fnss_topo, 50, 'packets')

# Convert FNSS topology to Mininet
# If argument relabel_nodes is set to False, node labels are not changed when
# converting an FNSS topology to a Mininet one, except converting the type to
# string (e.g. 1 -> '1'). If relabel_nodes is set to True (default option)
# then nodes are label according to Mininet conventions, e.g. hosts are
# prepended an h (e.g. 1 -> 'h1') and switches are prepended an s
# (e.g. 2 -> 's2')
mn_topo = fnss.to_mininet(fnss_topo, relabel_nodes=True)

# Create a Mininet instance and start it
# Use TCLink to implement links enables Linux Traffic Container (TC) for rate
# limitation
예제 #30
0
def build_topology():

	# We use fat tree topology for datacenters
	kval = 0
	edgeLinkCapacity = [10, 'Mbps']
	aggrLinkCapacity = [100,'Mbps']
	coreLinkCapacity = [1,  'Gbps']
	linkDelay		 = [10, 'ns']

	# Get the value from the network.config file
	lines = open('./network.config', 'r').readlines()
	for line in lines:
		val = line.split()
		if val[0] == "K_VALUE":
			kval = int(val[1])
		elif val[0] == "EDGE_LINK_SPEED":
			edgeLinkCapacity[0] = val[1]
			edgeLinkCapacity[1] = val[2]
		elif val[0] == "AGGR_LINK_SPEED":
			aggrLinkCapacity[0] = val[1]
			aggrLinkCapacity[1] = val[2]
		elif val[0] == "CORE_LINK_SPEED":
			coreLinkCapacity[0] = val[1]
			coreLinkCapacity[1] = val[2]
		elif val[0] == "LINK_DELAY":
			linkDelay[0] = val[1]
			linkDelay[1] = val[2]

	if kval == 0:
		print "ERROR: Wrong value of K for a fat tree topo, exiting"
		sys.exit(0)

	# Build the topology using fnss
	topology = fnss.fat_tree_topology(kval)

	# Get link types
	link_types = nx.get_edge_attributes(topology, 'type')

	edge_leaf_links = [link for link in link_types
                if link_types[link] == 'edge_leaf']

	aggregation_edge_links = [link for link in link_types
                if link_types[link] == 'aggregation_edge']

	core_edge_links = [link for link in link_types
                if link_types[link] == 'core_edge']

	# Set the link speeds
	fnss.set_capacities_constant(topology, edgeLinkCapacity[0], edgeLinkCapacity[1], edge_leaf_links)
	fnss.set_capacities_constant(topology, aggrLinkCapacity[0], aggrLinkCapacity[1], aggregation_edge_links)
	fnss.set_capacities_constant(topology, coreLinkCapacity[0], coreLinkCapacity[1], core_edge_links)

	# Set default weight of 1 to all links
	fnss.set_weights_constant(topology, 1)

	# Set link delay to be 10 ns
	fnss.set_delays_constant(topology, linkDelay[0], linkDelay[1])

	# Generate the topology.xml file
	fnss.write_topology(topology, 'topology.xml')

	# Create mininet topology from fnss with renaming to mininet format
	mn_topo = fnss.to_mininet(topology, relabel_nodes=True)

	net = Mininet(topo=mn_topo, link=TCLink, controller=None)

	net.addController('floodlight', controller=RemoteController, ip="127.0.0.1", port=6653)

	net.start()

	# Dump host connections
	dumpNodeConnections(net.hosts)

	# Test network connectivity
	net.pingAll()
예제 #31
0
 def test_fan_in_out_capacities_undirected(self):
     topology = fnss.star_topology(3)
     fnss.set_capacities_constant(topology, 10, 'Mbps')
     in_cap, out_cap = fnss.fan_in_out_capacities(topology)
     self.assertEqual({0: 30, 1: 10, 2: 10, 3: 10}, in_cap)
     self.assertEqual(in_cap, out_cap)
예제 #32
0
# this return a dictionary of egdes and value of attribute type
# This function is provided by the NetworkX library.
# Since FNSS Topology and DirecteedTopology objects inherit from NetworkX's
# Graph and DiGraph, respectively, NetworkX functions can be used in FNSS too.
link_types = nx.get_edge_attributes(fnss_topo, 'type')
core_links = [links for links in link_types if link_types[links] == 'core']
edge_links = [links for links in link_types 
              if link_types[links] == 'right_bell' 
              or link_types[links] == 'left_bell']

# set delay equal to 1 ms in edge links and equal to 2 ms in core links
fnss.set_delays_constant(fnss_topo, 1, 'ms', edge_links)
fnss.set_delays_constant(fnss_topo, 2, 'ms', core_links)

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

# Set buffer size constant to all interfaces
fnss.set_buffer_sizes_constant(fnss_topo, 50, 'packets')

# Now we deploy a traffic sources on right bell and traffic receivers on left
# bell
node_types = nx.get_node_attributes(fnss_topo, 'type')
core_nodes = [nodes for nodes in node_types 
              if node_types[nodes] == 'core']
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']
예제 #33
0
# This function is provided by the NetworkX library.
# Since FNSS Topology and DirecteedTopology objects inherit from NetworkX's
# Graph and DiGraph, respectively, NetworkX functions can be used in FNSS too.
link_types = nx.get_edge_attributes(topology, 'type')
core_links = [links for links in link_types if link_types[links] == 'core']
edge_links = [
    links for links in link_types
    if link_types[links] == 'right_bell' or link_types[links] == 'left_bell'
]

# set delay equal to 1 ms in edge links and equal to 2 ms in core links
fnss.set_delays_constant(topology, 1, 'ms', edge_links)
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', {})
예제 #34
0
# create a topology with 10 core switches, 20 edge switches and 10 hosts
# per switch (i.e. 200 hosts in total)
topology = fnss.two_tier_topology(n_core=10, n_edge=20, n_hosts=10)

# assign capacities
# let's set links connecting servers to edge switches to 1 Gbps
# and links connecting core and edge switches to 10 Gbps.

# get list of core_edge links and edge_leaf links
link_types = nx.get_edge_attributes(topology, 'type')
core_edge_links = [
    link for link in link_types if link_types[link] == 'core_edge'
]
edge_leaf_links = [
    link for link in link_types if link_types[link] == 'edge_leaf'
]

# assign capacities
fnss.set_capacities_constant(topology, 1, 'Gbps', edge_leaf_links)
fnss.set_capacities_constant(topology, 10, 'Gbps', core_edge_links)

# assign weight 1 to all links
fnss.set_weights_constant(topology, 1)

# assign delay of 10 nanoseconds to each link
fnss.set_delays_constant(topology, 10, 'ns')

# save topology to a file
fnss.write_topology(topology, 'datacenter_topology.xml')
"""
import fnss
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
from mininet.cli import CLI
from mininet.node import RemoteController
from mininet.node import OVSController


# Create FNSS topology -- FatTree with k = 4
fnss_topo = fnss.fat_tree_topology(k=4)
# Set link attributes  10Mbps bandwidth
fnss.set_capacities_constant(fnss_topo, 10, "Mbps")
# Set link delay to be 2ms
fnss.set_delays_constant(fnss_topo, 2, "ms")
# Set switch buffer to be 50 packets size
fnss.set_buffer_sizes_constant(fnss_topo, 50, "packets")

# Convert FNSS topology to Mininet
mn_topo = fnss.to_mininet(fnss_topo, relabel_nodes=True)
# Create a remote controller object in local host
RemoteCon = RemoteController("RemoteCon1", ip="127.0.0.1")
# Create a Mininet instance and start it
# Use TCLink to implement links enables Linux Traffic Container (TC) for rate
# limitation
net = Mininet(topo=mn_topo, link=TCLink, controller=RemoteCon)
net.start()
# Dump host connections
"""
import fnss
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
from mininet.cli import CLI
from mininet.node import RemoteController
from mininet.node import OVSController
import time

# Create FNSS topology -- FatTree with k = 4
fnss_topo = fnss.fat_tree_topology(k=4)
# Set link attributes  10Mbps bandwidth
fnss.set_capacities_constant(fnss_topo, 10, 'Mbps')
# Set link delay to be 2ms
fnss.set_delays_constant(fnss_topo, 2, 'ms')
# Set switch buffer to be 50 packets size
fnss.set_buffer_sizes_constant(fnss_topo, 50, 'packets')

# Convert FNSS topology to Mininet
mn_topo = fnss.to_mininet(fnss_topo, relabel_nodes=True)
# Create a remote controller object in local host
RemoteCon = RemoteController('RemoteCon1', ip='127.0.0.1')
# Create a Mininet instance and start it
# Use TCLink to implement links enables Linux Traffic Container (TC) for rate
# limitation
net = Mininet(topo=mn_topo, link=TCLink, controller=RemoteCon)
net.start()
# Dump host connections
예제 #37
0
def generate_traffic_matrix():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("--as_no", type=str, required=True)
    parser.add_argument('--arrival_rate', type=float,
                        default=0.003)  # 10 sfc per hour
    parser.add_argument('--max_simulation_time', type=int,
                        default=86400)  # 24 hour
    parser.add_argument('--sfc_lifetime', type=int,
                        default=5400)  # 1 hour 30 minute
    parser.add_argument('--num_time_slots', type=int, default=24)
    parser.add_argument('--stddev', type=float, default=0.03)

    args = parser.parse_args()
    co_file = args.as_no + ".co"
    co_topology = read_co_topology(co_file)
    slot_width = args.max_simulation_time / args.num_time_slots

    times = []
    current_time = 0
    while current_time < args.max_simulation_time:
        wait_time = int(random.expovariate(args.arrival_rate)) + 1
        duration = int(random.expovariate(1.0 / args.sfc_lifetime)) + 1
        times.append((current_time, current_time + duration))
        current_time += wait_time
    timeslot_sfc_count = dict()
    flow_time_slot = dict()
    sources = random.sample(range(0,
                                  len(co_topology.nodes()) - 1),
                            len(co_topology.nodes()) / 2)
    destinations = random.sample(range(0,
                                       len(co_topology.nodes()) - 1),
                                 len(co_topology.nodes()) / 2)
    topology = fnss.Topology(co_topology)
    fnss.set_capacities_constant(topology, 10000, 'Mbps')
    tmc = fnss.sin_cyclostationary_traffic_matrix(
        topology,
        mean=0.1,  # average flow in TM is 100 Mbps 
        stddev=args.
        stddev,  # this is the std among average flows of different OD pairs
        gamma=0.8,  # gamma and log_psi are parameters for fitting the std of 
        log_psi=
        -0.033,  # volume fluctuations over time. Look at Nucci et al. paper
        delta=
        0.2,  # traffic variation from period max and avg as fraction of average
        n=1,  # number of samples per each period
        periods=args.num_time_slots,  # number of periods
        max_u=0.50,  # max link utilization desired 
        origin_nodes=sources,
        destination_nodes=destinations)
    flow_id = 0
    all_flows = []
    for i in range(len(tmc)):
        tm = tmc.get(i)
        flows = tm.flows()
        for (endpoint, traffic) in flows.items():
            [source, destination] = endpoint
            traffic *= 1000
            traffic /= round((24 * 1.0 / args.num_time_slots) * 3600.0, 0)
            if source == destination:
                continue
            if traffic < 10:
                continue
            if traffic > 8000:
                traffic = 8000
            mbox_seq = GenerateMiddleboxSequence(random.randint(3, 6))
            flow = dict()
            flow["flow_id"] = flow_id
            flow["src"] = source
            flow["dst"] = destination
            flow["bw"] = int(round(traffic, 0))
            flow["mbox_seq"] = mbox_seq
            flow["delay"] = int(round(random.uniform(1000, 2000), 0))
            all_flows.append(flow)
            flow_id += 1
    # traffic_file.write(str(current_time) + "," + str(source) + "," +
    # str(destination) + "," + str(int(round(traffic, 0))) + "," + str(max_latency) +
    # ",0.00000010," + mbox_seq[0] + "," + mbox_seq[1] + "," + mbox_seq[2] +
    # "\n")
    num_flows = len(all_flows)
    with open(args.as_no + ".timeslots", "w") as f:
        f.write(str(len(times)) + "\n")
        f.write(str(args.num_time_slots) + "\n")
        flow_index = 0
        for time_point in times:
            current_time, ends_at = time_point
            cur_slot_idx, end_slot_idx = get_timeslot_index(
                current_time,
                slot_width), get_timeslot_index(ends_at, slot_width)
            if cur_slot_idx not in timeslot_sfc_count.keys():
                timeslot_sfc_count[cur_slot_idx] = 0
                flow_time_slot[cur_slot_idx] = []
            timeslot_sfc_count[cur_slot_idx] += 1
            ttl = end_slot_idx - cur_slot_idx + 1
            flow_idx = random.randint(0, num_flows - 1)
            flow = all_flows[flow_idx]
            flow['ttl'] = ttl
            flow_str = " ".join([
                str(flow_index),
                str(flow["src"]),
                str(flow["dst"]),
                str(flow["ttl"]),
                str(len(flow["mbox_seq"])), " ".join(flow["mbox_seq"]),
                str(flow["bw"]),
                str(flow["delay"])
            ])
            flow_time_slot[cur_slot_idx].append(flow_str)
            flow_index += 1
        for (ts, flows) in flow_time_slot.iteritems():
            f.write(str(len(flows)) + "\n")
            for flow in flows:
                f.write(flow + "\n")
예제 #38
0
"""
import fnss
import networkx as nx

# create a topology with 10 core switches, 20 edge switches and 10 hosts
# per switch (i.e. 200 hosts in total)
topology = fnss.two_tier_topology(n_core=10, n_edge=20, n_hosts=10)

# assign capacities
# let's set links connecting servers to edge switches to 1 Gbps
# and links connecting core and edge switches to 10 Gbps.

# get list of core_edge links and edge_leaf links
link_types = nx.get_edge_attributes(topology, 'type')
core_edge_links = [link for link in link_types
                   if link_types[link] == 'core_edge']
edge_leaf_links = [link for link in link_types
                   if link_types[link] == 'edge_leaf']

# assign capacities
fnss.set_capacities_constant(topology, 1, 'Gbps', edge_leaf_links)
fnss.set_capacities_constant(topology, 10, 'Gbps', core_edge_links)

# assign weight 1 to all links
fnss.set_weights_constant(topology, 1)

# assign delay of 10 nanoseconds to each link
fnss.set_delays_constant(topology, 10, 'ns')

# save topology to a file
fnss.write_topology(topology, 'datacenter_topology.xml')
예제 #39
0
"""
Export topology to ns-2
=======================

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
예제 #40
0
for i in dir(fnss):
    print i
link_types = nx.get_edge_attributes(fnss_topo, 'type')
core_links = [links for links in link_types if link_types[links] == 'core']
edge_links = [
    links for links in link_types
    if link_types[links] == 'right_bell' or link_types[links] == 'left_bell'
]

# set delay equal to 1 ms in edge links and equal to 2 ms in core links
fnss.set_delays_constant(fnss_topo, 1, 'ms', edge_links)
fnss.set_delays_constant(fnss_topo, 2, 'ms', core_links)

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

# Set buffer size constant to all interfaces
fnss.set_buffer_sizes_constant(fnss_topo, 50, 'packets')

# Now we deploy a traffic sources on right bell and traffic receivers on left
# bell
node_types = nx.get_node_attributes(fnss_topo, 'type')
core_nodes = [nodes for nodes in node_types if node_types[nodes] == 'core']
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'
]