This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agent: Add agent_ucc_listener implementation
Signed-off-by: Moran Shoeg <[email protected]>
- Loading branch information
Showing
2 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <beerocks/bcl/network/network_utils.h> | ||
#include <beerocks/tlvf/beerocks_message.h> | ||
|
||
#include <easylogging++.h> | ||
|
||
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<uint8_t> Buffer pointer. | ||
*/ | ||
std::shared_ptr<uint8_t> agent_ucc_listener::get_buffer_filled_with_cmdu() | ||
{ | ||
// Currently, no such buffer on agent side. | ||
return std::shared_ptr<uint8_t>(); | ||
} | ||
|
||
/** | ||
* @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<std::string, std::string> ¶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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <beerocks/bcl/beerocks_config_file.h> | ||
#include <beerocks/bcl/beerocks_ucc_listener.h> | ||
|
||
#include <mutex> | ||
|
||
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<uint8_t> 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<std::string, std::string> ¶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__ |