Goal

This tutorial shows how to access interfaces (physical/logical ports/links) of a network element and operations supported by onePK on these interfaces.

Tutorial Code

The code used in this tutorial is available in the NetworkInterfaceTutorial.py file located under <SDK Location>/python/tutorials/interfaces/NetworkInterfaceTutorial.py.

Requirements/Prerequisites

To connect to a network element, an application must have the following information available:

Steps In Detail

Get Ethernet Interfaces

Retrieve a list of network interfaces that matches the filter criteria. The list is returned as a collection of interface objects consisting of a list of networkInterface objects.

filter = InterfaceFilter(None,InterfaceTypes.ONEP_IF_TYPE_ETHERNET) 
networkInterfaces = network_element.get_interface_list(filter)
print "\nPrinting all Ethernet interfaces..."
for networkInterface in networkInterfaces:
    print "\t" + networkInterface.__str__()

Get Interface Hardware Properties

Determine the hardware properties of the network interfaces. These properties do not change over the life of the interfaces as these hardware properties represent slot number and port number specifically.

intf = tutorial.get_an_interface()
if intf == None:
    logger.error("No interfaces are available.")
    sys.exit(1)
intfProperty = NetworkInterface.get_property(intf)
print "\t" + intf.name + "\t Port" + str(intfProperty.port) + "\t Slot" + str(intfProperty.slot)

Get Interface Status

Get the status of each network interface.

print "\t Interface " + intf.name + " status is " + str(intf.get_status())

Get Interface Configurations

Get the configuration from each network interface.

	#NOT supported
        #for networkInterface in networkInterfaces:
        #    intfConfig = NetworkInterface.get_config(networkInterface)
        #    print "\t" + intfConfig.display_name

Get Parent Interfaces

Get the parent of each network interface.

for networkInterface in networkInterfaces:
    parentIntf = networkInterface.get_parent()
    print "\t" + parentIntf.__str__()

Get Subinterfaces

Get the subinterface of each network interface.

for networkInterface in networkInterfaces:
    parentIntf = networkInterface.get_parent()
    subIntfList = parentIntf.get_subinterface_list()
    for subIntf in subIntfList:
        print "\t" + subIntf.__str__()

Result

Congratulations! You now know how to access various network interfaces and interface properties.