2 * Copyright (c) 2013 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.openflow.md.core.sal;
10 import com.google.common.collect.ImmutableList;
11 import com.google.common.collect.ImmutableList.Builder;
12 import java.util.Collection;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
14 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
15 import org.opendaylight.openflowplugin.api.openflow.md.AbstractModelDrivenSwitchRegistration;
16 import org.opendaylight.openflowplugin.api.openflow.md.ModelDrivenSwitch;
17 import org.opendaylight.openflowplugin.api.openflow.md.ModelDrivenSwitchRegistration;
18 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.SalPortService;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 * RPC abstract for MD-switch
39 public abstract class AbstractModelDrivenSwitch implements ModelDrivenSwitch {
41 private final InstanceIdentifier<Node> identifier;
43 protected final SessionContext sessionContext;
45 private boolean isEntityOwner = false;
47 protected AbstractModelDrivenSwitch(InstanceIdentifier<Node> identifier,SessionContext conductor) {
48 this.identifier = identifier;
49 this.sessionContext = conductor;
53 public final InstanceIdentifier<Node> getIdentifier() {
54 return this.identifier;
58 public ModelDrivenSwitchRegistration register(RpcProviderRegistry rpcProviderRegistry) {
59 final Builder<RoutedRpcRegistration<?>> builder = ImmutableList.builder();
61 final RoutedRpcRegistration<SalFlowService> flowRegistration = rpcProviderRegistry.addRoutedRpcImplementation(SalFlowService.class, this);
62 flowRegistration.registerPath(NodeContext.class, getIdentifier());
63 builder.add(flowRegistration);
65 final RoutedRpcRegistration<SalPortService> portRegistration = rpcProviderRegistry.addRoutedRpcImplementation(SalPortService.class, this);
66 portRegistration.registerPath(NodeContext.class, getIdentifier());
67 builder.add(portRegistration);
69 final RoutedRpcRegistration<SalMeterService> meterRegistration = rpcProviderRegistry.addRoutedRpcImplementation(SalMeterService.class, this);
70 meterRegistration.registerPath(NodeContext.class, getIdentifier());
71 builder.add(meterRegistration);
73 final RoutedRpcRegistration<SalGroupService> groupRegistration = rpcProviderRegistry.addRoutedRpcImplementation(SalGroupService.class, this);
74 groupRegistration.registerPath(NodeContext.class, getIdentifier());
75 builder.add(groupRegistration);
77 final RoutedRpcRegistration<SalTableService> tableRegistration = rpcProviderRegistry.addRoutedRpcImplementation(SalTableService.class, this);
78 tableRegistration.registerPath(NodeContext.class, getIdentifier());
79 builder.add(tableRegistration);
81 final RoutedRpcRegistration<PacketProcessingService> packetRegistration = rpcProviderRegistry.addRoutedRpcImplementation(PacketProcessingService.class, this);
82 packetRegistration.registerPath(NodeContext.class, getIdentifier());
83 builder.add(packetRegistration);
85 final RoutedRpcRegistration<OpendaylightFlowStatisticsService> flowStatisticsRegistration = rpcProviderRegistry.addRoutedRpcImplementation(OpendaylightFlowStatisticsService.class, this);
86 flowStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
87 builder.add(flowStatisticsRegistration);
89 final RoutedRpcRegistration<OpendaylightGroupStatisticsService> groupStatisticsRegistration = rpcProviderRegistry.addRoutedRpcImplementation(OpendaylightGroupStatisticsService.class, this);
90 groupStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
91 builder.add(groupStatisticsRegistration);
93 final RoutedRpcRegistration<OpendaylightMeterStatisticsService> meterStatisticsRegistration = rpcProviderRegistry.addRoutedRpcImplementation(OpendaylightMeterStatisticsService.class, this);
94 meterStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
95 builder.add(meterStatisticsRegistration);
97 final RoutedRpcRegistration<OpendaylightPortStatisticsService> portStatisticsRegistration = rpcProviderRegistry.addRoutedRpcImplementation(OpendaylightPortStatisticsService.class, this);
98 portStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
99 builder.add(portStatisticsRegistration);
101 final RoutedRpcRegistration<NodeConfigService> nodeConfigRegistration = rpcProviderRegistry.addRoutedRpcImplementation(NodeConfigService.class, this);
102 nodeConfigRegistration.registerPath(NodeContext.class, getIdentifier());
103 builder.add(nodeConfigRegistration);
105 final RoutedRpcRegistration<OpendaylightFlowTableStatisticsService> flowTableStatisticsRegistration = rpcProviderRegistry.addRoutedRpcImplementation(OpendaylightFlowTableStatisticsService.class, this);
106 flowTableStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
107 builder.add(flowTableStatisticsRegistration);
109 final RoutedRpcRegistration<OpendaylightQueueStatisticsService> queueStatisticsRegistration = rpcProviderRegistry.addRoutedRpcImplementation(OpendaylightQueueStatisticsService.class, this);
110 queueStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
111 builder.add(queueStatisticsRegistration);
113 final Collection<RoutedRpcRegistration<?>> registrations = builder.build();
114 return new AbstractModelDrivenSwitchRegistration(this) {
116 protected void removeRegistration() {
117 for (RoutedRpcRegistration<?> r : registrations) {
125 * @return session context
127 public SessionContext getSessionContext() {
128 return sessionContext;
132 public boolean isEntityOwner() {
133 return isEntityOwner;
137 public void setEntityOwnership(boolean isOwner) {
138 isEntityOwner = isOwner;