#!/usr/bin/perl ################################################################################ # # # Copyright 1997 - 2020 by IXIA Keysight # # All Rights Reserved. # # # ################################################################################ ################################################################################ # # # LEGAL NOTICE: # # ============== # # The following code and documentation (hereinafter "the script") is an # # example script for demonstration purposes only. # # The script is not a standard commercial product offered by Ixia and have # # been developed and is being provided for use only as indicated herein. The # # script [and all modifications enhancements and updates thereto (whether # # made by Ixia and/or by the user and/or by a third party)] shall at all times # # remain the property of Ixia. # # # # Ixia does not warrant (i) that the functions contained in the script will # # meet the users requirements or (ii) that the script will be without # # omissions or error-free. # # THE SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND IXIA # # DISCLAIMS ALL WARRANTIES EXPRESS IMPLIED STATUTORY OR OTHERWISE # # INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF MERCHANTABILITY AND FITNESS FOR # # A PARTICULAR PURPOSE OR OF NON-INFRINGEMENT. # # THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SCRIPT IS WITH THE # # USER. # # IN NO EVENT SHALL IXIA BE LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING # # OUT OF THE USE OF OR THE INABILITY TO USE THE SCRIPT OR ANY PART THEREOF # # INCLUDING BUT NOT LIMITED TO ANY LOST PROFITS LOST BUSINESS LOST OR # # DAMAGED DATA OR SOFTWARE OR ANY INDIRECT INCIDENTAL PUNITIVE OR # # CONSEQUENTIAL DAMAGES EVEN IF IXIA HAS BEEN ADVISED OF THE POSSIBILITY OF # # SUCH DAMAGES IN ADVANCE. # # Ixia will not be required to provide any software maintenance or support # # services of any kind (e.g. any error corrections) in connection with the # # script or any part thereof. The user acknowledges that although Ixia may # # from time to time and in its sole discretion provide maintenance or support # # services for the script any such services are subject to the warranty and # # damages limitations set forth herein and will not obligate Ixia to provide # # any additional maintenance or support services. # # # ################################################################################ ################################################################################ # # # Description: # # This script intends to demonstrate how to use NGPF OpenFlow Controller API# # It will create 1 topology of OpenFlow Controller, it will start the # emulation and then it will retrieve and display few statistics # It will also check detailed learned info and learned info after sending on# # demand message # # # ################################################################################ use IxNetwork # Script Starts print("!!! Test Script Starts !!!\n"); # Edit this variables values to match your setup my $ixTclServer = '10.214.101.141'; my $ixTclPort = '8558'; my @ports = (('12.0.1.253', '5', '10')); # Spawn a new instance of IxNetwork object. my $ixNet = new IxNetwork(); ################################################################################ # Connecting to IxTclNetwork Server and adding ports # ################################################################################ print("Connect to IxNetwork Tcl server\n"); $ixNet->connect($ixTclServer, '-port', $ixTclPort, '-version', '8.20', '-setAttribute', 'strict'); print("Creating a new config\n"); $ixNet->execute('newConfig'); print("Adding a vports\n"); $ixNet->add($ixNet->getRoot(), 'vport'); $ixNet->commit(); my @vPorts = $ixNet->getList($ixNet->getRoot(), 'vport'); my $vportTx = $vPorts[0]; print "vport is : $vportTx\n"; sleep(5); my $chassis1 = $ports[0]; my $card1 = $ports[1]; my $port1 = $ports[2]; my $vport1 = $vportTx; sleep(5); my $root = $ixNet->getRoot(); my $chassisObj1 = $ixNet->add($root.'/availableHardware', 'chassis'); $ixNet->setAttribute($chassisObj1, '-hostname', $chassis1); $ixNet->commit(); $chassisObj1 = ($ixNet->remapIds($chassisObj1))[0]; my $cardPortRef1 = $chassisObj1.'/card:'.$card1.'/port:'.$port1; $ixNet->setMultiAttribute($vport1, '-connectedTo', $cardPortRef1, '-rxMode', 'captureAndMeasure', '-name', 'Ethernet - 001'); $ixNet->commit(); ################################################################################ # protocol configuration section # ################################################################################ print("Adding 2 topologies\n"); $ixNet->add($ixNet->getRoot(), 'topology', '-vports', $vportTx); $ixNet->commit(); my @topologies = $ixNet->getList($ixNet->getRoot(), 'topology'); my $topo1 = $topologies[0]; print("Adding device groups\n"); $ixNet->add($topo1, 'deviceGroup'); $ixNet->commit(); my @t1devices = ($ixNet->getList($topo1, 'deviceGroup')); my $t1devices = ($ixNet->getList($topo1, 'deviceGroup')); my $t1dev1 = $t1devices[0]; print("Configuring the multipliers (number of sessions)\n"); $ixNet->setAttribute($t1dev1, '-multiplier', '1'); $ixNet->commit(); print("Adding ethernet/mac endpoints\n"); $ixNet->add($t1dev1, 'ethernet'); $ixNet->commit(); my $mac1 = ($ixNet->getList($t1dev1, 'ethernet'))[0]; print("Add ipv4\n"); $ixNet->add($mac1, 'ipv4'); $ixNet->commit(); my $ip1 = ($ixNet->getList($mac1, 'ipv4'))[0]; my $mvAdd1 = $ixNet->getAttribute($ip1, '-address'); my $mvGw1 = $ixNet->getAttribute($ip1, '-gatewayIp'); print("configuring ipv4 addresses \n"); $ixNet->setAttribute($mvAdd1.'/singleValue', '-value', '1.1.1.2'); $ixNet->setAttribute($mvGw1.'/singleValue', '-value', '1.1.1.1'); $ixNet->setAttribute($ixNet->getAttribute($ip1, '-prefix').'/singleValue', '-value', '24'); $ixNet->setMultiAttribute($ixNet->getAttribute($ip1, '-resolveGateway').'/singleValue', '-value', 'true'); $ixNet->commit(); print("Adding Openflow Controller over IP4 stacks \n"); $ixNet->add($ip1, 'openFlowSwitch'); $ixNet->commit(); my $openFlowSwitch1 = ($ixNet->getList($ip1, 'openFlowSwitch'))[0]; print "of Switch is : $openFlowSwitch1\n"; my $openflowSwchannels = $ixNet->add($openFlowSwitch1, 'OFSwitchChannel'); $ixNet->commit(); print "OFchannel is : $openflowchannels\n"; sleep(2); my $openflowSwChannellist = ($ixNet->getList($openFlowSwitch1, 'OFSwitchChannel'))[0]; $ixNet->setAttribute($openflowSwchannels, '-auxConnectionsPerChannel', '1'); $ixNet->commit(); sleep(2); $ixNet->setMultiAttribute($openFlowSwitch1, '-numberOfTableRanges', '1'); $ixNet->commit(); sleep(2); my $switchTableList = ($ixNet->getList($openFlowSwitch1, 'switchTablesList'))[0]; print "$switchTableList"; my $networkTopologyObj =($ixNet->add($t1dev1, 'networkTopology')); $ixNet->commit(); my $networkTopologyObjRing = ($ixNet->add($networkTopologyObj, 'netTopologyRing')); $ixNet->commit(); ################################################################################ # Start open flow controller and wait for 45 seconds # ################################################################################ print("Starting protocols and waiting for 45 seconds for protocols to come up\n"); $ixNet->execute('startAllProtocols'); sleep(45); ################################################################################ # Retrieve protocol statistics # ################################################################################ print("Fetching all Protocol Summary Stats\n"); my $viewPage = '::ixNet::OBJ-/statistics/view:"Protocols Summary"/page'; my @statcap = $ixNet->getAttribute($viewPage, '-columnCaptions'); my @rowvals = $ixNet->getAttribute($viewPage, '-rowValues'); my $index = 0; my $statValueList= ''; foreach $statValueList (@rowvals) { print("***************************************************\n"); my $statVal = ''; foreach $statVal (@$statValueList) { my $statIndiv = ''; $index = 0; foreach $statIndiv (@$statVal) { printf(" %-30s:%s\n", $statcap[$index], $statIndiv); $index++; } } } print("***************************************************\n"); print("Verifying OF Switch Per Port stats\n"); my $viewPage = '::ixNet::OBJ-/statistics/view:"OF Switch Per Port"/page'; my @statcap = $ixNet->getAttribute($viewPage, '-columnCaptions'); my @rowvals = $ixNet->getAttribute($viewPage, '-rowValues'); my $index = 0; my $statValueList= ''; foreach $statValueList (@rowvals) { print("***************************************************\n"); my $statVal = ''; foreach $statVal (@$statValueList) { my $statIndiv = ''; $index = 0; foreach $statIndiv (@$statVal) { printf(" %-30s:%s\n", $statcap[$index], $statIndiv); $index++; } } } print("***************************************************\n"); ################################################################################ # On the fly section # ################################################################################ my $swPortActive = ($ixNet->getList($openFlowSwitch1, 'ofSwitchPorts'))[0]; print "$swPortActive\n"; print "Disabling switch on the fly\n"; my $ofSwitchActive = ($ixNet->getAttribute($swPortActive, '-active')); my $swActive = ($ixNet->add($ofSwitchActive, 'overlay')); $ixNet->setMultiAttribute($swActive, '-value', 'false'); $ixNet->commit(); sleep(5); print "Enabling switch o the fly\n"; my $ofSwitchActive = ($ixNet->getAttribute($swPortActive, '-active')); my $swActive = ($ixNet->add($ofSwitchActive, 'overlay')); $ixNet->setMultiAttribute($swActive, '-value', 'true'); $ixNet->commit(); sleep(5); my $globals = ($ixNet->getRoot()).'/globals'; my $topology = $globals.'/topology'; print("Applying changes on the fly\n"); $ixNet->execute('applyOnTheFly', $topology); sleep(5); my $EthernetDestVal = ($ixNet->getAttribute($swPortActive, '-etherAddr')); print "$EthernetDestVal\n"; my $val = ($ixNet->getAttribute($EthernetDestVal, '-values'))[0]; print "$val\n"; $ixNet->setMultiAttribute($EthernetDestVal, '-clearOverlays', 'false'); $ixNet->commit(); my $EthernetDestValues = ($ixNet->add($EthernetDestVal, 'singleValue')); $ixNet->setMultiAttribute($EthernetDestValues, '-value', '56:00:00:00:00:1'); $ixNet->commit(); sleep(20); my $globals = ($ixNet->getRoot()).'/globals'; my $topology = $globals.'/topology'; print("Applying changes on the fly\n"); $ixNet->execute('applyOnTheFly', $topology); sleep(5); my $PortVal =($ixNet->getAttribute($swPortActive, '-portNumber')); $ixNet->setMultiAttribute($PortVal, '-clearOverlays', 'false'); $ixNet->commit(); my $PortSetValues = ($ixNet->add($PortVal, 'singleValue')); $ixNet->setMultiAttribute($PortSetValues, '-value', '5677888'); $ixNet->commit(); my $globals = ($ixNet->getRoot()).'/globals'; my $topology = $globals.'/topology'; print("Applying changes on the fly\n"); $ixNet->execute('applyOnTheFly', $topology); sleep(5); ############################################################################### # print learned info # ############################################################################### print("Printing Learned info!!!\n"); $ixNet->execute('getOFChannelLearnedInfo', $openFlowSwitch1, '1'); sleep(5); print("Print OF Channel Learned Info \n"); my $learnedInfoList = ($ixNet->getList($openFlowSwitch1, 'learnedInfo'))[0]; my $learnedInfo = ($learnedInfoList, 'end')[0]; my $table = ($ixNet->getList($learnedInfo, 'table'))[0]; my @learnedInfoColumnsList = ($ixNet->getAttribute($table, '-columns')); my @learnedInfoValuesList = ($ixNet->getAttribute($table, '-values')); my @row2 = (@learnedInfoValuesList) [1]; print("@learnedInfoColumnsList\n"); my $v = ''; print("***************************************************\n"); foreach $v (@row2) { my $w = '0'; foreach $w (@$v) { printf("%10s", $w); } print("\n"); } print("***************************************************\n"); $ixNet->execute('getOFSwitchFlowStatLearnedInfo', $openFlowSwitch1, '1'); sleep(5); print("Print OF Switch Flow Learned Info \n"); my $learnedInfoList = ($ixNet->getList($openFlowSwitch1, 'learnedInfo'))[0]; my $learnedInfo = ($learnedInfoList, 'end')[0]; my $table = ($ixNet->getList($learnedInfo, 'table'))[0]; my @learnedInfoColumnsList = ($ixNet->getAttribute($table, '-columns')); my @learnedInfoValuesList = ($ixNet->getAttribute($table, '-values')); my @row2 = (@learnedInfoValuesList) [1]; print("@learnedInfoColumnsList\n"); my $v = ''; print("***************************************************\n"); foreach $v (@row2) { my $w = '0'; foreach $w (@$v) { printf("%10s", $w); } print("\n"); } print("***************************************************\n"); ################################################################################ # Stop all protocols # ################################################################################ $ixNet->execute('stopAllProtocols'); print("!!! Test Script Ends !!!\n");