Esempio n. 1
0
 def test_delays_geo_distance_conversions(self):
     topology = fnss.Topology(distance_unit='m')
     topology.add_edge(1, 2, length=2000)
     specific_delay = 1.2
     fnss.set_delays_geo_distance(topology, specific_delay, None, 'us')
     self.assertAlmostEqual(topology.edge[1][2]['delay'], 2400)
     fnss.clear_delays(topology)
     fnss.set_delays_geo_distance(topology, specific_delay, None, 's')
     self.assertAlmostEqual(topology.edge[1][2]['delay'], 0.0024)
Esempio n. 2
0
 def test_delays_geo_distance_conversions(self):
     topology = fnss.Topology(distance_unit='m')
     topology.add_edge(1,2, length=2000)
     specific_delay=1.2
     fnss.set_delays_geo_distance(topology, specific_delay, None, 'us')
     self.assertAlmostEqual(topology.edge[1][2]['delay'], 2400)
     fnss.clear_delays(topology)
     fnss.set_delays_geo_distance(topology, specific_delay, None, 's')
     self.assertAlmostEqual(topology.edge[1][2]['delay'], 0.0024)
Esempio n. 3
0
 def test_delays_geo_distance_conversions_defaults(self):
     topology = fnss.Topology(distance_unit='m')
     topology.add_edge(1, 2, length=2000)
     topology.add_edge(2, 3, length=3000)
     topology.add_edge(3, 4)
     specific_delay = 1.2
     fnss.set_delays_geo_distance(topology, specific_delay, 3, 's', None)
     self.assertEquals(topology.graph['distance_unit'], 'm')
     self.assertEquals(topology.graph['delay_unit'], 's')
     self.assertAlmostEqual(topology.edge[1][2]['delay'], 0.0024)
     self.assertAlmostEqual(topology.edge[2][3]['delay'], 0.0036)
     self.assertAlmostEqual(topology.edge[3][4]['delay'], 3)
Esempio n. 4
0
 def test_delays_geo_distance_conversions_defaults(self):
     topology = fnss.Topology(distance_unit='m')
     topology.add_edge(1, 2, length=2000)
     topology.add_edge(2, 3, length=3000)
     topology.add_edge(3, 4)
     specific_delay=1.2
     fnss.set_delays_geo_distance(topology, specific_delay, 3, 's', None)
     self.assertEquals(topology.graph['distance_unit'], 'm')
     self.assertEquals(topology.graph['delay_unit'], 's')
     self.assertAlmostEqual(topology.edge[1][2]['delay'], 0.0024)
     self.assertAlmostEqual(topology.edge[2][3]['delay'], 0.0036)
     self.assertAlmostEqual(topology.edge[3][4]['delay'], 3)
Esempio n. 5
0
 def test_delays_geo_distance_conversions_partial_assignments(self):
     topology = fnss.Topology(distance_unit='m')
     topology.add_edge(1, 2, length=2000)
     topology.add_edge(2, 3, length=3000)
     topology.add_edge(3, 4)
     specific_delay=1.2
     fnss.set_delays_geo_distance(topology, specific_delay,
                                  None, 'us', links=[(1, 2)])
     fnss.set_delays_geo_distance(topology, specific_delay,
                                  3, 's', links=[(2, 3), (3, 4)])
     self.assertEquals(topology.graph['distance_unit'], 'm')
     self.assertEquals(topology.graph['delay_unit'], 'us')
     self.assertAlmostEqual(topology.edge[1][2]['delay'], 2400)
     self.assertAlmostEqual(topology.edge[2][3]['delay'], 3600)
     self.assertAlmostEqual(topology.edge[3][4]['delay'], 3000000)
Esempio n. 6
0
 def test_delays_geo_distance(self):
     specific_delay = 1.2
     L = 5
     G_len = fnss.waxman_1_topology(100, L=L)
     G_xy = fnss.waxman_2_topology(100, domain=(0, 0, 3, 4))
     # leave only node coordinate to trigger failure
     for u, v in G_xy.edges_iter():
         del G_xy.edge[u][v]['length']
     self.assertRaises(ValueError, fnss.set_delays_geo_distance,
                       G_len, 2, delay_unit='Km')
     self.assertRaises(ValueError, fnss.set_delays_geo_distance,
                       G_xy, specific_delay, None, 'ms')
     fnss.set_delays_geo_distance(G_len, specific_delay,
                             None, 'ms', links=None)
     delays = nx.get_edge_attributes(G_len, 'delay')
     self.assertEqual(G_len.number_of_edges(), len(delays))
     self.assertGreaterEqual(specific_delay*L, max(delays.values()))
     self.assertLessEqual(0, min(delays.values()))
