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