3e4b60fb46a75ebbb46414d278553c35f80ad187
[honeycomb.git] / nat / nat2vpp / src / main / java / io / fd / honeycomb / nat / read / ifc / InterfaceInboundNatCustomizer.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.nat.read.ifc;
18
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;
40
41 final class InterfaceInboundNatCustomizer extends AbstractInterfaceNatCustomizer<Inbound, InboundBuilder> {
42
43     private static final Logger LOG = LoggerFactory.getLogger(InterfaceInboundNatCustomizer.class);
44
45     InterfaceInboundNatCustomizer(
46             @Nonnull final DumpCacheManager<SnatInterfaceDetailsReplyDump, Void> dumpMgr,
47             @Nonnull final NamingContext ifcContext) {
48         super(dumpMgr, ifcContext);
49     }
50
51     @Override
52     protected Logger getLog() {
53         return LOG;
54     }
55
56     @Override
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);
61     }
62
63     @Override
64     boolean isExpectedNatType(final SnatInterfaceDetails snatInterfaceDetails) {
65         return snatInterfaceDetails.isInside == 1;
66     }
67
68     @Nonnull
69     @Override
70     public InboundBuilder getBuilder(@Nonnull final InstanceIdentifier<Inbound> id) {
71         // Return not present value by default
72         return new InboundBuilder();
73     }
74
75     @Override
76     public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final Inbound readValue) {
77         ((NatBuilder) parentBuilder).setInbound(readValue);
78     }
79
80     @Nonnull
81     @Override
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)
91                 .child(Nat.class)
92                 .child(Inbound.class);
93         return Initialized.create(cfgId, readValue);
94     }
95 }