-
Notifications
You must be signed in to change notification settings - Fork 7
/
run-mininet
executable file
·71 lines (53 loc) · 2.27 KB
/
run-mininet
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
#!/usr/bin/python3
import os, sys
import click
from mininet.node import RemoteController, Ryu
dir_path = os.path.dirname(os.path.realpath(__file__))
src_path = dir_path + '/src/python'
sys.path.insert(0, src_path)
try:
import chirouter.simulator as simulator
except ImportError as ie:
print(ie)
print("Could not import chirouter packages.")
print("Please make sure you run this command from your chirouter directory.")
sys.exit(1)
def validate_host(ctx, param, value):
if value is None:
return None
try:
host, port = value.split(":")
port = int(port)
return host, port
except ValueError:
raise click.BadParameter("Host needs to be in format HOST:PORT")
@click.command(name="run-mininet")
@click.argument('topo_file', type=click.Path(exists=True))
@click.option('--chirouter', callback=validate_host, metavar="HOST:PORT", help="Host and port of chirouter")
@click.option('--remote-controller', callback=validate_host, metavar="HOST:PORT", help="Host and port of remote controller")
def cmd(topo_file, chirouter, remote_controller):
if chirouter is not None and remote_controller is not None:
exit("You cannot specify both the --chirouter and --remote-controller options")
if os.geteuid() != 0:
exit("Mininet must be run as root. Please try running with 'sudo'.")
topo_file = os.path.abspath(topo_file)
if remote_controller is not None:
# Connect to a remote controller
rhost, rport = remote_controller
controller = RemoteController("c0", ip=rhost, port=rport)
else:
# Launch a Ryu-based controller
if chirouter is None:
chirouter_host, chirouter_port = "localhost", 23320
else:
chirouter_host, chirouter_port = chirouter
command = "PYTHONPATH=./src/python/ ryu-manager"
params = ["chirouter.controller"]
params += ["--user-flags src/python/chirouter/ryu_flags.py"]
params += ["--chirouter-topology-file=" + topo_file]
params += ["--chirouter-host=" + chirouter_host]
params += ["--chirouter-port=" + str(chirouter_port)]
controller = Ryu("c0", command=command, ryuArgs=params)
simulator.run(topo_file=topo_file, controller=controller)
if __name__ == "__main__":
cmd()