2 * Copyright 2020 AT&T Intellectual Property
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 //#include <mdclog/mdclog.h>
28 #include "oranE2/E2AP-PDU.h"
29 #include "oranE2/InitiatingMessage.h"
30 #include "oranE2/SuccessfulOutcome.h"
31 #include "oranE2/UnsuccessfulOutcome.h"
33 #include "oranE2/ProtocolIE-Field.h"
34 #include "oranE2/ENB-ID.h"
35 #include "oranE2/GlobalENB-ID.h"
36 #include "oranE2/GlobalE2node-gNB-ID.h"
37 #include "oranE2/constr_TYPE.h"
39 #include "E2Builder.h"
44 #include "BuildRunName.h"
46 void buildRanName(E2AP_PDU_t *pdu, unsigned char *buffer) {
47 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) {
48 auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i];
49 if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) {
50 if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) {
51 memset(buffer, 0, 128);
52 buildRanName( (char *) buffer, ie);
59 void extractPdu(E2AP_PDU_t *pdu, unsigned char *buffer, int buffer_size) {
61 er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size);
62 if (er.encoded == -1) {
63 cerr << "encoding of " << asn_DEF_E2AP_PDU.name << " failed, " << strerror(errno) << endl;
65 } else if (er.encoded > (ssize_t) buffer_size) {
66 cerr << "Buffer of size " << buffer_size << " is to small for " << asn_DEF_E2AP_PDU.name << endl;
69 cout << "XML result = " << buffer << endl;
74 auto main(const int argc, char **argv) -> int {
78 FILE *stream = open_memstream(&printBuffer, &size);
79 auto buffer_size = 8192;
80 unsigned char buffer[8192] = {};
82 buildSetupRequest(&pdu, 311, 410);
83 asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu);
84 cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl;
85 fseek(stream,0,SEEK_SET);
87 extractPdu(&pdu, buffer, buffer_size);
88 buildRanName(&pdu, buffer);
89 cout << "Ran name = " << buffer << endl;
91 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, &pdu);
92 memset(buffer, 0, buffer_size);
94 buildSetupRequestWithFunc(&pdu, 311, 410);
95 extractPdu(&pdu, buffer, buffer_size);
97 buildRanName(&pdu, buffer);
98 cout << "Ran name = " << buffer << endl;
100 cout << "Sucessesfull outcome" << endl;
101 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, &pdu);
102 memset(buffer, 0, buffer_size);
103 uint8_t data[4] = {0x99, 0xAA, 0xBB, 0};
105 buildSetupSuccsessfulResponse(&pdu, 311, 410, data);
107 asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu);
108 cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl;
109 fseek(stream,0,SEEK_SET);
111 extractPdu(&pdu, buffer, buffer_size);
113 cout << "Failure outcome" << endl;
114 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, &pdu);
115 memset(buffer, 0, buffer_size);
117 buildSetupUnSuccsessfulResponse(&pdu);
118 asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu);
119 cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl;
120 fseek(stream,0,SEEK_SET);
122 extractPdu(&pdu, buffer, buffer_size);