RIC-641 Fixing client/server model definitions and adding client and server API 73/9973/9
authorsandeepindia <kumar.sandeep3@hcl.com>
Mon, 5 Dec 2022 18:47:19 +0000 (00:17 +0530)
committerSANDEEP KUMAR <kumar.sandeep3@hcl.com>
Wed, 14 Dec 2022 14:38:46 +0000 (14:38 +0000)
Signed-off-by: sandeepindia <kumar.sandeep3@hcl.com>
Change-Id: Ic177b9b7c417f1ccc184ae0e945b7748582604fe

50 files changed:
CMakeLists.txt
Dockerfile
src/model/ActionToBeSetup.cpp [new file with mode: 0644]
src/model/ActionToBeSetup.h [new file with mode: 0644]
src/model/CMakeLists.txt [new file with mode: 0644]
src/model/ConfigMetadata.cpp [new file with mode: 0644]
src/model/ConfigMetadata.h [new file with mode: 0644]
src/model/Dockerfile [new file with mode: 0644]
src/model/ModelBase.h [new file with mode: 0644]
src/model/RestModel.h [new file with mode: 0644]
src/model/SubscriptionData.cpp [new file with mode: 0644]
src/model/SubscriptionData.h [new file with mode: 0644]
src/model/SubscriptionDetail.cpp [new file with mode: 0644]
src/model/SubscriptionDetail.h [new file with mode: 0644]
src/model/SubscriptionInstance.cpp [new file with mode: 0644]
src/model/SubscriptionInstance.h [new file with mode: 0644]
src/model/SubscriptionParams.cpp [new file with mode: 0644]
src/model/SubscriptionParams.h [new file with mode: 0644]
src/model/SubscriptionParams_ClientEndpoint.cpp [new file with mode: 0644]
src/model/SubscriptionParams_ClientEndpoint.h [new file with mode: 0644]
src/model/SubscriptionParams_E2SubscriptionDirectives.cpp [new file with mode: 0644]
src/model/SubscriptionParams_E2SubscriptionDirectives.h [new file with mode: 0644]
src/model/SubscriptionResponse.cpp [new file with mode: 0644]
src/model/SubscriptionResponse.h [new file with mode: 0644]
src/model/SubsequentAction.cpp [new file with mode: 0644]
src/model/SubsequentAction.h [new file with mode: 0644]
src/model/XAppConfig.cpp [new file with mode: 0644]
src/model/XAppConfig.h [new file with mode: 0644]
src/model/temperory.h [new file with mode: 0644]
src/rest-client/CMakeLists.txt [new file with mode: 0644]
src/rest-client/RestClient.cpp [new file with mode: 0644]
src/rest-client/RestClient.h [new file with mode: 0644]
src/rest-server/CMakeLists.txt [new file with mode: 0644]
src/rest-server/pistacheserver.cpp [new file with mode: 0644]
src/rest-server/pistacheserver.h [new file with mode: 0644]
src/rest/CMakeLists.txt [deleted file]
src/rest/model/ActionToBeSetup.h [deleted file]
src/rest/model/CMakeLists.txt [deleted file]
src/rest/model/ConfigMetadata.h [deleted file]
src/rest/model/ModelBase.h [deleted file]
src/rest/model/RestModel.h [deleted file]
src/rest/model/SubscriptionData.h [deleted file]
src/rest/model/SubscriptionDetail.h [deleted file]
src/rest/model/SubscriptionInstance.h [deleted file]
src/rest/model/SubscriptionParams.h [deleted file]
src/rest/model/SubscriptionParams_ClientEndpoint.h [deleted file]
src/rest/model/SubscriptionParams_E2SubscriptionDirectives.h [deleted file]
src/rest/model/SubscriptionResponse.h [deleted file]
src/rest/model/SubsequentAction.h [deleted file]
test/Makefile

index 01f8da0..b17af09 100644 (file)
@@ -100,7 +100,7 @@ add_definitions(
        -DMAJOR_VER=${major_version}
        -DMINOR_VER=${minor_version}
        -DPATCH_VER=${patch_level}
-       -DDEBUG=${debugging}
+       #-DDEBUG=${debugging}
 )
 
 # ---------------- suss out pkg gen tools so we don't fail generating packages that the system cannot support --------------
@@ -156,10 +156,13 @@ set ( srcd "${CMAKE_CURRENT_SOURCE_DIR}" )
 # but Cmake insists on having these exist when we add them to include directories to
 # enable code to find them after we build them.
 #
-include_directories("${srcd}/src/messaging;${srcd}/src/json;${srcd}/src/alarm;${srcd}/src/metrics;${srcd}/src/config;${srcd}/src/rest/model;${srcd}/ext/jsmn")
+#include_directories( "${srcd}/src/messaging;${srcd}/src/json;${srcd}/src/alarm;${srcd}/src/metrics;${srcd}/src/config;${srcd}/ext/jsmn" )
+include_directories( "${srcd}/src/messaging;${srcd}/src/json;${srcd}/src/alarm;${srcd}/src/metrics;${srcd}/src/config;${srcd}/ext/jsmn;;${srcd}/src/model;${srcd}/src/rest-client;${srcd}/src/rest-server" )
 
 # Compiler flags
 #
+#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
+#set(CMAKE_CXX_STANDARD 17)
 set( CMAKE_POSITION_INDEPENDENT_CODE ON )
 set( CMAKE_C_FLAGS "-g " )
 set( CMAKE_CPP_FLAGS "-g " )
@@ -188,13 +191,16 @@ add_subdirectory( src/xapp )
 add_subdirectory( src/alarm )
 add_subdirectory( src/metrics )
 add_subdirectory( src/config )
