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