summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ospfd/ospf_interface.c12
-rw-r--r--ospfd/ospf_packet.c20
-rw-r--r--ospfd/ospf_vty.c215
3 files changed, 247 insertions, 0 deletions
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index 34a1e6f6d6..e8700e7eb0 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -453,6 +453,15 @@ struct ospf_interface *ospf_if_lookup_recv_if(struct ospf *ospf,
return match;
}
+static void ospf_if_reset_stats(struct ospf_interface *oi)
+{
+ oi->hello_in = oi->hello_out = 0;
+ oi->db_desc_in = oi->db_desc_out = 0;
+ oi->ls_req_in = oi->ls_req_out = 0;
+ oi->ls_upd_in = oi->ls_upd_out = 0;
+ oi->ls_ack_in = oi->ls_ack_out = 0;
+}
+
void ospf_if_stream_set(struct ospf_interface *oi)
{
/* set output fifo queue. */
@@ -468,6 +477,9 @@ void ospf_if_stream_unset(struct ospf_interface *oi)
ospf_fifo_free(oi->obuf);
oi->obuf = NULL;
+ /*reset protocol stats */
+ ospf_if_reset_stats(oi);
+
if (oi->on_write_q) {
listnode_delete(ospf->oi_write_q, oi);
if (list_isempty(ospf->oi_write_q))
diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c
index 47f5ee76d2..633c3deeaf 100644
--- a/ospfd/ospf_packet.c
+++ b/ospfd/ospf_packet.c
@@ -825,6 +825,26 @@ static int ospf_write(struct thread *thread)
"-----------------------------------------------------");
}
+ switch (type) {
+ case OSPF_MSG_HELLO:
+ oi->hello_out++;
+ break;
+ case OSPF_MSG_DB_DESC:
+ oi->db_desc_out++;
+ break;
+ case OSPF_MSG_LS_REQ:
+ oi->ls_req_out++;
+ break;
+ case OSPF_MSG_LS_UPD:
+ oi->ls_upd_out++;
+ break;
+ case OSPF_MSG_LS_ACK:
+ oi->ls_ack_out++;
+ break;
+ default:
+ break;
+ }
+
/* Now delete packet from queue. */
ospf_packet_delete(oi);
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 70e0da1158..df3cd16c1c 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -3666,6 +3666,154 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
return CMD_SUCCESS;
}
+static void show_ip_ospf_interface_traffic_sub(struct vty *vty,
+ struct ospf_interface *oi,
+ json_object *json_interface_sub,
+ u_char use_json)
+{
+ if (use_json) {
+ json_object_int_add(json_interface_sub,
+ "ifIndex",
+ oi->ifp->ifindex);
+ json_object_int_add(json_interface_sub,
+ "helloIn",
+ oi->hello_in);
+ json_object_int_add(json_interface_sub,
+ "helloOut",
+ oi->hello_out);
+ json_object_int_add(json_interface_sub,
+ "dbDescIn",
+ oi->db_desc_in);
+ json_object_int_add(json_interface_sub,
+ "dbDescOut",
+ oi->db_desc_out);
+ json_object_int_add(json_interface_sub,
+ "lsReqIn",
+ oi->ls_req_in);
+ json_object_int_add(json_interface_sub,
+ "lsReqOut",
+ oi->ls_req_out);
+ json_object_int_add(json_interface_sub,
+ "lsUpdIn",
+ oi->ls_upd_in);
+ json_object_int_add(json_interface_sub,
+ "lsUpdOut",
+ oi->ls_upd_out);
+ json_object_int_add(json_interface_sub,
+ "lsAckIn",
+ oi->ls_ack_in);
+ json_object_int_add(json_interface_sub,
+ "lsAckOut",
+ oi->ls_ack_out);
+ } else {
+ vty_out(vty,
+ "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
+ oi->ifp->name, oi->hello_in,
+ oi->hello_out,
+ oi->db_desc_in, oi->db_desc_out,
+ oi->ls_req_in, oi->ls_req_out,
+ oi->ls_upd_in, oi->ls_upd_out,
+ oi->ls_ack_in, oi->ls_ack_out);
+ }
+}
+
+/* OSPFv2 Packet Counters */
+static int show_ip_ospf_interface_traffic_common(struct vty *vty,
+ struct ospf *ospf,
+ char *intf_name,
+ int display_once,
+ u_char use_json)
+{
+ struct vrf *vrf = NULL;
+ struct interface *ifp = NULL;
+ json_object *json = NULL;
+ json_object *json_interface_sub = NULL;
+
+ if (!use_json && !display_once) {
+ vty_out(vty, "\n");
+ vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n",
+ "Interface", " HELLO", " DB-Desc", " LS-Req",
+ " LS-Update", " LS-Ack");
+ vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
+ " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx");
+ vty_out(vty,
+ "--------------------------------------------------------------------------------------------\n");
+ } else if (use_json) {
+ json = json_object_new_object();
+ }
+
+ if (intf_name == NULL) {
+ vrf = vrf_lookup_by_id(ospf->vrf_id);
+ FOR_ALL_INTERFACES (vrf, ifp) {
+ struct route_node *rn;
+ struct ospf_interface *oi;
+
+ if (ospf_oi_count(ifp) == 0)
+ continue;
+
+ for (rn = route_top(IF_OIFS(ifp)); rn;
+ rn = route_next(rn)) {
+ oi = rn->info;
+
+ if (oi == NULL)
+ continue;
+
+ if (use_json) {
+ json_interface_sub =
+ json_object_new_object();
+ }
+
+ show_ip_ospf_interface_traffic_sub(vty, oi,
+ json_interface_sub,
+ use_json);
+ if (use_json) {
+ json_object_object_add(json, ifp->name,
+ json_interface_sub);
+ }
+ }
+ }
+ } else {
+ /* Interface name is specified. */
+ ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
+ if (ifp != NULL) {
+ struct route_node *rn;
+ struct ospf_interface *oi;
+
+ if (ospf_oi_count(ifp) == 0) {
+ vty_out(vty, " OSPF not enabled on this interface %s\n",
+ ifp->name);
+ return CMD_SUCCESS;
+ }
+
+ for (rn = route_top(IF_OIFS(ifp)); rn;
+ rn = route_next(rn)) {
+ oi = rn->info;
+
+ if (use_json) {
+ json_interface_sub =
+ json_object_new_object();
+ }
+
+ show_ip_ospf_interface_traffic_sub(vty, oi,
+ json_interface_sub,
+ use_json);
+ if (use_json) {
+ json_object_object_add(json, ifp->name,
+ json_interface_sub);
+ }
+ }
+ }
+ }
+
+ if (use_json) {
+ vty_out(vty, "%s\n", json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
+ json_object_free(json);
+ }
+
+ return CMD_SUCCESS;
+}
+
DEFUN (show_ip_ospf_interface,
show_ip_ospf_interface_cmd,
"show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
@@ -3753,6 +3901,71 @@ DEFUN (show_ip_ospf_instance_interface,
return show_ip_ospf_interface_common(vty, ospf, argc, argv, 5, uj);
}
+DEFUN (show_ip_ospf_interface_traffic,
+ show_ip_ospf_interface_traffic_cmd,
+ "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
+ SHOW_STR
+ IP_STR
+ "OSPF information\n"
+ VRF_CMD_HELP_STR
+ "All VRFs\n"
+ "Interface information\n"
+ "Protocol Packet counters\n"
+ "Interface name\n"
+ JSON_STR)
+{
+ struct ospf *ospf = NULL;
+ struct listnode *node = NULL;
+ char *vrf_name = NULL, *intf_name = NULL;
+ bool all_vrf = FALSE;
+ int inst = 0;
+ int idx_vrf = 0, idx_intf = 0;
+ u_char uj = use_json(argc, argv);
+ int ret = CMD_SUCCESS;
+ int display_once = 0;
+
+ if (uj)
+ argc--;
+
+
+ OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
+
+ if (argv_find(argv, argc, "INTERFACE", &idx_intf))
+ intf_name = argv[idx_intf]->arg;
+
+ if (vrf_name) {
+ if (all_vrf) {
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+
+ ret = show_ip_ospf_interface_traffic_common(vty,
+ ospf, intf_name,
+ display_once,
+ uj);
+ display_once = 1;
+ }
+ return ret;
+ }
+ ospf = ospf_lookup_by_inst_name(inst, vrf_name);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ ret = show_ip_ospf_interface_traffic_common(vty, ospf,
+ intf_name,
+ display_once, uj);
+ } else {
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ ret = show_ip_ospf_interface_traffic_common(vty, ospf,
+ intf_name,
+ display_once, uj);
+ }
+
+ return ret;
+}
+
+
static void show_ip_ospf_neighbour_header(struct vty *vty)
{
vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
@@ -9484,6 +9697,8 @@ void ospf_vty_show_init(void)
install_element(VIEW_NODE, &show_ip_ospf_interface_cmd);
install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
+ /* "show ip ospf interface traffic */
+ install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd);
/* "show ip ospf neighbor" commands. */
install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);