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