blob: baaaef98ec6461513284945b80ff18d92851eb0b [file] [log] [blame]
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -08001/*
2 * Copyright 2015 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 Sample Demo module. This contains the "business logic" for the topology
19 overlay that we are implementing.
20 */
21
22(function () {
23 'use strict';
24
25 // injected refs
26 var $log, fs, flash, wss;
27
28 // constants
29 var srcMessage = 'ppTopovSetSrc',
30 dstMessage = 'ppTopovSetDst',
Andrea Campanella0c17a0a2015-12-01 09:53:51 -080031 swapMessage = 'ppTopovSwapSrcDst',
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080032 modeMessage = 'ppTopovSetMode',
33 nextPathMessage = 'ppTopovNextPath',
Andrea Campanella48c674c2015-12-04 14:48:04 -080034 clearMessage = 'ppTopovClear',
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080035 prevPathMessage = 'ppTopovPrevPath';
36
37 // internal state
38 var currentMode = null;
39
40
41 // === ---------------------------
42 // === Helper functions
43
44
45 // === ---------------------------
46 // === Main API functions
47
Andrea Campanella48c674c2015-12-04 14:48:04 -080048 function clear() {
49 wss.sendEvent(clearMessage);
50 flash.flash('Source node: ' + node.id);
51 }
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080052
53 function setSrc(node) {
54 wss.sendEvent(srcMessage, {
Andrea Campanella490e8392015-12-03 12:18:11 -080055 id: node.id,
56 type: node.type
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080057 });
58 flash.flash('Source node: ' + node.id);
59 }
60
61 function setDst(node) {
62 wss.sendEvent(dstMessage, {
Andrea Campanella490e8392015-12-03 12:18:11 -080063 id: node.id,
64 type: node.type
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080065 });
66 flash.flash('Destination node: ' + node.id);
67 }
68
Andrea Campanella0c17a0a2015-12-01 09:53:51 -080069 function swapSrcDst() {
70 wss.sendEvent(swapMessage)
71 flash.flash('Source and destination swap');
72 }
73
74 function nextPath() {
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080075 wss.sendEvent(nextPathMessage);
76 }
77
Andrea Campanella0c17a0a2015-12-01 09:53:51 -080078 function prevPath() {
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080079 wss.sendEvent(prevPathMessage);
80 }
81
82
83 function setMode(mode) {
84 if (currentMode === mode) {
85 $log.debug('(in mode', mode, 'already)');
Andrea Campanella8583e6b2015-12-01 21:24:45 -080086 flash.flash('Already in ' + mode + ' mode');
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080087 } else {
88 currentMode = mode;
89 wss.sendEvent(modeMessage, {
90 mode: mode
91 });
92 flash.flash('Path mode: ' + mode);
93 }
94 }
95
96 // === ---------------------------
97 // === Module Factory Definition
98
99 angular.module('ovPpTopov', [])
100 .factory('PathPainterTopovService',
101 ['$log', 'FnService', 'FlashService', 'WebSocketService',
102
103 function (_$log_, _fs_, _flash_, _wss_) {
104 $log = _$log_;
105 fs = _fs_;
106 flash = _flash_;
107 wss = _wss_;
108
109 return {
110 setSrc: setSrc,
111 setDst: setDst,
112 setMode: setMode,
113 nextPath: nextPath,
Andrea Campanella0c17a0a2015-12-01 09:53:51 -0800114 prevPath: prevPath,
Andrea Campanella48c674c2015-12-04 14:48:04 -0800115 swapSrcDst: swapSrcDst,
116 clear: clear
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800117 };
118 }]);
119}());