Control Message Encode/Decode
[ric-app/hw.git] / src / xapp-asn / e2ap / response_helper.hpp
1 /*
2 ==================================================================================
3         Copyright (c) 2019-2020 AT&T Intellectual Property.
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================================
17 */
18
19 #pragma once
20
21 #ifndef S_RESPONSE_HELPER_
22 #define S_RESPONSE_HELPER_
23
24 #include <vector>
25 #include <memory>
26
27 /* Simple structure to store action for RICaction of the Subscription response based on E2 v0.31 */
28 struct ActionResponse {
29 public:
30   ActionResponse(int id): _is_admit(true), _id(id), _cause(-1), _sub_cause(-1){};
31   ActionResponse(int id, int cause, int sub_cause): _is_admit(false), _id(id), _cause(cause), _sub_cause(sub_cause){};
32   
33   int get_id() const{
34     return _id;
35   };
36
37   int get_cause() const{
38     return _cause;
39   };
40
41   int get_sub_cause() const{
42     return _sub_cause;
43   };
44
45   bool is_admitted(void){
46     return _is_admit;
47   };
48   
49 private:
50
51   bool _is_admit;
52   int _id, _cause, _sub_cause;
53   
54 };
55
56
57 struct subscription_response_helper {
58   
59 public:
60
61   using action_t = std::vector<ActionResponse>;
62   
63   subscription_response_helper(void){
64     _action_admitted_ref = std::make_unique<action_t>();
65     _action_not_admitted_ref = std::make_unique<action_t>();
66     
67   };
68   
69   // copy operator
70   subscription_response_helper(const subscription_response_helper &he ){
71     _action_admitted_ref = std::make_unique<action_t>();
72     _action_not_admitted_ref = std::make_unique<action_t>();
73     
74     _req_id = he.get_request_id();
75     _req_seq_no = he.get_req_seq();
76     _func_id = he.get_function_id();
77     
78     // Take care of the actions
79     for (auto const & e: *(he.get_admitted_list())){
80       add_action(e.get_id());
81     }
82     
83     for(auto const  & e: *(he.get_not_admitted_list())){
84       add_action(e.get_id(), e.get_cause(), e.get_sub_cause());
85     };
86   }
87   
88
89   // assignment operator
90   void operator=(const subscription_response_helper & he){
91     _action_admitted_ref = std::make_unique<action_t>();
92     _action_not_admitted_ref = std::make_unique<action_t>();
93     
94     _req_id = he.get_request_id();
95     _req_seq_no = he.get_req_seq();
96     _func_id = he.get_function_id();
97     
98     
99     // Take care of the actions
100     for (auto  const & e: *(he.get_admitted_list())){
101       add_action(e.get_id());
102     }
103   
104     for(auto const  & e: *(he.get_not_admitted_list())){
105       add_action(e.get_id(), e.get_cause(), e.get_sub_cause());
106     };
107     
108   }
109   
110   action_t * get_admitted_list (void ) const {return _action_admitted_ref.get();};
111   action_t * get_not_admitted_list (void ) const{return _action_not_admitted_ref.get();};
112   
113   void set_request(int id, int seq_no){
114     _req_id = id;
115     _req_seq_no = seq_no;
116     
117   };
118
119   void clear(void){
120     _action_admitted_ref.get()->clear();
121     _action_not_admitted_ref.get()->clear();
122   }
123
124   
125   void set_function_id(int id){
126     _func_id = id;
127   };
128
129   void add_action(int id){
130     ActionResponse a(id) ;
131     _action_admitted_ref.get()->push_back(a);
132   };
133
134   void add_action(int id, int cause, int sub_cause){
135     ActionResponse a (id, cause, sub_cause);
136     _action_not_admitted_ref.get()->push_back(a);
137   };
138
139
140   int  get_request_id(void) const{
141     return _req_id;
142   }
143   
144   int get_req_seq(void) const{
145     return _req_seq_no;
146   }
147
148   int  get_function_id(void) const{
149     return _func_id;
150   }
151  
152   std::string  to_string(void){
153     std::string Info;
154     Info += "Request ID = " + std::to_string(_req_id) + "\n";
155     Info += "Request Sequence No = "  + std::to_string(_req_seq_no) + "\n";
156     Info += "RAN Function ID = " + std::to_string(_func_id) + "\n";
157     Info += "Actions Admitted =\n";
158     int i = 0;
159     for(auto & e: *(_action_admitted_ref)){
160         Info += std::to_string(i)  + ": ID=" + std::to_string(e.get_id()) + "\n";
161         i++;
162     }    
163     Info += "Actions Not Admitted =\n";
164     i = 0;
165     for(auto & e: *(_action_not_admitted_ref)){
166       Info += std::to_string(i)  + ": ID=" + std::to_string(e.get_id()) +  ": Cause =" + std::to_string(e.get_cause()) + ": Sub-Cause=" + std::to_string(e.get_sub_cause()) + "\n";
167       i++;
168     }    
169   
170     return Info;
171   } 
172
173 private:
174   int _req_id, _req_seq_no, _func_id;
175   std::unique_ptr<action_t> _action_admitted_ref;
176   std::unique_ptr<action_t> _action_not_admitted_ref;
177   
178 };
179   
180
181 #endif