From 5817c7b7eb097b0bff1d74c51e712d697b069db7 Mon Sep 17 00:00:00 2001 From: Esben Norby Date: Mon, 14 Mar 2005 18:21:30 +0000 Subject: Add "show summary" to ospfctl. ok claudio@ henning@ --- usr.sbin/ospfctl/ospfctl.8 | 8 +++--- usr.sbin/ospfctl/ospfctl.c | 52 ++++++++++++++++++++++++++++++------ usr.sbin/ospfctl/parser.c | 4 +-- usr.sbin/ospfctl/parser.h | 4 +-- usr.sbin/ospfd/control.c | 3 ++- usr.sbin/ospfd/ospfd.h | 26 +++++++++++++++--- usr.sbin/ospfd/ospfe.c | 8 +++--- usr.sbin/ospfd/rde.c | 66 ++++++++++++++++++++++++++++++++++++++++++++-- usr.sbin/ospfd/rde_spf.c | 5 ++-- 9 files changed, 150 insertions(+), 26 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/ospfctl/ospfctl.8 b/usr.sbin/ospfctl/ospfctl.8 index fc1d72355c1..cee44999314 100644 --- a/usr.sbin/ospfctl/ospfctl.8 +++ b/usr.sbin/ospfctl/ospfctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ospfctl.8,v 1.3 2005/01/28 18:11:54 jmc Exp $ +.\" $OpenBSD: ospfctl.8,v 1.4 2005/03/14 18:21:28 norby Exp $ .\" .\" Copyright (c) 2004, 2005 Esben Norby .\" @@ -35,10 +35,12 @@ The following commands are available: .Bl -tag -width Ds .It Cm show database Show the entire link state database. -.It Cm show neighbor -Show neighbor summary. .It Cm show interfaces Show interface summary. +.It Cm show neighbor +Show neighbor summary. +.It Cm show summary +Show summary status. .El .Sh FILES .Bl -tag -width "/etc/ospfd.confXXXX" -compact diff --git a/usr.sbin/ospfctl/ospfctl.c b/usr.sbin/ospfctl/ospfctl.c index 4dcfbc44976..6079b438cd2 100644 --- a/usr.sbin/ospfctl/ospfctl.c +++ b/usr.sbin/ospfctl/ospfctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfctl.c,v 1.6 2005/03/12 11:03:05 norby Exp $ */ +/* $OpenBSD: ospfctl.c,v 1.7 2005/03/14 18:21:29 norby Exp $ */ /* * Copyright (c) 2005 Claudio Jeker @@ -37,7 +37,7 @@ #include "log.h" __dead void usage(void); -int show_summary_msg(struct imsg *, int); +int show_summary_msg(struct imsg *); int show_interface_msg(struct imsg *); void print_baudrate(u_long); const char *print_if_type(enum iface_type type); @@ -82,7 +82,6 @@ main(int argc, char *argv[]) struct imsg imsg; unsigned int ifidx = 0; int ctl_sock; - int nodescr = 0; int done = 0; int n; @@ -111,7 +110,8 @@ main(int argc, char *argv[]) usage(); /* not reached */ case SHOW: - case SHOW_SUMMARY: + case SHOW_SUM: + imsg_compose(ibuf, IMSG_CTL_SHOW_SUM, 0, 0, -1, NULL, 0); break; case SHOW_IFACE: if (*res->ifname) { @@ -165,8 +165,8 @@ main(int argc, char *argv[]) break; switch (res->action) { case SHOW: - case SHOW_SUMMARY: - done = show_summary_msg(&imsg, nodescr); + case SHOW_SUM: + done = show_summary_msg(&imsg); break; case SHOW_IFACE: done = show_interface_msg(&imsg); @@ -201,8 +201,44 @@ main(int argc, char *argv[]) } int -show_summary_msg(struct imsg *imsg, int nodescr) +show_summary_msg(struct imsg *imsg) { + struct ctl_sum *sum; + struct ctl_sum_area *sumarea; + + switch (imsg->hdr.type) { + case IMSG_CTL_SHOW_SUM: + sum = imsg->data; + printf("Router ID: %s\n", inet_ntoa(sum->rtr_id)); + printf("RFC1583 compatibility flag is "); + if (sum->rfc1583compat) + printf("enabled\n"); + else + printf("disabled\n"); + + printf("SPF delay is %d sec(s), hold time between two SPFs " + "is %d sec(s)\n", sum->spf_delay, sum->spf_hold_time); + printf("Number of external LSA(s) %d\n", sum->num_ext_lsa); + printf("Number of areas attached to this router: %d\n", + sum->num_area); + break; + case IMSG_CTL_SHOW_SUM_AREA: + sumarea = imsg->data; + printf("\nArea ID: %s\n", inet_ntoa(sumarea->area)); + printf(" Number of interfaces in this area: %d\n", + sumarea->num_iface); + printf(" Number of fully adjacent neighbors in this " + "area: %d\n", sumarea->num_adj_nbr); + printf(" SPF algorithm executed %d time(s)\n", + sumarea->num_spf_calc); + printf(" Number LSA(s) %d\n", sumarea->num_lsa); + break; + case IMSG_CTL_END: + printf("\n"); + return (1); + default: + break; + } return (0); } @@ -225,7 +261,7 @@ show_interface_msg(struct imsg *imsg) printf(" Router ID %s, network type %s, cost: %d\n", inet_ntoa(iface->rtr_id), print_if_type(iface->type), iface->metric); - printf(" Transmit delay is %d sec, state %s, priority %d\n", + printf(" Transmit delay is %d sec(s), state %s, priority %d\n", iface->transfer_delay, print_if_state(iface->state), iface->priority); printf(" Designated Router (ID) %s, ", diff --git a/usr.sbin/ospfctl/parser.c b/usr.sbin/ospfctl/parser.c index 1ab0e16a81b..459ddd8a981 100644 --- a/usr.sbin/ospfctl/parser.c +++ b/usr.sbin/ospfctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.4 2005/03/12 11:03:05 norby Exp $ */ +/* $OpenBSD: parser.c,v 1.5 2005/03/14 18:21:29 norby Exp $ */ /* * Copyright (c) 2004 Esben Norby @@ -66,8 +66,8 @@ static const struct token t_show[] = { {KEYWORD, "interfaces", SHOW_IFACE, t_show_iface}, {KEYWORD, "database", SHOW_DB, t_show_db}, {KEYWORD, "neighbor", SHOW_NBR, t_show_nbr}, -/* {KEYWORD, "summary", SHOW_SUMMARY, NULL}, */ {KEYWORD, "rib", SHOW_RIB, t_show_rib}, + {KEYWORD, "summary", SHOW_SUM, NULL}, {ENDTOKEN, "", NONE, NULL} }; diff --git a/usr.sbin/ospfctl/parser.h b/usr.sbin/ospfctl/parser.h index 3ecf6e7c33f..a8e616d1e6a 100644 --- a/usr.sbin/ospfctl/parser.h +++ b/usr.sbin/ospfctl/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.3 2005/03/12 11:03:05 norby Exp $ */ +/* $OpenBSD: parser.h,v 1.4 2005/03/14 18:21:29 norby Exp $ */ /* * Copyright (c) 2004 Esben Norby @@ -27,7 +27,7 @@ enum actions { NONE, SHOW, - SHOW_SUMMARY, + SHOW_SUM, SHOW_IFACE, SHOW_NBR, SHOW_NBR_DTAIL, diff --git a/usr.sbin/ospfd/control.c b/usr.sbin/ospfd/control.c index 57d0b66692e..aacd4c0fffa 100644 --- a/usr.sbin/ospfd/control.c +++ b/usr.sbin/ospfd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.5 2005/03/14 16:57:41 claudio Exp $ */ +/* $OpenBSD: control.c,v 1.6 2005/03/14 18:21:29 norby Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -244,6 +244,7 @@ control_dispatch_imsg(int fd, short event, void *bula) ospfe_nbr_ctl(c); break; case IMSG_CTL_SHOW_RIB: + case IMSG_CTL_SHOW_SUM: c->ibuf.pid = imsg.hdr.pid; ospfe_imsg_compose_rde(imsg.hdr.type, 0, imsg.hdr.pid, imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE); diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h index 5cadc3b4048..3a2773fbeb1 100644 --- a/usr.sbin/ospfd/ospfd.h +++ b/usr.sbin/ospfd/ospfd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.h,v 1.14 2005/03/12 11:03:05 norby Exp $ */ +/* $OpenBSD: ospfd.h,v 1.15 2005/03/14 18:21:29 norby Exp $ */ /* * Copyright (c) 2004 Esben Norby @@ -92,6 +92,8 @@ enum imsg_type { IMSG_CTL_SHOW_DATABASE, IMSG_CTL_SHOW_NBR, IMSG_CTL_SHOW_RIB, + IMSG_CTL_SHOW_SUM, + IMSG_CTL_SHOW_SUM_AREA, IMSG_CTL_FIB_COUPLE, IMSG_CTL_FIB_DECOUPLE, IMSG_CTL_AREA, @@ -139,13 +141,13 @@ RB_HEAD(lsa_tree, vertex); struct area { LIST_ENTRY(area) entry; struct in_addr id; - struct lsa_tree lsa_tree; + LIST_HEAD(, iface) iface_list; LIST_HEAD(, rde_nbr) nbr_list; /* list addr_range_list; */ u_int32_t stub_default_cost; - + u_int32_t num_spf_calc; u_int32_t dead_interval; u_int16_t transfer_delay; u_int16_t hello_interval; @@ -322,6 +324,7 @@ struct ospfd_conf { int ospf_socket; int flags; int options; /* OSPF options */ + u_int8_t rfc1583compat; }; /* kroute */ @@ -403,6 +406,23 @@ struct ctl_rt { u_int8_t prefixlen; }; +struct ctl_sum { + struct in_addr rtr_id; + u_int32_t spf_delay; + u_int32_t spf_hold_time; + u_int32_t num_ext_lsa; + u_int32_t num_area; + u_int8_t rfc1583compat; +}; + +struct ctl_sum_area { + struct in_addr area; + u_int32_t num_iface; + u_int32_t num_adj_nbr; + u_int32_t num_spf_calc; + u_int32_t num_lsa; +}; + void show_config(struct ospfd_conf *xconf); /* area.c */ diff --git a/usr.sbin/ospfd/ospfe.c b/usr.sbin/ospfd/ospfe.c index 617d7caebf6..2adff85a0e5 100644 --- a/usr.sbin/ospfd/ospfe.c +++ b/usr.sbin/ospfd/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.11 2005/03/12 11:03:05 norby Exp $ */ +/* $OpenBSD: ospfe.c,v 1.12 2005/03/14 18:21:29 norby Exp $ */ /* * Copyright (c) 2005 Claudio Jeker @@ -522,10 +522,12 @@ ospfe_dispatch_rde(int fd, short event, void *bula) nbr_fsm(nbr, NBR_EVT_BAD_LS_REQ); break; - case IMSG_CTL_SHOW_DATABASE: - case IMSG_CTL_SHOW_RIB: case IMSG_CTL_AREA: case IMSG_CTL_END: + case IMSG_CTL_SHOW_DATABASE: + case IMSG_CTL_SHOW_RIB: + case IMSG_CTL_SHOW_SUM: + case IMSG_CTL_SHOW_SUM_AREA: control_imsg_relay(&imsg); break; default: diff --git a/usr.sbin/ospfd/rde.c b/usr.sbin/ospfd/rde.c index da05d90aba1..7f532d86366 100644 --- a/usr.sbin/ospfd/rde.c +++ b/usr.sbin/ospfd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.9 2005/03/12 11:03:05 norby Exp $ */ +/* $OpenBSD: rde.c,v 1.10 2005/03/14 18:21:29 norby Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker @@ -41,7 +41,8 @@ void rde_sig_handler(int sig, short, void *); void rde_shutdown(void); void rde_dispatch_imsg(int, short, void *); - +void rde_send_summary(pid_t); +void rde_send_summary_area(struct area *, pid_t); void rde_nbr_init(u_int32_t); struct rde_nbr *rde_nbr_find(u_int32_t); struct rde_nbr *rde_nbr_new(u_int32_t, struct rde_nbr *); @@ -470,6 +471,13 @@ rde_dispatch_imsg(int fd, short event, void *bula) imsg_compose(ibuf_ospfe, IMSG_CTL_END, 0, imsg.hdr.pid, -1, NULL, 0); break; + case IMSG_CTL_SHOW_SUM: + rde_send_summary(imsg.hdr.pid); + LIST_FOREACH(area, &rdeconf->area_list, entry) + rde_send_summary_area(area, imsg.hdr.pid); + imsg_compose(ibuf_ospfe, IMSG_CTL_END, 0, imsg.hdr.pid, + -1, NULL, 0); + break; default: log_debug("rde_dispatch_msg: unexpected imsg %d", imsg.hdr.type); @@ -512,6 +520,60 @@ rde_send_delete_kroute(struct rt_node *r) imsg_compose(ibuf_main, IMSG_KROUTE_DELETE, 0, 0, -1, &kr, sizeof(kr)); } +void +rde_send_summary(pid_t pid) +{ + static struct ctl_sum sumctl; + struct lsa_tree *tree = &rdeconf->lsa_tree; + struct area *area; + struct vertex *v; + + bzero(&sumctl, sizeof(struct ctl_sum)); + + sumctl.rtr_id.s_addr = rde_router_id(); + sumctl.spf_delay = rdeconf->spf_delay; + sumctl.spf_hold_time = rdeconf->spf_hold_time; + + LIST_FOREACH(area, &rdeconf->area_list, entry) + sumctl.num_area++; + + RB_FOREACH(v, lsa_tree, tree) + sumctl.num_ext_lsa++; + + sumctl.rfc1583compat = rdeconf->rfc1583compat; + + rde_imsg_compose_ospfe(IMSG_CTL_SHOW_SUM, 0, pid, &sumctl, + sizeof(sumctl)); +} + +void +rde_send_summary_area(struct area *area, pid_t pid) +{ + static struct ctl_sum_area sumareactl; + struct iface *iface; + struct rde_nbr *nbr; + struct lsa_tree *tree = &area->lsa_tree; + struct vertex *v; + + bzero(&sumareactl, sizeof(struct ctl_sum_area)); + + sumareactl.area.s_addr = area->id.s_addr; + sumareactl.num_spf_calc = area->num_spf_calc; + + LIST_FOREACH(iface, &area->iface_list, entry) + sumareactl.num_iface++; + + LIST_FOREACH(nbr, &area->nbr_list, entry) + if (nbr->state == NBR_STA_FULL && !nbr->self) + sumareactl.num_adj_nbr++; + + RB_FOREACH(v, lsa_tree, tree) + sumareactl.num_lsa++; + + rde_imsg_compose_ospfe(IMSG_CTL_SHOW_SUM_AREA, 0, pid, &sumareactl, + sizeof(sumareactl)); +} + LIST_HEAD(rde_nbr_head, rde_nbr); struct nbr_table { diff --git a/usr.sbin/ospfd/rde_spf.c b/usr.sbin/ospfd/rde_spf.c index 3e4b949e61c..f6f3c3a5678 100644 --- a/usr.sbin/ospfd/rde_spf.c +++ b/usr.sbin/ospfd/rde_spf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_spf.c,v 1.5 2005/03/12 11:03:05 norby Exp $ */ +/* $OpenBSD: rde_spf.c,v 1.6 2005/03/14 18:21:29 norby Exp $ */ /* * Copyright (c) 2005 Esben Norby @@ -243,7 +243,7 @@ spf_calc(struct area *area) PT_INTRA_AREA, DT_NET); } - /* routers */ + /* router */ addr.s_addr = htonl(v->ls_id); adv_rtr.s_addr = htonl(v->adv_rtr); @@ -299,6 +299,7 @@ spf_calc(struct area *area) log_debug("spf_calc: calculation ended, area ID %s", inet_ntoa(area->id)); + area->num_spf_calc++; start_spf_timer(rdeconf); return; -- cgit v1.2.3