2 * Copyright (c) 2016 Cisco and/or its affiliates.
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.honeycomb.samples.interfaces.mapping.oper;
19 import io.fd.honeycomb.samples.interfaces.mapping.LowerLayerAccess;
20 import io.fd.honeycomb.translate.read.ReadContext;
21 import io.fd.honeycomb.translate.read.ReadFailedException;
22 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
23 import javax.annotation.Nonnull;
24 import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810._interface.state.Counters;
25 import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810._interface.state.CountersBuilder;
26 import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810.interfaces.state.Interface;
27 import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810.interfaces.state.InterfaceBuilder;
28 import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810.interfaces.state.InterfaceKey;
29 import org.opendaylight.yangtools.concepts.Builder;
30 import org.opendaylight.yangtools.yang.binding.DataObject;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * This is a customizer responsible for reading Counters operational data
38 public class CountersReaderCustomizer implements ReaderCustomizer<Counters, CountersBuilder> {
40 private static final Logger LOG = LoggerFactory.getLogger(CountersReaderCustomizer.class);
41 private final LowerLayerAccess access;
43 public CountersReaderCustomizer(final LowerLayerAccess access) {
50 public CountersBuilder getBuilder(@Nonnull final InstanceIdentifier<Counters> id) {
51 return new CountersBuilder();
55 public void readCurrentAttributes(@Nonnull final InstanceIdentifier<Counters> id,
56 @Nonnull final CountersBuilder builder, @Nonnull final ReadContext ctx)
57 throws ReadFailedException {
58 // Get the information about which interface to get counters for
59 final InterfaceKey interfaceKey = id.firstKeyOf(Interface.class);
60 LOG.info("Reading counters for interface: {} at {}", interfaceKey.getInterfaceId(), id);
62 // Set some random data
63 builder.setDroppedPackets(access.getDroppedPacketsForIfc(interfaceKey.getInterfaceId().getValue()));
64 builder.setTotalPackets(access.getTotalPacketsForInterface(interfaceKey.getInterfaceId().getValue()));
68 public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final Counters readValue) {
69 ((InterfaceBuilder) parentBuilder).setCounters(readValue);