Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [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 Force Module. |
| 19 | Visualization of the topology in an SVG layer, using a D3 Force Layout. |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
| 25 | // injected refs |
| 26 | var $log, wss; |
| 27 | |
| 28 | // ========================== Helper Functions |
| 29 | |
| 30 | function init() { |
| 31 | $log.debug('Initialize topo force layout'); |
| 32 | } |
| 33 | |
| 34 | function destroy() { |
| 35 | $log.debug('Destroy topo force layout'); |
| 36 | } |
| 37 | |
| 38 | // ========================== Temporary Code (to be deleted later) |
| 39 | |
| 40 | function request(dir, rid) { |
| 41 | wss.sendEvent('topo2navRegion', { |
| 42 | dir: dir, |
| 43 | rid: rid |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | function doTmpCurrentLayout(data) { |
| 48 | var topdiv = d3.select('#topoXtmp'); |
| 49 | var parentRegion = data.parent; |
| 50 | var span = topdiv.select('.parentRegion').select('span'); |
| 51 | span.text(parentRegion || '[no parent]'); |
| 52 | span.classed('nav-me', !!parentRegion); |
| 53 | } |
| 54 | |
| 55 | function doTmpCurrentRegion(data) { |
| 56 | var topdiv = d3.select('#topoXtmp'); |
| 57 | var span = topdiv.select('.thisRegion').select('span'); |
| 58 | var div; |
| 59 | |
| 60 | span.text(data.id); |
| 61 | |
| 62 | div = topdiv.select('.subRegions').select('div'); |
| 63 | data.subregions.forEach(function (r) { |
| 64 | |
| 65 | function nav() { |
| 66 | request('down', r.id); |
| 67 | } |
| 68 | |
| 69 | div.append('p') |
| 70 | .classed('nav-me', true) |
| 71 | .text(r.id) |
| 72 | .on('click', nav); |
| 73 | }); |
| 74 | |
| 75 | div = topdiv.select('.devices').select('div'); |
| 76 | data.layerOrder.forEach(function (tag, idx) { |
| 77 | var devs = data.devices[idx]; |
| 78 | devs.forEach(function (d) { |
| 79 | div.append('p') |
| 80 | .text('[' + tag + '] ' + d.id); |
| 81 | }); |
| 82 | |
| 83 | }); |
| 84 | |
| 85 | div = topdiv.select('.hosts').select('div'); |
| 86 | data.layerOrder.forEach(function (tag, idx) { |
| 87 | var hosts = data.hosts[idx]; |
| 88 | hosts.forEach(function (h) { |
| 89 | div.append('p') |
| 90 | .text('[' + tag + '] ' + h.id); |
| 91 | }); |
| 92 | }); |
| 93 | |
| 94 | div = topdiv.select('.links').select('div'); |
| 95 | var links = data.links; |
| 96 | links.forEach(function (lnk) { |
| 97 | div.append('p') |
| 98 | .text(lnk.id); |
| 99 | }); |
| 100 | } |
| 101 | |
| 102 | function doTmpPeerRegions(data) { |
| 103 | |
| 104 | } |
| 105 | |
| 106 | // ========================== Event Handlers |
| 107 | |
| 108 | function allInstances(data) { |
| 109 | $log.debug('>> topo2AllInstances event:', data) |
| 110 | doTmpCurrentLayout(data); |
| 111 | } |
| 112 | |
| 113 | function currentLayout(data) { |
| 114 | $log.debug('>> topo2CurrentLayout event:', data) |
| 115 | } |
| 116 | |
| 117 | function currentRegion(data) { |
| 118 | $log.debug('>> topo2CurrentRegion event:', data) |
| 119 | doTmpCurrentRegion(data); |
| 120 | } |
| 121 | |
| 122 | function peerRegions(data) { |
| 123 | $log.debug('>> topo2PeerRegions event:', data) |
| 124 | doTmpPeerRegions(data); |
| 125 | } |
| 126 | |
| 127 | function startDone(data) { |
| 128 | $log.debug('>> topo2StartDone event:', data) |
| 129 | } |
| 130 | |
| 131 | // ========================== Main Service Definition |
| 132 | |
| 133 | angular.module('ovTopoX') |
| 134 | .factory('TopoXForceService', |
| 135 | ['$log', 'WebSocketService', |
| 136 | |
| 137 | function (_$log_, _wss_) { |
| 138 | $log = _$log_; |
| 139 | wss = _wss_; |
| 140 | |
| 141 | return { |
| 142 | init: init, |
| 143 | destroy: destroy, |
| 144 | topo2AllInstances: allInstances, |
| 145 | topo2CurrentLayout: currentLayout, |
| 146 | topo2CurrentRegion: currentRegion, |
| 147 | topo2PeerRegions: peerRegions, |
| 148 | topo2StartDone: startDone |
| 149 | }; |
| 150 | }]); |
| 151 | }()); |