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