-
Notifications
You must be signed in to change notification settings - Fork 0
/
topology_to_mininet.py
75 lines (54 loc) · 1.77 KB
/
topology_to_mininet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import networkx as nx
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.node import OVSController, RemoteController
from mininet.cli import CLI
def from_autonetkit(topology):
"""Convert an AutoNetKit graph into an FNSS Topology object.
The current implementation of this function only renames the weight
attribute from *weight* to *ospf_cost*
Parameters
----------
topology : NetworkX graph
An AutoNetKit NetworkX graph
Returns
-------
fnss_topology : FNSS Topology
FNSS topology
"""
topology = topology.copy()
fnss.rename_edge_attribute(topology, 'ospf_cost', 'weight')
return topology
def main():
G = nx.Graph()
G = nx.read_gpickle("mendocino.gpickle")
fnss_topo = from_autonetkit(G)
node_types = nx.get_node_attributes(fnss_topo, 'type')
hosts = []
switches = []
for node in fnss_topo.nodes():
nodetype = G.node[node]['type']
if nodetype == 'cpe':
hosts.append(node)
else:
switches.append(node)
mn_topo = fnss.to_mininet(fnss_topo, switches=switches, hosts=hosts, relabel_nodes=True)
net = Mininet(topo=mn_topo, link=TCLink, controller=None)
c0=net.addController(name='c0', controller=RemoteController, ip='127.0.0.1', protocol='tcp', port=6653)
net.start()
# Dump host connections
dumpNodeConnections(net.hosts)
# Test network connectivity
#net.pingAll()
# Test bandwidth between nodes
#h1, h8 = net.get('h1', 'h8')
#net.iperf((h1, h8))
# Stop Mininet
CLI(net)
net.stop()
if __name__ == "__main__":
main()