HONEYCOMB-58 - Routing Api
[honeycomb.git] / ioam / impl / src / main / java / io / fd / honeycomb / vppioam / impl / VppIoamModule.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 package io.fd.honeycomb.vppioam.impl;
17
18 import com.google.common.annotations.VisibleForTesting;
19 import com.google.inject.AbstractModule;
20 import com.google.inject.Singleton;
21 import com.google.inject.multibindings.Multibinder;
22 import com.google.inject.name.Names;
23 import com.google.inject.Provider;
24 import io.fd.honeycomb.data.init.DataTreeInitializer;
25 import io.fd.honeycomb.translate.read.ReaderFactory;
26 import io.fd.honeycomb.translate.write.WriterFactory;
27 import io.fd.honeycomb.vppioam.impl.config.VppIoamWriterFactory;
28 import io.fd.honeycomb.vppioam.impl.util.JVppIoamProvider;
29 import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace;
30 import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * Glue code necessary for Honeycomb distribution to pick up the plugin classes
36  */
37 public final class VppIoamModule extends AbstractModule {
38
39     private static final Logger LOG = LoggerFactory.getLogger(VppIoamModule.class);
40     private final Class<? extends Provider<FutureJVppIoamtraceFacade>> jvppIoamProviderClass;
41
42     public VppIoamModule() {
43         this(JVppIoamProvider.class);
44     }
45
46     @VisibleForTesting
47     VppIoamModule(Class<? extends Provider<FutureJVppIoamtraceFacade>> jvppIoamProvider) {
48         this.jvppIoamProviderClass = jvppIoamProvider;
49     }
50
51     @Override
52     protected void configure() {
53         LOG.debug("Installing iOAM module");
54
55         // Bind to Plugin's JVPP.
56         bind(FutureJVppIoamtrace.class).toProvider(jvppIoamProviderClass).in(Singleton.class);
57
58         // Below are classes picked up by HC framework
59         Multibinder.newSetBinder(binder(), WriterFactory.class).addBinding().to(VppIoamWriterFactory.class);
60
61         LOG.debug("Module iOAM successfully configured");
62     }
63 }