Fix checkstyle warnings for util package
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / util / MdSalRegistrationUtils.java
1 /*
2  * Copyright (c) 2015 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.impl.util;
9
10 import com.google.common.base.Preconditions;
11 import java.util.concurrent.atomic.AtomicLong;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
14 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
15 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
16 import org.opendaylight.openflowplugin.api.openflow.statistics.compatibility.Delegator;
17 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
18 import org.opendaylight.openflowplugin.extension.onf.service.SalBundleServiceImpl;
19 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
20 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProviderFactory;
21 import org.opendaylight.openflowplugin.impl.services.sal.FlowCapableTransactionServiceImpl;
22 import org.opendaylight.openflowplugin.impl.services.sal.NodeConfigServiceImpl;
23 import org.opendaylight.openflowplugin.impl.services.sal.PacketProcessingServiceImpl;
24 import org.opendaylight.openflowplugin.impl.services.sal.SalEchoServiceImpl;
25 import org.opendaylight.openflowplugin.impl.services.sal.SalExperimenterMessageServiceImpl;
26 import org.opendaylight.openflowplugin.impl.services.sal.SalExperimenterMpMessageServiceImpl;
27 import org.opendaylight.openflowplugin.impl.services.sal.SalFlatBatchServiceImpl;
28 import org.opendaylight.openflowplugin.impl.services.sal.SalFlowServiceImpl;
29 import org.opendaylight.openflowplugin.impl.services.sal.SalFlowsBatchServiceImpl;
30 import org.opendaylight.openflowplugin.impl.services.sal.SalGroupServiceImpl;
31 import org.opendaylight.openflowplugin.impl.services.sal.SalGroupsBatchServiceImpl;
32 import org.opendaylight.openflowplugin.impl.services.sal.SalMeterServiceImpl;
33 import org.opendaylight.openflowplugin.impl.services.sal.SalMetersBatchServiceImpl;
34 import org.opendaylight.openflowplugin.impl.services.sal.SalPortServiceImpl;
35 import org.opendaylight.openflowplugin.impl.services.sal.SalTableServiceImpl;
36 import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightFlowStatisticsServiceImpl;
37 import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightFlowTableStatisticsServiceImpl;
38 import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightGroupStatisticsServiceImpl;
39 import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightMeterStatisticsServiceImpl;
40 import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightPortStatisticsServiceImpl;
41 import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightQueueStatisticsServiceImpl;
42 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.OpendaylightFlowStatisticsServiceDelegateImpl;
43 import org.opendaylight.openflowplugin.impl.statistics.services.direct.OpendaylightDirectStatisticsServiceImpl;
44 import org.opendaylight.openflowplugin.impl.statistics.services.direct.multilayer.MultiLayerDirectStatisticsProviderInitializer;
45 import org.opendaylight.openflowplugin.impl.statistics.services.direct.singlelayer.SingleLayerDirectStatisticsProviderInitializer;
46 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.OpendaylightDirectStatisticsService;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SalEchoService;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SalExperimenterMessageService;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SalExperimenterMpMessageService;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.SalFlatBatchService;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.SalBundleService;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.SalPortService;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
68
69 public class MdSalRegistrationUtils {
70
71     //TODO: Make one register and one unregister method for all services
72     private MdSalRegistrationUtils() {
73         throw new IllegalStateException();
74     }
75
76     /**
77      * Method registers all OF services for role {@link OfpRole#BECOMEMASTER}.
78      *
79      * @param rpcContext    - registration processing is implemented in
80      *        {@link org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext}
81      *
82      * @param deviceContext - every service needs
83      *        {@link org.opendaylight.openflowplugin.api.openflow.device.DeviceContext} as input parameter
84      *
85      * @param convertorExecutor convertor executor
86      */
87     public static void registerServices(@Nonnull final RpcContext rpcContext,
88                                         @Nonnull final DeviceContext deviceContext,
89                                         final ExtensionConverterProvider extensionConverterProvider,
90                                         final ConvertorExecutor convertorExecutor) {
91         // TODO: Use multipart writer provider from device context
92         final MultipartWriterProvider multipartWriterProvider = MultipartWriterProviderFactory
93             .createDefaultProvider(deviceContext);
94
95         // create service instances
96         final SalFlowServiceImpl salFlowService = new SalFlowServiceImpl(rpcContext, deviceContext, convertorExecutor);
97         final FlowCapableTransactionServiceImpl flowCapableTransactionService =
98                 new FlowCapableTransactionServiceImpl(rpcContext, deviceContext);
99         final SalGroupServiceImpl salGroupService =
100                 new SalGroupServiceImpl(rpcContext, deviceContext, convertorExecutor);
101         final SalMeterServiceImpl salMeterService =
102                 new SalMeterServiceImpl(rpcContext, deviceContext, convertorExecutor);
103
104         // register routed service instances
105         rpcContext.registerRpcServiceImplementation(SalEchoService.class,
106                 new SalEchoServiceImpl(rpcContext, deviceContext));
107         rpcContext.registerRpcServiceImplementation(SalFlowService.class, salFlowService);
108         rpcContext.registerRpcServiceImplementation(FlowCapableTransactionService.class, flowCapableTransactionService);
109         rpcContext.registerRpcServiceImplementation(SalMeterService.class, salMeterService);
110         rpcContext.registerRpcServiceImplementation(SalGroupService.class, salGroupService);
111         rpcContext.registerRpcServiceImplementation(SalTableService.class,
112                 new SalTableServiceImpl(rpcContext, deviceContext, convertorExecutor, multipartWriterProvider));
113         rpcContext.registerRpcServiceImplementation(SalPortService.class,
114                 new SalPortServiceImpl(rpcContext, deviceContext, convertorExecutor));
115         rpcContext.registerRpcServiceImplementation(PacketProcessingService.class,
116                 new PacketProcessingServiceImpl(rpcContext, deviceContext, convertorExecutor));
117         rpcContext.registerRpcServiceImplementation(NodeConfigService.class,
118                 new NodeConfigServiceImpl(rpcContext, deviceContext));
119         rpcContext.registerRpcServiceImplementation(OpendaylightFlowStatisticsService.class,
120                 OpendaylightFlowStatisticsServiceImpl.createWithOook(rpcContext, deviceContext, convertorExecutor));
121
122         // register direct statistics gathering services
123         rpcContext.registerRpcServiceImplementation(OpendaylightDirectStatisticsService.class,
124             new OpendaylightDirectStatisticsServiceImpl(deviceContext.canUseSingleLayerSerialization()
125                 ? SingleLayerDirectStatisticsProviderInitializer
126                     .createProvider(rpcContext, deviceContext, convertorExecutor, multipartWriterProvider)
127                 : MultiLayerDirectStatisticsProviderInitializer
128                     .createProvider(rpcContext, deviceContext, convertorExecutor, multipartWriterProvider)));
129
130         // register flat batch services
131         rpcContext.registerRpcServiceImplementation(SalFlatBatchService.class, new SalFlatBatchServiceImpl(
132                 new SalFlowsBatchServiceImpl(salFlowService, flowCapableTransactionService),
133                 new SalGroupsBatchServiceImpl(salGroupService, flowCapableTransactionService),
134                 new SalMetersBatchServiceImpl(salMeterService, flowCapableTransactionService)
135         ));
136
137         // register experimenter services
138         rpcContext.registerRpcServiceImplementation(SalExperimenterMessageService.class,
139                 new SalExperimenterMessageServiceImpl(rpcContext, deviceContext, extensionConverterProvider));
140         rpcContext.registerRpcServiceImplementation(SalExperimenterMpMessageService.class,
141                 new SalExperimenterMpMessageServiceImpl(rpcContext, deviceContext, extensionConverterProvider));
142
143         //register onf extension bundles
144         rpcContext.registerRpcServiceImplementation(SalBundleService.class,
145                 new SalBundleServiceImpl(new SalExperimenterMessageServiceImpl(
146                         rpcContext, deviceContext, extensionConverterProvider)));
147     }
148
149     /**
150      * Support deprecated statistic related services for backward compatibility. The only exception from deprecation is
151      * the aggregated flow statistic with match criteria input.
152      *
153      * @param rpcContext    - registration processing is implemented in
154      *        {@link org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext}
155      *
156      * @param deviceContext - every service needs
157      *        {@link org.opendaylight.openflowplugin.api.openflow.device.DeviceContext} as input parameter
158      *
159      * @param notificationPublishService - notification service
160      *
161      * @param convertorExecutor - convertor executor
162      */
163     public static void registerStatCompatibilityServices(final RpcContext rpcContext, final DeviceContext deviceContext,
164                                                          final NotificationPublishService notificationPublishService,
165                                                          final ConvertorExecutor convertorExecutor) {
166
167         AtomicLong compatibilityXidSeed = new AtomicLong();
168         // pickup low statistics service
169         final OpendaylightFlowStatisticsService flowStatisticsService = Preconditions.checkNotNull(
170                 rpcContext.lookupRpcService(OpendaylightFlowStatisticsService.class));
171
172         // attach delegate to flow statistics service (to cover all but aggregated stats with match filter input)
173         final OpendaylightFlowStatisticsServiceDelegateImpl flowStatisticsDelegate =
174                 new OpendaylightFlowStatisticsServiceDelegateImpl(rpcContext, deviceContext, notificationPublishService,
175                         new AtomicLong(), convertorExecutor);
176         ((Delegator<OpendaylightFlowStatisticsService>) flowStatisticsService).setDelegate(flowStatisticsDelegate);
177
178         // register all statistics (deprecated) services
179         rpcContext.registerRpcServiceImplementation(OpendaylightFlowTableStatisticsService.class,
180                 new OpendaylightFlowTableStatisticsServiceImpl(rpcContext, deviceContext,
181                         compatibilityXidSeed, notificationPublishService));
182         rpcContext.registerRpcServiceImplementation(OpendaylightGroupStatisticsService.class,
183                 new OpendaylightGroupStatisticsServiceImpl(rpcContext, deviceContext,
184                         compatibilityXidSeed, notificationPublishService, convertorExecutor));
185         rpcContext.registerRpcServiceImplementation(OpendaylightMeterStatisticsService.class,
186                 new OpendaylightMeterStatisticsServiceImpl(rpcContext, deviceContext,
187                         compatibilityXidSeed, notificationPublishService, convertorExecutor));
188         rpcContext.registerRpcServiceImplementation(OpendaylightQueueStatisticsService.class,
189                 new OpendaylightQueueStatisticsServiceImpl(rpcContext, deviceContext,
190                         compatibilityXidSeed, notificationPublishService));
191         rpcContext.registerRpcServiceImplementation(OpendaylightPortStatisticsService.class,
192                 new OpendaylightPortStatisticsServiceImpl(rpcContext, deviceContext,
193                         compatibilityXidSeed, notificationPublishService));
194     }
195 }