Fix: update the correct pre-built script to cmake-sonar.sh
[ric-app/mc.git] / schemaparser / load_mcnib1.cc
1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<string.h>
4
5 #include<string>
6 #include<iostream>
7 #include<fstream>
8
9 #include"json.h"
10 #include"schemaparser.h"
11
12 #include <sdl/syncstorage.hpp>
13
14 //      data type definitions from sdl
15 using Namespace = std::string;
16 using Key = std::string;
17 using Data = std::vector<uint8_t>;
18 using DataMap = std::map<Key, Data>;
19 using Keys = std::set<Key>;
20
21 struct vstring32 {
22     unsigned int length;
23     unsigned int offset;
24     unsigned int reserved;
25 };
26
27
28 struct thpt{
29         unsigned long long int TS;
30         unsigned long long int e_RAB_ID;
31         unsigned long long int UE_ID;
32         vstring32 GNB_ID;
33         double measurement_interval;
34         unsigned long long int active_throughput;
35         unsigned long long int average_throughput;
36         unsigned long long int min_throughput;
37         unsigned long long int max_throughput;
38 };
39         
40
41 using namespace std;
42 using namespace mc_schema;
43
44 vector<uint8_t> packData(const char *d, int len){
45         const uint8_t *d8 = (const uint8_t *)d;
46         return Data(d8, d8+len+1);
47 }
48
49 int main(int argc, char **argv){
50         Namespace ns("mcnib");  
51
52         string directory = ".";
53         if(argc>1){
54                 directory = argv[1];
55         }
56         string inflnm = directory + "/" + string("nib.json");
57
58         ifstream infl(inflnm);
59         if(!infl){
60                 cerr << "Error, can't open " << inflnm << endl;
61                 exit(1);
62         }
63         string line;
64         string nib_str;
65         while(getline(infl, line)){
66                 nib_str += line;
67         }
68         infl.close();
69
70
71         mc_schemas *mcs = new_mc_schemas(nib_str);
72         if(mcs->has_errors()){
73                 fprintf(stderr, "Errors loading the schemas:\n%s\n",mcs->get_errors().c_str());
74         }else{
75                 vector<string> streams = mcs->get_streams();
76                 printf("Loaded %ld streams:\n", streams.size());
77                 for(int i=0;i<streams.size(); ++i){
78                         string str_rep = mcs->get_query_rep(streams[i])->to_string();
79                         printf("\t%s\n",str_rep.c_str());
80                 }
81         }
82         query_rep *qr = mcs->get_query_rep("throughput_ue");
83         
84 // ---------------------------------------------
85         std::unique_ptr<shareddatalayer::SyncStorage> sdl(shareddatalayer::SyncStorage::create());
86         DataMap D;
87
88 // --------------------------------------------
89
90         char buf[150];
91         thpt *t = (thpt *)buf;
92         int t_len = sizeof(thpt)+6;
93
94         t->TS = 10001;
95         t->e_RAB_ID = 2;
96         t->UE_ID = 3;
97         t->GNB_ID.length = 6;
98         t->GNB_ID.offset = sizeof(thpt);
99         string foobar("foobar");
100         strncpy(buf+sizeof(thpt), foobar.c_str(), 6);
101         t->measurement_interval = 10.1;
102         t->active_throughput = 4;
103         t->average_throughput = 5;
104         t->min_throughput = 6;
105         t->max_throughput = 7;
106
107         string key = "throughput_ue:"+to_string(t->UE_ID)+":"+foobar+":"+to_string(t->e_RAB_ID);
108         vector<uint8_t> val1 = packData(buf,t_len);
109         D[key] = val1;
110         
111
112         t->TS = 110001;
113         t->e_RAB_ID = 12;
114         t->UE_ID = 3;
115         t->GNB_ID.length = 6;
116         t->GNB_ID.offset = sizeof(thpt);
117 //      string foobar("foobar");
118         foobar = "foobar";
119         strncpy(buf+sizeof(thpt), foobar.c_str(), 6);
120         t->measurement_interval = 110.1;
121         t->active_throughput = 14;
122         t->average_throughput = 15;
123         t->min_throughput = 16;
124         t->max_throughput = 17;
125
126         key = "throughput_ue:"+to_string(t->UE_ID)+":"+foobar+":"+to_string(t->e_RAB_ID);
127         vector<uint8_t> val2 = packData(buf,t_len);
128         D[key] = val2;
129         
130
131         t->TS = 210001;
132         t->e_RAB_ID = 12;
133         t->UE_ID = 3;
134         t->GNB_ID.length = 6;
135         t->GNB_ID.offset = sizeof(thpt);
136 //      string foobar("foobaz");
137         foobar = "foobaz";
138         strncpy(buf+sizeof(thpt), foobar.c_str(), 6);
139         t->measurement_interval = 210.1;
140         t->active_throughput = 24;
141         t->average_throughput = 25;
142         t->min_throughput = 26;
143         t->max_throughput = 27;
144
145         key = "throughput_ue:"+to_string(t->UE_ID)+":"+foobar+":"+to_string(t->e_RAB_ID);
146         vector<uint8_t> val3 = packData(buf,t_len);
147         D[key] = val3;
148         
149
150         t->TS = 310001;
151         t->e_RAB_ID = 12;
152         t->UE_ID = 33;
153         t->GNB_ID.length = 6;
154         t->GNB_ID.offset = sizeof(thpt);
155 //      string foobar("foobar");
156         foobar = "foobar";
157         strncpy(buf+sizeof(thpt), foobar.c_str(), 6);
158         t->measurement_interval = 310.1;
159         t->active_throughput = 34;
160         t->average_throughput = 35;
161         t->min_throughput = 36;
162         t->max_throughput = 37;
163
164         key = "throughput_ue:"+to_string(t->UE_ID)+":"+foobar+":"+to_string(t->e_RAB_ID);
165         vector<uint8_t> val4 = packData(buf,t_len);
166         D[key] = val4;
167         
168         sdl->set(ns, D);
169 }