2 * Copyright (c) 2014 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.applications.statistics.manager;
11 import java.util.List;
12 import java.util.UUID;
13 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
14 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
15 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
16 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
17 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
18 import org.opendaylight.openflowplugin.applications.statistics.manager.StatPermCollector.StatCapabTypes;
19 import org.opendaylight.openflowplugin.applications.statistics.manager.impl.StatisticsManagerConfig;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsListener;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsListener;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsListener;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsListener;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsListener;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsListener;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 * org.opendaylight.openflowplugin.applications.statistics.manager
42 * It represent a central point for whole module. Implementation
43 * StatisticsManager registers all Operation/DS {@link StatNotifyCommiter} and
44 * Config/DS {@link StatListeningCommiter}, as well as {@link StatPermCollector}
45 * for statistic collecting and {@link StatRpcMsgManager} as Device RPCs provider.
46 * In next, StatisticsManager provides all DS contact Transaction services.
48 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
50 * Created: Aug 27, 2014
52 public interface StatisticsManager extends AutoCloseable, TransactionChainListener {
55 * StatDataStoreOperation
56 * Interface represent functionality to submit changes to DataStore.
57 * Internal {@link TransactionChainListener} joining all DS commits
58 * to Set of chained changes for prevent often DataStore touches.
60 abstract class StatDataStoreOperation {
61 public enum StatsManagerOperationType {
63 * Operation will carry out work related to new node addition /
68 * Operation will carry out work related to node removal
72 * Operation will commit data to the operational data store
77 private NodeId nodeId;
78 private StatsManagerOperationType operationType = StatsManagerOperationType.DATA_COMMIT_OPER_DS;
79 private UUID nodeUUID;
81 public StatDataStoreOperation(final StatsManagerOperationType operType, final NodeId id){
83 operationType = operType;
86 nodeUUID = generatedUUIDForNode();
89 public final StatsManagerOperationType getType() {
93 public final NodeId getNodeId(){
97 public UUID getNodeUUID() {
102 * Apply all read / write (put|merge) operation for DataStore
104 * @param tx {@link ReadWriteTransaction}
106 public abstract void applyOperation(ReadWriteTransaction tx);
108 protected abstract UUID generatedUUIDForNode();
110 public InstanceIdentifier<Node> getNodeIdentifier() {
111 final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
112 .child(Node.class, new NodeKey(nodeId));
121 private final L left;
122 private final R right;
124 public Pair(L left, R right) {
129 public L getLeft() { return left; }
130 public R getRight() { return right; }
133 public int hashCode() { return left.hashCode() ^ right.hashCode(); }
136 public boolean equals(Object o) {
137 if (!(o instanceof Pair)) return false;
138 Pair pairo = (Pair) o;
139 return this.left.equals(pairo.getLeft()) &&
140 this.right.equals(pairo.getRight());
146 * Method starts whole StatisticManager functionality
148 * @param notifService
151 void start(final NotificationProviderService notifService,
152 final RpcConsumerRegistry rpcRegistry);
155 * Method provides read/write DataStore functionality cross applyOperation
156 * defined in {@link StatDataStoreOperation}
158 * @param inventoryOper - operation for DataStore
160 void enqueue(final StatDataStoreOperation inventoryOper);
163 * Method wraps {@link StatisticsManager#isProvidedFlowNodeActive(InstanceIdentifier)} method
164 * to provide parallel statCollection process for Set of Nodes. So it has to
165 * identify correct Node Set by NodeIdentifier
169 boolean isProvidedFlowNodeActive(InstanceIdentifier<Node> nodeIdent);
172 * Method wraps {@link StatPermCollector}.collectNextStatistics to provide
173 * parallel statCollection process for Set of Nodes. So it has to
174 * identify correct Node Set by NodeIdentifier.
178 void collectNextStatistics(InstanceIdentifier<Node> nodeIdent, TransactionId xid);
181 * Method wraps {@link StatPermCollector}.connectedNodeRegistration to provide
182 * parallel statCollection process for Set of Nodes. So it has to
183 * connect node to new or not full Node statCollector Set.
187 * @param nrOfSwitchTables
189 void connectedNodeRegistration(InstanceIdentifier<Node> nodeIdent,
190 List<StatCapabTypes> statTypes, Short nrOfSwitchTables);
193 * Method wraps {@link StatPermCollector}.disconnectedNodeUnregistration to provide
194 * parallel statCollection process for Set of Nodes. So it has to identify
195 * correct collector for disconnect node.
199 void disconnectedNodeUnregistration(InstanceIdentifier<Node> nodeIdent);
202 * Method wraps {@link StatPermCollector}.registerAdditionalNodeFeature to provide
203 * possibility to register additional Node Feature {@link StatCapabTypes} for
204 * statistics collecting.
209 void registerAdditionalNodeFeature(InstanceIdentifier<Node> nodeIdent, StatCapabTypes statCapab);
212 * Method wraps {@link StatPermCollector}.unregisterNodeStats to provide
213 * possibility to unregister Node stats type {@link StatCapabTypes} from
214 * statistics collecting.
219 void unregisterNodeStats(InstanceIdentifier<Node> nodeIdent, StatCapabTypes statCapab);
222 * Method provides access to Device RPC methods by wrapped
223 * internal method. In next {@link StatRpcMsgManager} is registered all
224 * Multipart device msg response and joining all to be able run all
225 * collected statistics in one time (easy identification Data for delete)
227 * @return {@link StatRpcMsgManager}
229 StatRpcMsgManager getRpcMsgManager();
232 * Define Method : {@link org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode}
233 * Operational/DS data change listener -> impl. target -> register FlowCapableNode to Statistic Collecting process
234 * @return {@link StatNodeRegistration}
236 StatNodeRegistration getNodeRegistrator();
239 * Define Method : Flow Config/DS data change listener -> impl. target ->
240 * -> make pair between Config/DS FlowId and Device Flow response Hash
243 StatListeningCommiter<Flow, OpendaylightFlowStatisticsListener> getFlowListenComit();
246 * Define Method : Meter Config/DS data change listener and Operation/DS notify commit
250 StatListeningCommiter<Meter, OpendaylightMeterStatisticsListener> getMeterListenCommit();
253 * Define Method : Group Config/DS data change listener and Operation/DS notify commit
257 StatListeningCommiter<Group, OpendaylightGroupStatisticsListener> getGroupListenCommit();
260 * Define Method : Queue Config/DS change listener and Operation/DS notify commit functionality
263 StatListeningCommiter<Queue, OpendaylightQueueStatisticsListener> getQueueNotifyCommit();
266 * Define Method : Table Operation/DS notify commit functionality
269 StatNotifyCommiter<OpendaylightFlowTableStatisticsListener> getTableNotifCommit();
272 * Define Method : Port Operation/DS notify commit functionality
275 StatNotifyCommiter<OpendaylightPortStatisticsListener> getPortNotifyCommit();
277 StatisticsManagerConfig getConfiguration();
280 * A unique UUID is generated with each node added by the statistics manager implementation in order to uniquely
281 * identify a session.
282 * @param nodeInstanceIdentifier
284 UUID getGeneratedUUIDForNode(InstanceIdentifier<Node> nodeInstanceIdentifier);
287 * Setting entity-ownership-service
289 void setOwnershipService(EntityOwnershipService ownershipService);
292 * Getting entity-ownership-service
294 EntityOwnershipService getOwnershipService();