Merge "DevManager functionality add"
[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 com.google.common.util.concurrent.ListenableFuture;
12 import io.netty.util.Timeout;
13 import java.math.BigInteger;
14 import java.util.List;
15 import javax.annotation.CheckForNull;
16
17 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
18 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
19 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
20 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
21 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
22 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
23 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
24 import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
25 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
26 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
27 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
28 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
31
32 /**
33  * <p>
34  * The central entity of OFP is the Device Context, which encapsulate the logical state of a switch
35  * as seen by the controller. Each OpenFlow session is tracked by a Connection Context.
36  * These attach to a particular Device Context in such a way, that there is at most one primary
37  * session associated with a Device Context. Whenever the controller needs to interact with a
38  * particular switch, it will do so in the context of the calling thread, obtaining a lock on
39  * the corresponding Device Context – thus the Device Context becomes the fine-grained point
40  * of synchronization. The only two entities allowed to send requests towards the switch are
41  * Statistics Manager and RPC Manager. Each of them allocates a Request Context for interacting
42  * with a particular Device Context. The Request Contexts are the basic units of fairness,
43  * which is enforced by keeping a cap on the number of outstanding requests a particular Request
44  * Context can have at any point in time. Should this quota be exceeded, any further attempt to make
45  * a request to the switch will fail immediately, with proper error indication.
46  * </p>
47  */
48 public interface DeviceContext extends AutoCloseable,
49         DeviceReplyProcessor,
50         PortNumberCache,
51         TxFacade,
52         XidSequencer,
53         OFPContext,
54         DeviceRegistry{
55
56     /**
57      * distinguished device context states
58      */
59     enum DEVICE_CONTEXT_STATE {
60         /**
61          * initial phase of talking to switch
62          */
63         INITIALIZATION,
64         /**
65          * standard phase - interacting with switch
66          */
67         WORKING,
68         /**
69          * termination phase of talking to switch
70          */
71         TERMINATION
72     }
73
74     /**
75      * Method returns current device context state.
76      *
77      * @return {@link DeviceContext.DEVICE_CONTEXT_STATE}
78      */
79     DEVICE_CONTEXT_STATE getDeviceContextState();
80
81     /**
82      * Method close all auxiliary connections and primary connection.
83      */
84     void shutdownConnection();
85
86     /**
87      * Method add auxiliary connection contexts to this context representing single device connection.
88      *
89      * @param connectionContext
90      */
91     void addAuxiliaryConnectionContext(ConnectionContext connectionContext);
92
93     /**
94      * Method removes auxiliary connection context from this context representing single device connection.
95      *
96      * @param connectionContext
97      */
98     void removeAuxiliaryConnectionContext(ConnectionContext connectionContext);
99
100     /**
101      * Method provides state of device represented by this device context.
102      *
103      * @return {@link DeviceState}
104      */
105     DeviceState getDeviceState();
106
107     DeviceInfo getDeviceInfo();
108
109     /**
110      * Method has to close TxManager ASAP we are notified about Closed Connection
111      * @return sync. future for Slave and MD-SAL completition for Master
112      */
113     ListenableFuture<Void> shuttingDownDataStoreTransactions();
114
115     /**
116      * Method provides current devices connection context.
117      *
118      * @return
119      */
120     ConnectionContext getPrimaryConnectionContext();
121
122     /**
123      * Method provides current devices auxiliary connection contexts.
124      *
125      * @return
126      */
127     ConnectionContext getAuxiliaryConnectiobContexts(BigInteger cookie);
128
129
130     /**
131      * @return translator library
132      */
133     TranslatorLibrary oook();
134
135     /**
136      * store cancellable timeout handler of currently running barrier task
137      */
138     void setCurrentBarrierTimeout(Timeout timeout);
139
140     /**
141      * @return cancellable timeout handle of currently running barrier task
142      */
143     Timeout getBarrierTaskTimeout();
144
145     void setNotificationPublishService(NotificationPublishService notificationPublishService);
146
147     MessageSpy getMessageSpy();
148
149     MultiMsgCollector getMultiMsgCollector(final RequestContext<List<MultipartReply>> requestContext);
150
151     /**
152      * indicates that device context is fully published (e.g.: packetIn messages should be passed)
153      */
154     void onPublished();
155
156     /**
157      * change packetIn rate limiter borders
158      *
159      * @param upperBound max amount of outstanding packetIns
160      */
161     void updatePacketInRateLimit(long upperBound);
162
163     /**
164      * @return registry point for item life cycle sources of device
165      */
166     ItemLifeCycleRegistry getItemLifeCycleSourceRegistry();
167
168     void setStatisticsContext(StatisticsContext statisticsContext);
169
170     StatisticsContext getStatisticsContext();
171
172     @Override
173     void close();
174 }
175