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
9 package org.opendaylight.openflowplugin.api.openflow.device;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import io.netty.util.Timeout;
13 import java.math.BigInteger;
14 import java.util.List;
15 import javax.annotation.CheckForNull;
16 import javax.annotation.Nullable;
17 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
18 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
19 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
20 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
21 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
22 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
23 import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
24 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
25 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
26 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
27 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
33 * The central entity of OFP is the Device Context, which encapsulate the logical state of a switch
34 * as seen by the controller. Each OpenFlow session is tracked by a Connection Context.
35 * These attach to a particular Device Context in such a way, that there is at most one primary
36 * session associated with a Device Context. Whenever the controller needs to interact with a
37 * particular switch, it will do so in the context of the calling thread, obtaining a lock on
38 * the corresponding Device Context – thus the Device Context becomes the fine-grained point
39 * of synchronization. The only two entities allowed to send requests towards the switch are
40 * Statistics Manager and RPC Manager. Each of them allocates a Request Context for interacting
41 * with a particular Device Context. The Request Contexts are the basic units of fairness,
42 * which is enforced by keeping a cap on the number of outstanding requests a particular Request
43 * Context can have at any point in time. Should this quota be exceeded, any further attempt to make
44 * a request to the switch will fail immediately, with proper error indication.
46 * Created by Martin Bobak <mbobak@cisco.com> on 25.2.2015.
48 public interface DeviceContext extends AutoCloseable,
54 void setStatisticsRpcEnabled(boolean isStatisticsRpcEnabled);
57 * distinguished device context states
59 enum DEVICE_CONTEXT_STATE {
61 * initial phase of talking to switch
65 * standard phase - interacting with switch
69 * termination phase of talking to switch
75 * Method returns current device context state.
77 * @return {@link DeviceContext.DEVICE_CONTEXT_STATE}
79 DEVICE_CONTEXT_STATE getDeviceContextState();
82 * Method close all auxiliary connections and primary connection.
84 void shutdownConnection();
87 * Method add auxiliary connection contexts to this context representing single device connection.
89 * @param connectionContext
91 void addAuxiliaryConnectionContext(ConnectionContext connectionContext);
94 * Method removes auxiliary connection context from this context representing single device connection.
96 * @param connectionContext
98 void removeAuxiliaryConnectionContext(ConnectionContext connectionContext);
101 * Method provides state of device represented by this device context.
103 * @return {@link DeviceState}
105 DeviceState getDeviceState();
108 * Method has to activate (MASTER) or deactivate (SLAVE) TransactionChainManager.
109 * TransactionChainManager represents possibility to write or delete Node subtree data
110 * for actual Controller Cluster Node. We are able to have an active TxManager only if
111 * newRole is {@link OfpRole#BECOMESLAVE}.
112 * Parameters are used as marker to be sure it is change to SLAVE from MASTER or from
113 * MASTER to SLAVE and the last parameter "cleanDataStore" is used for validation only.
114 * @param oldRole - old role for quick validation for needed processing
115 * @param role - NewRole expect to be {@link OfpRole#BECOMESLAVE} or {@link OfpRole#BECOMEMASTER}
116 * @return RoleChangeTxChainManager future for activation/deactivation
117 * @deprecated replaced by method onDeviceTakeClusterLeadership and onDevicLostClusterLeadership
120 ListenableFuture<Void> onClusterRoleChange(@Nullable OfpRole oldRole, @CheckForNull OfpRole role);
123 * Method has to activate TransactionChainManager and prepare all Contexts from Device Contects suite
124 * to Taking ClusterLeadership role {@link OfpRole#BECOMEMASTER} (e.g. Routed RPC registration, StatPolling ...)
125 * @return DeviceInitialization furure
127 ListenableFuture<Void> onDeviceTakeClusterLeadership();
130 * Method has to deactivate TransactionChainManager and prepare all Contexts from Device Contects suite
131 * to Lost ClusterLeadership role {@link OfpRole#BECOMESLAVE} (e.g. Stop RPC rounting, stop StatPolling ...)
132 * @return RoleChangeTxChainManager future for deactivation
134 ListenableFuture<Void> onDeviceLostClusterLeadership();
137 * Method has to close TxManager ASAP we are notified about Closed Connection
138 * @return sync. future for Slave and MD-SAL completition for Master
140 ListenableFuture<Void> shuttingDownDataStoreTransactions();
143 * Method provides current devices connection context.
147 ConnectionContext getPrimaryConnectionContext();
150 * Method provides current devices auxiliary connection contexts.
154 ConnectionContext getAuxiliaryConnectiobContexts(BigInteger cookie);
157 * Method exposes flow registry used for storing flow ids identified by calculated flow hash.
161 DeviceFlowRegistry getDeviceFlowRegistry();
164 * Method exposes device group registry used for storing group ids.
168 DeviceGroupRegistry getDeviceGroupRegistry();
171 * Method exposes device meter registry used for storing meter ids.
175 DeviceMeterRegistry getDeviceMeterRegistry();
179 * @return translator library
181 TranslatorLibrary oook();
184 * store cancellable timeout handler of currently running barrier task
186 void setCurrentBarrierTimeout(Timeout timeout);
189 * @return cancellable timeout handle of currently running barrier task
191 Timeout getBarrierTaskTimeout();
193 void setNotificationPublishService(NotificationPublishService notificationPublishService);
195 MessageSpy getMessageSpy();
197 MultiMsgCollector getMultiMsgCollector(final RequestContext<List<MultipartReply>> requestContext);
200 * indicates that device context is fully published (e.g.: packetIn messages should be passed)
205 * change packetIn rate limiter borders
207 * @param upperBound max amount of outstanding packetIns
209 void updatePacketInRateLimit(long upperBound);
212 * @return registry point for item life cycle sources of device
214 ItemLifeCycleRegistry getItemLifeCycleSourceRegistry();
216 void setRpcContext(RpcContext rpcContext);
218 RpcContext getRpcContext();
220 void setStatisticsContext(StatisticsContext statisticsContext);
222 StatisticsContext getStatisticsContext();