First commit

This commit is contained in:
Leonardo Bonati
2021-12-08 20:17:46 +00:00
commit 60dffad583
2923 changed files with 463894 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
//
// Created by adi ENZEL on 11/26/19.
//
#include "LogTest.h"
string LogTest::getLine() {
std::string line;
if (std::getline(file, line)) {
return line;
}
return "";
}
void LogTest::getJsonDoc(string json) {
if (json.length() != 0) {
document.Parse(json.c_str());
}
}
string LogTest::getBase64(Document &document) {
if (document.HasMember("asnBase64")) {
return document["asnBase64"].GetString();
}
return "";
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
//
// Created by adi ENZEL on 11/26/19.
//
#ifndef E2_LOGTEST_H
#define E2_LOGTEST_H
#include <algorithm>
#include <cstdio>
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <random>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/sctp.h>
#include <thread>
#include <atomic>
#include <sys/param.h>
#include <sys/file.h>
#include <ctime>
#include <netdb.h>
#include <sys/epoll.h>
#include <mutex>
#include <shared_mutex>
#include <iterator>
#include <map>
#include <fstream>
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
using namespace std;
using namespace rapidjson;
class LogTest {
public:
LogTest() = default;
int openFile(string const& configFile) {
file.open(configFile.c_str());
if (!file) {
return -1;
}
return 0;
}
string getLine();
void getJsonDoc(string json);
string getBase64(Document &document);
private:
std::ifstream file;
Document document;
};
#endif //E2_LOGTEST_H

View File

@@ -0,0 +1,112 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
//
// Created by adi ENZEL on 11/19/19.
//
#include "ReadConfigFile.h"
#include <mdclog/mdclog.h>
#include <cgreen/cgreen.h>
Describe(Cgreen);
BeforeEach(Cgreen) {}
AfterEach(Cgreen) {}
using namespace cgreen;
void init_log() {
mdclog_attr_t *attr;
mdclog_attr_init(&attr);
mdclog_attr_set_ident(attr, "TestConfiguration");
mdclog_init(attr);
mdclog_attr_destroy(attr);
}
Ensure(Cgreen, fileNotExist) {
ReadConfigFile conf {};
assert_that( conf.openConfigFile("kuku") == -1);
}
Ensure(Cgreen, fileExists) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.conf") == 0);
}
Ensure(Cgreen, goodparams) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.conf") == 0);
assert_that(conf.getIntValue("nano") == 38000);
assert_that(conf.getStringValue("loglevel") == "info");
assert_that(conf.getStringValue("volume") == "log");
}
Ensure(Cgreen, badParams) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.conf") == 0);
assert_that(conf.getIntValue("nano") != 38002);
assert_that(conf.getStringValue("loglevel") != "");
assert_that(conf.getStringValue("volume") != "bob");
assert_that(conf.getStringValue("volum") != "bob");
}
Ensure(Cgreen, wrongType) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.conf") == 0);
assert_that(conf.getStringValue("nano") != "debug");
assert_that(conf.getIntValue("loglevel") != 3);
assert_that(conf.getDoubleValue("loglevel") != 3.0);
}
Ensure(Cgreen, badValues) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.bad") == 0);
}
Ensure(Cgreen, sectionTest) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.sec") == 0);
assert_that(conf.getIntValue("config.nano") == 38000);
}
Ensure(Cgreen, sectionBadTest) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.secbad") == -1);
//assert_that(conf.getIntValue("config.nano") == 38000);
}
int main(const int argc, char **argv) {
mdclog_severity_t loglevel = MDCLOG_INFO;
init_log();
mdclog_level_set(loglevel);
//TestSuite *suite = create_test_suite();
TestSuite *suite = create_named_test_suite_(__FUNCTION__, __FILE__, __LINE__);
add_test_with_context(suite, Cgreen, fileNotExist);
add_test_with_context(suite, Cgreen, fileExists);
add_test_with_context(suite, Cgreen, goodparams);
add_test_with_context(suite, Cgreen, badParams);
add_test_with_context(suite, Cgreen, wrongType);
add_test_with_context(suite, Cgreen, badValues);
add_test_with_context(suite, Cgreen, sectionTest);
add_test_with_context(suite, Cgreen, sectionBadTest);
return cgreen::run_test_suite(suite, create_text_reporter());
}

View File

@@ -0,0 +1,60 @@
##############################################################################
#
# Copyright (c) 2019 AT&T Intellectual Property.
#
# 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.
#
##############################################################################
#
# This source code is part of the near-RT RIC (RAN Intelligent Controller)
# platform project (RICP).
#
FROM snapshot.docker.ranco-dev-tools.eastus.cloudapp.azure.com:10001/e2_base:1.0.0 as ubuntu
WORKDIR /opt/e2/
RUN mkdir -p /opt/e2/RIC-E2-TERMINATION/ \
&& mkdir -p /opt/e2/RIC-E2-TERMINATION/TEST/T1 \
&& mkdir -p /opt/e2/RIC-E2-TERMINATION/TEST/T2
COPY . /opt/e2/RIC-E2-TERMINATION/
RUN mv /opt/e2/RIC-E2-TERMINATION/CMakeLists.txt /opt/e2/
RUN echo "137.135.91.204 gerrit.ranco-dev-tools.eastus.cloudapp.azure.com" >> /etc/hosts \
&& apt-get install -y autoconf gawk libtool automake pkg-config autoconf-archive \
&& git clone http://gerrit.ranco-dev-tools.eastus.cloudapp.azure.com/com/log \
&& cd log \
&& ./autogen.sh && ./configure && make && make install && ldconfig
RUN git clone https://gerrit.o-ran-sc.org/r/ric-plt/lib/rmr \
&& cd rmr/; mkdir build; cd build; /opt/bin/cmake -DDEV_PKG=1 ..; make install \
&& cd /opt/e2/ && /opt/bin/cmake . && make
FROM ubuntu:16.04
COPY --from=ubuntu /opt/e2/setUpTest /opt/e2/setUpTest
COPY --from=ubuntu /opt/e2/RIC-E2-TERMINATION/TEST/T1/dockerRouter.txt /opt/e2/dockerRouter.txt
COPY --from=ubuntu /usr/local/lib/librmr_nng.so.1 /usr/local/lib/librmr_nng.so.1
COPY --from=ubuntu /usr/local/lib/libnng.so.1 /usr/local/lib/libnng.so.1
COPY --from=ubuntu /usr/local/lib/libmdclog.so.0 /usr/local/lib/libmdclog.so.0
WORKDIR /opt/e2/
ENV LD_LIBRARY_PATH=/usr/local/lib
#ENV RMR_RTG_SVC=127.0.0.1
ENV RMR_SEED_RT=dockerRouter.txt
ENV host=127.0.0.1
ENV port=5566
ENV ran=ranname
ENV rmr=38012
ENV loglevel=info
EXPOSE 5566
EXPOSE 38012
CMD ["sh", "-c", "./setUpTest host $host port $port ran $ran rmr $rmr loglevel $loglevel" ]

View File

