eb17433141d3bc6df8fe36b55b560ffda45afd3f
[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.connection.OutboundQueueProvider;
21 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextClosedHandler;
22 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
23 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
24 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MessageHandler;
25 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
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.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
32 import org.opendaylight.yangtools.yang.binding.DataObject;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34
35 /**
36  * <p>
37  * The central entity of OFP is the Device Context, which encapsulate the logical state of a switch
38  * as seen by the controller. Each OpenFlow session is tracked by a Connection Context.
39  * These attach to a particular Device Context in such a way, that there is at most one primary
40  * session associated with a Device Context. Whenever the controller needs to interact with a
41  * particular switch, it will do so in the context of the calling thread, obtaining a lock on
42  * the corresponding Device Context – thus the Device Context becomes the fine-grained point
43  * of synchronization. The only two entities allowed to send requests towards the switch are
44  * Statistics Manager and RPC Manager. Each of them allocates a Request Context for interacting
45  * with a particular Device Context. The Request Contexts are the basic units of fairness,
46  * which is enforced by keeping a cap on the number of outstanding requests a particular Request
47  * Context can have at any point in time. Should this quota be exceeded, any further attempt to make
48  * a request to the switch will fail immediately, with proper error indication.
49  * </p>
50  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 25.2.2015.
51  */
52 public interface DeviceContext extends AutoCloseable,
53         OpenFlowPluginTimer,
54         MessageHandler,
55         TranslatorLibrarian,
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 submits Transaction to DataStore.
94      * @return transaction is submitted successfully
95      */
96     boolean submitTransaction();
97
98     /**
99      * Method exposes transaction created for device
100      * represented by this context. This read only transaction has a fresh dataStore snapshot.
101      * There is a possibility to get different data set from  DataStore
102      * as write transaction in this context.
103      */
104     ReadTransaction getReadTransaction();
105
106
107     /**
108      * Method provides current devices connection context.
109      *
110      * @return
111      */
112     ConnectionContext getPrimaryConnectionContext();
113
114     /**
115      * Method provides current devices auxiliary connection contexts.
116      *
117      * @return
118      */
119     ConnectionContext getAuxiliaryConnectiobContexts(BigInteger cookie);
120
121     /**
122      * Method exposes flow registry used for storing flow ids identified by calculated flow hash.
123      *
124      * @return
125      */
126     DeviceFlowRegistry getDeviceFlowRegistry();
127
128     /**
129      * Method exposes device group registry used for storing group ids.
130      *
131      * @return
132      */
133     DeviceGroupRegistry getDeviceGroupRegistry();
134
135     /**
136      * Method exposes device meter registry used for storing meter ids.
137      *
138      * @return
139      */
140     DeviceMeterRegistry getDeviceMeterRegistry();
141
142
143     /**
144      * store cancellable timeout handler of currently running barrier task
145      */
146     void setCurrentBarrierTimeout(Timeout timeout);
147
148     /**
149      * @return cancellable timeout handle of currently running barrier task
150      */
151     Timeout getBarrierTaskTimeout();
152
153     /**
154      * Sets notification service
155      *
156      * @param notificationService
157      */
158     void setNotificationService(NotificationService notificationService);
159
160     void setNotificationPublishService(NotificationPublishService notificationPublishService);
161
162     MessageSpy getMessageSpy();
163
164     void setDeviceDisconnectedHandler(DeviceDisconnectedHandler deviceDisconnectedHandler);
165
166     /**
167      * Method sets reference to handler used for cleanup after device context about to be closed.
168      */
169     void addDeviceContextClosedHandler(DeviceContextClosedHandler deviceContextClosedHandler);
170
171     MultiMsgCollector getMultiMsgCollector(final RequestContext<List<MultipartReply>> requestContext);
172
173     Long getReservedXid();
174
175     /**
176      * indicates that device context is fully published (e.g.: packetIn messages should be passed)
177      */
178     void onPublished();
179
180
181     /**
182      * Method registers outbound queue provider into current device context's primary connection adapter.
183      *
184      * @param outboundQueueProvider
185      * @param maxQueueDepth
186      * @param barrierNanos
187      */
188     void registerOutboundQueueProvider(OutboundQueueProvider outboundQueueProvider, int maxQueueDepth, long barrierNanos);
189
190
191 }
192