-add_subdirectory( src/rest )
+add_subdirectory( src/model )
+add_subdirectory( src/rest-client )
+add_subdirectory( src/rest-server )
+
 #add_subdirectory( doc )                               # this will auto skip if {X}fm is not available
 
 # shared and static libraries are built from the same object files.
 #
 add_library( ricxfcpp_shared SHARED
-       "$<TARGET_OBJECTS:message_objects>;$<TARGET_OBJECTS:json_objects>;$<TARGET_OBJECTS:alarm_objects>;$<TARGET_OBJECTS:metrics_objects>;$<TARGET_OBJECTS:config_objects>;$<TARGET_OBJECTS:xapp_objects>"
+       "$<TARGET_OBJECTS:message_objects>;$<TARGET_OBJECTS:json_objects>;$<TARGET_OBJECTS:alarm_objects>;$<TARGET_OBJECTS:metrics_objects>;$<TARGET_OBJECTS:config_objects>;$<TARGET_OBJECTS:xapp_objects>;$<TARGET_OBJECTS:model_objects>;$<TARGET_OBJECTS:rest-client_objects>;$<TARGET_OBJECTS:rest-server_objects>"
 )
 set_target_properties( ricxfcpp_shared
        PROPERTIES
@@ -207,7 +213,7 @@ set_target_properties( ricxfcpp_shared
 # we only build/export the static archive (.a) if generating a dev package
 if( DEV_PKG )
        add_library( ricxfcpp_static STATIC
-               "$<TARGET_OBJECTS:message_objects>;$<TARGET_OBJECTS:json_objects>;$<TARGET_OBJECTS:alarm_objects>;$<TARGET_OBJECTS:config_objects>;$<TARGET_OBJECTS:metrics_objects>;$<TARGET_OBJECTS:xapp_objects>"
+               "$<TARGET_OBJECTS:message_objects>;$<TARGET_OBJECTS:json_objects>;$<TARGET_OBJECTS:alarm_objects>;$<TARGET_OBJECTS:config_objects>;$<TARGET_OBJECTS:metrics_objects>;$<TARGET_OBJECTS:xapp_objects>;$<TARGET_OBJECTS:model_objects>;$<TARGET_OBJECTS:rest-client_objects>;$<TARGET_OBJECTS:rest-server_objects>"
        )
        set_target_properties( ricxfcpp_static
                PROPERTIES
@@ -282,3 +288,4 @@ IF( EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake" )
 
        INCLUDE( CPack )
 ENDIF()
+
index b979228..e43a578 100644 (file)
@@ -58,6 +58,56 @@ ARG RMR_VER=4.8.5
 COPY ${SRC}/build_rmr.sh /playpen/bin
 RUN bash /playpen/bin/build_rmr.sh -t ${RMR_VER}
 
+#building cpprestsdk
+RUN apt-get install -y libcpprest-dev
+
+RUN apt-get install -y  g++ git libboost-atomic-dev libboost-thread-dev libboost-system-dev libboost-date-time-dev libboost-regex-dev libboost-filesystem-dev libboost-random-dev libboost-chrono-dev libboost-serialization-dev libwebsocketpp-dev openssl libssl-dev ninja-build zlib1g-dev
+
+RUN git clone https://github.com/Microsoft/cpprestsdk.git casablanca && \
+    cd casablanca && \
+    mkdir build && \
+    cd build && \
+    cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF -DBUILD_SAMPLES=OFF -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
+    ninja && \
+    ninja install && \
+    cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=0 -DBUILD_TESTS=OFF -DBUILD_SAMPLES=OFF -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
+    ninja && \
+    ninja install && \
+    rm -rf casablanca
+#installing all dependicies for pistache
+RUN apt-get update && apt-get install -y cmake gcc make \
+git g++ wget meson libcurl4-openssl-dev libssl-dev pkg-config ninja-build
+
+ RUN git clone https://github.com/Tencent/rapidjson && \
+      cd rapidjson && \
+     mkdir build && \
+     cd build && \
+    cmake -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
+   make install && \
+    cd ../../
+        #rm -rf rapidjson
+
+#building and installing pistache
+RUN git clone https://github.com/pistacheio/pistache.git
+RUN cd pistache && \
+        meson setup build \
+    --buildtype=release \
+    -DPISTACHE_USE_SSL=true \
+    -DPISTACHE_BUILD_EXAMPLES=true \
+    -DPISTACHE_BUILD_TESTS=true \
+    -DPISTACHE_BUILD_DOCS=false \
+    --prefix="/usr/local"
+RUN cd pistache/build && \
+        ninja && \
+        ninja install
+RUN cp /usr/local/lib/x86_64-linux-gnu/libpistache* /usr/local/lib/
+RUN cp /usr/local/lib/x86_64-linux-gnu/pkgconfig/libpistache.pc /usr/local/lib/pkgconfig
+
+#install nlohmann json
+RUN git clone https://github.com/nlohmann/json.git && cd json && cmake . && make install
+
+#install json-schema-validator
+RUN git clone https://github.com/pboettch/json-schema-validator.git && cd json-schema-validator &&mkdir build &&cd build && cmake .. && make install
 
 #copy the content as git repo inside the container.
 #COPY ${SRC}/CMakeLists.txt /playpen/factory/
@@ -84,24 +134,28 @@ RUN cd /playpen/factory/test; bash unit_test.sh
 
 
 # -----  final, smaller image ----------------------------------
-FROM ubuntu:20.04
-
+#FROM ubuntu:20.04
+FROM nexus3.o-ran-sc.org:10002/o-ran-sc/bldr-ubuntu20-c-go:1.0.0
 # must add compile tools to make it a builder environmnent. If a build environment isn't needed 
 # comment out the next line and reduce the image size by more than 180M.
 #
 RUN apt-get update && apt-get install -y --no-install-recommends make g++
 
 # if bash doesn't cut it for run_replay grab a real shell and clean up as much as we can
-RUN apt-get update; apt-get install -y ksh
+#RUN apt-get update; apt-get install -y ksh
 RUN rm -fr /var/lib/apt/lists 
 
 RUN mkdir -p /usr/local/include/ricxfcpp
 COPY --from=buildenv /usr/local/lib /usr/local/lib/
 COPY --from=buildenv /usr/local/include/ricxfcpp /usr/local/include/ricxfcpp/
 COPY --from=buildenv /usr/local/include/rmr /usr/local/include/rmr/
+COPY --from=buildenv /usr/local/include/cpprest /usr/local/include/cpprest/
+COPY --from=buildenv /usr/local/include/pplx /usr/local/include/pplx/
+COPY --from=buildenv /usr/local/include/pistache /usr/local/include/pistache/
 
 ENV LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib
 ENV C_INCLUDE_PATH=/usr/local/include
 WORKDIR /factory
 
 CMD [ "make" ]
+
diff --git a/src/model/ActionToBeSetup.cpp b/src/model/ActionToBeSetup.cpp
new file mode 100644 (file)
index 0000000..6bf6903
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"ActionToBeSetup.h"
+namespace xapp {
+       namespace model {
+               void from_json(const nlohmann::json & j, ActionToBeSetup& ref) {
+
+                       std::cout << __PRETTY_FUNCTION__ << std::endl;
+                       ref.validate_json(j);
+                       if (j.contains("ActionDefinition")) {
+                               j.at("ActionDefinition").get_to(ref.ActionDefinition);
+                       }
+                       j.at("ActionID").get_to(ref.ActionID);
+                       j.at("ActionType").get_to(ref.ActionType);
+                       if (j.contains("SubsequentAction")) {
+                               j.at("SubsequentAction").get_to(ref.m_SubsequentAction);
+                       }
+                       
+
+               }
+
+               void from_json(const nlohmann::json & j, std::vector<ActionToBeSetup>& ref) {
+
+                       std::cout << __PRETTY_FUNCTION__ << std::endl;
+
+                       for (auto& element : j) {
+                               ActionToBeSetup tmp;
+                               tmp.validate_json(element);
+                               for (auto& val : element.items())
+                               {
+                                       if (val.key() == "ActionDefinition") {
+
+                                               tmp.ActionDefinition.assign(val.value().begin(), val.value().end());
+
+                                       }
+                                       else if (val.key() == "ActionID") {
+                                               tmp.ActionID = val.value();
+                                       }
+                                       else if (val.key() == "ActionType") {
+                                               tmp.ActionType = val.value();
+                                       }
+                                       else if (val.key() == "SubsequentAction") {
+                                               tmp.m_SubsequentAction.SubsequentActionType = val.value()["SubsequentActionType"];
+                                               tmp.m_SubsequentAction.TimeToWait = val.value()["TimeToWait"];
+                                       }
+
+
+                               }
+                               ref.push_back(tmp);
+                       }
+
+               }
+               void to_json(nlohmann::json& j, const ActionToBeSetup& ref) {
+
+                       j = nlohmann::json{
+                               //{"ActionDefinition", ref.ActionDefinition},
+                               {"ActionID", ref.ActionID},
+                               {"ActionType", ref.ActionType}//,
+                               //{"SubsequentAction", {{"SubsequentActionType",ref.m_SubsequentAction.SubsequentActionType},{"TimeToWait", ref.m_SubsequentAction.TimeToWait } }}
+                       };
+                       if (ref.ActionDefinition.size() > 0) {
+                               j["ActionDefinition"] = ref.ActionDefinition;
+                       }
+                       if (ref.m_SubsequentAction.SubsequentActionType.length() > 0 && ref.m_SubsequentAction.TimeToWait.length() > 0) {
+                               j["SubsequentAction"] = ref.m_SubsequentAction;
+                       }
+
+               }
+
+               void to_json(nlohmann::json& j, const std::vector<ActionToBeSetup>& ref) {
+                       /*
+                       for (int i = 0; i < ref.size(); i++) {
+                               nlohmann::json tmp;
+                               tmp = nlohmann::json{
+                               {"ActionDefinition", ref[i].ActionDefinition},
+                               {"ActionID", ref[i].ActionID},
+                               {"ActionType", ref[i].ActionType},
+                               {"SubsequentAction", {{"SubsequentActionType",ref[i].m_SubsequentAction.SubsequentActionType},{"TimeToWait", ref[i].m_SubsequentAction.TimeToWait } }}
+                               };
+                               j.push_back(tmp);
+                       }
+                       */
+                       for (int i = 0; i < ref.size(); i++) {
+                               nlohmann::json tmp;
+                               to_json(tmp, ref[i]);
+                               j.push_back(tmp);
+                       }
+               }
+       }
+}
diff --git a/src/model/ActionToBeSetup.h b/src/model/ActionToBeSetup.h
new file mode 100644 (file)
index 0000000..2dd8e9c
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef _ActionToBeSetupList_H
+#define _ActionToBeSetupList_H
+#include"SubsequentAction.h"
+
+namespace xapp
+{
+       namespace model
+       {
+               struct ActionToBeSetup: public ModelBase
+               {
+                       int ActionID{0};
+                       std::string ActionType{""};
+                       //std::string SubsequentActionType{""};
+                       //std::string TimeToWait{""};
+                       SubsequentAction m_SubsequentAction; 
+                       std::vector<int> ActionDefinition{};
+
+                       nlohmann::json validator_schema = R"(
+                       {
+                       "$schema": "http://json-schema.org/draft-07/schema#",
+                       "title": "ActionToBeSetup",
+                       "properties": {
+                           "ActionDefinition": {
+                               "description": "Action Definition",
+                               "type": "array",
+                               "items": {
+                                   "type": "integer"
+                               }
+                           },
+                           "ActionID": {
+                               "description": "Identification of Action",
+                               "type": "integer",
+                               "minimum": 0,
+                               "maximum": 255
+                           },
+                           "ActionType": {
+                               "description": "Type of Action",
+                               "type": "string",
+                               "enum": ["policy", "insert", "report"]
+                           },
+                           "SubsequentAction": {
+                               "description": "Subsequent Action",
+                               "type": "object"
+                           }
+                       },
+                       "required": [
+                                    "ActionID",
+                                    "ActionType"
+                                   ],
+                       "type": "object"
+                       })"_json;
+
+                       virtual nlohmann::json get_validator_schema() const { return validator_schema; }
+
+               };
+
+               void from_json(const nlohmann::json & j, ActionToBeSetup& ref);
+               void from_json(const nlohmann::json & j, std::vector<ActionToBeSetup>& ref);
+               void to_json(nlohmann::json& j, const ActionToBeSetup& ref);
+               void to_json(nlohmann::json& j, const std::vector<ActionToBeSetup>& ref);
+
+       }
+       
+}
+
+
+#endif
+
diff --git a/src/model/CMakeLists.txt b/src/model/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1d61af0
--- /dev/null
@@ -0,0 +1,47 @@
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
+set(CMAKE_CXX_STANDARD 17)
+# BUILD TYPE
+message("A ${CMAKE_BUILD_TYPE} build configuration is detected")
+message("CPP flag is  ${CMAKE_CXX_FLAGS} ")
+message("CPP standard is  ${CMAKE_CXX_STANDARD} ")
+
+include_directories( "${srcd}/src/model")
+#SOURCE FILES
+file(GLOB SOURCE_FILES  "${srcd}/src/model/*.cpp" )
+
+
+add_library(model_objects OBJECT  ${SOURCE_FILES})
+
+target_include_directories (model_objects PUBLIC
+        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
+        $<INSTALL_INTERFACE:include>
+        PRIVATE src)
+
+# header files should go into .../include/xfcpp/
+
+file(GLOB SOURCE_INSTALL_FILES  "${srcd}/src/model/*.h")
+#set( install_inc_client "include/ricxfcpp/rest-client" )
+
+if( DEV_PKG )
+        install( FILES
+                 ${SOURCE_INSTALL_FILES}
+                DESTINATION ${install_inc}
+        )
+endif()
+
+
diff --git a/src/model/ConfigMetadata.cpp b/src/model/ConfigMetadata.cpp
new file mode 100644 (file)
index 0000000..503e7d0
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"ConfigMetadata.h"
+namespace xapp {
+       namespace model {
+
+               void from_json(const nlohmann::json& j, ConfigMetadata& ref) {
+
+                       std::cout << __func__ << " ConfigMetadata " << std::endl;
+                       ref.validate_json(j);
+                       j.at("configType").get_to(ref.ConfigType);
+                       j.at("xappName").get_to(ref.XappName);
+               }
+
+               void to_json(nlohmann::json& j, const ConfigMetadata& ref) {
+                       j = nlohmann::json{
+                               {"configType",ref.ConfigType},
+                               {"xappName", ref.XappName}
+                       };
+               }
+       }
+}
\ No newline at end of file
diff --git a/src/model/ConfigMetadata.h b/src/model/ConfigMetadata.h
new file mode 100644 (file)
index 0000000..465ac05
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef XAPP_MODEL_ConfigMetadata_H
+#define XAPP_MODEL_ConfigMetadata_H
+
+#include "ModelBase.h"
+
+namespace xapp {
+       namespace model {
+
+               struct ConfigMetadata : public ModelBase {
+                       std::string ConfigType;
+                       std::string XappName;
+                       nlohmann::json validator_schema = R"(
+                               {
+                               "$schema": "http://json-schema.org/draft-07/schema#",
+                               "title": "ConfigMetadata",
+                               "properties": {
+                                   "configType": {
+                                       "description": "Type of Config",
+                                       "type": "string",
+                                       "enum": ["json", "xml", "other"]
+                                   },
+                                   "xappName": {
+                                       "description": "Name of xApp",
+                                       "type": "string"
+                                   }
+                               },
+                               "required": [
+                                            "ConfigType",
+                                            "XappName"
+                                            ],
+                               "type": "object"
+                               })"_json;
+
+                       virtual nlohmann::json get_validator_schema() const { return validator_schema; }
+               };
+               void from_json(const nlohmann::json& j, ConfigMetadata& ref);
+               void to_json(nlohmann::json& j, const ConfigMetadata& ref);
+
+       } /*namespace model*/
+} /*namespace xapp*/
+#endif /*XAPP_MODEL_ConfigMetadata_H*/
diff --git a/src/model/Dockerfile b/src/model/Dockerfile
new file mode 100644 (file)
index 0000000..9b275c4
--- /dev/null
@@ -0,0 +1,16 @@
+FROM nexus3.o-ran-sc.org:10001/ubuntu:18.04
+RUN apt-get update && apt-get install -y cmake
+
+RUN apt-get install -y libcpprest-dev
+
+RUN apt-get install -y  g++ git libboost-atomic-dev libboost-thread-dev libboost-system-dev libboost-date-time-dev libboost-regex-dev libboost-filesystem-dev libboost-random-dev libboost-chrono-dev libboost-serialization-dev libwebsocketpp-dev openssl libssl-dev ninja-build zlib1g-dev
+RUN git clone https://github.com/Microsoft/cpprestsdk.git casablanca && \
+    cd casablanca && \
+    mkdir build && \
+    cd build && \
+    cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF -DBUILD_SAMPLES=OFF -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
+    ninja && \
+    ninja install
+RUN git clone https://github.com/nlohmann/json.git && cd json && cmake . && make install
+RUN git clone https://github.com/pboettch/json-schema-validator.git && cd json-schema-validator &&mkdir build &&cd build && cmake .. && make install
+COPY . ./
diff --git a/src/model/ModelBase.h b/src/model/ModelBase.h
new file mode 100644 (file)
index 0000000..2dfe3fc
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef _CleintModelBase_H
+#define _CleintModelBase_H
+#include<nlohmann/json.hpp>
+#include <nlohmann/json-schema.hpp>
+#include <type_traits>
+#include<vector>
+#include<string>
+#include<iostream>
+#include<limits.h>
+#include"temperory.h"
+namespace xapp
+{
+       namespace model
+       {
+               struct ModelBase {
+                       nlohmann::json validator_schema = R"(
+                       {
+                           "$schema": "http://json-schema.org/draft-07/schema#",
+                           "title": "ModelBase"
+                       })"_json;
+
+
+
+                       void validate_json(const nlohmann::json& _json) {
+                               nlohmann::json_schema::json_validator validator;
+                               validator.set_root_schema(get_validator_schema());
+                               
+                               try {
+                                       validator.validate(_json);
+                               }
+                               catch (const std::exception& e) {
+                                       throw;
+                               }
+                               
+                               return;
+                       }
+
+                       virtual nlohmann::json get_validator_schema() const { return validator_schema; }
+               };
+
+       }
+
+}
+
+
+#endif
diff --git a/src/model/RestModel.h b/src/model/RestModel.h
new file mode 100644 (file)
index 0000000..9e18758
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef XAPP_MODEL_H
+#define XAPP_MODEL_H
+#include "ModelBase.h"
+#include "SubsequentAction.h"
+#include "ActionToBeSetup.h"
+#include "SubscriptionResponse.h"
+#include "ConfigMetadata.h"
+#include "SubscriptionDetail.h"
+#include "SubscriptionParams_ClientEndpoint.h"
+#include "SubscriptionParams_E2SubscriptionDirectives.h"
+#include "SubscriptionParams.h"
+#include "SubscriptionInstance.h"
+#include "SubscriptionData.h"
+#include"SubscriptionDetail.h"
+#include"XAppConfig.h"
+//moved the implementation of model class into separate CPP file, in order to prevent ODR violation
+#endif
diff --git a/src/model/SubscriptionData.cpp b/src/model/SubscriptionData.cpp
new file mode 100644 (file)
index 0000000..b84c19c
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"SubscriptionData.h"
+namespace xapp {
+       namespace model {
+               void from_json(const nlohmann::json& j, SubscriptionData& ref) {
+
+                       std::cout << __PRETTY_FUNCTION__ << std::endl;
+                       ref.validate_json(j);
+                       if (j.contains("SubscriptionId")) {
+                               j.at("SubscriptionId").get_to(ref.SubscriptionID);
+                       }
+                       if (j.contains("SubscriptionInstances")) {
+                               j.at("SubscriptionInstances").get_to(ref.m_SubscriptionInstances);
+                       }
+                       
+                       if (j.contains("Meid")) {
+                               j.at("Meid").get_to(ref.Meid);
+                       }
+                       
+                       if (j.contains("ClientEndpoint")) {
+                               j.at("ClientEndpoint").get_to(ref.ClientEndpoint);
+                       }
+                       
+               }
+
+               void from_json(const nlohmann::json& j, std::vector<SubscriptionData>& ref) {
+                       for (auto& element : j) {
+                               SubscriptionData tmp;
+                               tmp.validate_json(element);
+                               for (auto& val : element.items())
+                               {
+                                       if (val.key() == "SubscriptionId") {
+                                               tmp.SubscriptionID = val.value();
+                                       }
+                                       else if (val.key() == "Meid") {
+                                               tmp.Meid = val.value();
+                                       }
+                                       else if (val.key() == "ClientEndpoint") {
+
+                                               tmp.ClientEndpoint.assign(val.value().begin(), val.value().end());
+                                       }
+                                       else if (val.key() == "SubscriptionInstances") {
+                                               from_json(val.value(), tmp.m_SubscriptionInstances);
+                                               /*
+                                               tmp.m_SubscriptionInstances.E2EventInstanceId= val.value()["E2EventInstanceId"];
+                                               tmp.m_SubscriptionInstances.XappEventInstanceId= val.value()["XappEventInstanceId"];
+                                               if (val.value().contains("ErrorCause"))
+                                               {
+                                                       tmp.m_SubscriptionInstances.ErrorCause= val.value()["ErrorCause"];
+                                               }
+                                               if (val.value().contains("ErrorSource"))
+                                               {
+                                                       tmp.m_SubscriptionInstances.ErrorCause = val.value()["ErrorSource"];
+                                               }
+                                               if (val.value().contains("TimeoutType"))
+                                               {
+                                                       tmp.m_SubscriptionInstances.ErrorCause = val.value()["TimeoutType"];
+                                               }
+                                               */
+
+                                       }
+                               }
+                               ref.push_back(tmp);
+                       }
+
+               }
+
+               void to_json(nlohmann::json& j, const SubscriptionData& ref) {
+                       /*
+                       j = nlohmann::json{
+                               {"SubscriptionId",ref.SubscriptionID},
+                               {"Meid",ref.Meid},
+                               {"ClientEndpoint", ref.ClientEndpoint}//,
+                               //{"SubscriptionInstances", {{"XappEventInstanceId", ref.m_SubscriptionInstances.XappEventInstanceId},{"E2EventInstanceId", ref.m_SubscriptionInstances.E2EventInstanceId},{"ErrorCause", ref.m_SubscriptionInstances.ErrorCause},{"ErrorSource", ref.m_SubscriptionInstances.ErrorSource},{"TimeoutType", ref.m_SubscriptionInstances.TimeoutType}}}
+
+                       };
+                       nlohmann::json tmp_j;
+                       to_json(tmp_j, ref.m_SubscriptionInstances);
+                       j["SubscriptionInstances"] = tmp_j;
+                       */
+                       if (ref.SubscriptionID != "") {
+                               j["SubscriptionId"] = ref.SubscriptionID;
+                       }
+                       if (ref.Meid.length() > 0) {
+                               j["Meid"] = ref.Meid;
+                       }
+                       if (ref.ClientEndpoint.size() > 0) {
+                               j["ClientEndpoint"] = ref.ClientEndpoint;
+                       }
+                       if (ref.m_SubscriptionInstances.size() > 0) {
+                               nlohmann::json tmp_j;
+                               to_json(tmp_j, ref.m_SubscriptionInstances);
+                               j["SubscriptionInstances"] = tmp_j;
+                       }
+               }
+               void to_json(nlohmann::json& j, const std::vector<SubscriptionData>& ref) {
+                       for (int i = 0; i < ref.size(); i++)
+                       {
+                               nlohmann::json tmp_j;
+                               to_json(tmp_j, ref[i]);
+                               j += tmp_j;
+                       }
+               }
+       }
+}
diff --git a/src/model/SubscriptionData.h b/src/model/SubscriptionData.h
new file mode 100644 (file)
index 0000000..1848c97
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef XAPP_MODEL_SubscriptionData_H
+#define XAPP_MODEL_SubscriptionData_H
+#include "SubscriptionInstance.h"
+namespace xapp {
+       namespace model {
+
+               struct SubscriptionData : ModelBase {
+                       std::vector<std::string> ClientEndpoint;
+                       std::string Meid;
+                       std::string SubscriptionID="";
+                       std::vector<SubscriptionInstance> m_SubscriptionInstances;
+
+                       nlohmann::json validator_schema = R"(
+                               {
+                               "$schema": "http://json-schema.org/draft-07/schema#",
+                               "title": "SubscriptionData",
+                               "properties": {
+                                   "SubscriptionId": {
+                                       "type": "string"
+                                   },
+                                   "Meid": {
+                                       "type": "string"
+                                   },
+                                   "ClientEndpoint": {
+                                       "type": "array",
+                                       "items": {
+                                           "type": "string"
+                                       }
+                                   },
+                                   "SubscriptionInstances": {
+                                       "type": "array"
+                                   }
+                               },
+                               "type": "object"
+                               })"_json;
+
+                       virtual nlohmann::json get_validator_schema() const { return validator_schema; }
+               };
+               void from_json(const nlohmann::json& j, SubscriptionData& ref);
+               void from_json(const nlohmann::json& j, std::vector<SubscriptionData>& ref);
+               void to_json(nlohmann::json& j, const SubscriptionData& ref);
+               void to_json(nlohmann::json& j, const std::vector<SubscriptionData>& ref);
+
+
+       } /*namespace model*/
+} /*namespace xapp*/
+#endif /*XAPP_MODEL_SubscriptionData_H*/
+
+
diff --git a/src/model/SubscriptionDetail.cpp b/src/model/SubscriptionDetail.cpp
new file mode 100644 (file)
index 0000000..4e62f8a
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"SubscriptionDetail.h"
+namespace xapp {
+       namespace model {
+               void from_json(const nlohmann::json& j, SubscriptionDetail& ref) {
+
+                       std::cout << __PRETTY_FUNCTION__ << std::endl;
+                       ref.validate_json(j);
+
+                       j.at("XappEventInstanceId").get_to(ref.XappEventInstanceId);
+                       j.at("EventTriggers").get_to(ref.EventTriggers);
+                       j.at("ActionToBeSetupList").get_to(ref.Data);
+               }
+
+               void from_json(const nlohmann::json& j, std::vector<SubscriptionDetail>& ref) {
+
+                       std::cout << __PRETTY_FUNCTION__ << std::endl;
+
+
+                       for (auto& element : j) {
+                               SubscriptionDetail tmp;
+                               tmp.validate_json(element);
+                               for (auto& val : element.items()) {
+                                       if (val.key() == "XappEventInstanceId") {
+
+                                               //tmp.SetXappEventInstanceId(val.value());
+                                               tmp.XappEventInstanceId = val.value();
+
+                                       }
+                                       else if (val.key() == "EventTriggers") {
+                                               //tmp.setEventTriggers(val.value());
+                                               tmp.EventTriggers.assign(val.value().begin(), val.value().end());
+
+
+                                       }
+                                       else if (val.key() == "ActionToBeSetupList") {
+
+                                               nlohmann::json tmp_j(val.value());
+                                               from_json(tmp_j, tmp.Data);
+                                       }
+                               }
+                               ref.push_back(tmp);
+
+                       }
+
+                       /*
+                       for (int i = 0; i < j.size(); i++)
+                       {
+                               ref[i].validate_json(j.at(i));
+                               j.at(i).at("XappEventInstanceId").get_to(ref[i].XappEventInstanceId);
+                               j.at(i).at("EventTriggers").get_to(ref[i].EventTriggers);
+                               j.at(i).at("ActionToBeSetupList").get_to(ref[i].Data);
+                       }
+                       */
+
+               }
+
+               void to_json(nlohmann::json& j, const SubscriptionDetail & ref) {
+
+                       j = nlohmann::json{
+                               {"XappEventInstanceId", ref.XappEventInstanceId},
+                               {"EventTriggers", ref.EventTriggers}
+                       };
+                       nlohmann::json tmp_j;
+                       to_json(tmp_j, ref.Data);
+                       j["ActionToBeSetupList"] = tmp_j;
+                       //for (int i = 0; i < ref.Data.size(); i++) {
+                       //      nlohmann::json tmp_j;
+                       //      to_json(tmp_j, ref.Data[i]);
+                       //      j["ActionToBeSetupList"] += tmp_j;
+                       //}
+               }
+               void to_json(nlohmann::json& j, const std::vector<SubscriptionDetail> & ref) {
+                       for (int i = 0; i < ref.size(); i++)
+                       {
+                               nlohmann::json tmp_j;
+                               to_json(tmp_j, ref[i]);
+                               j += tmp_j;
+                       }
+               }
+       }
+}
\ No newline at end of file
diff --git a/src/model/SubscriptionDetail.h b/src/model/SubscriptionDetail.h
new file mode 100644 (file)
index 0000000..19b7fb9
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef _SubscriptionDetails_H
+#define _SubscriptionDetails_H
+#include"ActionToBeSetup.h"
+
+namespace xapp
+{
+       namespace model
+       {
+               struct SubscriptionDetail : public ModelBase
+               {
+                       std::vector<ActionToBeSetup> Data;
+                       int XappEventInstanceId{0};
+                       std::vector<int> EventTriggers{};
+                       friend void from_json(const nlohmann::json& j, SubscriptionDetail& ref);
+                       friend void to_json(nlohmann::json& j, const SubscriptionDetail& ref);
+                       friend void from_json(const nlohmann::json& j, std::vector<SubscriptionDetail>& ref);
+                       nlohmann::json validator_schema = R"(
+                       {
+                       "$schema": "http://json-schema.org/draft-07/schema#",
+                       "title": "Subscription detail",
+                       "properties": {
+                           "XappEventInstanceId": {
+                               "type": "integer",
+                               "minimum": 0,
+                               "maximum": 255
+                           },
+                           "EventTriggers": {
+                               "description": "Identification of Action",
+                               "type": "array",
+                               "items": {
+                                   "type": "integer"
+                               }
+                           },
+                           "ActionToBeSetupList": {
+                               "type": "array"
+                           }
+                       },
+                       "required": [
+                                    "XappEventInstanceId",
+                                    "EventTriggers",
+                                    "ActionToBeSetupList"
+                                   ],
+                       "type": "object"
+                       })"_json;
+
+                       virtual nlohmann::json get_validator_schema() const { return validator_schema; }
+                       
+
+               };
+               void from_json(const nlohmann::json& j, SubscriptionDetail& ref);
+               void from_json(const nlohmann::json& j, std::vector<SubscriptionDetail>& ref);
+               void to_json(nlohmann::json& j, const SubscriptionDetail & ref);
+               void to_json(nlohmann::json& j, const std::vector<SubscriptionDetail> & ref);
+               
+
+       }
+}
+
+#endif
diff --git a/src/model/SubscriptionInstance.cpp b/src/model/SubscriptionInstance.cpp
new file mode 100644 (file)
index 0000000..3be4b20
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"SubscriptionInstance.h"
+namespace xapp {
+       namespace model {
+               void from_json(const nlohmann::json& j, SubscriptionInstance& ref) {
+
+                       std::cout << __PRETTY_FUNCTION__ << std::endl;
+                       ref.validate_json(j);
+
+                       j.at("XappEventInstanceId").get_to(ref.XappEventInstanceId);
+                       j.at("E2EventInstanceId").get_to(ref.E2EventInstanceId);
+                       j.at("ErrorCause").get_to(ref.ErrorCause);
+                       j.at("ErrorSource").get_to(ref.ErrorSource);
+                       j.at("TimeoutType").get_to(ref.TimeoutType);
+               }
+               void from_json(const nlohmann::json& j, std::vector<SubscriptionInstance>& ref) {
+
+                       std::cout << __PRETTY_FUNCTION__ << std::endl;
+                       for (auto& element : j) {
+                               SubscriptionInstance tmp;
+                               tmp.validate_json(element);
+                               for (auto& val : element.items())
+                               {
+
+
+                                       if (val.key() == "XappEventInstanceId") {
+
+                                               tmp.XappEventInstanceId = val.value();
+
+                                       }
+                                       else if (val.key() == "E2EventInstanceId") {
+                                               tmp.E2EventInstanceId = val.value();
+                                       }
+                                       else if (val.key() == "ErrorCause") {
+                                               tmp.ErrorCause = val.value();
+                                       }
+                                       else if (val.key() == "ErrorSource") {
+                                               tmp.ErrorSource = val.value();
+                                       }
+                                       else if (val.key() == "TimeoutType") {
+                                               tmp.TimeoutType = val.value();
+                                       }
+
+
+                               }
+                               ref.push_back(tmp);
+
+
+                       }
+
+
+               }
+
+               void to_json(nlohmann::json& j, const SubscriptionInstance& ref) {
+
+                       j = nlohmann::json{
+                               {"XappEventInstanceId", ref.XappEventInstanceId},
+                               {"E2EventInstanceId", ref.E2EventInstanceId},
+                               {"ErrorCause", ref.ErrorCause},
+                               {"ErrorSource", ref.ErrorSource},
+                               {"TimeoutType", ref.TimeoutType}
+                       };
+               }
+               void to_json(nlohmann::json& j, const std::vector<SubscriptionInstance>& ref) {
+
+
+                       for (int i = 0; i < ref.size(); i++)
+                       {
+
+                               nlohmann::json tmp = nlohmann::json{
+                               {"XappEventInstanceId", ref[i].XappEventInstanceId},
+                               {"E2EventInstanceId", ref[i].E2EventInstanceId},
+                               {"ErrorCause", ref[i].ErrorCause},
+                               {"ErrorSource", ref[i].ErrorSource},
+                               {"TimeoutType", ref[i].TimeoutType}
+                               };
+                               j.push_back(tmp);
+                       }
+               }
+       }
+}
\ No newline at end of file
diff --git a/src/model/SubscriptionInstance.h b/src/model/SubscriptionInstance.h
new file mode 100644 (file)
index 0000000..baff74f
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef SubscriptionInstance_H
+#define SubscriptionInstance_H
+#include"ModelBase.h"
+
+namespace xapp
+{
+       namespace model
+       {
+               struct SubscriptionInstance : public ModelBase
+               {
+               public:
+                       nlohmann::json validator_schema = R"(
+                       {
+                       "$schema": "http://json-schema.org/draft-07/schema#",
+                       "title": "SubscriptionInstance",
+                       "description": "xApp service address and port",
+                       "properties": {
+                           "XappEventInstanceId": {
+                               "type": "integer",
+                               "minimum": 0,
+                               "maximum": 65535
+                           },
+                           "E2EventInstanceId": {
+                               "type": "integer",
+                               "minimum": 0,
+                               "maximum": 65535
+                           },
+                           "ErrorCause": {
+                               "description": "Descriptive error cause. Empty string when no error.",
+                               "type": "string"
+                           },
+                           "ErrorSource": {
+                               "description": "Source of error cause.",
+                               "type": "string",
+                               "enum": ["SUBMGR", "RTMGR", "DBAAS", "ASN1", "E2Node"]
+                           },
+                           "TimeoutType": {
+                               "description": "Type timeout. xApp should retry if timeout occurs.",
+                               "type": "string",
+                               "enum": ["E2-Timeout", "RTMGR-Timeout", "DBAAS-Timeout"]
+                           }
+                       },
+                       "required": [
+                                    "XappEventInstanceId",
+                                    "E2EventInstanceId"
+                                    ],
+                       "type": "object"
+                       })"_json;
+                       virtual nlohmann::json get_validator_schema() const { return validator_schema; }
+                       int XappEventInstanceId{ 0 };
+                       int     E2EventInstanceId{ 0 };
+                       std::string     ErrorCause{ "" };
+                       std::string     ErrorSource{ "" };
+                       std::string     TimeoutType{ "" };
+               };
+               void from_json(const nlohmann::json& j, SubscriptionInstance& ref);
+               void from_json(const nlohmann::json& j, std::vector<SubscriptionInstance>& ref);
+               void to_json(nlohmann::json& j, const SubscriptionInstance& ref);
+               void to_json(nlohmann::json& j, const std::vector<SubscriptionInstance>& ref);
+
+       }
+       
+}
+#endif
diff --git a/src/model/SubscriptionParams.cpp b/src/model/SubscriptionParams.cpp
new file mode 100644 (file)
index 0000000..0d5d938
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"SubscriptionParams.h"
+namespace xapp {
+       namespace model {
+               void from_json(const nlohmann::json& j, SubscriptionParams& ref) {
+
+                       std::cout << __PRETTY_FUNCTION__ << std::endl;
+                       ref.validate_json(j);
+                       j.at("ClientEndpoint").get_to(ref.ClientEndpoint);
+
+                       if (j.contains("E2SubscriptionDirectives"))
+                       {
+                               j.at("E2SubscriptionDirectives").get_to(ref.E2SubscriptionDirectives);
+                       }
+
+                       if (j.contains("SubscriptionId"))
+                       {
+                               j.at("SubscriptionId").get_to(ref.SubscriptionId);
+                       }
+
+                       j.at("Meid").get_to(ref.Meid);
+                       j.at("RANFunctionID").get_to(ref.RANFunctionID);
+                       j.at("SubscriptionDetails").get_to(ref.Data);
+               }
+
+               void to_json(nlohmann::json& j, const SubscriptionParams& ref) {
+
+                       j = nlohmann::json{
+                               {"ClientEndpoint", ref.ClientEndpoint},
+                               //{"E2SubscriptionDirectives", ref.E2SubscriptionDirectives},
+                               {"Meid", ref.Meid},
+                               {"RANFunctionID", ref.RANFunctionID},
+                               {"SubscriptionId", ref.SubscriptionId}
+                       };
+                       if (ref.E2SubscriptionDirectives.E2RetryCount != INT_MIN && ref.E2SubscriptionDirectives.E2TimeoutTimerValue != INT_MIN) {
+                               //nlohmann::json tmp_j;
+                               //to_json(tmp_j, ref.E2SubscriptionDirectives);
+                               //j["E2SubscriptionDirectives"] = tmp_j;
+                               j["E2SubscriptionDirectives"] = ref.E2SubscriptionDirectives;
+                       }
+                       for (int i = 0; i < ref.Data.size(); i++) {
+                               nlohmann::json tmp_j;
+                               to_json(tmp_j, ref.Data[i]);
+                               j["SubscriptionDetails"] += tmp_j;
+                       }
+               }
+       }
+}
diff --git a/src/model/SubscriptionParams.h b/src/model/SubscriptionParams.h
new file mode 100644 (file)
index 0000000..0b65d0f
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef XAPP_MODEL_SubscriptionParams_H
+#define XAPP_MODEL_SubscriptionParams_H
+#include"SubscriptionDetail.h"
+#include"SubscriptionParams_ClientEndpoint.h"
+#include"SubscriptionParams_E2SubscriptionDirectives.h"
+
+namespace xapp
+
+{
+       namespace model {
+
+               struct SubscriptionParams:public ModelBase {
+
+                       std::string Host{ "" };
+                       int HTTPPort{ 0 };
+                       int RMRPort{ 0 };
+                       SubscriptionParams_ClientEndpoint ClientEndpoint;
+                       std::string Meid{ "" };
+                       int RANFunctionID{ 0 };
+                       std::string SubscriptionId{ "" };
+                       std::vector<SubscriptionDetail> Data;
+                       SubscriptionParams_E2SubscriptionDirectives E2SubscriptionDirectives;
+
+                       nlohmann::json validator_schema = R"(
+                       {
+                       "$schema": "http://json-schema.org/draft-07/schema#",
+                       "title": "SubscriptionParams",
+                       "properties": {
+                           "SubscriptionId": {
+                               "description": "Optional subscription ID '(Submgr allocates if not given)'",
+                               "type": "string"
+                           },
+                           "Meid": {
+                               "type": "string"
+                           },
+                           "RANFunctionID": {
+                               "type": "integer",
+                               "minimum": 0,
+                               "maximum": 4095
+                           },
+                               "ClientEndpoint":{
+                                       "type": "object"
+                               },
+                               "E2SubscriptionDirectives":{
+                                       "type": "object"
+                               },
+                               "SubscriptionDetails":{
+                                       "type": "array"
+                               }
+                       },
+                       "required": [
+                                    "ClientEndpoint",
+                                    "Meid",
+                                    "RANFunctionID",
+                                    "SubscriptionDetails"
+                                   ],
+                       "type": "object"
+                       })"_json;
+
+                       virtual nlohmann::json get_validator_schema() const { return validator_schema; }
+               };
+               void from_json(const nlohmann::json& j, SubscriptionParams& ref);
+               void to_json(nlohmann::json& j, const SubscriptionParams& ref);
+
+
+       }
+}
+#endif /*XAPP_MODEL_SubscriptionParams_H*/
diff --git a/src/model/SubscriptionParams_ClientEndpoint.cpp b/src/model/SubscriptionParams_ClientEndpoint.cpp
new file mode 100644 (file)
index 0000000..89d029d
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"SubscriptionParams_ClientEndpoint.h"
+namespace xapp {
+       namespace model {
+               void from_json(const nlohmann::json& j, SubscriptionParams_ClientEndpoint& ref) {
+
+                       std::cout << __PRETTY_FUNCTION__ << std::endl;
+                       ref.validate_json(j);
+                       j.at("HTTPPort").get_to(ref.HTTPPort);
+                       j.at("Host").get_to(ref.Host);
+                       j.at("RMRPort").get_to(ref.RMRPort);
+               }
+
+               void to_json(nlohmann::json& j, const SubscriptionParams_ClientEndpoint& ref) {
+                       j = nlohmann::json{
+                               {"HTTPPort", ref.HTTPPort},
+                               {"Host", ref.Host},
+                               {"RMRPort", ref.RMRPort},
+                       };
+               }
+       }
+}
\ No newline at end of file
diff --git a/src/model/SubscriptionParams_ClientEndpoint.h b/src/model/SubscriptionParams_ClientEndpoint.h
new file mode 100644 (file)
index 0000000..0096c38
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef XAPP_MODEL_SubscriptionParams_ClientEndpoint_H
+#define XAPP_MODEL_SubscriptionParams_ClientEndpoint_H
+#include "ModelBase.h"
+#include"nlohmann/json.hpp"
+
+namespace xapp {
+       namespace model {
+
+               struct SubscriptionParams_ClientEndpoint :public ModelBase {
+                       int HTTPPort;
+                       std::string Host;
+                       int RMRPort;
+                       nlohmann::json validator_schema = R"(
+                       {
+                       "$schema": "http://json-schema.org/draft-07/schema#",
+                       "title": "SubscriptionParams_ClientEndpoint",
+                       "description": "xApp service address and port",
+                       "properties": {
+                           "HTTPPort": {
+                               "description": "xApp HTTP service address port",
+                               "type": "integer",
+                               "minimum": 0,
+                               "maximum": 65535
+                           },
+                           "Host": {
+                               "description": "xApp service address name like service-ricxapp-xappname-http.ricxapp",
+                               "type": "string"
+                           },
+                           "RMRPort": {
+                               "description": "xApp RMR service address port",
+                               "type": "integer",
+                               "minimum": 0,
+                               "maximum": 65535
+                           }
+                       },
+                       "required": [
+                                    "HTTPPort",
+                                    "Host",
+                                    "RMRPort"
+                                    ],
+                       "type": "object"
+                       })"_json;
+
+                       virtual nlohmann::json get_validator_schema() const { return validator_schema; }
+
+               };
+               void from_json(const nlohmann::json& j, SubscriptionParams_ClientEndpoint& ref);
+               void to_json(nlohmann::json& j, const SubscriptionParams_ClientEndpoint& ref);
+
+               
+       } /*namespace model*/
+} /*namespace xapp*/
+#endif /*XAPP_MODEL_SubscriptionParams_ClientEndpoint_H*/
+
diff --git a/src/model/SubscriptionParams_E2SubscriptionDirectives.cpp b/src/model/SubscriptionParams_E2SubscriptionDirectives.cpp
new file mode 100644 (file)
index 0000000..cef5add
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"SubscriptionParams_E2SubscriptionDirectives.h"
+namespace xapp {
+       namespace model {
+               void from_json(const nlohmann::json& j, SubscriptionParams_E2SubscriptionDirectives& ref) {
+
+                       std::cout << __PRETTY_FUNCTION__ << std::endl;
+                       ref.validate_json(j);
+                       j.at("E2RetryCount").get_to(ref.E2RetryCount);
+                       j.at("E2TimeoutTimerValue").get_to(ref.E2TimeoutTimerValue);
+                       j.at("RMRRoutingNeeded").get_to(ref.RMRRoutingNeeded);
+               }
+
+               void to_json(nlohmann::json& j, const SubscriptionParams_E2SubscriptionDirectives& ref) {
+
+                       j = nlohmann::json{
+                               {"E2RetryCount", ref.E2RetryCount},
+                               {"E2TimeoutTimerValue", ref.E2TimeoutTimerValue},
+                               {"RMRRoutingNeeded", ref.RMRRoutingNeeded},
+                       };
+               }
+       }
+}
\ No newline at end of file
diff --git a/src/model/SubscriptionParams_E2SubscriptionDirectives.h b/src/model/SubscriptionParams_E2SubscriptionDirectives.h
new file mode 100644 (file)
index 0000000..897acb3
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef XAPP_MODEL_SubscriptionParams_E2SubscriptionDirectives_H
+#define XAPP_MODEL_SubscriptionParams_E2SubscriptionDirectives_H
+#include"ModelBase.h"
+#include"nlohmann/json.hpp"
+
+namespace xapp {
+       namespace model {
+
+               struct SubscriptionParams_E2SubscriptionDirectives : public ModelBase {
+
+                       int E2RetryCount=INT_MIN;
+                       int E2TimeoutTimerValue=INT_MIN;
+                       bool RMRRoutingNeeded;
+                       nlohmann::json validator_schema = R"(
+                       {
+                       "$schema": "http://json-schema.org/draft-07/schema#",
+                       "title": "SubscriptionParams_E2SubscriptionDirectives",
+                       "description": "Optional. If not set Submgr uses its default values",
+                       "properties": {
+                           "E2RetryCount": {
+                               "description": "How many times E2 subscription request is retried",
+                               "type": "integer",
+                               "minimum": 0,
+                               "maximum": 10
+                           },
+                           "E2TimeoutTimerValue": {
+                               "description": "How long time response is waited from E2 node",
+                               "type": "integer",
+                               "minimum": 0,
+                               "maximum": 10
+                           },
+                           "RMRRoutingNeeded": {
+                               "description": "Subscription needs RMR route from E2Term to xApp",
+                               "type": "boolean"
+                           }
+                       },
+                       "required": [
+                                    "E2TimeoutTimerValue",
+                                    "E2RetryCount",
+                                    "RMRRoutingNeeded"
+                                   ],
+                       "type": "object"
+                       })"_json;
+                       virtual nlohmann::json get_validator_schema() const { return validator_schema; }
+               };
+               
+               void from_json(const nlohmann::json& j, SubscriptionParams_E2SubscriptionDirectives& ref);
+               void to_json(nlohmann::json& j, const SubscriptionParams_E2SubscriptionDirectives& ref);
+
+               
+       } /*namespace model*/
+} /*namespace xapp*/
+#endif /*XAPP_MODEL_SubscriptionParams_ClientEndpoint_H*/
diff --git a/src/model/SubscriptionResponse.cpp b/src/model/SubscriptionResponse.cpp
new file mode 100644 (file)
index 0000000..d651e92
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"SubscriptionResponse.h"
+namespace xapp {
+       namespace model {
+               void from_json(const  nlohmann::json& j, SubscriptionResponse& ref) {
+
+                       std::cout << __PRETTY_FUNCTION__ << std::endl;
+                       ref.validate_json(j);
+
+                       j.at("SubscriptionId").get_to(ref.SubscriptionId);
+                       j.at("SubscriptionInstances").get_to(ref.SubInst);
+               }
+
+               void to_json(nlohmann::json& j, const SubscriptionResponse& ref) {
+
+                       //j = nlohmann::json{
+                       //      {"SubscriptionId",ref.SubscriptionId},
+                       //      {"SubscriptionInstances", ref.SubInst}
+                       //};
+                       j = nlohmann::json{
+                               {"SubscriptionId",ref.SubscriptionId}
+                       };
+                       for (int i = 0; i < ref.SubInst.size(); i++)
+                       {
+                               j["SubscriptionInstances"] += nlohmann::json{
+                               {"XappEventInstanceId", ref.SubInst[i].XappEventInstanceId},
+                               {"E2EventInstanceId", ref.SubInst[i].E2EventInstanceId},
+                               {"ErrorCause", ref.SubInst[i].ErrorCause},
+                               {"ErrorSource", ref.SubInst[i].ErrorSource},
+                               {"TimeoutType", ref.SubInst[i].TimeoutType}
+                               };
+                       }
+
+               }
+       }
+}
\ No newline at end of file
diff --git a/src/model/SubscriptionResponse.h b/src/model/SubscriptionResponse.h
new file mode 100644 (file)
index 0000000..d6b93ab
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef XAPP_MODEL_SubscriptionResponse_H
+#define XAPP_MODEL_SubscriptionResponse_H
+#include"SubscriptionInstance.h"
+namespace xapp
+{
+       namespace model {
+               struct SubscriptionResponse:public ModelBase
+               {
+                       nlohmann::json validator_schema = R"(
+                       {
+                       "$schema": "http://json-schema.org/draft-07/schema#",
+                       "title": "SubscriptionResponse",
+                       "properties": {
+                           "SubscriptionId": {
+                               "description": "Indentification of Subscription",
+                               "type": "integer"
+                           },
+                           "SubscriptionInstances": {
+                               "description": "List of Subscription Instance",
+                               "type": "array"
+                           }
+                       },
+                       "required": [
+                                    "SubscriptionId",
+                                    "SubscriptionInstances"
+                                    ],
+                       "type": "object"
+                       })"_json;
+
+                       virtual nlohmann::json get_validator_schema() const { return validator_schema; }
+                       std::string SubscriptionId{ "" };
+                       std::vector<SubscriptionInstance > SubInst;
+
+               };
+               void from_json(const  nlohmann::json& j, SubscriptionResponse& ref);
+               void to_json(nlohmann::json& j, const SubscriptionResponse& ref);
+
+       }
+
+}
+#endif
+
diff --git a/src/model/SubsequentAction.cpp b/src/model/SubsequentAction.cpp
new file mode 100644 (file)
index 0000000..d646ffa
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"SubsequentAction.h"
+namespace xapp {
+       namespace model {
+               void from_json(const nlohmann::json& j, SubsequentAction& ref) {
+
+                       std::cout << __PRETTY_FUNCTION__ << "\n";
+                       ref.validate_json(j);
+
+                       j.at("SubsequentActionType").get_to(ref.SubsequentActionType);
+                       j.at("TimeToWait").get_to(ref.TimeToWait);
+               }
+
+               void to_json(nlohmann::json& j, const SubsequentAction& ref) {
+
+                       j = nlohmann::json{
+                               {"SubsequentActionType",ref.SubsequentActionType},
+                               {"TimeToWait", ref.TimeToWait}
+                       };
+               }
+       }
+}
\ No newline at end of file
diff --git a/src/model/SubsequentAction.h b/src/model/SubsequentAction.h
new file mode 100644 (file)
index 0000000..3ffa29d
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef SubsequentAction_H
+#define SubsequentAction_H
+#include"ModelBase.h"
+namespace xapp
+{
+       namespace model
+       {
+               struct SubsequentAction : public ModelBase {
+                       std::string SubsequentActionType;
+                       std::string TimeToWait;
+                       nlohmann::json validator_schema = R"(
+                       {
+                       "$schema": "http://json-schema.org/draft-07/schema#",
+                       "title": "SubsequentAction",
+                       "properties": {
+                           "SubsequentActionType": {
+                               "description": "Type of Subsequent Action",
+                               "type": "string",
+                               "enum": ["wait", "continue"]
+
+                           },
+                           "TimeToWait": {
+                               "description": "Time to waiting",
+                               "type": "string",
+                               "enum": ["zero", "w1ms", "w2ms", "w5ms", "w10ms", "w20ms", "w30ms",
+                                       "w40ms", "w50ms", "w100ms", "w200ms", "w500ms", "w1s",
+                                       "w2s", "w5s", "w10s", "w20s", "w60s"]
+                           }
+                       },
+                       "required": [
+                                    "SubsequentActionType",
+                                    "TimeToWait"
+                                    ],
+                       "type": "object"
+                       })"_json;
+                       virtual nlohmann::json get_validator_schema() const { return validator_schema; }
+               };
+               void from_json(const nlohmann::json& j, SubsequentAction& ref);
+               void to_json(nlohmann::json& j, const SubsequentAction& ref);
+
+       }
+       
+}
+
+#endif
diff --git a/src/model/XAppConfig.cpp b/src/model/XAppConfig.cpp
new file mode 100644 (file)
index 0000000..a5402db
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"XAppConfig.h"
+namespace xapp {
+       namespace model {
+               void from_json(const nlohmann::json& j, XAppConfig& ref) {
+                       std::cout << __PRETTY_FUNCTION__ << std::endl;
+                       ref.validate_json(j);
+                       j.at("metadata").get_to(ref.m_ConfigMetadata);
+                       j.at("config").get_to(ref.config);
+
+               }
+               void from_json(const nlohmann::json& j, std::vector<XAppConfig>& ref) {
+                       for (auto& element : j) {
+                               XAppConfig tmp;
+                               tmp.validate_json(element);
+                               for (auto& val : element.items())
+                               {
+                                       if (val.key() == "metadata") {
+                                               tmp.m_ConfigMetadata.ConfigType = val.value()["configType"];
+                                               tmp.m_ConfigMetadata.XappName = val.value()["xappName"];
+                                       }
+                                       else if (val.key() == "config") {
+                                               tmp.config = val.value();
+                                       }
+                               }
+                               ref.push_back(tmp);
+                       }
+               }
+
+               void to_json(nlohmann::json& j, const XAppConfig& ref) {
+                       j = nlohmann::json{
+                               {"metadata",{{"configType",ref.m_ConfigMetadata.ConfigType},{"xappName",ref.m_ConfigMetadata.XappName}}},
+                               {"config",ref.config}
+                       };
+               }
+
+               void to_json(nlohmann::json& j, const std::vector<XAppConfig>& ref) {
+                       for (int i = 0; i < ref.size(); i++)
+                       {
+                               nlohmann::json tmp_j;
+                               to_json(tmp_j, ref[i]);
+                               j += tmp_j;
+                       }
+               }
+       }
+}
\ No newline at end of file
diff --git a/src/model/XAppConfig.h b/src/model/XAppConfig.h
new file mode 100644 (file)
index 0000000..5f8a8b0
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef XAPP_MODEL_XAppConfig_H
+#define XAPP_MODEL_XAppConfig_H
+#include"ConfigMetadata.h"
+
+namespace xapp {
+       namespace model {
+               struct  XAppConfig : public ModelBase {
+                       ConfigMetadata m_ConfigMetadata;
+                       nlohmann::json config;// = nlohmann::json::object();
+                       nlohmann::json validator_schema = R"(
+                               {
+                               "$schema": "http://json-schema.org/draft-07/schema#",
+                               "title": "XAppConfig",
+                               "properties": {
+                                   
+                                   "metadata": {
+                                       "type": "object"
+                                   },
+                                        "config": {
+                                       "type": "object"
+                                   }
+                               },
+                               "required": [
+                                            "metadata",
+                                                        "config"
+                                            ],
+                               "type": "object"
+                               })"_json;
+                       virtual nlohmann::json get_validator_schema() const { return validator_schema; }
+               };
+               void from_json(const nlohmann::json& j, XAppConfig& ref);
+               void from_json(const nlohmann::json& j, std::vector<XAppConfig>& ref);
+               void to_json(nlohmann::json& j, const XAppConfig& ref);
+               void to_json(nlohmann::json& j, const std::vector<XAppConfig>& ref);
+
+       }
+}
+#endif
diff --git a/src/model/temperory.h b/src/model/temperory.h
new file mode 100644 (file)
index 0000000..e5b1a92
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#pragma once
+#if !defined(__PRETTY_FUNCTION__) && !defined(__GNUC__)
+#define __PRETTY_FUNCTION__ __FUNCSIG__
+#endif
diff --git a/src/rest-client/CMakeLists.txt b/src/rest-client/CMakeLists.txt
new file mode 100644 (file)
index 0000000..595485a
--- /dev/null
@@ -0,0 +1,47 @@
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
+set(CMAKE_CXX_STANDARD 17)
+# BUILD TYPE
+message("A ${CMAKE_BUILD_TYPE} build configuration is detected")
+message("CPP flag is  ${CMAKE_CXX_FLAGS} ")
+message("CPP standard is  ${CMAKE_CXX_STANDARD} ")
+
+include_directories( "${srcd}/src/rest-client")
+#SOURCE FILES
+file(GLOB SOURCE_FILES  "${srcd}/src/rest-client/*.cpp" )
+
+
+add_library(rest-client_objects OBJECT  ${SOURCE_FILES})
+
+target_include_directories (rest-client_objects PUBLIC
+        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
+        $<INSTALL_INTERFACE:include>
+        PRIVATE src)
+
+# header files should go into .../include/xfcpp/
+
+file(GLOB SOURCE_INSTALL_FILES  "${srcd}/src/rest-client/*.h")
+#set( install_inc_client "include/ricxfcpp/rest-client" )
+
+if( DEV_PKG )
+        install( FILES
+                 ${SOURCE_INSTALL_FILES}
+                DESTINATION ${install_inc}
+        )
+endif()
+
+
diff --git a/src/rest-client/RestClient.cpp b/src/rest-client/RestClient.cpp
new file mode 100644 (file)
index 0000000..12c8728
--- /dev/null
@@ -0,0 +1,422 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"RestClient.h"
+namespace xapp
+{
+       void cpprestclient::SetbaseUrl(std::string url)
+       {
+               this->baseUrl = utility::conversions::to_string_t(url);
+               this->Baseurl = url;
+       }
+       cpprestclient::cpprestclient(std::string base_url) {
+               this->baseUrl = utility::conversions::to_string_t(base_url);
+               this->Baseurl = base_url;
+       }
+       cpprestclient::cpprestclient(std::string base_url, std::function<void(web::http::http_request)>callback):listener{ utility::conversions::to_string_t(resp_url) }
+       {
+               this->baseUrl= utility::conversions::to_string_t(base_url);
+               this->Baseurl = base_url;
+               try
+               {
+                       listener.support(web::http::methods::POST, [callback](web::http::http_request request) { callback(request); });
+                       ok_2_run = true;
+                        /*
+                        ok_2_run = true;
+                        t = new std::thread*[1];
+                        t[0] = new std::thread(&cpprestclient::response_listener, this);
+                        t[0]->detach();
+                        */
+                        response_listener();
+
+                       
+               }
+               catch (std::exception const & e)
+               {
+                       std::wcout << e.what() << std::endl;
+               }
+
+       }
+       cpprestclient::cpprestclient(std::string base_url,std::string response_url, std::function<void(web::http::http_request)>callback):listener{ utility::conversions::to_string_t(response_url) }{
+               
+               this->baseUrl= utility::conversions::to_string_t(base_url);
+                this->Baseurl = base_url;
+                try
+                {
+                        listener.support(web::http::methods::POST, [callback](web::http::http_request request) { callback(request); });
+                        /*
+                        ok_2_run = true;
+                        t = new std::thread*[1];
+                        t[0] = new std::thread(&cpprestclient::response_listener, this);
+                        t[0]->detach();
+                        */
+                        response_listener();
+
+
+
+                }
+                catch (std::exception const & e)
+                {
+                        std::wcout << e.what() << std::endl;
+                }
+
+
+
+       }
+
+       /*
+       void cpprestclient::start_response_listener() {
+               try {
+                       t[0] = new std::thread(&cpprestclient::response_listener, this);
+                       t[0]->detach();
+               }
+               catch (std::exception const & e)
+               {
+                       std::wcout << e.what() << std::endl;
+               }
+       }
+       */
+       std::string cpprestclient::getBaseUrl()
+       {
+               return Baseurl;
+       }
+       void cpprestclient::response_listener() {
+               try
+               {
+                       this->listener.open().wait();
+                       //std::cout<<"kumar "<<"\n";
+                       //std::this_thread::sleep_for(std::chrono::seconds(20));
+                       /*
+                       while (ok_2_run) {
+                               //std::cout<<"sandeeep ";
+
+                       }
+                        */
+
+               }
+               catch (std::exception const & e)
+               {
+                       std::wcout << e.what() << std::endl;
+               }
+       }
+       void cpprestclient::stop_response_listener() {
+               try
+               {
+                       ok_2_run = false;
+                       listener.close();
+                       //delete[] t;
+                       std::cout << "\nclosed1\n";
+               }
+               catch (std::exception const & e)
+               {
+                       std::wcout << e.what() << std::endl;
+               }
+       }
+       oresponse_t cpprestclient::post_subscriptions(const nlohmann::json & json, std::string path) {
+               oresponse_t res;
+               res.status_code = 0;
+               res.SubscriptionId = "";
+               auto postJson = pplx::create_task([&]() {
+                       utility::stringstream_t s;
+                       s << json.dump().c_str();
+                       web::json::value sdk_json = web::json::value::parse(s);
+                       web::uri_builder uri(this->baseUrl + utility::conversions::to_string_t(path));
+                       auto addr = uri.to_uri().to_string();
+                       web::http::client::http_client client(addr);
+                       return client.request(web::http::methods::POST, U("/"), sdk_json.serialize(), U("application/json"));
+               })
+                       .then([&](web::http::http_response response) {
+
+                       res.status_code = response.status_code();
+                       if (response.status_code() != 201) {
+                               throw std::runtime_error("Returned " + std::to_string(response.status_code()));
+                       }
+                       ucout << response.to_string() << "\n";
+                       response.headers().set_content_type(U("application/json"));
+                       return response.extract_json();
+               })
+
+                       .then([&](web::json::value jsonObject) {
+                       res.SubscriptionId = utility::conversions::to_utf8string(jsonObject[U("SubscriptionId")].as_string());
+
+                       //validating subscription response against its schema
+                       std::string s = utility::conversions::to_utf8string(jsonObject.serialize());
+                       nlohmann::json  j= nlohmann::json::parse(s);
+                       xapp::model::SubscriptionResponse SResp;
+                       xapp::model::from_json(j, SResp);
+                       
+                       //sanity check
+                       nlohmann::json ans;
+                       xapp::model::to_json(ans, SResp);
+                       std::cout << ans.dump(4) << "\n";
+
+               });
+               try {
+                       postJson.wait();
+               }
+               catch (const std::exception& e) {
+                       
+                       printf("Error exception:%s\n", e.what());
+               }
+               return res;
+
+       }
+       int  cpprestclient::delete_subscriptions(std::string Id, std::string path)
+       {
+               int status_code=0;
+               auto delJson = pplx::create_task([&]() {
+                       web::uri_builder uri(this->baseUrl + utility::conversions::to_string_t(path));
+                       auto addr = uri.to_uri().to_string();
+                       web::http::client::http_client client(addr);
+                       addr.append(utility::conversions::to_string_t(Id));
+                       //ucout << utility::string_t(U("making requests at: ")) << addr << std::endl;
+                       return client.request(web::http::methods::DEL);
+               })
+
+
+                       .then([&](web::http::http_response response) {
+                       status_code = response.status_code();
+                       if (response.status_code() != 204) {
+                               throw std::runtime_error("Returned " + std::to_string(response.status_code()));
+                       }
+               });
+
+               try {
+                       delJson.wait();
+               }
+               catch (const std::exception& e) {
+                       printf("Error exception:%s\n", e.what());
+               }
+
+               return status_code;
+       }
+       response_t  cpprestclient::get_config(std::string path)
+       {
+               response_t res;
+               res.status_code = 0;
+               res.body = utility::conversions::to_string_t("");
+               auto postJson = pplx::create_task([&]() {
+
+
+                       web::http::client::http_client client(this->baseUrl);
+
+
+                       return client.request(web::http::methods::GET, web::uri_builder(U("/")).append_path(utility::conversions::to_string_t(path)).to_string());
+               })
+                       .then([&](web::http::http_response response) {
+
+                       res.status_code = response.status_code();
+                       if (response.status_code() != 200) {
+                               throw std::runtime_error("Returned " + std::to_string(response.status_code()));
+                       }
+                       ucout << response.to_string() << "\n";
+                       response.headers().set_content_type(U("application/json"));
+                       return response.extract_json();
+               })
+
+                       .then([&](web::json::value jsonObject) {
+                       //validating configlist against its schema
+                       std::string s = utility::conversions::to_utf8string(jsonObject.serialize());
+                       res.body = nlohmann::json::parse(s);
+                       std::vector<xapp::model::XAppConfig> cfg;
+                       xapp::model::from_json(res.body, cfg);
+                       
+                       //sanity check
+                       nlohmann::json ans;
+                       xapp::model::to_json(ans, cfg);
+                       std::cout << ans.dump(4) << "\n";
+               });
+               try {
+                       postJson.wait();
+               }
+               catch (const std::exception& e) {
+                       printf("Error exception:%s\n", e.what());
+               }
+               return res;
+       }
+       response_t  cpprestclient::get_subscriptions(std::string path)
+       {
+               response_t res;
+               res.status_code = 0;
+               res.body = utility::conversions::to_string_t("");
+               auto postJson = pplx::create_task([&]() {
+
+
+                       web::http::client::http_client client(this->baseUrl);
+
+
+                       return client.request(web::http::methods::GET, web::uri_builder(U("/")).append_path(utility::conversions::to_string_t(path)).to_string());
+               })
+                       .then([&](web::http::http_response response) {
+
+                       res.status_code = response.status_code();
+                       if (response.status_code() != 200) {
+                               throw std::runtime_error("Returned " + std::to_string(response.status_code()));
+                       }
+                       ucout << response.to_string() << "\n";
+                       response.headers().set_content_type(U("application/json"));
+                       return response.extract_json();
+               })
+
+                       .then([&](web::json::value jsonObject) {
+
+                       //validating subscription list  against its schema
+                       std::string s = utility::conversions::to_utf8string(jsonObject.serialize());
+                       res.body = nlohmann::json::parse(s);
+                       std::vector<xapp::model::SubscriptionData> subList;
+                       xapp::model::from_json(res.body, subList);
+
+                       //sanity check
+                       nlohmann::json ans;
+                       xapp::model::to_json(ans, subList);
+                       std::cout << ans.dump(4) << "\n";
+
+               });
+               try {
+                       postJson.wait();
+               }
+               catch (const std::exception& e) {
+                       printf("Error exception:%s\n", e.what());
+               }
+               return res;
+       }
+       response_t cpprestclient::do_post(const nlohmann::json & json, std::string path)
+       {
+               response_t res;
+               res.status_code = 0;
+               res.body = utility::conversions::to_string_t("");
+               auto postJson = pplx::create_task([&]() {
+                       //conversion from nlhomann json to cpprestsdk json
+                       utility::stringstream_t s;
+                       s << json.dump().c_str();
+                       web::json::value sdk_json = web::json::value::parse(s);
+                       web::uri_builder uri(this->baseUrl + utility::conversions::to_string_t(path));
+                       auto addr = uri.to_uri().to_string();
+                       web::http::client::http_client client(addr);
+                       return client.request(web::http::methods::POST, U("/"), sdk_json.serialize(), U("application/json"));
+               })
+                               .then([&](web::http::http_response response) {
+
+                                       res.status_code = response.status_code();
+                                       if (response.status_code() != 201) {
+                                       throw std::runtime_error("Returned " + std::to_string(response.status_code()));
+                                       }
+                                       ucout << response.to_string() << "\n";
+                                       response.headers().set_content_type(U("application/json"));
+                                       return response.extract_json();
+                       })
+                               
+                               .then([&](web::json::value jsonObject) {
+                                       //std::cout << "\nRecieved REST subscription response\n";
+                                       //std::wcout << jsonObject.serialize().c_str() << "\n";
+                                       //resp.body = jsonObject.serialize();
+
+                               //conversion from cpprestsdk json to nlhomann json
+                               std::string s = utility::conversions::to_utf8string(jsonObject.serialize());
+                               res.body = nlohmann::json::parse(s);
+                       });
+                       try {
+                               postJson.wait();
+                       }
+                       catch (const std::exception& e) {
+                               printf("Error exception:%s\n", e.what());
+                       }
+                       return res;
+       }
+       response_t cpprestclient::do_del(std::string Id, std::string path)
+       {
+               response_t res;
+               res.status_code = 0;
+               res.body = utility::conversions::to_string_t("");
+               auto delJson = pplx::create_task([&]() {
+                       web::uri_builder uri(this->baseUrl + utility::conversions::to_string_t(path));
+                       auto addr = uri.to_uri().to_string();
+                       web::http::client::http_client client(addr);
+                       addr.append(utility::conversions::to_string_t(Id));
+                       //ucout << utility::string_t(U("making requests at: ")) << addr << std::endl;
+                       return client.request(web::http::methods::DEL);
+               })
+
+                       
+                       .then([&](web::http::http_response response) {
+                               res.status_code = response.status_code();
+                               if (response.status_code() != 204) {
+                                       throw std::runtime_error("Returned " + std::to_string(response.status_code()));
+                               }
+                               ucout << response.to_string() << "\n";
+                               response.headers().set_content_type(U("application/json"));
+                               return response.extract_json();
+                               //std::wcout << "Deleted: " << std::boolalpha << (response.status_code() == 204) << std::endl;
+               })
+                       .then([&](web::json::value jsonObject) {
+
+                               //resp.body = jsonObject.serialize();
+                       std::string s = utility::conversions::to_utf8string(jsonObject.serialize());
+                       res.body = nlohmann::json::parse(s);
+               });
+
+               try {
+                       delJson.wait();
+               }
+               catch (const std::exception& e) {
+                       printf("Error exception:%s\n", e.what());
+               }
+
+               return res;
+
+       }
+        response_t cpprestclient::do_get(std::string path)
+       {
+               response_t res;
+               res.status_code = 0;
+               res.body = utility::conversions::to_string_t("");
+               auto postJson = pplx::create_task([&]() {
+
+
+                       web::http::client::http_client client(this->baseUrl);
+
+                       
+                       return client.request(web::http::methods::GET, web::uri_builder(U("/")).append_path(utility::conversions::to_string_t(path)).to_string());
+               })
+                       .then([&](web::http::http_response response) {
+
+                       res.status_code = response.status_code();
+                       if (response.status_code() != 200) {
+                               throw std::runtime_error("Returned " + std::to_string(response.status_code()));
+                       }
+                       ucout << response.to_string() << "\n";
+                       response.headers().set_content_type(U("application/json"));
+                       return response.extract_json();
+               })
+
+                       .then([&](web::json::value jsonObject) {
+       
+                       //resp.body = jsonObject.serialize();
+                       std::string s = utility::conversions::to_utf8string(jsonObject.serialize());
+                       res.body = nlohmann::json::parse(s);
+               });
+               try {
+                       postJson.wait();
+               }
+               catch (const std::exception& e) {
+                       printf("Error exception:%s\n", e.what());
+               }
+               return res;
+       }
+}
+
+
diff --git a/src/rest-client/RestClient.h b/src/rest-client/RestClient.h
new file mode 100644 (file)
index 0000000..8368547
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef _CPPREST_SDK_WRAPPER_H
+#define _CPPREST_SDK_WRAPPER_H
+
+#include<string>
+#include<cpprest/http_client.h>
+#include<cpprest/filestream.h>
+#include<cpprest/uri.h>
+#include<cpprest/json.h>
+#include<sstream>
+#include <cpprest/http_listener.h>
+#include"nlohmann/json.hpp"
+#include<functional>
+#include"RestModel.h"
+#include<thread>
+#include <chrono>
+#include <pthread.h>
+
+
+namespace xapp
+{
+       typedef struct resp
+       {
+               long status_code;
+               nlohmann::json body;
+               //utility::string_t body;
+       }response_t;
+
+       typedef struct oran_resp
+       {
+               long status_code;
+               std::string SubscriptionId;
+       }oresponse_t;
+
+       class cpprestclient
+       {
+       protected:
+               utility::string_t baseUrl;
+               std::string Baseurl;
+               //utility::string_t resp_url=U("http://0.0.0.0:8080/ric/v1/subscriptions/response");
+               std::string resp_url = "http://0.0.0.0:8080/ric/v1/subscriptions/response";//default response url
+               web::http::experimental::listener::http_listener listener;
+               std::thread** t;
+               void response_listener();
+               bool ok_2_run;
+       public:
+               void SetbaseUrl(std::string);
+               std::string getBaseUrl();
+               //O-RAN specific api calls
+               oresponse_t post_subscriptions(const nlohmann::json & json, std::string path);
+               int delete_subscriptions(std::string Id, std::string path);
+               response_t get_subscriptions(std::string path);
+               response_t get_config(std::string path);
+
+               //general api calls
+               virtual response_t do_get(std::string path);
+               virtual response_t do_post(const nlohmann::json & json, std::string path);
+               virtual response_t do_del(std::string Id, std::string path);
+               //virtual response_t do_post(const web::json::value & json, std::string path);
+               cpprestclient(std::string base_url, std::function<void(web::http::http_request)>callback);
+               cpprestclient(std::string base_url,std::string response_url, std::function<void(web::http::http_request)>callback);
+               cpprestclient(std::string base_url);
+               virtual ~cpprestclient(){}
+               //void start_response_listener();
+               void stop_response_listener();
+       };
+
+}
+
+
+
+
+
+#endif
diff --git a/src/rest-server/CMakeLists.txt b/src/rest-server/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5629496
--- /dev/null
@@ -0,0 +1,48 @@
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
+set(CMAKE_CXX_STANDARD 17)
+# BUILD TYPE
+message("A ${CMAKE_BUILD_TYPE} build configuration is detected")
+message("CPP flag is  ${CMAKE_CXX_FLAGS} ")
+message("CPP standard is  ${CMAKE_CXX_STANDARD} ")
+
+#include_directories( "${srcd}/src/rest-server")
+#SOURCE FILES
+file(GLOB SOURCE_FILES  "${srcd}/src/rest-server/*.cpp" )
+
+
+add_library(rest-server_objects OBJECT  ${SOURCE_FILES})
+
+target_include_directories (rest-server_objects PUBLIC
+        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
+        $<INSTALL_INTERFACE:include>
+        PRIVATE src)
+
+# header files should go into .../include/xfcpp/
+
+file(GLOB SOURCE_INSTALL_FILES  "${srcd}/src/rest-server/*.h")
+#set( install_inc_server "include/ricxfcpp/rest-server" )
+
+if( DEV_PKG )
+        install( FILES
+                 ${SOURCE_INSTALL_FILES}
+                DESTINATION ${install_inc}
+        )
+endif()
+
+
+
diff --git a/src/rest-server/pistacheserver.cpp b/src/rest-server/pistacheserver.cpp
new file mode 100644 (file)
index 0000000..7f7fed9
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#include"pistacheserver.h"
+namespace xapp
+{
+       pistacheserver::pistacheserver(Pistache::Address addr,std::vector<std::string> method,std::vector<bool> static_routing,std::vector<bool> dynamic_routing)
+        : httpEndpoint(std::make_shared<Pistache::Http::Endpoint>(addr))
+    { 
+       this->t=new std::thread*[1];
+        this->method=method;
+       this->static_routing=static_routing;
+       this->dynamic_routing=dynamic_routing;
+       assert(static_routing.size()==method.size() && dynamic_routing.size()==method.size());
+       stat_sz=cal_stat_size();
+       dyn_sz=cal_dyn_size();
+    }
+   int pistacheserver::cal_stat_size()//caclualting no of true in static_routing
+       {
+               int size=0;
+               for(int i=0;i<static_routing.size();i++)
+               {
+                       if (static_routing[i])
+                               size++;
+               }
+               return size;
+       }
+
+        int pistacheserver::cal_dyn_size() //calaculating no true in dynamic_routing
+        {
+                int size=0;
+                for(int i=0;i<dynamic_routing.size();i++)
+                {
+                        if (dynamic_routing[i])
+                                size++;
+                }
+                return size;
+        }
+
+    void pistacheserver::setup_base_url(std::string base)
+    {
+        this->base=base;
+    }
+    void pistacheserver::setup_static_route(std::unordered_map<int,std::string> route)//routing path
+    {
+        this->route_static=route;
+    }
+ void pistacheserver::setup_dynamic_route(std::unordered_map<int,std::string> route)//routing path
+    {
+        this->route_dynamic=route;
+    }
+void pistacheserver::add_static_cb(std::unordered_map<int,usr_callback> cb)
+{
+       this->cb_static=cb;
+}
+void pistacheserver::add_dynamic_cb(std::unordered_map<int,usr_callback> cb) 
+{
+        this->cb_dynamic=cb;
+}
+
+    void pistacheserver::init(size_t thr = 2) 
+    {
+                        auto opts = Pistache::Http::Endpoint::options().threads(thr).flags(Pistache::Tcp::Options::ReuseAddr)/*.flags(Pistache::Tcp::Options::ReusePort)*/; // how many threads for the server
+                        httpEndpoint->init(opts);
+               assert(route_static.size()==stat_sz && route_dynamic.size()==dyn_sz); //no of true in satatic_routing and dynamic_routig should match with size of route_static and  route_dynamic respectively. 
+
+               assert(cb_static.size()==stat_sz && cb_dynamic.size()==dyn_sz); //no of true in satatic_routing and dynamic_routig should match with size of cb_static and cb_dynamic respectively.
+               for (int i=0;i<method.size();i++)
+       {
+               if (method[i]=="get")
+               {
+                       setupRoutes_get(i+1);
+               }
+               else if (method[i]=="post" )
+               {
+                       setupRoutes_post(i+1);
+               }
+
+               else if (method[i]=="del")
+               {
+                       setupRoutes_del(i+1);
+               }
+       
+                       else
+               {
+                       std::cout<<"Wrong Method called \n";
+               }
+       }
+
+
+    }
+
+
+    void pistacheserver::start()
+    {
+       httpEndpoint->setHandler(router.handler());
+        t[0]=new std::thread(&pistacheserver::thread_start,this);
+       t[0]->detach();
+    }
+    void pistacheserver::thread_start()
+    {
+       this->httpEndpoint->serve();
+
+    }
+
+    void pistacheserver::shutdown()
+    {
+        httpEndpoint->shutdown();
+    }
+
+    void pistacheserver::setupRoutes_get(int index)
+    {
+        using namespace Pistache::Rest;
+       auto search_s=route_static.find(index);
+        auto search_d=route_dynamic.find(index);
+        auto cbs_search=cb_static.find(index);
+        auto cbd_search=cb_dynamic.find(index);
+        assert (search_s!=route_static.end() || search_d!=route_dynamic.end()); 
+        if (static_routing[index-1])
+                {
+               std::cout<<"static routing get"<<std::endl;
+                assert (search_s!=route_static.end() && cbs_search!=cb_static.end());
+                Routes::Get(router, base + search_s->second, Routes::bind(cbs_search->second));
+                }
+        if (dynamic_routing[index-1])
+                {
+               std::cout<<"dynamic routing get"<<std::endl;
+                assert (search_d!=route_dynamic.end() && cbd_search!=cb_dynamic.end());
+                Routes::Get(router, base + search_d->second+ dynamic_id, Routes::bind(cbd_search->second));
+                }
+
+       // Default handler, called when a route is not found
+        router.addCustomHandler(Routes::bind(&pistacheserver::default_handler, this));
+    }
+    void pistacheserver::setupRoutes_post(int index)
+    {
+        using namespace Pistache::Rest;
+       auto search_s=route_static.find(index);
+       auto search_d=route_dynamic.find(index);
+       auto cbs_search=cb_static.find(index);
+       auto cbd_search=cb_dynamic.find(index);
+       assert (search_s!=route_static.end() || search_d!=route_dynamic.end()); 
+       if (static_routing[index-1])
+               {
+               std::cout<<"static routing post"<<std::endl;
+               assert (search_s!=route_static.end() && cbs_search!=cb_static.end());
+               Routes::Post(router, base + search_s->second, Routes::bind(cbs_search->second));
+               }
+       if (dynamic_routing[index-1])
+               {
+               std::cout<<"dynamic routing post"<<std::endl;
+               assert (search_d!=route_dynamic.end() && cbd_search!=cb_dynamic.end());
+               Routes::Post(router, base + search_d->second+ dynamic_id, Routes::bind(cbd_search->second));
+               }
+        // Default handler, called when a route is not found
+        router.addCustomHandler(Routes::bind(&pistacheserver::default_handler, this));
+    }
+    void pistacheserver::setupRoutes_del(int index)
+    {
+        using namespace Pistache::Rest;
+        auto search_s=route_static.find(index);
+        auto search_d=route_dynamic.find(index);
+        auto cbs_search=cb_static.find(index);
+        auto cbd_search=cb_dynamic.find(index);
+        assert (search_s!=route_static.end() || search_d!=route_dynamic.end()); 
+        if (static_routing[index-1])
+                {
+               std::cout<<"static routing delete"<<std::endl;
+                assert (search_s!=route_static.end() && cbs_search!=cb_static.end());
+                Routes::Delete(router, base + search_s->second, Routes::bind(cbs_search->second));
+                }
+        if (dynamic_routing[index-1])
+                {
+               std::cout<<"dynamic routing delete"<<std::endl;
+                assert (search_d!=route_dynamic.end() && cbd_search!=cb_dynamic.end());
+                Routes::Delete(router, base + search_d->second+ dynamic_id, Routes::bind(cbd_search->second));
+               }
+       // Default handler, called when a route is not found
+        router.addCustomHandler(Routes::bind(&pistacheserver::default_handler, this));
+    }
+
+}
+
+
+
diff --git a/src/rest-server/pistacheserver.h b/src/rest-server/pistacheserver.h
new file mode 100644 (file)
index 0000000..75fb9b8
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+# ==================================================================================
+# Copyright (c) 2020 HCL Technologies Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+*/
+#ifndef _pistacheserver_h
+#define _pistacheserver_h
+#include <pistache/endpoint.h>
+#include <pistache/http.h>
+#include <pistache/router.h>
+#include <pistache/http_headers.h>
+#include<vector>
+#include<string>
+#include<memory>
+#include<thread>
+#include<vector>
+#include<unordered_set>
+#include<assert.h>
+#include<functional>
+#include<unordered_map>
+namespace xapp
+{
+    using usr_callback=void(*)(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
+    class pistacheserver
+    {
+        private:
+            std::shared_ptr<Pistache::Http::Endpoint> httpEndpoint;
+            Pistache::Rest::Router router;
+            void setupRoutes_get(int index);
+            void setupRoutes_post(int index);
+            void setupRoutes_del(int index);
+
+            std::vector<std::string> method;
+           std::vector< bool> static_routing;
+            std::vector<bool> dynamic_routing;
+            std::unordered_map<int,std::string> route_static;
+           std::unordered_map<int,std::string> route_dynamic;
+           std::unordered_map<int,usr_callback> cb_static;
+           std::unordered_map<int,usr_callback> cb_dynamic;
+
+           std::string base = "/ric/v1";
+            std::string dynamic_id="/:Id";
+           int stat_sz=0;
+           int dyn_sz=0;
+           int cal_stat_size();
+           int cal_dyn_size();
+           std::thread **t;
+        public:
+           void thread_start();
+            pistacheserver(Pistache::Address addr,std::vector<std::string> method,std::vector<bool> static_routing,std::vector<bool> dynamic_routing);
+           virtual ~pistacheserver(){};
+           virtual void default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response)
+                {
+                       response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
+                }
+
+            void init(size_t thr);
+            void setup_base_url(std::string base);
+            void setup_static_route(std::unordered_map<int,std::string> route);//routing path
+           void setup_dynamic_route(std::unordered_map<int,std::string> route);
+           void add_static_cb(std::unordered_map<int,usr_callback> cb);
+           void add_dynamic_cb(std::unordered_map<int,usr_callback> cb);
+            void start();
+            void shutdown();
+    };
+}
+#endif
+
diff --git a/src/rest/CMakeLists.txt b/src/rest/CMakeLists.txt
deleted file mode 100644 (file)
index 282e9b9..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-# vim: sw=4 ts=4 noet:
-#
-#==================================================================================
-#   Copyright (c) 2020 Nokia
-#   Copyright (c) 2020 AT&T Intellectual Property.
-#
-#   Licensed under the Apache License, Version 2.0 (the "License");
-#   you may not use this file except in compliance with the License.
-#   You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-#   Unless required by applicable law or agreed to in writing, software
-#   distributed under the License is distributed on an "AS IS" BASIS,
-#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#   See the License for the specific language governing permissions and
-#   limitations under the License.
-#==================================================================================
-#
-
-
-# For clarity: this generates object, not a lib as the CM command implies.
-#
-add_subdirectory(./model)
-#add_subdirectory(./clientapi)
-#add_subdirectory(./serverapi)
-
diff --git a/src/rest/model/ActionToBeSetup.h b/src/rest/model/ActionToBeSetup.h
deleted file mode 100644 (file)
index 6bb8d55..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#ifndef XAPP_MODEL_ActionToBeSetup_H
-#define XAPP_MODEL_ActionToBeSetup_H
-#include "ModelBase.h"
-#include "SubsequentAction.h"
-
-namespace xapp {
-namespace model {
-
-using namespace xapp::model;
-using ActionDefinition = std::vector<int>;
-
-struct ActionToBeSetup: ModelBase {
-    ActionDefinition m_ActionDefinition;
-    int ActionID;
-    std::string ActionType;
-    SubsequentAction m_SubsequentAction;
-
-    json validator_schema = R"(
-    {
-    "$schema": "http://json-schema.org/draft-07/schema#",
-    "title": "SubsequentAction",
-    "properties": {
-        "ActionDefinition": {
-            "description": "Action Definition",
-            "type": "array",
-            "items": {
-                "type": "integer"
-            }
-        },
-        "ActionID": {
-            "description": "Identification of Action",
-            "type": "integer",
-            "minimum": 0,
-            "maximum": 255
-        },
-        "ActionType": {
-            "description": "Type of Action",
-            "type": "string",
-            "enum": ["policy", "insert", "report"]
-        },
-        "SubsequentAction": {
-            "description": "Subsequent Action",
-            "type": "object"
-        }
-    },
-    "required": [
-                 "ActionDefinition",
-                 "ActionID",
-                 "ActionType",
-                 "SubsequentAction"
-                ],
-    "type": "object"
-    })"_json;
-
-    virtual json get_validator_schema() const { return validator_schema; }
-};
-
-void from_json(const json& j, ActionToBeSetup& ref) {
-
-    std::cout << __PRETTY_FUNCTION__ << std::endl;
-    ref.validate_json(j);
-    j.at("ActionDefinition").get_to(ref.m_ActionDefinition);
-    j.at("ActionID").get_to(ref.ActionID);
-    j.at("ActionType").get_to(ref.ActionType);
-    j.at("SubsequentAction").get_to(ref.m_SubsequentAction);
-
-}
-
-void to_json(json& j, const ActionToBeSetup& ref) {
-
-    j = json {
-        {"ActionDefinition", ref.m_ActionDefinition},
-        {"ActionID", ref.ActionID},
-        {"ActionType", ref.ActionType},
-        {"SubsequentAction", ref.m_SubsequentAction}
-    };
-}
-
-using ActionsToBeSetup = std::vector<ActionToBeSetup>;
-
-} /*namespace model*/
-} /*namespace xapp*/
-
-#endif /* XAPP_MODEL_ActionToBeSetup_H */
-
diff --git a/src/rest/model/CMakeLists.txt b/src/rest/model/CMakeLists.txt
deleted file mode 100644 (file)
index 932a93c..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-# vim: sw=4 ts=4 noet:
-#
-#==================================================================================
-#   Copyright (c) 2020 Nokia
-#   Copyright (c) 2020 AT&T Intellectual Property.
-#
-#   Licensed under the Apache License, Version 2.0 (the "License");
-#   you may not use this file except in compliance with the License.
-#   You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-#   Unless required by applicable law or agreed to in writing, software
-#   distributed under the License is distributed on an "AS IS" BASIS,
-#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#   See the License for the specific language governing permissions and
-#   limitations under the License.
-#==================================================================================
-#
-
-
-# For clarity: this generates object, not a lib as the CM command implies.
-#
-if( DEV_PKG )
-       install(
-               DIRECTORY ./ DESTINATION ${install_inc}
-               FILES_MATCHING PATTERN "*.h"
-       )
-endif()
-
diff --git a/src/rest/model/ConfigMetadata.h b/src/rest/model/ConfigMetadata.h
deleted file mode 100644 (file)
index a60bfb5..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-#ifndef XAPP_MODEL_ConfigMetadata_H
-#define XAPP_MODEL_ConfigMetadata_H
-
-#include "ModelBase.h"
-
-namespace xapp {
-namespace model {
-
-struct ConfigMetadata: ModelBase {
-    std::string ConfigType;
-    std::string XappName;
-    json validator_schema = R"(
-    {
-    "$schema": "http://json-schema.org/draft-07/schema#",
-    "title": "ConfigMetadata",
-    "properties": {
-        "ConfigType": {
-            "description": "Type of Config",
-            "type": "string",
-            "enum": ["json", "xml", "other"]
-        },
-        "XappName": {
-            "description": "Name of xApp",
-            "type": "string"
-        }
-    },
-    "required": [
-                 "ConfigType",
-                 "XappName"
-                 ],
-    "type": "object"
-    })"_json;
-
-    virtual json get_validator_schema() const { return validator_schema; }
-};
-
-void from_json(const json& j, ConfigMetadata& ref) {
-
-    std::cout << __func__ << " ConfigMetadata " << std::endl;
-    ref.validate_json(j);
-    j.at("ConfigType").get_to(ref.ConfigType);
-    j.at("XappName").get_to(ref.XappName);
-}
-
-void to_json(json& j, const ConfigMetadata& ref) {
-    j = json {
-        {"ConfigType",ref.ConfigType},
-        {"XappName", ref.XappName}
-    };
-}
-
-} /*namespace model*/
-} /*namespace xapp*/
-#endif /*XAPP_MODEL_ConfigMetadata_H*/
diff --git a/src/rest/model/ModelBase.h b/src/rest/model/ModelBase.h
deleted file mode 100644 (file)
index 159b772..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-#ifndef XAPP_MODEL_ModelBase_H
-#define XAPP_MODEL_ModelBase_H
-#include <iostream>
-#include <string.h>
-#include <nlohmann/json.hpp>
-#include <nlohmann/json-schema.hpp>
-#include <type_traits>
-
-using nlohmann::json_schema::json_validator;
-using json = nlohmann::json;
-
-namespace xapp {
-namespace model {
-
-std::invalid_argument invalid_parameter("Invalid Json Input");
-
-template<typename ModelType>
-bool _validate(const ModelType model) {
-    json _json = model;
-    json_validator validator;
-    validator.set_root_schema(model.validator_schema);
-
-    try {
-        validator.validate(_json);
-    } catch (const std::exception& e) {
-        std::cerr << "Struct Validation failed, here is why: " << e.what() << "\n";
-        throw;
-    }
-    return true;
-}
-
-struct ModelBase {
-    json validator_schema = R"(
-    {
-        "$schema": "http://json-schema.org/draft-07/schema#",
-        "title": "ModelBase"
-    })"_json;
-
-    bool validate_() {
-        return _validate(std::move(*this));
-    }
-
-    void validate_json(const json& _json) {
-        json_validator validator;
-        validator.set_root_schema(get_validator_schema());
-        try {
-            validator.validate(_json);
-        } catch (const std::exception& e) {
-            throw;
-        }
-        return;
-    }
-
-    virtual json get_validator_schema() const { return validator_schema; }
-};
-
-void from_json(const json& j, ModelBase& ref) {
-    return;
-}
-void to_json(json& j, const ModelBase& ref) {
-    return;
-}
-
-} /*model*/
-} /*xapp*/
-#endif /*XAPP_MODEL_ModelBase_H*/
diff --git a/src/rest/model/RestModel.h b/src/rest/model/RestModel.h
deleted file mode 100644 (file)
index 266e221..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef XAPP_MODEL_H
-#define XAPP_MODEL_H
-#include "ModelBase.h"
-#include "SubsequentAction.h"
-#include "ActionToBeSetup.h"
-#include "SubscriptionResponse.h"
-#include "ConfigMetadata.h"
-#include "SubscriptionDetail.h"
-#include "SubscriptionParams_ClientEndpoint.h"
-#include "SubscriptionParams_E2SubscriptionDirectives.h"
-#include "SubscriptionParams.h"
-#include "SubscriptionInstance.h"
-#include "SubscriptionData.h"
-
-#endif /*XAPP_MODEL_H*/
diff --git a/src/rest/model/SubscriptionData.h b/src/rest/model/SubscriptionData.h
deleted file mode 100644 (file)
index 008b72a..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-#ifndef XAPP_MODEL_SubscriptionData_H
-#define XAPP_MODEL_SubscriptionData_H
-#include "ModelBase.h"
-#include "SubscriptionInstance.h"
-namespace xapp {
-namespace model {
-
-struct SubscriptionData: ModelBase {
-    std::vector<std::string> ClientEndpoint;
-    std::string Meid;
-    int SubscriptionID;
-    SubscriptionInstances m_SubscriptionInstances;
-
-    json validator_schema = R"(
-    {
-    "$schema": "http://json-schema.org/draft-07/schema#",
-    "title": "SubscriptionData",
-    "properties": {
-        "SubscriptionId": {
-            "type": "integer"
-        },
-        "Meid": {
-            "type": "string"
-        },
-        "ClientEndpoint": {
-            "type": "array",
-            "items": {
-                "type": "string"
-            }
-        },
-        "SubscriptionInstances": {
-            "type": "array"
-        }
-    },
-    "required": [
-                 "SubscriptionId",
-                 "Meid",
-                 "ClientEndpoint",
-                 "SubscriptionInstances"
-                 ],
-    "type": "object"
-    })"_json;
-
-    virtual json get_validator_schema() const { return validator_schema; }
-};
-
-void from_json(const json& j, SubscriptionData& ref) {
-
-    std::cout << __PRETTY_FUNCTION__ << std::endl;
-    ref.validate_json(j);
-
-    j.at("SubscriptionId").get_to(ref.SubscriptionID);
-    j.at("SubscriptionInstances").get_to(ref.m_SubscriptionInstances);
-    j.at("Meid").get_to(ref.Meid);
-    j.at("ClientEndpoint").get_to(ref.ClientEndpoint);
-}
-
-void to_json(json& j, const SubscriptionData& ref) {
-
-    j = json {
-        {"SubscriptionId",ref.SubscriptionID},
-        {"Meid",ref.Meid},
-        {"ClientEndpoint", ref.ClientEndpoint},
-        {"SubscriptionInstances", ref.m_SubscriptionInstances}
-    };
-}
-
-using SubscriptionList = std::vector<SubscriptionData>;
-
-} /*namespace model*/
-} /*namespace xapp*/
-#endif /*XAPP_MODEL_SubscriptionData_H*/
diff --git a/src/rest/model/SubscriptionDetail.h b/src/rest/model/SubscriptionDetail.h
deleted file mode 100644 (file)
index 1651619..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-#ifndef XAPP_MODEL_SubscriptionDetail_H
-#define XAPP_MODEL_SubscriptionDetail_H
-#include "ModelBase.h"
-#include "ActionToBeSetup.h"
-
-namespace xapp {
-namespace model {
-
-using EventTriggerDefinition = std::vector<int>;
-
-struct SubscriptionDetail: ModelBase {
-    ActionsToBeSetup ActionToBeSetupList;
-    EventTriggerDefinition EventTriggers;
-    int XappEventInstanceID;
-    json validator_schema = R"(
-    {
-    "$schema": "http://json-schema.org/draft-07/schema#",
-    "title": "Subscription detail",
-    "properties": {
-        "XappEventInstanceId": {
-            "type": "integer",
-            "minimum": 0,
-            "maximum": 255
-        },
-        "EventTriggers": {
-            "description": "Identification of Action",
-            "type": "array",
-            "items": {
-                "type": "integer"
-            }
-        },
-        "ActionToBeSetupList": {
-            "type": "array"
-        }
-    },
-    "required": [
-                 "XappEventInstanceId",
-                 "EventTriggers",
-                 "ActionToBeSetupList"
-                ],
-    "type": "object"
-    })"_json;
-
-    virtual json get_validator_schema() const { return validator_schema; }
-
-};
-
-void from_json(const json& j, SubscriptionDetail& ref) {
-
-    std::cout << __PRETTY_FUNCTION__ << std::endl;
-    ref.validate_json(j);
-
-    j.at("XappEventInstanceId").get_to(ref.XappEventInstanceID);
-    j.at("EventTriggers").get_to(ref.EventTriggers);
-    j.at("ActionToBeSetupList").get_to(ref.ActionToBeSetupList);
-}
-
-void to_json(json& j, const SubscriptionDetail& ref) {
-
-    j = json {
-        {"XappEventInstanceId", ref.XappEventInstanceID},
-        {"EventTriggers", ref.EventTriggers},
-        {"ActionToBeSetupList", ref.ActionToBeSetupList},
-    };
-}
-
-using SubscriptionDetailsList = std::vector<SubscriptionDetail>;
-
-} /*namespace model*/
-} /*namespace xapp*/
-#endif /*XAPP_MODEL_SubscriptionDetail_H*/
diff --git a/src/rest/model/SubscriptionInstance.h b/src/rest/model/SubscriptionInstance.h
deleted file mode 100644 (file)
index f427e79..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-#ifndef XAPP_MODEL_SubscriptionInstance_H
-#define XAPP_MODEL_SubscriptionInstance_H
-#include "ModelBase.h"
-
-namespace xapp {
-namespace model {
-
-struct SubscriptionInstance: ModelBase {
-    int E2EventInstanceID;
-    std::string ErrorCause;
-    std::string ErrorSource;
-    std::string TimeoutType;
-    int XappEventInstanceID;
-
-    json validator_schema = R"(
-    {
-    "$schema": "http://json-schema.org/draft-07/schema#",
-    "title": "SubscriptionInstance",
-    "description": "xApp service address and port",
-    "properties": {
-        "XappEventInstanceId": {
-            "type": "integer",
-            "minimum": 0,
-            "maximum": 65535
-        },
-        "E2EventInstanceId": {
-            "type": "integer",
-            "minimum": 0,
-            "maximum": 65535
-        },
-        "ErrorCause": {
-            "description": "Descriptive error cause. Empty string when no error.",
-            "type": "string"
-        },
-        "ErrorSource": {
-            "description": "Source of error cause.",
-            "type": "string",
-            "enum": ["SUBMGR", "RTMGR", "DBAAS", "ASN1", "E2Node"]
-        },
-        "TimeoutType": {
-            "description": "Type timeout. xApp should retry if timeout occurs.",
-            "type": "string",
-            "enum": ["E2-Timeout", "RTMGR-Timeout", "DBAAS-Timeout"]
-        }
-    },
-    "required": [
-                 "XappEventInstanceId",
-                 "E2EventInstanceId"
-                 ],
-    "type": "object"
-    })"_json;
-
-    virtual json get_validator_schema() const { return validator_schema; }
-};
-
-void from_json(const json& j, SubscriptionInstance& ref) {
-
-    std::cout << __PRETTY_FUNCTION__ << std::endl;
-    ref.validate_json(j);
-
-    j.at("XappEventInstanceId").get_to(ref.XappEventInstanceID);
-    j.at("E2EventInstanceId").get_to(ref.E2EventInstanceID);
-    j.at("ErrorCause").get_to(ref.ErrorCause);
-    j.at("ErrorSource").get_to(ref.ErrorSource);
-    j.at("TimeoutType").get_to(ref.TimeoutType);
-}
-
-void to_json(json& j, const SubscriptionInstance& ref) {
-
-    j = json {
-        {"XappEventInstanceId", ref.XappEventInstanceID},
-        {"E2EventInstanceId", ref.E2EventInstanceID},
-        {"ErrorCause", ref.ErrorCause},
-        {"ErrorSource", ref.ErrorSource},
-        {"TimeoutType", ref.TimeoutType}
-    };
-}
-
-using SubscriptionInstances = std::vector<SubscriptionInstance>;
-
-} /*namespace model*/
-} /*namespace xapp*/
-#endif /*XAPP_MODEL_SubscriptionInstance_H*/
diff --git a/src/rest/model/SubscriptionParams.h b/src/rest/model/SubscriptionParams.h
deleted file mode 100644 (file)
index cc19750..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-#ifndef XAPP_MODEL_SubscriptionParams_H
-#define XAPP_MODEL_SubscriptionParams_H
-#include "ModelBase.h"
-#include "SubscriptionDetail.h"
-#include "SubscriptionParams_ClientEndpoint.h"
-#include "SubscriptionParams_E2SubscriptionDirectives.h"
-
-namespace xapp {
-namespace model {
-
-struct SubscriptionParams: public ModelBase {
-
-    SubscriptionParams_ClientEndpoint ClientEndpoint;
-    SubscriptionParams_E2SubscriptionDirectives E2SubscriptionDirectives;
-    std::string Meid;
-    int RANFunctionID;
-    std::string SubscriptionID;
-    SubscriptionDetailsList m_SubscriptionDetailsList;
-
-    json validator_schema = R"(
-    {
-    "$schema": "http://json-schema.org/draft-07/schema#",
-    "title": "SubscriptionParams",
-    "properties": {
-        "SubscriptionId": {
-            "description": "Optional subscription ID '(Submgr allocates if not given)'",
-            "type": "string"
-        },
-        "Meid": {
-            "type": "string"
-        },
-        "RANFunctionId": {
-            "type": "integer",
-            "minimum": 0,
-            "maximum": 4095
-        }
-    },
-    "required": [
-                 "ClientEndpoint",
-                 "Meid",
-                 "RANFunctionId",
-                 "SubscriptionDetails"
-                ],
-    "type": "object"
-    })"_json;
-
-    virtual json get_validator_schema() const { return validator_schema; }
-
-};
-
-void from_json(const json& j, SubscriptionParams& ref) {
-
-    std::cout << __PRETTY_FUNCTION__ << std::endl;
-    ref.validate_json(j);
-    j.at("ClientEndpoint").get_to(ref.ClientEndpoint);
-
-    if (j.contains("E2SubscriptionDirectives"))
-    {
-        j.at("E2SubscriptionDirectives").get_to(ref.E2SubscriptionDirectives);
-    }
-
-    if (j.contains("SubscriptionId"))
-    {
-        j.at("SubscriptionId").get_to(ref.SubscriptionID);
-    }
-
-    j.at("Meid").get_to(ref.Meid);
-    j.at("RANFunctionId").get_to(ref.RANFunctionID);
-    j.at("SubscriptionDetails").get_to(ref.m_SubscriptionDetailsList);
-}
-
-void to_json(json& j, const SubscriptionParams& ref) {
-
-    j = json {
-        {"ClientEndpoint", ref.ClientEndpoint},
-        {"E2SubscriptionDirectives", ref.E2SubscriptionDirectives},
-        {"Meid", ref.Meid},
-        {"RANFunctionId", ref.RANFunctionID},
-        {"SubscriptionId", ref.SubscriptionID},
-        {"SubscriptionDetails", ref.m_SubscriptionDetailsList},
-    };
-}
-
-} /*namespace model*/
-} /*namespace xapp*/
-#endif /*XAPP_MODEL_SubscriptionParams_H*/
diff --git a/src/rest/model/SubscriptionParams_ClientEndpoint.h b/src/rest/model/SubscriptionParams_ClientEndpoint.h
deleted file mode 100644 (file)
index 3d43997..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-#ifndef XAPP_MODEL_SubscriptionParams_ClientEndpoint_H
-#define XAPP_MODEL_SubscriptionParams_ClientEndpoint_H
-#include "ModelBase.h"
-
-namespace xapp {
-namespace model {
-
-struct SubscriptionParams_ClientEndpoint: ModelBase {
-    int HTTPPort;
-    std::string Host;
-    int RMRPort;
-    json validator_schema = R"(
-    {
-    "$schema": "http://json-schema.org/draft-07/schema#",
-    "title": "SubscriptionParams_ClientEndpoint",
-    "description": "xApp service address and port",
-    "properties": {
-        "HTTPPort": {
-            "description": "xApp HTTP service address port",
-            "type": "integer",
-            "minimum": 0,
-            "maximum": 65535
-        },
-        "Host": {
-            "description": "xApp service address name like service-ricxapp-xappname-http.ricxapp",
-            "type": "string"
-        },
-        "RMRPort": {
-            "description": "xApp RMR service address port",
-            "type": "integer",
-            "minimum": 0,
-            "maximum": 65535
-        }
-    },
-    "required": [
-                 "HTTPPort",
-                 "Host",
-                 "RMRPort"
-                 ],
-    "type": "object"
-    })"_json;
-
-    virtual json get_validator_schema() const { return validator_schema; }
-};
-
-void from_json(const json& j, SubscriptionParams_ClientEndpoint& ref) {
-
-    std::cout << __PRETTY_FUNCTION__ << std::endl;
-    ref.validate_json(j);
-    j.at("HTTPPort").get_to(ref.HTTPPort);
-    j.at("Host").get_to(ref.Host);
-    j.at("RMRPort").get_to(ref.RMRPort);
-}
-
-void to_json(json& j, const SubscriptionParams_ClientEndpoint& ref) {
-    j = json {
-        {"HTTPPort", ref.HTTPPort},
-        {"Host", ref.Host},
-        {"RMRPort", ref.RMRPort},
-    };
-}
-
-} /*namespace model*/
-} /*namespace xapp*/
-#endif /*XAPP_MODEL_SubscriptionParams_ClientEndpoint_H*/
diff --git a/src/rest/model/SubscriptionParams_E2SubscriptionDirectives.h b/src/rest/model/SubscriptionParams_E2SubscriptionDirectives.h
deleted file mode 100644 (file)
index a0f783c..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-#ifndef XAPP_MODEL_SubscriptionParams_E2SubscriptionDirectives_H
-#define XAPP_MODEL_SubscriptionParams_E2SubscriptionDirectives_H
-#include "ModelBase.h"
-
-namespace xapp {
-namespace model {
-
-struct SubscriptionParams_E2SubscriptionDirectives: ModelBase {
-    int E2RetryCount;
-    int E2TimeoutTimerValue;
-    bool RMRRoutingNeeded;
-    json validator_schema = R"(
-    {
-    "$schema": "http://json-schema.org/draft-07/schema#",
-    "title": "SubscriptionParams_E2SubscriptionDirectives",
-    "description": "Optional. If not set Submgr uses its default values",
-    "properties": {
-        "E2RetryCount": {
-            "description": "How many times E2 subscription request is retried",
-            "type": "integer",
-            "minimum": 0,
-            "maximum": 10
-        },
-        "E2TimeoutTimerValue": {
-            "description": "How long time response is waited from E2 node",
-            "type": "integer",
-            "minimum": 0,
-            "maximum": 10
-        },
-        "RMRRoutingNeeded": {
-            "description": "Subscription needs RMR route from E2Term to xApp",
-            "type": "boolean"
-        }
-    },
-    "required": [
-                 "E2TimeoutTimerValue",
-                 "E2RetryCount",
-                 "RMRRoutingNeeded"
-                ],
-    "type": "object"
-    })"_json;
-
-    virtual json get_validator_schema() const { return validator_schema; }
-};
-
-void from_json(const json& j, SubscriptionParams_E2SubscriptionDirectives& ref) {
-
-    std::cout << __PRETTY_FUNCTION__ << std::endl;
-
-    j.at("E2RetryCount").get_to(ref.E2RetryCount);
-    j.at("E2TimeoutTimerValue").get_to(ref.E2TimeoutTimerValue);
-    j.at("RMRRoutingNeeded").get_to(ref.RMRRoutingNeeded);
-}
-
-void to_json(json& j, const SubscriptionParams_E2SubscriptionDirectives& ref) {
-
-    j = json {
-        {"E2RetryCount", ref.E2RetryCount},
-        {"E2TimeoutTimerValue", ref.E2TimeoutTimerValue},
-        {"RMRRoutingNeeded", ref.RMRRoutingNeeded},
-    };
-}
-
-} /*namespace model*/
-} /*namespace xapp*/
-#endif /*XAPP_MODEL_SubscriptionParams_ClientEndpoint_H*/
diff --git a/src/rest/model/SubscriptionResponse.h b/src/rest/model/SubscriptionResponse.h
deleted file mode 100644 (file)
index 3d8e8d4..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#ifndef XAPP_MODEL_SubscriptionResponse_H
-#define XAPP_MODEL_SubscriptionResponse_H
-#include "ModelBase.h"
-#include "SubscriptionInstance.h"
-
-namespace xapp {
-namespace model {
-
-struct SubscriptionResponse: ModelBase {
-    int SubscriptionID;
-    SubscriptionInstances m_SubscriptionInstances;
-
-    json validator_schema = R"(
-    {
-    "$schema": "http://json-schema.org/draft-07/schema#",
-    "title": "SubscriptionResponse",
-    "properties": {
-        "SubscriptionId": {
-            "description": "Indentification of Subscription",
-            "type": "integer"
-        },
-        "SubscriptionInstances": {
-            "description": "List of Subscription Instance",
-            "type": "array"
-        }
-    },
-    "required": [
-                 "SubscriptionId",
-                 "SubscriptionInstances"
-                 ],
-    "type": "object"
-    })"_json;
-
-    virtual json get_validator_schema() const { return validator_schema; }
-};
-
-void from_json(const json& j, SubscriptionResponse& ref) {
-
-    std::cout << __PRETTY_FUNCTION__ << std::endl;
-    ref.validate_json(j);
-
-    j.at("SubscriptionId").get_to(ref.SubscriptionID);
-    j.at("SubscriptionInstances").get_to(ref.m_SubscriptionInstances);
-}
-
-void to_json(json& j, const SubscriptionResponse& ref) {
-
-    j = json {
-        {"SubscriptionId",ref.SubscriptionID},
-        {"SubscriptionInstances", ref.m_SubscriptionInstances}
-    };
-}
-
-} /*model*/
-} /*xapp*/
-#endif /*XAPP_MODEL_SubscriptionResponse_H*/
diff --git a/src/rest/model/SubsequentAction.h b/src/rest/model/SubsequentAction.h
deleted file mode 100644 (file)
index 0943579..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#ifndef XAPP_MODEL_SubsequentAction_H
-#define XAPP_MODEL_SubsequentAction_H
-#include "ModelBase.h"
-
-namespace xapp {
-namespace model {
-
-struct SubsequentAction: ModelBase {
-    std::string SubsequentActionType;
-    std::string TimeToWait;
-    json validator_schema = R"(
-    {
-    "$schema": "http://json-schema.org/draft-07/schema#",
-    "title": "SubsequentAction",
-    "properties": {
-        "SubsequentActionType": {
-            "description": "Type of Subsequent Action",
-            "type": "string",
-            "enum": ["wait", "continue"]
-
-        },
-        "TimeToWait": {
-            "description": "Time to waiting",
-            "type": "string",
-            "enum": ["zero", "w1ms", "w2ms", "w5ms", "w10ms", "w20ms", "w30ms",
-                    "w40ms", "w50ms", "w100ms", "w200ms", "w500ms", "w1s",
-                    "w2s", "w5s", "w10s", "w20s", "w60s"]
-        }
-    },
-    "required": [
-                 "SubsequentActionType",
-                 "TimeToWait"
-                 ],
-    "type": "object"
-    })"_json;
-
-    virtual json get_validator_schema() const { return validator_schema; }
-};
-
-void from_json(const json& j, SubsequentAction& ref) {
-
-    std::cout << __PRETTY_FUNCTION__ << "\n";
-    ref.validate_json(j);
-
-    j.at("SubsequentActionType").get_to(ref.SubsequentActionType);
-    j.at("TimeToWait").get_to(ref.TimeToWait);
-}
-
-void to_json(json& j, const SubsequentAction& ref) {
-
-    j = json {
-        {"SubsequentActionType",ref.SubsequentActionType},
-        {"TimeToWait", ref.TimeToWait}
-    };
-}
-
-} /*model*/
-} /*xapp*/
-#endif /*XAPP_MODEL_SubsequentAction_H*/
index 7be7eee..ed36205 100644 (file)
@@ -2,7 +2,7 @@
 coverage_opts = -ftest-coverage -fprofile-arcs
 
 binaries = unit_test jhash_test config_test metrics_test
