summaryrefslogtreecommitdiffstats
path: root/nat/nat2vpp/src
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-10-26 12:18:53 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-10-28 11:06:17 +0000
commitfbaf23a926ce6727301aa8a293cb101ba17800b8 (patch)
tree9b56f2d0f0e3d77d08d1424e336c35eaa59e2ad1 /nat/nat2vpp/src
parent8dd7be1663a75d0f1b0cdd0375630d5596e6a066 (diff)
Honeycomb-73 Extensible initializers for nat
Change-Id: Ic3f28ecf2a798a9ff084abb551f90bad516d3a13 Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'nat/nat2vpp/src')
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/NatModule.java5
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/init/NatInitializer.java67
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/ExternalIpPoolCustomizer.java19
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/MappingEntryCustomizer.java23
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/NatInstanceCustomizer.java25
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/NatReaderFactory.java8
6 files changed, 65 insertions, 82 deletions
diff --git a/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/NatModule.java b/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/NatModule.java
index b33f900e5..adaaca9c3 100644
--- a/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/NatModule.java
+++ b/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/NatModule.java
@@ -21,8 +21,6 @@ import com.google.inject.AbstractModule;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.multibindings.Multibinder;
-import io.fd.honeycomb.data.init.DataTreeInitializer;
-import io.fd.honeycomb.nat.init.NatInitializer;
import io.fd.honeycomb.nat.jvpp.JVppSnatProvider;
import io.fd.honeycomb.nat.read.NatReaderFactory;
import io.fd.honeycomb.nat.read.ifc.IfcNatReaderFactory;
@@ -69,9 +67,6 @@ public final class NatModule extends AbstractModule {
final Multibinder<WriterFactory> writeBinder = Multibinder.newSetBinder(binder(), WriterFactory.class);
writeBinder.addBinding().to(IfcNatWriterFactory.class).in(Singleton.class);
writeBinder.addBinding().to(NatWriterFactory.class).in(Singleton.class);
-
- Multibinder.newSetBinder(binder(), DataTreeInitializer.class)
- .addBinding().to(NatInitializer.class).in(Singleton.class);
LOG.info("Module NAT successfully configured");
}
}
diff --git a/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/init/NatInitializer.java b/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/init/NatInitializer.java
deleted file mode 100644
index 1c5b20392..000000000
--- a/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/init/NatInitializer.java
+++ /dev/null
@@ -1,67 +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.nat.init;
-
-import com.google.inject.Inject;
-import com.google.inject.name.Named;
-import io.fd.honeycomb.data.init.AbstractDataTreeConverter;
-import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.NatConfig;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.NatConfigBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.NatState;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.NatInstancesBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstanceBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.MappingTableBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryBuilder;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-/**
- * Initialize nat-config from nat-state.
- */
-public final class NatInitializer extends AbstractDataTreeConverter<NatState, NatConfig> {
-
- @Inject
- public NatInitializer(@Named("honeycomb-initializer") @Nonnull final DataBroker bindingDataBroker) {
- super(bindingDataBroker, InstanceIdentifier.create(NatState.class), InstanceIdentifier.create(NatConfig.class));
- }
-
- @Override
- public NatConfig convert(final NatState operationalData) {
- return new NatConfigBuilder()
- .setNatInstances(new NatInstancesBuilder()
- .setNatInstance(operationalData.getNatInstances().getNatInstance().stream()
- .map(operNatInstance -> new NatInstanceBuilder()
- .setId(operNatInstance.getId())
- // Ext IP pools
- .setExternalIpAddressPool(operNatInstance.getNatCurrentConfig().getExternalIpAddressPool())
- // Mapping entries
- .setMappingTable(new MappingTableBuilder()
- .setMappingEntry(
- operNatInstance.getMappingTable().getMappingEntry().stream()
- .map(operEntry -> new MappingEntryBuilder(operEntry).build())
- .collect(Collectors.toList()))
- .build())
- .build())
- .collect(Collectors.toList()))
- .build())
- .build();
-
- // TODO implement initialization for nat inbound/outbound NAT feature after VPP-459
- }
-}
diff --git a/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/ExternalIpPoolCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/ExternalIpPoolCustomizer.java
index 206b15e63..959bfbdc1 100644
--- a/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/ExternalIpPoolCustomizer.java
+++ b/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/ExternalIpPoolCustomizer.java
@@ -18,7 +18,9 @@ package io.fd.honeycomb.nat.read;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
-import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
+import io.fd.honeycomb.translate.spi.read.Initialized;
+import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer;
+import io.fd.honeycomb.translate.util.RWUtils;
import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
import io.fd.honeycomb.translate.vpp.util.Ipv4Translator;
@@ -46,7 +48,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final class ExternalIpPoolCustomizer implements
- ListReaderCustomizer<ExternalIpAddressPool, ExternalIpAddressPoolKey, ExternalIpAddressPoolBuilder>,
+ InitializingListReaderCustomizer<ExternalIpAddressPool, ExternalIpAddressPoolKey, ExternalIpAddressPoolBuilder>,
JvppReplyConsumer, Ipv4Translator {
private static final Logger LOG = LoggerFactory.getLogger(ExternalIpPoolCustomizer.class);
@@ -116,6 +118,19 @@ final class ExternalIpPoolCustomizer implements
((NatCurrentConfigBuilder) builder).setExternalIpAddressPool(readData);
}
+ @Override
+ public Initialized<ExternalIpAddressPool> init(
+ @Nonnull final InstanceIdentifier<ExternalIpAddressPool> id,
+ @Nonnull final ExternalIpAddressPool readValue,
+ @Nonnull final ReadContext ctx) {
+ return Initialized.create(getCfgId(id), readValue);
+ }
+
+ static InstanceIdentifier<ExternalIpAddressPool> getCfgId(final @Nonnull InstanceIdentifier<ExternalIpAddressPool> id) {
+ return NatInstanceCustomizer.getCfgId(RWUtils.cutId(id, NatInstance.class))
+ .child(ExternalIpAddressPool.class, id.firstKeyOf(ExternalIpAddressPool.class));
+ }
+
static final class AddressRangeDumpExecutor implements EntityDumpExecutor<SnatAddressDetailsReplyDump, Void>,
JvppReplyConsumer {
private final FutureJVppSnatFacade jvppSnat;
diff --git a/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/MappingEntryCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/MappingEntryCustomizer.java
index c0f70452b..c525cb9da 100644
--- a/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/MappingEntryCustomizer.java
+++ b/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/MappingEntryCustomizer.java
@@ -19,7 +19,9 @@ package io.fd.honeycomb.nat.read;
import io.fd.honeycomb.nat.util.MappingEntryContext;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
-import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
+import io.fd.honeycomb.translate.spi.read.Initialized;
+import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer;
+import io.fd.honeycomb.translate.util.RWUtils;
import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
import io.fd.honeycomb.translate.vpp.util.Ipv4Translator;
@@ -35,6 +37,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.mapping.entry.ExternalSrcPortBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.mapping.entry.InternalSrcPortBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.MappingTable;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.NatInstance;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.nat.instance.MappingTableBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.nat.instance.mapping.table.MappingEntry;
@@ -48,7 +51,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final class MappingEntryCustomizer implements Ipv4Translator,
- ListReaderCustomizer<MappingEntry, MappingEntryKey, MappingEntryBuilder> {
+ InitializingListReaderCustomizer<MappingEntry, MappingEntryKey, MappingEntryBuilder> {
private static final Logger LOG = LoggerFactory.getLogger(MappingEntryCustomizer.class);
@@ -131,6 +134,22 @@ final class MappingEntryCustomizer implements Ipv4Translator,
((MappingTableBuilder) builder).setMappingEntry(readData);
}
+ @Override
+ public Initialized<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry> init(@Nonnull final InstanceIdentifier<MappingEntry> id,
+ @Nonnull final MappingEntry readValue,
+ @Nonnull final ReadContext ctx) {
+ return Initialized.create(getCfgId(id),
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryBuilder(readValue)
+ .build());
+ }
+
+ static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry> getCfgId(final @Nonnull InstanceIdentifier<MappingEntry> id) {
+ return NatInstanceCustomizer.getCfgId(RWUtils.cutId(id, NatInstance.class))
+ .child(MappingTable.class)
+ .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry.class,
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryKey(id.firstKeyOf(MappingEntry.class).getIndex()));
+ }
+
static final class MappingEntryDumpExecutor
implements EntityDumpExecutor<SnatStaticMappingDetailsReplyDump, Void>, JvppReplyConsumer {
diff --git a/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/NatInstanceCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/NatInstanceCustomizer.java
index 43f4f1e0c..0c089e454 100644
--- a/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/NatInstanceCustomizer.java
+++ b/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/NatInstanceCustomizer.java
@@ -18,12 +18,14 @@ package io.fd.honeycomb.nat.read;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
-import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
+import io.fd.honeycomb.translate.spi.read.Initialized;
+import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer;
import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
import io.fd.vpp.jvpp.snat.dto.SnatStaticMappingDetailsReplyDump;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.NatConfig;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.NatInstancesBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.NatInstance;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.NatInstanceBuilder;
@@ -37,7 +39,7 @@ import org.slf4j.LoggerFactory;
/**
* Nat instance ID is mapped to VRF-ID in VPP.
*/
-final class NatInstanceCustomizer implements ListReaderCustomizer<NatInstance, NatInstanceKey, NatInstanceBuilder> {
+final class NatInstanceCustomizer implements InitializingListReaderCustomizer<NatInstance, NatInstanceKey, NatInstanceBuilder> {
private static final Logger LOG = LoggerFactory.getLogger(NatInstanceCustomizer.class);
static final NatInstanceKey DEFAULT_VRF_ID = new NatInstanceKey(0L);
@@ -89,4 +91,23 @@ final class NatInstanceCustomizer implements ListReaderCustomizer<NatInstance, N
public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<NatInstance> readData) {
((NatInstancesBuilder) builder).setNatInstance(readData);
}
+
+ @Override
+ public Initialized<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstance> init(@Nonnull final InstanceIdentifier<NatInstance> id,
+ @Nonnull final NatInstance readValue,
+ @Nonnull final ReadContext ctx) {
+ return Initialized.create(getCfgId(id),
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstanceBuilder()
+ .setId(readValue.getId())
+ .build());
+ }
+
+ static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstance> getCfgId(
+ @Nonnull final InstanceIdentifier<NatInstance> id) {
+ return InstanceIdentifier.create(NatConfig.class)
+ .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.NatInstances.class)
+ .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstance.class,
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstanceKey(
+ id.firstKeyOf(NatInstance.class).getId()));
+ }
}
diff --git a/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/NatReaderFactory.java b/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/NatReaderFactory.java
index 9ae0e12f9..a44d1117e 100644
--- a/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/NatReaderFactory.java
+++ b/nat/nat2vpp/src/main/java/io/fd/honeycomb/nat/read/NatReaderFactory.java
@@ -19,7 +19,7 @@ package io.fd.honeycomb.nat.read;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
import io.fd.honeycomb.nat.util.MappingEntryContext;
-import io.fd.honeycomb.translate.impl.read.GenericListReader;
+import io.fd.honeycomb.translate.impl.read.GenericInitListReader;
import io.fd.honeycomb.translate.read.ReaderFactory;
import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
@@ -71,15 +71,15 @@ public class NatReaderFactory implements ReaderFactory {
public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) {
registry.addStructuralReader(NAT_OPER_ID, NatStateBuilder.class);
registry.addStructuralReader(NAT_INSTANCES_ID, NatInstancesBuilder.class);
- registry.add(new GenericListReader<>(NAT_INSTANCE_ID, new NatInstanceCustomizer(mapEntryDumpMgr)));
+ registry.add(new GenericInitListReader<>(NAT_INSTANCE_ID, new NatInstanceCustomizer(mapEntryDumpMgr)));
registry.addStructuralReader(MAP_TABLE_ID, MappingTableBuilder.class);
registry.subtreeAdd(Sets.newHashSet(InstanceIdentifier.create(MappingEntry.class).child(ExternalSrcPort.class),
InstanceIdentifier.create(MappingEntry.class).child(InternalSrcPort.class)),
- new GenericListReader<>(MAP_ENTRY_ID,
+ new GenericInitListReader<>(MAP_ENTRY_ID,
new MappingEntryCustomizer(mapEntryDumpMgr, mappingEntryContext)));
registry.addStructuralReader(CURRENT_CONFIG, NatCurrentConfigBuilder.class);
- registry.add(new GenericListReader<>(CURRENT_CONFIG.child(ExternalIpAddressPool.class),
+ registry.add(new GenericInitListReader<>(CURRENT_CONFIG.child(ExternalIpAddressPool.class),
new ExternalIpPoolCustomizer(addressRangeDumpMgr)));
}
}