Merge "Table update rpc added as provider"
[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.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
27 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
28 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration.CompositeObjectRegistrationBuilder;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30
31 /**
32  * RPC abstract for MD-switch
33  */
34 public abstract class AbstractModelDrivenSwitch implements ModelDrivenSwitch {
35
36     private final InstanceIdentifier<Node> identifier;
37
38     private RoutedRpcRegistration<SalFlowService> flowRegistration;
39
40     private RoutedRpcRegistration<SalGroupService> groupRegistration;
41     
42     private RoutedRpcRegistration<SalTableService> tableRegistration;
43
44     private RoutedRpcRegistration<SalMeterService> meterRegistration;
45
46     private RoutedRpcRegistration<PacketProcessingService> packetRegistration;
47     
48     private RoutedRpcRegistration<OpendaylightFlowStatisticsService> flowStatisticsRegistration;
49
50     private RoutedRpcRegistration<OpendaylightGroupStatisticsService> groupStatisticsRegistration;
51
52     private RoutedRpcRegistration<OpendaylightMeterStatisticsService> meterStatisticsRegistration;
53
54     private RoutedRpcRegistration<OpendaylightPortStatisticsService> portStatisticsRegistration;
55
56     private RoutedRpcRegistration<OpendaylightFlowTableStatisticsService> flowTableStatisticsRegistration;
57
58     private RoutedRpcRegistration<OpendaylightQueueStatisticsService> queueStatisticsRegistration;
59
60     protected final SessionContext sessionContext;
61
62     protected AbstractModelDrivenSwitch(InstanceIdentifier<Node> identifier,SessionContext conductor) {
63         this.identifier = identifier;
64         this.sessionContext = conductor;
65     }
66
67     @Override
68     public final InstanceIdentifier<Node> getIdentifier() {
69         return this.identifier;
70     }
71
72     @Override
73     public CompositeObjectRegistration<ModelDrivenSwitch> register(ProviderContext ctx) {
74         CompositeObjectRegistrationBuilder<ModelDrivenSwitch> builder = CompositeObjectRegistration
75                 .<ModelDrivenSwitch> builderFor(this);
76
77         flowRegistration = ctx.addRoutedRpcImplementation(SalFlowService.class, this);
78         flowRegistration.registerPath(NodeContext.class, getIdentifier());
79         builder.add(flowRegistration);
80
81         meterRegistration = ctx.addRoutedRpcImplementation(SalMeterService.class, this);
82         meterRegistration.registerPath(NodeContext.class, getIdentifier());
83         builder.add(meterRegistration);
84
85         groupRegistration = ctx.addRoutedRpcImplementation(SalGroupService.class, this);
86         groupRegistration.registerPath(NodeContext.class, getIdentifier());
87         builder.add(groupRegistration);
88         
89         tableRegistration = ctx.addRoutedRpcImplementation(SalTableService.class, this);
90         tableRegistration.registerPath(NodeContext.class, getIdentifier());
91         builder.add(tableRegistration);
92
93         packetRegistration = ctx.addRoutedRpcImplementation(PacketProcessingService.class, this);
94         packetRegistration.registerPath(NodeContext.class, getIdentifier());
95         builder.add(packetRegistration);
96
97         flowStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightFlowStatisticsService.class, this);
98         flowStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
99         builder.add(flowStatisticsRegistration);
100
101         groupStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightGroupStatisticsService.class, this);
102         groupStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
103         builder.add(groupStatisticsRegistration);
104
105         meterStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightMeterStatisticsService.class, this);
106         meterStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
107         builder.add(meterStatisticsRegistration);
108
109         portStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightPortStatisticsService.class, this);
110         portStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
111         builder.add(portStatisticsRegistration);
112
113         flowTableStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightFlowTableStatisticsService.class, this);
114         flowTableStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
115         builder.add(flowTableStatisticsRegistration);
116         
117         queueStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightQueueStatisticsService.class, this);
118         queueStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
119         builder.add(queueStatisticsRegistration);
120
121         return builder.toInstance();
122     }
123
124     /**
125      * @return session context 
126      */
127     public SessionContext getSessionContext() {
128         return sessionContext;
129     }
130
131 }