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