aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl/sysrepo-plugins/hicn-plugin/plugin/model
diff options
context:
space:
mode:
authorAlberto Compagno <acompagn+fdio@cisco.com>2019-12-19 12:22:57 +0000
committerGerrit Code Review <gerrit@fd.io>2019-12-19 12:22:57 +0000
commitee4e2645e36a34ee736d320832349bcfa54ab306 (patch)
treec8708a4b188f39d4ce94d04a0a6810c900864210 /ctrl/sysrepo-plugins/hicn-plugin/plugin/model
parentf2ef661f26d13ee55976f1578e5f76f7ddb20df7 (diff)
parenta0f325f0b6ca0129ed339ac4ac94d7159e926977 (diff)
Merge "[HICN-440] Add comments to hicn sysrepo plugin code"
Diffstat (limited to 'ctrl/sysrepo-plugins/hicn-plugin/plugin/model')
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c144
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h91
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.h37
3 files changed, 143 insertions, 129 deletions
diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c
index 8db0a6238..d73e6145a 100644
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c
+++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c
@@ -13,6 +13,13 @@
* limitations under the License.
*/
+
+
+/** @file hicn_model.c
+ * @brief This file contains implementations of the main calls
+ */
+
+
#define _GNU_SOURCE
#include <stdio.h>
@@ -39,14 +46,29 @@ DEFINE_VAPI_MSG_IDS_HICN_API_JSON
// Shared local variables between state and RPCs
+/**
+ * @brief this shared variable keeps the hicn state
+ */
volatile hicn_state_t * hicn_state = NULL;
-volatile hicn_strategy_t * hicn_strategy = NULL;
+/**
+ * @brief this shared variable keeps hicn strategies
+ */
volatile hicn_strategies_t * hicn_strategies =NULL;
-volatile hicn_route_t * hicn_route = NULL;
-volatile hicn_face_ip_params_t * hicn_face_ip_params = NULL;
+/**
+ * @brief this shared variable keeps statistics of hicn faces
+ */
volatile hicn_faces_t * hicn_faces = NULL;
+/**
+ * @brief this shared variable keeps routes information in hicn
+ */
volatile hicn_routes_t * hicn_routes = NULL;
+/**
+ * @brief this shared variable is the link list to maintain all the faces (up to MAX_FACES)
+ */
struct hicn_faces_s * fcurrent = NULL;
+/**
+ * @brief this shared variable is the link list to maintain all the routes
+ */
struct hicn_routes_s * rcurrent = NULL;
@@ -55,15 +77,9 @@ static int init_buffer(void){
hicn_state = memalign(MEM_ALIGN, sizeof(hicn_state_t) );
memset((hicn_state_t *)hicn_state, 0 , sizeof(hicn_state_t) );
- hicn_strategy = memalign(MEM_ALIGN, sizeof(hicn_strategy_t) );
- memset((hicn_strategy_t *) hicn_strategy, 0 , sizeof(hicn_strategy_t) );
-
hicn_strategies = memalign(MEM_ALIGN, sizeof(hicn_strategies_t) );
memset((hicn_strategies_t *) hicn_strategies, 0 , sizeof(hicn_strategies_t) );
- hicn_route = memalign(MEM_ALIGN, sizeof(hicn_route_t) );
- memset((hicn_route_t *) hicn_route, 0 , sizeof(hicn_route_t) );
-
hicn_faces = memalign(MEM_ALIGN, sizeof(hicn_faces_t) );
hicn_faces->next=memalign(MEM_ALIGN, sizeof(struct hicn_faces_s));
fcurrent=hicn_faces->next;
@@ -75,7 +91,7 @@ static int init_buffer(void){
int retval=-1;
- ARG_CHECK7(retval, hicn_state, hicn_strategy, hicn_strategies, hicn_route, fcurrent, hicn_faces, hicn_routes);
+ ARG_CHECK5(retval, hicn_state, hicn_strategies, fcurrent, hicn_faces, hicn_routes);
hicn_routes->nroute=0;
hicn_faces->nface=0;
retval=0;
@@ -83,7 +99,6 @@ static int init_buffer(void){
return retval;
}
-
static int init_face_pool(struct hicn_faces_s * head){
for(int i=0; i<MAX_FACE_POOL; i++){
@@ -96,7 +111,6 @@ static int init_face_pool(struct hicn_faces_s * head){
}
-
static int init_route_pool(struct hicn_routes_s * head){
for(int i=0; i<MAX_ROUTE_POOL; i++){
@@ -111,20 +125,7 @@ static int init_route_pool(struct hicn_routes_s * head){
/* VAPI CALLBACKS */
-vapi_error_e call_hicn_api_strategy_get(struct vapi_ctx_s *ctx,
- void *callback_ctx,
- vapi_error_e rv,
- bool is_last,
- vapi_payload_hicn_api_node_params_set_reply *reply){
-if(!reply->retval){
- SRP_LOG_DBGMSG("Successfully done");
- return VAPI_OK;
- }else
- return VAPI_EUSER;
-}
-
-
-vapi_error_e call_hicn_api_strategies_get(struct vapi_ctx_s *ctx,
+static vapi_error_e call_hicn_api_strategies_get(struct vapi_ctx_s *ctx,
void *callback_ctx,
vapi_error_e rv,
bool is_last,
@@ -136,20 +137,7 @@ if(!reply->retval){
return VAPI_EUSER;
}
-vapi_error_e call_hicn_api_route_get_hton(struct vapi_ctx_s *ctx,
- void *callback_ctx,
- vapi_error_e rv,
- bool is_last,
- vapi_payload_hicn_api_strategies_get_reply *reply){
-if(!reply->retval){
- SRP_LOG_DBGMSG("Successfully done");
- return VAPI_OK;
- }else
- return VAPI_EUSER;
-}
-
-
-vapi_error_e call_hicn_api_route_nhops_add(struct vapi_ctx_s *ctx,
+static vapi_error_e call_hicn_api_route_nhops_add(struct vapi_ctx_s *ctx,
void *callback_ctx,
vapi_error_e rv,
bool is_last,
@@ -161,7 +149,7 @@ if(!reply->retval){
return VAPI_EUSER;
}
-vapi_error_e call_hicn_api_route_del(struct vapi_ctx_s *ctx,
+static vapi_error_e call_hicn_api_route_del(struct vapi_ctx_s *ctx,
void *callback_ctx,
vapi_error_e rv,
bool is_last,
@@ -174,7 +162,7 @@ if(!reply->retval){
return VAPI_EUSER;
}
-vapi_error_e call_hicn_api_face_ip_params_get(struct vapi_ctx_s *ctx,
+static vapi_error_e call_hicn_api_face_ip_params_get(struct vapi_ctx_s *ctx,
void *callback_ctx,
vapi_error_e rv,
bool is_last,
@@ -190,8 +178,7 @@ if(!reply->retval){
return VAPI_EUSER;
}
-
-vapi_error_e call_hicn_api_punting_add(struct vapi_ctx_s *ctx,
+static vapi_error_e call_hicn_api_punting_add(struct vapi_ctx_s *ctx,
void *callback_ctx,
vapi_error_e rv,
bool is_last,
@@ -204,7 +191,7 @@ if(!reply->retval){
}
-vapi_error_e call_hicn_api_route_nhop_del(struct vapi_ctx_s *ctx,
+static vapi_error_e call_hicn_api_route_nhop_del(struct vapi_ctx_s *ctx,
void *callback_ctx,
vapi_error_e rv,
bool is_last,
@@ -216,8 +203,7 @@ if(!reply->retval){
return VAPI_EUSER;
}
-
-vapi_error_e call_hicn_api_punting_del(struct vapi_ctx_s *ctx,
+static vapi_error_e call_hicn_api_punting_del(struct vapi_ctx_s *ctx,
void *callback_ctx,
vapi_error_e rv,
bool is_last,
@@ -230,7 +216,7 @@ if(!reply->retval){
}
-vapi_error_e call_hicn_api_face_ip_del(struct vapi_ctx_s *ctx,
+static vapi_error_e call_hicn_api_face_ip_del(struct vapi_ctx_s *ctx,
void *callback_ctx,
vapi_error_e rv,
bool is_last,
@@ -243,7 +229,7 @@ if(!reply->retval){
}
-vapi_error_e call_hicn_api_face_ip_add(struct vapi_ctx_s *ctx,
+static vapi_error_e call_hicn_api_face_ip_add(struct vapi_ctx_s *ctx,
void *callback_ctx,
vapi_error_e rv,
bool is_last,
@@ -256,7 +242,7 @@ if(!reply->retval){
}
-vapi_error_e call_vapi_hicn_api_node_stats_get(struct vapi_ctx_s *ctx,
+static vapi_error_e call_vapi_hicn_api_node_stats_get(struct vapi_ctx_s *ctx,
void *callback_ctx,
vapi_error_e rv,
bool is_last,
@@ -283,21 +269,9 @@ if(!reply->retval){
return VAPI_EUSER;
}
-vapi_error_e call_hicn_api_node_params_set(struct vapi_ctx_s *ctx,
- void *callback_ctx,
- vapi_error_e rv,
- bool is_last,
- vapi_payload_hicn_api_node_params_set_reply *reply){
- if(!reply->retval){
- SRP_LOG_DBGMSG("Successfully done");
- return VAPI_OK;
- }else
- return VAPI_EUSER;
-}
-
static inline void state_update(sr_val_t * vals, struct lyd_node **parent, sr_session_ctx_t *session){
char buf[20];
- //struct ly_ctx *ly_ctx = sr_get_context(sr_session_get_connection(session));
+
sr_val_set_xpath(&vals[0], "/hicn:hicn-state/states/pkts_processed");
vals[0].type = SR_UINT64_T;
vals[0].data.uint64_val = hicn_state->pkts_processed;
@@ -463,8 +437,6 @@ static inline int faces_update(sr_val_t * vals, uint32_t nleaves, struct lyd_no
for(int count=0; count<nleaves; count++){
-
- // This part must be removed once the faceid is provided by the dump msg
vapi_msg_hicn_api_face_ip_params_get *msg;
msg = vapi_alloc_hicn_api_face_ip_params_get(g_vapi_ctx_instance);
@@ -661,9 +633,6 @@ static int hicn_state_route_cb(sr_session_ctx_t *session, const char *module_nam
}
-/**
-* @brief API to get hicn strategies in vpp.
-*/
static int hicn_strategies_get_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt,
sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) {
@@ -680,9 +649,6 @@ return SR_ERR_OK;
}
-/**
-* @brief API to add hicn route nhops in vpp.
-*/
static int hicn_route_nhops_add_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt,
sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) {
@@ -730,9 +696,6 @@ if(vapi_hicn_api_route_nhops_add(g_vapi_ctx_instance,msg,call_hicn_api_route_nho
return SR_ERR_OK;
}
-/**
-* @brief API to del hicn route in vpp.
-*/
static int hicn_route_del_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt,
sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) {
@@ -774,9 +737,6 @@ if(vapi_hicn_api_route_del(g_vapi_ctx_instance,msg,call_hicn_api_route_del,NULL)
return SR_ERR_OK;
}
-/**
-* @brief API to get face ip params in hicn in vpp.
-*/
static int hicn_face_ip_params_get_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt,
sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) {
@@ -794,9 +754,6 @@ if (vapi_hicn_api_face_ip_params_get(g_vapi_ctx_instance,msg,call_hicn_api_face_
return SR_ERR_OK;
}
-/**
-* @brief API to get face ip params in hicn in vpp.
-*/
static int hicn_punting_add_ip_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt,
sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) {
@@ -842,9 +799,6 @@ if (vapi_hicn_api_punting_add(g_vapi_ctx_instance, msg, call_hicn_api_punting_ad
return SR_ERR_OK;
}
-/**
-* @brief API to del hicn route nhops in vpp.
-*/
static int hicn_route_nhops_del_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt,
sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) {
@@ -890,9 +844,6 @@ if (vapi_hicn_api_route_nhop_del(g_vapi_ctx_instance, msg, call_hicn_api_route_n
return SR_ERR_OK;
}
-/**
-* @brief API to del hicn punting in vpp.
-*/
static int hicn_punting_del_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt,
sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) {
@@ -939,9 +890,7 @@ return SR_ERR_OK;
}
-/**
-* @brief API to del hicn face ip in vpp.
-*/
+
static int hicn_face_ip_del_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt,
sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) {
@@ -960,9 +909,7 @@ if(vapi_hicn_api_face_ip_del(g_vapi_ctx_instance,msg, call_hicn_api_face_ip_del,
return SR_ERR_OK;
}
-/**
-* @brief API to del hicn face ip in vpp.
-*/
+
static int hicn_face_ip_add_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt,
sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) {
@@ -1024,7 +971,7 @@ if(vapi_hicn_api_face_ip_add(g_vapi_ctx_instance,msg,call_hicn_api_face_ip_add,N
return SR_ERR_OK;
}
- vapi_error_e
+static vapi_error_e
hicn_api_routes_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx,
vapi_error_e rv, bool is_last,
vapi_payload_hicn_api_routes_details *reply)
@@ -1060,7 +1007,6 @@ hicn_api_routes_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx,
}
-
static vapi_error_e
hicn_api_face_stats_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx,
vapi_error_e rv, bool is_last,
@@ -1099,9 +1045,7 @@ hicn_api_face_stats_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx,
return SR_ERR_OK;
}
-/**
-* @brief Thread to update the state
-*/
+
static void *state_thread(void *arg) {
// mapping can be retrieved by cpuinfo
@@ -1154,9 +1098,7 @@ static void *state_thread(void *arg) {
return NULL;
}
-/**
-* @brief helper function for subscribing all hicn APIs.
-*/
+
int hicn_subscribe_events(sr_session_ctx_t *session,
sr_subscription_ctx_t **subscription) {
int rc = SR_ERR_OK;
@@ -1279,7 +1221,7 @@ int hicn_subscribe_events(sr_session_ctx_t *session,
goto error;
}
- rc = sr_rpc_subscribe(session, "/hicn:punting-del", hicn_punting_del_cb,
+ rc = sr_rpc_subscribe(session, "/hicn:punting-del-ip", hicn_punting_del_cb,
session, 89,SR_SUBSCR_CTX_REUSE, subscription);
if (rc != SR_ERR_OK) {
SRP_LOG_DBGMSG("Problem in subscription punting-del\n");
diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h
index 9c5d9df9a..62fb15340 100644
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h
+++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h
@@ -13,38 +13,84 @@
* limitations under the License.
*/
+/**
+ * @file hicn_model.h
+ * @brief This file contains main calls for hICN events coresponding to the hICN yang models
+ */
+
#ifndef __IETF_HICN_H__
#define __IETF_HICN_H__
#include "../hicn_vpp_comm.h"
#include <vapi/hicn.api.vapi.h>
+/**
+ * @brief Align memory to one page boundary
+ */
#define MEM_ALIGN 4096
+
+/**
+ * @brief 32 bits = 4 bytes
+ */
#define B32 4
+/**
+ * @brief 64bits = 8 bytes
+ */
#define B64 8
+/**
+ * @brief 128 bits = 16 bytes
+ */
#define B128 16
-// Number of locks is equal to number of nodes in hicn-state
-// It is a coarse grain approach later can be changed to fine grained
-// better to initialize the lock by 0
+/**
+ * @brief set number of lock to 5
+ */
#define NLOCKS 5
-#define LOCK_INIT 0
+/**
+ * @brief initialize all locks by 0, better to initialize by 0 :)
+ */
+#define LOCK_INIT 0
+/**
+ * @brief enumeration for the locks
+ */
enum locks_name {lstate, lstrategy, lstrategies, lroute, lfaces};
+
+// It is a coarse grain approach later can be changed to fine grained
+
+
+/**
+ * @brief This indicates the number of leaves for the hICN state
+ */
#define NSTATE_LEAVES 15
+/**
+ * @brief This indicates the number of leaves for strategy
+ */
#define NSTRATEGY_LEAVES 1
+/**
+ * @brief This indicates the number of leaves for strategies
+ */
#define NSTRATEGIES_LEAVES 2
+/**
+ * @brief This indicates the maximum faces which can be read as operational data
+ */
#define MAX_FACE_POOL 100
+/**
+ * @brief This indicates the maximum routes which can be read as operational data
+ */
#define MAX_ROUTE_POOL 100
-
+/**
+ * @brief This indicates the number of leaves for faces
+ */
#define FACES_CHILDREN 9 /*this is the number of children of each leave in face except the key*/
+/**
+ * @brief This indicates the number of leaves for routes
+ */
#define ROUTES_CHILDREN 2 /*this is the number of children of each leave in face except the key*/
typedef struct __attribute__ ((__packed__)) {
-
-
int32_t retval;
uint64_t pkts_processed;
uint64_t pkts_interest_count;
@@ -61,14 +107,8 @@ typedef struct __attribute__ ((__packed__)) {
uint64_t pit_entries_count;
uint64_t cs_entries_count;
uint64_t cs_entries_ntw_count;
-
} hicn_state_t;
-typedef struct __attribute__ ((__packed__)) {
- uint8_t description[200];
- int32_t retval;
-} hicn_strategy_t;
-
typedef struct __attribute__ ((__packed__)) {
@@ -77,18 +117,6 @@ typedef struct __attribute__ ((__packed__)) {
int32_t retval;
} hicn_strategies_t;
-typedef struct __attribute__ ((__packed__)) {
- uint32_t faceids[1000];
- uint32_t strategy_id;
- int32_t retval;
-} hicn_route_t;
-
-typedef struct __attribute__ ((__packed__)) {
- uint64_t nh_addr[2];
- uint32_t swif;
- uint32_t flags;
- int32_t retval;
-} hicn_face_ip_params_t;
typedef struct __attribute__ ((__packed__)) {
uint32_t faceid;
@@ -103,6 +131,7 @@ typedef struct __attribute__ ((__packed__)) {
uint64_t dtx_bytes;
} hicn_face_inf_t;
+
typedef struct __attribute__ ((__packed__)) {
u32 route_id;
vapi_type_prefix prefix;
@@ -111,17 +140,23 @@ typedef struct __attribute__ ((__packed__)) {
u32 strategy_id;
} hicn_route_inf_t;
-
+/**
+ * @brief This is the link list to maintain the statistics of the faces
+ */
struct hicn_faces_s{
hicn_face_inf_t face;
struct hicn_faces_s * next;
};
+
typedef struct __attribute__ ((__packed__)) {
uint32_t nface;
struct hicn_faces_s * next;
} hicn_faces_t;
+/**
+ * @brief This is the link list to maintain the route informations
+ */
struct hicn_routes_s{
hicn_route_inf_t route;
struct hicn_routes_s * next;
@@ -133,6 +168,10 @@ typedef struct __attribute__ ((__packed__)) {
struct hicn_routes_s * next;
} hicn_routes_t;
+/**
+ * @brief This function subscribes the hICN evens consisting of all RPCs
+ * as well as operational data
+ */
int hicn_subscribe_events(sr_session_ctx_t *session,
sr_subscription_ctx_t **subscription);
diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.h
index 8cdfc8b5b..a871705a3 100644
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.h
+++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.h
@@ -14,18 +14,51 @@
*/
+
+/**
+ * @file tlock.h
+ * @brief This file contains ticket lock APIs.
+ */
+
#ifndef __TLOCK_H__
#define __TLOCK_H__
-// limit on the number of locks: it shoud be matched with the number of hicn-state leaves
+/**
+
+ * @brief limit the number of locks: it shoud be matched with the
+ * number of hicn-state leaves
+ */
#define MAX_LOCK_SIZE 5
-volatile long int En[MAX_LOCK_SIZE] , De[MAX_LOCK_SIZE] ; // For Ticket Algorithm
+/**
+ * @brief Ticket lock counters
+ */
+volatile long int En[MAX_LOCK_SIZE] ;
+
+/**
+ * @brief Ticket lock counters
+ */
+volatile long int De[MAX_LOCK_SIZE] ;
+/**
+ * @brief This function initialize the ticket lock
+ * @param Lock_Number describes the number of locks need to be initialized
+ * @param init describes the init number
+ */
void ticket_init ( int Lock_Number , long int init );
+/**
+ * @brief this function acquire the lock
+ * Description of what the function does. This part may refer to the parameters
+ * @param Lock_Number pass the lock
+ */
void tlock(int Lock_Number );
+/**
+ * @briefthis function release the lock
+ * @param Lock_Number lock number
+
+ */
void tunlock(int Lock_Number );
#endif /* __IETF_HICN_H__ */ \ No newline at end of file