blob: 3bcbb92cd78e8de7795ce03c7a6cb629c2564d80 [file] [log] [blame]
Rizwan Haider30b33792016-08-18 02:11:18 -04001import random
Rizwan Haider65baf552016-09-28 16:47:28 -04002import json
Rizwan Haider30b33792016-08-18 02:11:18 -04003
4from xos.logger import Logger, logging
Rizwan Haidereb2cc772016-09-08 12:14:55 -04005from services.metronetwork.models import *
Rizwan Haidere6ffdc02016-11-08 13:43:48 -05006from core.models import Site
Rizwan Haider30b33792016-08-18 02:11:18 -04007from synchronizers.metronetwork.providers.metronetworkprovider import MetroNetworkProvider
8
9logger = Logger(level=logging.INFO)
10
11
12class MetroNetworkTestProvider(MetroNetworkProvider):
13 def __init__(self, networkdevice, **args):
14 MetroNetworkProvider.__init__(self, networkdevice, **args)
15
16 # Method for retrieving all network ports from the backend system
17 def get_network_ports(self):
Rizwan Haider65baf552016-09-28 16:47:28 -040018 #
Rizwan Haidere6ffdc02016-11-08 13:43:48 -050019 # Our Test Network Consists of one NetworkDevice (which correspond to ONOS instance):
Rizwan Haider65baf552016-09-28 16:47:28 -040020 #
Rizwan Haidere6ffdc02016-11-08 13:43:48 -050021 # 8 Ports
22 # 1 Eline (2 ports)
23 # 1 Etree (3 ports)
24 # 1 Elan (3 ports)
Rizwan Haider65baf552016-09-28 16:47:28 -040025 #
Rizwan Haidere6ffdc02016-11-08 13:43:48 -050026 # 2 Sites - Representing Two R-CORD Pods
27 # 2 Ports, One-per-site
28 # 1 Bandwidth Profile
29 # 2 Service Spokes
30 # 1 VnodGlobalService
Rizwan Haider30b33792016-08-18 02:11:18 -040031
32 objs = []
33
34 # For The Test Provider we don't handle re-sync for anything but the Metro Test Network
35 if self.networkdevice.id != 'TestMetroNet':
36 return objs
37
Rizwan Haidere6ffdc02016-11-08 13:43:48 -050038 # Set the parent device id to just be the Test NetworkDevice
Rizwan Haider30b33792016-08-18 02:11:18 -040039 device1 = NetworkDevice()
Rizwan Haidere6ffdc02016-11-08 13:43:48 -050040 device1.id = self.networkdevice.id
Rizwan Haider30b33792016-08-18 02:11:18 -040041
Rizwan Haider65baf552016-09-28 16:47:28 -040042 port1 = NetworkEdgePort()
43 port1.element = device1
44 port1.pid = device1.id + "." + "of:000000001/1"
45 port1.bwpCfgCbs = 1000000
46 port1.bwpCfgEbs = 1000000
47 port1.bwpCfgEir = 1000000
48 port1.bwpCfgCir = 1000000
49 port1.location = "San Francisco"
50 port1.name = "Central Office 1"
51 port1.latlng = "[-122.419416, 37.774929]"
Rizwan Haider30b33792016-08-18 02:11:18 -040052 objs.append(port1)
53
Rizwan Haider65baf552016-09-28 16:47:28 -040054 port2 = NetworkEdgePort()
55 port2.element = device1
56 port2.pid = device1.id + "." + "of:000000001/2"
57 port2.bwpCfgCbs = 1000000
58 port2.bwpCfgEbs = 1000000
59 port2.bwpCfgEir = 1000000
60 port2.bwpCfgCir = 1000000
61 port2.location = "San Jose"
62 port2.name = "Central Office 2"
63 port2.latlng = "[-121.886329, 37.338208]"
Rizwan Haider30b33792016-08-18 02:11:18 -040064 objs.append(port2)
65
Rizwan Haider30b33792016-08-18 02:11:18 -040066 port3 = NetworkEdgePort()
Rizwan Haider65baf552016-09-28 16:47:28 -040067 port3.element = device1
68 port3.pid = device1.id + "." + "of:000000001/3"
Rizwan Haider30b33792016-08-18 02:11:18 -040069 port3.bwpCfgCbs = 1000000
70 port3.bwpCfgEbs = 1000000
71 port3.bwpCfgEir = 1000000
72 port3.bwpCfgCir = 1000000
Rizwan Haider65baf552016-09-28 16:47:28 -040073 port3.location = "Palo Alto"
74 port3.name = "Central Office 3"
75 port3.latlng = "[-122.143019, 37.441883]"
Rizwan Haider30b33792016-08-18 02:11:18 -040076 objs.append(port3)
77
Rizwan Haider65baf552016-09-28 16:47:28 -040078 port4 = NetworkEdgePort()
79 port4.element = device1
80 port4.pid = device1.id + "." + "of:000000001/4"
81 port4.bwpCfgCbs = 1000000
82 port4.bwpCfgEbs = 1000000
83 port4.bwpCfgEir = 1000000
84 port4.bwpCfgCir = 1000000
85 port4.location = "Oakland"
86 port4.name = "Central Office 4"
87 port4.latlng = "[-122.271114, 37.804364]"
Rizwan Haider30b33792016-08-18 02:11:18 -040088 objs.append(port4)
89
Rizwan Haider30b33792016-08-18 02:11:18 -040090 port5 = NetworkEdgePort()
Rizwan Haider65baf552016-09-28 16:47:28 -040091 port5.element = device1
92 port5.pid = device1.id + "." + "of:000000001/5"
Rizwan Haider30b33792016-08-18 02:11:18 -040093 port5.bwpCfgCbs = 1000000
94 port5.bwpCfgEbs = 1000000
95 port5.bwpCfgEir = 1000000
96 port5.bwpCfgCir = 1000000
Rizwan Haider65baf552016-09-28 16:47:28 -040097 port5.location = "San Rafael"
98 port5.name = "Central Office 5"
99 port5.latlng = "[-122.531087, 37.973535]"
Rizwan Haider30b33792016-08-18 02:11:18 -0400100 objs.append(port5)
101
Rizwan Haider65baf552016-09-28 16:47:28 -0400102 port6 = NetworkEdgePort()
103 port6.element = device1
104 port6.pid = device1.id + "." + "of:000000001/6"
105 port6.bwpCfgCbs = 1000000
106 port6.bwpCfgEbs = 1000000
107 port6.bwpCfgEir = 1000000
108 port6.bwpCfgCir = 1000000
109 port6.location = "San Mateo"
110 port6.name = "Central Office 6"
111 port6.latlng = "[-122.325525, 37.562992]"
Rizwan Haider30b33792016-08-18 02:11:18 -0400112 objs.append(port6)
113
Rizwan Haider30b33792016-08-18 02:11:18 -0400114 port7 = NetworkEdgePort()
Rizwan Haider65baf552016-09-28 16:47:28 -0400115 port7.element = device1
116 port7.pid = device1.id + "." + "of:000000001/7"
Rizwan Haider30b33792016-08-18 02:11:18 -0400117 port7.bwpCfgCbs = 1000000
118 port7.bwpCfgEbs = 1000000
119 port7.bwpCfgEir = 1000000
120 port7.bwpCfgCir = 1000000
Rizwan Haider65baf552016-09-28 16:47:28 -0400121 port7.location = "Hayward"
122 port7.name = "Central Office 7"
123 port7.latlng = "[-122.080796, 37.668821]"
Rizwan Haider30b33792016-08-18 02:11:18 -0400124 objs.append(port7)
125
Rizwan Haider65baf552016-09-28 16:47:28 -0400126 port8 = NetworkEdgePort()
127 port8.element = device1
128 port8.pid = device1.id + "." + "of:000000001/8"
129 port8.bwpCfgCbs = 1000000
130 port8.bwpCfgEbs = 1000000
131 port8.bwpCfgEir = 1000000
132 port8.bwpCfgCir = 1000000
133 port8.location = "Fremont"
134 port8.name = "Central Office 8"
135 port8.latlng = "[-121.988572, 37.548270]"
Rizwan Haider30b33792016-08-18 02:11:18 -0400136 objs.append(port8)
137
Rizwan Haider30b33792016-08-18 02:11:18 -0400138 return objs
139
140 def get_network_ports_for_deletion(self):
141
142 objs = []
143
144 # For The Test Provider we don't handle re-sync for anything but the Metro Test Network
145 if self.networkdevice.id != 'TestMetroNet':
146 return objs
147
148 allports = MetroNetworkProvider.get_network_ports_for_deletion(self)
149
150 for port in allports:
151 objs.append(port)
152
Rizwan Haider30b33792016-08-18 02:11:18 -0400153 return objs
154
155 def get_network_links(self):
156
157 objs = []
158
Rizwan Haider65baf552016-09-28 16:47:28 -0400159 # Connectivity object - Point to Point
Rizwan Haider30b33792016-08-18 02:11:18 -0400160 cordpod1device = NetworkDevice()
Rizwan Haidere6ffdc02016-11-08 13:43:48 -0500161 cordpod1device.id = self.networkdevice.id
Rizwan Haider30b33792016-08-18 02:11:18 -0400162
163 # Edge to Edge Point Connectivity Objects
164 edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection()
Rizwan Haider65baf552016-09-28 16:47:28 -0400165 edgetoedgeconnectivity.uni1_createbuffer = cordpod1device.id + "." + "of:000000001/1"
166 edgetoedgeconnectivity.uni2_createbuffer = cordpod1device.id + "." + "of:000000001/2"
Rizwan Haider30b33792016-08-18 02:11:18 -0400167 edgetoedgeconnectivity.type = 'direct'
168 edgetoedgeconnectivity.operstate = 'active'
169 edgetoedgeconnectivity.adminstate = 'enabled'
Rizwan Haider65baf552016-09-28 16:47:28 -0400170 edgetoedgeconnectivity.sid = 'EdgeToEdgePointConnectivity_1'
Rizwan Haider30b33792016-08-18 02:11:18 -0400171 objs.append(edgetoedgeconnectivity)
172
Rizwan Haider65baf552016-09-28 16:47:28 -0400173
174 # Multipoint to Multipoint Connectivity Objects
175 multipoint2multipointconnectivity=NetworkMultipointToMultipointConnection()
176 multipoint2multipointconnectivity.operstate = 'active'
177 multipoint2multipointconnectivity.adminstate = 'enabled'
178 multipoint2multipointconnectivity.type = 'ethernet'
179 multipoint2multipointconnectivity.sid = 'MultipointToMultipointConnectivity_1'
180
181 #
182 # Create JSON array for post-save behaviour
183 #
184 eps = []
185 eps.append(cordpod1device.id + "." + "of:000000001/3")
186 eps.append(cordpod1device.id + "." + "of:000000001/4")
187 eps.append(cordpod1device.id + "." + "of:000000001/5")
188
189 myjsonstr = {'eps': eps, 'foo':0, 'bar':0}
190 multipoint2multipointconnectivity.eps_createbuffer = json.dumps(myjsonstr)
191 objs.append(multipoint2multipointconnectivity)
192
193 # Edge to Multipoint Connectivity Objects
194 edge2multipointconnectivity = NetworkEdgeToMultipointConnection()
195 edge2multipointconnectivity.operstate = 'active'
196 edge2multipointconnectivity.adminstate = 'enabled'
197 edge2multipointconnectivity.type = 'ethernet'
198 edge2multipointconnectivity.sid = 'EdgeToMultipointConnectivity_1'
199 edge2multipointconnectivity.root_createbuffer = cordpod1device.id + "." + "of:000000001/7"
200 #
201 # Create JSON array for post-save behaviour
202 #
203 eps = []
204 eps.append(cordpod1device.id + "." + "of:000000001/6")
205 eps.append(cordpod1device.id + "." + "of:000000001/8")
206
207 myjsonstr = {'eps': eps, 'foo': 0, 'bar': 0}
208 edge2multipointconnectivity.eps_createbuffer = json.dumps(myjsonstr)
209 objs.append(edge2multipointconnectivity)
210
Rizwan Haidere6ffdc02016-11-08 13:43:48 -0500211 # Create Objects for VnodGlobal Sort of Testing
212
213 # Bandwidth Profile
214
215 bwprofile = BandwidthProfile()
216 bwprofile.bwpcfgcbs = 0
217 bwprofile.bwpcfgcir = 0
218 bwprofile.bwpcfgebs = 0
219 bwprofile.bwpcfgeir = 0
220 bwprofile.name = 'TestBWP'
221 objs.append(bwprofile)
222
223 # Two Sites
224 site1 = Site()
225 site1.name = 'CORDPod1'
226 site1.login_base = 'CordPod1'
227 site1.site_url = 'http://1.2.3.4:8080/VnodLocalApi'
228 objs.append(site1)
229
230 site2 = Site()
231 site2.name = 'CORDPod2'
232 site2.login_base = 'CordPod2'
233 site2.site_url = 'http://10.11.12.13:8080/VnodLocalApi'
234 objs.append(site2)
235
236 # Two Ports - one per Site
237
238 remoteport1 = RemotePort()
239 remoteport1.name = "CORDPOD1:Port1"
240 remoteport1.sitename = 'CordPod1'
241 remoteport1.edgeportname = cordpod1device.id + "." + "of:000000001/1"
242 objs.append(remoteport1)
243
244 remoteport2 = RemotePort()
245 remoteport2.name = "CORDPOD2:Port1"
246 remoteport2.sitename = 'CordPod2'
247 remoteport2.edgeportname = cordpod1device.id + "." + "of:000000001/2"
248 objs.append(remoteport2)
249
250 # One Spoke/Site
251 spoke1 = ServiceSpoke()
252 spoke1.name = 'TestSpoke1'
253 spoke1.remoteportname = "CORDPOD1:Port1"
254 spoke1.remotevnodid = 'CORDPod1:VnodLocal:1'
255 spoke1.operstate = 'inactive'
256 spoke1.adminstate = 'enabled'
257 spoke1.sitename = 'CordPod1'
258 objs.append(spoke1)
259
260 spoke2 = ServiceSpoke()
261 spoke2.name = 'TestSpoke2'
262 spoke2.remoteportname = "CORDPOD2:Port1"
263 spoke2.remotevnodid = 'CORDPod2:VnodLocal:1'
264 spoke2.operstate = 'active'
265 spoke2.adminstate = 'enabled'
266 spoke2.sitename = 'CordPod2'
267 objs.append(spoke2)
268
269 # One VnodGlobal Service
270 vnodglobal = VnodGlobalService()
271 vnodglobal.name = 'VnodGlobalPtToPtTest1'
272 vnodglobal.type = 'eline'
273 vnodglobal.vlanid = '100'
274 vnodglobal.operstate = 'active'
275 vnodglobal.adminstate = 'enabled'
276 vnodglobal.servicehandle = 'testhandle1'
277 vnodglobal.pointtopointsid = 'onos_eline_id'
278 vnodglobal.bwpname = 'TestBWP'
279
280 # Create JSON array for post-save behaviour
281 #
282 spokes = ['TestSpoke1', 'TestSpoke2']
283 myjsonstr = {'spokes': spokes}
284 vnodglobal.spokes_createbuffer = json.dumps(myjsonstr)
285 objs.append(vnodglobal)
Rizwan Haider65baf552016-09-28 16:47:28 -0400286
Rizwan Haider30b33792016-08-18 02:11:18 -0400287 return objs
288
289 def get_network_links_for_deletion(self):
290
291 # For now we'll rely on cascade deletes in the port area - so from the test provider nothing to do
292 objs = []
293 return objs
294
295 def create_point_to_point_connectivity(self, obj):
296
297 # Ok - here is what we'll do to simulate the 'real world' - get a random number between 1 and 10
298 # 1-7 is considered 'successful' 8 is considered a transient error - 9 is a configuration problem
299 # 10 is a - resource exhausted problem - there you go!!
300 scenario = random.randint(1, 10)
301
302 if (scenario >= 1 and scenario <= 7):
303 obj.adminstate = 'enabled'
304 obj.operstate = 'active'
305 return True
306 elif (scenario == 8):
307 obj.adminstate = 'enabled'
308 obj.operstate = 'inactive'
309 obj.backend_status = '8 - Transient Server Error'
310 return False
311 elif (scenario == 9):
312 obj.adminstate = 'invalid'
313 obj.operstate = 'inactive'
314 obj.backend_status = '9 - Configuration Error'
315 return False
316 else:
317 obj.adminstate = 'enabled'
318 obj.operstate = 'inactive'
319 obj.backend_status = '10 - Resource Exhaustion'
320 return False
321
322 def delete_point_to_point_connectivity(self, obj):
323
324 # Ok - here is what we'll do to simulate the 'real world' - get a random number between 1 and 10
325 # 1-8 is considered 'successful' 8 is considered a transient error - 9 is a configuration problem
326 scenario = random.randint(1, 10)
327
328 if (scenario >= 1 and scenario <= 8):
329 obj.adminstate = 'disabled'
330 obj.operstate = 'inactive'
331 return True
332 elif (scenario == 9):
333 obj.adminstate = 'disabled'
334 obj.backend_status = '8 - Transient Server Error'
335 return False
336 else:
337 obj.adminstate = 'invalid'
338 obj.backend_status = '9 - Configuration Error'
339 return False