eigrpd: Create enum for states and string name for display

Create an enum for the different states and create
a string name display handler.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2017-10-28 18:04:19 -04:00
parent 5cc74ec1b8
commit 94ccb30979
2 changed files with 61 additions and 12 deletions

View File

@ -153,14 +153,37 @@ enum eigrp_fsm_states {
#define EIGRP_FSM_NEED_QUERY 2 #define EIGRP_FSM_NEED_QUERY 2
/*EIGRP FSM events*/ /*EIGRP FSM events*/
#define EIGRP_FSM_EVENT_NQ_FCN 0 /*input event other than query from succ, FC not satisfied*/ enum eigrp_fsm_events {
#define EIGRP_FSM_EVENT_LR 1 /*last reply, FD is reset*/ /*
#define EIGRP_FSM_EVENT_Q_FCN 2 /*query from succ, FC not satisfied*/ * Input event other than query from succ,
#define EIGRP_FSM_EVENT_LR_FCS 3 /*last reply, FC satisfied with current value of FDij*/ * FC is not satisified
#define EIGRP_FSM_EVENT_DINC 4 /*distance increase while in active state*/ */
#define EIGRP_FSM_EVENT_QACT 5 /*query from succ while in active state*/ EIGRP_FSM_EVENT_NQ_FCN,
#define EIGRP_FSM_EVENT_LR_FCN 6 /*last reply, FC not satisfied with current value of FDij*/
#define EIGRP_FSM_KEEP_STATE 7 /*state not changed, usually by receiving not last reply */ /* last reply, FD is reset */
EIGRP_FSM_EVENT_LR,
/* Query from succ, FC not satisfied */
EIGRP_FSM_EVENT_Q_FCN,
/* last reply, FC satisifed with current value of FDij */
EIGRP_FSM_EVENT_LR_FCS,
/* distance increase while in a active state */
EIGRP_FSM_EVENT_DINC,
/* Query from succ while in active state */
EIGRP_FSM_EVENT_QACT,
/* last reply, FC not satisified */
EIGRP_FSM_EVENT_LR_FCN,
/*
* state not changed
* usually by receiving not last reply
*/
EIGRP_FSM_KEEP_STATE,
};
/** /**
* External routes originate from some other protocol - these are them * External routes originate from some other protocol - these are them

View File

@ -188,6 +188,29 @@ static const char *prefix_state2str(enum eigrp_fsm_states state)
return "Unknown"; return "Unknown";
} }
static const char *fsm_state2str(enum eigrp_fsm_events event)
{
switch (event) {
case EIGRP_FSM_KEEP_STATE:
return "Keep State Event";
case EIGRP_FSM_EVENT_NQ_FCN:
return "Non Query Event Feasability not satisfied";
case EIGRP_FSM_EVENT_LR:
return "Last Reply Event";
case EIGRP_FSM_EVENT_Q_FCN:
return "Query Event Feasability not satisified";
case EIGRP_FSM_EVENT_LR_FCS:
return "Last Reply Event Feasability satisified";
case EIGRP_FSM_EVENT_DINC:
return "Distance Increase Event";
case EIGRP_FSM_EVENT_QACT:
return "Query from Successor while in active state";
case EIGRP_FSM_EVENT_LR_FCN:
return "Last Reply Event, Feasibility not satisfied";
};
return "Unknown";
}
/* /*
* Main function in which are make decisions which event occurred. * Main function in which are make decisions which event occurred.
* msg - argument of type struct eigrp_fsm_action_message contain * msg - argument of type struct eigrp_fsm_action_message contain
@ -196,7 +219,8 @@ static const char *prefix_state2str(enum eigrp_fsm_states state)
* Return number of occurred event (arrow in diagram). * Return number of occurred event (arrow in diagram).
* *
*/ */
static int eigrp_get_fsm_event(struct eigrp_fsm_action_message *msg) static enum eigrp_fsm_events eigrp_get_fsm_event(
struct eigrp_fsm_action_message *msg)
{ {
// Loading base information from message // Loading base information from message
// struct eigrp *eigrp = msg->eigrp; // struct eigrp *eigrp = msg->eigrp;
@ -348,10 +372,12 @@ static int eigrp_get_fsm_event(struct eigrp_fsm_action_message *msg)
*/ */
int eigrp_fsm_event(struct eigrp_fsm_action_message *msg) int eigrp_fsm_event(struct eigrp_fsm_action_message *msg)
{ {
int event = eigrp_get_fsm_event(msg); enum eigrp_fsm_events event = eigrp_get_fsm_event(msg);
zlog_info("EIGRP AS: %d State: %s Event: %d Network: %s",
zlog_info("EIGRP AS: %d State: %s Event: %s Network: %s",
msg->eigrp->AS, prefix_state2str(msg->prefix->state), msg->eigrp->AS, prefix_state2str(msg->prefix->state),
event, eigrp_topology_ip_string(msg->prefix)); fsm_state2str(event),
eigrp_topology_ip_string(msg->prefix));
(*(NSM[msg->prefix->state][event].func))(msg); (*(NSM[msg->prefix->state][event].func))(msg);
return 1; return 1;