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.controller.md.sal.binding.api.NotificationService;
19 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginTimer;
22 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
23 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
24 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
25 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
26 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
27 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
28 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
29 import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
30 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
31 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
32 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
33 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
36 import org.opendaylight.yangtools.yang.binding.DataObject;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 * The central entity of OFP is the Device Context, which encapsulate the logical state of a switch
42 * as seen by the controller. Each OpenFlow session is tracked by a Connection Context.
43 * These attach to a particular Device Context in such a way, that there is at most one primary
44 * session associated with a Device Context. Whenever the controller needs to interact with a
45 * particular switch, it will do so in the context of the calling thread, obtaining a lock on
46 * the corresponding Device Context – thus the Device Context becomes the fine-grained point
47 * of synchronization. The only two entities allowed to send requests towards the switch are
48 * Statistics Manager and RPC Manager. Each of them allocates a Request Context for interacting
49 * with a particular Device Context. The Request Contexts are the basic units of fairness,
50 * which is enforced by keeping a cap on the number of outstanding requests a particular Request
51 * Context can have at any point in time. Should this quota be exceeded, any further attempt to make
52 * a request to the switch will fail immediately, with proper error indication.
54 * Created by Martin Bobak <mbobak@cisco.com> on 25.2.2015.
56 public interface DeviceContext extends AutoCloseable,
59 DeviceDisconnectedHandler,
63 * distinguished device context states
65 enum DEVICE_CONTEXT_STATE {
67 * initial phase of talking to switch
71 * standard phase - interacting with switch
75 * termination phase of talking to switch
81 * Method returns current device context state.
83 * @return {@link DeviceContext.DEVICE_CONTEXT_STATE}
85 DEVICE_CONTEXT_STATE getDeviceContextState();
88 * Method close all auxiliary connections and primary connection.
90 void shutdownConnection();
93 * Method add auxiliary connection contexts to this context representing single device connection.
95 * @param connectionContext
97 void addAuxiliaryConnectionContext(ConnectionContext connectionContext);
100 * Method removes auxiliary connection context from this context representing single device connection.
102 * @param connectionContext
104 void removeAuxiliaryConnectionContext(ConnectionContext connectionContext);
108 * Method provides state of device represented by this device context.
110 * @return {@link DeviceState}
112 DeviceState getDeviceState();
115 * Method has to activate (MASTER) or deactivate (SLAVE) TransactionChainManager.
116 * TransactionChainManager represents possibility to write or delete Node subtree data
117 * for actual Controller Cluster Node. We are able to have an active TxManager only if
118 * newRole is {@link OfpRole#BECOMESLAVE}.
119 * Parameters are used as marker to be sure it is change to SLAVE from MASTER or from
120 * MASTER to SLAVE and the last parameter "cleanDataStore" is used for validation only.
121 * @param oldRole - old role for quick validation for needed processing
122 * @param role - NewRole expect to be {@link OfpRole#BECOMESLAVE} or {@link OfpRole#BECOMEMASTER}
125 ListenableFuture<Void> onClusterRoleChange(@Nullable OfpRole oldRole, @CheckForNull OfpRole role);
128 * Method has to activate TransactionChainManager and prepare all Contexts from Device Contects suite
129 * to Taking ClusterLeadership role {@link OfpRole#BECOMEMASTER} (e.g. Routed RPC registration, StatPolling ...)
130 * @return DeviceInitialization furure
132 ListenableFuture<Void> onDeviceTakeClusterLeadership();
135 * Method has to deactivate TransactionChainManager and prepare all Contexts from Device Contects suite
136 * to Lost ClusterLeadership role {@link OfpRole#BECOMESLAVE} (e.g. Stop RPC rounting, stop StatPolling ...)
137 * @return RoleChangeTxChainManager future for deactivation
139 ListenableFuture<Void> onDeviceLostClusterLeadership();
142 * Method creates put operation using provided data in underlying transaction chain.
144 <T extends DataObject> void writeToTransaction(final LogicalDatastoreType store, final InstanceIdentifier<T> path, final T data);
147 * Method creates delete operation for provided path in underlying transaction chain.
149 <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path);
152 * Method submits Transaction to DataStore.
153 * @return transaction is submitted successfully
155 boolean submitTransaction();
158 * Method exposes transaction created for device
159 * represented by this context. This read only transaction has a fresh dataStore snapshot.
160 * There is a possibility to get different data set from DataStore
161 * as write transaction in this context.
162 * @return readOnlyTransaction - Don't forget to close it after finish reading
164 ReadOnlyTransaction getReadTransaction();
168 * Method provides current devices connection context.
172 ConnectionContext getPrimaryConnectionContext();
175 * Method provides current devices auxiliary connection contexts.
179 ConnectionContext getAuxiliaryConnectiobContexts(BigInteger cookie);
182 * Method exposes flow registry used for storing flow ids identified by calculated flow hash.
186 DeviceFlowRegistry getDeviceFlowRegistry();
189 * Method exposes device group registry used for storing group ids.
193 DeviceGroupRegistry getDeviceGroupRegistry();
196 * Method exposes device meter registry used for storing meter ids.
200 DeviceMeterRegistry getDeviceMeterRegistry();
204 * @return translator library
206 TranslatorLibrary oook();
209 * store cancellable timeout handler of currently running barrier task
211 void setCurrentBarrierTimeout(Timeout timeout);
214 * @return cancellable timeout handle of currently running barrier task
216 Timeout getBarrierTaskTimeout();
219 * Sets notification service
221 * @param notificationService
223 void setNotificationService(NotificationService notificationService);
225 void setNotificationPublishService(NotificationPublishService notificationPublishService);
227 MessageSpy getMessageSpy();
230 * Method sets reference to handler used for cleanup after device context about to be closed.
232 void addDeviceContextClosedHandler(DeviceTerminationPhaseHandler deviceContextClosedHandler);
234 MultiMsgCollector getMultiMsgCollector(final RequestContext<List<MultipartReply>> requestContext);
237 * Method is reserved unique XID for Device Message.
238 * Attention: OFJava expect the message, otherwise OutboundQueue could stop working.
239 * @return Reserved XID
241 Long reservedXidForDeviceMessage();
244 * indicates that device context is fully published (e.g.: packetIn messages should be passed)
249 * change packetIn rate limiter borders
251 * @param upperBound max amount of outstanding packetIns
253 void updatePacketInRateLimit(long upperBound);
256 * @return registry point for item life cycle sources of device
258 ItemLifeCycleRegistry getItemLifeCycleSourceRegistry();
260 void setRpcContext(RpcContext rpcContext);
262 RpcContext getRpcContext();
264 void setStatisticsContext(StatisticsContext statisticsContext);
266 StatisticsContext getStatisticsContext();