Sending the Probe

The event handler send_packet() sends the probe packet, which is defined in the following structure in the ipprobe-manager.h file:

typedef struct {
    u_short id;                     /** Probe ID */
    u_short type;                   /** Packet type */
    u_short seq;                    /** Packet sequence number */
    struct timeval tx_time;         /** Initiator transmit time */
    struct timeval target_rx_time;  /** Target receive time */
    struct timeval target_tx_time;  /** Target transmit time */
    struct timeval rx_time;         /** Initiator receive time */
    char pad[0];                    /** Pad section */
} probe_packet_data_t;


typedef struct {
    struct ip header;           /** IP header */
    union {
        struct icmphdr icmp;    /** ICMP header */
        struct udphdr udp;      /** UDP header */
    };
    probe_packet_data_t data;   /** Packet data section */
} probe_packet_t;

Setting Up Time Tracking

This code sets up time-interval tracking by first calling the FreeBSD function gettimeofday() and storing the value in the packet data field tx_time. The tx_time field is a FreeBSD timeval structure that represents an elapsed time. It is declared in sys/time.h and has the following members:

The receive_probe_packets() handler on the target router declares another timeval structure, rx_time, and populates it in the same way. The process_probe_packets() function then calculates the difference between the two values. For example:

packet_stats[i].sd_delay = time_diff(&data_buf[i].tx_time,
                    &data_buf[i].target_rx_time);

For more information about the application's statistics gathering, see Receiving Reply Packets and Calculating Statistics.

Sending the Packet

The code that sends the probe packet is:

static void
send_packet (evContext ctx UNUSED, void *uap UNUSED,
        struct timespec due UNUSED, struct timespec inter UNUSED)
{
    probe_packet_t *packet = (probe_packet_t *)tx_buf;
    int send_len;

    do {
        packet->data.seq = tx_count;
        gettimeofday(&packet->data.tx_time, NULL);

        if (probe_params.protocol == IPPROTO_ICMP) {
            packet->icmp.icmp_cksum = 0;
            packet->icmp.icmp_cksum = icmp_cksum(&packet->icmp,
                    probe_params.packet_size - sizeof(struct ip));
        } else if (probe_params.protocol == IPPROTO_UDP) {
            packet->udp.uh_sum = 0;
            packet->udp.uh_sum = udp_cksum(ntohs(packet->udp.uh_ulen),
                    &packet->header.ip_src.s_addr,
                    &packet->header.ip_dst.s_addr,
                    &packet->udp);
        }

        send_len = sendto(tx_socket, packet, probe_params.packet_size, 0,
                (struct sockaddr *)&target_addr, sizeof(target_addr));
        if (send_len < 0) {
            PRINT_ERRORNO("Send probe packet!\n");
        }

        if (++tx_count == probe_params.packet_count) {

            /* Disable the timer. */
            evClearTimer(ev_ctx, ev_tx_timer_id);
            printf("Sent %d probe packets to %s.\n", tx_count,
                    inet_ntoa(target_addr.sin_addr));
            break;
        }
    } while (probe_params.packet_interval == 0);
    return;
}

Receiving Reply Packets and Calculating Statistics


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:26:47 2010 for Juniper Networks Partner Solution Development Platform JUNOS SDK 10.2R1 by Doxygen 1.4.5