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;
19 import com.google.common.annotations.VisibleForTesting;
20 import com.google.inject.AbstractModule;
21 import com.google.inject.Provider;
22 import com.google.inject.Singleton;
23 import com.google.inject.multibindings.Multibinder;
24 import io.fd.honeycomb.nat.jvpp.JVppSnatProvider;
25 import io.fd.honeycomb.nat.read.NatReaderFactory;
26 import io.fd.honeycomb.nat.read.ifc.IfcNatReaderFactory;
27 import io.fd.honeycomb.nat.util.MappingEntryContext;
28 import io.fd.honeycomb.nat.write.NatWriterFactory;
29 import io.fd.honeycomb.nat.write.ifc.IfcNatWriterFactory;
30 import io.fd.honeycomb.translate.read.ReaderFactory;
31 import io.fd.honeycomb.translate.write.WriterFactory;
32 import io.fd.vpp.jvpp.snat.future.FutureJVppSnatFacade;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * Module class instantiating nat plugin components.
39 public final class NatModule extends AbstractModule {
41 private static final Logger LOG = LoggerFactory.getLogger(NatModule.class);
42 private final Class<? extends Provider<FutureJVppSnatFacade>> jvppSnatProviderClass;
45 this(JVppSnatProvider.class);
49 NatModule(Class<? extends Provider<FutureJVppSnatFacade>> jvppSnatProvider) {
50 this.jvppSnatProviderClass = jvppSnatProvider;
54 protected void configure() {
55 // Mapping entry context util
56 bind(MappingEntryContext.class).toInstance(new MappingEntryContext());
58 LOG.debug("Installing NAT module");
60 // Bind to Plugin's JVPP
61 bind(FutureJVppSnatFacade.class).toProvider(jvppSnatProviderClass).in(Singleton.class);
63 final Multibinder<ReaderFactory> readBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class);
64 readBinder.addBinding().to(IfcNatReaderFactory.class).in(Singleton.class);
65 readBinder.addBinding().to(NatReaderFactory.class).in(Singleton.class);
67 final Multibinder<WriterFactory> writeBinder = Multibinder.newSetBinder(binder(), WriterFactory.class);
68 writeBinder.addBinding().to(IfcNatWriterFactory.class).in(Singleton.class);
69 writeBinder.addBinding().to(NatWriterFactory.class).in(Singleton.class);
70 LOG.info("Module NAT successfully configured");