bf2c600a2d33c58fecf64e97afaf54ceeb16fa37
[honeycomb.git] / nat / nat2vpp / src / main / java / io / fd / honeycomb / nat / write / ifc / IfcNatWriterFactory.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.write.ifc;
18
19 import com.google.inject.Inject;
20 import com.google.inject.name.Named;
21 import io.fd.honeycomb.translate.impl.write.GenericWriter;
22 import io.fd.honeycomb.translate.vpp.util.NamingContext;
23 import io.fd.honeycomb.translate.write.WriterFactory;
24 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
25 import io.fd.vpp.jvpp.snat.future.FutureJVppSnatFacade;
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.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.nat.Inbound;
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.yangtools.yang.binding.InstanceIdentifier;
34
35 /**
36  * Nat Writers registration.
37  */
38 public final class IfcNatWriterFactory implements WriterFactory {
39
40     private static final InstanceIdentifier<Interface>
41             IFC_ID = InstanceIdentifier.create(Interfaces.class).child(Interface.class);
42     private static final InstanceIdentifier<Nat> NAT_AUG_ID =
43             IFC_ID .augmentation(NatInterfaceAugmentation.class).child(Nat.class);
44
45     private final FutureJVppSnatFacade jvppSnat;
46     private final NamingContext ifcContext;
47
48     @Inject
49     public IfcNatWriterFactory(final FutureJVppSnatFacade jvppSnat,
50                                @Named("interface-context") final NamingContext ifcContext) {
51         this.jvppSnat = jvppSnat;
52         this.ifcContext = ifcContext;
53     }
54
55     @Override
56     public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
57         registry.addAfter(new GenericWriter<>(NAT_AUG_ID.child(Inbound.class),
58                 new InterfaceInboundNatCustomizer(jvppSnat, ifcContext)), IFC_ID);
59         registry.addAfter(new GenericWriter<>(NAT_AUG_ID.child(Outbound.class),
60                 new InterfaceOutboundNatCustomizer(jvppSnat, ifcContext)), IFC_ID);
61     }
62 }