#!/usr/bin/python ################################################################################ # # # 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 user's 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: # # - Connects to a chassis # # - Removes all elements from the topology # # - Adds a couple of cards # # - Adds a couple of ports to the cards # # - Changes various card information # # - Keep Alive # # - Management IP # # - Changes various port information # # - Promiscuous mode # # - MTU # # # ################################################################################ # HARNESS VARS **************************************************************** # NOTE: Change these variables according to your setup. if 'py' not in dir(): # define stuff if we don't run from harness class TestFailedError(Exception): pass class Py: pass py = Py() py.ports = [('10.10.10.10', '1', '1'), ('10.10.10.10', '2', '1')] py.ixTclServer = "11.11.11.11" py.ixRestPort = "12345" py.IP_list = ["1.1.1.1", "1.1.1.2"] # END HARNESS VARS ************************************************************ import sys import zipfile # Needed for REST API import time import requests import json # Import REST Library library from FW_RestApiUtils import * from VM_RestApiUtils import RestCB from utils import sm ####################################################### ## Script steps start ####################################################### print ("Sleep 15 sec to finish initialization for IxNet") time.sleep(15) ixnetUrl = "http://" + py.ixTclServer + ":" + py.ixRestPort + "/api/v1/" urlHeadersJson = {'content-type': 'application/json'} port_tuple = py.ports[0] chassis = port_tuple[0] print ("Chassis IP is:", chassis) # Get the desired session based on Process ID print ("All Sessions connected:") allSessions = getIxNetSessions(ixnetUrl) allSessionsList = allSessions for sess in allSessionsList: print ("id: " + str(sess['id']) + "\t PID: " + str(sess['mwSdmProcessId']) + "\t State:" + str(sess['state'])) sessionId = sess['id'] sessionUrl = getIxNetSessionUrl(ixnetUrl, sessionId) print ("") print ("#######################################################") print ("") ixNetExec(sessionUrl,"newConfig") print ("") print (" * Connecting to chassis... " + str(chassis)) print ("") arg1 = {"arg1": chassis} a = ixNetExec(sessionUrl, "connectToChassis", arg1) vChassisUrl = sessionUrl + "/availableHardware/virtualChassis" print ("") print (" * IP_list :" + str(py.IP_list)) print ("") print ("") RestCB.clear_topology(sessionUrl) print ("- Wait 15 sec") time.sleep(15) RestCB.create_toplogy(sessionUrl,py.IP_list,2,2) print ("- Wait 30 sec") time.sleep(30) topo_result = RestCB.getChassisTopology(sessionUrl) print ("topo_result = " + str(topo_result)) expected_topology = [ ['Port', [('Card ID', '=', '1', None), ('Card IP', '=', py.IP_list[0], None), ('KeepAlive', '=', '300', None), ('Port ID', '=', '1', None), ('Interface Name', '=', 'eth1', None), ('Promisc', '=', '0', None), ('MTU', '=', '1500', None), ('Speed', '=', '1000', None)]], ['Port', [('Card ID', '=', '1', None), ('Card IP', '=', py.IP_list[0], None), ('KeepAlive', '=', '300', None), ('Port ID', '=', '2', None), ('Interface Name', '=', 'eth2', None), ('Promisc', '=', '0', None), ('MTU', '=', '1500', None), ('Speed', '=', '1000', None)]], ['Port', [('Card ID', '=', '2', None), ('Card IP', '=', py.IP_list[1], None), ('KeepAlive', '=', '300', None), ('Port ID', '=', '1', None), ('Interface Name', '=', 'eth1', None), ('Promisc', '=', '0', None), ('MTU', '=', '1500', None), ('Speed', '=', '1000', None)]], ['Port', [('Card ID', '=', '2', None), ('Card IP', '=', py.IP_list[1], None), ('KeepAlive', '=', '300', None), ('Port ID', '=', '2', None), ('Interface Name', '=', 'eth2', None), ('Promisc', '=', '0', None), ('MTU', '=', '1500', None), ('Speed', '=', '1000', None)]], ] if sm.checkStats(topo_result, expected_topology,True): raise TestFailedError("Topologies do not match") card_list = RestCB.ixNetGetList(vChassisUrl,'ixVmCard') card1_Url = sessionUrl.split('/api')[0]+str(card_list[0]['links'][-1]['href']) card2_Url = sessionUrl.split('/api')[0]+str(card_list[1]['links'][-1]['href']) port1_list = RestCB.ixNetGetList(card1_Url,'ixVmPort') port1_1_Url = sessionUrl.split('/api')[0]+str(port1_list[0]['links'][-1]['href']) port1_2_Url = sessionUrl.split('/api')[0]+str(port1_list[1]['links'][-1]['href']) port2_list = RestCB.ixNetGetList(card2_Url,'ixVmPort') port2_1_Url = sessionUrl.split('/api')[0]+str(port2_list[0]['links'][-1]['href']) port2_2_Url = sessionUrl.split('/api')[0]+str(port2_list[1]['links'][-1]['href']) print ("") print ("card1_Url = " + str(card1_Url)) print (" -> port1_1_Url = " + str(port1_1_Url)) print (" -> port1_2_Url = " + str(port1_2_Url)) print ("card2_Url = " + str(card2_Url)) print (" -> port2_1_Url = " + str(port2_1_Url)) print (" -> port2_2_Url = " + str(port2_2_Url)) print ("") print ("") print (" * Change - Card1 - KeepAlive") print ("") attribute = {"keepAliveTimeout":"400"} aaa = ixNetSetAttFromSession(card1_Url, "", attribute) print (aaa) print ("") print (" * Change - Card1 - managementIp") print ("") attribute = {"managementIp":"10.0.0.7"} aaa = ixNetSetAttFromSession(card1_Url, "", attribute) print (aaa) print ("") print (" * Change - Port1_1 - promiscMode") print ("") attribute = {"promiscMode":"true" , "interface":"eth1"} aaa = ixNetSetAttFromSession(port1_1_Url, "", attribute) print (aaa) print ("") print (" * Change - Card2 - KeepAlive") print ("") attribute = {"keepAliveTimeout":"500"} aaa = ixNetSetAttFromSession(card2_Url, "", attribute) print (aaa) print ("") print (" * Change - Port2_1 - mtu") print ("") attribute = {"mtu":"9000"} aaa = ixNetSetAttFromSession(port2_1_Url, "", attribute) print (aaa) print ("- Wait 30 sec") time.sleep(30) topo_result = RestCB.getChassisTopology(sessionUrl) print ("topo_result = " + str(topo_result)) expected_topology = [ ['Port', [('Card ID', '=', '1', None), ('Card IP', '=', '10.0.0.7', None), ('KeepAlive', '=', '400', None), ('Port ID', '=', '1', None), ('Interface Name', '=', 'eth1', None), ('Promisc', '=', '1', None), ('MTU', '=', '1500', None), ('Speed', '=', '1000', None)]], ['Port', [('Card ID', '=', '1', None), ('Card IP', '=', '10.0.0.7', None), ('KeepAlive', '=', '400', None), ('Port ID', '=', '2', None), ('Interface Name', '=', 'eth2', None), ('Promisc', '=', '0', None), ('MTU', '=', '1500', None), ('Speed', '=', '1000', None)]], ['Port', [('Card ID', '=', '2', None), ('Card IP', '=', py.IP_list[1], None), ('KeepAlive', '=', '500', None), ('Port ID', '=', '1', None), ('Interface Name', '=', 'eth1', None), ('Promisc', '=', '0', None), ('MTU', '=', '9000', None), ('Speed', '=', '1000', None)]], ['Port', [('Card ID', '=', '2', None), ('Card IP', '=', py.IP_list[1], None), ('KeepAlive', '=', '500', None), ('Port ID', '=', '2', None), ('Interface Name', '=', 'eth2', None), ('Promisc', '=', '0', None), ('MTU', '=', '1500', None), ('Speed', '=', '1000', None)]], ] if sm.checkStats(topo_result, expected_topology,True): raise TestFailedError("Topologies do not match") print (" - Clean UP") RestCB.clear_topology(sessionUrl) print ("#######################################################") print ("# Test PASS ") print ("#######################################################") ##raise TestFailedError("STOP HERE") print ("DONE")