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.nat.read.ifc;
19 import io.fd.honeycomb.translate.read.ReadContext;
20 import io.fd.honeycomb.translate.read.ReadFailedException;
21 import io.fd.honeycomb.translate.spi.read.Initialized;
22 import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
23 import io.fd.honeycomb.translate.vpp.util.NamingContext;
24 import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetails;
25 import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump;
26 import javax.annotation.Nonnull;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214.NatInterfaceAugmentation;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.Nat;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.NatBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.nat.Inbound;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.nat.InboundBuilder;
35 import org.opendaylight.yangtools.concepts.Builder;
36 import org.opendaylight.yangtools.yang.binding.DataObject;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 final class InterfaceInboundNatCustomizer extends AbstractInterfaceNatCustomizer<Inbound, InboundBuilder> {
43 private static final Logger LOG = LoggerFactory.getLogger(InterfaceInboundNatCustomizer.class);
45 InterfaceInboundNatCustomizer(
46 @Nonnull final DumpCacheManager<SnatInterfaceDetailsReplyDump, Void> dumpMgr,
47 @Nonnull final NamingContext ifcContext) {
48 super(dumpMgr, ifcContext);
52 protected Logger getLog() {
57 public void readCurrentAttributes(@Nonnull final InstanceIdentifier<Inbound> id,
58 @Nonnull final InboundBuilder builder, @Nonnull final ReadContext ctx)
59 throws ReadFailedException {
60 super.readCurrentAttributes(id, builder, ctx);
64 boolean isExpectedNatType(final SnatInterfaceDetails snatInterfaceDetails) {
65 return snatInterfaceDetails.isInside == 1;
70 public InboundBuilder getBuilder(@Nonnull final InstanceIdentifier<Inbound> id) {
71 // Return not present value by default
72 return new InboundBuilder();
76 public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final Inbound readValue) {
77 ((NatBuilder) parentBuilder).setInbound(readValue);
82 public Initialized<? extends DataObject> init(@Nonnull final InstanceIdentifier<Inbound> id,
83 @Nonnull final Inbound readValue,
84 @Nonnull final ReadContext ctx) {
85 final InstanceIdentifier<Inbound> cfgId =
86 InstanceIdentifier.create(Interfaces.class)
87 .child(Interface.class,
88 new InterfaceKey(id.firstKeyOf(
89 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.class).getName()))
90 .augmentation(NatInterfaceAugmentation.class)
92 .child(Inbound.class);
93 return Initialized.create(cfgId, readValue);