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.translate.v3po.interfacesstate;
19 import static io.fd.honeycomb.translate.vpp.util.SubInterfaceUtils.getSubInterfaceName;
21 import io.fd.honeycomb.translate.read.ReadContext;
22 import io.fd.honeycomb.translate.read.ReadFailedException;
23 import io.fd.honeycomb.translate.spi.read.Initialized;
24 import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer;
25 import io.fd.honeycomb.translate.util.RWUtils;
26 import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
27 import io.fd.honeycomb.translate.vpp.util.NamingContext;
28 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
29 import javax.annotation.Nonnull;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.L2;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.L2Builder;
37 import org.opendaylight.yangtools.concepts.Builder;
38 import org.opendaylight.yangtools.yang.binding.DataObject;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 * Customizer for reading vlan sub interface L2 operational state
46 public class SubInterfaceL2Customizer extends FutureJVppCustomizer
47 implements InitializingReaderCustomizer<L2, L2Builder> {
49 private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceL2Customizer.class);
50 private final InterconnectionReadUtils icReadUtils;
52 public SubInterfaceL2Customizer(@Nonnull final FutureJVppCore futureJVppCore,
53 @Nonnull final NamingContext interfaceContext,
54 @Nonnull final NamingContext bridgeDomainContext) {
55 super(futureJVppCore);
56 this.icReadUtils = new InterconnectionReadUtils(futureJVppCore, interfaceContext, bridgeDomainContext);
60 public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final L2 readValue) {
61 ((SubInterfaceBuilder) parentBuilder).setL2(readValue);
66 public L2Builder getBuilder(@Nonnull final InstanceIdentifier<L2> id) {
67 return new L2Builder();
71 public void readCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2Builder builder,
72 @Nonnull final ReadContext ctx) throws ReadFailedException {
73 LOG.debug("Reading attributes for sub-interface L2: {}", id);
74 final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class);
75 final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class);
76 final String subInterfaceName = getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue());
78 builder.setInterconnection(icReadUtils.readInterconnection(id, subInterfaceName, ctx));
82 public Initialized<L2> init(
83 @Nonnull final InstanceIdentifier<L2> id,
84 @Nonnull final L2 readValue,
85 @Nonnull final ReadContext ctx) {
86 return Initialized.create(getCfgId(id), readValue);
89 static InstanceIdentifier<L2> getCfgId(final InstanceIdentifier<L2> id) {
90 return SubInterfaceCustomizer.getCfgId(RWUtils.cutId(id, SubInterface.class))