UNC_KT_CTR_DOMAIN,
UNC_KT_LOGICAL_PORT,
UNC_KT_LOGICAL_MEMBER_PORT,
- UNC_KT_BOUNDARY
+ UNC_KT_BOUNDARY,
+ UNC_KT_INVALID = 0x300
} unc_key_type_t;
/* Operation */
\r
include ../defs.mk\r
\r
-CXX_SOURCES = $(wildcard *.cc) \r
+CXX_SOURCES = $(wildcard *.cc) \r
\r
-UNC_LIBS += -lcurl \\r
- -ljson \r
+UNC_LIBS += -lcurl \\r
+ -ljson \r
\r
include ../rules.mk\r
\r
#ifndef _ODC_CONTROLLER_HH_
#define _ODC_CONTROLLER_HH_
+#include <pfc/ipc_struct.h>
#include <arpa/inet.h>
#include <driver/controller_interface.hh>
#include <string>
class ODCController: public unc::driver::controller {
public:
- /*
- * @brief - Parametrised Constructor
- * @param[in] - key_ctr - key structure for controller
- * @param[in] - val_ctr - value structure for controller
+ /**
+ * @brief - Parametrised Constructor
+ * @param[in] - key_ctr (key structure for controller)
+ * @param[in] - val_ctr (value structure for controller)
*/
ODCController(const key_ctr_t& key_ctr, const val_ctr_t& val_ctr);
- /*
- * Destructor
+ /**
+ * @brief - Destructor
*/
~ODCController();
/**
- * Gets the controller type
- * @retval - unc_keytype_ctrtype_t - enum for controller type
+ * @brief - Gets the controller type
+ * @return - unc_keytype_ctrtype_t (controller type)
*/
unc_keytype_ctrtype_t get_controller_type();
/**
- * Ping needed for the ODC Conttoller or not
- * @reval - pfc_bool_t - PFC_TRUE./ PFC_FALSE
- */
- pfc_bool_t is_ping_needed();
-
- /*
- * Gets the ping interval
- * @retval - uint32_t - ping interval
+ * @brief - Gets the contoller id
+ * @return - std::strinig(controller id)
*/
- uint32_t get_ping_interval();
+ std::string get_controller_id();
- /*
- * Gets the ping interval count
- * @retval - uint32_t - ping interval count
+ /**
+ * @brief - Gets the audit status
+ * @return - pfc_bool_t(audit status)
*/
- uint32_t get_ping_fail_retry_count();
+ pfc_bool_t get_audit_status();
- /*
- * Gets the contoller id
- * @retval - std::strin - controller id
+ /**
+ * @brief - reset connect set or not
+ * @return - PFC_TRUE on reset connection, PFC_FALSE on failure
*/
- std::string get_controller_id();
+ pfc_bool_t reset_connect();
- /*
- * ping conttoller available or nor
- * @retval - pfc_bool_t - PFC_TRUE/ PFC_FALSE
+ /**
+ * @brief - get the host address
+ * @return - std::string(host address)
*/
- pfc_bool_t ping_controller();
+ std::string get_host_address();
- /*
- * rest connect set or not
- * @retval - pfc_bool_t - PFC_TRUE/ PFC_FALSE
+ /**
+ * @brief - gets the user name
+ * @return - std::string (username)
*/
- pfc_bool_t reset_connect();
+ std::string get_user_name();
/**
- * get the host address
- * @retval - std::string - host address
+ * @brief - Gets the password
+ * @return - std::string(password)
*/
- std::string get_host_address();
+ std::string get_pass_word();
private:
std::string ip_addr_;
std::string controller_name_;
std::string version_;
std::string description_;
+ std::string user_name_;
+ std::string pass_word_;
pfc_bool_t audit_;
};
-}
-}
-
+} // namespace odcdriver
+} // namespace unc
#endif
#define ODCDRIVER_COMMON_DEFS_H_
#include <string>
+#define TCLIB_MODULE_NAME "tclib"
namespace unc {
namespace odcdriver {
-const int ODC_PORT = 8080;
-const std::string USER_NAME = "admin";
-const std::string PASS_WORD = "admin";
+const std::string USER_NAME = "admin";
+const std::string PASS_WORD = "admin";
+const std::string DOM_NAME = "(DEFAULT)";
+const std::string VTN_URL = "/controller/nb/v2/vtn/default/vtns";
+const int ODC_PORT = 8080;
+const int CONNECTION_TIME_OUT = 30;
+const int REQUEST_TIME_OUT = 30;
+const uint32_t PING_INTERVAL = 10;
+const uint32_t PING_RETRY_COUNT = 5;
typedef enum {
ODC_DRV_SUCCESS = 0,
} odc_drv_resp_code_t;
typedef enum {
- HTTP_METHOD_POST = 0,
- HTTP_METHOD_PUT,
- HTTP_METHOD_DELETE,
- HTTP_METHOD_READ
-} HttpMethod;
-
-typedef enum {
- RESP_BAD_REQUEST = 400,
- RESP_UN_AUTHORISED = 401,
- RESP_NOT_FOUND = 404,
- RESP_NOT_ACCEPTABLE = 406,
- RESP_CONFLICT = 409,
- RESP_UN_SUPPORTED_MEDIA_TYPE = 415,
- RESP_INTERNAL_SERVER_ERROR = 500,
- RESP_SERVICE_UNAVAILABLE = 503,
- RESP_CREATED = 201,
- RESP_OK = 200,
- RESP_UNKNOWN = 1
+ RESP_BAD_REQUEST = 400,
+ RESP_UN_AUTHORISED = 401,
+ RESP_NOT_FOUND = 404,
+ RESP_NOT_ACCEPTABLE = 406,
+ RESP_CONFLICT = 409,
+ RESP_UN_SUPPORTED_MEDIA_TYPE = 415,
+ RESP_INTERNAL_SERVER_ERROR = 500,
+ RESP_SERVICE_UNAVAILABLE = 503,
+ RESP_CREATED = 201,
+ RESP_OK = 200,
+ RESP_UNKNOWN = 1
} ServerResponseCode;
-}
-}
+} // namespace odcdriver
+} // namespace unc
#endif // ODCDRIVER_COMMON_DEFS_H_
#ifndef _ODC_MOD_HH__
#define _ODC_MOD_HH__
+#include <rest_client.hh>
#include <odc_vtn.hh>
#include <odc_vbr.hh>
#include <odc_vbrif.hh>
+#include <odc_root.hh>
#include <odc_driver_common_defs.hh>
#include <vtn_drv_module.hh>
+#include <arpa/inet.h>
+#include <unc/tc/external/tc_services.h>
+#include <string>
namespace unc {
namespace odcdriver {
class ODCModule: public pfc::core::Module, public unc::driver::driver {
public:
- /*
- * Paramaretrised Constructor
+ /**
+ * @brief - Paramaretrised Constructor
+ * @param[in] - pfc_modattr obj
*/
- explicit ODCModule(const pfc_modattr_t*& obj) :
- Module(obj) {
- }
- /*
- *@brief - Gets the controller type
- *@param[in] - unc_keytype_ctrtype_t enum
+ explicit ODCModule(const pfc_modattr_t*& obj)
+ : Module(obj) { }
+ /**
+ * @brief - Gets the controller type
+ * @param[in] - unc_keytype_ctrtype_t enum
+ * @return - returns Enum of type unc_keytype_ctrtype_t
*/
unc_keytype_ctrtype_t get_controller_type();
- /*
- * init method - Get Instance of vtndrvinntf & Register into RegisterDriver
- * @retnal - PFC_TRUE/ PFC_FALSE
+ /**
+ * @brief - init method - Get Instance of vtndrvinntf & Register into RegisterDriver
+ * @return - returns PFC_TRUE on success
+ * returns PFC_FALSE on failure
*/
pfc_bool_t init();
- /*
- * Fini
- * @retval PFC_TRUE/ PFC_FALSE
+
+ /**
+ * @brief - Fini
+ * @return - returns PFC_TRUE on success/
+ * returns PFC_FALSE on failure
*/
pfc_bool_t fini();
- /*
- * Is 2phase commit supported or not
- * @retval - PFC_TRUE/ PFC_FALSE
+ /**
+ * @brief - Is 2phase commit supported or not
+ * @return - returns PFC_TRUE if 2phase commit support is needed
+ * returns PFC_FALSE if 2 phase commit is not required.
*/
pfc_bool_t is_2ph_commit_support_needed();
- /*
- * Is audit collection needed or not
- * @retval - PFC_TRUE/ PFC_FALSE
+ /**
+ * @brief - Is audit collection needed or not
+ * @return - returns PFC_TRUE if audit collection is required/returns PFC_FALSE
+ * if audit collection is not required.
*/
pfc_bool_t is_audit_collection_needed();
- /*
- * Creatyes Controller pointer with specific values and return
- * @param[in]- key_ctr_t - Controller key structure
- * @param[in] - val_ctr- Controller value structute
- * @param[out]- Controller pointer
+ /**
+ * @brief - Creates Controller pointer with specific values and return
+ * @param[in] key_ctr - Controller key structure
+ * @param[in] val_ctr - Controller value structute
+ * @return - returns new added controller pointer
*/
unc::driver::controller* add_controller(const key_ctr_t& key_ctr,
- const val_ctr_t& val_ctr);
+ const val_ctr_t& val_ctr);
- /*
- * Updates Controller pointer with specific values and return
- * @param[in]- key_ctr_t - Controller key structure
- * @param[in] - val_ctr- Controller value structute
- * @param[out]- Controller pointer
+ /**
+ * @brief - Updates Controller pointer with specific values and return
+ * @param[in] key_ctr - Controller key structure
+ * @param[in] val_ctr - Controller value structute
+ * @param[in] ctrl_inst - Controller pointer
+ * @return - returns new updated controller pointer
*/
unc::driver::controller* update_controller(const key_ctr_t& key_ctr,
- const val_ctr_t& val_ctr, unc::driver::controller* ctrl_inst);
+ const val_ctr_t& val_ctr,
+ unc::driver::controller*
+ ctrl_inst);
- /*
- * Deletes Controller pointer with specific values
- * @param[in]- Controller pointer
- * @retval - PFC_TRUE/ PFC_FALSE
+ /**
+ * @brief - Deletes Controller pointer with specific values
+ * @param[in] delete_inst - Controller pointer
+ * @return - returns PFC_TRUE if the controller is deleted/ returns PFC_FALSE
+ * if controller is not deleted
*/
pfc_bool_t delete_controller(unc::driver::controller* delete_inst);
- /*
- * DGets the driver command as per the keytype
- * @param[in]- unc_key_type_t- Keytype
- * @retval - driver_command - correspoding driver_command
+ /**
+ * @brief - Gets the driver command as per the keytype
+ * @param[in] key_type - unc Keytype
+ * @return driver_command* - returns corresponding instance driver_command* of the
+ * key type
*/
unc::driver::driver_command* get_driver_command(unc_key_type_t key_type);
- /*
- * HandleVote
- * @param[in] - Controller pointer
- * @partam[out]- unc::tclib::TcCommonRet - enum value
+ /**
+ * @brief - HandleVote
+ * @param[in] - Controller pointer
+ * @return - returns unc::tclib::TcCommonRet - enum value
*/
unc::tclib::TcCommonRet HandleVote(unc::driver::controller*);
- /*
- * Handlethecommit
+ /**
+ * @brief - Handle the commit
* @param[in] - Controller pointer
- * @partam[ou]- unc::tclib::TcCommonRet - enum value
+ * @return - returns unc::tclib::TcCommonRet - enum value
*/
unc::tclib::TcCommonRet HandleCommit(unc::driver::controller*);
- /*
- * Handle the abort
+ /**
+ * @brief - Handle the abort
* @param[in] - Controller pointer
- * @partam[out]- unc::tclib::TcCommonRet - enum value
+ * @return - returns unc::tclib::TcCommonRet - enum value
*/
unc::tclib::TcCommonRet HandleAbort(unc::driver::controller*);
+
+ /**
+ * @brief - Ping needed for the ODC Conttoller or not
+ * @return - returns PFC_TRUE if ping is need / returns PFC_FALSE
+ * if ping is not needed.
+ */
+ pfc_bool_t is_ping_needed();
+
+ /**
+ * @brief - Gets the ping interval
+ * @return - returns the ping interval
+ */
+ uint32_t get_ping_interval();
+
+ /**
+ * @brief - Gets the ping interval count
+ * @return - returns the ping interval count
+ */
+ uint32_t get_ping_fail_retry_count();
+
+ /**
+ * @brief - ping conttoller available or nor
+ * @param[in] - Controller pointer
+ * @return - returns PFC_TRUE if controller is available/
+ * returns PFC_FALSE if controller is not available
+ */
+ pfc_bool_t ping_controller(unc::driver::controller*);
+
+ private:
+ /**
+ * @brief - Notify Audit to TC
+ * @param[in] - controller id
+ * @return - returns ODC_DRV_SUCCESS on sending start
+ * notification to tc
+ */
+ uint32_t notify_audit_start_to_tc(std::string controller_id);
};
-}
-}
+} // namespace odcdriver
+} // namespace unc
#endif
--- /dev/null
+/*
+ * Copyright (c) 2012-2013 NEC Corporation
+ * All rights reserved.
+ *
+ * This program and the accompanying materials are made
+ * available under the
+ * terms of the Eclipse Public License v1.0 which
+ * accompanies this
+ * distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+#ifndef _ODC_ROOT_HH_
+#define _ODC_ROOT_HH_
+
+#include <driver/driver_command.hh>
+#include <vtn_conf_data_element_op.hh>
+#include <odc_vtn.hh>
+#include <odc_vbr.hh>
+#include <vector>
+#include <string>
+
+namespace unc {
+namespace odcdriver {
+
+class ODCROOTCommand : public unc::driver::root_driver_command {
+ public:
+ /**
+ * Constructor
+ */
+ ODCROOTCommand() {}
+
+ /**
+ * Destructor
+ */
+ ~ODCROOTCommand() {}
+
+ /**
+ * @brief - Creates cmd
+ * @param[in] - key structure of key_root
+ * @param[in] - value structure of val_root
+ * @param[in] - controller pointer
+ * @return - returns drv_resp_code enum
+ */
+ drv_resp_code_t create_cmd(key_root_t& key,
+ unc::driver::val_root_t& val,
+ unc::driver::controller *conn) {
+ return DRVAPI_RESPONSE_SUCCESS;
+ }
+
+ /**
+ * @brief - Update Cmd
+ * @param[in] - key structure of key_root
+ * @param[out] - value structure of val_root
+ * @param[in] - controller pointer
+ * @return - returns drv_resp_code enum
+ */
+ drv_resp_code_t update_cmd(key_root_t& key,
+ unc::driver::val_root_t& val,
+ unc::driver::controller *conn) {
+ return DRVAPI_RESPONSE_SUCCESS;
+ }
+
+ /**
+ * @brief - Update Cmd
+ * @param[in] - key structure of key_root
+ * @param[in] - value structure of val_root
+ * @param[in] - controller pointer
+ * @return - returns drv_resp_code enum
+ */
+ drv_resp_code_t delete_cmd(key_root_t& key,
+ unc::driver::val_root_t& val,
+ unc::driver::controller *conn) {
+ return DRVAPI_RESPONSE_SUCCESS;
+ }
+
+ /**
+ * @brief - validates the operation
+ * @param[in] - key(key structure of key_root)
+ * @param[in] - val(value structure of val_root)
+ * @param[in] - conn(controller pointer)
+ * @param[in] - op(peration)
+ * @return - returns drv_resp_code enum
+ */
+ drv_resp_code_t validate_op(key_root_t& key,
+ unc::driver::val_root_t& val,
+ unc::driver::controller* ctr,
+ uint32_t op) {
+ return DRVAPI_RESPONSE_SUCCESS;
+ }
+
+ /**
+ * @brief - reads the root child
+ * @param[in] - Config Node pointer
+ * @param[in] - Controller pointer
+ * @return - returns DRVAPI_RESPONSE_SUCCESS on successfully
+ * reading the root child/ reurns DRVAPI_RESPONSE_FAILURE on failure
+ */
+ drv_resp_code_t
+ read_root_child(std::vector<unc::vtndrvcache::ConfigNode*> &cfg_ptr,
+ unc::driver::controller* ctl_ptr);
+
+ /**
+ * @brief - reads all child info
+ * @param[in] - Config Node pointer
+ * @param[in] - vector of Config Node ptr
+ * @param[in] - controller pointer
+ * @return - returns DRVAPI_RESPONSE_SUCCESS on
+ * successfully reading all the childs/ returns DRVAPI_RESPONSE_FAILURE on
+ * failure
+ */
+ drv_resp_code_t
+ read_all_child(unc::vtndrvcache::ConfigNode* cfg_ptr,
+ std::vector<unc::vtndrvcache::ConfigNode*> & cfg,
+ unc::driver::controller* ctl_ptr);
+};
+} // namespace odcdriver
+} // namespace unc
+#endif
* http://www.eclipse.org/legal/epl-v10.html
*/
-/**
- * @brief Handles VBR Command Formation"
- * @file odc_vbr.hh
- *
- **/
-
#ifndef _ODC_VBR_HH_
#define _ODC_VBR_HH_
#include <driver/driver_command.hh>
+#include <json_build_parse.hh>
+#include <vtn_conf_data_element_op.hh>
+#include <unc/upll_ipc_enum.h>
+#include <unc/pfcdriver_ipc_enum.h>
#include <rest_client.hh>
#include <odc_driver_common_defs.hh>
#include <odc_controller.hh>
#include <string>
+#include <vector>
namespace unc {
namespace odcdriver {
class ODCVBRCommand: public unc::driver::vbr_driver_command {
public:
- /*
+ /**
* @brief Default Constructor
*/
ODCVBRCommand();
- /*
- * @bried Default Destructor
+ /**
+ * @brief Default Destructor
*/
~ODCVBRCommand();
/**
- * @brief - Creates VBR
- * @param[in] key_vbr_t - key structure of VBR
- * @param[in] val_vbr_t - value structure of VBR
- * @param[in] ControllerConnection - Controller connection information
- * @retval - SUCCESS / FAILURE
+ * @brief - Creates VBR
+ * @param[in] key_vbr - key structure of VBR
+ * @param[in] val_vbr - value structure of VBR
+ * @param[in] ControllerPointer - Controller connection information
+ * @return drv_resp_t - returns DRVAPI_RESPONSE_SUCCESS on creating vbr successfully
+ * /returns DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t create_cmd(key_vbr_t& key_vbr, val_vbr_t& val_vbr,
- unc::driver::controller *conn);
+ unc::driver::controller *conn);
/**
- * @brief - Updates VBR
- * @param[in] key_vbr_t - key structure of VBR
- * @param[in] val_vbr_t - value structure of VBR
- * @param[in] ControllerConnection - Controller connection information
- * @retval - SUCCESS / FAILURE
+ * @brief - Updates VBR
+ * @param[in] key_vbr - key structure of VBR
+ * @param[in] val_vbr - value structure of VBR
+ * @param[in] ControllerPointer - Controller connection information
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on updating vbr successfully
+ * /returns DRVAPI_RESPONSE_FAILURE on failure
*/
-
drv_resp_code_t update_cmd(key_vbr_t& key_vbr, val_vbr_t& val_vbr,
- unc::driver::controller* conn);
+ unc::driver::controller* conn);
/**
- * @brief - Deletes VBR
- * @param[in] key_vbr_t - key structure of VBR
- * @param[in] val_vbr_t - value structure of VBR
- * @param[in] ControllerConnection - Controller connection information
- * @retval - SUCCESS / FAILURE
+ * @brief - Deletes VBR
+ * @param[in] key_vbr - key structure of VBR
+ * @param[in] val_vbr - value structure of VBR
+ * @param[in] ControllerPointer - Controller connection information
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on deleting a vbr
+ * / returns DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t delete_cmd(key_vbr_t& key_vbr, val_vbr_t& val_vbr,
- unc::driver::controller *conn);
+ unc::driver::controller *conn);
/**
- * @brief - Validates the operation
- * @param[in] - key_vbr - VBR Key Structure key_vbr_t
- * @param[in] - val_vbr - VBR value structure val_vbr_t
- * @param[in] - ctr - Controller Connection
- * @param[in] - op - operation
+ * @brief - Validates the operation
+ * @param[in] key_vbr - VBR Key Structure key_vbr_t
+ * @param[in] val_vbr - VBR value structure val_vbr_t
+ * @param[in] ctr - Controller Pointer
+ * @param[in] op - operation
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on validation operation success
+ * /returns DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t validate_op(key_vbr_t& key_vbr, val_vbr_t& val_vbr,
- unc::driver::controller* ctr, uint32_t op);
+ unc::driver::controller* ctr, uint32_t op);
+ /**
+ * @brief - get all the vbr child
+ * @param[in] vtn_name - vtn name
+ * @param[in] vbr_name - vbr name
+ * @param[in] ctr - controller pointer
+ * @param[out] cfgnode_vector - config node vector
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on successfully retieving a vbr
+ * child /returns DRVAPI_RESPONSE_FAILURE on failure
+ */
+ drv_resp_code_t get_vbr_child(std::string vtn_name,
+ std::string vbr_name,
+ unc::driver::controller* ctr,
+ std::vector< unc::vtndrvcache::ConfigNode *>
+ &cfgnode_vector);
+
+ /**
+ * @brief - parse the vbr if data
+ * @param[in] vtn_name - vtn name
+ * @param[in] vbr_name - vbr name
+ * @param[in] url - url to send the request
+ * @param[in] ctr - controller pointer
+ * @param[in] data - data from which parse should happen
+ * @param[out] cfgnode_vector - config node vector
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on parsing the
+ * response of vbrif/returns DRVAPI_RESPONSE_FAILURE on failure
+ */
+ drv_resp_code_t parse_vbrif_resp_data(std::string vtn_name,
+ std::string vbr_name,
+ std::string url,
+ unc::driver::controller* ctr,
+ char *data,
+ std::vector<
+ unc::vtndrvcache::ConfigNode *>
+ &cfgnode_vector);
private:
- /*
- * @brief - gets the vbr url
- * @param[in] - key_vbr_t - vbr key structure
+ /**
+ * @brief - gets the vbr url
+ * @param[in] key_vbr - vbr key structure
+ * @return std::string - returns the url string of vbr
*/
std::string get_vbr_url(key_vbr_t& key_vbr);
- /*
- * @brief - Creates the Request Body
- * @param[in] - val - VTN value structure val_vtn_t
- * @retval - const char* - request body formed
+
+ /**
+ * @brief - Creates the Request Body
+ * @param[in] val_vtn - VTN value structure val_vtn_t
+ * @return const char* - returns the request body formed
*/
- const char* create_request_body(val_vbr_t& val_vtn);
+ const char* create_request_body(const val_vbr_t& val_vtn);
- /*
- * @brief - Validates Create Vbr
- * @param[in] - key_vbr - VBR Key Structure key_vbr_t
- * @param[in] - val_vbr - VBR value structure val_vbr_t
- * @param[in] - ctr - Controller Connection
- * @retval - drv_resp_code_t - DRVAPI_RESPONSE_SUCCESS
- * / DRVAPI_RESPONSE_FAILURE
+ /**
+ * @brief - Validates Create Vbr
+ * @param[in] key_vbr - VBR Key Structure key_vbr_t
+ * @param[in] ctr - Controller Pointer
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on successfully
+ * validating creation of vbr/returns DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t validate_create_vbr(key_vbr_t& key_vbr,
- unc::driver::controller* ctr);
+ unc::driver::controller* ctr);
- /*
- * @brief - Validates Delete Vbr
- * @param[in] - key_vbr - VBR Key Structure key_vbr_t
- * @param[in] - val_vbr - VBR value structure val_vbr_t
- * @param[in] - ctr - Controller Connection
- * @retval - drv_resp_code_t - DRVAPI_RESPONSE_SUCCESS
- * / DRVAPI_RESPONSE_FAILURE
+ /**
+ * @brief - Validates Delete Vbr
+ * @param[in] key_vbr - VBR Key Structure key_vbr_t
+ * @param[in] ctr - Controller Pointer
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on deleting vbr
+ * / returns DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t validate_delete_vbr(key_vbr_t& key_vbr,
- unc::driver::controller* ctr);
+ unc::driver::controller* ctr);
- /*
- * @brief - Validates Update Vbr
- * @param[in] - key_vbr - VBR Key Structure key_vbr_t
- * @param[in] - val_vbr - VBR value structure val_vbr_t
- * @param[in] - ctr - Controller Connection
- * @retval - drv_resp_code_t - DRVAPI_RESPONSE_SUCCESS
- * / DRVAPI_RESPONSE_FAILURE
+ /**
+ * @brief - Validates Update Vbr
+ * @param[in] key_vbr - VBR Key Structure key_vbr_t
+ * @param[in] ctr - Controller Pointer
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on updating vbr
+ * /returns DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t validate_update_vbr(key_vbr_t& key_vbr,
- unc::driver::controller* ctr);
+ unc::driver::controller* ctr);
- /*
- * @brief - Checks is_vtn_exists_in_controller
- * @param[in] - key_vbr - VBR Key Structure key_vbr_t
- * @param[in] - val_vbr - VBR value structure val_vbr_t
- * @param[in] - ctr - Controller Connection
- * @uint32_t - response code from the controller
+ /**
+ * @brief - Checks is_vtn_exists_in_controller
+ * @param[in] key_vbr - VBR Key Structure key_vbr_t
+ * @param[in] ctr - Controller Pointer
+ * @return uint32_t - returns the response code from the controller on checking whether
+ * the vtn exists in controller
*/
- uint32_t is_vtn_exists_in_controller(key_vbr_t& key_vbr,
- unc::driver::controller* ctr);
+ uint32_t is_vtn_exists_in_controller(const key_vbr_t& key_vbr,
+ unc::driver::controller* ctr);
- /*
- * @brief - Checks is_vtn_exists_in_controller
- * @param[in] - key_vbr - VBR Key Structure key_vbr_t
- * @param[in] - val_vbr - VBR value structure val_vbr_t
- * @param[in] - ctr - Controller Connection
- * @uint32_t - response code from the controller
+ /**
+ * @brief - Checks is_vtn_exists_in_controller
+ * @param[in] key_vbr - VBR Key Structure key_vbr_t
+ * @param[in] ctr - Controller Pointer
+ * @return uint32_t - returns response code from the controller on checking
+ * whether the vbr exists in controller
*/
uint32_t is_vbr_exists_in_controller(key_vbr_t& key_vbr,
- unc::driver::controller* ctr);
+ unc::driver::controller* ctr);
- /*
- * @brief - GetControllerResponse and checks the resp code
- * @param[in] - url to be set to
- * @uint32_t - response code from the controller
+ /**
+ * @brief - GetControllerResponse and checks the resp code
+ * @param[in] url - url to be set to
+ * @param[in] ctr - controller pointer
+ * @param[in] method - Http Method
+ * @param[in] request_body - request body
+ * @return uint32_t - returns the response code from the controller
+ */
+ uint32_t get_controller_response_code(std::string url,
+ unc::driver::controller* ctr,
+ unc::restjson::HttpMethod method,
+ const char* request_body);
+ /**
+ * @brief - parse vbr if and append it to vector
+ * @param[in] vtn_name - vtn name
+ * @param[in] vbr_name - vbr name
+ * @param[in] json_obj - json object
+ * @param[in] arr_idx - array index
+ * @param[in] url - url to send request
+ * @param[in] ctr - controller pointer
+ * @param[out] cfgnode_vector - config node vector
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on parsing vbrif and appending
+ * vector/ returns DRVAPI_RESPONSE_FAILURE on failure
+ */
+ drv_resp_code_t parse_vbrif_append_vector(std::string vtn_name,
+ std::string vbr_name,
+ json_object *json_obj,
+ uint32_t arr_idx,
+ std::string url,
+ unc::driver::controller* ctr,
+ std::vector< unc::vtndrvcache::
+ ConfigNode *>&cfgnode_vector);
+
+ /**
+ * @brief - read port map
+ * @param[in] ctr - controller pointer
+ * @param[in] url - url to send the request
+ * @return json_object pointer - returns the response from controller
*/
- uint32_t get_controller_response(string url, unc::driver::controller* ctr);
+ json_object* read_portmap(unc::driver::controller* ctr, std::string url);
private:
std::string age_interval_;
};
-}
-}
+} // namespace odcdriver
+} // namespace unc
#endif
#include <driver/driver_command.hh>
#include <rest_client.hh>
+#include <unc/upll_ipc_enum.h>
+#include <unc/pfcdriver_ipc_enum.h>
#include <odc_driver_common_defs.hh>
#include <odc_controller.hh>
#include <string>
+#include <sstream>
namespace unc {
namespace odcdriver {
class ODCVBRIfCommand: public unc::driver::vbrif_driver_command {
public:
- /*
+ /**
* @brief Default Constructor
*/
ODCVBRIfCommand();
- /*
- * @bried Default Destructor
+ /**
+ * @brief Default Destructor
*/
~ODCVBRIfCommand();
/**
- * @brief - Creates VBRIf/ PortMap
- * @param[in] key_vbr_if - key structure of VBRIf
- * @param[in] val_vbr_if - value structure of VBRIf
- * @param[in] ControllerConnection - Controller connection information
- * @retval - SUCCESS / FAILURE
+ * @brief - Creates VBRIf/ PortMap
+ * @param[in] - key structure of VBRIf
+ * @param[in] - value structure of VBRIf
+ * @param[in] - Controller connection information
+ * @retval - returns DRVAPI_RESPONSE SUCCESS on creation of vbrif successfully
+ * /returns DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t create_cmd(key_vbr_if_t& key, pfcdrv_val_vbr_if_t& val,
- unc::driver::controller *conn);
-
- /**
- * @brief - Creates PortMap
- * @param[in] key_vbr_if - key structure of VBRIf
- * @param[in] val_vbr_if - value structure of VBRIf
- * @param[in] ControllerConnection - Controller connection information
- * @retval - SUCCESS / FAILURE
- */
- uint32_t create_cmd_port_map(key_vbr_if_t& vbrif_key,
- pfcdrv_val_vbr_if_t& vbrif_val, unc::driver::controller *conn);
+ unc::driver::controller *conn);
/**
- * @brief - Updates VBRIf/ PortMap
- * @param[in] key_vbr_if - key structure of VBRIf
- * @param[in] val_vbr_if - value structure of VBRIf
- * @param[in] ControllerConnection - Controller connection information
- * @retval - SUCCESS / FAILURE
+ * @brief - Updates VBRIf
+ * @param[in] key - key structure of VBRIf
+ * @param[in] val - value structure of VBRIf
+ * @param[in] conn - Controller connection information
+ * @retval drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on updation of VBRIf
+ * successfully/returns DRVAPI_RESPONSE_FAILURE on failure
*/
-
drv_resp_code_t update_cmd(key_vbr_if_t& key, pfcdrv_val_vbr_if_t& val,
- unc::driver::controller *conn);
+ unc::driver::controller *conn);
/**
- * @brief - Updates PortMap
- * @param[in] key_vbr_if - key structure of VBRIf
- * @param[in] val_vbr_if - value structure of VBRIf
- * @param[in] ControllerConnection - Controller connection information
- * @retval - SUCCESS / FAILURE
+ * @brief - Updates PortMap
+ * @param[in] vbrif_key - key structure of VBRIf
+ * @param[in] vbrif_val - value structure of VBRIf
+ * @param[in] conn - Controller connection information
+ * @return uint32_t - returns DRVAPI_RESPONSE_SUCCESS on updation of port_map
+ * successfully/returns DRVAPI_RESPONSE_FAILURE on failure
*/
-
uint32_t update_cmd_port_map(key_vbr_if_t& vbrif_key,
- pfcdrv_val_vbr_if_t& vbrif_val, unc::driver::controller *conn);
+ pfcdrv_val_vbr_if_t& vbrif_val,
+ unc::driver::controller *conn);
+
/**
- * @brief - Deletes VBRIf/ PortMap
- * @param[in] key_vbr_if - key structure of VBRIf
- * @param[in] val_vbr_if - value structure of VBRIf
- * @param[in] ControllerConnection - Controller connection information
- * @retval - SUCCESS / FAILURE
+ * @brief - Deletes VBRIf
+ * @param[in] key - key structure of VBRIf
+ * @param[in] val - value structure of VBRIf
+ * @param[in] conn - Controller connection information
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on deletion of
+ * VBRIf successfully /returns
+ * DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t delete_cmd(key_vbr_if_t& key, pfcdrv_val_vbr_if_t& val,
- unc::driver::controller *conn);
+ unc::driver::controller *conn);
/**
- * @brief - Deletes VBRIf/ PortMap
- * @param[in] key_vbr_if - key structure of VBRIf
- * @param[in] val_vbr_if - value structure of VBRIf
- * @param[in] ControllerConnection - Controller connection information
- * @retval - SUCCESS / FAILURE
+ * @brief - Deletes VBRIf/ PortMap
+ * @param[in] vbrif_key - key structure of VBRIf
+ * @param[in] vbrif_val - value structure of VBRIf
+ * @param[in] conn - Controller connection information
+ * @retval uint32_t - returns DRVAPI_RESPONSE_SUCCESS on deletion of
+ * PortMap /returns
+ * DRVAPI_RESPONSE_FAILURE on failure
*/
-
uint32_t delete_cmd_port_map(key_vbr_if_t& vbrif_key,
- pfcdrv_val_vbr_if_t& vbrif_val, unc::driver::controller *conn);
+ pfcdrv_val_vbr_if_t& vbrif_val,
+ unc::driver::controller *conn);
/**
- * @brief - Validates the operation
- * @param[in] - key - VBRIF Key Structure key_vbr_if
- * @param[in] - val - VBRIF value structure pfcdrv_val_vbr_if_t
- * @param[in] - conn - Controller Connection
- * @param[in] - op - operation
- */
- drv_resp_code_t validate_op(key_vbr_if_t& key, pfcdrv_val_vbr_if_t& val,
- unc::driver::controller* ctr, uint32_t op);
+ * @brief - Validates the operation
+ * @param[in] - key - VBRIF Key Structure key_vbr_if
+ * @param[in] - val - VBRIF value structure pfcdrv_val_vbr_if_t
+ * @param[in] - ctr - Controller pointer
+ * @param[in] - op - operation
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on suceess of
+ * validation operation of VBRIf/returns
+ * DRVAPI_RESPONSE_FAILURE on failure
+ */
+ drv_resp_code_t validate_op(key_vbr_if_t& key,
+ pfcdrv_val_vbr_if_t& val,
+ unc::driver::controller* ctr,
+ uint32_t op);
private:
- /*
- * @brief - Constructs url for vbrif
- * @param[in] - key_vbr_if_t - key structure of vbrif key structure
+ /**
+ * @brief - get_controller_response and checks the res code
+ * @param[in] url - url to be set to
+ * @param[in] ctr - controller pointer
+ * @param[in] method - HttpMethod enum
+ * @param[in] request_body - request body
+ * @return uint32_t - returns response code from the controller
+ */
+ uint32_t get_controller_response_code(std::string url,
+ unc::driver::controller* ctr,
+ unc::restjson::HttpMethod method,
+ const char* request_body);
+ /**
+ * @brief - Constructs url for vbrif
+ * @param[in] vbrif_key - key structure of vbrif key structure
+ * @return - returns the url of VBRIf
*/
std::string get_vbrif_url(key_vbr_if_t& vbrif_key);
- /*
- * @brief - Creates the Request Body for portmap
- * @param[in] - val - VTN value structure val_vtn_t
- * @retval - const char* - request body formed
+ /**
+ * @brief - Creates the Request Body for portmap
+ * @param[in] vbrif_val - VTN value structure val_vtn_t
+ * @return const char* - returns the request body formed
*/
const char* create_request_body_port_map(pfcdrv_val_vbr_if_t& vbrif_val);
- /*
- * @brief - Validates Create vbrif
- * @param[in] - key_vbr_if - VBRIF Key Structure key_vbr_if
- * @param[in] - conn - Controller Connection
- * @retval - drv_resp_code_t - DRVAPI_RESPONSE_SUCCESS
- * / DRVAPI_RESPONSE_FAILURE
+ /**
+ * @brief - Validates Create vbrif
+ * @param[in] key_vbr_if - VBRIF Key Structure key_vbr_if
+ * @param[in] ctr - Controller pointer
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on success of
+ * validate create of VBRIf / returns
+ * DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t validate_create_vbrif(key_vbr_if_t& key_vbr_if,
- unc::driver::controller* ctr);
+ unc::driver::controller* ctr);
- /*
- * @brief - Validates Delete vbrif
- * @param[in] - key_vbr_if - VBRIF Key Structure key_vbr_if
- * @param[in] - conn - Controller Connection
- * @retval - drv_resp_code_t - DRVAPI_RESPONSE_SUCCESS
- * / DRVAPI_RESPONSE_FAILURE
+ /**
+ * @brief - Validates Delete vbrif
+ * @param[in] key_vbr_if - VBRIF Key Structure key_vbr_if
+ * @param[in] ctr - Controller pointer
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on success of
+ * validate delete of VBRIf/returns
+ * DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t validate_delete_vbrif(key_vbr_if_t& key_vbr_if,
- unc::driver::controller* ctr);
+ unc::driver::controller* ctr);
- /*
- * @brief - Validates Update vbrif
- * @param[in] - key_vbr_if - VBRIF Key Structure key_vbr_if
- * @param[in] - conn - Controller Connection
- * @retval - drv_resp_code_t - DRVAPI_RESPONSE_SUCCESS
- * / DRVAPI_RESPONSE_FAILURE
+ /**
+ * @brief - Validates Update vbrif
+ * @param[in] key_vbr_if - VBRIF Key Structure key_vbr_if
+ * @param[in] ctr - Controller pointer
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on success of
+ * validate update of VBRIf/returns
+ * DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t validate_update_vbrIf(key_vbr_if_t& key_vbr_if,
- unc::driver::controller* ctr);
+ unc::driver::controller* ctr);
- /*
- * @brief - Checks is_vtn_exists_in_controller
- * @param[in] - key_vbr_if - VBRIF Key Structure key_vbr_if
- * @param[in] - conn - Controller Connection
- * @uint32_t - response code from the controller
+ /**
+ * @brief - Checks is_vtn_exists_in_controller
+ * @param[in] key_vbr_if - VBRIF Key Structure key_vbr_if
+ * @param[in] ctr - Controller pointer
+ * @return unint32_t - returns response code from the controller
+ * on checking whether the vtn exists in
+ * controller
*/
uint32_t is_vtn_exists_in_controller(key_vbr_if_t& key_vbr_if,
- unc::driver::controller* ctr);
+ unc::driver::controller* ctr);
- /*
- * @brief - Checks is_vbr_exists_in_controller
- * @param[in] - key_vbr_if - VBRIF Key Structure key_vbr_if
- * @param[in] - conn - Controller Connection
- * @uint32_t - response code from the controller
+ /**
+ * @brief - Checks is_vbr_exists_in_controller
+ * @param[in] key_vbr_if - VBRIF Key Structure key_vbr_if
+ * @param[in] ctr - Controller pointer
+ * @return unint32_t - returns response code from the controller on
+ * checking whether the VBRIf exists in the
+ * controller
*/
uint32_t is_vbrif_exists_in_controller(key_vbr_if_t& key_vbr_if,
- unc::driver::controller* ctr);
+ unc::driver::controller* ctr);
- /*
- * @brief - Checks is_vbrif_exists_in_controller
- * @param[in] - key_vbr_if - VBRIF Key Structure key_vbr_if
- * @param[in] - conn - Controller Connection
- * @uint32_t - response code from the controller
+ /**
+ * @brief - Checks is_vbrif_exists_in_controller
+ * @param[in] key_vbr_if - VBRIF Key Structure key_vbr_if
+ * @param[in] ctr - Controller pointer
+ * @return uint32_t - returns response code from the controller on
+ * checking whether the vbr exists in ctl
*/
uint32_t is_vbr_exists_in_controller(key_vbr_if_t& key_vbr_if,
- unc::driver::controller* ctr);
+ unc::driver::controller* ctr);
- /*
- * @brief - get_controller_response and checks the resp code
- * @param[in] - url to be set to
- * @uint32_t - response code from the controller
+ /**
+ * @brief - get_controller_response and checks the resp code
+ * @param[in] url - url to be set to
+ * @param[in] ctr - controller pointer
+ * @return - returns response code from the controller
*/
uint32_t get_controller_response(std::string url,
- unc::driver::controller* ctr);
+ unc::driver::controller* ctr);
- /*
- * @brief - Creates the Request Body
- * @param[in] - val - VTN value structure val_vtn_t
- * @retval - const char* - request body formed
+ /**
+ * @brief - Creates the Request Body
+ * @param[in] - val_vtn - VTN value structure val_vtn_t
+ * @return - const char* - returns the request body formed
*/
const char* create_request_body(pfcdrv_val_vbr_if_t& val_vtn);
};
-}
-}
+} // namespace odcdriver
+} // namespace unc
#endif
* http://www.eclipse.org/legal/epl-v10.html
*/
-/**
- * @brief Handles VTN Command Formation"
- * @file odc_vtn.hh
- *
- **/
-
#ifndef _ODC_VTN_HH_
#define _ODC_VTN_HH_
#include <driver/driver_command.hh>
#include <odc_driver_common_defs.hh>
#include <odc_controller.hh>
+#include <unc/upll_ipc_enum.h>
+#include <vtn_conf_data_element_op.hh>
+#include <vector>
#include <string>
namespace unc {
namespace odcdriver {
-/**
- * @brief ODLVTN Command provides function to send Request and Get Response
- *
- **/
-
class ODCVTNCommand: public unc::driver::vtn_driver_command {
public:
- /*
+ /**
* @brief Default Constructor
*/
ODCVTNCommand();
- /*
- * @bried Default Destructor
+ /**
+ * @brief Default Destructor
*/
~ODCVTNCommand();
/**
- * @brief - Creates VTN
- * @param[in] key_vtn_t - key structure of VTN
- * @param[in] val_vtn_t - value structure of VTN
+ * @brief - Creates VTN
+ * @param[in] key_vtn_t - key structure of VTN
+ * @param[in] val_vtn_t - value structure of VTN
* @param[in] ControllerConnection - Controller connection information
- * @retval - ODLDRVSUCCESS / ODLDRVFAILURE
+ * @return - returns DRVAPI_RESPONSE_SUCCESS on
+ * creation of vtn/ returns
+ * DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t create_cmd(key_vtn_t& key, val_vtn_t& val,
- unc::driver::controller *conn);
+ unc::driver::controller *conn);
/**
- * @brief - Updates VTN
- * @param[in] key_vtn_t - key structure of VTN
- * @param[in] val_vtn_t - value structure of VTN
+ * @brief - Updates VTN
+ * @param[in] key_vtn_t - key structure of VTN
+ * @param[in] val_vtn_t - value structure of VTN
* @param[in] ControllerConnection - Controller connection information
- * @retval - SUCCESS / FAILURE
+ * @return - returns DRVAPI_RESPONSE_SUCCESS on
+ * updation of vtn /returns
+ * DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t update_cmd(key_vtn_t& key, val_vtn_t& val,
- unc::driver::controller *conn);
+ unc::driver::controller *conn);
/**
- * @brief - Creates VTN
- * @param[in] key_vtn_t - key structure of VTN
- * @param[in] val_vtn_t - value structure of VTN
+ * @brief - Creates VTN
+ * @param[in] key_vtn_t - key structure of VTN
+ * @param[in] val_vtn_t - value structure of VTN
* @param[in] ControllerConnection - Controller connection information
- * @retval - ODLDRVSUCCESS / ODLDRVFAILURE
+ * @return - returns DRVAPI_RESPONSE_SUCCESS on
+ * deletion/returns DRVAPI_RESPONSE_FAILURE
+ * on failure
*/
drv_resp_code_t delete_cmd(key_vtn_t& key, val_vtn_t& val,
- unc::driver::controller *conn);
+ unc::driver::controller *conn);
/**
- * @brief - Validates the operation
- * @param[in] - key - VTN Key Structure key_vtn_t
- * @param[in] - conn - Controller Connection
- * @param[in] - op - operation
+ * @brief - Validates the operation
+ * @param[in] key - VTN Key Structure key_vtn_t
+ * @param[in] conn - Controller Connection
+ * @param[in] op - operation
+ * @return drv_resp_code -returns DRVAPI_RESPONSE_SUCCESS on
+ * validation operation success/returns
+ * DRVAPI_RESPONSE_FAILURE on failure
*/
drv_resp_code_t validate_op(key_vtn_t& key, val_vtn_t& val,
- unc::driver::controller *conn, uint32_t op);
+ unc::driver::controller *conn, uint32_t op);
+
+ /**
+ * @brief - read all - reads all the vtns
+ * @param[in] ctr - controller pointer
+ * @param[in] cfgnode_vector - cfgnode_vector
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on
+ * success of read all operation/returns
+ * DRVAPI_RESPONSE_FAILURE on failure
+ */
+ drv_resp_code_t read_all(unc::driver::controller* ctr,
+ std::vector<unc::vtndrvcache::ConfigNode *>
+ &cfgnode_vector);
+
+ /**
+ * @brief - get vtn child - gets all the vbridge
+ * under particular vtn
+ * @param[in] - vtn name
+ * @param[in] ctr - controller pointer
+ * @param[in] cfgnode_vector - cfgnode_vector
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on
+ * retrieving the vtn child successfully/
+ * returns DRVAPI_RESPONSE_FAILURE on fail
+ */
+ drv_resp_code_t get_vtn_child(std::string vtnname,
+ unc::driver::controller* ctr,
+ std::vector<unc::vtndrvcache::ConfigNode *>
+ &cfgnode_vector);
private:
- /*
- * @brief - Validates Create Vtn
- * @param[in] - key - VTN Key Structure key_vtn_t
- * @param[in] - conn - Controller Connection
- * @retval - drv_resp_code_t - DRVAPI_RESPONSE_SUCCESS
- * / DRVAPI_RESPONSE_FAILURE
- */
- drv_resp_code_t validate_create_vtn(key_vtn_t& key_vtn,
- unc::driver::controller* ctr);
-
- /*
- * @brief - Validates Delete Vtn
- * @param[in] - key - VTN Key Structure key_vtn_t
- * @param[in] - conn - Controller Connection
- * @retval - drv_resp_code_t - DRVAPI_RESPONSE_SUCCESS
- * / DRVAPI_RESPONSE_FAILURE
- */
- drv_resp_code_t validate_delete_vtn(key_vtn_t& key_vtn,
- unc::driver::controller* ctr);
-
- /*
- * @brief - Validates Update Vtn
- * @param[in] - key - VTN Key Structure key_vtn_t
- * @param[in] - conn - Controller Connection
- * @retval - drv_resp_code_t - DRVAPI_RESPONSE_SUCCESS
- * / DRVAPI_RESPONSE_FAILURE
- */
- drv_resp_code_t validate_update_vtn(key_vtn_t& key_vtn,
- unc::driver::controller* ctr);
-
- /*
- * @brief - Checks is_vtn_exists_in_controller
- * @param[in] - key - VTN Key Structure key_vtn_t
- * @param[in] - conn - Controller Connection
- * @uint32_t - response code from the controller
- */
- uint32_t is_vtn_exists_in_controller(key_vtn_t& key_vtn,
- unc::driver::controller* ctr);
-
- /*
- * @brief - get_controller_response and checks the resp code
- * @param[in] - url to be set to
- * @uint32_t - response code from the controller
- */
- uint32_t get_controller_response(std::string url,
- unc::driver::controller* ctr);
-
- /*
- * @brief - Creates the Request Body
- * @param[in] - val - VTN value structure val_vtn_t
- * @retval - char* - request body formed
- */
- const char* create_request_body(val_vtn_t& val_vtn);
+ /**
+ * @brief - parse vtn and append to the vector
+ * @param[in] - json_obj_vtn - json object
+ * @param[in] arr_idx - array index
+ * @param[in] cfgnode_vector - vector to which config node needs to be
+ * pushed
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on
+ * parsing vtn and appending to vector
+ * successfully/returns
+ * DRVAPI_RESPONSE_FAILURE on failure
+ */
+ drv_resp_code_t parse_vtn_append_vector(json_object *json_obj_vtn,
+ int arr_idx,
+ std::vector<unc::vtndrvcache::ConfigNode *>
+ &cfgnode_vector);
+
+ /**
+ * @brief - parse vbr and append to the vector
+ * @param[in] ctr - controller pointer
+ * @param[in] json_obj_vbr - json object
+ * @param[in] arr_idx - array index
+ * @param[in] cfgnode_vector - vector to which config node needs
+ * to be pushed
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on
+ * parsing vbr and appending to vector
+ * successfully/returns
+ * DRVAPI_RESPONSE_FAILURE on failure
+ */
+ drv_resp_code_t parse_vbr_append_vector(unc::driver::controller* ctr,
+ json_object *json_obj_vbr,
+ std::string vtn_name,
+ uint32_t arr_idx,
+ std::vector<
+ unc::vtndrvcache::ConfigNode *>
+ &cfgnode_vector);
+
+ /**
+ * @brief - Validates Create Vtn
+ * @param[in] key - VTN Key Structure key_vtn_t
+ * @param[in] ctr - Controller pointer
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on validating
+ * creation of vtn successfully/returns
+ * DRVAPI_RESPONSE_FAILURE on failure
+ */
+ drv_resp_code_t validate_create_vtn(const key_vtn_t& key_vtn,
+ unc::driver::controller* ctr);
+
+ /**
+ * @brief - Validates Delete Vtn
+ * @param[in] key - VTN Key Structure key_vtn_t
+ * @param[in] ctr - Controller pointer
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on validating
+ * deletion of vtn successfully/returns
+ * DRVAPI_RESPONSE_FAILURE on failure
+ */
+ drv_resp_code_t validate_delete_vtn(const key_vtn_t& key_vtn,
+ unc::driver::controller* ctr);
+
+ /**
+ * @brief - Validates Update Vtn
+ * @param[in] key - VTN Key Structure key_vtn_t
+ * @param[in] ctr - Controller pointer
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on validating
+ * updation of vtn successfully/returns
+ * DRVAPI_RESPONSE_FAILURE on failure
+ */
+ drv_resp_code_t validate_update_vtn(const key_vtn_t& key_vtn,
+ unc::driver::controller* ctr);
+
+ /**
+ * @brief - Checks is_vtn_exists_in_controller
+ * @param[in] key - VTN Key Structure key_vtn_t
+ * @param[in] ctr - Controller pointer
+ * @return uint32_t - returns response code from the controller
+ * on checking whether the vtn exists in
+ * the controller
+ */
+ uint32_t is_vtn_exists_in_controller(const key_vtn_t& key_vtn,
+ unc::driver::controller* ctr);
+
+ /**
+ * @brief - get_controller_response and checks the resp code
+ * @param[in] url - url to be set to
+ * @param[in] ctr - controller pointer
+ * @param[in] method - HttpMethod Enum
+ * @param[in] request_body - request body char pointer
+ * @return uint32_t - returns response code from the controller
+ */
+ uint32_t get_controller_response_code(std::string url,
+ unc::driver::controller* ctr,
+ unc::restjson::HttpMethod method,
+ const char* request_body);
+
+ /**
+ * @brief - Creates the Request Body
+ * @param[in] val - VTN value structure val_vtn_t
+ * @retval - char* - returns the request body formed
+ */
+ const char* create_request_body(const val_vtn_t& val_vtn);
+
+ /**
+ * @brief - parse the response data
+ * @param[in] - data which is the response
+ * @param[in] cfgnode_vector - to which the resp to be pushed
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on parsing the
+ * response data/returns DRVAPI_RESPONSE_FAILURE
+ * on failure
+ */
+ drv_resp_code_t parse_resp_data(char *data,
+ std::vector< unc::vtndrvcache::ConfigNode *>
+ &cfgnode_vector);
+
+ /**
+ * @brief - parse the vbr response data
+ * @param[in] data - data which is the response
+ * @param[in] vtn_name - vtn name
+ * @param[in] cfgnode_vector - to which the resp to be pushed
+ * @return drv_resp_code_t - returns DRVAPI_RESPONSE_SUCCESS on parsing vbr
+ * reponse data successfully/returns
+ * DRVAPI_RESPONSE_FAILURE on failure
+ */
+ drv_resp_code_t parse_vbr_resp_data(char *data, std::string vtn_name,
+ unc::driver::controller* ctr,
+ std::vector<
+ unc::vtndrvcache::ConfigNode *>
+ &cfgnode_vector);
private:
std::string idle_timeout_;
std::string hard_timeout_;
};
-}
-}
+} // namespace odcdriver
+} // namespace unc
#endif
* All rights reserved.
*
* This program and the accompanying materials are made
- * available under the
- * terms of the Eclipse Public License v1.0 which
- * accompanies this
- * distribution, and is available at
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
// Constructor
ODCController::ODCController(const key_ctr_t& key_ctr, const val_ctr_t& val_ctr)
-: ip_addr_(inet_ntoa(val_ctr.ip_address)),
- controller_name_(reinterpret_cast<const char*>(key_ctr.controller_name)),
- version_(reinterpret_cast<const char*>(val_ctr.version)),
- description_(reinterpret_cast<const char*>(val_ctr.description)),
- audit_(val_ctr.enable_audit) {
- pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
- pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
-}
+ : ip_addr_(inet_ntoa(val_ctr.ip_address)),
+ controller_name_(reinterpret_cast<const char*>(key_ctr.controller_name)),
+ version_(reinterpret_cast<const char*>(val_ctr.version)),
+ description_(reinterpret_cast<const char*>(val_ctr.description)),
+ user_name_(reinterpret_cast<const char*>(val_ctr.user)),
+ pass_word_(reinterpret_cast<const char*>(val_ctr.password)),
+ audit_(val_ctr.enable_audit) {
+ pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
+ pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
+ }
// Destructor
ODCController::~ODCController() {
-}
-
-// Gets the contoleer type
-unc_keytype_ctrtype_t ODCController::get_controller_type() {
pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
- return UNC_CT_ODC;
-}
-
-// Is ping need or not
-pfc_bool_t ODCController::is_ping_needed() {
- pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
- pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
- return PFC_FALSE;
}
-// Gets the ping interval
-uint32_t ODCController::get_ping_interval() {
+// Gets the controller type
+unc_keytype_ctrtype_t ODCController::get_controller_type() {
pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
- return 0;
+ return UNC_CT_ODC;
}
-// Gets the ping fail retry count
-uint32_t ODCController::get_ping_fail_retry_count() {
+pfc_bool_t ODCController::get_audit_status() {
pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
- return 0;
+ return audit_;
}
// Gets the controller id
return ip_addr_;
}
-// Ping controller or not
-pfc_bool_t ODCController::ping_controller() {
+// Reset connect or not
+pfc_bool_t ODCController::reset_connect() {
pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
return PFC_FALSE;
}
-// Reset connect or not
-pfc_bool_t ODCController::reset_connect() {
+// Gets the user name
+std::string ODCController::get_user_name() {
pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
- return PFC_FALSE;
-}
+ return user_name_;
}
+
+// Gets the pass word
+std::string ODCController::get_pass_word() {
+ pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
+ pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
+ return pass_word_;
}
+} // namespace odcdriver
+} // namespace unc
* All rights reserved.
*
* This program and the accompanying materials are made
- * available under the
- * terms of the Eclipse Public License v1.0 which
- * accompanies this
- * distribution, and is available at
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
// Get Intsance of vtndrvintf and Register Driver
pfc_bool_t ODCModule::init() {
pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
- pfc_log_info("Launching Odc Module");
+ pfc_log_debug("Launching Odc Module");
unc::driver::VtnDrvIntf* disp_inst =
- static_cast<unc::driver::VtnDrvIntf*> (getInstance("vtndrvintf"));
+ static_cast<unc::driver::VtnDrvIntf*> (getInstance("vtndrvintf"));
PFC_ASSERT(disp_inst != NULL);
uint32_t ret_val = disp_inst->register_driver(this);
if (ret_val) {
- pfc_log_info("Register driver failed");
+ pfc_log_debug("Register driver failed");
return PFC_FALSE;
}
pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
// Return New Contrtoller Pointer
unc::driver::controller* ODCModule::add_controller(const key_ctr_t& key_ctr,
- const val_ctr_t& val_ctr) {
+ const val_ctr_t& val_ctr) {
pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
+ const char* ctr_name =
+ reinterpret_cast<const char*>(key_ctr.controller_name);
+ if (0 == strlen(ctr_name)) {
+ return NULL;
+ }
pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
return new ODCController(key_ctr, val_ctr);
}
+// Start audit notification to TC
+uint32_t ODCModule::notify_audit_start_to_tc(
+ std::string controller_id) {
+ // Send start audit notification to TC
+ unc::tclib::TcLibModule* ptr_tclib_key_data;
+ pfc::core::Module* ptr_tclib = NULL;
+ ptr_tclib = static_cast<unc::tclib::TcLibModule*>
+ (unc::tclib::TcLibModule::getInstance(TCLIB_MODULE_NAME));
+ PFC_ASSERT(ptr_tclib != NULL);
+ ptr_tclib_key_data = static_cast<unc::tclib::TcLibModule*> (ptr_tclib);
+ ptr_tclib_key_data->TcLibAuditControllerRequest(controller_id);
+ return ODC_DRV_SUCCESS;
+}
+
// Return Updated Contrtoller Pointer
unc::driver::controller* ODCModule::update_controller(const key_ctr_t& key_ctr,
- const val_ctr_t& val_ctr, unc::driver::controller* ctr_ptr) {
+ const val_ctr_t& val_ctr,
+ unc::driver::controller*
+ ctr_ptr) {
pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
PFC_ASSERT(ctr_ptr != NULL);
unc::driver::controller *controller_ptr = NULL;
- const char* ctr_name = reinterpret_cast<const char*>(key_ctr.controller_name);
+ const char* ctr_name =
+ reinterpret_cast<const char*>(key_ctr.controller_name);
if (0 == strlen(ctr_name)) {
return controller_ptr;
}
-
- std::string ip_addr = inet_ntoa(val_ctr.ip_address);
- if (ip_addr.compare("0.0.0.0") != 0) {
- return controller_ptr;
- }
- const char* version = reinterpret_cast<const char*>(val_ctr.version);
- if (0 == strlen(version)) {
- return controller_ptr;
- }
-
- if (ctr_ptr != NULL) {
- delete ctr_ptr;
- }
pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
return new ODCController(key_ctr, val_ctr);
}
pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
unc::driver::driver_command* driver_cmd_ptr = NULL;
switch (key_type) {
- case UNC_KT_VTN: {
- pfc_log_debug("UNC_KT_VTN key type received");
- driver_cmd_ptr = new ODCVTNCommand();
- break;
+ case UNC_KT_VTN: {
+ pfc_log_debug("UNC_KT_VTN key type received");
+ driver_cmd_ptr = new ODCVTNCommand();
+ break;
+ }
+ case UNC_KT_VBRIDGE: {
+ pfc_log_debug("UNC_KT_VBR key type received");
+ driver_cmd_ptr = new ODCVBRCommand();
+ break;
+ }
+ case UNC_KT_VBR_IF: {
+ pfc_log_debug("UNC_KT_VBRIF key type received");
+ driver_cmd_ptr = new ODCVBRIfCommand();
+ break;
+ }
+ case UNC_KT_ROOT: {
+ pfc_log_debug("UNC_KT_ROOT key type received");
+ driver_cmd_ptr = new ODCROOTCommand();
+ break;
+ }
+ default:
+ pfc_log_debug("Unknown keytype received : %d", key_type);
+ break;
+ }
+ pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
+ return driver_cmd_ptr;
+}
+
+// Gets the ping interval
+uint32_t ODCModule::get_ping_interval() {
+ pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
+ pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
+ return PING_INTERVAL;
+}
+
+// Gets the ping fail retry count
+uint32_t ODCModule::get_ping_fail_retry_count() {
+ pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
+ pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
+ return PING_RETRY_COUNT;
+}
+
+// Is ping need or not
+pfc_bool_t ODCModule::is_ping_needed() {
+ pfc_log_debug(" %s Entering Function" , PFC_FUNCNAME);
+ pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
+ return PFC_TRUE;
+}
+
+// ping controller
+pfc_bool_t ODCModule::ping_controller(unc::driver::controller* ctr) {
+ PFC_ASSERT(ctr != NULL);
+ std::string ipaddress = ctr->get_host_address();
+
+ if ((ipaddress.compare("0.0.0.0") == 0) ||
+ (0 == strlen(ipaddress.c_str()))) {
+ pfc_log_debug(" ipaddress empty");
+ return PFC_FALSE;
}
- case UNC_KT_VBRIDGE: {
- pfc_log_debug("UNC_KT_VBR key type received");
- driver_cmd_ptr = new ODCVBRCommand();
- break;
+ restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
+ std::string url = "/controller/nb/v2/vtn/version";
+ uint32_t retval = ODC_DRV_FAILURE;
+ retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
+ if (ODC_DRV_FAILURE == retval) {
+ return PFC_FALSE;
+ }
+ retval = rest_util_obj.set_timeout(CONNECTION_TIME_OUT, REQUEST_TIME_OUT);
+ if (ODC_DRV_FAILURE == retval) {
+ return PFC_FALSE;
+ }
+ retval = rest_util_obj.create_request_header(url, restjson::HTTP_METHOD_GET);
+ if (ODC_DRV_FAILURE == retval) {
+ return PFC_FALSE;
}
- case UNC_KT_VBR_IF: {
- pfc_log_debug("UNC_KT_VBRIF key type received");
- driver_cmd_ptr = new ODCVBRIfCommand();
- break;
+ uint32_t resp = rest_util_obj.send_request_and_get_response_code();
+ if (RESP_OK != resp) {
+ return PFC_FALSE;
}
- default:
- pfc_log_debug("Unknown keytype received : %d", key_type);
- break;
+ pfc_bool_t new_audit_status = ctr->get_audit_status();
+ unc::driver::ConnectionStatus connection_status =
+ ctr->get_connection_status();
+ if ((connection_status) && (new_audit_status)) {
+ std::string controller_name = ctr->get_controller_id();
+ notify_audit_start_to_tc(controller_name);
}
pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
- return driver_cmd_ptr;
+ return PFC_TRUE;
}
unc::tclib::TcCommonRet ODCModule::HandleVote(unc::driver::controller*) {
pfc_log_debug(" %s Exiting Function" , PFC_FUNCNAME);
return unc::tclib::TC_FAILURE;
}
-}
-}
-// Declare C++ module
+} // namespace odcdriver
+} // namespace unc
PFC_MODULE_IPC_DECL(unc::odcdriver::ODCModule, 0);
--- /dev/null
+/*
+ * Copyright (c) 2012-2013 NEC Corporation
+ * All rights reserved.
+ *
+ * This program and the accompanying materials are made
+ * available under the
+ * terms of the Eclipse Public License v1.0 which
+ * accompanies this
+ * distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+#include <odc_root.hh>
+
+namespace unc {
+namespace odcdriver {
+
+// Read all vtns from Controller
+drv_resp_code_t ODCROOTCommand::read_root_child(
+ std::vector<unc::vtndrvcache::ConfigNode*> &cfg_ptr,
+ unc::driver::controller* ctrl_ptr) {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
+ ODCVTNCommand vtn_obj;
+ drv_resp_code_t ret_code = DRVAPI_RESPONSE_FAILURE;
+ ret_code = vtn_obj.read_all(ctrl_ptr, cfg_ptr);
+ if (ret_code == DRVAPI_RESPONSE_NO_SUCH_INSTANCE) {
+ pfc_log_debug("vtn_obj.read_all no object in ctl");
+ return DRVAPI_RESPONSE_NO_SUCH_INSTANCE;
+ }
+ std::vector<unc::vtndrvcache::ConfigNode*> ::iterator it_begin =
+ cfg_ptr.begin();
+ std::vector<unc::vtndrvcache::ConfigNode*> ::iterator it_last =
+ cfg_ptr.end();
+ for (; it_begin != it_last; it_begin++) {
+ unc::vtndrvcache::ConfigNode* ptr =
+ static_cast<unc::vtndrvcache::ConfigNode*>(*it_begin);
+ pfc_log_debug("odcdriver:read_root_child-get_key:%s ",
+ ptr->get_key().c_str());
+ }
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
+ return ret_code;
+}
+
+// Read all childs from vtns
+drv_resp_code_t
+ODCROOTCommand::read_all_child(unc::vtndrvcache::ConfigNode* cfg_ptr,
+ std::vector< unc::vtndrvcache
+ ::ConfigNode*>
+ &child_list,
+ unc::driver::controller* ctrl_ptr) {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
+ unc_key_type_t keytype = cfg_ptr->get_type();
+ pfc_log_debug("read_all_child for key Type:%d", keytype);
+ char* vtn_name = NULL;
+ char* vbr_name = NULL;
+ drv_resp_code_t ret_code = DRVAPI_RESPONSE_FAILURE;
+
+ switch (keytype) {
+ case UNC_KT_VTN: {
+ unc::vtndrvcache::CacheElementUtil <key_vtn_t, val_vtn_t, uint32_t>
+ * cache_util_ptr = dynamic_cast <unc::vtndrvcache::CacheElementUtil
+ <key_vtn_t, val_vtn_t, uint32_t> * >(cfg_ptr);
+ if (cache_util_ptr == NULL) {
+ pfc_log_error(" %s VTN. Exiting Function" , PFC_FUNCNAME);
+ return ret_code;
+ }
+ ODCVTNCommand vtn_obj;
+ key_vtn_t *key_struct = cache_util_ptr->getkey();
+ if (NULL == key_struct) {
+ return ret_code;
+ }
+ vtn_name = reinterpret_cast<char*>(key_struct->vtn_name);
+ pfc_log_debug("name %s", vtn_name);
+ ret_code = vtn_obj.get_vtn_child(vtn_name, ctrl_ptr, child_list);
+ pfc_log_debug("VTN child_list... zise: %d", static_cast<int>
+ (child_list.size()));
+ break;
+ }
+
+ case UNC_KT_VBRIDGE: {
+ unc::vtndrvcache::CacheElementUtil <key_vbr_t, val_vbr_t, uint32_t>
+ * cache_util_ptr = dynamic_cast <unc::vtndrvcache::CacheElementUtil
+ <key_vbr_t, val_vbr_t, uint32_t> * >(cfg_ptr);
+ ODCVBRCommand vbr_obj;
+ if (cache_util_ptr == NULL) {
+ pfc_log_error(" %s VBR. Exiting Function" , PFC_FUNCNAME);
+ return ret_code;
+ }
+ key_vbr_t *key_struct = cache_util_ptr->getkey();
+ if (NULL == key_struct) {
+ return ret_code;
+ }
+ vtn_name = reinterpret_cast<char*> (key_struct->vtn_key.vtn_name);
+ vbr_name = reinterpret_cast<char*> (key_struct->vbridge_name);
+ ret_code = vbr_obj.get_vbr_child(vtn_name, vbr_name, ctrl_ptr,
+ child_list);
+ pfc_log_debug("VBR child_list... zise: %d", static_cast<int>
+ (child_list.size()));
+ break;
+ }
+
+ case UNC_KT_VBR_IF: {
+ // no child for vbrif
+ break;
+ }
+
+ default:
+ ret_code = DRVAPI_RESPONSE_FAILURE;
+ break;
+ };
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
+ return ret_code;
+}
+} // namespace odcdriver
+} // namespace unc
*/
#include <odc_vbr.hh>
+#include <string>
namespace unc {
namespace odcdriver {
// Constructor
ODCVBRCommand::ODCVBRCommand()
-: age_interval_("600") {
-}
+ : age_interval_("600") {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
+ }
// Destructor
ODCVBRCommand::~ODCVBRCommand() {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
}
// Create Command and send Request to Controller
drv_resp_code_t ODCVBRCommand::create_cmd(key_vbr_t& key_vbr,
- val_vbr_t& val_vbr, unc::driver::controller *ctr_ptr) {
- pfc_log_debug("%s Entering function", PFC_FUNCNAME);
+ val_vbr_t& val_vbr,
+ unc::driver::controller
+ *ctr_ptr) {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
PFC_ASSERT(ctr_ptr != NULL);
-
- std::string ipaddress = ctr_ptr->get_host_address();
- if (0 == strlen(ipaddress.c_str())) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
- pfc_log_info("Controller Name in Create vbr %s", ipaddress.c_str());
-
std::string vbr_url = get_vbr_url(key_vbr);
if (0 == strlen(vbr_url.c_str())) {
return DRVAPI_RESPONSE_FAILURE;
}
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- pfc_log_debug("Return value for SetUserName Password %d", retval);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- retval = rest_util_obj.create_request_header(vbr_url,
- unc::restjson::HTTP_METHOD_POST);
- pfc_log_debug("Return value for Request Header %d", retval);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
const char* request = create_request_body(val_vbr);
- if (NULL != request) {
- retval = rest_util_obj.set_request_body(request);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- } else {
- pfc_log_info(" No Request Body Formed");
- }
- pfc_log_debug("Request Body for create vbr : %s", request);
-
- uint32_t resp = rest_util_obj.send_request_and_get_response_code();
- pfc_log_info("resp_code for create vbr is %d", resp);
-
+ uint32_t resp = get_controller_response_code(vbr_url, ctr_ptr,
+ unc::restjson
+ ::HTTP_METHOD_POST,
+ request);
+ pfc_log_debug("resp_code for create vbr is %d", resp);
if (RESP_CREATED != resp) {
return DRVAPI_RESPONSE_FAILURE;
}
- pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
return DRVAPI_RESPONSE_SUCCESS;
}
// Command to update vtn and Send request to Controller
drv_resp_code_t ODCVBRCommand::update_cmd(key_vbr_t& key_vbr,
- val_vbr_t& val_vbr, unc::driver::controller *ctr_ptr) {
- pfc_log_debug("%s Entering function", PFC_FUNCNAME);
+ val_vbr_t& val_vbr,
+ unc::driver::controller
+ *ctr_ptr) {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
PFC_ASSERT(ctr_ptr != NULL);
-
- std::string ipaddress = ctr_ptr->get_host_address();
- if (0 == strlen(ipaddress.c_str())) {
- return DRVAPI_RESPONSE_FAILURE;
- }
-
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
std::string vbr_url = get_vbr_url(key_vbr);
if (0 == strlen(vbr_url.c_str())) {
return DRVAPI_RESPONSE_FAILURE;
}
-
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- pfc_log_debug("Return value for SetUserName Password %d", retval);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
-
- retval = rest_util_obj.create_request_header(vbr_url,
- unc::restjson::HTTP_METHOD_PUT);
- pfc_log_debug("Return value for Request Header %d", retval);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
const char* request = create_request_body(val_vbr);
- if (NULL != request) {
- retval = rest_util_obj.set_request_body(request);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- } else {
- pfc_log_info(" No Request Body Formed");
- }
-
- uint32_t resp = rest_util_obj.send_request_and_get_response_code();
+ uint32_t resp = get_controller_response_code(vbr_url, ctr_ptr,
+ unc::restjson
+ ::HTTP_METHOD_PUT,
+ request);
if (RESP_OK != resp) {
return DRVAPI_RESPONSE_FAILURE;
}
- pfc_log_info("resp_code for update vbr is %d", resp);
- pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+ pfc_log_debug("resp_code for update vbr is %d", resp);
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
return DRVAPI_RESPONSE_SUCCESS;
}
-// Delete Request sned to the Controller
+// Delete Request send to the Controller
drv_resp_code_t ODCVBRCommand::delete_cmd(key_vbr_t& key_vbr,
- val_vbr_t& val_vbr, unc::driver::controller *ctr_ptr) {
- pfc_log_debug("%s Entering function", PFC_FUNCNAME);
+ val_vbr_t& val_vbr,
+ unc::driver::controller
+ *ctr_ptr) {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
PFC_ASSERT(ctr_ptr != NULL);
-
- std::string ipaddress = ctr_ptr->get_host_address();
- if (0 == strlen(ipaddress.c_str())) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
std::string vbr_url = get_vbr_url(key_vbr);
+ pfc_log_debug("vbr_url:%s", vbr_url.c_str());
if (0 == strlen(vbr_url.c_str())) {
return DRVAPI_RESPONSE_FAILURE;
}
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- pfc_log_debug("Return value for SetUserName Password %d", retval);
-
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- retval = rest_util_obj.create_request_header(vbr_url,
- unc::restjson::HTTP_METHOD_DELETE);
- pfc_log_debug("Return value for Request Header %d", retval);
-
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
-
- uint32_t resp = rest_util_obj.send_request_and_get_response_code();
-
+ uint32_t resp = get_controller_response_code(vbr_url, ctr_ptr,
+ unc::restjson
+ ::HTTP_METHOD_DELETE,
+ NULL);
if (RESP_OK != resp) {
return DRVAPI_RESPONSE_FAILURE;
}
- pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
return DRVAPI_RESPONSE_SUCCESS;
}
// Creates Request Body
-const char* ODCVBRCommand::create_request_body(val_vbr_t& val_vbr) {
- pfc_log_debug("%s Entering function", PFC_FUNCNAME);
+const char* ODCVBRCommand::create_request_body(const val_vbr_t& val_vbr) {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
unc::restjson::JsonBuildParse json_obj;
json_object *jobj = json_obj.create_json_obj();
- char* description = reinterpret_cast<char*>(val_vbr.vbr_description);
- int ret_val = 1;
-
+ const char* description = reinterpret_cast<const char*>
+ (val_vbr.vbr_description);
+ uint32_t ret_val = 1;
if (0 != strlen(description)) {
ret_val = json_obj.build(jobj, "description", description);
if (ret_val) {
return NULL;
}
const char* req_body = json_obj.json_obj_to_json_string(jobj);
- pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
return req_body;
}
// validates the operation
drv_resp_code_t ODCVBRCommand::validate_op(key_vbr_t& key_vbr,
- val_vbr_t& val_vbr, unc::driver::controller* ctr,
- uint32_t operation) {
- pfc_log_debug("%s Entering function", PFC_FUNCNAME);
+ val_vbr_t& val_vbr,
+ unc::driver::controller*
+ ctr,
+ uint32_t operation) {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
drv_resp_code_t resp_code = DRVAPI_RESPONSE_FAILURE;
switch (operation) {
- case UNC_OP_CREATE:
- resp_code = validate_create_vbr(key_vbr, ctr);
- break;
- case UNC_OP_UPDATE:
- resp_code = validate_update_vbr(key_vbr, ctr);
- break;
- case UNC_OP_DELETE:
- resp_code = validate_delete_vbr(key_vbr, ctr);
- break;
- default:
- pfc_log_info("Unknown operation received %d", operation);
- break;
+ case UNC_OP_CREATE:
+ resp_code = validate_create_vbr(key_vbr, ctr);
+ break;
+ case UNC_OP_UPDATE:
+ resp_code = validate_update_vbr(key_vbr, ctr);
+ break;
+ case UNC_OP_DELETE:
+ resp_code = validate_delete_vbr(key_vbr, ctr);
+ break;
+ default:
+ pfc_log_debug("Unknown operation received %d", operation);
+ break;
}
- pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
return resp_code;
}
// Validates create vbr
drv_resp_code_t ODCVBRCommand::validate_create_vbr(key_vbr_t& key_vbr,
- unc::driver::controller* ctr) {
- pfc_log_debug("%s Entering function", PFC_FUNCNAME);
+ unc::driver::controller*
+ ctr) {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
uint32_t resp_code = ODC_DRV_FAILURE;
resp_code = is_vtn_exists_in_controller(key_vbr, ctr);
if (RESP_NOT_FOUND == resp_code) {
- return DRVAPI_RESPONSE_FAILURE;
+ return DRVAPI_RESPONSE_FAILURE;
}
if (RESP_OK == resp_code) {
resp_code = is_vbr_exists_in_controller(key_vbr, ctr);
return DRVAPI_RESPONSE_SUCCESS;
}
}
- pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
return DRVAPI_RESPONSE_FAILURE;
}
+// Validate delete vbridge
drv_resp_code_t ODCVBRCommand::validate_delete_vbr(key_vbr_t& key_vbr,
- unc::driver::controller* ctr) {
- pfc_log_debug("%s Entering function", PFC_FUNCNAME);
+ unc::driver::controller*
+ ctr) {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
uint32_t vbr_resp_code = ODC_DRV_FAILURE;
-
vbr_resp_code = is_vbr_exists_in_controller(key_vbr, ctr);
if (RESP_OK == vbr_resp_code) {
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return DRVAPI_RESPONSE_SUCCESS;
}
- pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
return DRVAPI_RESPONSE_FAILURE;
}
-// Validates update vbr
+// Validates update vbridge
drv_resp_code_t ODCVBRCommand::validate_update_vbr(key_vbr_t& key_vbr,
- unc::driver::controller* ctr) {
+ unc::driver::controller*
+ ctr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
uint32_t vbr_resp_code = ODC_DRV_FAILURE;
vbr_resp_code = is_vbr_exists_in_controller(key_vbr, ctr);
}
// Checks the exists in controlle ror not
-uint32_t ODCVBRCommand::is_vtn_exists_in_controller(key_vbr_t& key_vbr,
- unc::driver::controller* ctr) {
+uint32_t ODCVBRCommand::is_vtn_exists_in_controller(const key_vbr_t& key_vbr,
+ unc::driver::controller*
+ ctr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
- char* vtnname = NULL;
- vtnname = reinterpret_cast<char*>(key_vbr.vtn_key.vtn_name);
+ const char* vtnname = NULL;
+ vtnname = reinterpret_cast<const char*>(key_vbr.vtn_key.vtn_name);
if (0 == strlen(vtnname)) {
return ODC_DRV_FAILURE;
}
- std::string url = "/controller/nb/v2/vtn/default/vtns/";
+ std::string url = "";
+ url.append(VTN_URL);
+ url.append("/");
url.append(vtnname);
- uint32_t response_code = get_controller_response(url, ctr);
+ uint32_t response_code = get_controller_response_code(url, ctr,
+ unc::restjson
+ ::HTTP_METHOD_GET,
+ NULL);
pfc_log_debug("Response code from Controller is : %d ", response_code);
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return response_code;
}
// Checks vbr exists in controller or not
uint32_t ODCVBRCommand::is_vbr_exists_in_controller(key_vbr_t& key_vbr,
- unc::driver::controller* ctr) {
+ unc::driver::controller*
+ ctr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
std::string vbr_url = get_vbr_url(key_vbr);
if (0 == strlen(vbr_url.c_str())) {
return ODC_DRV_FAILURE;
}
- uint32_t response_code = get_controller_response(vbr_url, ctr);
+ uint32_t response_code = get_controller_response_code(vbr_url, ctr,
+ unc::restjson
+ ::HTTP_METHOD_GET,
+ NULL);
pfc_log_debug("Response code from Controller is : %d ", response_code);
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return response_code;
}
// Gets the Controller Response
-uint32_t ODCVBRCommand::get_controller_response(std::string url,
- unc::driver::controller* ctr) {
+uint32_t ODCVBRCommand::get_controller_response_code(std::string url,
+ unc::driver::controller*
+ ctr,
+ unc::restjson
+ ::HttpMethod method,
+ const char* request_body) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
PFC_ASSERT(ctr != NULL);
std::string ipaddress = ctr->get_host_address();
- if (0 == strlen(ipaddress.c_str())) {
+ if (0 == strlen(ipaddress.c_str())) {
+ return ODC_DRV_FAILURE;
+ }
+ if (( method != unc::restjson::HTTP_METHOD_POST ) &&
+ (method != unc::restjson::HTTP_METHOD_PUT) &&
+ (method != unc::restjson::HTTP_METHOD_DELETE) &&
+ (method != unc::restjson::HTTP_METHOD_GET)) {
+ pfc_log_debug("Invalid Method : %d", method);
return ODC_DRV_FAILURE;
}
+ std::string username_ctr = ctr->get_user_name();
+ std::string password_ctr = ctr->get_pass_word();
+
unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- pfc_log_debug("Return value for SetUserName Password %d", retval);
+ uint32_t retval = ODC_DRV_FAILURE;
+ if ((0 == strlen(username_ctr.c_str()))
+ || (0 == strlen(password_ctr.c_str()))) {
+ retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
+ } else {
+ retval = rest_util_obj.set_username_password(username_ctr, password_ctr);
+ }
if (ODC_DRV_FAILURE == retval) {
- return retval;
+ return DRVAPI_RESPONSE_FAILURE;
}
- retval = rest_util_obj.create_request_header(url,
- unc::restjson::HTTP_METHOD_GET);
+ retval = rest_util_obj.set_timeout(CONNECTION_TIME_OUT, REQUEST_TIME_OUT);
if (ODC_DRV_FAILURE == retval) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ retval = rest_util_obj.create_request_header(url, method);
+ if (ODC_DRV_FAILURE == retval) {
+ pfc_log_debug("Failure in create request header : %d", retval);
return retval;
}
+ if ((method == unc::restjson::HTTP_METHOD_POST) ||
+ (method == unc::restjson::HTTP_METHOD_PUT)) {
+ if (NULL != request_body) {
+ pfc_log_debug("Request Body : %s", request_body);
+ retval = rest_util_obj.set_request_body(request_body);
+ if (ODC_DRV_FAILURE == retval) {
+ pfc_log_debug("Failure in set Request Body %d", retval);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ }
+ }
uint32_t resp = rest_util_obj.send_request_and_get_response_code();
pfc_log_debug("Response code from Controller is : %d ", resp);
- pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+ pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
return resp;
}
+drv_resp_code_t ODCVBRCommand::parse_vbrif_append_vector(std::string vtn_name,
+ std::string vbr_name,
+ json_object *json_obj,
+ uint32_t arr_idx,
+ std::string url,
+ unc::driver
+ ::controller* ctr,
+ std::vector< unc::vtndrvcache
+ ::ConfigNode *>
+ &cfgnode_vector) {
+ pfc_log_debug("%s Enter function", PFC_FUNCNAME);
+ key_vbr_if_t key_vbr_if;
+ pfcdrv_val_vbr_if_t val_vbr_if;
+ memset(&key_vbr_if, 0, sizeof(key_vbr_if_t));
+ memset(&val_vbr_if, 0, sizeof(pfcdrv_val_vbr_if_t));
+
+ std::string name = "";
+ std::string description = "";
+ std::string entity_state = "";
+ uint32_t ret_val = unc::restjson::JsonBuildParse::parse(json_obj,
+ "name", arr_idx, name);
+ if (ret_val) {
+ pfc_log_error("JsonBuildParse::parse fail.");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ pfc_log_debug("vbr_if name: %s", name.c_str());
+ if (strlen(name.c_str()) == 0) {
+ pfc_log_error("NO vbr_if name");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ ret_val = unc::restjson::JsonBuildParse::parse(json_obj,
+ "description",
+ arr_idx, description);
+ if (ret_val) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ pfc_log_debug("vbr_if description: %s", description.c_str());
+ // Fills the vbrif KEY structure
+ strncpy(reinterpret_cast<char*> (key_vbr_if.vbr_key.vtn_key.vtn_name),
+ vtn_name.c_str(), sizeof(key_vbr_if.vbr_key.vtn_key.vtn_name) - 1);
+ pfc_log_debug(" vtn name in vbrif:%s", reinterpret_cast<char*>
+ (key_vbr_if.vbr_key.vtn_key.vtn_name));
+
+ strncpy(reinterpret_cast<char*> (key_vbr_if.vbr_key.vbridge_name),
+ vbr_name.c_str(), sizeof(key_vbr_if.vbr_key.vbridge_name) - 1);
+ pfc_log_error(" vbr name in vbrif:%s",
+ reinterpret_cast<char*> (key_vbr_if.vbr_key.vbridge_name));
+
+ strncpy(reinterpret_cast<char*> (key_vbr_if.if_name), name.c_str(),
+ sizeof(key_vbr_if.if_name) - 1);
+ pfc_log_debug(" vbrif name:%s",
+ reinterpret_cast<char*> (key_vbr_if.if_name));
+
+ // Fills vbrif VAL structure
+ val_vbr_if.valid[PFCDRV_IDX_VAL_VBRIF] = UNC_VF_VALID;
+
+ if (0 == strlen(description.c_str())) {
+ val_vbr_if.val_vbrif.valid[UPLL_IDX_DESC_VBRI] = UNC_VF_INVALID;
+ } else {
+ val_vbr_if.val_vbrif.valid[UPLL_IDX_DESC_VBRI] = UNC_VF_VALID;
+ strncpy(reinterpret_cast<char*> (val_vbr_if.val_vbrif.description),
+ description.c_str(), sizeof(val_vbr_if.val_vbrif.description) - 1);
+ }
+ url.append("/");
+ url.append(name);
+ val_vbr_if.val_vbrif.valid[UPLL_IDX_PM_VBRI] = UNC_VF_VALID;
+ json_object *jobj = read_portmap(ctr, url);
+ pfc_log_debug("json response %s:",
+ unc::restjson::JsonBuildParse::json_obj_to_json_string(jobj));
+ if (json_object_is_type(jobj, json_type_null)) {
+ pfc_log_debug("null jobj no portmap");
+ } else {
+ std::string vlanid = "0";
+ ret_val = unc::restjson::JsonBuildParse::parse(jobj, "vlan", -1,
+ vlanid);
+ if (ret_val) {
+ pfc_log_debug("vlan parse error");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ pfc_log_debug("vlan id in portmap read %s", vlanid.c_str());
+ if (0 == atoi(vlanid.c_str())) {
+ val_vbr_if.val_vbrif.portmap.valid[UPLL_IDX_VLAN_ID_PM] = UNC_VF_INVALID;
+ pfc_log_debug("untagged");
+ val_vbr_if.val_vbrif.portmap.tagged = UPLL_VLAN_UNTAGGED;
+ val_vbr_if.val_vbrif.portmap.valid[UPLL_IDX_TAGGED_PM] = UNC_VF_INVALID;
+ } else {
+ pfc_log_debug("vlan id valid");
+ val_vbr_if.val_vbrif.portmap.valid[UPLL_IDX_VLAN_ID_PM] = UNC_VF_VALID;
+ val_vbr_if.val_vbrif.portmap.vlan_id = atoi(vlanid.c_str());
+ pfc_log_debug("%s vlan id ", vlanid.c_str());
+ pfc_log_debug("vlan id tagged");
+ val_vbr_if.val_vbrif.portmap.tagged = UPLL_VLAN_TAGGED;
+ val_vbr_if.val_vbrif.portmap.valid[UPLL_IDX_TAGGED_PM] = UNC_VF_VALID;
+ }
+ json_object *jobj_node = NULL;
+ json_object *jobj_port = NULL;
+ ret_val = unc::restjson::JsonBuildParse::parse(jobj, "node", -1,
+ jobj_node);
+ pfc_log_debug("node");
+ if (ret_val) {
+ pfc_log_debug("node is null");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ ret_val = unc::restjson::JsonBuildParse::parse(jobj, "port",
+ -1, jobj_port);
+ if (ret_val) {
+ pfc_log_debug("port is null");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ std::string node_id = "";
+ std::string port_name = "";
+ std::string logical_port = "PP-";
+
+ if ((!json_object_is_type(jobj_node, json_type_null)) &&
+ (!json_object_is_type(jobj_port, json_type_null))) {
+ ret_val = unc::restjson::JsonBuildParse::parse(jobj_node, "id",
+ -1, node_id);
+ if (ret_val) {
+ pfc_log_debug("id parse error");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ ret_val = unc::restjson::JsonBuildParse::parse(jobj_port, "name",
+ -1, port_name);
+ if (ret_val) {
+ pfc_log_debug("name parse error");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ if ((0 == strlen(node_id.c_str())) || (0 == strlen(port_name.c_str()))) {
+ pfc_log_debug("port or node is 0");
+ val_vbr_if.val_vbrif.portmap.valid[UPLL_IDX_LOGICAL_PORT_ID_PM] =
+ UNC_VF_INVALID;
+ } else {
+ logical_port.append(node_id);
+ logical_port.append("-");
+ logical_port.append(port_name);
+ strncpy(reinterpret_cast<char*>
+ (val_vbr_if.val_vbrif.portmap.logical_port_id),
+ logical_port.c_str(),
+ sizeof(val_vbr_if.val_vbrif.portmap.logical_port_id) - 1);
+ pfc_log_debug("%s logical port id in readportmap " ,
+ reinterpret_cast<char*>
+ (val_vbr_if.val_vbrif.portmap.logical_port_id));
+ val_vbr_if.val_vbrif.portmap.valid[UPLL_IDX_LOGICAL_PORT_ID_PM] =
+ UNC_VF_VALID;
+ }
+ } else {
+ val_vbr_if.val_vbrif.portmap.valid[UPLL_IDX_LOGICAL_PORT_ID_PM] =
+ UNC_VF_INVALID;
+ }
+ }
+
+ unc::vtndrvcache::ConfigNode *cfgptr =
+ new unc::vtndrvcache::CacheElementUtil
+ <key_vbr_if_t, pfcdrv_val_vbr_if_t, uint32_t> (
+ &key_vbr_if,
+ &val_vbr_if,
+ uint32_t(UNC_OP_READ));
+
+ cfgnode_vector.push_back(cfgptr);
+ pfc_log_debug("%s Exit function", PFC_FUNCNAME);
+ return DRVAPI_RESPONSE_SUCCESS;
+}
+
+// Getting vbridge child if available
+drv_resp_code_t ODCVBRCommand::get_vbr_child(std::string vtn_name,
+ std::string vbr_name,
+ unc::driver::controller* ctr,
+ std::vector< unc::vtndrvcache
+ ::ConfigNode *>
+ &cfgnode_vector) {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
+ if ((0 == strlen(vtn_name.c_str())) || (0 == strlen(vbr_name.c_str()))) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ std::string url = "";
+ url.append(VTN_URL);
+ url.append("/");
+ url.append(vtn_name);
+ url.append("/vbridges/");
+ url.append(vbr_name);
+ url.append("/interfaces");
+
+ PFC_ASSERT(ctr != NULL);
+ std::string ipaddress = ctr->get_host_address();
+ if (0 == strlen(ipaddress.c_str())) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ std::string username_ctr = ctr->get_user_name();
+ std::string password_ctr = ctr->get_pass_word();
+
+ unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
+ uint32_t retval = ODC_DRV_FAILURE;
+ if ((0 == strlen(username_ctr.c_str()))
+ || (0 == strlen(password_ctr.c_str()))) {
+ retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
+ } else {
+ retval = rest_util_obj.set_username_password(username_ctr, password_ctr);
+ }
+ if (ODC_DRV_FAILURE == retval) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ retval = rest_util_obj.set_timeout(CONNECTION_TIME_OUT, REQUEST_TIME_OUT);
+ if (ODC_DRV_FAILURE == retval) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ retval = rest_util_obj.create_request_header(url,
+ unc::restjson::HTTP_METHOD_GET);
+ if (ODC_DRV_FAILURE == retval) {
+ pfc_log_error("rest_util_obj.create_request_header fail.");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ uint32_t resp = rest_util_obj.send_request_and_get_response_code();
+ if (RESP_OK != resp) {
+ pfc_log_error("rest_util_obj.send_request_and_get_response_code fail");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ unc::restjson::HttpContent_t* content = rest_util_obj.get_response_body();
+ if (content == NULL) {
+ pfc_log_error("content is null");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ char *data = content->memory;
+ pfc_log_debug("data-:%s", data);
+ drv_resp_code_t parse_ret = DRVAPI_RESPONSE_FAILURE;
+ parse_ret = parse_vbrif_resp_data(vtn_name, vbr_name, url, ctr, data,
+ cfgnode_vector);
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
+ return parse_ret;
+}
+drv_resp_code_t ODCVBRCommand::parse_vbrif_resp_data(std::string vtn_name,
+ std::string vbr_name,
+ std::string url,
+ unc::driver::controller*
+ ctr,
+ char *data,
+ std::vector< unc::vtndrvcache
+ ::ConfigNode *>
+ &cfgnode_vector) {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
+ json_object* jobj = unc::restjson::JsonBuildParse::
+ string_to_json_object(data);
+ if (json_object_is_type(jobj, json_type_null)) {
+ pfc_log_error("json_object_is_type fail");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ uint32_t array_length = 0;
+ json_object *json_obj_vbrif = NULL;
+
+ uint32_t ret_val = unc::restjson::JsonBuildParse::parse(jobj, "interface",
+ -1, json_obj_vbrif);
+ if (ret_val) {
+ pfc_log_error("JsonBuildParse::parse fail");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ if (json_object_is_type(json_obj_vbrif, json_type_array)) {
+ array_length = restjson::JsonBuildParse::get_array_length(jobj,
+ "interface");
+ }
+
+ pfc_log_debug("interface array_length:%d", array_length);
+
+ if (json_object_is_type(json_obj_vbrif, json_type_null)) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ drv_resp_code_t resp_code = DRVAPI_RESPONSE_FAILURE;
+ for (uint32_t arr_idx = 0; arr_idx < array_length; arr_idx++) {
+ pfc_log_debug("inside array_length for loop");
+ resp_code = parse_vbrif_append_vector(vtn_name, vbr_name, json_obj_vbrif,
+ arr_idx, url, ctr, cfgnode_vector);
+ if (DRVAPI_RESPONSE_FAILURE == resp_code) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ }
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
+ return DRVAPI_RESPONSE_SUCCESS;
+}
+
+// Reading port-map from active controller
+json_object* ODCVBRCommand::read_portmap(unc::driver::controller* ctr,
+ std::string url) {
+ pfc_log_debug("%s Entering Function ... ", PFC_FUNCNAME);
+ url.append("/portmap");
+
+ json_object* jobj = NULL;
+ PFC_ASSERT(ctr != NULL);
+ std::string ipaddress = ctr->get_host_address();
+ if (0 == strlen(ipaddress.c_str())) {
+ return jobj;
+ }
+ std::string username_ctr = ctr->get_user_name();
+ std::string password_ctr = ctr->get_pass_word();
+
+ unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
+ uint32_t retval = ODC_DRV_FAILURE;
+ if ((0 == strlen(username_ctr.c_str()))
+ || (0 == strlen(password_ctr.c_str()))) {
+ retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
+ } else {
+ retval = rest_util_obj.set_username_password(username_ctr, password_ctr);
+ }
+ if (ODC_DRV_FAILURE == retval) {
+ return jobj;
+ }
+ retval = rest_util_obj.set_timeout(CONNECTION_TIME_OUT, REQUEST_TIME_OUT);
+ if (ODC_DRV_FAILURE == retval) {
+ return jobj;
+ }
+ retval = rest_util_obj.create_request_header(url,
+ unc::restjson::HTTP_METHOD_GET);
+ if (ODC_DRV_FAILURE == retval) {
+ return jobj;
+ }
+ uint32_t resp = rest_util_obj.send_request_and_get_response_code();
+ if (RESP_OK != resp) {
+ return jobj;
+ }
+ unc::restjson::HttpContent_t* content = rest_util_obj.get_response_body();
+ if (content == NULL) {
+ return jobj;
+ }
+ char *data = content->memory;
+ jobj = unc::restjson::JsonBuildParse::string_to_json_object(data);
+ pfc_log_debug("%s Exiting Function ... ", PFC_FUNCNAME);
+ return jobj;
+}
+
+// Constructing URL for vbridge,inject request to controller
std::string ODCVBRCommand::get_vbr_url(key_vbr_t& key_vbr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
char* vtnname = NULL;
char* vbrname = NULL;
-
- std::string url = "/controller/nb/v2/vtn/default/vtns/";
+ std::string url = "";
+ url.append(VTN_URL);
+ url.append("/");
vtnname = reinterpret_cast<char*>(key_vbr.vtn_key.vtn_name);
if (0 == strlen(vtnname)) {
return "";
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return url;
}
-}
-}
+} // namespace odcdriver
+} // namespace unc
// Destructor
ODCVBRIfCommand::~ODCVBRIfCommand() {
+ pfc_log_debug("%s Entering function", PFC_FUNCNAME);
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
}
// Creates Request Body for Port Map
reinterpret_cast<char*>(vbrif_val.val_vbrif.portmap.logical_port_id);
if (logical_port_id.length() > 0) {
- pfc_log_info("logical_port_id is %s", logical_port_id.c_str());
+ pfc_log_debug("logical_port_id is %s", logical_port_id.c_str());
if (logical_port_id.compare(0, 3, "PP-") == 0) {
switch_id = logical_port_id.substr(3, 23);
port_name = logical_port_id.substr(27);
}
} else {
- pfc_log_info("logical_port_id is empty");
+ pfc_log_debug("logical_port_id is empty");
return NULL;
}
json_object *jobj_node = json_obj.create_json_obj();
json_object *jobj_port = json_obj.create_json_obj();
- int ret_val = json_obj.build(jobj_node, "type", "OF");
+ std::ostringstream convert_vlanid;
+ convert_vlanid << vbrif_val.val_vbrif.portmap.vlan_id;
+ std::string vlanid = "";
+ vlanid.append(convert_vlanid.str());
+ if (0 != strlen(vlanid.c_str())) {
+ uint32_t ret_val = json_obj.build(jobj_parent, "vlan", vlanid);
+ if (ret_val) {
+ return NULL;
+ }
+ }
+ uint32_t ret_val = json_obj.build(jobj_node, "type", "OF");
if (ret_val) {
return NULL;
}
}
const char* req_body = json_obj.json_obj_to_json_string(jobj_parent);
- pfc_log_info("%s json request ", req_body);
+ pfc_log_debug("%s json request ", req_body);
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return req_body;
}
-// Creates command for portmap
-uint32_t ODCVBRIfCommand::create_cmd_port_map(key_vbr_if_t& vbrif_key,
- pfcdrv_val_vbr_if_t& vbrif_val, unc::driver::controller *ctr_ptr) {
- pfc_log_debug("%s Entering function", PFC_FUNCNAME);
- PFC_ASSERT(ctr_ptr != NULL);
- std::string ipaddress = ctr_ptr->get_host_address();
+// Get controller response code to validate success/failure
+uint32_t ODCVBRIfCommand::get_controller_response_code(std::string url,
+ unc::driver::controller*
+ ctr,
+ unc::restjson
+ ::HttpMethod method,
+ const char*
+ request_body) {
+ pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
+ PFC_ASSERT(ctr != NULL);
+ std::string ipaddress = ctr->get_host_address();
+ pfc_log_debug("ip address of controller is %s", ipaddress.c_str());
if (0 == strlen(ipaddress.c_str())) {
return ODC_DRV_FAILURE;
}
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
-
- std::string vbrif_url = get_vbrif_url(vbrif_key);
- if (0 == strlen(vbrif_url.c_str())) {
+ if (( method != unc::restjson::HTTP_METHOD_POST ) &&
+ (method != unc::restjson::HTTP_METHOD_PUT) &&
+ (method != unc::restjson::HTTP_METHOD_DELETE) &&
+ (method != unc::restjson::HTTP_METHOD_GET)) {
+ pfc_log_debug("Invalid Method : %d", method);
return ODC_DRV_FAILURE;
}
- vbrif_url.append("/portmap");
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
+ std::string username_ctr = ctr->get_user_name();
+ std::string password_ctr = ctr->get_pass_word();
+
+ unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
+ uint32_t retval = ODC_DRV_FAILURE;
+ if ((0 == strlen(username_ctr.c_str()))
+ || (0 == strlen(password_ctr.c_str()))) {
+ retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
+ } else {
+ retval = rest_util_obj.set_username_password(username_ctr, password_ctr);
+ }
if (ODC_DRV_FAILURE == retval) {
return DRVAPI_RESPONSE_FAILURE;
}
- retval = rest_util_obj.create_request_header(vbrif_url,
- unc::restjson::HTTP_METHOD_POST);
+ retval = rest_util_obj.set_timeout(CONNECTION_TIME_OUT, REQUEST_TIME_OUT);
if (ODC_DRV_FAILURE == retval) {
return DRVAPI_RESPONSE_FAILURE;
}
- const char* request = create_request_body_port_map(vbrif_val);
- if (NULL != request) {
- retval = rest_util_obj.set_request_body(request);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
+ retval = rest_util_obj.create_request_header(url, method);
+ if (ODC_DRV_FAILURE == retval) {
+ pfc_log_debug("Failure in create request header : %d", retval);
+ return retval;
+ }
+ if ((method == unc::restjson::HTTP_METHOD_POST) ||
+ (method == unc::restjson::HTTP_METHOD_PUT)) {
+ if (NULL != request_body) {
+ pfc_log_debug("Request Body : %s", request_body);
+ retval = rest_util_obj.set_request_body(request_body);
+ if (ODC_DRV_FAILURE == retval) {
+ pfc_log_debug("Failure in set Request Body %d", retval);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
}
- } else {
- pfc_log_info(" No Request Body Formed");
}
uint32_t resp = rest_util_obj.send_request_and_get_response_code();
- if (RESP_OK != resp) {
- return ODC_DRV_FAILURE;
- }
- pfc_log_info("response code returned in create_cmd_port_map is %d", resp);
- pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
- return ODC_DRV_SUCCESS;
+ pfc_log_debug("Response code from Controller is : %d ", resp);
+ pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
+ return resp;
}
+// Form URL for vbridge interface ,inject request to controller
std::string ODCVBRIfCommand::get_vbrif_url(key_vbr_if_t& vbrif_key) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
char* vtnname = NULL;
- std::string url = "/controller/nb/v2/vtn/default/vtns/";
+ std::string url = "";
+ url.append(VTN_URL);
+ url.append("/");
vtnname = reinterpret_cast<char*>(vbrif_key.vbr_key.vtn_key.vtn_name);
if (0 == strlen(vtnname)) {
return "";
// Updates the Portmap Command and send it to conttoller
uint32_t ODCVBRIfCommand::update_cmd_port_map(key_vbr_if_t& vbrif_key,
- pfcdrv_val_vbr_if_t& vbrif_val, unc::driver::controller *ctr_ptr) {
+ pfcdrv_val_vbr_if_t& vbrif_val,
+ unc::driver::controller
+ *ctr_ptr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
PFC_ASSERT(ctr_ptr != NULL);
- std::string ipaddress = ctr_ptr->get_host_address();
- if (0 == strlen(ipaddress.c_str())) {
- return ODC_DRV_FAILURE;
- }
-
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
std::string vbrif_url = get_vbrif_url(vbrif_key);
if (0 == strlen(vbrif_url.c_str())) {
return ODC_DRV_FAILURE;
}
vbrif_url.append("/portmap");
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- retval = rest_util_obj.create_request_header(vbrif_url,
- unc::restjson::HTTP_METHOD_PUT);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
const char* request = create_request_body_port_map(vbrif_val);
- if (NULL != request) {
- retval = rest_util_obj.set_request_body(request);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- } else {
- pfc_log_info(" No Request Body Formed");
- }
- uint32_t resp = rest_util_obj.send_request_and_get_response_code();
+ uint32_t resp = get_controller_response_code(vbrif_url, ctr_ptr,
+ unc::restjson
+ ::HTTP_METHOD_PUT, request);
if (RESP_OK != resp) {
return ODC_DRV_FAILURE;
}
// Delete Command for Port map created and send to Controller
uint32_t ODCVBRIfCommand::delete_cmd_port_map(key_vbr_if_t& vbrif_key,
- pfcdrv_val_vbr_if_t& vbrif_val, unc::driver::controller *ctr_ptr) {
+ pfcdrv_val_vbr_if_t& vbrif_val,
+ unc::driver::controller
+ *ctr_ptr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
PFC_ASSERT(ctr_ptr != NULL);
- std::string ipaddress = ctr_ptr->get_host_address();
- if (0 == strlen(ipaddress.c_str())) {
- return ODC_DRV_FAILURE;
- }
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
std::string vbrif_url = get_vbrif_url(vbrif_key);
if (0 == strlen(vbrif_url.c_str())) {
return ODC_DRV_FAILURE;
}
vbrif_url.append("/portmap");
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- retval = rest_util_obj.create_request_header(vbrif_url,
- unc::restjson::HTTP_METHOD_DELETE);
-
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- uint32_t resp = rest_util_obj.send_request_and_get_response_code();
-
+ uint32_t resp = get_controller_response_code(vbrif_url, ctr_ptr,
+ unc::restjson
+ ::HTTP_METHOD_DELETE, NULL);
if (RESP_OK != resp) {
return ODC_DRV_FAILURE;
}
- pfc_log_info("response code returned in delete_cmd_port_map is %d", resp);
+ pfc_log_debug("response code returned in delete_cmd_port_map is %d", resp);
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return ODC_DRV_SUCCESS;
}
// Create Command for vbrif
drv_resp_code_t ODCVBRIfCommand::create_cmd(key_vbr_if_t& vbrif_key,
- pfcdrv_val_vbr_if_t& val, unc::driver::controller *ctr_ptr) {
+ pfcdrv_val_vbr_if_t& val,
+ unc::driver::controller*
+ ctr_ptr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
PFC_ASSERT(ctr_ptr != NULL);
- std::string ipaddress = ctr_ptr->get_host_address();
- if (0 == strlen(ipaddress.c_str())) {
- return DRVAPI_RESPONSE_FAILURE;
- }
-
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
- pfc_log_info("Controller Name in Create vbr_if %s", ipaddress.c_str());
std::string vbrif_url = get_vbrif_url(vbrif_key);
if (0 == strlen(vbrif_url.c_str())) {
return DRVAPI_RESPONSE_FAILURE;
}
-
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- retval = rest_util_obj.create_request_header(vbrif_url,
- unc::restjson::HTTP_METHOD_POST);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
const char* request = create_request_body(val);
- if (NULL != request) {
- retval = rest_util_obj.set_request_body(request);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- } else {
- pfc_log_info(" No Request Body Formed");
- }
+ uint32_t resp = get_controller_response_code(vbrif_url, ctr_ptr,
+ unc::restjson
+ ::HTTP_METHOD_POST, request);
- uint32_t resp = rest_util_obj.send_request_and_get_response_code();
if (RESP_CREATED != resp) {
return DRVAPI_RESPONSE_FAILURE;
}
// VBR_IF successful...Check for PortMap
- if (val.val_vbrif.valid[2] == UNC_VF_VALID) {
- retval = create_cmd_port_map(vbrif_key, val, ctr_ptr);
- if (retval != ODC_DRV_SUCCESS) {
+ if (val.val_vbrif.valid[UPLL_IDX_PM_VBRI] == UNC_VF_VALID) {
+ resp = update_cmd_port_map(vbrif_key, val, ctr_ptr);
+ if (ODC_DRV_SUCCESS != resp) {
return DRVAPI_RESPONSE_FAILURE;
}
} else {
- pfc_log_info("NO V-external");
+ pfc_log_debug("NO V-external");
}
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return DRVAPI_RESPONSE_SUCCESS;
// Update command for vbrif command
drv_resp_code_t ODCVBRIfCommand::update_cmd(key_vbr_if_t& vbrif_key,
- pfcdrv_val_vbr_if_t& val, unc::driver::controller *ctr_ptr) {
+ pfcdrv_val_vbr_if_t& val,
+ unc::driver::controller
+ *ctr_ptr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
PFC_ASSERT(ctr_ptr != NULL);
- std::string ipaddress = ctr_ptr->get_host_address();
- if (0 == strlen(ipaddress.c_str())) {
- return DRVAPI_RESPONSE_FAILURE;
- }
-
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
std::string vbrif_url = get_vbrif_url(vbrif_key);
if (0 == strlen(vbrif_url.c_str())) {
return DRVAPI_RESPONSE_FAILURE;
}
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- retval = rest_util_obj.create_request_header(vbrif_url,
- unc::restjson::HTTP_METHOD_PUT);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
const char* request = create_request_body(val);
- if (NULL != request) {
- retval = rest_util_obj.set_request_body(request);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- } else {
- pfc_log_info(" No Request Body Formed");
- }
- uint32_t resp = rest_util_obj.send_request_and_get_response_code();
+ uint32_t resp = get_controller_response_code(vbrif_url, ctr_ptr,
+ unc::restjson
+ ::HTTP_METHOD_PUT, request);
+
if (RESP_OK != resp) {
return DRVAPI_RESPONSE_FAILURE;
}
// VBR_IF successful...Check for PortMap
- if ((val.val_vbrif.valid[2] == UNC_VF_VALID)
- && (val.valid[0] == UNC_VF_VALID)) {
- retval = update_cmd_port_map(vbrif_key, val, ctr_ptr);
- if (retval != ODC_DRV_SUCCESS) {
+ if ((val.val_vbrif.valid[UPLL_IDX_PM_VBRI] == UNC_VF_VALID)
+ && (val.valid[PFCDRV_IDX_VAL_VBRIF] == UNC_VF_VALID)) {
+ resp = update_cmd_port_map(vbrif_key, val, ctr_ptr);
+ if (resp != ODC_DRV_SUCCESS) {
return DRVAPI_RESPONSE_FAILURE;
}
- } else if ((val.val_vbrif.valid[2] == UNC_VF_VALID_NO_VALUE)
- && (val.valid[0] == UNC_VF_VALID)) {
- retval = delete_cmd_port_map(vbrif_key, val, ctr_ptr);
- if (retval != ODC_DRV_SUCCESS) {
+ } else if ((val.val_vbrif.valid[UPLL_IDX_PM_VBRI] == UNC_VF_VALID_NO_VALUE)
+ && (val.valid[PFCDRV_IDX_VAL_VBRIF] == UNC_VF_VALID)) {
+ resp = delete_cmd_port_map(vbrif_key, val, ctr_ptr);
+ if (resp != ODC_DRV_SUCCESS) {
return DRVAPI_RESPONSE_FAILURE;
}
}
// Delete Command for vbr if
drv_resp_code_t ODCVBRIfCommand::delete_cmd(key_vbr_if_t& vbrif_key,
- pfcdrv_val_vbr_if_t& val, unc::driver::controller *ctr_ptr) {
+ pfcdrv_val_vbr_if_t& val,
+ unc::driver::controller*
+ ctr_ptr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
+ pfc_log_debug("%s Enter delete_cmd", PFC_FUNCNAME);
PFC_ASSERT(ctr_ptr != NULL);
- std::string ipaddress = ctr_ptr->get_host_address();
- if (0 == strlen(ipaddress.c_str())) {
- return DRVAPI_RESPONSE_FAILURE;
- }
-
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
std::string vbrif_url = get_vbrif_url(vbrif_key);
+ pfc_log_debug("vbrif_url:%s", vbrif_url.c_str());
if (0 == strlen(vbrif_url.c_str())) {
return DRVAPI_RESPONSE_FAILURE;
}
-
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- retval = rest_util_obj.create_request_header(vbrif_url,
- unc::restjson::HTTP_METHOD_DELETE);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- uint32_t resp = rest_util_obj.send_request_and_get_response_code();
+ uint32_t resp = get_controller_response_code(vbrif_url, ctr_ptr,
+ unc::restjson
+ ::HTTP_METHOD_DELETE, NULL);
if (RESP_OK != resp) {
+ pfc_log_error("exit delete_cmd, get_controller_response_code fail");
return DRVAPI_RESPONSE_FAILURE;
}
+ pfc_log_debug("%s Exit delete_cmd", PFC_FUNCNAME);
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return DRVAPI_RESPONSE_SUCCESS;
}
json_object *jobj = json_obj.create_json_obj();
char* description = reinterpret_cast<char*>(val_vtn.val_vbrif.description);
int ret_val = 1;
- pfc_log_info("%s description", description);
+ pfc_log_debug("%s description", description);
if (0 != strlen(description)) {
ret_val = json_obj.build(jobj, "description", description);
if (ret_val) {
}
}
const char* req_body = json_obj.json_obj_to_json_string(jobj);
- pfc_log_info("%s json request ", req_body);
+ pfc_log_debug("%s json request ", req_body);
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return req_body;
}
// Validates the operation
drv_resp_code_t ODCVBRIfCommand::validate_op(key_vbr_if_t& key_vbr_if,
- pfcdrv_val_vbr_if_t& val, unc::driver::controller* ctr,
- uint32_t operation) {
+ pfcdrv_val_vbr_if_t& val,
+ unc::driver::controller*
+ ctr,
+ uint32_t operation) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
drv_resp_code_t resp_code = DRVAPI_RESPONSE_FAILURE;
PFC_ASSERT(ctr != NULL);
switch (operation) {
- case UNC_OP_CREATE:
- resp_code = validate_create_vbrif(key_vbr_if, ctr);
- break;
- case UNC_OP_UPDATE:
- resp_code = validate_update_vbrIf(key_vbr_if, ctr);
- break;
- case UNC_OP_DELETE:
- resp_code = validate_delete_vbrif(key_vbr_if, ctr);
- break;
- default:
- pfc_log_debug("Unknown operation %d", operation);
- break;
+ case UNC_OP_CREATE:
+ resp_code = validate_create_vbrif(key_vbr_if, ctr);
+ break;
+ case UNC_OP_UPDATE:
+ resp_code = validate_update_vbrIf(key_vbr_if, ctr);
+ break;
+ case UNC_OP_DELETE:
+ resp_code = validate_delete_vbrif(key_vbr_if, ctr);
+ break;
+ default:
+ pfc_log_debug("Unknown operation %d", operation);
+ break;
}
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return resp_code;
}
// Validate the create vbr if command
-drv_resp_code_t ODCVBRIfCommand::validate_create_vbrif(key_vbr_if_t& key_vbr_if,
- unc::driver::controller* ctr) {
+drv_resp_code_t ODCVBRIfCommand::validate_create_vbrif(key_vbr_if_t&
+ key_vbr_if,
+ unc::driver::controller*
+ ctr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
uint32_t resp_code = ODC_DRV_FAILURE;
resp_code = is_vtn_exists_in_controller(key_vbr_if, ctr);
if (RESP_NOT_FOUND == resp_code) {
- return DRVAPI_RESPONSE_FAILURE;
+ return DRVAPI_RESPONSE_FAILURE;
}
if (RESP_OK == resp_code) {
resp_code = is_vbr_exists_in_controller(key_vbr_if, ctr);
if (RESP_NOT_FOUND == resp_code) {
- return DRVAPI_RESPONSE_FAILURE;
+ return DRVAPI_RESPONSE_FAILURE;
}
if (RESP_OK == resp_code) {
resp_code = is_vbrif_exists_in_controller(key_vbr_if, ctr);
}
}
}
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return DRVAPI_RESPONSE_FAILURE;
}
// Validates delete vbr if operatopn
-drv_resp_code_t ODCVBRIfCommand::validate_delete_vbrif(key_vbr_if_t& key_vbr_if,
- unc::driver::controller* ctr) {
+drv_resp_code_t ODCVBRIfCommand::validate_delete_vbrif(key_vbr_if_t&
+ key_vbr_if,
+ unc::driver::controller*
+ ctr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
uint32_t resp_code = ODC_DRV_FAILURE;
resp_code = is_vbrif_exists_in_controller(key_vbr_if, ctr);
if (RESP_OK == resp_code) {
return DRVAPI_RESPONSE_SUCCESS;
}
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return DRVAPI_RESPONSE_FAILURE;
}
// Validates the update command
-drv_resp_code_t ODCVBRIfCommand::validate_update_vbrIf(key_vbr_if_t& key_vbr_if,
- unc::driver::controller* ctr) {
+drv_resp_code_t ODCVBRIfCommand::validate_update_vbrIf(key_vbr_if_t&
+ key_vbr_if,
+ unc::driver::controller*
+ ctr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
uint32_t resp_code = ODC_DRV_FAILURE;
resp_code = is_vbrif_exists_in_controller(key_vbr_if, ctr);
if (RESP_OK == resp_code) {
return DRVAPI_RESPONSE_SUCCESS;
}
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return DRVAPI_RESPONSE_FAILURE;
}
// Check if vtn exist in controller or not
uint32_t ODCVBRIfCommand::is_vtn_exists_in_controller(key_vbr_if_t& key_vbr_if,
- unc::driver::controller* ctr) {
+ unc::driver::controller*
+ ctr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
char* vtnname = NULL;
vtnname = reinterpret_cast<char*>(key_vbr_if.vbr_key.vtn_key.vtn_name);
if (0 == strlen(vtnname)) {
return ODC_DRV_FAILURE;
}
- std::string url = "/controller/nb/v2/vtn/default/vtns/";
+ std::string url = "";
+ url.append(VTN_URL);
+ url.append("/");
url.append(vtnname);
uint32_t response_code = get_controller_response(url, ctr);
pfc_log_debug("Response code from Controller is : %d ", response_code);
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return response_code;
}
// Checks if vbr if exists in controller or not
uint32_t ODCVBRIfCommand::is_vbrif_exists_in_controller(
- key_vbr_if_t& key_vbr_if, unc::driver::controller* ctr) {
+ key_vbr_if_t& key_vbr_if, unc::driver::controller* ctr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
std::string vbrif_url = get_vbrif_url(key_vbr_if);
if (0 == strlen(vbrif_url.c_str())) {
}
uint32_t response_code = get_controller_response(vbrif_url, ctr);
pfc_log_debug("Response code from Controller is : %d ", response_code);
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return response_code;
}
// Checks the vbr exist in controller or not
uint32_t ODCVBRIfCommand::is_vbr_exists_in_controller(key_vbr_if_t& key_vbr_if,
- unc::driver::controller* ctr) {
+ unc::driver::controller*
+ ctr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
char* vtnname = NULL;
char* vbrname = NULL;
- std::string url = "/controller/nb/v2/vtn/default/vtns/";
+ std::string url = "";
+ url.append(VTN_URL);
+ url.append("/");
vtnname = reinterpret_cast<char*>(key_vbr_if.vbr_key.vtn_key.vtn_name);
if (0 == strlen(vtnname)) {
return ODC_DRV_FAILURE;
url.append(vbrname);
uint32_t response_code = get_controller_response(url, ctr);
pfc_log_debug("Response code from Controller is : %d ", response_code);
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return response_code;
}
-// Gets the controller respnse
+// Gets the controller response
uint32_t ODCVBRIfCommand::get_controller_response(std::string url,
- unc::driver::controller* ctr_ptr) {
+ unc::driver::controller*
+ ctr_ptr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
PFC_ASSERT(ctr_ptr != NULL);
uint32_t resp = rest_util_obj.send_request_and_get_response_code();
pfc_log_debug("Response code from Controller is : %d ", resp);
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return resp;
}
-}
-}
+} // namespace odcdriver
+} // namespace unc
// Constructor
ODCVTNCommand::ODCVTNCommand()
-: idle_timeout_("300"),
- hard_timeout_("0") {
- pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
- pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
-}
+ : idle_timeout_("300"),
+ hard_timeout_("0") {
+ pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
+ pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
+ }
// Destructor
ODCVTNCommand::~ODCVTNCommand() {
+ pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
+ pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
}
// validates the operation
drv_resp_code_t ODCVTNCommand::validate_op(key_vtn_t& key_vtn,
- val_vtn_t& val_vtn, unc::driver::controller* ctr,
- uint32_t op) {
- PFC_ASSERT(ctr != NULL);
+ val_vtn_t& val_vtn,
+ unc::driver::controller* ctr,
+ uint32_t op) {
pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
+ PFC_ASSERT(ctr != NULL);
drv_resp_code_t resp_code = DRVAPI_RESPONSE_FAILURE;
pfc_log_debug("operation received %d", op);
switch (op) {
- case UNC_OP_CREATE:
- resp_code = validate_create_vtn(key_vtn, ctr);
- break;
- case UNC_OP_UPDATE:
- resp_code = validate_update_vtn(key_vtn, ctr);
- break;
- case UNC_OP_DELETE:
- resp_code = validate_delete_vtn(key_vtn, ctr);
- break;
- default:
- pfc_log_debug("Unknown operation %d", op);
- break;
+ case UNC_OP_CREATE:
+ resp_code = validate_create_vtn(key_vtn, ctr);
+ break;
+ case UNC_OP_UPDATE:
+ resp_code = validate_update_vtn(key_vtn, ctr);
+ break;
+ case UNC_OP_DELETE:
+ resp_code = validate_delete_vtn(key_vtn, ctr);
+ break;
+ default:
+ pfc_log_debug("Unknown operation %d", op);
+ break;
}
pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
return resp_code;
}
// Validates create vtn
-drv_resp_code_t ODCVTNCommand::validate_create_vtn(key_vtn_t& key_vtn,
- unc::driver::controller* ctr) {
-
+drv_resp_code_t ODCVTNCommand::validate_create_vtn(const key_vtn_t& key_vtn,
+ unc::driver::controller*
+ ctr) {
pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
uint32_t resp_code = is_vtn_exists_in_controller(key_vtn, ctr);
pfc_log_debug("Response code for is_vtn_exists_in_controller %d", resp_code);
}
// Validates delete vtn
-drv_resp_code_t ODCVTNCommand::validate_delete_vtn(key_vtn_t& key_vtn,
- unc::driver::controller* ctr) {
+drv_resp_code_t ODCVTNCommand::validate_delete_vtn(const key_vtn_t& key_vtn,
+ unc::driver::controller*
+ ctr) {
pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
uint32_t resp_code = is_vtn_exists_in_controller(key_vtn, ctr);
pfc_log_debug("Response code for is_vtn_exists_in_controller %d", resp_code);
}
// Validates update vtn
-drv_resp_code_t ODCVTNCommand::validate_update_vtn(key_vtn_t& key_vtn,
- unc::driver::controller* ctr) {
+drv_resp_code_t ODCVTNCommand::validate_update_vtn(const key_vtn_t& key_vtn,
+ unc::driver::controller*
+ ctr) {
pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
uint32_t resp_code = is_vtn_exists_in_controller(key_vtn, ctr);
pfc_log_debug("Response code for is_vtn_exists_in_controller %d", resp_code);
}
// Checks if vtn exist in Controller or not
-uint32_t ODCVTNCommand::is_vtn_exists_in_controller(key_vtn_t& key_vtn,
- unc::driver::controller* ctr) {
+uint32_t ODCVTNCommand::is_vtn_exists_in_controller(const key_vtn_t& key_vtn,
+ unc::driver::controller*
+ ctr) {
pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
- char* vtnname = NULL;
- vtnname = reinterpret_cast<char*>(key_vtn.vtn_name);
+ const char* vtnname = NULL;
+ vtnname = reinterpret_cast<const char*>(key_vtn.vtn_name);
if (0 == strlen(vtnname)) {
return ODC_DRV_FAILURE;
}
- std::string url = "/controller/nb/v2/vtn/default/vtns/";
+ std::string url = "";
+ url.append(VTN_URL);
+ url.append("/");
url.append(vtnname);
- uint32_t response = get_controller_response(url, ctr);
- pfc_log_debug("Response code from Controller is : %d ", response);
+ uint32_t response = get_controller_response_code(url, ctr,
+ unc::restjson::
+ HTTP_METHOD_GET,
+ NULL);
+ pfc_log_debug("Response code from Controller is for vtn : %d ", response);
pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
return response;
}
-// Gets the Controller Response code
-uint32_t ODCVTNCommand::get_controller_response(std::string url,
- unc::driver::controller* ctr) {
+// Return controller response code
+uint32_t ODCVTNCommand::get_controller_response_code(std::string url,
+ unc::driver::controller*
+ ctr,
+ unc::restjson::HttpMethod
+ method,
+ const char* request_body) {
pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
-
- PFC_ASSERT( ctr != NULL);
+ PFC_ASSERT(ctr != NULL);
std::string ipaddress = ctr->get_host_address();
pfc_log_debug("ip address of controller is %s", ipaddress.c_str());
if (0 == strlen(ipaddress.c_str())) {
return ODC_DRV_FAILURE;
}
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- pfc_log_debug("Return value for SetUserName Password %d", retval);
+ if (( method != unc::restjson::HTTP_METHOD_POST ) &&
+ (method != unc::restjson::HTTP_METHOD_PUT) &&
+ (method != unc::restjson::HTTP_METHOD_DELETE) &&
+ (method != unc::restjson::HTTP_METHOD_GET)) {
+ pfc_log_debug("Invalid Method : %d", method);
+ pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
+ return ODC_DRV_FAILURE;
+ }
+
+ std::string username_ctr = ctr->get_user_name();
+ std::string password_ctr = ctr->get_pass_word();
+ unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
+ uint32_t retval = ODC_DRV_FAILURE;
+ if ((0 == strlen(username_ctr.c_str()))
+ || (0 == strlen(password_ctr.c_str()))) {
+ retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
+ } else {
+ retval = rest_util_obj.set_username_password(username_ctr, password_ctr);
+ }
if (ODC_DRV_FAILURE == retval) {
- return retval;
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ retval = rest_util_obj.set_timeout(CONNECTION_TIME_OUT, REQUEST_TIME_OUT);
+ if (ODC_DRV_FAILURE == retval) {
+ return DRVAPI_RESPONSE_FAILURE;
}
- retval = rest_util_obj.create_request_header(url, unc::restjson::HTTP_METHOD_GET);
+ retval = rest_util_obj.create_request_header(url, method);
if (ODC_DRV_FAILURE == retval) {
+ pfc_log_debug("Failure in create request header : %d", retval);
return retval;
}
-
+ if ((method == unc::restjson::HTTP_METHOD_POST)
+ || (method == unc::restjson::HTTP_METHOD_PUT)) {
+ if (NULL != request_body) {
+ pfc_log_debug("Request Body : %s", request_body);
+ retval = rest_util_obj.set_request_body(request_body);
+ if (ODC_DRV_FAILURE == retval) {
+ pfc_log_debug("Failure in set Request Body %d", retval);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ }
+ }
uint32_t resp = rest_util_obj.send_request_and_get_response_code();
pfc_log_debug("Response code from Controller is : %d ", resp);
pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
// Create Command and send Request to Controller
drv_resp_code_t ODCVTNCommand::create_cmd(key_vtn_t& key_vtn,
- val_vtn_t& val_vtn, unc::driver::controller *ctr_ptr) {
+ val_vtn_t& val_vtn,
+ unc::driver::controller *ctr_ptr) {
pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
char* vtnname = NULL;
PFC_ASSERT(ctr_ptr != NULL);
- std::string url = "/controller/nb/v2/vtn/default/vtns/";
+ std::string url = "";
+ url.append(VTN_URL);
+ url.append("/");
std::string ipaddress = ctr_ptr->get_host_address();
-
if (0 == strlen(ipaddress.c_str())) {
return DRVAPI_RESPONSE_FAILURE;
}
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
vtnname = reinterpret_cast<char*>(key_vtn.vtn_name);
if (0 == strlen(vtnname)) {
return DRVAPI_RESPONSE_FAILURE;
}
url.append(vtnname);
-
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- pfc_log_debug("Return value for SetUserName Password %d", retval);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
-
- retval = rest_util_obj.create_request_header(url, unc::restjson::HTTP_METHOD_POST);
- pfc_log_debug("Return value for Request Header %d", retval);
-
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
-
const char* request = create_request_body(val_vtn);
- if (NULL != request) {
- pfc_log_debug("Request Body for create vtn : %s", request);
- retval = rest_util_obj.set_request_body(request);
- pfc_log_debug("Return value to set Request Body %d", retval);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- } else {
- pfc_log_info(" No Request body formed");
- }
-
- uint32_t resp = rest_util_obj.send_request_and_get_response_code();
- pfc_log_info("response code returned in createvtn is %d", resp);
+ pfc_log_debug("Request body formed %s", request);
+ uint32_t resp = get_controller_response_code(url, ctr_ptr,
+ unc::restjson::HTTP_METHOD_POST,
+ request);
+ pfc_log_debug("response code returned in create vtn is %d", resp);
if (RESP_CREATED != resp) {
return DRVAPI_RESPONSE_FAILURE;
}
}
// Creates Request Body
-const char* ODCVTNCommand::create_request_body(val_vtn_t& val_vtn) {
+const char* ODCVTNCommand::create_request_body(const val_vtn_t& val_vtn) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
unc::restjson::JsonBuildParse json_obj;
- char* description = reinterpret_cast<char*>(val_vtn.description);
+ const char* description = reinterpret_cast<const char*>(val_vtn.description);
json_object *jobj = json_obj.create_json_obj();
-
int ret_val = 1;
- pfc_log_info("%s description", description);
+ pfc_log_debug("%s description", description);
if (0 != strlen(description)) {
ret_val = json_obj.build(jobj, "description", description);
if (ret_val) {
if (ret_val) {
return NULL;
}
-
const char* req_body = json_obj.json_obj_to_json_string(jobj);
- pfc_log_info("%s json request ", req_body);
+ pfc_log_debug("%s json request ", req_body);
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return req_body;
}
// Command to update vtn and Send request to Controller
drv_resp_code_t ODCVTNCommand::update_cmd(key_vtn_t& key_vtn,
- val_vtn_t& val_vtn, unc::driver::controller *ctr_ptr) {
+ val_vtn_t& val_vtn,
+ unc::driver::controller *ctr_ptr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
char* vtnname = NULL;
PFC_ASSERT(ctr_ptr != NULL);
- std::string url = "/controller/nb/v2/vtn/default/vtns/";
+ std::string url = "";
+ url.append(VTN_URL);
+ url.append("/");
std::string ipaddress = ctr_ptr->get_host_address();
-
if (0 == strlen(ipaddress.c_str())) {
return DRVAPI_RESPONSE_FAILURE;
}
-
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
vtnname = reinterpret_cast<char*>(key_vtn.vtn_name);
if (0 == strlen(vtnname)) {
return DRVAPI_RESPONSE_FAILURE;
}
-
url.append(vtnname);
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- pfc_log_debug("Return value for SetUserName Password %d", retval);
- if (ODC_DRV_FAILURE == retval) {
+ const char* request = create_request_body(val_vtn);
+ pfc_log_debug(" Request body formed %s", request);
+ uint32_t resp = get_controller_response_code(url, ctr_ptr,
+ unc::restjson::HTTP_METHOD_PUT,
+ request);
+ if (RESP_OK != resp) {
return DRVAPI_RESPONSE_FAILURE;
}
+ pfc_log_debug("response code returned in updatevtn is %d", resp);
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+ return DRVAPI_RESPONSE_SUCCESS;
+}
- retval = rest_util_obj.create_request_header(url, unc::restjson::HTTP_METHOD_PUT);
- pfc_log_debug("Return value for Request Header %d", retval);
+// Get all child of vtns
+drv_resp_code_t ODCVTNCommand::get_vtn_child(std::string vtn_name,
+ unc::driver::controller* ctr,
+ std::vector< unc::vtndrvcache
+ ::ConfigNode *>
+ &cfgnode_vector) {
+ pfc_log_debug("%s Entering function", PFC_FUNCNAME);
+ if (0 == strlen(vtn_name.c_str())) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ std::string url = "";
+ url.append(VTN_URL);
+ url.append("/");
+ url.append(vtn_name);
+ url.append("/vbridges");
+ pfc_log_debug("%s Entering function, url:%s", PFC_FUNCNAME, url.c_str());
+
+ PFC_ASSERT(NULL != ctr);
+ std::string ipaddress = ctr->get_host_address();
+ if (0 == strlen(ipaddress.c_str())) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
+ std::string username_ctr = ctr->get_user_name();
+ std::string password_ctr = ctr->get_pass_word();
+
+ uint32_t retval = ODC_DRV_FAILURE;
+ if ((0 == strlen(username_ctr.c_str()))
+ || (0 == strlen(password_ctr.c_str()))) {
+ retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
+ } else {
+ retval = rest_util_obj.set_username_password(username_ctr, password_ctr);
+ }
if (ODC_DRV_FAILURE == retval) {
return DRVAPI_RESPONSE_FAILURE;
}
- const char* request = create_request_body(val_vtn);
- if (NULL != request) {
- pfc_log_debug("Request Body for create vtn : %s", request);
- retval = rest_util_obj.set_request_body(request);
- pfc_log_debug("Return value to set Request Body %d", retval);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
+ retval = rest_util_obj.set_timeout(CONNECTION_TIME_OUT, REQUEST_TIME_OUT);
+ if (ODC_DRV_FAILURE == retval) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ retval = rest_util_obj.create_request_header(url, restjson::HTTP_METHOD_GET);
+ if (ODC_DRV_FAILURE == retval) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ uint32_t resp = rest_util_obj.send_request_and_get_response_code();
+ if (RESP_OK != resp) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ restjson::HttpContent_t* content = rest_util_obj.get_response_body();
+ if (content == NULL) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ char *data = content->memory;
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+ return parse_vbr_resp_data(data, vtn_name, ctr, cfgnode_vector);
+}
+
+// Gets the Controller Response code
+drv_resp_code_t ODCVTNCommand::read_all(unc::driver::controller* ctr,
+ std::vector<unc::vtndrvcache::ConfigNode *>
+ &cfgnode_vector) {
+ pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
+ PFC_ASSERT(NULL != ctr);
+ std::string ipaddress = ctr->get_host_address();
+
+ if (0 == strlen(ipaddress.c_str())) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
+ std::string username_ctr = ctr->get_user_name();
+ std::string password_ctr = ctr->get_pass_word();
+
+ uint32_t retval = ODC_DRV_FAILURE;
+ if ((0 == strlen(username_ctr.c_str()))
+ || (0 == strlen(password_ctr.c_str()))) {
+ retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
} else {
- pfc_log_info(" No Request body formed");
+ retval = rest_util_obj.set_username_password(username_ctr, password_ctr);
+ }
+ if (ODC_DRV_FAILURE == retval) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ retval = rest_util_obj.set_timeout(CONNECTION_TIME_OUT, REQUEST_TIME_OUT);
+ if (ODC_DRV_FAILURE == retval) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ retval = rest_util_obj.create_request_header(VTN_URL,
+ restjson::HTTP_METHOD_GET);
+ if (ODC_DRV_FAILURE == retval) {
+ return DRVAPI_RESPONSE_FAILURE;
}
uint32_t resp = rest_util_obj.send_request_and_get_response_code();
+ pfc_log_debug("%d resp ", resp);
if (RESP_OK != resp) {
+ pfc_log_debug("Error in response code");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ restjson::HttpContent_t* content = rest_util_obj.get_response_body();
+ if (content == NULL) {
return DRVAPI_RESPONSE_FAILURE;
}
- pfc_log_info("response code returned in updatevtn is %d", resp);
+ char *data = content->memory;
+ pfc_log_debug("data in ODCVTN %s", data);
+ if (0 == strlen(data)) {
+ pfc_log_debug(" %s No vtn present in controller ", PFC_FUNCNAME);
+ return DRVAPI_RESPONSE_NO_SUCH_INSTANCE;
+ }
+ drv_resp_code_t ret_val = parse_resp_data(data, cfgnode_vector);
+ pfc_log_debug("read_all_-- size, %d",
+ static_cast<int>(cfgnode_vector.size()));
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+ return ret_val;
+}
+
+// Prsing fuction for vbridge after getting vbridge from controller
+drv_resp_code_t ODCVTNCommand::parse_vbr_resp_data(char *data,
+ std::string vtn_name,
+ unc::driver::controller* ctr,
+ std::vector< unc::vtndrvcache
+ ::ConfigNode *>
+ &cfgnode_vector) {
+ pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
+ key_vbr_t key_vbr;
+ val_vbr_t val_vbr;
+ memset(&key_vbr, 0, sizeof(key_vbr_t));
+ memset(&val_vbr, 0, sizeof(val_vbr_t));
+
+ json_object* jobj = restjson::JsonBuildParse::string_to_json_object(data);
+ if (json_object_is_type(jobj, json_type_null)) {
+ pfc_log_error("Exit parse_vbr_resp_data. json_object_is_type error");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ pfc_log_debug("response data from controller : %s", data);
+ uint32_t array_length = 0;
+ json_object *json_obj_vbr = NULL;
+
+ uint32_t ret_val = restjson::JsonBuildParse::parse(jobj, "vbridge", -1 ,
+ json_obj_vbr);
+ if (ret_val) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ if (json_object_is_type(json_obj_vbr, json_type_array)) {
+ array_length = restjson::JsonBuildParse::get_array_length(jobj, "vbridge");
+ }
+ pfc_log_debug(" array _length %d" , array_length);
+ if (json_object_is_type(jobj, json_type_null)) {
+ pfc_log_debug("%s jobj NULL", PFC_FUNCNAME);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ for (uint32_t arr_idx = 0; arr_idx < array_length; arr_idx++) {
+ drv_resp_code_t retval = parse_vbr_append_vector(ctr, json_obj_vbr,
+ vtn_name,
+ arr_idx,
+ cfgnode_vector);
+ if (DRVAPI_RESPONSE_FAILURE == retval) {
+ pfc_log_error("Error in parsing vbr resp data in %s", PFC_FUNCNAME);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ }
+ pfc_log_debug("cfgnode_vector.size: %d" ,
+ static_cast<int>(cfgnode_vector.size()));
+ pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
+ return DRVAPI_RESPONSE_SUCCESS;
+}
+
+// each vbridge node append to cache
+drv_resp_code_t ODCVTNCommand::parse_vbr_append_vector(
+ unc::driver::controller* ctr, json_object *json_obj_vbr,
+ std::string vtn_name, uint32_t arr_idx,
+ std::vector<unc::vtndrvcache::ConfigNode *> &cfgnode_vector) {
+ pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
+ key_vbr_t key_vbr;
+ val_vbr_t val_vbr;
+ memset(&key_vbr, 0, sizeof(key_vbr_t));
+ memset(&val_vbr, 0, sizeof(val_vbr_t));
+ std::string vbr_name = "";
+ std::string vbr_description = "";
+
+ uint32_t ret_val = restjson::JsonBuildParse::parse(json_obj_vbr, "name",
+ arr_idx, vbr_name);
+ if (ret_val) {
+ pfc_log_error("Error occured while parsing vbr name");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ ret_val = restjson::JsonBuildParse::parse(json_obj_vbr, "description",
+ arr_idx, vbr_description);
+ if (ret_val) {
+ pfc_log_error(" Error occured while parsing vbr description");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ // Fills the vbr KEY structure
+ strncpy(reinterpret_cast<char*> (key_vbr.vtn_key.vtn_name), vtn_name.c_str(),
+ sizeof(key_vbr.vtn_key.vtn_name) - 1);
+ pfc_log_debug("vtn :%s", reinterpret_cast<char*> (key_vbr.vtn_key.vtn_name));
+
+ strncpy(reinterpret_cast<char*> (key_vbr.vbridge_name), vbr_name.c_str(),
+ sizeof(key_vbr.vbridge_name) - 1);
+ pfc_log_error(" vbr :%s", reinterpret_cast<char*> (key_vbr.vbridge_name));
+
+ // Fills the vbr VAL structure
+ if (0 == strlen(vbr_description.c_str())) {
+ val_vbr.valid[UPLL_IDX_DESC_VBR] = UNC_VF_INVALID;
+ } else {
+ strncpy(reinterpret_cast<char*>(val_vbr.vbr_description),
+ vbr_description.c_str(), sizeof(val_vbr.vbr_description) - 1);
+ val_vbr.valid[UPLL_IDX_DESC_VBR] = UNC_VF_VALID;
+ }
+ pfc_log_debug("desc :%s", reinterpret_cast<char*> (val_vbr.vbr_description));
+
+ std::string controller_name = ctr->get_controller_id();
+ if (0 == strlen(controller_name.c_str())) {
+ val_vbr.valid[UPLL_IDX_CONTROLLER_ID_VBR] = UNC_VF_INVALID;
+ } else {
+ strncpy(reinterpret_cast<char*>(val_vbr.controller_id),
+ controller_name.c_str(), sizeof(val_vbr.controller_id) - 1);
+ pfc_log_debug(" %s controller id",
+ reinterpret_cast<char*>(val_vbr.controller_id));
+ val_vbr.valid[UPLL_IDX_CONTROLLER_ID_VBR] = UNC_VF_VALID;
+ }
+ std::string host_address = ctr->get_host_address();
+ if (0 == strlen(host_address.c_str())) {
+ val_vbr.valid[UPLL_IDX_HOST_ADDR_VBR] = UNC_VF_INVALID;
+ } else {
+ uint32_t val = inet_aton(host_address.c_str(), &val_vbr.host_addr);
+ if (val) {
+ pfc_log_debug(" %s host address", inet_ntoa(val_vbr.host_addr));
+ val_vbr.valid[UPLL_IDX_HOST_ADDR_VBR] = UNC_VF_VALID;
+ }
+ }
+ strncpy(reinterpret_cast<char*> (val_vbr.domain_id), DOM_NAME.c_str(),
+ sizeof(val_vbr.domain_id) - 1);
+ val_vbr.valid[UPLL_IDX_DOMAIN_ID_VBR] = UNC_VF_VALID;
+
+ unc::vtndrvcache::ConfigNode *cfgptr =
+ new unc::vtndrvcache::CacheElementUtil<key_vbr_t, val_vbr_t, uint32_t> (
+ &key_vbr,
+ &val_vbr,
+ uint32_t(UNC_OP_READ));
+ PFC_ASSERT(cfgptr != NULL);
+ cfgnode_vector.push_back(cfgptr);
+ pfc_log_debug("parse_vbr_append_vector Exiting. cfgnode_vector size: %d",
+ static_cast<int>(cfgnode_vector.size()));
+ pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
+
+ return DRVAPI_RESPONSE_SUCCESS;
+}
+
+// each vtn node append to cache
+drv_resp_code_t ODCVTNCommand::parse_vtn_append_vector(
+ json_object *json_obj_vtn, int arr_idx,
+ std::vector<unc::vtndrvcache::ConfigNode *> &cfgnode_vector) {
+ pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
+ key_vtn_t key_vtn;
+ val_vtn_t val_vtn;
+ memset(&key_vtn, 0, sizeof(key_vtn_t));
+ memset(&val_vtn, 0, sizeof(val_vtn_t));
+
+ std::string vtn_name = "";
+ std::string vtn_description = "";
+
+ uint32_t ret_val = restjson::JsonBuildParse::parse(json_obj_vtn, "name",
+ arr_idx, vtn_name);
+ pfc_log_debug(" vtn_name %s:", vtn_name.c_str());
+ if (ret_val) {
+ pfc_log_debug(" Error while parsing vtn name");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ ret_val = restjson::JsonBuildParse::parse(json_obj_vtn, "description",
+ arr_idx, vtn_description);
+ pfc_log_debug(" vtn_description %s:", vtn_description.c_str());
+ if (ret_val) {
+ pfc_log_debug(" Error while parsing vtn description");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ // Fills Key Structure
+ strncpy(reinterpret_cast<char*> (key_vtn.vtn_name), vtn_name.c_str(),
+ sizeof(key_vtn.vtn_name) - 1);
+
+ // Fill Value Structure
+ if (0 == strlen(vtn_description.c_str())) {
+ val_vtn.valid[UPLL_IDX_DESC_VTN] = UNC_VF_INVALID;
+ } else {
+ strncpy(reinterpret_cast<char*>(val_vtn.description),
+ vtn_description.c_str(), sizeof(val_vtn.description) - 1);
+ val_vtn.valid[UPLL_IDX_DESC_VTN] = UNC_VF_VALID;
+ }
+ pfc_log_debug("key_vtn.vtn_name: %s",
+ reinterpret_cast<char*> (key_vtn.vtn_name));
+ pfc_log_debug("val_vtn.description: %s",
+ reinterpret_cast<char*> (val_vtn.description));
+
+ unc::vtndrvcache::ConfigNode *cfgptr =
+ new unc::vtndrvcache::CacheElementUtil<key_vtn_t, val_vtn_t, uint32_t>
+ (&key_vtn, &val_vtn, uint32_t(UNC_OP_READ));
+ PFC_ASSERT(cfgptr != NULL);
+ cfgnode_vector.push_back(cfgptr);
+ pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
+ return DRVAPI_RESPONSE_SUCCESS;
+}
+
+// parsing function for converting controller response to driver format
+drv_resp_code_t ODCVTNCommand::parse_resp_data(char *data,
+ std::vector< unc::vtndrvcache
+ ::ConfigNode *>
+ &cfgnode_vector) {
+ pfc_log_debug("Entering function ... %s", PFC_FUNCNAME);
+ json_object* jobj = restjson::JsonBuildParse::string_to_json_object(data);
+ if (json_object_is_type(jobj, json_type_null)) {
+ pfc_log_error("Exit. json_object_is_type error");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ uint32_t array_length =0;
+ json_object *json_obj_vtn = NULL;
+ uint32_t ret_val = restjson::JsonBuildParse::parse(jobj, "vtn", -1,
+ json_obj_vtn);
+ if (ret_val) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ if (json_object_is_type(json_obj_vtn, json_type_null)) {
+ pfc_log_debug("Parsing Error json_obj_vtn is null");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ if (json_object_is_type(json_obj_vtn, json_type_array)) {
+ array_length = restjson::JsonBuildParse::get_array_length(jobj, "vtn");
+ }
+ pfc_log_debug("vtn array length : %d", array_length);
+ if (0 == array_length) {
+ pfc_log_debug("inside 0==arraylength");
+ return DRVAPI_RESPONSE_NO_SUCH_INSTANCE;
+ }
+ for (uint32_t arr_idx = 0; arr_idx < array_length; arr_idx++) {
+ drv_resp_code_t ret_val = parse_vtn_append_vector(json_obj_vtn, arr_idx,
+ cfgnode_vector);
+ if (ret_val == DRVAPI_RESPONSE_FAILURE) {
+ pfc_log_debug(" return from parse_vtn_append_vector failure");
+ return ret_val;
+ }
+ }
+
+ pfc_log_debug("Exiting function ... %s", PFC_FUNCNAME);
return DRVAPI_RESPONSE_SUCCESS;
}
// Delete Request send to the Contoller
drv_resp_code_t ODCVTNCommand::delete_cmd(key_vtn_t& key_vtn,
- val_vtn_t& val_vtn, unc::driver::controller *ctr_ptr) {
-
+ val_vtn_t& val_vtn,
+ unc::driver::controller *ctr_ptr) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
char* vtnname = NULL;
- std::string url = "/controller/nb/v2/vtn/default/vtns/";
+ std::string url = "";
+ url.append(VTN_URL);
+ url.append("/");
PFC_ASSERT(ctr_ptr != NULL);
std::string ipaddress = ctr_ptr->get_host_address();
if (0 == strlen(ipaddress.c_str())) {
return DRVAPI_RESPONSE_FAILURE;
}
-
- unc::restjson::RestClient rest_util_obj(ipaddress, ODC_PORT);
vtnname = reinterpret_cast<char*>(key_vtn.vtn_name);
if (0 == strlen(vtnname)) {
return DRVAPI_RESPONSE_FAILURE;
}
-
url.append(vtnname);
- uint32_t retval = rest_util_obj.set_username_password(USER_NAME, PASS_WORD);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
-
- retval = rest_util_obj.create_request_header(url,
- unc::restjson::HTTP_METHOD_DELETE);
- if (ODC_DRV_FAILURE == retval) {
- return DRVAPI_RESPONSE_FAILURE;
- }
- uint32_t resp = rest_util_obj.send_request_and_get_response_code();
+ uint32_t resp = get_controller_response_code(url, ctr_ptr,
+ unc::restjson
+ ::HTTP_METHOD_DELETE,
+ NULL);
if (RESP_OK != resp) {
return DRVAPI_RESPONSE_FAILURE;
}
- pfc_log_info("response code returned in delete vtn is %d", resp);
+ pfc_log_debug("response code returned in delete vtn is %d", resp);
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return DRVAPI_RESPONSE_SUCCESS;
}
-}
-}
+} // namespace odcdriver
+} // namespace unc
include ../defs.mk
CXX_SOURCES = rest_client.cc \
- http_client.cc \
- json_build_parse.cc \
- restjsonmod.cc
+ http_client.cc \
+ json_build_parse.cc \
+ restjsonmod.cc
UNC_LIBS += -lcurl \
- -ljson
+ -ljson
include ../rules.mk
/*
* Copyright (c) 2012-2013 NEC Corporation
* All rights reserved.
- *
+ *
* This program and the accompanying materials are made
* available under the
* terms of the Eclipse Public License v1.0 which
// Constructor
HttpClient::HttpClient()
-: handle_(NULL),
- response_(NULL),
- slist_(NULL) {
- pfc_log_debug("%s, Entering function", PFC_FUNCNAME);
- pfc_log_debug("%s, Exiting function", PFC_FUNCNAME);
-}
+ : handle_(NULL),
+ response_(NULL),
+ slist_(NULL) {
+ pfc_log_debug("%s, Entering function", PFC_FUNCNAME);
+ pfc_log_debug("%s, Exiting function", PFC_FUNCNAME);
+ }
// Destructor
HttpClient::~HttpClient() {
// Sets the Username and password to the CURL handle
rest_resp_code_t HttpClient::set_username_password(const std::string &username,
- const std::string &password) {
+ const std::string
+ &password) {
pfc_log_debug("%s, Entering function", PFC_FUNCNAME);
std::string username_password = "";
username_password.append(username);
pfc_log_debug("%d CURLOPT_USERPWD", CURLOPT_USERPWD);
CURLcode curlRetCode = curl_easy_setopt(handle_, CURLOPT_USERPWD,
- username_password.c_str());
+ username_password.c_str());
if (CURLE_OK != curlRetCode) {
return FAILURE;
}
// Sets the Connection TimeOut to the CURL handle
rest_resp_code_t HttpClient::set_connection_timeout(
- const int connectionTimeOut) {
+ const int connectionTimeOut) {
pfc_log_debug("%s, Entering function", PFC_FUNCNAME);
pfc_log_debug("%d CURLOPT_CONNECTTIMEOUT", CURLOPT_CONNECTTIMEOUT);
CURLcode curlRetCode = curl_easy_setopt(handle_, CURLOPT_CONNECTTIMEOUT,
- connectionTimeOut);
+ connectionTimeOut);
if (CURLE_OK != curlRetCode) {
return FAILURE;
}
rest_resp_code_t HttpClient::set_request_timeout(const int reqTimeOut) {
pfc_log_debug("%s, Entering function", PFC_FUNCNAME);
CURLcode curlRetCode = curl_easy_setopt(handle_, CURLOPT_TIMEOUT,
- reqTimeOut);
+ reqTimeOut);
if (CURLE_OK != curlRetCode) {
return FAILURE;
}
switch (operation) {
case HTTP_METHOD_POST: {
- pfc_log_info("HTTP_METHOD_POST");
+ pfc_log_debug("HTTP_METHOD_POST");
curlRetCode = curl_easy_setopt(handle_, CURLOPT_POST, 1);
if (CURLE_OK != curlRetCode) {
pfc_log_error(" SetRequest Body failed with curl error code %d",
break;
}
}
- break;
+ break;
case HTTP_METHOD_PUT: {
curlRetCode = curl_easy_setopt(handle_, CURLOPT_CUSTOMREQUEST, "PUT");
break;
}
}
- break;
+ break;
case HTTP_METHOD_DELETE: {
curlRetCode = curl_easy_setopt(handle_, CURLOPT_CUSTOMREQUEST, "DELETE");
if (CURLE_OK != curlRetCode) {
break;
}
}
- break;
+ break;
case HTTP_METHOD_GET: {
curlRetCode = curl_easy_setopt(handle_, CURLOPT_HTTPGET, 1);
if (CURLE_OK != curlRetCode) {
break;
}
}
- break;
+ break;
default: {
pfc_log_debug("Unsupported case type %d ", operation);
pfc_log_debug("requestbody : %s", requestbody);
CURLcode curlRetCode = curl_easy_setopt(handle_, CURLOPT_POSTFIELDS,
- requestbody);
+ requestbody);
if (CURLE_OK != curlRetCode) {
pfc_log_error(" SetRequest Body failed with curl error code %d",
// Sets Common Values to the CURL hanlde, Post the handle and writes the reponse
rest_resp_code_t HttpClient::execute() {
- pfc_log_info("%s Entering method ", PFC_FUNCNAME);
+ pfc_log_debug("%s Entering method ", PFC_FUNCNAME);
rest_resp_code_t curl_ret_code = set_opt_common();
if (SUCCESS != curl_ret_code) {
if (SUCCESS != curl_ret_code) {
return FAILURE;
}
- pfc_log_info("%s Exiting Execute method ", PFC_FUNCNAME);
+ pfc_log_debug("%s Exiting Execute method ", PFC_FUNCNAME);
return SUCCESS;
}
pfc_log_debug("%s, Entering function", PFC_FUNCNAME);
CURLcode curlRetCode = CURLE_OK;
curlRetCode = curl_easy_setopt(handle_, CURLOPT_URL,
- (requestheader).c_str());
+ (requestheader).c_str());
if (CURLE_OK != curlRetCode) {
return FAILURE;
rest_resp_code_t HttpClient::set_opt_write_data() {
pfc_log_debug("%s, Entering function", PFC_FUNCNAME);
CURLcode curlRetCode = curl_easy_setopt(handle_, CURLOPT_WRITEFUNCTION,
- write_call_back);
+ write_call_back);
if (CURLE_OK != curlRetCode) {
return FAILURE;
}
curlRetCode = curl_easy_setopt(handle_, CURLOPT_WRITEDATA,
- reinterpret_cast<void *>
- (response_->write_data));
+ reinterpret_cast<void *>
+ (response_->write_data));
if (CURLE_OK != curlRetCode) {
return FAILURE;
pfc_log_debug("%s, Entering function", PFC_FUNCNAME);
if (NULL != response_) {
if (NULL != response_->write_data) {
- pfc_log_info("Output from server %s ", response_->write_data->memory);
+ pfc_log_debug("Output from server %s ", response_->write_data->memory);
return response_->write_data;
}
}
CURLcode curlRetCode = curl_easy_perform(handle_);
if (CURLE_OK != curlRetCode) {
- pfc_log_info("%d Error", curlRetCode);
+ pfc_log_debug("%d Error", curlRetCode);
return FAILURE;
}
curlRetCode = curl_easy_getinfo(handle_,
- CURLINFO_RESPONSE_CODE, &(response_->code));
+ CURLINFO_RESPONSE_CODE, &(response_->code));
if (CURLE_OK != curlRetCode) {
return FAILURE;
// Call back to get the response from the CURL and
// write it to the resp structure
size_t HttpClient::write_call_back(void *ptr, size_t size, size_t nmemb,
- void *data) {
+ void *data) {
pfc_log_debug("%s, Entering function", PFC_FUNCNAME);
HttpContent_t *mem = reinterpret_cast<HttpContent_t*>(data);
pfc_log_debug("%s, Exiting function", PFC_FUNCNAME);
return realsize;
}
-}
-}
+} // namespace restjson
+} // namespace unc
-/*
+/*
* Copyright (c) 2012-2013 NEC Corporation
* All rights reserved.
- *
+ *
* This program and the accompanying materials are made
* available under the
* terms of the Eclipse Public License v1.0 which
namespace restjson {
class HttpClient {
- public:
- /**
- ** @brief Default Constructor.
- **/
- HttpClient();
-
- /**
- ** @brief Default Constructor.
- **/
- ~HttpClient();
-
- /**
- ** Initialises curl handle
- ** @retval int - returns 0 - for success, 1- failure
- **/
- void init();
-
- /**
- ** Fini Method to release handle
- **/
- void fini();
-
- /**
- ** Method to Execute the Request
- ** @restClientStruct_ - RestClientHeader structue
- ** @curlCmdStruct_ - CurlCommandHeader structure
- ** @reval Curlrest_resp_code_t - 0 for SUCCESS, 1 for FAILURE
- **/
- rest_resp_code_t execute();
-
- /**
- ** Method to get the response code from server
- ** @ret_val HttpResponse_t - structure which contains the response code from server
- **/
- HttpResponse_t get_http_resp_code();
-
- /**
- ** Method to get the respnse body from server
- ** @HttpContent_t - retval - Structure which contains response body from server
- **/
- HttpContent_t* get_http_resp_body();
-
- /**
- * Method to set the request Header
- * @param[in] requestheader
- * @param[out] - SUCCESS/ FAILURE
- */
- rest_resp_code_t set_request_header(const std::string &requestheader);
- /**
- * Method to set the user name and password
- * @param[in] username
- * @param[in] password
- * @param[out] - SUCCESS/ FAILURE
- */
- rest_resp_code_t set_username_password(const std::string &username,
- const std::string &password);
- /**
- * Method to set the connection TimeOut
- * @param[in] connectionTimeOut
- * @param[out] - SUCCESS/ FAILURE
- */
- rest_resp_code_t set_connection_timeout(const int connectionTimeOut);
- /**
- * Method to set the request TimeOut
- * @param[in] request TimeOut
- * @param[out] - SUCCESS/ FAILURE
- */
- rest_resp_code_t set_request_timeout(const int reqTimeOut);
- /**
- * Method to set the type of operation
- * @param[in] operation
- * @param[out] - SUCCESS/ FAILURE
- */
- rest_resp_code_t set_operation_type(const HttpMethod operation);
- /**
- * Method to set the request body
- * @param[in] requestbody
- * @param[out] - SUCCESS/ FAILURE
- */
- rest_resp_code_t set_request_body(const char* req);
-
- private:
- /**
- ** Method to set Common parameters like Time out
- ** @restClientStruct_ - RestClientHeader structue
- ** @curlCmdStruct_ - CurlCommandHeader structure
- ** @retval Curlrest_resp_code_t - 0 for SUCCESS, 1 for FAILURE
- **/
- rest_resp_code_t set_opt_common();
-
- /**
- ** Method to send Request
- ** @retval Curlrest_resp_code_t - 0 for SUCCESS, 1 for FAILURE
- **/
- rest_resp_code_t perform_http_req();
-
- /**
- ** Method to Write the Response from Server
- ** @retval Curlrest_resp_code_t - 0 for SUCCESS, 1 for FAILURE
- **/
- rest_resp_code_t set_opt_write_data();
-
- /**
- ** Callback Method used to write response data
- **/
- static size_t write_call_back(void* ptr, size_t size, size_t nmemb,
+ public:
+ /**
+ * @brief Default Constructor.
+ */
+ HttpClient();
+
+ /**
+ * @brief Default Destructor.
+ */
+ ~HttpClient();
+
+ /**
+ * @brief - Initialises curl handle
+ * @retval - None
+ */
+ void init();
+
+ /**
+ * @brief - Fini Method to release handle
+ * @retval - None
+ */
+ void fini();
+
+ /**
+ * @brief - Method to Execute the Request for restClientStruct
+ * and RestClientHeader structue
+ * @retval - Curlrest_resp_code_t - 0 for SUCCESS, 1 for FAILURE
+ */
+ rest_resp_code_t execute();
+
+ /**
+ * @brief - Method to get the response code from server
+ * @ret_val - HttpResponse_t - structure which contains the
+ * response code from server
+ */
+ HttpResponse_t get_http_resp_code();
+
+ /**
+ * @brief - Method to get the respnse body from server
+ * @retval - HttpContent_t Structure which contains response body from server
+ */
+ HttpContent_t* get_http_resp_body();
+
+ /**
+ * @brief - Method to set the request Header
+ * @param[in] - requestheader
+ * @retval - SUCCESS/ FAILURE
+ */
+ rest_resp_code_t set_request_header(const std::string &requestheader);
+
+ /**
+ * @brief - Method to set the user name and password
+ * @param[in] - username
+ * @param[in] - password
+ * @retval - SUCCESS/ FAILURE
+ */
+ rest_resp_code_t set_username_password(const std::string &username,
+ const std::string &password);
+ /**
+ * @brief - Method to set the connection TimeOut
+ * @param[in] - connectionTimeOut
+ * @retval - SUCCESS/ FAILURE
+ */
+ rest_resp_code_t set_connection_timeout(const int connectionTimeOut);
+
+ /**
+ * @brief - Method to set the request TimeOut
+ * @param[in] - request TimeOut
+ * @retval - SUCCESS/ FAILURE
+ */
+ rest_resp_code_t set_request_timeout(const int reqTimeOut);
+
+ /**
+ * @brief - Method to set the type of operation
+ * @param[in] - operation
+ * @retval - SUCCESS/ FAILURE
+ */
+ rest_resp_code_t set_operation_type(const HttpMethod operation);
+
+ /**
+ * @brief - Method to set the request body
+ * @param[in] - requestbody
+ * @retval - SUCCESS/ FAILURE
+ */
+ rest_resp_code_t set_request_body(const char* req);
+
+ private:
+ /**
+ * @brief - Method to set Common parameters like Time out using
+ * RestClientHeader structue and CurlCommandHeader structure
+ * @retval - Curlrest_resp_code_t - 0 for SUCCESS, 1 for FAILURE
+ */
+ rest_resp_code_t set_opt_common();
+
+ /**
+ * @brief - Method to send http Request
+ * @retval - Curlrest_resp_code_t - 0 for SUCCESS, 1 for FAILURE
+ */
+ rest_resp_code_t perform_http_req();
+
+ /**
+ * @brief - Method to Write the Response from Server
+ * @retval - Curlrest_resp_code_t - 0 for SUCCESS, 1 for FAILURE
+ */
+ rest_resp_code_t set_opt_write_data();
+
+ /**
+ * @brief - Callback Method used to write response data
+ * @param[in] - size, nmemb
+ * @param[out] - ptr, data
+ * @retval - size_t
+ */
+ static size_t write_call_back(void* ptr, size_t size, size_t nmemb,
void* data);
- private:
- CURL* handle_;
- HttpResponse_t *response_;
- struct curl_slist *slist_;
+ private:
+ CURL* handle_;
+ HttpResponse_t *response_;
+ struct curl_slist *slist_;
};
-}
-}
+} // namespace restjson
+} // namespace unc
#endif // RESTJSON_HTTP_CLIENT_H_
-/*
+/*
* Copyright (c) 2012-2013 NEC Corporation
* All rights reserved.
*
namespace restjson {
class JsonBuildParse {
- public:
- /*
- * @brief Creates json object
- * @param[out] - retval - json_object pointer
- */
- static json_object* create_json_obj();
+ public:
+ /**
+ * @brief -Creates json object
+ * @param[out] json_object* - json_object pointer
+ */
+ static json_object* create_json_obj();
- /**
- * @brief - Template method which build the json request
- * @param[out] - json_object* - json object pointer to which the data should be added
- * @param[in] - const std::string &key - string key to be added to the jsonobject
- * @param[in] T data - template type which is the value to be added for the specific key
- * - accepts type int, string, bool, json_object
- */
- template<typename T>
- static int build(json_object* jparent, const std::string &key, T data);
+ /**
+ * @brief - Template method which build the json request
+ * @param[out] json_object* - json object pointer to which the data should
+ * be added
+ * @param[in] key - string key to be added to the jsonobject
+ * @param[in] T data - template type which is the value to be added
+ * for the specific key. Accepts type int,
+ * string, bool, json_object
+ * @return - returns 0 on SUCCESS / 1 on FAILURE
+ */
+ template<typename T>
+static int build(json_object* jparent, const std::string &key, T data);
- /**
- * @brief - Template method which parse the json object
- * @param[in] -json_object* - json object pointer from which the data should be retrieved
- * @param[in] - const std::string &key - string key to be parsed from the jsonobject
- * @param[in] - const int arrindex - if the value to be parsed inside array, give the array index,
- * - otherwise -1
- * @param[out] - T data - template type which is the value to be added for the specific key
- * - accepts type int, string, bool, json_object
- * @param[out] - int - SUCCESS - 0 , FAILURE - 1
- */
- template<typename T>
- static int parse(json_object* jobj, const std::string &key,
- int arrindex, T &val);
+ /**
+ * @brief - Template method which parse the json object
+ * @param[in] json_object* - json object pointer from which the data
+ * should be retrieved
+ * @param[in] key - string key to be parsed from the jsonobject
+ * @param[in] arrindex - if the value to be parsed inside array, give
+ * the array index otherwise -1
+ * @param[out] T data - template type which is the value to be added
+ * for the specific key accepts type int,
+ * string, bool, json_object
+ * return int - returns 0 on SUCCESS / 1 on FAILURE
+ */
+ template<typename T>
+static int parse(json_object* jobj, const std::string &key,
+ int arrindex, T &val);
- /**
- * @Gets the type of the value for the specified key
- * @param[in] json_object - json object from which the val to be retieved
- * @param[in] - key - value retrieved from the specified key
- * @param[out] - int enum value json type
- */
- static int get_type(json_object* jobj, const std::string &key);
+ /**
+ * @brief - Gets the type of the value for the specified key
+ * @param[in] json_object - json object from which the val to be retieved
+ * @param[in] key - value retrieved from the specified key
+ * return int - returns enum value json type
+ */
+ static int get_type(json_object* jobj, const std::string &key);
- /**
- * GetArrayLength - the length of the array
- * @param[in] json_object - json object from which the val to be retieved
- * @param[in] - key - value retrieved from the specified key
- * @param[out] - the length of the array
- */
- static int get_array_length(json_object* jobj, const std::string &key);
+ /**
+ * GetArrayLength - the length of the array
+ * @param[in] json_object - json object from which the val to be retieved
+ * @param[in] key - value retrieved from the specified key
+ * @return int - the length of the array
+ */
+ static int get_array_length(json_object* jobj, const std::string &key);
- /*
- * Converts th ejson object to json string
- * @param[in] - json_object* which needs to converted to json string
- * @param[out] - const char* - converted from json object
- */
- static const char* json_obj_to_json_string(json_object* jobj);
+ /**
+ * @brief - Converts th ejson object to json string
+ * @param[in] json_object* - which needs to converted to json string
+ * return const char* - converted from json object
+ */
+ static const char* json_obj_to_json_string(json_object* jobj);
+
+ /**
+ * @brief - Converts string to json object
+ * @param[in] data - char pointer which needs to be converted to
+ * json obj
+ * @param[out] json_object* - returns converted json object
+ */
+ static json_object* string_to_json_object(char *data);
};
template<typename T>
int JsonBuildParse::build(json_object* jparent, const std::string &key,
- T data) {
+ T data) {
if (json_object_is_type(jparent, json_type_null)) {
return FAILURE;
}
jobj_getval = json_object_object_get(jobj, key.c_str());
}
if (json_object_is_type(jobj_getval, json_type_null)) {
- return FAILURE;
+ return SUCCESS;
}
+
JsonType::get_value(jobj_getval, val);
return SUCCESS;
}
-}
-}
+} // namespace restjson
+} // namespace unc
#endif // RESTJSON_JSON_BUILD_PARSE_H_
/*
- * Copyright (c) 2012-2013 NEC Corporation
- * All rights reserved.
+ * copyright (c) 2012-2013 nec corporation
+ * all rights reserved.
*
- * This program and the accompanying materials are made
+ * this program and the accompanying materials are made
* available under the
- * terms of the Eclipse Public License v1.0 which
+ * terms of the eclipse public license v1.0 which
* accompanies this
* distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
-#ifndef RESTJSON_JSON_TYPE_H_
-#define RESTJSON_JSON_TYPE_H_
+#ifndef restjson_json_type_h_
+#define restjson_json_type_h_
#include <json/json.h>
#include <string>
namespace unc {
namespace restjson {
class JsonType {
- private:
- /*
- * json object
- */
- json_object* jobj_;
+ private:
+ /**
+ * json object
+ */
+ json_object* jobj_;
- public:
- /*
- * @brief - Parametrised constructor takes arg as string
- * - Creates json object of type string
- */
- explicit JsonType(std::string strdata) {
- jobj_ = json_object_new_string(strdata.c_str());
- }
- /*
- * @brief - Parametrised constructor takes arg as int
- * - Creates json object of type int
- */
- explicit JsonType(int intdata) {
- jobj_ = json_object_new_int(intdata);
- }
- /*
- * @brief - Parametrised constructor takes arg as json object
- * - Creates json object of type json object
- */
- explicit JsonType(json_object* jsondata) {
- jobj_ = jsondata;
- }
+ public:
+ /**
+ * @brief - parametrised constructor takes arg as string
+ * - creates json object of type string
+ * @param[in] strdata - string value
+ */
+ explicit JsonType(std::string strdata) {
+ jobj_ = json_object_new_string(strdata.c_str());
+ }
- /**
- * Function overloading getValue - returns the value of type string
- * @param[in] - jobjval - json object from which the value to be retrieved
- * @param[out] - val - the value stored in this string reference
- */
- static void get_value(json_object* jobjval, std::string &val) {
- val = json_object_get_string(jobjval);
- }
- /**
- * Function overloading getValue - returns the value of type int
- * @param[in] - jobjval - json object from which the value to be retrieved
- * @param[out] - val - the value stored in this int reference
- */
- static void get_value(json_object* jobjval, int &val) {
- val = json_object_get_int(jobjval);
- }
- /**
- * Function overloading getValue - returns the value of type json_object
- * @param[in] - jobjval - json object from which the value to be retrieved
- * @param[out] - val - the value stored in this json_object reference
- */
- static void get_value(json_object* jobjval, json_object*& jobjgetval) {
- jobjgetval = jobjval;
- }
+ /**
+ * @brief - parametrised constructor takes arg as int
+ * - creates json object of type int
+ * @param[in] intdata - integer value
+ */
+ explicit JsonType(int intdata) {
+ jobj_ = json_object_new_int(intdata);
+ }
- /*
- * @brief - gets the JsonData
- * @param[out] - json_object
- */
- json_object* get_json_data() {
- return jobj_;
- }
+ /**
+ * @brief - Parametrised constructor takes arg as json object
+ * - Creates json object of type json object
+ * @param[in] jsondata - json object
+ */
+ explicit JsonType(json_object* jsondata) {
+ jobj_ = jsondata;
+ }
+
+ /**
+ * @brief - Function overloading getValue - returns the value
+ * of type string
+ * @param[in] jobjval - json object from which the value to be retrieved
+ * @param[out] val - the value stored in this string reference
+ * return - None
+ */
+ static void get_value(json_object* jobjval, std::string &val) {
+ val = json_object_get_string(jobjval);
+ }
+
+ /**
+ * @brief - Function overloading getValue - returns the
+ * value of type int
+ * @param[in] jobjval - json object from which the value to be retrieved
+ * @param[out] val - the value stored in this int reference
+ * return - None
+ */
+ static void get_value(json_object* jobjval, int &val) {
+ val = json_object_get_int(jobjval);
+ }
+
+ /**
+ * @brief - Function overloading getValue - returns the
+ * value of type json_object
+ * @param[in] jobjval - json obj from which the value to be retrive
+ * @param[out] val - the value stored in this json_object reference
+ * return - None
+ */
+
+ static void get_value(json_object* jobjval, json_object*& jobjgetval) {
+ jobjgetval = jobjval;
+ }
+
+ /**
+ * @brief - gets the JsonData
+ * @param[out] json_object* - json_object
+ */
+ json_object* get_json_data() {
+ return jobj_;
+ }
};
-}
-}
+} // namespace restjson
+} // namespace unc
#endif // RESTJSON_JSON_TYPE_H_
-/*
+/*
* Copyright (c) 2012-2013 NEC Corporation
* All rights reserved.
- *
+ *
* This program and the accompanying materials are made
* available under the
* terms of the Eclipse Public License v1.0 which
namespace restjson {
class RestClient {
- public:
- /**
- ** Constructor get ipaddress in string format, port number as input
- **/
- RestClient(const std::string &ipaddress, const int portnumber);
+ public:
+ /**
+ * @brief - Constructor get ipaddress in string format, port number
+ * as input
+ */
+ RestClient(const std::string &ipaddress, const int portnumber);
- /**
- * Destructor
- **/
- ~RestClient();
+ /**
+ * @brief - Destructor
+ */
+ ~RestClient();
- /**
- ** Method to set the username password to authenticate request
- ** @param [in] - username
- ** @param [in] - password
- **/
- rest_resp_code_t set_username_password(const std::string &username,
- const std::string &password);
+ /**
+ * @brief - Method to set the username password to
+ * authenticate request
+ * @param [in] username - username
+ * @param [in] password - password
+ * return rest_resp_code_t - returns SUCCESS on successfully setting username
+ * and password/returns FAILURE on failure
+ */
+ rest_resp_code_t set_username_password(const std::string &username,
+ const std::string &password);
- /**
- * Method to set the Connection timeout and request time out
- * @param[in] - connectionTimeOut
- * @param[in] - reqTimeOut
- */
- rest_resp_code_t set_timeout(const int connectionTimeOut,
- const int reqTimeOut);
+ /**
+ * @brief - Method to set the Connection timeout and
+ * request time out
+ * @param[in] connectionTimeOut - connection timeout
+ * @param[in] reqTimeOut - request timeout
+ * return rest_resp_code_t - returns SUCCESS on setting timeout
+ * successfully/ returns FAILURE on failure
+ */
+ rest_resp_code_t set_timeout(const int connectionTimeOut,
+ const int reqTimeOut);
- /**
- * Method to Create Request Header
- * @param [in] - operation - Operation 1- POST, 2 for PUT, 3 for DELETE, 4- GET
- ** @param [in] -url - specifies the url
- **/
+ /**
+ * @brief - Method to Create Request Header
+ * @param [in] url - specifies the url
+ * return rest_resp_code_t - returns SUCCESS on creating request header
+ * successfully/returns FAILURE on failure
+ */
+ rest_resp_code_t create_request_header(const std::string &url,
+ const HttpMethod operation);
- rest_resp_code_t create_request_header(const std::string &url,
- const HttpMethod operation);
+ /**
+ * @brief - Method to Request for Create Operation - id
+ * and value as input
+ * @param[in] str - request body
+ * @param[out] - returns SUCCESS on successfully setting the
+ * request body/ returns FAILURE on failure
+ */
+ rest_resp_code_t set_request_body(const char* str);
- /**
- ** Method to Request for Create Operation - id and value as input
- ** @param[in] - map idValuePair - contains the request body as id and value pair
- ** @param[in] - delimiter
- ** @param[out] - SUCCESS/ FAILURE
- **/
- rest_resp_code_t set_request_body(const char* str);
+ /**
+ * @brief - Method to Send Request and Get Response Code
+ * param[out] - returns SUCCESS on successfully sending request
+ * and getting the response code /returns FAILURE on failure
+ */
+ uint32_t send_request_and_get_response_code();
- /**
- * Method to Send Request and Get Response Code
- * param[out] - SUCCESS/ FAILURE
- */
- uint32_t send_request_and_get_response_code();
+ /**
+ * @brief - Gets the response body
+ * param[out] HttpContent_t - returns the HttpContent_t* structure
+ */
+ HttpContent_t* get_response_body();
- private:
- HttpClient *http_client_obj_;
- const std::string mipaddress_;
- const int mportnumber_;
+
+ private:
+ HttpClient *http_client_obj_;
+ const std::string mipaddress_;
+ const int mportnumber_;
};
-}
-}
+} // namespace restjson
+} // namespace unc
#endif // RESTJSON_REST_CLIENT_H_
-/*
+/*
* Copyright (c) 2012-2013 NEC Corporation
* All rights reserved.
- *
+ *
* This program and the accompanying materials are made
* available under the
* terms of the Eclipse Public License v1.0 which
} HttpMethod;
typedef struct {
- char *memory;
- int size;
+ char *memory;
+ int size;
} HttpContent_t;
typedef struct {
- int code;
- HttpContent_t *write_data;
+ int code;
+ HttpContent_t *write_data;
} HttpResponse_t;
typedef enum {
RESP_OK = 200,
RESP_UNKNOWN = 1
} ServerResponseCode;
-}
-}
+} // namespace restjson
+} // namespace unc
#endif // RESTJSON_REST_COMMON_DEFS_H_
*/
#include <json_build_parse.hh>
+#include <pfc/debug.h>
+#include <pfc/log.h>
namespace unc {
namespace restjson {
return json_object_to_json_string(jobj);
}
+// Converts String to Json Object
+json_object* JsonBuildParse::string_to_json_object(char *data) {
+ return json_tokener_parse(data);
+}
+
// Gets the enum type of the value
int JsonBuildParse::get_type(json_object* jobj, const std::string &key) {
if (json_object_is_type(jobj, json_type_null)) {
if (json_object_is_type(jobj, json_type_null)) {
return FAILURE;
}
+
json_object *jobj_value = json_object_object_get(jobj, key.c_str());
if (json_object_is_type(jobj_value, json_type_null)) {
return FAILURE;
}
+ pfc_log_debug("%s json", json_obj_to_json_string(jobj_value));
int arr_length = json_object_array_length(jobj_value);
+ pfc_log_debug("%d array length", arr_length);
+
return arr_length;
}
-}
-}
+} // namespace restjson
+} // namespace unc
/*
* Copyright (c) 2012-2013 NEC Corporation
* All rights reserved.
- *
+ *
* This program and the accompanying materials are made
* available under the
* terms of the Eclipse Public License v1.0 which
// Constructor
RestClient::RestClient(const std::string &ipaddress, const int portnumber)
-: mipaddress_(ipaddress),
- mportnumber_(portnumber) {
- pfc_log_debug("%s Entering function", PFC_FUNCNAME);
- http_client_obj_ = new HttpClient();
- http_client_obj_->init();
- pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
-}
+ : mipaddress_(ipaddress),
+ mportnumber_(portnumber) {
+ pfc_log_debug("%s Entering function", PFC_FUNCNAME);
+ http_client_obj_ = new HttpClient();
+ if (http_client_obj_ != NULL) {
+ http_client_obj_->init();
+ } else {
+ pfc_log_error(" init() nOT called");
+ }
+ pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
+ }
// Destructor
RestClient::~RestClient() {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
- if (NULL != http_client_obj_) {
+ if (http_client_obj_ != NULL) {
http_client_obj_->fini();
delete http_client_obj_;
http_client_obj_ = NULL;
// Send the Username and password to SetUserNamePassword
rest_resp_code_t RestClient::set_username_password(const std::string &username,
- const std::string &password) {
+ const std::string
+ &password) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
if ((0 == strlen(username.c_str())) || (0 == strlen(password.c_str()))) {
// Send the timeout values to HttpClient Class
rest_resp_code_t RestClient::set_timeout(const int connectionTimeOut,
- const int reqTimeOut) {
+ const int reqTimeOut) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
+ PFC_ASSERT(NULL != http_client_obj_);
rest_resp_code_t retval = http_client_obj_->set_connection_timeout(
- connectionTimeOut);
+ connectionTimeOut);
if (FAILURE == retval) {
return FAILURE;
}
// Create Request Header and send to HttpClient Class
rest_resp_code_t RestClient::create_request_header(const std::string &url,
- const HttpMethod operation) {
+ const HttpMethod operation) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
if ((HTTP_METHOD_POST != operation) && (HTTP_METHOD_PUT != operation)
&& (HTTP_METHOD_DELETE != operation) && (HTTP_METHOD_GET != operation)) {
}
if ( 0 == mportnumber_ ) {
- pfc_log_error("Invalid port number");
- return FAILURE;
+ pfc_log_error("Invalid port number");
+ return FAILURE;
}
std::string requestHeader = "";
if (FAILURE == retval) {
return FAILURE;
}
- pfc_log_info("%s requestHeader", requestHeader.c_str());
+ pfc_log_debug("%s requestHeader", requestHeader.c_str());
retval = http_client_obj_->set_operation_type(operation);
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return respStructure.code;
}
+// Get the response body
+HttpContent_t* RestClient::get_response_body() {
+ PFC_ASSERT(NULL != http_client_obj_);
+ return http_client_obj_->get_http_resp_body();
+}
+
// Invokes HttpClient Class SetRequestBody Method
rest_resp_code_t RestClient::set_request_body(const char* reqbody) {
pfc_log_debug("%s Entering function", PFC_FUNCNAME);
pfc_log_debug("%s Exiting function", PFC_FUNCNAME);
return ret_val;
}
-}
-}
+} // namespace restjson
+} // namespace unc
*/
explicit RestJsonMod(const pfc_modattr_t *mattr) :
pfc::core::Module(mattr) {
- }
+ }
/*
* @brief - init method
return PFC_TRUE;
}
};
-}
-}
+} // namespace restjson
+} // namespace unc
PFC_MODULE_IPC_DECL(unc::restjson::RestJsonMod, 0);
}
if (PFC_EXPECT_TRUE(driver_id_ >= UNC_CT_PFC) &&
- PFC_EXPECT_TRUE(driver_id_ <= UNC_CT_VNP)) {
+ PFC_EXPECT_TRUE(driver_id_ <= UNC_CT_ODC)) {
util_resp = tc::TcClientSessionUtils::set_uint8(abortsess, driver_id_);
if (PFC_EXPECT_TRUE(util_resp != TCUTIL_RET_SUCCESS)) {
TcClientSessionUtils::tc_session_close(&abortsess, conn);
return ReturnUtilResp(util_resp);
}
if (PFC_EXPECT_TRUE(driver_id_ >= UNC_CT_PFC) &&
- PFC_EXPECT_TRUE(driver_id_ <= UNC_CT_VNP)) {
+ PFC_EXPECT_TRUE(driver_id_ <= UNC_CT_ODC)) {
util_resp = tc::TcClientSessionUtils::set_uint8(end_sess, driver_id_);
if (PFC_EXPECT_TRUE(util_resp != TCUTIL_RET_SUCCESS)) {
TcClientSessionUtils::tc_session_close(&end_sess, conn);
/*validate driver_id_ and controller i
* session-id can be 0 incase of driver-audit */
if (PFC_EXPECT_TRUE(driver_id_ < UNC_CT_PFC) ||
- PFC_EXPECT_TRUE(driver_id_ > UNC_CT_VNP) ||
+ PFC_EXPECT_TRUE(driver_id_ > UNC_CT_ODC) ||
PFC_EXPECT_TRUE(controller_id_.empty())) {
pfc_log_error("Invalid Driver/Controller ID");
return TCOPER_RET_FAILURE;
}
case tclib::MSG_AUDIT_TRANS_START: {
pfc_log_info("*** AUDIT TxSTART ***");
- notifyorder_.push_back(TC_DRV_OPENFLOW);
- notifyorder_.push_back(TC_DRV_OVERLAY);
+ notifyorder_.push_back(TC_DRV_ODL);
+ //notifyorder_.push_back(TC_DRV_OVERLAY);
// notifyorder_.push_back(TC_DRV_LEGACY);
notifyorder_.push_back(TC_UPLL);
notifyorder_.push_back(TC_UPPL);
notifyorder_.push_back(TC_UPPL);
notifyorder_.push_back(TC_UPLL);
// notifyorder_.push_back(TC_DRV_LEGACY);
- notifyorder_.push_back(TC_DRV_OVERLAY);
- notifyorder_.push_back(TC_DRV_OPENFLOW);
+ notifyorder_.push_back(TC_DRV_ODL);
break;
}
default: {
/*validate controller_id_ and driver_id_*/
if ((PFC_EXPECT_TRUE(driver_id_ < UNC_CT_PFC) ||
- PFC_EXPECT_TRUE(driver_id_ > UNC_CT_VNP)) ||
+ PFC_EXPECT_TRUE(driver_id_ > UNC_CT_ODC)) ||
PFC_EXPECT_TRUE(controller_id_.empty())) {
pfc_log_error("Invalid Driver/Controller ID");
return TCOPER_RET_FAILURE;
#
# Copyright (c) 2012-2013 NEC Corporation
# All rights reserved.
-#
+#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v1.0 which accompanies this
# distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
include ../defs.mk
CXX_SOURCES = keytree.cc \
- confignode.cc \
- vtncachemod.cc
+ confignode.cc \
+ vtncachemod.cc
include ../rules.mk
##
## Targets:
##
-## make all (default target)
+## make all(default target)
## Build all binary distributions.
##
## make installu
* terms of the Eclipse Public License v1.0 which accompanies this
* distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-#include "include/confignode.hh"
-#include "include/keytree.hh"
+#include "confignode.hh"
+#include "keytree.hh"
namespace unc {
namespace vtndrvcache {
/**
- * @brief Returns the type string corresponding the the keytype.
- * This is used
- * to print the keytree structure
- * param[in] search_type
- * param[out] Kettype converted to
- * string
+ * @brief : Returns the type string corresponding the the keytype.
+ * This is used to print the keytree structure
+ * @param[in] : search_type
+ * @retval : string
*/
std::string TypeToStrFun(unc_key_type_t search_type) {
std::string typeStr;
switch (search_type) {
case UNC_KT_VTN:
- typeStr = string("UNC_KT_VTN");
+ typeStr = std::string("UNC_KT_VTN");
break;
case UNC_KT_VBRIDGE:
- typeStr = string("UNC_KT_VBRIDGE");
+ typeStr = std::string("UNC_KT_VBRIDGE");
break;
case UNC_KT_VBR_IF:
- typeStr = string("UNC_KT_VBR_IF");
+ typeStr = std::string("UNC_KT_VBR_IF");
break;
case UNC_KT_ROOT:
- typeStr = string("UNC_KT_ROOT");
+ typeStr = std::string("UNC_KT_ROOT");
break;
default:
- typeStr = string("Unknown");
- pfc_log_info("%s: key_type = %d", PFC_FUNCNAME,
+ typeStr = std::string("Unknown");
+ pfc_log_debug("%s: key_type = %d", PFC_FUNCNAME,
search_type);
break;
}
/**
* @brief : default constructor
*/
-ConfigNode::ConfigNode() :node_key(""),parent_key(""),operation(0) {
- pfc_log_trace("ConfigNode Constructor");
- child_list.clear();
+ConfigNode::ConfigNode() : operation_(0), cfgnode_count_(0) {
+ pfc_log_debug("Entering default constructor %s..", PFC_FUNCNAME);
+ child_list_.clear();
}
/**
- * @brief Method to retrieve each node from the Keytree and
- * populate in
- * the vector
- * param[in] value_list
- * param[out] TREE_OK
+ * @brief : Method to retrieve each node from the Keytree and populate in
+ the vector
+ * @param[in] : ConfigNode value_list
+ * @retval : TREE_OK
*/
-uint32_t ConfigNode::get_node_list(std::vector<ConfigNode*>&value_list) {
+uint32_t ConfigNode::get_node_list(std::vector<ConfigNode*>& value_list) {
pfc_log_debug("Entering %s ", PFC_FUNCNAME);
- if (child_list.size() <= 0) {
+
+ // If the node doesn't have any child, this return can be
+ // from the root node or to the recursive caller
+ if (child_list_.empty()) {
pfc_log_debug("%s: No child list", PFC_FUNCNAME);
return TREE_OK;
}
+
+ // Get the child list of each node
std::map<unc_key_type_t, std::vector<ConfigNode*> >::iterator sb_itr =
- child_list.begin();
+ child_list_.begin();
std::map<unc_key_type_t, std::vector<ConfigNode*> >::iterator sb_itr_end =
- child_list.end();
+ child_list_.end();
+
+ // Iterate the child list and by make a recursive call to iterate
+ // the child list and hence the list is traversed in DFS order
+ // till the node has no children
for (; sb_itr != sb_itr_end; ++sb_itr) {
std::vector<ConfigNode*>& node_list = sb_itr->second;
for (; node_itr != node_itr_end; ++node_itr) {
value_list.push_back(*node_itr);
- pfc_log_debug("ConfigNode::get_node_list: KeyTree::getNodeList:%s "
- " pushed in to &value_list ",
- TypeToStrFun((*node_itr)->get_type()).c_str());
(*node_itr)->get_node_list(value_list);
}
}
}
/**
- * @brief This method prints each node information
- * param[in] level_index
- * param[out] none
+ * @brief : This method prints each node information
+ * @param[in] : level_index
+ * @retval : None
*/
void ConfigNode::print(int level_index) {
pfc_log_debug("%s: Entering function....", PFC_FUNCNAME);
print_key(level_index);
- if (child_list.size() > 0) {
+ if (!child_list_.empty()) {
std::map<unc_key_type_t, std::vector<ConfigNode*> >::iterator sb_itr =
- child_list.begin();
+ child_list_.begin();
std::map<unc_key_type_t,
- std::vector<ConfigNode*> >::iterator sb_itr_end = child_list.end();
+ std::vector<ConfigNode*> >::iterator sb_itr_end = child_list_.end();
for (; sb_itr != sb_itr_end; sb_itr++) {
std::vector<ConfigNode*>& node_list = sb_itr->second;
- if (node_list.size() > 0) {
+ if (!node_list.empty()) {
std::vector<ConfigNode*>::iterator node_itr = node_list.begin();
std::vector<ConfigNode*>::iterator node_itr_end = node_list.end();
}
/**
- * @brief This method inserts the node in the cache
- * param[in] confignode*
- * param[out]uint32_t
+ * @brief : This method inserts the node in the cache
+ * @param[in] : confignode *
+ * @retval : CACHEMGR_RESPONSE_FAILURE / TREE_OK
*/
uint32_t ConfigNode::add_child_to_list(ConfigNode *node_ptr) {
pfc_log_debug("%s:Entering", PFC_FUNCNAME);
- std::map<unc_key_type_t, std::vector<ConfigNode*> >::iterator itr =
- child_list.begin();
+ std::map<unc_key_type_t, std::vector<ConfigNode*> >::iterator itr;
std::map<unc_key_type_t, std::vector<ConfigNode*> >::iterator itr_end =
- child_list.end();
+ child_list_.end();
- itr = child_list.find(node_ptr->get_type());
+ if (node_ptr == NULL) {
+ pfc_log_error("%s : ConfigNode is NULL", PFC_FUNCNAME);
+ return CACHEMGR_RESPONSE_FAILURE;
+ }
- /* If the child list already present for that node type, add the new
- child to the list..... else create new child list */
+ itr = child_list_.find(node_ptr->get_type());
+
+ // If the child list already present for that node type, add the new
+ // child to the list..... else create new child list
if (itr == itr_end) {
pfc_log_debug("add_child_to_list: Child list NOT present for %s ",
TypeToStrFun(node_ptr->get_type()).c_str());
- child_list.insert(
- pair<unc_key_type_t, std::vector<ConfigNode*> > (
+ child_list_.insert(
+ std::pair<unc_key_type_t, std::vector<ConfigNode*> > (
node_ptr->get_type(),
- vector<ConfigNode*> ()));
+ std::vector<ConfigNode*> ()));
- itr = child_list.find(node_ptr->get_type());
+ itr = child_list_.find(node_ptr->get_type());
} else {
pfc_log_debug("ConfigNode::AddChildNode: Child list present for %s ",
TypeToStrFun(node_ptr->get_type()).c_str());
std::vector<ConfigNode*>& node_list = itr->second;
node_list.push_back(node_ptr);
+ cfgnode_count_++;
+ pfc_log_debug("cfgnode_count_ %d", cfgnode_count_);
+
pfc_log_debug("%s: AddChildNode: Exiting", PFC_FUNCNAME);
return TREE_OK;
}
/**
- * @brief This method clear the cache
- * param[in] none
- * param[out]none
- */
-void ConfigNode::clear_kt_map() {
- pfc_log_debug("%s:Entering", PFC_FUNCNAME);
- std::map<unc_key_type_t, std::vector<ConfigNode*> >::iterator sb_itr =
- child_list.begin();
- std::map<unc_key_type_t, std::vector<ConfigNode*> >::iterator sb_itr_end =
- child_list.end();
-
- for (; sb_itr != sb_itr_end; ++sb_itr) {
- std::vector<ConfigNode*>& node_list = sb_itr->second;
-
- if (!node_list.empty()) {
- std::vector<ConfigNode*>::iterator node_itr = node_list.begin();
- std::vector<ConfigNode*>::iterator node_itr_end = node_list.end();
-
- for (; node_itr != node_itr_end; ++node_itr) {
- if (*node_itr != NULL) {
- delete *node_itr;
- }
- }
- }
- node_list.clear();
- }
- child_list.clear();
- pfc_log_debug("%s:Exiting", PFC_FUNCNAME);
-}
-
-/**
- * @brief This method read confignode from cache
- * param[in] keytype,confignode* vector
- * param[out]filled confignode* vector
- */
-uint32_t ConfigNode::read_all_cfgnode(unc_key_type_t key,
- std::vector<ConfigNode*>& vec) {
- pfc_log_debug("%s:Entering", PFC_FUNCNAME);
- std::map<unc_key_type_t, std::vector<ConfigNode*> >::iterator sb_itr;
- sb_itr = child_list.find(key);
- if (sb_itr != child_list.end()) {
- vec.reserve(sb_itr->second.size());
- std::copy(sb_itr->second.begin(), sb_itr->second.end(),
- back_inserter(vec));
- return PFCDRVAPI_RESPONSE_SUCCESS;
- }
- pfc_log_debug("%s:Exiting", PFC_FUNCNAME);
- return PFCDRVAPI_RESPONSE_FAILURE;
-}
-
-/**
- * @brief This method prints each node information
- * param[in] level_index
- * param[out] none
+ * @brief : This method prints the Key of the
+ * particular node
+ * @param[in] : level_index
+ * @retval : None
*/
void RootNode::print_key(int level_index) {
int num_spaces = level_index* NUM_SPACES;
- std::string prefix_str = "";
+ std::string prefix_str;
unc_key_type_t node_type = get_type();
- for (int i = 0; i < num_spaces; i++)
+ for (int i = 0; i < num_spaces; ++i)
prefix_str.append(" ");
prefix_str.append(TypeToStrFun(node_type));
prefix_str.append("->");
}
/**
- * @brief : default desstructor
+ * @brief : default destructor
*/
RootNode::~RootNode() {
pfc_log_debug("Entering default destructor %s..", PFC_FUNCNAME);
}
-} // vtndrvcache
-} // unc
+} // namespace vtndrvcache
+} // namespace unc
#ifndef _CONFIGNODE_HH_
#define _CONFIGNODE_HH_
+#include <pfc/debug.h>
+#include <pfc/log.h>
#include <string>
#include <map>
#include <vector>
#include "unc/keytype.h"
-#include <pfc/debug.h>
-#include <pfc/log.h>
-using namespace std;
-
-#define NUM_SPACES 4
-#define INVALID_CCID 999
-#define TREE_OK 1000
-#define ERR_OBJ_NULL 1001
-#define ERR_INCORRECT_LEVEL_INDEX 1002
-#define ERR_PARENT_MISMATCH 1003
-#define ERR_POPULATENODE_FAILD 1004
-#define ERR_ADD_CHILD_TO_TREE_FAILD 1005
-#define ERR_INVALID_NODE_TYPE 1006
-#define ERR_GET_PARENTLIST_FAILD 1007
-#define NODE_ALREADY_PRESENT 1008
+unsigned const NUM_SPACES = 4;
namespace unc {
namespace vtndrvcache {
/**
- * @brief Returns the type string corresponding the the keytype. This is used
- * to print the keytree structure
- * param[in] search_type
- * param[out] Kettype converted to string
+ * @brief : Returns the type string corresponding the the keytype. This is used
+ to print the keytree structure
+ * param[in] : search_type
+ * @retval : string
*/
std::string TypeToStrFun(unc_key_type_t search_type);
/**
* @brief : default virtual destructor
*/
-
virtual ~ConfigNode() {}
/**
- * @brief Method to retrieve each node from the Keytree and populate in
- * the vector
- * param[in] value_list
- * param[out] TREE_OK
+ * @brief : Method to retrieve each node from the Keytree and populate in
+ * the vector
+ * param[in] : value_list
+ * @retval : iuint32_t
*/
uint32_t get_node_list(std::vector<ConfigNode*>&value_list);
/**
- * @brief This virtual method returns the Keytype of a node
- * param[in] none
- * param[out] TREE_OK
+ * @brief : This virtual method returns the Keytype of a node
+ * @retval : unc_key_type_t
*/
virtual unc_key_type_t get_type() {
return (unc_key_type_t) -1;
}
/**
- * @brief This virtual method returns the Search Key of the node
- * param[in] none
- * param[out] unc_key_type_t
+ * @brief : This virtual method returns the Search Key of the node
+ * @retval : string
*/
- virtual string get_key() {
- return node_key;
+ virtual std::string get_key() {
+ return "";
}
/**
- * @brief This virtual method returns the parent Key of the node
- * param[in] none
- * param[out]string
+ * @brief : This virtual method returns the parent Key of the node
+ * @retval : string
*/
- virtual string get_parent_key() {
- return parent_key;
+ virtual std::string get_parent_key() {
+ return "";
}
/**
- * @brief This method inserts the node in the cache
- * param[in] confignode *
- * param[out]uint32_t
+ * @brief : This method inserts the node in the cache
+ * param[in] : confignode *
+ * @retval : uint32_t
*/
uint32_t add_child_to_list(ConfigNode *node_ptr);
/**
- * @brief This method prints each node information
- * param[in] level_index
- * param[out] none
+ * @brief : This method prints each node information
+ * param[in] : level_index
*/
void print(int level_index);
/**
- * @brief This method prints the Key of the
- * particular node
- * param[in] level_index
- * param[out] none
+ * @brief : This method prints the Key of the
+ * particular node
+ * param[in] : level_index
*/
virtual void print_key(int level_index) {
return;
}
/**
- * @brief This virtual method returns the operation
- * param[in] none
- * param[out]string
+ * @brief : This virtual method returns the operation
+ * @retval : string
*/
virtual uint32_t get_operation() {
- return operation;
+ return operation_;
}
/**
- * @brief This method clear the cache
- * param[in] none
- * param[out]none
+ * @brief : This method gets the confignode count
+ * @param[in] : none
+ * @retval : node count
*/
- void clear_kt_map();
-
- /**
- * @brief This method read confignode from cache
- * param[in] keytype,confignode* vector
- * param[out]filled confignode* vector
- */
- uint32_t read_all_cfgnode(unc_key_type_t key,
- std::vector<ConfigNode*>& vec_vtn);
-
+ uint32_t get_cfgnode_count() {
+ return cfgnode_count_;
+ }
protected:
- string node_key;
- string parent_key;
- std::map<unc_key_type_t, std::vector<ConfigNode*> > child_list;
- uint32_t operation;
+ std::map<unc_key_type_t, std::vector<ConfigNode*> > child_list_;
+ uint32_t operation_;
+ uint32_t cfgnode_count_;
};
+
class RootNode : public ConfigNode {
public:
-
/**
* @brief : default constructor
*/
~RootNode();
/**
- * @brief This method return root
- * param[in] none
- * param[out]UNC_KT_ROOT
+ * @brief : This method return root
+ * @retval : UNC_KT_ROOT
*/
- inline unc_key_type_t get_type() {
+ unc_key_type_t get_type() {
return UNC_KT_ROOT;
}
/**
- * @brief This method prints each node information
- * param[in] level_index
- * param[out] none
+ * @brief : This method prints each node information
+ * param[in] : level_index
*/
void print_key(int level_index);
};
} // end of namespace vtndrvcache
} // end of namespace unc
#endif
-
-
#ifndef KEYTREE_CONFIG_HH_
#define KEYTREE_CONFIG_HH_
-#include "confignode.hh"
#include <vector>
#include <utility>
#include <map>
#include <string>
+#include "confignode.hh"
-#define TREE_OK 1000
-#define ERR_ADD_CHILD_TO_TREE_FAILD 1005
-#define CONFIGARR_SIZE 50
-#define PFCDRVAPI_RESPONSE_FAILURE 1
-#define PFCDRVAPI_RESPONSE_SUCCESS 0
-#define CACHEMGR_RESPONSE_SUCCESS 0
+#define TREE_OK 0
+#define ERR_ADD_CHILD_TO_TREE_FAILED 1
+#define CONFIGARR_SIZE 50
+#define CACHEMGR_RESPONSE_FAILURE 1
+#define CACHEMGR_RESPONSE_SUCCESS 0
+#define CACHEMGR_APPEND_NODE_FAIL -1
namespace unc {
namespace vtndrvcache {
friend class CommonIterator;
/**
- ** Method to create Cache and return the pointer to it
- ** @param [out] - KeyTree*
- **/
+ * @brief : Method to create Cache and return the pointer to it
+ * @retval : KeyTree*
+ */
static KeyTree* create_cache();
/**
- ** Constructor to insert the root node in the array of map
- **/
- KeyTree() {
- configHashArr[0].insert(pair <std::string, ConfigNode*>
- ("ROOT", &node_tree));
- }
+ * @brief : Constructor to insert the root node in the array of map
+ */
+ KeyTree();
+
/**
- * Destructor
+ * @brief : Destructor
**/
- ~KeyTree() {}
+ ~KeyTree();
+
void print();
/**
- ** Method to traverse the tree and populate the nodes into the vector
- ** @param [in] - ctrlid
- ** @param [in] - value_list
- ** @param [out] - TREE_OK
- **/
+ * @brief : Method to traverse the tree and populate the nodes into
+ * the vector
+ * @param [in] : value_list
+ * @retval : TREE_OK
+ */
uint32_t get_nodelist_keytree(
std::vector<ConfigNode*>&value_list);
/**
- ** Method to return the Keytype of Parent given the search Key
- ** @param [in] - search_type
- ** @param [out] - unc_key_type_t
- **/
+ * @brief : Method to return the Keytype of Parent given the search Key
+ * @param [in] : search_type
+ * @retval : unc_key_type_t
+ */
unc_key_type_t get_parenttype(unc_key_type_t search_type);
/**
- ** Method to validate if parent exists for this particular node
- ** @param [in] - value_list
- ** @param [out] - true/false
- **/
+ * @brief : Method to validate if parent exists for this particular node
+ * @param [in] : value_list
+ * @retval : true/false
+ */
bool validate_parentkey(ConfigNode* value_list);
/**
- ** Method to add confignode to the cache for Audit
- ** @param [in] - value_list
- ** @param [out] - TREE_OK
- **/
+ * @brief : Method to add confignode to the cache for Audit
+ * @param [in] : value_list
+ * @retval : uint32_t
+ */
uint32_t append_audit_node(const std::vector<ConfigNode*>&value_list);
/**
- ** Method to add confignode to the cache for Audit
- ** @param [in] - value_list
- ** @param [out] - TREE_OK
- **/
+ * @brief : Method to add confignode to the cache for Audit
+ * @param [in] : value_list
+ * @retval : uint32_t
+ */
uint32_t append_audit_node(ConfigNode* value_list);
/**
- ** Method to add confignode to the cache for commit
- ** @param [in] - value_list
- ** @param [out] - TREE_OK
- **/
+ * @brief : Method to add confignode to the cache for commit
+ * @param [in] : value_list
+ * @retval : uint32_t
+ */
uint32_t append_commit_node(ConfigNode* value_list);
/**
- ** Method to add node to the cache and search map by validation
- ** @param [in] - value_list
- ** @param [out] - TREE_OK/PFCDRVAPI_RESPONSE_FAILURE
- **/
+ * @brief : Method to add node to the cache and search map by validation
+ * @param [in] : child_ptr
+ * @retval : uint32_t
+ */
uint32_t add_node_to_tree(ConfigNode* child_ptr);
/**
- ** Method to search and retrieve the node from the search map
- ** @param [in] - key
- ** @param [in] - key_Type
- ** @param [out] - ConfigNode*
- **/
+ * @brief : Method to search and retrieve the node from the search map
+ * @param [in] : key
+ * @param [in] : key_Type
+ * @retval : ConfigNode*
+ */
ConfigNode* get_node_from_hash(std::string key,
unc_key_type_t key_Type);
/**
- ** Method to check if the particular key is already present in search map
- ** @param [in] - key
- ** @param [in] - key_Type
- ** @param [out] - true/false
- **/
+ * @brief : Method to check if the particular key is already present in search map
+ * @param [in] : key
+ * @param [in] : key_Type
+ * @retval : bool
+ */
bool is_already_present(std::string key, unc_key_type_t key_Type);
/**
- ** Method to insert node to the search map
- ** @param [in] - child_ptr
- ** @param [out] - TREE_OK
- **/
+ * @brief : Method to insert node to the search map
+ * @param [in] : child_ptr
+ * @retval : uint32_t
+ */
uint32_t add_child_to_hash(ConfigNode* child_ptr);
/**
- ** Method to clear the elements of commit cache
- ** @param [in] - None
- ** @param [out] - None
- **/
+ * @brief : Method to clear the elements of commit cache
+ */
void clear_commit_cache();
/**
- ** Method to clear the elements of audit cache
- ** @param [in] - None
- ** @param [out] - None
- **/
- void clear_audit_cache();
+ * @brief : Method to clear the elements of audit cache
+ * @retval : uint32_t
+ */
+ uint32_t clear_audit_cache();
/**
- ** Method to clear the elements of vector
- ** @param [in] - None
- ** @param [out] - None
- **/
+ * @brief : Method to clear the elements of vector
+ */
void clear_cache_vector();
/**
- ** Method to clear the elements of search map
- ** @param [in] - None
- ** @param [out] - None
- **/
+ * @brief : Method to clear the elements of search map
+ */
void clear_search_cache();
/**
- ** Method to clear the elements of audit cache
- ** @param [in] - None
- ** @param [out] - None
- **/
+ * @brief : Method to get the iterator of Keytree
+ * @retval : CommonIterator*
+ */
CommonIterator* get_iterator();
+
/**
- ** Overloaded [] operator that returns each element of the container
- ** @param [in] - None
- ** @param [out] - None
- **/
- ConfigNode* operator[](int itemIndex) {
- return cfg_node_list[itemIndex];
+ * @brief : Overloaded [] operator that returns each element of the container
+ * @retval : ConfigNode*
+ */
+ ConfigNode* operator[](uint32_t itemIndex) {
+ return cfg_node_list_[itemIndex];
}
/**
- ** Method to calculate the size of container cfg_node_list
- ** @param [in] - None
- ** @param [out] - None
- **/
- int cfg_list_count() {
- return cfg_node_list.size();
+ * @brief : Method to calculate the size of container cfg_node_list_
+ * @retval : uint32_t
+ */
+ uint32_t cfg_list_count() {
+ return cfg_node_list_.size();
+ }
+
+ /**
+ * @brief : Method to calculate the size of root node's cfg_node_list_
+ * @retval : uint32_t
+ */
+ uint32_t cfg_list_cnt() {
+ return node_tree_.get_cfgnode_count();
}
- uint32_t read_all_cfgnode(unc_key_type_t key,
- std::vector<ConfigNode*>& vec_vtn);
configNodeHash configHashArr[CONFIGARR_SIZE];
typedef std::vector<ConfigNode*> Config_node_list;
- Config_node_list cfg_node_list;
- RootNode node_tree;
+ Config_node_list cfg_node_list_;
+ RootNode node_tree_;
};
class CommonIterator {
KeyTree *aggregate_;
- int currentIndex_;
+ uint32_t currentIndex_;
public:
+ /**
+ * @brief : Constructor to initialize the members
+ * @param[in] : KeyTree *
+ **/
explicit CommonIterator(KeyTree *aggregate)
: aggregate_(aggregate)
, currentIndex_(0) {
}
+
+ /**
+ * @brief : Method to fetch first element from Keytree container
+ * @retval : ConfigNode*
+ */
ConfigNode* FirstItem() {
currentIndex_ = 0;
- return (*aggregate_)[currentIndex_];
+ if (aggregate_ != NULL) {
+ return (*aggregate_)[currentIndex_];
+ }
+ return NULL;
}
+ /**
+ * @brief : Method to fetch next element from Keytree container
+ * @retval : ConfigNode*
+ */
ConfigNode* NextItem() {
currentIndex_ += 1;
if (IsDone() == false) {
- return (*aggregate_)[currentIndex_];
- } else {
- return NULL;
+ if (aggregate_ != NULL)
+ return (*aggregate_)[currentIndex_];
}
+ return NULL;
}
+ /**
+ * @brief : Method to fetch first element from Keytree container
+ during audit
+ * @retval : ConfigNode*
+ */
ConfigNode* AuditFirstItem() {
currentIndex_ = 0;
- aggregate_->get_nodelist_keytree(aggregate_->cfg_node_list);
- return (*aggregate_)[currentIndex_];
+ if (aggregate_ != NULL) {
+ aggregate_->get_nodelist_keytree(aggregate_->cfg_node_list_);
+ return (*aggregate_)[currentIndex_];
+ }
+ return NULL;
}
+ /**
+ * @brief : Method to fetch the current element from Keytree container
+ * @param [in] : None
+ * @retval : current element in container
+ */
ConfigNode* CurrentItem() {
- return (*aggregate_)[currentIndex_];
+ if (aggregate_ != NULL)
+ return (*aggregate_)[currentIndex_];
}
+ /**
+ * @brief : Method to check the end of Keytree container
+ * @param [in] : None
+ * @retval : true/false
+ */
bool IsDone() {
- if (currentIndex_ < aggregate_->cfg_list_count()) {
- return false;
+ if (aggregate_ != NULL) {
+ if (currentIndex_ < aggregate_->cfg_list_count()) {
+ return false;
+ }
}
return true;
}
};
-}
-}
+} // namespace vtndrvcache
+} // namespace unc
#endif
-
-
#ifndef __VTN_CONF_DATA_ELEMENT_OP_HH__
#define __VTN_CONF_DATA_ELEMENT_OP_HH__
+#include<string>
#include "vtn_conf_utility.hh"
#include "confignode.hh"
-#include<string>
-
namespace unc {
- namespace vtndrvcache {
- template<typename key, typename value, typename cache_oper>
- class CacheElementUtil: public ConfigNode {
- private:
- key* key_;
- value* value_;
- cache_oper operation;
-
- public:
- /**
- ** Constructor to set the key struct, value structure & operation
- **/
-
- CacheElementUtil(key* key_ty, value* value_ty, cache_oper opet):
- operation(opet) {
-
- key_ = new key();
- PFC_ASSERT(key_ != NULL);
- value_ = new value();
- PFC_ASSERT(value_ != NULL);
-
- memcpy(key_, key_ty, sizeof(key));
- memcpy(value_, value_ty, sizeof(value));
- }
-
- /**
- ** Destructor to free the key struct, value structure
- **/
- ~CacheElementUtil() {
- delete key_;
- delete value_;
- }
-
-
- /**
- ** This method returns the Keytype given the key struct
- ** @param [out] - key_Type
- **/
- unc_key_type_t get_type() {
- pfc_log_debug("In function %s..", PFC_FUNCNAME);
- return ConfUtil::get_key_type(*key_);
- }
-
- /**
- ** This method returns the search Key given the key struct
- ** @param [out] - search key - string
- **/
- std::string get_key() {
- pfc_log_debug("In %s function ", PFC_FUNCNAME);
- return ConfUtil::get_search_key(*key_);
- }
-
- /**
- ** This method returns the parent Key given the key struct
- ** @param [out] - parent key - string
- **/
- std::string get_parent_key() {
- pfc_log_debug("In %s function ", PFC_FUNCNAME);
- return ConfUtil::get_parent_key(*key_);
- }
+namespace vtndrvcache {
+template<typename key, typename value, typename op>
+class CacheElementUtil: public ConfigNode {
+ private:
+ key* key_;
+ value* value_;
+ op operation;
+
+ public:
+ /**
+ * @brief : Constructor to set the key struct, value structure & operation
+ */
+ CacheElementUtil(key* key_ty, value* value_ty, op opet):
+ operation(opet) {
+ key_ = new key();
+ PFC_ASSERT(key_ != NULL);
+ value_ = new value();
+ PFC_ASSERT(value_ != NULL);
+
+ memcpy(key_, key_ty, sizeof(key));
+ memcpy(value_, value_ty, sizeof(value));
+ pfc_log_debug("In constructor %s..", PFC_FUNCNAME);
+ }
+
+ /**
+ * @brief : Destructor to free the key struct, value structure
+ */
+ ~CacheElementUtil() {
+ pfc_log_debug("In destructor %s..", PFC_FUNCNAME);
+ if (key_ != NULL)
+ delete key_;
+
+ if (value_ != NULL)
+ delete value_;
+ }
- /**
- ** This method returns the key struct
- ** @param [out] - key*
- **/
- key* getkey() {
- pfc_log_debug("In %s function ", PFC_FUNCNAME);
- return key_;
- }
+ /**
+ * @brief : This method returns the Keytype given the key struct
+ * @retval : key_Type
+ */
+ unc_key_type_t get_type() {
+ pfc_log_debug("In function %s..", PFC_FUNCNAME);
+ if (key_ != NULL) {
+ return ConfUtil::get_key_type(*key_);
+ }
+ return UNC_KT_INVALID;
+ }
- /**
- ** This method returns the value struct
- ** @param [out] - key*
- **/
- value* getval() {
- pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
- return value_;
- }
+ /**
+ * @brief : This method returns the search Key given the key struct
+ * @retval : string
+ */
+ std::string get_key() {
+ pfc_log_debug("In %s function ", PFC_FUNCNAME);
+ if (key_ != NULL) {
+ return ConfUtil::get_search_key(*key_);
+ }
+ return "";
+ }
- /**
- ** This method returns the operation
- ** @param [out] - cache_oper
- **/
- cache_oper get_operation() {
- pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
- return operation;
- }
- };
+ /**
+ * @brief : This method returns the parent Key given the key struct
+ * @retval : string
+ */
+ std::string get_parent_key() {
+ pfc_log_debug("In %s function ", PFC_FUNCNAME);
+ if (key_ != NULL) {
+ return ConfUtil::get_parent_key(*key_);
+ }
+ return "";
}
-}
+ /**
+ * @brief : This method returns the key struct
+ * @retval : key*
+ */
+ key* getkey() {
+ pfc_log_debug("In %s function ", PFC_FUNCNAME);
+ return key_;
+ }
+ /**
+ * @brief : This method returns the value struct
+ * @retval : key*
+ */
+ value* getval() {
+ pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
+ return value_;
+ }
+ /**
+ * @brief : This method returns the operation
+ * @retval : operation
+ */
+ op get_operation() {
+ pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
+ return operation;
+ }
+};
+} // namespace vtndrvcache
+} // namespace unc
#endif
#ifndef __VTN_CONF_UTILTY_HH__
#define __VTN_CONF_UTILTY_HH__
-#include <string>
#include <pfc/ipc_struct.h>
#include <unc/keytype.h>
+#include <string>
namespace unc {
- namespace vtndrvcache {
- class ConfUtil {
- public:
- /**
- ** This method returns the Keytype for UNC_KT_VTN
- ** @param [out] - key_Type
- **/
- static unc_key_type_t get_key_type(key_vtn_t& key) {
- pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
- pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
- return UNC_KT_VTN;
- }
-
- /**
- ** This method returns the search Key for UNC_KT_VTN
- ** @param [out] - search key - string
- **/
- static std::string get_search_key(key_vtn_t& key) {
- pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
- std::string key_str(reinterpret_cast<const char*>(key.vtn_name));
- pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
- return key_str;
- }
-
- /**
- ** This method returns the parent Key for UNC_KT_VTN
- ** @param [out] - parent key - string
- **/
- static std::string get_parent_key(key_vtn_t& key) {
- pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
- pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
- return "ROOT";
- }
-
- /**
- ** This method returns the Keytype for UNC_KT_VBRIDGE
- ** @param [out] - key_Type
- **/
- static unc_key_type_t get_key_type(key_vbr_t& key) {
- pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
- pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
- return UNC_KT_VBRIDGE;
- }
+namespace vtndrvcache {
+class ConfUtil {
+ public:
+ /**
+ * @brief : This method returns the Keytype for UNC_KT_VTN
+ * @param [in] : key
+ * @retval : unc_key_type_t
+ */
+ static unc_key_type_t get_key_type(const key_vtn_t& key) {
+ pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
+ pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
+ return UNC_KT_VTN;
+ }
- /**
- ** This method returns the search Key for UNC_KT_VBRIDGE
- ** @param [out] - search key - string
- **/
- static std::string get_search_key(key_vbr_t& key) {
- pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
- std::string key_str(reinterpret_cast<const char*>
- (key.vtn_key.vtn_name));
- key_str += std::string(reinterpret_cast<const char*>
- (key.vbridge_name));
- pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
- return key_str;
- }
- /**
- ** This method returns the parent Key for UNC_KT_VBRIDGE
- ** @param [out] - parent key - string
- **/
+ /**
+ * @brief : This method returns the search Key for UNC_KT_VTN
+ * @param [in] : key
+ * @retval : string
+ */
+ static std::string get_search_key(const key_vtn_t& key) {
+ pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
+ std::string key_str(reinterpret_cast<const char*>(&key.vtn_name));
+ pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
+ return key_str;
+ }
- static std::string get_parent_key(key_vbr_t& key) {
- pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
- pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
- return std::string(reinterpret_cast<const char*>
- (key.vtn_key.vtn_name));
- }
+ /**
+ * @brief : This method returns the parent Key for UNC_KT_VTN
+ * @param [in] : key
+ * @retval : string
+ */
+ static std::string get_parent_key(const key_vtn_t& key) {
+ pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
+ pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
+ return "ROOT";
+ }
- /**
- ** This method returns the Keytype for UNC_KT_VBR_IF
- ** @param [out] - key_Type
- **/
- static unc_key_type_t get_key_type(key_vbr_if_t& key) {
- pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
- pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
- return UNC_KT_VBR_IF;
- }
+ /**
+ * @brief : This method returns the Keytype for UNC_KT_VBRIDGE
+ * @param [in] : key
+ * @retval : unc_key_type_t
+ */
+ static unc_key_type_t get_key_type(const key_vbr_t& key) {
+ pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
+ pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
+ return UNC_KT_VBRIDGE;
+ }
- /**
- ** This method returns the search Key for UNC_KT_VBR_IF
- ** @param [out] - search key - string
- **/
- static std::string get_search_key(key_vbr_if_t& key) {
- pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
- std::string key_str(reinterpret_cast<const char*>
- (key.vbr_key.vtn_key.vtn_name));
- key_str += std::string(reinterpret_cast<const char*>
- (key.vbr_key.vbridge_name));
- key_str += std::string(reinterpret_cast<const char*>(key.if_name));
- pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
- return key_str;
- }
+ /**
+ * @brief : This method returns the search Key for UNC_KT_VBRIDGE
+ * @param [in] : key
+ * @retval : string
+ **/
+ static std::string get_search_key(const key_vbr_t& key) {
+ pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
+ std::string key_str(reinterpret_cast<const char*>
+ (key.vtn_key.vtn_name));
+ key_str += std::string(reinterpret_cast<const char*>
+ (key.vbridge_name));
+ pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
+ return key_str;
+ }
+ /**
+ * @brief : This method returns the parent Key for UNC_KT_VBRIDGE
+ * @param [in] : key
+ * @retval : string
+ */
+ static std::string get_parent_key(const key_vbr_t& key) {
+ pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
+ std::string key_str = reinterpret_cast<const char*>
+ (key.vtn_key.vtn_name);
+ pfc_log_debug("Exiting Function %s.. vbr parentkey: %s", PFC_FUNCNAME,
+ key_str.c_str());
+ return key_str;
+ }
- /**
- ** This method returns the parent Key for UNC_KT_VBR_IF
- ** @param [out] - parent key - string
- **/
- static std::string get_parent_key(key_vbr_if_t& key) {
- pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
- std::string key_str(reinterpret_cast<const char*>
- (key.vbr_key.vtn_key.vtn_name));
- key_str += std::string(reinterpret_cast<const char*>
- (key.vbr_key.vbridge_name));
- pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
- return key_str;
- }
- };
+ /**
+ * @brief : This method returns the Keytype for UNC_KT_VBR_IF
+ * @param [in] : key
+ * @retval : unc_key_type_t
+ */
+ static unc_key_type_t get_key_type(const key_vbr_if_t& key) {
+ pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
+ pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
+ return UNC_KT_VBR_IF;
}
-}
+ /**
+ * @brief : This method returns the search Key for UNC_KT_VBR_IF
+ * @param [in] : key
+ * @retval : search key - string
+ */
+ static std::string get_search_key(const key_vbr_if_t& key) {
+ pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
+ std::string key_str(reinterpret_cast<const char*>
+ (key.vbr_key.vtn_key.vtn_name));
+ key_str += std::string(reinterpret_cast<const char*>
+ (key.vbr_key.vbridge_name));
+ key_str += std::string(reinterpret_cast<const char*>(key.if_name));
+ pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
+ return key_str;
+ }
+ /**
+ * @brief : This method returns the parent Key for UNC_KT_VBR_IF
+ * @param [in] : key
+ * @retval : parent key - string
+ */
+ static std::string get_parent_key(const key_vbr_if_t& key) {
+ pfc_log_debug("Entering function %s..", PFC_FUNCNAME);
+ std::string key_str(reinterpret_cast<const char*>
+ (key.vbr_key.vtn_key.vtn_name));
+ key_str += std::string(reinterpret_cast<const char*>
+ (key.vbr_key.vbridge_name));
+ pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
+ return key_str;
+ }
+};
+} // namespace vtndrvcache
+} // namespace unc
#endif
* terms of the Eclipse Public License v1.0 which accompanies this
* distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-#include "include/keytree.hh"
+
+#include "keytree.hh"
#include "unc/keytype.h"
#define TREE_TABLE_SIZE 5
namespace vtndrvcache {
/**
- ** Method to create Cache and return the pointer to it
- ** @param [out] - KeyTree*
- **/
+ * @brief : Method to create Cache and return the pointer to it
+ * @retval : KeyTree*
+ */
KeyTree* KeyTree::create_cache() {
return new KeyTree();
}
/**
- ** Method to clear the elements of audit cache
- ** @param [in] - None
- ** @param [out] - None
- **/
+ * @brief : Method to get Iterator for iterating each element from tree
+ * @retval : CommonIterator*
+ */
CommonIterator* KeyTree::get_iterator() {
return new CommonIterator(this);
}
+/**
+ * @brief : Keytree constructor
+ */
+KeyTree::KeyTree() {
+ pfc_log_debug("%s: Entering keytree constructor....", PFC_FUNCNAME);
+ configHashArr[0].insert(std::pair <std::string, ConfigNode*>
+ ("ROOT", &node_tree_));
+ pfc_log_debug("%s: Exiting keytree constructor....", PFC_FUNCNAME);
+}
+
+/**
+ * @brief : Keytree destructor
+ */
+KeyTree::~KeyTree() {
+ pfc_log_debug("%s: Entering keytree destructor....", PFC_FUNCNAME);
+ clear_commit_cache();
+ clear_audit_cache();
+ pfc_log_debug("%s: Exiting keytree destructor....", PFC_FUNCNAME);
+}
+
+/**
+ * @brief : Constructing parent/child relation for supported KT
+ */
key_tree key_tree_table[TREE_TABLE_SIZE] = {
{ UNC_KT_CONTROLLER, UNC_KT_ROOT, 0 },
{ UNC_KT_VTN, UNC_KT_ROOT, 3 },
};
/**
- ** Method to return the Keytype of Parent given the search Key
- ** @param [in] - search_type
- ** @param [out] - unc_key_type_t
- **/
+ * @brief : Method to return the Keytype of Parent given the search Key
+ * @param [in] : search_type
+ * @retval : unc_key_type_t
+ */
unc_key_type_t KeyTree::get_parenttype(unc_key_type_t search_type) {
pfc_log_debug("Entering %s function", PFC_FUNCNAME);
int table_size = sizeof(key_tree_table) / sizeof(key_tree);
}
/**
- ** Method to traverse the tree and populate the nodes into
- ** the vector
- ** @param [in] - ctrlid
- ** @param [in] - value_list
- ** @param [out] - TREE_OK
- **/
+ * @brief : Method to traverse the tree and populate the nodes into
+ * the vector
+ * @param [in] : value_list
+ * @retval : uint32_t
+ */
uint32_t KeyTree::get_nodelist_keytree(
std::vector<ConfigNode*>&value_list) {
pfc_log_debug("Entering %s function", PFC_FUNCNAME);
- return node_tree.get_node_list(value_list);
+ return node_tree_.get_node_list(value_list);
}
/**
- ** Method to add confignode to the cache for commit
- ** @param [in] - value_list
- ** @param [out] - TREE_OK
- **/
+ * @brief : Method to add confignode to the cache for commit
+ * @param [in] : value_list
+ * @retval : CACHEMGR_RESPONSE_SUCCESS/CACHEMGR_RESPONSE_FAILURE
+ */
uint32_t KeyTree::append_commit_node(ConfigNode* value_list) {
pfc_log_debug("Entering %s function", PFC_FUNCNAME);
- int err = 0;
- cfg_node_list.push_back(value_list);
+ int err = CACHEMGR_RESPONSE_SUCCESS;
+ cfg_node_list_.push_back(value_list);
err = add_child_to_hash(value_list);
if ( TREE_OK != err ) {
pfc_log_error("add_node_to_tree:add_child_to_hash Faild for: %s!!!!",
value_list->get_key().c_str());
- return PFCDRVAPI_RESPONSE_FAILURE;
+ return CACHEMGR_RESPONSE_FAILURE;
}
return CACHEMGR_RESPONSE_SUCCESS;
}
/**
- ** Method to clear the elements of commit cache
- ** @param [in] - None
- ** @param [out] - None
- **/
+ * @brief : Method to clear the elements of commit cache
+ */
void KeyTree::clear_commit_cache() {
+ pfc_log_debug("%s: Entering Function....", PFC_FUNCNAME);
clear_search_cache();
clear_cache_vector();
+ pfc_log_debug("%s: Exiting Function....", PFC_FUNCNAME);
}
/**
- ** Method to clear the elements of vector
- ** @param [in] - None
- ** @param [out] - None
- **/
+ * @brief : Method to clear the elements of vector using for commit cache
+ */
void KeyTree::clear_cache_vector() {
- vector<ConfigNode*>::const_iterator itr = cfg_node_list.begin();
- vector<ConfigNode*>::const_iterator itr_end = cfg_node_list.end();
+ pfc_log_debug("%s: Entering Function....", PFC_FUNCNAME);
+ if (!cfg_node_list_.empty()) {
+ std::vector<ConfigNode*>::iterator itr = cfg_node_list_.begin();
+ std::vector<ConfigNode*>::iterator itr_end = cfg_node_list_.end();
for (; itr != itr_end; ++itr) {
if (*itr != NULL) {
delete *itr;
+ *itr = NULL;
}
}
- cfg_node_list.clear();
+ cfg_node_list_.clear();
+ }
+ pfc_log_debug("%s: Exiting Function....", PFC_FUNCNAME);
}
/**
- ** Method to clear the elements of search map
- ** @param [in] - None
- ** @param [out] - None
- **/
+ * @brief : Method to clear the elements of search map
+ */
void KeyTree::clear_search_cache() {
- for ( int i =0; i < CONFIGARR_SIZE; i++ ) {
- configHashArr[i].clear();
+ pfc_log_debug("%s: Entering Function....", PFC_FUNCNAME);
+ for (uint32_t Configarray = 0; Configarray < CONFIGARR_SIZE; Configarray++) {
+ configHashArr[Configarray].clear();
}
+ pfc_log_debug("%s: Exiting Function....", PFC_FUNCNAME);
}
/**
- ** Method to clear the elements of audit cache
- ** @param [in] - None
- ** @param [out] - None
- **/
-void KeyTree::clear_audit_cache() {
+ * @brief : Method to clear the elements of audit cache
+ * @retval : CACHEMGR_RESPONSE_SUCCESS
+ */
+uint32_t KeyTree::clear_audit_cache() {
clear_search_cache();
- node_tree.clear_kt_map();
-}
-
-uint32_t KeyTree::read_all_cfgnode(unc_key_type_t key,
- std::vector<ConfigNode*>& vec) {
- return node_tree.read_all_cfgnode(key, vec);
+ pfc_log_debug("%s: Entering Function....", PFC_FUNCNAME);
+ if (!cfg_node_list_.empty()) {
+ std::vector<ConfigNode*>::iterator itr = cfg_node_list_.begin();
+ std::vector<ConfigNode*>::iterator itr_end = cfg_node_list_.end();
+ for (; itr != itr_end; ++itr) {
+ if (*itr != NULL) {
+ delete *itr;
+ *itr = NULL;
+ }
+ }
+ cfg_node_list_.clear();
+ }
+ pfc_log_debug("%s: Exiting Function....", PFC_FUNCNAME);
+ return CACHEMGR_RESPONSE_SUCCESS;
}
/**
- ** Method to add confignode to the cache for Audit
- ** @param [in] - value_list
- ** @param [out] - TREE_OK
- **/
+ * @brief : Method to add confignode to the cache for Audit
+ * @param [in] : value_list
+ * @retval : ERR_ADD_CHILD_TO_TREE_FAILED / TREE_OK
+ */
uint32_t KeyTree::append_audit_node(
const std::vector<ConfigNode*>&value_list) {
- pfc_log_info("%s: Entering function", PFC_FUNCNAME);
- uint32_t err = -1;
+ pfc_log_debug("%s: Entering function", PFC_FUNCNAME);
+ uint32_t err = CACHEMGR_APPEND_NODE_FAIL;
ConfigNode* tmp_cfgnode_ptr = NULL;
ConfigNode* real_cfgnode_ptr= NULL;
- vector<ConfigNode*>::const_iterator it = value_list.begin();
- vector<ConfigNode*>::const_iterator itr_end = value_list.end();
+ std::vector<ConfigNode*>::const_iterator it = value_list.begin();
+ std::vector<ConfigNode*>::const_iterator itr_end = value_list.end();
+ // Iterate the vector of config nodes
for (; it!= value_list.end(); it++) {
if (*it == NULL) {
pfc_log_error("RunningConfig::%s:%d: ConfigNode is NULL",
}
tmp_cfgnode_ptr = *it;
+ pfc_log_debug("ConfigNode is valid");
unc_key_type_t key_Type = tmp_cfgnode_ptr->get_type();
+ pfc_log_debug("key_Type:%u", key_Type);
std::string key = tmp_cfgnode_ptr->get_key();
+ pfc_log_debug("key:%s", key.c_str());
if (PFC_TRUE != is_already_present(key, key_Type)) {
- pfc_log_trace("%s: Node Not Present in Tree..for:%s", PFC_FUNCNAME,
- key.c_str());
+ pfc_log_debug("%s: Node Not Present in Tree..for:%s keytype %d",
+ PFC_FUNCNAME, key.c_str(), key_Type);
+ pfc_log_debug("%s: Parent Type Check %s ", PFC_FUNCNAME,
+ tmp_cfgnode_ptr->get_parent_key().c_str());
err = add_node_to_tree(tmp_cfgnode_ptr);
if (TREE_OK != err) {
pfc_log_error("%s: AddChildToTree faild err=%d", PFC_FUNCNAME, err);
tmp_cfgnode_ptr = NULL;
- return ERR_ADD_CHILD_TO_TREE_FAILD;
+ return ERR_ADD_CHILD_TO_TREE_FAILED;
}
real_cfgnode_ptr = tmp_cfgnode_ptr;
} else {
- pfc_log_trace("%s: Node already Present in Tree...", PFC_FUNCNAME);
+ pfc_log_debug("%s: Node already Present in Tree...", PFC_FUNCNAME);
real_cfgnode_ptr = get_node_from_hash(key, key_Type);
delete tmp_cfgnode_ptr;
tmp_cfgnode_ptr = NULL;
}
}
}
- pfc_log_info("%s: Exiting function", PFC_FUNCNAME);
+ pfc_log_debug("%s: Exiting function", PFC_FUNCNAME);
return TREE_OK;
}
/**
- ** Method to add confignode to the cache for Audit
- ** @param [in] - value_list
- ** @param [out] - TREE_OK
- **/
+ * @brief : Method to add confignode to the cache for Audit
+ * @param [in] : value_list
+ * @retval : CACHEMGR_APPEND_NODE_FAIL / ERR_ADD_CHILD_TO_TREE_FAILED
+ * /TREE_OK
+ */
uint32_t KeyTree::append_audit_node(
ConfigNode* value_list) {
- pfc_log_info("%s: Entering function", PFC_FUNCNAME);
- uint32_t err = -1;
+ pfc_log_debug("%s: Entering function", PFC_FUNCNAME);
+ uint32_t err = CACHEMGR_APPEND_NODE_FAIL;
ConfigNode* tmp_cfgnode_ptr = NULL;
ConfigNode* real_cfgnode_ptr= NULL;
unc_key_type_t key_Type = tmp_cfgnode_ptr->get_type();
std::string key = tmp_cfgnode_ptr->get_key();
if (PFC_TRUE != is_already_present(key, key_Type)) {
- pfc_log_trace("%s: Node Not Present in Tree..for:%s", PFC_FUNCNAME,
- key.c_str());
+ pfc_log_debug("%s: Node Not Present in Tree..for:%s keytype %d",
+ PFC_FUNCNAME, key.c_str(), key_Type);
+ pfc_log_debug("%s: Parent Type Check %s ", PFC_FUNCNAME,
+ tmp_cfgnode_ptr->get_parent_key().c_str());
err = add_node_to_tree(tmp_cfgnode_ptr);
if (TREE_OK != err) {
pfc_log_error("%s: AddChildToTree faild err=%d", PFC_FUNCNAME, err);
tmp_cfgnode_ptr = NULL;
- return ERR_ADD_CHILD_TO_TREE_FAILD;
+ return ERR_ADD_CHILD_TO_TREE_FAILED;
}
real_cfgnode_ptr = tmp_cfgnode_ptr;
} else {
- pfc_log_trace("%s: Node already Present in Tree...", PFC_FUNCNAME);
+ pfc_log_debug("%s: Node already Present in Tree...", PFC_FUNCNAME);
real_cfgnode_ptr = get_node_from_hash(key, key_Type);
delete tmp_cfgnode_ptr;
tmp_cfgnode_ptr = NULL;
}
}
- pfc_log_info("%s: Exiting function", PFC_FUNCNAME);
+ pfc_log_debug("%s: Exiting function", PFC_FUNCNAME);
return TREE_OK;
}
/**
- ** Method to validate if parent exists for this particular node
- ** @param [in] - value_list
- ** @param [out] - true/false
- **/
+ * @brief : Method to validate if parent exists for this particular node
+ * @param [in] : value_list
+ * @retval : true/false
+ */
bool KeyTree:: validate_parentkey(ConfigNode* value_list) {
pfc_log_debug("%s: Entering function", PFC_FUNCNAME);
unc_key_type_t parent_type = get_parenttype(value_list->get_type());
}
/**
- ** Method to add node to the cache and search map by validation
- ** @param [in] - value_list
- ** @param [out] - TREE_OK/PFCDRVAPI_RESPONSE_FAILURE
- **/
+ * @brief : Method to add node to the cache and search map by validation
+ * @param [in] : value_list
+ * @retval : TREE_OK/CACHEMGR_RESPONSE_FAILURE
+ */
uint32_t KeyTree::add_node_to_tree(ConfigNode* child_ptr) {
pfc_log_debug("%s: Entering function", PFC_FUNCNAME);
if (NULL == child_ptr) {
pfc_log_fatal("add_node_to_tree:Child Node is NULL!!!!!!");
- return PFCDRVAPI_RESPONSE_FAILURE;
+ return CACHEMGR_RESPONSE_FAILURE;
}
std::string parent_key = child_ptr->get_parent_key();
unc_key_type_t parent_type = get_parenttype(child_ptr->get_type());
+
+ // Retrieve the parent from the map using parent_key & parent_type
ConfigNode* parent_ptr = get_node_from_hash(parent_key, parent_type);
if (NULL == parent_ptr) {
pfc_log_fatal("Parent:%s Not Present for:%s", parent_key.c_str(),
child_ptr->get_key().c_str());
- return PFCDRVAPI_RESPONSE_FAILURE;
+ return CACHEMGR_RESPONSE_FAILURE;
}
+ // Add the new node to child list of the parentnode using parent_ptr
uint32_t err = parent_ptr->add_child_to_list(child_ptr);
if ( TREE_OK != err ) {
pfc_log_fatal("add_node_to_tree:add_child_to_list Faild for:%s!!!!",
child_ptr->get_key().c_str());
- return PFCDRVAPI_RESPONSE_FAILURE;
+ return CACHEMGR_RESPONSE_FAILURE;
}
+ // Add the new node to the search map
err = add_child_to_hash(child_ptr);
if ( TREE_OK != err ) {
pfc_log_error("add_node_to_tree:add_child_to_hash Faild for: %s!!!!",
child_ptr->get_key().c_str());
- return PFCDRVAPI_RESPONSE_FAILURE;
+ return CACHEMGR_RESPONSE_FAILURE;
}
pfc_log_debug("%s: Exiting function", PFC_FUNCNAME);
return TREE_OK;
}
/**
- ** Method to search and retrieve the node from the search map
- ** @param [in] - key
- ** @param [in] - key_Type
- ** @param [out] - ConfigNode*
- **/
+ * @brief : Method to search and retrieve the node from the search map
+ * @param [in] : key
+ * @param [in] : key_Type
+ * @retval : ConfigNode*
+ */
ConfigNode* KeyTree::get_node_from_hash(
std::string key, unc_key_type_t key_Type) {
pfc_log_debug("%s: Entering function", PFC_FUNCNAME);
pfc_log_debug("Node Not Present for:%s", key.c_str());
return NULL;
}
- pfc_log_trace("Node Present for:%s", key.c_str());
+ pfc_log_debug("Node Present for:%s", key.c_str());
pfc_log_debug("%s: Exiting function", PFC_FUNCNAME);
return itr->second;
}
/**
- ** Method to insert node to the search map
- ** @param [in] - child_ptr
- ** @param [out] - TREE_OK
- **/
+ * @brief : Method to insert node to the search map
+ * @param [in] : child_ptr
+ * @retval : TREE_OK
+ */
uint32_t KeyTree::add_child_to_hash(ConfigNode* child_ptr) {
pfc_log_debug("%s: Entering function", PFC_FUNCNAME);
unc_key_type_t key_type = child_ptr->get_type();
std::string key = child_ptr->get_key();
- configHashArr[key_type].insert(pair <std::string,
+ configHashArr[key_type].insert(std::pair <std::string,
ConfigNode*>(key, child_ptr));
pfc_log_debug("%s: Exiting function", PFC_FUNCNAME);
return TREE_OK;
}
/**
- ** Method to check if the particular key is already present in search map
- ** @param [in] - key
- ** @param [in] - key_Type
- ** @param [out] - true/false
- **/
+ * @brief : Method to check if the particular key is already present in search map
+ * @param [in] : key
+ * @param [in] : key_Type
+ * @retval : true/false
+ */
bool KeyTree::is_already_present(std::string key, unc_key_type_t key_Type) {
pfc_log_debug("%s: Entering function", PFC_FUNCNAME);
configNodeHash::iterator itr;
itr = configHashArr[key_Type].find(key);
if (itr == configHashArr[key_Type].end()) {
- pfc_log_trace("Node Not Present for: %s", key.c_str());
+ pfc_log_debug("Node Not Present for: %s", key.c_str());
return false;
}
- pfc_log_trace("Node Present for: %s", key.c_str());
+ pfc_log_debug("Node Present for: %s", key.c_str());
pfc_log_debug("%s: Exiting function", PFC_FUNCNAME);
return true;
}
-}
-}
+} // namespace vtndrvcache
+} // namespace unc
class vtndrvcachemod: public pfc::core::Module {
public:
+ /**
+ ** @brief : vtndrvcachemod Constructor
+ **/
explicit vtndrvcachemod(const pfc_modattr_t *mattr):
- pfc::core::Module(mattr) {
- }
+ /**
+ ** @brief : Call Module constructor
+ **/
+ pfc::core::Module(mattr) { }
+
+ /**
+ ** @brief : Call init function to initialize module
+ **/
pfc_bool_t init() {
return PFC_TRUE;
}
+ /**
+ ** @brief : Call fini function to release module
+ **/
pfc_bool_t fini() {
return PFC_TRUE;
}
};
-}
-}
-
+} // namespace vtndrvcache
+} // namespace unc
PFC_MODULE_IPC_DECL(unc::vtndrvcache::vtndrvcachemod, 0);
/**
- * @brief : default constructor
+ * @brief : constructor
*/
- ControllerFramework::ControllerFramework() {
+ ControllerFramework::ControllerFramework(pfc::core::TaskQueue* taskq_c) {
pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
+ taskq_ = taskq_c;
+ pfc_log_debug("taskq created");
pfc_log_debug("%s: Exiting function..", PFC_FUNCNAME);
}
/**
- * @brief : default destructor
+ * @brief : destructor
*/
ControllerFramework::~ControllerFramework() {
pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
}
/**
- * AddController:
+ * @brief : constructor of ReadParams
+ */
+ ReadParams::ReadParams(std::string ctr_name,
+ unc::driver::ControllerFramework* fw_obj)
+ :ctlr_name_(ctr_name),
+ ctr_fw_(fw_obj) {}
+
+ /**
* @brief : Adding new controller with controller information in
- * a map
+ * a map and also checks that ping is needed for the
+ * particular controller or not
* @param[in] : controller name , controller*, driver*
* @retval : None
- */
- void ControllerFramework::AddController(
+ **/
+ void ControllerFramework::AddController(
std::string& controller_name,
controller* controller_instance, driver* driver_instance) {
pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
+ PFC_ASSERT(driver_instance != NULL);
+ PFC_ASSERT(controller_instance != NULL);
+
ControllerContainer *controller_container = new ControllerContainer();
controller_container->ctr = controller_instance;
controller_container->drv = driver_instance;
controller_list_rwlock_.wrlock();
controller_list.insert(std::make_pair(controller_name,
controller_container));
- pfc_log_info("controller added successfully");
+ pfc_log_debug("controller added successfully");
controller_list_rwlock_.unlock();
+
+ pfc_bool_t ping_needed = driver_instance->is_ping_needed();
+
+ if (ping_needed == PFC_TRUE) {
+ controller_instance->timed_ = pfc::core::Timer::create(
+ taskq_->getId());
+ PostTimer(controller_name, driver_instance, controller_instance);
+ } else {
+ pfc_log_debug("Ping not needed for the controller %s",
+ controller_name.c_str());
+ }
+ pfc_log_debug("%s: Exiting function..", PFC_FUNCNAME);
+ }
+
+ /**
+ * @brief : The time interval for every ping is set and the
+ * timer is get reset.
+ * @param[in] : controller name , driver*
+ * @retval : int
+ */
+
+ int ControllerFramework::PostTimer(std::string& controller_name,
+ driver* driver_instance,
+ controller* controller_instance) {
+ pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
+ int ret = 0;
+ pfc_timespec_t timeout;
+ pfc_timeout_t time_out_id;
+
+ uint32_t time_out = driver_instance->get_ping_interval();
+
+ if (time_out == 0) {
+ pfc_log_debug("Ping interval is 0");
+ return ret;
+ } else {
+ ReadParams fun_obj(controller_name, this);
+ pfc::core::timer_func_t timer_func(fun_obj);
+
+ timeout.tv_sec = time_out;
+ timeout.tv_nsec = 0;
+ pfc::core::Timer* timer = controller_instance->timed_;
+ ret = timer->post(&timeout, timer_func, &time_out_id);
+
+ if (ret != 0) {
+ pfc_log_fatal("Failed to post() for ping operation");
+ }
+ pfc_log_debug("Timer successfully posted");
+ }
+
pfc_log_debug("%s: Exiting function..", PFC_FUNCNAME);
+ return ret;
}
/**
- * UpdateControllerConfiguration:
+ * @brief : Ping the controller and update the connection status
+ * based on the response
+ * @param[in] : None
+ * @retval : VTN_DRV_RET_FAILURE / VTN_DRV_RET_SUCCESS
+ */
+
+ VtnDrvRetEnum ReadParams::PingController() {
+ pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
+ unc::driver::driver* drv_instance = NULL;
+ unc::driver::controller* ctr_instance = NULL;
+
+ ctr_fw_->GetDriverByControllerName(ctlr_name_, &ctr_instance,
+ &drv_instance);
+
+ if (drv_instance == NULL || ctr_instance == NULL) {
+ pfc_log_error("Driver instance not obtained");
+ return VTN_DRV_RET_FAILURE;
+ }
+
+ pfc_bool_t ping_status = drv_instance->ping_controller(ctr_instance);
+
+ if (ping_status == PFC_TRUE) {
+ ctr_instance->set_connection_status(CONNECTION_UP);
+ pfc_log_debug("Controller staus is UP ctlr_name: %s",
+ ctlr_name_.c_str());
+ } else {
+ ctr_instance->set_connection_status(CONNECTION_DOWN);
+ pfc_log_debug("Controller staus is DOWN ctlr_name:%s",
+ ctlr_name_.c_str());
+ }
+
+ ctr_fw_->PostTimer(ctlr_name_, drv_instance, ctr_instance);
+ pfc_log_debug("%s: Exiting function..", PFC_FUNCNAME);
+ return VTN_DRV_RET_SUCCESS;
+ }
+
+
+ /**
* @brief : Updating controler as per controller name,if controllername
- * not found from list,it's consider as new controller and add it to
- * list
+ * not found from list,it's consider as new controller and
+ * add it to list
* @param[in] : controller_name, controller*, driver*
- * @retval : None
+ * @retval : VTN_DRV_RET_FAILURE / VTN_DRV_RET_SUCCESS
*/
- void ControllerFramework::UpdateControllerConfiguration(
+ VtnDrvRetEnum ControllerFramework::UpdateControllerConfiguration(
std::string& controller_name,
controller* controller_instance, driver* driver_instance) {
pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
- //PFC_ASSERT(controller_connection != NULL);
std::map<std::string, ControllerContainer*>::iterator
controller_list_iterator = controller_list.begin();
- controller_list_rwlock_.wrlock();
+
+ PFC_ASSERT(controller_instance != NULL);
+ PFC_ASSERT(driver_instance != NULL);
+
ControllerContainer* controller_container(NULL);
controller_list_iterator = controller_list.find(controller_name);
+ pfc::core::ScopedMutex m(controller_list_iterator->second->rw_mutex);
+
+ pfc_bool_t ping_needed = driver_instance->is_ping_needed();
+
+ if (ping_needed == PFC_TRUE) {
+ controller_instance->timed_ = pfc::core::Timer::create(
+ taskq_->getId());
+ PostTimer(controller_name, driver_instance, controller_instance);
+ } else {
+ pfc_log_debug("%s Ping not needed for the controller %s",
+ PFC_FUNCNAME, controller_name.c_str());
+ }
+
if (controller_list_iterator != controller_list.end()) {
controller_container = controller_list_iterator->second;
PFC_ASSERT(controller_container != NULL);
delete controller_container->ctr;
- delete controller_container->drv;
-
- controller_list.erase(controller_list_iterator);
controller_container->ctr = controller_instance;
- controller_container->drv = driver_instance;
- controller_list.insert(std::make_pair(controller_name,
- controller_container));
- pfc_log_info("Controller updated successfully");
+ PFC_ASSERT(controller_container->ctr != NULL);
+
+ pfc_log_debug("Controller updated successfully");
} else {
- ControllerContainer* new_controller_container = new ControllerContainer();
+ ControllerContainer* new_controller_container = new
+ ControllerContainer();
+
pfc_log_trace("%s: Consider as a new controller to be add..",
PFC_FUNCNAME);
new_controller_container->ctr = controller_instance;
controller_list.insert(std::make_pair(controller_name,
new_controller_container));
- pfc_log_info("Controller added successfully");
+ pfc_log_debug("Controller added successfully");
}
- controller_list_rwlock_.unlock();
pfc_log_debug("%s: Exiting function..", PFC_FUNCNAME);
+ return VTN_DRV_RET_SUCCESS;
}
/**
- * RemoveControllerConfiguration:
* @brief : This function removes the existing controller from list
* @param[in] : controller_name
- * @retval : None
+ * @retval : VTN_DRV_RET_FAILURE / VTN_DRV_RET_SUCCESS
*/
VtnDrvRetEnum
ControllerFramework::RemoveControllerConfiguration(
- std::string& controller_name) {
+ std::string& controller_name,
+ controller* controller_instance,
+ driver* driver_instance) {
pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
+ PFC_ASSERT(controller_instance != NULL);
+ PFC_ASSERT(driver_instance != NULL);
+
std::map<std::string, ControllerContainer*>::iterator
controller_list_iterator = controller_list.begin();
+
if (controller_list.size() == 0) {
- pfc_log_info("Controller name not found .List is Empty");
+ pfc_log_error("Controller name not found .List is Empty");
return VTN_DRV_RET_FAILURE;
}
- controller_list_rwlock_.wrlock();
ControllerContainer* controller_container(NULL);
controller_list_iterator = controller_list.find(controller_name);
controller_container = controller_list_iterator->second;
PFC_ASSERT(controller_container != NULL);
- delete controller_container->ctr;
- delete controller_container->drv;
+ controller_container->rw_mutex.lock();
+
+ if (controller_instance->timed_) {
+ delete controller_instance->timed_;
+ controller_instance->timed_ = NULL;
+ }
+ driver_instance->delete_controller(controller_instance);
+ controller_container->rw_mutex.unlock();
+
+ controller_list_rwlock_.wrlock();
+ delete controller_container;
controller_list.erase(controller_list_iterator);
- pfc_log_info("Existing controller configuration gets removed");
+ controller_list_rwlock_.unlock();
+ pfc_log_debug("Existing controller configuration gets removed");
} else {
- pfc_log_debug("controller name not found");
+ pfc_log_error("controller not found");
return VTN_DRV_RET_FAILURE;
}
- controller_list_rwlock_.unlock();
pfc_log_debug("%s: Exiting function..", PFC_FUNCNAME);
return VTN_DRV_RET_SUCCESS;
}
/**
- * GetControllerConnectionByName:
+ * GetDriverByControllerName:
* @brief : This function gets the driver type for the appropriate
- * controllers
- * @param[in] : controller_name, controller*, driver*
- * @retval : driver*
+ * controllers
+ * @param[in] : controller_name, controller**, driver**
+ * @retval : VTN_DRV_RET_FAILURE / VTN_DRV_RET_SUCCESS
*/
VtnDrvRetEnum ControllerFramework::GetDriverByControllerName(
std::string& controller_name,
controller_list_iterator = controller_list.find(controller_name);
if (controller_list_iterator == controller_list.end()) {
- pfc_log_info("controller name not found");
+ pfc_log_error("controller name not found");
return VTN_DRV_RET_FAILURE;
}
controller_container = controller_list_iterator->second;
- *controller_instance = controller_container->ctr;
+ *controller_instance = controller_container->ctr;
*driver_instance = controller_container->drv;
- PFC_ASSERT(*controller_instance != NULL );
- PFC_ASSERT(*driver_instance != NULL );
+ if (*controller_instance == NULL || *driver_instance == NULL) {
+ pfc_log_error("controller instance or driver instance is NULL");
+ return VTN_DRV_RET_FAILURE;
+ }
pfc_log_debug("%s: Exiting function..", PFC_FUNCNAME);
return VTN_DRV_RET_SUCCESS;
}
- void ControllerFramework::RegisterDriver(
+
+ /**
+ * @brief : This function stores the driver instance for the appropriate
+ * controller type in map
+ * @param[in] : controller_type, driver*
+ * @retval : VTN_DRV_RET_FAILURE / VTN_DRV_RET_SUCCESS
+ */
+ VtnDrvRetEnum ControllerFramework::RegisterDriver(
unc_keytype_ctrtype_t controller_type,
driver* driver_instance) {
pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
- PFC_ASSERT(driver_instance != NULL);
+
+ if (driver_instance == NULL) {
+ pfc_log_error("RegisterDriver:Driver instance is NULL");
+ return VTN_DRV_RET_FAILURE;
+ }
controller_list_rwlock_.wrlock();
driver_container.insert(std::make_pair(controller_type, driver_instance));
controller_list_rwlock_.unlock();
- pfc_log_info("driver instance populated");
+ pfc_log_debug("driver instance populated");
pfc_log_debug("%s: Exiting function..", PFC_FUNCNAME);
+ return VTN_DRV_RET_SUCCESS;
}
+ /**
+ * @brief : This function gets the driver instance and ctl instance
+ * for the appropriate without acquiring the lock controllers
+ * @param[in] : controller_name, controller*, driver*
+ * @param[out]: driver*
+ * @retval : VTN_DRV_RET_FAILURE / VTN_DRV_RET_SUCCESS
+ */
+ VtnDrvRetEnum ControllerFramework::GetControllerInstance(
+ std::string& controller_name,
+ controller** controller_instance,
+ driver** driver_instance) {
+ pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
+
+ ControllerContainer* controller_container(NULL);
+ std::map<std::string, ControllerContainer*>::iterator
+ controller_list_iterator = controller_list.begin();
+ controller_list_iterator = controller_list.find(controller_name);
+
+ if (controller_list_iterator == controller_list.end()) {
+ pfc_log_error("Controller Name not found in the list");
+ return VTN_DRV_RET_FAILURE;
+ }
+
+ controller_container = controller_list_iterator->second;
+
+ *controller_instance = controller_container->ctr;
+ *driver_instance = controller_container->drv;
+ PFC_ASSERT(*controller_instance != NULL);
+ PFC_ASSERT(*driver_instance != NULL);
+
+ pfc_log_debug("%s: Exiting function..", PFC_FUNCNAME);
+ return VTN_DRV_RET_SUCCESS;
+ }
+
+ /**
+ * @brief : This function returns the driver instance for the appropriate
+ * controller type
+ * @param[in] : controller_type
+ * @retval : driver*
+ */
driver* ControllerFramework::GetDriverInstance(
unc_keytype_ctrtype_t controller_type) {
pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
return driver_container.find(controller_type)->second;
}
-
-
-} //driver
-} //unc
+} // namespace driver
+} // namespace unc
#include <vtndrvintf_defs.h>
#include <driver/driver_interface.hh>
#include <driver/controller_interface.hh>
-#include <map>
+#include <pfcxx/timer.hh>
+#include <pfcxx/task_queue.hh>
+#include <pfc/taskq.h>
+#include <pfc/thread.h>
+#include <pfcxx/synch.hh>
+#include <functional>
#include <iterator>
+#include <map>
#include <string>
-#include <pfcxx/synch.hh>
-
namespace unc {
namespace driver {
/**
- * @brief : This class contains the controller instance ,driver instance,
+ * @brief - This class contains the controller instance ,driver instance,
* mutex lock
- * @DataMembers : controller*, driver*, rw_mutex
+ * @DataMembers - controller*, driver*, rw_mutex
*/
class ControllerContainer {
public:
ControllerContainer():ctr(NULL), drv(NULL) {}
controller* ctr;
driver* drv;
- pfc::core::Mutex rw_mutex; // Global Mutex lock
+ pfc::core::Mutex rw_mutex;
};
+
/**
- * Class - ControllerFramework1
- * Base class
- * DataMembers : controller_list, driver_container, controller_list_rwlock
- * MemberFunctions : GetControllerConnectionByName,AddAndConfigureController
- * UpdateControllerConfiguration,RemoveControllerConfiguration.
- * GetDriverInstance, RegisterDriver, GetDriverByControllerName
- **/
+ * Class - ControllerFramework
+ * DataMembers - controller_list, driver_container, controller_list_rwlock
+ * MemberFunctions - GetControllerConnectionByName,AddAndConfigureController
+ * UpdateControllerConfiguration,RemoveControllerConfiguration.
+ * GetDriverInstance, RegisterDriver, GetDriverByControllerName
+ */
class ControllerFramework {
public:
+ pfc::core::TaskQueue* taskq_;
+
/**
- *@brief: constructor
- **/
+ * @brief - constructor
+ */
+ explicit ControllerFramework(pfc::core::TaskQueue*);
- ControllerFramework();
/**
- *@brief: destructor
- **/
+ * @brief - destructor
+ */
~ControllerFramework();
/**
- *@brief: This function is to get the driver type
- for the respective controllers
- **/
-
+ * @brief - Retrieves the driver type for the respective controllers
+ * @param[in] - controller name ,controller**, driver**
+ * @retval - VTN_DRV_RET_FAILURE/VTN_DRV_RET_SUCCESS
+ */
VtnDrvRetEnum GetDriverByControllerName(std::string& controller_name,
- controller**, driver**);
+ controller**, driver**);
/**
- *@brief: This function adds the respective controller information
- in the controller list
- **/
-
+ * @brief - This function adds the respective controller information
+ * in the controller list
+ * @param[in] - controller name, controller*, driver*
+ * @retval - None
+ */
void AddController(std::string& controller_name,
controller* , driver*);
/**
- *@brief: This function updates the respective controller information
- in the controller list
+ * @brief - This function sets the time interval for every ping and the
+ * timer is get reset.
+ * @param[in] - controller name, driver*, controller*
+ * @retval - int
*/
+ int PostTimer(std::string& controller_name, driver*, controller*);
- void UpdateControllerConfiguration(std::string& controller_name,
- controller*, driver*);
/**
- *@brief: This function removes the respective controller information
- in the controller list
- **/
- VtnDrvRetEnum RemoveControllerConfiguration(std::string& controller_name);
-
+ * @brief - This function updates the respective controller information
+ * in the controller list
+ * @param[in] - controller name, controller*, driver*
+ * @retval - VTN_DRV_RET_FAILURE/ VTN_DRV_RET_SUCCESS
+ */
+ VtnDrvRetEnum UpdateControllerConfiguration(std::string& controller_name,
+ controller*, driver*);
/**
- *@Brief: This function is to get driver typw
- **/
+ * @brief - This function removes the respective controller information
+ * in the controller list
+ * @param[in] - controller name, controller*, driver*
+ * @retval - VTN_DRV_RET_FAILURE/ VTN_DRV_RET_SUCCESS
+ */
+ VtnDrvRetEnum RemoveControllerConfiguration(std::string& controller_name,
+ controller*, driver*);
+ /**
+ * @brief - This function is to get driver type
+ * @param[in] - controller type
+ * @retval - driver*
+ */
driver* GetDriverInstance(unc_keytype_ctrtype_t controller_type);
/**
- *@Brief: This function is to register controller type and Driver*
- **/
+ * @brief - This function is to stores the controller type and Driver*
+ * @param[in] - controller type, driver*
+ * @retval - VTN_DRV_RET_FAILURE/ VTN_DRV_RET_SUCCESS
+ */
+ VtnDrvRetEnum RegisterDriver(unc_keytype_ctrtype_t controller_type, driver*);
+
+
+ /**
+ * @brief - This function is to get the driver instance and controller
+ * instance for the respective controllers
+ * @param[in] - controller name, controller**, driver**
+ * @retval - VTN_DRV_RET_FAILURE/ VTN_DRV_RET_SUCCESS
+ */
+ VtnDrvRetEnum GetControllerInstance(std::string& controller_name,
+ controller**, driver**);
- void RegisterDriver(unc_keytype_ctrtype_t controller_type, driver*);
+ private:
+ std::map<std::string, ControllerContainer*> controller_list;
+ std::map<unc_keytype_ctrtype_t, driver*> driver_container;
+ pfc::core::ReadWriteLock controller_list_rwlock_;
+};
- private:
- std::map<std::string, ControllerContainer*> controller_list;
- std::map<unc_keytype_ctrtype_t, driver*> driver_container;
- pfc::core::ReadWriteLock controller_list_rwlock_;
+/**
+ * Class - ReadParams
+ * DataMembers - ctlr_name_, ctr_fw_
+ * MemberFunctions - PingController()
+ */
+
+class ReadParams : public std::unary_function < void, void> {
+ public:
+ std::string ctlr_name_;
+ unc::driver::ControllerFramework* ctr_fw_;
+
+ /**
+ * @brief - constructor
+ */
+ ReadParams(std::string, unc::driver::ControllerFramework*);
+
+ /**
+ * @brief - This fuction calls the method PingController()
+ * @retval - None
+ */
+ void operator() () {
+ PingController();
+ }
+
+ /**
+ * @brief - Ping the controller and update the connection status
+ * based on the response
+ * @retval - VTN_DRV_RET_FAILURE/ VTN_DRV_RET_SUCCESS
+ */
+ VtnDrvRetEnum PingController();
};
-} //driver
-} //unc
+} // namespace driver
+} // namespace unc
#endif
+/*
+ * Copyright (c) 2012-2013 NEC Corporation
+ * All rights reserved.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
#ifndef __CONTROLLER_INTERFACE_HH__
#define __CONTROLLER_INTERFACE_HH__
#include <unc/keytype.h>
+#include <pfcxx/timer.hh>
#include <keytree.hh>
+#include <string>
+
+namespace unc {
+namespace driver {
+
+typedef enum {
+ CONNECTION_UP = 0,
+ CONNECTION_DOWN
+}ConnectionStatus;
-namespace unc{
-namespace driver{
class controller {
public:
- controller () :keytree_ptr(NULL) {}
+ /**
+ * @brief - Constructor of controller class
+ */
+ controller() :keytree_ptr(NULL),
+ timed_(NULL),
+ connection_status_(CONNECTION_DOWN) {}
+ /**
+ * @brief - Destructor of controller class
+ */
virtual ~controller() {}
- // Invoked to know the type of controller
- virtual unc_keytype_ctrtype_t get_controller_type()=0;
- // Invoked to learn if CDF needs to ping the controller
- // to check if alive
- virtual pfc_bool_t is_ping_needed ()=0;
- // Ping Interval
- virtual uint32_t get_ping_interval()=0;
- // Ping Fail Retry Count
- virtual uint32_t get_ping_fail_retry_count()=0;
- // Get the controller ID
- virtual std::string get_controller_id ()=0;
- // PING function for the controller
- virtual pfc_bool_t ping_controller ()=0;
- // Invoked on global commit failure
- virtual pfc_bool_t reset_connect ()=0;
- // Gets the host address
+
+ /**
+ * @brief - Method to get the type of controller
+ * @retval - unc_keytype_ctrtype_t Controller type
+ */
+ virtual unc_keytype_ctrtype_t get_controller_type() = 0;
+
+ /**
+ * @brief - Method to get the controller ID
+ * @retval - string - Controller ID
+ */
+ virtual std::string get_controller_id() = 0;
+
+ /**
+ * @brief - Method Invoked on global commit failure
+ * @retval - PFC_TRUE/PFC_FALSE
+ */
+ virtual pfc_bool_t reset_connect() = 0;
+
+ /**
+ * @brief - Method to get the host address
+ * @retval - string - hostaddress
+ */
virtual std::string get_host_address() = 0;
- // Invoked cache create element
+
+ /**
+ * @brief - Method to get the audit status
+ * @retval - PFC_TRUE/PFC_FALSE
+ */
+ virtual pfc_bool_t get_audit_status() = 0;
+
+ /**
+ * @brief - Method to get the user name
+ * @retval - string - username configured
+ */
+ virtual std::string get_user_name() = 0;
+
+ /**
+ * @brief - Method to get the password
+ * @retval - string - password configured
+ */
+ virtual std::string get_pass_word() = 0;
+
+ /**
+ * @brief - Method to return connection status of controller
+ * @retval - CONNECTION_UP/CONNECTION_DOWN
+ */
+ ConnectionStatus get_connection_status() {
+ return connection_status_;
+ }
+ /**
+ * @brief - Method to set connection status of controller
+ * @param[in] - ConnectionStatus - CONNECTION_UP/CONNECTION_DOWN
+ */
+ void set_connection_status(ConnectionStatus conn_status) {
+ connection_status_ = conn_status;
+ }
+
+ /**
+ * @brief - Keytree pointer to access cache manager
+ */
unc::vtndrvcache::KeyTree *keytree_ptr;
-};
-} // driver
-} // unc
+ /**
+ * @brief - Timer Instance
+ */
+ pfc::core::Timer* timed_;
+ private:
+ ConnectionStatus connection_status_;
+};
+} // namespace driver
+} // namespace unc
#endif
-/*\r
- * Copyright (c) 2012-2013 NEC Corporation\r
- * All rights reserved.\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies \r
- * this distribution, * and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-#ifndef __CDF_DRIVER_COMMANDS_HH__\r
-#define __CDF_DRIVER_COMMANDS_HH__\r
-\r
-#include <driver/controller_interface.hh>\r
-#include <pfc/ipc_struct.h>\r
-#include <unc/unc_base.h>\r
-\r
-namespace unc {\r
-namespace driver {\r
-\r
-/*\r
- * @desc:Base Class For Driver Commands\r
- */\r
-class driver_command {\r
-public:\r
- virtual ~driver_command() {\r
- }\r
- virtual unc_key_type_t get_key_type()=0;\r
-};\r
-\r
-/*\r
- * Class to be extended for VTN Commands\r
- */\r
-\r
-class vtn_driver_command: public driver_command {\r
-public:\r
- /* Create VTN in the controller*/\r
- virtual drv_resp_code_t create_cmd(key_vtn_t& keyvtn_, val_vtn_t& valvtn_,\r
- controller*)=0;\r
- /* Update VTN in the controller*/\r
- virtual drv_resp_code_t update_cmd(key_vtn_t& keyvtn_, val_vtn_t& valvtn_,\r
- controller*)=0;\r
- /* Delete VTN in the controller*/\r
- virtual drv_resp_code_t delete_cmd(key_vtn_t& keyvtn_, val_vtn_t& valvtn_,\r
- controller*)=0;\r
- /* Validate Operation during Vote */\r
- virtual drv_resp_code_t validate_op(key_vtn_t& keyvtn_, val_vtn_t& valvtn_,\r
- controller*, uint32_t op)=0;\r
- unc_key_type_t get_key_type() {\r
- return UNC_KT_VTN;\r
- }\r
-};\r
-\r
-class vbr_driver_command: public driver_command {\r
-public:\r
- virtual drv_resp_code_t create_cmd(key_vbr_t& keyvbr_, val_vbr_t& valvbr_,\r
- unc::driver::controller*)=0;\r
-\r
- virtual drv_resp_code_t update_cmd(key_vbr_t& keyvbr_, val_vbr_t& valvbr_,\r
- unc::driver::controller*)=0;\r
- virtual drv_resp_code_t delete_cmd(key_vbr_t& keyvbr_, val_vbr_t& valvbr_,\r
- unc::driver::controller*)=0;\r
- virtual drv_resp_code_t validate_op(key_vbr_t& keyvbr_, val_vbr_t& valvbr_,\r
- unc::driver::controller*, uint32_t op)=0;\r
- unc_key_type_t get_key_type() {\r
- return UNC_KT_VBRIDGE;\r
- }\r
-};\r
-\r
-class vbrif_driver_command: public driver_command {\r
-public:\r
- virtual drv_resp_code_t create_cmd(key_vbr_if_t& key,\r
- pfcdrv_val_vbr_if_t& val, unc::driver::controller *conn)=0;\r
-\r
- virtual drv_resp_code_t update_cmd(key_vbr_if_t& key,\r
- pfcdrv_val_vbr_if_t& val, unc::driver::controller *conn) = 0;\r
-\r
- virtual drv_resp_code_t delete_cmd(key_vbr_if_t& key,\r
- pfcdrv_val_vbr_if_t& val, unc::driver::controller *conn) = 0;\r
-\r
- virtual drv_resp_code_t validate_op(key_vbr_if_t& key,\r
- pfcdrv_val_vbr_if_t& val, unc::driver::controller* ctr,\r
- uint32_t op)=0;\r
-\r
- unc_key_type_t get_key_type() {\r
- return UNC_KT_VBR_IF;\r
- }\r
-};\r
-\r
-class controller_command: public driver_command {\r
-public:\r
- drv_resp_code_t create_cmd(key_ctr_t& key,\r
- val_ctr_t & val, unc::driver::controller *conn) {\r
- return DRVAPI_RESPONSE_FAILURE; \r
- }\r
-\r
- drv_resp_code_t update_cmd(key_ctr_t & key,\r
- val_ctr_t& val, unc::driver::controller *conn){\r
- return DRVAPI_RESPONSE_FAILURE;\r
- \r
- }\r
-\r
- drv_resp_code_t delete_cmd(key_ctr_t & key,\r
- val_ctr_t & val, unc::driver::controller *conn) {\r
- return DRVAPI_RESPONSE_FAILURE;\r
- }\r
-\r
- drv_resp_code_t validate_op(key_ctr_t & key,\r
- val_ctr_t& val, unc::driver::controller* ctr,\r
- uint32_t op) {\r
- return DRVAPI_RESPONSE_FAILURE;\r
-\r
- }\r
-\r
- unc_key_type_t get_key_type() {\r
- return UNC_KT_VBR_IF;\r
- }\r
-};\r
-\r
-} //driver\r
-} //unc\r
-#endif\r
+/*
+* Copyright (c) 2012-2013 NEC Corporation
+ * All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies
+ * this distribution, * and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+#ifndef __CDF_DRIVER_COMMANDS_HH__
+#define __CDF_DRIVER_COMMANDS_HH__
+
+#include <driver/controller_interface.hh>
+#include <pfc/ipc_struct.h>
+#include <unc/unc_base.h>
+#include <confignode.hh>
+#include <vector>
+
+namespace unc {
+namespace driver {
+
+typedef struct val_root {
+ uint8_t root_key;
+} val_root_t;
+
+/*
+ * @desc:Base Class For Driver Commands
+ */
+class driver_command {
+ public:
+ virtual ~driver_command() {}
+ virtual unc_key_type_t get_key_type()=0;
+};
+
+/*
+ * @desc:Abstract base Class to be extended for VTN Commands
+ */
+class vtn_driver_command: public driver_command {
+ public:
+ /**
+ * @brief - Method to create VTN in the controller
+ * @param[in]- key_vtn_t, val_vtn_t, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t create_cmd(key_vtn_t& keyvtn_, val_vtn_t& valvtn_,
+ unc::driver::controller*)=0;
+ /**
+ * @brief - Method to update VTN in the controller
+ * @param[in]- key_vtn_t, val_vtn_t, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t update_cmd(key_vtn_t& keyvtn_, val_vtn_t& valvtn_,
+ unc::driver::controller*)=0;
+ /**
+ * @brief - Method to delete VTN in the controller
+ * @param[in]- key_vtn_t, val_vtn_t, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t delete_cmd(key_vtn_t& keyvtn_, val_vtn_t& valvtn_,
+ unc::driver::controller*)=0;
+ /**
+ * @brief - Method to validate Operation during Vote Request
+ * @param[in]- key_vtn_t, val_vtn_t, controller*, op
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t validate_op(key_vtn_t& keyvtn_, val_vtn_t& valvtn_,
+ unc::driver::controller*, uint32_t op)=0;
+ /**
+ * @brief - Method to return the Keytype
+ * @param[in]- None
+ * @retval - unc_key_type_t - UNC_KT_VTN
+ */
+ unc_key_type_t get_key_type() {
+ return UNC_KT_VTN;
+ }
+};
+
+/*
+ * @desc:Abstract base Class to be extended for VBR Commands
+ */
+class vbr_driver_command: public driver_command {
+ public:
+ /**
+ * @brief - Method to create Vbridge in the controller
+ * @param[in]- key_vbr_t, val_vbr_t, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t create_cmd(key_vbr_t& keyvbr_, val_vbr_t& valvbr_,
+ unc::driver::controller*) = 0;
+ /**
+ * @brief - Method to update Vbridge in the controller
+ * @param[in]- key_vbr_t, val_vbr_t, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t update_cmd(key_vbr_t& keyvbr_, val_vbr_t& valvbr_,
+ unc::driver::controller*) = 0;
+
+ /**
+ * @brief - Method to delete Vbridge in the controller
+ * @param[in]- key_vbr_t, val_vbr_t, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t delete_cmd(key_vbr_t& keyvbr_, val_vbr_t& valvbr_,
+ unc::driver::controller*)=0;
+ /**
+ * @brief - Method to validate Operation during Vote Request
+ * @param[in]- key_vbr_t, val_vbr_t, controller*, op
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t validate_op(key_vbr_t& keyvbr_, val_vbr_t& valvbr_,
+ unc::driver::controller*, uint32_t op)=0;
+ /**
+ * @brief - Method to return the Keytype
+ * @param[in]- None
+ * @retval - unc_key_type_t - UNC_KT_VBRIDGE
+ */
+ unc_key_type_t get_key_type() {
+ return UNC_KT_VBRIDGE;
+ }
+};
+
+/*
+ * @desc:Abstract base Class to be extended for VBRIf Commands
+ */
+class vbrif_driver_command: public driver_command {
+ public:
+ /**
+ * @brief - Method to create Vbr Interface in the controller
+ * @param[in]- key_vbr_if_t, pfcdrv_val_vbr_if_t, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t create_cmd(key_vbr_if_t& key,
+ pfcdrv_val_vbr_if_t& val, unc::driver::controller *conn)=0;
+
+ /**
+ * @brief - Method to update Vbr Interface in the controller
+ * @param[in]- key_vbr_if_t, pfcdrv_val_vbr_if_t, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t update_cmd(key_vbr_if_t& key,
+ pfcdrv_val_vbr_if_t& val, unc::driver::controller *conn) = 0;
+
+ /**
+ * @brief - Method to delete Vbr Interface in the controller
+ * @param[in]- key_vbr_if_t, pfcdrv_val_vbr_if_t, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t delete_cmd(key_vbr_if_t& key,
+ pfcdrv_val_vbr_if_t& val, unc::driver::controller *conn) = 0;
+
+ /**
+ * @brief - Method to validate Operation during Vote Request
+ * @param[in]- key_vbr_if_t, pfcdrv_val_vbr_if_t, controller*,op
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t validate_op(key_vbr_if_t& key,
+ pfcdrv_val_vbr_if_t& val, unc::driver::controller* ctr,
+ uint32_t op)=0;
+
+ /**
+ * @brief - Method to return the Keytype
+ * @param[in]- None
+ * @retval - unc_key_type_t - UNC_KT_VBR_IF
+ */
+ unc_key_type_t get_key_type() {
+ return UNC_KT_VBR_IF;
+ }
+};
+
+/*
+ * @desc:Abstract base Class to be extended for VBRIf Commands
+ */
+class controller_command: public driver_command {
+ public:
+ /**
+ * @brief - Method to create controller configuration
+ * @param[in]- key_ctr_t, val_ctr_t, controller*
+ * @retval - DRVAPI_RESPONSE_FAILURE
+ */
+ drv_resp_code_t create_cmd(key_ctr_t& key,
+ val_ctr_t & val, unc::driver::controller *conn) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ /**
+ * @brief - Method to update controller configuration
+ * @param[in]- key_ctr_t, val_ctr_t, controller*
+ * @retval - DRVAPI_RESPONSE_FAILURE
+ */
+ drv_resp_code_t update_cmd(key_ctr_t & key,
+ val_ctr_t& val, unc::driver::controller *conn) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ /**
+ * @brief - Method to update controller configuration
+ * @param[in]- key_ctr_t, val_ctr_t, controller*
+ * @retval - DRVAPI_RESPONSE_FAILURE
+ */
+ drv_resp_code_t delete_cmd(key_ctr_t & key,
+ val_ctr_t & val, unc::driver::controller *conn) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ /**
+ * @brief - Method to validate Operation during Vote Request
+ * @param[in]- key_ctr_t, val_ctr_t, controller*, op
+ * @retval - DRVAPI_RESPONSE_FAILURE
+ */
+ drv_resp_code_t validate_op(key_ctr_t & key,
+ val_ctr_t& val, unc::driver::controller* ctr,
+ uint32_t op) {
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ /**
+ * @brief - Method to return the Keytype
+ * @param[in]- None
+ * @retval - unc_key_type_t - UNC_KT_CONTROLLER
+ */
+ unc_key_type_t get_key_type() {
+ return UNC_KT_CONTROLLER;
+ }
+};
+
+/*
+ * @desc:Abstract base Class to be extended for Audit KT_ROOT Commands
+ */
+class root_driver_command : public driver_command {
+ public:
+ /**
+ * @brief - Method to form the create command for Audit
+ * @param[in]- key_root_t, val_root_t, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t
+ create_cmd(key_root_t& key,
+ val_root_t & val,
+ unc::driver::controller *conn) = 0;
+
+ /**
+ * @brief - Method to form the KT_ROOT update oommand
+ * @param[in]- key_root_t, val_root_t, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t
+ update_cmd(key_root_t& key,
+ val_root_t & val,
+ unc::driver::controller *conn) = 0;
+
+ /**
+ * @brief - Method to form the KT_ROOT delete oommand
+ * @param[in]- key_root_t, val_root_t, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t
+ delete_cmd(key_root_t& key,
+ val_root_t & val,
+ unc::driver::controller *conn)=0;
+
+ /**
+ * @brief - Method to form the KT_ROOT delete oommand
+ * @param[in]- key_root_t, val_root_t, controller*,op
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t
+ validate_op(key_root_t& key,
+ val_root_t & val,
+ unc::driver::controller *conn,
+ uint32_t op) = 0;
+
+ /**
+ * @brief - Method to read configurations during Audit
+ * @param[in]- vector<unc::vtndrvcache::ConfigNode*>, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t
+ read_root_child(std::vector<unc::vtndrvcache::ConfigNode*>&,
+ unc::driver::controller*) = 0;
+
+ /**
+ * @brief - Method to read configurations from controller during Audit
+ * @param[in]- vector<unc::vtndrvcache::ConfigNode*>, controller*
+ * @retval - DRVAPI_RESPONSE_SUCCESS/DRVAPI_RESPONSE_FAILURE
+ */
+ virtual drv_resp_code_t
+ read_all_child(unc::vtndrvcache::ConfigNode*,
+ std::vector<unc::vtndrvcache::ConfigNode*>&,
+ unc::driver::controller*)=0;
+ /**
+ * @brief - Method to return the Keytype
+ * @param[in]- None
+ * @retval - unc_key_type_t - UNC_KT_ROOT
+ */
+ unc_key_type_t get_key_type() {
+ return UNC_KT_ROOT;
+ }
+};
+} // namespace driver
+} // namespace unc
+#endif
-/*\r
- * Copyright (c) 2012-2013 NEC Corporation\r
- * All rights reserved.\r
- * \r
- * This program and the accompanying materials are made\r
- * available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-#ifndef __CDF_DRIVER_INTERFACE_HH__\r
-#define __CDF_DRIVER_INTERFACE_HH__\r
-\r
-#include <driver/controller_interface.hh>\r
-#include <driver/driver_command.hh>\r
-#include <pfc/ipc_struct.h>\r
-#include <unc/keytype.h>\r
-#include <uncxx/tclib/tclib_defs.hh>\r
-\r
-namespace unc {\r
-namespace driver {\r
-\r
-\r
-class driver {\r
- public:\r
- // 2-phase commit support from CDF needed?\r
- virtual pfc_bool_t is_2ph_commit_support_needed () =0;\r
- // Can driver collect running config by itself?\r
- virtual pfc_bool_t is_audit_collection_needed () =0;\r
- // add controller of this type\r
- virtual controller* add_controller(const key_ctr_t& key_ctr,\r
- const val_ctr_t& val_ctr)=0;\r
- // update controller of this type\r
- virtual controller* update_controller(const key_ctr_t& key_ctr,\r
- const val_ctr_t& val_ctr,\r
- controller* ctrl_inst)=0;\r
- //REturn Type of Controller supported by driver\r
- virtual unc_keytype_ctrtype_t get_controller_type() =0;\r
- // delete controller of this type\r
- virtual pfc_bool_t delete_controller(controller* delete_inst)=0;\r
- // driver command for particular KT\r
- virtual driver_command* get_driver_command(unc_key_type_t key_type)=0;\r
- // transaction command, if no transaction needed, return NULL\r
- virtual unc::tclib::TcCommonRet HandleVote(controller*)=0;\r
- virtual unc::tclib::TcCommonRet HandleCommit(controller*)=0;\r
- virtual unc::tclib::TcCommonRet HandleAbort(controller*)=0;\r
-\r
- virtual ~driver() {}; \r
-};\r
-} // driver\r
-} // unc\r
-#endif\r
+/*
+ * Copyright (c) 2012-2013 NEC Corporation
+ * All rights reserved.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+#ifndef __CDF_DRIVER_INTERFACE_HH__
+#define __CDF_DRIVER_INTERFACE_HH__
+
+#include <driver/controller_interface.hh>
+#include <driver/driver_command.hh>
+#include <pfc/ipc_struct.h>
+#include <unc/keytype.h>
+#include <uncxx/tclib/tclib_defs.hh>
+
+namespace unc {
+namespace driver {
+
+class driver {
+ public:
+ /**
+ * @brief - Method to check if two phase commit support is needed
+ * @retval - PFC_TRUE/PFC_FALSE
+ */
+ virtual pfc_bool_t is_2ph_commit_support_needed() =0;
+
+ /**
+ * @brief - Method to check if needs driver needs audit support
+ * @retval - PFC_TRUE/PFC_FALSE
+ */
+ virtual pfc_bool_t is_audit_collection_needed() =0;
+
+ /**
+ * @brief - Method to add controller
+ * @param[in] - key_ctr_t,val_ctr_t
+ * @retval - controller* - Instance of controller
+ */
+ virtual controller* add_controller(const key_ctr_t& key_ctr,
+ const val_ctr_t& val_ctr)=0;
+ /**
+ * @brief - Method to update controller
+ * @param[in] - key_ctr_t,val_ctr_t,controller*
+ * @retval - controller* - Instance of controller
+ */
+ virtual controller* update_controller(const key_ctr_t& key_ctr,
+ const val_ctr_t& val_ctr,
+ controller* ctrl_inst)=0;
+
+ /**
+ * @brief - Method to retrieve the type of Controller supported by driver
+ * @retval - unc_keytype_ctrtype_t - Type of controller
+ */
+ virtual unc_keytype_ctrtype_t get_controller_type() =0;
+
+ /**
+ * @brief - Method to delete controller
+ * @param[in] - controller* - Instance of controller
+ * @retval - PFC_TRUE/PFC_FALSE
+ */
+ virtual pfc_bool_t delete_controller(controller* delete_inst)=0;
+
+ /**
+ * @brief - Method to get the driver command ptr for particular KT
+ * @param[in] - key_type
+ * @retval - driver_command* - command pointer of Keytype
+ */
+ virtual driver_command* get_driver_command(unc_key_type_t key_type)=0;
+
+ /**
+ * @brief - Method to handle vote request of transaction
+ * @param[in] - controller* -Instance of controller
+ * @retval - TcCommonRet - TC return code
+ */
+ virtual unc::tclib::TcCommonRet HandleVote(controller* ctlptr)=0;
+ /**
+ * @brief - Method to handle global commit request of transaction
+ * @param[in] - controller* -Instance of controller
+ * @retval - TcCommonRet - TC return code
+ */
+ virtual unc::tclib::TcCommonRet HandleCommit(controller* ctlptr)=0;
+
+ /**
+ * @brief - Method to get the abort request of transaction
+ * @param[in] - controller* -Instance of controller
+ * @retval - TcCommonRet - TC return code
+ */
+ virtual unc::tclib::TcCommonRet HandleAbort(controller* ctlptr)=0;
+
+ /**
+ * @brief - Method to check if ping is needed by the controller
+ * @retval - PFC_TRUE/PFC_FALSE
+ */
+ virtual pfc_bool_t is_ping_needed() = 0;
+
+ /**
+ * @brief - Method to retrive the ping Interval
+ * @retval - uint32_t - ping Interval in secs
+ */
+ virtual uint32_t get_ping_interval() = 0;
+
+ /**
+ * @brief - Method to retrive the Ping Retry Count
+ * @retval - uint32_t - ping retry count
+ */
+ virtual uint32_t get_ping_fail_retry_count() = 0;
+
+ /**
+ * @brief - Method to ping the controller
+ * @param[in] - controller* -Instance of controller
+ * @retval - PFC_TRUE/PFC_FALSE
+ */
+ virtual pfc_bool_t ping_controller(unc::driver::controller*) = 0;
+
+ /**
+ * @brief - Virtual destructort
+ */
+ virtual ~driver() {}
+};
+} // namespace driver
+} // namespace unc
+#endif
-/*
- * Copyright (c) 2012-2013 NEC Corporation
- * All rights reserved.
- *
- * This program and the accompanying materials are made
- * available under the
- * terms of the Eclipse Public License v1.0 which
- * accompanies this
- * distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
+ /*
+* Copyright (c) 2012-2013 NEC Corporation
+* All rights reserved.
+*
+* This program and the accompanying materials are made
+* available under the
+* terms of the Eclipse Public License v1.0 which
+* accompanies this
+* distribution, and is available at
+* http://www.eclipse.org/legal/epl-v10.html
+*/
#ifndef __HANDLER_HH__
#define __HANDLER_HH__
IPC_DATA_TYPE_INDEX, /* datatype=7 */
IPC_KEY_TYPE_INDEX, /* keytype=8 */
} request_header_t;
-
-} //driver
-
-} //unc
-
+} // namespace driver
+} // namespace unc
#endif
-/*
- * Copyright (c) 2012-2013 NEC Corporation
- * All rights reserved.
- *
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
+ /*
+* Copyright (c) 2012-2013 NEC Corporation
+* All rights reserved.
+*
+* This program and the accompanying materials are made
+* available under the terms of the Eclipse Public License v1.0 which
+* accompanies this distribution, and is available at
+* http://www.eclipse.org/legal/epl-v10.html
+*/
#ifndef KT_HANDLER_HH_
#define KT_HANDLER_HH_
class KtHandler {
public:
/**
- * @brief - Handling Request received from platform
- * @param[in] ServerSession, keyif_drv_request_header_t,ControllerFramework
- * @retval - drv_resp_code_t
- **/
+ * @brief - Destructor
+ */
+ virtual ~KtHandler() { }
+
+ /**
+ * @brief - Handling Request received from platform
+ * @param[in] - ControllerFramework pointer
+ * @param[in] - ServerSession,
+ * @param[in] - key interface request header
+ * @retval - drv_resp_code_t
+ */
virtual drv_resp_code_t handle_request(pfc::core::ipc::ServerSession &sess,
keyif_drv_request_header_t &request_header,
- ControllerFramework* )=0;
+ ControllerFramework*) = 0;
/**
- * @brief - Converting ConfigNode pointer to Command
- * @param[in] ConfigNode*, controller*, driver*
- * @retval - drv_resp_code_t
- **/
-
+ * @brief - Converting ConfigNode pointer to execute Command
+ * @param[in] - ConfigNode pointer
+ * @param[in] - controller pointer
+ * @param[in] - driver pointer
+ * @retval - drv_resp_code_t
+ */
virtual drv_resp_code_t execute_cmd(unc::vtndrvcache::ConfigNode *cfgptr,
unc::driver::controller* ctl_ptr,
unc::driver::driver* drv_ptr)=0;
/**
- * @brief - Retrieve Key struct
- * @param[in] ConfigNode*
- * @retval - drv_resp_code_t
- **/
+ * @brief - Retrieve Key struct
+ * @param[in] - ConfigNode pointer
+ * @retval - void * to key
+ */
virtual void* get_key_struct(unc::vtndrvcache::ConfigNode *cfgptr)=0;
/**
- * @brief - Retrieve Val struct
- * @param[in] ConfigNode*
- * @retval - drv_resp_code_t
- **/
-
+ * @brief - Retrieve Val struct
+ * @param[in] - ConfigNode pointer
+ * @retval - void * to val
+ */
virtual void* get_val_struct(unc::vtndrvcache::ConfigNode *cfgptr)=0;
};
-} //driver
-} //unc
+} // namespace driver
+} // namespace unc
#endif
#define _REQUEST_TEMPLATE_H_
#include <kt_handler.hh>
-#include <vtn_drv_module.hh>
#include <controller_fw.hh>
#include <driver/driver_interface.hh>
#include <vtndrvintf_defs.h>
#include <map>
#include <string>
-
+#include <utility>
+#include <vector>
+#include <memory>
namespace unc {
namespace driver {
/**
-* @brief KtRequestHandler provides function for handling request and response
-*
-**/
-
+ * @brief KtRequestHandler provides function for handling request and response
+ *
+ **/
template<typename key, typename val, typename command_ptr>
class KtRequestHandler : public KtHandler {
- public:
- /*
- * @brief Default Constructor
- */
-
- KtRequestHandler();
-
- /*
- * @brief Default Destructor
- */
-
- ~KtRequestHandler();
-
- /**
- * @brief - Handling Request received from platform
- * @param[in] ServerSession, keyif_drv_request_header_t,ControllerFramework
- * @retval - drv_resp_code_t
- **/
-
- drv_resp_code_t
- handle_request(pfc::core::ipc::ServerSession &sess,
+ public:
+ /*
+ * @brief - Default Constructor
+ */
+ KtRequestHandler();
+
+ /*
+ * @brief - Default Destructor
+ */
+ ~KtRequestHandler();
+
+ /**
+ * @brief - This method handles request received from platform layer
+ * @param[in]- ServerSession, keyif_drv_request_header_t,ControllerFramework*
+ * @retval - drv_resp_code_t
+ **/
+ drv_resp_code_t
+ handle_request(pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_request_header_t &request_header,
+ unc::driver::ControllerFramework* ctrl_int);
+
+ /**
+ * @brief - This method retrieves the key and val structures
+ * @param[in] - ServerSession, keyif_drv_request_header_t,key,val
+ * @retval - drv_resp_code_t
+ **/
+ drv_resp_code_t
+ parse_request(pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_request_header_t &request_header,
+ key &key_generic_,
+ val &val_generic_);
+
+ /**
+ * @brief - This method executes the Create,Delete,Update requests of
+ * Keytypes
+ * @param[in]- ServerSession, keyif_drv_request_header_t, ControllerFramework*
+ * drv_resp_code_t,key,val
+ * @retval - drv_resp_code_t
+ **/
+ drv_resp_code_t
+ execute(pfc::core::ipc::ServerSession &sess,
unc::driver::keyif_drv_request_header_t &request_header,
- unc::driver::ControllerFramework* ctrl_int);
-
- /**
- * @brief - Retrieve key and val struct
- * @param[in] ServerSession, keyif_drv_request_header_t
- * @retval - drv_resp_code_t
- **/
-
- drv_resp_code_t
- parse_request(pfc::core::ipc::ServerSession &sess,
- unc::driver::keyif_drv_request_header_t &request_header);
-
- /**
- * @brief - Create,Delete,Update Of KT
- * @param[in] ServerSession, keyif_drv_request_header_t, ControllerFramework
- * @retval - drv_resp_code_t
- **/
-
- drv_resp_code_t
- execute(pfc::core::ipc::ServerSession &sess,
- unc::driver::keyif_drv_request_header_t &request_header,
- unc::driver::ControllerFramework* ctrl_int);
-
-
- /**
- * @brief - Handle Response
- * @param[in] ServerSession, keyif_drv_request_header_t
- * @retval - drv_resp_code_t
- **/
-
- drv_resp_code_t
- handle_response(pfc::core::ipc::ServerSession &sess,
- unc::driver::keyif_drv_request_header_t &request_header);
-
-
- /**
- * @brief - Response Header Creation
- * @param[in] keyif_drv_response_header_t, keyif_drv_request_header_t
- * @retval - void
- */
-
- void
- create_response_header(unc::driver::keyif_drv_request_header_t &reqhdr,
- unc::driver::keyif_drv_response_header_t &resphdr);
-
-
- /**
- * @brief - Populating Response Header
- * @param[in] ServerSession, keyif_drv_response_header_t
- * @retval - drv_resp_code_t
- **/
-
- drv_resp_code_t
- populate_response_header(pfc::core::ipc::ServerSession &sess,
- unc::driver::keyif_drv_response_header_t &resp_hdr);
-
-
- /**
- * @brief - Converting ConfigNode pointer to Command
- * @param[in] ConfigNode*, controller*, driver*
- * @retval - drv_resp_code_t
- **/
-
- drv_resp_code_t
- execute_cmd(unc::vtndrvcache::ConfigNode *cfgptr,
- unc::driver::controller* ctl_ptr,
- unc::driver::driver* drv_ptr);
-
-
- /**
- * @brief - Retrieve Key struct
- * @param[in] ConfigNode*
- * @retval - drv_resp_code_t
- **/
-
- void* get_key_struct(unc::vtndrvcache::ConfigNode *cfgptr);
-
-
- /**
- * @brief - Retrieve Val struct
- * @param[in] ConfigNode*
- * @retval - drv_resp_code_t
- **/
-
- void* get_val_struct(unc::vtndrvcache::ConfigNode *cfgptr);
-
- private:
- key key_generic_;
- val val_generic_;
- unc_keytype_operation_t operation_;
- command_ptr *command_ptr_;
- unc_key_type_t keytype_;
- drv_resp_code_t resp_code_;
+ unc::driver::ControllerFramework* ctrl_int,
+ drv_resp_code_t &resp_code_,
+ key &key_generic_,
+ val &val_generic_);
+
+ /**
+ * @brief - This method handles response from controller
+ * @param[in] - ServerSession, keyif_drv_request_header_t,ControllerFramework*,
+ * key,val,drv_resp_code_t
+ * @retval - drv_resp_code_t
+ **/
+ drv_resp_code_t
+ handle_response(pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_request_header_t &request_header,
+ unc::driver::ControllerFramework* ctrl_int,
+ key &key_generic_,
+ val &val_generic_,
+ drv_resp_code_t &resp_code_);
+
+ /**
+ * @brief - This method creates the Response Header
+ * @param[in]- keyif_drv_response_header_t,
+ * keyif_drv_request_header_t,drv_resp_code_t
+ * @retval - void
+ */
+ void
+ create_response_header(unc::driver::keyif_drv_request_header_t &reqhdr,
+ unc::driver::keyif_drv_response_header_t &resphdr,
+ drv_resp_code_t &resp_code_);
+
+ /**
+ * @brief - This method populates the Response Header
+ * @param[in]- ServerSession, keyif_drv_response_header_t
+ * @retval - drv_resp_code_t
+ **/
+ drv_resp_code_t
+ populate_response_header(pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_response_header_t &resp_hdr);
+
+
+ /**
+ * @brief - This method forms the command from ConfigNode pointer
+ * @param[in]- ConfigNode*, controller*, driver*
+ * @retval - drv_resp_code_t
+ **/
+ drv_resp_code_t
+ execute_cmd(unc::vtndrvcache::ConfigNode *cfgptr,
+ unc::driver::controller* ctl_ptr,
+ unc::driver::driver* drv_ptr);
+
+ /**
+ * @brief - This method retrieves the Key struct from ConfigNode pointer
+ * @param[in]- ConfigNode*
+ * @retval - void*
+ **/
+ void* get_key_struct(unc::vtndrvcache::ConfigNode *cfgptr);
+
+ /**
+ * @brief - This method retrieves the value struct from ConfigNode pointer
+ * @param[in]- ConfigNode*
+ * @retval - void*
+ **/
+ void* get_val_struct(unc::vtndrvcache::ConfigNode *cfgptr);
+
+ /**
+ * @brief - This method adds config nodes to vtncache
+ * @param[in]- cfg_list,KeyTree*,root_driver_command*,
+ * controller*,drv_resp_code_t
+ * @retval - void
+ **/
+ void
+ fill_cache(std::vector<unc::vtndrvcache::ConfigNode*> &cfg_list,
+ unc::vtndrvcache::KeyTree *keytree_ptr,
+ root_driver_command* command_ptr_root,
+ unc::driver::controller* ctl_ptr,
+ drv_resp_code_t &resp_code_);
+
+ /**
+ * @brief - This method initializes map for STDEF
+ * @retval - void
+ **/
+ void initialize_map();
+
+ private:
+ std::map<unc_key_type_t, pfc_ipcstdef_t*> key_map_;
+ std::map<unc_key_type_t, pfc_ipcstdef_t*> val_map_;
};
/**
-* @brief: Default Constructor
-**/
+ * @brief: Default Constructor
+ **/
template<typename key, typename val, typename command_ptr>
-KtRequestHandler<key, val, command_ptr>::KtRequestHandler():command_ptr_(NULL), resp_code_(DRVAPI_RESPONSE_FAILURE) { }
+KtRequestHandler<key, val, command_ptr>::KtRequestHandler() { }
/**
-* @brief: Default Destructor
-**/
-
+ * @brief: Default Destructor
+ **/
template<typename key, typename val, typename command_ptr>
KtRequestHandler<key, val, command_ptr>::~KtRequestHandler() { }
-
-/**
-* @brief - Retrieve key structure
-**/
-
+ /**
+ * @brief - This method retrieves the Key struct from ConfigNode pointer
+ * @param[in]- ConfigNode*
+ * @retval - void*
+ **/
template<typename key, typename val, typename command_ptr>
void* KtRequestHandler<key, val, command_ptr>::
- get_key_struct(unc::vtndrvcache::ConfigNode *cfgptr) {
+get_key_struct(unc::vtndrvcache::ConfigNode *cfgptr) {
unc::vtndrvcache::CacheElementUtil <key, val, uint32_t> * cache_util_ptr =
- dynamic_cast <unc::vtndrvcache::CacheElementUtil
- <key, val, uint32_t> * >(cfgptr);
+ static_cast <unc::vtndrvcache::CacheElementUtil<key, val, uint32_t> * >
+ (cfgptr);
- if(cache_util_ptr == NULL) {
+ if (cache_util_ptr == NULL) {
pfc_log_error("%s: cache_util_ptr is null", PFC_FUNCNAME);
return NULL;
}
return cache_util_ptr->getkey();
}
-/**
-* @brief - Retrieve Value Structure
-**/
-
+ /**
+ * @brief - This method retrieves the Value struct from ConfigNode pointer
+ * @param[in]- ConfigNode*
+ * @retval - void*
+ **/
template<typename key, typename val, typename command_ptr>
void* KtRequestHandler<key, val, command_ptr>::
- get_val_struct(unc::vtndrvcache::ConfigNode *cfgptr) {
+get_val_struct(unc::vtndrvcache::ConfigNode *cfgptr) {
unc::vtndrvcache::CacheElementUtil<key, val, uint32_t> * cache_util_ptr =
- dynamic_cast <unc::vtndrvcache::CacheElementUtil
- <key, val, uint32_t> * >(cfgptr);
+ static_cast <unc::vtndrvcache::CacheElementUtil
+ <key, val, uint32_t> * >(cfgptr);
- if(cache_util_ptr == NULL) {
- pfc_log_error("%s: cache_util_ptr is null", PFC_FUNCNAME);
+ if (cache_util_ptr == NULL) {
+ pfc_log_error("%s: cache_util_ptr is null for get_val_struct",
+ PFC_FUNCNAME);
return NULL;
}
return cache_util_ptr->getval();
}
-
-/**
-* @brief - parse key and value structure
-**/
-
-
+ /**
+ * @brief - This method retrieves the key and val structures
+ * @param[in] - ServerSession, keyif_drv_request_header_t,key,val
+ * @retval - drv_resp_code_t
+ **/
template<typename key, typename val, typename command_ptr>
drv_resp_code_t
KtRequestHandler<key, val, command_ptr>::parse_request(
- pfc::core::ipc::ServerSession &sess,
- unc::driver::keyif_drv_request_header_t &request_header) {
+ pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_request_header_t &request_header,
+ key &key_generic_,
+ val &val_generic_) {
if (sess.getArgument(INPUT_KEY_STRUCT_INDEX, key_generic_)) {
- pfc_log_info("%s: Exting Function.getArg Failed to read key struct."
- " rc=%u", PFC_FUNCNAME, 2);
- return DRVAPI_RESPONSE_CTRLAPI_FAILURE;
+ pfc_log_debug("%s: Exting Function.getArg Failed to read key struct."
+ " rc=%u", PFC_FUNCNAME, 2);
+ return DRVAPI_RESPONSE_CTRLAPI_FAILURE;
}
if (sess.getArgument(INPUT_VAL_STRUCT_INDEX, val_generic_)) {
- pfc_log_info("%s: No value struct present.", PFC_FUNCNAME);
+ pfc_log_debug("%s: No value struct present.", PFC_FUNCNAME);
}
- operation_ = (unc_keytype_operation_t) request_header.header.operation;
- pfc_log_info("%u: operation_.", operation_);
- keytype_ = request_header.key_type;
return DRVAPI_RESPONSE_SUCCESS;
}
-
-/**
-* @brief - Create , Delete and Update Command execution
-**/
-
-template<typename key, typename val, class command_ptr>
+ /**
+ * @brief - This method executes the Create,Delete,Update requests of
+ * Keytypes
+ * @param[in]- ServerSession, keyif_drv_request_header_t, ControllerFramework*
+ * drv_resp_code_t,key,val
+ * @retval - drv_resp_code_t
+ **/
+template<typename key, typename val, typename command_ptr>
drv_resp_code_t
KtRequestHandler<key, val, command_ptr>::execute(
- pfc::core::ipc::ServerSession &sess,
- unc::driver::keyif_drv_request_header_t &request_header,
- unc::driver::ControllerFramework* ctrl_int) {
- pfc_log_info("%s: Entering Function.", PFC_FUNCNAME);
+ pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_request_header_t &request_header,
+ unc::driver::ControllerFramework* ctrl_int,
+ drv_resp_code_t &resp_code_,
+ key &key_generic_,
+ val &val_generic_) {
+ pfc_log_debug("%s: Entering Function.", PFC_FUNCNAME);
std::string ctrl_name = std::string(request_header.controller_name);
unc::driver::driver* drv_ptr = NULL;
unc::driver::controller* ctrl_ptr = NULL;
-
- resp_code_ = (drv_resp_code_t) ctrl_int->GetDriverByControllerName(ctrl_name, &ctrl_ptr, &drv_ptr);
- pfc_log_info("%u:resp_code_. GetDriverByControllerName", resp_code_);
-
- if (resp_code_) {
- pfc_log_error("%s:GetDriverByControllerName failed with re_code,%u",
- PFC_FUNCNAME, resp_code_);
- return resp_code_;
+ drv_resp_code_t ret_val = DRVAPI_RESPONSE_FAILURE;
+ VtnDrvRetEnum ctl_retval = VTN_DRV_RET_FAILURE;
+ resp_code_ = DRVAPI_RESPONSE_FAILURE;
+
+ ctl_retval = ctrl_int->GetDriverByControllerName(ctrl_name,
+ &ctrl_ptr,
+ &drv_ptr);
+ pfc_log_debug("%u:resp_code_. GetDriverByControllerName",
+ ctl_retval);
+
+ if (ctl_retval == VTN_DRV_RET_FAILURE) {
+ pfc_log_error("%s:GetDriverByControllerName failed with re_code,%u",
+ PFC_FUNCNAME, resp_code_);
+ return DRVAPI_RESPONSE_FAILURE;
}
-
PFC_ASSERT(drv_ptr != NULL);
PFC_ASSERT(ctrl_ptr !=NULL);
unc::driver::driver_command * drv_command_ptr_ =
- drv_ptr->get_driver_command(keytype_);
+ drv_ptr->get_driver_command(request_header.key_type);
PFC_ASSERT(drv_command_ptr_ != NULL);
- command_ptr_ = static_cast<command_ptr *> (drv_command_ptr_);
+ command_ptr *command_ptr_ = static_cast<command_ptr *> (drv_command_ptr_);
PFC_ASSERT(command_ptr_ != NULL);
if (!drv_ptr->is_2ph_commit_support_needed()) {
- if (ctrl_ptr->keytree_ptr == NULL) {
- pfc_log_info("Cache for controller created");
- ctrl_ptr->keytree_ptr = unc::vtndrvcache::KeyTree::create_cache();
- }
- unc::vtndrvcache::ConfigNode *cfgptr =
- new unc::vtndrvcache::CacheElementUtil<key, val, uint32_t> (
- &key_generic_,
- &val_generic_,
- operation_);
- resp_code_ = (drv_resp_code_t) ctrl_ptr->keytree_ptr->append_commit_node(cfgptr);
- pfc_log_info("%u:resp_code_ AppendCommitNode", resp_code_);
-
- if (resp_code_) {
- pfc_log_info("%s:Exiting Function. AppendCommitNode fail",
- PFC_FUNCNAME);
- if(cfgptr)
- delete cfgptr;
- return resp_code_;
- }
+ if (ctrl_ptr->keytree_ptr == NULL) {
+ pfc_log_debug("Cache for controller created");
+ ctrl_ptr->keytree_ptr = unc::vtndrvcache::KeyTree::create_cache();
+ }
+ unc::vtndrvcache::ConfigNode *cfgptr =
+ new unc::vtndrvcache::CacheElementUtil<key, val, uint32_t> (
+ &key_generic_,
+ &val_generic_,
+ request_header.header.operation);
+ if (cfgptr == NULL) {
+ pfc_log_debug("%s:Exiting Function. Not able to create ConfigNode",
+ PFC_FUNCNAME);
+ delete command_ptr_;
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ uint32_t size = ctrl_ptr->keytree_ptr->cfg_list_count();
+ pfc_log_debug("before add .... size is %d", size);
+ ret_val = (drv_resp_code_t) ctrl_ptr->keytree_ptr->append_commit_node(
+ cfgptr);
+ size = 0;
+ size = ctrl_ptr->keytree_ptr->cfg_list_count();
+ pfc_log_debug("after add .... size is %d", size);
+
+ if (ret_val) {
+ pfc_log_debug("%s:Exiting Function. AppendCommitNode fail",
+ PFC_FUNCNAME);
+ if (cfgptr != NULL)
+ delete cfgptr;
+ delete command_ptr_;
+ return resp_code_;
+ } else {
+ pfc_log_debug("Caching Success");
+ resp_code_= DRVAPI_RESPONSE_SUCCESS;
+ }
} else {
- switch (operation_) {
- case UNC_OP_CREATE:
- pfc_log_info("%s: Translate Create Command string", PFC_FUNCNAME);
- resp_code_ = command_ptr_->create_cmd(key_generic_, val_generic_, ctrl_ptr);
+ switch (request_header.header.operation) {
+ case UNC_OP_CREATE:
+ pfc_log_debug("%s: Translate Create Command string", PFC_FUNCNAME);
+ resp_code_ = command_ptr_->create_cmd(key_generic_,
+ val_generic_,
+ ctrl_ptr);
- break;
+ break;
- case UNC_OP_DELETE:
- pfc_log_info("%s: Translate Delete Command string", PFC_FUNCNAME);
+ case UNC_OP_DELETE:
+ pfc_log_debug("%s: Translate Delete Command string", PFC_FUNCNAME);
- resp_code_ = command_ptr_->delete_cmd(key_generic_, val_generic_, ctrl_ptr);
+ resp_code_ = command_ptr_->delete_cmd(key_generic_,
+ val_generic_,
+ ctrl_ptr);
- break;
+ break;
- case UNC_OP_UPDATE:
- pfc_log_info("%s: Translate Update Command string", PFC_FUNCNAME);
- resp_code_ = command_ptr_->update_cmd(key_generic_, val_generic_, ctrl_ptr);
+ case UNC_OP_UPDATE:
+ pfc_log_debug("%s: Translate Update Command string", PFC_FUNCNAME);
- break;
+ resp_code_ = command_ptr_->update_cmd(key_generic_,
+ val_generic_,
+ ctrl_ptr);
- default:
+ break;
- pfc_log_info("%s: Invalid operation ", PFC_FUNCNAME);
+ default:
- resp_code_ = DRVAPI_RESPONSE_FAILURE;
+ pfc_log_debug("%s: Invalid operation ", PFC_FUNCNAME);
- break;
+ resp_code_ = DRVAPI_RESPONSE_FAILURE;
+
+ break;
}
}
- pfc_log_info("%s: Exiting Function.", PFC_FUNCNAME);
+ pfc_log_debug("%s: Exiting Function.", PFC_FUNCNAME);
+ delete command_ptr_;
return resp_code_;
}
-
-/**
-* @brief:Template Specialization for parsing KT_Controller structures(Key,Val)
-**/
-
+ /**
+ * @brief - This method is the Template Specialization for parsing
+ * KT_Controller structures(Key,Val)
+ * @param[in] - ServerSession, keyif_drv_request_header_t,key_ctr_t,val_ctr_t
+ * @retval - drv_resp_code_t
+ **/
template<>
drv_resp_code_t
KtRequestHandler<key_ctr_t, val_ctr_t, controller_command>::parse_request(
- pfc::core::ipc::ServerSession &sess,
- unc::driver::keyif_drv_request_header_t &request_header) {
- pfc_log_info("%s: Entering Function.", PFC_FUNCNAME);
+ pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_request_header_t &request_header,
+ key_ctr_t &key_generic_,
+ val_ctr_t &val_generic_) {
+ pfc_log_debug("%s: Entering Function.", PFC_FUNCNAME);
uint32_t ret_value = DRVAPI_RESPONSE_FAILURE;
ret_value = sess.getArgument(INPUT_KEY_STRUCT_INDEX, key_generic_);
if (ret_value) {
- pfc_log_error("%s: GetArgument failed to read key struct "
- "for UNC_KT_CONTROLLER (err = %u)",
- PFC_FUNCNAME, ret_value);
- return DRVAPI_RESPONSE_MISSING_KEY_STRUCT;
+ pfc_log_error("%s: GetArgument failed to read key struct "
+ "for UNC_KT_CONTROLLER (err = %u)",
+ PFC_FUNCNAME, ret_value);
+ return DRVAPI_RESPONSE_MISSING_KEY_STRUCT;
}
if ((request_header.header.operation == UNC_OP_CREATE)
- || (request_header.header.operation == UNC_OP_UPDATE)) {
- ret_value = sess.getArgument(INPUT_VAL_STRUCT_INDEX, val_generic_);
- if (ret_value) {
- pfc_log_error("%s: GetArgument failed to read value struct "
- "for UNC_KT_CONTROLLER (err = %u)",
- PFC_FUNCNAME, ret_value);
- return DRVAPI_RESPONSE_MISSING_VAL_STRUCT;
- }
+ || (request_header.header.operation == UNC_OP_UPDATE)) {
+ ret_value = sess.getArgument(INPUT_VAL_STRUCT_INDEX, val_generic_);
+ if (ret_value) {
+ pfc_log_error("%s: GetArgument failed to read value struct "
+ "for UNC_KT_CONTROLLER (err = %u)",
+ PFC_FUNCNAME, ret_value);
+ return DRVAPI_RESPONSE_MISSING_VAL_STRUCT;
+ }
}
+ pfc_log_debug("%s: Exiting Function.", PFC_FUNCNAME);
return DRVAPI_RESPONSE_SUCCESS;
- pfc_log_info("%s: Exiting Function.", PFC_FUNCNAME);
}
+ /**
+ * @brief - This method is template Specialization for parsing KT_ROOT
+ * @param[in] - ServerSession,keyif_drv_request_header_t,key_root_t
+ * val_root_t
+ * @retval - drv_resp_code_t
+ **/
+template<>
+drv_resp_code_t
+KtRequestHandler<key_root_t, val_root_t, root_driver_command>::parse_request(
+ pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_request_header_t &request_header,
+ key_root_t &key_generic_,
+ val_root_t &val_generic_) {
+ request_header.key_type = UNC_KT_ROOT;
+ return DRVAPI_RESPONSE_SUCCESS;
+}
-/**
-* @brief:Template Specialization for KT Controller command Execution
-**/
-
+ /**
+ * @brief - This method is the template Specialization for
+ * KT ROOT command Execution
+ * @param[in]- ServerSession, keyif_drv_request_header_t, ControllerFramework*
+ * drv_resp_code_t,key_root_t,val_root_t
+ * @retval - drv_resp_code_t
+ **/
template<>
drv_resp_code_t
-KtRequestHandler<key_ctr_t, val_ctr_t, controller_command>::execute(
- pfc::core::ipc::ServerSession &sess,
- unc::driver::keyif_drv_request_header_t &request_header,
- unc::driver::ControllerFramework* ctrl_int) {
- pfc_log_info("%s: Entering Function.", PFC_FUNCNAME);
- unc::driver::driver *drv_ptr = NULL;
- unc::driver::controller* ctl_ptr = NULL;
- std::string ctrl_name = std::string(request_header.controller_name);
-
- drv_ptr = ctrl_int->GetDriverInstance((unc_keytype_ctrtype_t)
- val_generic_.type);
- PFC_ASSERT(drv_ptr != NULL);
-
-
- switch (request_header.header.operation) {
- case UNC_OP_CREATE: {
- pfc_log_info("%s: Creates new controller ", PFC_FUNCNAME);
- ctl_ptr = drv_ptr->add_controller(key_generic_, val_generic_);
- ctrl_int->AddController(ctrl_name, ctl_ptr, drv_ptr);
- if(ctl_ptr)
- resp_code_ = DRVAPI_RESPONSE_SUCCESS;
- else
- resp_code_ = DRVAPI_RESPONSE_FAILURE;
- break;
- }
-
- case UNC_OP_UPDATE: {
- pfc_log_info("%s: Updated Controller ", PFC_FUNCNAME);
- ctl_ptr = drv_ptr->update_controller(key_generic_,
- val_generic_,
- ctl_ptr);
- ctrl_int->UpdateControllerConfiguration(ctrl_name, ctl_ptr, drv_ptr);
- if(ctl_ptr)
- resp_code_ = DRVAPI_RESPONSE_SUCCESS;
- else
- resp_code_ = DRVAPI_RESPONSE_FAILURE;
-
- break;
- }
-
- case UNC_OP_DELETE: {
- pfc_log_info("%s: deleted Controller ", PFC_FUNCNAME);
- if(ctl_ptr) {
- drv_ptr->delete_controller(ctl_ptr);
- ctrl_int->RemoveControllerConfiguration(ctrl_name);
- if(ctl_ptr == NULL)
- resp_code_ = DRVAPI_RESPONSE_SUCCESS;
- else
- resp_code_ = DRVAPI_RESPONSE_FAILURE;
- }
- break;
- }
- default: {
- pfc_log_info("%s: Operation not Support ", PFC_FUNCNAME);
- resp_code_ = DRVAPI_RESPONSE_FAILURE;
- break;
- }
- }
- pfc_log_info("%s: Exiting Function.", PFC_FUNCNAME);
+KtRequestHandler<key_root_t, val_root_t, root_driver_command>::execute(
+ pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_request_header_t &request_header,
+ unc::driver::ControllerFramework* ctrl_int,
+ drv_resp_code_t &resp_code_,
+ key_root_t &key_generic_,
+ val_root_t &val_generic_) {
+ pfc_log_debug("%s: Entering Function.", PFC_FUNCNAME);
+
+ std::string ctrl_name = std::string(request_header.controller_name);
+ drv_resp_code_t ret_val_ = DRVAPI_RESPONSE_FAILURE;
+ unc::driver::driver* drv_ptr = NULL;
+ unc::driver::controller* ctrl_ptr = NULL;
+ VtnDrvRetEnum ctl_retval = VTN_DRV_RET_FAILURE;
+ resp_code_ = DRVAPI_RESPONSE_FAILURE;
+ ctl_retval = ctrl_int->GetDriverByControllerName(ctrl_name,
+ &ctrl_ptr,
+ &drv_ptr);
+ pfc_log_debug("%u:ctl_retval. GetDriverByControllerName,ctrl_name%s",
+ ctl_retval, ctrl_name.c_str());
+
+ if (ctl_retval == VTN_DRV_RET_FAILURE) {
+ pfc_log_error("%s:GetDriverByControllerName failed .rt,%u",
+ PFC_FUNCNAME, resp_code_);
return resp_code_;
+ }
+
+ PFC_ASSERT(drv_ptr != NULL);
+
+ PFC_ASSERT(ctrl_ptr !=NULL);
+
+ unc::driver::driver_command * drv_command_ptr_=
+ drv_ptr->get_driver_command(request_header.key_type);
+
+ PFC_ASSERT(drv_command_ptr_ != NULL);
+
+ root_driver_command * command_ptr_root = static_cast<root_driver_command *>
+ (drv_command_ptr_);
+
+ PFC_ASSERT(command_ptr_root != NULL);
+
+ std::vector<unc::vtndrvcache::ConfigNode*> cfg_list;
+
+ if (ctrl_ptr->keytree_ptr == NULL) {
+ pfc_log_debug("Cache for controller created, ctrl_name:%s",
+ ctrl_name.c_str());
+ ctrl_ptr->keytree_ptr = unc::vtndrvcache::KeyTree::create_cache();
+ } else {
+ pfc_log_debug("re-create Cache for controller, ctrl_name:%s",
+ ctrl_name.c_str());
+ delete ctrl_ptr->keytree_ptr;
+ ctrl_ptr->keytree_ptr = NULL;
+ ctrl_ptr->keytree_ptr = unc::vtndrvcache::KeyTree::create_cache();
+ }
+
+
+ cfg_list.clear();
+
+ ret_val_ = command_ptr_root->read_root_child(cfg_list, ctrl_ptr);
+ pfc_log_debug("%dVTN..cfg_list.size:", static_cast<int> (cfg_list.size()));
+
+ if (ret_val_) {
+ pfc_log_error("%s:Reading all vtn failed", PFC_FUNCNAME);
+ delete command_ptr_root;
+ return ret_val_;
+ } else {
+ pfc_log_debug("%s:Reading all vtn done", PFC_FUNCNAME);
+ ret_val_ = (drv_resp_code_t) ctrl_ptr->keytree_ptr->append_audit_node(
+ cfg_list);
+ if (ret_val_ != TREE_OK) {
+ pfc_log_debug("append_audit_node fail ..%s", PFC_FUNCNAME);
+ delete command_ptr_root;
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ fill_cache(cfg_list, ctrl_ptr->keytree_ptr,
+ command_ptr_root, ctrl_ptr, resp_code_);
+ }
+
+ delete command_ptr_root;
+ return DRVAPI_RESPONSE_SUCCESS;
}
-/**
-* @brief - Handling Request for the platform
-**/
+ /**
+ * @brief - This is a recursive function for filling cache
+ * @param[in]- cfg_list,KeyTree*,root_driver_command*,
+ * controller*,drv_resp_code_t
+ * @retval - void
+ **/
+template<typename key, typename val, typename command_ptr>
+void
+KtRequestHandler<key, val, command_ptr>::fill_cache(
+ std::vector<unc::vtndrvcache::ConfigNode*> &cfg_list,
+ unc::vtndrvcache::KeyTree *keytree_ptr,
+ root_driver_command* command_ptr_root,
+ unc::driver::controller* ctrl_ptr,
+ drv_resp_code_t &resp_code_) {
+ pfc_log_debug("inside fill_cache.");
+ std::vector<unc::vtndrvcache::ConfigNode*>::iterator it_node =
+ cfg_list.begin();
+ std::vector<unc::vtndrvcache::ConfigNode*>::iterator it_node_end =
+ cfg_list.end();
+ for (; it_node != it_node_end; it_node++) {
+ pfc_log_debug("for loop continue.");
+ std::vector<unc::vtndrvcache::ConfigNode*> cfg_child_list;
+ unc::vtndrvcache::ConfigNode * cfg_ptr =
+ static_cast<unc::vtndrvcache::ConfigNode*>(*it_node);
+ cfg_child_list.clear();
+ pfc_log_debug("before read_all_child");
+ uint32_t ret_code = command_ptr_root->read_all_child(cfg_ptr,
+ cfg_child_list, ctrl_ptr);
+
+ pfc_log_debug("cfg_child_list.size():%d",
+ static_cast<int> (cfg_child_list.size()));
+ if (!ret_code) {
+ pfc_log_debug("ret_code: %u", ret_code);
+ if (cfg_child_list.size()) {
+ resp_code_ =
+ (drv_resp_code_t)keytree_ptr->append_audit_node(cfg_child_list);
+ if (resp_code_) {
+ pfc_log_error("%s:append_audit_node failed"
+ "child with resp_code %u",
+ PFC_FUNCNAME, resp_code_);
+ break;
+ }
+ fill_cache(cfg_child_list, keytree_ptr, command_ptr_root,
+ ctrl_ptr, resp_code_);
+ } else {
+ pfc_log_debug("NO child for this node...");
+ }
+ } else {
+ pfc_log_debug("This NO is not exist. NO append_audit_node");
+ }
+ }
+}
-template<typename key, typename val, class command_ptr>
+ /**
+ * @brief - This method is the template Specialization for KT Controller command Execution
+ * @param[in]- ServerSession, keyif_drv_request_header_t, ControllerFramework*
+ * drv_resp_code_t,key_root_t,val_root_t
+ * @retval - drv_resp_code_t
+ **/
+template<>
drv_resp_code_t
-KtRequestHandler<key, val, command_ptr>::handle_request(
- pfc::core::ipc::ServerSession &sess,
- unc::driver::keyif_drv_request_header_t &request_header,
- unc::driver::ControllerFramework* ctrl_int) {
- pfc_log_info("%s: Entering Function.", PFC_FUNCNAME);
+KtRequestHandler<key_ctr_t, val_ctr_t, controller_command>::execute(
+ pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_request_header_t &request_header,
+ unc::driver::ControllerFramework* ctrl_int,
+ drv_resp_code_t &resp_code_,
+ key_ctr_t &key_generic_,
+ val_ctr_t &val_generic_) {
+ pfc_log_debug("%s: Entering Function.", PFC_FUNCNAME);
+ unc::driver::driver *drv_ptr = NULL;
+ unc::driver::controller* ctl_ptr = NULL;
+ std::string ctrl_name = std::string(request_header.controller_name);
+
+
+ switch (request_header.header.operation) {
+ case UNC_OP_CREATE: {
+ pfc_log_debug("%s: Creates new controller ", PFC_FUNCNAME);
+ drv_ptr = ctrl_int->GetDriverInstance((unc_keytype_ctrtype_t)
+ val_generic_.type);
+ PFC_ASSERT(drv_ptr != NULL);
+ ctl_ptr = drv_ptr->add_controller(key_generic_, val_generic_);
+ if (ctl_ptr) {
+ resp_code_ = DRVAPI_RESPONSE_SUCCESS;
+ } else {
+ resp_code_ = DRVAPI_RESPONSE_FAILURE;
+ return resp_code_;
+ }
+ ctrl_int->AddController(ctrl_name, ctl_ptr, drv_ptr);
+ break;
+ }
+ case UNC_OP_UPDATE: {
+ pfc_log_debug("%s: Updated Controller ", PFC_FUNCNAME);
+ VtnDrvRetEnum ctl_retval = VTN_DRV_RET_FAILURE;
+ ctl_retval = ctrl_int->GetControllerInstance(ctrl_name,
+ &ctl_ptr, &drv_ptr);
+ if (ctl_retval) {
+ pfc_log_error("%s:GetDriverByControllerName failed with rtcode,%u",
+ PFC_FUNCNAME, resp_code_);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
- memset(&key_generic_, 0, sizeof(key));
- memset(&val_generic_, 0, sizeof(val));
+ PFC_ASSERT(drv_ptr != NULL);
+ PFC_ASSERT(ctl_ptr != NULL);
- if (ctrl_int == NULL) {
- pfc_log_info("ctrl_int is null\n");
- return DRVAPI_RESPONSE_FAILURE;
- }
+ unc::driver::controller* update_ctl_ptr =
+ drv_ptr->update_controller(key_generic_,
+ val_generic_,
+ ctl_ptr);
+ VtnDrvRetEnum update_status =
+ ctrl_int->UpdateControllerConfiguration(ctrl_name,
+ update_ctl_ptr,
+ drv_ptr);
- resp_code_ = parse_request(sess, request_header);
+ if (update_status == VTN_DRV_RET_SUCCESS)
+ resp_code_ = DRVAPI_RESPONSE_SUCCESS;
+ else
+ resp_code_ = DRVAPI_RESPONSE_FAILURE;
- if (!resp_code_) {
- resp_code_ = execute(sess, request_header, ctrl_int);
- } else {
- pfc_log_error("%s: Failed to parse key and val struct(err = %u)",
- PFC_FUNCNAME, resp_code_);
- }
+ break;
+ }
- resp_code_ = handle_response(sess, request_header);
+ case UNC_OP_DELETE: {
+ pfc_log_debug("%s: deleted Controller ", PFC_FUNCNAME);
+ VtnDrvRetEnum ctl_retval = VTN_DRV_RET_FAILURE;
+ ctl_retval = ctrl_int->GetControllerInstance(ctrl_name,
+ &ctl_ptr, &drv_ptr);
+ if (ctl_retval) {
+ pfc_log_error("%s:GetDriverByControllerName failed with rtcode,%u",
+ PFC_FUNCNAME, resp_code_);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ PFC_ASSERT(drv_ptr != NULL);
+ PFC_ASSERT(ctl_ptr != NULL);
- if (resp_code_) {
- pfc_log_error("%s:. Failed to send response(err = %u)",
- PFC_FUNCNAME, resp_code_);
- }
+ VtnDrvRetEnum delete_status =
+ ctrl_int->RemoveControllerConfiguration(ctrl_name, ctl_ptr,
+ drv_ptr);
- return resp_code_;
+ if (delete_status == VTN_DRV_RET_SUCCESS)
+ resp_code_ = DRVAPI_RESPONSE_SUCCESS;
+ else
+ resp_code_ = DRVAPI_RESPONSE_FAILURE;
+ break;
+ }
+ default: {
+ pfc_log_debug("%s: Operation not Support ", PFC_FUNCNAME);
+ resp_code_ = DRVAPI_RESPONSE_FAILURE;
+ break;
+ }
+ }
+ pfc_log_debug("%s: Exiting Function.", PFC_FUNCNAME);
+ return resp_code_;
}
+ /**
+ * @brief - This method handles request received from platform layer
+ * @param[in]- ServerSession, keyif_drv_request_header_t,ControllerFramework*
+ * @retval - drv_resp_code_t
+ **/
+template<typename key, typename val, class command_ptr>
+drv_resp_code_t
+KtRequestHandler<key, val, command_ptr>::handle_request(
+ pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_request_header_t &request_header,
+ unc::driver::ControllerFramework* ctrl_int) {
+ pfc_log_debug("%s: Entering Function.", PFC_FUNCNAME);
+
+ drv_resp_code_t ret_val = DRVAPI_RESPONSE_FAILURE;
+ drv_resp_code_t resp_code_ = DRVAPI_RESPONSE_FAILURE;
+ key key_generic_;
+ val val_generic_;
+ memset(&key_generic_, 0, sizeof(key));
+ memset(&val_generic_, 0, sizeof(val));
+
+ if (ctrl_int == NULL) {
+ pfc_log_debug("ctrl_int is null\n");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
-/**
-* @brief - Converting ConfigNode pointer to command
-**/
+ ret_val = parse_request(sess, request_header, key_generic_, val_generic_);
+ if (!ret_val) {
+ resp_code_ = execute(sess, request_header, ctrl_int,
+ resp_code_, key_generic_, val_generic_);
+ } else {
+ pfc_log_error("%s: Failed to parse key and val struct(err = %u)",
+ PFC_FUNCNAME, resp_code_);
+ }
+
+ ret_val = handle_response(sess, request_header, ctrl_int,
+ key_generic_, val_generic_, resp_code_);
+
+ if (ret_val) {
+ pfc_log_error("%s:. Failed to send response(err = %u)",
+ PFC_FUNCNAME, resp_code_);
+ }
+
+ return resp_code_;
+}
+
+ /**
+ * @brief - This method forms the command from ConfigNode pointer
+ * @param[in]- ConfigNode*, controller*, driver*
+ * @retval - drv_resp_code_t
+ **/
template<typename key, typename val, class command_ptr>
drv_resp_code_t
KtRequestHandler<key, val, command_ptr>::execute_cmd(
- unc::vtndrvcache::ConfigNode *cfgptr,
- unc::driver::controller* conn,
- unc::driver::driver* drv_ptr) {
+ unc::vtndrvcache::ConfigNode *cfgptr,
+ unc::driver::controller* conn,
+ unc::driver::driver* drv_ptr) {
unc::vtndrvcache::CacheElementUtil<key, val, uint32_t> * ptr =
- dynamic_cast <unc::vtndrvcache::CacheElementUtil
- <key, val, uint32_t> * > (cfgptr);
+ dynamic_cast <unc::vtndrvcache::CacheElementUtil
+ <key, val, uint32_t> * > (cfgptr);
+
+ drv_resp_code_t resp_code_ = DRVAPI_RESPONSE_FAILURE;
- if(ptr == NULL) {
- pfc_log_debug("CacheElementUtil ptr is NULL");
- return DRVAPI_RESPONSE_FAILURE;
+ if (ptr == NULL) {
+ pfc_log_debug("CacheElementUtil ptr is NULL");
+ return DRVAPI_RESPONSE_FAILURE;
}
unc_key_type_t keytype = cfgptr->get_type();
unc::driver::driver_command * drv_command_ptr_ =
PFC_ASSERT(drv_command_ptr_ != NULL);
command_ptr * config_cmd_ptr = NULL;
config_cmd_ptr = static_cast<command_ptr *> (drv_command_ptr_);
- //unc_keytype_operation_t operat = cfgptr->get_operation();
uint32_t operat = cfgptr->get_operation();
resp_code_ = config_cmd_ptr->validate_op(
- *(ptr->getkey()),
- *(ptr->getval()),
- conn,
- operat);
+ *(ptr->getkey()),
+ *(ptr->getval()),
+ conn,
+ operat);
if (resp_code_ != DRVAPI_RESPONSE_SUCCESS) {
- pfc_log_debug("%s: Validate op failed with resp_code ,%u",
- PFC_FUNCNAME,resp_code_);
- return resp_code_;
+ pfc_log_debug("%s: Validate op failed with resp_code ,%u",
+ PFC_FUNCNAME, resp_code_);
+ return resp_code_;
}
switch (operat) {
case UNC_OP_CREATE:
- pfc_log_debug("%s: Translate Create Command string", PFC_FUNCNAME);
- resp_code_ = config_cmd_ptr->create_cmd(*(ptr->getkey()), *(ptr->getval()), conn);
+ pfc_log_debug("%s: Translate Create Command string", PFC_FUNCNAME);
+ resp_code_ = config_cmd_ptr->create_cmd(*(ptr->getkey()),
+ *(ptr->getval()), conn);
- break;
+ break;
case UNC_OP_DELETE:
pfc_log_debug("%s: Translate Delete Command string", PFC_FUNCNAME);
- resp_code_ = config_cmd_ptr->delete_cmd(*(ptr->getkey()), *(ptr->getval()), conn);
+ resp_code_ = config_cmd_ptr->delete_cmd(*(ptr->getkey()),
+ *(ptr->getval()), conn);
break;
pfc_log_debug("%s: Translate Update Command string", PFC_FUNCNAME);
- resp_code_ = config_cmd_ptr->update_cmd(*(ptr->getkey()), *(ptr->getval()), conn);
+ resp_code_ = config_cmd_ptr->update_cmd(*(ptr->getkey()),
+ *(ptr->getval()), conn);
break;
return resp_code_;
}
-/**
-* @brief - Sending Response to the platform
-**/
-
+ /**
+ * @brief - This method handles response from controller
+ * @param[in] - ServerSession, keyif_drv_request_header_t,ControllerFramework*,
+ * key,val,drv_resp_code_t
+ * @retval - drv_resp_code_t
+ **/
template<typename key, typename val, class command_ptr>
drv_resp_code_t
KtRequestHandler<key, val, command_ptr>::handle_response(
- pfc::core::ipc::ServerSession &sess,
- unc::driver::keyif_drv_request_header_t &request_header) {
+ pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_request_header_t &request_header,
+ unc::driver::ControllerFramework* ctrl_int,
+ key &key_generic_,
+ val &val_generic_,
+ drv_resp_code_t &resp_code_) {
pfc_log_debug("Entring Function %s..", PFC_FUNCNAME);
unc::driver::keyif_drv_response_header_t resp_hdr;
+ uint32_t err_= 0;
resp_hdr.result = resp_code_;
- create_response_header(request_header, resp_hdr);
+ create_response_header(request_header, resp_hdr, resp_code_);
resp_code_ = populate_response_header(sess, resp_hdr);
if (resp_code_) {
- pfc_log_error("%s: populate_response_header failed with ret_code ,%u",
- PFC_FUNCNAME,resp_code_);
- return resp_code_;
+ pfc_log_error("%s: populate_response_header failed with ret_code ,%u",
+ PFC_FUNCNAME, resp_code_);
+ return resp_code_;
+ }
+
+ err_ = sess.addOutput(resp_hdr.result);
+ if (err_ != 0) {
+ pfc_log_error("%s: Failed to send resp code:(err = %d)",
+ PFC_FUNCNAME, resp_code_);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ err_ = sess.addOutput((uint32_t) resp_hdr.key_type);
+ if (err_ != 0) {
+ pfc_log_error("%s: Failed to send driver data key type: (err = %d)",
+ PFC_FUNCNAME, resp_code_);
+ return DRVAPI_RESPONSE_FAILURE;
}
if (resp_hdr.header.data_type != UNC_DT_RUNNING) {
uint32_t ret_code = sess.addOutput(key_generic_);
if (ret_code) {
- pfc_log_error("%s: addOutput failed with ret_code ,%u", PFC_FUNCNAME,ret_code);
+ pfc_log_error("%s: addOutput failed with ret_code ,%u",
+ PFC_FUNCNAME, ret_code);
return DRVAPI_RESPONSE_FAILURE;
}
}
}
-/**
-* @brief - Creating Response Header
-**/
+ /**
+ * @brief - This method handles response from controller for Audit
+ * @param[in] - ServerSession, keyif_drv_request_header_t,ControllerFramework*,
+ * key_root_t,val_root_t,drv_resp_code_t
+ * @retval - drv_resp_code_t
+ **/
+template<>
+drv_resp_code_t
+KtRequestHandler<key_root_t, val_root_t, root_driver_command>::handle_response(
+ pfc::core::ipc::ServerSession &sess,
+ unc::driver::keyif_drv_request_header_t &request_header,
+ unc::driver::ControllerFramework* ctrl_int,
+ key_root_t &key_generic_,
+ val_root_t &val_generic_,
+ drv_resp_code_t &resp_code_) {
+ pfc_log_debug("Entring Function %s..", PFC_FUNCNAME);
+ driver* drv = NULL;
+ controller* ctr = NULL;
+ memset(&key_generic_, 0, sizeof(key_root_t));
+
+ VtnDrvRetEnum ctl_retval = VTN_DRV_RET_FAILURE;
+ unc::driver::keyif_drv_response_header_t resp_hdr;
+ resp_hdr.result = resp_code_;
+ pfc_log_debug("handle_response, resp_code_: %u", resp_code_);
+ pfc_log_debug("resp_hdr.result, resp_hdr.result: %u", resp_hdr.result);
+ create_response_header(request_header, resp_hdr, resp_code_);
+ resp_code_ = populate_response_header(sess, resp_hdr);
+ if (resp_code_) {
+ pfc_log_error("%s: populate_response_header failed"
+ "with ret_code root ,%u", PFC_FUNCNAME, resp_code_);
+ return resp_code_;
+ }
+ std::string ctr_name = resp_hdr.controller_name;
+ if (resp_hdr.header.data_type == UNC_DT_RUNNING) {
+ pfc_log_debug("UNC_DT_RUNNING processing");
+ ctl_retval = ctrl_int->GetDriverByControllerName(ctr_name,
+ &ctr,
+ &drv);
+
+ if (ctl_retval == VTN_DRV_RET_SUCCESS) {
+ std::auto_ptr<unc::vtndrvcache::CommonIterator>
+ itr_ptr(ctr->keytree_ptr->get_iterator());
+ uint32_t size = ctr->keytree_ptr->cfg_list_cnt();
+ pfc_log_debug("config node size is %d for controller %s",
+ size, ctr_name.c_str());
+ unc::vtndrvcache::ConfigNode *cfgnode = NULL;
+ // Not Success and Error Case check for Reps
+ if ((size == 0) &&
+ (resp_hdr.result == DRVAPI_RESPONSE_NO_SUCH_INSTANCE)) {
+ pfc_log_debug("%s: Value list empty and Response"
+ "header success", PFC_FUNCNAME);
+ pfc_log_debug("%s: Adding Root key only", PFC_FUNCNAME);
+ sess.addOutput((uint32_t) DRVAPI_RESPONSE_NO_SUCH_INSTANCE);
+ sess.addOutput((uint32_t) UNC_KT_ROOT);
+ sess.addOutput(key_generic_);
+ pfc_log_trace("ResponseHandler::%s Exiting", PFC_FUNCNAME);
+ return DRVAPI_RESPONSE_SUCCESS;
+ } else if (resp_hdr.result != DRVAPI_RESPONSE_SUCCESS) {
+ pfc_log_debug("%s: Response header result Error",
+ PFC_FUNCNAME);
+ pfc_log_debug("%s: Adding Root Key only", PFC_FUNCNAME);
+ sess.addOutput((uint32_t) DRVAPI_RESPONSE_FAILURE);
+ sess.addOutput((uint32_t) UNC_KT_ROOT);
+ sess.addOutput(key_generic_);
+ pfc_log_trace("ResponseHandler::%s Exiting", PFC_FUNCNAME);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ pfc_log_trace("Audit cfgnode need to add");
+ int err_ = sess.addOutput(resp_hdr.result);
+ if (err_ != 0) {
+ pfc_log_error("%s: Failed to send resp code audit:(err = %d)",
+ PFC_FUNCNAME, resp_code_);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ bool first = true;
+
+ for (cfgnode = itr_ptr->AuditFirstItem();
+ itr_ptr->IsDone() == false;
+ cfgnode = itr_ptr->NextItem() ) {
+ if (cfgnode == NULL) {
+ pfc_log_debug("cfgnode is NULL before get_type");
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ if (first) {
+ first = false;
+ } else {
+ sess.addOutput();
+ pfc_log_debug("Add empty success");
+ }
+ unc_key_type_t keytype = cfgnode->get_type();
+ pfc_log_debug("%u,keytype", keytype);
+
+ uint32_t ret_code = sess.addOutput((uint32_t)keytype);
+ if (ret_code) {
+ pfc_log_error("%s: addOutput failed with keytype ,%u",
+ PFC_FUNCNAME, ret_code);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ pfc_log_debug("Add key type success");
+
+ void* key = get_key_struct(cfgnode);
+ void* val = get_val_struct(cfgnode);
+ initialize_map();
+ pfc_ipcstdef_t* key_sdf =key_map_.find(keytype)->second;
+ pfc_ipcstdef_t* val_sdf =val_map_.find(keytype)->second;
+ ret_code = sess.addOutput(*key_sdf, key);
+ if (ret_code) {
+ pfc_log_error("%s: addOutput failed with ret_code ,%u",
+ PFC_FUNCNAME, ret_code);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+
+ pfc_log_debug("Add key success");
+ ret_code = sess.addOutput(*val_sdf, val);
+ if (ret_code) {
+ pfc_log_error("%s: addOutput failed with ret_code ,%u",
+ PFC_FUNCNAME, ret_code);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ pfc_log_debug("Add val success");
+ } // for loop
+ } else {
+ pfc_log_error("%s: unable to get controller/driver pointer",
+ PFC_FUNCNAME);
+ return DRVAPI_RESPONSE_FAILURE;
+ }
+ delete ctr->keytree_ptr;
+ ctr->keytree_ptr = NULL;
+ pfc_log_debug("UNC_DT_RUNNING processing complete");
+ }
+ pfc_log_debug("Exiting Function %s..", PFC_FUNCNAME);
+ return DRVAPI_RESPONSE_SUCCESS;
+}
+
+ /**
+ * @brief - This method creates the Response Header
+ * @param[in]- keyif_drv_response_header_t,
+ * keyif_drv_request_header_t,drv_resp_code_t
+ * @retval - void
+ */
template<typename key, typename val, class command_ptr>
void
KtRequestHandler<key, val, command_ptr>::create_response_header(
- unc::driver::keyif_drv_request_header_t &reqhdr,
- unc::driver::keyif_drv_response_header_t &resphdr) {
+ unc::driver::keyif_drv_request_header_t &reqhdr,
+ unc::driver::keyif_drv_response_header_t &resphdr,
+ drv_resp_code_t &resp_code_) {
memset(&resphdr, 0, sizeof(resphdr));
/* Copy parameters from the request header to the response header. */
memcpy(reinterpret_cast<void *>(&resphdr.header),
- reinterpret_cast<void *>(&reqhdr.header),
+ reinterpret_cast<void *>(&reqhdr.header),
sizeof(resphdr.header));
/* Set the result code. */
pfc_log_trace("RESP controller_name : %s", resphdr.controller_name);
resphdr.key_type = reqhdr.key_type;
-
}
-
-/**
-* @brief - populating response header
-**/
-
+ /**
+ * @brief - This method populates the Response Header
+ * @param[in]- ServerSession, keyif_drv_response_header_t
+ * @retval - drv_resp_code_t
+ **/
template<typename key, typename val, class command_ptr>
drv_resp_code_t
KtRequestHandler<key, val, command_ptr>::populate_response_header(
pfc::core::ipc::ServerSession &sess,
- unc::driver::keyif_drv_response_header_t &resp_hdr) {
+ unc::driver::keyif_drv_response_header_t &resp_hdr) {
pfc_log_trace("%s: Entering function", PFC_FUNCNAME);
uint32_t err = DRVAPI_RESPONSE_FAILURE;
reinterpret_cast<const char*> (resp_hdr.controller_name);
pfc_log_debug("%s: Request received from "
- "platfotm layer. controller_name = %s \n"
- "session_id = %u \n"
- "config_id = %u \n"
- "operation = %u \n"
- "option1 = %u \n"
- "option2 = %u \n"
- "data_type = %u \n"
- "result = %u \n", PFC_FUNCNAME, ctr_name, resp_hdr.header.session_id,
- resp_hdr.header.config_id, resp_hdr.header.operation,
- resp_hdr.header.option1, resp_hdr.header.option2,
- resp_hdr.header.data_type, resp_hdr.result);
+ "platfotm layer. controller_name = %s \n"
+ "session_id = %u \n"
+ "config_id = %u \n"
+ "operation = %u \n"
+ "option1 = %u \n"
+ "option2 = %u \n"
+ "data_type = %u \n"
+ "result = %u \n", PFC_FUNCNAME, ctr_name,
+ resp_hdr.header.session_id,
+ resp_hdr.header.config_id, resp_hdr.header.operation,
+ resp_hdr.header.option1, resp_hdr.header.option2,
+ resp_hdr.header.data_type, resp_hdr.result);
/* Sends session_id */
err = sess.addOutput(resp_hdr.header.session_id);
if (err) {
pfc_log_error("%s: Failed to send configurationid: (err = %d)",
PFC_FUNCNAME, err);
- return DRVAPI_RESPONSE_FAILURE;
+ return DRVAPI_RESPONSE_FAILURE;
}
/* Sends controller_name */
return DRVAPI_RESPONSE_FAILURE;
}
- err = sess.addOutput(resp_hdr.result);
-
- if (err) {
- pfc_log_error("%s: Failed to send resp code:(err = %d)", PFC_FUNCNAME, err);
- return DRVAPI_RESPONSE_FAILURE;
- }
-
- /* Sends key_type */
- err = sess.addOutput((uint32_t) resp_hdr.key_type);
- if (err) {
- pfc_log_error("%s: Failed to send driver data key type: (err = %d)",
- PFC_FUNCNAME, err);
- return DRVAPI_RESPONSE_FAILURE;
- }
-
pfc_log_trace("%s: Exiting function", PFC_FUNCNAME);
return DRVAPI_RESPONSE_SUCCESS;
}
-} // driver
-} // unc
+
+ /**
+ * @brief - This method initializes map for STDEF
+ * @retval - void
+ **/
+template<typename key, typename val, typename command_ptr>
+void
+KtRequestHandler<key, val, command_ptr>::initialize_map() {
+ uint32_t loop = 0;
+ unc_key_type_t KT[3] = {UNC_KT_VTN, UNC_KT_VBRIDGE, UNC_KT_VBR_IF};
+ for (loop = 0; loop < 3; loop++) {
+ switch (KT[loop]) {
+ case UNC_KT_VTN:
+ {
+ pfc_ipcstdef_t *stdef_k = new pfc_ipcstdef_t;
+ PFC_IPC_STDEF_INIT(stdef_k, key_vtn);
+ pfc_ipcstdef_t *stdef_v = new pfc_ipcstdef_t;
+ PFC_IPC_STDEF_INIT(stdef_v, val_vtn);
+ key_map_.insert(std::pair<unc_key_type_t, pfc_ipcstdef_t*>(KT[loop],
+ stdef_k));
+ val_map_.insert(std::pair<unc_key_type_t, pfc_ipcstdef_t*>(KT[loop],
+ stdef_v));
+ break;
+ }
+ case UNC_KT_VBRIDGE:
+ {
+ pfc_ipcstdef_t *stdef_kvbr = new pfc_ipcstdef_t;
+ PFC_IPC_STDEF_INIT(stdef_kvbr, key_vbr);
+ pfc_ipcstdef_t *stdef_vbr = new pfc_ipcstdef_t;
+ PFC_IPC_STDEF_INIT(stdef_vbr, val_vbr);
+ key_map_.insert(std::pair<unc_key_type_t, pfc_ipcstdef_t*>(KT[loop],
+ stdef_kvbr));
+ val_map_.insert(std::pair<unc_key_type_t, pfc_ipcstdef_t*>(KT[loop],
+ stdef_vbr));
+ break;
+ }
+ case UNC_KT_VBR_IF:
+ {
+ pfc_ipcstdef_t *stdef_kvbrif = new pfc_ipcstdef_t;
+ PFC_IPC_STDEF_INIT(stdef_kvbrif, key_vbr_if);
+ pfc_ipcstdef_t *stdef_vbrif = new pfc_ipcstdef_t;
+ PFC_IPC_STDEF_INIT(stdef_vbrif, pfcdrv_val_vbr_if);
+ key_map_.insert(std::pair<unc_key_type_t, pfc_ipcstdef_t*>(KT[loop],
+ stdef_kvbrif));
+ val_map_.insert(std::pair<unc_key_type_t, pfc_ipcstdef_t*>(KT[loop],
+ stdef_vbrif));
+ break;
+ }
+ default:
+ break;
+ }
+ }
+}
+} // namespace driver
+} // namespace unc
#endif
#include <vtndrvintf_defs.h>
#include <request_template.hh>
#include <map>
+#define PFC_IPCINT_EVSESS_OK 0
namespace unc {
namespace driver {
class VtnDrvIntf :public pfc::core::Module {
public:
-
/**
- *@brief: Constructor
+ * @brief : Constructor
+ * @param[in] : pfc_modattr_t*
**/
-
explicit VtnDrvIntf(const pfc_modattr_t* attr);
/**
- *@brief: Destructor
+ * @brief : TaskQueue*
+ */
+ pfc::core::TaskQueue* taskq_;
+
+ /**
+ * @brief : Destructor
**/
~VtnDrvIntf();
+
/**
- *@brief: This Function is called to load the
- * vtndrvintf module
+ * @brief : This Function is called to load the
+ * vtndrvintf module
+ * @return : PFC_TRUE/PFC_FALSE
**/
pfc_bool_t init(void);
/**
- *@brief: This Function is called to unload the
- * vtndrvintf module
+ * @brief : This Function is called to unload the
+ * vtndrvintf module
+ * @return : PFC_TRUE/PFC_FALSE
**/
pfc_bool_t fini(void);
/**
- *@brief: This Function is called to register the driver handler
- * with respect to the controller type
+ * @brief : This Function is called to register the driver handler
+ * with respect to the controller type
+ * @param[in] : driver *
+ * @return : VTN_DRV_RET_FAILURE /VTN_DRV_RET_SUCCESS
**/
VtnDrvRetEnum register_driver(driver *drvobj);
/**
- *@brief: This Function recevies the ipc request and process the same
- **/
-
+ * @brief : This Function recevies the ipc request and process the same
+ * @param[in] : sess, service
+ * @retval : PFC_IPCRESP_FATAL/PFC_IPCINT_EVSESS_OK
+ */
pfc_ipcresp_t ipcService(pfc::core::ipc::ServerSession& sess,
pfc_ipcid_t service);
/**
- *@brief: This function parse the sess and fills
- * keyif_drv_request_header_t
- **/
+ * @brief : This function parse the session and fills
+ * keyif_drv_request_header_t
+ * @param[in] : sess, request_hdr
+ * @retval : VTN_DRV_RET_FAILURE /VTN_DRV_RET_SUCCESS
+ */
VtnDrvRetEnum get_request_header(pfc::core::ipc::ServerSession*sess,
keyif_drv_request_header_t &request_hdr);
/**
- * @brief: This Function returns the kt_handler for
- * the appropriate key types
- **/
+ * @brief : This Function returns the kt_handler for
+ * the appropriate key types
+ * @param[in] : key type
+ * @retval : KtHandler*
+ */
KtHandler* get_kt_handler(unc_key_type_t kt);
+ /**
+ * @brief : This Function intialize ctrl_inst
+ * @param[in] : ctrl_inst
+ * @retval : None
+ */
+ void set_controller_instance(ControllerFramework* ctrl_inst) {
+ ctrl_inst_ = ctrl_inst;
+ }
+
private:
std::map <unc_key_type_t, unc::driver::KtHandler*> map_kt_;
pfc::core::ReadWriteLock kt_installer_wrlock_;
pfc::core::ReadWriteLock drvcmds_installer_wrlock_;
ControllerFramework* ctrl_inst_;
};
-} // driver
-} // unc
+} // namespace driver
+} // namespace unc
#endif
#ifndef _TCLIB_VTNDRVINTF_HH_
#define _TCLIB_VTNDRVINTF_HH_
-#include <pfcxx/module.hh>
#include <uncxx/tclib/tclib_interface.hh>
#include <tclib_module.hh>
-#include <unc/keytype.h>
-#include <unc/tc/external/tc_services.h>
-#include <controller_fw.hh>
#include <kt_handler.hh>
-#include <confignode.hh>
+#include <list>
#include <string>
#include <map>
class DriverTxnInterface : public unc::tclib::TcLibInterface {
public:
+ typedef std::list<std::string> ::iterator ctr_iter;
+ typedef std::map<unc_key_type_t, pfc_ipcstdef_t*> kt_map;
+ typedef std::map <unc_key_type_t, KtHandler*> kt_handler_map;
/**
* @brief - DriverTxnInterface constructor
- * */
+ */
DriverTxnInterface(ControllerFramework *,
- std::map <unc_key_type_t, KtHandler*>&);
+ kt_handler_map &);
/**
* @brief - DriverTxnInterface destructor
- * */
+ */
~DriverTxnInterface() {}
+ /**
+ * @brief - Handles commit vote request
+ * @param[in] - session id
+ * @param[in] - config id
+ * @param[in] - driver info
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleCommitVoteRequest(uint32_t session_id,
- uint32_t config_id,
- unc::tclib::TcDriverInfoMap& driver_info) {
+ uint32_t config_id,
+ unc::tclib::TcDriverInfoMap&
+ driver_info) {
return unc::tclib::TC_FAILURE;
}
+
+ /**
+ * @brief - Handles commit global commit
+ * @param[in] - session id
+ * @param[in] - config id
+ * @param[out] - driver info
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleCommitGlobalCommit(uint32_t session_id,
- uint32_t config_id,
- unc::tclib::TcDriverInfoMap& driver_info) {
+ uint32_t config_id,
+ unc::tclib::TcDriverInfoMap&
+ driver_info) {
return unc::tclib::TC_FAILURE;
}
+
+ /**
+ * @brief - Handles commit driver result
+ * @param[in] - config id
+ * @param[in] - commit phase type
+ * @param[in] - driver result
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleCommitDriverResult(uint32_t session_id,
- uint32_t config_id,
- unc::tclib::TcCommitPhaseType phase,
- unc::tclib::TcCommitPhaseResult driver_result) {
+ uint32_t config_id,
+ unc::tclib::TcCommitPhaseType
+ phase,
+ unc::tclib
+ ::TcCommitPhaseResult
+ driver_result) {
return unc::tclib::TC_FAILURE;
}
+
+ /**
+ * @brief - Handles Audit vote request
+ * @param[in] - session id
+ * @param[in] - controller type
+ * @param[in] - controller id
+ * @param[out] - driver info
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleAuditVoteRequest(uint32_t session_id,
- uint32_t ctr_type,
- std::string controller_id,
- unc::tclib::TcDriverInfoMap& driver_info) {
+ uint32_t ctr_type,
+ std::string controller_id,
+ unc::tclib::TcDriverInfoMap&
+ driver_info) {
return unc::tclib::TC_FAILURE;
}
+
+ /**
+ * @brief - Handles Audit Global commit
+ * @param[in] - session id
+ * @param[in] - controller type
+ * @param[in] - controller id
+ * @param[out] - driver info
+ * @param[out] - audit result
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleAuditGlobalCommit(uint32_t session_id,
- uint32_t ctr_type,
- std::string controller_id,
- unc::tclib::TcDriverInfoMap& driver_info,
- unc::tclib::TcAuditResult& audit_result) {
+ uint32_t ctr_type,
+ std::string controller_id,
+ unc::tclib::TcDriverInfoMap&
+ driver_info,
+ unc::tclib::TcAuditResult&
+ audit_result) {
return unc::tclib::TC_FAILURE;
}
+
+ /**
+ * @brief - Handles Audit Driver Request
+ * @param[in] - session id
+ * @param[in] - controller id
+ * @param[in] - commit phase type
+ * @param[in] - driver result
+ * @param[out] - audit result
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleAuditDriverResult(uint32_t session_id,
- std::string controller_id,
- unc::tclib::TcCommitPhaseType phase,
- unc::tclib::TcCommitPhaseResult driver_result,
- unc::tclib::TcAuditResult& audit_result) {
+ std::string controller_id,
+ unc::tclib::TcCommitPhaseType
+ phase,
+ unc::tclib
+ ::TcCommitPhaseResult
+ driver_result,
+ unc::tclib
+ ::TcAuditResult&
+ audit_result) {
return unc::tclib::TC_FAILURE;
}
+
+ /**
+ * @brief - Handles save configuration
+ * @param[in] - session id
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleSaveConfiguration(uint32_t session_id) {
return unc::tclib::TC_FAILURE;
}
+
+ /**
+ * @brief - Handles Abort candidate
+ * @param[in] - session id
+ * @param[in] - config id
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleAbortCandidate(uint32_t session_id,
uint32_t config_id) {
return unc::tclib::TC_FAILURE;
}
+
+ /**
+ * @brief - Handles clear startup
+ * @param[in] - session id
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleClearStartup(uint32_t session_id) {
return unc::tclib::TC_FAILURE;
}
+
+ /**
+ * @brief - Handle set up
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleSetup() {
return unc::tclib::TC_FAILURE;
}
+
+ /**
+ * @brief - Handle set up complete
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleSetupComplete() {
return unc::tclib::TC_FAILURE;
}
+
+ /**
+ * @brief - Retrieves the controller type
+ * @retval - returns UNC_CT_ODC
+ */
unc_keytype_ctrtype_t HandleGetControllerType(std::string controller_id) {
return UNC_CT_ODC;
}
+ /**
+ * @brief - Handles audit config
+ * @param[in] - datatype target
+ * @param[in] - enum of TCServiceType for operation failure
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleAuditConfig(unc_keytype_datatype_t db_target,
TcServiceType fail_oper) {
return unc::tclib::TC_FAILURE;
}
+
+ /**
+ * @brief - Handles commit transaction start
+ * @param[in] - session id
+ * @param[in] - config id
+ * @retval - returns TC_SUCCESS
+ */
unc::tclib::TcCommonRet HandleCommitTransactionStart(uint32_t session_id,
uint32_t config_id) {
return unc::tclib::TC_SUCCESS;
}
+ /**
+ * @brief - Handles commit transaction end
+ * @param[in] - session id
+ * @param[in] - config id
+ * @param[in] - transaction end result
+ * @retval - returns TC_SUCCESS
+ */
unc::tclib::TcCommonRet HandleCommitTransactionEnd(uint32_t session_id,
- uint32_t config_id,
- unc::tclib::TcTransEndResult end_result) {
+ uint32_t config_id,
+ unc::tclib
+ ::TcTransEndResult
+ end_result) {
return unc::tclib::TC_SUCCESS;
}
+ /**
+ * @brief - Handles COmmit Global Abort
+ * @param[in] - session id
+ * @param[in] - config id
+ * @param[in] - Tc Commit operation abort phase status
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleCommitGlobalAbort(uint32_t session_id,
- uint32_t config_id,
- unc::tclib::TcCommitOpAbortPhase fail_phase) {
- return unc::tclib::TC_SUCCESS;
+ uint32_t config_id,
+ unc::tclib
+ ::TcCommitOpAbortPhase
+ fail_phase) {
+ return unc::tclib::TC_FAILURE;
}
+ /**
+ * @brief - Handles Audit Start
+ * @param[in] - session id
+ * @param[in] - controller type
+ * @param[in] - controller id
+ * @retval - returns TC_SUCCESS
+ */
unc::tclib::TcCommonRet HandleAuditStart(uint32_t session_id,
unc_keytype_ctrtype_t ctr_type,
std::string controller_id) {
return unc::tclib::TC_SUCCESS;
}
+ /**
+ * @brief - Handles Audit end
+ * @param[in] - session id
+ * @param[in] - controller type
+ * @param[in] - controller id
+ * @param[in] - audit result
+ * @retval - returns TC_SUCCESS
+ */
unc::tclib::TcCommonRet HandleAuditEnd(uint32_t session_id,
- unc_keytype_ctrtype_t ctr_type,
- std::string controller_id,
- unc::tclib::TcAuditResult audit_result) {
+ unc_keytype_ctrtype_t ctr_type,
+ std::string
+ controller_id,
+ unc::tclib::TcAuditResult
+ audit_result) {
return unc::tclib::TC_SUCCESS;
}
+ /**
+ * @brief - Handles Audit Transaction Start
+ * @param[in] - session id
+ * @param[in] - controller type
+ * @param[in] - controller id
+ * @retval - returns TC_SUCCESS
+ */
unc::tclib::TcCommonRet HandleAuditTransactionStart(uint32_t session_id,
- unc_keytype_ctrtype_t ctr_type,
- std::string controller_id) {
+ unc_keytype_ctrtype_t
+ ctr_type,
+ std::string
+ controller_id) {
return unc::tclib::TC_SUCCESS;
}
+ /**
+ * @brief - Handles Audit Transaction End
+ * @param[in] - session id
+ * @param[in] - controller type
+ * @param[in] - controller id
+ * @param[in] - TcCommonRet enum value
+ * @retval - returns TC_SUCCESS
+ */
unc::tclib::TcCommonRet HandleAuditTransactionEnd(uint32_t session_id,
- unc_keytype_ctrtype_t ctr_type,
- std::string controller_id,
- unc::tclib::TcTransEndResult end_result) {
+ unc_keytype_ctrtype_t
+ ctr_type,
+ std::string
+ controller_id,
+ unc::tclib::TcTransEndResult
+ end_result) {
return unc::tclib::TC_SUCCESS;
}
-
+ /**
+ * @brief - Handles Audit Vote
+ * @param[in] - session id
+ * @param[in] - controller id
+ * @param[in] - Tc controllers list
+ * @retval - returns TcCommonRet enum value
+ */
unc::tclib::TcCommonRet HandleAuditVoteRequest(uint32_t session_id,
- std::string controller_id,
- unc::tclib::TcControllerList controllers) {
- return unc::tclib::TC_SUCCESS;
- }
+ std::string controller_id,
+ unc::tclib
+ ::TcControllerList
+ controllers);
+ /**
+ * @brief - Handles Audit Global commit
+ * @param[in] - controller id
+ * @param[in] - Tc controller list
+ * @retval - returns TcCommitRet enum
+ */
unc::tclib::TcCommonRet HandleAuditGlobalCommit(uint32_t session_id,
- std::string controller_id,
- unc::tclib::TcControllerList controllers) {
- return unc::tclib::TC_SUCCESS;
- }
+ std::string controller_id,
+ unc::tclib::TcControllerList
+ controllers);
+ /**
+ * @brief - Handles Audit Global Abort
+ * @param[in] - controller type
+ * @param[in] - controller id
+ * @param[in] - Tc Audit Operation Abort Phase
+ * @retval - returns TC_FAILURE
+ */
unc::tclib::TcCommonRet HandleAuditGlobalAbort(uint32_t session_id,
- unc_keytype_ctrtype_t ctr_type,
- std::string controller_id,
- unc::tclib::TcAuditOpAbortPhase fail_phase) {
- return unc::tclib::TC_SUCCESS;
+ unc_keytype_ctrtype_t ctr_type,
+ std::string controller_id,
+ unc::tclib::TcAuditOpAbortPhase
+ fail_phase) {
+ return unc::tclib::TC_FAILURE;
}
+ /**
+ * @brief - Retrieves the controller type
+ * @retval - returns UNC_CT_ODC
+ */
+
unc_keytype_ctrtype_t HandleGetControllerType() {
return UNC_CT_ODC;
}
/**
- * @brief - Method to handle TC vote request
- * */
+ * @brief - Method to handle TC vote request
+ * @param[in] - session id
+ * @param[in] - config id
+ * @param[in] - Tc controllers list
+ * @retval - TcCommonRet enum value
+ */
unc::tclib::TcCommonRet HandleCommitVoteRequest(uint32_t session_id,
- uint32_t config_id,
- unc::tclib::TcControllerList
- controllers);
+ uint32_t config_id,
+ unc::tclib::TcControllerList
+ controllers);
/**
- * @brief - Method to handle TC commit request
- * */
+ * @brief - Method to handle TC commit request
+ * @param[in] - session id
+ * @param[in] - config id
+ * @param[in] - Tc controllers list
+ * @retval - TcCommonRet enum value
+ */
unc::tclib::TcCommonRet HandleCommitGlobalCommit(uint32_t session_id,
- uint32_t config_id,
- unc::tclib::TcControllerList controllers);
+ uint32_t config_id,
+ unc::tclib::TcControllerList
+ controllers);
/**
- * @brief - Method to initialize map_kt_
- * */
+ * @brief - Method to initialize pfc_ipcstdef_t pointer with keytype
+ * @retval - None
+ */
void initialize_map(void);
+
/**
- * @brief - Method to Abort the controller which failed in VOTE
- * */
+ * @brief - Method to Abort the controller which failed in VOTE
+ * @param[in] - Tc controller list
+ * @retval - None
+ */
void AbortControllers(unc::tclib::TcControllerList
- controllers);
+ controllers);
private:
ControllerFramework* crtl_inst_;
- std::map<unc_key_type_t, pfc_ipcstdef_t*> key_map_;
- std::map<unc_key_type_t, pfc_ipcstdef_t*> val_map_;
- std::map <unc_key_type_t, KtHandler*> kt_handler_map_;
+ kt_map key_map_, val_map_;
+ kt_handler_map kt_handler_map_;
};
} // namespace driver
} // namespace unc
* Copyright (c) 2012-2013 NEC Corporation
* All rights reserved.
*
- * This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
*/
#ifndef __VTNDRVINTF_DEFS_H_
#define __VTNDRVINTF_DEFS_H_
typedef enum {
- VTN_DRV_RET_SUCCESS=0,
+ VTN_DRV_RET_SUCCESS = 0,
VTN_DRV_RET_FAILURE
}VtnDrvRetEnum;
#endif
namespace driver {
/**
- * VtnDrvIntf():
* @brief : constructor
*/
-
VtnDrvIntf::VtnDrvIntf(const pfc_modattr_t* attr)
-: Module(attr), ctrl_inst_(new ControllerFramework()) {
+: Module(attr), taskq_(NULL), ctrl_inst_(NULL) {
pfc_log_debug("Entering constructor %s..", PFC_FUNCNAME);
pfc_log_debug("Existing constructor %s..", PFC_FUNCNAME);
}
*/
VtnDrvIntf::~VtnDrvIntf() {
pfc_log_debug("Entering default desstructor %s..", PFC_FUNCNAME);
- if(ctrl_inst_)
+ if (ctrl_inst_)
delete ctrl_inst_;
pfc_log_debug("Existing default desstructor %s..", PFC_FUNCNAME);
}
/**
- * Init:
* @brief : This Function is called to load the vtndrvintf module
* @param[in] : None
- * @retval : pfc_bool_t
+ * @retval : PFC_FALSE/PFC_TRUE
*/
pfc_bool_t VtnDrvIntf::init(void) {
pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
- /****Initialize KT_Handler_Instance*****/
+ uint32_t concurrency = 1;
+ taskq_ = pfc::core::TaskQueue::create(concurrency);
+ ControllerFramework *ctrl_inst_= new ControllerFramework(taskq_);
+ set_controller_instance(ctrl_inst_);
+
+ // Initialize KT_Handler_Instance
KtHandler* vtn_req = new unc::driver::KtRequestHandler<key_vtn_t,
val_vtn_t,
unc::driver::vtn_driver_command>();
UNC_KT_CONTROLLER,
ctrl_req));
+ KtHandler* ktroot_req = new unc::driver::KtRequestHandler<key_root_t,
+ val_root_t,
+ unc::driver::root_driver_command>();
+ if (ktroot_req == NULL) {
+ pfc_log_error("KT_ROOT requrest handler is NULL");
+ return PFC_FALSE;
+ }
+ map_kt_.insert(std::pair<unc_key_type_t, unc::driver::KtHandler*>(
+ UNC_KT_ROOT,
+ ktroot_req));
+
unc::tclib::TcLibModule* TcLibModule_obj =
static_cast<unc::tclib::TcLibModule*>(pfc::core::Module::getInstance(
"tclib"));
- if(TcLibModule_obj == NULL) {
+ if (TcLibModule_obj == NULL) {
pfc_log_error("tclib getInstance failed");
- return PFC_TRUE;
+ return PFC_FALSE;
}
- if(ctrl_inst_ == NULL) {
+ if (ctrl_inst_ == NULL) {
pfc_log_error("controller instance not created");
return PFC_FALSE;
}
/**
- * fini:
* @brief : This Function is called to unload the vtndrvintf module
- * @param[in] : void
- * @retval : pfc_bool_t
+ * @param[in] : None
+ * @retval : PFC_TRUE
*/
pfc_bool_t VtnDrvIntf::fini(void) {
pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
+
+ if (taskq_) {
+ delete taskq_;
+ taskq_ = NULL;
+ }
+
+ if (ctrl_inst_) {
+ delete ctrl_inst_;
+ ctrl_inst_ = NULL;
+ }
+
pfc_log_debug("%s: Exiting function..", PFC_FUNCNAME);
return PFC_TRUE;
}
/**
- * ipcService:
* @brief : This Function recevies the ipc request and process the same
- * @param[in] : sess
- * @retval : pfc_ipcresp_t
+ * @param[in] : sess, service
+ * @retval : PFC_IPCRESP_FATAL/PFC_IPCINT_EVSESS_OK
*/
pfc_ipcresp_t VtnDrvIntf::ipcService(pfc::core::ipc::ServerSession& sess,
- pfc_ipcid_t service) {
- pfc_log_info("%s: Entering function..", PFC_FUNCNAME);
+ pfc_ipcid_t service) {
+ pfc_log_debug("%s: Entering function..", PFC_FUNCNAME);
pfc::core::ipc::ServerSession* p_sess=&sess;
keyif_drv_request_header_t request_hdr;
}
if (map_kt_.empty()) {
- pfc_log_info("map_kt empty");
+ pfc_log_debug("map_kt empty");
return PFC_IPCRESP_FATAL;
}
KtHandler *ptr_KT_Handler = get_kt_handler(request_hdr.key_type);
if (ptr_KT_Handler == NULL) {
- pfc_log_info("Key Type Not Supported %d", request_hdr.key_type);
+ pfc_log_debug("Key Type Not Supported %d", request_hdr.key_type);
return PFC_IPCRESP_FATAL;
}
ptr_KT_Handler->handle_request(sess, request_hdr, ctrl_inst_);
pfc_log_debug("%s: Exiting function..", PFC_FUNCNAME);
- return 0;
+ return PFC_IPCINT_EVSESS_OK;
}
/**
- * GetRequestHeader:
* @brief : This function parse the session and fills
* keyif_drv_request_header_t
* @param[in] : sess, request_hdr
- * @retval : VtnDrvRetEnum
+ * @retval : VTN_DRV_RET_FAILURE /VTN_DRV_RET_SUCCESS
*/
-VtnDrvRetEnum VtnDrvIntf::get_request_header(pfc::core::ipc::ServerSession* sess,
+VtnDrvRetEnum VtnDrvIntf::get_request_header(
+ pfc::core::ipc::ServerSession* sess,
keyif_drv_request_header_t &request_hdr) {
pfc_log_debug("Entering Function %s..", PFC_FUNCNAME);
}
request_hdr.key_type=(unc_key_type_t)keytype;
- pfc_log_info("Keytype is %d", request_hdr.key_type);
+ pfc_log_debug("Keytype is %d", request_hdr.key_type);
const char *ctr_name;
err = sess->getArgument(IPC_CONTROLLER_ID_INDEX, ctr_name);
}
/**
- * get_kt_handler:
* @brief : This Function returns the kt_handler for
* the appropriate key types
- * @param[in] : kt
- * @retval : kt_handler
+ * @param[in] : key type
+ * @retval : KtHandler*
*/
KtHandler* VtnDrvIntf::get_kt_handler(unc_key_type_t kt) {
return map_kt_.find(kt)->second;
}
/**
- * RegisterDriver:
* @brief : This Function is called to register the driver handler
* with respect to the controller type
* @param[in] : *drvobj
- * @retval : uint32_t
+ * @retval : VTN_DRV_RET_SUCCESS
*/
VtnDrvRetEnum VtnDrvIntf:: register_driver(driver *drvobj) {
unc_keytype_ctrtype_t ctr_type = drvobj->get_controller_type();
ctrl_inst_->RegisterDriver(ctr_type, drvobj);
return VTN_DRV_RET_SUCCESS;
}
-} // driver
-} // unc
+} // namespace driver
+} // namespace unc
PFC_MODULE_IPC_DECL(unc::driver::VtnDrvIntf, 3);
* @brief : constructor
*/
DriverTxnInterface::DriverTxnInterface(ControllerFramework* ctrl_frame,
- std::map <unc_key_type_t, KtHandler*> &map_kt)
+ kt_handler_map &map_kt)
: crtl_inst_(ctrl_frame), kt_handler_map_(map_kt) {
initialize_map();
}
/**
-* @Description :This functions invokes when TC sends VOTE request to driver
-* @param[in] :session_id - ipc session id used for TC validation
+* @brief : This functions invokes when TC sends VOTE request to driver
+* @param[in] : session_id - ipc session id used for TC validation
config_id - configuration id used for TC validation
controllers -list contains controller names
-* @return :TC_SUCCESS is returned when VOTE is success for all
+* @return : TC_SUCCESS is returned when VOTE is success for all
* controllers.
-* TC_SUCCESS is returned when VOTE is failure for any
+* TC_FAILURE is returned when VOTE is failure for any
* one of the controller in the list
**/
unc::tclib::TcCommonRet DriverTxnInterface::HandleCommitVoteRequest(
uint32_t config_id,
unc::tclib::TcControllerList
controllers) {
- pfc_log_info("inside HandleCommitVoteRequest");
+ pfc_log_debug("inside HandleCommitVoteRequest");
std::string ctr_name;
driver* drv = NULL;
controller* ctr = NULL;
unc::tclib::TcCommonRet ret_code = unc::tclib::TC_SUCCESS;
+ ctr_iter iter;
+
+ unc::tclib::TcLibModule* tclib_ptr =
+ static_cast<unc::tclib::TcLibModule*>
+ (unc::tclib::TcLibModule::getInstance("tclib"));
+
+ if (tclib_ptr == NULL) {
+ pfc_log_error("tclib getInstance returned NULL");
+ return unc::tclib::TC_FAILURE;
+ }
- std::list<std::string> ::iterator iter;
for (iter = controllers.begin(); iter != controllers.end(); iter++) {
pfc_bool_t vote = false;
ctr_name = *iter;
uint32_t err_code = crtl_inst_->GetDriverByControllerName(ctr_name,
&ctr, &drv);
+ pfc_log_error("Inside controller list iteration %d", err_code);
if (err_code == 0) {
+ if (ctr != NULL) {
+ pfc_log_error("gettin conn status..ctr nt NULL");
+ if (ctr->get_connection_status() == CONNECTION_DOWN) {
+ // check controller connection status, if down send disconnected
+ pfc_log_debug("%s Controller status is down, send disconnected", \
+ PFC_FUNCNAME);
+ tclib_ptr->TcLibWriteControllerInfo(ctr_name,
+ (uint32_t)DRVAPI_RESPONSE_CONTROLLER_DISCONNECTED, 0);
+ continue;
+ }
+ }
vote = drv->is_2ph_commit_support_needed();
if (vote) {
ret_code = drv->HandleVote(ctr);
AbortControllers(controllers);
return unc::tclib::TC_FAILURE;
} else {
- pfc_log_info("HandleVote success for controller:%s",
+ pfc_log_debug("HandleVote success for controller:%s",
ctr_name.c_str());
}
} else {
- unc::tclib::TcLibModule* tclib_ptr =
- static_cast<unc::tclib::TcLibModule*>
- (unc::tclib::TcLibModule::getInstance("tclib"));
- if (tclib_ptr == NULL) {
- pfc_log_error("tclib getInstance returned NULL");
- return unc::tclib::TC_FAILURE;
- }
+ pfc_log_debug("TcLibWriteControllerInfo for controller:%s",
+ ctr_name.c_str());
tclib_ptr->TcLibWriteControllerInfo(ctr_name,
(uint32_t)DRVAPI_RESPONSE_SUCCESS, 0);
}
}
}
- pfc_log_info("Exiting HandleCommitVoteRequest");
+ pfc_log_debug("Exiting HandleCommitVoteRequest");
return ret_code;
}
+/**
+* @brief : This functions invokes when TC sends Audit VOTE request to drv
+* @param[in] : session_id - ipc session id used for TC validation
+* controller_id - controller_id used for TC validation
+* controllers -list contains controller names
+* @return : TC_SUCCESS is returned when VOTE is success for all
+* controllers.
+* TC_FAILURE is returned when VOTE is failure for any
+* one of the controller in the list
+*/
+
+unc::tclib::TcCommonRet
+DriverTxnInterface::HandleAuditVoteRequest(uint32_t session_id,
+ std::string controller_id,
+ unc::tclib::TcControllerList controllers) {
+ uint32_t config_id = 0;
+ unc::tclib::TcCommonRet ret_code = unc::tclib::TC_FAILURE;
+ ret_code = HandleCommitVoteRequest(session_id, config_id, controllers);
+ if (ret_code == unc::tclib::TC_FAILURE) {
+ pfc_log_debug("Audit VOTE Failed");
+ return unc::tclib::TC_FAILURE;
+ }
+ return unc::tclib::TC_SUCCESS;
+}
+
+/**
+* @brief : This functions invokes when TC sends AuditGlobalCommit to drv
+* @param[in] : session_id - ipc session id used for TC validation
+* controller_id - controller_id used for TC validation
+* controllers -list contains controller names
+* @return : TC_SUCCESS is returned when VOTE is success for all
+* controllers.
+* TC_FAILURE is returned when VOTE is failure for any
+* one of the controller in the list
+*/
+unc::tclib::TcCommonRet
+DriverTxnInterface::HandleAuditGlobalCommit(uint32_t session_id,
+ std::string controller_id,
+ unc::tclib::TcControllerList controllers) {
+ uint32_t config_id = 0;
+ unc::tclib::TcCommonRet ret_code = unc::tclib::TC_FAILURE;
+ ret_code = HandleCommitGlobalCommit(session_id, config_id, controllers);
+ if (ret_code == unc::tclib::TC_FAILURE) {
+ pfc_log_debug("Audit Global commit Failed");
+ return unc::tclib::TC_FAILURE;
+ }
+ return unc::tclib::TC_SUCCESS;
+}
+
/**
* @Description :This functions invokes when Vote is failed for controller
* @param[in] :controllers -list contains controller names
**/
void DriverTxnInterface::AbortControllers(unc::tclib::TcControllerList
controllers) {
- pfc_log_info("inside AbortControllers");
+ pfc_log_debug("inside AbortControllers");
std::string ctr_name;
driver* drv = NULL;
controller* ctr = NULL;
uint32_t ret_code = unc::tclib::TC_SUCCESS;
- std::list<std::string> ::iterator iter;
+ ctr_iter iter;
for (iter = controllers.begin(); iter != controllers.end(); iter++) {
pfc_bool_t Abort = false;
ctr_name = *iter;
if (Abort)
ret_code = drv->HandleAbort(ctr);
if (ret_code == unc::tclib::TC_SUCCESS) {
- pfc_log_info("abort controller :%s ret_code %d", ctr_name.c_str(),
+ pfc_log_debug("abort controller :%s ret_code %d", ctr_name.c_str(),
ret_code);
} else {
- pfc_log_info("abort controller :%s failed ret_code %d",
+ pfc_log_debug("abort controller :%s failed ret_code %d",
ctr_name.c_str(), ret_code);
}
}
} // for loop
- pfc_log_info("Exiting AbortControllers");
+ pfc_log_debug("Exiting AbortControllers");
}
+
/**
* @Description :This functions invokes when TC sends COMMIT request to driver
* @param[in] :session_id - ipc session id used for TC validation
uint32_t config_id,
unc::tclib::TcControllerList
controllers) {
- pfc_log_info("inside HandleCommitGlobalCommit");
+ pfc_log_debug("inside HandleCommitGlobalCommit");
std::string ctr_name;
driver* drv = NULL;
controller* ctr = NULL;
uint32_t retc = DRVAPI_RESPONSE_FAILURE;
- std::list<std::string> ::iterator iter;
- unc::tclib::TcCommonRet ret_code = unc::tclib::TC_FAILURE;
+ ctr_iter iter;
+ unc::tclib::TcCommonRet ret_code = unc::tclib::TC_SUCCESS;
+ unc::tclib::TcLibModule* tclib_ptr =
+ static_cast<unc::tclib::TcLibModule*>
+ (unc::tclib::TcLibModule::getInstance("tclib"));
+
+ if (tclib_ptr == NULL) {
+ pfc_log_fatal("tclib getInstance returned NULL");
+ return unc::tclib::TC_FAILURE;
+ }
for (iter = controllers.begin(); iter != controllers.end(); iter++) {
pfc_bool_t commit = false;
ctr_name = *iter;
uint32_t err_code = crtl_inst_->GetDriverByControllerName(ctr_name,
&ctr, &drv);
- if (err_code == 0) {
+ if (ctr == NULL) {
+ pfc_log_error("ctr is null : HandleCommitGlobalCommit");
+ return ret_code;
+ }
+ if (drv == NULL) {
+ pfc_log_error("drv is null : HandleCommitGlobalCommit");
+ return ret_code;
+ }
+
+ if (err_code == VTN_DRV_RET_SUCCESS) {
+ // check controller connection status, if down send disconnected
+ if (ctr->get_connection_status() == CONNECTION_DOWN) {
+ pfc_log_debug("%s Controller status is down, send disconnected", \
+ PFC_FUNCNAME);
+ tclib_ptr->TcLibWriteControllerInfo(ctr_name,
+ (uint32_t)DRVAPI_RESPONSE_CONTROLLER_DISCONNECTED, 0);
+ ret_code = unc::tclib::TC_SUCCESS;
+ continue;
+ }
commit = drv->is_2ph_commit_support_needed();
if (commit) {
ret_code = drv->HandleCommit(ctr);
if (ret_code != unc::tclib::TC_SUCCESS)
+ pfc_log_fatal("Global Commit Failure in driver");
return unc::tclib::TC_FAILURE;
} else {
if (ctr->keytree_ptr != NULL) {
unc::vtndrvcache::CommonIterator* itr_ptr =
ctr->keytree_ptr->get_iterator();
+ if (itr_ptr == NULL) {
+ pfc_log_fatal("%s: exit. itr_ptr is null", PFC_FUNCNAME);
+ return unc::tclib::TC_FAILURE;
+ }
uint32_t size = ctr->keytree_ptr->cfg_list_count();
- pfc_log_info("config node size is %d for controller %s",
+ pfc_log_debug("config node size is %d for controller %s",
size, ctr_name.c_str());
unc::vtndrvcache::ConfigNode *cfgnode = NULL;
for (cfgnode = itr_ptr->FirstItem(); itr_ptr->IsDone() == false;
cfgnode = itr_ptr->NextItem() ) {
unc_key_type_t keytype = cfgnode->get_type();
- pfc_log_info("%u,keytype", keytype);
+ pfc_log_debug("%u,keytype", keytype);
KtHandler* hnd_ptr = kt_handler_map_.find(keytype)->second;
PFC_ASSERT(hnd_ptr != NULL);
if (retc == DRVAPI_RESPONSE_SUCCESS)
ret_code = unc::tclib::TC_SUCCESS;
if (ret_code != unc::tclib::TC_SUCCESS) {
- unc::tclib::TcLibModule* tclib_ptr =
- static_cast<unc::tclib::TcLibModule*>
- (unc::tclib::TcLibModule::getInstance("tclib"));
- if (tclib_ptr == NULL) {
- pfc_log_error("tclib getInstance returned NULL");
- return unc::tclib::TC_FAILURE;
- }
- tclib_ptr->TcLibWriteControllerInfo(ctr_name, ret_code, 1);
+ pfc_log_debug("%u,execute_cmd not success", keytype);
+ tclib_ptr->TcLibWriteControllerInfo(ctr_name, retc, 1);
void* key = hnd_ptr->get_key_struct(cfgnode);
void* val = hnd_ptr->get_val_struct(cfgnode);
pfc_ipcstdef_t* key_sdf =key_map_.find(keytype)->second;
key, val);
}
}
+ if (itr_ptr != NULL)
+ delete itr_ptr;
} else {
- pfc_log_error("unable to get keytree pointer");
+ pfc_log_fatal("no Cache in Controller");
return unc::tclib::TC_FAILURE;
}
}
} else {
pfc_log_fatal("unable to get controller/driver connection pointer");
+ return unc::tclib::TC_FAILURE;
}
if (ret_code == unc::tclib::TC_SUCCESS) {
unc::tclib::TcLibModule* tclib_ptr =
tclib_ptr->TcLibWriteControllerInfo(ctr_name, retc, 0);
}
ctr->keytree_ptr->clear_commit_cache();
- pfc_log_info("Config Node cleared for %s", ctr_name.c_str());
+ pfc_log_debug("Config Node cleared for %s", ctr_name.c_str());
+ if (ctr->keytree_ptr != NULL) {
+ pfc_log_debug("delete keytree_ptr for:%s", ctr_name.c_str());
+ delete ctr->keytree_ptr;
+ ctr->keytree_ptr = NULL;
+ }
} // for loop
- pfc_log_info("Exiting HandleCommitGlobalCommit");
+ pfc_log_debug("Exiting HandleCommitGlobalCommit");
return ret_code;
}