Home > Ixia, Technical, Traffic Generators > Automating starting of Ixia IxNetwork NGPF DHCP clients

Automating starting of Ixia IxNetwork NGPF DHCP clients


Courtesy: The baseline script which is mentioned here is provided by Anush Varada of ixia customer support team and a big thanks to him for the same.

Problem: In my system testbed which is using IxNetwork NGPF interfaces,I wanted an automated way of starting all device-groups especially the ones using dhcpv4/dhcpv6 clients one by one. Starting all device blocks doesnt work most of the time and hence I wanted to start one by one.

Resoultion: Run the below python code in your IxNetwork Machine, which will automate the starting of the device blocks.
Note:This script can be easily converted to Tcl as the ixnetwork API’s are mostly same.

Environment setup:

Note: This script assumes that you already have a IxNetwork configuration with a DHCPv4 server running.

  1. IxNetwork TCL server: Instead of opening the Ixnetwork config directly, open it from the IxNetwork TCL server. IxNetwork TCL server is also same as IxNetwork GUI, but it will start a TCL server as well.
  2. Python ENV setup: Add “C:\Program Files (x86)\Ixia\Python\x.x.x” to your PATH variable in windows, where x.x.x is your python version (Refer http://www.computerhope.com/issues/ch000549.htm  for setting up path variable)
  3. Command prompt: Type “cmd” in Run prompt and there type python to  make sure its working fine.
from pprint import pprint
import os
import sys
import time
from datetime import datetime
ixNetPath = r'C:\Program Files (x86)\Ixia\IxNetwork\7.30-GA\API\Python'
sys.path.append(ixNetPath)
from IxNetwork import IxNet
ixNet = IxNet()
starttime=str(datetime.now())
ixNet.connect('10.78.24.105', '-port', 8009, '-version', '7.30')
root = ixNet.getRoot()
#Retrieves all topologies in the config
topologies = ixNet.getList(root, 'topology')
#Iterating over each topology
device_count = 0
for each_topology in topologies:
	#Retrieving topology name so that DHCP server name can be excluded
	topology_name = ixNet.getAttribute(each_topology, '-name')
	print "Executing for topology %s." %topology_name
	#Execute the below code except for DHCP server topology
	if topology_name != 'N56-55-FEX103-104-EVPC':
		print topology_name
		#Retreiving the device groups in each topology
		device_groups = ixNet.getList(each_topology, 'deviceGroup')
		#Iterating over each device group in the topology
		for each_devicegroup in device_groups:
			devicegroup_name = ixNet.getAttribute(each_devicegroup, '-name')
			print "Executing for devicegroup %s." %devicegroup_name
			#Retrieving the handle for dhcpv4_client and dhcpv6_client
			#this is required to start dhcpv6 client first before starting dhcpv4 client
			dhcpv4_client = ixNet.getList(each_devicegroup + ('/ethernet:1'),'dhcpv4client')
			dhcpv6_client = ixNet.getList(each_devicegroup + ('/ethernet:1'),'dhcpv6client')
			if len(dhcpv6_client) > 0:
				print "STARTING DHCPV6 CLIENT FOR %s."%devicegroup_name
				count=int(ixNet.getAttribute(each_devicegroup, '-multiplier'))
				print count
				ixNet.execute('start', dhcpv6_client)
				if count <=10 :
					print "sleeping for 10 seconds"
					time.sleep(10)
				elif count <=50 :
					print "sleeping for 10 seconds"
					time.sleep(10)
				elif count  100 :
					print "sleeping for 20 seconds"
					time.sleep(20)
			if len(dhcpv4_client) > 0:
				print "STARTING DHCPV4 CLIENT FOR %s."%devicegroup_name
				count=int(ixNet.getAttribute(each_devicegroup, '-multiplier'))
				print count
				ixNet.execute('start', dhcpv4_client)
				if count <=10 :
					print "sleeping for 10 seconds"
					time.sleep(10)
				elif count <=50 :
					print "sleeping for 20 seconds"
					time.sleep(20)
				elif count 100 :
					print "sleeping for 60 seconds"
					time.sleep(60)
			#when a device-group has either static ipv4/ipv6 or ethernet only then dhcpv4_client and dhcpv6_client returns an empty list
			if len(dhcpv6_client) == 0:
				print "Starting IPv4,IPv6 and Ethernet clients for %s"%devicegroup_name
				ixNet.execute('start',each_devicegroup)
				print "Sleeping for 5 seconds"
				time.sleep(5)
#print "Total number of devices is {0}".format(device_count)
endtime=str(datetime.now())
print "program started at {0}".format(starttime)
print "program ended at {0}".format(endtime)
print "Ixia program completed"
ixNet.disconnect()
Advertisements
  1. Leon Seng
    March 2, 2017 at 5:08 AM

    Hi,

    Can you tell me how I can install the IxNetwork package for Python? Is it available online?

    Thanks.

    Leon

    • March 2, 2017 at 8:47 AM

      Hi Leon,
      In windows, this gets installed by default when you install Ixnetwork.

      • Leon Seng
        March 2, 2017 at 8:51 AM

        Does the IxNetwork have to be above certain version number? I currently have v7.0 (it’s old, I know) in the lab but I don’t seem to have that python package installed.

  2. March 2, 2017 at 9:19 AM

    Hi Leon,
    That part I am not sure. My Ixnetwork version is 7.30 GA. You can check in the below folder to see whether you have the python libraries “C:\Program Files (x86)\Ixia\Python\x.x.x”

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: