From 2d92edf65ee34329d9226e2efe90a5d10265cd72 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Wed, 11 Jan 2017 10:11:20 +0100 Subject: Fix NPE in L3 rules Patch introduces proper handling for IP adresses, which are optional. Change-Id: Ib009207b4b241d3e2b8c665a35bb1ff87b4a12ac Signed-off-by: Marek Gradzki (cherry picked from commit e0b4359b39acfe8a583089117a0c2485b85ff7e4) --- .../fd/hc2vpp/acl/write/VppAclCustomizerTest.java | 19 ++++++++++- .../acl/standard/standard-acl-tcp-src-only.json | 37 ++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 acl/acl-impl/src/test/resources/acl/standard/standard-acl-tcp-src-only.json (limited to 'acl/acl-impl/src/test') diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java index bfdd17682..b4b4ef9ba 100644 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java @@ -168,7 +168,7 @@ public class VppAclCustomizerTest extends WriterCustomizerTest implements AclTes @Test public void updateCurrentAttributesTcp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp.json") - AccessLists standardAcls) throws Exception { + AccessLists standardAcls) throws Exception { final int aclIndex = 4; when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); final Acl data = standardAcls.getAcl().get(0); @@ -178,6 +178,23 @@ public class VppAclCustomizerTest extends WriterCustomizerTest implements AclTes verifyTcpRequest(aclIndex); } + @Test + public void updateCurrentAttributesTcpSrcOnly(@InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp-src-only.json") + AccessLists standardAcls) throws Exception { + final int aclIndex = 4; + when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); + final Acl data = standardAcls.getAcl().get(0); + aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); + final AclRule tcpRule = request.r[0]; + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, tcpRule.srcIpAddr)); + assertEquals(32, tcpRule.srcIpPrefixLen); + assertTrue(Arrays.equals(new byte[]{0, 0, 0, 0}, tcpRule.dstIpAddr)); + assertEquals(0, tcpRule.dstIpPrefixLen); + } + @Test public void writeCurrentAttributesUdp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") diff --git a/acl/acl-impl/src/test/resources/acl/standard/standard-acl-tcp-src-only.json b/acl/acl-impl/src/test/resources/acl/standard/standard-acl-tcp-src-only.json new file mode 100644 index 000000000..48e6f8807 --- /dev/null +++ b/acl/acl-impl/src/test/resources/acl/standard/standard-acl-tcp-src-only.json @@ -0,0 +1,37 @@ +{ + "access-lists": { + "acl": [ + { + "acl-name": "standard-acl", + "acl-type": "vpp-acl:vpp-acl", + "access-list-entries": { + "ace": [ + { + "rule-name": "tcp-rule", + "matches": { + "vpp-ace-nodes": { + "source-ipv4-network": "192.168.2.2/32", + "tcp-nodes": { + "source-port-range": { + "lower-port": "1", + "upper-port": "5487" + }, + "destination-port-range": { + "lower-port": "87", + "upper-port": "6745" + }, + "tcp-flags-mask": "1", + "tcp-flags-value": "7" + } + } + }, + "actions": { + "permit": {} + } + } + ] + } + } + ] + } +} \ No newline at end of file -- cgit 1.2.3-korg