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