2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.impl.datastore.multipart;
11 import java.util.Objects;
12 import org.opendaylight.openflowplugin.api.openflow.device.DeviceRegistry;
13 import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
14 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
15 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
16 import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMapList;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 public class FlowStatsMultipartWriter extends AbstractMultipartWriter<FlowAndStatisticsMapList> {
32 private final DeviceRegistry registry;
33 private final short version;
35 public FlowStatsMultipartWriter(final TxFacade txFacade,
36 final InstanceIdentifier<Node> instanceIdentifier,
37 final DeviceRegistry registry,
38 final short version) {
39 super(txFacade, instanceIdentifier);
40 this.registry = registry;
41 this.version = version;
45 protected Class<FlowAndStatisticsMapList> getType() {
46 return FlowAndStatisticsMapList.class;
50 public void storeStatistics(final FlowAndStatisticsMapList statistics, final boolean withParents) {
51 statistics.getFlowAndStatisticsMapList()
53 final FlowBuilder flow = new FlowBuilder(stat)
55 FlowStatisticsData.class,
56 new FlowStatisticsDataBuilder()
57 .setFlowStatistics(new FlowStatisticsBuilder(stat).build())
60 final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(version, flow.build());
61 registry.getDeviceFlowRegistry().store(flowRegistryKey);
63 final FlowDescriptor flowDescriptor = registry
64 .getDeviceFlowRegistry()
65 .retrieveDescriptor(flowRegistryKey);
67 if (Objects.nonNull(flowDescriptor)) {
68 final FlowKey key = new FlowKey(flowDescriptor
72 getInstanceIdentifier()
73 .augmentation(FlowCapableNode.class)
74 .child(Table.class, new TableKey(stat.getTableId()))
75 .child(Flow.class, key),