60ac1659a8f91ba540dba25403d307f3f0855f4b
[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 org.opendaylight.controller.sal.binding.api.NotificationProviderService;
12
13 import io.netty.util.Timeout;
14 import java.math.BigInteger;
15 import java.util.Map;
16 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.openflowplugin.api.openflow.OpenflowPluginTimer;
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.MessageHandler;
22 import org.opendaylight.openflowplugin.api.openflow.device.handlers.OutstandingMessageExtractor;
23 import org.opendaylight.openflowplugin.api.openflow.device.listener.OpenflowMessageListenerFacade;
24 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
25 import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
26 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
27 import org.opendaylight.openflowplugin.api.openflow.translator.TranslatorLibrarian;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures;
29 import org.opendaylight.yangtools.yang.binding.DataObject;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31
32 /**
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  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 25.2.2015.
47  */
48 public interface DeviceContext extends OpenflowPluginTimer, MessageHandler, TranslatorLibrarian, OutstandingMessageExtractor, DeviceReplyProcessor {
49
50
51     /**
52      * Method add auxiliary connection contexts to this context representing single device connection.
53      *
54      * @param connectionContext
55      */
56     void addAuxiliaryConenctionContext(ConnectionContext connectionContext);
57
58     /**
59      * Method removes auxiliary connection context from this context representing single device connection.
60      *
61      * @param connectionContext
62      */
63     void removeAuxiliaryConenctionContext(ConnectionContext connectionContext);
64
65
66     /**
67      * Method provides state of device represented by this device context.
68      *
69      * @return {@link DeviceState}
70      */
71     DeviceState getDeviceState();
72
73     /**
74      * Method creates put operation using provided data in underlying transaction chain.
75      */
76     <T extends DataObject> void writeToTransaction(final LogicalDatastoreType store, final InstanceIdentifier<T> path, final T data);
77
78     /**
79      * Method creates delete operation for provided path in underlying transaction chain.
80      */
81     <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path);
82
83     /**
84      * Method exposes transaction created for device
85      * represented by this context. This read only transaction has a fresh dataStore snapshot.
86      * There is a possibility to get different data set from  DataStore
87      * as write transaction in this context.
88      */
89     ReadTransaction getReadTransaction();
90
91
92     /**
93      * Method provides capabilities of connected device.
94      *
95      * @return
96      */
97     TableFeatures getCapabilities();
98
99     /**
100      * Method provides current devices connection context.
101      *
102      * @return
103      */
104     ConnectionContext getPrimaryConnectionContext();
105
106     /**
107      * Method provides current devices auxiliary connection contexts.
108      *
109      * @return
110      */
111     ConnectionContext getAuxiliaryConnectiobContexts(BigInteger cookie);
112
113     /**
114      * Method generates unique XID value.
115      * @return
116      */
117     Xid getNextXid();
118
119     /**
120      * @return readonly map of outstanding requests
121      */
122     Map<Long, RequestContext> getRequests();
123
124     /**
125      * Method writes request context into request context map. This method
126      * is ment to be used by {@link org.opendaylight.openflowplugin.impl.services.OFJResult2RequestCtxFuture#processResultFromOfJava}
127      *
128      * @param xid
129      * @param requestFutureContext
130      */
131     void hookRequestCtx(Xid xid, RequestContext requestFutureContext);
132
133     /**
134      * Method that attaches anyMessageTypeListener to connection adapters as message listener.
135      *
136      * @param openflowMessageListenerFacade
137      */
138     void attachOpenflowMessageListener(OpenflowMessageListenerFacade openflowMessageListenerFacade);
139
140     /**
141      * Method returns registered {@link org.opendaylight.openflowplugin.api.openflow.device.listener.OpenflowMessageListenerFacade}
142      * @return
143      */
144     OpenflowMessageListenerFacade getOpenflowMessageListenerFacade();
145
146     /**
147      * Method exposes flow registry used for storing flow ids identified by calculated flow hash.
148      * @return
149      */
150     DeviceFlowRegistry getDeviceFlowRegistry();
151     /**
152      * Method exposes device group registry used for storing group ids.
153      * @return
154      */
155     DeviceGroupRegistry getDeviceGroupRegistry();
156     /**
157      * Method exposes device meter registry used for storing meter ids.
158      * @return
159      */
160     DeviceMeterRegistry getDeviceMeterRegistry();
161
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      * @param notificationService
177      */
178     void setNotificationService(NotificationProviderService notificationService);
179
180 }
181