When I started writing a southbound plugin for one of the netconf device that I am working on, one of my very first question was how will MD-SAL know that it has to route the request received from flow provisioning app to my plugin. I obviously dug a little further and here is what I figured out.
If we look at the OpenDaylight controller architecture given below, we can figure out that service abstraction layer or MD-SAL is talking to southbound plugins of different types. Now if from Management GUI, I create a request to provision a flow, service abstraction layer has the capability to identify to which southbound plugin it has to route this flow provisioning request. Now the question is how? Let’s read further.
First, we need to understand different RPC Service Types, that MD-SAL supports. For a southbound plugin, we use Routed Service.
Second, we need to understand that SalFlowService is a RpcService that provides APIs to add, delete and update flows.
Third, BindingAwareBroker provides an interface RoutedRpcRegistration that provides API to register particular instance identifier to be processed by a given RpcService.
Now, when I write my southbound plugin,
- I have to extend SalFlowService to provide an implementation of addFlow, removeFlow and updateFlow. Let’s say “NetconfPluginProvider” is my bundle activator which also extends SalFlowService.
- I have to register NetconfPluginProvider as an RpcService as below:
1234567private RoutedRpcRegistration<SalFlowService> flowRegistration;............// ctx is an instance of ProviderContext// this refers to NetconfPluginProviderflowRegistration = ctx.addRoutedRpcImplementation(SalFlowService.class, this);
Note that we have used addRoutedRpcImplementation method here.
- For flow service, MD-SAL identifies the southbound plugin using node. So my southbound plugin need to tell RoutedRpcRegistration for flow service , that hey fella, you have to come to me whenever you receives a flow provisioning request on this particular node. To do this, I first have to create an instance identifier with my node id as below:
123NodeId nodeId = new NodeId("node_001");NodeKey nodeKey = new NodeKey(nodeId);InstanceIdentifier<Node> identifier = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).toInstance();
- Then I register this instance identifier with the RoutedRpcRegistration for flow service as below:
12//Carefully note the context - NodeContext.classflowRegistration.registerPath(NodeContext.class, identifier);
- So whenever I connect to a new device using my southbound plugin, I create an instance identifier and register it with flow registration.
- Now, whenever MD-SAL gets a flow provisioning request on “node_001”, it routes it to my southbound plugin.
For further reference, browse AbstractModelDrivenSwitch.java’s register method in openflow plugin project. Or leave a comment here, I will be glad to answer 🙂