summaryrefslogtreecommitdiffstats
path: root/nat/nat2vpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'nat/nat2vpp/src')
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java11
-rw-r--r--nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizerTest.java8
-rw-r--r--nat/nat2vpp/src/test/resources/nat/static-mapping-unsupported-proto.json12
-rw-r--r--nat/nat2vpp/src/test/resources/nat/static-mapping.json1
4 files changed, 30 insertions, 2 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 b2852fa4f..ecffe9ca9 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
@@ -19,10 +19,10 @@ package io.fd.hc2vpp.nat.write;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.base.Optional;
-import io.fd.hc2vpp.nat.util.MappingEntryContext;
-import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.hc2vpp.nat.util.MappingEntryContext;
+import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.snat.dto.SnatAddStaticMapping;
@@ -151,6 +151,13 @@ final class MappingEntryCustomizer implements ListWriterCustomizer<MappingEntry,
ipv4AddressNoZoneToArray(dataAfter.getInternalSrcAddress().getIpv4Address().getValue());
request.externalIpAddress = ipv4AddressNoZoneToArray(dataAfter.getExternalSrcAddress().getValue());
request.externalSwIfIndex = -1; // external ip address is ignored if externalSwIfIndex is given
+ request.protocol = -1;
+ final Short protocol = dataAfter.getTransportProtocol();
+ if (protocol != null) {
+ checkArgument(protocol == 1 || protocol == 6 || protocol == 17,
+ "Unsupported protocol %s only ICMP, TCP and UDP are currently supported", protocol);
+ request.protocol = protocol.byteValue();
+ }
Optional<Short> internalPortNumber = getPortNumber(id, dataAfter,
(entry) -> Optional.fromNullable(entry.getInternalSrcPort()).transform(PortNumber::getPortType));
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 2627cba4d..649284a44 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
@@ -76,6 +76,13 @@ public class MappingEntryCustomizerTest extends WriterCustomizerTest implements
verify(jvppSnat).snatAddStaticMapping(expectedRequest);
}
+ @Test(expected = IllegalArgumentException.class)
+ public void testWriteUnsupportedProtocol(
+ @InjectTestData(resourcePath = "/nat/static-mapping-unsupported-proto.json", id = MAPPING_TABLE_PATH) MappingTable data)
+ throws WriteFailedException {
+ customizer.writeCurrentAttributes(IID, extractMappingEntry(data), writeContext);
+ }
+
@Test(expected = WriteFailedException.UpdateFailedException.class)
public void testUpdate() throws WriteFailedException {
final MappingEntry data = mock(MappingEntry.class);
@@ -99,6 +106,7 @@ public class MappingEntryCustomizerTest extends WriterCustomizerTest implements
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, 87};
diff --git a/nat/nat2vpp/src/test/resources/nat/static-mapping-unsupported-proto.json b/nat/nat2vpp/src/test/resources/nat/static-mapping-unsupported-proto.json
new file mode 100644
index 000000000..455465d20
--- /dev/null
+++ b/nat/nat2vpp/src/test/resources/nat/static-mapping-unsupported-proto.json
@@ -0,0 +1,12 @@
+{
+ "mapping-table" : {
+ "mapping-entry": {
+ "index": 22,
+ "type": "static",
+ "transport-protocol": 123,
+ "internal-src-address": "192.168.1.87",
+ "external-src-address": "45.1.5.7"
+ }
+ }
+}
+
diff --git a/nat/nat2vpp/src/test/resources/nat/static-mapping.json b/nat/nat2vpp/src/test/resources/nat/static-mapping.json
index 293e5be2b..b1561a46b 100644
--- a/nat/nat2vpp/src/test/resources/nat/static-mapping.json
+++ b/nat/nat2vpp/src/test/resources/nat/static-mapping.json
@@ -3,6 +3,7 @@
"mapping-entry": {
"index": 22,
"type": "static",
+ "transport-protocol": 17,
"internal-src-address": "192.168.1.87",
"external-src-address": "45.1.5.7"
}