📄 ospf6_damp.c
字号:
int (*event) (void *), void *target){ time_t t_now, t_diff; struct ospf6_damp_info *di; char namebuf[64]; struct timeval now; if (dc->enabled == OFF) { (*event) (target); return; } di = ospf6_damp_lookup (type, name); if (! di) di = ospf6_damp_create (type, name); t_now = time (NULL); di->event = event; di->target = target; di->event_type = event_type; if (! ospf6_reuse_list_lookup (di)) di->t_start = t_now; else { ospf6_reuse_list_remove (di); t_diff = t_now - di->t_updated; di->penalty = (int) (di->penalty * ospf6_damp_decay (t_diff)); } /* penalty only on down event */ if (event_type == event_down) { di->flap++; di->penalty += dc->default_penalty; } /* limit penalty up to ceiling */ if (di->penalty > dc->ceiling) di->penalty = dc->ceiling; if (IS_OSPF6_DEBUG_DAMP) { prefix2str (&di->name, namebuf, sizeof (namebuf)); gettimeofday (&now, NULL); zlog_info ("DAMP: %lu.%06lu update penalty: type: %d, name: %s, penalty: %d", now.tv_sec, now.tv_usec, di->type, namebuf, di->penalty); } /* if penalty < reuse, stop damping here */ if (di->penalty < dc->reuse && di->damping == ON) { if (IS_OSPF6_DEBUG_DAMP) { prefix2str (&di->name, namebuf, sizeof (namebuf)); gettimeofday (&now, NULL); zlog_info ("DAMP: %lu.%06lu stop damping: %ld: type: %d, name: %s", now.tv_sec, now.tv_usec, t_now, di->type, namebuf); } di->damping = OFF; } /* if event == up and if penalty >= suppress , start damping here */ if (di->event_type == event_up && di->penalty >= dc->suppress && di->damping == OFF) { if (IS_OSPF6_DEBUG_DAMP) { prefix2str (&di->name, namebuf, sizeof (namebuf)); gettimeofday (&now, NULL); zlog_info ("DAMP: %lu.%06lu start damping: %ld: type: %d, name: %s", now.tv_sec, now.tv_usec, t_now, type, namebuf); } di->damping = ON; } /* execute event if we're not damping */ if (di->damping == OFF) { (*(di->event)) (di->target); di->target_status = di->event_type; } /* if the penalty goes beyond suppress value, start damping */ if (di->penalty >= dc->suppress && di->damping == OFF) { if (IS_OSPF6_DEBUG_DAMP) { prefix2str (name, namebuf, sizeof (namebuf)); gettimeofday (&now, NULL); zlog_info ("DAMP: %lu.%06lu start damping: %ld: type: %d, name: %s", now.tv_sec, now.tv_usec, t_now, type, namebuf); } di->damping = ON; } /* update last-updated-time field */ di->t_updated = t_now; /* Insert it into the reuse list */ ospf6_reuse_list_add (di);}voidospf6_damp_event_up (u_short type, struct prefix *name, int (*event) (void *), void *target){ struct timeval now; gettimeofday (&now, NULL); if (IS_OSPF6_DEBUG_DAMP) zlog_info ("DAMP: Up Event at %lu.%06lu", now.tv_sec, now.tv_usec); ospf6_damp_event (event_up, type, name, event, target);}voidospf6_damp_event_down (u_short type, struct prefix *name, int (*event) (void *), void *target){ struct timeval now; gettimeofday (&now, NULL); if (IS_OSPF6_DEBUG_DAMP) zlog_info ("DAMP: Down Event at %lu.%06lu", now.tv_sec, now.tv_usec); ospf6_damp_event (event_down, type, name, event, target);}intospf6_damp_debug_thread (struct thread *thread){ int i; struct ospf6_damp_info *di; char buf[256]; time_t t_now; struct timeval now; for (i = 0; i < dc->reuse_list_size; i++) { for (di = dc->reuse_list_array[i]; di; di = di->next) { t_now = time (NULL); gettimeofday (&now, NULL); prefix2str (&di->name, buf, sizeof (buf)); zlog_info ("DAMP: %lu.%06lu %c %-32s penalty %7u", now.tv_sec, now.tv_usec, (di->damping == ON ? 'D' : 'A'), buf, (u_int) (di->penalty * ospf6_damp_decay (t_now - di->t_updated))); } } thread_add_timer (master, ospf6_damp_debug_thread, NULL, 1); return 0;}DEFUN (show_ipv6_ospf6_route_flapping, show_ipv6_ospf6_route_flapping_cmd, "show ipv6 ospf6 route flapping", SHOW_STR IP6_STR OSPF6_STR){ int i; struct ospf6_damp_info *di; char buf[256]; time_t t_now; t_now = time (NULL); vty_out (vty, "%c %-32s %7s%s", ' ', "Prefix", "penalty", VTY_NEWLINE); for (i = 0; i < dc->reuse_list_size; i++) { for (di = dc->reuse_list_array[i]; di; di = di->next) { prefix2str (&di->name, buf, sizeof (buf)); vty_out (vty, "%c %-32s %7u%s", (di->damping == ON ? 'D' : ' '), buf, (u_int) (di->penalty * ospf6_damp_decay (t_now - di->t_updated)), VTY_NEWLINE); } } return CMD_SUCCESS;}DEFUN (ospf6_flap_damping_route, ospf6_flap_damping_route_cmd, "flap-damping route <0-4294967295> <0-4294967295> " "<0-4294967295> <0-4294967295>", "enable flap dampening\n" "enable route flap dampening\n" "half-life in second\n" "reuse value\n" "suppress value\n" "t-hold in second (maximum time that the target can be damped)\n" ){ u_int half_life, reuse, suppress, t_hold; if (argc) { half_life = (u_int) strtoul (argv[0], NULL, 10); reuse = (u_int) strtoul (argv[1], NULL, 10); suppress = (u_int) strtoul (argv[2], NULL, 10); t_hold = (u_int) strtoul (argv[3], NULL, 10); } else { half_life = (u_int) DEFAULT_HALF_LIFE; reuse = (u_int) DEFAULT_REUSE; suppress = (u_int) DEFAULT_SUPPRESS; t_hold = (u_int) DEFAULT_HALF_LIFE * 4; } if (reuse && suppress && reuse >= suppress) { vty_out (vty, "reuse value exceeded suppress value, failed%s\n", VTY_NEWLINE); return CMD_SUCCESS; } if (half_life && t_hold && half_life >= t_hold) { vty_out (vty, "half-life exceeded t-hold, failed%s\n", VTY_NEWLINE); return CMD_SUCCESS; } ospf6_damp_init_config (half_life, reuse, suppress, t_hold); if (ospf6_reuse_thread == NULL) ospf6_reuse_thread = thread_add_timer (master, ospf6_damp_reuse_timer, NULL, dc->delta_reuse); return CMD_SUCCESS;}DEFUN (show_ipv6_ospf6_damp_config, show_ipv6_ospf6_camp_config_cmd, "show ipv6 ospf6 damp config", SHOW_STR IP6_STR OSPF6_STR "Flap-dampening information\n" "shows dampening configuration\n" ){ int i; vty_out (vty, "%10s %10s %10s %10s%s", "Half life", "Suppress", "Reuse", "T-hold", VTY_NEWLINE); vty_out (vty, "%10u %10u %10u %10u%s", dc->half_life, dc->suppress, dc->reuse, dc->t_hold, VTY_NEWLINE); vty_out (vty, "%s", VTY_NEWLINE); vty_out (vty, "Delta-t = %u%s", dc->delta_t, VTY_NEWLINE); vty_out (vty, "Delta-Reuse = %u%s", dc->delta_reuse, VTY_NEWLINE); vty_out (vty, "Default-Penalty = %u%s", dc->default_penalty, VTY_NEWLINE); vty_out (vty, "Ceiling = %u%s", dc->ceiling, VTY_NEWLINE); vty_out (vty, "ScaleFactor = %f%s", dc->scale_factor, VTY_NEWLINE); vty_out (vty, "DecayArray(%d) =%s", dc->decay_array_size, VTY_NEWLINE); for (i = 0; i < dc->decay_array_size; i++) { if (i % 10 == 0) vty_out (vty, " "); vty_out (vty, " %f", dc->decay_array[i]); if (i % 10 == 0) vty_out (vty, "%s", VTY_NEWLINE); } vty_out (vty, "%s", VTY_NEWLINE); vty_out (vty, "ReuseIndexArray(%d) =%s", dc->reuse_index_array_size, VTY_NEWLINE); for (i = 0; i < dc->reuse_index_array_size; i++) { if (i % 10 == 0) vty_out (vty, " "); vty_out (vty, " %d", dc->reuse_index_array[i]); if (i % 10 == 0) vty_out (vty, "%s", VTY_NEWLINE); } vty_out (vty, "%s", VTY_NEWLINE); return CMD_SUCCESS;}voidospf6_damp_config_write (struct vty *vty){ if (dc->enabled == ON) { vty_out (vty, " flap-damping route %u %u %u %u%s", dc->half_life, dc->reuse, dc->suppress, dc->t_hold, VTY_NEWLINE); }}DEFUN (debug_ospf6_damp, debug_ospf6_damp_cmd, "debug ospf6 damp", DEBUG_STR OSPF6_STR "Flap-dampening information\n" ){ ospf6_damp_debug = 1; return CMD_SUCCESS;}DEFUN (no_debug_ospf6_damp, no_debug_ospf6_damp_cmd, "no debug ospf6 damp", NO_STR DEBUG_STR OSPF6_STR "Flap-dampening information\n" ){ ospf6_damp_debug = 0; return CMD_SUCCESS;}DEFUN (show_debug_ospf6_damp, show_debug_ospf6_damp_cmd, "show debugging ospf6 damp", SHOW_STR DEBUG_STR OSPF6_STR "Flap-dampening information\n" ){ vty_out (vty, "debugging ospf6 damp is "); if (IS_OSPF6_DEBUG_DAMP) vty_out (vty, "enabled."); else vty_out (vty, "disabled."); vty_out (vty, "%s", VTY_NEWLINE); return CMD_SUCCESS;}voidospf6_damp_init (){ int i; for (i = 0; i < OSPF6_DAMP_TYPE_MAX; i++) damp_info_table[i] = route_table_init (); install_element (VIEW_NODE, &show_ipv6_ospf6_route_flapping_cmd); install_element (ENABLE_NODE, &show_ipv6_ospf6_route_flapping_cmd); install_element (ENABLE_NODE, &show_ipv6_ospf6_camp_config_cmd); install_element (OSPF6_NODE, &ospf6_flap_damping_route_cmd); install_element (ENABLE_NODE, &show_debug_ospf6_damp_cmd); install_element (CONFIG_NODE, &debug_ospf6_damp_cmd); install_element (CONFIG_NODE, &no_debug_ospf6_damp_cmd); thread_add_event (master, ospf6_damp_debug_thread, NULL, 0);}#endif /* HAVE_OSPF6_DAMP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -