blob: 3c3f17918482c0f396a258f3671eb142caae356c [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 Haider30b33792016-08-18 02:11:18 -04006from synchronizers.metronetwork.providers.metronetworkprovider import MetroNetworkProvider
7
8logger = Logger(level=logging.INFO)
9
10
11class MetroNetworkTestProvider(MetroNetworkProvider):
12 def __init__(self, networkdevice, **args):
13 MetroNetworkProvider.__init__(self, networkdevice, **args)
14
15 # Method for retrieving all network ports from the backend system
16 def get_network_ports(self):
Rizwan Haider65baf552016-09-28 16:47:28 -040017 #
18 # Our Test Network Consists of three NetworkDevices (which correspond to ONOS instances):
19 #
20 # ONOS1-CORDPOD1
21 # ONOS2-MetroNetwork
22 # ONOW3-CORDPOD2
23 #
24 #
25 # Uni-NetworkEdgePort3--
26 # Uni-NetworkEdgePort11-
27 # Uni-NetworkEdgePort5--ONOS1-CORDPOD1-NetworkPort6
28 # NetworkPort4-- |
29 # NetworkPort1-ONOS2-MetroNetwork
30 # NetworkPort2-
31 # |
32 # Uni-NetworkEdgePort7--ONOS3-CORDPOD2-NetworkPort10
33 # Uni-NetworkEdgePort9--
34 # Uni-NetworkEdgePort12-
35 # NetworkPort8--
36 #
37 # Note: NetworkPorts can be endpoints of Interlinks and NetworkPointToPointConnections
38 # they can be seem as a simple port.
39 # NetworkEdgePorts are UNIs in the network, so are specicially user facing.
40 #
41 #
42 # InterLinks - Port1 - Port6
43 # Port2 - Port10
44 #
45 # NetworkPointToPointConnections: Port1 - Port2
46 # Port4 - Port6
47 # Port8 - Port10
48 #
49 # NetworkEdgeToEdgePointConnections: Port3 - Port7
50 #
51 # NetworkMultipointConnection: Port11 - Port5 - Port9 - Port12
Rizwan Haider30b33792016-08-18 02:11:18 -040052
53 objs = []
54
55 # For The Test Provider we don't handle re-sync for anything but the Metro Test Network
56 if self.networkdevice.id != 'TestMetroNet':
57 return objs
58
Rizwan Haider65baf552016-09-28 16:47:28 -040059 # Ok - in the test class we cheat and create one NetworkDevice with 8 NetworkEdgePorts
Rizwan Haider30b33792016-08-18 02:11:18 -040060 device1 = NetworkDevice()
Rizwan Haider65baf552016-09-28 16:47:28 -040061 device1.id = 'TestCORDNet'
Rizwan Haider30b33792016-08-18 02:11:18 -040062 device1.administrativeState = 'enabled'
63 device1.restCtrlUrl = 'testCordPod1.onlab.net:8000'
64 device1.username = 'karaf'
65 device1.password = 'karaf'
66 objs.append(device1)
67
Rizwan Haider65baf552016-09-28 16:47:28 -040068 port1 = NetworkEdgePort()
69 port1.element = device1
70 port1.pid = device1.id + "." + "of:000000001/1"
71 port1.bwpCfgCbs = 1000000
72 port1.bwpCfgEbs = 1000000
73 port1.bwpCfgEir = 1000000
74 port1.bwpCfgCir = 1000000
75 port1.location = "San Francisco"
76 port1.name = "Central Office 1"
77 port1.latlng = "[-122.419416, 37.774929]"
Rizwan Haider30b33792016-08-18 02:11:18 -040078 objs.append(port1)
79
Rizwan Haider65baf552016-09-28 16:47:28 -040080 port2 = NetworkEdgePort()
81 port2.element = device1
82 port2.pid = device1.id + "." + "of:000000001/2"
83 port2.bwpCfgCbs = 1000000
84 port2.bwpCfgEbs = 1000000
85 port2.bwpCfgEir = 1000000
86 port2.bwpCfgCir = 1000000
87 port2.location = "San Jose"
88 port2.name = "Central Office 2"
89 port2.latlng = "[-121.886329, 37.338208]"
Rizwan Haider30b33792016-08-18 02:11:18 -040090 objs.append(port2)
91
Rizwan Haider30b33792016-08-18 02:11:18 -040092 port3 = NetworkEdgePort()
Rizwan Haider65baf552016-09-28 16:47:28 -040093 port3.element = device1
94 port3.pid = device1.id + "." + "of:000000001/3"
Rizwan Haider30b33792016-08-18 02:11:18 -040095 port3.bwpCfgCbs = 1000000
96 port3.bwpCfgEbs = 1000000
97 port3.bwpCfgEir = 1000000
98 port3.bwpCfgCir = 1000000
Rizwan Haider65baf552016-09-28 16:47:28 -040099 port3.location = "Palo Alto"
100 port3.name = "Central Office 3"
101 port3.latlng = "[-122.143019, 37.441883]"
Rizwan Haider30b33792016-08-18 02:11:18 -0400102 objs.append(port3)
103
Rizwan Haider65baf552016-09-28 16:47:28 -0400104 port4 = NetworkEdgePort()
105 port4.element = device1
106 port4.pid = device1.id + "." + "of:000000001/4"
107 port4.bwpCfgCbs = 1000000
108 port4.bwpCfgEbs = 1000000
109 port4.bwpCfgEir = 1000000
110 port4.bwpCfgCir = 1000000
111 port4.location = "Oakland"
112 port4.name = "Central Office 4"
113 port4.latlng = "[-122.271114, 37.804364]"
Rizwan Haider30b33792016-08-18 02:11:18 -0400114 objs.append(port4)
115
Rizwan Haider30b33792016-08-18 02:11:18 -0400116 port5 = NetworkEdgePort()
Rizwan Haider65baf552016-09-28 16:47:28 -0400117 port5.element = device1
118 port5.pid = device1.id + "." + "of:000000001/5"
Rizwan Haider30b33792016-08-18 02:11:18 -0400119 port5.bwpCfgCbs = 1000000
120 port5.bwpCfgEbs = 1000000
121 port5.bwpCfgEir = 1000000
122 port5.bwpCfgCir = 1000000
Rizwan Haider65baf552016-09-28 16:47:28 -0400123 port5.location = "San Rafael"
124 port5.name = "Central Office 5"
125 port5.latlng = "[-122.531087, 37.973535]"
Rizwan Haider30b33792016-08-18 02:11:18 -0400126 objs.append(port5)
127
Rizwan Haider65baf552016-09-28 16:47:28 -0400128 port6 = NetworkEdgePort()
129 port6.element = device1
130 port6.pid = device1.id + "." + "of:000000001/6"
131 port6.bwpCfgCbs = 1000000
132 port6.bwpCfgEbs = 1000000
133 port6.bwpCfgEir = 1000000
134 port6.bwpCfgCir = 1000000
135 port6.location = "San Mateo"
136 port6.name = "Central Office 6"
137 port6.latlng = "[-122.325525, 37.562992]"
Rizwan Haider30b33792016-08-18 02:11:18 -0400138 objs.append(port6)
139
Rizwan Haider30b33792016-08-18 02:11:18 -0400140 port7 = NetworkEdgePort()
Rizwan Haider65baf552016-09-28 16:47:28 -0400141 port7.element = device1
142 port7.pid = device1.id + "." + "of:000000001/7"
Rizwan Haider30b33792016-08-18 02:11:18 -0400143 port7.bwpCfgCbs = 1000000
144 port7.bwpCfgEbs = 1000000
145 port7.bwpCfgEir = 1000000
146 port7.bwpCfgCir = 1000000
Rizwan Haider65baf552016-09-28 16:47:28 -0400147 port7.location = "Hayward"
148 port7.name = "Central Office 7"
149 port7.latlng = "[-122.080796, 37.668821]"
Rizwan Haider30b33792016-08-18 02:11:18 -0400150 objs.append(port7)
151
Rizwan Haider65baf552016-09-28 16:47:28 -0400152 port8 = NetworkEdgePort()
153 port8.element = device1
154 port8.pid = device1.id + "." + "of:000000001/8"
155 port8.bwpCfgCbs = 1000000
156 port8.bwpCfgEbs = 1000000
157 port8.bwpCfgEir = 1000000
158 port8.bwpCfgCir = 1000000
159 port8.location = "Fremont"
160 port8.name = "Central Office 8"
161 port8.latlng = "[-121.988572, 37.548270]"
Rizwan Haider30b33792016-08-18 02:11:18 -0400162 objs.append(port8)
163
Rizwan Haider30b33792016-08-18 02:11:18 -0400164 return objs
165
166 def get_network_ports_for_deletion(self):
167
168 objs = []
169
170 # For The Test Provider we don't handle re-sync for anything but the Metro Test Network
171 if self.networkdevice.id != 'TestMetroNet':
172 return objs
173
174 allports = MetroNetworkProvider.get_network_ports_for_deletion(self)
175
176 for port in allports:
177 objs.append(port)
178
179 # Ok - in the test class we cheat and take down the adjunct Fake NetworkDevices Devices
180 device1 = NetworkDevice()
Rizwan Haider65baf552016-09-28 16:47:28 -0400181 device1.id = 'TestCORDNet'
Rizwan Haider30b33792016-08-18 02:11:18 -0400182 objs.append(device1)
183
Rizwan Haider30b33792016-08-18 02:11:18 -0400184 return objs
185
186 def get_network_links(self):
187
188 objs = []
189
Rizwan Haider65baf552016-09-28 16:47:28 -0400190 # Connectivity object - Point to Point
Rizwan Haider30b33792016-08-18 02:11:18 -0400191 cordpod1device = NetworkDevice()
Rizwan Haider65baf552016-09-28 16:47:28 -0400192 cordpod1device.id = 'TestCORDNet'
Rizwan Haider30b33792016-08-18 02:11:18 -0400193
194 # Edge to Edge Point Connectivity Objects
195 edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection()
Rizwan Haider65baf552016-09-28 16:47:28 -0400196 edgetoedgeconnectivity.uni1_createbuffer = cordpod1device.id + "." + "of:000000001/1"
197 edgetoedgeconnectivity.uni2_createbuffer = cordpod1device.id + "." + "of:000000001/2"
Rizwan Haider30b33792016-08-18 02:11:18 -0400198 edgetoedgeconnectivity.type = 'direct'
199 edgetoedgeconnectivity.operstate = 'active'
200 edgetoedgeconnectivity.adminstate = 'enabled'
Rizwan Haider65baf552016-09-28 16:47:28 -0400201 edgetoedgeconnectivity.sid = 'EdgeToEdgePointConnectivity_1'
Rizwan Haider30b33792016-08-18 02:11:18 -0400202 objs.append(edgetoedgeconnectivity)
203
Rizwan Haider65baf552016-09-28 16:47:28 -0400204
205 # Multipoint to Multipoint Connectivity Objects
206 multipoint2multipointconnectivity=NetworkMultipointToMultipointConnection()
207 multipoint2multipointconnectivity.operstate = 'active'
208 multipoint2multipointconnectivity.adminstate = 'enabled'
209 multipoint2multipointconnectivity.type = 'ethernet'
210 multipoint2multipointconnectivity.sid = 'MultipointToMultipointConnectivity_1'
211
212 #
213 # Create JSON array for post-save behaviour
214 #
215 eps = []
216 eps.append(cordpod1device.id + "." + "of:000000001/3")
217 eps.append(cordpod1device.id + "." + "of:000000001/4")
218 eps.append(cordpod1device.id + "." + "of:000000001/5")
219
220 myjsonstr = {'eps': eps, 'foo':0, 'bar':0}
221 multipoint2multipointconnectivity.eps_createbuffer = json.dumps(myjsonstr)
222 objs.append(multipoint2multipointconnectivity)
223
224 # Edge to Multipoint Connectivity Objects
225 edge2multipointconnectivity = NetworkEdgeToMultipointConnection()
226 edge2multipointconnectivity.operstate = 'active'
227 edge2multipointconnectivity.adminstate = 'enabled'
228 edge2multipointconnectivity.type = 'ethernet'
229 edge2multipointconnectivity.sid = 'EdgeToMultipointConnectivity_1'
230 edge2multipointconnectivity.root_createbuffer = cordpod1device.id + "." + "of:000000001/7"
231 #
232 # Create JSON array for post-save behaviour
233 #
234 eps = []
235 eps.append(cordpod1device.id + "." + "of:000000001/6")
236 eps.append(cordpod1device.id + "." + "of:000000001/8")
237
238 myjsonstr = {'eps': eps, 'foo': 0, 'bar': 0}
239 edge2multipointconnectivity.eps_createbuffer = json.dumps(myjsonstr)
240 objs.append(edge2multipointconnectivity)
241
242
Rizwan Haider30b33792016-08-18 02:11:18 -0400243 return objs
244
245 def get_network_links_for_deletion(self):
246
247 # For now we'll rely on cascade deletes in the port area - so from the test provider nothing to do
248 objs = []
249 return objs
250
251 def create_point_to_point_connectivity(self, obj):
252
253 # Ok - here is what we'll do to simulate the 'real world' - get a random number between 1 and 10
254 # 1-7 is considered 'successful' 8 is considered a transient error - 9 is a configuration problem
255 # 10 is a - resource exhausted problem - there you go!!
256 scenario = random.randint(1, 10)
257
258 if (scenario >= 1 and scenario <= 7):
259 obj.adminstate = 'enabled'
260 obj.operstate = 'active'
261 return True
262 elif (scenario == 8):
263 obj.adminstate = 'enabled'
264 obj.operstate = 'inactive'
265 obj.backend_status = '8 - Transient Server Error'
266 return False
267 elif (scenario == 9):
268 obj.adminstate = 'invalid'
269 obj.operstate = 'inactive'
270 obj.backend_status = '9 - Configuration Error'
271 return False
272 else:
273 obj.adminstate = 'enabled'
274 obj.operstate = 'inactive'
275 obj.backend_status = '10 - Resource Exhaustion'
276 return False
277
278 def delete_point_to_point_connectivity(self, obj):
279
280 # Ok - here is what we'll do to simulate the 'real world' - get a random number between 1 and 10
281 # 1-8 is considered 'successful' 8 is considered a transient error - 9 is a configuration problem
282 scenario = random.randint(1, 10)
283
284 if (scenario >= 1 and scenario <= 8):
285 obj.adminstate = 'disabled'
286 obj.operstate = 'inactive'
287 return True
288 elif (scenario == 9):
289 obj.adminstate = 'disabled'
290 obj.backend_status = '8 - Transient Server Error'
291 return False
292 else:
293 obj.adminstate = 'invalid'
294 obj.backend_status = '9 - Configuration Error'
295 return False