-include = -I ../src/xapp -I ../src/alarm -I ../src/messaging  -I  ../src/config -I ../ext/jsmn  -I  ../src/json -I ../src/metrics
+include = -I ../src/xapp -I ../src/alarm -I ../src/messaging  -I  ../src/config -I ../ext/jsmn  -I  ../src/json -I ../src/metrics  -I ../src/model -I ../src/rest-client -I ../src/rest-server
 
 tests::        $(binaries)
 
@@ -14,7 +14,7 @@ rmr_em.o::    rmr_em.c
 # emulate (and don't need to)
 #
 unit_test:: unit_test.cpp rmr_em.o
-       g++ -g $(coverage_opts) $(include) unit_test.cpp -o unit_test -L../.build -lricxfcpp rmr_em.o  -lrmr_si -lpthread
+       g++ -g $(coverage_opts) $(include) unit_test.cpp -o unit_test -L../.build -lricxfcpp rmr_em.o  -lrmr_si -lpthread -lm -lboost_system -lcrypto -lssl -lcpprest -lpistache -lnlohmann_json_schema_validator
 
 # build a special jwrapper object with coverage settings
 jwrapper_test.o:: ../src/json/jwrapper.c ../src/json/jwrapper.h
@@ -22,13 +22,13 @@ jwrapper_test.o:: ../src/json/jwrapper.c ../src/json/jwrapper.h
 
 jhash_test:: jwrapper_test.o jhash_test.cpp
        # do NOT link the xapp lib; we include all modules in the test programme
