/* *------------------------------------------------------------------ * Copyright (c) 2005-2016 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include "g2.h" /* * globals */ event_def_t g_eventdefs[NEVENTS]; /* * locals */ static GtkWidget *s_pointselbox; static FILE *s_hfp; static FILE *s_elog_hfp; static int s_basenum; static GtkWidget *s_event_buttons[NEVENTS]; static int s_min_shown_pointsel; static int s_max_shown_pointsel; static GtkWidget *s_allbutton; static GtkWidget *s_nonebutton; static GtkWidget *s_pointselbuttons; static GtkWidget *s_ps_vscroll; static GtkObject *s_ps_vsadj; static int g_neventdefs; enum button_click { ALL_BUTTON=1, NONE_BUTTON, }; /* * config params */ int c_maxpointsel; /**************************************************************************** * recompute_vscrollbar ****************************************************************************/ static void recompute_ps_vscrollbar (void) { GtkAdjustment *adj; ulong limit; adj = GTK_ADJUSTMENT(s_ps_vsadj); #ifdef NOTDEF /* This seems like the right calculation, but seems not to work */ if (g_neventdefs > c_maxpointsel) limit = g_neventdefs - c_maxpointsel; else limit = g_neventdefs; #else limit = g_neventdefs-1; #endif adj->lower = (gfloat)0.00; adj->upper = (gfloat)limit; adj->value = (gfloat)0.00; adj->step_increment = (gfloat)1.00; adj->page_increment = (gfloat)(c_maxpointsel / 3); adj->page_size = (gfloat)c_maxpointsel; gtk_adjustment_changed(adj); gtk_adjustment_value_changed(adj); gtk_widget_show(s_ps_vscroll); } /**************************************************************************** * point_select_callback ****************************************************************************/ static void point_select_callback(GtkToggleButton *item, gpointer data) { int i = (int) (unsigned long long) data; g_eventdefs[i].selected = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(s_event_buttons[i])); view1_display_when_idle(); } /**************************************************************************** * up_button ****************************************************************************/ static void up_button(void) { int i; int increment = c_maxpointsel/4; if (s_min_shown_pointsel == 0) return; s_min_shown_pointsel -= increment; if (s_min_shown_pointsel < 0) s_min_shown_pointsel = 0; s_max_shown_pointsel = s_min_shown_pointsel + c_maxpointsel; for (i = 0; i < g_neventdefs; i++) { if (i >= s_min_shown_pointsel && i <= s_max_shown_pointsel) gtk_widget_show(s_event_buttons[i]); else gtk_widget_hide(s_event_buttons[i]); } } #ifdef NOTDEF /**************************************************************************** * down_button ****************************************************************************/ static void down_button(void) { int i; int increment = c_maxpointsel/4; if (s_max_shown_pointsel == g_neventdefs) return; s_max_shown_pointsel += increment; if (s_max_shown_pointsel >= g_neventdefs) s_max_shown_pointsel = (g_neventdefs-1); s_min_shown_pointsel = s_max_shown_pointsel - c_maxpointsel; if (s_min_shown_pointsel < 0) s_min_shown_pointsel = 0; for (i = 0; i < g_neventdefs; i++) { if (i >= s_min_shown_pointsel && i <= s_max_shown_pointsel) gtk_widget_show(s_event_buttons[i]); else gtk_widget_hide(s_event_buttons[i]); } } #endif /**************************************************************************** * button_click_callback ****************************************************************************/ static void button_click_callback(GtkButton *item, gpointer data) { int i; enum button_click click = (enum button_click)data; switch (click) { case ALL_BUTTON: for (i = 0; i < g_neventdefs; i++) { gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(s_event_buttons[i]), TRUE); g_eventdefs[i].selected = TRUE; } break; case NONE_BUTTON: for (i = 0; i < g_neventdefs; i++) { gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(s_event_buttons[i]), FALSE); g_eventdefs[i].selected = FALSE; } break; } } /**************************************************************************** * scroll_callback ****************************************************************************/ static void scroll_callback (GtkAdjustment *adj, GtkWidget *notused) { int i; s_min_shown_pointsel = (int)adj->value; s_max_shown_pointsel = s_min_shown_pointsel + c_maxpointsel; for (i = 0; i < g_neventdefs; i++) { if (i >= s_min_shown_pointsel && i <= s_max_shown_pointsel) gtk_widget_show(s_event_buttons[i]); else gtk_widget_hide(s_event_buttons[i]); } } /**************************************************************************** * point_selector_init ****************************************************************************/ void point_selector_init(void) { c_maxpointsel = atol(getprop_default("event_selector_lines", "20")); s_pointselbox = gtk_vbox_new(FALSE,5); s_pointselbuttons = gtk_hbox_new(FALSE,5); s_allbutton = gtk_button_new_with_label("ALL"); gtk_widget_show(s_allbutton); s_nonebutton = gtk_button_new_with_label("NONE"); gtk_widget_show(s_nonebutton); gtk_signal_connect (GTK_OBJECT(s_allbutton), "clicked", GTK_SIGNAL_FUNC(button_click_callback), (gpointer) ALL_BUTTON); gtk_signal_connect (GTK_OBJECT(s_nonebutton), "clicked", GTK_SIGNAL_FUNC(button_click_callback), (gpointer) NONE_BUTTON); gtk_box_pack_start(GTK_BOX(s_pointselbuttons), s_allbutton, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(s_pointselbuttons), s_nonebutton, FALSE, FALSE, 0); gtk_widget_show(s_pointselbuttons); gtk_widget_ref(s_pointselbuttons); gtk_box_pack_start(GTK_BOX(s_pointselbox), s_pointselbuttons, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX(g_mainhbox), s_pointselbox, FALSE, FALSE, 0); s_ps_vsadj = gtk_adjustment_new(0.0 /* initial value */, 0.0 /* minimum value */, 2000.0 /* maximum value */, 0.1 /* step increment */, 10.0/* page increment */, 10.0/* page size */); s_ps_vscroll = gtk_vscrollbar_new (GTK_ADJUSTMENT(s_ps_vsadj)); gtk_signal_connect (GTK_OBJECT (s_ps_vsadj), "value-changed", GTK_SIGNAL_FUNC (scroll_callback), (gpointer)s_ps_vscroll); gtk_box_pack_end(GTK_BOX(g_mainhbox), s_ps_vscroll, FALSE, FALSE, 0); } /**************************************************************************** * sxerox ****************************************************************************/ char *sxerox (char *s) { char *rv; /* Note: g_malloc does or dies... */ rv = (char *)g_malloc(strlen(s)+1); strcpy (rv, s); return (rv); } /**************************************************************************** * reset_point_selector ****************************************************************************/ static void reset_point_selector(void) { int i; gtk_widget_hide(s_pointselbox); gtk_widget_hide(s_pointselbuttons); gtk_widget_hide(s_ps_vscroll); gtk_container_remove(GTK_CONTAINER(s_pointselbox), s_pointselbuttons); for (i = 0; i < g_neventdefs; i++) { if (s_event_buttons[i]) { gtk_container_remove(GTK_CONTAINER(s_pointselbox), s_event_buttons[i]); s_event_buttons[i] = 0; } } } /**************************************************************************** * create_point_selector ****************************************************************************/ static void create_point_selector(void) { int i; char tmpbuf [1024]; event_def_t *ep; GtkWidget *wp; for (i = 0; i < g_neventdefs; i++) { ep = &g_eventdefs[i]; sprintf(tmpbuf, "[%lu] %s", ep->event, ep->name ? ep->name : "(none)"); /* Hack to reduce width of point selectors */ if (strlen(tmpbuf) > 50) { tmpbuf[50] = 0; } wp = gtk_check_button_new_with_label (tmpbuf); s_event_buttons[i] = wp; gtk_signal_connect (GTK_OBJECT(wp), "toggled", GTK_SIGNAL_FUNC(point_select_callback), (gpointer) (unsigned long long) i); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(wp), TRUE); gtk_box_pack_start(GTK_BOX(s_pointselbox), wp, FALSE, FALSE, 0); } /* set up scroll parameters by faking an up-button */ s_min_shown_pointsel = 1; up_button(); gtk_box_pack_start(GTK_BOX(s_pointselbox), s_pointselbuttons, FALSE, FALSE, 0); gtk_widget_show(s_pointselbuttons); gtk_widget_show(s_pointselbox); gtk_widget_show(s_ps_vscroll); } /**************************************************************************** * remove_all_events ****************************************************************************/ static void remove_all_events(void) { event_def_t *ep; int i; for (i = 0; i < g_neventdefs; i++) { ep = &g_eventdefs[i]; if (!ep->is_clib) { if (ep->name) g_free(ep->name); if(ep->format) g_free(ep->format); } } g_neventdefs = 0; } /**************************************************************************** * add_event ****************************************************************************/ static void add_event(ulong event, char *name, char *format) { int i; event_def_t *ep; if (g_neventdefs >= NEVENTS) { g_error("Too many event definitions, increase NEVENTS!"); /*NOTREACHED*/ } /* Simple dup check, probably not needed very often */ for (i = 0; i < g_neventdefs; i++) { if (g_eventdefs[i].event == event) { g_warning("Duplicate def event %lu: first definition retained\n", event); return; } } ep = &g_eventdefs[g_neventdefs++]; ep->event = event; ep->name = sxerox(name); ep->format = sxerox(format); ep->selected = TRUE; } /**************************************************************************** * add_event_from_cpel_file ****************************************************************************/ void add_event_from_cpel_file(ulong event, char *event_format, char *datum_format) { event_def_t *ep; if (g_neventdefs >= NEVENTS) { g_error("Too many event definitions, increase NEVENTS!"); /*NOTREACHED*/ } ep = &g_eventdefs[g_neventdefs++]; ep->event = event; /* * Duplicate the strings for backward compatibility. Otherwise, * the g_free above will barf because the name/format strings are * actually in mmap'ed memory */ ep->name = sxerox(event_format); ep->format = sxerox(datum_format); ep->selected = TRUE; } /**************************************************************************** * add_event_from_clib_file **********************************************
/*
 * l2_uu_fwd.c : Foward unknown unicast packets to BD's configured interface
 *
 * Copyright (c) 2018 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARR