Commit 7bcdc95e authored by Yann Garcia's avatar Yann Garcia
Browse files

Start implementing bases for AtsAVM

parent 9e0608be
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
Copyright 2019-2024 ETSI
Copyright 2019-2026 ETSI

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:
+7 −0
Original line number Diff line number Diff line
{
    "folders": [
        {
            "path": "."
        }
    ]
}
 No newline at end of file
+70 −0
Original line number Diff line number Diff line
#include <TTCN3.hh>

#include "loggers.hh"
#include "registration.hh"

#include "AdapterControlPort_AVM.hh"
#include "cam_layer.hh"

//=============================================================================
namespace LibItsAvm__TestSystem {

  AdapterControlPort::AdapterControlPort(const char *par_port_name) : AdapterControlPort_BASE(par_port_name) {}

  AdapterControlPort::~AdapterControlPort() {}

  void AdapterControlPort::set_parameter(const char * /*parameter_name*/, const char * /*parameter_value*/) {}

  /*void AdapterControlPort::Handle_Fd_Event(int fd, boolean is_readable,
          boolean is_writable, boolean is_error) {}*/

  void AdapterControlPort::Handle_Fd_Event_Error(int /*fd*/) {}

  void AdapterControlPort::Handle_Fd_Event_Writable(int /*fd*/) {}

  void AdapterControlPort::Handle_Fd_Event_Readable(int /*fd*/) {}

  /*void AdapterControlPort::Handle_Timeout(double time_since_last_call) {}*/

  void AdapterControlPort::user_map(const char * /*system_port*/) {}

  void AdapterControlPort::user_unmap(const char * /*system_port*/) {}

  void AdapterControlPort::user_start() {}

  void AdapterControlPort::user_stop() {}

  void AdapterControlPort::outgoing_send(const LibItsCommon__TypesAndValues::AcGnssPrimitive & /*send_par*/) {}

  void AdapterControlPort::outgoing_send(const LibItsCommon__TypesAndValues::AcSecPrimitive &send_par) {
    loggers::get_instance().log_msg(">>> AdapterControlPort::outgoing_send: ", send_par);

    // Register this object for AdapterControlPort
    cam_layer *p = registration<cam_layer>::get_instance().get_item(std::string("AVM"));
    if (p != NULL) {
      loggers::get_instance().log("AdapterControlPort::outgoing_send: Got AVM layer %p", p);
      LibItsCommon__TypesAndValues::AdapterControlResults response;
      response.acSecResponse() = BOOLEAN(true);
      if (send_par.ischosen(LibItsCommon__TypesAndValues::AcSecPrimitive::ALT_acEnableSecurity)) {
        loggers::get_instance().log("AdapterControlPort::outgoing_send: Enable secured mode");
        std::string str(static_cast<const char *>(send_par.acEnableSecurity().certificateId()));
        if (p->enable_secured_mode(str, send_par.acEnableSecurity().enforceSecurity()) == -1) {
          response.acSecResponse() = BOOLEAN(false);
        }
      } else if (send_par.ischosen(LibItsCommon__TypesAndValues::AcSecPrimitive::ALT_acDisableSecurity)) {
        loggers::get_instance().log("AdapterControlPort::outgoing_send: Disable secured mode");
        if (p->disable_secured_mode() == -1) {
          response.acSecResponse() = BOOLEAN(false);
        }
      } else {
        response.acSecResponse() = BOOLEAN(false);
      }
      // Send response
      loggers::get_instance().log_msg("AdapterControlPort::outgoing_send: Send response: ", response);
      incoming_message(response);
    } else {
      loggers::get_instance().error("AdapterControlPort::outgoing_send: AVM not registered");
    }
  }

} // namespace LibItsAvm__TestSystem
+36 −0
Original line number Diff line number Diff line
#ifndef AdapterControlPort_AVM_HH
#define AdapterControlPort_AVM_HH
//=============================================================================
#include "LibItsAvm_TestSystem.hh"

namespace LibItsAvm__TestSystem {

  class AdapterControlPort : public AdapterControlPort_BASE {
  public:
    AdapterControlPort(const char *par_port_name = NULL);
    ~AdapterControlPort();

    void set_parameter(const char *parameter_name, const char *parameter_value);

