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.v3po.translate.v3po.interfacesstate;
19 import static io.fd.honeycomb.v3po.translate.v3po.interfacesstate.InterfaceUtils.isInterfaceOfType;
21 import com.google.common.base.Preconditions;
22 import io.fd.honeycomb.v3po.translate.Context;
23 import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
24 import io.fd.honeycomb.v3po.translate.spi.read.ChildReaderCustomizer;
25 import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer;
26 import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
27 import javax.annotation.Nonnull;
28 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanTag;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanType;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.SubInterface;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.SubInterfaceBuilder;
36 import org.opendaylight.yangtools.concepts.Builder;
37 import org.opendaylight.yangtools.yang.binding.DataObject;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.openvpp.jvpp.dto.SwInterfaceDetails;
40 import org.openvpp.jvpp.future.FutureJVpp;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
45 * Customizer for reading sub interfaces form the VPP.
47 public class SubInterfaceCustomizer extends FutureJVppCustomizer
48 implements ChildReaderCustomizer<SubInterface, SubInterfaceBuilder> {
50 private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceCustomizer.class);
51 private NamingContext interfaceContext;
53 public SubInterfaceCustomizer(@Nonnull final FutureJVpp jvpp,
54 @Nonnull final NamingContext interfaceContext) {
56 this.interfaceContext = Preconditions.checkNotNull(interfaceContext, "interfaceContext should not be null");
60 public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder,
61 @Nonnull final SubInterface readValue) {
62 ((VppInterfaceStateAugmentationBuilder) parentBuilder).setSubInterface(readValue);
67 public SubInterfaceBuilder getBuilder(@Nonnull final InstanceIdentifier<SubInterface> id) {
68 return new SubInterfaceBuilder();
72 public void readCurrentAttributes(@Nonnull final InstanceIdentifier<SubInterface> id,
73 @Nonnull final SubInterfaceBuilder builder, @Nonnull final Context ctx)
74 throws ReadFailedException {
75 final InterfaceKey key = id.firstKeyOf(Interface.class);
76 // Relying here that parent InterfaceCustomizer was invoked first (PREORDER)
77 // to fill in the context with initial ifc mapping
78 final int index = interfaceContext.getIndex(key.getName());
79 if (!isInterfaceOfType(ctx, index, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.SubInterface.class)) {
83 LOG.debug("Reading attributes for sub interface: {}", id);
84 final SwInterfaceDetails iface = InterfaceUtils.getVppInterfaceDetails(getFutureJVpp(), key, index, ctx);
85 LOG.debug("VPP interface details: {}", ReflectionToStringBuilder.toString(iface));
87 if (iface.subId == 0) {
88 // Not a sub interface type
92 builder.setIdentifier(Long.valueOf(iface.subId));
93 builder.setSuperInterface(interfaceContext.getName(iface.supSwIfIndex));
94 builder.setNumberOfTags(Short.valueOf(iface.subNumberOfTags));
95 builder.setVlanType(iface.subDot1Ad == 1 ? VlanType._802dot1q : VlanType._802dot1ad);
96 if (iface.subExactMatch == 1) {
97 builder.setExactMatch(true);
99 if (iface.subDefault == 1) {
100 builder.setDefaultSubif(true);
102 if (iface.subOuterVlanIdAny == 1) {
103 builder.setMatchAnyOuterId(true);
105 if (iface.subOuterVlanIdAny == 1) {
106 builder.setMatchAnyInnerId(true);
108 if (iface.subOuterVlanId != 0) { // optional
109 builder.setOuterId(new VlanTag(Integer.valueOf(iface.subOuterVlanId)));
111 if (iface.subInnerVlanId != 0) { // optional
112 builder.setInnerId(new VlanTag(Integer.valueOf(iface.subInnerVlanId)));