Exemplo n.º 1
0
def execute_vivaldi(topology: Topology,
                    node_filter: Callable[[Node], bool] = lambda _: True,
                    neighbor_generator: Callable[[List[Node]], Iterable[Tuple[
                        Node, Node]]] = random_neighbors,
                    min_executions: int = 100) -> int:
    """
    Executes vivaldi on each node of the topology until each node has executed vivaldi at least min_executions times.

    :param topology: the topology to operate on
    :param node_filter: can be used to run vivaldi only on certain nodes
    :param neighbor_generator: a generator that, given the topology and the selected nodes, yields (n1, n2) neighbor
    tuples. The default value is a function that yields shuffled permutations of the nodes.
    :param min_executions: the minimum number of executions per node, which serves as break condition
    :return: the total number of vivaldi executions
    """
    nodes = list(filter(node_filter, topology.get_nodes()))
    executions = 0
    for node1, node2 in neighbor_generator(nodes):
        if all(
                map(
                    lambda n: n.coordinate and n.coordinate.vivaldi_runs >=
                    min_executions, nodes)):
            break
        vivaldi.execute(node1, node2, topology.route(node1, node2).rtt)
        executions += 1
    return executions
Exemplo n.º 2
0
def main():
    topology = Topology()
    topology.load_inet_graph('cloudping')
    regions = list(topology.nodes)

    scenario = CloudRegionsScenario(regions, [(5, 1)] * len(regions))
    scenario.materialize(topology)

    execute_vivaldi(topology)
    (measured, calculated) = distances(topology)
    qq_plot_distances(measured, calculated)
    plt.show()

    print('rmse:', mean_squared_error(measured, calculated, squared=False))
Exemplo n.º 3
0
def main():
    topology = Topology()

    IndustrialIoTScenario(num_premises=3,
                          internet='internet_chix').materialize(topology)
    IndustrialIoTScenario(num_premises=1,
                          internet='internet_nyc').materialize(topology)

    topology.add_connection(Connection('internet_chix', 'internet_nyc', 10))

    draw_basic(topology)
    fig = plt.gcf()
    fig.set_size_inches(18.5, 10.5)
    plt.show()  # display
Exemplo n.º 4
0
def create_topology() -> Topology:
    topology = Topology()
    counters = defaultdict(lambda: itertools.count(0, 1))
    lognorm = ParameterizedDistribution.lognorm

    def client_factory_with_region(region: str):
        def create_client():
            name = 'client_%d_%s' % (next(counters['client']), region)
            return Client(name)

        return create_client

    def edge_broker_factory_with_region(region: str):
        def create_edge_broker() -> Broker:
            name = 'edge-broker_%d_%s' % (next(
                counters['edge-brokers']), region)
            return Broker(name)

        return create_edge_broker

    # load cloudping dataset and select 5 random regions
    topology.load_inet_graph('cloudping')
    regions = random.choices(list(topology.nodes), k=5)

    # remove unused regions from topology
    unused_regions = topology.nodes - regions
    for r in unused_regions:
        topology.remove_node(r)

    # create 1 city (including one edge broker per neighborhood) plus 1 cloud broker per region
    for region in regions:
        aot_node = IoTComputeBox(nodes=[client_factory_with_region(region)])
        neighborhood = lambda size: SharedLinkCell(
            nodes=[[aot_node] * size,
                   [edge_broker_factory_with_region(region)]],
            backhaul=MobileConnection(region))
        city = GeoCell(5, nodes=[neighborhood], density=lognorm((0.82, 2.02)))
        topology.add(city)

        broker = Broker(f'cloud-broker_{region}', backhaul=region)
        topology.add(broker)

    return topology
Exemplo n.º 5
0
def distances(
    topology: Topology,
    node_filter: Callable[[Node], bool] = lambda _: True
) -> (List[float], List[float]):
    """
    Calculates `true_distances`, i.e., the list of distances when calculating the routes using the mode of the
    distance distributions, and `vivaldi_distances`, i.e., the list of distances calculated using vivaldi coordinates

    :param topology: the topology to run calculations on
    :param node_filter: if set, filters the set of nodes
    :return: a tuple of (true_distances, vivaldi_distances)
    """
    pairs = list(combinations(filter(node_filter, topology.get_nodes()), 2))
    true_distances = [
        topology.route(node1, node2, use_mode=True).rtt
        for node1, node2 in pairs
    ]
    vivaldi_distances = [node1.distance_to(node2) for node1, node2 in pairs]
    return true_distances, vivaldi_distances
Exemplo n.º 6
0
    def materialize(self, topology: Topology, parent=None):
        self._create_identity()

        for cell in self.nodes:
            self._materialize(topology, cell, self.link)

        if self.backhaul:
            if isinstance(self.backhaul, UpDownLink):
                uplink = Link(self.backhaul.bw_up, tags={'type': 'uplink', 'name': 'up_%s' % self.name})
                downlink = Link(self.backhaul.bw_down, tags={'type': 'downlink', 'name': 'down_%s' % self.name})

                topology.add_connection(Connection(self.link, uplink, latency_dist=self.backhaul.latency_dist), True)
                topology.add_connection(Connection(downlink, self.link), True)

                topology.add_connection(Connection(self.backhaul.backhaul, downlink,
                                                   latency_dist=self.backhaul.latency_dist), directed=True)
                topology.add_connection(Connection(uplink, self.backhaul.backhaul), directed=True)

            else:
                topology.add_connection(Connection(self.link, self.backhaul))