@@ -0,0 +1,787 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
//
// Created by adi ENZEL on 12/10/19.
//
#ifndef E2_E2BUILDER_H
#define E2_E2BUILDER_H
#include <cstring>
#include <cstdio>
#include <cerrno>
#include <cstdlib>
#include <sys/types.h>
#include <error.h>
#include <algorithm>
#include <3rdparty/oranE2SM/E2SM-gNB-NRT-RANfunction-Definition.h>
#include <3rdparty/oranE2SM/RIC-InsertStyle-List.h>
#include <3rdparty/oranE2SM/RANparameterDef-Item.h>
#include <3rdparty/oranE2/GlobalE2node-en-gNB-ID.h>
//#include <mdclog/mdclog.h>
#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 "oranE2/asn_constant.h"
using namespace std;
#define printEntry(type, function); fprintf(stdout, "start Test %s , %s", type, function);
static void checkAndPrint(asn_TYPE_descriptor_t *typeDescriptor, void *data, char *dataType, const char *function) {
char errbuf[128]; /* Buffer for error message */
size_t errlen = sizeof(errbuf); /* Size of the buffer */
if (asn_check_constraints(typeDescriptor, data, errbuf, &errlen) != 0) {
fprintf(stderr, "%s Constraint validation failed: %s", dataType, errbuf);
}
fprintf(stdout, "%s successes function %s", dataType, function);
}
void createPLMN_IDByMCCandMNC(PLMN_Identity_t *plmnId, int mcc, int mnc) {
//printEntry("PLMN_Identity_t", __func__)
ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, plmnId);
plmnId->size = 3;
plmnId->buf = (uint8_t *) calloc(1, 3);
volatile auto mcc1 = (unsigned int) (mcc / 100);
volatile auto mcc2 = (unsigned int) (mcc / 10 % 10);
volatile auto mcc3 = (unsigned int) (mcc % 10);
plmnId->buf[0] = mcc2 << 4 | mcc1;
volatile auto mnc1 = (unsigned int)0;
volatile auto mnc2 = (unsigned int)0;
volatile auto mnc3 = (unsigned int)0;
if (mnc >= 100) {
mnc1 = (unsigned int) (mnc / 100);
mnc2 = (unsigned int) (mnc / 10 % 10);
mnc3 = (unsigned int) (mnc % 10);
} else {
mnc1 = (unsigned int) (mnc / 10);
mnc2 = (unsigned int) (mnc % 10);
mnc3 = 15;
}
plmnId->buf[1] = mcc3 << 4 | mnc3 ;
plmnId->buf[2] = mnc2 << 4 | mnc1 ;
//checkAndPrint(&asn_DEF_PLMN_Identity, plmnId, (char *) "PLMN_Identity_t", __func__);
}
PLMN_Identity_t *createPLMN_ID(const unsigned char *data) {
printEntry("PLMN_Identity_t", __func__)
auto *plmnId = (PLMN_Identity_t *) calloc(1, sizeof(PLMN_Identity_t));
ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, plmnId);
plmnId->size = 3;
plmnId->buf = (uint8_t *) calloc(1, 3);
memcpy(plmnId->buf, data, 3);
checkAndPrint(&asn_DEF_PLMN_Identity, plmnId, (char *) "PLMN_Identity_t", __func__);
return plmnId;
}
BIT_STRING_t *createBIT_STRING(int size, int unusedBits, uint8_t *data) {
printEntry("BIT_STRING_t", __func__)
auto *bitString = (BIT_STRING_t *) calloc(1, sizeof(BIT_STRING_t));
ASN_STRUCT_RESET(asn_DEF_BIT_STRING, bitString);
bitString->size = size;
bitString->bits_unused = unusedBits;
bitString->buf = (uint8_t *) calloc(1, size);
// set bits to zero
data[bitString->size - 1] = ((unsigned) (data[bitString->size - 1] >>
(unsigned) bitString->bits_unused)
<< (unsigned) bitString->bits_unused);
memcpy(bitString->buf, data, size);
checkAndPrint(&asn_DEF_BIT_STRING, bitString, (char *) "BIT_STRING_t", __func__);
return bitString;
}
OCTET_STRING_t *createOCTET_STRING(const unsigned char *data, int size) {
printEntry("OCTET_STRING_t", __func__)
auto *octs = (PLMN_Identity_t *) calloc(1, sizeof(PLMN_Identity_t));
ASN_STRUCT_RESET(asn_DEF_OCTET_STRING, octs);
octs->size = size;
octs->buf = (uint8_t *) calloc(1, size);
memcpy(octs->buf, data, size);
checkAndPrint(&asn_DEF_OCTET_STRING, octs, (char *) "OCTET_STRING_t", __func__);
return octs;
}
ENB_ID_t *createENB_ID(ENB_ID_PR enbType, unsigned char *data) {
printEntry("ENB_ID_t", __func__)
auto *enb = (ENB_ID_t *) calloc(1, sizeof(ENB_ID_t));
ASN_STRUCT_RESET(asn_DEF_ENB_ID, enb);
enb->present = enbType;
switch (enbType) {
case ENB_ID_PR_macro_eNB_ID: { // 20 bit 3 bytes
enb->choice.macro_eNB_ID.size = 3;
enb->choice.macro_eNB_ID.bits_unused = 4;
enb->present = ENB_ID_PR_macro_eNB_ID;
enb->choice.macro_eNB_ID.buf = (uint8_t *) calloc(1, enb->choice.macro_eNB_ID.size);
data[enb->choice.macro_eNB_ID.size - 1] = ((unsigned) (data[enb->choice.macro_eNB_ID.size - 1] >>
(unsigned) enb->choice.macro_eNB_ID.bits_unused)
<< (unsigned) enb->choice.macro_eNB_ID.bits_unused);
memcpy(enb->choice.macro_eNB_ID.buf, data, enb->choice.macro_eNB_ID.size);
break;
}
case ENB_ID_PR_home_eNB_ID: { // 28 bit 4 bytes
enb->choice.home_eNB_ID.size = 4;
enb->choice.home_eNB_ID.bits_unused = 4;
enb->present = ENB_ID_PR_home_eNB_ID;
enb->choice.home_eNB_ID.buf = (uint8_t *) calloc(1, enb->choice.home_eNB_ID.size);
data[enb->choice.home_eNB_ID.size - 1] = ((unsigned) (data[enb->choice.home_eNB_ID.size - 1] >>
(unsigned) enb->choice.home_eNB_ID.bits_unused)
<< (unsigned) enb->choice.home_eNB_ID.bits_unused);
memcpy(enb->choice.home_eNB_ID.buf, data, enb->choice.home_eNB_ID.size);
break;
}
case ENB_ID_PR_short_Macro_eNB_ID: { // 18 bit - 3 bytes
enb->choice.short_Macro_eNB_ID.size = 3;
enb->choice.short_Macro_eNB_ID.bits_unused = 6;
enb->present = ENB_ID_PR_short_Macro_eNB_ID;
enb->choice.short_Macro_eNB_ID.buf = (uint8_t *) calloc(1, enb->choice.short_Macro_eNB_ID.size);
data[enb->choice.short_Macro_eNB_ID.size - 1] = (
(unsigned) (data[enb->choice.short_Macro_eNB_ID.size - 1] >>
(unsigned) enb->choice.short_Macro_eNB_ID.bits_unused)
<< (unsigned) enb->choice.short_Macro_eNB_ID.bits_unused);
memcpy(enb->choice.short_Macro_eNB_ID.buf, data, enb->choice.short_Macro_eNB_ID.size);
break;
}
case ENB_ID_PR_long_Macro_eNB_ID: { // 21
enb->choice.long_Macro_eNB_ID.size = 3;
enb->choice.long_Macro_eNB_ID.bits_unused = 3;
enb->present = ENB_ID_PR_long_Macro_eNB_ID;
enb->choice.long_Macro_eNB_ID.buf = (uint8_t *) calloc(1, enb->choice.long_Macro_eNB_ID.size);
data[enb->choice.long_Macro_eNB_ID.size - 1] =
((unsigned) (data[enb->choice.long_Macro_eNB_ID.size - 1] >> (unsigned) enb->choice.long_Macro_eNB_ID.bits_unused)
<< (unsigned) enb->choice.long_Macro_eNB_ID.bits_unused);
memcpy(enb->choice.long_Macro_eNB_ID.buf, data, enb->choice.long_Macro_eNB_ID.size);
break;
}
default:
free(enb);
return nullptr;
}
checkAndPrint(&asn_DEF_ENB_ID, enb, (char *) "ENB_ID_t", __func__);
return enb;
}
GlobalENB_ID_t *createGlobalENB_ID(PLMN_Identity_t *plmnIdentity, ENB_ID_t *enbId) {
printEntry("GlobalENB_ID_t", __func__)
auto *genbId = (GlobalENB_ID_t *) calloc(1, sizeof(GlobalENB_ID_t));
ASN_STRUCT_RESET(asn_DEF_GlobalENB_ID, genbId);
memcpy(&genbId->pLMN_Identity, plmnIdentity, sizeof(PLMN_Identity_t));
memcpy(&genbId->eNB_ID, enbId, sizeof(ENB_ID_t));
checkAndPrint(&asn_DEF_GlobalENB_ID, genbId, (char *) "GlobalENB_ID_t", __func__);
return genbId;
}
//static void buildInitiatingMessagePDU(E2AP_PDU_t &pdu, InitiatingMessage_t *initMsg) {
// pdu.present = E2AP_PDU_PR_initiatingMessage;
// pdu.choice.initiatingMessage = initMsg;
//}
template<typename T>
static void buildInitMsg(InitiatingMessage_t &initMsg,
InitiatingMessage__value_PR present,
ProcedureCode_t procedureCode,
Criticality_t criticality,
T *value) {
initMsg.value.present = present;
initMsg.procedureCode = procedureCode;
initMsg.criticality = criticality;
switch (present) {
case InitiatingMessage__value_PR_RICsubscriptionRequest: {
memcpy(&initMsg.value.choice.RICsubscriptionRequest, value, sizeof(*value));
break;
}
case InitiatingMessage__value_PR_RICsubscriptionDeleteRequest: {
memcpy(&initMsg.value.choice.RICsubscriptionDeleteRequest, value, sizeof(*value));
break;
}
case InitiatingMessage__value_PR_RICserviceUpdate: {
memcpy(&initMsg.value.choice.RICserviceUpdate, value, sizeof(*value));
break;
}
case InitiatingMessage__value_PR_RICcontrolRequest: {
memcpy(&initMsg.value.choice.RICcontrolRequest, value, sizeof(*value));
break;
}
case InitiatingMessage__value_PR_RICindication: {
memcpy(&initMsg.value.choice.RICindication, value, sizeof(*value));
break;
}
case InitiatingMessage__value_PR_RICserviceQuery: {
memcpy(&initMsg.value.choice.RICserviceQuery, value, sizeof(*value));
break;
}
case InitiatingMessage__value_PR_NOTHING:
default : {
break;
}
}
}
//static void buildSuccsesfulMessagePDU(E2AP_PDU_t &pdu, SuccessfulOutcome_t *succMsg) {
// pdu.present = E2AP_PDU_PR_successfulOutcome;
// pdu.choice.successfulOutcome = succMsg;
//}
template<typename T>
static void buildSuccMsg(SuccessfulOutcome_t &succMsg,
SuccessfulOutcome__value_PR present,
ProcedureCode_t procedureCode,
Criticality_t criticality,
T *value) {
succMsg.value.present = present;
succMsg.procedureCode = procedureCode;
succMsg.criticality = criticality;
switch (present) {
case SuccessfulOutcome__value_PR_RICsubscriptionResponse: {
memcpy(&succMsg.value.choice.RICsubscriptionResponse, value, sizeof(*value));
break;
}
case SuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse: {
memcpy(&succMsg.value.choice.RICsubscriptionDeleteResponse, value, sizeof(*value));
break;
}
case SuccessfulOutcome__value_PR_RICserviceUpdateAcknowledge: {
memcpy(&succMsg.value.choice.RICserviceUpdateAcknowledge, value, sizeof(*value));
break;
}
case SuccessfulOutcome__value_PR_RICcontrolAcknowledge: {
memcpy(&succMsg.value.choice.RICcontrolAcknowledge, value, sizeof(*value));
break;
}
case SuccessfulOutcome__value_PR_ResetResponse: {
memcpy(&succMsg.value.choice.ResetResponse, value, sizeof(*value));
break;
}
case SuccessfulOutcome__value_PR_NOTHING:
default:
break;
}
}
//static void buildUnSucssesfullMessagePDU(E2AP_PDU_t &pdu, UnsuccessfulOutcome_t *unSuccMsg) {
// pdu.present = E2AP_PDU_PR_unsuccessfulOutcome;
// pdu.choice.unsuccessfulOutcome = unSuccMsg;
//}
template<typename T>
static void buildUnSuccMsg(UnsuccessfulOutcome_t &unSuccMsg,
UnsuccessfulOutcome__value_PR present,
ProcedureCode_t procedureCode,
Criticality_t criticality,
T *value) {
unSuccMsg.value.present = present;
unSuccMsg.procedureCode = procedureCode;
unSuccMsg.criticality = criticality;
switch (present) {
case UnsuccessfulOutcome__value_PR_RICsubscriptionFailure: {
memcpy(&unSuccMsg.value.choice.RICsubscriptionFailure, value, sizeof(*value));
break;
}
case UnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure: {
memcpy(&unSuccMsg.value.choice.RICsubscriptionDeleteFailure, value, sizeof(*value));
break;
}
case UnsuccessfulOutcome__value_PR_RICserviceUpdateFailure: {
memcpy(&unSuccMsg.value.choice.RICserviceUpdateFailure, value, sizeof(*value));
break;
}
case UnsuccessfulOutcome__value_PR_RICcontrolFailure: {
memcpy(&unSuccMsg.value.choice.RICcontrolFailure, value, sizeof(*value));
break;
}
case UnsuccessfulOutcome__value_PR_NOTHING:
default:
break;
}
}
//static void createPLMN_ID(PLMN_Identity_t &plmnId, const unsigned char *data) {
// //printEntry("PLMN_Identity_t", __func__)
// //PLMN_Identity_t *plmnId = calloc(1, sizeof(PLMN_Identity_t));
// ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, &plmnId);
// plmnId.size = 3;// uint64_t st = 0;
//// uint32_t aux1 = 0;
//// st = rdtscp(aux1);
//
// plmnId.buf = (uint8_t *) calloc(1, 3);
// memcpy(plmnId.buf, data, 3);
//
// checkAndPrint(&asn_DEF_PLMN_Identity, &plmnId, (char *) "PLMN_Identity_t", __func__);
//
//}
static void createENB_ID(ENB_ID_t &enb, ENB_ID_PR enbType, unsigned char *data) {
//printEntry("ENB_ID_t", __func__)
ASN_STRUCT_RESET(asn_DEF_ENB_ID, &enb);
enb.present = enbType;
switch (enbType) {
case ENB_ID_PR_macro_eNB_ID: { // 20 bit 3 bytes
enb.choice.macro_eNB_ID.size = 3;
enb.choice.macro_eNB_ID.bits_unused = 4;
enb.present = ENB_ID_PR_macro_eNB_ID;
enb.choice.macro_eNB_ID.buf = (uint8_t *) calloc(1, enb.choice.macro_eNB_ID.size);
data[enb.choice.macro_eNB_ID.size - 1] = ((unsigned) (data[enb.choice.macro_eNB_ID.size - 1]
>> (unsigned) enb.choice.macro_eNB_ID.bits_unused)
<< (unsigned) enb.choice.macro_eNB_ID.bits_unused);
memcpy(enb.choice.macro_eNB_ID.buf, data, enb.choice.macro_eNB_ID.size);
break;
}
case ENB_ID_PR_home_eNB_ID: { // 28 bit 4 bytes
enb.choice.home_eNB_ID.size = 4;
enb.choice.home_eNB_ID.bits_unused = 4;
enb.present = ENB_ID_PR_home_eNB_ID;
enb.choice.home_eNB_ID.buf = (uint8_t *) calloc(1, enb.choice.home_eNB_ID.size);
data[enb.choice.home_eNB_ID.size - 1] = ((unsigned) (data[enb.choice.home_eNB_ID.size - 1]
>> (unsigned) enb.choice.home_eNB_ID.bits_unused)
<< (unsigned) enb.choice.home_eNB_ID.bits_unused);
memcpy(enb.choice.home_eNB_ID.buf, data, enb.choice.home_eNB_ID.size);
break;
}
case ENB_ID_PR_short_Macro_eNB_ID: { // 18 bit - 3 bytes
enb.choice.short_Macro_eNB_ID.size = 3;
enb.choice.short_Macro_eNB_ID.bits_unused = 6;
enb.present = ENB_ID_PR_short_Macro_eNB_ID;
enb.choice.short_Macro_eNB_ID.buf = (uint8_t *) calloc(1, enb.choice.short_Macro_eNB_ID.size);
data[enb.choice.short_Macro_eNB_ID.size - 1] = ((unsigned) (data[enb.choice.short_Macro_eNB_ID.size - 1]
>> (unsigned) enb.choice.short_Macro_eNB_ID.bits_unused)
<< (unsigned) enb.choice.short_Macro_eNB_ID.bits_unused);
memcpy(enb.choice.short_Macro_eNB_ID.buf, data, enb.choice.short_Macro_eNB_ID.size);
break;
}
case ENB_ID_PR_long_Macro_eNB_ID: { // 21
enb.choice.long_Macro_eNB_ID.size = 3;
enb.choice.long_Macro_eNB_ID.bits_unused = 3;
enb.present = ENB_ID_PR_long_Macro_eNB_ID;
enb.choice.long_Macro_eNB_ID.buf = (uint8_t *) calloc(1, enb.choice.long_Macro_eNB_ID.size);
data[enb.choice.long_Macro_eNB_ID.size - 1] = ((unsigned) (data[enb.choice.long_Macro_eNB_ID.size - 1]
>> (unsigned) enb.choice.long_Macro_eNB_ID.bits_unused)
<< (unsigned) enb.choice.long_Macro_eNB_ID.bits_unused);
memcpy(enb.choice.long_Macro_eNB_ID.buf, data, enb.choice.long_Macro_eNB_ID.size);
break;
}
default:
break;
}
checkAndPrint(&asn_DEF_ENB_ID, &enb, (char *) "ENB_ID_t", __func__);
}
static void buildGlobalENB_ID(GlobalENB_ID_t *gnbId,
const unsigned char *gnbData,
ENB_ID_PR enbType,
unsigned char *enbData) {
auto *plmnID = createPLMN_ID(gnbData);
memcpy(&gnbId->pLMN_Identity, plmnID, sizeof(PLMN_Identity_t));
createENB_ID(gnbId->eNB_ID, enbType, enbData);
checkAndPrint(&asn_DEF_GlobalENB_ID, gnbId, (char *) "GlobalENB_ID_t", __func__);
}
void buildSetupRequest(E2AP_PDU_t *pdu, int mcc, int mnc) {
ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
pdu->choice.initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t));
auto *initiatingMessage = pdu->choice.initiatingMessage;
ASN_STRUCT_RESET(asn_DEF_InitiatingMessage, initiatingMessage);
initiatingMessage->procedureCode = ProcedureCode_id_E2setup;
initiatingMessage->criticality = Criticality_reject;
initiatingMessage->value.present = InitiatingMessage__value_PR_E2setupRequest;
auto *e2SetupRequestIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, e2SetupRequestIEs);
e2SetupRequestIEs->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.gNB = (GlobalE2node_gNB_ID_t *)calloc(1, sizeof(GlobalE2node_gNB_ID_t));
auto *globalE2NodeGNbId = e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.gNB;
ASN_STRUCT_RESET(asn_DEF_GlobalE2node_gNB_ID, globalE2NodeGNbId);
createPLMN_IDByMCCandMNC(&globalE2NodeGNbId->global_gNB_ID.plmn_id, mcc, mnc);
globalE2NodeGNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = 4;
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf =
(uint8_t *) calloc(1, globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size); //22..32 bits
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.bits_unused = 0;
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[0] = 0xB5;
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[1] = 0xC6;
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[2] = 0x77;
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[3] = 0x88;
e2SetupRequestIEs->criticality = Criticality_reject;
e2SetupRequestIEs->id = ProtocolIE_ID_id_GlobalE2node_ID;
e2SetupRequestIEs->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
auto *e2SetupRequest = &initiatingMessage->value.choice.E2setupRequest;
ASN_STRUCT_RESET(asn_DEF_E2setupRequest, e2SetupRequest);
ASN_SEQUENCE_ADD(&e2SetupRequest->protocolIEs.list, e2SetupRequestIEs);
pdu->present = E2AP_PDU_PR_initiatingMessage;
}
void buildSetupRequesteenGNB(E2AP_PDU_t *pdu, int mcc, int mnc) {
ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
pdu->choice.initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t));
auto *initiatingMessage = pdu->choice.initiatingMessage;
ASN_STRUCT_RESET(asn_DEF_InitiatingMessage, initiatingMessage);
initiatingMessage->procedureCode = ProcedureCode_id_E2setup;
initiatingMessage->criticality = Criticality_reject;
initiatingMessage->value.present = InitiatingMessage__value_PR_E2setupRequest;
auto *e2SetupRequestIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, e2SetupRequestIEs);
e2SetupRequestIEs->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_en_gNB;
e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.en_gNB = (GlobalE2node_en_gNB_ID_t *)calloc(1, sizeof(GlobalE2node_en_gNB_ID_t));
auto *globalE2NodeEN_GNb = e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.en_gNB;
ASN_STRUCT_RESET(asn_DEF_GlobalE2node_en_gNB_ID, globalE2NodeEN_GNb);
globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.present = ENGNB_ID_PR_gNB_ID;
createPLMN_IDByMCCandMNC(&globalE2NodeEN_GNb->global_gNB_ID.pLMN_Identity, mcc, mnc);
globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.size = 4;
globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.buf =
(uint8_t *) calloc(1, globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.size); //22..32 bits
globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.buf[0] = 0xC5;
globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.buf[1] = 0xC6;
globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.buf[2] = 0xC7;
globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.buf[3] = 0xF8;
globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.bits_unused = 0;
e2SetupRequestIEs->criticality = Criticality_reject;
e2SetupRequestIEs->id = ProtocolIE_ID_id_GlobalE2node_ID;
e2SetupRequestIEs->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
auto *e2SetupRequest = &initiatingMessage->value.choice.E2setupRequest;
ASN_STRUCT_RESET(asn_DEF_E2setupRequest, e2SetupRequest);
ASN_SEQUENCE_ADD(&e2SetupRequest->protocolIEs.list, e2SetupRequestIEs);
pdu->present = E2AP_PDU_PR_initiatingMessage;
}
void buildSetupRequestWithFunc(E2AP_PDU_t *pdu, int mcc, int mnc) {
ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
pdu->choice.initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t));
auto *initiatingMessage = pdu->choice.initiatingMessage;
ASN_STRUCT_RESET(asn_DEF_InitiatingMessage, initiatingMessage);
initiatingMessage->procedureCode = ProcedureCode_id_E2setup;
initiatingMessage->criticality = Criticality_reject;
initiatingMessage->value.present = InitiatingMessage__value_PR_E2setupRequest;
auto *e2SetupRequestIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, e2SetupRequestIEs);
e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.gNB = (GlobalE2node_gNB_ID_t *)calloc(1, sizeof(GlobalE2node_gNB_ID_t));
auto *globalE2NodeGNbId = e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.gNB;
ASN_STRUCT_RESET(asn_DEF_GlobalE2node_gNB_ID, globalE2NodeGNbId);
createPLMN_IDByMCCandMNC(&globalE2NodeGNbId->global_gNB_ID.plmn_id, mcc, mnc);
globalE2NodeGNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = 4;
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf =
(uint8_t *) calloc(1, globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size); //22..32 bits
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.bits_unused = 0;
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[0] = 0xB5;
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[1] = 0xC6;
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[2] = 0x77;
globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[3] = 0x88;
e2SetupRequestIEs->criticality = Criticality_reject;
e2SetupRequestIEs->id = ProtocolIE_ID_id_GlobalE2node_ID;
e2SetupRequestIEs->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
e2SetupRequestIEs->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
auto *e2SetupRequest = &initiatingMessage->value.choice.E2setupRequest;
ASN_STRUCT_RESET(asn_DEF_E2setupRequest, e2SetupRequest);
ASN_SEQUENCE_ADD(&e2SetupRequest->protocolIEs.list, e2SetupRequestIEs);
auto *ranFlistIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, ranFlistIEs);
ranFlistIEs->criticality = Criticality_reject;
ranFlistIEs->id = ProtocolIE_ID_id_RANfunctionsAdded;
ranFlistIEs->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
auto *itemIes = (RANfunction_ItemIEs_t *)calloc(1, sizeof(RANfunction_ItemIEs_t));
ASN_STRUCT_RESET(asn_DEF_RANfunction_ItemIEs, itemIes);
E2SM_gNB_NRT_RANfunction_Definition_t ranFunDef;
uint8_t funcDes[] = "asdfghjklpoiuytrewq\0";
ranFunDef.ranFunction_Name.ranFunction_Description.buf = (uint8_t *)calloc(1, strlen((char *)funcDes));
ranFunDef.ranFunction_Name.ranFunction_Description.size = strlen((char *)funcDes);
memcpy(ranFunDef.ranFunction_Name.ranFunction_Description.buf, funcDes, strlen((char *)funcDes));
uint8_t funcOID[] = "ABCDEFGHIJ1234567890\0";
ranFunDef.ranFunction_Name.ranFunction_E2SM_OID.buf = (uint8_t *)calloc(1, strlen((char *)funcOID));
ranFunDef.ranFunction_Name.ranFunction_E2SM_OID.size = strlen((char *)funcOID);
memcpy(ranFunDef.ranFunction_Name.ranFunction_E2SM_OID.buf, funcOID, strlen((char *)funcOID));
uint8_t shortName[] = "Nothing to declare\0";
ranFunDef.ranFunction_Name.ranFunction_ShortName.buf = (uint8_t *)calloc(1, strlen((char *)shortName));
ranFunDef.ranFunction_Name.ranFunction_ShortName.size = strlen((char *)shortName);
memcpy(ranFunDef.ranFunction_Name.ranFunction_ShortName.buf, shortName, strlen((char *)shortName));
RIC_InsertStyle_List_t insertStyleList;
insertStyleList.ric_CallProcessIDFormat_Type = 28l;
insertStyleList.ric_IndicationHeaderFormat_Type = 29;
insertStyleList.ric_IndicationMessageFormat_Type = 30;
insertStyleList.ric_InsertActionFormat_Type = 31l;
uint8_t styleName[] = "What a style\0";
insertStyleList.ric_InsertStyle_Name.buf = (uint8_t *)calloc(1, strlen((char *)styleName));
insertStyleList.ric_InsertStyle_Name.size = strlen((char *)styleName);
memcpy(insertStyleList.ric_InsertStyle_Name.buf, styleName, strlen((char *)styleName));
insertStyleList.ric_InsertStyle_Type = 23;
RANparameterDef_Item_t raNparameterDefItem;
raNparameterDefItem.ranParameter_ID = 8;
raNparameterDefItem.ranParameter_Type = 12;
uint8_t ItemName[] = "What a style\0";
raNparameterDefItem.ranParameter_Name.buf = (uint8_t *)calloc(1, strlen((char *)ItemName));
raNparameterDefItem.ranParameter_Name.size = strlen((char *)ItemName);
memcpy(raNparameterDefItem.ranParameter_Name.buf, ItemName, strlen((char *)ItemName));
ASN_SEQUENCE_ADD(&insertStyleList.ric_InsertRanParameterDef_List.list, &raNparameterDefItem);
ASN_SEQUENCE_ADD(&ranFunDef.ric_InsertStyle_List->list, &insertStyleList);
//ranFunDef.ric_InsertStyle_List.
uint8_t buffer[8192];
size_t buffer_size = 8192;
auto *ranDef = &itemIes->value.choice.RANfunction_Item.ranFunctionDefinition;
auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, &ranFunDef, buffer, buffer_size);
if (er.encoded == -1) {
cerr << "encoding of " << asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.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_E2SM_gNB_NRT_RANfunction_Definition.name << endl;
exit(-1);
} else {
ranDef->buf = (uint8_t *)calloc(1, er.encoded);
ranDef->size = er.encoded;
memcpy(ranDef->buf, buffer, ranDef->size);
}
itemIes->id = ProtocolIE_ID_id_RANfunction_Item;
itemIes->criticality = Criticality_reject;
itemIes->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
itemIes->value.choice.RANfunction_Item.ranFunctionID = 1;
// auto *ranDef = &itemIes->value.choice.RANfunction_Item.ranFunctionDefinition;
// ranDef->size = 3;
// ranDef->buf = (uint8_t *)calloc(1, ranDef->size);
// memcpy(ranDef->buf, buf, ranDef->size);
ASN_SEQUENCE_ADD(&ranFlistIEs->value.choice.RANfunctions_List.list, itemIes);
auto *itemIes1 = (RANfunction_ItemIEs_t *)calloc(1, sizeof(RANfunction_ItemIEs_t));
ASN_STRUCT_RESET(asn_DEF_RANfunction_ItemIEs, itemIes1);
itemIes1->id = ProtocolIE_ID_id_RANfunction_Item;
itemIes1->criticality = Criticality_reject;
itemIes1->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
itemIes1->value.choice.RANfunction_Item.ranFunctionID = 7;
ranDef = &itemIes1->value.choice.RANfunction_Item.ranFunctionDefinition;
ranDef->buf = (uint8_t *)calloc(1, er.encoded);
ranDef->size = er.encoded;
memcpy(ranDef->buf, buffer, ranDef->size);
ASN_SEQUENCE_ADD(&ranFlistIEs->value.choice.RANfunctions_List.list, itemIes1);
ASN_SEQUENCE_ADD(&e2SetupRequest->protocolIEs.list, ranFlistIEs);
pdu->present = E2AP_PDU_PR_initiatingMessage;
}
void buildSetupSuccsessfulResponse(E2AP_PDU_t *pdu, int mcc, int mnc, uint8_t *data) {
ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
pdu->choice.successfulOutcome = (SuccessfulOutcome_t *)calloc(1, sizeof(SuccessfulOutcome_t));
SuccessfulOutcome_t *successfulOutcome = pdu->choice.successfulOutcome;
ASN_STRUCT_RESET(asn_DEF_E2setupResponse, &successfulOutcome->value.choice.E2setupResponse);
successfulOutcome->procedureCode = ProcedureCode_id_E2setup;
successfulOutcome->criticality = Criticality_reject;
successfulOutcome->value.present = SuccessfulOutcome__value_PR_E2setupResponse;
auto *globalRicidIE = (E2setupResponseIEs_t *)calloc(1, sizeof(E2setupResponseIEs_t));
ASN_STRUCT_RESET(asn_DEF_E2setupResponseIEs, globalRicidIE);
globalRicidIE->criticality = Criticality_reject;
globalRicidIE->id = ProtocolIE_ID_id_GlobalRIC_ID;
globalRicidIE->value.present = E2setupResponseIEs__value_PR_GlobalRIC_ID;
createPLMN_IDByMCCandMNC(&globalRicidIE->value.choice.GlobalRIC_ID.pLMN_Identity, mcc, mnc);
globalRicidIE->value.choice.GlobalRIC_ID.ric_ID = {nullptr, 3, 4};
globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.buf = (uint8_t *)calloc(1, globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.size);
memcpy(globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.buf, data, globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.size);
globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.buf[2] &= (unsigned)0xF0;
ASN_STRUCT_RESET(asn_DEF_E2setupResponse, &successfulOutcome->value.choice.E2setupResponse);
ASN_SEQUENCE_ADD(&successfulOutcome->value.choice.E2setupResponse.protocolIEs.list, globalRicidIE);
auto *ranFunctionAdd = (E2setupResponseIEs_t *)calloc(1, sizeof(E2setupResponseIEs_t));
ASN_STRUCT_RESET(asn_DEF_E2setupResponseIEs, ranFunctionAdd);
ranFunctionAdd->criticality = Criticality_reject;
ranFunctionAdd->id = ProtocolIE_ID_id_RANfunctionsAccepted;
ranFunctionAdd->value.present = E2setupResponseIEs__value_PR_RANfunctionsID_List;
auto *ranFuncIdItemIEs = (RANfunctionID_ItemIEs_t *)calloc(1, sizeof(RANfunctionID_ItemIEs_t));
ranFuncIdItemIEs->criticality = Criticality_ignore;
ranFuncIdItemIEs->id = ProtocolIE_ID_id_RANfunctionID_Item;
ranFuncIdItemIEs->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item;
ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionID = 10;
ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionRevision = 1;
ASN_SEQUENCE_ADD(&ranFunctionAdd->value.choice.RANfunctionsID_List.list, ranFuncIdItemIEs);
ASN_SEQUENCE_ADD(&successfulOutcome->value.choice.E2setupResponse.protocolIEs.list, ranFunctionAdd);
pdu->present = E2AP_PDU_PR_successfulOutcome;
}
void buildSetupUnSuccsessfulResponse(E2AP_PDU_t *pdu) {
ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
pdu->choice.unsuccessfulOutcome = (UnsuccessfulOutcome_t *)calloc(1, sizeof(UnsuccessfulOutcome_t));
UnsuccessfulOutcome_t *uns = pdu->choice.unsuccessfulOutcome;
uns->procedureCode = ProcedureCode_id_E2setup;
uns->criticality = Criticality_reject;
uns->value.present = UnsuccessfulOutcome__value_PR_E2setupFailure;
ASN_STRUCT_RESET(asn_DEF_E2setupFailure, &uns->value.choice.E2setupFailure);
{
auto *e2SetupFIE = (E2setupFailureIEs_t *) calloc(1, sizeof(E2setupFailureIEs_t));
ASN_STRUCT_RESET(asn_DEF_E2setupFailureIEs, e2SetupFIE);
e2SetupFIE->criticality = Criticality_ignore;
e2SetupFIE->id = ProtocolIE_ID_id_Cause;
e2SetupFIE->value.present = E2setupFailureIEs__value_PR_Cause;
e2SetupFIE->value.choice.Cause.present = Cause_PR_transport;
e2SetupFIE->value.choice.Cause.choice.transport = CauseTransport_transport_resource_unavailable;
ASN_SEQUENCE_ADD(&uns->value.choice.E2setupFailure.protocolIEs.list, e2SetupFIE);
}
{
auto *e2SetupFIE = (E2setupFailureIEs_t *) calloc(1, sizeof(E2setupFailureIEs_t));
ASN_STRUCT_RESET(asn_DEF_E2setupFailureIEs, e2SetupFIE);
e2SetupFIE->criticality = Criticality_ignore;
e2SetupFIE->id = ProtocolIE_ID_id_TimeToWait;
e2SetupFIE->value.present = E2setupFailureIEs__value_PR_TimeToWait;
e2SetupFIE->value.choice.TimeToWait = TimeToWait_v60s;
ASN_SEQUENCE_ADD(&uns->value.choice.E2setupFailure.protocolIEs.list, e2SetupFIE);
}
{
auto *e2SetupFIE = (E2setupFailureIEs_t *) calloc(1, sizeof(E2setupFailureIEs_t));
ASN_STRUCT_RESET(asn_DEF_E2setupFailureIEs, e2SetupFIE);
e2SetupFIE->criticality = Criticality_ignore;
e2SetupFIE->id = ProtocolIE_ID_id_CriticalityDiagnostics;
e2SetupFIE->value.present = E2setupFailureIEs__value_PR_CriticalityDiagnostics;
e2SetupFIE->value.choice.CriticalityDiagnostics.procedureCode = (ProcedureCode_t *)calloc(1,sizeof(ProcedureCode_t));
*e2SetupFIE->value.choice.CriticalityDiagnostics.procedureCode = ProcedureCode_id_E2setup;
e2SetupFIE->value.choice.CriticalityDiagnostics.triggeringMessage = (TriggeringMessage_t *)calloc(1,sizeof(TriggeringMessage_t));
*e2SetupFIE->value.choice.CriticalityDiagnostics.triggeringMessage = TriggeringMessage_initiating_message;
e2SetupFIE->value.choice.CriticalityDiagnostics.procedureCriticality = (Criticality_t *)calloc(1, sizeof(Criticality_t));
*e2SetupFIE->value.choice.CriticalityDiagnostics.procedureCriticality = Criticality_reject;
ASN_SEQUENCE_ADD(&uns->value.choice.E2setupFailure.protocolIEs.list, e2SetupFIE);
}
pdu->present = E2AP_PDU_PR_unsuccessfulOutcome;
}
#endif //E2_E2BUILDER_H

View File

@@ -0,0 +1,112 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
//
// Created by adi ENZEL on 12/10/19.
//
#include "E2Builder.h"
#include "asn1cFiles/ProtocolIE-Field.h"
template<typename T>
X2SetupRequest_IEs_t *buildX2SetupIE(ProtocolIE_ID_t id,
Criticality_t criticality,
X2SetupRequest_IEs__value_PR present,
T *value) {
auto *x2SetupIE = (X2SetupRequest_IEs_t *)calloc(1, sizeof(X2SetupRequest_IEs_t));
x2SetupIE->id = id;
x2SetupIE->criticality = criticality;
x2SetupIE->value.present = present;
switch (present) {
case X2SetupRequest_IEs__value_PR_GlobalENB_ID: {
memcpy(&x2SetupIE->value.choice.GlobalENB_ID, value, sizeof(GlobalENB_ID_t));
break;
}
case X2SetupRequest_IEs__value_PR_ServedCells: {
memcpy(&x2SetupIE->value.choice.ServedCells, value, sizeof(ServedCells_t));
break;
}
case X2SetupRequest_IEs__value_PR_GUGroupIDList: {
memcpy(&x2SetupIE->value.choice.GUGroupIDList, value, sizeof(GUGroupIDList_t));
break;
}
case X2SetupRequest_IEs__value_PR_LHN_ID: {
memcpy(&x2SetupIE->value.choice.LHN_ID, value, sizeof(LHN_ID_t));
break;
}
case X2SetupRequest_IEs__value_PR_NOTHING:
default:
free(x2SetupIE);
x2SetupIE = nullptr;
break;
}
return x2SetupIE;
}
/**
*
* @param x2Setup
* @param member
*/
void buildE2SetupRequest(X2SetupRequest_t *x2Setup, vector<X2SetupRequest_IEs_t> &member) {
for (auto v : member) {
ASN_SEQUENCE_ADD(&x2Setup->protocolIEs.list, &v);
}
}
void init_log() {
mdclog_attr_t *attr;
mdclog_attr_init(&attr);
mdclog_attr_set_ident(attr, "setup Request");
mdclog_init(attr);
mdclog_attr_destroy(attr);
}
int main(const int argc, char **argv) {
init_log();
//mdclog_level_set(MDCLOG_WARN);
//mdclog_level_set(MDCLOG_INFO);
mdclog_level_set(MDCLOG_DEBUG);
// x2Setup X2AP-ELEMENTARY-PROCEDURE ::= {
// INITIATING MESSAGE X2SetupRequest
// SUCCESSFUL OUTCOME X2SetupResponse
// UNSUCCESSFUL OUTCOME X2SetupFailure
// PROCEDURE CODE id-x2Setup
// CRITICALITY reject
// }
//
//
// X2SetupRequest ::= SEQUENCE {
// protocolIEs ProtocolIE-Container {{X2SetupRequest-IEs}},
// ...
// }
//
// X2SetupRequest-IEs X2AP-PROTOCOL-IES ::= {
// { ID id-GlobalENB-ID CRITICALITY reject TYPE GlobalENB-ID PRESENCE mandatory}|
// { ID id-ServedCells CRITICALITY reject TYPE ServedCells PRESENCE mandatory}|
// { ID id-GUGroupIDList CRITICALITY reject TYPE GUGroupIDList PRESENCE optional}|
// { ID id-LHN-ID CRITICALITY ignore TYPE LHN-ID PRESENCE optional},
// ...
// }
}

View File

