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