monitube-mgmt_ui.c

Go to the documentation of this file.
00001 /*
00002  * $Id: monitube-mgmt_ui.c 346460 2009-11-14 05:06:47Z ssiano $
00003  *
00004  * This code is provided as is by Juniper Networks SDK Developer Support.
00005  * It is provided with no warranties or guarantees, and Juniper Networks
00006  * will not provide support or maintenance of this code in any fashion.
00007  * The code is provided only to help a developer better understand how
00008  * the SDK can be used.
00009  * 
00010  * Copyright (c) 2008, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013  
00014 
00022 #include <sync/common.h>
00023 #include <junoscript/xmllib_pub.h>
00024 #include <junoscript/xmlrpc.h>
00025 #include <junoscript/xmlstr.h>
00026 #include <ddl/defs.h>
00027 #include "monitube-mgmt_main.h"
00028 #include "monitube-mgmt_config.h"
00029 #include "monitube-mgmt_conn.h"
00030 #include "monitube-mgmt_logging.h"
00031 
00032 #include MONITUBE_ODL_H
00033 #include MONITUBE_OUT_H
00034 
00035 /*** Constants ***/
00036 
00037 
00038 /*** Data Structures ***/
00039 
00040 
00041 // See menu structure at the bottom of this file
00042 
00043 
00044 /*** STATIC/INTERNAL Functions ***/
00045 
00046 
00056 static void
00057 show_monitor_stats(mgmt_sock_t * msp, monitor_t * mon)
00058 {
00059     flowstat_t * fs;
00060     struct in_addr addr;
00061     int i;
00062     double max_df, min_df, avg_df;
00063     uint32_t max_mlr, min_mlr, avg_mlr, total_loss;
00064     
00065     XML_OPEN(msp, ODCI_MONITOR_GROUP);
00066     
00067     XML_ELT(msp, ODCI_GROUP_NAME, "%s", mon->name);
00068     
00069     XML_OPEN(msp, ODCI_FLOW_STATS);
00070     
00071     fs = next_flowstat(mon, NULL);
00072     while(fs != NULL) {
00073 
00074         // We don't break down flow stats per FPC/PIC SLOT although we store it
00075         // so some flows may have multiple statistics
00076         
00077         XML_OPEN(msp, ODCI_FLOW_STAT);
00078         addr.s_addr = fs->flow_addr;
00079         
00080         XML_ELT(msp, ODCI_FLOW_ADDRESS, "%s:%d",
00081                     inet_ntoa(addr), fs->flow_port);
00082         
00083         if(fs->reports >= STATS_BASE_WINDOW) {
00084             if(fs->window_position == 0) {
00085                 i = STATS_BASE_WINDOW;
00086             } else {
00087                 i = fs->window_position - 1;
00088             }
00089             
00090             XML_ELT(msp, ODCI_LAST_MDI_STAT, "%.4f:%d",
00091                     fs->last_mdi_df[i], fs->last_mdi_mlr[i]);
00092             
00093             max_df = min_df = avg_df = fs->last_mdi_df[0];
00094             max_mlr = min_mlr = avg_mlr = fs->last_mdi_mlr[0];
00095             
00096             for(i = 1; i < STATS_BASE_WINDOW; ++i) {
00097                 if(fs->last_mdi_df[i] > max_df) {
00098                     max_df = fs->last_mdi_df[i];
00099                 } else if(fs->last_mdi_df[i] < min_df) {
00100                     min_df = fs->last_mdi_df[i];
00101                 }
00102                 
00103                 if(fs->last_mdi_mlr[i] > max_mlr) {
00104                     max_mlr = fs->last_mdi_mlr[i];
00105                 } else if(fs->last_mdi_mlr[i] < min_mlr) {
00106                     min_mlr = fs->last_mdi_mlr[i];
00107                 }
00108                 
00109                 avg_df += fs->last_mdi_df[i];
00110                 avg_mlr += fs->last_mdi_mlr[i];
00111             }
00112             
00113             avg_df /= STATS_BASE_WINDOW;
00114             total_loss = avg_mlr;
00115             avg_mlr /= STATS_BASE_WINDOW;
00116             
00117             XML_ELT(msp, ODCI_MAX_MDI_STAT, "%.4f:%d", max_df, max_mlr);
00118             XML_ELT(msp, ODCI_MIN_MDI_STAT, "%.4f:%d", min_df, min_mlr);
00119             XML_ELT(msp, ODCI_AVG_MDI_STAT, "%.4f:%d", avg_df, avg_mlr);
00120             XML_ELT(msp, ODCI_TOTAL_LOSS, "%d", total_loss);
00121         }        
00122 
00123         XML_CLOSE(msp, ODCI_FLOW_STAT);
00124 
00125         fs = next_flowstat(mon, fs);
00126     }
00127     
00128     XML_CLOSE(msp, ODCI_FLOW_STATS);
00129     
00130     XML_CLOSE(msp, ODCI_MONITOR_GROUP);
00131 }
00132 
00133 
00148 static int32_t
00149 monitube_show_stats(mgmt_sock_t * msp,
00150                     parse_status_t * csb __unused,
00151                     char * unparsed)
00152 {
00153     char * mon_name = unparsed;
00154     monitor_t * mon;
00155     
00156     XML_OPEN(msp, ODCI_MONITUBE_STATS);
00157 
00158     if(mon_name == NULL) {
00159         // show all service sets
00160         mon = next_monitor(NULL);
00161         while(mon != NULL) {
00162 
00163             show_monitor_stats(msp, mon);
00164 
00165             mon = next_monitor(mon);
00166         }
00167     } else { // show only given monitor
00168         if((mon = find_monitor(mon_name)) != NULL) {
00169             
00170             show_monitor_stats(msp, mon);
00171 
00172         } else {
00173             XML_RAW(msp, 0, xml_error_str(FALSE, NULL, NULL, NULL, NULL, 
00174                mon_name, NULL, "Monitor group name not found"));
00175         }
00176     }
00177     
00178     XML_CLOSE(msp, ODCI_MONITUBE_STATS);
00179     
00180     return 0;
00181 }
00182 
00183 
00184 
00199 static int32_t
00200 monitube_clear_stats(mgmt_sock_t * msp,
00201                      parse_status_t * csb __unused,
00202                      char * unparsed)
00203 {
00204     char * mon_name = unparsed;
00205     
00206     XML_OPEN(msp, ODCI_MONITUBE_CLEAR_STATUS);
00207 
00208     if(mon_name == NULL) {
00209         
00210         clear_all_flowstats();
00211         XML_ELT(msp, ODCI_GROUP_NAME, "%s", "<all groups>");
00212         
00213     } else { // clear stats only in given monitor
00214         if(clear_flowstats(mon_name) == 0) {
00215             
00216             XML_ELT(msp, ODCI_GROUP_NAME, "%s", mon_name);
00217             
00218         } else {
00219             XML_RAW(msp, 0, xml_error_str(FALSE, NULL, NULL, NULL, NULL, 
00220                mon_name, NULL, "Monitor group name not found"));
00221         }
00222     }
00223     
00224     XML_CLOSE(msp, ODCI_MONITUBE_CLEAR_STATUS);
00225     
00226     return 0;
00227 }
00228 
00229 
00230 /*** GLOBAL/EXTERNAL Functions ***/
00231 
00232 
00233 
00234 /******************************************************************************
00235  *                        Menu Structure
00236  *****************************************************************************/
00237 
00238 /*
00239  * format (from libjuniper's ms_parse.h):
00240  *   command,
00241  *   help desc (or NULL),
00242  *   user data arg block (or 0),
00243  *   child (next) menu (or NULL),
00244  *   handler for command(or 0)
00245  */
00246 
00247 
00251 static const parse_menu_t show_sync_monitube_menu[] = {
00252     { "statistics", NULL, 0, NULL, monitube_show_stats },
00253     { NULL, NULL, 0, NULL, NULL }
00254 };
00255 
00259 static const parse_menu_t clear_sync_monitube_menu[] = {
00260     { "statistics", NULL, 0, NULL, monitube_clear_stats },
00261     { NULL, NULL, 0, NULL, NULL }
00262 };
00263 
00267 static const parse_menu_t show_sync_menu[] = {
00268     { "monitube", NULL, 0, show_sync_monitube_menu, NULL },
00269     { NULL, NULL, 0, NULL, NULL }
00270 };
00271 
00275 static const parse_menu_t clear_sync_menu[] = {
00276     { "monitube", NULL, 0, clear_sync_monitube_menu, NULL },
00277     { NULL, NULL, 0, NULL, NULL }
00278 };
00279 
00283 static const parse_menu_t show_menu[] = {
00284     { "sync", NULL, 0, show_sync_menu, NULL },
00285     { NULL, NULL, 0, NULL, NULL }
00286 };
00287 
00291 static const parse_menu_t clear_menu[] = {
00292     { "sync", NULL, 0, clear_sync_menu, NULL },
00293     { NULL, NULL, 0, NULL, NULL }
00294 };
00295 
00299 const parse_menu_t master_menu[] = {
00300     { "show", NULL, 0, show_menu, NULL },
00301     { "clear", NULL, 0, clear_menu, NULL }, 
00302     { NULL, NULL, 0, NULL, NULL }
00303 };
00304 

2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:27:03 2010 for SDK Your Net Corporation Monitube IPTV Monitoring Example: monitube-mgmt 1.0 by Doxygen 1.5.1