/* * Copyright 2020 AT&T Intellectual Property * Copyright 2020 Nokia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include //#include #include "oranE2/E2AP-PDU.h" #include "oranE2/InitiatingMessage.h" #include "oranE2/SuccessfulOutcome.h" #include "oranE2/UnsuccessfulOutcome.h" #include "oranE2/ProtocolIE-Field.h" #include "oranE2/ENB-ID.h" #include "oranE2/GlobalENB-ID.h" #include "oranE2/GlobalE2node-gNB-ID.h" #include "oranE2/constr_TYPE.h" #include "E2Builder.h" using namespace std; #include "BuildRunName.h" void buildRanName(E2AP_PDU_t *pdu, unsigned char *buffer) { for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) { auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i]; if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) { if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) { memset(buffer, 0, 128); buildRanName( (char *) buffer, ie); } } } } void extractPdu(E2AP_PDU_t *pdu, unsigned char *buffer, int buffer_size) { asn_enc_rval_t er; er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size); if (er.encoded == -1) { cerr << "encoding of " << asn_DEF_E2AP_PDU.name << " failed, " << strerror(errno) << endl; exit(-1); } else if (er.encoded > (ssize_t) buffer_size) { cerr << "Buffer of size " << buffer_size << " is to small for " << asn_DEF_E2AP_PDU.name << endl; exit(-1); } else { cout << "XML result = " << buffer << endl; } } std::string otherXml = "\n" " \n" " 1\n" " \n" " \n" " \n" " \n" " \n" " 4\n" " \n" " \n" " \n" " 13 10 14\n" " \n" " 10011001101010101011" " \n" " \n" " \n" " \n" " \n" " 9\n" " \n" " \n" " \n" " \n" " 6\n" " \n" " \n" " \n" " 1\n" " 1\n" " \n" " \n" " \n" " \n" " 6\n" " \n" " \n" " \n" " 2\n" " 1\n" " \n" " \n" " \n" " \n" " 6\n" " \n" " \n" " \n" " 3\n" " 1\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "\n"; std::string newXml = "1413 10 14101010101100110011109611621631"; std::string setupFailure = "" "" "1" "" "" "" "" "" "1" "" "" "" "" "" "" "" "" "" "" "" "" "" ""; std::string otherSucc = " " "" "1" "" "" "" "" "" "4" "" "" "" "131014" "10101010110011001110" "" "" "9611621631"; auto main(const int argc, char **argv) -> int { E2AP_PDU_t pdu; char *printBuffer; size_t size; FILE *stream = open_memstream(&printBuffer, &size); auto buffer_size = 8192; unsigned char buffer[8192] = {}; E2AP_PDU_t *XERpdu = nullptr; cout << "message size = " << otherSucc.length() << endl; auto rval = asn_decode(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, (void **) &XERpdu, otherSucc.c_str(), otherSucc.length()); if (rval.code != RC_OK) { cout << "Error " << rval.code << " (unpack) setup response " << endl; //return -1; } asn_fprint(stream, &asn_DEF_E2AP_PDU, XERpdu); cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl; fseek(stream,0,SEEK_SET); cout << "=========================" << endl << endl << endl << "========================" << endl; buildSubsReq(&pdu); char errbuf[256]; int errlen = 256; int ret = asn_check_constraints(&asn_DEF_E2AP_PDU, &pdu, errbuf, (size_t *)&errlen); if (ret) { cout << "Constraint validation failed: " << errbuf << endl; } asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl; //fseek(stream,0,SEEK_SET); extractPdu(&pdu, buffer, buffer_size); memset(buffer, 0, buffer_size); buildSetupRequest(&pdu, 311, 410); asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl; fseek(stream,0,SEEK_SET); extractPdu(&pdu, buffer, buffer_size); buildRanName(&pdu, buffer); cout << "Ran name = " << buffer << endl; ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, &pdu); memset(buffer, 0, buffer_size); cout << "========== en-gnb ============" << endl; buildSetupRequesteenGNB(&pdu, 320, 512); asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl; fseek(stream,0,SEEK_SET); cout << "========== en-gnb ============" << endl; extractPdu(&pdu, buffer, buffer_size); buildRanName(&pdu, buffer); cout << "Ran name = " << buffer << endl; ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, &pdu); memset(buffer, 0, buffer_size); buildSetupRequestWithFunc(&pdu, 311, 410); extractPdu(&pdu, buffer, buffer_size); buildRanName(&pdu, buffer); cout << "Ran name = " << buffer << endl; cout << "Sucessesfull outcome" << endl; ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, &pdu); memset(buffer, 0, buffer_size); uint8_t data[4] = {0x99, 0xAA, 0xBB, 0}; buildSetupSuccsessfulResponse(&pdu, 311, 410, data); asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl; fseek(stream,0,SEEK_SET); extractPdu(&pdu, buffer, buffer_size); cout << "Failure outcome" << endl; ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, &pdu); memset(buffer, 0, buffer_size); buildSetupUnSuccsessfulResponse(&pdu); asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl; fseek(stream,0,SEEK_SET); extractPdu(&pdu, buffer, buffer_size); memset(buffer, 0, buffer_size); buildResetReq(&pdu); asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); cout << "Encoding E2AP PDU (Reset Request) of size " << size << endl << printBuffer << endl; fseek(stream,0,SEEK_SET); extractPdu(&pdu, buffer, buffer_size); memset(buffer, 0, buffer_size); buildServiceQuery(&pdu); asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); cout << "Encoding E2AP PDU (service query) of size " << size << endl << printBuffer << endl; fseek(stream,0,SEEK_SET); extractPdu(&pdu, buffer, buffer_size); memset(buffer, 0, buffer_size); buildServiceUpdateResponce(&pdu); asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); cout << "Encoding E2AP PDU (service update ack) of size " << size << endl << printBuffer << endl; fseek(stream,0,SEEK_SET); extractPdu(&pdu, buffer, buffer_size); memset(buffer, 0, buffer_size); buildResetResponse(&pdu); asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); cout << "Encoding E2AP PDU (reset response example) of size " << size << endl << printBuffer << endl; fseek(stream,0,SEEK_SET); extractPdu(&pdu, buffer, buffer_size); memset(buffer, 0, buffer_size); }