connection adapter is set to autoread = false when notofications are not handled
[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 io.netty.util.Timeout;
12 import java.math.BigInteger;
13 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
14 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
15 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginTimer;
18 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
19 import org.opendaylight.openflowplugin.api.openflow.connection.ThrottledConnectionsHolder;
20 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextClosedHandler;
21 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
22 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
23 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MessageHandler;
24 import org.opendaylight.openflowplugin.api.openflow.device.handlers.OutstandingMessageExtractor;
25 import org.opendaylight.openflowplugin.api.openflow.device.listener.OpenflowMessageListenerFacade;
26 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
27 import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
28 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
29 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
30 import org.opendaylight.openflowplugin.api.openflow.translator.TranslatorLibrarian;
31 import org.opendaylight.yangtools.yang.binding.DataObject;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33
34 /**
35  * <p>
36  * The central entity of OFP is the Device Context, which encapsulate the logical state of a switch
37  * as seen by the controller. Each OpenFlow session is tracked by a Connection Context.
38  * These attach to a particular Device Context in such a way, that there is at most one primary
39  * session associated with a Device Context. Whenever the controller needs to interact with a
40  * particular switch, it will do so in the context of the calling thread, obtaining a lock on
41  * the corresponding Device Context – thus the Device Context becomes the fine-grained point
42  * of synchronization. The only two entities allowed to send requests towards the switch are
43  * Statistics Manager and RPC Manager. Each of them allocates a Request Context for interacting
44  * with a particular Device Context. The Request Contexts are the basic units of fairness,
45  * which is enforced by keeping a cap on the number of outstanding requests a particular Request
46  * Context can have at any point in time. Should this quota be exceeded, any further attempt to make
47  * a request to the switch will fail immediately, with proper error indication.
48  * </p>
49  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 25.2.2015.
50  */
51 public interface DeviceContext extends AutoCloseable,
52         OpenFlowPluginTimer,
53         MessageHandler,
54         TranslatorLibrarian,
55         OutstandingMessageExtractor,
56         DeviceReplyProcessor,
57         DeviceDisconnectedHandler {
58
59
60     /**
61      * Method add auxiliary connection contexts to this context representing single device connection.
62      *
63      * @param connectionContext
64      */
65     void addAuxiliaryConenctionContext(ConnectionContext connectionContext);
66
67     /**
68      * Method removes auxiliary connection context from this context representing single device connection.
69      *
70      * @param connectionContext
71      */
72     void removeAuxiliaryConenctionContext(ConnectionContext connectionContext);
73
74
75     /**
76      * Method provides state of device represented by this device context.
77      *
78      * @return {@link DeviceState}
79      */
80     DeviceState getDeviceState();
81
82     /**
83      * Method creates put operation using provided data in underlying transaction chain.
84      */
85     <T extends DataObject> void writeToTransaction(final LogicalDatastoreType store, final InstanceIdentifier<T> path, final T data);
86
87     /**
88      * Method creates delete operation for provided path in underlying transaction chain.
89      */
90     <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path);
91
92     /**
93      * Method exposes transaction created for device
94      * represented by this context. This read only transaction has a fresh dataStore snapshot.
95      * There is a possibility to get different data set from  DataStore
96      * as write transaction in this context.
97      */
98     ReadTransaction getReadTransaction();
99
100
101     /**
102      * Method provides current devices connection context.
103      *
104      * @return
105      */
106     ConnectionContext getPrimaryConnectionContext();
107
108     /**
109      * Method provides current devices auxiliary connection contexts.
110      *
111      * @return
112      */
113     ConnectionContext getAuxiliaryConnectiobContexts(BigInteger cookie);
114
115     /**
116      * Method generates unique XID value.
117      *
118      * @return
119      */
120     Xid getNextXid();
121
122     /**
123      * @param xid key
124      * @return request by xid
125      */
126     RequestContext lookupRequest(Xid xid);
127
128     /**
129      * @return number of outstanding requests in map
130      */
131     int getNumberOfOutstandingRequests();
132
133     /**
134      * Method writes request context into request context map. This method
135      * is ment to be used by org.opendaylight.openflowplugin.impl.services.OFJResult2RequestCtxFuture#processResultFromOfJava.
136      *
137      * @param xid
138      * @param requestFutureContext
139      */
140     void hookRequestCtx(Xid xid, RequestContext requestFutureContext);
141
142     /**
143      * Method removes request context from request context map.
144      *
145      * @param xid
146      */
147     RequestContext unhookRequestCtx(Xid xid);
148
149     /**
150      * Method that attaches anyMessageTypeListener to connection adapters as message listener.
151      *
152      * @param openflowMessageListenerFacade
153      */
154     void attachOpenflowMessageListener(OpenflowMessageListenerFacade openflowMessageListenerFacade);
155
156     /**
157      * Method returns registered {@link org.opendaylight.openflowplugin.api.openflow.device.listener.OpenflowMessageListenerFacade}
158      *
159      * @return
160      */
161     OpenflowMessageListenerFacade getOpenflowMessageListenerFacade();
162
163     /**
164      * Method exposes flow registry used for storing flow ids identified by calculated flow hash.
165      *
166      * @return
167      */
168     DeviceFlowRegistry getDeviceFlowRegistry();
169
170     /**
171      * Method exposes device group registry used for storing group ids.
172      *
173      * @return
174      */
175     DeviceGroupRegistry getDeviceGroupRegistry();
176
177     /**
178      * Method exposes device meter registry used for storing meter ids.
179      *
180      * @return
181      */
182     DeviceMeterRegistry getDeviceMeterRegistry();
183
184
185     /**
186      * store cancellable timeout handler of currently running barrier task
187      */
188     void setCurrentBarrierTimeout(Timeout timeout);
189
190     /**
191      * @return cancellable timeout handle of currently running barrier task
192      */
193     Timeout getBarrierTaskTimeout();
194
195     /**
196      * Sets notification service
197      *
198      * @param notificationService
199      */
200     void setNotificationService(NotificationService notificationService);
201
202     void setNotificationPublishService(NotificationPublishService notificationPublishService);
203
204     MessageSpy getMessageSpy();
205
206     void setDeviceDisconnectedHandler(DeviceDisconnectedHandler deviceDisconnectedHandler);
207
208     /**
209      * Method sets reference to handler used for cleanup after device context about to be closed.
210      */
211     void addDeviceContextClosedHandler(DeviceContextClosedHandler deviceContextClosedHandler);
212
213     void startGatheringOperationsToOneTransaction();
214
215     void commitOperationsGatheredInOneTransaction();
216
217 }
218