@@ -0,0 +1,320 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi on 6/11/19.
//
#include <mdclog/mdclog.h>
#include "asn1cFiles/E2AP-PDU.h"
#include "asn1cFiles/InitiatingMessage.h"
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <unistd.h>
#include <pthread.h>
#include <rmr/rmr.h>
#include <rmr/RIC_message_types.h>
#include "logInit.h"
// test X2SetUP request and response
using namespace std;
#define MAXEVENTS 64
int main(const int argc, char **argv) {
mdclog_severity_t loglevel = MDCLOG_INFO;
auto buff = new string("SETUP TEST");
init_log((char *)buff->c_str());
mdclog_level_set(loglevel);
if (argc < 9){
mdclog_mdc_add("app", argv[0]);
mdclog_write(MDCLOG_ERR, "Usage host <host address> port <sctpPort> ran <ran name> rmr <rmr address> [logLevel <debug/warning/info/error]");
return -1 ;
}
char host[256] {0};
char port [10] {0};
char ranName[256] {0};
char rmrAddress[256] {0};
char str1[128];
for (int i = 1; i < argc; i += 2) {
for (int j = 0; j < strlen(argv[i]); j++) {
str1[j] = (char)tolower(argv[i][j]);
}
str1[strlen(argv[i])] = 0;
if (strcmp("host", str1) == 0) {
strcpy(host, argv[i + 1]);
} else if (strcmp("port", str1) == 0) {
strcpy(port, argv[i + 1]);
} else if (strcmp("ran", str1) == 0) {
strcpy(ranName, argv[i + 1]);
} else if (strcmp("rmr", str1) == 0) {
strcpy(ranName, argv[i + 1]);
}else if (strcmp("loglevel", str1) == 0) {
if (strcmp("debug", argv[i + 1]) == 0) {
loglevel = MDCLOG_DEBUG;
} else if (strcmp("info", argv[i + 1]) == 0) {
loglevel = MDCLOG_INFO;
} else if (strcmp("warning", argv[i + 1]) == 0) {
loglevel = MDCLOG_WARN;
} else if (strcmp("error", argv[i + 1]) == 0) {
loglevel = MDCLOG_ERR;
}
}
}
void *rmrCtx = rmr_init(rmrAddress, RMR_MAX_RCV_BYTES, RMRFL_NONE);
if (rmrCtx == nullptr ) {
mdclog_write(MDCLOG_ERR, "RMR failed to initialise : %s", strerror(errno));
return(-1);
}
// get the RMR fd for the epoll
auto rmrListenFd = rmr_get_rcvfd(rmrCtx);
auto epoll_fd = epoll_create1(0);
if (epoll_fd == -1) {
mdclog_write(MDCLOG_ERR,"failed to open epoll descriptor");
rmr_close(rmrCtx);
return -2;
}
struct epoll_event event {};
event.events = EPOLLIN;
event.data.fd = rmrListenFd;
// add listening sctpPort to epoll
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, rmrListenFd, &event)) {
mdclog_write(MDCLOG_ERR, "Failed to add RMR descriptor to epoll");
close(rmrListenFd);
rmr_close(rmrCtx);
return -3;
}
// we need to find that routing table exist and we can run
if (mdclog_level_get() >= MDCLOG_INFO) {
mdclog_write(MDCLOG_INFO, "We are after RMR INIT wait for RMR_Ready");
}
int rmrReady = 0;
int count = 0;
while (!rmrReady) {
if ((rmrReady = rmr_ready(rmrCtx)) == 0) {
sleep(1);
}
count++;
if (count % 60 == 0) {
mdclog_write(MDCLOG_INFO, "waiting to RMR ready state for %d seconds", count);
}
if (count > 180) {
mdclog_write(MDCLOG_ERR, "RMR not ready tried for 3 minutes ");
return(-2);
}
}
if (mdclog_level_get() >= MDCLOG_INFO) {
mdclog_write(MDCLOG_INFO, "RMR running");
}
E2AP_PDU_t pdu {};
auto &initiatingMsg = pdu.select_initiatingMessage();
initiatingMsg.ref_procedureCode().select_id_x2Setup();
initiatingMsg.ref_criticality().select_id_x2Setup();
auto &x2setup = initiatingMsg.ref_value().select_id_x2Setup();
auto &ies = x2setup.ref_protocolIEs();
X2SetupRequest::protocolIEs_t::value_type val {};
val.ref_id().select_id_GlobalENB_ID();
val.ref_criticality().select_id_GlobalENB_ID();
uint8_t v1[] = {0x02, 0xf8, 0x29};
val.ref_value().select_id_GlobalENB_ID().ref_pLMN_Identity().set(3, v1);
uint32_t eNBId = 5;
val.ref_value().select_id_GlobalENB_ID().ref_eNB_ID().select_macro_eNB_ID().set_buffer(20,reinterpret_cast<uint8_t*>(&eNBId));
ies.push_back(val);
X2SetupRequest::protocolIEs_t::value_type sc {};
ies.push_back(sc);
sc.ref_id().select_id_ServedCells();
sc.ref_criticality().select_id_ServedCells();
ServedCells::value_type sce;
sc.ref_value().select_id_ServedCells().push_back(sce);
sce.ref_servedCellInfo().ref_pCI().set(0x1F7);
uint8_t v3[] = {0x1, 0x2};
sce.ref_servedCellInfo().ref_tAC().set(2,v3);
sce.ref_servedCellInfo().ref_cellId().ref_pLMN_Identity().set(3, v1);
uint8_t v4[] = {0x00, 0x07, 0xab, ((unsigned)0x50) >> (unsigned)4};
sce.ref_servedCellInfo().ref_cellId().ref_eUTRANcellIdentifier().set_buffer(28, v4);
BroadcastPLMNs_Item::value_type bpe;
sce.ref_servedCellInfo().ref_broadcastPLMNs().push_back(bpe);
bpe.set(3, v1);
sce.ref_servedCellInfo().ref_eUTRA_Mode_Info().select_fDD().ref_uL_EARFCN().set(0x1);
sce.ref_servedCellInfo().ref_eUTRA_Mode_Info().select_fDD().ref_dL_EARFCN().set(0x1);
sce.ref_servedCellInfo().ref_eUTRA_Mode_Info().select_fDD().ref_uL_Transmission_Bandwidth().set(Transmission_Bandwidth::bw50);
sce.ref_servedCellInfo().ref_eUTRA_Mode_Info().select_fDD().ref_dL_Transmission_Bandwidth().set(Transmission_Bandwidth::bw50);
unsigned char s_buffer[4096];
asn::per::EncoderCtx ctx{s_buffer, sizeof(s_buffer)};
std::cout << asn::get_printed(pdu) << std::endl;
if (!asn::per::pack(pdu, ctx)) {
std::cout << ctx.refErrorCtx().toString() << std::endl;
return -3;
}
size_t packed_buf_size;
packed_buf_size = static_cast<size_t>(ctx.refBuffer().getBytesUsed());
// build message
char data[4096] {};
//auto delimiter = (const char) '|';
sprintf(data, "%s|%s|%s|%d|%s/0", host, port, ranName, (int)packed_buf_size, ctx.refBuffer().getBytes(packed_buf_size));
rmr_mbuf_t *msg = rmr_alloc_msg(rmrCtx, int(strlen(data)));
rmr_bytes2meid(msg, (unsigned char const*)ranName, strlen(ranName));
rmr_bytes2payload(msg, (unsigned char const*)data, strlen(data));
rmr_bytes2xact(msg, (unsigned char const*)ranName, strlen(ranName));
msg->mtype = RIC_X2_SETUP_REQ;
msg->state = 0;
msg = rmr_send_msg(rmrCtx, msg);
if (msg->state != 0) {
mdclog_write(MDCLOG_ERR, "Message state %d while sending RIC_X2_SETUP to %s", msg->state, ranName);
rmr_free_msg(msg);
rmr_close(rmrCtx);
return -4;
}
rmr_free_msg(msg);
unsigned char allocBuffer[64*1024] {0};
auto *events = (struct epoll_event *)calloc(MAXEVENTS, sizeof(event));
while (true) {
auto numOfEvents = epoll_wait(epoll_fd, events, MAXEVENTS, -1);
if (numOfEvents < 0) {
mdclog_write(MDCLOG_ERR, "Epoll wait failed, errno = %s", strerror(errno));
rmr_close(rmrCtx);
return -4;
}
for (auto i = 0; i < numOfEvents; i++) {
if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) {
mdclog_write(MDCLOG_ERR, "epoll error");
} else if (rmrListenFd == events[i].data.fd) {
msg = rmr_alloc_msg(rmrCtx, 4096);
if (msg == nullptr) {
mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno));
rmr_close(rmrCtx);
return -5;
}
msg = rmr_rcv_msg(rmrCtx, msg);
if (msg == nullptr) {
mdclog_write(MDCLOG_ERR, "RMR Receving message, %s", strerror(errno));
rmr_close(rmrCtx);
return -6;
}
memset(allocBuffer, 0, 64*1024);
switch (msg->mtype) {
case RIC_X2_SETUP_RESP: {
mdclog_write(MDCLOG_INFO, "successful, RMR receiveing RIC_X2_SETUP_RESP");
asn::per::DecoderCtx dCtx{msg->payload, (size_t) msg->len, allocBuffer, sizeof(allocBuffer)};
E2AP_PDU opdu;
if (!asn::per::unpack(opdu, dCtx)) {
mdclog_write(MDCLOG_ERR, "Failed to unpack ASN message, %s", dCtx.refErrorCtx().toString());
rmr_free_msg(msg);
rmr_close(rmrCtx);
return -7;
}
break;
}
case RIC_X2_SETUP_FAILURE: {
mdclog_write(MDCLOG_INFO, "successful, RMR receiveing RIC_X2_SETUP_FAILURE");
asn::per::DecoderCtx dCtx{msg->payload, (size_t) msg->len, allocBuffer, sizeof(allocBuffer)};
E2AP_PDU opdu;
if (!asn::per::unpack(opdu, dCtx)) {
mdclog_write(MDCLOG_ERR, "Failed to unpack ASN message, %s", dCtx.refErrorCtx().toString());
rmr_free_msg(msg);
rmr_close(rmrCtx);
return -7;
}
break;
}
default: {
mdclog_write(MDCLOG_INFO, "RMR receiveing message type %d", msg->mtype);
asn::per::DecoderCtx dCtx{msg->payload, (size_t) msg->len, allocBuffer, sizeof(allocBuffer)};
E2AP_PDU opdu;
if (!asn::per::unpack(opdu, dCtx)) {
mdclog_write(MDCLOG_ERR, "Failed to unpack ASN message, %s", dCtx.refErrorCtx().toString());
rmr_close(rmrCtx);
return -7;
}
switch (opdu.get_index()) {
case 1: { //initiating message
mdclog_write(MDCLOG_INFO, "ASN initiating message type %ld",
opdu.get_initiatingMessage()->ref_procedureCode().ref_value().get());
break;
}
case 2: { //successful message
mdclog_write(MDCLOG_INFO, "ASN initiating message type %ld",
opdu.get_successfulOutcome()->ref_procedureCode().ref_value().get());
break;
}
case 3: { //unsuccessesful message
mdclog_write(MDCLOG_INFO, "ASN initiating message type %ld",
opdu.get_unsuccessfulOutcome()->ref_procedureCode().ref_value().get());
break;
}
}
mdclog_write(MDCLOG_INFO, "RMR receiveing message from E2 terminator, %d",
msg->mtype);
break;
}
}
}
}
}
}

View File

@@ -0,0 +1,7 @@
newrt|start
rte|10061|10.0.2.15:38012
rte|10062|10.0.2.15:38012
rte|1080|10.0.2.15:38012
rte|12011|10.0.2.15:38012
rte|12012|10.0.2.15:38012
newrt|end

View File

@@ -0,0 +1,100 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
//
// Created by adi ENZEL on 11/27/19.
//
#include "base64.h"
#include <mdclog/mdclog.h>
#include <cgreen/cgreen.h>
#include <cstdio>
#include <cerrno>
#include <cstdlib>
#include <cstring>
using namespace std;
Describe(base64);
BeforeEach(base64) {}
AfterEach(base64) {}
using namespace cgreen;
void init_log() {
mdclog_attr_t *attr;
mdclog_attr_init(&attr);
mdclog_attr_set_ident(attr, "TestConfiguration");
mdclog_init(attr);
mdclog_attr_destroy(attr);
}
const char *data = "ABC123Test Lets Try this' input and see What \"happens\"";
Ensure(base64, encDec) {
string str = "ABC123Test Lets Try this' input and see What \"happens\"";
auto *buf = (unsigned char *)malloc(str.length() * 2);
auto length = (long)(str.length() * 2);
base64::encode((unsigned char *)str.c_str(), str.length(), buf, length);
auto *backBackBuff = (unsigned char *)malloc(length);
auto length2 = length;
assert_that(base64::decode(buf, length, backBackBuff, length2) == 0);
std::string str1( backBackBuff, backBackBuff + sizeof backBackBuff / sizeof backBackBuff[0]);
assert_that(str.compare((const char *)backBackBuff) == 0)
free(backBackBuff);
free(buf);
}
Ensure(base64, errorsHandling) {
string str = "ABC123Test Lets Try this' input and see What \"happens\"";
auto *buf = (unsigned char *)malloc(str.length() * 2);
auto length = (long)(str.length());
assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), buf, length) == -1);
length = (long)(str.length() * 2);
assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), buf, length) == 0);
auto *backBackBuff = (unsigned char *)malloc(length);
auto length2 = length >> 2;
assert_that(base64::decode(buf, length, backBackBuff, length2) == -1);
//std::string str1( backBackBuff, backBackBuff + sizeof backBackBuff / sizeof backBackBuff[0]);
auto length1 = 0l;
assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), nullptr , length) == -1);
// assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), nullptr , length) == -1);
assert_that(base64::encode(nullptr, str.length(), backBackBuff , length) == -1);
assert_that(base64::encode((unsigned char *)str.c_str(), length1, backBackBuff , length) == -1);
assert_that(base64::encode(nullptr, str.length(), backBackBuff , length1) == -1);
length1 = -1;
assert_that(base64::encode((unsigned char *)str.c_str(), length1, backBackBuff , length) == -1);
assert_that(base64::encode(nullptr, str.length(), backBackBuff , length1) == -1);
}
int main(const int argc, char **argv) {
mdclog_severity_t loglevel = MDCLOG_INFO;
init_log();
mdclog_level_set(loglevel);
//TestSuite *suite = create_test_suite();
TestSuite *suite = create_named_test_suite_(__FUNCTION__, __FILE__, __LINE__);
add_test_with_context(suite, base64, encDec);
add_test_with_context(suite, base64, errorsHandling);
return cgreen::run_test_suite(suite, create_text_reporter());
}

View File

