Merge "SONAR TD - AbstractService"
[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.DeviceInfo;
15 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
18
19 /**
20  * <p>
21  * Each OpenFlow session is tracked by a Connection Context. These attach to a particular Device Context in such a way,
22  * that there is at most one primary session associated with a Device Context.
23  * </p>
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     String getSafeNodeIdForLOG();
110
111     void setOutboundQueueHandleRegistration(OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration);
112
113     /**
114      * actively drop associated connection
115      *
116      * @param propagate true if event need to be propagated to higher contexts (device, stats, rpc..)
117      *                  or false if invoked from higher context
118      * @see ConnectionAdapter#disconnect()
119      */
120     void closeConnection(boolean propagate);
121
122     /**
123      * cleanup context upon connection closed event (by device)
124      */
125     void onConnectionClosed();
126
127     /**
128      * change internal state to {@link ConnectionContext.CONNECTION_STATE#HANDSHAKING}
129      */
130     void changeStateToHandshaking();
131
132     /**
133      * change internal state to {@link ConnectionContext.CONNECTION_STATE#TIMEOUTING}
134      */
135     void changeStateToTimeouting();
136
137     /**
138      * change internal state to {@link ConnectionContext.CONNECTION_STATE#WORKING}
139      */
140     void changeStateToWorking();
141
142     /**
143      * Create and return basic device info
144      * @return created device info
145      */
146     DeviceInfo getDeviceInfo();
147
148     /**
149      * This method creates a basic device information. Should be called after nodeId and features are set in connection context
150      */
151     void handshakeSuccessful();
152 }