summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-10-26 12:19:02 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-10-28 11:06:23 +0000
commitac29fb15b906ea62b722a2b442de909c6330251f (patch)
tree2a13b5053b172593991e4b803e5a3bfd1e268053 /lisp/lisp2vpp/src
parentaecc708c8918476ca0fa6e5c52cb3366e58cffc1 (diff)
Honeycomb-73 Extensible initializers for lisp
Change-Id: I30b0f472a8ba79b74c92c1b8283d23e860ec78af Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src')
-rw-r--r--lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/LispModule.java8
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializer.java64
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LispStateCustomizer.java36
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializerTest.java32
4 files changed, 30 insertions, 110 deletions
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/LispModule.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/LispModule.java
index 2317b49f7..bd345904f 100644
--- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/LispModule.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/LispModule.java
@@ -26,11 +26,9 @@ import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;
-import io.fd.honeycomb.data.init.DataTreeInitializer;
import io.fd.honeycomb.lisp.cfgattrs.LispConfiguration;
import io.fd.honeycomb.lisp.context.util.ContextsReaderFactoryProvider;
import io.fd.honeycomb.lisp.context.util.EidMappingContext;
-import io.fd.honeycomb.lisp.translate.initializers.LispInitializer;
import io.fd.honeycomb.lisp.translate.read.factory.LispStateReaderFactory;
import io.fd.honeycomb.lisp.translate.write.factory.LispWriterFactory;
import io.fd.honeycomb.translate.read.ReaderFactory;
@@ -75,12 +73,6 @@ public class LispModule extends AbstractModule {
writerFactoryBinder.addBinding().to(LispWriterFactory.class);
LOG.info("Writer factories binded");
- LOG.info("Binding initializers");
- final Multibinder<DataTreeInitializer> initializerBinder =
- Multibinder.newSetBinder(binder(), DataTreeInitializer.class);
- initializerBinder.addBinding().to(LispInitializer.class);
- LOG.info("Initializers binded");
-
final Multibinder<ReaderFactory> readerBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class);
readerBinder.addBinding().toProvider(ContextsReaderFactoryProvider.class).in(Singleton.class);
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializer.java
deleted file mode 100755
index 2715bc1dd..000000000
--- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializer.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.lisp.translate.initializers;
-
-
-import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.HONEYCOMB_INITIALIZER;
-
-import com.google.inject.Inject;
-import com.google.inject.name.Named;
-import io.fd.honeycomb.data.init.AbstractDataTreeConverter;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.Lisp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.LispBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.LispState;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Initializes vpp node in config data tree based on operational state
- */
-public class LispInitializer extends AbstractDataTreeConverter<LispState, Lisp> {
-
- private static final Logger LOG = LoggerFactory.getLogger(LispInitializer.class);
-
- @Inject
- public LispInitializer(@Named(HONEYCOMB_INITIALIZER) final DataBroker bindingDataBroker) {
- super(bindingDataBroker, InstanceIdentifier.create(LispState.class), InstanceIdentifier.create(Lisp.class));
- }
-
- @Override
- protected Lisp convert(final LispState operationalData) {
- LOG.debug("LispInitializer started");
- final LispBuilder lispBuilder = new LispBuilder();
-
- // set everything from LispState to LispBuilder
- // this is necessary in cases, when HC connects to a running VPP with some LISP configuration. HC needs to
- // reconstruct configuration based on what's present in VPP in order to support subsequent configuration changes
- // without any issues
-
- // the other reason this should work is HC persistence, so that HC after restart only performs diff (only push
- // configuration that is not currently in VPP, but is persisted. If they are equal skip any VPP calls)
- // updates to VPP. If this is not fully implemented (depending on VPP implementation, restoration of persisted
- // configuration can fail)
-
- return lispBuilder.setEnable(operationalData.isEnable())
- .setLispFeatureData(operationalData.getLispFeatureData())
- .build();
- }
-}
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LispStateCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LispStateCustomizer.java
index 50c9461a9..77374f9ad 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LispStateCustomizer.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LispStateCustomizer.java
@@ -19,21 +19,24 @@ package io.fd.honeycomb.lisp.translate.read;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
-import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.spi.read.Initialized;
+import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer;
import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
+import io.fd.vpp.jvpp.VppBaseCallException;
+import io.fd.vpp.jvpp.core.dto.ShowLispStatus;
+import io.fd.vpp.jvpp.core.dto.ShowLispStatusReply;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
import java.util.concurrent.TimeoutException;
import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.Lisp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.LispBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.LispState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.LispStateBuilder;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import io.fd.vpp.jvpp.VppBaseCallException;
-import io.fd.vpp.jvpp.core.dto.ShowLispStatus;
-import io.fd.vpp.jvpp.core.dto.ShowLispStatusReply;
-import io.fd.vpp.jvpp.core.future.FutureJVppCore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,7 +45,7 @@ import org.slf4j.LoggerFactory;
* Customizer that handles reads of {@code LispState}
*/
public class LispStateCustomizer extends FutureJVppCustomizer
- implements ReaderCustomizer<LispState, LispStateBuilder>, JvppReplyConsumer, ByteDataTranslator {
+ implements InitializingReaderCustomizer<LispState, LispStateBuilder>, JvppReplyConsumer, ByteDataTranslator {
private static final Logger LOG = LoggerFactory.getLogger(LispStateCustomizer.class);
@@ -73,4 +76,25 @@ public class LispStateCustomizer extends FutureJVppCustomizer
public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final LispState readValue) {
LOG.warn("Merge is unsupported for data roots");
}
+
+ @Override
+ public Initialized<Lisp> init(
+ @Nonnull final InstanceIdentifier<LispState> id, @Nonnull final LispState readValue,
+ @Nonnull final ReadContext ctx) {
+ return Initialized.create(InstanceIdentifier.create(Lisp.class),
+
+ // set everything from LispState to LispBuilder
+ // this is necessary in cases, when HC connects to a running VPP with some LISP configuration. HC needs to
+ // reconstruct configuration based on what's present in VPP in order to support subsequent configuration changes
+ // without any issues
+
+ // the other reason this should work is HC persistence, so that HC after restart only performs diff (only push
+ // configuration that is not currently in VPP, but is persisted. If they are equal skip any VPP calls)
+ // updates to VPP. If this is not fully implemented (depending on VPP implementation, restoration of persisted
+ // configuration can fail)
+ new LispBuilder()
+ .setEnable(readValue.isEnable())
+ .setLispFeatureData(readValue.getLispFeatureData())
+ .build());
+ }
}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializerTest.java
deleted file mode 100644
index d14140f3f..000000000
--- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializerTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package io.fd.honeycomb.lisp.translate.initializers;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
-
-import org.junit.Test;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.Lisp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.LispState;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.LispStateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.lisp.feature.data.grouping.LispFeatureDataBuilder;
-
-
-public class LispInitializerTest {
- @Test
- public void convert() throws Exception {
-
- final LispInitializer initializer = new LispInitializer(mock(DataBroker.class));
- final LispState state = new LispStateBuilder()
- .setEnable(true)
- .setLispFeatureData(new LispFeatureDataBuilder().build())
- .build();
-
- final Lisp operational = initializer.convert(state);
-
- assertNotNull(operational);
- assertEquals(operational.isEnable(), state.isEnable());
- assertEquals(operational.getLispFeatureData(), state.getLispFeatureData());
- }
-
-} \ No newline at end of file