@@ -0,0 +1,833 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 6/19/19.
//
#include "e2sm.h"
#define printEntry(type, function) \
if (mdclog_level_get() >= MDCLOG_DEBUG) { \
mdclog_write(MDCLOG_DEBUG, "start Test %s , %s", type, function); \
}
static void checkAndPrint(asn_TYPE_descriptor_t *typeDescriptor, void *data, char *dataType, const char *function) {
char errbuf[128]; /* Buffer for error message */
size_t errlen = sizeof(errbuf); /* Size of the buffer */
if (asn_check_constraints(typeDescriptor, data, errbuf, &errlen) != 0) {
mdclog_write(MDCLOG_ERR, "%s Constraint validation failed: %s", dataType, errbuf);
} else if (mdclog_level_get() >= MDCLOG_DEBUG) {
mdclog_write(MDCLOG_DEBUG, "%s successes function %s", dataType, function);
}
}
static size_t encodebuff(int codingType,
asn_TYPE_descriptor_t *typeDescriptor,
void *objectData,
uint8_t *buffer,
size_t buffer_size) {
asn_enc_rval_t er;
struct timespec start = {0,0};
struct timespec end = {0,0};
clock_gettime(CLOCK_MONOTONIC, &start);
er = asn_encode_to_buffer(0, codingType, typeDescriptor, objectData, buffer, buffer_size);
clock_gettime(CLOCK_MONOTONIC, &end);
if (er.encoded == -1) {
mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2SM_gNB_X2_eventTriggerDefinition.name, strerror(errno));
} else if (er.encoded > (ssize_t)buffer_size) {
mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s", (int) buffer_size,
typeDescriptor->name);
} else if (mdclog_level_get() >= MDCLOG_DEBUG) {
if (codingType == ATS_BASIC_XER) {
mdclog_write(MDCLOG_DEBUG, "Buffer of size %d, data = %s", (int) er.encoded, buffer);
}
else {
if (mdclog_level_get() >= MDCLOG_INFO) {
char *printBuffer;
size_t size;
FILE *stream = open_memstream(&printBuffer, &size);
asn_fprint(stream, typeDescriptor, objectData);
mdclog_write(MDCLOG_DEBUG, "Encoding E2SM PDU past : %s", printBuffer);
}
mdclog_write(MDCLOG_DEBUG, "Buffer of size %d", (int) er.encoded);
}
}
mdclog_write(MDCLOG_INFO, "Encoding type %d, time is %ld seconds, %ld nanoseconds", codingType, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
//mdclog_write(MDCLOG_INFO, "Encoding time is %3.9f seconds", ((double)end.tv_sec + 1.0e-9 * end.tv_nsec) - ((double)start.tv_sec + 1.0e-9 * start.tv_nsec));
return er.encoded;
}
PLMN_Identity_t *createPLMN_ID(const unsigned char *data) {
printEntry("PLMN_Identity_t", __func__)
PLMN_Identity_t *plmnId = calloc(1, sizeof(PLMN_Identity_t));
ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, plmnId);
plmnId->size = 3;
plmnId->buf = calloc(1, 3);
memcpy(plmnId->buf, data, 3);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_PLMN_Identity, plmnId, "PLMN_Identity_t", __func__);
}
return plmnId;
}
ENB_ID_t *createENB_ID(ENB_ID_PR enbType, unsigned char *data) {
printEntry("ENB_ID_t", __func__)
ENB_ID_t *enb = calloc(1, sizeof(ENB_ID_t));
ASN_STRUCT_RESET(asn_DEF_ENB_ID, enb);
enb->present = enbType;
switch (enbType) {
case ENB_ID_PR_macro_eNB_ID: { // 20 bit 3 bytes
enb->choice.macro_eNB_ID.size = 3;
enb->choice.macro_eNB_ID.bits_unused = 4;
enb->present = ENB_ID_PR_macro_eNB_ID;
enb->choice.macro_eNB_ID.buf = calloc(1, enb->choice.macro_eNB_ID.size);
data[enb->choice.macro_eNB_ID.size - 1] = ((unsigned)(data[enb->choice.macro_eNB_ID.size - 1] >>
(unsigned)enb->choice.macro_eNB_ID.bits_unused) << (unsigned)enb->choice.macro_eNB_ID.bits_unused);
memcpy(enb->choice.macro_eNB_ID.buf, data, enb->choice.macro_eNB_ID.size);
break;
}
case ENB_ID_PR_home_eNB_ID: { // 28 bit 4 bytes
enb->choice.home_eNB_ID.size = 4;
enb->choice.home_eNB_ID.bits_unused = 4;
enb->present = ENB_ID_PR_home_eNB_ID;
enb->choice.home_eNB_ID.buf = calloc(1, enb->choice.home_eNB_ID.size);
data[enb->choice.home_eNB_ID.size - 1] = ((unsigned)(data[enb->choice.home_eNB_ID.size - 1] >>
(unsigned)enb->choice.home_eNB_ID.bits_unused) << (unsigned)enb->choice.home_eNB_ID.bits_unused);
memcpy(enb->choice.home_eNB_ID.buf, data, enb->choice.home_eNB_ID.size);
break;
}
case ENB_ID_PR_short_Macro_eNB_ID: { // 18 bit - 3 bytes
enb->choice.short_Macro_eNB_ID.size = 3;
enb->choice.short_Macro_eNB_ID.bits_unused = 6;
enb->present = ENB_ID_PR_short_Macro_eNB_ID;
enb->choice.short_Macro_eNB_ID.buf = calloc(1, enb->choice.short_Macro_eNB_ID.size);
data[enb->choice.short_Macro_eNB_ID.size - 1] = ((unsigned)(data[enb->choice.short_Macro_eNB_ID.size - 1] >>
(unsigned)enb->choice.short_Macro_eNB_ID.bits_unused) << (unsigned)enb->choice.short_Macro_eNB_ID.bits_unused);
memcpy(enb->choice.short_Macro_eNB_ID.buf, data, enb->choice.short_Macro_eNB_ID.size);
break;
}
case ENB_ID_PR_long_Macro_eNB_ID: { // 21
enb->choice.long_Macro_eNB_ID.size = 3;
enb->choice.long_Macro_eNB_ID.bits_unused = 3;
enb->present = ENB_ID_PR_long_Macro_eNB_ID;
enb->choice.long_Macro_eNB_ID.buf = calloc(1, enb->choice.long_Macro_eNB_ID.size);
data[enb->choice.long_Macro_eNB_ID.size - 1] = ((unsigned)(data[enb->choice.long_Macro_eNB_ID.size - 1] >>
(unsigned)enb->choice.long_Macro_eNB_ID.bits_unused) << (unsigned)enb->choice.long_Macro_eNB_ID.bits_unused);
memcpy(enb->choice.long_Macro_eNB_ID.buf, data, enb->choice.long_Macro_eNB_ID.size);
break;
}
default:
free(enb);
return NULL;
}
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ENB_ID, enb, "ENB_ID_t", __func__);
}
return enb;
}
GNB_ID_t *createGnb_id(const unsigned char *data, int numOfBits) {
printEntry("GNB_ID_t", __func__)
if (numOfBits < 22 || numOfBits > 32) {
mdclog_write(MDCLOG_ERR, "GNB_ID_t number of bits = %d, needs to be 22 .. 32", numOfBits);
return NULL;
}
GNB_ID_t *gnb = calloc(1, sizeof(GNB_ID_t));
ASN_STRUCT_RESET(asn_DEF_GNB_ID, gnb);
gnb->present = GNB_ID_PR_gNB_ID;
gnb->choice.gNB_ID.size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
gnb->choice.gNB_ID.bits_unused = (int)gnb->choice.gNB_ID.size * 8 - numOfBits;
gnb->choice.gNB_ID.buf = calloc(1, gnb->choice.gNB_ID.size);
memcpy(gnb->choice.gNB_ID.buf, data, gnb->choice.gNB_ID.size);
gnb->choice.gNB_ID.buf[gnb->choice.gNB_ID.size - 1] =
((unsigned)(gnb->choice.gNB_ID.buf[gnb->choice.gNB_ID.size - 1] >> (unsigned)gnb->choice.gNB_ID.bits_unused)
<< (unsigned)gnb->choice.gNB_ID.bits_unused);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_GNB_ID, gnb, "GNB_ID_t", __func__);
}
return gnb;
}
GlobalENB_ID_t *createGlobalENB_ID(PLMN_Identity_t *plmnIdentity, ENB_ID_t *enbId) {
printEntry("GlobalENB_ID_t", __func__)
GlobalENB_ID_t *genbId = calloc(1, sizeof(GlobalENB_ID_t));
ASN_STRUCT_RESET(asn_DEF_GlobalENB_ID, genbId);
memcpy(&genbId->pLMN_Identity, plmnIdentity, sizeof(PLMN_Identity_t));
memcpy(&genbId->eNB_ID, enbId, sizeof(ENB_ID_t));
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_GlobalENB_ID, genbId, "GlobalENB_ID_t", __func__);
}
return genbId;
}
GlobalGNB_ID_t *createGlobalGNB_ID(PLMN_Identity_t *plmnIdentity, GNB_ID_t *gnb) {
printEntry("GlobalGNB_ID_t", __func__)
GlobalGNB_ID_t *ggnbId = calloc(1, sizeof(GlobalGNB_ID_t));
ASN_STRUCT_RESET(asn_DEF_GlobalGNB_ID, ggnbId);
memcpy(&ggnbId->pLMN_Identity, plmnIdentity, sizeof(PLMN_Identity_t));
memcpy(&ggnbId->gNB_ID, gnb, sizeof(GNB_ID_t));
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_GlobalGNB_ID, ggnbId, "GlobalGNB_ID_t", __func__);
}
return ggnbId;
}
Interface_ID_t *createInterfaceIDForGnb(GlobalGNB_ID_t *gnb) {
printEntry("Interface_ID_t", __func__)
Interface_ID_t *interfaceId = calloc(1, sizeof(Interface_ID_t));
ASN_STRUCT_RESET(asn_DEF_Interface_ID, interfaceId);
interfaceId->present = Interface_ID_PR_global_gNB_ID;
//memcpy(&interfaceId->choice.global_gNB_ID, gnb, sizeof(GlobalGNB_ID_t));
interfaceId->choice.global_gNB_ID = gnb;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_Interface_ID, interfaceId, "Interface_ID_t", __func__);
}
return interfaceId;
}
Interface_ID_t *createInterfaceIDForEnb(GlobalENB_ID_t *enb) {
printEntry("Interface_ID_t", __func__)
Interface_ID_t *interfaceId = calloc(1, sizeof(Interface_ID_t));
ASN_STRUCT_RESET(asn_DEF_Interface_ID, interfaceId);
interfaceId->present = Interface_ID_PR_global_eNB_ID;
//memcpy(&interfaceId->choice.global_eNB_ID, enb, sizeof(GlobalENB_ID_t));
interfaceId->choice.global_eNB_ID = enb;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_Interface_ID, interfaceId, "Interface_ID_t", __func__);
}
return interfaceId;
}
InterfaceMessageType_t *createInterfaceMessageInitiating(long procedureCode) {
printEntry("InterfaceMessageType_t", __func__)
InterfaceMessageType_t *intMsgT = calloc(1, sizeof(InterfaceMessageType_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceMessageType, intMsgT);
intMsgT->procedureCode = procedureCode;
intMsgT->typeOfMessage = TypeOfMessage_initiating_message;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceMessageType, intMsgT, "InterfaceMessageType_t", __func__);
}
return intMsgT;
}
InterfaceMessageType_t *createInterfaceMessageSuccsesful(long procedureCode) {
printEntry("InterfaceMessageType_t", __func__)
InterfaceMessageType_t *intMsgT = calloc(1, sizeof(InterfaceMessageType_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceMessageType, intMsgT);
intMsgT->procedureCode = procedureCode;
intMsgT->typeOfMessage = TypeOfMessage_successful_outcome;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceMessageType, intMsgT, "InterfaceMessageType_t", __func__);
}
return intMsgT;
}
InterfaceMessageType_t *createInterfaceMessageUnsuccessful(long procedureCode) {
printEntry("InterfaceMessageType_t", __func__)
InterfaceMessageType_t *intMsgT = calloc(1, sizeof(InterfaceMessageType_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceMessageType, intMsgT);
intMsgT->procedureCode = procedureCode;
intMsgT->typeOfMessage = TypeOfMessage_unsuccessful_outcome;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceMessageType, intMsgT, "InterfaceMessageType_t", __func__);
}
return intMsgT;
}
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueInt(long number) {
printEntry("InterfaceProtocolIE_Value_t", __func__)
InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
value->present = InterfaceProtocolIE_Value_PR_valueInt;
value->choice.valueInt = number;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
}
return value;
}
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueEnum(long number) {
printEntry("InterfaceProtocolIE_Value_t", __func__)
InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
value->present = InterfaceProtocolIE_Value_PR_valueEnum;
value->choice.valueEnum = number;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
}
return value;
}
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueBool(int val) {
printEntry("InterfaceProtocolIE_Value_t", __func__)
InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
value->present = InterfaceProtocolIE_Value_PR_valueBool;
value->choice.valueBool = val == 0 ? 0 : 1;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
}
return value;
}
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueBitString(unsigned char *buf, int numOfBits) {
printEntry("InterfaceProtocolIE_Value_t", __func__)
size_t size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
if (strlen((const char *)buf) < size) {
mdclog_write(MDCLOG_ERR, "size of buffer is small : %d needs to be %d in %s", (int)strlen((const char *)buf), (int)size, __func__);
}
InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
value->present = InterfaceProtocolIE_Value_PR_valueBitS;
value->choice.valueBitS.size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
value->choice.valueBitS.buf = calloc(1, value->choice.valueBitS.size);
int bits_unused = (int)value->choice.valueBitS.size * 8 - numOfBits;
value->choice.valueBitS.bits_unused = bits_unused;
memcpy(value->choice.valueBitS.buf, buf, value->choice.valueBitS.size);
value->choice.valueBitS.buf[size -1] = ((unsigned)(buf[size - 1]) >> (unsigned)bits_unused << (unsigned)bits_unused);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
}
return value;
}
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueOCTETS(uint8_t *buf) {
printEntry("InterfaceProtocolIE_Value_t", __func__)
size_t size = strlen((const char *)buf);
InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
value->present = InterfaceProtocolIE_Value_PR_valueOctS;
value->choice.valueOctS.size = size;
value->choice.valueOctS.buf = calloc(1, value->choice.valueOctS.size);
memcpy(value->choice.valueOctS.buf, buf, value->choice.valueOctS.size);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
}
return value;
}
InterfaceProtocolIE_Item_t *createInterfaceProtocolIE_Item(long id, long test, InterfaceProtocolIE_Value_t *value) {
printEntry("InterfaceProtocolIE_Item_t", __func__)
if (test < InterfaceProtocolIE_Test_equal || test > InterfaceProtocolIE_Test_present) {
mdclog_write(MDCLOG_ERR, "InterfaceProtocolIE_Item_t test value is %ld, out of scope %d .. %d ",
test, InterfaceProtocolIE_Test_equal, InterfaceProtocolIE_Test_present);
return NULL;
}
InterfaceProtocolIE_Item_t *intProtIt = calloc(1, sizeof(InterfaceProtocolIE_Item_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Item, intProtIt);
intProtIt->interfaceProtocolIE_ID = id;
intProtIt->interfaceProtocolIE_Test = test;
memcpy(&intProtIt->interfaceProtocolIE_Value, value, sizeof(InterfaceProtocolIE_Value_t));
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceProtocolIE_Item, intProtIt, "InterfaceProtocolIE_Item_t", __func__);
}
return intProtIt;
}
ActionParameter_Value_t *createActionParameterValue_Int(long number) {
printEntry("ActionParameter_Value_t", __func__)
ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
value->present = ActionParameter_Value_PR_valueInt;
value->choice.valueInt = number;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
}
return value;
}
ActionParameter_Value_t *createActionParameterValue_Enum(long number) {
printEntry("ActionParameter_Value_t", __func__)
ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
value->present = ActionParameter_Value_PR_valueEnum;
value->choice.valueEnum = number;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
}
return value;
}
ActionParameter_Value_t *createActionParameterValue_Bool(int val) {
printEntry("ActionParameter_Value_t", __func__)
ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
value->present = ActionParameter_Value_PR_valueBool;
value->choice.valueBool = val == 0 ? 0 : 1;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
}
return value;
}
ActionParameter_Value_t *createActionParameterValue_Bit_String(unsigned char *buf, int numOfBits) {
printEntry("ActionParameter_Value_t", __func__)
size_t size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
if (strlen((const char *)buf) < size) {
mdclog_write(MDCLOG_ERR, "size of buffer is small : %d needs to be %d in %s", (int)strlen((const char *)buf), (int)size, __func__);
}
int bits_unused = (int)size * 8 - numOfBits;
ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
value->present = ActionParameter_Value_PR_valueBitS;
value->choice.valueBitS.size = size;
value->choice.valueBitS.buf = calloc(1, size);
value->choice.valueBitS.bits_unused = bits_unused;
memcpy(value->choice.valueBitS.buf, buf, size);
value->choice.valueBitS.buf[size -1] = ((unsigned)(buf[size - 1]) >> (unsigned)bits_unused << (unsigned)bits_unused);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
}
return value;
}
ActionParameter_Value_t *createActionParameterValue_OCTETS(uint8_t *buf) {
printEntry("ActionParameter_Value_t", __func__)
size_t size = strlen((const char *)buf);
ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
value->present = ActionParameter_Value_PR_valueOctS;
value->choice.valueOctS.size = size;
value->choice.valueOctS.buf = calloc(1, value->choice.valueOctS.size);
memcpy(value->choice.valueOctS.buf, buf, value->choice.valueOctS.size);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
}
return value;
}
/**
*
* @param buf buffer that must be null terminated
* @return ActionParameter_Value_t *
*/
ActionParameter_Value_t *createActionParameterValue_PRINTS(char *buf) {
printEntry("ActionParameter_Value_t", __func__)
size_t size = strlen((const char *)buf);
ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
value->present = ActionParameter_Value_PR_valuePrtS;
value->choice.valuePrtS.size = size;
value->choice.valuePrtS.buf = calloc(1, value->choice.valuePrtS.size);
memcpy(value->choice.valuePrtS.buf, buf, value->choice.valuePrtS.size);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
}
return value;
}
ActionParameter_Item_t *creatActionParameter_Item(long id, ActionParameter_Value_t *val) {
printEntry("ActionParameter_Item_t", __func__)
if (id < 0 || id > 255) {
mdclog_write(MDCLOG_ERR, "ActionParameter_Item_t id = %ld, values are 0 .. 255", id);
return NULL;
}
ActionParameter_Item_t *actionParameterItem = calloc(1, sizeof(ActionParameter_Item_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Item, actionParameterItem);
actionParameterItem->actionParameter_ID = id;
memcpy(&actionParameterItem->actionParameter_Value, val, sizeof(ActionParameter_Value_t));
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Item, actionParameterItem, "ActionParameter_Item_t", __func__);
}
return actionParameterItem;
}
/**
*
* @param interfaceId
* @param direction
* @param messageType
* @param interfaceProtocolItemList
* @param listSize
* @param buffer
* @param buffer_size
* @return
*/
size_t createEventTrigger(Interface_ID_t *interfaceId, long direction,
InterfaceMessageType_t *messageType,
InterfaceProtocolIE_Item_t interfaceProtocolItemList[],
int listSize,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_eventTriggerDefinition_t", __func__)
if (direction < InterfaceDirection_incoming || direction > InterfaceDirection_outgoing) {
mdclog_write(MDCLOG_ERR, "E2SM_gNB_X2_eventTriggerDefinition_t direction = %ld, values are %d .. %d",
direction, InterfaceDirection_incoming, InterfaceDirection_outgoing);
return -1;
}
E2SM_gNB_X2_eventTriggerDefinition_t *eventTrigger = calloc(1, sizeof(E2SM_gNB_X2_eventTriggerDefinition_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, eventTrigger);
memcpy(&eventTrigger->interface_ID , interfaceId, sizeof(Interface_ID_t));
eventTrigger->interfaceDirection = direction;
memcpy(&eventTrigger->interfaceMessageType, messageType, sizeof(InterfaceMessageType_t));
for (int i = 0; i < listSize; i++) {
ASN_SEQUENCE_ADD(eventTrigger->interfaceProtocolIE_List, &interfaceProtocolItemList[i]);
}
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, eventTrigger, "E2SM_gNB_X2_eventTriggerDefinition_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition,
eventTrigger,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition,
eventTrigger,
buf1,
4096);
}
return len;
}
size_t createActionDefinition(long styleId, ActionParameter_Item_t actionParamList[], int listSize,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_actionDefinition_t", __func__)
E2SM_gNB_X2_actionDefinition_t *actDef = calloc(1, sizeof(E2SM_gNB_X2_actionDefinition_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_actionDefinition, actDef);
actDef->style_ID = styleId;
for (int i = 0; i < listSize; i++) {
ASN_SEQUENCE_ADD(actDef->actionParameter_List, &actionParamList[i]);
}
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_actionDefinition, actDef, "E2SM_gNB_X2_actionDefinition_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_actionDefinition,
actDef,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_actionDefinition,
actDef,
buf1,
4096);
}
return len;
}
size_t createE2SM_gNB_X2_indicationHeader(long direction,
Interface_ID_t *interfaceId,
uint8_t *timestamp, //can put NULL if size == 0
int size,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_indicationHeader_t", __func__)
if (direction < InterfaceDirection_incoming || direction > InterfaceDirection_outgoing) {
mdclog_write(MDCLOG_ERR, "E2SM_gNB_X2_indicationHeader_t direction = %ld, values are %d .. %d",
direction, InterfaceDirection_incoming, InterfaceDirection_outgoing);
return -1;
}
E2SM_gNB_X2_indicationHeader_t *indiHead = calloc(1, sizeof(E2SM_gNB_X2_indicationHeader_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_indicationHeader, indiHead);
indiHead->interfaceDirection = direction;
memcpy(&indiHead->interface_ID, interfaceId, sizeof(Interface_ID_t));
if (size > 0) {
indiHead->timestamp->size = size;
indiHead->timestamp->buf = calloc(1, sizeof(uint8_t) * size);
memcpy(indiHead->timestamp->buf, timestamp, size);
}
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_indicationHeader, indiHead, "E2SM_gNB_X2_indicationHeader_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_indicationHeader,
indiHead,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_indicationHeader,
indiHead,
buf1,
4096);
}
return len;
}
size_t createE2SM_gNB_X2_indicationMessage(uint8_t *message, uint msgSize,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_indicationMessage_t", __func__)
if (msgSize <= 0) {
mdclog_write(MDCLOG_ERR, "E2SM_gNB_X2_indicationMessage_t failed messsage size = %d", msgSize);
return -1;
}
E2SM_gNB_X2_indicationMessage_t *indicationMessage = calloc(1, sizeof(E2SM_gNB_X2_indicationMessage_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_indicationMessage, indicationMessage);
indicationMessage->interfaceMessage.size = msgSize;
indicationMessage->interfaceMessage.buf = calloc(1, sizeof(uint8_t) * msgSize);
memcpy(indicationMessage->interfaceMessage.buf, message, msgSize);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_indicationMessage, indicationMessage, "E2SM_gNB_X2_indicationMessage_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_indicationMessage,
indicationMessage,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_indicationMessage,
indicationMessage,
buf1,
4096);
}
return len;
}
size_t createE2SM_gNB_X2_callProcessID(long callProcess_Id,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_callProcessID_t", __func__)
E2SM_gNB_X2_callProcessID_t *callProcessId = calloc(1, sizeof(E2SM_gNB_X2_callProcessID_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_callProcessID, callProcessId);
callProcessId->callProcess_ID = callProcess_Id;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_callProcessID, callProcessId, "E2SM_gNB_X2_indicationMessage_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_callProcessID,
callProcessId,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_callProcessID,
callProcessId,
buf1,
4096);
}
return len;
}
size_t createE2SM_gNB_X2_controlHeader(Interface_ID_t *interfaceId, long direction,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_controlHeader_t", __func__)
if (direction < InterfaceDirection_incoming || direction > InterfaceDirection_outgoing) {
mdclog_write(MDCLOG_ERR, "E2SM_gNB_X2_controlHeader_t direction = %ld, values are %d .. %d",
direction, InterfaceDirection_incoming, InterfaceDirection_outgoing);
return -1;
}
E2SM_gNB_X2_controlHeader_t *controlHeader = calloc(1, sizeof(E2SM_gNB_X2_controlHeader_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_controlHeader, controlHeader);
memcpy(&controlHeader->interface_ID, interfaceId, sizeof(Interface_ID_t));
controlHeader->interfaceDirection = direction;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_controlHeader, controlHeader, "E2SM_gNB_X2_controlHeader_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_controlHeader,
controlHeader,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_controlHeader,
controlHeader,
buf1,
4096);
}
return len;
}
size_t createE2SM_gNB_X2_controlMessage(uint8_t *message, uint msgSize,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_controlMessage_t", __func__)
E2SM_gNB_X2_controlMessage_t *controlMsg = calloc(1, sizeof(E2SM_gNB_X2_controlMessage_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_controlMessage, controlMsg);
controlMsg->interfaceMessage.size = msgSize;
controlMsg->interfaceMessage.buf = calloc(1, sizeof(uint8_t) * msgSize);
memcpy(controlMsg->interfaceMessage.buf, message, msgSize);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_controlMessage, controlMsg, "E2SM_gNB_X2_controlMessage_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_controlMessage,
controlMsg,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_controlMessage,
controlMsg,
buf1,
4096);
}
return len;
}

View File

@@ -0,0 +1,322 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 6/19/19.
//
#ifndef ASN_DISABLE_OER_SUPPORT
#define ASN_DISABLE_OER_SUPPORT // this is to remove the OER do not remove it
#endif
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef E2_E2SM_H
#define E2_E2SM_H
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <error.h>
#include <errno.h>
#include <mdclog/mdclog.h>
#include <time.h>
#include <math.h>
#include "asn1cFiles/ENB-ID.h"
#include "asn1cFiles/E2SM-gNB-X2-actionDefinition.h"
#include "asn1cFiles/E2SM-gNB-X2-callProcessID.h"
#include "asn1cFiles/E2SM-gNB-X2-controlHeader.h"
#include "asn1cFiles/E2SM-gNB-X2-controlMessage.h"
#include "asn1cFiles/E2SM-gNB-X2-indicationHeader.h"
#include "asn1cFiles/E2SM-gNB-X2-indicationMessage.h"
#include "asn1cFiles/E2SM-gNB-X2-eventTriggerDefinition.h"
#include "asn1cFiles/ActionParameter-Item.h"
#include "asn1cFiles/ActionParameter-Value.h"
#include "asn1cFiles/PLMN-Identity.h"
#include "asn1cFiles/GlobalENB-ID.h"
#include "asn1cFiles/GlobalGNB-ID.h"
#include "asn1cFiles/Interface-ID.h"
#include "asn1cFiles/InterfaceMessageType.h"
#include "asn1cFiles/InterfaceProtocolIE-Item.h"
/**
*
* @param data
* @return
*/
PLMN_Identity_t *createPLMN_ID(const unsigned char *data);
/**
*
* @param enbType
* @param data
* @return
*/
ENB_ID_t *createENB_ID(ENB_ID_PR enbType, unsigned char *data);
/**
*
* @param data
* @param numOfBits
* @return
*/
GNB_ID_t *createGnb_id(const unsigned char *data, int numOfBits);
/**
*
* @param plmnIdentity
* @param enbId
* @return
*/
GlobalENB_ID_t *createGlobalENB_ID(PLMN_Identity_t *plmnIdentity, ENB_ID_t *enbId);
/**
*
* @param plmnIdent#ifdef __cplusplus
}
#endif
ity
* @param gnb
* @return
*/
GlobalGNB_ID_t *createGlobalGNB_ID(PLMN_Identity_t *plmnIdentity, GNB_ID_t *gnb);
/**
*
* @param gnb
* @return
*/
Interface_ID_t *createInterfaceIDForGnb(GlobalGNB_ID_t *gnb);
/**
*
* @param enb
* @return
*/
Interface_ID_t *createInterfaceIDForEnb(GlobalENB_ID_t *enb);
/**
*
* @param procedureCode
* @return
*/
InterfaceMessageType_t *createInterfaceMessageInitiating(ProcedureCode_t procedureCode);
/**
*
* @param procedureCode
* @return
*/
InterfaceMessageType_t *createInterfaceMessageSuccsesful(ProcedureCode_t procedureCode);
/**
*
* @param procedureCode
* @return
*/
InterfaceMessageType_t *createInterfaceMessageUnsuccessful(ProcedureCode_t procedureCode);
/**
*
* @param number
* @return
*/
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueInt(long number);
/**
*
* @param number
* @return
*/
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueEnum(long number);
/**
*
* @param val
* @return
*/
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueBool(int val);
/**
*
* @param buf
* @param numOfBits
* @return
*/
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueBitString(unsigned char *buf, int numOfBits);
/**
*
* @param buf
* @param size
* @return
*/
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueOCTETS(uint8_t *buf);
/**
*
* @param id
* @param test
* @param value
* @return
*/
InterfaceProtocolIE_Item_t *createInterfaceProtocolIE_Item(long id, long test, InterfaceProtocolIE_Value_t *value);
/**
*
* @param number
* @return
*/
ActionParameter_Value_t *createActionParameterValue_Int(long number);
/**
*
* @param number
* @return
*/
ActionParameter_Value_t *createActionParameterValue_Enum(long number);
/**
*
* @param val
* @return
*/
ActionParameter_Value_t *createActionParameterValue_Bool(int val);
/**
*
* @param buf
* @param numOfBits
* @return
*/
ActionParameter_Value_t *createActionParameterValue_Bit_String(unsigned char *buf, int numOfBits);
/**
*
* @param buf
* @param size
* @return
*/
ActionParameter_Value_t *createActionParameterValue_OCTETS(uint8_t *buf);
/**
*
* @param buf
* @param size
* @return
*/
ActionParameter_Value_t *createActionParameterValue_PRINTS(char *buf);
/**
*
* @param id
* @param val
* @return
*/
ActionParameter_Item_t *creatActionParameter_Item(long id, ActionParameter_Value_t *val);
/**
*
* @param interfaceId
* @param direction
* @param messageType
* @param interfaceProtocolItemList
* @param listSize
* @param buffer
* @param buffer_size
* @return
*/
size_t createEventTrigger(Interface_ID_t *interfaceId, long direction,
InterfaceMessageType_t *messageType,
InterfaceProtocolIE_Item_t interfaceProtocolItemList[],
int listSize,
uint8_t *buffer,
size_t buffer_size);
/**
*
* @param styleId
* @param actionParamList
* @param listSize
* @param buffer
* @param buffer_size
* @return
*/
size_t createActionDefinition(long styleId, ActionParameter_Item_t actionParamList[], int listSize,
uint8_t *buffer,
size_t buffer_size);
/**
*
* @param interfaceDirection
* @param interfaceId
* @param timestamp
* @param size
* @param buffer
* @param buffer_size
* @return
*/
size_t createE2SM_gNB_X2_indicationHeader(long interfaceDirection,
Interface_ID_t *interfaceId,
uint8_t *timestamp, //can put NULL if size == 0
int size,
uint8_t *buffer,
size_t buffer_size);
/**
*
* @param message
* @param msgSize
* @param buffer
* @param buffer_size
* @return
*/
size_t createE2SM_gNB_X2_indicationMessage(uint8_t *message, uint msgSize,
uint8_t *buffer,
size_t buffer_size);
/**
*
* @param callProcess_Id
* @param buffer
* @param buffer_size
* @return
*/
size_t createE2SM_gNB_X2_callProcessID(long callProcess_Id,
uint8_t *buffer,
size_t buffer_size);
size_t createE2SM_gNB_X2_controlHeader(Interface_ID_t *interfaceId, long direction,
uint8_t *buffer,
size_t buffer_size);
size_t createE2SM_gNB_X2_controlMessage(uint8_t *message, uint msgSize,
uint8_t *buffer,
size_t buffer_size);
#endif //E2_E2SM_H
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,163 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 6/19/19.
//
#include "../e2sm.h"
#include <mdclog/mdclog.h>
void init_log()
{
mdclog_attr_t *attr;
mdclog_attr_init(&attr);
mdclog_attr_set_ident(attr, "e2smTests");
mdclog_init(attr);
mdclog_attr_destroy(attr);
}
int main(const int argc, char **argv) {
init_log();
//mdclog_level_set(MDCLOG_WARN);
//mdclog_level_set(MDCLOG_INFO);
mdclog_level_set(MDCLOG_DEBUG);
unsigned char plmnidData[3] = {0x33, 0xF4, 0x55};
//mdclog_write(MDCLOG_INFO, "Test PLMN_Identity_t");
PLMN_Identity_t *plmnid = createPLMN_ID(plmnidData);
unsigned char enbData[3] = {0x66, 0x77, 0x88};
ENB_ID_t *enb = createENB_ID(ENB_ID_PR_macro_eNB_ID, enbData);
enbData[2] = 0x89;
ENB_ID_t *enb1 = createENB_ID(ENB_ID_PR_home_eNB_ID, enbData);
enbData[2] = 0x89;
ENB_ID_t *enb2 = createENB_ID(ENB_ID_PR_long_Macro_eNB_ID, enbData);
enbData[2] = 0x89;
ENB_ID_t *enb3 = createENB_ID(ENB_ID_PR_short_Macro_eNB_ID, enbData);
unsigned char gnbData[3] = {0x99, 0xaa, 0xbb};
GNB_ID_t *gnb = createGnb_id(gnbData, 26);
GlobalENB_ID_t *globalEnb = createGlobalENB_ID(plmnid, enb2);
GlobalGNB_ID_t *globaGnb = createGlobalGNB_ID(plmnid, gnb);
Interface_ID_t *gnbInterfaceId = createInterfaceIDForGnb(globaGnb);
Interface_ID_t *enbInterfaceId = createInterfaceIDForEnb(globalEnb);
InterfaceMessageType_t *initiatingInterface = createInterfaceMessageInitiating(28);
InterfaceMessageType_t *succsesfulInterface = createInterfaceMessageSuccsesful(29);
InterfaceMessageType_t *unSuccsesfulInterface = createInterfaceMessageUnsuccessful(29);
InterfaceProtocolIE_Value_t *intVal = createInterfaceProtocolValueInt(88);
InterfaceProtocolIE_Value_t *enumVal = createInterfaceProtocolValueEnum(2);
InterfaceProtocolIE_Value_t *boolVal = createInterfaceProtocolValueBool(0);
InterfaceProtocolIE_Value_t *bitStringVal = createInterfaceProtocolValueBitString((unsigned char *)"abcd0987", 60);
uint8_t octe[6] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
InterfaceProtocolIE_Value_t *octetsVal = createInterfaceProtocolValueOCTETS(octe);
InterfaceProtocolIE_Item_t *item1 = createInterfaceProtocolIE_Item(10, 0, intVal);
InterfaceProtocolIE_Item_t *item2 = createInterfaceProtocolIE_Item(10, 1, enumVal);
InterfaceProtocolIE_Item_t *item3 = createInterfaceProtocolIE_Item(10, 0, boolVal);
InterfaceProtocolIE_Item_t *item4 = createInterfaceProtocolIE_Item(10, 3, bitStringVal);
InterfaceProtocolIE_Item_t *item5 = createInterfaceProtocolIE_Item(10, 4, octetsVal);
ActionParameter_Item_t *actItem1 = creatActionParameter_Item(17, createActionParameterValue_Int(9));
ActionParameter_Value_t *actP_enum = createActionParameterValue_Enum(5);
ActionParameter_Item_t *actItem2 = creatActionParameter_Item(18, actP_enum);
ActionParameter_Value_t *actP_bool = createActionParameterValue_Bool(0);
ActionParameter_Item_t *actItem3 = creatActionParameter_Item(18, actP_bool);
//ActionParameter_Value_t *actP_bitString = createActionParameterValue_Bit_String((unsigned char *)"ABCDEF", 42);
ActionParameter_Item_t *actItem4 = creatActionParameter_Item(17, createActionParameterValue_Bit_String((unsigned char *)"ABCDEF", 42));
uint8_t octe1[7] = {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27};
ActionParameter_Value_t *actP_octates = createActionParameterValue_OCTETS(octe1);
ActionParameter_Item_t *actItem5 = creatActionParameter_Item(18, actP_octates);
char print[10] = {'a', 'b', 'C', 'D', 'e', 'f', 'g', 'H', 'I', '\0'};
ActionParameter_Value_t *actP_printable = createActionParameterValue_PRINTS(print);
ActionParameter_Item_t *actItem6 = creatActionParameter_Item(18, actP_printable);
InterfaceProtocolIE_Item_t *interfaceProtocolItemList[] = {item1, item2, item3, item4, item5};
uint8_t buffer[4096];
size_t len;
if ((len = createEventTrigger(gnbInterfaceId,
0,
initiatingInterface,
*interfaceProtocolItemList,
5,
buffer,
4096)) <= 0) {
mdclog_write(MDCLOG_ERR, "returned error from createEventTrigger");
}
ActionParameter_Item_t *actionParamList[] = {actItem1, actItem2, actItem3, actItem4, actItem5, actItem6};
len = createActionDefinition(10034, *actionParamList, 6, buffer, 4096);
len = createE2SM_gNB_X2_indicationHeader(1, enbInterfaceId, nullptr, 0, buffer, 4096);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
mdclog_write(MDCLOG_DEBUG, "Check bad direction in header indication");
len = createE2SM_gNB_X2_indicationHeader(2, enbInterfaceId, nullptr, 0, buffer, 4096);
if (len == (size_t)-1) {
mdclog_write(MDCLOG_DEBUG, "successes call function returned NULL please ignore ERROR log");
}
}
uint8_t msg[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x0};
int x = 1;
for (int i = 0; i < x; i++) {
len = createE2SM_gNB_X2_indicationMessage(msg, strlen((char *)msg), buffer, 4096);
}
for (int i = 0; i < x; i++) {
len = createE2SM_gNB_X2_callProcessID(8, buffer, 4096);
}
for (int i = 0; i < x; i++) {
len = createE2SM_gNB_X2_controlHeader(enbInterfaceId, 1, buffer, 4096);
}
for (int i = 0; i < x; i++) {
len = createE2SM_gNB_X2_controlHeader(gnbInterfaceId, 1, buffer, 4096);
}
for (int i = 0; i < x; i++) {
len = createE2SM_gNB_X2_controlMessage(msg, strlen((char *)msg), buffer, 4096);
}
return 0;
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 12/19/19.
//
#include "e2test.h"
int main(const int argc, char **argv) {
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 12/19/19.
//
#ifndef E2_E2TEST_H
#define E2_E2TEST_H
#include <algorithm>
//#include <pistache/net.h>
//#include <pistache/http.h>
//#include <pistache/peer.h>
//#include <pistache/http_headers.h>
//#include <pistache/cookie.h>
//#include <pistache/endpoint.h>
//#include <pistache/common.h>
//#include <pistache/router.h>
//
//
//using namespace Pistache;
class e2test {
// Rest::Router router;
};
#endif //E2_E2TEST_H

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 6/11/19.
//
#ifndef __LOG_INIT__
#define __LOG_INIT__
#include <mdclog/mdclog.h>
#ifdef __cplusplus
extern "C"
{
#endif
void init_log(char *name) {
mdclog_attr_t *attr;
mdclog_attr_init(&attr);
mdclog_attr_set_ident(attr, name);
mdclog_init(attr);
mdclog_attr_destroy(attr);
}
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
//
// Created by adi ENZEL on 11/26/19.
//
#include "LogTest.h"
string LogTest::getLine() {
std::string line;
if (std::getline(file, line)) {
return line;
}
return "";
}
void LogTest::getJsonDoc(string json) {
if (json.length() != 0) {
document.Parse(json.c_str());
}
}
string LogTest::getBase64(Document &document) {
if (document.HasMember("asnBase64")) {
return document["asnBase64"].GetString();
}
return "";
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
//
// Created by adi ENZEL on 11/26/19.
//
#ifndef E2_LOGTEST_H
#define E2_LOGTEST_H
#include <algorithm>
#include <cstdio>
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <random>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/sctp.h>
#include <thread>
#include <atomic>
#include <sys/param.h>
#include <sys/file.h>
#include <ctime>
#include <netdb.h>
#include <sys/epoll.h>
#include <mutex>
#include <shared_mutex>
#include <iterator>
#include <map>
#include <fstream>
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
using namespace std;
using namespace rapidjson;
class LogTest {
public:
LogTest() = default;
int openFile(string const& configFile) {
file.open(configFile.c_str());
if (!file) {
return -1;
}
return 0;
}
string getLine();
void getJsonDoc(string json);
string getBase64(Document &document);
private:
std::ifstream file;
Document document;
};
#endif //E2_LOGTEST_H

View File

@@ -0,0 +1,112 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
//
// Created by adi ENZEL on 11/19/19.
//
#include "ReadConfigFile.h"
#include <mdclog/mdclog.h>
#include <cgreen/cgreen.h>
Describe(Cgreen);
BeforeEach(Cgreen) {}
AfterEach(Cgreen) {}
using namespace cgreen;
void init_log() {
mdclog_attr_t *attr;
mdclog_attr_init(&attr);
mdclog_attr_set_ident(attr, "TestConfiguration");
mdclog_init(attr);
mdclog_attr_destroy(attr);
}
Ensure(Cgreen, fileNotExist) {
ReadConfigFile conf {};
assert_that( conf.openConfigFile("kuku") == -1);
}
Ensure(Cgreen, fileExists) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.conf") == 0);
}
Ensure(Cgreen, goodparams) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.conf") == 0);
assert_that(conf.getIntValue("nano") == 38000);
assert_that(conf.getStringValue("loglevel") == "info");
assert_that(conf.getStringValue("volume") == "log");
}
Ensure(Cgreen, badParams) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.conf") == 0);
assert_that(conf.getIntValue("nano") != 38002);
assert_that(conf.getStringValue("loglevel") != "");
assert_that(conf.getStringValue("volume") != "bob");
assert_that(conf.getStringValue("volum") != "bob");
}
Ensure(Cgreen, wrongType) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.conf") == 0);
assert_that(conf.getStringValue("nano") != "debug");
assert_that(conf.getIntValue("loglevel") != 3);
assert_that(conf.getDoubleValue("loglevel") != 3.0);
}
Ensure(Cgreen, badValues) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.bad") == 0);
}
Ensure(Cgreen, sectionTest) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.sec") == 0);
assert_that(conf.getIntValue("config.nano") == 38000);
}
Ensure(Cgreen, sectionBadTest) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config/config.secbad") == -1);
//assert_that(conf.getIntValue("config.nano") == 38000);
}
int main(const int argc, char **argv) {
mdclog_severity_t loglevel = MDCLOG_INFO;
init_log();
mdclog_level_set(loglevel);
//TestSuite *suite = create_test_suite();
TestSuite *suite = create_named_test_suite_(__FUNCTION__, __FILE__, __LINE__);
add_test_with_context(suite, Cgreen, fileNotExist);
add_test_with_context(suite, Cgreen, fileExists);
add_test_with_context(suite, Cgreen, goodparams);
add_test_with_context(suite, Cgreen, badParams);
add_test_with_context(suite, Cgreen, wrongType);
add_test_with_context(suite, Cgreen, badValues);
add_test_with_context(suite, Cgreen, sectionTest);
add_test_with_context(suite, Cgreen, sectionBadTest);
return cgreen::run_test_suite(suite, create_text_reporter());
}

