Merge "BUG-5636: making table features configurable for the He plugin. DEFAULT will...
[openflowplugin.git] / applications / notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / item / stat / FlowStatNotificationSupplierImpl.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.applications.notification.supplier.impl.item.stat;
10
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.inventory.rev130819.tables.table.FlowKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdateBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatistics;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27
28 /**
29  * Implementation define a contract between {@link FlowStatistics} data object
30  * and {@link FlowsStatisticsUpdate} notification.
31  */
32 public class FlowStatNotificationSupplierImpl extends AbstractNotificationSupplierForItemStat<FlowStatistics, FlowsStatisticsUpdate> {
33
34     private static final InstanceIdentifier<FlowStatistics> wildCardedInstanceIdent =
35             getNodeWildII().augmentation(FlowCapableNode.class).child(Table.class)
36                     .child(Flow.class).augmentation(FlowStatisticsData.class).child(FlowStatistics.class);
37
38     /**
39      * Constructor register supplier as DataChangeLister and create wildCarded InstanceIdentifier.
40      *
41      * @param notifProviderService - {@link NotificationProviderService}
42      * @param db - {@link DataBroker}
43      */
44     public FlowStatNotificationSupplierImpl(final NotificationProviderService notifProviderService, final DataBroker db) {
45         super(notifProviderService, db, FlowStatistics.class);
46     }
47
48     @Override
49     public InstanceIdentifier<FlowStatistics> getWildCardPath() {
50         return wildCardedInstanceIdent;
51     }
52
53     @Override
54     public FlowsStatisticsUpdate createNotification(final FlowStatistics o, final InstanceIdentifier<FlowStatistics> path) {
55         Preconditions.checkArgument(o != null);
56         Preconditions.checkArgument(path != null);
57
58         final FlowAndStatisticsMapListBuilder fsmlBuilder = new FlowAndStatisticsMapListBuilder(o);
59         fsmlBuilder.setFlowId(new FlowId(path.firstKeyOf(Flow.class, FlowKey.class).getId().getValue()));
60
61         final FlowsStatisticsUpdateBuilder builder = new FlowsStatisticsUpdateBuilder();
62         builder.setId(getNodeId(path));
63         builder.setMoreReplies(Boolean.FALSE);
64         // NOTE : fix if it needs, but we have to ask DataStore for the NodeConnector list
65         builder.setNodeConnector(Collections.<NodeConnector>emptyList());
66         builder.setFlowAndStatisticsMapList(Collections.singletonList(fsmlBuilder.build()));
67         return builder.build();
68     }
69 }
70