  private:
    /* void Handle_Fd_Event(int fd, boolean is_readable,
            boolean is_writable, boolean is_error); */
    void Handle_Fd_Event_Error(int fd);
    void Handle_Fd_Event_Writable(int fd);
    void Handle_Fd_Event_Readable(int fd);
    /* void Handle_Timeout(double time_since_last_call); */
  protected:
    void user_map(const char *system_port);
    void user_unmap(const char *system_port);

    void user_start();
    void user_stop();

    void outgoing_send(const LibItsCommon__TypesAndValues::AcGnssPrimitive &send_par);

    void outgoing_send(const LibItsCommon__TypesAndValues::AcSecPrimitive &send_par);
  };

} // namespace LibItsAvm__TestSystem

#endif
+90 −0
Original line number Diff line number Diff line
// This Test Port skeleton source file was generated by the
// TTCN-3 Compiler of the TTCN-3 Test Executor version CRL 113 200/5 R3A
// for U-ERICSSON\ethgry (ethgry@HU00078339) on Fri Aug 14 16:32:05 2015

// Copyright Ericsson Telecom AB 2000-2014

// You may modify this file. Complete the body of empty functions and
// add your member functions here.

#include "CamPort.hh"
#include "cam_layer_factory.hh"
#include "loggers.hh"

namespace LibItsCam__TestSystem {

  CamPort::CamPort(const char *par_port_name)
    : CamPort_BASE(par_port_name), _cfg_params(), _layer_params(), _layer(NULL), _time_key("CamPort::outgoing_send") {}

  CamPort::~CamPort() {
    if (_layer != NULL) {
      delete _layer;
    }
  }

  void CamPort::set_parameter(const char *parameter_name, const char *parameter_value) {
    loggers::get_instance().log("CamPort::set_parameter: %s=%s", parameter_name, parameter_value);
    _cfg_params.insert(std::pair<std::string, std::string>(std::string(parameter_name), std::string(parameter_value)));
  }

  /*void CamPort::Handle_Fd_Event(int fd, boolean is_readable,
    boolean is_writable, boolean is_error) {}*/

  void CamPort::Handle_Fd_Event_Error(int /*fd*/) {}

  void CamPort::Handle_Fd_Event_Writable(int /*fd*/) {}

  void CamPort::Handle_Fd_Event_Readable(int /*fd*/) {}

  /*void CamPort::Handle_Timeout(double time_since_last_call) {}*/

  void CamPort::user_map(const char *system_port) {
    loggers::get_instance().log(">>> CamPort::user_map: %s", system_port);
    // Build layer stack
    params_its::iterator it = _cfg_params.find(std::string("params"));
    if (it != _cfg_params.end()) {
      loggers::get_instance().log("CamPort::user_map: %s", it->second.c_str());
      // Setup parameters
      params_its::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless
      // Create layer
      _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str());
      if (static_cast<cam_layer *>(_layer) == NULL) {
        loggers::get_instance().error("CamPort::user_map: Invalid stack configuration: %s", it->second.c_str());
      }
      static_cast<cam_layer *>(_layer)->add_upper_port(this);
    } else {
      loggers::get_instance().error("CamPort::user_map: No layers defined in configuration file");
    }
  }

  void CamPort::user_unmap(const char *system_port) {
    loggers::get_instance().log(">>> CamPort::user_unmap: %s", system_port);
    if (_layer != NULL) {
      delete _layer;
      _layer = NULL;
    }
  }

  void CamPort::user_start() {}

  void CamPort::user_stop() {}

  void CamPort::outgoing_send(const LibItsCam__TypesAndValues::CamReq &send_par) {
    loggers::get_instance().log_msg(">>> CamPort::outgoing_send: payload=", send_par);

    float duration;
    loggers::get_instance().set_start_time(_time_key);
    params_its params;
    static_cast<cam_layer *>(_layer)->sendMsg(send_par, params);
    loggers::get_instance().set_stop_time(_time_key, duration);
  }

  void CamPort::receiveMsg(const LibItsCam__TypesAndValues::CamInd &p_ind, const params& p_params) {
    //loggers::get_instance().log_msg(">>> CamPort::receive_msg: ", p_ind);
    const params_its& p = static_cast<const params_its&>(p_params);
    loggers::get_instance().log(">>> CamPort::receive_msg: %s", p.station_id.c_str());

    incoming_message(p_ind);
  }

} // namespace LibItsCam__TestSystem
Loading