View File

@@ -0,0 +1,352 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 6/17/19.
//
#include <mdclog/mdclog.h>
#include "asn/type_defs.h"
#include "asn/per/codec.hpp"
#include "asn/printer.hpp"
#include "X2AP-CommonDataTypes.hpp"
#include "X2AP-Containers.hpp"
#include "X2AP-Constants.hpp"
#include "X2AP-IEs.hpp"
#include "X2AP-PDU-Contents.hpp"
#include "E2AP-Constants.hpp"
#include "E2AP-IEs.hpp"
#include "E2AP-PDU-Contents.hpp"
#include "E2AP-PDU-Descriptions.hpp"
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <pthread.h>
#include <rmr/rmr.h>
#include <rmr/RIC_message_types.h>
#include "logInit.h"
// test X2SetUP request and response
using namespace std;
#define MAXEVENTS 64
int main(const int argc, char **argv) {
mdclog_severity_t loglevel = MDCLOG_INFO;
auto buff = new string("Subscription TEST");
init_log((char *)buff->c_str());
mdclog_level_set(loglevel);
if (argc < 5){
mdclog_mdc_add("app", argv[0]);
mdclog_write(MDCLOG_ERR, "Usage ran <ran name> rmr <rmr address> [logLevel <debug/warning/info/error]");
return -1 ;
}
char ranName[256] {0};
char rmrAddress[256] {0};
char str1[128];
for (int i = 1; i < argc; i += 2) {
for (int j = 0; j < strlen(argv[i]); j++) {
str1[j] = (char)tolower(argv[i][j]);
}
str1[strlen(argv[i])] = 0;
if (strcmp("ran", str1) == 0) {
strcpy(ranName, argv[i + 1]);
} else if (strcmp("rmr", str1) == 0) {
strcpy(rmrAddress, argv[i + 1]);
} else if (strcmp("loglevel", str1) == 0) {
if (strcmp("debug", argv[i + 1]) == 0) {
loglevel = MDCLOG_DEBUG;
} else if (strcmp("info", argv[i + 1]) == 0) {
loglevel = MDCLOG_INFO;
} else if (strcmp("warning", argv[i + 1]) == 0) {
loglevel = MDCLOG_WARN;
} else if (strcmp("error", argv[i + 1]) == 0) {
loglevel = MDCLOG_ERR;
}
}
}
void *rmrCtx = rmr_init(rmrAddress, RMR_MAX_RCV_BYTES, RMRFL_NONE);
if (rmrCtx == nullptr ) {
mdclog_write(MDCLOG_ERR, "RMR failed to initialise : %s", strerror(errno));
return(-1);
}
// get the RMR fd for the epoll
auto rmrListenFd = rmr_get_rcvfd(rmrCtx);
auto epoll_fd = epoll_create1(0);
if (epoll_fd == -1) {
mdclog_write(MDCLOG_ERR,"failed to open epoll descriptor");
rmr_close(rmrCtx);
return -2;
}
struct epoll_event event {};
event.events = EPOLLIN;
event.data.fd = rmrListenFd;
// add listening sctpPort to epoll
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, rmrListenFd, &event)) {
mdclog_write(MDCLOG_ERR, "Failed to add RMR descriptor to epoll");
close(rmrListenFd);
rmr_close(rmrCtx);
return -3;
}
// we need to find that routing table exist and we can run
if (mdclog_level_get() >= MDCLOG_INFO) {
mdclog_write(MDCLOG_INFO, "We are after RMR INIT wait for RMR_Ready");
}
int rmrReady = 0;
int count = 0;
while (!rmrReady) {
if ((rmrReady = rmr_ready(rmrCtx)) == 0) {
sleep(1);
}
count++;
if (count % 60 == 0) {
mdclog_write(MDCLOG_INFO, "waiting to RMR ready state for %d seconds", count);
}
if (count > 180) {
mdclog_write(MDCLOG_ERR, "RMR not ready tried for 3 minutes ");
return(-2);
}
}
if (mdclog_level_get() >= MDCLOG_INFO) {
mdclog_write(MDCLOG_INFO, "RMR running");
}
E2AP_PDU cuAckPdu {};
auto &succ = cuAckPdu.select_successfulOutcome();
succ.ref_procedureCode().select_id_endcConfigurationUpdate();
succ.ref_criticality().select_id_endcConfigurationUpdate();
auto &endcConfAck = succ.ref_value().select_id_endcConfigurationUpdate();
auto &confAckIes = endcConfAck.ref_protocolIEs();
ENDCConfigurationUpdateAcknowledge::protocolIEs_t::value_type endcENB {};
endcENB.ref_id().select_id_RespondingNodeType_EndcConfigUpdate();
endcENB.ref_criticality().select_id_RespondingNodeType_EndcConfigUpdate();
auto &respondingNode = endcENB.ref_value().select_id_RespondingNodeType_EndcConfigUpdate();
auto &enb = respondingNode.select_respond_eNB();
confAckIes.push_back(endcENB);
E2AP_PDU pdu {};
auto &initiatingMsg = pdu.select_initiatingMessage();
initiatingMsg.ref_procedureCode().select_id_ricSubscription();
initiatingMsg.ref_criticality().select_id_ricSubscription();
auto &subscription = initiatingMsg.ref_value().select_id_ricSubscription();
auto &ies = subscription.ref_protocolIEs();
RICsubscriptionRequest::protocolIEs_t::value_type ranFuncId {};
ranFuncId.ref_id().select_id_RANfunctionID();
ranFuncId.ref_criticality().select_id_RANfunctionID();
ranFuncId.ref_value().select_id_RANfunctionID().set(28);
ies.push_back(ranFuncId);
RICsubscriptionRequest::protocolIEs_t::value_type ricRequestId {};
ricRequestId.ref_id().select_id_RICrequestID();
ricRequestId.ref_criticality().select_id_RICrequestID();
ricRequestId.ref_value().select_id_RICrequestID().ref_ricRequestorID().set(44);
ricRequestId.ref_value().select_id_RICrequestID().ref_ricRequestSequenceNumber().set(55);
ies.push_back(ricRequestId);
RICsubscriptionRequest::protocolIEs_t::value_type ricSubId {};
ricSubId.ref_id().select_id_RICsubscription();
ricSubId.ref_criticality().select_id_RICsubscription();
//E2SM_gNB_X2_eventTriggerDefinition_t evt;
uint8_t v1[] = {0x02, 0xf8, 0x29, 0x88};
RICeventTriggerDefinition eventTriggerDef {}; // octet string in E2AP but struct in E2SM
eventTriggerDef.set(4, v1);
// eventTriggerDef.
//
//
// RICaction_Admitted_List::value_type actbl {};
// actbl.ref_id().select_id_RICaction_Admitted_Item();
// actbl.ref_criticality().select_id_RICaction_Admitted_Item();
// RICaction_ToBeSetup_Item actb1{};
//
// actbl.ref_value().select_id_RICaction_Admitted_Item().ref_ricActionID().set(actb1);
// ricSubId.ref_value().select_id_RICsubscription().ref_ricAction_ToBeSetup_List().set(actbl);
ies.push_back(ricSubId);
/*
ies.push_back(ranFuncId);
X2SetupRequest::protocolIEs_t::value_type sc {};
ies.push_back(sc);
sc.ref_id().select_id_ServedCells();
sc.ref_criticality().select_id_ServedCells();
ServedCells::value_type sce;
sc.ref_value().select_id_ServedCells().push_back(sce);
sce.ref_servedCellInfo().ref_pCI().set(0x1F7);
uint8_t v3[] = {0x1, 0x2};
sce.ref_servedCellInfo().ref_tAC().set(2,v3);
sce.ref_servedCellInfo().ref_cellId().ref_pLMN_Identity().set(3, v1);
uint8_t v4[] = {0x00, 0x07, 0xab, ((unsigned)0x50) >> (unsigned)4};
sce.ref_servedCellInfo().ref_cellId().ref_eUTRANcellIdentifier().set_buffer(28, v4);
BroadcastPLMNs_Item::value_type bpe;
sce.ref_servedCellInfo().ref_broadcastPLMNs().push_back(bpe);
bpe.set(3, v1);
sce.ref_servedCellInfo().ref_eUTRA_Mode_Info().select_fDD().ref_uL_EARFCN().set(0x1);
sce.ref_servedCellInfo().ref_eUTRA_Mode_Info().select_fDD().ref_dL_EARFCN().set(0x1);
sce.ref_servedCellInfo().ref_eUTRA_Mode_Info().select_fDD().ref_uL_Transmission_Bandwidth().set(Transmission_Bandwidth::bw50);
sce.ref_servedCellInfo().ref_eUTRA_Mode_Info().select_fDD().ref_dL_Transmission_Bandwidth().set(Transmission_Bandwidth::bw50);
*/
unsigned char s_buffer[64 * 1024];
asn::per::EncoderCtx ctx{s_buffer, sizeof(s_buffer)};
std::cout << asn::get_printed(pdu) << std::endl;
if (!asn::per::pack(pdu, ctx)) {
std::cout << ctx.refErrorCtx().toString() << std::endl;
return -3;
}
size_t packed_buf_size;
packed_buf_size = static_cast<size_t>(ctx.refBuffer().getBytesUsed());
// build message
char data[4096] {};
//auto delimiter = (const char) '|';
sprintf(data, "%s/0", ctx.refBuffer().getBytes(packed_buf_size));
rmr_mbuf_t *msg = rmr_alloc_msg(rmrCtx, int(strlen(data)));
rmr_bytes2meid(msg, (unsigned char const*)ranName, strlen(ranName));
rmr_bytes2payload(msg, (unsigned char const*)data, strlen(data));
rmr_bytes2xact(msg, (unsigned char const*)ranName, strlen(ranName));
msg->mtype = RIC_SUB_REQ;
msg->state = 0;
msg = rmr_send_msg(rmrCtx, msg);
if (msg->state != 0) {
mdclog_write(MDCLOG_ERR, "Message state %d while sending RIC_X2_SETUP to %s", msg->state, ranName);
rmr_free_msg(msg);
rmr_close(rmrCtx);
return -4;
}
rmr_free_msg(msg);
unsigned char allocBuffer[64*1024] {0};
auto *events = (struct epoll_event *)calloc(MAXEVENTS, sizeof(event));
while (true) {
auto numOfEvents = epoll_wait(epoll_fd, events, MAXEVENTS, -1);
if (numOfEvents < 0) {
mdclog_write(MDCLOG_ERR, "Epoll wait failed, errno = %s", strerror(errno));
rmr_close(rmrCtx);
return -4;
}
for (auto i = 0; i < numOfEvents; i++) {
if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) {
mdclog_write(MDCLOG_ERR, "epoll error");
} else if (rmrListenFd == events[i].data.fd) {
msg = rmr_alloc_msg(rmrCtx, 4096);
if (msg == nullptr) {
mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno));
rmr_close(rmrCtx);
return -5;
}
msg = rmr_rcv_msg(rmrCtx, msg);
if (msg == nullptr) {
mdclog_write(MDCLOG_ERR, "RMR Receving message, %s", strerror(errno));
rmr_close(rmrCtx);
return -6;
}
memset(allocBuffer, 0, 64*1024);
switch (msg->mtype) {
default: {
mdclog_write(MDCLOG_INFO, "RMR receiveing message type %d", msg->mtype);
asn::per::DecoderCtx dCtx{msg->payload, (size_t) msg->len, allocBuffer, sizeof(allocBuffer)};
E2AP_PDU opdu;
if (!asn::per::unpack(opdu, dCtx)) {
mdclog_write(MDCLOG_ERR, "Failed to unpack ASN message, %s", dCtx.refErrorCtx().toString());
rmr_close(rmrCtx);
return -7;
}
switch (opdu.get_index()) {
case 1: { //initiating message
mdclog_write(MDCLOG_INFO, "ASN initiating message type %ld",
opdu.get_initiatingMessage()->ref_procedureCode().ref_value().get());
break;
}
case 2: { //successful message
mdclog_write(MDCLOG_INFO, "ASN initiating message type %ld",
opdu.get_successfulOutcome()->ref_procedureCode().ref_value().get());
break;
}
case 3: { //unsuccessesful message
mdclog_write(MDCLOG_INFO, "ASN initiating message type %ld",
opdu.get_unsuccessfulOutcome()->ref_procedureCode().ref_value().get());
break;
}
}
mdclog_write(MDCLOG_INFO, "RMR receiveing message from E2 terminator, %d",
msg->mtype);
break;
}
}
}
}
}
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
//
// Created by adi ENZEL on 11/27/19.
//
#include "base64.h"
#include <mdclog/mdclog.h>
#include <cgreen/cgreen.h>
#include <cstdio>
#include <cerrno>
#include <cstdlib>
#include <cstring>
using namespace std;
Describe(base64);
BeforeEach(base64) {}
AfterEach(base64) {}
using namespace cgreen;
void init_log() {
mdclog_attr_t *attr;
mdclog_attr_init(&attr);
mdclog_attr_set_ident(attr, "TestConfiguration");
mdclog_init(attr);
mdclog_attr_destroy(attr);
}
const char *data = "ABC123Test Lets Try this' input and see What \"happens\"";
Ensure(base64, encDec) {
string str = "ABC123Test Lets Try this' input and see What \"happens\"";
auto *buf = (unsigned char *)malloc(str.length() * 2);
auto length = (long)(str.length() * 2);
base64::encode((unsigned char *)str.c_str(), str.length(), buf, length);
auto *backBackBuff = (unsigned char *)malloc(length);
auto length2 = length;
assert_that(base64::decode(buf, length, backBackBuff, length2) == 0);
std::string str1( backBackBuff, backBackBuff + sizeof backBackBuff / sizeof backBackBuff[0]);
assert_that(str.length() == (ulong)length2)
//auto val = str.compare((const char *)backBackBuff);
assert_that(str.compare((const char *)backBackBuff) == 0)
free(backBackBuff);
free(buf);
}
Ensure(base64, errorsHandling) {
string str = "ABC123Test Lets Try this' input and see What \"happens\"";
auto *buf = (unsigned char *)malloc(str.length() * 2);
auto length = (long)(str.length());
assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), buf, length) == -1);
length = (long)(str.length() * 2);
assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), buf, length) == 0);
auto *backBackBuff = (unsigned char *)malloc(length);
auto length2 = length >> 2;
assert_that(base64::decode(buf, length, backBackBuff, length2) == -1);
//std::string str1( backBackBuff, backBackBuff + sizeof backBackBuff / sizeof backBackBuff[0]);
auto length1 = 0l;
assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), nullptr , length) == -1);
// assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), nullptr , length) == -1);
assert_that(base64::encode(nullptr, str.length(), backBackBuff , length) == -1);
assert_that(base64::encode((unsigned char *)str.c_str(), length1, backBackBuff , length) == -1);
assert_that(base64::encode(nullptr, str.length(), backBackBuff , length1) == -1);
length1 = -1;
assert_that(base64::encode((unsigned char *)str.c_str(), length1, backBackBuff , length) == -1);
assert_that(base64::encode(nullptr, str.length(), backBackBuff , length1) == -1);
}
int main(const int argc, char **argv) {
mdclog_severity_t loglevel = MDCLOG_INFO;
init_log();
mdclog_level_set(loglevel);
//TestSuite *suite = create_test_suite();
TestSuite *suite = create_named_test_suite_(__FUNCTION__, __FILE__, __LINE__);
add_test_with_context(suite, base64, encDec);
add_test_with_context(suite, base64, errorsHandling);
return cgreen::run_test_suite(suite, create_text_reporter());
}

View File

