srsLTE/srsenb/test/upper/plmn_test.cc

137 lines
4.6 KiB
C++
Raw Normal View History

/**
2017-06-01 03:25:57 -07:00
*
* \section COPYRIGHT
2017-06-01 03:25:57 -07:00
*
2021-03-19 03:45:56 -07:00
* Copyright 2013-2021 Software Radio Systems Limited
2019-04-26 12:27:38 -07:00
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
2017-06-01 03:25:57 -07:00
*
*/
#include "srsenb/hdr/common/common_enb.h"
2021-03-19 03:45:56 -07:00
#include "srsran/asn1/rrc/common.h"
#include "srsran/asn1/rrc_utils.h"
#include "srsran/common/bcd_helpers.h"
#include "srsran/interfaces/rrc_interface_types.h"
2020-05-20 12:16:06 -07:00
#include <arpa/inet.h> //for inet_ntop()
2019-01-17 03:42:01 -08:00
#include <iostream>
2017-06-01 03:25:57 -07:00
2019-01-17 03:42:01 -08:00
using namespace asn1::rrc;
#define TESTASSERT(cond) \
{ \
if (!(cond)) { \
std::cout << "[" << __FUNCTION__ << "][Line " << __LINE__ << "]: FAIL at " << (#cond) << std::endl; \
return -1; \
} \
}
int rrc_plmn_test()
2017-06-01 03:25:57 -07:00
{
2019-01-17 03:42:01 -08:00
plmn_id_s plmn_in, plmn_out;
uint8_t ref[3] = {0x89, 0x19, 0x14};
uint8_t byte_buf[4];
2017-06-01 03:25:57 -07:00
// 2-digit MNC test
asn1::cbit_ref bref_out(&ref[0], sizeof(ref));
2019-01-17 03:42:01 -08:00
plmn_out.unpack(bref_out);
TESTASSERT(plmn_out.mcc_present);
uint16_t mcc, mnc;
2021-03-19 03:45:56 -07:00
srsran::bytes_to_mcc(&plmn_out.mcc[0], &mcc);
srsran::bytes_to_mnc(&plmn_out.mnc[0], &mnc, plmn_out.mnc.size());
2019-01-17 03:42:01 -08:00
TESTASSERT(mcc == 0xF123);
TESTASSERT(mnc == 0xFF45);
// Test MCC/MNC --> vector
plmn_in.mcc_present = plmn_out.mcc_present;
2021-03-19 03:45:56 -07:00
TESTASSERT(srsran::mcc_to_bytes(mcc, &plmn_in.mcc[0]));
TESTASSERT(srsran::mnc_to_bytes(mnc, plmn_in.mnc));
2019-01-17 03:42:01 -08:00
TESTASSERT(plmn_in.mcc_present == plmn_out.mcc_present);
TESTASSERT(plmn_in.mcc == plmn_out.mcc);
TESTASSERT(plmn_in.mnc == plmn_out.mnc);
// Test plmn --> string
2021-03-19 03:45:56 -07:00
srsran::plmn_id_t srsplmn_out = srsran::make_plmn_id_t(plmn_out);
TESTASSERT(srsplmn_out.to_string() == "12345");
2019-01-17 03:42:01 -08:00
asn1::bit_ref bref_in(&byte_buf[0], sizeof(byte_buf));
asn1::bit_ref bref_in0(&byte_buf[0], sizeof(byte_buf));
plmn_out.pack(bref_in);
TESTASSERT(bref_in.distance() == bref_out.distance());
2019-01-17 03:42:01 -08:00
TESTASSERT(memcmp(&ref[0], &byte_buf[0], sizeof(ref)) == 0);
2017-06-01 03:25:57 -07:00
// 3-digit MNC test
2021-03-19 03:45:56 -07:00
TESTASSERT(srsran::mnc_to_bytes(0xF456, plmn_in.mnc));
2019-01-17 03:42:01 -08:00
bref_in = asn1::bit_ref(&byte_buf[0], sizeof(byte_buf));
plmn_in.pack(bref_in);
uint8_t ref2[4] = {0x89, 0x1D, 0x15, 0x80};
TESTASSERT(bref_in.distance(bref_in0) == (1 + 3 * 4 + 1 + 3 * 4));
TESTASSERT(memcmp(&byte_buf[0], &ref2[0], sizeof(ref)) == 0);
bref_out = asn1::cbit_ref(&ref2[0], sizeof(ref2));
2019-01-17 03:42:01 -08:00
plmn_out.unpack(bref_out);
TESTASSERT(plmn_in.mcc_present == plmn_out.mcc_present);
TESTASSERT(plmn_in.mcc == plmn_out.mcc);
TESTASSERT(plmn_in.mnc == plmn_out.mnc);
return 0;
2017-06-01 03:25:57 -07:00
}
2019-01-17 03:42:01 -08:00
int s1ap_plmn_test()
2017-06-01 03:25:57 -07:00
{
2020-05-20 12:16:06 -07:00
uint16_t mcc = 0xF123;
uint16_t mnc = 0xFF45;
uint32_t plmn;
2021-03-19 03:45:56 -07:00
srsran::plmn_id_t srsran_plmn, srsran_plmn2;
2020-05-20 12:16:06 -07:00
asn1::fixed_octstring<3, true> s1ap_plmn{};
2017-06-01 03:25:57 -07:00
// 2-digit MNC test
2021-03-19 03:45:56 -07:00
srsran::s1ap_mccmnc_to_plmn(mcc, mnc, &plmn);
2019-01-17 03:42:01 -08:00
TESTASSERT(plmn == 0x21F354);
2021-03-19 03:45:56 -07:00
srsran::s1ap_plmn_to_mccmnc(plmn, &mcc, &mnc);
2019-01-17 03:42:01 -08:00
TESTASSERT(mcc == 0xF123);
TESTASSERT(mnc == 0xFF45);
2017-06-01 03:25:57 -07:00
2020-05-20 12:16:06 -07:00
// Test MCC/MNC --> S1AP
2021-03-19 03:45:56 -07:00
srsran_plmn.from_number(mcc, mnc);
TESTASSERT(srsran_plmn.to_string() == "12345");
srsran::to_asn1(&s1ap_plmn, srsran_plmn);
2020-05-20 12:16:06 -07:00
TESTASSERT(s1ap_plmn[0] == ((uint8_t*)&plmn)[2]);
TESTASSERT(s1ap_plmn[1] == ((uint8_t*)&plmn)[1]);
TESTASSERT(s1ap_plmn[2] == ((uint8_t*)&plmn)[0]);
2021-03-19 03:45:56 -07:00
srsran_plmn2 = srsran::make_plmn_id_t(s1ap_plmn);
TESTASSERT(srsran_plmn2 == srsran_plmn);
2020-05-20 12:16:06 -07:00
2017-06-01 03:25:57 -07:00
// 3-digit MNC test
mnc = 0xF456;
2021-03-19 03:45:56 -07:00
srsran::s1ap_mccmnc_to_plmn(mcc, mnc, &plmn);
2020-05-20 12:16:06 -07:00
TESTASSERT(plmn == 0x214365);
2021-03-19 03:45:56 -07:00
srsran::s1ap_plmn_to_mccmnc(plmn, &mcc, &mnc);
2019-01-17 03:42:01 -08:00
TESTASSERT(mcc == 0xF123);
TESTASSERT(mnc == 0xF456);
2020-05-20 12:16:06 -07:00
// Test MCC/MNC --> S1AP
2021-03-19 03:45:56 -07:00
srsran_plmn.from_number(mcc, mnc);
TESTASSERT(srsran_plmn.to_string() == "123456");
srsran::to_asn1(&s1ap_plmn, srsran_plmn);
2020-05-20 12:16:06 -07:00
TESTASSERT(s1ap_plmn[0] == ((uint8_t*)&plmn)[2]);
TESTASSERT(s1ap_plmn[1] == ((uint8_t*)&plmn)[1]);
TESTASSERT(s1ap_plmn[2] == ((uint8_t*)&plmn)[0]);
2021-03-19 03:45:56 -07:00
srsran_plmn2 = srsran::make_plmn_id_t(s1ap_plmn);
TESTASSERT(srsran_plmn2 == srsran_plmn);
2020-05-20 12:16:06 -07:00
2019-01-17 03:42:01 -08:00
return 0;
2017-06-01 03:25:57 -07:00
}
int main(int argc, char** argv)
2017-06-01 03:25:57 -07:00
{
2019-01-17 03:42:01 -08:00
TESTASSERT(rrc_plmn_test() == 0);
TESTASSERT(s1ap_plmn_test() == 0);
return 0;
2017-06-01 03:25:57 -07:00
}