ipprobe-mt_ui.c

Go to the documentation of this file.
00001 /*
00002  * $Id: ipprobe-mt_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 
00021 #include <string.h>
00022 #include <sys/types.h>
00023 #include <sys/queue.h>
00024 #include <isc/eventlib.h>
00025 #include <netinet/in.h>
00026 #include <netinet/in_systm.h>
00027 #include <netinet/ip.h>
00028 #include <netinet/udp.h>
00029 #include <netinet/ip_icmp.h>
00030 #include <arpa/inet.h>
00031 #include <jnx/aux_types.h>
00032 #include <jnx/bits.h>
00033 #include <jnx/patricia.h>
00034 #include <jnx/pconn.h>
00035 #include <jnx/junos_trace.h>
00036 #include <jnx/mgmt_sock_pub.h>
00037 #include <jnx/ms_parse.h>
00038 #include <jnx/parse_ip.h>
00039 #include <junoscript/xmllib_pub.h>
00040 #include <junoscript/xmlrpc.h>
00041 #include <junoscript/xmlstr.h>
00042 #include "ipprobe-mt.h"
00043 #include IPPROBE_MT_OUT_H
00044 #include IPPROBE_MT_ODL_H
00045 
00059 static int32_t
00060 show_probe (mgmt_sock_t *msp, parse_status_t* csb UNUSED, char *unparsed)
00061 {
00062     probe_params_t *params;
00063     patroot *dst_pat;
00064     probe_dst_t *dst;
00065     struct in_addr addr;
00066     char buf[64];
00067 
00068     XML_OPEN(msp, ODCI_PROBE_REPORT);
00069     params = probe_params_get(unparsed);
00070     if (!params) {
00071         XML_ELT(msp, ODCI_PROBE_MSG, "Probe %s is not configured!", unparsed);
00072         XML_CLOSE(msp, ODCI_PROBE_REPORT);
00073         return 0;
00074     }
00075     XML_OPEN(msp, ODCI_PROBE_INFO);
00076     XML_ELT(msp, ODCI_PROBE_NAME, "%s", params->name);
00077     XML_ELT(msp, ODCI_PKT_SIZE, "%d", params->pkt_size);
00078     XML_ELT(msp, ODCI_PKT_COUNT, "%d", params->pkt_count);
00079     XML_ELT(msp, ODCI_PKT_INTERVAL, "%d", params->pkt_interval);
00080     XML_CLOSE(msp, ODCI_PROBE_INFO);
00081 
00082     dst_pat = probe_mngr_probe_result_get(unparsed);    
00083     if (!dst_pat) {
00084         XML_ELT(msp, ODCI_PROBE_MSG, "Probe %s thread is not setup!", unparsed);
00085         XML_CLOSE(msp, ODCI_PROBE_REPORT);
00086         return 0;
00087     }
00088     dst = (probe_dst_t *)patricia_find_next(dst_pat, NULL);
00089     while (dst) {
00090         XML_OPEN(msp, ODCI_PROBE_RESULT);
00091 
00092         XML_OPEN(msp, ODCI_RESULT_DST);
00093         addr.s_addr = dst->dst_addr;
00094         XML_ELT(msp, ODCI_PROBE_DST, "%s", inet_ntoa(addr));
00095         XML_CLOSE(msp, ODCI_RESULT_DST);
00096 
00097         XML_OPEN(msp, ODCI_RESULT_TABLE);
00098         XML_ELT(msp, ODCI_PROBE_PATH, "%s", "source->destination");
00099         sprintf(buf, "%8.3f", dst->result.delay_sd_average);
00100         XML_ELT(msp, ODCI_AVERAGE_DELAY, "%s", buf);
00101         sprintf(buf, "%8.3f", dst->result.delay_sd_max);
00102         XML_ELT(msp, ODCI_MAX_DELAY, "%s", buf);
00103         sprintf(buf, "%8.3f", dst->result.jitter_sd_average);
00104         XML_ELT(msp, ODCI_AVERAGE_JITTER, "%s", buf);
00105         sprintf(buf, "%8.3f", dst->result.jitter_sd_max);
00106         XML_ELT(msp, ODCI_MAX_JITTER, "%s", buf);
00107 
00108         XML_ELT(msp, ODCI_PROBE_PATH, "%s", "destination->source");
00109         sprintf(buf, "%8.3f", dst->result.delay_ds_average);
00110         XML_ELT(msp, ODCI_AVERAGE_DELAY, "%s", buf);
00111         sprintf(buf, "%8.3f", dst->result.delay_ds_max);
00112         XML_ELT(msp, ODCI_MAX_DELAY, "%s", buf);
00113         sprintf(buf, "%8.3f", dst->result.jitter_ds_average);
00114         XML_ELT(msp, ODCI_AVERAGE_JITTER, "%s", buf);
00115         sprintf(buf, "%8.3f", dst->result.jitter_ds_max);
00116         XML_ELT(msp, ODCI_MAX_JITTER, "%s", buf);
00117 
00118         XML_ELT(msp, ODCI_PROBE_PATH, "%s", "round->trip");
00119         sprintf(buf, "%8.3f", dst->result.delay_rr_average);
00120         XML_ELT(msp, ODCI_AVERAGE_DELAY, "%s", buf);
00121         sprintf(buf, "%8.3f", dst->result.delay_rr_max);
00122         XML_ELT(msp, ODCI_MAX_DELAY, "%s", buf);
00123         sprintf(buf, "%8.3f", dst->result.jitter_rr_average);
00124         XML_ELT(msp, ODCI_AVERAGE_JITTER, "%s", buf);
00125         sprintf(buf, "%8.3f", dst->result.jitter_rr_max);
00126         XML_ELT(msp, ODCI_MAX_JITTER, "%s", buf);
00127         XML_CLOSE(msp, ODCI_RESULT_TABLE);
00128 
00129         XML_CLOSE(msp, ODCI_PROBE_RESULT);
00130         dst = (probe_dst_t *)patricia_find_next(dst_pat, (patnode *)dst);
00131     }
00132 
00133     XML_CLOSE(msp, ODCI_PROBE_REPORT);
00134     return 0;
00135 }
00136 
00150 static int32_t
00151 start_probe (mgmt_sock_t *msp UNUSED, parse_status_t* csb UNUSED,
00152         char *unparsed)
00153 {
00154     char sep[] = "\t ";
00155     char *probe_name;
00156     char *word;
00157     int af = AF_INET;
00158     struct in_addr addr;
00159 
00160     if (!unparsed) {
00161         /* This should never happen because of the 'mandatory' flag in DDL. */
00162         return 0;
00163     }
00164     XML_OPEN(msp, ODCI_PROBE_REPORT);
00165     word = strsep(&unparsed, sep);
00166     if (strncmp(word, "probe", 5) == 0) {
00167         probe_name = strsep(&unparsed, sep);
00168     } else {
00169         XML_ELT(msp, ODCI_PROBE_MSG, "%s", "Missing 'probe'!");
00170         goto ret_ok;
00171     }
00172     word = strsep(&unparsed, sep);
00173     if (strncmp(word, "destination", 11) == 0) {
00174         word = strsep(&unparsed, sep);
00175         if (parse_ipaddr(&af, word, 0, &addr, sizeof(addr), NULL, NULL, NULL,
00176                 NULL, 0, NULL, 0) != PARSE_OK) {
00177             XML_ELT(msp, ODCI_PROBE_MSG, "%s", "Parse IP address ERROR!");
00178             goto ret_ok;
00179         }
00180     } else {
00181         XML_ELT(msp, ODCI_PROBE_MSG, "%s", "Missing 'destination'!");
00182         goto ret_ok;
00183     }
00184     if (probe_mngr_probe_start(probe_name, addr.s_addr) < 0) {
00185         XML_ELT(msp, ODCI_PROBE_MSG, "Probe %s is not configured!", probe_name);
00186     } else {
00187         XML_ELT(msp, ODCI_PROBE_MSG, "Probe %s started.", probe_name);
00188     }
00189 
00190 ret_ok:
00191     XML_CLOSE(msp, ODCI_PROBE_REPORT);
00192     return 0;
00193 }
00194 
00208 static int32_t
00209 stop_probe (mgmt_sock_t *msp, parse_status_t* csb UNUSED, char *unparsed)
00210 {
00211     XML_OPEN(msp, ODCI_PROBE_REPORT);
00212     if (probe_mngr_probe_stop(unparsed) < 0) {
00213         XML_ELT(msp, ODCI_PROBE_MSG, "Stop probe %s ERROR!", unparsed);
00214     } else {
00215         XML_ELT(msp, ODCI_PROBE_MSG, "Probe %s is stopped.", unparsed);
00216     }
00217     XML_CLOSE(msp, ODCI_PROBE_REPORT);
00218     return 0;
00219 }
00220 
00234 static int32_t
00235 clear_probe (mgmt_sock_t *msp, parse_status_t* csb UNUSED, char *unparsed)
00236 {
00237     XML_OPEN(msp, ODCI_PROBE_REPORT);
00238     if (probe_mngr_probe_clear(unparsed) < 0) {
00239         XML_ELT(msp, ODCI_PROBE_MSG, "Probe %s is not cleared!", unparsed);
00240     } else {
00241         XML_ELT(msp, ODCI_PROBE_MSG, "Probe %s is cleared.", unparsed);
00242     }
00243     XML_CLOSE(msp, ODCI_PROBE_REPORT);
00244 
00245     return 0;
00246 }
00247 
00248 /*** GLOBAL/EXTERNAL Functions ***/
00249 
00250 /*
00251  * Menu Structure
00252  *
00253  * format (from libjuniper's ms_parse.h):
00254  *   command,
00255  *   help desc (or NULL),
00256  *   user data arg block (or 0),
00257  *   child (next) menu (or NULL),
00258  *   handler for command(or 0)
00259  */
00260 
00261 /* request sync ipprobe-mt ... commands */
00262 static const parse_menu_t request_sync_probe_menu[] = {
00263     { "start", NULL, 0, NULL, start_probe },
00264     { "stop", NULL, 0, NULL, stop_probe },
00265     { "clear", NULL, 0, NULL, clear_probe },
00266     { NULL, NULL, 0, NULL, NULL }
00267 };
00268 
00269 /* request sync ... commands */
00270 static const parse_menu_t request_sync_menu[] = {
00271     { "ipprobe-mt", NULL, 0, request_sync_probe_menu, NULL },
00272     { NULL, NULL, 0, NULL, NULL }
00273 };
00274 
00275 /* request ... commands */
00276 static const parse_menu_t request_menu[] = {
00277     { "sync", NULL, 0, request_sync_menu, NULL },
00278     { NULL, NULL, 0, NULL, NULL }
00279 };
00280 
00281 /* show sync ... commands */
00282 static const parse_menu_t show_sync_menu[] = {
00283     { "ipprobe-mt", NULL, 0, NULL, show_probe },
00284     { NULL, NULL, 0, NULL, NULL }
00285 };
00286 
00287 /* show ... commands */
00288 static const parse_menu_t show_menu[] = {
00289     { "sync", NULL, 0, show_sync_menu, NULL },
00290     { NULL, NULL, 0, NULL, NULL }
00291 };
00292 
00293 /* clear sync ... commands */
00294 static const parse_menu_t clear_sync_menu[] = {
00295     { "ipprobe-mt", NULL, 0, NULL, clear_probe },
00296     { NULL, NULL, 0, NULL, NULL }
00297 };
00298 
00299 /* clear ... commands */
00300 static const parse_menu_t clear_menu[] = {
00301     { "sync", NULL, 0, clear_sync_menu, NULL },
00302     { NULL, NULL, 0, NULL, NULL }
00303 };
00304 
00305 /* main menu of commands */
00306 const parse_menu_t master_menu[] = {
00307     { "show", NULL, 0, show_menu, NULL }, 
00308     { "request", NULL, 0, request_menu, NULL },
00309     { NULL, NULL, 0, NULL, NULL }
00310 };
00311 

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:00 2010 for SDK Your Net Corporation IP Probe MT: ipprobe-mt 1.0 by Doxygen 1.5.1