From 43485e2862128bc5fa1bee776babcda06d5510d8 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Fri, 30 Sep 2016 12:28:28 +0200 Subject: HONEYCOMB-234: update YANG model to support egress ACLs - marks existing ACL support as ingress - updates postman collection Change-Id: I7ae39cb6698d9aafbe932d57725f138194b52e70 Signed-off-by: Maros Marsalek Signed-off-by: Marek Gradzki --- .../v3po/interfaces/AclCustomizerTest.java | 36 +++-- .../interfaces/SubInterfaceAclCustomizerTest.java | 139 ----------------- .../v3po/interfaces/acl/AceEthWriterTest.java | 107 ------------- .../v3po/interfaces/acl/AceIp4WriterTest.java | 151 ------------------ .../v3po/interfaces/acl/AceIp6WriterTest.java | 173 --------------------- .../v3po/interfaces/acl/AceIpWriterTestUtils.java | 34 ---- .../v3po/interfaces/acl/AclWriterTest.java | 13 +- .../v3po/interfaces/acl/IetfAclCustomizerTest.java | 161 ------------------- .../acl/SubInterfaceIetfAclCustomizerTest.java | 150 ------------------ .../interfaces/acl/ingress/AceEthWriterTest.java | 107 +++++++++++++ .../interfaces/acl/ingress/AceIp4WriterTest.java | 150 ++++++++++++++++++ .../interfaces/acl/ingress/AceIp6WriterTest.java | 172 ++++++++++++++++++++ .../acl/ingress/AceIpWriterTestUtils.java | 34 ++++ .../acl/ingress/IetfAclCustomizerTest.java | 162 +++++++++++++++++++ .../acl/ingress/SubInterfaceAclCustomizerTest.java | 140 +++++++++++++++++ .../ingress/SubInterfaceIetfAclCustomizerTest.java | 152 ++++++++++++++++++ .../v3po/interfacesstate/AclCustomizerTest.java | 98 ------------ .../SubInterfaceAclCustomizerTest.java | 107 ------------- .../acl/ingress/AclCustomizerTest.java | 99 ++++++++++++ .../acl/ingress/SubInterfaceAclCustomizerTest.java | 108 +++++++++++++ 20 files changed, 1151 insertions(+), 1142 deletions(-) delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceAclCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceEthWriterTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp4WriterTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp6WriterTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIpWriterTestUtils.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/IetfAclCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/SubInterfaceIetfAclCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceEthWriterTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceIp4WriterTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceIp6WriterTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceIpWriterTestUtils.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/IetfAclCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/SubInterfaceAclCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/SubInterfaceIetfAclCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceAclCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/acl/ingress/AclCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/acl/ingress/SubInterfaceAclCustomizerTest.java (limited to 'v3po/v3po2vpp/src/test') diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java index 734893b5b..4b7489f8e 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java @@ -22,10 +22,14 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; -import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.translate.v3po.interfaces.acl.ingress.AclCustomizer; import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; +import io.fd.honeycomb.translate.vpp.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.VppBaseCallException; +import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; +import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply; 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,11 +39,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2Acl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2AclBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Acl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.AclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.acl.Ingress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.acl.IngressBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.VppBaseCallException; -import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; -import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply; public class AclCustomizerTest extends WriterCustomizerTest { @@ -62,13 +64,13 @@ public class AclCustomizerTest extends WriterCustomizerTest { classifyTableContext); } - private InstanceIdentifier getAclId(final String name) { + private InstanceIdentifier getAclId(final String name) { return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation( - VppInterfaceAugmentation.class).child(Acl.class); + VppInterfaceAugmentation.class).child(Acl.class).child(Ingress.class); } - private Acl generateAcl(final String tableName) { - final AclBuilder builder = new AclBuilder(); + private Ingress generateAcl(final String tableName) { + final IngressBuilder builder = new IngressBuilder(); final L2Acl l2Acl = new L2AclBuilder().setClassifyTable(tableName).build(); builder.setL2Acl(l2Acl); return builder.build(); @@ -96,8 +98,8 @@ public class AclCustomizerTest extends WriterCustomizerTest { @Test public void testCreate() throws Exception { - final Acl acl = generateAcl(ACL_TABLE_NAME); - final InstanceIdentifier id = getAclId(IF_NAME); + final Ingress acl = generateAcl(ACL_TABLE_NAME); + final InstanceIdentifier id = getAclId(IF_NAME); whenInputAclSetInterfaceThenSuccess(); @@ -108,8 +110,8 @@ public class AclCustomizerTest extends WriterCustomizerTest { @Test public void testCreateFailed() throws Exception { - final Acl acl = generateAcl(ACL_TABLE_NAME); - final InstanceIdentifier id = getAclId(IF_NAME); + final Ingress acl = generateAcl(ACL_TABLE_NAME); + final InstanceIdentifier id = getAclId(IF_NAME); whenInputAclSetInterfaceThenFailure(); @@ -125,8 +127,8 @@ public class AclCustomizerTest extends WriterCustomizerTest { @Test public void testDelete() throws Exception { - final Acl acl = generateAcl(ACL_TABLE_NAME); - final InstanceIdentifier id = getAclId(IF_NAME); + final Ingress acl = generateAcl(ACL_TABLE_NAME); + final InstanceIdentifier id = getAclId(IF_NAME); whenInputAclSetInterfaceThenSuccess(); @@ -137,8 +139,8 @@ public class AclCustomizerTest extends WriterCustomizerTest { @Test public void testDeleteFailed() throws Exception { - final Acl acl = generateAcl(ACL_TABLE_NAME); - final InstanceIdentifier id = getAclId(IF_NAME); + final Ingress acl = generateAcl(ACL_TABLE_NAME); + final InstanceIdentifier id = getAclId(IF_NAME); whenInputAclSetInterfaceThenFailure(); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceAclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceAclCustomizerTest.java deleted file mode 100644 index 0492e16c8..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceAclCustomizerTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * 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.honeycomb.translate.v3po.interfaces; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.honeycomb.translate.vpp.util.NamingContext; -import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; -import org.junit.Test; -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.v3po.rev150105.acl.base.attributes.Ip4Acl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4AclBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6Acl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6AclBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.AclBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; -import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply; - -public class SubInterfaceAclCustomizerTest extends WriterCustomizerTest { - private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; - private static final String IF_NAME = "local0"; - private static final int IF_INDEX = 1; - private static final String SUBIF_NAME = "local0.0"; - private static final int SUBIF_INDEX = 11; - private static final long SUBIF_ID = 0; - private static final String TABLE_NAME = "table0"; - private static final int TABLE_INDEX = 123; - - private static final InstanceIdentifier IID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation( - SubinterfaceAugmentation.class).child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(SUBIF_ID)).child(Acl.class); - - @Mock - private VppClassifierContextManager classifyTableContext; - - private SubInterfaceAclCustomizer customizer; - - @Override - protected void setUp() throws Exception { - customizer = new SubInterfaceAclCustomizer(api, new NamingContext("prefix", IFC_TEST_INSTANCE), - classifyTableContext); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); - defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE); - when(classifyTableContext.getTableIndex(TABLE_NAME, mappingContext)).thenReturn(TABLE_INDEX); - } - - @Test - public void testCreate() throws WriteFailedException { - when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply())); - customizer.writeCurrentAttributes(IID, ip4Acl(), writeContext); - verify(api).inputAclSetInterface(expectedIp4AclRequest()); - } - - @Test(expected = WriteFailedException.CreateFailedException.class) - public void testCreateFailed() throws WriteFailedException { - when(api.inputAclSetInterface(any())).thenReturn(failedFuture()); - customizer.writeCurrentAttributes(IID, ip4Acl(), writeContext); - } - - @Test(expected = UnsupportedOperationException.class) - public void testUpdate() throws WriteFailedException { - customizer.updateCurrentAttributes(IID, ip4Acl(), ip6Acl(), writeContext); - } - - @Test - public void testDelete() throws Exception { - when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply())); - customizer.deleteCurrentAttributes(IID, ip6Acl(), writeContext); - verify(api).inputAclSetInterface(expectedIp6AclRequest()); - } - - @Test(expected = WriteFailedException.DeleteFailedException.class) - public void testDeleteFailed() throws WriteFailedException { - when(api.inputAclSetInterface(any())).thenReturn(failedFuture()); - customizer.deleteCurrentAttributes(IID, ip4Acl(), writeContext); - } - - private Acl ip4Acl() { - final AclBuilder builder = new AclBuilder(); - final Ip4Acl acl = new Ip4AclBuilder().setClassifyTable(TABLE_NAME).build(); - builder.setIp4Acl(acl); - return builder.build(); - } - - private InputAclSetInterface expectedIp4AclRequest() { - final InputAclSetInterface request = new InputAclSetInterface(); - request.isAdd = 1; - request.l2TableIndex = -1; - request.ip4TableIndex = TABLE_INDEX; - request.ip6TableIndex = -1; - request.swIfIndex = SUBIF_INDEX; - return request; - } - - private Acl ip6Acl() { - final AclBuilder builder = new AclBuilder(); - final Ip6Acl acl = new Ip6AclBuilder().setClassifyTable(TABLE_NAME).build(); - builder.setIp6Acl(acl); - return builder.build(); - } - - private InputAclSetInterface expectedIp6AclRequest() { - final InputAclSetInterface request = new InputAclSetInterface(); - request.isAdd = 0; - request.l2TableIndex = -1; - request.ip4TableIndex = -1; - request.ip6TableIndex = TABLE_INDEX; - request.swIfIndex = SUBIF_INDEX; - return request; - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceEthWriterTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceEthWriterTest.java deleted file mode 100644 index c00f3b231..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceEthWriterTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.honeycomb.translate.v3po.interfaces.acl; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.mockito.MockitoAnnotations.initMocks; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.PacketHandling; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.DenyBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceEth; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceEthBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; -import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession; -import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable; -import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; - -public class AceEthWriterTest { - - @Mock - private FutureJVppCore jvpp; - private AceEthWriter writer; - private PacketHandling action; - private AceEth aceEth; - - @Before - public void setUp() throws Exception { - initMocks(this); - writer = new AceEthWriter(jvpp); - action = new DenyBuilder().setDeny(true).build(); - aceEth = new AceEthBuilder() - .setDestinationMacAddress(new MacAddress("11:22:33:44:55:66")) - .setDestinationMacAddressMask(new MacAddress("ff:ff:ff:ff:ff:ff")) - .setSourceMacAddress(new MacAddress("aa:bb:cc:dd:ee:ff")) - .setSourceMacAddressMask(new MacAddress("ff:ff:ff:00:00:00")) - .build(); - } - - @Test - public void testGetClassifyAddDelTableRequest() throws Exception { - final int nextTableIndex = 42; - final ClassifyAddDelTable request = writer.createClassifyTable(action, aceEth, nextTableIndex, 0); - - assertEquals(1, request.isAdd); - assertEquals(-1, request.tableIndex); - assertEquals(1, request.nbuckets); - assertEquals(-1, request.missNextIndex); - assertEquals(nextTableIndex, request.nextTableIndex); - assertEquals(0, request.skipNVectors); - assertEquals(AceEthWriter.MATCH_N_VECTORS, request.matchNVectors); - assertEquals(AceEthWriter.TABLE_MEM_SIZE, request.memorySize); - - byte[] expectedMask = new byte[] { - // destination MAC: - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - // source MAC: - (byte) 0xff, (byte) 0xff, (byte) 0xff, 0, 0, 0, - 0, 0, 0, 0 - }; - assertArrayEquals(expectedMask, request.mask); - } - - @Test - public void testGetClassifyAddDelSessionRequest() throws Exception { - final int tableIndex = 123; - final ClassifyAddDelSession request = writer.createClassifySession(action, aceEth, tableIndex, 0); - - assertEquals(1, request.isAdd); - assertEquals(tableIndex, request.tableIndex); - assertEquals(0, request.hitNextIndex); - - byte[] expectedMatch = new byte[] { - // destination MAC: - (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44, (byte) 0x55, (byte) 0x66, - // source MAC: - (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd, (byte) 0xee, (byte) 0xff, - 0, 0, 0, 0 - }; - assertArrayEquals(expectedMatch, request.match); - } - - @Test - public void testSetClassifyTable() throws Exception { - final int tableIndex = 321; - final InputAclSetInterface request = new InputAclSetInterface(); - writer.setClassifyTable(request, tableIndex); - assertEquals(tableIndex, request.l2TableIndex); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp4WriterTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp4WriterTest.java deleted file mode 100644 index 99a4b9f82..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp4WriterTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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.honeycomb.translate.v3po.interfaces.acl; - -import static io.fd.honeycomb.translate.v3po.interfaces.acl.AbstractAceWriter.VLAN_TAG_LEN; -import static io.fd.honeycomb.translate.v3po.interfaces.acl.AceIpWriterTestUtils.assertArrayEqualsWithOffset; -import static org.junit.Assert.assertEquals; -import static org.mockito.MockitoAnnotations.initMocks; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.PacketHandling; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.DenyBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIp; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; -import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession; -import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable; -import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; - -public class AceIp4WriterTest { - - @Mock - private FutureJVppCore jvpp; - private AceIp4Writer writer; - private PacketHandling action; - private AceIp aceIp; - - @Before - public void setUp() throws Exception { - initMocks(this); - writer = new AceIp4Writer(jvpp); - action = new DenyBuilder().setDeny(true).build(); - aceIp = new AceIpBuilder() - .setProtocol((short) 4) - .setDscp(new Dscp((short) 11)) - .setAceIpVersion(new AceIpv4Builder() - .setSourceIpv4Network(new Ipv4Prefix("1.2.3.4/32")) - .setDestinationIpv4Network(new Ipv4Prefix("1.2.4.5/24")) - .build()) - .build(); - } - - private static void verifyTableRequest(final ClassifyAddDelTable request, final int nextTableIndex, - final int vlanTags) { - assertEquals(1, request.isAdd); - assertEquals(-1, request.tableIndex); - assertEquals(1, request.nbuckets); - assertEquals(-1, request.missNextIndex); - assertEquals(nextTableIndex, request.nextTableIndex); - assertEquals(0, request.skipNVectors); - assertEquals(AceIp4Writer.MATCH_N_VECTORS, request.matchNVectors); - assertEquals(AceIp4Writer.TABLE_MEM_SIZE, request.memorySize); - - byte[] expectedMask = new byte[] { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0xf0, (byte) 0xfc, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, - -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - assertArrayEqualsWithOffset(expectedMask, request.mask, vlanTags * VLAN_TAG_LEN); - - } - - private static void verifySessionRequest(final ClassifyAddDelSession request, final int tableIndex, - final int vlanTags) { - assertEquals(1, request.isAdd); - assertEquals(tableIndex, request.tableIndex); - assertEquals(0, request.hitNextIndex); - - byte[] expectedMatch = new byte[] { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0x40, (byte) 0x2c, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 1, 2, - 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - assertArrayEqualsWithOffset(expectedMatch, request.match, vlanTags * VLAN_TAG_LEN); - - } - - @Test - public void testGetClassifyAddDelTableRequest() throws Exception { - final int nextTableIndex = 42; - final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, 0); - verifyTableRequest(request, nextTableIndex, 0); - } - - @Test - public void testGetClassifyAddDelTableRequest1VlanTag() throws Exception { - final int nextTableIndex = 42; - final int vlanTags = 1; - final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags); - verifyTableRequest(request, nextTableIndex, vlanTags); - } - - @Test - public void testGetClassifyAddDelTableRequest2VlanTags() throws Exception { - final int nextTableIndex = 42; - final int vlanTags = 2; - final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags); - verifyTableRequest(request, nextTableIndex, vlanTags); - } - - @Test - public void testGetClassifyAddDelSessionRequest() throws Exception { - final int tableIndex = 123; - final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, 0); - verifySessionRequest(request, tableIndex, 0); - } - - @Test - public void testGetClassifyAddDelSessionRequest1VlanTag() throws Exception { - final int tableIndex = 123; - final int vlanTags = 1; - final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags); - verifySessionRequest(request, tableIndex, vlanTags); - } - - @Test - public void testGetClassifyAddDelSessionRequest2VlanTags() throws Exception { - final int tableIndex = 123; - final int vlanTags = 2; - final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags); - - verifySessionRequest(request, tableIndex, vlanTags); - } - - @Test - public void testSetClassifyTable() throws Exception { - final int tableIndex = 321; - final InputAclSetInterface request = new InputAclSetInterface(); - writer.setClassifyTable(request, tableIndex); - assertEquals(tableIndex, request.ip4TableIndex); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp6WriterTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp6WriterTest.java deleted file mode 100644 index b5d3d471f..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp6WriterTest.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * 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.honeycomb.translate.v3po.interfaces.acl; - -import static io.fd.honeycomb.translate.v3po.interfaces.acl.AbstractAceWriter.VLAN_TAG_LEN; -import static io.fd.honeycomb.translate.v3po.interfaces.acl.AceIpWriterTestUtils.assertArrayEqualsWithOffset; -import static org.junit.Assert.assertEquals; -import static org.mockito.MockitoAnnotations.initMocks; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.PacketHandling; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.DenyBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIp; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv6Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; -import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession; -import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable; -import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; - -public class AceIp6WriterTest { - - @Mock - private FutureJVppCore jvpp; - private AceIp6Writer writer; - private PacketHandling action; - private AceIp aceIp; - - @Before - public void setUp() throws Exception { - initMocks(this); - writer = new AceIp6Writer(jvpp); - action = new DenyBuilder().setDeny(true).build(); - aceIp = new AceIpBuilder() - .setProtocol((short) 6) - .setDscp(new Dscp((short) 11)) - .setAceIpVersion(new AceIpv6Builder() - .setFlowLabel(new Ipv6FlowLabel(123L)) - .setSourceIpv6Network(new Ipv6Prefix("2001:db8:85a3:8d3:1319:8a2e:370:7348/128")) - .setDestinationIpv6Network(new Ipv6Prefix("fe80:1234:5678:abcd:ef01::/64")) - .build()) - .build(); - } - - - private static void verifyTableRequest(final ClassifyAddDelTable request, final int nextTableIndex, - final int vlanTags) { - assertEquals(1, request.isAdd); - assertEquals(-1, request.tableIndex); - assertEquals(1, request.nbuckets); - assertEquals(-1, request.missNextIndex); - assertEquals(nextTableIndex, request.nextTableIndex); - assertEquals(0, request.skipNVectors); - assertEquals(AceIp6Writer.MATCH_N_VECTORS, request.matchNVectors); - assertEquals(AceIp6Writer.TABLE_MEM_SIZE, request.memorySize); - - byte[] expectedMask = new byte[] { - // L2: - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - // version, dscp, flow: - (byte) 0xff, (byte) 0xcf, (byte) 0xff, (byte) 0xff, - 0, 0, 0, 0, - // source address: - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - // destination address: - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - 0, 0, 0, 0, 0, 0, 0, 0, - // padding to multiple of 16B: - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - assertArrayEqualsWithOffset(expectedMask, request.mask, vlanTags * VLAN_TAG_LEN); - - } - - private static void verifySessionRequest(final ClassifyAddDelSession request, final int tableIndex, - final int vlanTags) { - assertEquals(1, request.isAdd); - assertEquals(tableIndex, request.tableIndex); - assertEquals(0, request.hitNextIndex); - - byte[] expectedMatch = new byte[] { - // L2: - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - // version(6), dscp(11), flow(123): - (byte) 0x62, (byte) 0xc0, (byte) 0x00, (byte) 0x7b, - 0, 0, 0, 0, - // source address: - (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8, (byte) 0x85, (byte) 0xa3, (byte) 0x08, (byte) 0xd3, - (byte) 0x13, (byte) 0x19, (byte) 0x8a, (byte) 0x2e, (byte) 0x03, (byte) 0x70, (byte) 0x73, (byte) 0x48, - // destination address: - (byte) 0xfe, (byte) 0x80, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0xab, (byte) 0xcd, - 0, 0, 0, 0, 0, 0, 0, 0, - // padding to multiple of 16B: - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - assertArrayEqualsWithOffset(expectedMatch, request.match, vlanTags * VLAN_TAG_LEN); - - } - - @Test - public void testGetClassifyAddDelTableRequest() throws Exception { - final int nextTableIndex = 42; - final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, 0); - verifyTableRequest(request, nextTableIndex, 0); - } - - @Test - public void testGetClassifyAddDelTableRequest1VlanTag() throws Exception { - final int nextTableIndex = 42; - final int vlanTags = 1; - final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags); - verifyTableRequest(request, nextTableIndex, vlanTags); - } - - @Test - public void testGetClassifyAddDelTableRequest2VlanTag() throws Exception { - final int nextTableIndex = 42; - final int vlanTags = 2; - final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags); - verifyTableRequest(request, nextTableIndex, vlanTags); - } - - @Test - public void testGetClassifyAddDelSessionRequest() throws Exception { - final int tableIndex = 123; - final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, 0); - verifySessionRequest(request, tableIndex, 0); - } - - @Test - public void testGetClassifyAddDelSessionRequest1VlanTag() throws Exception { - final int tableIndex = 123; - final int vlanTags = 1; - final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags); - verifySessionRequest(request, tableIndex, vlanTags); - } - - @Test - public void testGetClassifyAddDelSessionRequest2VlanTag() throws Exception { - final int tableIndex = 123; - final int vlanTags = 2; - final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags); - verifySessionRequest(request, tableIndex, vlanTags); - } - - @Test - public void testSetClassifyTable() throws Exception { - final int tableIndex = 321; - final InputAclSetInterface request = new InputAclSetInterface(); - writer.setClassifyTable(request, tableIndex); - assertEquals(tableIndex, request.ip6TableIndex); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIpWriterTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIpWriterTestUtils.java deleted file mode 100644 index 6b176b67e..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIpWriterTestUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.honeycomb.translate.v3po.interfaces.acl; - -import static org.junit.Assert.assertArrayEquals; - -final class AceIpWriterTestUtils { - - private AceIpWriterTestUtils() { - throw new UnsupportedOperationException("This utility class cannot be instantiated"); - } - - protected static void assertArrayEqualsWithOffset(final byte[] baseExpected, final byte[] actual, - final int offset) { - byte[] expected = new byte[baseExpected.length]; - System.arraycopy(baseExpected, 0, expected, offset, expected.length - offset); - - assertArrayEquals(expected, actual); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AclWriterTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AclWriterTest.java index 98d645d4d..75059e4fd 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AclWriterTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AclWriterTest.java @@ -40,6 +40,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.AccessListsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.access.lists.AclBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.IetfAclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.ietf.acl.IngressBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class AclWriterTest extends WriterCustomizerTest { @@ -51,11 +52,11 @@ public class AclWriterTest extends WriterCustomizerTest { @Mock private Acl acl; - private AclWriter customizer; + private IetfAclWriter customizer; @Override public void setUp() { - customizer = new AclWriter(); + customizer = new IetfAclWriter(); when(acl.getAclName()).thenReturn(ACL_NAME); doReturn(ACL_TYPE).when(acl).getAclType(); } @@ -87,9 +88,11 @@ public class AclWriterTest extends WriterCustomizerTest { public void testDeleteFailed() throws WriteFailedException { final Interface iface = new InterfaceBuilder().addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder().setIetfAcl( - new IetfAclBuilder().setAccessLists( - new AccessListsBuilder().setAcl( - Collections.singletonList(new AclBuilder().setName(ACL_NAME).setType(ACL_TYPE).build()) + new IetfAclBuilder().setIngress( + new IngressBuilder().setAccessLists( + new AccessListsBuilder().setAcl( + Collections.singletonList(new AclBuilder().setName(ACL_NAME).setType(ACL_TYPE).build()) + ).build() ).build() ).build() ).build() diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/IetfAclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/IetfAclCustomizerTest.java deleted file mode 100644 index 6b981d2dc..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/IetfAclCustomizerTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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.honeycomb.translate.v3po.interfaces.acl; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.common.base.Optional; -import io.fd.honeycomb.translate.vpp.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; -import java.util.Collections; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AclBase; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.EthAcl; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.AccessListEntriesBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.AceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.ActionsBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.MatchesBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.DenyBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv6Builder; -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.v3po.rev150105.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.AccessListsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.access.lists.AclBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.IetfAcl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.IetfAclBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSessionReply; -import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable; -import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTableReply; -import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterface; -import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply; -import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; -import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply; - -public class IetfAclCustomizerTest extends WriterCustomizerTest { - - private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; - private static final String IF_NAME = "local0"; - private static final int IF_INDEX = 1; - private static final InstanceIdentifier IID = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation( - VppInterfaceAugmentation.class).child(IetfAcl.class); - private static final String ACL_NAME = "acl1"; - private static final Class ACL_TYPE = EthAcl.class; - - private IetfAclCustomizer customizer; - private IetfAcl acl; - - @Override - protected void setUp() { - customizer = new IetfAclCustomizer(new IetfAClWriter(api), new NamingContext("prefix", IFC_TEST_INSTANCE)); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); - acl = new IetfAclBuilder().setAccessLists( - new AccessListsBuilder().setAcl( - Collections.singletonList(new AclBuilder() - .setName(ACL_NAME) - .setType(ACL_TYPE) - .build()) - ).build() - ).build(); - } - - @Test - public void testWrite() throws WriteFailedException { - when(api.classifyAddDelTable(any())).thenReturn(future(new ClassifyAddDelTableReply())); - when(api.classifyAddDelSession(any())).thenReturn(future(new ClassifyAddDelSessionReply())); - - when(writeContext.readAfter(any())).thenReturn(Optional.of( - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclBuilder() - .setAccessListEntries( - new AccessListEntriesBuilder().setAce(Collections.singletonList( - new AceBuilder() - .setMatches(new MatchesBuilder().setAceType( - new AceIpBuilder() - .setAceIpVersion(new AceIpv6Builder().build()) - .setProtocol((short)1) - .build() - ).build()) - .setActions(new ActionsBuilder().setPacketHandling(new DenyBuilder().build()).build()) - .build() - )).build() - ).build() - - )); - when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply())); - - customizer.writeCurrentAttributes(IID, acl, writeContext); - - verify(api).classifyAddDelTable(any()); - verify(api).classifyAddDelSession(any()); - verify(api).inputAclSetInterface(inputAclSetInterfaceWriteRequest()); - } - - @Test - public void testDelete() throws WriteFailedException { - when(api.classifyTableByInterface(any())).thenReturn(future(classifyTableByInterfaceReply())); - when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply())); - when(api.classifyAddDelTable(any())).thenReturn(future(new ClassifyAddDelTableReply())); - - customizer.deleteCurrentAttributes(IID, acl, writeContext); - - final ClassifyTableByInterface expectedRequest = new ClassifyTableByInterface(); - expectedRequest.swIfIndex = IF_INDEX; - verify(api).classifyTableByInterface(expectedRequest); - verify(api).inputAclSetInterface(inputAclSetInterfaceDeleteRequest()); - verify(api).classifyAddDelTable(classifyAddDelTable(1)); - verify(api).classifyAddDelTable(classifyAddDelTable(2)); - verify(api).classifyAddDelTable(classifyAddDelTable(3)); - } - - private static InputAclSetInterface inputAclSetInterfaceDeleteRequest() { - final InputAclSetInterface request = new InputAclSetInterface(); - request.l2TableIndex = 1; - request.ip4TableIndex = 2; - request.ip6TableIndex = 3; - return request; - } - - private static ClassifyAddDelTable classifyAddDelTable(final int tableIndex) { - final ClassifyAddDelTable reply = new ClassifyAddDelTable(); - reply.tableIndex = tableIndex; - return reply; - } - - private static ClassifyTableByInterfaceReply classifyTableByInterfaceReply() { - final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply(); - reply.l2TableId = 1; - reply.ip4TableId = 2; - reply.ip6TableId = 3; - return reply; - } - - private static InputAclSetInterface inputAclSetInterfaceWriteRequest() { - final InputAclSetInterface request = new InputAclSetInterface(); - request.swIfIndex = IF_INDEX; - request.isAdd = 1; - request.l2TableIndex = -1; - request.ip4TableIndex = -1; - request.ip6TableIndex = 0; - return request; - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/SubInterfaceIetfAclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/SubInterfaceIetfAclCustomizerTest.java deleted file mode 100644 index 3033131a1..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/SubInterfaceIetfAclCustomizerTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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.honeycomb.translate.v3po.interfaces.acl; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.common.base.Optional; -import io.fd.honeycomb.translate.vpp.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; -import java.util.Collections; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AclBase; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.EthAcl; -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.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.AccessListEntriesBuilder; -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.v3po.rev150105.ietf.acl.base.attributes.AccessListsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.access.lists.AclBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.IetfAcl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.IetfAclBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterface; -import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply; -import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; -import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply; - -public class SubInterfaceIetfAclCustomizerTest extends WriterCustomizerTest { - - private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; - private static final String IF_NAME = "local0"; - private static final int IF_INDEX = 1; - private static final String SUBIF_NAME = "local0.123"; - private static final int SUBIF_INDEX = 2; - private static final long SUB_IF_ID = 123; - private static final InstanceIdentifier IID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation( - SubinterfaceAugmentation.class).child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(IetfAcl.class); - private static final String ACL_NAME = "acl1"; - private static final Class ACL_TYPE = EthAcl.class; - - private SubInterfaceIetfAclCustomizer customizer; - private IetfAcl acl; - - @Override - protected void setUp() { - customizer = - new SubInterfaceIetfAclCustomizer(new IetfAClWriter(api), new NamingContext("prefix", IFC_TEST_INSTANCE)); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); - - acl = new IetfAclBuilder().setAccessLists( - new AccessListsBuilder().setAcl( - Collections.singletonList(new AclBuilder() - .setName(ACL_NAME) - .setType(ACL_TYPE) - .build()) - ).build() - ).build(); - } - - private static InputAclSetInterface inputAclSetInterfaceWriteRequest() { - final InputAclSetInterface request = new InputAclSetInterface(); - request.swIfIndex = SUBIF_INDEX; - request.isAdd = 1; - request.l2TableIndex = -1; - request.ip4TableIndex = -1; - request.ip6TableIndex = -1; - return request; - } - - @Test - public void testDelete() throws WriteFailedException { - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); - defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE); - when(api.classifyTableByInterface(any())).thenReturn(future(noClassifyTablesAssigned())); - when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply())); - - customizer.deleteCurrentAttributes(IID, acl, writeContext); - - final ClassifyTableByInterface expectedRequest = new ClassifyTableByInterface(); - expectedRequest.swIfIndex = SUBIF_INDEX; - verify(api).classifyTableByInterface(expectedRequest); - verify(api).inputAclSetInterface(inputAclSetInterfaceDeleteRequest()); - } - - private static ClassifyTableByInterfaceReply noClassifyTablesAssigned() { - final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply(); - reply.l2TableId = -1; - reply.ip4TableId = -1; - reply.ip6TableId = -1; - return reply; - } - - private static InputAclSetInterface inputAclSetInterfaceDeleteRequest() { - final InputAclSetInterface request = new InputAclSetInterface(); - request.l2TableIndex = -1; - request.ip4TableIndex = -1; - request.ip6TableIndex = -1; - return request; - } - - @Test - public void testWrite() throws WriteFailedException { - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); - defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE); - - when(writeContext.readAfter(IID.firstIdentifierOf(SubInterface.class))).thenReturn(Optional.of( - new SubInterfaceBuilder().build() - )); - - when(writeContext.readAfter(AclWriter.ACL_ID.child( - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl.class, - new AclKey(ACL_NAME, ACL_TYPE)))).thenReturn(Optional.of( - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclBuilder() - .setAccessListEntries( - new AccessListEntriesBuilder().setAce(Collections.emptyList()).build() - ).build() - )); - - when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply())); - - customizer.writeCurrentAttributes(IID, acl, writeContext); - - verify(api).inputAclSetInterface(inputAclSetInterfaceWriteRequest()); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceEthWriterTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceEthWriterTest.java new file mode 100644 index 000000000..c352b5104 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceEthWriterTest.java @@ -0,0 +1,107 @@ +/* + * 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.honeycomb.translate.v3po.interfaces.acl.ingress; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession; +import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable; +import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.PacketHandling; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.DenyBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceEth; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceEthBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; + +public class AceEthWriterTest { + + @Mock + private FutureJVppCore jvpp; + private AceEthWriter writer; + private PacketHandling action; + private AceEth aceEth; + + @Before + public void setUp() throws Exception { + initMocks(this); + writer = new AceEthWriter(jvpp); + action = new DenyBuilder().setDeny(true).build(); + aceEth = new AceEthBuilder() + .setDestinationMacAddress(new MacAddress("11:22:33:44:55:66")) + .setDestinationMacAddressMask(new MacAddress("ff:ff:ff:ff:ff:ff")) + .setSourceMacAddress(new MacAddress("aa:bb:cc:dd:ee:ff")) + .setSourceMacAddressMask(new MacAddress("ff:ff:ff:00:00:00")) + .build(); + } + + @Test + public void testGetClassifyAddDelTableRequest() throws Exception { + final int nextTableIndex = 42; + final ClassifyAddDelTable request = writer.createClassifyTable(action, aceEth, nextTableIndex, 0); + + assertEquals(1, request.isAdd); + assertEquals(-1, request.tableIndex); + assertEquals(1, request.nbuckets); + assertEquals(-1, request.missNextIndex); + assertEquals(nextTableIndex, request.nextTableIndex); + assertEquals(0, request.skipNVectors); + assertEquals(AceEthWriter.MATCH_N_VECTORS, request.matchNVectors); + assertEquals(AceEthWriter.TABLE_MEM_SIZE, request.memorySize); + + byte[] expectedMask = new byte[] { + // destination MAC: + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + // source MAC: + (byte) 0xff, (byte) 0xff, (byte) 0xff, 0, 0, 0, + 0, 0, 0, 0 + }; + assertArrayEquals(expectedMask, request.mask); + } + + @Test + public void testGetClassifyAddDelSessionRequest() throws Exception { + final int tableIndex = 123; + final ClassifyAddDelSession request = writer.createClassifySession(action, aceEth, tableIndex, 0); + + assertEquals(1, request.isAdd); + assertEquals(tableIndex, request.tableIndex); + assertEquals(0, request.hitNextIndex); + + byte[] expectedMatch = new byte[] { + // destination MAC: + (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44, (byte) 0x55, (byte) 0x66, + // source MAC: + (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd, (byte) 0xee, (byte) 0xff, + 0, 0, 0, 0 + }; + assertArrayEquals(expectedMatch, request.match); + } + + @Test + public void testSetClassifyTable() throws Exception { + final int tableIndex = 321; + final InputAclSetInterface request = new InputAclSetInterface(); + writer.setClassifyTable(request, tableIndex); + assertEquals(tableIndex, request.l2TableIndex); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceIp4WriterTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceIp4WriterTest.java new file mode 100644 index 000000000..85ee57f79 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceIp4WriterTest.java @@ -0,0 +1,150 @@ +/* + * 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.honeycomb.translate.v3po.interfaces.acl.ingress; + +import static io.fd.honeycomb.translate.v3po.interfaces.acl.ingress.AbstractAceWriter.VLAN_TAG_LEN; +import static org.junit.Assert.assertEquals; +import static org.mockito.MockitoAnnotations.initMocks; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.PacketHandling; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.DenyBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIp; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; +import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession; +import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable; +import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; + +public class AceIp4WriterTest { + + @Mock + private FutureJVppCore jvpp; + private AceIp4Writer writer; + private PacketHandling action; + private AceIp aceIp; + + @Before + public void setUp() throws Exception { + initMocks(this); + writer = new AceIp4Writer(jvpp); + action = new DenyBuilder().setDeny(true).build(); + aceIp = new AceIpBuilder() + .setProtocol((short) 4) + .setDscp(new Dscp((short) 11)) + .setAceIpVersion(new AceIpv4Builder() + .setSourceIpv4Network(new Ipv4Prefix("1.2.3.4/32")) + .setDestinationIpv4Network(new Ipv4Prefix("1.2.4.5/24")) + .build()) + .build(); + } + + private static void verifyTableRequest(final ClassifyAddDelTable request, final int nextTableIndex, + final int vlanTags) { + assertEquals(1, request.isAdd); + assertEquals(-1, request.tableIndex); + assertEquals(1, request.nbuckets); + assertEquals(-1, request.missNextIndex); + assertEquals(nextTableIndex, request.nextTableIndex); + assertEquals(0, request.skipNVectors); + assertEquals(AceIp4Writer.MATCH_N_VECTORS, request.matchNVectors); + assertEquals(AceIp4Writer.TABLE_MEM_SIZE, request.memorySize); + + byte[] expectedMask = new byte[] { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0xf0, (byte) 0xfc, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, + -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMask, request.mask, vlanTags * VLAN_TAG_LEN); + + } + + private static void verifySessionRequest(final ClassifyAddDelSession request, final int tableIndex, + final int vlanTags) { + assertEquals(1, request.isAdd); + assertEquals(tableIndex, request.tableIndex); + assertEquals(0, request.hitNextIndex); + + byte[] expectedMatch = new byte[] { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0x40, (byte) 0x2c, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 1, 2, + 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMatch, request.match, vlanTags * VLAN_TAG_LEN); + + } + + @Test + public void testGetClassifyAddDelTableRequest() throws Exception { + final int nextTableIndex = 42; + final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, 0); + verifyTableRequest(request, nextTableIndex, 0); + } + + @Test + public void testGetClassifyAddDelTableRequest1VlanTag() throws Exception { + final int nextTableIndex = 42; + final int vlanTags = 1; + final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags); + verifyTableRequest(request, nextTableIndex, vlanTags); + } + + @Test + public void testGetClassifyAddDelTableRequest2VlanTags() throws Exception { + final int nextTableIndex = 42; + final int vlanTags = 2; + final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags); + verifyTableRequest(request, nextTableIndex, vlanTags); + } + + @Test + public void testGetClassifyAddDelSessionRequest() throws Exception { + final int tableIndex = 123; + final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, 0); + verifySessionRequest(request, tableIndex, 0); + } + + @Test + public void testGetClassifyAddDelSessionRequest1VlanTag() throws Exception { + final int tableIndex = 123; + final int vlanTags = 1; + final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags); + verifySessionRequest(request, tableIndex, vlanTags); + } + + @Test + public void testGetClassifyAddDelSessionRequest2VlanTags() throws Exception { + final int tableIndex = 123; + final int vlanTags = 2; + final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags); + + verifySessionRequest(request, tableIndex, vlanTags); + } + + @Test + public void testSetClassifyTable() throws Exception { + final int tableIndex = 321; + final InputAclSetInterface request = new InputAclSetInterface(); + writer.setClassifyTable(request, tableIndex); + assertEquals(tableIndex, request.ip4TableIndex); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceIp6WriterTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceIp6WriterTest.java new file mode 100644 index 000000000..3f3c6f7bc --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceIp6WriterTest.java @@ -0,0 +1,172 @@ +/* + * 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.honeycomb.translate.v3po.interfaces.acl.ingress; + +import static io.fd.honeycomb.translate.v3po.interfaces.acl.ingress.AbstractAceWriter.VLAN_TAG_LEN; +import static org.junit.Assert.assertEquals; +import static org.mockito.MockitoAnnotations.initMocks; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.PacketHandling; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.DenyBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIp; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; +import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession; +import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable; +import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; + +public class AceIp6WriterTest { + + @Mock + private FutureJVppCore jvpp; + private AceIp6Writer writer; + private PacketHandling action; + private AceIp aceIp; + + @Before + public void setUp() throws Exception { + initMocks(this); + writer = new AceIp6Writer(jvpp); + action = new DenyBuilder().setDeny(true).build(); + aceIp = new AceIpBuilder() + .setProtocol((short) 6) + .setDscp(new Dscp((short) 11)) + .setAceIpVersion(new AceIpv6Builder() + .setFlowLabel(new Ipv6FlowLabel(123L)) + .setSourceIpv6Network(new Ipv6Prefix("2001:db8:85a3:8d3:1319:8a2e:370:7348/128")) + .setDestinationIpv6Network(new Ipv6Prefix("fe80:1234:5678:abcd:ef01::/64")) + .build()) + .build(); + } + + + private static void verifyTableRequest(final ClassifyAddDelTable request, final int nextTableIndex, + final int vlanTags) { + assertEquals(1, request.isAdd); + assertEquals(-1, request.tableIndex); + assertEquals(1, request.nbuckets); + assertEquals(-1, request.missNextIndex); + assertEquals(nextTableIndex, request.nextTableIndex); + assertEquals(0, request.skipNVectors); + assertEquals(AceIp6Writer.MATCH_N_VECTORS, request.matchNVectors); + assertEquals(AceIp6Writer.TABLE_MEM_SIZE, request.memorySize); + + byte[] expectedMask = new byte[] { + // L2: + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // version, dscp, flow: + (byte) 0xff, (byte) 0xcf, (byte) 0xff, (byte) 0xff, + 0, 0, 0, 0, + // source address: + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + // destination address: + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + 0, 0, 0, 0, 0, 0, 0, 0, + // padding to multiple of 16B: + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMask, request.mask, vlanTags * VLAN_TAG_LEN); + + } + + private static void verifySessionRequest(final ClassifyAddDelSession request, final int tableIndex, + final int vlanTags) { + assertEquals(1, request.isAdd); + assertEquals(tableIndex, request.tableIndex); + assertEquals(0, request.hitNextIndex); + + byte[] expectedMatch = new byte[] { + // L2: + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // version(6), dscp(11), flow(123): + (byte) 0x62, (byte) 0xc0, (byte) 0x00, (byte) 0x7b, + 0, 0, 0, 0, + // source address: + (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8, (byte) 0x85, (byte) 0xa3, (byte) 0x08, (byte) 0xd3, + (byte) 0x13, (byte) 0x19, (byte) 0x8a, (byte) 0x2e, (byte) 0x03, (byte) 0x70, (byte) 0x73, (byte) 0x48, + // destination address: + (byte) 0xfe, (byte) 0x80, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0xab, (byte) 0xcd, + 0, 0, 0, 0, 0, 0, 0, 0, + // padding to multiple of 16B: + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMatch, request.match, vlanTags * VLAN_TAG_LEN); + + } + + @Test + public void testGetClassifyAddDelTableRequest() throws Exception { + final int nextTableIndex = 42; + final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, 0); + verifyTableRequest(request, nextTableIndex, 0); + } + + @Test + public void testGetClassifyAddDelTableRequest1VlanTag() throws Exception { + final int nextTableIndex = 42; + final int vlanTags = 1; + final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags); + verifyTableRequest(request, nextTableIndex, vlanTags); + } + + @Test + public void testGetClassifyAddDelTableRequest2VlanTag() throws Exception { + final int nextTableIndex = 42; + final int vlanTags = 2; + final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags); + verifyTableRequest(request, nextTableIndex, vlanTags); + } + + @Test + public void testGetClassifyAddDelSessionRequest() throws Exception { + final int tableIndex = 123; + final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, 0); + verifySessionRequest(request, tableIndex, 0); + } + + @Test + public void testGetClassifyAddDelSessionRequest1VlanTag() throws Exception { + final int tableIndex = 123; + final int vlanTags = 1; + final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags); + verifySessionRequest(request, tableIndex, vlanTags); + } + + @Test + public void testGetClassifyAddDelSessionRequest2VlanTag() throws Exception { + final int tableIndex = 123; + final int vlanTags = 2; + final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags); + verifySessionRequest(request, tableIndex, vlanTags); + } + + @Test + public void testSetClassifyTable() throws Exception { + final int tableIndex = 321; + final InputAclSetInterface request = new InputAclSetInterface(); + writer.setClassifyTable(request, tableIndex); + assertEquals(tableIndex, request.ip6TableIndex); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceIpWriterTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceIpWriterTestUtils.java new file mode 100644 index 000000000..7deb61f19 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/AceIpWriterTestUtils.java @@ -0,0 +1,34 @@ +/* + * 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.honeycomb.translate.v3po.interfaces.acl.ingress; + +import static org.junit.Assert.assertArrayEquals; + +final class AceIpWriterTestUtils { + + private AceIpWriterTestUtils() { + throw new UnsupportedOperationException("This utility class cannot be instantiated"); + } + + protected static void assertArrayEqualsWithOffset(final byte[] baseExpected, final byte[] actual, + final int offset) { + byte[] expected = new byte[baseExpected.length]; + System.arraycopy(baseExpected, 0, expected, offset, expected.length - offset); + + assertArrayEquals(expected, actual); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/IetfAclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/IetfAclCustomizerTest.java new file mode 100644 index 000000000..a0e467a5a --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/IetfAclCustomizerTest.java @@ -0,0 +1,162 @@ +/* + * 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.honeycomb.translate.v3po.interfaces.acl.ingress; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.common.base.Optional; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSessionReply; +import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable; +import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTableReply; +import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterface; +import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply; +import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; +import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply; +import java.util.Collections; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AclBase; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.EthAcl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.AccessListEntriesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.AceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.ActionsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.MatchesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.DenyBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv6Builder; +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.v3po.rev150105.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.AccessListsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.access.lists.AclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.IetfAcl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.ietf.acl.Ingress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.ietf.acl.IngressBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class IetfAclCustomizerTest extends WriterCustomizerTest { + + private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; + private static final String IF_NAME = "local0"; + private static final int IF_INDEX = 1; + private static final InstanceIdentifier IID = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation( + VppInterfaceAugmentation.class).child(IetfAcl.class).child(Ingress.class); + private static final String ACL_NAME = "acl1"; + private static final Class ACL_TYPE = EthAcl.class; + + private IetfAclCustomizer customizer; + private Ingress acl; + + @Override + protected void setUp() { + customizer = new IetfAclCustomizer(new IetfAClWriter(api), new NamingContext("prefix", IFC_TEST_INSTANCE)); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); + acl = new IngressBuilder().setAccessLists( + new AccessListsBuilder().setAcl( + Collections.singletonList(new AclBuilder() + .setName(ACL_NAME) + .setType(ACL_TYPE) + .build()) + ).build() + ).build(); + } + + @Test + public void testWrite() throws WriteFailedException { + when(api.classifyAddDelTable(any())).thenReturn(future(new ClassifyAddDelTableReply())); + when(api.classifyAddDelSession(any())).thenReturn(future(new ClassifyAddDelSessionReply())); + + when(writeContext.readAfter(any())).thenReturn(Optional.of( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclBuilder() + .setAccessListEntries( + new AccessListEntriesBuilder().setAce(Collections.singletonList( + new AceBuilder() + .setMatches(new MatchesBuilder().setAceType( + new AceIpBuilder() + .setAceIpVersion(new AceIpv6Builder().build()) + .setProtocol((short)1) + .build() + ).build()) + .setActions(new ActionsBuilder().setPacketHandling(new DenyBuilder().build()).build()) + .build() + )).build() + ).build() + + )); + when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply())); + + customizer.writeCurrentAttributes(IID, acl, writeContext); + + verify(api).classifyAddDelTable(any()); + verify(api).classifyAddDelSession(any()); + verify(api).inputAclSetInterface(inputAclSetInterfaceWriteRequest()); + } + + @Test + public void testDelete() throws WriteFailedException { + when(api.classifyTableByInterface(any())).thenReturn(future(classifyTableByInterfaceReply())); + when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply())); + when(api.classifyAddDelTable(any())).thenReturn(future(new ClassifyAddDelTableReply())); + + customizer.deleteCurrentAttributes(IID, acl, writeContext); + + final ClassifyTableByInterface expectedRequest = new ClassifyTableByInterface(); + expectedRequest.swIfIndex = IF_INDEX; + verify(api).classifyTableByInterface(expectedRequest); + verify(api).inputAclSetInterface(inputAclSetInterfaceDeleteRequest()); + verify(api).classifyAddDelTable(classifyAddDelTable(1)); + verify(api).classifyAddDelTable(classifyAddDelTable(2)); + verify(api).classifyAddDelTable(classifyAddDelTable(3)); + } + + private static InputAclSetInterface inputAclSetInterfaceDeleteRequest() { + final InputAclSetInterface request = new InputAclSetInterface(); + request.l2TableIndex = 1; + request.ip4TableIndex = 2; + request.ip6TableIndex = 3; + return request; + } + + private static ClassifyAddDelTable classifyAddDelTable(final int tableIndex) { + final ClassifyAddDelTable reply = new ClassifyAddDelTable(); + reply.tableIndex = tableIndex; + return reply; + } + + private static ClassifyTableByInterfaceReply classifyTableByInterfaceReply() { + final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply(); + reply.l2TableId = 1; + reply.ip4TableId = 2; + reply.ip6TableId = 3; + return reply; + } + + private static InputAclSetInterface inputAclSetInterfaceWriteRequest() { + final InputAclSetInterface request = new InputAclSetInterface(); + request.swIfIndex = IF_INDEX; + request.isAdd = 1; + request.l2TableIndex = -1; + request.ip4TableIndex = -1; + request.ip6TableIndex = 0; + return request; + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/SubInterfaceAclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/SubInterfaceAclCustomizerTest.java new file mode 100644 index 000000000..f5ec496ef --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/SubInterfaceAclCustomizerTest.java @@ -0,0 +1,140 @@ +/* + * 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.honeycomb.translate.v3po.interfaces.acl.ingress; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; +import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply; +import org.junit.Test; +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.v3po.rev150105.acl.base.attributes.Ip4Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4AclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6AclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.acl.Ingress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.acl.IngressBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceAclCustomizerTest extends WriterCustomizerTest { + private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; + private static final String IF_NAME = "local0"; + private static final int IF_INDEX = 1; + private static final String SUBIF_NAME = "local0.0"; + private static final int SUBIF_INDEX = 11; + private static final long SUBIF_ID = 0; + private static final String TABLE_NAME = "table0"; + private static final int TABLE_INDEX = 123; + + private static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation( + SubinterfaceAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(SUBIF_ID)).child(Acl.class).child(Ingress.class); + + @Mock + private VppClassifierContextManager classifyTableContext; + + private SubInterfaceAclCustomizer customizer; + + @Override + protected void setUp() throws Exception { + customizer = new SubInterfaceAclCustomizer(api, new NamingContext("prefix", IFC_TEST_INSTANCE), + classifyTableContext); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); + defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE); + when(classifyTableContext.getTableIndex(TABLE_NAME, mappingContext)).thenReturn(TABLE_INDEX); + } + + @Test + public void testCreate() throws WriteFailedException { + when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply())); + customizer.writeCurrentAttributes(IID, ip4Acl(), writeContext); + verify(api).inputAclSetInterface(expectedIp4AclRequest()); + } + + @Test(expected = WriteFailedException.CreateFailedException.class) + public void testCreateFailed() throws WriteFailedException { + when(api.inputAclSetInterface(any())).thenReturn(failedFuture()); + customizer.writeCurrentAttributes(IID, ip4Acl(), writeContext); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdate() throws WriteFailedException { + customizer.updateCurrentAttributes(IID, ip4Acl(), ip6Acl(), writeContext); + } + + @Test + public void testDelete() throws Exception { + when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply())); + customizer.deleteCurrentAttributes(IID, ip6Acl(), writeContext); + verify(api).inputAclSetInterface(expectedIp6AclRequest()); + } + + @Test(expected = WriteFailedException.DeleteFailedException.class) + public void testDeleteFailed() throws WriteFailedException { + when(api.inputAclSetInterface(any())).thenReturn(failedFuture()); + customizer.deleteCurrentAttributes(IID, ip4Acl(), writeContext); + } + + private Ingress ip4Acl() { + final IngressBuilder builder = new IngressBuilder(); + final Ip4Acl acl = new Ip4AclBuilder().setClassifyTable(TABLE_NAME).build(); + builder.setIp4Acl(acl); + return builder.build(); + } + + private InputAclSetInterface expectedIp4AclRequest() { + final InputAclSetInterface request = new InputAclSetInterface(); + request.isAdd = 1; + request.l2TableIndex = -1; + request.ip4TableIndex = TABLE_INDEX; + request.ip6TableIndex = -1; + request.swIfIndex = SUBIF_INDEX; + return request; + } + + private Ingress ip6Acl() { + final IngressBuilder builder = new IngressBuilder(); + final Ip6Acl acl = new Ip6AclBuilder().setClassifyTable(TABLE_NAME).build(); + builder.setIp6Acl(acl); + return builder.build(); + } + + private InputAclSetInterface expectedIp6AclRequest() { + final InputAclSetInterface request = new InputAclSetInterface(); + request.isAdd = 0; + request.l2TableIndex = -1; + request.ip4TableIndex = -1; + request.ip6TableIndex = TABLE_INDEX; + request.swIfIndex = SUBIF_INDEX; + return request; + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/SubInterfaceIetfAclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/SubInterfaceIetfAclCustomizerTest.java new file mode 100644 index 000000000..6e135d5fa --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/acl/ingress/SubInterfaceIetfAclCustomizerTest.java @@ -0,0 +1,152 @@ +/* + * 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.honeycomb.translate.v3po.interfaces.acl.ingress; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.common.base.Optional; +import io.fd.honeycomb.translate.v3po.interfaces.acl.IetfAclWriter; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterface; +import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply; +import io.fd.vpp.jvpp.core.dto.InputAclSetInterface; +import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply; +import java.util.Collections; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AclBase; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.EthAcl; +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.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.AccessListEntriesBuilder; +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.v3po.rev150105.ietf.acl.base.attributes.AccessListsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.ietf.acl.base.attributes.access.lists.AclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.IetfAcl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.ietf.acl.Ingress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.ietf.acl.IngressBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceIetfAclCustomizerTest extends WriterCustomizerTest { + + private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; + private static final String IF_NAME = "local0"; + private static final int IF_INDEX = 1; + private static final String SUBIF_NAME = "local0.123"; + private static final int SUBIF_INDEX = 2; + private static final long SUB_IF_ID = 123; + private static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation( + SubinterfaceAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(IetfAcl.class).child(Ingress.class); + private static final String ACL_NAME = "acl1"; + private static final Class ACL_TYPE = EthAcl.class; + + private SubInterfaceIetfAclCustomizer customizer; + private Ingress acl; + + @Override + protected void setUp() { + customizer = + new SubInterfaceIetfAclCustomizer(new IetfAClWriter(api), new NamingContext("prefix", IFC_TEST_INSTANCE)); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); + + acl = new IngressBuilder().setAccessLists( + new AccessListsBuilder().setAcl( + Collections.singletonList(new AclBuilder() + .setName(ACL_NAME) + .setType(ACL_TYPE) + .build()) + ).build() + ).build(); + } + + private static InputAclSetInterface inputAclSetInterfaceWriteRequest() { + final InputAclSetInterface request = new InputAclSetInterface(); + request.swIfIndex = SUBIF_INDEX; + request.isAdd = 1; + request.l2TableIndex = -1; + request.ip4TableIndex = -1; + request.ip6TableIndex = -1; + return request; + } + + @Test + public void testDelete() throws WriteFailedException { + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); + defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE); + when(api.classifyTableByInterface(any())).thenReturn(future(noClassifyTablesAssigned())); + when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply())); + + customizer.deleteCurrentAttributes(IID, acl, writeContext); + + final ClassifyTableByInterface expectedRequest = new ClassifyTableByInterface(); + expectedRequest.swIfIndex = SUBIF_INDEX; + verify(api).classifyTableByInterface(expectedRequest); + verify(api).inputAclSetInterface(inputAclSetInterfaceDeleteRequest()); + } + + private static ClassifyTableByInterfaceReply noClassifyTablesAssigned() { + final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply(); + reply.l2TableId = -1; + reply.ip4TableId = -1; + reply.ip6TableId = -1; + return reply; + } + + private static InputAclSetInterface inputAclSetInterfaceDeleteRequest() { + final InputAclSetInterface request = new InputAclSetInterface(); + request.l2TableIndex = -1; + request.ip4TableIndex = -1; + request.ip6TableIndex = -1; + return request; + } + + @Test + public void testWrite() throws WriteFailedException { + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); + defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE); + + when(writeContext.readAfter(IID.firstIdentifierOf(SubInterface.class))).thenReturn(Optional.of( + new SubInterfaceBuilder().build() + )); + + when(writeContext.readAfter(IetfAclWriter.ACL_ID.child( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl.class, + new AclKey(ACL_NAME, ACL_TYPE)))).thenReturn(Optional.of( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclBuilder() + .setAccessListEntries( + new AccessListEntriesBuilder().setAce(Collections.emptyList()).build() + ).build() + )); + + when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply())); + + customizer.writeCurrentAttributes(IID, acl, writeContext); + + verify(api).inputAclSetInterface(inputAclSetInterfaceWriteRequest()); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java deleted file mode 100644 index 388b56374..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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.honeycomb.translate.v3po.interfacesstate; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.honeycomb.translate.vpp.util.NamingContext; -import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; -import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; -import org.junit.Test; -import org.mockito.Mock; -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.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2AclBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Acl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.AclBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply; - -public class AclCustomizerTest extends ReaderCustomizerTest { - - private static final String IF_NAME = "local0"; - private static final int IF_INDEX = 1; - private static final int TABLE_INDEX = 123; - private static final String TABLE_NAME = "table123"; - private static final InstanceIdentifier IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(Acl.class); - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - - private NamingContext interfaceContext; - - @Mock - private VppClassifierContextManager classifyTableContext; - - public AclCustomizerTest() { - super(Acl.class, VppInterfaceStateAugmentationBuilder.class); - } - - @Override - public void setUp() { - interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new AclCustomizer(api, interfaceContext, classifyTableContext); - } - - @Test - public void testRead() throws ReadFailedException { - final AclBuilder builder = mock(AclBuilder.class); - - final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply(); - reply.l2TableId = TABLE_INDEX; - reply.ip4TableId = ~0; - reply.ip6TableId = ~0; - when(api.classifyTableByInterface(any())).thenReturn(future(reply)); - - when(classifyTableContext.getTableName(TABLE_INDEX, mappingContext)).thenReturn(TABLE_NAME); - - getCustomizer().readCurrentAttributes(IID, builder, ctx); - - verify(builder).setL2Acl(new L2AclBuilder().setClassifyTable(TABLE_NAME).build()); - verify(builder).setIp4Acl(null); - verify(builder).setIp6Acl(null); - } - - @Test(expected = ReadFailedException.class) - public void testReadFailed() throws ReadFailedException { - when(api.classifyTableByInterface(any())).thenReturn(failedFuture()); - getCustomizer().readCurrentAttributes(IID, mock(AclBuilder.class), ctx); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceAclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceAclCustomizerTest.java deleted file mode 100644 index 3559e6448..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceAclCustomizerTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.honeycomb.translate.v3po.interfacesstate; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.honeycomb.translate.vpp.util.NamingContext; -import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; -import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; -import org.junit.Test; -import org.mockito.Mock; -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.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4AclBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6AclBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.AclBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply; - -public class SubInterfaceAclCustomizerTest extends ReaderCustomizerTest { - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IF_NAME = "local0"; - private static final int IF_INDEX = 1; - private static final String SUB_IF_NAME = "local0.1"; - private static final long SUB_IF_ID = 1; - private static final int SUB_IF_INDEX = 11; - private static final int TABLE_INDEX = 123; - private static final String TABLE_NAME = "table123"; - - private static final InstanceIdentifier IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class).child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(Acl.class); - - private NamingContext interfaceContext; - - @Mock - private VppClassifierContextManager classifyTableContext; - - public SubInterfaceAclCustomizerTest() { - super(Acl.class, SubInterfaceBuilder.class); - } - - @Override - protected void setUp() throws Exception { - interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new SubInterfaceAclCustomizer(api, interfaceContext, classifyTableContext); - } - - @Test - public void testRead() throws ReadFailedException { - final AclBuilder builder = mock(AclBuilder.class); - - final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply(); - reply.swIfIndex = SUB_IF_INDEX; - reply.l2TableId = ~0; - reply.ip4TableId = TABLE_INDEX; - reply.ip6TableId = TABLE_INDEX; - when(api.classifyTableByInterface(any())).thenReturn(future(reply)); - - when(classifyTableContext.getTableName(TABLE_INDEX, mappingContext)).thenReturn(TABLE_NAME); - - getCustomizer().readCurrentAttributes(IID, builder, ctx); - - verify(builder).setL2Acl(null); - verify(builder).setIp4Acl(new Ip4AclBuilder().setClassifyTable(TABLE_NAME).build()); - verify(builder).setIp6Acl(new Ip6AclBuilder().setClassifyTable(TABLE_NAME).build()); - } - - @Test(expected = ReadFailedException.class) - public void testReadFailed() throws ReadFailedException { - when(api.classifyTableByInterface(any())).thenReturn(failedFuture()); - getCustomizer().readCurrentAttributes(IID, mock(AclBuilder.class), ctx); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/acl/ingress/AclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/acl/ingress/AclCustomizerTest.java new file mode 100644 index 000000000..20247f0da --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/acl/ingress/AclCustomizerTest.java @@ -0,0 +1,99 @@ +/* + * 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.honeycomb.translate.v3po.interfacesstate.acl.ingress; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; +import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply; +import org.junit.Test; +import org.mockito.Mock; +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.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2AclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.AclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.acl.Ingress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.acl.IngressBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class AclCustomizerTest extends ReaderCustomizerTest { + + private static final String IF_NAME = "local0"; + private static final int IF_INDEX = 1; + private static final int TABLE_INDEX = 123; + private static final String TABLE_NAME = "table123"; + private static final InstanceIdentifier IID = + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceStateAugmentation.class).child(Acl.class).child(Ingress.class); + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + + private NamingContext interfaceContext; + + @Mock + private VppClassifierContextManager classifyTableContext; + + public AclCustomizerTest() { + super(Ingress.class, AclBuilder.class); + } + + @Override + public void setUp() { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new AclCustomizer(api, interfaceContext, classifyTableContext); + } + + @Test + public void testRead() throws ReadFailedException { + final IngressBuilder builder = mock(IngressBuilder.class); + + final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply(); + reply.l2TableId = TABLE_INDEX; + reply.ip4TableId = ~0; + reply.ip6TableId = ~0; + when(api.classifyTableByInterface(any())).thenReturn(future(reply)); + + when(classifyTableContext.getTableName(TABLE_INDEX, mappingContext)).thenReturn(TABLE_NAME); + + getCustomizer().readCurrentAttributes(IID, builder, ctx); + + verify(builder).setL2Acl(new L2AclBuilder().setClassifyTable(TABLE_NAME).build()); + verify(builder).setIp4Acl(null); + verify(builder).setIp6Acl(null); + } + + @Test(expected = ReadFailedException.class) + public void testReadFailed() throws ReadFailedException { + when(api.classifyTableByInterface(any())).thenReturn(failedFuture()); + getCustomizer().readCurrentAttributes(IID, mock(IngressBuilder.class), ctx); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/acl/ingress/SubInterfaceAclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/acl/ingress/SubInterfaceAclCustomizerTest.java new file mode 100644 index 000000000..63c1d38b6 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/acl/ingress/SubInterfaceAclCustomizerTest.java @@ -0,0 +1,108 @@ +/* + * 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.honeycomb.translate.v3po.interfacesstate.acl.ingress; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; +import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply; +import org.junit.Test; +import org.mockito.Mock; +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.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4AclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6AclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.AclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.acl.Ingress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.acl.IngressBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceAclCustomizerTest extends ReaderCustomizerTest { + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "local0"; + private static final int IF_INDEX = 1; + private static final String SUB_IF_NAME = "local0.1"; + private static final long SUB_IF_ID = 1; + private static final int SUB_IF_INDEX = 11; + private static final int TABLE_INDEX = 123; + private static final String TABLE_NAME = "table123"; + + private static final InstanceIdentifier IID = + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(SubinterfaceStateAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(Acl.class).child(Ingress.class); + + private NamingContext interfaceContext; + + @Mock + private VppClassifierContextManager classifyTableContext; + + public SubInterfaceAclCustomizerTest() { + super(Ingress.class, AclBuilder.class); + } + + @Override + protected void setUp() throws Exception { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new SubInterfaceAclCustomizer(api, interfaceContext, classifyTableContext); + } + + @Test + public void testRead() throws ReadFailedException { + final IngressBuilder builder = mock(IngressBuilder.class); + + final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply(); + reply.swIfIndex = SUB_IF_INDEX; + reply.l2TableId = ~0; + reply.ip4TableId = TABLE_INDEX; + reply.ip6TableId = TABLE_INDEX; + when(api.classifyTableByInterface(any())).thenReturn(future(reply)); + + when(classifyTableContext.getTableName(TABLE_INDEX, mappingContext)).thenReturn(TABLE_NAME); + + getCustomizer().readCurrentAttributes(IID, builder, ctx); + + verify(builder).setL2Acl(null); + verify(builder).setIp4Acl(new Ip4AclBuilder().setClassifyTable(TABLE_NAME).build()); + verify(builder).setIp6Acl(new Ip6AclBuilder().setClassifyTable(TABLE_NAME).build()); + } + + @Test(expected = ReadFailedException.class) + public void testReadFailed() throws ReadFailedException { + when(api.classifyTableByInterface(any())).thenReturn(failedFuture()); + getCustomizer().readCurrentAttributes(IID, mock(IngressBuilder.class), ctx); + } +} \ No newline at end of file -- cgit 1.2.3-korg