E2AP Wrapper Implementation
[ric-app/hw.git] / src / xapp-asn / e2ap / e2ap_action.hpp
1 /*
2 ==================================================================================
3
4         Copyright (c) 2019-2020 AT&T Intellectual Property.
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19 /*
20  * e2ap_action.hpp
21  *
22  *  Created on: Jun 30, 2020
23  *      Author: Shraboni Jana
24  */
25
26 #ifndef XAPP_ASN_REFACTOR_E2AP_ACTION_HPP_
27 #define XAPP_ASN_REFACTOR_E2AP_ACTION_HPP_
28
29 #include <mdclog/mdclog.h>
30
31 #include <string>
32 #include <memory>
33 #include <sstream>
34 #include <vector>
35
36 #include "e2ap_consts.hpp"
37 /*
38  RICaction-ToBeSetup-Item ::= SEQUENCE {
39         ricActionID                                     RICactionID,
40         ricActionType                           RICactionType,
41         ricActionDefinition                     RICactionDefinition     OPTIONAL,
42         ricSubsequentAction                     RICsubsequentAction     OPTIONAL,
43         ...
44 }
45 RICsubsequentAction ::=SEQUENCE{
46         ricSubsequentActionType         RICsubsequentActionType,
47         ricTimeToWait                           RICtimeToWait,
48         ...
49 }
50
51 */
52
53
54 template<typename E2SMActionDefinition>
55 class E2APAction{
56
57 public:
58         class ActionIEs{
59         private:
60                          bool is_ricSubsequentAction, is_ricActionDefinition;
61                          unsigned int ricActionType, ricActionID,ricSubsequentActionType,ricTimeToWait;
62                          unsigned char ricActionDefinition[IE_SIZE];
63                          size_t ricActionDefinition_size = IE_SIZE;
64         public:
65                          ActionIEs():ricActionType(0),ricActionID(0),ricSubsequentActionType(0),ricTimeToWait(0),is_ricSubsequentAction(false),is_ricActionDefinition(false){ };
66                          ActionIEs& set_ricSubsequentAction(int subsequentActionType, int timeToWait){
67                                  is_ricSubsequentAction = true;
68                                  ricSubsequentActionType = subsequentActionType;
69                                  ricTimeToWait = timeToWait;
70                                  return *this;
71                          };
72
73                          ActionIEs& set_ricActionDefinition(E2SMActionDefinition &e2smObj){
74                                  bool res = e2smObj.encode(&(this->ricActionDefinition)[0],&this->ricActionDefinition_size);
75                                  if(!res){
76                                          mdclog_write(MDCLOG_ERR, "Failed to encode: %s","RIC Action Definition");
77                                          mdclog_write(MDCLOG_ERR, "Error during encode: %s",e2smObj.get_error());
78
79                                  } else {
80                                          mdclog_write(MDCLOG_INFO, "Successfully encoded: %s","RIC Action Definition");
81                                  }
82                                  this->is_ricActionDefinition = true;
83                                  return *this;
84                          };
85                          ActionIEs& set_ricActionID(int actionID){ricActionID = actionID; return *this;};
86                          ActionIEs& set_ricActionType(int actionType) {ricActionType = actionType; return *this;};
87
88                          int    get_ricActionID(){return this->ricActionID;};
89                          int    get_ricActionType() {return this->ricActionType;};
90                          bool   get_is_ricSubsequentAction() { return this->is_ricSubsequentAction; };
91                          int    get_ricSubsequentActionType(){return this->ricSubsequentActionType; }
92                          int    get_ricTimeToWait(){ return this->ricTimeToWait; }
93                          bool   get_is_ricActionDefinition(){return this->is_ricActionDefinition;};
94                          void*  get_ricActionDefinition(){ return this->ricActionDefinition; };
95                          size_t get_ricActionDefinition_size(){return this->ricActionDefinition_size; };
96
97         };
98         E2APAction(){ _ref_list = std::make_unique<std::vector<ActionIEs>>(); _count_list = 0;};
99
100         std::vector<E2APAction<E2SMActionDefinition>::ActionIEs> * get_list() const {return _ref_list.get();};
101         int get_list_count() {return _count_list;};
102
103         void add(E2APAction<E2SMActionDefinition>::ActionIEs &actionObj) { _ref_list.get()->push_back(actionObj); _count_list++;};
104 private:
105
106         std::unique_ptr<std::vector<ActionIEs>> _ref_list;
107         int _count_list;
108 };
109
110 /*RICaction-Admitted-Item ::= SEQUENCE {
111         ricActionID                                     RICactionID,
112         ...
113 }
114
115
116 RICaction-NotAdmitted-Item ::= SEQUENCE {
117         ricActionID                                     RICactionID,
118         cause                                           Cause,
119         ...
120 }*/
121
122 class RICactionAdmittedList{
123
124 public:
125         class RICactionAdmittedItemIEs{
126                 private:
127                         long int ricActionID;
128                 public:
129                         RICactionAdmittedItemIEs(void):ricActionID(0){};
130                         RICactionAdmittedItemIEs& set_ricActionID(long int actID){ricActionID = actID; return *this;};
131                         long int get_ricActionID(){return this->ricActionID;};
132
133         };
134         RICactionAdmittedList(){ _ref_list = std::make_unique<std::vector<RICactionAdmittedItemIEs>>(); _count_list = 0;};
135
136         std::vector<RICactionAdmittedItemIEs> * get_list() const {return _ref_list.get();};
137         int get_list_count() {return _count_list;};
138
139         void add(RICactionAdmittedItemIEs &actionObj) { _ref_list.get()->push_back(actionObj); _count_list++;};
140 private:
141
142         std::unique_ptr<std::vector<RICactionAdmittedItemIEs>> _ref_list;
143         int _count_list;
144
145 };
146
147 class RICactionNotAdmittedList{
148  public:
149         class RICactionNotAdmittedItemIEs{
150                 private:
151                         long int ricActionID;
152                         unsigned int ricCause, ricSubCause;
153                 public:
154                         RICactionNotAdmittedItemIEs(void):ricActionID(0),ricCause(0),ricSubCause(0){};
155                         RICactionNotAdmittedItemIEs& set_ricCause(long int cause){ricCause = cause; return *this;};
156                         RICactionNotAdmittedItemIEs& set_ricSubCause(long int subcause){ricSubCause = subcause; return *this;};
157                         RICactionNotAdmittedItemIEs& set_ricActionID(long int actID){ricActionID = actID; return *this;};
158
159                         long int get_ricCause(){return this->ricCause;};
160                         long int get_ricSubCause(){return this->ricSubCause;};
161                         long int get_ricActionID(){return this->ricActionID;};
162         };
163         RICactionNotAdmittedList(){ _ref_list = std::make_unique<std::vector<RICactionNotAdmittedItemIEs>>(); _count_list = 0;};
164
165         std::vector<RICactionNotAdmittedItemIEs> * get_list() const {return _ref_list.get();};
166         int get_list_count() {return _count_list;};
167
168         void add(RICactionNotAdmittedItemIEs &actionObj) { _ref_list.get()->push_back(actionObj); _count_list++;};
169 private:
170
171         std::unique_ptr<std::vector<RICactionNotAdmittedItemIEs>> _ref_list;
172         int _count_list;
173
174 };
175
176
177 #endif /* XAPP_ASN_REFACTOR_E2AP_ACTION_HPP_ */