Commit c9e3c590 authored by juvancic's avatar juvancic
Browse files

Added NGAP protocol support

parent f71ffbfa
Loading
Loading
Loading
Loading
+62 −0
Original line number Diff line number Diff line
/*!
 * \file      codec.hh
 * \brief     Header file for ITS abstract codec definition.
 * \author    ETSI STF525
 * \copyright ETSI Copyright Notification
 *            No part may be reproduced except as authorized by written permission.
 *            The copyright and the foregoing restriction extend to reproduction in all media.
 *            All rights reserved.
 * \version   0.1
 */
#pragma once

///#include "params_its.hh"
#include "t_layer.hh"

class OCTETSTRING; //! Declare TITAN class
class CHARSTRING;  //! Declare TITAN class
class BITSTRING;   //! Declare TITAN class

/*!
 * \class codec
 * \brief  This class provides the interface for all ITS codecs, include UT and AC codecs
 * \abstract
 */
template <typename TPDUEnc, typename TPDUDec> class codec {
protected:
  params *_params; //! Reference to params stack
                       // \todo Use smart pointer std::unique_ptr<params>

public: //! \publicsection
  /*!
   * \fn codec();
   * \brief  Default constructor
   * \todo Remove logs
   */
  explicit codec() : _params(nullptr){};
  /*!
   * \fn ~codec();
   * \brief  Default destructor
   * \virtual
   * \todo Remove logs
   */
  virtual ~codec(){};
  /*!
   * \fn int encode(const TPDUEnc& msg, OCTETSTRING& data);
   * \brief  Encode typed message into an octet string
   * \param[in] p_message The typed message to be encoded
   * \param[out] p_data The encoding result
   * \return 0 on success, -1 otherwise
   * \pure
   */
  virtual int encode(const TPDUEnc &p_message, OCTETSTRING &p_data) ;//= 0;
  /*!
   * \fn int decode(const OCTETSTRING& p_, TPDUDec& p_message, params_its* p_params = NULL);
   * \brief  Encode typed message into an octet string format
   * \param[in] p_data The message in its octet string
   * \param[out] p_message The decoded typed message
   * \return 0 on success, -1 otherwise
   * \pure
   */
  virtual int decode(const OCTETSTRING &p_, TPDUDec &p_message, params *p_params = NULL) ;//= 0;
}; // End of class codec
+2 −0
Original line number Diff line number Diff line
sources := ngap_codec.cc ngap_pdu_codec.cc
includes := .
+76 −0
Original line number Diff line number Diff line
/*!
 * \file      ngap_codec.cc
 * \brief     CC file for NGAP protocol codec.
 * \author    ETSI TTF041
 * \copyright ETSI Copyright Notification
 *            No part may be reproduced except as authorized by written permission.
 *            The copyright and the foregoing restriction extend to reproduction in all media.
 *            All rights reserved.
 * \version   0.1
 */


#include "ngap_codec.hh"
#include "LibNGAP_TypesAndValues.hh"
#include "asn1/asn_application.h" // from asn1c
#include "loggers.hh"
#include "NGAP_PDU_Descriptions.hh"
#include "NGAP_IEs.hh"

template <typename T_type> class OPTIONAL;
class TTCN_EncDec;


//int ngap_codec::encode(const NGAP__PDU__Descriptions::NGAP__PDU , OCTETSTRING &data) {return 0;}
int ngap_codec::encode(const NGAP__PDU__Descriptions::NGAP__PDU& ngap, OCTETSTRING &data) {

  BITSTRING b;
  int       rc = asn_codec.encode(ngap, b);
  
  if (rc>0) {
      data = bit2oct(b);
  }else{
    //encode failed
  }
  return rc;
}

int ngap_codec::encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer) {
   loggers::get_instance().log(">>> ngap_codec::encode_: processing %s/%s", type.get_descriptor()->name, field_descriptor.name);
   loggers::get_instance().log_msg(">>> ngap_codec::encode_: ", type);

  return 0;
}



//int ngap_codec::decode(const OCTETSTRING &data, NGAP__PDU__Descriptions::NGAP__PDU &ngap, params_ *params) {return 0;}
int ngap_codec::decode(const OCTETSTRING &data, NGAP__PDU__Descriptions::NGAP__PDU &ngap, params *params) {

  int rc = asn_codec.decode(oct2bit(data), ngap);

  if (rc>0) {
  }else{
    //decode failed
  }
  return rc;
}

