This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
onoslib.py
70 lines (52 loc) · 2.64 KB
/
onoslib.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
"""
Libraries for using ONOS from within Mininet.
"""
from mininet.node import OVSBridge
from mininet.util import netParse, ipStr
import os, sys, imp
# Import the ONOS classes from onos.py in the ONOS repository
if not 'ONOS_ROOT' in os.environ:
print 'ONOS_ROOT is not set.'
print 'Try running the script with \'sudo -E\' to pass your environment in.'
sys.exit(1)
onos_path = os.path.join(os.path.abspath(os.environ['ONOS_ROOT']), 'tools/test/topos/onos.py')
onos = imp.load_source('onos', onos_path)
from onos import ONOS
class ONOSHostCluster(object):
def __init__(self, controlSubnet='192.168.1.0/24', numInstances=1, basename='ONOS',
features=[]):
self.controlSubnet = controlSubnet
self.numInstances = numInstances
self.basename = basename
self.instances = []
self.features = features
def create(self, topology):
cs0 = topology.addSwitch('cs0', cls=OVSBridge)
ctrlIp, ctrlPrefixLen = netParse(self.controlSubnet)
for i in range(1, self.numInstances + 1):
strCtrlIp = '%s/%i' % (ipStr(ctrlIp + i), ctrlPrefixLen)
c = topology.addHost('%s%s' % (self.basename, i), cls=ONOS, inNamespace=True,
ip=strCtrlIp,
features=['onos-app-config', 'onos-app-proxyarp',
'onos-core'] + self.features,
reactive=False)
topology.addLink(c, cs0, params1={ 'ip' : strCtrlIp })
self.instances.append(c)
# Connect switch to root namespace so that data network
# switches will be able to talk to us
highestIp = '%s/%i' % (ipStr(ctrlIp + (2 ** (32 - ctrlPrefixLen)) - 2), ctrlPrefixLen)
root = topology.addHost('root', inNamespace=False, ip=highestIp)
topology.addLink(root, cs0)
class ONOSHostSdnipCluster(ONOSHostCluster):
def __init__(self, dataSubnet='10.0.0.0/24', features=['onos-app-sdnip'], **kwargs):
super(ONOSHostSdnipCluster, self).__init__(features=features, **kwargs)
self.dataSubnet = dataSubnet
def create(self, topology):
super(ONOSHostSdnipCluster, self).create(topology)
cs1 = topology.addSwitch('cs1', cls=OVSBridge)
dataIp, dataPrefixLen = netParse(self.dataSubnet)
for i in range(1, len(self.instances) + 1):
c = self.instances[i-1]
strDataIp = '%s/%i' % (ipStr(dataIp + i), dataPrefixLen)
topology.addLink(c, cs1, params1={ 'ip' : strDataIp })
return cs1