summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java8
-rw-r--r--nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizerTest.java87
2 files changed, 70 insertions, 25 deletions
diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java
index a3874482f..9075f4d0c 100644
--- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java
+++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java
@@ -124,12 +124,12 @@ final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator,
if (detail.addrOnly == 0) {
builder.setExternalSrcPort(new ExternalSrcPortBuilder()
.setPortType(new SinglePortNumberBuilder().setSinglePortNumber(new PortNumber(
- (int) detail.externalPort))
+ Short.toUnsignedInt(detail.externalPort)))
.build())
.build());
builder.setInternalSrcPort(new InternalSrcPortBuilder()
.setPortType(new SinglePortNumberBuilder().setSinglePortNumber(new PortNumber(
- (int) detail.localPort))
+ Short.toUnsignedInt(detail.localPort)))
.build())
.build());
}
@@ -151,12 +151,12 @@ final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator,
builder.setExternalSrcPort(new ExternalSrcPortBuilder()
.setPortType(new SinglePortNumberBuilder().setSinglePortNumber(new PortNumber(
- (int) detail.oPort))
+ Short.toUnsignedInt(detail.oPort)))
.build())
.build());
builder.setInternalSrcPort(new InternalSrcPortBuilder()
.setPortType(new SinglePortNumberBuilder().setSinglePortNumber(new PortNumber(
- (int) detail.iPort))
+ Short.toUnsignedInt(detail.iPort)))
.build())
.build());
}
diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizerTest.java
index 5402746ae..576324757 100644
--- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizerTest.java
+++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizerTest.java
@@ -93,22 +93,37 @@ public class MappingEntryCustomizerTest
public void testReadNat44() throws Exception {
final Nat44StaticMappingDetailsReplyDump dumpNat44 = dumpReplyNat44NonEmpty();
when(nat44DumpExecutor.executeDump(mappingEntryId, null)).thenReturn(dumpNat44);
+ stubFindDetailsNat44(dumpNat44, 2);
+
final MappingEntryBuilder builder = new MappingEntryBuilder();
- when(mappingContext
- .findDetailsNat44(dumpNat44.nat44StaticMappingDetails, NatInstanceCustomizer.DEFAULT_VRF_ID.getId(),
- NAT_MAPPING_ID, ctx.getMappingContext()))
- .thenReturn(Optional.of(dumpNat44.nat44StaticMappingDetails.get(2)));
getCustomizer().readCurrentAttributes(mappingEntryId, builder, ctx);
assertEquals(NAT_MAPPING_ID, builder.getIndex().longValue());
assertEquals("192.168.3.8", builder.getExternalSrcAddress().getValue());
assertEquals(6874,
- ((SinglePortNumber) builder.getExternalSrcPort().getPortType()).getSinglePortNumber().getValue()
- .intValue());
+ ((SinglePortNumber) builder.getExternalSrcPort().getPortType()).getSinglePortNumber().getValue()
+ .intValue());
assertArrayEquals("192.168.2.2".toCharArray(), builder.getInternalSrcAddress().getValue());
assertEquals(1274,
- ((SinglePortNumber) builder.getInternalSrcPort().getPortType()).getSinglePortNumber().getValue()
- .intValue());
+ ((SinglePortNumber) builder.getInternalSrcPort().getPortType()).getSinglePortNumber().getValue()
+ .intValue());
+ }
+
+ @Test
+ public void testReadNat44HighPorts() throws Exception {
+ final Nat44StaticMappingDetailsReplyDump dumpNat44 = dumpReplyNat44NonEmpty();
+ when(nat44DumpExecutor.executeDump(mappingEntryId, null)).thenReturn(dumpNat44);
+ stubFindDetailsNat44(dumpNat44, 1);
+
+ final MappingEntryBuilder builder = new MappingEntryBuilder();
+ getCustomizer().readCurrentAttributes(mappingEntryId, builder, ctx);
+
+ assertEquals(65535,
+ ((SinglePortNumber) builder.getExternalSrcPort().getPortType()).getSinglePortNumber().getValue()
+ .intValue());
+ assertEquals(60000,
+ ((SinglePortNumber) builder.getInternalSrcPort().getPortType()).getSinglePortNumber().getValue()
+ .intValue());
}
@Test
@@ -116,22 +131,38 @@ public class MappingEntryCustomizerTest
when(nat44DumpExecutor.executeDump(mappingEntryId, null)).thenReturn(new Nat44StaticMappingDetailsReplyDump());
final Nat64BibDetailsReplyDump dumpNat64 = dumpReplyNat64NonEmpty();
when(nat64DumpExecutor.executeDump(mappingEntryId, null)).thenReturn(dumpNat64);
+ stubFindDetailsNat64(dumpNat64, 2);
+
final MappingEntryBuilder builder = new MappingEntryBuilder();
- when(mappingContext
- .findDetailsNat64(dumpNat64.nat64BibDetails, NatInstanceCustomizer.DEFAULT_VRF_ID.getId(),
- NAT_MAPPING_ID, ctx.getMappingContext()))
- .thenReturn(Optional.of(dumpNat64.nat64BibDetails.get(2)));
getCustomizer().readCurrentAttributes(mappingEntryId, builder, ctx);
assertEquals(NAT_MAPPING_ID, builder.getIndex().longValue());
assertEquals("192.168.64.3", builder.getExternalSrcAddress().getValue());
assertEquals(6874,
- ((SinglePortNumber) builder.getExternalSrcPort().getPortType()).getSinglePortNumber().getValue()
- .intValue());
+ ((SinglePortNumber) builder.getExternalSrcPort().getPortType()).getSinglePortNumber().getValue()
+ .intValue());
assertArrayEquals("2001:db8:85a3::8a2e:370:7303".toCharArray(), builder.getInternalSrcAddress().getValue());
assertEquals(1274,
- ((SinglePortNumber) builder.getInternalSrcPort().getPortType()).getSinglePortNumber().getValue()
- .intValue());
+ ((SinglePortNumber) builder.getInternalSrcPort().getPortType()).getSinglePortNumber().getValue()
+ .intValue());
+ }
+
+ @Test
+ public void testReadNat64HighPorts() throws Exception {
+ when(nat44DumpExecutor.executeDump(mappingEntryId, null)).thenReturn(new Nat44StaticMappingDetailsReplyDump());
+ final Nat64BibDetailsReplyDump dumpNat64 = dumpReplyNat64NonEmpty();
+ when(nat64DumpExecutor.executeDump(mappingEntryId, null)).thenReturn(dumpNat64);
+ stubFindDetailsNat64(dumpNat64, 1);
+
+ final MappingEntryBuilder builder = new MappingEntryBuilder();
+ getCustomizer().readCurrentAttributes(mappingEntryId, builder, ctx);
+
+ assertEquals(65535,
+ ((SinglePortNumber) builder.getExternalSrcPort().getPortType()).getSinglePortNumber().getValue()
+ .intValue());
+ assertEquals(60000,
+ ((SinglePortNumber) builder.getInternalSrcPort().getPortType()).getSinglePortNumber().getValue()
+ .intValue());
}
@Test
@@ -209,11 +240,11 @@ public class MappingEntryCustomizerTest
detailsOne.vrfId = NatInstanceCustomizer.DEFAULT_VRF_ID.getId().byteValue();
Nat44StaticMappingDetails detailsTwo = new Nat44StaticMappingDetails();
- detailsTwo.addrOnly = 1;
+ detailsTwo.addrOnly = 0;
detailsTwo.localIpAddress = new byte[]{-64, -88, 2, 3};
- detailsTwo.localPort = 1235;
+ detailsTwo.localPort = (short) 60000;
detailsTwo.externalIpAddress = new byte[]{-64, -88, 2, 5};
- detailsTwo.externalPort = 5874;
+ detailsTwo.externalPort = (short) 65535;
detailsTwo.vrfId = 2;
Nat44StaticMappingDetails detailsThree = new Nat44StaticMappingDetails();
@@ -246,9 +277,9 @@ public class MappingEntryCustomizerTest
detailsTwo.iAddr =
new byte[]{0x20, 0x01, 0x0d, (byte) 0xb8, (byte) 0x85, (byte) 0xa3, 0, 0, 0, 0, (byte) 0x8a, 0x2e, 0x03,
0x70, 0x73, 0x02};
- detailsTwo.iPort = 1235;
+ detailsTwo.iPort = (short) 60000;
detailsTwo.oAddr = new byte[]{-64, -88, 64, 2};
- detailsTwo.oPort = 5874;
+ detailsTwo.oPort = (short) 65535;
detailsTwo.vrfId = 2;
Nat64BibDetails detailsThree = new Nat64BibDetails();
@@ -264,4 +295,18 @@ public class MappingEntryCustomizerTest
replyDump.nat64BibDetails = Arrays.asList(detailsOne, detailsTwo, detailsThree);
return replyDump;
}
+
+ private void stubFindDetailsNat44(final Nat44StaticMappingDetailsReplyDump dumpNat44, final int index) {
+ when(mappingContext
+ .findDetailsNat44(dumpNat44.nat44StaticMappingDetails, NatInstanceCustomizer.DEFAULT_VRF_ID.getId(),
+ NAT_MAPPING_ID, ctx.getMappingContext()))
+ .thenReturn(Optional.of(dumpNat44.nat44StaticMappingDetails.get(index)));
+ }
+
+ private void stubFindDetailsNat64(final Nat64BibDetailsReplyDump dumpNat64, final int index) {
+ when(mappingContext
+ .findDetailsNat64(dumpNat64.nat64BibDetails, NatInstanceCustomizer.DEFAULT_VRF_ID.getId(),
+ NAT_MAPPING_ID, ctx.getMappingContext()))
+ .thenReturn(Optional.of(dumpNat64.nat64BibDetails.get(index)));
+ }
} \ No newline at end of file