int ngap_codec::decode_(Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &decoding_buffer) {
   loggers::get_instance().log(">>> ngap_codec::decode_: processing %s/%s (%d,%d,%p)", type.get_descriptor()->name, field_descriptor.name,
   decoding_buffer.get_len(), decoding_buffer.get_pos(), decoding_buffer.get_read_data());

  return 0;
}

int ngap_codec::decode(const OCTETSTRING &data, NGAP__IEs::PDUSessionResourceSetupResponseTransfer &ie, params *params){
  
  int rc=1;
  //int rc = asn_codec.decode(oct2bit(data), ie);
  
  if (rc>0) {
  }else{
  }

  return 0;
}
+55 −0
Original line number Diff line number Diff line
/*!
 * \file      ngap_codec.hh
 * \brief     Header file for NGAP protocol codec.
 * \author    ETSI TTF041
 * \copyright ETSI Copyright Notification
 *            No part may be reproduced except as authorized by written permission.
 *            The copyright and the foregoing restriction extend to reproduction in all media.
 *            All rights reserved.
 * \version   0.1
 */

#pragma once

#include "LibNGAP_TypesAndValues.hh"
#include "ngap_pdu_codec.hh"
//#include "codec.hh"
#include "NGAP_PDU_Descriptions.hh"
#include "NGAP_IEs.hh"

class BITSTRING;   //! Forward declaration of TITAN class
class OCTETSTRING; //! Forward declaration of TITAN class
//class params_;

class Base_Type;
class TTCN_Typedescriptor_t;
class TTCN_Buffer;


//namespace NGAP__PDU__Descriptions { //! Forward declaration of asn1c NGAP class
//  class NGAP__PDU;
//}

//class ngap_codec : public codec<NGAP__PDU__Descriptions::NGAP__PDU, NGAP__PDU__Descriptions::NGAP__PDU> {
class ngap_codec {
  ngap_pdu_codec asn_codec;

  int encode_(const Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &encoding_buffer);

  int decode_(Base_Type &type, const TTCN_Typedescriptor_t &field_descriptor, TTCN_Buffer &decoding_buffer);


public:
  //explicit ngap_codec() : codec<NGAP__PDU__Descriptions::NGAP__PDU, NGAP__PDU__Descriptions::NGAP__PDU>(), asn_codec(){};
  /*explicit*/ ngap_codec() :  asn_codec(){};
  virtual ~ngap_codec(){};

  /*virtual*/ int encode(const NGAP__PDU__Descriptions::NGAP__PDU& ngap, OCTETSTRING &data);
  /*virtual*/ int decode(const OCTETSTRING &data, NGAP__PDU__Descriptions::NGAP__PDU &, params *params = NULL);
  
  /*NGAP_IEs*/
  /*virtual*/ int decode(const OCTETSTRING &data, NGAP__IEs::PDUSessionResourceSetupResponseTransfer &, params *params = NULL);

};

+36 −0
Original line number Diff line number Diff line
/*!
 * \file      ngap_pdu_codec.cc
 * \brief     CC file for NGAP PDU protocol codec.
 * \author    ETSI TTF041
 * \copyright ETSI Copyright Notification
 *            No part may be reproduced except as authorized by written permission.
 *            The copyright and the foregoing restriction extend to reproduction in all media.
 *            All rights reserved.
 * \version   0.1
 */

#include "ngap_pdu_codec.hh"
#include "LibNGAP_TypesAndValues.hh"
#include "asn1/asn_application.h" // from asn1c
#include "loggers.hh"
#include "NGAP_PDU_Descriptions.hh"
#include "TTCN3.hh"
#include <errno.h>
extern "C" {
extern asn_TYPE_descriptor_s asn_DEF_NGAP_PDU;
}
extern "C" {
static int asn1c_collect_encoded_data(const void *buffer, size_t size, void *application_specific_key) {
  TTCN_Buffer *tb = (TTCN_Buffer *)application_specific_key;
  tb->put_s(size, (unsigned char *)buffer);
  return 0;
}
}

int ngap_pdu_codec::encode(const NGAP__PDU__Descriptions::NGAP__PDU &p_ngap, BITSTRING &p_data) {
  return _encode(NGAP__PDU__Descriptions::NGAP__PDU_descr_, asn_DEF_NGAP_PDU, p_ngap, p_data);
}

int ngap_pdu_codec::decode(const BITSTRING &p_data, NGAP__PDU__Descriptions::NGAP__PDU &p_ngap) {
  return  _decode(NGAP__PDU__Descriptions::NGAP__PDU_descr_, asn_DEF_NGAP_PDU, p_data, p_ngap);
}
Loading