Printer FriendlyEmail Article Link

Spirent Testcenter-HLTAPI:How to retrieve the IP Address of the DHCP device after binding?

Environment/Versions
  • Spirent TestCenter
  • Automation-HLTAPI
  • DHCP
Answer

Below is the code

set device_ret1 [sth::emulation_dhcp_group_config\
                -mode                                             create\
                -dhcp_range_ip_type                               4\
                -encap                                            ethernet_ii\
                -handle                                           $dhcp_handle\
                -num_sessions                                     5 \
                -opt_list                                         "1 6 15 33 44" \
                -host_name                                        client_@p-@b-@s \
                -mac_addr                                         00:10:94:00:00:02 \
                -mac_addr_step                                    00:00:00:00:00:01 \
                -ipv4_gateway_address                             1.1.1.1 \
]

set status [keylget device_ret1 status]
if {$status == 0} {
        puts "run sth::emulation_dhcp_group_config failed"
        puts $device_ret1
} else {
        puts "***** run sth::emulation_dhcp_group_config successfully"
}
set dhcp_block_handle [keylget device_ret1 handles]
puts "The DHCP Block handle for the device is $dhcp_block_handle"

set ctrl_ret2 [sth::emulation_dhcp_control    \
                -port_handle                                      "$port2"\
                -action                                           bind\
                -ip_version                                       4\
]

set status [keylget ctrl_ret2 status]
if {$status == 0} {
        puts "run sth::emulation_dhcp_control failed"
        puts $ctrl_ret2
} else {
        puts "***** run sth::emulation_dhcp_control successfully"
}

after 10000

# To get the IP address of the device
stc::perform Dhcpv4ShowSessionInfoCommand -blocklist $dhcp_block_handle
set results_list [split [stc::get $dhcp_block_handle -children-Dhcpv4SessionResults] " "]
foreach result $results_list {
    set ipv4Addr [stc::get $result -Ipv4Addr]
    set macAddr [stc::get $result -MacAddr]
    puts "Device with macAddr $macAddr has been assigned $ipv4Addr\n"
}

 


Product : Access,Spirent TestCenter,Automation,API,Spirent TestCenter,DHCP