Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | |
| 17 | /* |
| 18 | ONOS GUI -- Topology Region Module. |
| 19 | Module that holds the current region in memory |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame^] | 25 | // Injected Services |
| 26 | var $log, wss, t2sr, t2ds, t2hs, t2ls; |
| 27 | var Collection, Model; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 28 | |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame^] | 29 | //Internal |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 30 | var region; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 31 | |
| 32 | function init() { |
| 33 | regions = {}; |
| 34 | } |
| 35 | |
| 36 | function addRegion(data) { |
| 37 | |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame^] | 38 | var RegionModel = Model.extend({ |
| 39 | findNodeById: findNodeById |
| 40 | }) |
| 41 | |
| 42 | region = new RegionModel({ |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 43 | id: data.id, |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame^] | 44 | layerOrder: data.layerOrder, |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 45 | }); |
| 46 | |
| 47 | region.set({ |
| 48 | subregions: t2sr.createSubRegionCollection(data.subregions, region), |
| 49 | devices: t2ds.createDeviceCollection(data.devices, region), |
| 50 | hosts: t2hs.createHostCollection(data.hosts, region), |
| 51 | links: t2ls.createLinkCollection(data.links, region), |
| 52 | }); |
| 53 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 54 | angular.forEach(region.get('links').models, function (link) { |
| 55 | link.createLink(); |
| 56 | }); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 57 | |
| 58 | $log.debug('Region: ', region); |
| 59 | } |
| 60 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 61 | function regionNodes() { |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame^] | 62 | return [].concat( |
| 63 | region.get('devices').models, |
| 64 | region.get('hosts').models, |
| 65 | region.get('subregions').models |
| 66 | ); |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame^] | 69 | function findNodeById(id) { |
| 70 | |
| 71 | // Remove /{port} from id if needed |
| 72 | var regex = new RegExp('^[^\/]*'); |
| 73 | id = regex.exec(id)[0]; |
| 74 | |
| 75 | return region.get('devices').get(id) || |
| 76 | region.get('hosts').get(id) || |
| 77 | region.get('subregions').get(id); |
| 78 | } |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 79 | |
| 80 | function regionLinks() { |
| 81 | return region.get('links').models; |
| 82 | } |
| 83 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 84 | angular.module('ovTopo2') |
| 85 | .factory('Topo2RegionService', |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 86 | ['$log', 'WebSocketService', 'Topo2Model', 'Topo2SubRegionService', 'Topo2DeviceService', |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame^] | 87 | 'Topo2HostService', 'Topo2LinkService', 'Topo2Collection', |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 88 | |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame^] | 89 | function (_$log_, _wss_, _Model_, _t2sr_, _t2ds_, _t2hs_, _t2ls_, _Collection_) { |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 90 | |
| 91 | $log = _$log_; |
| 92 | wss = _wss_; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 93 | Model = _Model_ |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 94 | t2sr = _t2sr_; |
| 95 | t2ds = _t2ds_; |
| 96 | t2hs = _t2hs_; |
| 97 | t2ls = _t2ls_; |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame^] | 98 | Collection = _Collection_; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 99 | |
| 100 | return { |
| 101 | init: init, |
| 102 | |
| 103 | addRegion: addRegion, |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 104 | regionNodes: regionNodes, |
| 105 | regionLinks: regionLinks, |
| 106 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 107 | getSubRegions: t2sr.getSubRegions |
| 108 | }; |
| 109 | }]); |
| 110 | |
| 111 | })(); |