blob: f2f09c5fa9e8e15c565473fb3372379f5fe4dd7b [file] [log] [blame]
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -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 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);
Andrea Campanelladffc7d62016-03-07 12:01:14 -080050 flash.flash('Cleared source and destination');
Andrea Campanella48c674c2015-12-04 14:48:04 -080051 }
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
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080082 function setMode(mode) {
83 if (currentMode === mode) {
84 $log.debug('(in mode', mode, 'already)');
Andrea Campanella8583e6b2015-12-01 21:24:45 -080085 flash.flash('Already in ' + mode + ' mode');
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080086 } else {
87 currentMode = mode;
88 wss.sendEvent(modeMessage, {
89 mode: mode
90 });
91 flash.flash('Path mode: ' + mode);
92 }
93 }
94
95 // === ---------------------------
96 // === Module Factory Definition
97
98 angular.module('ovPpTopov', [])
99 .factory('PathPainterTopovService',
100 ['$log', 'FnService', 'FlashService', 'WebSocketService',
101
102 function (_$log_, _fs_, _flash_, _wss_) {
103 $log = _$log_;
104 fs = _fs_;
105 flash = _flash_;
106 wss = _wss_;
107
108 return {
109 setSrc: setSrc,
110 setDst: setDst,
111 setMode: setMode,
112 nextPath: nextPath,
Andrea Campanella0c17a0a2015-12-01 09:53:51 -0800113 prevPath: prevPath,
Andrea Campanella48c674c2015-12-04 14:48:04 -0800114 swapSrcDst: swapSrcDst,
115 clear: clear
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800116 };
117 }]);
118}());