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