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.impl.registry.flow.FlowRegistryKeyFactory;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
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.inventory.rev130819.tables.table.FlowBuilder;
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.FlowAndStatisticsMapList;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 public class FlowStatsMultipartWriter extends AbstractMultipartWriter<FlowAndStatisticsMapList> {
26 private final DeviceRegistry registry;
28 public FlowStatsMultipartWriter(final TxFacade txFacade,
29 final InstanceIdentifier<Node> instanceIdentifier,
30 final DeviceRegistry registry) {
31 super(txFacade, instanceIdentifier);
32 this.registry = registry;
36 protected Class<FlowAndStatisticsMapList> getType() {
37 return FlowAndStatisticsMapList.class;
41 public void storeStatistics(final FlowAndStatisticsMapList statistics, final boolean withParents) {
42 statistics.nonnullFlowAndStatisticsMapList()
44 final var flowBuilder = new FlowBuilder(stat)
45 .withKey(FlowRegistryKeyFactory.DUMMY_FLOW_KEY)
46 .addAugmentation(new FlowStatisticsDataBuilder()
47 .setFlowStatistics(new FlowStatisticsBuilder(stat).build())
50 final var flowRegistry = registry.getDeviceFlowRegistry();
51 final var flowRegistryKey = flowRegistry.createKey(flowBuilder.build());
52 flowRegistry.store(flowRegistryKey);
54 final var flowDescriptor = flowRegistry.retrieveDescriptor(flowRegistryKey);
55 if (flowDescriptor != null) {
56 final FlowKey key = new FlowKey(flowDescriptor.getFlowId());
59 getInstanceIdentifier()
60 .augmentation(FlowCapableNode.class)
61 .child(Table.class, new TableKey(stat.getTableId()))
62 .child(Flow.class, key),