Exemplo n.º 7
0
def run_experiment(topology: Topology):
    execute_vivaldi(topology,
                    node_filter=lambda n: 'broker' in n.name,
                    min_executions=300)
    nodes = topology.get_nodes()
    clients = [n for n in nodes if 'client' in n.name]
    brokers = [n for n in nodes if 'broker' in n.name]
    experiment = ClientExperiment(topology, clients, brokers)
    experiment.run_and_plot(
        '5 random brokers, 3 closest brokers',
        lambda _: random.choices(brokers, k=5),
        lambda c: experiment.find_vivaldi_closest_brokers(c)[:3])
Exemplo n.º 8
0
 def create_initial_topology(self) -> Topology:
     topology = Topology()
     topology.load_inet_graph('cloudping')
     # maps region names of cloudping dataset to custom region names
     region_map = {
         'internet_eu-west-1': 'eu-west',
         'internet_eu-central-1': 'eu-central',
         'internet_us-east-1': 'us-east',
     }
     # remove all or regions from the graph
     topology.remove_nodes_from(
         [n for n in topology.nodes if n not in region_map.keys()])
     # relabel the region nodes according to the map above
     nx.relabel_nodes(topology, region_map, copy=False)
     return topology
Exemplo n.º 9
0
def main():
    topology = Topology()

    aot_node = IoTComputeBox(nodes=[nodes.rpi3, nodes.rpi3])
    neighborhood = lambda size: SharedLinkCell(
        nodes=[[aot_node] * size,
               IoTComputeBox([nodes.nuc] + ([nodes.tx2] * size * 2))],
        shared_bandwidth=500,
        backhaul=MobileConnection('internet_chix'))
    city = GeoCell(5, nodes=[neighborhood], density=lognorm((0.82, 2.02)))
    cloudlet = Cloudlet(5, 2, backhaul=FiberToExchange('internet_chix'))

    topology.add(city)
    topology.add(cloudlet)

    #######################

    draw_basic(topology)
    fig = plt.gcf()
    fig.set_size_inches(18.5, 10.5)
    plt.show()  # display

    print('num nodes:', len(topology.nodes))
Exemplo n.º 10
0
 def materialize(self, topology: Topology):
     topology.add(self.create_city())
     topology.add(self.create_cloudlet())
Exemplo n.º 11
0
    def materialize(self, topology: Topology, parent=None, latency_dist=latency.lan):
        node = self.nodes[0]

        topology.add_connection(Connection(node, self.link, latency_dist=latency_dist))
        if self.backhaul:
            topology.add_connection(Connection(self.link, self.backhaul))
Exemplo n.º 12
0
 def generate(self) -> Topology:
     t: Topology = Topology()
     self.materialize(t)
     return t
Exemplo n.º 13
0
    def test_graph(self):
        topology = Topology()

        n0 = create_nuc_node()
        n1 = create_nuc_node()
        n2 = create_nuc_node()
        n3 = create_nuc_node()
        n4 = create_rpi3_node()

        l0 = Link(tags={'name': 'link_%s' % n0.name})
        l1 = Link(tags={'name': 'link_%s' % n1.name})
        l2 = Link(tags={'name': 'link_%s' % n2.name})
        l3 = Link(tags={'name': 'link_%s' % n3.name})
        l4 = Link(tags={'name': 'link_%s' % n4.name})

        topology.add_connection(Connection(n0, l0))
        topology.add_connection(Connection(n1, l1))
        topology.add_connection(Connection(n2, l2))
        topology.add_connection(Connection(n3, l3))
        topology.add_connection(Connection(n4, l4))

        topology.add_connection(Connection(l0, l4), True)
        topology.add_connection(Connection(l1, l2), True)
        topology.add_connection(Connection(l2, l3), True)
        topology.add_connection(Connection(l2, l4), True)
        topology.add_connection(Connection(l1, l4), True)
        topology.add_connection(Connection(l3, l4), True)
        topology.add_connection(Connection(l2, l4), True)

        gen = nx.all_pairs_shortest_path(topology)
        for p in gen:
            print('-----')
            print(p)

        print('path', topology.path(n1, n4))

        r = topology.route(n1, n4)
        print('route', r)

        pos = nx.spring_layout(topology)  # positions for all nodes

        nx.draw_networkx_nodes(topology, pos)
        nx.draw_networkx_edges(topology, pos, width=1.0, alpha=0.5)
        nx.draw_networkx_labels(topology,
                                pos,
                                dict(zip([n1, n2, n3, n4], [n1, n2, n3, n4])),
                                font_size=8)

        plt.axis('off')
        fig = plt.gcf()
        fig.set_size_inches(18.5, 10.5)

        plt.show()  # display

        print('num nodes:', len(topology.nodes))