Merge "added API for OFP internal flow registry"
[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 java.math.BigInteger;
12 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.openflowplugin.api.openflow.OpenflowPluginTimer;
15 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
16 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
17 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MessageHandler;
18 import org.opendaylight.openflowplugin.api.openflow.device.handlers.OutstandingMessageExtractor;
19 import org.opendaylight.openflowplugin.api.openflow.device.listener.OpenflowMessageListenerFacade;
20 import org.opendaylight.openflowplugin.api.openflow.flow.registry.FlowRegistry;
21 import org.opendaylight.openflowplugin.api.openflow.translator.TranslatorLibrarian;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25
26 /**
27  * The central entity of OFP is the Device Context, which encapsulate the logical state of a switch
28  * as seen by the controller. Each OpenFlow session is tracked by a Connection Context.
29  * These attach to a particular Device Context in such a way, that there is at most one primary
30  * session associated with a Device Context. Whenever the controller needs to interact with a
31  * particular switch, it will do so in the context of the calling thread, obtaining a lock on
32  * the corresponding Device Context – thus the Device Context becomes the fine-grained point
33  * of synchronization. The only two entities allowed to send requests towards the switch are
34  * Statistics Manager and RPC Manager. Each of them allocates a Request Context for interacting
35  * with a particular Device Context. The Request Contexts are the basic units of fairness,
36  * which is enforced by keeping a cap on the number of outstanding requests a particular Request
37  * Context can have at any point in time. Should this quota be exceeded, any further attempt to make
38  * a request to the switch will fail immediately, with proper error indication.
39  * <p/>
40  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 25.2.2015.
41  */
42 public interface DeviceContext extends OpenflowPluginTimer, MessageHandler, TranslatorLibrarian, OutstandingMessageExtractor, DeviceReplyProcessor {
43
44
45     /**
46      * Method add auxiliary connection contexts to this context representing single device connection.
47      *
48      * @param connectionContext
49      */
50     void addAuxiliaryConenctionContext(ConnectionContext connectionContext);
51
52     /**
53      * Method removes auxiliary connection context from this context representing single device connection.
54      *
55      * @param connectionContext
56      */
57     void removeAuxiliaryConenctionContext(ConnectionContext connectionContext);
58
59
60     /**
61      * Method provides state of device represented by this device context.
62      *
63      * @return {@link DeviceState}
64      */
65     DeviceState getDeviceState();
66
67     /**
68      * Method exposes possibility for write a child of {@link DataObject} to transaction for DataStore.
69      */
70     <T extends DataObject> void writeToTransaction(final LogicalDatastoreType store, final InstanceIdentifier<T> path, final T data);
71
72     /**
73      * Method exposes transaction created for device
74      * represented by this context. This should be used as read only.
75      * This read only transaction has a fresh dataStore snapshot and
76      * here is a possibility to get different data set from  DataStore
77      * as have a write transaction in this context.
78      */
79     ReadTransaction getReadTransaction();
80
81     /**
82      * Method provides capabilities of connected device.
83      *
84      * @return
85      */
86     TableFeatures getCapabilities();
87
88     /**
89      * Method provides current devices connection context.
90      *
91      * @return
92      */
93     ConnectionContext getPrimaryConnectionContext();
94
95     /**
96      * Method provides current devices auxiliary connection contexts.
97      *
98      * @return
99      */
100     ConnectionContext getAuxiliaryConnectiobContexts(BigInteger cookie);
101
102     Xid getNextXid();
103
104     /**
105      * Method writes request context into request context map. This method
106      * is ment to be used by {@link org.opendaylight.openflowplugin.impl.services.OFJResult2RequestCtxFuture#processResultFromOfJava}
107      *
108      * @param xid
109      * @param requestFutureContext
110      */
111     void hookRequestCtx(Xid xid, RequestContext requestFutureContext);
112
113     /**
114      * Method that attaches anyMessageTypeListener to connection adapters as message listener.
115      *
116      * @param openflowMessageListenerFacade
117      */
118     void attachOpenflowMessageListener(OpenflowMessageListenerFacade openflowMessageListenerFacade);
119
120     OpenflowMessageListenerFacade getOpenflowMessageListenerFacade();
121
122     FlowRegistry getFlowRegistry();
123
124 }
125