@@ -0,0 +1,833 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 6/19/19.
//
#include "e2sm.h"
#define printEntry(type, function) \
if (mdclog_level_get() >= MDCLOG_DEBUG) { \
mdclog_write(MDCLOG_DEBUG, "start Test %s , %s", type, function); \
}
static void checkAndPrint(asn_TYPE_descriptor_t *typeDescriptor, void *data, char *dataType, const char *function) {
char errbuf[128]; /* Buffer for error message */
size_t errlen = sizeof(errbuf); /* Size of the buffer */
if (asn_check_constraints(typeDescriptor, data, errbuf, &errlen) != 0) {
mdclog_write(MDCLOG_ERR, "%s Constraint validation failed: %s", dataType, errbuf);
} else if (mdclog_level_get() >= MDCLOG_DEBUG) {
mdclog_write(MDCLOG_DEBUG, "%s successes function %s", dataType, function);
}
}
static size_t encodebuff(int codingType,
asn_TYPE_descriptor_t *typeDescriptor,
void *objectData,
uint8_t *buffer,
size_t buffer_size) {
asn_enc_rval_t er;
struct timespec start = {0,0};
struct timespec end = {0,0};
clock_gettime(CLOCK_MONOTONIC, &start);
er = asn_encode_to_buffer(0, codingType, typeDescriptor, objectData, buffer, buffer_size);
clock_gettime(CLOCK_MONOTONIC, &end);
if (er.encoded == -1) {
mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2SM_gNB_X2_eventTriggerDefinition.name, strerror(errno));
} else if (er.encoded > (ssize_t)buffer_size) {
mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s", (int) buffer_size,
typeDescriptor->name);
} else if (mdclog_level_get() >= MDCLOG_DEBUG) {
if (codingType == ATS_BASIC_XER) {
mdclog_write(MDCLOG_DEBUG, "Buffer of size %d, data = %s", (int) er.encoded, buffer);
}
else {
if (mdclog_level_get() >= MDCLOG_INFO) {
char *printBuffer;
size_t size;
FILE *stream = open_memstream(&printBuffer, &size);
asn_fprint(stream, typeDescriptor, objectData);
mdclog_write(MDCLOG_DEBUG, "Encoding E2SM PDU past : %s", printBuffer);
}
mdclog_write(MDCLOG_DEBUG, "Buffer of size %d", (int) er.encoded);
}
}
mdclog_write(MDCLOG_INFO, "Encoding type %d, time is %ld seconds, %ld nanoseconds", codingType, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
//mdclog_write(MDCLOG_INFO, "Encoding time is %3.9f seconds", ((double)end.tv_sec + 1.0e-9 * end.tv_nsec) - ((double)start.tv_sec + 1.0e-9 * start.tv_nsec));
return er.encoded;
}
PLMN_Identity_t *createPLMN_ID(const unsigned char *data) {
printEntry("PLMN_Identity_t", __func__)
PLMN_Identity_t *plmnId = calloc(1, sizeof(PLMN_Identity_t));
ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, plmnId);
plmnId->size = 3;
plmnId->buf = calloc(1, 3);
memcpy(plmnId->buf, data, 3);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_PLMN_Identity, plmnId, "PLMN_Identity_t", __func__);
}
return plmnId;
}
ENB_ID_t *createENB_ID(ENB_ID_PR enbType, unsigned char *data) {
printEntry("ENB_ID_t", __func__)
ENB_ID_t *enb = calloc(1, sizeof(ENB_ID_t));
ASN_STRUCT_RESET(asn_DEF_ENB_ID, enb);
enb->present = enbType;
switch (enbType) {
case ENB_ID_PR_macro_eNB_ID: { // 20 bit 3 bytes
enb->choice.macro_eNB_ID.size = 3;
enb->choice.macro_eNB_ID.bits_unused = 4;
enb->present = ENB_ID_PR_macro_eNB_ID;
enb->choice.macro_eNB_ID.buf = calloc(1, enb->choice.macro_eNB_ID.size);
data[enb->choice.macro_eNB_ID.size - 1] = ((unsigned)(data[enb->choice.macro_eNB_ID.size - 1] >>
(unsigned)enb->choice.macro_eNB_ID.bits_unused) << (unsigned)enb->choice.macro_eNB_ID.bits_unused);
memcpy(enb->choice.macro_eNB_ID.buf, data, enb->choice.macro_eNB_ID.size);
break;
}
case ENB_ID_PR_home_eNB_ID: { // 28 bit 4 bytes
enb->choice.home_eNB_ID.size = 4;
enb->choice.home_eNB_ID.bits_unused = 4;
enb->present = ENB_ID_PR_home_eNB_ID;
enb->choice.home_eNB_ID.buf = calloc(1, enb->choice.home_eNB_ID.size);
data[enb->choice.home_eNB_ID.size - 1] = ((unsigned)(data[enb->choice.home_eNB_ID.size - 1] >>
(unsigned)enb->choice.home_eNB_ID.bits_unused) << (unsigned)enb->choice.home_eNB_ID.bits_unused);
memcpy(enb->choice.home_eNB_ID.buf, data, enb->choice.home_eNB_ID.size);
break;
}
case ENB_ID_PR_short_Macro_eNB_ID: { // 18 bit - 3 bytes
enb->choice.short_Macro_eNB_ID.size = 3;
enb->choice.short_Macro_eNB_ID.bits_unused = 6;
enb->present = ENB_ID_PR_short_Macro_eNB_ID;
enb->choice.short_Macro_eNB_ID.buf = calloc(1, enb->choice.short_Macro_eNB_ID.size);
data[enb->choice.short_Macro_eNB_ID.size - 1] = ((unsigned)(data[enb->choice.short_Macro_eNB_ID.size - 1] >>
(unsigned)enb->choice.short_Macro_eNB_ID.bits_unused) << (unsigned)enb->choice.short_Macro_eNB_ID.bits_unused);
memcpy(enb->choice.short_Macro_eNB_ID.buf, data, enb->choice.short_Macro_eNB_ID.size);
break;
}
case ENB_ID_PR_long_Macro_eNB_ID: { // 21
enb->choice.long_Macro_eNB_ID.size = 3;
enb->choice.long_Macro_eNB_ID.bits_unused = 3;
enb->present = ENB_ID_PR_long_Macro_eNB_ID;
enb->choice.long_Macro_eNB_ID.buf = calloc(1, enb->choice.long_Macro_eNB_ID.size);
data[enb->choice.long_Macro_eNB_ID.size - 1] = ((unsigned)(data[enb->choice.long_Macro_eNB_ID.size - 1] >>
(unsigned)enb->choice.long_Macro_eNB_ID.bits_unused) << (unsigned)enb->choice.long_Macro_eNB_ID.bits_unused);
memcpy(enb->choice.long_Macro_eNB_ID.buf, data, enb->choice.long_Macro_eNB_ID.size);
break;
}
default:
free(enb);
return NULL;
}
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ENB_ID, enb, "ENB_ID_t", __func__);
}
return enb;
}
GNB_ID_t *createGnb_id(const unsigned char *data, int numOfBits) {
printEntry("GNB_ID_t", __func__)
if (numOfBits < 22 || numOfBits > 32) {
mdclog_write(MDCLOG_ERR, "GNB_ID_t number of bits = %d, needs to be 22 .. 32", numOfBits);
return NULL;
}
GNB_ID_t *gnb = calloc(1, sizeof(GNB_ID_t));
ASN_STRUCT_RESET(asn_DEF_GNB_ID, gnb);
gnb->present = GNB_ID_PR_gNB_ID;
gnb->choice.gNB_ID.size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
gnb->choice.gNB_ID.bits_unused = (int)gnb->choice.gNB_ID.size * 8 - numOfBits;
gnb->choice.gNB_ID.buf = calloc(1, gnb->choice.gNB_ID.size);
memcpy(gnb->choice.gNB_ID.buf, data, gnb->choice.gNB_ID.size);
gnb->choice.gNB_ID.buf[gnb->choice.gNB_ID.size - 1] =
((unsigned)(gnb->choice.gNB_ID.buf[gnb->choice.gNB_ID.size - 1] >> (unsigned)gnb->choice.gNB_ID.bits_unused)
<< (unsigned)gnb->choice.gNB_ID.bits_unused);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_GNB_ID, gnb, "GNB_ID_t", __func__);
}
return gnb;
}
GlobalENB_ID_t *createGlobalENB_ID(PLMN_Identity_t *plmnIdentity, ENB_ID_t *enbId) {
printEntry("GlobalENB_ID_t", __func__)
GlobalENB_ID_t *genbId = calloc(1, sizeof(GlobalENB_ID_t));
ASN_STRUCT_RESET(asn_DEF_GlobalENB_ID, genbId);
memcpy(&genbId->pLMN_Identity, plmnIdentity, sizeof(PLMN_Identity_t));
memcpy(&genbId->eNB_ID, enbId, sizeof(ENB_ID_t));
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_GlobalENB_ID, genbId, "GlobalENB_ID_t", __func__);
}
return genbId;
}
GlobalGNB_ID_t *createGlobalGNB_ID(PLMN_Identity_t *plmnIdentity, GNB_ID_t *gnb) {
printEntry("GlobalGNB_ID_t", __func__)
GlobalGNB_ID_t *ggnbId = calloc(1, sizeof(GlobalGNB_ID_t));
ASN_STRUCT_RESET(asn_DEF_GlobalGNB_ID, ggnbId);
memcpy(&ggnbId->pLMN_Identity, plmnIdentity, sizeof(PLMN_Identity_t));
memcpy(&ggnbId->gNB_ID, gnb, sizeof(GNB_ID_t));
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_GlobalGNB_ID, ggnbId, "GlobalGNB_ID_t", __func__);
}
return ggnbId;
}
Interface_ID_t *createInterfaceIDForGnb(GlobalGNB_ID_t *gnb) {
printEntry("Interface_ID_t", __func__)
Interface_ID_t *interfaceId = calloc(1, sizeof(Interface_ID_t));
ASN_STRUCT_RESET(asn_DEF_Interface_ID, interfaceId);
interfaceId->present = Interface_ID_PR_global_gNB_ID;
//memcpy(&interfaceId->choice.global_gNB_ID, gnb, sizeof(GlobalGNB_ID_t));
interfaceId->choice.global_gNB_ID = gnb;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_Interface_ID, interfaceId, "Interface_ID_t", __func__);
}
return interfaceId;
}
Interface_ID_t *createInterfaceIDForEnb(GlobalENB_ID_t *enb) {
printEntry("Interface_ID_t", __func__)
Interface_ID_t *interfaceId = calloc(1, sizeof(Interface_ID_t));
ASN_STRUCT_RESET(asn_DEF_Interface_ID, interfaceId);
interfaceId->present = Interface_ID_PR_global_eNB_ID;
//memcpy(&interfaceId->choice.global_eNB_ID, enb, sizeof(GlobalENB_ID_t));
interfaceId->choice.global_eNB_ID = enb;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_Interface_ID, interfaceId, "Interface_ID_t", __func__);
}
return interfaceId;
}
InterfaceMessageType_t *createInterfaceMessageInitiating(long procedureCode) {
printEntry("InterfaceMessageType_t", __func__)
InterfaceMessageType_t *intMsgT = calloc(1, sizeof(InterfaceMessageType_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceMessageType, intMsgT);
intMsgT->procedureCode = procedureCode;
intMsgT->typeOfMessage = TypeOfMessage_initiating_message;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceMessageType, intMsgT, "InterfaceMessageType_t", __func__);
}
return intMsgT;
}
InterfaceMessageType_t *createInterfaceMessageSuccsesful(long procedureCode) {
printEntry("InterfaceMessageType_t", __func__)
InterfaceMessageType_t *intMsgT = calloc(1, sizeof(InterfaceMessageType_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceMessageType, intMsgT);
intMsgT->procedureCode = procedureCode;
intMsgT->typeOfMessage = TypeOfMessage_successful_outcome;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceMessageType, intMsgT, "InterfaceMessageType_t", __func__);
}
return intMsgT;
}
InterfaceMessageType_t *createInterfaceMessageUnsuccessful(long procedureCode) {
printEntry("InterfaceMessageType_t", __func__)
InterfaceMessageType_t *intMsgT = calloc(1, sizeof(InterfaceMessageType_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceMessageType, intMsgT);
intMsgT->procedureCode = procedureCode;
intMsgT->typeOfMessage = TypeOfMessage_unsuccessful_outcome;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceMessageType, intMsgT, "InterfaceMessageType_t", __func__);
}
return intMsgT;
}
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueInt(long number) {
printEntry("InterfaceProtocolIE_Value_t", __func__)
InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
value->present = InterfaceProtocolIE_Value_PR_valueInt;
value->choice.valueInt = number;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
}
return value;
}
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueEnum(long number) {
printEntry("InterfaceProtocolIE_Value_t", __func__)
InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
value->present = InterfaceProtocolIE_Value_PR_valueEnum;
value->choice.valueEnum = number;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
}
return value;
}
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueBool(int val) {
printEntry("InterfaceProtocolIE_Value_t", __func__)
InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
value->present = InterfaceProtocolIE_Value_PR_valueBool;
value->choice.valueBool = val == 0 ? 0 : 1;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
}
return value;
}
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueBitString(unsigned char *buf, int numOfBits) {
printEntry("InterfaceProtocolIE_Value_t", __func__)
size_t size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
if (strlen((const char *)buf) < size) {
mdclog_write(MDCLOG_ERR, "size of buffer is small : %d needs to be %d in %s", (int)strlen((const char *)buf), (int)size, __func__);
}
InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
value->present = InterfaceProtocolIE_Value_PR_valueBitS;
value->choice.valueBitS.size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
value->choice.valueBitS.buf = calloc(1, value->choice.valueBitS.size);
int bits_unused = (int)value->choice.valueBitS.size * 8 - numOfBits;
value->choice.valueBitS.bits_unused = bits_unused;
memcpy(value->choice.valueBitS.buf, buf, value->choice.valueBitS.size);
value->choice.valueBitS.buf[size -1] = ((unsigned)(buf[size - 1]) >> (unsigned)bits_unused << (unsigned)bits_unused);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
}
return value;
}
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueOCTETS(uint8_t *buf) {
printEntry("InterfaceProtocolIE_Value_t", __func__)
size_t size = strlen((const char *)buf);
InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
value->present = InterfaceProtocolIE_Value_PR_valueOctS;
value->choice.valueOctS.size = size;
value->choice.valueOctS.buf = calloc(1, value->choice.valueOctS.size);
memcpy(value->choice.valueOctS.buf, buf, value->choice.valueOctS.size);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
}
return value;
}
InterfaceProtocolIE_Item_t *createInterfaceProtocolIE_Item(long id, long test, InterfaceProtocolIE_Value_t *value) {
printEntry("InterfaceProtocolIE_Item_t", __func__)
if (test < InterfaceProtocolIE_Test_equal || test > InterfaceProtocolIE_Test_present) {
mdclog_write(MDCLOG_ERR, "InterfaceProtocolIE_Item_t test value is %ld, out of scope %d .. %d ",
test, InterfaceProtocolIE_Test_equal, InterfaceProtocolIE_Test_present);
return NULL;
}
InterfaceProtocolIE_Item_t *intProtIt = calloc(1, sizeof(InterfaceProtocolIE_Item_t));
ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Item, intProtIt);
intProtIt->interfaceProtocolIE_ID = id;
intProtIt->interfaceProtocolIE_Test = test;
memcpy(&intProtIt->interfaceProtocolIE_Value, value, sizeof(InterfaceProtocolIE_Value_t));
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_InterfaceProtocolIE_Item, intProtIt, "InterfaceProtocolIE_Item_t", __func__);
}
return intProtIt;
}
ActionParameter_Value_t *createActionParameterValue_Int(long number) {
printEntry("ActionParameter_Value_t", __func__)
ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
value->present = ActionParameter_Value_PR_valueInt;
value->choice.valueInt = number;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
}
return value;
}
ActionParameter_Value_t *createActionParameterValue_Enum(long number) {
printEntry("ActionParameter_Value_t", __func__)
ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
value->present = ActionParameter_Value_PR_valueEnum;
value->choice.valueEnum = number;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
}
return value;
}
ActionParameter_Value_t *createActionParameterValue_Bool(int val) {
printEntry("ActionParameter_Value_t", __func__)
ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
value->present = ActionParameter_Value_PR_valueBool;
value->choice.valueBool = val == 0 ? 0 : 1;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
}
return value;
}
ActionParameter_Value_t *createActionParameterValue_Bit_String(unsigned char *buf, int numOfBits) {
printEntry("ActionParameter_Value_t", __func__)
size_t size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
if (strlen((const char *)buf) < size) {
mdclog_write(MDCLOG_ERR, "size of buffer is small : %d needs to be %d in %s", (int)strlen((const char *)buf), (int)size, __func__);
}
int bits_unused = (int)size * 8 - numOfBits;
ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
value->present = ActionParameter_Value_PR_valueBitS;
value->choice.valueBitS.size = size;
value->choice.valueBitS.buf = calloc(1, size);
value->choice.valueBitS.bits_unused = bits_unused;
memcpy(value->choice.valueBitS.buf, buf, size);
value->choice.valueBitS.buf[size -1] = ((unsigned)(buf[size - 1]) >> (unsigned)bits_unused << (unsigned)bits_unused);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
}
return value;
}
ActionParameter_Value_t *createActionParameterValue_OCTETS(uint8_t *buf) {
printEntry("ActionParameter_Value_t", __func__)
size_t size = strlen((const char *)buf);
ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
value->present = ActionParameter_Value_PR_valueOctS;
value->choice.valueOctS.size = size;
value->choice.valueOctS.buf = calloc(1, value->choice.valueOctS.size);
memcpy(value->choice.valueOctS.buf, buf, value->choice.valueOctS.size);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
}
return value;
}
/**
*
* @param buf buffer that must be null terminated
* @return ActionParameter_Value_t *
*/
ActionParameter_Value_t *createActionParameterValue_PRINTS(char *buf) {
printEntry("ActionParameter_Value_t", __func__)
size_t size = strlen((const char *)buf);
ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
value->present = ActionParameter_Value_PR_valuePrtS;
value->choice.valuePrtS.size = size;
value->choice.valuePrtS.buf = calloc(1, value->choice.valuePrtS.size);
memcpy(value->choice.valuePrtS.buf, buf, value->choice.valuePrtS.size);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
}
return value;
}
ActionParameter_Item_t *creatActionParameter_Item(long id, ActionParameter_Value_t *val) {
printEntry("ActionParameter_Item_t", __func__)
if (id < 0 || id > 255) {
mdclog_write(MDCLOG_ERR, "ActionParameter_Item_t id = %ld, values are 0 .. 255", id);
return NULL;
}
ActionParameter_Item_t *actionParameterItem = calloc(1, sizeof(ActionParameter_Item_t));
ASN_STRUCT_RESET(asn_DEF_ActionParameter_Item, actionParameterItem);
actionParameterItem->actionParameter_ID = id;
memcpy(&actionParameterItem->actionParameter_Value, val, sizeof(ActionParameter_Value_t));
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_ActionParameter_Item, actionParameterItem, "ActionParameter_Item_t", __func__);
}
return actionParameterItem;
}
/**
*
* @param interfaceId
* @param direction
* @param messageType
* @param interfaceProtocolItemList
* @param listSize
* @param buffer
* @param buffer_size
* @return
*/
size_t createEventTrigger(Interface_ID_t *interfaceId, long direction,
InterfaceMessageType_t *messageType,
InterfaceProtocolIE_Item_t interfaceProtocolItemList[],
int listSize,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_eventTriggerDefinition_t", __func__)
if (direction < InterfaceDirection_incoming || direction > InterfaceDirection_outgoing) {
mdclog_write(MDCLOG_ERR, "E2SM_gNB_X2_eventTriggerDefinition_t direction = %ld, values are %d .. %d",
direction, InterfaceDirection_incoming, InterfaceDirection_outgoing);
return -1;
}
E2SM_gNB_X2_eventTriggerDefinition_t *eventTrigger = calloc(1, sizeof(E2SM_gNB_X2_eventTriggerDefinition_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, eventTrigger);
memcpy(&eventTrigger->interface_ID , interfaceId, sizeof(Interface_ID_t));
eventTrigger->interfaceDirection = direction;
memcpy(&eventTrigger->interfaceMessageType, messageType, sizeof(InterfaceMessageType_t));
for (int i = 0; i < listSize; i++) {
ASN_SEQUENCE_ADD(eventTrigger->interfaceProtocolIE_List, &interfaceProtocolItemList[i]);
}
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, eventTrigger, "E2SM_gNB_X2_eventTriggerDefinition_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition,
eventTrigger,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition,
eventTrigger,
buf1,
4096);
}
return len;
}
size_t createActionDefinition(long styleId, ActionParameter_Item_t actionParamList[], int listSize,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_actionDefinition_t", __func__)
E2SM_gNB_X2_actionDefinition_t *actDef = calloc(1, sizeof(E2SM_gNB_X2_actionDefinition_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_actionDefinition, actDef);
actDef->style_ID = styleId;
for (int i = 0; i < listSize; i++) {
ASN_SEQUENCE_ADD(actDef->actionParameter_List, &actionParamList[i]);
}
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_actionDefinition, actDef, "E2SM_gNB_X2_actionDefinition_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_actionDefinition,
actDef,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_actionDefinition,
actDef,
buf1,
4096);
}
return len;
}
size_t createE2SM_gNB_X2_indicationHeader(long direction,
Interface_ID_t *interfaceId,
uint8_t *timestamp, //can put NULL if size == 0
int size,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_indicationHeader_t", __func__)
if (direction < InterfaceDirection_incoming || direction > InterfaceDirection_outgoing) {
mdclog_write(MDCLOG_ERR, "E2SM_gNB_X2_indicationHeader_t direction = %ld, values are %d .. %d",
direction, InterfaceDirection_incoming, InterfaceDirection_outgoing);
return -1;
}
E2SM_gNB_X2_indicationHeader_t *indiHead = calloc(1, sizeof(E2SM_gNB_X2_indicationHeader_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_indicationHeader, indiHead);
indiHead->interfaceDirection = direction;
memcpy(&indiHead->interface_ID, interfaceId, sizeof(Interface_ID_t));
if (size > 0) {
indiHead->timestamp->size = size;
indiHead->timestamp->buf = calloc(1, sizeof(uint8_t) * size);
memcpy(indiHead->timestamp->buf, timestamp, size);
}
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_indicationHeader, indiHead, "E2SM_gNB_X2_indicationHeader_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_indicationHeader,
indiHead,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_indicationHeader,
indiHead,
buf1,
4096);
}
return len;
}
size_t createE2SM_gNB_X2_indicationMessage(uint8_t *message, uint msgSize,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_indicationMessage_t", __func__)
if (msgSize <= 0) {
mdclog_write(MDCLOG_ERR, "E2SM_gNB_X2_indicationMessage_t failed messsage size = %d", msgSize);
return -1;
}
E2SM_gNB_X2_indicationMessage_t *indicationMessage = calloc(1, sizeof(E2SM_gNB_X2_indicationMessage_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_indicationMessage, indicationMessage);
indicationMessage->interfaceMessage.size = msgSize;
indicationMessage->interfaceMessage.buf = calloc(1, sizeof(uint8_t) * msgSize);
memcpy(indicationMessage->interfaceMessage.buf, message, msgSize);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_indicationMessage, indicationMessage, "E2SM_gNB_X2_indicationMessage_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_indicationMessage,
indicationMessage,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_indicationMessage,
indicationMessage,
buf1,
4096);
}
return len;
}
size_t createE2SM_gNB_X2_callProcessID(long callProcess_Id,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_callProcessID_t", __func__)
E2SM_gNB_X2_callProcessID_t *callProcessId = calloc(1, sizeof(E2SM_gNB_X2_callProcessID_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_callProcessID, callProcessId);
callProcessId->callProcess_ID = callProcess_Id;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_callProcessID, callProcessId, "E2SM_gNB_X2_indicationMessage_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_callProcessID,
callProcessId,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_callProcessID,
callProcessId,
buf1,
4096);
}
return len;
}
size_t createE2SM_gNB_X2_controlHeader(Interface_ID_t *interfaceId, long direction,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_controlHeader_t", __func__)
if (direction < InterfaceDirection_incoming || direction > InterfaceDirection_outgoing) {
mdclog_write(MDCLOG_ERR, "E2SM_gNB_X2_controlHeader_t direction = %ld, values are %d .. %d",
direction, InterfaceDirection_incoming, InterfaceDirection_outgoing);
return -1;
}
E2SM_gNB_X2_controlHeader_t *controlHeader = calloc(1, sizeof(E2SM_gNB_X2_controlHeader_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_controlHeader, controlHeader);
memcpy(&controlHeader->interface_ID, interfaceId, sizeof(Interface_ID_t));
controlHeader->interfaceDirection = direction;
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_controlHeader, controlHeader, "E2SM_gNB_X2_controlHeader_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_controlHeader,
controlHeader,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_controlHeader,
controlHeader,
buf1,
4096);
}
return len;
}
size_t createE2SM_gNB_X2_controlMessage(uint8_t *message, uint msgSize,
uint8_t *buffer,
size_t buffer_size) {
printEntry("E2SM_gNB_X2_controlMessage_t", __func__)
E2SM_gNB_X2_controlMessage_t *controlMsg = calloc(1, sizeof(E2SM_gNB_X2_controlMessage_t));
ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_controlMessage, controlMsg);
controlMsg->interfaceMessage.size = msgSize;
controlMsg->interfaceMessage.buf = calloc(1, sizeof(uint8_t) * msgSize);
memcpy(controlMsg->interfaceMessage.buf, message, msgSize);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
checkAndPrint(&asn_DEF_E2SM_gNB_X2_controlMessage, controlMsg, "E2SM_gNB_X2_controlMessage_t", __func__);
}
size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_controlMessage,
controlMsg,
buffer,
buffer_size);
if (mdclog_level_get() >= MDCLOG_INFO) {
uint8_t buf1[4096];
//asn_enc_rval_t er1;
encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_controlMessage,
controlMsg,
buf1,
4096);
}
return len;
}

View File

