Add initial codes
[it/test.git] / simulators / e2sim / src / e2agent.cpp
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2019 AT&T Intellectual Property                                  *
4 # Copyright 2019 Nokia                                                       *
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 <unistd.h>
22 #include <string>
23 #include <iostream>
24
25 #include "e2sim_defs.h"
26 #include "e2sim_sctp.hpp"
27 #include "asn_e2ap.hpp"
28 #include "e2ap_message_handler.hpp"
29
30 using namespace std;
31
32 void test(void)
33 {
34   e2ap_pdu_t* pdu = new_e2ap_pdu();
35
36   gNB_config gnb_cfg;
37
38   e2ap_create_ENDCX2SetupResponse(pdu, gnb_cfg);
39
40   e2ap_print_pdu(pdu);
41
42   //Encode into buffer
43   sctp_buffer_t data;
44   e2ap_encode_pdu(pdu, data.buffer, sizeof(data.buffer), data.len);
45
46 }
47
48 int main(int argc, char* argv[]){
49
50   LOG_I("E2 Agent (E2 Simulator) Version %s", VERSION);
51
52   // test();
53   // return 0;
54
55   options_t ops = read_input_options(argc, argv);
56
57   int server_fd = sctp_start_server(ops.server_ip, ops.server_port);
58   int client_fd = sctp_accept_connection(ops.server_ip, server_fd);
59
60   sctp_buffer_t recv_buf;
61
62   LOG_I("[SCTP] Waiting for SCTP data");
63   while(1) //constantly looking for data on SCTP interface
64   {
65     if(sctp_receive_data(client_fd, recv_buf) <= 0)
66       break;
67
68     LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
69
70     e2ap_handle_sctp_data(client_fd, recv_buf);
71   }
72
73   return 0;
74 }