81c2ce6f454a3b9eba016b85a769f998965e8ab6
[openflowplugin.git] / openflowplugin-api / src / main / java / org / opendaylight / openflowplugin / api / openflow / device / DeviceContext.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
9 package org.opendaylight.openflowplugin.api.openflow.device;
10
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;
30
31 /**
32  * <p>
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.
45  * </p>
46  */
47 public interface DeviceContext extends AutoCloseable,
48         DeviceReplyProcessor,
49         PortNumberCache,
50         TxFacade,
51         XidSequencer {
52
53     void setStatisticsRpcEnabled(boolean isStatisticsRpcEnabled);
54
55     /**
56      * distinguished device context states
57      */
58     enum DEVICE_CONTEXT_STATE {
59         /**
60          * initial phase of talking to switch
61          */
62         INITIALIZATION,
63         /**
64          * standard phase - interacting with switch
65          */
66         WORKING,
67         /**
68          * termination phase of talking to switch
69          */
70         TERMINATION
71     }
72
73     /**
74      * Method returns current device context state.
75      *
76      * @return {@link DeviceContext.DEVICE_CONTEXT_STATE}
77      */
78     DEVICE_CONTEXT_STATE getDeviceContextState();
79
80     /**
81      * Method close all auxiliary connections and primary connection.
82      */
83     void shutdownConnection();
84
85     /**
86      * Method add auxiliary connection contexts to this context representing single device connection.
87      *
88      * @param connectionContext
89      */
90     void addAuxiliaryConnectionContext(ConnectionContext connectionContext);
91
92     /**
93      * Method removes auxiliary connection context from this context representing single device connection.
94      *
95      * @param connectionContext
96      */
97     void removeAuxiliaryConnectionContext(ConnectionContext connectionContext);
98
99     /**
100      * Method provides state of device represented by this device context.
101      *
102      * @return {@link DeviceState}
103      */
104     DeviceState getDeviceState();
105
106     /**
107      * Method has to activate (MASTER) or deactivate (SLAVE) TransactionChainManager.
108      * TransactionChainManager represents possibility to write or delete Node subtree data
109      * for actual Controller Cluster Node. We are able to have an active TxManager only if
110      * newRole is {@link OfpRole#BECOMESLAVE}.
111      * Parameters are used as marker to be sure it is change to SLAVE from MASTER or from
112      * MASTER to SLAVE and the last parameter "cleanDataStore" is used for validation only.
113      * @param oldRole - old role for quick validation for needed processing
114      * @param role - NewRole expect to be {@link OfpRole#BECOMESLAVE} or {@link OfpRole#BECOMEMASTER}
115      * @return RoleChangeTxChainManager future for activation/deactivation
116      * @deprecated replaced by method onDeviceTakeClusterLeadership and onDevicLostClusterLeadership
117      */
118     @Deprecated
119     ListenableFuture<Void> onClusterRoleChange(@Nullable OfpRole oldRole, @CheckForNull OfpRole role);
120
121     /**
122      * Method has to activate TransactionChainManager and prepare all Contexts from Device Contects suite
123      * to Taking ClusterLeadership role {@link OfpRole#BECOMEMASTER} (e.g. Routed RPC registration, StatPolling ...)
124      * @return DeviceInitialization furure
125      */
126     ListenableFuture<Void> onDeviceTakeClusterLeadership();
127
128     /**
129      * Method has to deactivate TransactionChainManager and prepare all Contexts from Device Contects suite
130      * to Lost ClusterLeadership role {@link OfpRole#BECOMESLAVE} (e.g. Stop RPC rounting, stop StatPolling ...)
131      * @return RoleChangeTxChainManager future for deactivation
132      */
133     ListenableFuture<Void> onDeviceLostClusterLeadership();
134
135     /**
136      * Method has to close TxManager ASAP we are notified about Closed Connection
137      * @return sync. future for Slave and MD-SAL completition for Master
138      */
139     ListenableFuture<Void> shuttingDownDataStoreTransactions();
140
141     /**
142      * Method provides current devices connection context.
143      *
144      * @return
145      */
146     ConnectionContext getPrimaryConnectionContext();
147
148     /**
149      * Method provides current devices auxiliary connection contexts.
150      *
151      * @return
152      */
153     ConnectionContext getAuxiliaryConnectiobContexts(BigInteger cookie);
154
155     /**
156      * Method exposes flow registry used for storing flow ids identified by calculated flow hash.
157      *
158      * @return
159      */
160     DeviceFlowRegistry getDeviceFlowRegistry();
161
162     /**
163      * Method exposes device group registry used for storing group ids.
164      *
165      * @return
166      */
167     DeviceGroupRegistry getDeviceGroupRegistry();
168
169     /**
170      * Method exposes device meter registry used for storing meter ids.
171      *
172      * @return
173      */
174     DeviceMeterRegistry getDeviceMeterRegistry();
175
176
177     /**
178      * @return translator library
179      */
180     TranslatorLibrary oook();
181
182     /**
183      * store cancellable timeout handler of currently running barrier task
184      */
185     void setCurrentBarrierTimeout(Timeout timeout);
186
187     /**
188      * @return cancellable timeout handle of currently running barrier task
189      */
190     Timeout getBarrierTaskTimeout();
191
192     void setNotificationPublishService(NotificationPublishService notificationPublishService);
193
194     MessageSpy getMessageSpy();
195
196     MultiMsgCollector getMultiMsgCollector(final RequestContext<List<MultipartReply>> requestContext);
197
198     /**
199      * indicates that device context is fully published (e.g.: packetIn messages should be passed)
200      */
201     void onPublished();
202
203     /**
204      * change packetIn rate limiter borders
205      *
206      * @param upperBound max amount of outstanding packetIns
207      */
208     void updatePacketInRateLimit(long upperBound);
209
210     /**
211      * @return registry point for item life cycle sources of device
212      */
213     ItemLifeCycleRegistry getItemLifeCycleSourceRegistry();
214
215     void setRpcContext(RpcContext rpcContext);
216
217     RpcContext getRpcContext();
218
219     void setStatisticsContext(StatisticsContext statisticsContext);
220
221     StatisticsContext getStatisticsContext();
222
223     @Override
224     void close();
225 }
226