OpenIxia / IxNetwork

A central location for IxNetwork sample scripts and utilities. Please also visit http://openixia.com
MIT License
50 stars 59 forks source link

RestPy: RestPy equivalent for HLTAPI DisableSuppressArpAllPorts proc #38

Closed muthvar1 closed 5 years ago

muthvar1 commented 5 years ago

Hi Team, Is there a restPy equivalent for disabling suppress arp on all ports? In HLTAPI, we had the function below. Please let me know if there is a corresponding restAPI equivalent.

def disable_suppress_arp(self): results = self.tcl.eval('DisableSuppressArpAllPorts false') results = self.tcl.eval('DisableSuppressArpAllPorts false ipv6') return results

proc DisableSuppressArpAllPorts { 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

# Psuedo code:
#    - 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.

set root [ixNet getRoot]
set globals $root\globals
set globalTopology $globals/topology
set globalTopologyIp $globalTopology/$ipType

if { $ipType eq "ipv4" } {
    set suppressKey -suppressArpForDuplicateGateway
} else {
    set suppressKey -suppressNsForDuplicateGateway
}

set portNameList [ixNet getAttribute $globalTopologyIp -rowNames]

foreach portName $portNameList {
    set multiValue [ixNet getAttribute $globalTopologyIp $suppressKey]
    set portIndex [expr [lsearch $portNameList $portName] + 1]

    if {$portIndex != -1} {
        set overlayDiscoveredFlag 0

        # currentValues = true true
        # portList = 1/1/1 1/1/2
        set overlayList [ixNet getList $multiValue overlay]
        if {$overlayList != ""} {
            foreach overlay $overlayList {
                set currentIndex [ixNet getAttribute $overlay -index]

                if {$portIndex == $currentIndex} {
                    set overlayDiscoveredFlag 1
                    puts "\nEnableDisableSuppressArpAllPorts = $action"
                    catch {ixNet setMultiAttribute $overlay -value $action -valueStep $action -count 1 -indexStep 0} errMsg
                    if {$errMsg != "::ixNet::OK"} {
                        puts "Error EnableDisableSuppressArp setAttr: $errMsg"
                    }

                    catch {ixNet commit} errMsg
                    if {$errMsg != "::ixNet::OK"} {
                        puts "Error EnableDisableSuppressArp: $errMsg"
                    } else {
                        puts "EnableDisableSuppressArp: Set to $action: $errMsg"
                    }
                }
            }

            if {$overlayDiscoveredFlag == 0} {
                # Getting here means no overlay index found for the $portIndex.
                # Have to create an overlay with the proper -index number.
                puts "\nEnableDisableSuppressArpAllPorts: No overlay found for: $portName"
                puts "Creating an overlay ..."
                set currentOverlay [ixNet add $multiValue overlay]
                ixNet setMultiAttr $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

            puts "\nEnableDisableSuppressArpAllPorts: Creating overlay: $portName -index $portIndex -value $action"
            # Create Overlays with proper index number based on the portIndex
            # in $root/globals/topology/ipv4 -rowNames indexes
            set currentOverlay [ixNet add $multiValue overlay]
            ixNet setMultiAttr $currentOverlay -value $action -valueStep $action -count 1 -index $portIndex
            ixNet commit
        }
    } else {
        puts "Error: No such port configured: $portName"
        return 1
    }
}
return 0

}

ajbalogh commented 5 years ago

ipv4_suppress_arp = ...Ixnetwork.Globals.Topology.Ipv4.SuppressArpForDuplicateGateway ipv4_suppress_arp.Single(False)

ipv6_suppress_arp = ...Ixnetwork.Globals.Topology.Ipv6.SuppressArpForDuplicateGateway ipv6_suppress_arp.Single(False)