def DisableSupressArpAllPortsPy(action='', ipType='ipv4'): # Description: # This API will automatically disable or enable # suppress ARP for duplicate gateway on all the # ports with ipv4. # action = true or false # Code logic: # - Verify if the multiValue -pattern is "counter" # - If not, make it counter (so that we could create overlays to modify things.) # - If it is counter, verify if there is any overlay. # - If there are overlays, verify if the correct portName index exists. # - If yes, then change its value true/false. # - If no, create an overlay and set true/false for the portIndex number. root = ixNet.getRoot() ixNetGlobals = root+'globals' globalTopology = ixNetGlobals+'/topology' globalTopologyIp = globalTopology+'/'+ipType if ipType is 'ipv4': supressKey = '-suppressArpForDuplicateGateway' else: supressKey = '-suppressNsForDuplicateGateway' portNameList = ixNet.getAttribute(globalTopologyIp, '-rowNames') for portName in portNameList: multiValue = ixNet.getAttribute(globalTopologyIp, supressKey) try: portIndex = portNameList.index(portName)+1 except: print '\nDisableSupressArpAllPorts Error: No such port configured:', portName return 1 else: overlayDiscoveredFlag = 0 overlayList = ixNet.getList(multiValue, 'overlay') if overlayList: for overlay in overlayList: currentIndex = ixNet.getAttribute(overlay, '-index') if portIndex == currentIndex: overlayDiscoveredFlag = 1 print '\nEnableDisableSuppressArpAllPorts = %s' % action ixNetResult = ixNet.setMultiAttribute(overlay, '-value', action, '-valueStep', action, '-count', '1', '-indexStep', '0' ) if ixNetResult != '::ixNet::OK': print '\EnableDisableSuppressArpAllPorts error:', ixNetResult ixNet.commit() if overlayDiscoveredFlag == 0: # Getting here means no overlay index found for the $portIndex. # Have to create an overlay with the proper -index number. print '\nEnableDisableSuppressArpAllPorts: No overlay found for:', portName print 'Creating an overlay ...' currentOverlay = ixNet.add(multiValue, 'overlay') ixNet.setMultiAttribute(currentOverlay, '-value', action, '-valueStep', action, '-count', '1', '-index', portIndex ) ixNet.commit() else: # Getting here means there is no overlays. # Change the multiValue pattern to counter so that we # are able to modify anything ixNet.setAttribute(multiValue, '-pattern', 'counter') ixNet.commit() ixNet.setAttribute(multiValue+'/counter', '-start', 'true') ixNet.commit() print '\nEnableDisableSuppressArpAllPorts: Creating overlay: %s -index %s -value %s' % ( portName, portIndex, action) # Create Overlays with proper index number based on the portIndex # in $root/globals/topology/ipv4 -rowNames indexes currentOverlay = ixNet.add(multiValue, 'overlay') ixNet.setMultiAttribute(currentOverlay, '-value', action, '-valueStep', action, '-count', '1', '-index', portIndex ) ixNet.commit() return 0