Cisco-like "show ospf neighbors" implemented.

This commit is contained in:
Ondrej Filip 2000-06-01 15:53:06 +00:00
parent b594ad2386
commit a783e259d8
6 changed files with 60 additions and 2 deletions

View file

@ -37,6 +37,7 @@ Reply codes of BIRD command-line interface
1010 Symbol list
1011 Uptime
1012 Route extended attribute list
1013 Show ospf neighbors
8000 Reply too long
8001 Route not found

View file

@ -13,6 +13,7 @@ CF_HDR
CF_DECLS
CF_KEYWORDS(OSPF, AREA, OSPF_METRIC1, OSPF_METRIC2, OSPF_TAG)
CF_KEYWORDS(NEIGHBORS)
CF_GRAMMAR
@ -39,6 +40,9 @@ CF_ADDTO(dynamic_attr, OSPF_METRIC1 { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF
CF_ADDTO(dynamic_attr, OSPF_METRIC2 { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_OSPF_METRIC2); })
CF_ADDTO(dynamic_attr, OSPF_TAG { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_OSPF_TAG); })
CF_CLI(SHOW OSPF NEIGHBORS, optsym, [<name>], [[Show information about ospf neighbors]])
{ ospf_sh_neigh(proto_get_named($4, &proto_ospf)); } ;
CF_CODE
CF_END

View file

@ -8,8 +8,14 @@
#include "ospf.h"
char *ospf_ns[]={"down", "attempt", "init", "2way", "exstart", "exchange",
"loading", "full"};
char *ospf_ns[]={" down",
" attempt",
" init",
" 2way",
" exstart",
"exchange",
" loading",
" full"};
const char *ospf_inm[]={ "hello received", "neighbor start", "2-way received",
"negotiation done", "exstart done", "bad ls request", "load done",
@ -480,3 +486,31 @@ ospf_neigh_remove(struct ospf_neighbor *n)
mb_free(n);
debug("%s: Deleting neigbor.\n", p->name);
}
void
ospf_sh_neigh_info(struct ospf_neighbor *n)
{
struct ospf_iface *ifa=n->ifa;
char *pos="other";
char etime[6];
int exp,sec,min;
exp=n->inactim->expires-now;
sec=exp-(exp/60);
min=(exp-sec)/60;
if(min>59)
{
sprintf(etime,"-Inf-");
}
else
{
sprintf(etime,"%02u:%02u", min, sec);
}
if(n->rid==ifa->drid) pos="dr ";
if(n->rid==ifa->bdrid) pos="bdr ";
cli_msg(-1013,"%-18I\t%3u\t%s/%s\t%-5s\t%-18I\t%-10s",n->rid, n->priority,
ospf_ns[n->state], pos, etime, n->ip,ifa->iface->name);
}

View file

@ -22,5 +22,6 @@ struct ospf_neighbor *find_neigh_noifa(struct proto_ospf *po, u32 rid);
struct ospf_area *ospf_find_area(struct proto_ospf *po, u32 aid);
void neighbor_timer_hook(timer *timer);
void ospf_neigh_remove(struct ospf_neighbor *n);
void ospf_sh_neigh_info(struct ospf_neighbor *n);
#endif /* _BIRD_OSPF_NEIGHBOR_H_ */

View file

@ -316,3 +316,19 @@ struct protocol proto_ospf = {
get_attr: ospf_get_attr,
get_status: ospf_get_status
};
void
ospf_sh_neigh(struct proto *p)
{
struct ospf_iface *ifa;
struct ospf_neighbor *n;
struct proto_ospf *po=(struct proto_ospf *)p;
cli_msg(-1013,"%s:",p->name);
cli_msg(-1013,"%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s","Router ID","Pri",
" State", "DTime", "Router IP", "Interface");
WALK_LIST(ifa,po->iface_list)
WALK_LIST(n, ifa->neigh_list)
ospf_sh_neigh_info(n);
cli_msg(0,"");
}

View file

@ -24,6 +24,7 @@
#include "nest/protocol.h"
#include "nest/iface.h"
#include "nest/route.h"
#include "nest/cli.h"
#include "conf/conf.h"
#include "lib/string.h"
@ -361,6 +362,7 @@ void ospf_rt_notify(struct proto *p, net *n, rte *new, rte *old,ea_list *attrs);
void area_disp(timer *timer);
void schedule_rt_lsa(struct ospf_area *oa);
void schedule_rtcalc(struct ospf_area *oa);
void ospf_sh_neigh(struct proto *p);
#define EA_OSPF_METRIC1 EA_CODE(EAP_OSPF, 0)
#define EA_OSPF_METRIC2 EA_CODE(EAP_OSPF, 1)