Class Routing
Routing class represents the entry point of Routing Service.To access the
Routing Service API, the application instantiates a Routing object that's
associated with a NetworkElement.
Warning: This Sample Code Has Not Been Verified
Example:
def example() :
# Get the network element and connect to it.
ne = element.NetworkElement.NetworkElement("10.1.1.4","dolph")
handle = ne.connect("cisco", "cisco")
# Get a Routing instance that's associated with the network element.
routing = Routing.get_instance(ne)
# Get RIB information and print the list of layer 3 unicast routes.
rib = routing.rib
scope = L3UnicastScope("", AFIType.IPV4, SAFIType.UNICAST, "")
prefix = None
filter = L3UnicastRIBFilter()
range = L3UnicastRouteRange(
prefix,
RouteRange.RangeType.EQUAL_OR_LARGER,
10)
routeList = rib.get_route_list(scope, filter, range)
for route in routeList :
if (isinstance (route,L3UnicastRoute) :
print route
# Add a listener to receive route state change events.
# When events arrive, listener.handleEvent() will be invoked.
listener = MyRouteListener()
eventHandle = rib.add_route_state_listener(
listener,
scope,
filter,
RIB.TRIGER_INITIAL_WALK,
None)
# Get the instance of AppRouteTable in Routing object.
art = routing.get_app_route_table()
# Create a new route and change its administrative distance
# to make it more trusted.
scope = L3UnicastScope("", AFIType.IPV4, SAFIType.UNICAST, "")
destNetwork = NetworkPrefix("192.168.200.0", 24)
# Wrong address for the interface, see what happen.
nextHop = L3UnicastNextHop(
ne.get_interface_by_name("Ethernet1/0"),
"192.168.99.77",
scope)
nextHopList = set()
nextHopList.add(nextHop)
aRoute = L3UnicastRoute(destNetwork, nextHopList)
aRoute.admin_distance = 1
# Now update the app route table with this route.
op = L3UnicastRouteOperation(RouteOperationType.REPLACE, aRoute);
opList = list()
opList.append(op);
resultList = art.update_routes(scope, opList);
# Implement a RIBRouteStateListener.
class MyRouteListener (RIBRouteStateListener) :
def handleEvent(event, clientData) :
print "Scope: " + event.scope
print "Route: " + event.route
Warning: This Sample Code Has Not Been Verified
|
__init__(self,
networkElement)
Constructor. |
|
|
int
|
|
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
|
get_instance(networkElement)
Create a Routing instance based on the provided NetworkElement. |
|
|
|
RoutingServiceType = enum('RIB', 'ART', 'ALL')
Type of routing service
|
|
static_route_table = None
|
|
network_element = property(_get_network_element, None, None, _...
|
|
rib = property(_get_rib, None, None, _doc)
|
|
app_route_table = property(_get_app_route_table, None, None, _...
|
Inherited from object :
__class__
|
__init__(self,
networkElement)
(Constructor)
|
|
Constructor. For internal use only.
- Parameters:
networkElement (NetworkElement) - The target network element which routing service is associate
with..
- Raises:
- Overrides:
object.__init__
|
get_instance(networkElement)
Static Method
|
|
Create a Routing instance based on the provided NetworkElement. This
static method follows factory pattern to guarantee only one instance of
Routing will be created for each NetworkElement.
- Parameters:
networkElement (NetworkElement) - The network element which the Routing instance is associate
with..
- Raises:
|
add_service_status_listener(self,
listener,
client_data)
|
|
Adds a routing service status listener.
- Parameters:
listener (RoutingServiceStatusListener) - The RoutingServiceStatusListener object that handles the events.
client_data - 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.
- Returns:
int
- Raises:
|
remove_service_status_listener(self,
event_handle)
|
|
Removes the RoutingServiceStatusListener listener object. This method
will remove the listener associated with the specified eventHandle and
also remove the corresponding registered event on the route table.
- Parameters:
eventHandle (int ) - Registered event identifier.
- Raises:
|
RoutingServiceType
Type of routing service
RIB : RIB service ART : ART service ALL : All of the above
- Value:
enum('RIB', 'ART', 'ALL')
|
|
network_element
- Value:
property(_get_network_element, None, None, _doc)
|
|
app_route_table
- Value:
property(_get_app_route_table, None, None, _doc)
|
|