Need to monitor DHCP performance remotely

Brad Dameron brad.dameron at clearwire.com
Thu Sep 25 19:19:45 UTC 2008


On Thu, 2008-09-25 at 11:48 -0700, Rob Tanner wrote:
> Hi,
> 
> I need to set up DHCP probes in several remote areas of campus to
> monitor DHCP response times -- not so much the performance of the
> server itself but rather how long it takes to get a response back over
> the network.  The probes would be running on statically addressed
> Linux boxes and log the response times.  
> 
> I have tried the Perl module Net::DHCP.  Amongst the example programs
> included in the package is dhcpd_test.pl.  When I try it from my
> desktop, it sends the DHCPDISCOVER packet but hangs waiting for the
> DHCPOFFER response.  A sniffer sees both the discover and the offer.
> DHCP programming is not my forté, so I'm not sure what's wrong.  Does
> anybody have some code that will work?  Or can someone suggest another
> package that might meet my needs.
> 
> Thanks,
> 
> Rob Tanner
> UNIX Service Manager
> Linfield College, Oregon


Here is a script I wrote you can use. Requires Net::DHCPClientLive, and
Logger::Syslog.

#!/usr/bin/perl -w
############################################################################
# This script tests the speed of DHCP requests.
# This script may be used free of charge but can not be included or sold
# as part of a commercial product.
#
# v1.0.0 - First Release - Brad Dameron (brad.dameron at clearwire.com)
10.18.2007
#
############################################################################

use strict;
use POSIX qw(setsid);
use Time::HiRes qw(gettimeofday);

# Logging modules
use Logger::Syslog;

# Service checking modules
use Net::DHCPClientLive;

# Set some variables
my $looptimer = 5;                      # Seconds between each loop. 
my $version = "1.0.0";                  # Code version. For display in
logs
my $interface1 = "bond0.2";             # Set the interface for the
4-way handshake
my $interface2 = "bond0.2";             # Set the interface for the
2-way handshake


my $twoway_end;
my $twoway_start;
my $fourway_end;
my $fourway_start;

my $check;
my $client;
my $client2;
my $date;
my $status;

my $end_timer;
my $start_timer;
my $end_seconds;
my $start_seconds;
my $end_ms;
my $start_ms;


# # # # # # # # # # # # # #
# Main 
# # # # # #

# Open a syslog socket on the 'local5' facility
logger_init('local5');

# Setup a new DHCP connections
$client = new Net::DHCPClientLive( interface => "$interface1", state =>
'INIT', cltmac => '00:00:00:00:00:01');
$client2 = new Net::DHCPClientLive( interface => "$interface2", state =>
'INIT', cltmac => '00:00:00:00:00:02');

# # # # # # # # # # # # # #
# Main Loop
# # # # # #

while(1) {

  # Check DHCP Server Status
  info("Checking DHCP server status");

  # Start timer
  $start_timer=[gettimeofday];
  ($start_seconds, $start_ms) = gettimeofday;

  # Initiate a 4-way handshake (Discover)
  $client->goState('BOUND');

  # Stop timer
  $end_timer=[gettimeofday];
  ($end_seconds, $end_ms) = gettimeofday;

  # If microseconds rolls over add 1000000 or get a negative number
  if ( $end_ms < $start_ms )
  { 
    $end_ms = $end_ms+1000000;
  }

  print "Time for fourway was ", ($end_seconds- $start_seconds), "
seconds - ", (($end_ms - $start_ms) / 1000), " milliseconds\n";

  # Start timer
  $start_timer=[gettimeofday];
  ($start_seconds, $start_ms) = gettimeofday;

  # Initiate a 2-way handshakre (Renew)
  $client2->goState('RENEW');

  # Stop timer
  $end_timer=[gettimeofday];
  ($end_seconds, $end_ms) = gettimeofday;

  print "Time for twoway was ", ($end_seconds- $start_seconds), "
seconds - ", (($end_ms - $start_ms) / 1000), " milliseconds\n";

  # Release 4-way handshake request
  $client->goState('INIT');

  # Pause for 5 seconds between checks
  sleep(5);

}

> 
> 
Brad Dameron
Senior Systems Engineer
Clearw're



More information about the dhcp-users mailing list