Merge "Drop the odlparent.netty property"
[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,
33         FlowsStatisticsUpdate> {
34
35     private static final InstanceIdentifier<FlowStatistics> FLOW_STATISTICS_INSTANCE_IDENTIFIER = getNodeWildII()
36             .augmentation(FlowCapableNode.class).child(Table.class).child(Flow.class)
37             .augmentation(FlowStatisticsData.class).child(FlowStatistics.class);
38
39     /**
40      * Constructor register supplier as DataTreeChangeListener and create wildCarded InstanceIdentifier.
41      *
42      * @param notifProviderService - {@link NotificationProviderService}
43      * @param db                   - {@link DataBroker}
44      */
45     public FlowStatNotificationSupplierImpl(final NotificationProviderService notifProviderService,
46                                             final DataBroker db) {
47         super(notifProviderService, db, FlowStatistics.class);
48     }
49
50     @Override
51     public InstanceIdentifier<FlowStatistics> getWildCardPath() {
52         return FLOW_STATISTICS_INSTANCE_IDENTIFIER;
53     }
54
55     @Override
56     public FlowsStatisticsUpdate createNotification(final FlowStatistics flowStatistics,
57                                                     final InstanceIdentifier<FlowStatistics> path) {
58         Preconditions.checkArgument(flowStatistics != null);
59         Preconditions.checkArgument(path != null);
60
61         final FlowAndStatisticsMapListBuilder fsmlBuilder = new FlowAndStatisticsMapListBuilder(flowStatistics);
62         fsmlBuilder.setFlowId(new FlowId(path.firstKeyOf(Flow.class, FlowKey.class).getId().getValue()));
63
64         final FlowsStatisticsUpdateBuilder builder = new FlowsStatisticsUpdateBuilder();
65         builder.setId(getNodeId(path));
66         builder.setMoreReplies(Boolean.FALSE);
67         // NOTE : fix if it needs, but we have to ask DataStore for the NodeConnector list
68         builder.setNodeConnector(Collections.<NodeConnector>emptyList());
69         builder.setFlowAndStatisticsMapList(Collections.singletonList(fsmlBuilder.build()));
70         return builder.build();
71     }
72 }
73