Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 1 | /* |
| 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 Campanella | 0c17a0a | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 31 | swapMessage = 'ppTopovSwapSrcDst', |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 32 | modeMessage = 'ppTopovSetMode', |
| 33 | nextPathMessage = 'ppTopovNextPath', |
Andrea Campanella | 48c674c | 2015-12-04 14:48:04 -0800 | [diff] [blame] | 34 | clearMessage = 'ppTopovClear', |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 35 | 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 Campanella | 48c674c | 2015-12-04 14:48:04 -0800 | [diff] [blame] | 48 | function clear() { |
| 49 | wss.sendEvent(clearMessage); |
| 50 | flash.flash('Source node: ' + node.id); |
| 51 | } |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 52 | |
| 53 | function setSrc(node) { |
| 54 | wss.sendEvent(srcMessage, { |
Andrea Campanella | 490e839 | 2015-12-03 12:18:11 -0800 | [diff] [blame] | 55 | id: node.id, |
| 56 | type: node.type |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 57 | }); |
| 58 | flash.flash('Source node: ' + node.id); |
| 59 | } |
| 60 | |
| 61 | function setDst(node) { |
| 62 | wss.sendEvent(dstMessage, { |
Andrea Campanella | 490e839 | 2015-12-03 12:18:11 -0800 | [diff] [blame] | 63 | id: node.id, |
| 64 | type: node.type |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 65 | }); |
| 66 | flash.flash('Destination node: ' + node.id); |
| 67 | } |
| 68 | |
Andrea Campanella | 0c17a0a | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 69 | function swapSrcDst() { |
| 70 | wss.sendEvent(swapMessage) |
| 71 | flash.flash('Source and destination swap'); |
| 72 | } |
| 73 | |
| 74 | function nextPath() { |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 75 | wss.sendEvent(nextPathMessage); |
| 76 | } |
| 77 | |
Andrea Campanella | 0c17a0a | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 78 | function prevPath() { |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 79 | wss.sendEvent(prevPathMessage); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | function setMode(mode) { |
| 84 | if (currentMode === mode) { |
| 85 | $log.debug('(in mode', mode, 'already)'); |
Andrea Campanella | 8583e6b | 2015-12-01 21:24:45 -0800 | [diff] [blame] | 86 | flash.flash('Already in ' + mode + ' mode'); |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 87 | } 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 Campanella | 0c17a0a | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 114 | prevPath: prevPath, |
Andrea Campanella | 48c674c | 2015-12-04 14:48:04 -0800 | [diff] [blame] | 115 | swapSrcDst: swapSrcDst, |
| 116 | clear: clear |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 117 | }; |
| 118 | }]); |
| 119 | }()); |