blob: 48ee2151c6fc4193a9959f9a130647444ed72bdd [file] [log] [blame]
Rizwan Haider30b33792016-08-18 02:11:18 -04001import random
2
3from xos.logger import Logger, logging
Rizwan Haidereb2cc772016-09-08 12:14:55 -04004from services.metronetwork.models import *
Rizwan Haider30b33792016-08-18 02:11:18 -04005from synchronizers.metronetwork.providers.metronetworkprovider import MetroNetworkProvider
6
7logger = Logger(level=logging.INFO)
8
9
10class MetroNetworkTestProvider(MetroNetworkProvider):
11 def __init__(self, networkdevice, **args):
12 MetroNetworkProvider.__init__(self, networkdevice, **args)
13
14 # Method for retrieving all network ports from the backend system
15 def get_network_ports(self):
16 # Our Test Network Consists of 6 ports - two on each of three internal switches
17
18 objs = []
19
20 # For The Test Provider we don't handle re-sync for anything but the Metro Test Network
21 if self.networkdevice.id != 'TestMetroNet':
22 return objs
23
24 # Ok - in the test class we cheat and create the adjunct NetworkDevices Devices
25 device1 = NetworkDevice()
26 device1.id = 'TestCORD1Net'
27 device1.administrativeState = 'enabled'
28 device1.restCtrlUrl = 'testCordPod1.onlab.net:8000'
29 device1.username = 'karaf'
30 device1.password = 'karaf'
31 objs.append(device1)
32
33 device2 = NetworkDevice()
34 device2.id = 'TestCORD2Net'
35 device2.administrativeState = 'enabled'
36 device2.restCtrlUrl = 'testCordPod2.onlabl.net:8000'
37 device2.username = 'karaf'
38 device2.password = 'karaf'
39 objs.append(device2)
40
41 # Ok - here we go creating ports - its 4 ports for each CORD Pod and 2 for MetroNetwork
42
43 # Metro Network Switch
44 port1 = NetworkPort()
45 port1.element = self.networkdevice
46 port1.pid = self.networkdevice.id + "." + "of:000000001/1"
47 objs.append(port1)
48
49 port2 = NetworkPort()
50 port2.element = self.networkdevice
51 port2.pid = self.networkdevice.id + "." + "of:000000001/2"
52 objs.append(port2)
53
54 # CORD POD1
55 cordpod1device = NetworkDevice()
56 cordpod1device.id = 'TestCORD1Net'
57
58 port3 = NetworkEdgePort()
59 port3.element = cordpod1device
60 port3.pid = cordpod1device.id + "." + "of:000000001/1"
61 port3.bwpCfgCbs = 1000000
62 port3.bwpCfgEbs = 1000000
63 port3.bwpCfgEir = 1000000
64 port3.bwpCfgCir = 1000000
65 port3.bwpCfgCir = 1000000
66 objs.append(port3)
67
68 port4 = NetworkPort()
69 port4.element = cordpod1device
70 port4.pid = cordpod1device.id + "." + "of:000000001/2"
71 objs.append(port4)
72
73 # Internal Switch 3
74 port5 = NetworkEdgePort()
75 port5.element = cordpod1device
76 port5.pid = cordpod1device.id + "." + "of:000000001/3"
77 port5.bwpCfgCbs = 1000000
78 port5.bwpCfgEbs = 1000000
79 port5.bwpCfgEir = 1000000
80 port5.bwpCfgCir = 1000000
81 port5.bwpCfgCir = 1000000
82 objs.append(port5)
83
84 port6 = NetworkPort()
85 port6.element = cordpod1device
86 port6.capacity = 1000000000
87 port6.usedCapacity = 1000000000
88 port6.pid = cordpod1device.id + "." + "of:000000001/4"
89 objs.append(port6)
90
91 # CORD POD2
92 cordpod2device = NetworkDevice()
93 cordpod2device.id = 'TestCORD2Net'
94
95 port7 = NetworkEdgePort()
96 port7.element = cordpod2device
97 port7.pid = cordpod2device.id + "." + "of:000000001/1"
98 port7.bwpCfgCbs = 1000000
99 port7.bwpCfgEbs = 1000000
100 port7.bwpCfgEir = 1000000
101 port7.bwpCfgCir = 1000000
102 port7.bwpCfgCir = 1000000
103 objs.append(port7)
104
105 port8 = NetworkPort()
106 port8.element = cordpod2device
107 port8.pid = cordpod2device.id + "." + "of:000000001/2"
108 objs.append(port8)
109
110 # Internal Switch 3
111 port9 = NetworkEdgePort()
112 port9.element = cordpod2device
113 port9.pid = cordpod2device.id + "." + "of:000000001/3"
114 port9.bwpCfgCbs = 1000000
115 port9.bwpCfgEbs = 1000000
116 port9.bwpCfgEir = 1000000
117 port9.bwpCfgCir = 1000000
118 port9.bwpCfgCir = 1000000
119 objs.append(port9)
120
121 port10 = NetworkPort()
122 port10.element = cordpod2device
123 port10.pid = cordpod2device.id + "." + "of:000000001/4"
124 objs.append(port10)
125
126 return objs
127
128 def get_network_ports_for_deletion(self):
129
130 objs = []
131
132 # For The Test Provider we don't handle re-sync for anything but the Metro Test Network
133 if self.networkdevice.id != 'TestMetroNet':
134 return objs
135
136 allports = MetroNetworkProvider.get_network_ports_for_deletion(self)
137
138 for port in allports:
139 objs.append(port)
140
141 # Ok - in the test class we cheat and take down the adjunct Fake NetworkDevices Devices
142 device1 = NetworkDevice()
143 device1.id = 'TestCORD1Net'
144 objs.append(device1)
145
146 device2 = NetworkDevice()
147 device2.id = 'TestCORD2Net'
148 objs.append(device2)
149
150 return objs
151
152 def get_network_links(self):
153
154 objs = []
155
156 # Metro Link Connectivity object - Point to Point
157 metronetconnectivity = NetworkPointToPointConnection()
158 port1 = NetworkPort()
159 port1.pid = self.networkdevice.id + "." + "of:000000001/1"
160 port2 = NetworkPort()
161 port2.pid = self.networkdevice.id + "." + "of:000000001/2"
162 metronetconnectivity.src = port1
163 metronetconnectivity.dest = port2
164 metronetconnectivity.type = 'direct'
165 metronetconnectivity.operstate = 'active'
166 metronetconnectivity.adminstate = 'enabled'
167 metronetconnectivity.sid = 'MetroNetworkPointToPointConnectivity_1'
168 objs.append(metronetconnectivity)
169
170 # CORDPOD1 Connectivity object - Point to Point
171 cordpod1device = NetworkDevice()
172 cordpod1device.id = 'TestCORD1Net'
173
174 cordpod1connectivity = NetworkPointToPointConnection()
175 port6 = NetworkPort()
176 port6.pid = cordpod1device.id + "." + "of:000000001/4"
177 port4 = NetworkPort()
178 port4.pid = cordpod1device.id + "." + "of:000000001/2"
179 cordpod1connectivity.src = port6
180 cordpod1connectivity.dest = port4
181 cordpod1connectivity.type = 'direct'
182 cordpod1connectivity.operstate = 'active'
183 cordpod1connectivity.adminstate = 'enabled'
184 cordpod1connectivity.sid = 'CordPod1PointToPointConnectivity_1'
185 objs.append(cordpod1connectivity)
186
187 # CORDPOD2 Connectivity object - Point to Point
188 cordpod2device = NetworkDevice()
189 cordpod2device.id = 'TestCORD2Net'
190
191 cordpod2connectivity = NetworkPointToPointConnection()
192 port8 = NetworkPort()
193 port8.pid = cordpod2device.id + "." + "of:000000001/2"
194 port10 = NetworkPort()
195 port10.pid = cordpod2device.id + "." + "of:000000001/4"
196 cordpod2connectivity.src = port10
197 cordpod2connectivity.dest = port8
198 cordpod2connectivity.type = 'direct'
199 cordpod2connectivity.operstate = 'active'
200 cordpod2connectivity.adminstate = 'enabled'
201 cordpod2connectivity.sid = 'CordPod2PointToPointConnectivity_1'
202 objs.append(cordpod2connectivity)
203
204 # InterLink object between CORDPOD1 and MetroNet
205 interlink1 = NetworkInterLink()
206 interlink1.src = port1
207 interlink1.dest = port6
208 interlink1.state = 'active'
209 objs.append(interlink1)
210
211 # InterLink object between CORDPOD2 and MetroNet
212 interlink2 = NetworkInterLink()
213 interlink2.src = port2
214 interlink2.dest = port10
215 interlink2.state = 'active'
216 objs.append(interlink2)
217
218 # Edge to Edge Point Connectivity Objects
219 edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection()
220 port3 = NetworkEdgePort()
221 port3.pid = cordpod1device.id + "." + "of:000000001/1"
222 port7 = NetworkEdgePort()
223 port7.pid = cordpod2device.id + "." + "of:000000001/1"
224 edgetoedgeconnectivity.uni1 = port3
225 edgetoedgeconnectivity.uni2 = port7
226 edgetoedgeconnectivity.type = 'direct'
227 edgetoedgeconnectivity.operstate = 'active'
228 edgetoedgeconnectivity.adminstate = 'enabled'
229 edgetoedgeconnectivity.sid = 'EdgePointToEdgePointConnectivity_1'
230 objs.append(edgetoedgeconnectivity)
231
232 return objs
233
234 def get_network_links_for_deletion(self):
235
236 # For now we'll rely on cascade deletes in the port area - so from the test provider nothing to do
237 objs = []
238 return objs
239
240 def create_point_to_point_connectivity(self, obj):
241
242 # Ok - here is what we'll do to simulate the 'real world' - get a random number between 1 and 10
243 # 1-7 is considered 'successful' 8 is considered a transient error - 9 is a configuration problem
244 # 10 is a - resource exhausted problem - there you go!!
245 scenario = random.randint(1, 10)
246
247 if (scenario >= 1 and scenario <= 7):
248 obj.adminstate = 'enabled'
249 obj.operstate = 'active'
250 return True
251 elif (scenario == 8):
252 obj.adminstate = 'enabled'
253 obj.operstate = 'inactive'
254 obj.backend_status = '8 - Transient Server Error'
255 return False
256 elif (scenario == 9):
257 obj.adminstate = 'invalid'
258 obj.operstate = 'inactive'
259 obj.backend_status = '9 - Configuration Error'
260 return False
261 else:
262 obj.adminstate = 'enabled'
263 obj.operstate = 'inactive'
264 obj.backend_status = '10 - Resource Exhaustion'
265 return False
266
267 def delete_point_to_point_connectivity(self, obj):
268
269 # Ok - here is what we'll do to simulate the 'real world' - get a random number between 1 and 10
270 # 1-8 is considered 'successful' 8 is considered a transient error - 9 is a configuration problem
271 scenario = random.randint(1, 10)
272
273 if (scenario >= 1 and scenario <= 8):
274 obj.adminstate = 'disabled'
275 obj.operstate = 'inactive'
276 return True
277 elif (scenario == 9):
278 obj.adminstate = 'disabled'
279 obj.backend_status = '8 - Transient Server Error'
280 return False
281 else:
282 obj.adminstate = 'invalid'
283 obj.backend_status = '9 - Configuration Error'
284 return False