blob: 79fc76069ddeae9797a6209cfc8e03e7cca07227 [file] [log] [blame]
Simon Huntbb596362015-01-26 21:27:42 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Simon Huntbb596362015-01-26 21:27:42 -08003 *
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 Event Module.
Simon Hunt24077f12015-02-04 17:58:21 -080019
20 Defines the conduit between the client and the server:
21 - provides a clean API for sending events to the server
Simon Hunt75ec9692015-02-11 16:40:36 -080022 - dispatches incoming events from the server to the appropriate sub-module
Simon Hunt24077f12015-02-04 17:58:21 -080023
Simon Huntbb596362015-01-26 21:27:42 -080024 */
25
26(function () {
27 'use strict';
28
Simon Huntfd1231a2015-01-26 22:14:51 -080029 // injected refs
Steven Burrows1c2a9682017-07-14 16:52:46 +010030 var $log, wss, tps, tis, tfs, tss, tov, tspr;
Simon Huntfd1231a2015-01-26 22:14:51 -080031
32 // internal state
Simon Hunt3b9ad04d2015-03-11 15:26:02 -070033 var handlerMap,
Simon Hunt45cd7262016-10-24 11:43:05 -070034 openListener;
Simon Hunt1894d792015-02-04 17:09:20 -080035
Simon Huntfd1231a2015-01-26 22:14:51 -080036 // ==========================
37
Simon Hunt20207df2015-03-10 18:30:14 -070038 function createHandlerMap() {
39 handlerMap = {
Simon Hunt24077f12015-02-04 17:58:21 -080040 showSummary: tps,
Simon Hunt08f841d02015-02-10 14:39:20 -080041
42 showDetails: tss,
43
Simon Hunt8d22c4b2015-08-06 16:24:43 -070044 showHighlights: tov,
Simon Huntf542d842015-02-11 16:20:33 -080045
Simon Hunt24077f12015-02-04 17:58:21 -080046 addInstance: tis,
47 updateInstance: tis,
48 removeInstance: tis,
Simon Hunt08f841d02015-02-10 14:39:20 -080049
Simon Hunt24077f12015-02-04 17:58:21 -080050 addDevice: tfs,
51 updateDevice: tfs,
52 removeDevice: tfs,
53 addHost: tfs,
54 updateHost: tfs,
Simon Hunt95d56fd2015-11-12 11:06:44 -080055 moveHost: tfs,
Simon Hunt24077f12015-02-04 17:58:21 -080056 removeHost: tfs,
57 addLink: tfs,
58 updateLink: tfs,
Simon Huntfd8c7d72015-04-14 17:53:37 -070059 removeLink: tfs,
60
Simon Hunt4a6b54b2015-10-27 22:08:25 -070061 topoStartDone: tfs,
62
Simon Huntfd8c7d72015-04-14 17:53:37 -070063 spriteListResponse: tspr,
Steven Burrows1c2a9682017-07-14 16:52:46 +010064 spriteDataResponse: tspr,
Simon Hunt24077f12015-02-04 17:58:21 -080065 };
66 }
67
Simon Hunt3b9ad04d2015-03-11 15:26:02 -070068 function wsOpen(host, url) {
69 $log.debug('TOPO: web socket open - cluster node:', host, 'URL:', url);
Thomas Vachuska4c2fa062015-03-23 15:07:55 -070070 // Request batch of initial data from the new server
71 wss.sendEvent('topoStart');
Simon Hunt3b9ad04d2015-03-11 15:26:02 -070072 }
73
Simon Hunt732bb2e2015-05-13 18:32:16 -070074
Simon Huntbb596362015-01-26 21:27:42 -080075 angular.module('ovTopo')
Simon Huntfd1231a2015-01-26 22:14:51 -080076 .factory('TopoEventService',
Steven Burrows1c2a9682017-07-14 16:52:46 +010077 ['$log', 'WebSocketService',
Simon Huntac4c6f72015-02-03 19:50:53 -080078 'TopoPanelService', 'TopoInstService', 'TopoForceService',
Simon Hunt8d22c4b2015-08-06 16:24:43 -070079 'TopoSelectService', 'TopoOverlayService', 'TopoSpriteService',
Simon Huntfd1231a2015-01-26 22:14:51 -080080
Steven Burrows1c2a9682017-07-14 16:52:46 +010081 function (_$log_, _wss_,
Simon Hunt8d22c4b2015-08-06 16:24:43 -070082 _tps_, _tis_, _tfs_, _tss_, _tov_, _tspr_) {
Simon Huntbb596362015-01-26 21:27:42 -080083 $log = _$log_;
Thomas Vachuska329af532015-03-10 02:08:33 -070084 wss = _wss_;
Simon Huntb0ec1e52015-01-28 18:13:49 -080085 tps = _tps_;
Simon Hunt4b668592015-01-29 17:33:53 -080086 tis = _tis_;
Simon Huntac4c6f72015-02-03 19:50:53 -080087 tfs = _tfs_;
Simon Hunt08f841d02015-02-10 14:39:20 -080088 tss = _tss_;
Simon Hunt8d22c4b2015-08-06 16:24:43 -070089 tov = _tov_;
Simon Huntfd8c7d72015-04-14 17:53:37 -070090 tspr = _tspr_;
Simon Huntbb596362015-01-26 21:27:42 -080091
Simon Hunt20207df2015-03-10 18:30:14 -070092 createHandlerMap();
Simon Hunt24077f12015-02-04 17:58:21 -080093
Simon Hunta4281242016-02-26 20:18:45 -080094 function bindHandlers() {
Simon Hunt20207df2015-03-10 18:30:14 -070095 wss.bindHandlers(handlerMap);
Simon Hunta4281242016-02-26 20:18:45 -080096 $log.debug('topo event handlers bound');
97 }
98
99 function start() {
100 // in case we fail over to a new server, listen for wsock-open
101 openListener = wss.addOpenListener(wsOpen);
Thomas Vachuska329af532015-03-10 02:08:33 -0700102 wss.sendEvent('topoStart');
103 $log.debug('topo comms started');
Simon Huntfd1231a2015-01-26 22:14:51 -0800104 }
105
Thomas Vachuska329af532015-03-10 02:08:33 -0700106 function stop() {
Thomas Vachuska329af532015-03-10 02:08:33 -0700107 wss.sendEvent('topoStop');
Simon Hunt20207df2015-03-10 18:30:14 -0700108 wss.unbindHandlers(handlerMap);
Simon Hunt3b9ad04d2015-03-11 15:26:02 -0700109 wss.removeOpenListener(openListener);
110 openListener = null;
Thomas Vachuska329af532015-03-10 02:08:33 -0700111 $log.debug('topo comms stopped');
Simon Huntfd1231a2015-01-26 22:14:51 -0800112 }
Simon Huntbb596362015-01-26 21:27:42 -0800113
114 return {
Simon Hunta4281242016-02-26 20:18:45 -0800115 bindHandlers: bindHandlers,
Thomas Vachuska329af532015-03-10 02:08:33 -0700116 start: start,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100117 stop: stop,
Simon Hunt737c89f2015-01-28 12:23:19 -0800118 };
Simon Huntbb596362015-01-26 21:27:42 -0800119 }]);
120}());