summaryrefslogtreecommitdiffstats
path: root/acl
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2017-07-24 14:59:24 +0200
committerMarek Gradzki <mgradzki@cisco.com>2017-07-25 20:32:24 +0200
commit054635ec17ddbd20b00021e76b535405cc069cc0 (patch)
treeedbd0395e626b0568c3e71537941087713b1f08c /acl
parent7d9c4dc654adb6ce7dd7fe350abc09c7e434d0c1 (diff)
HC2VPP-173: set empty acl list when deleting ifc assignment
Change-Id: I95e4675723bbb52c0244b68a731e3ec0f5831ce4 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'acl')
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequest.java19
-rw-r--r--acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java2
-rw-r--r--acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequestTest.java50
-rw-r--r--acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizerTest.java15
4 files changed, 63 insertions, 23 deletions
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequest.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequest.java
index 4447b7534..bf1f1497e 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequest.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequest.java
@@ -19,6 +19,7 @@ package io.fd.hc2vpp.acl.util.iface.acl;
import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.collect.ImmutableList;
import io.fd.hc2vpp.acl.util.AclContextManager;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
@@ -27,6 +28,7 @@ import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.acl.dto.AclInterfaceSetAclList;
import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade;
+import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
@@ -45,8 +47,8 @@ public class AclInterfaceAssignmentRequest implements JvppReplyConsumer, ByteDat
private final MappingContext mappingContext;
private InstanceIdentifier<Acl> identifier;
- private List<String> inputAclNames;
- private List<String> outputAclNames;
+ private List<String> inputAclNames = Collections.emptyList();
+ private List<String> outputAclNames = Collections.emptyList();
private AclContextManager standardAclContext;
private NamingContext interfaceContext;
@@ -66,12 +68,14 @@ public class AclInterfaceAssignmentRequest implements JvppReplyConsumer, ByteDat
}
public AclInterfaceAssignmentRequest inputAclNames(@Nonnull final List<String> inputAclNames) {
- this.inputAclNames = inputAclNames;
+ checkNotNull(inputAclNames, "Input ACL names cannot be null");
+ this.inputAclNames = ImmutableList.copyOf(inputAclNames);
return this;
}
public AclInterfaceAssignmentRequest outputAclNames(@Nonnull final List<String> outputAclNames) {
- this.outputAclNames = outputAclNames;
+ checkNotNull(outputAclNames, "Output ACL names cannot be null");
+ this.outputAclNames = ImmutableList.copyOf(outputAclNames);
return this;
}
@@ -87,8 +91,6 @@ public class AclInterfaceAssignmentRequest implements JvppReplyConsumer, ByteDat
private void checkValidRequest() {
checkNotNull(identifier, "Identifier cannot be null");
- checkNotNull(inputAclNames, "Input ACL names cannot be null");
- checkNotNull(outputAclNames, "Output ACL names cannot be null");
checkNotNull(standardAclContext, "ACL context cannot be null");
checkNotNull(interfaceContext, "Interface context cannot be null");
}
@@ -140,6 +142,10 @@ public class AclInterfaceAssignmentRequest implements JvppReplyConsumer, ByteDat
"Executing acl interface assignment delete request for interface={}, input ACL's={},output ACL's={}",
interfaceName, inputAclNames, outputAclNames);
+ // remove all ACLs, just in case they were set by AclInterfaceAssignmentRequest user
+ inputAclNames = Collections.emptyList();
+ outputAclNames = Collections.emptyList();
+
getReplyForDelete(api.aclInterfaceSetAclList(createRequest(interfaceName)).toCompletableFuture(),
identifier);
LOG.debug(
@@ -153,6 +159,7 @@ public class AclInterfaceAssignmentRequest implements JvppReplyConsumer, ByteDat
AclInterfaceSetAclList request = new AclInterfaceSetAclList();
request.swIfIndex = interfaceContext.getIndex(interfaceName, mappingContext);
+ // FIXME (HC2VPP-201): possible overflow
request.nInput = (byte) inputAclNames.size();
request.count = (byte) (inputAclNames.size() + outputAclNames.size());
request.acls = Stream.concat(inputAclNames.stream(), outputAclNames.stream())
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java
index 43360c629..a6ca35af3 100644
--- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java
+++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java
@@ -82,8 +82,6 @@ public class InterfaceAclCustomizer extends FutureJVppAclCustomizer implements W
.standardAclContext(standardAclContext)
.interfaceContext(interfaceContext)
.identifier(id)
- .inputAclNames(getAclNames(dataBefore.getIngress()))
- .outputAclNames(getAclNames(dataBefore.getEgress()))
.executeAsDelete(getjVppAclFacade());
}
diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequestTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequestTest.java
index 3eb1a6267..3427dc7fd 100644
--- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequestTest.java
+++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequestTest.java
@@ -23,7 +23,6 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
@@ -39,7 +38,6 @@ import io.fd.vpp.jvpp.acl.dto.AclInterfaceSetAclList;
import io.fd.vpp.jvpp.acl.dto.AclInterfaceSetAclListReply;
import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade;
import java.util.Arrays;
-import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -113,15 +111,6 @@ public class AclInterfaceAssignmentRequestTest implements NamingContextHelper, F
verifyVariant(create(mappingContext).identifier(validIdentifier));
verifyVariant(create(mappingContext).identifier(validIdentifier).interfaceContext(interfaceContext));
-
- verifyVariant(create(mappingContext).identifier(validIdentifier).interfaceContext(interfaceContext)
- .standardAclContext(aclContext));
-
- verifyVariant(create(mappingContext).identifier(validIdentifier).interfaceContext(interfaceContext)
- .standardAclContext(aclContext).inputAclNames(Collections.emptyList()));
-
- verifyVariant(create(mappingContext).identifier(validIdentifier).interfaceContext(interfaceContext)
- .standardAclContext(aclContext).outputAclNames(Collections.emptyList()));
}
private void verifyVariant(final AclInterfaceAssignmentRequest request) throws WriteFailedException {
@@ -132,13 +121,46 @@ public class AclInterfaceAssignmentRequestTest implements NamingContextHelper, F
@Test
public void executeAsCreate() throws Exception {
-
createValidRequest().executeAsCreate(api);
+
+ verify(api).aclInterfaceSetAclList(requestCaptor.capture());
+ verifyValidRequest(requestCaptor.getValue());
+ }
+
+ @Test
+ public void executeAsUpdate() throws Exception {
createValidRequest().executeAsUpdate(api, mock(Acl.class), mock(Acl.class));
+
+ verify(api).aclInterfaceSetAclList(requestCaptor.capture());
+ verifyValidRequest(requestCaptor.getValue());
+ }
+
+ @Test
+ public void executeAsDelete() throws Exception {
+ create(mappingContext)
+ .identifier(validIdentifier)
+ .standardAclContext(aclContext)
+ .interfaceContext(interfaceContext)
+ .executeAsDelete(api);
+
+ verify(api).aclInterfaceSetAclList(requestCaptor.capture());
+ final AclInterfaceSetAclList request = requestCaptor.getValue();
+ assertNotNull(request);
+ assertEquals(0, request.count);
+ assertEquals(0, request.nInput);
+ assertTrue(Arrays.equals(new int[] {}, request.acls));
+ }
+
+ @Test
+ public void executeAsDeleteWithAclNames() throws Exception {
createValidRequest().executeAsDelete(api);
- verify(api, times(3)).aclInterfaceSetAclList(requestCaptor.capture());
- requestCaptor.getAllValues().forEach(AclInterfaceAssignmentRequestTest::verifyValidRequest);
+ verify(api).aclInterfaceSetAclList(requestCaptor.capture());
+ final AclInterfaceSetAclList request = requestCaptor.getValue();
+ assertNotNull(request);
+ assertEquals(0, request.count);
+ assertEquals(0, request.nInput);
+ assertTrue(Arrays.equals(new int[]{}, request.acls));
}
private AclInterfaceAssignmentRequest createValidRequest() {
diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizerTest.java
index 465351c40..5dc139acc 100644
--- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizerTest.java
+++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizerTest.java
@@ -17,6 +17,7 @@
package io.fd.hc2vpp.acl.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;
@@ -27,6 +28,7 @@ import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.vpp.jvpp.acl.dto.AclInterfaceSetAclList;
import io.fd.vpp.jvpp.acl.dto.AclInterfaceSetAclListReply;
import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade;
+import java.util.Collections;
import org.junit.Test;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
@@ -35,6 +37,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.IngressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAcls;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAclsBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public class InterfaceAclCustomizerTest extends WriterCustomizerTest implements AclTestSchemaContext {
@@ -83,7 +88,15 @@ public class InterfaceAclCustomizerTest extends WriterCustomizerTest implements
@Test
public void testDelete() throws Exception {
- final Acl acl = new AclBuilder().build();
+ final VppAcls
+ element = mock(VppAcls.class);
+ final Acl acl = new AclBuilder()
+ .setIngress(new IngressBuilder()
+ .setVppAcls(Collections.singletonList(new VppAclsBuilder()
+ .setName("asd")
+ .build()))
+ .build())
+ .build();
customizer.deleteCurrentAttributes(ACL_ID, acl, writeContext);
final AclInterfaceSetAclList list = new AclInterfaceSetAclList();
list.swIfIndex = IFACE_ID;