import os
PL_NODES = dict({
- "0": "iraplab1.iralab.uni-karlsruhe.de",
- "1": "planetvs2.informatik.uni-stuttgart.de",
- "2": "dfn-ple1.x-win.dfn.de",
- "3": "planetlab2.extern.kuleuven.be",
- "4": "mars.planetlab.haw-hamburg.de",
- "5": "planetlab-node3.it-sudparis.eu",
- "6": "node2pl.planet-lab.telecom-lille1.eu",
- "7": "planetlab1.informatik.uni-wuerzburg.de",
- "8": "planet1.l3s.uni-hannover.de",
- "9": "planetlab1.wiwi.hu-berlin.de",
- "10": "pl2.uni-rostock.de",
- "11": "planetlab1.u-strasbg.fr",
- "12": "peeramidion.irisa.fr",
- "13": "planetlab2.unineuchatel.ch",
+ 0: "iraplab1.iralab.uni-karlsruhe.de",
+ 1: "planetvs2.informatik.uni-stuttgart.de",
+ 2: "dfn-ple1.x-win.dfn.de",
+ 3: "planetlab2.extern.kuleuven.be",
+ 4: "mars.planetlab.haw-hamburg.de",
+ 5: "planetlab-node3.it-sudparis.eu",
+ 6: "node2pl.planet-lab.telecom-lille1.eu",
+ 7: "planetlab1.informatik.uni-wuerzburg.de",
+ 8: "planet1.l3s.uni-hannover.de",
+ 9: "planetlab1.wiwi.hu-berlin.de",
+ 10: "pl2.uni-rostock.de",
+ 11: "planetlab1.u-strasbg.fr",
+ 12: "peeramidion.irisa.fr",
+ 13: "planetlab2.unineuchatel.ch",
})
pl_slice = os.environ.get("PL_SLICE")
""" Adds CCN content history for each node in the topology graph.
"""
+
# Make a copy of the graph to ensure integrity
graph = graph.copy()
# Each dirpath correspond to a different node
nid = os.path.basename(dirpath)
+
+ # Cast to numeric nid if necessary
+ if int(nid) in graph.nodes():
+ nid = int(nid)
content_history = dict()
:param version: IP version for IP address assignment.
:type version: int
-
:param assign_st: Select source and target nodes on the graph.
:type assign_st: bool
+ :param sources_targets: dictionary with the list of sources (key =
+ "sources") and list of targets (key = "targets") if defined, ignore
+ assign_st
+ :type sources_targets: dictionary of lists
+
+ :param leaf_source: if True, random sources will be selected only
+ from leaf nodes.
+ :type leaf_source: bool
+
NOTE: Only point-to-point like network topologies are supported for now.
(Wireless and Ethernet networks were several nodes share the same
edge (hyperedge) can not be modeled for the moment).
self.assign_p2p_ips(network = network, prefix = prefix,
version = version)
- if kwargs.get("assign_st"):
+ sources_targets = kwargs.get("sources_targets")
+ if sources_targets:
+ [self.set_source(n) for n in sources_targets["sources"]]
+ [self.set_target(n) for n in sources_targets["targets"]]
+ elif kwargs.get("assign_st"):
self.select_target_zero()
- self.select_random_leaf_source()
+ self.select_random_source(is_leaf = kwargs.get("leaf_source"))
@property
def topology(self):
prev = c
c += 1
- # node ids are int, make them str
- g = networkx.Graph()
- g.add_nodes_from(map(lambda nid: str(nid), graph.nodes()))
- g.add_edges_from(map(lambda t: (str(t[0]), str(t[1])),
- graph.edges()))
-
- return g
+ return graph
def add_node(self, nid):
- nid = str(nid)
-
if nid not in self.topology:
self.topology.add_node(nid)
def add_edge(self, nid1, nid2):
- nid1 = str(nid1)
- nid2 = str(nid2)
-
self.add_node(nid1)
self.add_node( nid2)
if self.topology.node[nid].get("source")]
def select_target_zero(self):
- """ Marks the node 0 as target
+ """ Mark the node 0 as target
"""
- self.set_target("0")
+ nid = 0 if 0 in self.topology.nodes() else "0"
+ self.set_target(nid)
- def select_random_leaf_source(self):
- """ Marks a random leaf node as source.
+ def select_random_source(self, **kwargs):
+ """ Mark a random node as source.
"""
# The ladder is a special case because is not symmetric.
if self.topo_type == TopologyType.LADDER:
total_nodes = self.order/2
- leaf1 = str(total_nodes)
- leaf2 = str(total_nodes - 1)
+ leaf1 = total_nodes
+ leaf2 = total_nodes - 1
leaves = [leaf1, leaf2]
source = leaves.pop(random.randint(0, len(leaves) - 1))
else:
# options must not be already sources or targets
options = [ k for k,v in self.topology.degree().iteritems() \
- if v == 1 and not self.topology.node[k].get("source") \
+ if (not kwargs.get("is_leaf") or v == 1) \
+ and not self.topology.node[k].get("source") \
and not self.topology.node[k].get("target")]
-
source = options.pop(random.randint(0, len(options) - 1))
self.set_source(source)
for nid in ec.netgraph.nodes():
ngnnode = doc.createElement("node")
ngnnode.setAttribute("nid", xmlencode(nid))
+ ngnnode.setAttribute("nid-type", from_type(nid))
ngnsnode.appendChild(ngnnode)
# Mark ources and targets
for nid1, nid2 in ec.netgraph.edges():
ngenode = doc.createElement("edge")
ngenode.setAttribute("nid1", xmlencode(nid1))
+ ngenode.setAttribute("nid1-type", from_type(nid1))
ngenode.setAttribute("nid2", xmlencode(nid2))
+ ngenode.setAttribute("nid2-type", from_type(nid2))
ngesnode.appendChild(ngenode)
# Edge annotations
ngnsnode = ngnsnode_list[0].getElementsByTagName("node")
for ngnnode in ngnsnode:
nid = xmldecode(ngnnode.getAttribute("nid"))
+ tipe = xmldecode(ngnnode.getAttribute("nid-type"))
+ nid = to_type(tipe, nid)
netgraph.add_node(nid)
if ngnnode.hasAttribute("source"):
ngesnode = ngesnode_list[0].getElementsByTagName("edge")
for ngenode in ngesnode:
nid1 = xmldecode(ngenode.getAttribute("nid1"))
+ tipe1 = xmldecode(ngenode.getAttribute("nid1-type"))
+ nid1 = to_type(tipe1, nid1)
+
nid2 = xmldecode(ngenode.getAttribute("nid2"))
+ tipe2 = xmldecode(ngenode.getAttribute("nid2-type"))
+ nid2 = to_type(tipe2, nid2)
+
netgraph.add_edge(nid1, nid2)
annosnode_list = ngenode.getElementsByTagName("edge-annotations")