2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.api.openflow.device;
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 import javax.annotation.Nullable;
18 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
19 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
20 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
21 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
22 import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginTimer;
23 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
24 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextClosedHandler;
25 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
26 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
27 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
28 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
29 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
30 import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
31 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
32 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
33 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
34 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
37 import org.opendaylight.yangtools.yang.binding.DataObject;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 * The central entity of OFP is the Device Context, which encapsulate the logical state of a switch
43 * as seen by the controller. Each OpenFlow session is tracked by a Connection Context.
44 * These attach to a particular Device Context in such a way, that there is at most one primary
45 * session associated with a Device Context. Whenever the controller needs to interact with a
46 * particular switch, it will do so in the context of the calling thread, obtaining a lock on
47 * the corresponding Device Context – thus the Device Context becomes the fine-grained point
48 * of synchronization. The only two entities allowed to send requests towards the switch are
49 * Statistics Manager and RPC Manager. Each of them allocates a Request Context for interacting
50 * with a particular Device Context. The Request Contexts are the basic units of fairness,
51 * which is enforced by keeping a cap on the number of outstanding requests a particular Request
52 * Context can have at any point in time. Should this quota be exceeded, any further attempt to make
53 * a request to the switch will fail immediately, with proper error indication.
55 * Created by Martin Bobak <mbobak@cisco.com> on 25.2.2015.
57 public interface DeviceContext extends AutoCloseable,
60 DeviceDisconnectedHandler,
65 * Method add auxiliary connection contexts to this context representing single device connection.
67 * @param connectionContext
69 void addAuxiliaryConenctionContext(ConnectionContext connectionContext);
72 * Method removes auxiliary connection context from this context representing single device connection.
74 * @param connectionContext
76 void removeAuxiliaryConenctionContext(ConnectionContext connectionContext);
80 * Method provides state of device represented by this device context.
82 * @return {@link DeviceState}
84 DeviceState getDeviceState();
87 * Method has to activate (MASTER) or deactivate (SLAVE) TransactionChainManager.
88 * TransactionChainManager represents possibility to write or delete Node subtree data
89 * for actual Controller Cluster Node. We are able to have an active TxManager only if
90 * newRole is {@link OfpRole#BECOMESLAVE}.
91 * Parameters are used as marker to be sure it is change to SLAVE from MASTER or from
92 * MASTER to SLAVE and the last parameter "cleanDataStore" is used for validation only.
93 * @param oldRole - old role for quick validation for needed processing
94 * @param role - NewRole expect to be {@link OfpRole#BECOMESLAVE} or {@link OfpRole#BECOMEMASTER}
96 ListenableFuture<Void> onClusterRoleChange(@Nullable OfpRole oldRole, @CheckForNull OfpRole role);
99 * Method creates put operation using provided data in underlying transaction chain.
101 <T extends DataObject> void writeToTransaction(final LogicalDatastoreType store, final InstanceIdentifier<T> path, final T data);
104 * Method creates delete operation for provided path in underlying transaction chain.
106 <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path);
109 * Method submits Transaction to DataStore.
110 * @return transaction is submitted successfully
112 boolean submitTransaction();
115 * Method exposes transaction created for device
116 * represented by this context. This read only transaction has a fresh dataStore snapshot.
117 * There is a possibility to get different data set from DataStore
118 * as write transaction in this context.
119 * @return readOnlyTransaction - Don't forget to close it after finish reading
121 ReadOnlyTransaction getReadTransaction();
125 * Method provides current devices connection context.
129 ConnectionContext getPrimaryConnectionContext();
132 * Method provides current devices auxiliary connection contexts.
136 ConnectionContext getAuxiliaryConnectiobContexts(BigInteger cookie);
139 * Method exposes flow registry used for storing flow ids identified by calculated flow hash.
143 DeviceFlowRegistry getDeviceFlowRegistry();
146 * Method exposes device group registry used for storing group ids.
150 DeviceGroupRegistry getDeviceGroupRegistry();
153 * Method exposes device meter registry used for storing meter ids.
157 DeviceMeterRegistry getDeviceMeterRegistry();
161 * @return translator library
163 TranslatorLibrary oook();
166 * store cancellable timeout handler of currently running barrier task
168 void setCurrentBarrierTimeout(Timeout timeout);
171 * @return cancellable timeout handle of currently running barrier task
173 Timeout getBarrierTaskTimeout();
176 * Sets notification service
178 * @param notificationService
180 void setNotificationService(NotificationService notificationService);
182 void setNotificationPublishService(NotificationPublishService notificationPublishService);
184 MessageSpy getMessageSpy();
187 * Method sets reference to handler used for cleanup after device context about to be closed.
189 void addDeviceContextClosedHandler(DeviceContextClosedHandler deviceContextClosedHandler);
191 MultiMsgCollector getMultiMsgCollector(final RequestContext<List<MultipartReply>> requestContext);
194 * Method is reserved unique XID for Device Message.
195 * Attention: OFJava expect the message, otherwise OutboundQueue could stop working.
196 * @return Reserved XID
198 Long reservedXidForDeviceMessage();
201 * indicates that device context is fully published (e.g.: packetIn messages should be passed)
206 * change packetIn rate limiter borders
208 * @param upperBound max amount of outstanding packetIns
210 void updatePacketInRateLimit(long upperBound);
213 * @return registry point for item life cycle sources of device
215 ItemLifeCycleRegistry getItemLifeCycleSourceRegistry();
217 void setRpcContext(RpcContext rpcContext);
219 RpcContext getRpcContext();
221 void setStatisticsContext(StatisticsContext statisticsContext);
223 StatisticsContext getStatisticsContext();