diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2017-05-12 10:55:39 +0200 |
---|---|---|
committer | Jan Srnicek <jsrnicek@cisco.com> | 2017-05-16 05:18:35 +0000 |
commit | 0119f7e2e8f96c7f6ed6af07200e432c16b837d5 (patch) | |
tree | 93a390200accf6505982c4025df56f5064cc7149 /nat/nat2vpp | |
parent | 400acf46ddab06a23a703f7d5b67cc4f5deeafe4 (diff) |
HC2VPP-145: fix snat mapping update
Change-Id: I51e8a3e6d62b9c0dacf03d2148b813309fe0dfc4
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
(cherry picked from commit 923dac1cedec9ad7a215d128d54eb77fd85562ae)
Diffstat (limited to 'nat/nat2vpp')
3 files changed, 37 insertions, 7 deletions
diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java index ecffe9ca9..999b8118f 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java @@ -107,8 +107,8 @@ final class MappingEntryCustomizer implements ListWriterCustomizer<MappingEntry, @Nonnull final MappingEntry dataBefore, @Nonnull final MappingEntry dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { - throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, - new UnsupportedOperationException("Mapping entry update not supported")); + deleteCurrentAttributes(id, dataBefore, writeContext); + writeCurrentAttributes(id, dataAfter, writeContext); } @Override diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizerTest.java index 649284a44..1d5eff7f3 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizerTest.java @@ -17,7 +17,6 @@ package io.fd.hc2vpp.nat.write; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -83,10 +82,17 @@ public class MappingEntryCustomizerTest extends WriterCustomizerTest implements customizer.writeCurrentAttributes(IID, extractMappingEntry(data), writeContext); } - @Test(expected = WriteFailedException.UpdateFailedException.class) - public void testUpdate() throws WriteFailedException { - final MappingEntry data = mock(MappingEntry.class); - customizer.updateCurrentAttributes(IID, data, data, writeContext); + @Test + public void testUpdate( + @InjectTestData(resourcePath = "/nat/static-mapping.json", id = MAPPING_TABLE_PATH) MappingTable before, + @InjectTestData(resourcePath = "/nat/static-mapping-address-update.json", id = MAPPING_TABLE_PATH) MappingTable after) + throws WriteFailedException { + customizer.updateCurrentAttributes(IID, extractMappingEntry(before), extractMappingEntry(after), writeContext); + final SnatAddStaticMapping expectedDeleteRequest = getExpectedRequest(); + verify(jvppSnat).snatAddStaticMapping(expectedDeleteRequest); + final SnatAddStaticMapping expectedUpdateRequest = getExpectedUpdateRequest(); + expectedUpdateRequest.isAdd = 1; + verify(jvppSnat).snatAddStaticMapping(expectedUpdateRequest); } @Test @@ -113,4 +119,16 @@ public class MappingEntryCustomizerTest extends WriterCustomizerTest implements expectedRequest.externalIpAddress = new byte[] {45, 1, 5, 7}; return expectedRequest; } + + private static SnatAddStaticMapping getExpectedUpdateRequest() { + final SnatAddStaticMapping expectedRequest = new SnatAddStaticMapping(); + expectedRequest.isIp4 = 1; + expectedRequest.addrOnly = 1; + expectedRequest.protocol = 17; // udp + expectedRequest.vrfId = (int) NAT_INSTANCE_ID; + expectedRequest.externalSwIfIndex = -1; + expectedRequest.localIpAddress = new byte[] {(byte) 192, (byte) 168, 1, 86}; + expectedRequest.externalIpAddress = new byte[] {45, 1, 5, 6}; + return expectedRequest; + } }
\ No newline at end of file diff --git a/nat/nat2vpp/src/test/resources/nat/static-mapping-address-update.json b/nat/nat2vpp/src/test/resources/nat/static-mapping-address-update.json new file mode 100644 index 000000000..224a62a6b --- /dev/null +++ b/nat/nat2vpp/src/test/resources/nat/static-mapping-address-update.json @@ -0,0 +1,12 @@ +{ + "mapping-table" : { + "mapping-entry": { + "index": 22, + "type": "static", + "transport-protocol": 17, + "internal-src-address": "192.168.1.86", + "external-src-address": "45.1.5.6" + } + } +} + |