da940c835d07a5084161ea2eb71629b60feae292
[honeycomb.git] / nat / nat2vpp / src / main / java / io / fd / honeycomb / nat / read / ifc / InterfaceOutboundNatCustomizer.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.spi.read.Initialized;
21 import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
22 import io.fd.honeycomb.translate.vpp.util.NamingContext;
23 import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetails;
24 import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump;
25 import javax.annotation.Nonnull;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214.NatInterfaceAugmentation;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.Nat;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.NatBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.nat.Outbound;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.nat.OutboundBuilder;
34 import org.opendaylight.yangtools.concepts.Builder;
35 import org.opendaylight.yangtools.yang.binding.DataObject;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 final class InterfaceOutboundNatCustomizer extends AbstractInterfaceNatCustomizer<Outbound, OutboundBuilder> {
41
42     private static final Logger LOG = LoggerFactory.getLogger(InterfaceOutboundNatCustomizer.class);
43
44     InterfaceOutboundNatCustomizer(
45             @Nonnull final DumpCacheManager<SnatInterfaceDetailsReplyDump, Void> dumpMgr,
46             @Nonnull final NamingContext ifcContext) {
47         super(dumpMgr, ifcContext);
48     }
49
50     @Override
51     protected Logger getLog() {
52         return LOG;
53     }
54
55     @Override
56     boolean isExpectedNatType(final SnatInterfaceDetails snatInterfaceDetails) {
57         return snatInterfaceDetails.isInside == 0;
58     }
59
60     @Nonnull
61     @Override
62     public OutboundBuilder getBuilder(@Nonnull final InstanceIdentifier<Outbound> id) {
63         return new OutboundBuilder();
64     }
65
66     @Override
67     public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final Outbound readValue) {
68         ((NatBuilder) parentBuilder).setOutbound(readValue);
69     }
70
71     @Nonnull
72     @Override
73     public Initialized<? extends DataObject> init(@Nonnull final InstanceIdentifier<Outbound> id,
74                                                   @Nonnull final Outbound readValue,
75                                                   @Nonnull final ReadContext ctx) {
76         final InstanceIdentifier<Outbound> cfgId =
77                 InstanceIdentifier.create(Interfaces.class)
78                         .child(Interface.class,
79                                 new InterfaceKey(id.firstKeyOf(
80                                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.class).getName()))
81                         .augmentation(NatInterfaceAugmentation.class)
82                         .child(Nat.class)
83                         .child(Outbound.class);
84         return Initialized.create(cfgId, readValue);
85     }
86 }