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.applications.notification.supplier.impl.item.stat;
11 import com.google.common.base.Preconditions;
12 import java.util.Collections;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdateBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatistics;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 * Implementation define a contract between {@link FlowStatistics} data object
29 * and {@link FlowsStatisticsUpdate} notification.
31 public class FlowStatNotificationSupplierImpl extends AbstractNotificationSupplierForItemStat<FlowStatistics,
32 FlowsStatisticsUpdate> {
34 private static final InstanceIdentifier<FlowStatistics> FLOW_STATISTICS_INSTANCE_IDENTIFIER = getNodeWildII()
35 .augmentation(FlowCapableNode.class).child(Table.class).child(Flow.class)
36 .augmentation(FlowStatisticsData.class).child(FlowStatistics.class);
39 * Constructor register supplier as DataTreeChangeListener and create wildCarded InstanceIdentifier.
41 * @param notifProviderService - {@link NotificationProviderService}
42 * @param db - {@link DataBroker}
44 public FlowStatNotificationSupplierImpl(final NotificationProviderService notifProviderService,
45 final DataBroker db) {
46 super(notifProviderService, db, FlowStatistics.class);
50 public InstanceIdentifier<FlowStatistics> getWildCardPath() {
51 return FLOW_STATISTICS_INSTANCE_IDENTIFIER;
55 public FlowsStatisticsUpdate createNotification(final FlowStatistics flowStatistics,
56 final InstanceIdentifier<FlowStatistics> path) {
57 Preconditions.checkArgument(flowStatistics != null);
58 Preconditions.checkArgument(path != null);
60 final FlowAndStatisticsMapListBuilder fsmlBuilder = new FlowAndStatisticsMapListBuilder(flowStatistics);
61 fsmlBuilder.setFlowId(new FlowId(path.firstKeyOf(Flow.class).getId().getValue()));
63 final FlowsStatisticsUpdateBuilder builder = new FlowsStatisticsUpdateBuilder();
64 builder.setId(getNodeId(path));
65 builder.setMoreReplies(Boolean.FALSE);
66 // NOTE : fix if it needs, but we have to ask DataStore for the NodeConnector list
67 builder.setNodeConnector(Collections.<NodeConnector>emptyList());
68 builder.setFlowAndStatisticsMapList(Collections.singletonList(fsmlBuilder.build()));
69 return builder.build();