From 8e0c7007906730fe4547b0265a895ad8a322a7dc Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Thu, 10 Nov 2016 12:22:28 +0100 Subject: Remove hc2vpp codebase Moved to a dedicated hc2vpp project in fd.io Change-Id: I03dc3b3029f21b127a00c69a86bcd8e467896241 Signed-off-by: Maros Marsalek --- .../java/io/fd/honeycomb/nat/NatModuleTest.java | 123 ------------- .../ifc/InterfaceInboundNatCustomizerTest.java | 107 ----------- .../ifc/InterfaceOutboundNatCustomizerTest.java | 94 ---------- .../nat/util/MappingEntryContextTest.java | 198 --------------------- nat/nat2vpp/src/test/resources/nat.json | 3 - 5 files changed, 525 deletions(-) delete mode 100644 nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/NatModuleTest.java delete mode 100644 nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/read/ifc/InterfaceInboundNatCustomizerTest.java delete mode 100644 nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/read/ifc/InterfaceOutboundNatCustomizerTest.java delete mode 100644 nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/util/MappingEntryContextTest.java delete mode 100644 nat/nat2vpp/src/test/resources/nat.json (limited to 'nat/nat2vpp/src/test') diff --git a/nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/NatModuleTest.java b/nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/NatModuleTest.java deleted file mode 100644 index f69672e15..000000000 --- a/nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/NatModuleTest.java +++ /dev/null @@ -1,123 +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; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.MockitoAnnotations.initMocks; - -import com.google.inject.Guice; -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.google.inject.multibindings.Multibinder; -import com.google.inject.name.Named; -import com.google.inject.testing.fieldbinder.Bind; -import com.google.inject.testing.fieldbinder.BoundFieldModule; -import io.fd.honeycomb.translate.read.ReaderFactory; -import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; -import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder; -import io.fd.honeycomb.translate.vpp.util.NamingContext; -import io.fd.honeycomb.translate.write.WriterFactory; -import io.fd.vpp.jvpp.snat.future.FutureJVppSnatFacade; -import java.util.HashSet; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesStateBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class NatModuleTest { - - @Named("honeycomb-context") - @Bind - @Mock - private DataBroker honeycombContext; - - @Bind - private ReaderFactory ietfIfcReaderFactory; - - @Named("honeycomb-initializer") - @Bind - @Mock - private DataBroker honeycombInitializer; - - @Named("interface-context") - @Bind - private NamingContext ifcContext; - - @Inject - private Set readerFactories = new HashSet<>(); - - @Inject - private Set writerFactories = new HashSet<>(); - - @Before - public void setUp() throws Exception { - ietfIfcReaderFactory = registry -> { - registry.addStructuralReader(InstanceIdentifier.create(InterfacesState.class), InterfacesStateBuilder.class); - registry.addStructuralReader(InstanceIdentifier.create(InterfacesState.class).child(Interface.class), InterfaceBuilder.class); - }; - initMocks(this); - ifcContext = new NamingContext("interface-", "interface-context"); - // Nat Module adds readers under InterfacesState/Interface and since readers for parents that do nothing need to - // be present, add structural readers (or add V3poModule here, but adding the full Module is not the best solution) - Guice.createInjector(binder -> Multibinder.newSetBinder(binder, ReaderFactory.class) - .addBinding().toInstance(registry -> { - registry.addStructuralReader(InstanceIdentifier.create(InterfacesState.class), - InterfacesStateBuilder.class); - registry.addStructuralReader(InstanceIdentifier.create(InterfacesState.class).child(Interface.class), - InterfaceBuilder.class); - }), new NatModule(MockJVppSnatProvider.class), BoundFieldModule.of(this)).injectMembers(this); - } - - @Test - public void testReaderFactories() throws Exception { - assertThat(readerFactories, is(not(empty()))); - - // Test registration process (all dependencies present, topological order of readers does exist, etc.) - final CompositeReaderRegistryBuilder registryBuilder = new CompositeReaderRegistryBuilder(); - readerFactories.forEach(factory -> factory.init(registryBuilder)); - assertNotNull(registryBuilder.build()); - } - - @Test - public void testWriterFactories() throws Exception { - assertThat(writerFactories, is(not(empty()))); - - // Test registration process (all dependencies present, topological order of writers does exist, etc.) - final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder(); - writerFactories.forEach(factory -> factory.init(registryBuilder)); - assertNotNull(registryBuilder.build()); - } - - private static final class MockJVppSnatProvider implements Provider { - - @Override - public FutureJVppSnatFacade get() { - return mock(FutureJVppSnatFacade.class); - } - } -} \ No newline at end of file diff --git a/nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/read/ifc/InterfaceInboundNatCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/read/ifc/InterfaceInboundNatCustomizerTest.java deleted file mode 100644 index 3cef1880e..000000000 --- a/nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/read/ifc/InterfaceInboundNatCustomizerTest.java +++ /dev/null @@ -1,107 +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.read.ifc; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import com.google.common.collect.Lists; -import io.fd.honeycomb.translate.impl.read.GenericReader; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -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.NamingContext; -import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; -import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetails; -import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214.NatInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.Nat; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.NatBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.nat.Inbound; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.nat.InboundBuilder; -import org.opendaylight.yangtools.yang.binding.ChildOf; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceInboundNatCustomizerTest - extends ReaderCustomizerTest { - - private static final String IFC_NAME = "a"; - private static final int IFC_IDX = 0; - private static final String CTX_NAME = "ifc"; - - @Mock - private EntityDumpExecutor natExecutor; - private DumpCacheManager dumpMgr; - private NamingContext ifcContext = new NamingContext(CTX_NAME, CTX_NAME); - private InstanceIdentifier id; - - public InterfaceInboundNatCustomizerTest() { - super(Inbound.class, NatBuilder.class); - } - - @Override - protected void setUp() throws Exception { - id = getId(Inbound.class); - defineMapping(mappingContext, IFC_NAME, IFC_IDX, CTX_NAME); - // empty dump - Mockito.doReturn(new SnatInterfaceDetailsReplyDump()).when(natExecutor).executeDump(id, null); - dumpMgr = new DumpCacheManager.DumpCacheManagerBuilder() - .withExecutor(natExecutor) - .build(); - } - - static > InstanceIdentifier getId(Class boundType) { - return InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFC_NAME)) - .augmentation(NatInterfaceStateAugmentation.class) - .child(Nat.class) - .child(boundType); - } - - @Test - public void testNoPresence() throws Exception { - assertFalse(getReader().read(id, ctx).isPresent()); - } - - private GenericReader getReader() { - return new GenericReader<>(RWUtils.makeIidWildcarded(id), customizer); - } - - @Test - public void testPresence() throws Exception { - final SnatInterfaceDetailsReplyDump details = new SnatInterfaceDetailsReplyDump(); - final SnatInterfaceDetails detail = new SnatInterfaceDetails(); - detail.isInside = 1; - detail.swIfIndex = IFC_IDX; - details.snatInterfaceDetails = Lists.newArrayList(detail); - Mockito.doReturn(details).when(natExecutor).executeDump(id, null); - - assertTrue(getReader().read(id, ctx).isPresent()); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new InterfaceInboundNatCustomizer(dumpMgr, ifcContext); - } -} \ No newline at end of file diff --git a/nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/read/ifc/InterfaceOutboundNatCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/read/ifc/InterfaceOutboundNatCustomizerTest.java deleted file mode 100644 index c33e040bb..000000000 --- a/nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/read/ifc/InterfaceOutboundNatCustomizerTest.java +++ /dev/null @@ -1,94 +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.read.ifc; - -import static io.fd.honeycomb.nat.read.ifc.InterfaceInboundNatCustomizerTest.getId; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import com.google.common.collect.Lists; -import io.fd.honeycomb.translate.impl.read.GenericReader; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -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.NamingContext; -import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; -import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetails; -import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.NatBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.nat.Outbound; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.nat.OutboundBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceOutboundNatCustomizerTest - extends ReaderCustomizerTest { - - private static final String IFC_NAME = "a"; - private static final int IFC_IDX = 0; - private static final String CTX_NAME = "ifc"; - - @Mock - private EntityDumpExecutor abc; - private DumpCacheManager dumpMgr; - private NamingContext ifcContext = new NamingContext(CTX_NAME, CTX_NAME); - private InstanceIdentifier id; - - public InterfaceOutboundNatCustomizerTest() { - super(Outbound.class, NatBuilder.class); - } - - @Override - protected void setUp() throws Exception { - id = getId(Outbound.class); - defineMapping(mappingContext, IFC_NAME, IFC_IDX, CTX_NAME); - // empty dump - Mockito.doReturn(new SnatInterfaceDetailsReplyDump()).when(abc).executeDump(id, null); - dumpMgr = new DumpCacheManager.DumpCacheManagerBuilder() - .withExecutor(abc) - .build(); - } - - @Test - public void testNoPresence() throws Exception { - assertFalse(getReader().read(id, ctx).isPresent()); - } - - private GenericReader getReader() { - return new GenericReader<>(RWUtils.makeIidWildcarded(id), customizer); - } - - @Test - public void testPresence() throws Exception { - final SnatInterfaceDetailsReplyDump details = new SnatInterfaceDetailsReplyDump(); - final SnatInterfaceDetails detail = new SnatInterfaceDetails(); - detail.isInside = 0; - detail.swIfIndex = IFC_IDX; - details.snatInterfaceDetails = Lists.newArrayList(detail); - Mockito.doReturn(details).when(abc).executeDump(id, null); - - assertTrue(getReader().read(id, ctx).isPresent()); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new InterfaceOutboundNatCustomizer(dumpMgr, ifcContext); - } -} \ No newline at end of file diff --git a/nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/util/MappingEntryContextTest.java b/nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/util/MappingEntryContextTest.java deleted file mode 100644 index fee8def89..000000000 --- a/nat/nat2vpp/src/test/java/io/fd/honeycomb/nat/util/MappingEntryContextTest.java +++ /dev/null @@ -1,198 +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.util; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import com.google.common.base.Optional; -import com.google.common.collect.Lists; -import io.fd.honeycomb.translate.MappingContext; -import io.fd.honeycomb.translate.vpp.util.Ipv4Translator; -import io.fd.vpp.jvpp.snat.dto.SnatStaticMappingDetails; -import java.util.Collections; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.mapping.entry.context.attributes.nat.mapping.entry.context.nat.instance.MappingTableBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry; -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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -@SuppressWarnings("unchecked") -public class MappingEntryContextTest implements Ipv4Translator { - - private MappingEntryContext ctx = new MappingEntryContext(); - @Mock - private MappingContext mappingCtx; - - @Before - public void setUp() throws Exception { - initMocks(this); - } - - @Test - public void testAdd() throws Exception { - when(mappingCtx.read(any(InstanceIdentifier.class))).thenReturn(Optional.absent()); - final long natId = 7; - final long entryId = 99; - final MappingEntry entry = getEntry(natId, "192.168.1.5", "17.14.4.6"); - - ctx.addEntry(natId, entryId, entry, mappingCtx); - - verify(mappingCtx).put(MappingEntryContext.getId(natId, MappingEntryContext.entryToKey(entry)), MappingEntryContext.toCtxMapEntry(entry, entryId)); - } - - @Test - public void testRemove() throws Exception { - final long natId = 0; - final MappingEntry entry = getEntry(natId, "192.168.1.5", "17.14.4.6"); - - ctx.removeEntry(natId, entry, mappingCtx); - - verify(mappingCtx).delete(MappingEntryContext.getId(natId, MappingEntryContext.entryToKey(entry))); - } - - @Test - public void testGetExistingIndex() throws Exception { - final long natId = 0; - final long entryId = 12; - final MappingEntry entry = getEntry(entryId, "192.168.1.5", "17.14.4.6"); - final SnatStaticMappingDetails details = getDetails(entryId, "192.168.1.5", "17.14.4.6"); - - when(mappingCtx.read(MappingEntryContext.getId(natId, MappingEntryContext.entryToKey(entry)))) - .thenReturn(Optional.of(MappingEntryContext.toCtxMapEntry(entry, entryId))); - - assertEquals(12, ctx.getStoredOrArtificialIndex(natId, details, mappingCtx)); - verify(mappingCtx).read(MappingEntryContext.getId(natId, MappingEntryContext.entryToKey(entry))); - } - - @Test - public void testFindDetails() throws Exception { - final long natId = 0; - final MappingEntry entry = getEntry(0, "192.168.1.5", "17.14.4.6"); - final SnatStaticMappingDetails details = getDetails(0, "192.168.1.5", "17.14.4.6"); - final MappingEntry entry2 = getEntry(1, "192.168.1.8", "17.14.4.10"); - final SnatStaticMappingDetails details2 = getDetails(1, "192.168.1.8", "17.14.4.10"); - - final List someDetails = Lists.newArrayList(details, details2); - - when(mappingCtx.read(MappingEntryContext.getTableId(natId))) - .thenReturn(Optional.of(new MappingTableBuilder() - .setMappingEntry(Lists.newArrayList( - MappingEntryContext.toCtxMapEntry(entry, 0), - MappingEntryContext.toCtxMapEntry(entry2, 1))) - .build())); - - assertSame(details, ctx.findDetails(someDetails, natId, 0, mappingCtx)); - } - - @Test(expected = IllegalStateException.class) - public void testFindDetailsNoMappingStored() throws Exception { - final long natId = 0; - final long entryId = 12; - final SnatStaticMappingDetails details = getDetails(entryId, "192.168.1.5", "17.14.4.6"); - final List someDetails = Lists.newArrayList(details); - when(mappingCtx.read(MappingEntryContext.getTableId(natId))).thenReturn(Optional.absent()); - - ctx.findDetails(someDetails, natId, entryId, mappingCtx); - } - - @Test(expected = IllegalStateException.class) - public void testFindDetailsNoMappingStored2() throws Exception { - final long natId = 0; - final long entryId = 12; - final SnatStaticMappingDetails details = getDetails(entryId, "192.168.1.5", "17.14.4.6"); - final List someDetails = Lists.newArrayList(details); - - when(mappingCtx.read(MappingEntryContext.getTableId(natId))) - .thenReturn(Optional.of(new MappingTableBuilder().setMappingEntry(Collections.emptyList()).build())); - - ctx.findDetails(someDetails, natId, entryId, mappingCtx); - } - - @Test - public void testGetArtificialIndex() throws Exception { - final long natId = 0; - final long entryId = 0; - final MappingEntry entry = getEntry(entryId, "192.168.1.5", "17.14.4.6"); - final long entryId2 = 55; - final MappingEntry entry2 = getEntry(entryId2, "192.168.1.6", "17.14.4.7"); - final long entryId3 = 18954; - final MappingEntry entry3 = getEntry(entryId3, "192.168.1.7", "17.14.4.8"); - final long entryId4 = 18955; - final MappingEntry entry4 = getEntry(entryId4, "192.168.1.8", "17.14.4.9"); - - final long newEntryId = 18956; - final MappingEntry newEntry = getEntry(newEntryId, "192.168.1.99", "17.14.4.99"); - final SnatStaticMappingDetails newDetails = getDetails(newEntryId, "192.168.1.99", "17.14.4.99"); - when(mappingCtx.read(MappingEntryContext.getId(natId, MappingEntryContext.entryToKey(newEntry)))) - .thenReturn(Optional.absent()); - - when(mappingCtx.read(MappingEntryContext.getTableId(natId))) - .thenReturn(Optional.of(new MappingTableBuilder() - .setMappingEntry(Lists.newArrayList( - MappingEntryContext.toCtxMapEntry(entry, entryId), - MappingEntryContext.toCtxMapEntry(entry3, entryId3), - MappingEntryContext.toCtxMapEntry(entry4, entryId4), - MappingEntryContext.toCtxMapEntry(entry2, entryId2))) - .build())); - - assertFalse(ctx.getStoredIndex(natId, newEntry, mappingCtx).isPresent()); - assertEquals(newEntryId, ctx.getStoredOrArtificialIndex(natId, newDetails, mappingCtx)); - } - - private SnatStaticMappingDetails getDetails(final long vrfId, final String localIp, final String externIp) { - final SnatStaticMappingDetails snatStaticMappingDetails = new SnatStaticMappingDetails(); - snatStaticMappingDetails.vrfId = (int) vrfId; - snatStaticMappingDetails.addrOnly = 1; - snatStaticMappingDetails.isIp4 = 1; - snatStaticMappingDetails.localIpAddress = ipv4AddressNoZoneToArray(localIp); - snatStaticMappingDetails.externalIpAddress = ipv4AddressNoZoneToArray(externIp); - return snatStaticMappingDetails; - } - - @Test(expected = IllegalArgumentException.class) - public void testAddExisting() throws Exception { - final long natId = 7; - final long entryId = 99; - final MappingEntry entry = getEntry(natId, "192.168.1.5", "17.14.4.6"); - final org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.mapping.entry.context.attributes.nat.mapping.entry.context.nat.instance.mapping.table.MappingEntry - data = MappingEntryContext.toCtxMapEntry(entry, entryId); - when(mappingCtx.read(any(InstanceIdentifier.class))).thenReturn(Optional.of(data)); - - ctx.addEntry(natId, entryId, entry, mappingCtx); - } - - private static MappingEntry getEntry(final long id, final String longernalIpv4, final String externalIpv4) { - return new MappingEntryBuilder() - .setKey(new MappingEntryKey(id)) - .setType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.MappingEntry.Type.Static) - .setInternalSrcAddress(new IpAddress(new Ipv4Address(longernalIpv4))) - .setExternalSrcAddress(new Ipv4Address(externalIpv4)) - .build(); - } -} \ No newline at end of file diff --git a/nat/nat2vpp/src/test/resources/nat.json b/nat/nat2vpp/src/test/resources/nat.json deleted file mode 100644 index c7d9afeb3..000000000 --- a/nat/nat2vpp/src/test/resources/nat.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "enabled": "true" -} \ No newline at end of file -- cgit 1.2.3-korg