Fix license header violations in openflowplugin-api
[openflowplugin.git] / openflowplugin-api / src / main / java / org / opendaylight / openflowplugin / api / openflow / connection / ConnectionContext.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.connection;
10
11 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
12 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
13 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
14 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
17
18 /**
19  * <p>
20  * Each OpenFlow session is tracked by a Connection Context. These attach to a particular Device Context in such a way,
21  * that there is at most one primary session associated with a Device Context.
22  * </p>
23  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 25.2.2015.
24  */
25 public interface ConnectionContext {
26
27     /**
28      * @param handshakeContext corresponding handshake context used upon this connection
29      */
30     void setHandshakeContext(HandshakeContext handshakeContext);
31
32     /**
33      * distinguished connection states
34      */
35     enum CONNECTION_STATE {
36         /**
37          * initial phase of talking to switch
38          */
39         HANDSHAKING,
40         /**
41          * standard phase - interacting with switch
42          */
43         WORKING,
44         /**
45          * connection is idle, waiting for echo reply from switch
46          */
47         TIMEOUTING,
48         /**
49          * talking to switch is over - resting in pieces
50          */
51         RIP
52     }
53
54     /**
55      * setter for nodeId
56      *
57      * @param nodeId
58      */
59     void setNodeId(NodeId nodeId);
60
61     /**
62      * Method returns identifier of device whic connection represents this context.
63      *
64      * @return {@link org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId}
65      */
66     NodeId getNodeId();
67
68     /**
69      * @return the connectionAdapter
70      */
71     ConnectionAdapter getConnectionAdapter();
72
73     /**
74      * Returns reference to OFJava outbound queue provider. Outbound queue is used for outbound messages processing.
75      *
76      * @return
77      */
78     OutboundQueue getOutboundQueueProvider();
79
80     /**
81      * Method sets reference to OFJava outbound queue provider.
82      */
83     void setOutboundQueueProvider(OutboundQueueProvider outboundQueueProvider);
84
85     /**
86      * Method returns current connection state.
87      *
88      * @return {@link ConnectionContext.CONNECTION_STATE}
89      */
90     CONNECTION_STATE getConnectionState();
91
92     /**
93      * @param featuresReply as received from device during handshake
94      */
95     void setFeatures(FeaturesReply featuresReply);
96
97     /**
98      * @return featureReply as received from device during handshake
99      */
100     FeaturesReply getFeatures();
101
102     /**
103      * Method sets handler for handling closing connections.
104      *
105      * @param deviceDisconnectedHandler
106      */
107     void setDeviceDisconnectedHandler(DeviceDisconnectedHandler deviceDisconnectedHandler);
108
109     void setOutboundQueueHandleRegistration(OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration);
110
111     /**
112      * actively drop associated connection
113      *
114      * @param propagate true if event need to be propagated to higher contexts (device, stats, rpc..)
115      *                  or false if invoked from higher context
116      * @see ConnectionAdapter#disconnect()
117      */
118     void closeConnection(boolean propagate);
119
120     /**
121      * cleanup context upon connection closed event (by device)
122      */
123     void onConnectionClosed();
124
125     /**
126      * change internal state to {@link ConnectionContext.CONNECTION_STATE#HANDSHAKING}
127      */
128     void changeStateToHandshaking();
129
130     /**
131      * change internal state to {@link ConnectionContext.CONNECTION_STATE#TIMEOUTING}
132      */
133     void changeStateToTimeouting();
134
135     /**
136      * change internal state to {@link ConnectionContext.CONNECTION_STATE#WORKING}
137      */
138     void changeStateToWorking();
139 }