Esempio n. 7
0
def topology():

    fnss_topology = fnss.parse_topology_zoo('AttMpls.gml')
    #fnss.two_tier_topology(1, 2, 2)
    "Create a network with some docker containers acting as hosts."

    # Set link attributes
    # https://fnss.github.io/doc/core/apidoc/fnss.functions.html
    #fnss.set_capacities_constant(fnss_topology, 10, 'Mbps')
    #fnss.set_delays_constant(fnss_topology, 2, 'ms')
    #fnss.set_buffer_sizes_constant(fnss_topology, 50, 'packets')
    fnss.set_delays_geo_distance(fnss_topology,
                                 specific_delay=fnss.PROPAGATION_DELAY_FIBER)

    mn_topo = fnss.to_mininet(fnss_topology, relabel_nodes=True)
    for node in mn_topo.hosts():
        mn_topo.setNodeInfo(
            node, {
                "dcmd": ["/bin/bash", "/ndn-entrypoint.sh"],
                "dimage": "ndnrepo_ndn:latest",
                "privileged": True,
                "cls": Docker
            })
        #mn_topo.setNodeInfo(node, "privileged", True )
        #mn_topo.setNodeInfo(node, "dimage", "ndnrepo_ndn:latest" )
        #node.dcmd=["/bin/bash", "/ndn-entrypoint.sh"]
        # = Docker('{0}'.format(node), ip='10.0.0.{0}'.format(node), , privileged=True, dimage="ndnrepo_ndn:latest")
        #node.type='host'
        #print node
        #nodes.append(node)

    net = NDNContainernet(topo=mn_topo, link=TCLink, controller=Controller)

    dumpNodeConnections(net.hosts)
    dumpNodeConnections(net.switches)
    fnss_topology.edges()
    info('*** Starting network\n')
    net.start()
    embed()

    #TODO Add NDN Links for all
    #fnss_topology.edges()
    #[(0, 1), (0, 2), (1, 3), (1, 4), (2, 5), (2, 6)]
    #addNDNRoute(d1, d2)

    #net = Containernet(controller=Controller)

    info('*** Adding controller\n')
    #net.addController('c0')

    info('*** Adding docker containers\n')
    #d1 = net.addDocker('d1', ip='10.0.0.251', dcmd=["/bin/bash", "/ndn-entrypoint.sh"], privileged=True, dimage="ndnrepo_ndn:latest")
    #d2 = net.addDocker('d2', ip='10.0.0.250', dcmd=["/bin/bash", "/ndn-entrypoint.sh"], privileged=True, dimage="ndnrepo_ndn:latest")

    #s1 = net.addSwitch('s1')

    info('*** Creating links\n')
    #net.addLink(d1, s1)
    #net.addLink(s1, d2)

    time.sleep(5)
    print addNDNRoute(d1, d2)
    #TODO create file when inserting is done
    while not (checkRepoNGInitDone(d1) and checkRepoNGInitDone(d2)):
        time.sleep(5)

    print listFilesInRepo(d1)
    print listFilesInRepo(d2)

    info('*** Running CLI\n')
    dumpNodeConnections(net.hosts)

    CLI(net)

    info('*** Stopping network')
    net.stop()
Esempio n. 8
0
    def generate_attributes(self,
                            vnr,
                            min_capacity,
                            max_capacity,
                            capacity_generation,
                            min_cpu,
                            max_cpu,
                            min_edge_distance=None,
                            max_edge_distance=None,
                            delay_per_km=0.005,
                            is_substrate=False,
                            minx=None,
                            maxx=None,
                            miny=None,
                            maxy=None,
                            **kwargs):
        """
        Sets the following edge attributes:
            * capacity [Mb/s]
            * delay [ms]
            * length [km]
            * mapping - zero if substrate else empty list
            * free_capacity if substrate is True
        Delay is calculated based on attribute delay and length of edge.

        Sets the following node attributes:
            * cpu
            * mapping
            * free_cpu if substrate is True
        If the network was created using the Waxman2 method, a longitude and
        latitude attribute will be present for the nodes

        Args:
            vnr (Vnr): Object of type Vnr.
            min_bw (int): Minimal value for bandwidth on edge.
            max_bw (int): Maximal value for bandwidth on edge.
            bandwidth (string): {uniform, power} - How bandwidth should be
                generated.
                if uniform is chosen distribution follows uniform distribution,
                if power is chosen distribution follows a power law.
            min_cpu (int): Minimal value for CPU capacity.
            max_cpu (int): Maximal value for CPU capacity.
            min_distance (int): Minimal length of an edge.
            max_distance (int): Maximal length of an edge.
            delay (float, optional): Delay per kilometer of cable length
            substrate (optional, bool): Whether it is a substrate network or not

        """
        if delay_per_km is None:
            delay_per_km = 0.05
        if 'distance_unit' not in vnr.graph:
            vnr.graph['distance_unit'] = 'km'
        bws = range(int(min_capacity), int(max_capacity) + 1)
        if capacity_generation == 'uniform':
            fnss.set_capacities_random_uniform(topology=vnr, capacities=bws)
        elif capacity_generation == 'power':
            fnss.set_capacities_random_power_law(topology=vnr, capacities=bws)
        for attributes in vnr.node.itervalues():
            attributes['cpu'] = int(np.random.uniform(min_cpu, max_cpu))
            attributes['mapping'] = 0
            if is_substrate:
                attributes['free_cpu'] = attributes['cpu']
                attributes['total_mapped'] = 0
                attributes['currently_mapped'] = 0
                if ('latitude' not in attributes) and (minx is not None) and (
                        maxx is not None):
                    attributes['latitude'] = np.random.uniform(minx, maxx)
                if ('longitude' not in attributes) and (minx is not None) and (
                        maxx is not None):
                    attributes['longitude'] = np.random.uniform(miny, maxy)

        for i, j, attr in vnr.edges(data=True):
            if 'length' not in attr:
                if 'longitude' in vnr.node[i] and 'latitude' in vnr.node[i]:
                    attr['length'] = np.sqrt(
                        np.square(vnr.node[i]['latitude'] -
                                  vnr.node[j]['latitude']) +
                        np.square(vnr.node[i]['longitude'] -
                                  vnr.node[j]['longitude']))
                else:
                    if (min_edge_distance is None) and (max_edge_distance is
                                                        None):
                        pass
                    else:
                        attr['length'] = np.random.uniform(
                            min_edge_distance, max_edge_distance)
            attr['mapping'] = 0 if is_substrate else []
            if is_substrate:
                attr['free_capacity'] = attr['capacity']
                attr['total_mapped'] = 0
                attr['currently_mapped'] = 0
        fnss.set_delays_geo_distance(vnr, specific_delay=delay_per_km)
        fnss.set_weights_delays(vnr)