Switch to MD-SAL APIs
[openflowplugin.git] / applications / notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / item / stat / FlowTableStatNotificationSupplierImpl.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.table.statistics.rev131215.FlowTableStatisticsData;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25
26 /**
27  * Implementation define a contract between {@link FlowTableStatistics} data object
28  * and {@link FlowTableStatisticsUpdate} notification.
29  */
30 public class FlowTableStatNotificationSupplierImpl extends
31         AbstractNotificationSupplierForItemStat<FlowTableStatistics, FlowTableStatisticsUpdate> {
32
33     private static final InstanceIdentifier<FlowTableStatistics> FLOW_TABLE_STATISTICS_INSTANCE_IDENTIFIER
34             = getNodeWildII().augmentation(FlowCapableNode.class).child(Table.class)
35             .augmentation(FlowTableStatisticsData.class).child(FlowTableStatistics.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 FlowTableStatNotificationSupplierImpl(final NotificationPublishService notifProviderService,
44                                                  final DataBroker db) {
45         super(notifProviderService, db, FlowTableStatistics.class);
46     }
47
48     @Override
49     public InstanceIdentifier<FlowTableStatistics> getWildCardPath() {
50         return FLOW_TABLE_STATISTICS_INSTANCE_IDENTIFIER;
51     }
52
53     @Override
54     public FlowTableStatisticsUpdate createNotification(final FlowTableStatistics flowTableStatistics,
55                                                         final InstanceIdentifier<FlowTableStatistics> path) {
56         Preconditions.checkArgument(flowTableStatistics != null);
57         Preconditions.checkArgument(path != null);
58
59         final FlowTableAndStatisticsMapBuilder ftsmBuilder = new FlowTableAndStatisticsMapBuilder(flowTableStatistics);
60         ftsmBuilder.withKey(new FlowTableAndStatisticsMapKey(
61                 new TableId(path.firstKeyOf(Table.class).getId())));
62
63         final FlowTableStatisticsUpdateBuilder builder = new FlowTableStatisticsUpdateBuilder();
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.setFlowTableAndStatisticsMap(Collections.singletonList(ftsmBuilder.build()));
69         return builder.build();
70     }
71 }
72