2 * Copyright (c) 2019 PANTHEON.tech.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.hc2vpp.v3po.interfacesstate;
19 import io.fd.hc2vpp.common.translate.util.NamingContext;
20 import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheStatisticsDumpManager;
21 import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheStatisticsSample;
22 import io.fd.honeycomb.translate.read.ReadContext;
23 import io.fd.honeycomb.translate.read.ReadFailedException;
24 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
25 import javax.annotation.Nonnull;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev181128.VppInterfaceStateStatsCollectionAugmentationBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev181128.interfaces.state._interface.StatisticsCollection;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev181128.interfaces.state._interface.StatisticsCollectionBuilder;
31 import org.opendaylight.yangtools.concepts.Builder;
32 import org.opendaylight.yangtools.yang.binding.DataObject;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 public class InterfaceStatisticsCollectionCustomizer implements
36 ReaderCustomizer<StatisticsCollection, StatisticsCollectionBuilder> {
37 private NamingContext ifcNamingCtx;
38 private InterfaceCacheStatisticsDumpManager ifaceStatisticsManager;
40 public InterfaceStatisticsCollectionCustomizer(final NamingContext ifcNamingCtx,
41 final InterfaceCacheStatisticsDumpManager ifaceStatisticsManager) {
43 this.ifcNamingCtx = ifcNamingCtx;
44 this.ifaceStatisticsManager = ifaceStatisticsManager;
49 public StatisticsCollectionBuilder getBuilder(@Nonnull final InstanceIdentifier<StatisticsCollection> id) {
50 return new StatisticsCollectionBuilder();
54 public void readCurrentAttributes(@Nonnull final InstanceIdentifier<StatisticsCollection> id,
55 @Nonnull final StatisticsCollectionBuilder builder,
56 @Nonnull final ReadContext ctx)
57 throws ReadFailedException {
58 final InterfaceKey key = id.firstKeyOf(Interface.class);
59 final int index = ifcNamingCtx.getIndex(key.getName(), ctx.getMappingContext());
60 final InterfaceCacheStatisticsSample statisticsDetails = this.ifaceStatisticsManager.getStatisticsData(index);
61 if (statisticsDetails != null) {
62 builder.setStatisticsEnabled(true);
64 builder.setStatisticsEnabled(false);
69 public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder,
70 @Nonnull final StatisticsCollection readValue) {
71 ((VppInterfaceStateStatsCollectionAugmentationBuilder) parentBuilder).setStatisticsCollection(readValue);