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