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