From a4b8e0c68e49564200404810d0ca36fb426fbb56 Mon Sep 17 00:00:00 2001 From: Moran Shoeg Date: Thu, 31 Oct 2019 10:54:51 +0200 Subject: [PATCH] agent: Add agent_ucc_listener implementation Signed-off-by: Moran Shoeg --- .../src/beerocks/slave/agent_ucc_listener.cpp | 133 ++++++++++++++++++ agent/src/beerocks/slave/agent_ucc_listener.h | 49 +++++++ 2 files changed, 182 insertions(+) create mode 100644 agent/src/beerocks/slave/agent_ucc_listener.cpp create mode 100644 agent/src/beerocks/slave/agent_ucc_listener.h diff --git a/agent/src/beerocks/slave/agent_ucc_listener.cpp b/agent/src/beerocks/slave/agent_ucc_listener.cpp new file mode 100644 index 0000000000..39b7c1fef3 --- /dev/null +++ b/agent/src/beerocks/slave/agent_ucc_listener.cpp @@ -0,0 +1,133 @@ +/* SPDX-License-Identifier: BSD-2-Clause-Patent + * + * Copyright (c) 2019 Intel Corporation + * + * This code is subject to the terms of the BSD+Patent license. + * See LICENSE file for more details. + */ + +#include "agent_ucc_listener.h" + +#include +#include + +#include + +using namespace beerocks; +using namespace net; + +agent_ucc_listener::agent_ucc_listener(uint16_t port, const std::string &vendor, + const std::string &model, const std::string &bridge_iface, + Socket **controller_sd) + : beerocks_ucc_listener(port), m_vendor(vendor), m_model(model), m_bridge_iface(bridge_iface), + m_controller_sd(controller_sd) +{ + m_ucc_listener_run_on = eUccListenerRunOn::CONTROLLER; +} + +bool agent_ucc_listener::init() +{ + network_utils::iface_info bridge_info; + if (network_utils::get_iface_info(bridge_info, m_bridge_iface) < 0) { + LOG(ERROR) << " failed getting iface info on bridge_mac '" << m_bridge_iface << "'"; + should_stop = true; + return false; + } + + m_bridge_mac = bridge_info.mac; + + return beerocks_ucc_listener::init(); +} + +/** + * @brief Returns string filled with reply to "DEVICE_GET_INFO" command. + * + * @return const std::string Device info in UCC reply format. + */ +std::string agent_ucc_listener::fill_version_reply_string() +{ + return std::string("vendor,") + m_vendor + std::string(",model,") + m_model + + std::string(",version,") + BEEROCKS_VERSION; + + return std::string(); +} + +/** + * @brief Clears configuration on Controller database. + * + * @return None. + */ +void agent_ucc_listener::clear_configuration() +{ + // TODO +} + +/** + * @brief Return socket to Agent with bridge 'dest_alid` MAC address. + * + * @param[in] dest_alid Agent bridge MAC address. + * @return Socket* Socket to the Agent. + */ +Socket *agent_ucc_listener::get_dev_send_1905_destination_socket(const std::string &dest_alid) +{ + // On the agent side, the dest_alid is not really needed since the destination socket will + // always be the controller socket. + return *m_controller_sd; +} + +/** + * @brief Get preprepared buffer with CMDU in it. + * + * @return std::shared_ptr Buffer pointer. + */ +std::shared_ptr agent_ucc_listener::get_buffer_filled_with_cmdu() +{ + // Currently, no such buffer on agent side. + return std::shared_ptr(); +} + +/** + * @brief Send CMDU to destined Agent. + * + * @param[in] sd Agent socket + * @param[in] cmdu_tx CMDU object + * @return true if successful, false if not. + */ +bool agent_ucc_listener::send_cmdu_to_destination(Socket *sd, ieee1905_1::CmduMessageTx &cmdu_tx) +{ + if (*m_controller_sd == nullptr) { + LOG(ERROR) << "socket to controller is nullptr"; + return false; + } + + return message_com::send_cmdu(*m_controller_sd, cmdu_tx, (*m_controller_sd)->getPeerMac(), + m_bridge_mac); + return true; +} + +/** + * @brief Parse bss_info string into bss_info_conf_struct. + * + * @param[in] bss_info_str String containing bss info configuration. + * @param[out] bss_info_conf Controller database struct filled with configuration. + * @param[out] err_string Contains an error description if the function fails. + * @return al_mac on success, empty string if not. + */ +bool agent_ucc_listener::handle_dev_set_config(std::unordered_map ¶ms, + std::string &err_string) +{ + + if (params.find("bss_info") != params.end()) { + err_string = "parameter 'bss_info' is not relevant to the agent"; + return false; + } + + if (params.find("backhaul") == params.end()) { + err_string = "parameter 'backhaul' is missing"; + return false; + } + + // TODO + + return true; +} diff --git a/agent/src/beerocks/slave/agent_ucc_listener.h b/agent/src/beerocks/slave/agent_ucc_listener.h new file mode 100644 index 0000000000..6a1c4bb648 --- /dev/null +++ b/agent/src/beerocks/slave/agent_ucc_listener.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: BSD-2-Clause-Patent + * + * Copyright (c) 2019 Intel Corporation + * + * This code is subject to the terms of the BSD+Patent license. + * See LICENSE file for more details. + */ + +#ifndef __AGENT_UCC_LISTENER_H__ +#define __AGENT_UCC_LISTENER_H__ + +#include +#include + +#include + +namespace beerocks { +class agent_ucc_listener : public beerocks_ucc_listener { +public: + agent_ucc_listener(uint16_t port, const std::string &vendor, const std::string &model, + const std::string &bridge_iface, Socket **controller_sd); + ~agent_ucc_listener(){}; + + bool init() override; + + void lock() override { mutex.lock(); } + void unlock() override { mutex.unlock(); } + +private: + std::string fill_version_reply_string() override; + void clear_configuration() override; + Socket *get_dev_send_1905_destination_socket(const std::string &dest_alid) override; + std::shared_ptr get_buffer_filled_with_cmdu() override; + bool send_cmdu_to_destination(Socket *sd, ieee1905_1::CmduMessageTx &cmdu_tx) override; + bool handle_dev_set_config(std::unordered_map ¶ms, + std::string &err_string) override; + + const std::string &m_vendor; + const std::string &m_model; + const std::string &m_bridge_iface; + std::string m_bridge_mac; + Socket **const m_controller_sd; + + std::mutex mutex; +}; + +} // namespace beerocks + +#endif // __AGENT_UCC_LISTENER_H__