2 ==================================================================================
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
20 /* Author : Ashwin Sridharan
24 #define CATCH_CONFIG_MAIN
25 #include <catch2/catch.hpp>
28 #include <admission_policy.hpp>
30 #define SCHEMA_FILE "../schemas/adm-ctrl-xapp-policy-schema.json"
31 #define SAMPLE_FILE "../schemas/samples.json"
32 #define VES_FILE "../schemas/ves_schema.json"
35 bool report_mode_only = false;
37 TEST_CASE("Admission Policy Wrapper", "[acxapp]"){
40 mdclog_attr_init(&attr);
41 mdclog_attr_set_ident(attr, "UNIT TEST MESSAGE PROCESSOR ");
43 mdclog_level_set(MDCLOG_INFO);
44 mdclog_attr_destroy(attr);
47 SECTION("Invalid AC xAPP Schema"){
48 REQUIRE_THROWS( admission("hello there", SAMPLE_FILE, VES_FILE, 1));
51 SECTION("Invalid sample file"){
52 REQUIRE_THROWS(admission(SCHEMA_FILE, "hello there", VES_FILE, 1));
53 REQUIRE_THROWS(admission(SCHEMA_FILE, "random.txt", VES_FILE, 1));
56 SECTION("Invalid VES schema"){
57 REQUIRE_THROWS(admission(SCHEMA_FILE, SAMPLE_FILE, "hello there", 1));
60 SECTION("Set policy : invalid"){
61 std::string invalid_policy1 = "{\"blocking_rate\":20\"}";
62 std::string invalid_policy2 = "{\"blocking_rate\":120, \"enforce\":\"true\", \"window_length\":50, \"trigger_threshold\":10}";
66 admission adm_plugin(SCHEMA_FILE, SAMPLE_FILE, VES_FILE, 1);
67 res = adm_plugin.setPolicy(invalid_policy1.c_str(), invalid_policy1.length(), response);
69 REQUIRE(res == false);
70 REQUIRE_THAT(response, Catch::Matchers::Contains("FAIL"));
72 res = adm_plugin.setPolicy(invalid_policy2.c_str(), invalid_policy2.length(), response);
73 REQUIRE(res == false);
74 REQUIRE_THAT(response, Catch::Matchers::Contains("FAIL"));
78 SECTION("Set policy : valid"){
79 std::string valid_policy = "{\"blocking_rate\":20, \"enforce\":true, \"window_length\":50, \"trigger_threshold\":10}";
83 admission adm_plugin(SCHEMA_FILE, SAMPLE_FILE, VES_FILE, 1);
84 res = adm_plugin.setPolicy(valid_policy.c_str(), valid_policy.length(), response);
85 std::cout <<"Response = " << response << " for " << valid_policy << std::endl;
87 REQUIRE_THAT(response, Catch::Matchers::Contains("SUCCESS"));
94 SECTION("Get policy"){
96 std::string valid_policy = "{\"blocking_rate\":20, \"enforce\":true, \"window_length\":50, \"trigger_threshold\":10}";
100 // first apply policy
101 admission adm_plugin(SCHEMA_FILE, SAMPLE_FILE, VES_FILE, 1);
102 res = adm_plugin.setPolicy(valid_policy.c_str(), valid_policy.length(), response);
103 std::cout <<"Response = " << response << std::endl;
104 REQUIRE(res == true);
105 REQUIRE_THAT(response, Catch::Matchers::Contains("SUCCESS"));
108 // now retreive policy and check
109 res = adm_plugin.getPolicy(valid_policy.c_str(), valid_policy.length(), response);
110 REQUIRE(res == true);
112 REQUIRE_THAT(response, Catch::Matchers::Contains("\"trigger_threshold\":10"));
117 admission adm_plugin(SCHEMA_FILE, SAMPLE_FILE, VES_FILE, 1);
119 std::string response;
121 res = adm_plugin.getMetrics(response);
123 std::cout << "Metrics response = " << response << std::endl;
124 REQUIRE_THAT(response, Catch::Matchers::Contains("\"SgNB Request Rate\":\"0\""));
127 SECTION("Get plugin"){
128 admission adm_plugin(SCHEMA_FILE, SAMPLE_FILE, VES_FILE, 1);;
129 protector * p = NULL;
130 p = adm_plugin.get_protector_instance(100);
133 p = adm_plugin.get_protector_instance(0);
135 REQUIRE(p->get_requests() == 0);