Package onep :: Package topology :: Module TopologyClass :: Class TopologyClass
[frames] | no frames]

Class TopologyClass



The Topology class represents the network topology as seen by a protocol in
an element.It provides methods to obtain the topology graph and to register
listener for receiving topology change events. A topology contains a list
of edges. Each edge denotes the connectivity between two node connectors
which in turn are hosted in network nodes.

For protocols such as CDP and EIGRP, the topology will contain only one-hop
neighbors. For OSPF or any other link state protocol it is possible to
obtain a complete topology pertaining to an area.

A Topology object will provide only the topology graph and report topology
changes as seen by an element. In the case where the application chooses
to obtain incremental topology by connecting to each discovered node, then
a new Topology object should  be instantiated using the new node.

Example:
#Get NetworkElement and connect to it

network_element = element.NetworkElement.NetworkElement("127.0.0.1","pythonapp")
handle = network_element.connect("cisco", "cisco")

# create a Topology object based on Topology Type
# The Topology object will keep a Graph object and will also keep the graph
# updated based on the events received
# The latest graph can be obtained by using the graph property
topology = TopologyClass(network_element, Topology.TopologyType.CDP)

# Get the Graph object which reflect the current snapshot.
graph = topology.get_graph()

# A topology Graph contains a list of Edge objects. We can traverse the
# Graph by visiting each Edge object in the list.

for (edge in graph.get_edge_list(Edge.EdgeType.UNDIRECTED)):
    edge_count = 1

    print "Edge #" + str(edge_count)
    edge_count += 1

# Every Edge object has a head NodeConnector and tail NodeConnector
# on its two ends.
edge_connector = edge.head_node_connector
tail_connector = edge.tail_node_connector

# Each NodeConnector in turn is housed in a topology Node.
head_node = head_connector.node
tail_node = tail_connector.node

# print information of connectors and nodes

print "Head Connector name " + head_connector.name + ",type = " + str(head_connector.type)
print "Head Node :" + head_node.name + ",type = " + str(head_node.type)

# Print information of connectors and nodes

for addr in headnode.address_list:
    print " address: " + addr

print "Tail Connector name :" + tail_connector.name + ",type = " + str(tail_connector.type)
print "Tail Node: " + tail_node.name + "type = " + str(tail_node.type)

for addr in tail_node.address_list:
    print "address : " + addr

class MyTopologyListener(TopologyListener):
    def handle_event(self, event, clientData):
        print "-------------"
        print Topology Event
        print "-------------"

listener = MyTopologyListener()
event_type = []
event_type.append(TopologyEvent.TopologyEventType.EDGES_ADD)
event_type.append(TopologyEvent.TopologyEventType.EDGES_DELETE)

filter = TopologyFilter(event_type)
event_handle = topology.add_topology_listener(listener, filter, None)

Instance Methods
 
__init__(self, element, type)
Construct a Topology object as seen by a protocol in an element.
 
get_graph(self)
Get the topology graph that represents the current snapshot of the topology.
 
add_topology_listener(self, listener, filter, client_data)
Adds a topology event listener to the Topology object.
 
remove_topology_listener(self, event_handle)
Removes the topology event listener.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables
  TopologyType = enum('CDP')
  network_element = property(_get_network_element, None, _doc)
  type = property(_get_type, None)
Properties

Inherited from object: __class__

Method Details

__init__(self, element, type)
(Constructor)

 

Construct a Topology object as seen by a protocol in an element.

Parameters:
  • element (NetworkElement) - The NetworkElement from which to initiate the discovery of topology.
  • type (int) - Type of topology as seen by a protocol
Raises:
Overrides: object.__init__

get_graph(self)

 

Get the topology graph that represents the current snapshot of the topology. This method assumes that the network element is connected. If it is not,OnepConnectionException will be thrown.

Returns:
The Graph object representing the current snapshot of the topology.
Raises:

add_topology_listener(self, listener, filter, client_data)

 

Adds a topology event listener to the Topology object.

Parameters:
  • listener (TopologyListener) - The TopologyListener object that handles the events.
  • filter (TopologyFilter) - The TopologyFilter to specify criteria of interested topology events
  • client_data (object) - The client data associated with the listener. This client data will be part of input parameters when the handleEvent method in the listener is invoked.
Raises:

remove_topology_listener(self, event_handle)

 

Removes the topology event listener. This method will remove the listener associated with the specified eventHandle and also remove the corresponding registered event on the NetworkElement

Parameters:
  • event_handle (int) - Registered event identifier
Raises: