Merge "BUG-4118: Li:backward compatibility - rpcs - stats services"
[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 java.util.List;
14 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
15 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
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.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.MultiMsgCollector;
24 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
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.rpc.RpcContext;
29 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
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         DeviceReplyProcessor,
54         DeviceDisconnectedHandler,
55         PortNumberCache {
56
57
58     /**
59      * Method add auxiliary connection contexts to this context representing single device connection.
60      *
61      * @param connectionContext
62      */
63     void addAuxiliaryConenctionContext(ConnectionContext connectionContext);
64
65     /**
66      * Method removes auxiliary connection context from this context representing single device connection.
67      *
68      * @param connectionContext
69      */
70     void removeAuxiliaryConenctionContext(ConnectionContext connectionContext);
71
72
73     /**
74      * Method provides state of device represented by this device context.
75      *
76      * @return {@link DeviceState}
77      */
78     DeviceState getDeviceState();
79
80     /**
81      * Method creates put operation using provided data in underlying transaction chain.
82      */
83     <T extends DataObject> void writeToTransaction(final LogicalDatastoreType store, final InstanceIdentifier<T> path, final T data);
84
85     /**
86      * Method creates delete operation for provided path in underlying transaction chain.
87      */
88     <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path);
89
90     /**
91      * Method submits Transaction to DataStore.
92      * @return transaction is submitted successfully
93      */
94     boolean submitTransaction();
95
96     /**
97      * Method exposes transaction created for device
98      * represented by this context. This read only transaction has a fresh dataStore snapshot.
99      * There is a possibility to get different data set from  DataStore
100      * as write transaction in this context.
101      */
102     ReadTransaction getReadTransaction();
103
104
105     /**
106      * Method provides current devices connection context.
107      *
108      * @return
109      */
110     ConnectionContext getPrimaryConnectionContext();
111
112     /**
113      * Method provides current devices auxiliary connection contexts.
114      *
115      * @return
116      */
117     ConnectionContext getAuxiliaryConnectiobContexts(BigInteger cookie);
118
119     /**
120      * Method exposes flow registry used for storing flow ids identified by calculated flow hash.
121      *
122      * @return
123      */
124     DeviceFlowRegistry getDeviceFlowRegistry();
125
126     /**
127      * Method exposes device group registry used for storing group ids.
128      *
129      * @return
130      */
131     DeviceGroupRegistry getDeviceGroupRegistry();
132
133     /**
134      * Method exposes device meter registry used for storing meter ids.
135      *
136      * @return
137      */
138     DeviceMeterRegistry getDeviceMeterRegistry();
139
140
141     /**
142      * @return translator library
143      */
144     TranslatorLibrary oook();
145
146     /**
147      * store cancellable timeout handler of currently running barrier task
148      */
149     void setCurrentBarrierTimeout(Timeout timeout);
150
151     /**
152      * @return cancellable timeout handle of currently running barrier task
153      */
154     Timeout getBarrierTaskTimeout();
155
156     /**
157      * Sets notification service
158      *
159      * @param notificationService
160      */
161     void setNotificationService(NotificationService notificationService);
162
163     void setNotificationPublishService(NotificationPublishService notificationPublishService);
164
165     MessageSpy getMessageSpy();
166
167     /**
168      * Method sets reference to handler used for cleanup after device context about to be closed.
169      */
170     void addDeviceContextClosedHandler(DeviceContextClosedHandler deviceContextClosedHandler);
171
172     MultiMsgCollector getMultiMsgCollector(final RequestContext<List<MultipartReply>> requestContext);
173
174     Long getReservedXid();
175
176     /**
177      * indicates that device context is fully published (e.g.: packetIn messages should be passed)
178      */
179     void onPublished();
180
181     /**
182      * change packetIn rate limiter borders
183      *
184      * @param upperBound max amount of outstanding packetIns
185      */
186     void updatePacketInRateLimit(long upperBound);
187
188     /**
189      * @return registry point for item life cycle sources of device
190      */
191     ItemLifeCycleRegistry getItemLifeCycleSourceRegistry();
192
193     void setRpcContext(RpcContext rpcContext);
194
195     RpcContext getRpcContext();
196
197     /**
198      * Callback when confirmed that device is disconnected from cluster
199       */
200     void onDeviceDisconnectedFromCluster();
201 }
202