Archive for the ‘Ixia’ Category

Automating starting of Ixia IxNetwork NGPF DHCP clients

August 8, 2016 4 comments

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  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'
from IxNetwork import IxNet
ixNet = IxNet()
ixNet.connect('', '-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"
				elif count <=50 :
					print "sleeping for 10 seconds"
				elif count  100 :
					print "sleeping for 20 seconds"
			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"
				elif count <=50 :
					print "sleeping for 20 seconds"
				elif count 100 :
					print "sleeping for 60 seconds"
			#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
				print "Sleeping for 5 seconds"
#print "Total number of devices is {0}".format(device_count)
print "program started at {0}".format(starttime)
print "program ended at {0}".format(endtime)
print "Ixia program completed"