version 4.0.0 first support for new E2 ASN
[ric-plt/e2.git] / RIC-E2-TERMINATION / TEST / testAsn / sctpClient / sctpClient.h
1 /*
2  * Copyright 2020 AT&T Intellectual Property
3  * Copyright 2020 Nokia
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 // Created by adi ENZEL on 2/16/20.
20 //
21
22 #ifndef E2_SCTPCLIENT_H
23 #define E2_SCTPCLIENT_H
24
25 #include <cstdio>
26 #include <cerrno>
27 #include <cstdlib>
28 #include <cstring>
29 #include <sys/socket.h>
30 #include <arpa/inet.h>
31 #include <netinet/in_systm.h>
32 #include <netinet/in.h>
33 #include <unistd.h>
34 #include <sys/file.h>
35 #include <netdb.h>
36 #include <sys/epoll.h>
37 #include <map>
38 #include "oranE2/E2AP-PDU.h"
39
40 #include "../httpServer/HttpServer.h"
41
42 #include "../rmrClient/rmrClient.h"
43 #include "cxxopts/include/cxxopts.hpp"
44 #include "../base64.h"
45 #include "../mapWrapper.h"
46
47
48
49
50 using namespace std;
51 using namespace Pistache;
52
53 #define SA struct sockaddr
54
55 #define MAXEVENTS 128
56 #define SCTP_BUFFER_SIZE (64*1024)
57
58 typedef enum messages {
59     setupRequest_gnb,
60     setupRequest_en_gNB,
61     setupRequest_ng_eNB,
62     setupRequest_eNB,
63
64     nothing
65 } messages_t;
66
67
68 typedef struct SctpClient {
69     string host {};
70     int rmrPort{};
71     int epoll_fd{};
72     int sctpSock{};
73     int httpBaseSocket {};
74     int httpSocket {};
75     mapWrapper mapKey;
76
77     char delimiter[2] {'|', 0};
78
79 } SctpClient_t;
80
81 void createHttpLocalSocket(SctpClient_t &sctpClient);
82
83 int createEpoll(SctpClient_t &sctpClient);
84
85 inline static uint64_t rdtscp(uint32_t &aux) {
86     uint64_t rax, rdx;
87     asm volatile ("rdtscp\n" : "=a" (rax), "=d" (rdx), "=c" (aux) : :);
88     return (rdx << (unsigned) 32) + rax;
89 }
90
91 int createSctpConnction(SctpClient_t *sctpClient, const char *address, int port, bool local = true);
92
93 __attribute_warn_unused_result__ int createListeningTcpConnection(SctpClient_t *sctpClient);
94
95 int modifyEpollToRead(SctpClient_t *sctpClient, int modifiedSocket);
96
97 cxxopts::ParseResult parse(SctpClient_t &sctpClient, int argc, char *argv[]);
98
99 #endif //E2_SCTPCLIENT_H