Open Ethernet Networking (OpEN) API Guide and Reference Manual
3.6.0.3
|
Oscar (openr_example.c) is a sample application that demonstrates the use of RPPI RPC APIs and event notifications. Oscar is started from the command line. Oscar has a primitive (and unforgiving) command line interface that provides a small number of local configuration commands and show commands.
In its main() function, Oscar initializes the OpEN API RPC service by calling openapi_setup(). Next, Oscar invokes several RPC APIs to discover scaling parameters in use on the router. After allocating local data structures, Oscar registers with all three RPPI services. If RPPI reports that routing initialization is already complete, Oscar calls a set of RPC APIs to retrieve the current router configuration and state. Otherwise, Oscar simply waits for RPPI to send router events to announce the initial configuration and state. Oscar creates a thread dedicated to receiving event messages from RPPI while the main thread waits for input from the console. The receive thread uses a select() to wait for messages received on any of the sockets Oscar has opened.
Oscar maintains an interface table. The local tables includes all routing interfaces on the local router. Assuming Oscars starts after switchdrvr is already running, xxPopulateRoutingInterfaceTable() uses onpapiRtrIntfNextGet() to iterate over all routing interfaces. Oscar adds an entry to its local interface table for each routing interface RPPI reports. xxPopulateRoutingInterfaceTable() also asks RPPI whether routing is globally enabled or not.
After initializing its local interface table, Oscar waits for RPPI to send router events indicating changes to the routing configuration or status. xxRouterEventClientStart() registers with RPPI for router events and creates a socket to receive router events. xxEventProcess() parses and processes and acknowledges router events.
Oscar maintains a route table. Oscar's route table includes routes created through the Oscar CLI as well as routes learned from RPPI. Each Oscar route entry includes the following data:
The Oscar CLI allows the user to add and remove routes. Oscar adds and removes these routes in the switchdrvr routing table. Before adding any of its own routes, Oscar registers a new protocol and a pair of route types with RPPI. In xxRouteTypesRegister(), Oscar tells switchdrvr its protocol name is "xrp" and that this protocol has two route types, "XRP Internal" and "XRP External."
When Oscar receives a forwarding table change notification, xxBestRouteChangeMsgProcess() retrieves the changes. Oscar updates its local routing table with these changes. If the user has configured routing policy to filter the routes that Oscar accepts, Oscar calls xxPolicyApply() to apply the policy through an RPPI API. The result sets the "permitted" flag on each route.
Oscar accepts two commands that configure routing policy. The routing policy is applied to all routes learned from RPPI to determine whether Oscar "accepts" the route. The "route-map" command configures Oscar to apply a route map to routes from RPPI. The "prefix-list" command configures Oscar to apply a prefix list. The commands include the name of the route map or prefix list to apply. The route map or prefix list must be configured in ICOS. xxPolicyApply() applies the configured policy. In xxPolicyClientStart(), Oscar registers with RPPI to be notified of any configuration change to any route map or prefix list. When such a change occurs, RPPI sends a message to Oscar. xxPolicyChangeMsgProcess() checks if the policy that changed is one Oscar is using, and if so, reapplies the policy.
RPPI sends Oscar periodic KEEPALIVE messages for each service Oscar registered for. When xxEventProcess() receives a KEEPALIVE, it calls xxKeepTimeUpdate() to record when the last KEEPALIVE was received from that service. Oscar's receive thread calls xxKeepaliveStatusCheck() once per second to check whether a service's dead time has expired. If so, Oscar attempts to reregister for the service.
Oscar uses the L7PROC_LOGF macro to send log messages to the switchdrvr log file.
When Oscar exits, it calls xxCleanup() to gracefully exit. xxCleanup() deregisters with each RPPI service, withdraws all routes Oscar added to the switchdrvr routing table, and deregisters its route types.