@@ -0,0 +1,322 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 6/19/19.
//
#ifndef ASN_DISABLE_OER_SUPPORT
#define ASN_DISABLE_OER_SUPPORT // this is to remove the OER do not remove it
#endif
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef E2_E2SM_H
#define E2_E2SM_H
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <error.h>
#include <errno.h>
#include <mdclog/mdclog.h>
#include <time.h>
#include <math.h>
#include "asn1cFiles/ENB-ID.h"
#include "asn1cFiles/E2SM-gNB-X2-actionDefinition.h"
#include "asn1cFiles/E2SM-gNB-X2-callProcessID.h"
#include "asn1cFiles/E2SM-gNB-X2-controlHeader.h"
#include "asn1cFiles/E2SM-gNB-X2-controlMessage.h"
#include "asn1cFiles/E2SM-gNB-X2-indicationHeader.h"
#include "asn1cFiles/E2SM-gNB-X2-indicationMessage.h"
#include "asn1cFiles/E2SM-gNB-X2-eventTriggerDefinition.h"
#include "asn1cFiles/ActionParameter-Item.h"
#include "asn1cFiles/ActionParameter-Value.h"
#include "asn1cFiles/PLMN-Identity.h"
#include "asn1cFiles/GlobalENB-ID.h"
#include "asn1cFiles/GlobalGNB-ID.h"
#include "asn1cFiles/Interface-ID.h"
#include "asn1cFiles/InterfaceMessageType.h"
#include "asn1cFiles/InterfaceProtocolIE-Item.h"
/**
*
* @param data
* @return
*/
PLMN_Identity_t *createPLMN_ID(const unsigned char *data);
/**
*
* @param enbType
* @param data
* @return
*/
ENB_ID_t *createENB_ID(ENB_ID_PR enbType, unsigned char *data);
/**
*
* @param data
* @param numOfBits
* @return
*/
GNB_ID_t *createGnb_id(const unsigned char *data, int numOfBits);
/**
*
* @param plmnIdentity
* @param enbId
* @return
*/
GlobalENB_ID_t *createGlobalENB_ID(PLMN_Identity_t *plmnIdentity, ENB_ID_t *enbId);
/**
*
* @param plmnIdent#ifdef __cplusplus
}
#endif
ity
* @param gnb
* @return
*/
GlobalGNB_ID_t *createGlobalGNB_ID(PLMN_Identity_t *plmnIdentity, GNB_ID_t *gnb);
/**
*
* @param gnb
* @return
*/
Interface_ID_t *createInterfaceIDForGnb(GlobalGNB_ID_t *gnb);
/**
*
* @param enb
* @return
*/
Interface_ID_t *createInterfaceIDForEnb(GlobalENB_ID_t *enb);
/**
*
* @param procedureCode
* @return
*/
InterfaceMessageType_t *createInterfaceMessageInitiating(ProcedureCode_t procedureCode);
/**
*
* @param procedureCode
* @return
*/
InterfaceMessageType_t *createInterfaceMessageSuccsesful(ProcedureCode_t procedureCode);
/**
*
* @param procedureCode
* @return
*/
InterfaceMessageType_t *createInterfaceMessageUnsuccessful(ProcedureCode_t procedureCode);
/**
*
* @param number
* @return
*/
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueInt(long number);
/**
*
* @param number
* @return
*/
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueEnum(long number);
/**
*
* @param val
* @return
*/
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueBool(int val);
/**
*
* @param buf
* @param numOfBits
* @return
*/
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueBitString(unsigned char *buf, int numOfBits);
/**
*
* @param buf
* @param size
* @return
*/
InterfaceProtocolIE_Value_t *createInterfaceProtocolValueOCTETS(uint8_t *buf);
/**
*
* @param id
* @param test
* @param value
* @return
*/
InterfaceProtocolIE_Item_t *createInterfaceProtocolIE_Item(long id, long test, InterfaceProtocolIE_Value_t *value);
/**
*
* @param number
* @return
*/
ActionParameter_Value_t *createActionParameterValue_Int(long number);
/**
*
* @param number
* @return
*/
ActionParameter_Value_t *createActionParameterValue_Enum(long number);
/**
*
* @param val
* @return
*/
ActionParameter_Value_t *createActionParameterValue_Bool(int val);
/**
*
* @param buf
* @param numOfBits
* @return
*/
ActionParameter_Value_t *createActionParameterValue_Bit_String(unsigned char *buf, int numOfBits);
/**
*
* @param buf
* @param size
* @return
*/
ActionParameter_Value_t *createActionParameterValue_OCTETS(uint8_t *buf);
/**
*
* @param buf
* @param size
* @return
*/
ActionParameter_Value_t *createActionParameterValue_PRINTS(char *buf);
/**
*
* @param id
* @param val
* @return
*/
ActionParameter_Item_t *creatActionParameter_Item(long id, ActionParameter_Value_t *val);
/**
*
* @param interfaceId
* @param direction
* @param messageType
* @param interfaceProtocolItemList
* @param listSize
* @param buffer
* @param buffer_size
* @return
*/
size_t createEventTrigger(Interface_ID_t *interfaceId, long direction,
InterfaceMessageType_t *messageType,
InterfaceProtocolIE_Item_t interfaceProtocolItemList[],
int listSize,
uint8_t *buffer,
size_t buffer_size);
/**
*
* @param styleId
* @param actionParamList
* @param listSize
* @param buffer
* @param buffer_size
* @return
*/
size_t createActionDefinition(long styleId, ActionParameter_Item_t actionParamList[], int listSize,
uint8_t *buffer,
size_t buffer_size);
/**
*
* @param interfaceDirection
* @param interfaceId
* @param timestamp
* @param size
* @param buffer
* @param buffer_size
* @return
*/
size_t createE2SM_gNB_X2_indicationHeader(long interfaceDirection,
Interface_ID_t *interfaceId,
uint8_t *timestamp, //can put NULL if size == 0
int size,
uint8_t *buffer,
size_t buffer_size);
/**
*
* @param message
* @param msgSize
* @param buffer
* @param buffer_size
* @return
*/
size_t createE2SM_gNB_X2_indicationMessage(uint8_t *message, uint msgSize,
uint8_t *buffer,
size_t buffer_size);
/**
*
* @param callProcess_Id
* @param buffer
* @param buffer_size
* @return
*/
size_t createE2SM_gNB_X2_callProcessID(long callProcess_Id,
uint8_t *buffer,
size_t buffer_size);
size_t createE2SM_gNB_X2_controlHeader(Interface_ID_t *interfaceId, long direction,
uint8_t *buffer,
size_t buffer_size);
size_t createE2SM_gNB_X2_controlMessage(uint8_t *message, uint msgSize,
uint8_t *buffer,
size_t buffer_size);
#endif //E2_E2SM_H
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,163 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 6/19/19.
//
#include "../e2sm.h"
#include <mdclog/mdclog.h>
void init_log()
{
mdclog_attr_t *attr;
mdclog_attr_init(&attr);
mdclog_attr_set_ident(attr, "e2smTests");
mdclog_init(attr);
mdclog_attr_destroy(attr);
}
int main(const int argc, char **argv) {
init_log();
//mdclog_level_set(MDCLOG_WARN);
//mdclog_level_set(MDCLOG_INFO);
mdclog_level_set(MDCLOG_DEBUG);
unsigned char plmnidData[3] = {0x33, 0xF4, 0x55};
//mdclog_write(MDCLOG_INFO, "Test PLMN_Identity_t");
PLMN_Identity_t *plmnid = createPLMN_ID(plmnidData);
unsigned char enbData[3] = {0x66, 0x77, 0x88};
ENB_ID_t *enb = createENB_ID(ENB_ID_PR_macro_eNB_ID, enbData);
enbData[2] = 0x89;
ENB_ID_t *enb1 = createENB_ID(ENB_ID_PR_home_eNB_ID, enbData);
enbData[2] = 0x89;
ENB_ID_t *enb2 = createENB_ID(ENB_ID_PR_long_Macro_eNB_ID, enbData);
enbData[2] = 0x89;
ENB_ID_t *enb3 = createENB_ID(ENB_ID_PR_short_Macro_eNB_ID, enbData);
unsigned char gnbData[3] = {0x99, 0xaa, 0xbb};
GNB_ID_t *gnb = createGnb_id(gnbData, 26);
GlobalENB_ID_t *globalEnb = createGlobalENB_ID(plmnid, enb2);
GlobalGNB_ID_t *globaGnb = createGlobalGNB_ID(plmnid, gnb);
Interface_ID_t *gnbInterfaceId = createInterfaceIDForGnb(globaGnb);
Interface_ID_t *enbInterfaceId = createInterfaceIDForEnb(globalEnb);
InterfaceMessageType_t *initiatingInterface = createInterfaceMessageInitiating(28);
InterfaceMessageType_t *succsesfulInterface = createInterfaceMessageSuccsesful(29);
InterfaceMessageType_t *unSuccsesfulInterface = createInterfaceMessageUnsuccessful(29);
InterfaceProtocolIE_Value_t *intVal = createInterfaceProtocolValueInt(88);
InterfaceProtocolIE_Value_t *enumVal = createInterfaceProtocolValueEnum(2);
InterfaceProtocolIE_Value_t *boolVal = createInterfaceProtocolValueBool(0);
InterfaceProtocolIE_Value_t *bitStringVal = createInterfaceProtocolValueBitString((unsigned char *)"abcd0987", 60);
uint8_t octe[6] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
InterfaceProtocolIE_Value_t *octetsVal = createInterfaceProtocolValueOCTETS(octe);
InterfaceProtocolIE_Item_t *item1 = createInterfaceProtocolIE_Item(10, 0, intVal);
InterfaceProtocolIE_Item_t *item2 = createInterfaceProtocolIE_Item(10, 1, enumVal);
InterfaceProtocolIE_Item_t *item3 = createInterfaceProtocolIE_Item(10, 0, boolVal);
InterfaceProtocolIE_Item_t *item4 = createInterfaceProtocolIE_Item(10, 3, bitStringVal);
InterfaceProtocolIE_Item_t *item5 = createInterfaceProtocolIE_Item(10, 4, octetsVal);
ActionParameter_Item_t *actItem1 = creatActionParameter_Item(17, createActionParameterValue_Int(9));
ActionParameter_Value_t *actP_enum = createActionParameterValue_Enum(5);
ActionParameter_Item_t *actItem2 = creatActionParameter_Item(18, actP_enum);
ActionParameter_Value_t *actP_bool = createActionParameterValue_Bool(0);
ActionParameter_Item_t *actItem3 = creatActionParameter_Item(18, actP_bool);
//ActionParameter_Value_t *actP_bitString = createActionParameterValue_Bit_String((unsigned char *)"ABCDEF", 42);
ActionParameter_Item_t *actItem4 = creatActionParameter_Item(17, createActionParameterValue_Bit_String((unsigned char *)"ABCDEF", 42));
uint8_t octe1[7] = {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27};
ActionParameter_Value_t *actP_octates = createActionParameterValue_OCTETS(octe1);
ActionParameter_Item_t *actItem5 = creatActionParameter_Item(18, actP_octates);
char print[10] = {'a', 'b', 'C', 'D', 'e', 'f', 'g', 'H', 'I', '\0'};
ActionParameter_Value_t *actP_printable = createActionParameterValue_PRINTS(print);
ActionParameter_Item_t *actItem6 = creatActionParameter_Item(18, actP_printable);
InterfaceProtocolIE_Item_t *interfaceProtocolItemList[] = {item1, item2, item3, item4, item5};
uint8_t buffer[4096];
size_t len;
if ((len = createEventTrigger(gnbInterfaceId,
0,
initiatingInterface,
*interfaceProtocolItemList,
5,
buffer,
4096)) <= 0) {
mdclog_write(MDCLOG_ERR, "returned error from createEventTrigger");
}
ActionParameter_Item_t *actionParamList[] = {actItem1, actItem2, actItem3, actItem4, actItem5, actItem6};
len = createActionDefinition(10034, *actionParamList, 6, buffer, 4096);
len = createE2SM_gNB_X2_indicationHeader(1, enbInterfaceId, nullptr, 0, buffer, 4096);
if (mdclog_level_get() >= MDCLOG_DEBUG) {
mdclog_write(MDCLOG_DEBUG, "Check bad direction in header indication");
len = createE2SM_gNB_X2_indicationHeader(2, enbInterfaceId, nullptr, 0, buffer, 4096);
if (len == (size_t)-1) {
mdclog_write(MDCLOG_DEBUG, "successes call function returned NULL please ignore ERROR log");
}
}
uint8_t msg[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x0};
int x = 1;
for (int i = 0; i < x; i++) {
len = createE2SM_gNB_X2_indicationMessage(msg, strlen((char *)msg), buffer, 4096);
}
for (int i = 0; i < x; i++) {
len = createE2SM_gNB_X2_callProcessID(8, buffer, 4096);
}
for (int i = 0; i < x; i++) {
len = createE2SM_gNB_X2_controlHeader(enbInterfaceId, 1, buffer, 4096);
}
for (int i = 0; i < x; i++) {
len = createE2SM_gNB_X2_controlHeader(gnbInterfaceId, 1, buffer, 4096);
}
for (int i = 0; i < x; i++) {
len = createE2SM_gNB_X2_controlMessage(msg, strlen((char *)msg), buffer, 4096);
}
return 0;
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 12/19/19.
//
#include "e2test.h"
int main(const int argc, char **argv) {
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 12/19/19.
//
#ifndef E2_E2TEST_H
#define E2_E2TEST_H
#include <algorithm>
//#include <pistache/net.h>
//#include <pistache/http.h>
//#include <pistache/peer.h>
//#include <pistache/http_headers.h>
//#include <pistache/cookie.h>
//#include <pistache/endpoint.h>
//#include <pistache/common.h>
//#include <pistache/router.h>
//
//
//using namespace Pistache;
class e2test {
// Rest::Router router;
};
#endif //E2_E2TEST_H

View File

@@ -0,0 +1,151 @@
/*
* 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.
*/
//
// Created by adi ENZEL on 2/16/20.
//
#include "HttpServer.h"
#include <algorithm>
#include <random>
#include "../sctpClient/sctpClient.h"
#include "../T1/E2Builder.h"
#include "../base64.h"
using namespace std;
using namespace Pistache;
#define RECEIVE_SCTP_BUFFER_SIZE 8192
namespace Generic {
void handleReady(const Rest::Request&, Http::ResponseWriter response) {
response.send(Http::Code::Ok, "1");
}
}
HttpServer::HttpServer(Address addr)
: httpBaseSocket(0), httpEndpoint(std::make_shared<Http::Endpoint>(addr)) { }
void HttpServer::init(size_t thr) {
if ((httpBaseSocket = socket(AF_INET, SOCK_STREAM, 0)) == 0) {
fprintf(stderr, "Socket() error. %s\n", strerror(errno));
exit(-1);
}
auto optval = 1;
if (setsockopt(httpBaseSocket, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof optval) != 0) {
fprintf(stderr, "setsockopt SO_REUSEPORT Error, %s %s, %d\n", strerror(errno), __func__, __LINE__);
close(httpBaseSocket);
exit(-1);
}
optval = 1;
if (setsockopt(httpBaseSocket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval) != 0) {
fprintf(stderr, "setsockopt SO_REUSEADDR Error, %s %s, %d\n", strerror(errno), __func__, __LINE__);
close(httpBaseSocket);
exit(-1);
}
struct sockaddr_in address{};
address.sin_family = AF_INET;
if(inet_pton(AF_INET, "127.0.0.1", &address.sin_addr)<=0)
{
fprintf(stderr,"Invalid address/Address not supported. %s", strerror(errno));
exit(-1);
}
address.sin_port = htons(9098);
if (connect(httpBaseSocket, (SA *)(&address), sizeof(address)) < 0) {
fprintf(stderr, "connect() error. %s\n", strerror(errno));
exit(-1);
}
auto opts = Http::Endpoint::options().threads(thr);
httpEndpoint->init(opts);
setupRoutes();
}
void HttpServer::start() {
std::random_device device{};
std::mt19937 generator(device());
std::uniform_int_distribution<long> distribution(1, (long) 1e12);
transactionCounter = distribution(generator);
httpEndpoint->setHandler(router.handler());
httpEndpoint->serve();
}
void HttpServer::setupRoutes() {
using namespace Rest;
Routes::Get(router, "/setup/:ricaddress/:ricPort/:mcc/:mnc", Routes::bind(&HttpServer::sendSetupReq, this));
//Routes::Post(router, "/ricIndication/:ricid/:subscriptionId/:mcc/:mnc", Routes::bind(&HttpServer::sendSetupReq, this));
Routes::Get(router, "/ready", Routes::bind(&Generic::handleReady));
}
void HttpServer::sendSetupReq(const Rest::Request& request, Http::ResponseWriter response) {
auto mcc = request.param(":mcc").as<int>();
auto mnc = request.param(":mnc").as<int>();
auto ricAdress = request.param(":ricaddress").as<std::string>();
auto ricPort = request.param(":ricPort").as<int>();
//TODO build setup to send to address
E2AP_PDU_t pdu;
buildSetupRequest(&pdu,mcc, mnc);
// encode PDU to PER
auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE;
unsigned char buffer[RECEIVE_SCTP_BUFFER_SIZE] = {};
// encode to xml
asn_enc_rval_t er;
er = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, &pdu, buffer, buffer_size);
if (er.encoded == -1) {
cerr << "encoding of : " << asn_DEF_E2AP_PDU.name << " failed, "<< strerror(errno) << endl;
response.send(Http::Code::Internal_Server_Error, "strerror(errno)");
return;
} else if (er.encoded > (ssize_t)buffer_size) {
cerr << "Buffer of size : " << buffer_size << " is to small for : " << asn_DEF_E2AP_PDU.name << endl;
response.send(Http::Code::Internal_Server_Error, "Buffer of size is too small");
return;
}
long len = er.encoded * 4 / 3 + 128;
auto *base64Buff = (unsigned char *)calloc(1,len + 1024);
char tx[32];
snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
auto sentLen = snprintf((char *)base64Buff, 1024, "%d|%s|%s|%d|", setupRequest_gnb, tx, ricAdress.c_str(), ricPort);
base64::encode(buffer, er.encoded, &base64Buff[sentLen], len);
sentLen += len;
len = send(httpBaseSocket, base64Buff, sentLen, 0);
if (len < 0) {
cerr << "failed sending setupRequest_gnb to Other thread. Error : " << strerror(errno) << endl;
response.send(Http::Code::Internal_Server_Error, "Failed send buffer");
free(base64Buff);
return;
}
char tx1[128];
snprintf((char *) tx1, sizeof tx1, "{\"id\": %s}", tx);
response.send(Http::Code::Ok, tx1);
free(base64Buff);
}

View File

@@ -0,0 +1,57 @@
/*
* 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.
*/
//
// Created by adi ENZEL on 2/18/20.
//
#ifndef E2_HTTPSERVER_H
#define E2_HTTPSERVER_H
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/endpoint.h>
#include <pistache/net.h>
using namespace std;
using namespace Pistache;
#define SA struct sockaddr
class HttpServer {
public:
explicit HttpServer(Address addr);
void init(size_t thr = 2);
void start();
private:
long transactionCounter = 0;
int httpBaseSocket;
void setupRoutes();
void sendSetupReq(const Rest::Request& request, Http::ResponseWriter response);
std::shared_ptr<Http::Endpoint> httpEndpoint;
Rest::Router router;
};
#endif //E2_HTTPSERVER_H

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 6/11/19.
//
#ifndef __LOG_INIT__
#define __LOG_INIT__
#include <mdclog/mdclog.h>
#ifdef __cplusplus
extern "C"
{
#endif
void init_log(char *name) {
mdclog_attr_t *attr;
mdclog_attr_init(&attr);
mdclog_attr_set_ident(attr, name);
mdclog_init(attr);
mdclog_attr_destroy(attr);
}
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,121 @@
/*
* 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.
*/
//
// Created by adi ENZEL on 2/12/20.
//
#include <iostream>
#include <string>
#include <cstring>
#include <exception>
#include <utility>
#include <unistd.h>
//rmr testing thread
#include <rmr/rmr.h>
using namespace std;
#define MAX_RECEIVED_BUFFER 8192
class RmrException: public std::exception
{
std::string msg;
public:
explicit RmrException(std::string msg) : msg(std::move(msg)){}
const char* what() const noexcept override {
return msg.c_str();
}
};
class RmrClient {
private:
void *rmrCtx = nullptr;
int rmr_fd = 0;
void getRmrContext(const char *address, int epoll_fd) {
rmrCtx = rmr_init((char *)address, MAX_RECEIVED_BUFFER, RMRFL_NONE);
if (rmrCtx == nullptr) {
cerr << "Failed to initialize RMR. address = " << address << endl;
throw RmrException("Failed to initialize RMR");
}
rmr_set_stimeout(rmrCtx, 0); // disable retries for any send operation
cout << "Wait for RMR_Ready" << endl;
auto rmrReady = 0;
auto count = 0;
while (!rmrReady) {
if ((rmrReady = rmr_ready(rmrCtx)) == 0) {
usleep(1000000);
}
count++;
if (count % 60 == 0) {
cout << "Wait for RMR ready state : " << count << " seconds" << endl;
}
}
cout << "RMR running" << endl;
rmr_init_trace(rmrCtx, 200);
// get the RMR fd for the epoll
rmr_fd = rmr_get_rcvfd(rmrCtx);
struct epoll_event event{};
// add RMR fd to epoll
event.events = (EPOLLIN);
event.data.fd = rmr_fd;
// add listening RMR FD to epoll
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, rmr_fd, &event)) {
cerr << "Failed to add RMR descriptor to epoll. " << strerror(errno) << endl;
close(rmr_fd);
rmr_close(rmrCtx);
throw RmrException("Failed to add RMR descriptor to epoll.");
}
}
public:
RmrClient(const char *address, int epoll_fd) {
try {
getRmrContext(address, epoll_fd);
} catch (RmrException &e) {
cout << e.what() << endl;
exit(-1);
}
}
RmrClient() = delete;
RmrClient(const RmrClient &) = delete;
RmrClient &operator=(const RmrClient &) = delete;
RmrClient &operator&&(const RmrClient &) = delete;
inline void *getRmrCtx() const {
return rmrCtx;
}
int getRmrFd() const {
return rmr_fd;
}
inline rmr_mbuf_t *allocateRmrMsg(int size) {return (rmr_alloc_msg(rmrCtx, size));}
static inline void freeRmrMsg(rmr_mbuf_t *msg) {rmr_free_msg(msg);}
};

View File

