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