3 # ==================================================================================
4 # Copyright (c) 2020 AT&T Intellectual Property.
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ==================================================================================
28 #include <sdl/syncstorage.hpp>
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>;
43 // ----------------------------------------------------------
45 std::string sdl_namespace_u = "TS-UE-metrics";
46 std::string sdl_namespace_c = "TS-cell-metrics";
49 std::unique_ptr<shareddatalayer::SyncStorage> sdl;
56 std::string prefix2="310";
57 Keys K = sdl->findKeys(nsc, prefix2); // just the prefix
58 DataMap Dk = sdl->get(nsc, K);
60 std::cout << "K contains " << K.size() << " elements.\n";
62 cout << "before forloop\n";
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
69 for(i=0;i<val_v.size();++i) val[i] = (char)(val_v[i]);
71 cout << "KEYS and Values " << (*si).c_str() << " = " << val << "\n";
74 std::string prefix3="12";
75 Keys K2 = sdl->findKeys(nsu, prefix3); // just the prefix
76 DataMap Dk2 = sdl->get(nsu, K2);
78 std::cout << "K contains " << K2.size() << " elements.\n";
80 cout << "before forloop\n";
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
86 for(i=0;i<val_v.size();++i) val[i] = (char)(val_v[i]);
88 cout << "KEYS and Values " << (*si).c_str() << " = " << val << "\n";
96 void delete_sdl_data() {
101 std::cout << "Removing All Keys from cell namespace\n";
105 std::cout << "Removing All Keys from UE namespace\n";
111 cout << "SDL Error in Removing Data for Namespace" << endl;
118 void write_sdl_data() {
120 cout << "before sdl set\n";
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}";
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 }";
130 // char key[4]="abc";
131 char key[] = "310-680-200-555001";
132 std::cout << "KEY: "<< key << std::endl;
135 // uint8_t num = 101;
136 d.assign(data_string.begin(), data_string.end());
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 }";
146 char key2[] = "310-680-200-555002";
147 std::cout << "KEY: "<< key2 << std::endl;
149 d2.assign(data_string_cell2.begin(), data_string_cell2.end());
151 dmap2.insert({k2,d});
153 sdl->set(nsc, dmap2);
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 }";
161 char key3[] = "310-680-200-555003";
162 std::cout << "KEY: "<< key3 << std::endl;
164 d3.assign(data_string_cell3.begin(), data_string_cell3.end());
166 dmap3.insert({k3,d3});
168 sdl->set(nsc, dmap3);
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 ] } ] }";
175 char key4[] = "12345";
176 std::cout << "KEY: "<< key4 << std::endl;
177 d4.assign(data_string_ue.begin(), data_string_ue.end());
180 dmap4.insert({k4,d4});
182 sdl->set(nsu, dmap4);
186 cout << "SDL Error in Set Data for Namespace" << endl;
190 cout << "after sdl set\n";
195 extern int main( int argc, char** argv ) {
197 sdl = shareddatalayer::SyncStorage::create();
199 nsu = Namespace(sdl_namespace_u);
200 nsc = Namespace(sdl_namespace_c);
205 cout << "Deleting Data\n";
210 cout << "Writing Data\n";