Fixed the route for 30000 message type; fixed license at top of write_sdl.cpp which...
[ric-app/ts.git] / test / populatedb / src / write_sdl.cpp
1
2 /*
3 # ==================================================================================
4 #       Copyright (c) 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 #include <stdio.h>
21 #include <string.h>
22 #include <unistd.h>
23
24 #include <thread>
25 #include <iostream>
26 #include <memory>
27
28 #include <sdl/syncstorage.hpp>
29 #include <set>
30 #include <map>
31 #include <vector>
32 #include <string>
33
34
35 using namespace std;
36 using Namespace = std::string;
37 using Key = std::string;
38 using Data = std::vector<uint8_t>;
39 using DataMap = std::map<Key, Data>;
40 using Keys = std::set<Key>;
41
42
43 // ----------------------------------------------------------
44
45 std::string sdl_namespace_u = "TS-UE-metrics";
46 std::string sdl_namespace_c = "TS-cell-metrics";
47
48
49 std::unique_ptr<shareddatalayer::SyncStorage> sdl;
50
51 Namespace nsu;
52 Namespace nsc;
53
54 void get_sdl_data() {
55
56   std::string prefix2="310";
57   Keys K = sdl->findKeys(nsc, prefix2);     // just the prefix
58   DataMap Dk = sdl->get(nsc, K);
59
60   std::cout << "K contains " << K.size() << " elements.\n";
61
62   cout << "before forloop\n";
63
64
65   for(auto si=K.begin();si!=K.end();++si){
66     std::vector<uint8_t> val_v = Dk[(*si)]; // 4 lines to unpack a string
67     char val[val_v.size()+1];                               // from Data
68     int i;
69     for(i=0;i<val_v.size();++i) val[i] = (char)(val_v[i]);
70     val[i]='\0';
71     cout << "KEYS and Values " << (*si).c_str()  << " = " <<  val << "\n";
72   }
73   
74   std::string prefix3="12";
75   Keys K2 = sdl->findKeys(nsu, prefix3);     // just the prefix
76   DataMap Dk2 = sdl->get(nsu, K2);
77
78   std::cout << "K contains " << K2.size() << " elements.\n";
79
80   cout << "before forloop\n";
81
82   for(auto si=K2.begin();si!=K2.end();++si){
83     std::vector<uint8_t> val_v = Dk2[(*si)]; // 4 lines to unpack a string
84     char val[val_v.size()+1];                               // from Data
85     int i;
86     for(i=0;i<val_v.size();++i) val[i] = (char)(val_v[i]);
87     val[i]='\0';
88     cout << "KEYS and Values " << (*si).c_str()  << " = " <<  val << "\n";
89   }
90   
91   cout << endl;
92
93 }
94
95
96 void delete_sdl_data() {
97
98
99   try{
100
101     std::cout << "Removing All Keys from cell namespace\n";
102
103     sdl->removeAll(nsc);
104
105     std::cout << "Removing All Keys from UE namespace\n";
106
107     sdl->removeAll(nsu);
108     
109   }
110   catch(...){
111     cout << "SDL Error in Removing Data for Namespace" << endl;
112
113   }    
114
115 }
116
117
118 void write_sdl_data() {
119
120   cout << "before sdl set\n";
121   
122   try{
123     //connecting to the Redis and generating a random key for namespace "hwxapp"
124     cout << "IN SDL Set Data";
125     //    std::string data_string = "{\"rsrp\" : -110}";
126
127     std::string data_string = "{\"CellID\": \"310-680-200-555001\", \"MeasTimestampPDCPBytes\": \"2020-03-18 02:23:18.220\", \"MeasPeriodPDCPBytes\": 20, \"PDCPBytesDL\": 2000000, \"PDCPBytesUL\": 1200000, \"MeasTimestampAvailPRB\": \"2020-03-18 02:23:18.220\", \"MeasPeriodAvailPRB\": 20, \"AvailPRBDL\": 30, \"AvailPRBUL\": 50  }";
128       
129     DataMap dmap;
130     //    char key[4]="abc";
131     char key[] = "310-680-200-555001";
132     std::cout << "KEY: "<< key << std::endl;
133     Key k = key;
134     Data d;
135     //    uint8_t num = 101;
136     d.assign(data_string.begin(), data_string.end());
137     //    d.push_back(num);
138     dmap.insert({k,d});
139
140     sdl->set(nsc, dmap);
141
142     std::string data_string_cell2 = "{ \"CellID\": \"310-680-200-555002\", \"MeasTimestampPDCPBytes\": \"2020-03-18 02:23:18.220\", \"MeasPeriodPDCPBytes\": 20, \"PDCPBytesDL\": 800000, \"PDCPBytesUL\": 400000, \"MeasTimestampAvailPRB\": \"2020-03-18 02:23:18.220\", \"MeasPeriodAvailPRB\": 20, \"AvailPRBDL\": 30, \"AvailPRBUL\": 45  }";
143
144     Data d2;
145     DataMap dmap2;    
146     char key2[] = "310-680-200-555002";
147     std::cout << "KEY: "<< key2 << std::endl;
148     Key k2 = key2;
149     d2.assign(data_string_cell2.begin(), data_string_cell2.end());
150     //    d.push_back(num);
151     dmap2.insert({k2,d});
152
153     sdl->set(nsc, dmap2);
154
155
156
157     std::string data_string_cell3 = "{ \"CellID\": \"310-680-200-555003\", \"MeasTimestampPDCPBytes\": \"2020-03-18 02:23:18.220\", \"MeasPeriodPDCPBytes\": 20, \"PDCPBytesDL\": 800000, \"PDCPBytesUL\": 400000, \"MeasTimestampAvailPRB\": \"2020-03-18 02:23:18.220\", \"MeasPeriodAvailPRB\": 20, \"AvailPRBDL\": 30, \"AvailPRBUL\": 45  }";
158
159     Data d3;
160     DataMap dmap3;
161     char key3[] = "310-680-200-555003";
162     std::cout << "KEY: "<< key3 << std::endl;
163     Key k3 = key3;
164     d3.assign(data_string_cell3.begin(), data_string_cell3.end());
165     //    d.push_back(num);
166     dmap3.insert({k3,d3});
167
168     sdl->set(nsc, dmap3);
169
170
171     std::string data_string_ue = "{ \"UEID\": 12345, \"ServingCellID\": \"310-680-200-555002\", \"MeasTimestampUEPDCPBytes\": \"2020-03-18 02:23:18.220\", \"MeasPeriodUEPDCPBytes\": 20,\"UEPDCPBytesDL\": 250000,\"UEPDCPBytesUL\": 100000, \"MeasTimestampUEPRBUsage\": \"2020-03-18 02:23:18.220\", \"MeasPeriodUEPRBUsage\": 20, \"UEPRBUsageDL\": 10, \"UEPRBUsageUL\": 30, \"MeasTimestampRF\": \"2020-03-18 02:23:18.210\",\"MeasPeriodRF\": 40, \"ServingCellRF\": [-115,-16,-5], \"NeighborCellRF\": [  {\"CID\": \"310-680-200-555001\",\"CellRF\": [-90,-13,-2.5 ] }, {\"CID\": \"310-680-200-555003\",     \"CellRF\": [-140,-17,-6 ] } ] }";
172       
173     Data d4;
174     DataMap dmap4;
175     char key4[] = "12345";
176     std::cout << "KEY: "<< key4 << std::endl;
177     d4.assign(data_string_ue.begin(), data_string_ue.end());
178     Key k4 = key4;
179     //    d.push_back(num);
180     dmap4.insert({k4,d4});
181
182     sdl->set(nsu, dmap4);
183     
184   }
185   catch(...){
186     cout << "SDL Error in Set Data for Namespace" << endl;
187
188   }
189
190   cout << "after sdl set\n";
191
192 }
193
194
195 extern int main( int argc, char** argv ) {
196
197   sdl = shareddatalayer::SyncStorage::create();
198
199   nsu = Namespace(sdl_namespace_u);
200   nsc = Namespace(sdl_namespace_c);
201
202   cout << "\n\n";
203   get_sdl_data();
204   cout << "\n\n";
205   cout << "Deleting Data\n";  
206   delete_sdl_data();
207   cout << "\n\n";  
208   get_sdl_data();
209   cout << "\n\n";
210   cout << "Writing Data\n";
211   write_sdl_data();
212   cout << "\n\n";
213   get_sdl_data();
214
215   return 0;
216   
217 }