9c71db50a3ffc22d7b30851622e4ff7159fca909
[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 import org.onap.policy.apex.examples.aadm.concepts.ImsiStatus;
21 import org.onap.policy.apex.examples.aadm.concepts.ENodeBStatus;
22
23 logger.debug(subject.id + ":" + subject.stateName + " execution logic");
24 logger.debug(inFields);
25
26 logger.debug("inFields[SERVICE_REQUEST_COUNT]=" + inFields["SERVICE_REQUEST_COUNT"]);
27
28 ImsiStatus imsiStatus = getContextAlbum("IMSIStatusAlbum").get((String)inFields["IMSI"]);
29
30 if (imsiStatus.getBlockingCount() > 1) {
31     subject.getTaskKey("AADMNoActTask").copyTo(selectedTask);
32     logger.debug("user blacklisted permanently");
33     return false;
34 }
35
36 logger.debug("imsi: " + imsiStatus.getImsi() + " anamalous " + imsiStatus.getAnomalous());
37
38 // check if this is second iteration
39 if (inFields["TCP_UE_SIDE_AVG_THROUGHPUT"] != null && inFields["TCP_UE_SIDE_AVG_THROUGHPUT"] > 100 && imsiStatus.getAnomalous()) {
40     subject.getTaskKey("AADMDoSProvenActTask").copyTo(selectedTask);
41     logger.debug("inside TCP_UE_SIDE_AVG_THROUGHPUT");
42     return true;
43 }
44
45 // Get the status of the ENodeB
46 ENodeBStatus eNodeBStatus = getContextAlbum("ENodeBStatusAlbum").get((String)inFields["ENODEB_ID"]);
47
48 // check if this is first iteration and DoS
49 if (inFields["SERVICE_REQUEST_COUNT"] != null &&
50         inFields["AVG_SUBSCRIBER_SERVICE_REQUEST"] != null &&
51         inFields["SERVICE_REQUEST_COUNT"] > inFields["AVG_SUBSCRIBER_SERVICE_REQUEST"] &&
52         eNodeBStatus != null && eNodeBStatus.getDosCount() > 100 &&
53         inFields["NUM_SUBSCRIBERS"] != null && inFields["NUM_SUBSCRIBERS"]  > 100) {
54     logger.debug("inside NUM_SUBSCRIBERS");
55     subject.getTaskKey("AADMDoSProvenActTask").copyTo(selectedTask);
56     return true;
57 }
58
59 // check if this is first iteration and request probe
60 if (inFields["UE_IP_ADDRESS"] != null) {
61     logger.debug("inside UE_IP_ADDRESS");
62     subject.getTaskKey("AADMDoSSuggestionActTask").copyTo(selectedTask);
63     return true;
64 }
65
66 subject.defaultTaskKey.copyTo(selectedTask);
67 return true;