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