@@ -0,0 +1,513 @@
/*
* 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 fprintfor 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.
*/
//
// Created by adi ENZEL on 2/10/20.
//
#include "sctpClient.h"
#define READ_BUFFER_SIZE 64 * 1024
using namespace std;
void createHttpLocalSocket(SctpClient_t *sctpClient) {
struct sockaddr_in address{};
int addrlen = sizeof(address);
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(9098);
sctpClient->httpSocket = accept(sctpClient->httpBaseSocket, (struct sockaddr *) &address, (socklen_t *) &addrlen) < 0;
if (sctpClient->httpSocket) {
fprintf(stderr, "Accept() error. %s\n", strerror(errno));
exit(-1);
}
struct epoll_event event{};
event.data.fd = sctpClient->httpSocket;
event.events = (EPOLLIN | EPOLLET);
if (epoll_ctl(sctpClient->epoll_fd, EPOLL_CTL_ADD, sctpClient->httpSocket, &event) < 0) {
fprintf(stderr, "epoll_ctl EPOLL_CTL_ADD, %s\n", strerror(errno));
close(sctpClient->httpSocket);
exit(-1);
}
}
int createEpoll(SctpClient &sctpClient) {
sctpClient.epoll_fd = epoll_create1(0);
if (sctpClient.epoll_fd == -1) {
fprintf(stderr, "failed to open epoll descriptor. %s\n", strerror(errno));
return -1;
}
return sctpClient.epoll_fd;
}
int createSctpConnction(SctpClient *sctpClient, const char *address, int port, bool local) {
sctpClient->sctpSock = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP);
if (sctpClient->sctpSock < 0) {
fprintf(stderr, "Socket Error, %s %s, %d\n", strerror(errno), __func__, __LINE__);
return -1;
}
auto optval = 1;
if (setsockopt(sctpClient->sctpSock, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof optval) != 0) {
fprintf(stderr, "setsockopt SO_REUSEPORT Error, %s %s, %d\n", strerror(errno), __func__, __LINE__);
close(sctpClient->sctpSock);
return -1;
}
optval = 1;
if (setsockopt(sctpClient->sctpSock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval) != 0) {
fprintf(stderr, "setsockopt SO_REUSEADDR Error, %s %s, %d\n", strerror(errno), __func__, __LINE__);
close(sctpClient->sctpSock);
return -1;
}
struct sockaddr_in6 servaddr = {};
// struct addrinfo hints = {};
// struct addrinfo *result;
servaddr.sin6_family = AF_INET6;
servaddr.sin6_port = htons(port); /* daytime server */
inet_pton(AF_INET6, address, &servaddr.sin6_addr);
// the bind here is to maintain the client port this is only if the test is not on the same IP as the tested system
if (!local) {
struct sockaddr_in6 localAddr{};
localAddr.sin6_family = AF_INET6;
localAddr.sin6_addr = in6addr_any;
localAddr.sin6_port = htons(port);
if (bind(sctpClient->sctpSock, (struct sockaddr *) &localAddr, sizeof(struct sockaddr_in6)) < 0) {
fprintf(stderr, "bind Socket Error, %s %s, %d\n", strerror(errno), __func__, __LINE__);
return -1;
}//Ends the binding.
}
// Add to Epol
struct epoll_event event{};
event.data.fd = sctpClient->sctpSock;
event.events = (EPOLLOUT | EPOLLIN | EPOLLET);
if (epoll_ctl(sctpClient->epoll_fd, EPOLL_CTL_ADD, sctpClient->sctpSock, &event) < 0) {
fprintf(stderr, "epoll_ctl EPOLL_CTL_ADD, %s\n", strerror(errno));
close(sctpClient->sctpSock);
return -1;
}
char hostBuff[NI_MAXHOST];
char portBuff[NI_MAXHOST];
if (getnameinfo((SA *) &servaddr, sizeof(servaddr),
hostBuff, sizeof(hostBuff),
portBuff, sizeof(portBuff),
(uint) (NI_NUMERICHOST) | (uint) (NI_NUMERICSERV)) != 0) {
fprintf(stderr, "getnameinfo() Error, %s %s %d\n", strerror(errno), __func__, __LINE__);
return -1;
}
auto flags = fcntl(sctpClient->sctpSock, F_GETFL, 0);
if (flags == -1) {
fprintf(stderr, "fcntl error. %s\n", strerror(errno));
close(sctpClient->sctpSock);
return -1;
}
flags = (unsigned) flags | (unsigned) O_NONBLOCK;
if (fcntl(sctpClient->sctpSock, F_SETFL, flags) == -1) {
fprintf(stderr, "fcntl set O_NONBLOCK fail. %s\n", strerror(errno));
close(sctpClient->sctpSock);
return -1;
}
if (connect(sctpClient->sctpSock, (SA *) &servaddr, sizeof(servaddr)) < 0) {
if (errno != EINPROGRESS) {
fprintf(stderr, "connect FD %d to host : %s port %d, %s\n", sctpClient->sctpSock, address, port,
strerror(errno));
close(sctpClient->sctpSock);
return -1;
}
fprintf(stdout, "Connect to FD %d returned with EINPROGRESS : %s\n", sctpClient->sctpSock, strerror(errno));
}
return sctpClient->sctpSock;
}
__attribute_warn_unused_result__ int createListeningTcpConnection(SctpClient *sctpClient) {
if ((sctpClient->httpBaseSocket = socket(AF_INET, SOCK_STREAM, 0)) == 0) {
fprintf(stderr, "socket failed. %s", strerror(errno));
return -1;
}
struct sockaddr_in address{};
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(9098);
if (bind(sctpClient->httpBaseSocket, (struct sockaddr *)&address, sizeof(address)) < 0) {
fprintf(stderr, "Bind failed , %s %s, %d\n", strerror(errno), __func__, __LINE__);
return -1;
}
struct epoll_event event{};
event.data.fd = sctpClient->httpBaseSocket;
event.events = (EPOLLIN | EPOLLET);
if (epoll_ctl(sctpClient->epoll_fd, EPOLL_CTL_ADD, sctpClient->httpBaseSocket, &event) < 0) {
fprintf(stderr, "epoll_ctl EPOLL_CTL_ADD, %s\n", strerror(errno));
close(sctpClient->httpBaseSocket);
return -1;
}
if (listen(sctpClient->httpBaseSocket, 128) < 0)
{
fprintf(stderr,"listen() error. %s", strerror(errno));
return -1;
}
return 0;
}
__attribute_warn_unused_result__ int modifyEpollToRead(SctpClient *sctpClient, int modifiedSocket) {
struct epoll_event event{};
event.data.fd = modifiedSocket;
event.events = (EPOLLIN | EPOLLET);
if (epoll_ctl(sctpClient->epoll_fd, EPOLL_CTL_MOD, modifiedSocket, &event) < 0) {
fprintf(stderr, "failed to open epoll descriptor. %s\n", strerror(errno));
return -1;
}
return 0;
}
__attribute_warn_unused_result__ cxxopts::ParseResult parse(SctpClient &sctpClient, int argc, const char *argv[]) {
cxxopts::Options options(argv[0], "sctp client test application");
options.positional_help("[optional args]").show_positional_help();
options.allow_unrecognised_options().add_options()
("a,host", "Host address", cxxopts::value<std::string>(sctpClient.host)->default_value("127.0.0.1"))
("p,port", "port number", cxxopts::value<int>(sctpClient.rmrPort)->default_value("38200"))
("h,help", "Print help");
auto result = options.parse(argc, argv);
if (result.count("help")) {
std::cout << options.help({""}) << std::endl;
exit(0);
}
return result;
}
void run(SctpClient_t *sctpClient) {
cout << "in theread" << endl;
sleep(10);
cout << "in theread after sleep" << endl;
sleep(10);
}
void runFunc(SctpClient_t *sctpClient) {
cout << "in theread 1" << endl;
char rmrAddress[128] {};
cout << "in theread 2" << endl;
snprintf(rmrAddress, 128, "%d", sctpClient->rmrPort);
cout << "in theread 3" << endl;
RmrClient rmrClient = {rmrAddress, sctpClient->epoll_fd};
cout << "in theread 4" << endl;
auto *events = (struct epoll_event *) calloc(MAXEVENTS, sizeof(struct epoll_event));
// auto counter = 1000;
// uint64_t st = 0;
// uint32_t aux1 = 0;
// st = rdtscp(aux1);
E2AP_PDU_t *pdu = nullptr;
auto *msg = rmrClient.allocateRmrMsg(8192);
while (true) {
auto numOfEvents = epoll_wait(sctpClient->epoll_fd, events, MAXEVENTS, 1000);
if (numOfEvents < 0) {
if (errno == EINTR) {
fprintf(stderr, "got EINTR : %s\n", strerror(errno));
continue;
}
fprintf(stderr, "Epoll wait failed, errno = %s\n", strerror(errno));
break;
}
if (numOfEvents == 0) { // timeout
// if (--counter <= 0) {
// fprintf(stdout, "Finish waiting for epoll. going out of the thread\n");
// continue;
// }
}
auto done = 0;
for (auto i = 0; i < numOfEvents; i++) {
uint32_t aux1 = 0;
auto start = rdtscp(aux1);
if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP)) {
fprintf(stderr, "Got EPOLLERR or EPOLLHUP on fd = %d, errno = %s\n", events[i].data.fd,
strerror(errno));
close(events[i].data.fd);
} else if (events[i].events & EPOLLOUT) { // AFTER EINPROGRESS
if (modifyEpollToRead(sctpClient, events[i].data.fd) < 0) {
fprintf(stderr, "failed modify FD %d after got EINPROGRESS\n", events[i].data.fd);
close(events[i].data.fd);
continue;
}
fprintf(stdout, "Connected to server after EinProgreevents[i].data.fdss FD %d\n", events[i].data.fd);
//TODO need to define RmrClient class
} else if (events[i].data.fd == sctpClient->httpBaseSocket) {
createHttpLocalSocket(sctpClient);
} else if (events[i].data.fd == sctpClient->httpSocket) {
//TODO handle messages from the http server
char buffer[READ_BUFFER_SIZE] {};
while (true) {
auto size = read(sctpClient->httpSocket, buffer, READ_BUFFER_SIZE);
if (size < 0) {
if (errno == EINTR) {
continue;
}
if (errno != EAGAIN) {
fprintf(stderr, "Read error, %s\n", strerror(errno));
done = 1;
}
break; // EAGAIN exit from loop on read normal way or on read error
}
// we got message get the id of message
char *tmp;
// get mesage type
char *val = strtok_r(buffer, sctpClient->delimiter, &tmp);
messages_t messageType;
char *dummy;
if (val != nullptr) {
messageType = (decltype(messageType))strtol(val, &dummy, 10);
} else {
fprintf(stderr,"wrong message %s", buffer);
break;
}
char sctpLinkId[128] {};
val = strtok_r(nullptr, sctpClient->delimiter, &tmp);
if (val != nullptr) {
memcpy(sctpLinkId, val, tmp - val);
} else {
fprintf(stderr,"wriong id %s", buffer);
break;
}
char *values[128] {};
int index = 0;
while ((val = strtok_r(nullptr, sctpClient->delimiter, &tmp)) != nullptr) {
auto valueLen = tmp - val;
values[index] = (char *)calloc(1, valueLen);
memcpy(values[index], val, valueLen);
index++;
}
values[i] = (char *)calloc(1, strlen(tmp));
switch ((int)messageType) {
case setupRequest_gnb:
case setupRequest_en_gNB:
case setupRequest_ng_eNB:
case setupRequest_eNB: {
char *ricAddress = nullptr;
if (values[0] != nullptr) {
ricAddress = values[0];
} else {
fprintf(stderr,"wrong address %s", buffer);
break;
}
//ric port
int ricPort = 0;
if (values[1] != nullptr) {
ricPort = (decltype(ricPort))strtol(values[1], &dummy, 10);
} else {
fprintf(stderr,"wrong port %s", buffer);
for (auto e : values) {
if (e != nullptr) {
free(e);
}
}
break;
}
// need to send message to E2Term
// build connection
auto fd = createSctpConnction(sctpClient, (const char *)ricAddress, ricPort);
if (fd < 0) {
fprintf(stderr,"Failed to create connection to %s:%d\n", ricAddress, ricPort);
for (auto e : values) {
if (e != nullptr) {
free(e);
}
}
break;
}
auto len = strlen(values[index]);
auto *b64Decoded = (unsigned char *)calloc(1, len);
base64::decode((const unsigned char *)values[index], len, b64Decoded, (long)len);
for (auto e : values) {
if (e != nullptr) {
free(e);
}
}
// send data
while (true) {
if (send(fd, b64Decoded, len, MSG_NOSIGNAL) < 0) {
if (errno == EINTR) {
continue;
}
cerr << "Error sendingdata to e2Term. " << strerror(errno) << endl;
break;
}
cout << "Message sent" << endl;
break;
}
free(b64Decoded);
char key[128] {};
char *value = (char *)calloc(1,256);
snprintf(key, 128, "id:%s", sctpLinkId);
snprintf(value, 16, "%d", fd);
sctpClient->mapKey.setkey(key, (void *)value);
snprintf(key, 128, "fd:%d", fd);
snprintf(&value[128], 128, "%s", sctpLinkId);
sctpClient->mapKey.setkey(key, (void *)&value[128]);
break;
}
case nothing:
default: {
break;
}
}
}
} else if (events[i].data.fd == rmrClient.getRmrFd()) {
msg->state = 0;
msg = rmr_rcv_msg(rmrClient.getRmrCtx(), msg);
if (msg == nullptr) {
cerr << "rmr_rcv_msg return with null pointer" << endl;
exit(-1);
} else if (msg->state != 0) {
cerr << "rmr_rcv_msg return with error status number : " << msg->state << endl;
msg->state = 0;
continue;
}
sleep(100); cout << "Got RMR message number : " << msg->mtype << endl;
} else { // got data from server
/* We RMR_ERR_RETRY have data on the fd waiting to be read. Read and display it.
* We must read whatever data is available completely, as we are running
* in edge-triggered mode and won't get a notification again for the same data. */
//TODO build a callback function to support many tests
if (pdu != nullptr) {
ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
}
unsigned char buffer[SCTP_BUFFER_SIZE]{};
while (true) {
auto len = read(events[i].data.fd, buffer, SCTP_BUFFER_SIZE);
if (len < 0) {
if (errno == EINTR) {
continue;
}
/* If errno == EAGAIN, that means we have read all
data. So go back to the main loop. */
if (errno != EAGAIN) {
fprintf(stderr, "Read error, %s\n", strerror(errno));
done = 1;
}
break; // EAGAIN exit from loop on read normal way or on read error
} else if (len == 0) {
/* End of file. The remote has closed the connection. */
fprintf(stdout, "EOF Closed connection - descriptor = %d", events[i].data.fd);
done = 1;
break;
}
asn_dec_rval_t rval;
rval = asn_decode(nullptr,
ATS_ALIGNED_BASIC_PER,
&asn_DEF_E2AP_PDU,
(void **) &pdu,
buffer,
len);
if (rval.code != RC_OK) {
fprintf(stderr, "Error %d Decoding E2AP PDU from E2TERM\n", rval.code);
break;
}
//TODO handle messages
// switch (pdu->present) {
// case E2AP_PDU_PR_initiatingMessage: {//initiating message
// asnInitiatingRequest(pdu, message, rmrMessageBuffer);
// break;
// }
// case E2AP_PDU_PR_successfulOutcome: { //successful outcome
// asnSuccsesfulMsg(pdu, message, sctpMap, rmrMessageBuffer);
// break;
// }
// case E2AP_PDU_PR_unsuccessfulOutcome: { //Unsuccessful Outcome
// asnUnSuccsesfulMsg(pdu, message, sctpMap, rmrMessageBuffer);
// break;
// ipv6 client server c program }
// case E2AP_PDU_PR_NOTHING:
// default:
// fprintf(stderr, "Unknown index %d in E2AP PDU\n", pdu->present);
// break;
// }
}
}
aux1 = 0;
fprintf(stdout, "one loop took %ld clocks\n", rdtscp(aux1) - start);
}
if (done) {
//TODO report to RMR on closed connection
}
}
return;// nullptr;
}
auto main(const int argc, const char **argv) -> int {
SctpClient_t sctpClient;
//unsigned num_cpus = std::thread::hardware_concurrency();
auto result = parse(sctpClient, argc, argv);
auto epoll_fd = createEpoll(sctpClient);
if (epoll_fd <= 0) {
exit(-1);
}
if (createListeningTcpConnection(&sctpClient) < 0) {
exit(-1);
}
std::thread th(runFunc, &sctpClient);
// std::thread th(run, &sctpClient);
sleep(29);
//start the http server
Port port(9080);
Address addr(Ipv4::any(), port);
HttpServer server(addr);
server.init(1);
server.start();
th.join();
}

View File

@@ -0,0 +1,99 @@
/*
* 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.
*/
//
// Created by adi ENZEL on 2/16/20.
//
#ifndef E2_SCTPCLIENT_H
#define E2_SCTPCLIENT_H
#include <cstdio>
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/file.h>
#include <netdb.h>
#include <sys/epoll.h>
#include <map>
#include "oranE2/E2AP-PDU.h"
#include "../httpServer/HttpServer.h"
#include "../rmrClient/rmrClient.h"
#include "cxxopts/include/cxxopts.hpp"
#include "../base64.h"
#include "../mapWrapper.h"
using namespace std;
using namespace Pistache;
#define SA struct sockaddr
#define MAXEVENTS 128
#define SCTP_BUFFER_SIZE (64*1024)
typedef enum messages {
setupRequest_gnb,
setupRequest_en_gNB,
setupRequest_ng_eNB,
setupRequest_eNB,
nothing
} messages_t;
typedef struct SctpClient {
string host {};
int rmrPort{};
int epoll_fd{};
int sctpSock{};
int httpBaseSocket {};
int httpSocket {};
mapWrapper mapKey;
char delimiter[2] {'|', 0};
} SctpClient_t;
void createHttpLocalSocket(SctpClient_t &sctpClient);
int createEpoll(SctpClient_t &sctpClient);
inline static uint64_t rdtscp(uint32_t &aux) {
uint64_t rax, rdx;
asm volatile ("rdtscp\n" : "=a" (rax), "=d" (rdx), "=c" (aux) : :);
return (rdx << (unsigned) 32) + rax;
}
int createSctpConnction(SctpClient_t *sctpClient, const char *address, int port, bool local = true);
__attribute_warn_unused_result__ int createListeningTcpConnection(SctpClient_t *sctpClient);
int modifyEpollToRead(SctpClient_t *sctpClient, int modifiedSocket);
cxxopts::ParseResult parse(SctpClient_t &sctpClient, int argc, const char *argv[]);
#endif //E2_SCTPCLIENT_H

View File

@@ -0,0 +1,91 @@
/*
* 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.
*/
//
// Created by adi ENZEL on 2/10/20.
//
#include <thread>
#include <vector>
#include <cgreen/cgreen.h>
//#include "sctpClient.cpp"
int epoll_fd = 0;
Describe(Cgreen);
BeforeEach(Cgreen) {}
AfterEach(Cgreen) {
close(epoll_fd);
}
using namespace cgreen;
using namespace std;
Ensure(Cgreen, createEpoll) {
epoll_fd = createEpoll();
assert_that(epoll_fd != -1);
assert_that(epoll_fd > 0);
}
Ensure(Cgreen, createConnectionIpV6) {
auto epoll_fd = createEpoll();
assert_that(epoll_fd != -1);
assert_that(epoll_fd > 0);
unsigned num_cpus = std::thread::hardware_concurrency();
std::vector<std::thread> threads(num_cpus);
// int i = 0;
// threads[i] = std::thread(listener, &epoll_fd);
// auto port = 36422;
// auto fd = createSctpConnction("::1", port, epoll_fd);
// assert_that(fd != -1);
// assert_that(fd == 0);
// threads[i].join();
//
// close(fd);
}
Ensure(Cgreen, createConnectionIpV4) {
auto epoll_fd = createEpoll();
assert_that(epoll_fd != -1);
assert_that(epoll_fd > 0);
unsigned num_cpus = std::thread::hardware_concurrency();
std::vector<std::thread> threads(num_cpus);
// int i = 0;
// threads[i] = std::thread(listener, &epoll_fd);
// auto port = 36422;
// auto fd = createSctpConnction("127.0.0.1", port, epoll_fd);
// assert_that(fd != -1);
// assert_that(fd == 0);
//
// threads[i].join();
// close(fd);
}
//int main(const int argc, char **argv) {
// TestSuite *suite = create_named_test_suite_(__FUNCTION__, __FILE__, __LINE__);
//
// add_test_with_context(suite, Cgreen, createEpoll);
// //add_test_with_context(suite, Cgreen, createConnectionIpV6);
// add_test_with_context(suite, Cgreen, createConnectionIpV4);
// return cgreen::run_test_suite(suite, create_text_reporter());
//}

View File

@@ -0,0 +1,264 @@
/*
* 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 <cstring>
#include <cstdio>
#include <cerrno>
#include <cstdlib>
#include <iostream>
//#include <mdclog/mdclog.h>
#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 = "<E2AP-PDU>\n"
" <successfulOutcome>\n"
" <procedureCode>1</procedureCode>\n"
" <criticality><reject/></criticality>\n"
" <value>\n"
" <E2setupResponse>\n"
" <protocolIEs>\n"
" <E2setupResponseIEs>\n"
" <id>4</id>\n"
" <criticality><reject/></criticality>\n"
" <value>\n"
" <GlobalRIC-ID>\n"
" <pLMN-Identity>13 10 14</pLMN-Identity>\n"
" <ric-ID>\n"
" 10011001101010101011"
" </ric-ID>\n"
" </GlobalRIC-ID>\n"
" </value>\n"
" </E2setupResponseIEs>\n"
" <E2setupResponseIEs>\n"
" <id>9</id>\n"
" <criticality><reject/></criticality>\n"
" <value>\n"
" <RANfunctionsID-List>\n"
" <ProtocolIE-SingleContainer>\n"
" <id>6</id>\n"
" <criticality><ignore/></criticality>\n"
" <value>\n"
" <RANfunctionID-Item>\n"
" <ranFunctionID>1</ranFunctionID>\n"
" <ranFunctionRevision>1</ranFunctionRevision>\n"
" </RANfunctionID-Item>\n"
" </value>\n"
" </ProtocolIE-SingleContainer>\n"
" <ProtocolIE-SingleContainer>\n"
" <id>6</id>\n"
" <criticality><ignore/></criticality>\n"
" <value>\n"
" <RANfunctionID-Item>\n"
" <ranFunctionID>2</ranFunctionID>\n"
" <ranFunctionRevision>1</ranFunctionRevision>\n"
" </RANfunctionID-Item>\n"
" </value>\n"
" </ProtocolIE-SingleContainer>\n"
" <ProtocolIE-SingleContainer>\n"
" <id>6</id>\n"
" <criticality><ignore/></criticality>\n"
" <value>\n"
" <RANfunctionID-Item>\n"
" <ranFunctionID>3</ranFunctionID>\n"
" <ranFunctionRevision>1</ranFunctionRevision>\n"
" </RANfunctionID-Item>\n"
" </value>\n"
" </ProtocolIE-SingleContainer>\n"
" </RANfunctionsID-List>\n"
" </value>\n"
" </E2setupResponseIEs>\n"
" </protocolIEs>\n"
" </E2setupResponse>\n"
" </value>\n"
" </successfulOutcome>\n"
"</E2AP-PDU>\n";
std::string newXml =
"<E2AP-PDU><successfulOutcome><procedureCode>1</procedureCode><criticality><reject/></criticality><value><E2setupResponse><protocolIEs><E2setupResponseIEs><id>4</id><criticality><reject/></criticality><value><GlobalRIC-ID><pLMN-Identity>13 10 14</pLMN-Identity><ric-ID>10101010110011001110</ric-ID></GlobalRIC-ID></value></E2setupResponseIEs><E2setupResponseIEs><id>9</id><criticality><reject/></criticality><value><RANfunctionsID-List><ProtocolIE-SingleContainer><id>6</id><criticality><ignore/></criticality><value><RANfunctionID-Item><ranFunctionID>1</ranFunctionID><ranFunctionRevision>1</ranFunctionRevision></RANfunctionID-Item></value></ProtocolIE-SingleContainer><ProtocolIE-SingleContainer><id>6</id><criticality><ignore/></criticality><value><RANfunctionID-Item><ranFunctionID>2</ranFunctionID><ranFunctionRevision>1</ranFunctionRevision></RANfunctionID-Item></value></ProtocolIE-SingleContainer><ProtocolIE-SingleContainer><id>6</id><criticality><ignore/></criticality><value><RANfunctionID-Item><ranFunctionID>3</ranFunctionID><ranFunctionRevision>1</ranFunctionRevision></RANfunctionID-Item></value></ProtocolIE-SingleContainer></RANfunctionsID-List></value></E2setupResponseIEs></protocolIEs></E2setupResponse></value></successfulOutcome></E2AP-PDU>";
std::string setupFailure = "<E2AP-PDU>"
"<unsuccessfulOutcome>"
"<procedureCode>1</procedureCode>"
"<criticality><reject/></criticality>"
"<value>"
"<E2setupFailure>"
"<protocolIEs>"
"<E2setupFailureIEs>"
"<id>1</id>"
"<criticality><reject/></criticality>"
"<value>"
"<Cause>"
"<transport>"
"<transport-resource-unavailable/>"
"</transport>"
"</Cause>"
"</value>"
"</E2setupFailureIEs>"
"</protocolIEs>"
"</E2setupFailure>"
"</value>"
"</unsuccessfulOutcome>"
"</E2AP-PDU>";
std::string otherSucc = " <E2AP-PDU>"
"<successfulOutcome>"
"<procedureCode>1</procedureCode>"
"<criticality><reject/></criticality>"
"<value>"
"<E2setupResponse>"
"<protocolIEs>"
"<E2setupResponseIEs>"
"<id>4</id>"
"<criticality><reject/></criticality>"
"<value>"
"<GlobalRIC-ID>"
"<pLMN-Identity>131014</pLMN-Identity>"
"<ric-ID>10101010110011001110</ric-ID>"
"</GlobalRIC-ID>"
"</value>"
"</E2setupResponseIEs><E2setupResponseIEs><id>9</id><criticality><reject/></criticality><value><RANfunctionsID-List><ProtocolIE-SingleContainer><id>6</id><criticality><ignore/></criticality><value><RANfunctionID-Item><ranFunctionID>1</ranFunctionID><ranFunctionRevision>1</ranFunctionRevision></RANfunctionID-Item></value></ProtocolIE-SingleContainer><ProtocolIE-SingleContainer><id>6</id><criticality><ignore/></criticality><value><RANfunctionID-Item><ranFunctionID>2</ranFunctionID><ranFunctionRevision>1</ranFunctionRevision></RANfunctionID-Item></value></ProtocolIE-SingleContainer><ProtocolIE-SingleContainer><id>6</id><criticality><ignore/></criticality><value><RANfunctionID-Item><ranFunctionID>3</ranFunctionID><ranFunctionRevision>1</ranFunctionRevision></RANfunctionID-Item></value></ProtocolIE-SingleContainer></RANfunctionsID-List></value></E2setupResponseIEs></protocolIEs></E2setupResponse></value></successfulOutcome></E2AP-PDU>";
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 << otherXml << endl << "========================" << endl;
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);
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 7/8/19.
//
#include <mdclog/mdclog.h>
#include "../../asn1cFiles/E2AP-PDU.h"
void init_log()
{
mdclog_attr_t *attr;
mdclog_attr_init(&attr);
mdclog_attr_set_ident(attr, "e2smTests");
mdclog_init(attr);
mdclog_attr_destroy(attr);
}
int main(const int argc, char **argv) {
init_log();
//mdclog_level_set(MDCLOG_WARN);
mdclog_level_set(MDCLOG_DEBUG);
E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2019 AT&T Intellectual Property
* Copyright 2019 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
//
// Created by adi ENZEL on 7/8/19.
//
#include <mdclog/mdclog.h>
#include "../../asn1cFiles/E2AP-PDU.h"
void init_log()
{
mdclog_attr_t *attr;
mdclog_attr_init(&attr);
mdclog_attr_set_ident(attr, "e2smTests");
mdclog_init(attr);
mdclog_attr_destroy(attr);
}
int main(const int argc, char **argv) {
init_log();
//mdclog_level_set(MDCLOG_WARN);
mdclog_level_set(MDCLOG_DEBUG);
E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
}