blob: 7cc4f663b7448e0584e5159c5127edcfe12179d4 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
A.R Karthick95d044e2016-06-10 18:44:36 -070017#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070018# Copyright 2016-present Ciena Corporation
19#
20# Licensed under the Apache License, Version 2.0 (the "License");
21# you may not use this file except in compliance with the License.
22# You may obtain a copy of the License at
A.R Karthick95d044e2016-06-10 18:44:36 -070023#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070024# http://www.apache.org/licenses/LICENSE-2.0
A.R Karthick95d044e2016-06-10 18:44:36 -070025#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070026# Unless required by applicable law or agreed to in writing, software
27# distributed under the License is distributed on an "AS IS" BASIS,
28# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29# See the License for the specific language governing permissions and
30# limitations under the License.
31#
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080032import json
33import requests
34import os,sys,time
A R Karthickb03cecd2016-07-27 10:27:55 -070035from OltConfig import OltConfig
A R Karthick1555c7c2017-09-07 14:59:41 -070036from CordTestUtils import get_mac, get_controller, log_test
A R Karthickefcf1ab2017-09-08 18:24:16 -070037from EapolAAA import get_radius_macs, get_radius_networks
A R Karthick2b93d6a2016-09-06 15:19:09 -070038
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080039class OnosCtrl:
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070040
41 auth = ('karaf', 'karaf')
A R Karthick2b93d6a2016-09-06 15:19:09 -070042 controller = get_controller()
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070043 cfg_url = 'http://%s:8181/onos/v1/network/configuration/' %(controller)
A.R Karthick95d044e2016-06-10 18:44:36 -070044 maven_repo = 'http://central.maven.org/maven2/org/onosproject'
Chetan Gaonker93e302d2016-04-05 10:51:07 -070045 applications_url = 'http://%s:8181/onos/v1/applications' %(controller)
A R Karthick36ae0252017-04-03 17:15:24 -070046 host_cfg_url = 'http://%s:8181/onos/v1/network/configuration/hosts/' %(controller)
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070047
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080048 def __init__(self, app, controller = None):
49 self.app = app
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070050 if controller is not None:
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080051 self.controller = controller
52 self.app_url = 'http://%s:8181/onos/v1/applications/%s' %(self.controller, self.app)
53 self.cfg_url = 'http://%s:8181/onos/v1/network/configuration/' %(self.controller)
54 self.auth = ('karaf', 'karaf')
55
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070056 @classmethod
A R Karthickbd82f362016-11-10 15:08:52 -080057 def config(cls, config, controller=None):
A R Karthick4e0c0912016-08-17 16:57:42 -070058 if config is not None:
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080059 json_data = json.dumps(config)
ChetanGaonker689b3862016-10-17 16:25:01 -070060 if controller is None:
ChetanGaonker689b3862016-10-17 16:25:01 -070061 resp = requests.post(cls.cfg_url, auth = cls.auth, data = json_data)
62 else:
63 cfg_url = 'http://%s:8181/onos/v1/network/configuration/' %(controller)
ChetanGaonker689b3862016-10-17 16:25:01 -070064 resp = requests.post(cfg_url, auth = cls.auth, data = json_data)
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080065 return resp.ok, resp.status_code
66 return False, 400
67
A R Karthickbd82f362016-11-10 15:08:52 -080068 @classmethod
A.R Karthickb17e2022017-01-27 11:29:26 -080069 def get_config(cls, controller=None):
70 if controller is None:
71 controller = cls.controller
72 cfg_url = 'http://%s:8181/onos/v1/network/configuration/' %(controller)
73 resp = requests.get(cfg_url, auth = cls.auth)
74 if resp.ok:
75 return resp.json()
76 return None
77
78 @classmethod
A R Karthickbd82f362016-11-10 15:08:52 -080079 def delete(cls, config, controller=None):
80 if config:
81 json_data = json.dumps(config)
82 if controller is None:
83 print('default Onos config url is %s'%cls.cfg_url)
84 resp = requests.delete(cls.cfg_url, auth = cls.auth, data = json_data)
85 else:
86 cfg_url = 'http://%s:8181/onos/v1/network/configuration/' %(controller)
A R Karthickbd82f362016-11-10 15:08:52 -080087 resp = requests.delete(cfg_url, auth = cls.auth, data = json_data)
88 return resp.ok, resp.status_code
89 return False, 400
90
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080091 def activate(self):
92 resp = requests.post(self.app_url + '/active', auth = self.auth)
93 return resp.ok, resp.status_code
94
95 def deactivate(self):
96 resp = requests.delete(self.app_url + '/active', auth = self.auth)
97 return resp.ok, resp.status_code
98
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070099 @classmethod
A R Karthick861ef162017-08-22 10:45:26 -0700100 def get_devices(cls, controller = None, mfr = None):
A R Karthick946141b2017-01-24 16:37:47 -0800101 if controller is None:
102 controller = cls.controller
103 url = 'http://%s:8181/onos/v1/devices' %(controller)
Chetan Gaonkera2b87df2016-03-31 15:41:31 -0700104 result = requests.get(url, auth = cls.auth)
105 if result.ok:
106 devices = result.json()['devices']
A R Karthick861ef162017-08-22 10:45:26 -0700107 devices = filter(lambda d: d['available'], devices)
108 if mfr:
109 devices = filter(lambda d: d['mfr'].startswith(mfr), devices)
110 return devices
Chetan Gaonkera2b87df2016-03-31 15:41:31 -0700111 return None
112
113 @classmethod
A.R Karthickd4eed642017-03-09 14:40:52 -0800114 def get_links(cls, controller = None):
115 if controller is None:
116 controller = cls.controller
117 url = 'http://%s:8181/onos/v1/links' %(controller)
118 result = requests.get(url, auth = cls.auth)
119 if result.ok:
120 links = result.json()['links']
121 return links
122 return None
123
124 @classmethod
A R Karthicka4d958a2017-09-05 19:01:37 -0700125 def get_device_id(cls, controller = None, mfr = None, olt_conf_file = ''):
A R Karthickb03cecd2016-07-27 10:27:55 -0700126 '''If running under olt, we get the first switch connected to onos'''
A R Karthicka4d958a2017-09-05 19:01:37 -0700127 olt = OltConfig(olt_conf_file = olt_conf_file)
A R Karthick078e63a2016-07-28 13:59:31 -0700128 did = 'of:' + get_mac()
A R Karthickb03cecd2016-07-27 10:27:55 -0700129 if olt.on_olt():
A R Karthick861ef162017-08-22 10:45:26 -0700130 devices = cls.get_devices(controller = controller, mfr = mfr)
A R Karthickb03cecd2016-07-27 10:27:55 -0700131 if devices:
132 dids = map(lambda d: d['id'], devices)
133 if len(dids) == 1:
134 did = dids[0]
135 else:
136 ###If we have more than 1, then check for env before using first one
137 did = os.getenv('OLT_DEVICE_ID', dids[0])
A R Karthickb03cecd2016-07-27 10:27:55 -0700138
139 return did
140
141 @classmethod
A R Karthicka4d958a2017-09-05 19:01:37 -0700142 def get_device_ids(cls, controller = None, olt_conf_file = ''):
A R Karthick0f6b6842016-12-06 17:17:44 -0800143 '''If running under olt, we get the first switch connected to onos'''
A R Karthicka4d958a2017-09-05 19:01:37 -0700144 olt = OltConfig(olt_conf_file = olt_conf_file)
A R Karthick0f6b6842016-12-06 17:17:44 -0800145 did = 'of:' + get_mac()
146 device_ids = []
147 if olt.on_olt():
A R Karthick946141b2017-01-24 16:37:47 -0800148 devices = cls.get_devices(controller = controller)
A R Karthick0f6b6842016-12-06 17:17:44 -0800149 if devices:
150 device_ids = map(lambda d: d['id'], devices)
151 else:
152 device_ids.append(did)
153
154 return device_ids
155
156 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -0700157 def get_flows(cls, device_id,controller=None):
158 if controller is None:
A R Karthick946141b2017-01-24 16:37:47 -0800159 url = 'http://%s:8181/onos/v1/flows/' %(cls.controller) + device_id
ChetanGaonker689b3862016-10-17 16:25:01 -0700160 else:
A R Karthick946141b2017-01-24 16:37:47 -0800161 url = 'http://%s:8181/onos/v1/flows/' %(controller) + device_id
Chetan Gaonkera2b87df2016-03-31 15:41:31 -0700162 result = requests.get(url, auth = cls.auth)
163 if result.ok:
164 return result.json()['flows']
165 return None
166
167 @classmethod
A R Karthick0f6b6842016-12-06 17:17:44 -0800168 def get_ports_device(cls, device_id, controller = None):
169 if controller is None:
170 url = 'http://{}:8181/onos/v1/devices/{}/ports'.format(cls.controller, device_id)
171 else:
172 url = 'http://{}:8181/onos/v1/devices/{}/ports'.format(controller, device_id)
173
174 result = requests.get(url, auth = cls.auth)
175 if result.ok:
176 return result.json()['ports']
177 return None
178
179 @classmethod
180 def cord_olt_device_map(cls, olt_config, controller = None):
181 olt_device_list = []
182 olt_port_map, _ = olt_config.olt_port_map()
183 switches = olt_port_map['switches']
184 if len(switches) > 1:
A R Karthick946141b2017-01-24 16:37:47 -0800185 device_ids = cls.get_device_ids(controller = controller)
A R Karthick0f6b6842016-12-06 17:17:44 -0800186 else:
A R Karthick946141b2017-01-24 16:37:47 -0800187 did = cls.get_device_id(controller = controller)
A R Karthick0f6b6842016-12-06 17:17:44 -0800188 if did is None:
189 return olt_device_list
190 uplink_dict = {}
191 uplink_dict['did'] = did
192 uplink_dict['switch'] = switches[0]
193 uplink_dict['uplink'] = str(olt_config.olt_conf['uplink'])
194 uplink_dict['vlan'] = str(olt_config.olt_conf['vlan'])
195 olt_device_list.append(uplink_dict)
196 return olt_device_list
197
198 for did in device_ids:
199 ports = cls.get_ports_device(did, controller = controller)
200 if ports:
201 matched = False
202 for port in ports:
203 for switch in switches:
204 if port['annotations']['portName'] == switch:
205 uplink_dict = {}
206 uplink = olt_port_map[switch]['uplink']
207 uplink_dict['did'] = did
208 uplink_dict['switch'] = switch
209 uplink_dict['uplink'] = str(uplink)
210 uplink_dict['vlan'] = str(olt_config.olt_conf['vlan'])
211 olt_device_list.append(uplink_dict)
212 matched = True
213 break
214 if matched == True:
215 break
216
217 return olt_device_list
218
219 @classmethod
220 def cord_olt_config(cls, olt_config, controller=None):
Chetan Gaonkera2b87df2016-03-31 15:41:31 -0700221 '''Configures OLT data for existing devices/switches'''
Chetan Gaonkera2b87df2016-03-31 15:41:31 -0700222 did_dict = {}
223 config = { 'devices' : did_dict }
A R Karthick0f6b6842016-12-06 17:17:44 -0800224 olt_device_list = cls.cord_olt_device_map(olt_config, controller = controller)
225 if not olt_device_list:
Chetan Gaonkera2b87df2016-03-31 15:41:31 -0700226 return
A R Karthick0f6b6842016-12-06 17:17:44 -0800227 for olt_map in olt_device_list:
Chetan Gaonkera2b87df2016-03-31 15:41:31 -0700228 access_device_dict = {}
A R Karthick0f6b6842016-12-06 17:17:44 -0800229 device_data = {'uplink': olt_map['uplink'], 'vlan': olt_map['vlan']}
230 access_device_dict['accessDevice'] = device_data
231 did_dict[olt_map['did']] = access_device_dict
Chetan Gaonkera2b87df2016-03-31 15:41:31 -0700232
233 ##configure the device list with access information
A R Karthick0f6b6842016-12-06 17:17:44 -0800234 return cls.config(config, controller=controller)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700235
236 @classmethod
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700237 def install_app(cls, app_file, onos_ip = None):
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700238 params = {'activate':'true'}
239 headers = {'content-type':'application/octet-stream'}
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700240 url = cls.applications_url if onos_ip is None else 'http://{0}:8181/onos/v1/applications'.format(onos_ip)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700241 with open(app_file, 'rb') as payload:
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700242 result = requests.post(url, auth = cls.auth,
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700243 params = params, headers = headers,
244 data = payload)
ChetanGaonker689b3862016-10-17 16:25:01 -0700245 print('result.ok, result.status_code are %s and %s'%(result.ok, result.status_code))
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700246 return result.ok, result.status_code
A R Karthickb7e80902016-05-17 09:38:31 -0700247
248 @classmethod
A.R Karthick95d044e2016-06-10 18:44:36 -0700249 def install_app_from_url(cls, app_name, app_version, app_url = None, onos_ip = None):
250 params = {'activate':'true'}
251 headers = {'content-type':'application/json'}
252 if app_url is None:
253 app_oar_file = '{}-{}.oar'.format(app_name, app_version)
254 app_url = '{0}/{1}/{2}/{3}'.format(cls.maven_repo, app_name, app_version, app_oar_file)
255 params['url'] = app_url
256 url = cls.applications_url if onos_ip is None else 'http://{0}:8181/onos/v1/applications'.format(onos_ip)
257 result = requests.post(url, auth = cls.auth,
258 json = params, headers = headers)
259 return result.ok, result.status_code
260
261 @classmethod
A R Karthickb7e80902016-05-17 09:38:31 -0700262 def uninstall_app(cls, app_name, onos_ip = None):
263 params = {'activate':'true'}
264 headers = {'content-type':'application/octet-stream'}
265 url = cls.applications_url if onos_ip is None else 'http://{0}:8181/onos/v1/applications'.format(onos_ip)
266 app_url = '{}/{}'.format(url, app_name)
267 resp = requests.delete(app_url, auth = cls.auth)
268 return resp.ok, resp.status_code
ChetanGaonkerf9c2f8b2016-07-19 15:49:41 -0700269
270 @classmethod
A R Karthick36ae0252017-04-03 17:15:24 -0700271 def host_config(cls, config, onos_ip=None):
ChetanGaonkerf9c2f8b2016-07-19 15:49:41 -0700272 if config:
273 json_data = json.dumps(config)
A R Karthick36ae0252017-04-03 17:15:24 -0700274 url = cls.host_cfg_url if onos_ip is None else 'http://{}:8181/onos/v1/network/configuration/hosts/'.format(onos_ip)
275 resp = requests.post(url, auth = cls.auth, data = json_data)
ChetanGaonkerf9c2f8b2016-07-19 15:49:41 -0700276 return resp.ok, resp.status_code
277 return False, 400
A R Karthick38d5df42017-07-10 13:33:26 -0700278
279 @classmethod
280 def config_device_driver(cls, controller = None, dids = None, driver = 'pmc-olt'):
281 driver_apps = ('org.onosproject.drivers', 'org.onosproject.openflow-base',)
282 if dids is None:
283 dids = cls.get_device_ids(controller = controller)
284 device_map = {}
285 for did in dids:
286 device_map[did] = { 'basic' : { 'driver' : driver } }
287 network_cfg = { 'devices' : device_map }
288 cls.config(network_cfg)
289 for driver in driver_apps:
290 cls(driver).deactivate()
291 time.sleep(2)
292 for driver in driver_apps:
293 cls(driver).activate()
294 time.sleep(5)
A R Karthick1555c7c2017-09-07 14:59:41 -0700295
296 @classmethod
297 def device_id_to_mac(cls, device_id):
298 device_mac_raw = device_id[-12:]
299 hwaddrs = []
300 for i in xrange(0, 12, 2):
301 hwaddrs.append(device_mac_raw[i:i+2])
302
303 device_mac = ':'.join(hwaddrs)
304 return device_mac
305
306 @classmethod
A R Karthickefcf1ab2017-09-08 18:24:16 -0700307 def aaa_load_config(cls, controller = None, olt_conf_file = '', conn_type = 'socket'):
A R Karthick1555c7c2017-09-07 14:59:41 -0700308 ovs_devices = cls.get_devices(controller = controller, mfr = 'Nicira')
309 if not ovs_devices:
310 log_test.info('No OVS devices found to configure AAA connect points')
311 return
312 olt = OltConfig(olt_conf_file = olt_conf_file)
313 port_map, _ = olt.olt_port_map()
314 app = 'org.opencord.aaa'
315 cfg = { 'apps' : { app : { 'AAA' : {} } } }
A R Karthickefcf1ab2017-09-08 18:24:16 -0700316 if conn_type == 'socket':
317 customizer = 'default'
318 else:
319 customizer = 'sample'
320 aaa_cfg = dict(radiusConnectionType = conn_type,
A R Karthick1555c7c2017-09-07 14:59:41 -0700321 radiusSecret = 'radius_password',
322 radiusServerPort = '1812',
A R Karthickefcf1ab2017-09-08 18:24:16 -0700323 packetCustomizer = customizer,
A R Karthick1555c7c2017-09-07 14:59:41 -0700324 vlanId = -1)
A R Karthickefcf1ab2017-09-08 18:24:16 -0700325 radius_networks = get_radius_networks(len(port_map['switch_radius_port_list']))
326 index = 0
A R Karthick1555c7c2017-09-07 14:59:41 -0700327 for switch, ports in port_map['switch_radius_port_list']:
328 radius_macs = get_radius_macs(len(ports))
A R Karthickefcf1ab2017-09-08 18:24:16 -0700329 prefix, _, _ = radius_networks[index]
330 index += 1
A R Karthick1555c7c2017-09-07 14:59:41 -0700331 aaa_cfg['nasIp'] = controller or cls.controller
332 aaa_cfg['nasMac'] = radius_macs[0]
333 aaa_cfg['radiusMac'] = radius_macs[0]
334 connect_points = []
335 radius_port = port_map[ ports[0] ]
A R Karthickefcf1ab2017-09-08 18:24:16 -0700336 radius_ip = '{}.{}'.format(prefix, radius_port)
337 if conn_type == 'socket':
338 radius_ip = os.getenv('ONOS_AAA_IP')
A R Karthick1555c7c2017-09-07 14:59:41 -0700339 aaa_cfg['radiusIp'] = radius_ip
340 for dev in ovs_devices:
A R Karthicke7232092017-09-07 18:01:33 -0700341 device_id = dev['id']
342 ports = OnosCtrl.get_ports_device(device_id, controller = controller)
343 radius_ports = filter(lambda p: p['isEnabled'] and 'annotations' in p and \
344 p['annotations']['portName'].startswith('r'),
345 ports)
A R Karthick36a75932017-10-25 14:40:42 -0700346 if not radius_ports:
347 continue
A R Karthicke7232092017-09-07 18:01:33 -0700348 radius_port = radius_ports[0]['port']
349 connect_point = '{}/{}'.format(device_id, radius_port)
A R Karthick1555c7c2017-09-07 14:59:41 -0700350 connect_points.append(connect_point)
351 aaa_cfg['radiusServerConnectPoints'] = connect_points
352 break
353
354 cfg['apps'][app]['AAA'] = aaa_cfg
355 cls.config(cfg, controller = controller)
356
357 @classmethod
358 def get_ovs_switch_map(cls, controller = None, olt_conf_file = ''):
359 port_map = None
360 #build ovs switch map
361 if olt_conf_file:
362 olt = OltConfig(olt_conf_file = olt_conf_file)
363 port_map, _ = olt.olt_port_map()
364
365 devices = cls.get_devices(controller = controller, mfr = 'Nicira')
366 switch_map = {}
367 for dev in devices:
368 device_id = dev['id']
369 serial = dev['serial']
370 ports = cls.get_ports_device(dev['id'], controller = controller)
371 ports = filter(lambda p: p['isEnabled'] and 'annotations' in p, ports)
372 #just create dummy ctag/uni port numbers
373 onu_ports = [1] * len(ports)
374 onu_names = map(lambda p: p['annotations']['portName'], ports)
375 onu_macs = map(lambda p: p['annotations']['portMac'], ports)
376 switch_map[device_id] = dict(uplink_vlan = 1,
377 serial = serial,
378 ports = onu_ports,
379 names = onu_names,
380 macs = onu_macs)
381 return switch_map
382
383 @classmethod
A R Karthickce96dde2017-10-05 16:41:52 -0700384 def sadis_load_config(cls, controller = None, olt_switch_map = {}, olt_conf_file = '', tagged_traffic = False):
A R Karthick1555c7c2017-09-07 14:59:41 -0700385 sadis_app = 'org.opencord.sadis'
386 aaa_app = 'org.opencord.aaa'
387 sadis_cfg = {
388 'apps' : {
389 sadis_app : {
390 'sadis' : {
391 'integration' : {
392 'cache' : {
393 'enabled' : False,
394 'maxsize' : 50,
A R Karthickefcf1ab2017-09-08 18:24:16 -0700395 'ttl' : 'PT0m',
A R Karthick1555c7c2017-09-07 14:59:41 -0700396 },
397 },
398 'entries' : [],
399 },
400 },
401 }
402 }
403 sadis_entries = sadis_cfg['apps'][sadis_app]['sadis']['entries']
404 nasId = '1/1/2'
405 nasPortId = '1/1/2'
406 switch_map = olt_switch_map.copy()
407 ovs_switch_map = cls.get_ovs_switch_map(controller = controller,
408 olt_conf_file = olt_conf_file)
409 #log_test.info('OVS switch map: %s' %ovs_switch_map)
410 switch_map.update(ovs_switch_map)
411 for device, entries in switch_map.iteritems():
412 uni_ports = entries['ports']
413 uni_port_names = entries['names']
414 uni_port_macs = entries['macs']
415 s_tag = entries['uplink_vlan']
416 serial = entries['serial']
417 #add entries for uni ports and device
418 for p in xrange(len(uni_ports)):
419 sadis_entry = dict(nasId = nasId, nasPortId = nasPortId, slot = 1)
420 sadis_entry['id'] = uni_port_names[p]
421 sadis_entry['hardwareIdentifier'] = uni_port_macs[p]
A R Karthickce96dde2017-10-05 16:41:52 -0700422 sadis_entry['cTag'] = uni_ports[p] if tagged_traffic else -1
423 sadis_entry['sTag'] = s_tag if tagged_traffic else -1
A R Karthick1555c7c2017-09-07 14:59:41 -0700424 sadis_entry['port'] = uni_ports[p]
425 sadis_entry['ipAddress'] = controller or cls.controller
426 sadis_entries.append(sadis_entry)
427 #add entry for the device itself
428 sadis_entry = dict(nasId = nasId, nasPortId = nasPortId, slot = 1)
429 sadis_entry['id'] = serial
430 sadis_entry['hardwareIdentifier'] = cls.device_id_to_mac(device)
A R Karthickce96dde2017-10-05 16:41:52 -0700431 sadis_entry['cTag'] = uni_ports[p] if tagged_traffic else -1
432 sadis_entry['sTag'] = s_tag if tagged_traffic else -1
A R Karthick1555c7c2017-09-07 14:59:41 -0700433 sadis_entry['port'] = uni_ports[p]
434 sadis_entry['ipAddress'] = controller or cls.controller
435 sadis_entries.append(sadis_entry)
436
437 #log_test.info('Sadis cfg: %s' %json.dumps(sadis_cfg, indent=4))
438 cls.config(sadis_cfg, controller = controller)
439
A R Karthickefcf1ab2017-09-08 18:24:16 -0700440 @classmethod
441 def config_olt_access(cls, uplink_vlan, controller = None, defaultVlan = '0', olt_conf_file = ''):
442 olt = OltConfig(olt_conf_file = olt_conf_file)
443 port_map, _ = olt.olt_port_map()
444 uplink = str(port_map['uplink'])
445 device_config = { 'devices' : {} }
446 ovs_devices = cls.get_devices(controller = controller, mfr = 'Nicira')
447 for dev in ovs_devices:
448 device_id = dev['id']
449 device_config['devices'][device_id] = {}
450 device_config['devices'][device_id]['basic'] = dict(driver = 'default')
451 device_config['devices'][device_id]['accessDevice'] = dict(uplink = uplink,
452 vlan = uplink_vlan,
453 defaultVlan = defaultVlan)
A R Karthick1555c7c2017-09-07 14:59:41 -0700454
A R Karthickefcf1ab2017-09-08 18:24:16 -0700455 cls.config(device_config, controller = controller)
A R Karthick21782982017-10-02 10:49:22 -0700456
457 @classmethod
458 def config_olt_component(cls, controller = None, enableDhcpIgmpOnProvisioning = True, defaultVlan = 0):
459 if controller is None:
460 controller = cls.controller
461 olt_property_url = 'configuration/org.opencord.olt.impl.Olt'
462 property_url = 'http://{}:8181/onos/v1/{}'.format(controller, olt_property_url)
463 cfg = dict(enableDhcpIgmpOnProvisioning = enableDhcpIgmpOnProvisioning, defaultVlan = defaultVlan)
464 resp = requests.post(property_url, auth = cls.auth, data = json.dumps(cfg))
465 return resp.ok, resp.status_code
A R Karthickc0a008f2017-10-04 18:35:25 -0700466
467 @classmethod
468 def config_extraneous_flows(cls, controller = None, enable = True):
469 if controller is None:
470 controller = cls.controller
471 flow_property_url = 'configuration/org.onosproject.net.flow.impl.FlowRuleManager'
472 property_url = 'http://{}:8181/onos/v1/{}'.format(controller, flow_property_url)
473 cfg = dict(allowExtraneousRules = enable)
474 resp = requests.post(property_url, auth = cls.auth, data = json.dumps(cfg))
475 return resp.ok, resp.status_code