Enabled registration for all rpc services
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / AbstractModelDrivenSwitch.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.openflow.md.core.sal;
9
10 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
11 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
12 import org.opendaylight.openflowplugin.openflow.md.ModelDrivenSwitch;
13 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
22 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
23 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration.CompositeObjectRegistrationBuilder;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25
26 /**
27  * RPC abstract for MD-switch
28  */
29 public abstract class AbstractModelDrivenSwitch implements ModelDrivenSwitch {
30
31     private final InstanceIdentifier<Node> identifier;
32
33     private RoutedRpcRegistration<SalFlowService> flowRegistration;
34
35     private RoutedRpcRegistration<SalGroupService> groupRegistration;
36
37     private RoutedRpcRegistration<SalMeterService> meterRegistration;
38
39     private RoutedRpcRegistration<PacketProcessingService> packetRegistration;
40
41     private RoutedRpcRegistration<OpendaylightGroupStatisticsService> groupStatisticsRegistration;
42
43     private RoutedRpcRegistration<OpendaylightMeterStatisticsService> meterStatisticsRegistration;
44
45     protected final SessionContext sessionContext;
46
47     protected AbstractModelDrivenSwitch(InstanceIdentifier<Node> identifier,SessionContext conductor) {
48         this.identifier = identifier;
49         this.sessionContext = conductor;
50     }
51
52     @Override
53     public final InstanceIdentifier<Node> getIdentifier() {
54         return this.identifier;
55     }
56
57     @Override
58     public CompositeObjectRegistration<ModelDrivenSwitch> register(ProviderContext ctx) {
59         CompositeObjectRegistrationBuilder<ModelDrivenSwitch> builder = CompositeObjectRegistration
60                 .<ModelDrivenSwitch> builderFor(this);
61
62         flowRegistration = ctx.addRoutedRpcImplementation(SalFlowService.class, this);
63         flowRegistration.registerPath(NodeContext.class, getIdentifier());
64         builder.add(flowRegistration);
65
66         meterRegistration = ctx.addRoutedRpcImplementation(SalMeterService.class, this);
67         meterRegistration.registerPath(NodeContext.class, getIdentifier());
68         builder.add(meterRegistration);
69
70         groupRegistration = ctx.addRoutedRpcImplementation(SalGroupService.class, this);
71         groupRegistration.registerPath(NodeContext.class, getIdentifier());
72         builder.add(groupRegistration);
73
74         packetRegistration = ctx.addRoutedRpcImplementation(PacketProcessingService.class, this);
75         packetRegistration.registerPath(NodeContext.class, getIdentifier());
76         builder.add(packetRegistration);
77         
78         groupStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightGroupStatisticsService.class, this);
79         groupStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
80         builder.add(groupStatisticsRegistration);
81
82         meterStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightMeterStatisticsService.class, this);
83         meterStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
84         builder.add(meterStatisticsRegistration);
85
86         return builder.toInstance();
87     }
88
89     /**
90      * @return session context 
91      */
92     public SessionContext getSessionContext() {
93         return sessionContext;
94     }
95
96 }