c50dd97945aad5f43dbe17f98f547402888d68ea
[policy/apex-pdp.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 load("nashorn:mozilla_compat.js");
22
23 var now = new Date().getTime();
24 executor.outFields["matchStart"] = now;
25
26 importClass(org.slf4j.LoggerFactory);
27
28 var logger = executor.logger;
29 logger.trace("start: " + executor.subject.id);
30 logger.trace("-- infields: " + executor.inFields);
31
32 var rootLogger = LoggerFactory.getLogger(logger.ROOT_LOGGER_NAME);
33
34 var ifEdgeName = executor.inFields["edgeName"];
35 var ifLinkStatus = executor.inFields["status"];
36
37 var albumTopoEdges = executor.getContextAlbum("albumTopoEdges");
38
39 logger.trace("-- got infields, checking albumTopoEdges changes");
40
41 var active = false;
42 switch (ifLinkStatus.toString()) {
43 case "UP":
44     active = true;
45     break;
46 case "DOWN":
47     active = false;
48     break;
49 default:
50     active = false;
51     logger.error("-- trigger sent unknown link status <" + ifLinkStatus + "> for link <" + ifEdgeName + ">");
52     rootLogger.error(executor.subject.id + " " + "-- trigger sent unknown link status <" + ifLinkStatus
53             + "> for link <" + ifEdgeName + ">");
54 }
55
56 var link = albumTopoEdges.get(ifEdgeName);
57 if (link == null) {
58     logger.trace("-- link <" + ifEdgeName + "> not in albumTopoEdges");
59 } else {
60     logger.trace("-- found link <" + link + "> in albumTopoEdges");
61     logger.trace("-- active <" + active + "> : link.active <" + link.get("active") + ">");
62     if (active != link.get("active")) {
63         link.put("active", active);
64         logger.trace("-- link <" + ifEdgeName + "> status changed to <active:" + link.get("active") + ">");
65         executor.outFields["hasChanged"] = true;
66     } else {
67         logger.trace("-- link <" + ifEdgeName + "> status not changed <active:" + link.get("active") + ">");
68         executor.outFields["hasChanged"] = false;
69     }
70 }
71
72 executor.outFields["edgeName"] = ifEdgeName;
73 executor.outFields["status"] = ifLinkStatus;
74
75 logger.info("vpnsla: detected " + ifEdgeName + " as " + ifLinkStatus);
76
77 var returnValueType = Java.type("java.lang.Boolean");
78 var returnValue = new returnValueType(true);
79 logger.trace("finished: " + executor.subject.id);
80 logger.debug(".m");