-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFirstSwitch.py
More file actions
executable file
·86 lines (73 loc) · 3.1 KB
/
FirstSwitch.py
File metadata and controls
executable file
·86 lines (73 loc) · 3.1 KB
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
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python
from mininet.net import Mininet
# from mininet.node import Controller, RemoteController, OVSController
from mininet.cli import CLI
from mininet.link import Intf
from mininet.log import setLogLevel, info
from mininet.node import OVSKernelSwitch, RemoteController
# from mininet.node import UserSwitch
import argparse
import random
import re
def myNetwork(d, server, port):
net = Mininet(topo=None,
build=False)
info('*** Adding controller\n')
net.addController(name='c0', controller=RemoteController, ip=server,
port=port)
info('*** Add switches\n')
s1 = net.addSwitch('s1', cls=OVSKernelSwitch, dpid=d)
Intf('eth1', node=s1)
info('*** Add hosts\n')
h1 = net.addHost('h1', ip='0.0.0.0')
h2 = net.addHost('h2', ip='0.0.0.0')
info('*** Add links\n')
net.addLink(h1, s1)
net.addLink(h2, s1)
info('*** Starting network\n')
net.start()
h1.cmdPrint('dhclient ' + h1.defaultIntf().name)
h2.cmdPrint('dhclient ' + h2.defaultIntf().name)
print " "
print "If your application is using OpenDaylight RESTCONF api then \
you are ready to go. Go write your app.\n\n\
If your application will use the Elbrys OpenNAC API then \
this is the data for adding the mininet switch to the list of network \
devices in the SDN Developer Lab (sdn-developer.elbrys.com):"
print " Local MAC: " + re.sub("(.{2})", "\\1:", d, 5, re.DOTALL)
ip = s1.cmd('ifconfig eth0 | grep \'inet addr\' | cut -d: -f2\
| awk \'{print $1}\'')
print " Local IPv4 Address: " + ip
dpidAsInt = int(d, 16)
print " Datapath id (dpid): " + d + " (decimal: " + str(dpidAsInt) + ")"
print " "
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel('info')
parser = argparse.ArgumentParser(description='Simple Mininet application\
to create and connect Mininet switch to SDN Developer Lab.')
parser.add_argument('--id',
required=True,
help='your SDN Developer Lab Application id. Go to sdn-developer.\
elbrys.com, logon, select "My Account" in top right.')
parser.add_argument('--server',
required=True,
help='The IP address of your SDN Developer Lab controller. Go to \
sdn-developer.elbrys.com, logon, look at \
"Controller" table.')
parser.add_argument('--port',
required=True,
help='The TCP OpenFlow API port number of your SDN Developer Lab \
server. Go to sdn-developer.elbrys.com, \
logon, look at "Controller" table for \
OpenFlow Port.')
args = parser.parse_args()
# Create a random dpid that is constant based on input args
random.seed(args.id)
r = random.randrange(0x111111111111, 0xffffffffffff)
r = r | 0x020000000000
d = format(r, 'x')
d = str(d)
# Create the network of switches and endpoints
myNetwork(d, args.server, int(args.port))