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
8 package org.opendaylight.openflowplugin.impl.datastore.multipart;
10 import org.opendaylight.openflowplugin.api.openflow.device.DeviceRegistry;
11 import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
12 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
13 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
14 import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
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.TableKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMapList;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 public class FlowStatsMultipartWriter extends AbstractMultipartWriter<FlowAndStatisticsMapList> {
30 private final DeviceRegistry registry;
31 private final short version;
33 public FlowStatsMultipartWriter(final TxFacade txFacade,
34 final InstanceIdentifier<Node> instanceIdentifier,
35 final DeviceRegistry registry,
36 final short version) {
37 super(txFacade, instanceIdentifier);
38 this.registry = registry;
39 this.version = version;
43 protected Class<FlowAndStatisticsMapList> getType() {
44 return FlowAndStatisticsMapList.class;
48 public void storeStatistics(final FlowAndStatisticsMapList statistics, final boolean withParents) {
49 statistics.nonnullFlowAndStatisticsMapList().values()
51 final FlowBuilder flow = new FlowBuilder(stat)
53 FlowStatisticsData.class,
54 new FlowStatisticsDataBuilder()
55 .setFlowStatistics(new FlowStatisticsBuilder(stat).build())
58 final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(version, flow.build());
59 registry.getDeviceFlowRegistry().store(flowRegistryKey);
61 final FlowDescriptor flowDescriptor = registry
62 .getDeviceFlowRegistry()
63 .retrieveDescriptor(flowRegistryKey);
65 if (flowDescriptor != null) {
66 final FlowKey key = new FlowKey(flowDescriptor.getFlowId());
69 getInstanceIdentifier()
70 .augmentation(FlowCapableNode.class)
71 .child(Table.class, new TableKey(stat.getTableId()))
72 .child(Flow.class, key),