79b84011b4c720689439c52e73c03cdd65952b36
[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
17 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
18 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
19 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
20 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
21 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
22 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
23 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
24 import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
25 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
26 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
27 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
28 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
31
32 /**
33  * <p>
34  * The central entity of OFP is the Device Context, which encapsulate the logical state of a switch
35  * as seen by the controller. Each OpenFlow session is tracked by a Connection Context.
36  * These attach to a particular Device Context in such a way, that there is at most one primary
37  * session associated with a Device Context. Whenever the controller needs to interact with a
38  * particular switch, it will do so in the context of the calling thread, obtaining a lock on
39  * the corresponding Device Context – thus the Device Context becomes the fine-grained point
40  * of synchronization. The only two entities allowed to send requests towards the switch are
41  * Statistics Manager and RPC Manager. Each of them allocates a Request Context for interacting
42  * with a particular Device Context. The Request Contexts are the basic units of fairness,
43  * which is enforced by keeping a cap on the number of outstanding requests a particular Request
44  * Context can have at any point in time. Should this quota be exceeded, any further attempt to make
45  * a request to the switch will fail immediately, with proper error indication.
46  * </p>
47  */
48 public interface DeviceContext extends AutoCloseable,
49         DeviceReplyProcessor,
50         PortNumberCache,
51         TxFacade,
52         XidSequencer,
53         OFPContext{
54
55     void setStatisticsRpcEnabled(boolean isStatisticsRpcEnabled);
56
57     /**
58      * distinguished device context states
59      */
60     enum DEVICE_CONTEXT_STATE {
61         /**
62          * initial phase of talking to switch
63          */
64         INITIALIZATION,
65         /**
66          * standard phase - interacting with switch
67          */
68         WORKING,
69         /**
70          * termination phase of talking to switch
71          */
72         TERMINATION
73     }
74
75     /**
76      * Method returns current device context state.
77      *
78      * @return {@link DeviceContext.DEVICE_CONTEXT_STATE}
79      */
80     DEVICE_CONTEXT_STATE getDeviceContextState();
81
82     /**
83      * Method close all auxiliary connections and primary connection.
84      */
85     void shutdownConnection();
86
87     /**
88      * Method add auxiliary connection contexts to this context representing single device connection.
89      *
90      * @param connectionContext
91      */
92     void addAuxiliaryConnectionContext(ConnectionContext connectionContext);
93
94     /**
95      * Method removes auxiliary connection context from this context representing single device connection.
96      *
97      * @param connectionContext
98      */
99     void removeAuxiliaryConnectionContext(ConnectionContext connectionContext);
100
101     /**
102      * Method provides state of device represented by this device context.
103      *
104      * @return {@link DeviceState}
105      */
106     DeviceState getDeviceState();
107
108     DeviceInfo getDeviceInfo();
109
110     /**
111      * Method has to activate (MASTER) or deactivate (SLAVE) TransactionChainManager.
112      * TransactionChainManager represents possibility to write or delete Node subtree data
113      * for actual Controller Cluster Node. We are able to have an active TxManager only if
114      * newRole is {@link OfpRole#BECOMESLAVE}.
115      * Parameters are used as marker to be sure it is change to SLAVE from MASTER or from
116      * MASTER to SLAVE and the last parameter "cleanDataStore" is used for validation only.
117      * @param role - NewRole expect to be {@link OfpRole#BECOMESLAVE} or {@link OfpRole#BECOMEMASTER}
118      * @return RoleChangeTxChainManager future for activation/deactivation
119      * @deprecated replaced by method onDeviceTakeClusterLeadership and onDevicLostClusterLeadership
120      */
121     @Deprecated
122     ListenableFuture<Void> onClusterRoleChange(@CheckForNull OfpRole role);
123
124     /**
125      * Method has to activate TransactionChainManager and prepare all Contexts from Device Contects suite
126      * to Taking ClusterLeadership role {@link OfpRole#BECOMEMASTER} (e.g. Routed RPC registration, StatPolling ...)
127      * @return DeviceInitialization furure
128      */
129     ListenableFuture<Void> onDeviceTakeClusterLeadership();
130
131     /**
132      * Method has to close TxManager ASAP we are notified about Closed Connection
133      * @return sync. future for Slave and MD-SAL completition for Master
134      */
135     ListenableFuture<Void> shuttingDownDataStoreTransactions();
136
137     /**
138      * Method provides current devices connection context.
139      *
140      * @return
141      */
142     ConnectionContext getPrimaryConnectionContext();
143
144     /**
145      * Method provides current devices auxiliary connection contexts.
146      *
147      * @return
148      */
149     ConnectionContext getAuxiliaryConnectiobContexts(BigInteger cookie);
150
151     /**
152      * Method exposes flow registry used for storing flow ids identified by calculated flow hash.
153      *
154      * @return
155      */
156     DeviceFlowRegistry getDeviceFlowRegistry();
157
158     /**
159      * Method exposes device group registry used for storing group ids.
160      *
161      * @return
162      */
163     DeviceGroupRegistry getDeviceGroupRegistry();
164
165     /**
166      * Method exposes device meter registry used for storing meter ids.
167      *
168      * @return
169      */
170     DeviceMeterRegistry getDeviceMeterRegistry();
171
172
173     /**
174      * @return translator library
175      */
176     TranslatorLibrary oook();
177
178     /**
179      * store cancellable timeout handler of currently running barrier task
180      */
181     void setCurrentBarrierTimeout(Timeout timeout);
182
183     /**
184      * @return cancellable timeout handle of currently running barrier task
185      */
186     Timeout getBarrierTaskTimeout();
187
188     void setNotificationPublishService(NotificationPublishService notificationPublishService);
189
190     MessageSpy getMessageSpy();
191
192     MultiMsgCollector getMultiMsgCollector(final RequestContext<List<MultipartReply>> requestContext);
193
194     /**
195      * indicates that device context is fully published (e.g.: packetIn messages should be passed)
196      */
197     void onPublished();
198
199     /**
200      * change packetIn rate limiter borders
201      *
202      * @param upperBound max amount of outstanding packetIns
203      */
204     void updatePacketInRateLimit(long upperBound);
205
206     /**
207      * @return registry point for item life cycle sources of device
208      */
209     ItemLifeCycleRegistry getItemLifeCycleSourceRegistry();
210
211     void setRpcContext(RpcContext rpcContext);
212
213     RpcContext getRpcContext();
214
215     void setStatisticsContext(StatisticsContext statisticsContext);
216
217     StatisticsContext getStatisticsContext();
218
219     @Override
220     void close();
221 }
222