From f8273e10b19ecc82bdda81feef9982ce28d5de21 Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Fri, 16 Dec 2016 13:07:56 +0100 Subject: HONEYCOMB-310: translation layer for acl plugin Not covered by this patch (moved to subsequent commits): - postman collection - distinguish ingress/egress ACLs while reading assigned acls - proper support for acl tag - unit tests improvements - read for acls (not necessarily assigned) - initializers Change-Id: I5a198ce1a6e20d0b1d95b4d2d83d0464fb86580c Signed-off-by: Jan Srnicek Signed-off-by: Marek Gradzki --- .../test/java/io/fd/hc2vpp/acl/AclModuleTest.java | 122 ++++++++ .../io/fd/hc2vpp/acl/AclTestSchemaContext.java | 46 +++ .../acl/AclInterfaceAssignmentRequestTest.java | 188 ++++++++++++ .../macip/MacIpInterfaceAssignmentRequestTest.java | 149 +++++++++ .../protocol/ProtoPreBindRuleProducerTest.java | 102 +++++++ .../acl/write/InterfaceAclCustomizerTest.java | 50 +++ .../fd/hc2vpp/acl/write/VppAclCustomizerTest.java | 340 +++++++++++++++++++++ 7 files changed, 997 insertions(+) create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/AclModuleTest.java create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/AclTestSchemaContext.java create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequestTest.java create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/macip/MacIpInterfaceAssignmentRequestTest.java create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/protocol/ProtoPreBindRuleProducerTest.java create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizerTest.java create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java (limited to 'acl/acl-impl/src/test/java') diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/AclModuleTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/AclModuleTest.java new file mode 100644 index 000000000..671cd283c --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/AclModuleTest.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.acl; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.empty; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.name.Named; +import com.google.inject.testing.fieldbinder.Bind; +import com.google.inject.testing.fieldbinder.BoundFieldModule; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; +import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.vpp.jvpp.JVppRegistry; +import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import java.util.HashSet; +import java.util.Set; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesStateBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + + +public class AclModuleTest { + + @Named("honeycomb-context") + @Bind + @Mock + private DataBroker honeycombContext; + + @Named("honeycomb-initializer") + @Bind + @Mock + private DataBroker honeycombInitializer; + + @Named("interface-context") + @Bind + private NamingContext interfaceContext = new NamingContext("iface", "interface-context"); + + @Bind + @Mock + private JVppRegistry registry; + + @Inject + private Set writerFactories = new HashSet<>(); + + @Inject + private Set readerFactories = new HashSet<>(); + + @Before + public void setUp() throws Exception { + initMocks(this); + // AclModule adds readers under InterfacesState + // because readers for parents need to be present (are part of V3poModule) + // add structural readers here (better than maven dependency). + + Guice.createInjector(binder -> Multibinder.newSetBinder(binder, ReaderFactory.class) + .addBinding().toInstance(registry -> { + registry.addStructuralReader(InstanceIdentifier.create(InterfacesState.class), + InterfacesStateBuilder.class); + registry.addStructuralReader(InstanceIdentifier.create(InterfacesState.class).child(Interface.class), + InterfaceBuilder.class); + }), new AclModule(MockJVppAclProvider.class), BoundFieldModule.of(this)).injectMembers(this); + } + + @Test + public void testWriterFactories() throws Exception { + assertThat(writerFactories, is(not(empty()))); + + final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder(); + writerFactories.forEach(factory -> factory.init(registryBuilder)); + assertNotNull(registryBuilder.build()); + } + + @Test + public void testReaderFactories() throws Exception { + assertThat(readerFactories, is(not(empty()))); + + final CompositeReaderRegistryBuilder registryBuilder = new CompositeReaderRegistryBuilder(); + readerFactories.forEach(factory -> factory.init(registryBuilder)); + assertNotNull(registryBuilder.build()); + } + + private static final class MockJVppAclProvider implements Provider { + + @Override + public FutureJVppAclFacade get() { + return mock(FutureJVppAclFacade.class); + } + } +} + diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/AclTestSchemaContext.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/AclTestSchemaContext.java new file mode 100644 index 000000000..dd3c1caa9 --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/AclTestSchemaContext.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.acl; + +import com.google.common.collect.ImmutableSet; +import io.fd.honeycomb.test.tools.annotations.SchemaContextProvider; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; + + +public interface AclTestSchemaContext { + + @SchemaContextProvider + default ModuleInfoBackedContext context() { + ModuleInfoBackedContext context = ModuleInfoBackedContext.create(); + context.addModuleInfos(ImmutableSet + .of(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.$YangModuleInfoImpl + .getInstance(), + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.$YangModuleInfoImpl + .getInstance(), + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.$YangModuleInfoImpl + .getInstance(), + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.$YangModuleInfoImpl + .getInstance(), + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.$YangModuleInfoImpl + .getInstance(), + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.$YangModuleInfoImpl + .getInstance(), + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.$YangModuleInfoImpl + .getInstance())); + return context; + } +} 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 new file mode 100644 index 000000000..2224d11b0 --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequestTest.java @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.acl.util.iface.acl; + +import static io.fd.hc2vpp.acl.util.iface.acl.AclInterfaceAssignmentRequest.create; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +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; + +import com.google.common.collect.ImmutableList; +import io.fd.hc2vpp.common.test.util.FutureProducer; +import io.fd.hc2vpp.common.test.util.NamingContextHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +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.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; +import org.mockito.Captor; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; +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.yangtools.yang.binding.InstanceIdentifier; + +public class AclInterfaceAssignmentRequestTest implements NamingContextHelper, FutureProducer { + + private static final String INTERFACE_NAME = "iface"; + private static final int INTERFACE_INDEX = 4; + + private static final String ACL_NAME_1 = "acl-1"; + private static final String ACL_NAME_2 = "acl-2"; + private static final String ACL_NAME_3 = "acl-3"; + private static final String ACL_NAME_4 = "acl-4"; + private static final String ACL_NAME_5 = "acl-5"; + + private static final int ACL_INDEX_1 = 2; + private static final int ACL_INDEX_2 = 7; + private static final int ACL_INDEX_3 = 4; + private static final int ACL_INDEX_4 = 5; + private static final int ACL_INDEX_5 = 1; + + @Captor + private ArgumentCaptor requestCaptor; + + @Mock + private FutureJVppAclFacade api; + + @Mock + private MappingContext mappingContext; + + private InstanceIdentifier validIdentifier; + private NamingContext interfaceContext; + private NamingContext aclContext; + + @Before + public void setUp() { + initMocks(this); + + validIdentifier = InstanceIdentifier.create(Interfaces.class). + child(Interface.class, new InterfaceKey(INTERFACE_NAME)) + .augmentation(VppAclInterfaceAugmentation.class) + .child(Acl.class); + + interfaceContext = new NamingContext("iface", "interface-context"); + aclContext = new NamingContext("acl", "acl-context"); + + defineMapping(mappingContext, INTERFACE_NAME, INTERFACE_INDEX, "interface-context"); + + defineMapping(mappingContext, ACL_NAME_1, ACL_INDEX_1, "acl-context"); + defineMapping(mappingContext, ACL_NAME_2, ACL_INDEX_2, "acl-context"); + defineMapping(mappingContext, ACL_NAME_3, ACL_INDEX_3, "acl-context"); + defineMapping(mappingContext, ACL_NAME_4, ACL_INDEX_4, "acl-context"); + defineMapping(mappingContext, ACL_NAME_5, ACL_INDEX_5, "acl-context"); + + when(api.aclInterfaceSetAclList(any())).thenReturn(future(new AclInterfaceSetAclListReply())); + } + + @Test + public void verifyNegativeCases() throws WriteFailedException { + verifyVariant(create(mappingContext)); + + 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 { + verifyCreateFailsWithNullPointer(request); + verifyUpdateFailsWithNullPointer(request); + verifyDeleteFailsWithNullPointer(request); + } + + @Test + public void executeAsCreate() throws Exception { + + createValidRequest().executeAsCreate(api); + createValidRequest().executeAsUpdate(api, mock(Acl.class), mock(Acl.class)); + createValidRequest().executeAsDelete(api); + + verify(api, times(3)).aclInterfaceSetAclList(requestCaptor.capture()); + requestCaptor.getAllValues().forEach(AclInterfaceAssignmentRequestTest::verifyValidRequest); + } + + private AclInterfaceAssignmentRequest createValidRequest() { + return create(mappingContext) + .identifier(validIdentifier) + .inputAclNames(ImmutableList.of(ACL_NAME_1, ACL_NAME_2, ACL_NAME_3)) + .outputAclNames(ImmutableList.of(ACL_NAME_4, ACL_NAME_5)) + .standardAclContext(aclContext) + .interfaceContext(interfaceContext); + } + + private static void verifyValidRequest(final AclInterfaceSetAclList request) { + assertNotNull(request); + assertEquals(5, request.count); + assertEquals(3, request.nInput); + assertTrue(Arrays.equals(new int[]{ACL_INDEX_1, ACL_INDEX_2, ACL_INDEX_3, ACL_INDEX_4, ACL_INDEX_5}, + request.acls)); + } + + private void verifyCreateFailsWithNullPointer(final AclInterfaceAssignmentRequest request) + throws WriteFailedException { + try { + request.executeAsCreate(api); + } catch (NullPointerException e) { + return; + } + fail("Test should have thrown null pointer"); + } + + private void verifyUpdateFailsWithNullPointer(final AclInterfaceAssignmentRequest request) + throws WriteFailedException { + try { + request.executeAsUpdate(api, mock(Acl.class), mock(Acl.class)); + } catch (NullPointerException e) { + return; + } + fail("Test should have thrown null pointer"); + } + + private void verifyDeleteFailsWithNullPointer(final AclInterfaceAssignmentRequest request) + throws WriteFailedException { + try { + request.executeAsCreate(api); + } catch (NullPointerException e) { + return; + } + fail("Test should have thrown null pointer"); + } +} \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/macip/MacIpInterfaceAssignmentRequestTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/macip/MacIpInterfaceAssignmentRequestTest.java new file mode 100644 index 000000000..e81550390 --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/macip/MacIpInterfaceAssignmentRequestTest.java @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.acl.util.iface.macip; + +import static io.fd.hc2vpp.acl.util.iface.macip.MacIpInterfaceAssignmentRequest.addNew; +import static io.fd.hc2vpp.acl.util.iface.macip.MacIpInterfaceAssignmentRequest.deleteExisting; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.test.util.FutureProducer; +import io.fd.hc2vpp.common.test.util.NamingContextHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceAddDel; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceAddDelReply; +import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; +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.acl.Ingress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.macip.acls.base.attributes.VppMacipAcl; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Created by jsrnicek on 13.12.2016. + */ +public class MacIpInterfaceAssignmentRequestTest implements NamingContextHelper,FutureProducer { + + private static final String INTERFACE_NAME = "iface"; + private static final int INTERFACE_INDEX = 4; + private static final String ACL_NAME = "mac-ip-acl"; + private static final int ACL_INDEX = 5; + + @Captor + private ArgumentCaptor requestCaptor; + + @Mock + private FutureJVppAclFacade api; + + @Mock + private MappingContext mappingContext; + + private InstanceIdentifier validIdentifier; + private NamingContext interfaceContext; + private NamingContext macIpAclContext; + + @Before + public void setUp() throws Exception { + initMocks(this); + + validIdentifier = InstanceIdentifier.create(Interfaces.class). + child(Interface.class, new InterfaceKey(INTERFACE_NAME)) + .augmentation(VppAclInterfaceAugmentation.class) + .child(Acl.class) + .child(Ingress.class) + .child(VppMacipAcl.class); + + interfaceContext = new NamingContext("iface", "interface-context"); + macIpAclContext = new NamingContext("mac-ip-acl", "mac-ip-acl-context"); + + defineMapping(mappingContext, INTERFACE_NAME, INTERFACE_INDEX, "interface-context"); + defineMapping(mappingContext, ACL_NAME, ACL_INDEX, "mac-ip-acl-context"); + when(api.macipAclInterfaceAddDel(any())).thenReturn(future(new MacipAclInterfaceAddDelReply())); + } + + @Test + public void testAddNew() throws Exception { + addNew(mappingContext) + .aclName(ACL_NAME) + .identifier(validIdentifier) + .interfaceContext(interfaceContext) + .macIpAclContext(macIpAclContext) + .execute(api); + verify(api, times(1)).macipAclInterfaceAddDel(requestCaptor.capture()); + + final MacipAclInterfaceAddDel request = requestCaptor.getValue(); + + assertNotNull(request); + assertEquals(1, request.isAdd); + assertEquals(INTERFACE_INDEX, request.swIfIndex); + assertEquals(ACL_INDEX, request.aclIndex); + } + + @Test + public void testDeleteExisting() throws Exception { + deleteExisting(mappingContext) + .aclName(ACL_NAME) + .identifier(validIdentifier) + .interfaceContext(interfaceContext) + .macIpAclContext(macIpAclContext) + .execute(api); + verify(api, times(1)).macipAclInterfaceAddDel(requestCaptor.capture()); + + final MacipAclInterfaceAddDel request = requestCaptor.getValue(); + + assertNotNull(request); + assertEquals(0, request.isAdd); + assertEquals(INTERFACE_INDEX, request.swIfIndex); + assertEquals(ACL_INDEX, request.aclIndex); + } + + @Test + public void testInvalidCases() throws Exception { + verifyFailsWithNullPointer(addNew(mappingContext)); + verifyFailsWithNullPointer(addNew(mappingContext).aclName(ACL_NAME)); + verifyFailsWithNullPointer(addNew(mappingContext).aclName(ACL_NAME).interfaceContext(interfaceContext)); + verifyFailsWithNullPointer(addNew(mappingContext).aclName(ACL_NAME).interfaceContext(interfaceContext) + .macIpAclContext(macIpAclContext)); + verifyFailsWithNullPointer(addNew(mappingContext).aclName(ACL_NAME).interfaceContext(interfaceContext) + .identifier(validIdentifier)); + } + + private void verifyFailsWithNullPointer(final MacIpInterfaceAssignmentRequest request) throws WriteFailedException { + try { + request.execute(api); + } catch (NullPointerException e) { + return; + } + fail("Test should have thrown null pointer"); + } +} \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/protocol/ProtoPreBindRuleProducerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/protocol/ProtoPreBindRuleProducerTest.java new file mode 100644 index 000000000..8f4100349 --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/protocol/ProtoPreBindRuleProducerTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.acl.util.protocol; + +import static org.junit.Assert.assertEquals; + +import io.fd.hc2vpp.acl.AclTestSchemaContext; +import io.fd.honeycomb.test.tools.HoneycombTestRunner; +import io.fd.honeycomb.test.tools.annotations.InjectTestData; +import io.fd.vpp.jvpp.acl.types.AclRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessLists; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.VppAce; + +@RunWith(HoneycombTestRunner.class) +public class ProtoPreBindRuleProducerTest implements ProtoPreBindRuleProducer, AclTestSchemaContext { + + //TODO - remove after resolving how to address identity from different model in textual yang instance identifier + private VppAce extractAce(AccessLists accessLists) { + return VppAce.class + .cast(accessLists.getAcl().get(0).getAccessListEntries().getAce().get(0).getMatches().getAceType()); + } + + @Test + public void testIcmpRule(@InjectTestData(resourcePath = "/rules/icmp-rule.json") AccessLists acls) { + final AclRule icmpRule = createPreBindRule(extractAce(acls)); + + assertEquals(1, icmpRule.proto); + assertEquals(5, icmpRule.srcportOrIcmptypeFirst); + assertEquals(8, icmpRule.srcportOrIcmptypeLast); + assertEquals(1, icmpRule.dstportOrIcmpcodeFirst); + assertEquals(3, icmpRule.dstportOrIcmpcodeLast); + assertEquals(0, icmpRule.tcpFlagsMask); + assertEquals(0, icmpRule.tcpFlagsValue); + } + + + @Test + public void testIcmpv6Rule(@InjectTestData(resourcePath = "/rules/icmp-v6-rule.json") AccessLists acls) { + final AclRule icmpv6Rule = createPreBindRule(extractAce(acls)); + + assertEquals(58, icmpv6Rule.proto); + assertEquals(5, icmpv6Rule.srcportOrIcmptypeFirst); + assertEquals(8, icmpv6Rule.srcportOrIcmptypeLast); + assertEquals(1, icmpv6Rule.dstportOrIcmpcodeFirst); + assertEquals(3, icmpv6Rule.dstportOrIcmpcodeLast); + assertEquals(0, icmpv6Rule.tcpFlagsMask); + assertEquals(0, icmpv6Rule.tcpFlagsValue); + } + + @Test + public void testTcpRule(@InjectTestData(resourcePath = "/rules/tcp-rule.json") AccessLists acls) { + final AclRule tcpRule = createPreBindRule(extractAce(acls)); + assertEquals(6, tcpRule.proto); + assertEquals(1, tcpRule.srcportOrIcmptypeFirst); + assertEquals(5487, tcpRule.srcportOrIcmptypeLast); + assertEquals(87, tcpRule.dstportOrIcmpcodeFirst); + assertEquals(6745, tcpRule.dstportOrIcmpcodeLast); + assertEquals(1, tcpRule.tcpFlagsMask); + assertEquals(7, tcpRule.tcpFlagsValue); + } + + @Test + public void testUdpRule(@InjectTestData(resourcePath = "/rules/udp-rule.json") AccessLists acls) { + final AclRule udpRule = createPreBindRule(extractAce(acls)); + assertEquals(17, udpRule.proto); + assertEquals(1, udpRule.srcportOrIcmptypeFirst); + assertEquals(5487, udpRule.srcportOrIcmptypeLast); + assertEquals(87, udpRule.dstportOrIcmpcodeFirst); + assertEquals(6745, udpRule.dstportOrIcmpcodeLast); + assertEquals(0, udpRule.tcpFlagsMask); + assertEquals(0, udpRule.tcpFlagsValue); + } + + @Test + public void testOtherRule(@InjectTestData(resourcePath = "/rules/other-rule.json") AccessLists acls) { + final AclRule icmpRule = createPreBindRule(extractAce(acls)); + assertEquals(64, icmpRule.proto); + assertEquals(0, icmpRule.srcportOrIcmptypeFirst); + assertEquals((short) 65535, icmpRule.srcportOrIcmptypeLast); + assertEquals(0, icmpRule.dstportOrIcmpcodeFirst); + assertEquals((short) 65535, icmpRule.dstportOrIcmpcodeLast); + assertEquals(0, icmpRule.tcpFlagsMask); + assertEquals(0, icmpRule.tcpFlagsValue); + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..cd261970e --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizerTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.acl.write; + +import io.fd.hc2vpp.acl.AclTestSchemaContext; +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import org.junit.Test; +import org.mockito.Mock; + +public class InterfaceAclCustomizerTest extends WriterCustomizerTest implements AclTestSchemaContext { + + @Mock + private FutureJVppAclFacade aclApi; + + @Override + protected void setUpTest() throws Exception { + + } + + @Test + public void writeCurrentAttributes() throws Exception { + + } + + @Test + public void updateCurrentAttributes() throws Exception { + + } + + @Test + public void deleteCurrentAttributes() throws Exception { + + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..d076311c9 --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java @@ -0,0 +1,340 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.acl.write; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.acl.AclTestSchemaContext; +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.test.tools.HoneycombTestRunner; +import io.fd.honeycomb.test.tools.annotations.InjectTestData; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.acl.dto.AclAddReplace; +import io.fd.vpp.jvpp.acl.dto.AclAddReplaceReply; +import io.fd.vpp.jvpp.acl.dto.AclDel; +import io.fd.vpp.jvpp.acl.dto.AclDelReply; +import io.fd.vpp.jvpp.acl.dto.MacipAclAdd; +import io.fd.vpp.jvpp.acl.dto.MacipAclAddReply; +import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import io.fd.vpp.jvpp.acl.types.AclRule; +import io.fd.vpp.jvpp.acl.types.MacipAclRule; +import java.util.Arrays; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessLists; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppAcl; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +@RunWith(HoneycombTestRunner.class) +public class VppAclCustomizerTest extends WriterCustomizerTest implements AclTestSchemaContext { + + @Mock + private FutureJVppAclFacade aclApi; + + @Captor + private ArgumentCaptor aclAddReplaceRequestCaptor; + + @Captor + private ArgumentCaptor macipAclAddReplaceRequestCaptor; + + @Captor + private ArgumentCaptor aclDelRequestCaptor; + + private InstanceIdentifier validId; + private InstanceIdentifier validMacipId; + private VppAclCustomizer aclCustomizer; + private NamingContext standardAclContext; + private NamingContext macIpAclContext; + + + @Override + protected void setUpTest() throws Exception { + validId = + InstanceIdentifier.create(AccessLists.class).child(Acl.class, new AclKey("standard-acl", VppAcl.class)); + validMacipId = + InstanceIdentifier.create(AccessLists.class).child(Acl.class, new AclKey("macip-acl", VppAcl.class)); + standardAclContext = new NamingContext("acl", "acl-context"); + macIpAclContext = new NamingContext("macip", "macip-context"); + aclCustomizer = new VppAclCustomizer(aclApi, standardAclContext, macIpAclContext); + + when(aclApi.aclAddReplace(any())).thenReturn(future(new AclAddReplaceReply())); + when(aclApi.aclDel(any())).thenReturn(future(new AclDelReply())); + when(aclApi.macipAclAdd(any())).thenReturn(future(new MacipAclAddReply())); + } + + @Test + public void writeCurrentAttributesMacip(@InjectTestData(resourcePath = "/acl/macip/macip-acl.json") + AccessLists macipAcl) throws WriteFailedException { + + aclCustomizer.writeCurrentAttributes(validMacipId, macipAcl.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).macipAclAdd(macipAclAddReplaceRequestCaptor.capture()); + + final MacipAclAdd request = macipAclAddReplaceRequestCaptor.getValue(); + + assertEquals(1, request.count); + assertTrue(Arrays.equals("macip-acl".getBytes(), request.tag)); + + final MacipAclRule rule = request.r[0]; + + assertEquals(0, rule.isIpv6); + assertEquals(1, rule.isPermit); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, rule.srcIpAddr)); + assertEquals(32, rule.srcIpPrefixLen); + assertTrue(Arrays.equals(new byte[]{(byte)0xaa, (byte)0xaa, (byte)0xaa, (byte)0xaa, (byte)0xaa, (byte)0xaa}, rule.srcMac)); + assertTrue(Arrays.equals(new byte[]{(byte)0xff, 0, 0, 0, 0, 0}, rule.srcMacMask)); + } + + @Test + public void writeCurrentAttributesIcmpIpv4(@InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") + AccessLists standardAcls) throws Exception { + aclCustomizer.writeCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyIcmpIpv4Request(-1); + } + + @Test + public void updateCurrentAttributesIcmpIpv4(@InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") + AccessLists standardAcls) throws Exception { + defineMapping(mappingContext, "standard-acl", 4, "acl-context"); + final Acl data = standardAcls.getAcl().get(0); + + aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyIcmpIpv4Request(4); + } + + + @Test + public void writeCurrentAttributesIcmpIpv6(@InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp-v6.json") + AccessLists standardAcls) throws Exception { + aclCustomizer.writeCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyIcmpv6Request(-1); + } + + @Test + public void updateCurrentAttributesIcmpIpv6( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp-v6.json") + AccessLists standardAcls) throws Exception { + defineMapping(mappingContext, "standard-acl", 4, "acl-context"); + final Acl data = standardAcls.getAcl().get(0); + aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyIcmpv6Request(4); + } + + + @Test + public void writeCurrentAttributesTcp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp.json") + AccessLists standardAcls) throws Exception { + aclCustomizer.writeCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyTcpRequest(-1); + } + + @Test + public void updateCurrentAttributesTcp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp.json") + AccessLists standardAcls) throws Exception { + defineMapping(mappingContext, "standard-acl", 4, "acl-context"); + final Acl data = standardAcls.getAcl().get(0); + aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyTcpRequest(4); + } + + + @Test + public void writeCurrentAttributesUdp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") + AccessLists standardAcls) throws Exception { + aclCustomizer.writeCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + + verifyUdpRequest(-1); + } + + @Test + public void updateCurrentAttributesUdp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") + AccessLists standardAcls) throws Exception { + defineMapping(mappingContext, "standard-acl", 4, "acl-context"); + final Acl data = standardAcls.getAcl().get(0); + aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyUdpRequest(4); + } + + + @Test + public void deleteCurrentAttributesIcmpIpv4(@InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") + AccessLists standardAcls) throws Exception { + defineMapping(mappingContext, "standard-acl", 4, "acl-context"); + aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclDel(aclDelRequestCaptor.capture()); + assertEquals(4, aclDelRequestCaptor.getValue().aclIndex); + } + + @Test + public void deleteCurrentAttributesIcmpIpv6( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp-v6.json") + AccessLists standardAcls) throws Exception { + defineMapping(mappingContext, "standard-acl", 4, "acl-context"); + aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclDel(aclDelRequestCaptor.capture()); + assertEquals(4, aclDelRequestCaptor.getValue().aclIndex); + } + + @Test + public void deleteCurrentAttributesTcp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp.json") + AccessLists standardAcls) throws Exception { + defineMapping(mappingContext, "standard-acl", 4, "acl-context"); + aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclDel(aclDelRequestCaptor.capture()); + assertEquals(4, aclDelRequestCaptor.getValue().aclIndex); + } + + @Test + public void deleteCurrentAttributesUdp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") + AccessLists standardAcls) throws Exception { + defineMapping(mappingContext, "standard-acl", 4, "acl-context"); + aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclDel(aclDelRequestCaptor.capture()); + assertEquals(4, aclDelRequestCaptor.getValue().aclIndex); + } + + private void verifyUdpRequest(final int aclIndex) { + final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); + assertEquals(aclIndex, request.aclIndex); + assertEquals(1, request.count); + assertTrue(Arrays.equals("standard-acl".getBytes(), request.tag)); + + final AclRule udpRule = request.r[0]; + + assertEquals(0, udpRule.isIpv6); + assertEquals(1, udpRule.isPermit); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, udpRule.srcIpAddr)); + assertEquals(32, udpRule.srcIpPrefixLen); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 1}, udpRule.dstIpAddr)); + assertEquals(24, udpRule.dstIpPrefixLen); + + assertEquals(17, udpRule.proto); + assertEquals(1, udpRule.srcportOrIcmptypeFirst); + assertEquals(5487, udpRule.srcportOrIcmptypeLast); + assertEquals(87, udpRule.dstportOrIcmpcodeFirst); + assertEquals(6745, udpRule.dstportOrIcmpcodeLast); + assertEquals(0, udpRule.tcpFlagsMask); + assertEquals(0, udpRule.tcpFlagsValue); + } + + private void verifyTcpRequest(final int aclIndex) { + final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); + assertEquals(aclIndex, request.aclIndex); + assertEquals(1, request.count); + assertTrue(Arrays.equals("standard-acl".getBytes(), request.tag)); + + final AclRule tcpRule = request.r[0]; + + assertEquals(0, tcpRule.isIpv6); + assertEquals(1, tcpRule.isPermit); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, tcpRule.srcIpAddr)); + assertEquals(32, tcpRule.srcIpPrefixLen); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 1}, tcpRule.dstIpAddr)); + assertEquals(24, tcpRule.dstIpPrefixLen); + + assertEquals(6, tcpRule.proto); + assertEquals(1, tcpRule.srcportOrIcmptypeFirst); + assertEquals(5487, tcpRule.srcportOrIcmptypeLast); + assertEquals(87, tcpRule.dstportOrIcmpcodeFirst); + assertEquals(6745, tcpRule.dstportOrIcmpcodeLast); + assertEquals(1, tcpRule.tcpFlagsMask); + assertEquals(7, tcpRule.tcpFlagsValue); + } + + private void verifyIcmpv6Request(final int aclIndex) { + final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); + assertEquals(aclIndex, request.aclIndex); + assertEquals(1, request.count); + assertTrue(Arrays.equals("standard-acl".getBytes(), request.tag)); + + final AclRule icmpv6Rule = request.r[0]; + + assertEquals(1, icmpv6Rule.isIpv6); + assertEquals(1, icmpv6Rule.isPermit); + assertTrue( + Arrays.equals(new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 2}, + icmpv6Rule.srcIpAddr)); + assertEquals(48, icmpv6Rule.srcIpPrefixLen); + assertTrue( + Arrays.equals(new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}, + icmpv6Rule.dstIpAddr)); + assertEquals(64, icmpv6Rule.dstIpPrefixLen); + + assertEquals(58, icmpv6Rule.proto); + assertEquals(5, icmpv6Rule.srcportOrIcmptypeFirst); + assertEquals(8, icmpv6Rule.srcportOrIcmptypeLast); + assertEquals(1, icmpv6Rule.dstportOrIcmpcodeFirst); + assertEquals(3, icmpv6Rule.dstportOrIcmpcodeLast); + assertEquals(0, icmpv6Rule.tcpFlagsMask); + assertEquals(0, icmpv6Rule.tcpFlagsValue); + } + + private void verifyIcmpIpv4Request(final int aclIndex) { + final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); + assertEquals(aclIndex, request.aclIndex); + assertEquals(1, request.count); + assertTrue(Arrays.equals("standard-acl".getBytes(), request.tag)); + + final AclRule icmpRule = request.r[0]; + + assertEquals(0, icmpRule.isIpv6); + assertEquals(1, icmpRule.isPermit); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, icmpRule.srcIpAddr)); + assertEquals(32, icmpRule.srcIpPrefixLen); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 1}, icmpRule.dstIpAddr)); + assertEquals(24, icmpRule.dstIpPrefixLen); + + assertEquals(1, icmpRule.proto); + assertEquals(5, icmpRule.srcportOrIcmptypeFirst); + assertEquals(8, icmpRule.srcportOrIcmptypeLast); + assertEquals(1, icmpRule.dstportOrIcmpcodeFirst); + assertEquals(3, icmpRule.dstportOrIcmpcodeLast); + assertEquals(0, icmpRule.tcpFlagsMask); + assertEquals(0, icmpRule.tcpFlagsValue); + } +} \ No newline at end of file -- cgit 1.2.3-korg