-       g++ -g $(coverage_opts) -I ../src/json -I ../ext/jsmn jhash_test.cpp -o jhash_test jwrapper_test.o -lrmr_si -lpthread
+       g++ -g $(coverage_opts) -I ../src/json -I ../ext/jsmn jhash_test.cpp -o jhash_test jwrapper_test.o -lrmr_si -lpthread -lm -lboost_system -lcrypto -lssl -lcpprest -lpistache -lnlohmann_json_schema_validator
 
 metrics_test:: metrics_test.cpp rmr_em.o
-       g++ -g $(coverage_opts) $(include) metrics_test.cpp -o metrics_test -L../.build -lricxfcpp rmr_em.o -l rmr_si -lpthread
+       g++ -g $(coverage_opts) $(include) metrics_test.cpp -o metrics_test -L../.build -lricxfcpp rmr_em.o -l rmr_si -lpthread -lm -lboost_system -lcrypto -lssl -lcpprest -lpistache -lnlohmann_json_schema_validator
 
 config_test:: config_test.cpp jwrapper_test.o
-       g++ -g $(coverage_opts) $(include) config_test.cpp -o config_test jwrapper_test.o -lricxfcpp -lrmr_si -lpthread
+       g++ -g $(coverage_opts) $(include) config_test.cpp -o config_test jwrapper_test.o -lricxfcpp -lrmr_si -lpthread -lm -lboost_system -lcrypto -lssl -lcpprest -lpistache -lnlohmann_json_schema_validator
 
 # prune gcov files generated by system include files
 clean::
@@ -38,3 +38,4 @@ clean::
 nuke::
        rm -f *.a *.o *.gcov *.gcda *.gcno core a.out $(binaries)
 
+