How to use the sol.topology.topologynx.Topology function in SoL

To help you get started, we’ve selected a few SoL examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github progwriter / SOL / src / sol / topology / generators.py View on Github external
# Add upper and lower levels
        graph.add_nodes_from(lower, layer=EDGE_LAYER, functions=SWITCH)
        graph.add_nodes_from(upper, layer=AGG_LAYER, functions=SWITCH)
        # connect the levels
        graph.add_edges_from(itertools.product(lower, upper), capacitymult=1)
        # keep the upper level for later
        middle.extend(upper)
    # Now, create the core
    core = []
    for coreswitch in xrange(int((k ** 2) / 4)):
        graph.add_node(index, layer=CORE_LAYER, functions=SWITCH)
        core.append(index)
        index += 1
    graph.add_edges_from(itertools.product(core, middle), capacitymult=10)
    graph = graph.to_directed()
    return Topology(u'k{}'.format(k), graph)
github progwriter / SOL / server / server.py View on Github external
def topology():
    """
    Set or return the stored topology

    """
    global _topology, _paths
    if request.method == 'GET':
        if _topology is None:
            return
        return jsonify(_topology.to_json())
    elif request.method == 'POST':
        data = request.get_json()
        logger.debug(data)
        _topology = Topology.from_json(data)
        logging.info('Topology read successfully')
        _paths = {}
        for s in _topology.nodes():
            _paths[s] = {}
            for t in _topology.nodes():
                _paths[s][t] = list(generate_paths_ie(s, t, _topology, null_predicate, 100, 5))
        return ""
    else:
        abort(405)  # method not allowed
github progwriter / SOL / server / server.py View on Github external
__API_VERSION = 1  # the current api version
_json_pretty = False  # whether to pretty print json or not (not == save space)
_gzip = True  # whether to gzip the returned responses


# SET THIS TO THE TOPOLOGY WE ARE TESTING
#_topology = None
_topology = nx.DiGraph()
_topology.add_node(0, services='switch',resources={})
_topology.add_node(1, services='switch',resources={})
_topology.add_node(2, services='switch',resources={})
_topology.add_edge(0, 1, source=0, target=1, resources={'bw': 10000})
_topology.add_edge(1, 0, source=1, target=0, resources={'bw': 10000})
_topology.add_edge(2, 1, source=2, target=1, resources={'bw': 10000})
_topology.add_edge(1, 2, source=1, target=2, resources={'bw': 10000})
_topology = Topology(u'NoName', _topology)

_predicatedict = {
    'null': null_predicate,
    'null_predicate': null_predicate,
}


def assign_to_tc(tcs, paths, name):
    """
    Assign paths to traffic classes based on the ingress & egress nodes.
    To be used only if there is one traffic class (predicate)
    per ingress-egress pair.

    :param tcs: list of traffic classes
    :param paths: dictionary of paths: ..
github progwriter / SOL / src / sol / topology / generators.py View on Github external
def complete_topology(n, name=u'complete'):
    """
    Generates a complete graph topology

    :param n: number of nodes in the complete graph
    :param name: name of the topology

    :return: the new topology
    :rtype: :py:class:`~sol.topology.topologynx.Topology`

    """
    assert n >= 0
    G = nx.complete_graph(n).to_directed()
    t = Topology(name, G)
    return t
github progwriter / SOL / server / server.py View on Github external
def composeview():
    """
    Create a new composed opimization, solve and return the

    :return:

    """
    try:
        data = request.get_json()
        logger.debug(data)
        apps_json = data['apps']
        topology = Topology.from_json(data['topology'])
    except KeyError:  # todo: is this right exception?
        abort(400)

    # TODO: take predicate into account
    apps = []
    for aj in apps_json:
        aj = AttrDict(aj)
        tcs = []
        for tcj in aj.traffic_classes:
            tc = TrafficClass(tcj.tcid, u'tc', tcj.src, tcj.dst,
                              numpy.array([tcj.vol_flows]))
            tcs.append(tc)

        pptc = assign_to_tc(tcs, _paths, aj.id)
        # pptc = generate_paths_tc(topology, tcs, _predicatedict[aj.predicate], 20,
        #                          float('inf'), name=aj.id)
github progwriter / SOL / src / sol / sdn / onosWrapper.py View on Github external
auth=self._auth)
        resp.raise_for_status()
        devices = resp.json()
        resp = requests.get("http://{}/onos/v1/links".format(self._host),
                            auth=self._auth)
        resp.raise_for_status()
        links = resp.json()

        G = networkx.Graph()
        G.add_nodes_from([x['id'] for x in devices['devices']])
        G.add_edges_from([(x['src']['device'], x['dst']['device'],
                           {"srcport": x['src']['port'],
                            "dstport": x['dst']['port']}) for x in
                          links['links']])

        return Topology('onosTopology', G.to_directed())
github progwriter / SOL / src / sol / topology / generators.py View on Github external
def chain_topology(n, name=u'chain'):
    """
    Generates a chain topology.

    :param n: number of nodes in the chain
    :param name: name of the topology

    :return: the new topology
    :rtype: :py:class:`~sol.topology.topologynx.Topology`

    """
    assert n >= 0
    G = nx.path_graph(n).to_directed()
    t = Topology(name, G)
    return t