monitube2-mgmt_ui.c

Go to the documentation of this file.
00001 /*
00002  * $Id: monitube2-mgmt_ui.c 347265 2009-11-19 13:55:39Z kdickman $
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) 2009, 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 "monitube2-mgmt_main.h"
00028 #include "monitube2-mgmt_config.h"
00029 #include "monitube2-mgmt_conn.h"
00030 #include "monitube2-mgmt_logging.h"
00031 
00032 #include MONITUBE2_ODL_H
00033 #include MONITUBE2_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 
00061 static int32_t
00062 monitube_show_stats(mgmt_sock_t * msp,
00063                     parse_status_t * csb UNUSED,
00064                     char * unparsed UNUSED)
00065 {
00066         flowstat_ss_t * fss = NULL;
00067         flowstat_t * fs = NULL;
00068         ss_info_t * ssi;
00069     struct in_addr addr;
00070     int i;
00071     double max_df, min_df, avg_df;
00072     uint32_t max_mlr, min_mlr, avg_mlr, total_loss;
00073 
00074     XML_OPEN(msp, ODCI_MONITUBE_STATS);
00075 
00076     fss =  next_flowstat_ss(fss);
00077     while(fss) {
00078         
00079         XML_OPEN(msp, ODCI_SERVICE_SET);
00080         
00081         XML_ELT(msp, ODCI_SSID, "%d", fss->ssid);
00082         
00083         // get service set name
00084         ssi = next_serviceset(NULL);
00085         while(ssi) {
00086                 if (ssi->id == fss->ssid) {
00087                 XML_ELT(msp, ODCI_SSNAME, "%s", ssi->name);
00088                 break;
00089                 }
00090                 ssi = next_serviceset(ssi);
00091         }
00092         
00093         if (!ssi) {
00094                 XML_ELT(msp, ODCI_SSNAME, "%s", "(not found)");
00095         }
00096         
00097         XML_OPEN(msp, ODCI_FLOW_STATS);
00098         
00099         fs = next_flowstat(fss, fs);
00100         while(fs) {
00101 
00102                         // We don't break down flow stats per FPC/PIC SLOT although we store it
00103                         // so some flows may have multiple statistics
00104                         
00105                         XML_OPEN(msp, ODCI_FLOW_STAT);
00106                         addr.s_addr = fs->flow_addr;
00107                         
00108                         XML_ELT(msp, ODCI_FLOW_ADDRESS, "%s:%d",
00109                                                 inet_ntoa(addr), fs->flow_port);
00110                         
00111                         if (fs->reports >= STATS_BASE_WINDOW) {
00112                                 if (fs->window_position == 0) {
00113                                         i = STATS_BASE_WINDOW;
00114                                 } else {
00115                                         i = fs->window_position - 1;
00116                                 }
00117                                 
00118                                 XML_ELT(msp, ODCI_LAST_MDI_STAT, "%.4f:%d",
00119                                                 fs->last_mdi_df[i], fs->last_mdi_mlr[i]);
00120                                 
00121                                 max_df = min_df = avg_df = fs->last_mdi_df[0];
00122                                 max_mlr = min_mlr = avg_mlr = fs->last_mdi_mlr[0];
00123                                 
00124                                 for(i = 1; i < STATS_BASE_WINDOW; ++i) {
00125                                         if (fs->last_mdi_df[i] > max_df) {
00126                                                 max_df = fs->last_mdi_df[i];
00127                                         } else if (fs->last_mdi_df[i] < min_df) {
00128                                                 min_df = fs->last_mdi_df[i];
00129                                         }
00130                                         
00131                                         if (fs->last_mdi_mlr[i] > max_mlr) {
00132                                                 max_mlr = fs->last_mdi_mlr[i];
00133                                         } else if (fs->last_mdi_mlr[i] < min_mlr) {
00134                                                 min_mlr = fs->last_mdi_mlr[i];
00135                                         }
00136                                         
00137                                         avg_df += fs->last_mdi_df[i];
00138                                         avg_mlr += fs->last_mdi_mlr[i];
00139                                 }
00140                                 
00141                                 avg_df /= STATS_BASE_WINDOW;
00142                                 total_loss = avg_mlr;
00143                                 avg_mlr /= STATS_BASE_WINDOW;
00144                                 
00145                                 XML_ELT(msp, ODCI_MAX_MDI_STAT, "%.4f:%d", max_df, max_mlr);
00146                                 XML_ELT(msp, ODCI_MIN_MDI_STAT, "%.4f:%d", min_df, min_mlr);
00147                                 XML_ELT(msp, ODCI_AVG_MDI_STAT, "%.4f:%d", avg_df, avg_mlr);
00148                                 XML_ELT(msp, ODCI_TOTAL_LOSS, "%d", total_loss);
00149                         }
00150 
00151                         XML_CLOSE(msp, ODCI_FLOW_STAT);
00152                 
00153             fs = next_flowstat(fss, fs);
00154         }
00155         
00156         XML_CLOSE(msp, ODCI_FLOW_STATS);
00157         XML_CLOSE(msp, ODCI_SERVICE_SET);
00158         
00159         fss = next_flowstat_ss(fss);
00160     }
00161     
00162     XML_CLOSE(msp, ODCI_MONITUBE_STATS);
00163     
00164     return 0;
00165 }
00166 
00167 
00168 
00183 static int32_t
00184 monitube_clear_stats(mgmt_sock_t * msp,
00185                      parse_status_t * csb UNUSED,
00186                      char * unparsed UNUSED)
00187 {
00188         clear_stats();
00189         
00190         XML_SEND_SUCCESS_TAG(msp);
00191     
00192     return 0;
00193 }
00194 
00195 
00196 /*** GLOBAL/EXTERNAL Functions ***/
00197 
00198 
00199 
00200 /******************************************************************************
00201  *                        Menu Structure
00202  *****************************************************************************/
00203 
00204 /*
00205  * format (from libjuniper's ms_parse.h):
00206  *   command,
00207  *   help desc (or NULL),
00208  *   user data arg block (or 0),
00209  *   child (next) menu (or NULL),
00210  *   handler for command(or 0)
00211  */
00212 
00213 
00217 static const parse_menu_t show_sync_monitube_menu[] = {
00218     { "statistics", NULL, 0, NULL, monitube_show_stats },
00219     { NULL, NULL, 0, NULL, NULL }
00220 };
00221 
00225 static const parse_menu_t clear_sync_monitube_menu[] = {
00226     { "statistics", NULL, 0, NULL, monitube_clear_stats },
00227     { NULL, NULL, 0, NULL, NULL }
00228 };
00229 
00233 static const parse_menu_t show_sync_menu[] = {
00234     { "monitube", NULL, 0, show_sync_monitube_menu, NULL },
00235     { NULL, NULL, 0, NULL, NULL }
00236 };
00237 
00241 static const parse_menu_t clear_sync_menu[] = {
00242     { "monitube", NULL, 0, clear_sync_monitube_menu, NULL },
00243     { NULL, NULL, 0, NULL, NULL }
00244 };
00245 
00249 static const parse_menu_t show_menu[] = {
00250     { "sync", NULL, 0, show_sync_menu, NULL },
00251     { NULL, NULL, 0, NULL, NULL }
00252 };
00253 
00257 static const parse_menu_t clear_menu[] = {
00258     { "sync", NULL, 0, clear_sync_menu, NULL },
00259     { NULL, NULL, 0, NULL, NULL }
00260 };
00261 
00265 const parse_menu_t master_menu[] = {
00266     { "show", NULL, 0, show_menu, NULL },
00267     { "clear", NULL, 0, clear_menu, NULL }, 
00268     { NULL, NULL, 0, NULL, NULL }
00269 };
00270 

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:04 2010 for SDK Your Net Corporation Monitube2 IPTV Monitoring Example: monitube2-mgmt 1.0 by Doxygen 1.5.1