4f0cf4ef68b59e2ebf389bc48f7ac36d72eace64
[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.Nonnull;
16 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
17 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
18 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
19 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
20 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
21 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
22 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
23 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28
29 /**
30  * The central entity of OFP is the Device Context, which encapsulate the logical state of a switch
31  * as seen by the controller. Each OpenFlow session is tracked by a Connection Context.
32  * These attach to a particular Device Context in such a way, that there is at most one primary
33  * session associated with a Device Context. Whenever the controller needs to interact with a
34  * particular switch, it will do so in the context of the calling thread, obtaining a lock on
35  * the corresponding Device Context – thus the Device Context becomes the fine-grained point
36  * of synchronization. The only two entities allowed to send requests towards the switch are
37  * Statistics Manager and RPC Manager. Each of them allocates a Request Context for interacting
38  * with a particular Device Context. The Request Contexts are the basic units of fairness,
39  * which is enforced by keeping a cap on the number of outstanding requests a particular Request
40  * Context can have at any point in time. Should this quota be exceeded, any further attempt to make
41  * a request to the switch will fail immediately, with proper error indication.
42  */
43 public interface DeviceContext extends
44         OFPContext,
45         DeviceReplyProcessor,
46         TxFacade,
47         DeviceRegistry,
48         RequestContextStack {
49
50     /**
51      * Method close all auxiliary connections and primary connection.
52      */
53     void shutdownConnection();
54
55     /**
56      * Method add auxiliary connection contexts to this context representing single device connection.
57      * @param connectionContext new connection context
58      */
59     void addAuxiliaryConnectionContext(ConnectionContext connectionContext);
60
61     /**
62      * Method removes auxiliary connection context from this context representing single device connection.
63      * @param connectionContext connection which need to be removed
64      */
65     void removeAuxiliaryConnectionContext(ConnectionContext connectionContext);
66
67     /**
68      * Method provides state of device represented by this device context.
69      *
70      * @return {@link DeviceState}
71      */
72     DeviceState getDeviceState();
73
74     /**
75      * Method has to close TxManager ASAP we are notified about Closed Connection.
76      * @return sync. future for Slave and MD-SAL completition for Master
77      */
78     ListenableFuture<Void> shuttingDownDataStoreTransactions();
79
80     /**
81      * Getter.
82      * @return current devices connection context
83      */
84     ConnectionContext getPrimaryConnectionContext();
85
86     /**
87      * Getter.
88      * @return current devices auxiliary connection contexts
89      */
90     ConnectionContext getAuxiliaryConnectionContexts(BigInteger cookie);
91
92
93     /**
94      * Getter.
95      * @return translator library
96      */
97     TranslatorLibrary oook();
98
99     /**
100      * store cancellable timeout handler of currently running barrier task.
101      */
102     void setCurrentBarrierTimeout(Timeout timeout);
103
104     /**
105      * Getter.
106      * @return cancellable timeout handle of currently running barrier task
107      */
108     Timeout getBarrierTaskTimeout();
109
110     void setNotificationPublishService(NotificationPublishService notificationPublishService);
111
112     MessageSpy getMessageSpy();
113
114     <T extends OfHeader> MultiMsgCollector<T> getMultiMsgCollector(final RequestContext<List<T>> requestContext);
115
116     /**
117      * indicates that device context is fully published (e.g.: packetIn messages should be passed).
118      */
119     void onPublished();
120
121     /**
122      * change packetIn rate limiter borders.
123      * @param upperBound max amount of outstanding packetIns
124      */
125     void updatePacketInRateLimit(long upperBound);
126
127     /**
128      * Getter.
129      * @return registry point for item life cycle sources of device
130      */
131     ItemLifeCycleRegistry getItemLifeCycleSourceRegistry();
132
133     void setSwitchFeaturesMandatory(boolean switchFeaturesMandatory);
134
135     void putLifecycleServiceIntoTxChainManager(LifecycleService lifecycleService);
136
137     boolean isSkipTableFeatures();
138
139     /**
140      * Setter for sal role service.
141      * @param salRoleService Role Service
142      */
143     void setSalRoleService(@Nonnull final SalRoleService salRoleService);
144
145     /**
146      * Make device slave.
147      * @return listenable future from sal role service
148      */
149     ListenableFuture<RpcResult<SetRoleOutput>> makeDeviceSlave();
150
151     boolean canUseSingleLayerSerialization();
152
153     void sendNodeAddedNotification();
154
155     void sendNodeRemovedNotification();
156 }
157