Printer FriendlyEmail Article Link

Spirent TestCenter-JTAPI: need a script which emulates DHCP client/server and get results.

Environment/Versions

Spirent TestCenter

Linux OS

Answer

See example script of how to script DHCP client/server and get results below:

###################################################################################################################
                              #
# Body :                               #
# 1) Connect to a chassis and reserve 2 ports.                      #
# 2) Configure DHCP server on one port and DHCP client on another
# 3) Start DHCP and then rebind DHCP
# 4) Stop DHCP and then rebind DHCP
# 5) Remove ports and then re-configure DHCP sever and client
#                                                                                                                 #
# Pass/Fail Criteria:  Script pass if:                                                                #
# 1) Reserve 2 ports successfully.                         #
# 2)
#                                 #

use strict;
use warnings;
use Data::Dumper;
use Spirent;
use JHelper;
#---------------Basic variables
my $chassisAddr = "10.61.36.100";
my $portlist = "11/3 11/4";
##############################################################
print "\nstep1: Connect to a chassis and reserve 2 ports.\n";
##############################################################
my $rt = new Spirent(host=>$chassisAddr);
die "Cannot get handle to object" unless ($rt);
#Reserve ports
print "\nReserve ports...\n";
my @portList = split /\s+/,$portlist;
my $port1 = $chassisAddr."/".$portList[0];
print "\n----------------------Chassis_Slot_Port1 is $port1\n----------------------";
my $port2 = $chassisAddr."/".$portList[1];
print "\n----------------------Chassis_Slot_Port2 is $port2\n----------------------";
my @ports;
push @ports,{port=>$port1};
push @ports,{port=>$port2};
my $init = $rt->init_modules(port=>\@ports, ready_modules=>1, reboot=>0, arp=>1);
##################################################################################
print "\nstep2: Configure DHCP server on one port and DHCP client on another.\n";
#################################################################################
#------------setup dhcpv4 client--------------------------#
my @msgv4 = ({option_type=>"77", msg_type=>"DISCOVER", hex_value=>"true", remove=>"true"},{option_type=>"70", msg_type=>"REQUEST"});
my $dhcpv4= {session_host_name=>"blablabla",msgs=>\@msgv4};
my @host1 = $rt->setup_hosts(ports=>[$port1], host_count=>1,  ipv4_addr=>"1.1.1.1", prefix_length=>"8",
                                        ipv4_gw_addr=>"1.1.1.6", dhcp_config=>$dhcpv4);

#-------------setup dhcpv4 server------------------------#
my @msgs = ({option_type=>10, msg_type=>"ACK", enable_wildcards=>"true"},
            {option_type=>20, msg_type=>"ACK OFFER", enable_wildcards=>"true"});
my $addr_pool = {ipv4_addr_pool=>"1.1.1.10", ipv4_addr_count=>"100", msgs=>\@msgs};
my $dhcp_server = {lease_time=>"3000", renew_time_percent=>"50", rebind_time_percent=>"87.5", server_name=>"server", addr_pool=>$addr_pool};
my @host2 = $rt->setup_hosts(ports=>[$port2], host_count=>1, ipv4_addr=>"1.1.1.6", ipv4_gw_addr=>"1.1.1.1",
       mac_addr=>"00:60:f3:00:02:01", dhcp_server_config=>$dhcp_server);

$rt->invoke("stc::perform SaveasXml -config system1 -filename C:/Perl/lib/JTAPI/results/CR316026443.xml");          
#####################################################
print "\nstep3: Start DHCP and then rebind DHCP.\n";
#####################################################    
$rt->start_dhcp_server(hosts=>\@host2,wait=>1,time=>10);
$rt->start_dhcp(hosts=>\@host1,wait=>1,time=>60);
sleep (30);
$rt->get_dhcp_stats()

 


Product : Automation,API,Spirent TestCenter,DHCP