topo2.js
7.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
ONOS GUI -- Topology View Module
NOTE: currently under development to support Regions.
*/
(function () {
'use strict';
// references to injected services
var $scope, $log, $loc,
fs, mast, ks, zs,
gs, ms, sus, flash,
wss, ps, th,
t2es, t2fs, t2is;
// DOM elements
var ovtopo2, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer;
// Internal state
var zoomer, actionMap;
// --- Glyphs, Icons, and the like -----------------------------------
function setUpDefs() {
defs = svg.append('defs');
gs.loadDefs(defs);
sus.loadGlowDefs(defs);
}
// callback invoked when the SVG view has been resized..
function svgResized(s) {
$log.debug('topo2 view resized', s);
t2fs.newDim([s.width, s.height]);
}
function setUpKeys(overlayKeys) {
$log.debug('topo2: set up keys....');
}
// --- Pan and Zoom --------------------------------------------------
// zoom enabled predicate. ev is a D3 source event.
function zoomEnabled(ev) {
return fs.isMobile() || (ev.metaKey || ev.altKey);
}
function zoomCallback() {
var sc = zoomer.scale(),
tr = zoomer.translate();
ps.setPrefs('topo_zoom', {tx:tr[0], ty:tr[1], sc:sc});
// keep the map lines constant width while zooming
// mapG.style('stroke-width', (2.0 / sc) + 'px');
}
function setUpZoom() {
zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer');
zoomer = zs.createZoomer({
svg: svg,
zoomLayer: zoomLayer,
zoomEnabled: zoomEnabled,
zoomCallback: zoomCallback
});
}
// === Controller Definition -----------------------------------------
angular.module('ovTopo2', ['onosUtil', 'onosSvg', 'onosRemote'])
.controller('OvTopo2Ctrl',
['$scope', '$log', '$location',
'FnService', 'MastService', 'KeyService', 'ZoomService',
'GlyphService', 'MapService', 'SvgUtilService', 'FlashService',
'WebSocketService', 'PrefsService', 'ThemeService',
'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService',
function (_$scope_, _$log_, _$loc_,
_fs_, _mast_, _ks_, _zs_,
_gs_, _ms_, _sus_, _flash_,
_wss_, _ps_, _th_,
_t2es_, _t2fs_, _t2is_) {
var params = _$loc_.search(),
projection,
dim,
wh,
uplink = {
// provides function calls back into this space
// showNoDevs: showNoDevs,
// projection: function () { return projection; },
// zoomLayer: function () { return zoomLayer; },
// zoomer: function () { return zoomer; },
// opacifyMap: opacifyMap,
// topoStartDone: topoStartDone
};
$scope = _$scope_;
$log = _$log_;
$loc = _$loc_;
fs = _fs_;
mast = _mast_;
ks = _ks_;
zs = _zs_;
gs = _gs_;
ms = _ms_;
sus = _sus_;
flash = _flash_;
wss = _wss_;
ps = _ps_;
th = _th_;
t2es = _t2es_;
t2fs = _t2fs_;
t2is = _t2is_;
// capture selected intent parameters (if they are set in the
// query string) so that the traffic overlay can highlight
// the path for that intent
if (params.intentKey && params.intentAppId && params.intentAppName) {
$scope.intentData = {
key: params.intentKey,
appId: params.intentAppId,
appName: params.intentAppName
};
}
$scope.notifyResize = function () {
svgResized(fs.windowSize(mast.mastHeight()));
};
// Cleanup on destroyed scope..
$scope.$on('$destroy', function () {
$log.log('OvTopo2Ctrl is saying Buh-Bye!');
t2es.stop();
ks.unbindKeys();
t2fs.destroy();
});
// svg layer and initialization of components
ovtopo2 = d3.select('#ov-topo2');
svg = ovtopo2.select('svg');
// set the svg size to match that of the window, less the masthead
wh = fs.windowSize(mast.mastHeight());
$log.debug('setting topo SVG size to', wh);
svg.attr(wh);
dim = [wh.width, wh.height];
// set up our keyboard shortcut bindings
setUpKeys();
setUpZoom();
setUpDefs();
// make sure we can respond to topology events from the server
t2es.bindHandlers();
// initialize the force layout, ready to render the topology
forceG = zoomLayer.append('g').attr('id', 'topo-force');
t2fs.init(svg, forceG, uplink, dim);
// =-=-=-=-=-=-=-=-
// TODO: in future, we will load background map data
// asynchronously (hence the promise) and then chain off
// there to send the topo2start event to the server.
// For now, we'll send the event inline...
t2es.start();
t2is.initInst({ showMastership: t2fs.showMastership });
// === ORIGINAL CODE ===
// setUpKeys();
// setUpToolbar();
// setUpDefs();
// setUpZoom();
// setUpNoDevs();
/*
setUpMap().then(
function (proj) {
var z = ps.getPrefs('topo_zoom', { tx:0, ty:0, sc:1 });
zoomer.panZoom([z.tx, z.ty], z.sc);
$log.debug('** Zoom restored:', z);
projection = proj;
$log.debug('** We installed the projection:', proj);
flash.enable(false);
toggleMap(prefsState.bg);
flash.enable(true);
mapShader(true);
// now we have the map projection, we are ready for
// the server to send us device/host data...
tes.start();
// need to do the following so we immediately get
// the summary panel data back from the server
restoreSummaryFromPrefs();
}
);
*/
// tes.bindHandlers();
// setUpSprites();
// forceG = zoomLayer.append('g').attr('id', 'topo-force');
// tfs.initForce(svg, forceG, uplink, dim);
// tis.initInst({ showMastership: tfs.showMastership });
// tps.initPanels();
// restoreConfigFromPrefs();
// ttbs.setDefaultOverlay(prefsState.ovidx);
// $log.debug('registered overlays...', tov.list());
$log.log('OvTopo2Ctrl has been created');
}]);
}());