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