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