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