summaryrefslogtreecommitdiffstats
path: root/vpp-classifier/impl/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'vpp-classifier/impl/src/test')
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/VppClassifierModuleTest.java84
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/context/VppClassifierContextManagerImplTest.java163
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/ClassifySessionReaderTest.java117
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/ClassifyTableReaderTest.java126
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/AclCustomizerTest.java99
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/SubInterfaceAclCustomizerTest.java111
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriterTest.java178
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifyTableWriterTest.java182
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/AclCustomizerTest.java153
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/AclWriterTest.java103
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceEthWriterTest.java94
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIp4WriterTest.java189
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIp6WriterTest.java200
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIpAndEthWriterTest.java124
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIpWriterTestUtils.java34
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AclTableContextManagerImplTest.java62
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/PortPairTest.java114
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/egress/EgressIetfAclWriterTest.java152
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/egress/IetfAclCustomizerTest.java114
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/egress/SubInterfaceIetfAclCustomizerTest.java133
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/ingress/IetfAclCustomizerTest.java205
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/ingress/SubInterfaceAclCustomizerTest.java143
-rw-r--r--vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/ingress/SubInterfaceIetfAclCustomizerTest.java158
23 files changed, 3038 insertions, 0 deletions
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/VppClassifierModuleTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/VppClassifierModuleTest.java
new file mode 100644
index 000000000..3b51a6dca
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/VppClassifierModuleTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.Matchers.empty;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+import com.google.inject.testing.fieldbinder.Bind;
+import com.google.inject.testing.fieldbinder.BoundFieldModule;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder;
+import io.fd.honeycomb.translate.write.WriterFactory;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
+public class VppClassifierModuleTest {
+
+ @Bind
+ @Mock
+ private FutureJVppCore futureJVppCore;
+
+ @Named("interface-context")
+ @Bind
+ private NamingContext ifcContext;
+
+ @Bind
+ @Mock
+ @Named("honeycomb-context")
+ private DataBroker contextBindingBrokerDependency;
+
+ @Inject
+ private Set<WriterFactory> writerFactories = new HashSet<>();
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+ ifcContext = new NamingContext("interface-", "interface-context");
+ Guice.createInjector(
+ new VppClassifierModule(),
+ new VppClassifierAclModule(),
+ new InterfaceClassifierAclModule(),
+ new InterfaceClassifierIetfAclModule(),
+ new SubInterfaceClassifierAclModule(),
+ new SubInterfaceClassifierIetfAclModule(),
+ BoundFieldModule.of(this)).injectMembers(this);
+ }
+
+ @Test
+ public void testWriterFactories() throws Exception {
+ assertThat(writerFactories, is(not(empty())));
+
+ // Test registration process (all dependencies present, topological order of writers does exist, etc.)
+ final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder();
+ writerFactories.stream().forEach(factory -> factory.init(registryBuilder));
+ assertNotNull(registryBuilder.build());
+ }
+
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/context/VppClassifierContextManagerImplTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/context/VppClassifierContextManagerImplTest.java
new file mode 100644
index 000000000..7b05ac208
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/context/VppClassifierContextManagerImplTest.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.context;
+
+import static io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManagerImpl.VPP_CLASSIFIER_CONTEXT_IID;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import com.google.common.base.Optional;
+import io.fd.honeycomb.translate.MappingContext;
+import java.util.Arrays;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.VppClassifierContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.VppClassifierContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.vpp.classifier.context.ClassifyTableContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.vpp.classifier.context.ClassifyTableContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.vpp.classifier.context.ClassifyTableContextKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.vpp.classifier.context.classify.table.context.NodeContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.vpp.classifier.context.classify.table.context.NodeContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.vpp.classifier.context.classify.table.context.NodeContextKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.VppNodeName;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+public class VppClassifierContextManagerImplTest {
+
+ private static final int TABLE_ID_0 = 0;
+ private static final String TABLE_NAME_0 = "table0";
+ private static final KeyedInstanceIdentifier<ClassifyTableContext, ClassifyTableContextKey> TABLE_IID_0 =
+ VPP_CLASSIFIER_CONTEXT_IID.child(ClassifyTableContext.class, new ClassifyTableContextKey(TABLE_NAME_0));
+
+ private static final int TABLE_ID_1 = 1;
+ private static final String TABLE_NAME_1 = "table1";
+
+ private VppClassifierContextManagerImpl vppClassfierContext;
+
+ @Mock
+ private MappingContext ctx;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ vppClassfierContext = new VppClassifierContextManagerImpl("classify-table-");
+ }
+
+ @Test
+ public void testAddTable() throws Exception {
+ final String classfierNodeName = "node123";
+ vppClassfierContext.addTable(TABLE_ID_0, TABLE_NAME_0, new VppNodeName(classfierNodeName), ctx);
+ verify(ctx).put(TABLE_IID_0, table(TABLE_ID_0, TABLE_NAME_0, classfierNodeName));
+ }
+
+ @Test
+ public void testContainsTable() throws Exception {
+ when(ctx.read(TABLE_IID_0)).thenReturn(Optional.absent());
+ assertFalse(vppClassfierContext.containsTable(TABLE_NAME_0, ctx));
+ }
+
+ @Test
+ public void testGetTableIndex() throws Exception {
+ when(ctx.read(TABLE_IID_0)).thenReturn(Optional.of(table(TABLE_ID_0, TABLE_NAME_0)));
+ assertEquals(TABLE_ID_0, vppClassfierContext.getTableIndex(TABLE_NAME_0, ctx));
+ }
+
+ @Test
+ public void testGetTableName() throws Exception {
+ when(ctx.read(VPP_CLASSIFIER_CONTEXT_IID))
+ .thenReturn(Optional.of(context(table(TABLE_ID_0, TABLE_NAME_0), table(TABLE_ID_1, TABLE_NAME_1))));
+ assertEquals(TABLE_NAME_0, (vppClassfierContext.getTableName(TABLE_ID_0, ctx)));
+ }
+
+ @Test
+ public void testGetTableBaseNode() throws Exception {
+ final String classfierNodeName = "node123";
+ when(ctx.read(TABLE_IID_0)).thenReturn(Optional.of(table(TABLE_ID_0, TABLE_NAME_0, classfierNodeName)));
+ vppClassfierContext.getTableBaseNode(TABLE_NAME_0, ctx);
+ assertEquals(Optional.of(classfierNodeName), (vppClassfierContext.getTableBaseNode(TABLE_NAME_0, ctx)));
+ }
+
+ @Test
+ public void testRemoveTable() throws Exception {
+ vppClassfierContext.removeTable(TABLE_NAME_0, ctx);
+ verify(ctx).delete(TABLE_IID_0);
+ }
+
+ @Test
+ public void testAddNodeName() throws Exception {
+ final String nodeName = "node123";
+ final int nodeIndex = 1;
+
+ vppClassfierContext.addNodeName(TABLE_NAME_0, nodeIndex, nodeName, ctx);
+ verify(ctx).put(
+ TABLE_IID_0.child(NodeContext.class, new NodeContextKey(nodeName)),
+ node(nodeName, nodeIndex)
+ );
+ }
+
+ @Test
+ public void testGetNonExistingNodeName() throws Exception {
+ when(ctx.read(VPP_CLASSIFIER_CONTEXT_IID)).thenReturn(Optional.of(context(table(TABLE_ID_1, TABLE_NAME_1))));
+ assertFalse(vppClassfierContext.getNodeName(TABLE_ID_0, 123, ctx).isPresent());
+ }
+
+ @Test
+ public void testGetNodeNameMissingNodeCtx() throws Exception {
+ final ClassifyTableContext tableCtx = table(TABLE_ID_0, TABLE_NAME_0, "aa");
+ when(ctx.read(VPP_CLASSIFIER_CONTEXT_IID)).thenReturn(Optional.of(context(tableCtx)));
+ when(ctx.read(TABLE_IID_0)).thenReturn(Optional.of(tableCtx));
+ assertEquals(Optional.absent(), vppClassfierContext.getNodeName(TABLE_ID_0, 123, ctx));
+ }
+
+ @Test
+ public void testGetNodeName() throws Exception {
+ final ClassifyTableContext tableCtx = table(TABLE_ID_0, TABLE_NAME_0, "aa", node("node123", 123));
+ when(ctx.read(VPP_CLASSIFIER_CONTEXT_IID)).thenReturn(Optional.of(context(tableCtx)));
+ when(ctx.read(TABLE_IID_0)).thenReturn(Optional.of(tableCtx));
+ assertEquals(Optional.of("node123"), vppClassfierContext.getNodeName(TABLE_ID_0, 123, ctx));
+ }
+
+ private VppClassifierContext context(ClassifyTableContext... tables) {
+ VppClassifierContextBuilder context = new VppClassifierContextBuilder();
+ context.setClassifyTableContext(Arrays.asList(tables));
+ return context.build();
+ }
+
+ private static ClassifyTableContext table(final Integer id, final String name) {
+ return table(id, name, null);
+ }
+
+ private static ClassifyTableContext table(final Integer id, final String name, final String classfierNodeName,
+ final NodeContext... nodeContexts) {
+ final ClassifyTableContextBuilder builder =
+ new ClassifyTableContextBuilder().setIndex(id).setName(name).setClassifierNodeName(classfierNodeName);
+
+ if (nodeContexts.length > 0) {
+ builder.setNodeContext(Arrays.asList(nodeContexts));
+ }
+
+ return builder.build();
+ }
+
+ private NodeContext node(final String nodeName, final int nodeIndex) {
+ return new NodeContextBuilder().setName(nodeName).setIndex(nodeIndex).build();
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/ClassifySessionReaderTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/ClassifySessionReaderTest.java
new file mode 100644
index 000000000..c2ea534e9
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/ClassifySessionReaderTest.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.read;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
+import io.fd.honeycomb.translate.ModificationCache;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.vpp.jvpp.core.dto.ClassifySessionDetails;
+import io.fd.vpp.jvpp.core.dto.ClassifySessionDetailsReplyDump;
+import io.fd.vpp.jvpp.core.dto.ClassifySessionDump;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.VppClassifierState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.classify.table.base.attributes.ClassifySession;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.classify.table.base.attributes.ClassifySessionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.classify.table.base.attributes.ClassifySessionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.vpp.classifier.state.ClassifyTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.vpp.classifier.state.ClassifyTableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.vpp.classifier.state.ClassifyTableKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ClassifySessionReaderTest extends
+ ListReaderCustomizerTest<ClassifySession, ClassifySessionKey, ClassifySessionBuilder> {
+
+ private static final String MATCH_1 = "00:00:00:00:00:00:01:02:03:04:05:06:00:00:00:00";
+ private static final String MATCH_2 = "00:00:00:00:00:00:01:02:03:04:05:07:00:00:00:00";
+
+ private static final int TABLE_INDEX = 1;
+ private static final String TABLE_NAME = "table1";
+
+ @Mock
+ private VppClassifierContextManager classifierContext;
+
+ public ClassifySessionReaderTest() {
+ super(ClassifySession.class, ClassifyTableBuilder.class);
+ }
+
+ @Override
+ protected ReaderCustomizer<ClassifySession, ClassifySessionBuilder> initCustomizer() {
+ return new ClassifySessionReader(api, classifierContext);
+ }
+
+ private static InstanceIdentifier<ClassifySession> getClassifySessionId(final String tableName,
+ final String match) {
+ return InstanceIdentifier.create(VppClassifierState.class)
+ .child(ClassifyTable.class, new ClassifyTableKey(tableName))
+ .child(ClassifySession.class, new ClassifySessionKey(new HexString(match)));
+ }
+
+ @Test
+ public void testReadWithCache() throws ReadFailedException {
+ final InstanceIdentifier<ClassifySession> id = getClassifySessionId(TABLE_NAME, MATCH_1);
+ final ClassifySessionBuilder builder = mock(ClassifySessionBuilder.class);
+ final ModificationCache cache = new ModificationCache();
+ final ClassifySessionDetailsReplyDump dump = new ClassifySessionDetailsReplyDump();
+ final ClassifySessionDetails details = new ClassifySessionDetails();
+ details.match =
+ new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04,
+ (byte) 0x05, (byte) 0x06, 0x00, 0x00, 0x00, 0x00};
+ dump.classifySessionDetails = Collections.singletonList(details);
+ cache.put(ClassifySessionReader.CACHE_KEY + id.firstKeyOf(ClassifyTable.class), dump);
+ when(ctx.getModificationCache()).thenReturn(cache);
+
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+ }
+
+ @Test
+ public void testGetAllIds() throws ReadFailedException {
+ final InstanceIdentifier<ClassifySession> id = getClassifySessionId(TABLE_NAME, MATCH_1);
+ final ClassifySessionDetailsReplyDump dump = new ClassifySessionDetailsReplyDump();
+ final ClassifySessionDetails details1 = new ClassifySessionDetails();
+ details1.match =
+ new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04,
+ (byte) 0x05, (byte) 0x06, 0x00, 0x00, 0x00, 0x00};
+ final ClassifySessionDetails details2 = new ClassifySessionDetails();
+ details2.match =
+ new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04,
+ (byte) 0x05, (byte) 0x07, 0x00, 0x00, 0x00, 0x00};
+ dump.classifySessionDetails = Arrays.asList(details1, details2);
+ doReturn(future(dump)).when(api).classifySessionDump(ArgumentMatchers.any(ClassifySessionDump.class));
+
+ when(classifierContext.containsTable(TABLE_NAME, mappingContext)).thenReturn(true);
+ when(classifierContext.getTableIndex(TABLE_NAME, mappingContext)).thenReturn(TABLE_INDEX);
+
+ final List<ClassifySessionKey> allIds = getCustomizer().getAllIds(id, ctx);
+ assertEquals(2, allIds.size());
+ assertEquals(MATCH_1, allIds.get(0).getMatch().getValue());
+ assertEquals(MATCH_2, allIds.get(1).getMatch().getValue());
+ }
+
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/ClassifyTableReaderTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/ClassifyTableReaderTest.java
new file mode 100644
index 000000000..75b6dd783
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/ClassifyTableReaderTest.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.read;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.vpp.jvpp.core.dto.ClassifyTableIds;
+import io.fd.vpp.jvpp.core.dto.ClassifyTableIdsReply;
+import io.fd.vpp.jvpp.core.dto.ClassifyTableInfo;
+import io.fd.vpp.jvpp.core.dto.ClassifyTableInfoReply;
+import java.util.List;
+import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.PacketHandlingAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.VppClassifierState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.VppClassifierStateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.VppNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.vpp.classifier.state.ClassifyTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.vpp.classifier.state.ClassifyTableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.vpp.classifier.state.ClassifyTableKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ClassifyTableReaderTest extends
+ ListReaderCustomizerTest<ClassifyTable, ClassifyTableKey, ClassifyTableBuilder> {
+
+ private static final int TABLE_INDEX_1 = 1;
+ private static final String TABLE_NAME_1 = "table1";
+ private static final int TABLE_INDEX_2 = 2;
+ private static final String TABLE_NAME_2 = "table2";
+
+ @Mock
+ private VppClassifierContextManager classifierContext;
+
+ public ClassifyTableReaderTest() {
+ super(ClassifyTable.class, VppClassifierStateBuilder.class);
+ }
+
+ @Override
+ protected ReaderCustomizer<ClassifyTable, ClassifyTableBuilder> initCustomizer() {
+ return new ClassifyTableReader(api, classifierContext);
+ }
+
+ private static InstanceIdentifier<ClassifyTable> getClassifyTableId(final String name) {
+ return InstanceIdentifier.create(VppClassifierState.class)
+ .child(ClassifyTable.class, new ClassifyTableKey(name));
+ }
+
+ private static ClassifyTableInfoReply generateClassifyTableInfoReply() {
+ final ClassifyTableInfoReply reply = new ClassifyTableInfoReply();
+ reply.tableId = TABLE_INDEX_1;
+ reply.nbuckets = 2;
+ reply.skipNVectors = 0;
+ reply.matchNVectors = 1;
+ reply.nextTableIndex = ~0;
+ reply.missNextIndex = ~0;
+ reply.mask =
+ new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04,
+ (byte) 0x05, (byte) 0x06, 0x00, 0x00, 0x00, 0x00};
+ return reply;
+ }
+
+ private void verifyClasifyTableRead(final ClassifyTableBuilder builder) {
+ verify(builder).setName(TABLE_NAME_1);
+ verify(builder).setNbuckets(2L);
+ verify(builder, times(0)).setNextTable(ArgumentMatchers.anyString());
+ verify(builder).setMissNext(new VppNode(PacketHandlingAction.Permit));
+ verify(builder).setMask(new HexString("00:00:00:00:00:00:01:02:03:04:05:06:00:00:00:00"));
+ verify(builder).setActiveSessions(0L);
+ }
+
+ @Test
+ public void testRead() throws ReadFailedException {
+ doReturn(future(generateClassifyTableInfoReply())).when(api).classifyTableInfo(ArgumentMatchers.any(ClassifyTableInfo.class));
+
+ when(classifierContext.containsTable(TABLE_NAME_1, mappingContext)).thenReturn(true);
+ when(classifierContext.getTableIndex(TABLE_NAME_1, mappingContext)).thenReturn(TABLE_INDEX_1);
+ when(classifierContext.getTableBaseNode(TABLE_NAME_1, mappingContext)).thenReturn(Optional.absent());
+
+ final ClassifyTableBuilder builder = mock(ClassifyTableBuilder.class);
+ getCustomizer().readCurrentAttributes(getClassifyTableId(TABLE_NAME_1), builder, ctx);
+
+ verifyClasifyTableRead(builder);
+ }
+
+ @Test
+ public void testGetAllIds() throws ReadFailedException {
+ final ClassifyTableIdsReply reply = new ClassifyTableIdsReply();
+ reply.ids = new int[] {1, 2};
+ doReturn(future(reply)).when(api).classifyTableIds(ArgumentMatchers.any(ClassifyTableIds.class));
+
+ when(classifierContext.getTableName(TABLE_INDEX_1, mappingContext)).thenReturn(TABLE_NAME_1);
+ when(classifierContext.getTableName(TABLE_INDEX_2, mappingContext)).thenReturn(TABLE_NAME_2);
+
+ final List<ClassifyTableKey> allIds = getCustomizer().getAllIds(getClassifyTableId(TABLE_NAME_1), ctx);
+
+ assertEquals(reply.ids.length, allIds.size());
+ assertEquals(TABLE_NAME_1, allIds.get(0).getName());
+ assertEquals(TABLE_NAME_2, allIds.get(1).getName());
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/AclCustomizerTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/AclCustomizerTest.java
new file mode 100644
index 000000000..6ce12c871
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/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.hc2vpp.vpp.classifier.read.acl;
+
+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.hc2vpp.common.test.read.ReaderCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+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.vpp._interface.acl.rev161214.VppInterfaceAclStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.acl.base.attributes.L2AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.Acl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.acl.Ingress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.acl.IngressBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class AclCustomizerTest extends ReaderCustomizerTest<Ingress, IngressBuilder> {
+
+ 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<Ingress> IID =
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
+ .augmentation(VppInterfaceAclStateAugmentation.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<Ingress, IngressBuilder> 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/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/SubInterfaceAclCustomizerTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/SubInterfaceAclCustomizerTest.java
new file mode 100644
index 000000000..0481a83db
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/SubInterfaceAclCustomizerTest.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.read.acl;
+
+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.hc2vpp.common.test.read.ReaderCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+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.vpp.classifier.acl.rev161214.acl.base.attributes.Ip4AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.acl.base.attributes.Ip6AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.Acl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.acl.Ingress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.acl.IngressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.subinterface.acl.rev161214.VppSubinterfaceAclStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class SubInterfaceAclCustomizerTest extends ReaderCustomizerTest<Ingress, IngressBuilder> {
+ 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<Ingress> 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))
+ .augmentation(VppSubinterfaceAclStateAugmentation.class)
+ .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<Ingress, IngressBuilder> 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
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriterTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriterTest.java
new file mode 100644
index 000000000..49e172fac
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriterTest.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.VppBaseCallException;
+import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession;
+import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSessionReply;
+import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.OpaqueIndex;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.PacketHandlingAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.VppClassifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.VppNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.VppNodeName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.classify.table.base.attributes.ClassifySession;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.classify.table.base.attributes.ClassifySessionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.classify.table.base.attributes.ClassifySessionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.vpp.classifier.ClassifyTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.vpp.classifier.ClassifyTableKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ClassifySessionWriterTest extends WriterCustomizerTest {
+
+ private static final int TABLE_INDEX = 123;
+ private static final String TABLE_NAME = "table123";
+ private static final int SESSION_INDEX = 456;
+ @Mock
+ private VppClassifierContextManager classfierContext;
+ private ClassifySessionWriter customizer;
+
+ private static ClassifySession generateClassifySession(final long opaqueIndex, final String match) {
+ final ClassifySessionBuilder builder = new ClassifySessionBuilder();
+ builder.setOpaqueIndex(new OpaqueIndex(opaqueIndex));
+ builder.setHitNext(new VppNode(PacketHandlingAction.Deny));
+ builder.setAdvance(123);
+ builder.setMatch(new HexString(match));
+ return builder.build();
+ }
+
+ private static InstanceIdentifier<ClassifySession> getClassifySessionId(final String tableName,
+ final String match) {
+ return InstanceIdentifier.create(VppClassifier.class)
+ .child(ClassifyTable.class, new ClassifyTableKey(tableName))
+ .child(ClassifySession.class, new ClassifySessionKey(new HexString(match)));
+ }
+
+ private static ClassifyAddDelSession generateClassifyAddDelSession(final byte isAdd, final int tableIndex,
+ final int sessionIndex) {
+ final ClassifyAddDelSession request = new ClassifyAddDelSession();
+ request.isAdd = isAdd;
+ request.tableIndex = tableIndex;
+ request.opaqueIndex = sessionIndex;
+ request.hitNextIndex = 0;
+ request.advance = 123;
+ request.match =
+ new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04,
+ (byte) 0x05, (byte) 0x06, 0x00, 0x00, 0x00, 0x00};
+ return request;
+ }
+
+ @Override
+ public void setUpTest() throws Exception {
+ customizer = new ClassifySessionWriter(api, classfierContext);
+
+ when(classfierContext.containsTable(TABLE_NAME, mappingContext)).thenReturn(true);
+ when(classfierContext.getTableIndex(TABLE_NAME, mappingContext)).thenReturn(TABLE_INDEX);
+
+ final ClassifyTable table = mock(ClassifyTable.class);
+ when(table.getClassifierNode()).thenReturn(new VppNodeName("ip4-classifier"));
+ when(writeContext.readAfter(ArgumentMatchers.any())).thenReturn(Optional.of(table));
+ when(writeContext.readBefore(ArgumentMatchers.any())).thenReturn(Optional.of(table));
+ }
+
+ private void whenClassifyAddDelSessionThenSuccess() {
+ doReturn(future(new ClassifyAddDelSessionReply())).when(api)
+ .classifyAddDelSession(ArgumentMatchers.any(ClassifyAddDelSession.class));
+ }
+
+ private void whenClassifyAddDelSessionThenFailure() {
+ doReturn(failedFuture()).when(api).classifyAddDelSession(ArgumentMatchers.any(ClassifyAddDelSession.class));
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ final String match = "00:00:00:00:00:00:01:02:03:04:05:06:00:00:00:00";
+ final ClassifySession classifySession = generateClassifySession(SESSION_INDEX, match);
+ final InstanceIdentifier<ClassifySession> id = getClassifySessionId(TABLE_NAME, match);
+
+ whenClassifyAddDelSessionThenSuccess();
+
+ customizer.writeCurrentAttributes(id, classifySession, writeContext);
+
+ verify(api).classifyAddDelSession(generateClassifyAddDelSession((byte) 1, TABLE_INDEX, SESSION_INDEX));
+ }
+
+ @Test
+ public void testCreateFailed() throws Exception {
+ final String match = "00:00:00:00:00:00:01:02:03:04:05:06:00:00:00:00";
+ final ClassifySession classifySession = generateClassifySession(SESSION_INDEX, match);
+ final InstanceIdentifier<ClassifySession> id = getClassifySessionId(TABLE_NAME, match);
+
+ whenClassifyAddDelSessionThenFailure();
+
+ try {
+ customizer.writeCurrentAttributes(id, classifySession, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).classifyAddDelSession(generateClassifyAddDelSession((byte) 1, TABLE_INDEX, SESSION_INDEX));
+ return;
+ }
+ fail("WriteFailedException.CreateFailedException was expected");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdate() throws Exception {
+ customizer.updateCurrentAttributes(null, null, null, writeContext);
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ final String match = "00:00:00:00:00:00:01:02:03:04:05:06:00:00:00:00";
+ final ClassifySession classifySession = generateClassifySession(SESSION_INDEX, match);
+ final InstanceIdentifier<ClassifySession> id = getClassifySessionId(TABLE_NAME, match);
+
+ whenClassifyAddDelSessionThenSuccess();
+
+ customizer.deleteCurrentAttributes(id, classifySession, writeContext);
+
+ verify(api).classifyAddDelSession(generateClassifyAddDelSession((byte) 0, TABLE_INDEX, SESSION_INDEX));
+ }
+
+ @Test
+ public void testDeleteFailed() throws Exception {
+ final String match = "00:00:00:00:00:00:01:02:03:04:05:06:00:00:00:00";
+ final ClassifySession classifySession = generateClassifySession(SESSION_INDEX, match);
+ final InstanceIdentifier<ClassifySession> id = getClassifySessionId(TABLE_NAME, match);
+
+ whenClassifyAddDelSessionThenFailure();
+
+ try {
+ customizer.deleteCurrentAttributes(id, classifySession, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).classifyAddDelSession(generateClassifyAddDelSession((byte) 0, TABLE_INDEX, SESSION_INDEX));
+ return;
+ }
+ fail("WriteFailedException.DeleteFailedException was expected");
+
+ customizer.deleteCurrentAttributes(id, classifySession, writeContext);
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifyTableWriterTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifyTableWriterTest.java
new file mode 100644
index 000000000..2a8b3db66
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifyTableWriterTest.java
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.VppBaseCallException;
+import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable;
+import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTableReply;
+import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.PacketHandlingAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.VppClassifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.VppNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.VppNodeName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.vpp.classifier.ClassifyTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.vpp.classifier.ClassifyTableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev161214.vpp.classifier.ClassifyTableKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ClassifyTableWriterTest extends WriterCustomizerTest {
+
+ private static final int TABLE_INDEX = 123;
+ private static final String TABLE_NAME = "table123";
+
+ @Mock
+ private VppClassifierContextManager classifierContext;
+
+ private ClassifyTableWriter customizer;
+
+ private static ClassifyTable generateClassifyTable(final String name) {
+ final ClassifyTableBuilder builder = new ClassifyTableBuilder();
+ builder.setName(name);
+ builder.setClassifierNode(new VppNodeName("ip4-classifier"));
+ builder.setKey(new ClassifyTableKey(name));
+ builder.setSkipNVectors(0L);
+ builder.setNbuckets(2L);
+ builder.setMemorySize(2L << 20);
+ builder.setMissNext(new VppNode(PacketHandlingAction.Permit));
+ builder.setMask(new HexString("00:00:00:00:00:00:01:02:03:04:05:06:00:00:00:00"));
+ return builder.build();
+ }
+
+ private static InstanceIdentifier<ClassifyTable> getClassifyTableId(final String name) {
+ return InstanceIdentifier.create(VppClassifier.class)
+ .child(ClassifyTable.class, new ClassifyTableKey(name));
+ }
+
+ private static ClassifyAddDelTable generateClassifyAddDelTable(final byte isAdd) {
+ return generateClassifyAddDelTable(isAdd, -1);
+ }
+
+ private static ClassifyAddDelTable generateClassifyAddDelTable(final byte isAdd, final int tableIndex) {
+ final ClassifyAddDelTable request = new ClassifyAddDelTable();
+ request.isAdd = isAdd;
+ request.tableIndex = tableIndex;
+ request.nbuckets = 2;
+ request.memorySize = 2 << 20;
+ request.skipNVectors = 0;
+ request.matchNVectors = 1;
+ request.nextTableIndex = ~0;
+ request.missNextIndex = ~0;
+ request.mask =
+ new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04,
+ (byte) 0x05, (byte) 0x06, 0x00, 0x00, 0x00, 0x00};
+ return request;
+ }
+
+ @Override
+ public void setUpTest() throws Exception {
+ customizer = new ClassifyTableWriter(api, classifierContext);
+ }
+
+ private void whenClassifyAddDelTableThenSuccess() {
+ final ClassifyAddDelTableReply reply = new ClassifyAddDelTableReply();
+ reply.newTableIndex = TABLE_INDEX;
+ doReturn(future(reply)).when(api).classifyAddDelTable(ArgumentMatchers.any(ClassifyAddDelTable.class));
+ }
+
+ private void whenClassifyAddDelTableThenFailure() {
+ doReturn(failedFuture()).when(api).classifyAddDelTable(ArgumentMatchers.any(ClassifyAddDelTable.class));
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ final ClassifyTable classifyTable = generateClassifyTable(TABLE_NAME);
+ final InstanceIdentifier<ClassifyTable> id = getClassifyTableId(TABLE_NAME);
+
+ whenClassifyAddDelTableThenSuccess();
+
+ customizer.writeCurrentAttributes(id, classifyTable, writeContext);
+
+ verify(api).classifyAddDelTable(generateClassifyAddDelTable((byte) 1));
+ verify(classifierContext)
+ .addTable(TABLE_INDEX, classifyTable.getName(), classifyTable.getClassifierNode(), mappingContext);
+ }
+
+ @Test
+ public void testCreateFailed() throws Exception {
+ final ClassifyTable classifyTable = generateClassifyTable(TABLE_NAME);
+ final InstanceIdentifier<ClassifyTable> id = getClassifyTableId(TABLE_NAME);
+
+ whenClassifyAddDelTableThenFailure();
+
+ try {
+ customizer.writeCurrentAttributes(id, classifyTable, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).classifyAddDelTable(generateClassifyAddDelTable((byte) 1));
+ verify(classifierContext, times(0))
+ .addTable(TABLE_INDEX, classifyTable.getName(), classifyTable.getClassifierNode(), mappingContext);
+ return;
+ }
+ fail("WriteFailedException.CreateFailedException was expected");
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ final ClassifyTable classifyTable = generateClassifyTable(TABLE_NAME);
+ final InstanceIdentifier<ClassifyTable> id = getClassifyTableId(TABLE_NAME);
+
+ when(classifierContext.containsTable(TABLE_NAME, mappingContext)).thenReturn(true);
+ when(classifierContext.getTableIndex(TABLE_NAME, mappingContext)).thenReturn(TABLE_INDEX);
+ whenClassifyAddDelTableThenSuccess();
+
+ customizer.deleteCurrentAttributes(id, classifyTable, writeContext);
+
+ verify(api).classifyAddDelTable(generateClassifyAddDelTable((byte) 0, TABLE_INDEX));
+ }
+
+ @Test
+ public void testDeleteFailed() throws Exception {
+ final ClassifyTable classifyTable = generateClassifyTable(TABLE_NAME);
+ final InstanceIdentifier<ClassifyTable> id = getClassifyTableId(TABLE_NAME);
+
+ when(classifierContext.containsTable(TABLE_NAME, mappingContext)).thenReturn(true);
+ when(classifierContext.getTableIndex(TABLE_NAME, mappingContext)).thenReturn(TABLE_INDEX);
+ whenClassifyAddDelTableThenFailure();
+
+ try {
+ customizer.deleteCurrentAttributes(id, classifyTable, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).classifyAddDelTable(generateClassifyAddDelTable((byte) 0, TABLE_INDEX));
+ return;
+ }
+ fail("WriteFailedException.DeleteFailedException was expected");
+
+ customizer.deleteCurrentAttributes(id, classifyTable, writeContext);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdate() throws Exception {
+ final ClassifyTable classifyTableBefore = generateClassifyTable(TABLE_NAME);
+ final InstanceIdentifier<ClassifyTable> id = getClassifyTableId(TABLE_NAME);
+ customizer.updateCurrentAttributes(id, classifyTableBefore, new ClassifyTableBuilder().build(), writeContext);
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/AclCustomizerTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/AclCustomizerTest.java
new file mode 100644
index 000000000..55d5587c9
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/AclCustomizerTest.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.acl;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
+import io.fd.hc2vpp.vpp.classifier.write.acl.ingress.AclCustomizer;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+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;
+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.vpp._interface.acl.rev161214.VppInterfaceAclAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.acl.base.attributes.L2Acl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.acl.base.attributes.L2AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.Acl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.acl.Ingress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.acl.IngressBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class AclCustomizerTest 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 int ACL_TABLE_INDEX = 0;
+ private static final String ACL_TABLE_NAME = "table0";
+ @Mock
+ private VppClassifierContextManager classifyTableContext;
+ private AclCustomizer customizer;
+
+ private static InputAclSetInterface generateInputAclSetInterface(final byte isAdd, final int ifIndex,
+ final int l2TableIndex) {
+ final InputAclSetInterface request = new InputAclSetInterface();
+ request.isAdd = isAdd;
+ request.l2TableIndex = l2TableIndex;
+ request.ip4TableIndex = ~0;
+ request.ip6TableIndex = ~0;
+ request.swIfIndex = ifIndex;
+ return request;
+ }
+
+ @Override
+ public void setUpTest() {
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
+ customizer = new AclCustomizer(api, new NamingContext("generatedInterfaceName", IFC_TEST_INSTANCE),
+ classifyTableContext);
+ }
+
+ private InstanceIdentifier<Ingress> getAclId(final String name) {
+ return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation(
+ VppInterfaceAclAugmentation.class).child(Acl.class).child(Ingress.class);
+ }
+
+ 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();
+ }
+
+ private void whenInputAclSetInterfaceThenSuccess() {
+ doReturn(future(new InputAclSetInterfaceReply())).when(api)
+ .inputAclSetInterface(any(InputAclSetInterface.class));
+ }
+
+ private void whenInputAclSetInterfaceThenFailure() {
+ doReturn(failedFuture()).when(api).inputAclSetInterface(any(InputAclSetInterface.class));
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ final Ingress acl = generateAcl(ACL_TABLE_NAME);
+ final InstanceIdentifier<Ingress> id = getAclId(IF_NAME);
+
+ whenInputAclSetInterfaceThenSuccess();
+
+ customizer.writeCurrentAttributes(id, acl, writeContext);
+
+ verify(api).inputAclSetInterface(generateInputAclSetInterface((byte) 1, IF_INDEX, ACL_TABLE_INDEX));
+ }
+
+ @Test
+ public void testCreateFailed() throws Exception {
+ final Ingress acl = generateAcl(ACL_TABLE_NAME);
+ final InstanceIdentifier<Ingress> id = getAclId(IF_NAME);
+
+ whenInputAclSetInterfaceThenFailure();
+
+ try {
+ customizer.writeCurrentAttributes(id, acl, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).inputAclSetInterface(generateInputAclSetInterface((byte) 1, IF_INDEX, ACL_TABLE_INDEX));
+ return;
+ }
+ fail("WriteFailedException.CreateFailedException was expected");
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ final Ingress acl = generateAcl(ACL_TABLE_NAME);
+ final InstanceIdentifier<Ingress> id = getAclId(IF_NAME);
+
+ whenInputAclSetInterfaceThenSuccess();
+
+ customizer.deleteCurrentAttributes(id, acl, writeContext);
+
+ verify(api).inputAclSetInterface(generateInputAclSetInterface((byte) 0, IF_INDEX, ACL_TABLE_INDEX));
+ }
+
+ @Test
+ public void testDeleteFailed() throws Exception {
+ final Ingress acl = generateAcl(ACL_TABLE_NAME);
+ final InstanceIdentifier<Ingress> id = getAclId(IF_NAME);
+
+ whenInputAclSetInterfaceThenFailure();
+
+ try {
+ customizer.deleteCurrentAttributes(id, acl, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).inputAclSetInterface(generateInputAclSetInterface((byte) 0, IF_INDEX, ACL_TABLE_INDEX));
+ return;
+ }
+ fail("WriteFailedException.DeleteFailedException was expected");
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/AclWriterTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/AclWriterTest.java
new file mode 100644
index 000000000..fbd7b5342
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/AclWriterTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.acl;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import java.util.Collections;
+import java.util.List;
+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.AccessLists;
+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;
+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.interfaces.rev140508.Interfaces;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesBuilder;
+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.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp._interface.acl.rev161214.VppInterfaceAclAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp._interface.acl.rev161214.VppInterfaceAclAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.AccessListsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.access.lists.AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.IetfAclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.ietf.acl.IngressBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class AclWriterTest extends WriterCustomizerTest {
+
+ private static final String ACL_NAME = "acl1";
+ private static final Class<? extends AclBase> ACL_TYPE = EthAcl.class;
+ private static final InstanceIdentifier<Acl> IID =
+ InstanceIdentifier.create(AccessLists.class).child(Acl.class, new AclKey(ACL_NAME, ACL_TYPE));
+
+ @Mock
+ private Acl acl;
+ private IetfAclWriter customizer;
+
+ @Override
+ public void setUpTest() {
+ customizer = new IetfAclWriter();
+ when(acl.getAclName()).thenReturn(ACL_NAME);
+ doReturn(ACL_TYPE).when(acl).getAclType();
+ }
+
+ private void defineInterfacesContext(final List<Interface> interfaces) {
+ when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of(
+ new InterfacesBuilder().setInterface(interfaces).build()
+ ));
+ }
+
+ @Test
+ public void testWrite() throws Exception {
+ customizer.writeCurrentAttributes(IID, acl, writeContext);
+ }
+
+ @Test
+ public void testUpdate() throws WriteFailedException {
+ defineInterfacesContext(Collections.emptyList());
+ customizer.updateCurrentAttributes(IID, acl, acl, writeContext);
+ }
+
+ @Test
+ public void testDelete() throws WriteFailedException {
+ defineInterfacesContext(Collections.emptyList());
+ customizer.deleteCurrentAttributes(IID, acl, writeContext);
+ }
+
+ @Test(expected = WriteFailedException.class)
+ public void testDeleteFailed() throws WriteFailedException {
+ final Interface iface = new InterfaceBuilder().addAugmentation(VppInterfaceAclAugmentation.class,
+ new VppInterfaceAclAugmentationBuilder().setIetfAcl(
+ new IetfAclBuilder().setIngress(
+ new IngressBuilder().setAccessLists(
+ new AccessListsBuilder().setAcl(
+ Collections.singletonList(new AclBuilder().setName(ACL_NAME).setType(ACL_TYPE).build())
+ ).build()
+ ).build()
+ ).build()
+ ).build()
+ ).build();
+ defineInterfacesContext(Collections.singletonList(iface));
+ customizer.deleteCurrentAttributes(IID, acl, writeContext);
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceEthWriterTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceEthWriterTest.java
new file mode 100644
index 000000000..a9b47e060
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceEthWriterTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.acl.common;
+
+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 org.junit.Before;
+import org.junit.Test;
+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 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.InterfaceMode;
+
+public class AceEthWriterTest {
+
+ private AceEthWriter writer;
+ private PacketHandling action;
+ private AceEth aceEth;
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+ writer = new AceEthWriter();
+ 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 testCreateTable() {
+ final int nextTableIndex = 42;
+ final ClassifyAddDelTable request = writer.createTable(aceEth, InterfaceMode.L2, nextTableIndex, 0);
+
+ assertEquals(1, request.isAdd);
+ assertEquals(-1, request.tableIndex);
+ assertEquals(1, request.nbuckets);
+ 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 testCreateClassifySession() {
+ final int tableIndex = 123;
+ final ClassifyAddDelSession request = writer.createSession(action, aceEth, InterfaceMode.L2, tableIndex, 0).get(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);
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIp4WriterTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIp4WriterTest.java
new file mode 100644
index 000000000..5064bb1f7
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIp4WriterTest.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.acl.common;
+
+import static io.fd.hc2vpp.vpp.classifier.write.acl.common.AclTranslator.VLAN_TAG_LEN;
+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 org.junit.Before;
+import org.junit.Test;
+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 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.DestinationPortRangeBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.SourcePortRangeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.InterfaceMode;
+
+public class AceIp4WriterTest {
+
+ private AceIp4Writer writer;
+ private PacketHandling action;
+ private AceIp aceIp;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ writer = new AceIp4Writer();
+ action = new DenyBuilder().setDeny(true).build();
+ aceIp = new AceIpBuilder()
+ .setProtocol((short) 132)
+ .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())
+ .setSourcePortRange(new SourcePortRangeBuilder().setLowerPort(new PortNumber(0x1111)).build())
+ .setDestinationPortRange(new DestinationPortRangeBuilder().setLowerPort(new PortNumber(0x2222)).build())
+ .build();
+ }
+
+ private static void verifyTableRequest(final ClassifyAddDelTable request, final int nextTableIndex,
+ final int vlanTags, final boolean isL2) {
+ assertEquals(1, request.isAdd);
+ assertEquals(-1, request.tableIndex);
+ assertEquals(1, request.nbuckets);
+ 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[] {
+ // L2:
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // dscp:
+ (byte) 0x00, (byte) 0xfc,
+ // protocol:
+ 0, 0, 0, 0, 0, 0, 0, (byte) 0xff, 0, 0,
+ // source address:
+ -1, -1, -1, -1,
+ // destination address:
+ -1, -1, -1, 0,
+ // source and destination port:
+ -1, -1, -1, -1,
+ // padding:
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ if (isL2) {
+ expectedMask[12] = (byte) 0xff;
+ expectedMask[13] = (byte) 0xff;
+ }
+ AceIpWriterTestUtils
+ .assertArrayEqualsWithOffset(expectedMask, expectedMask.length, request.mask, vlanTags * VLAN_TAG_LEN);
+
+ }
+
+ private static void verifySessionRequest(final ClassifyAddDelSession request, final int tableIndex,
+ final int vlanTags, final boolean isL2) {
+ 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,
+ // dscp:
+ 0, (byte) 0x2c,
+ // protocol (132):
+ 0, 0, 0, 0, 0, 0, 0, (byte) 132, 0, 0,
+ // source address:
+ 1, 2, 3, 4,
+ // destination address:
+ 1, 2, 4, 0,
+ // source and destination port:
+ 0x11, 0x11, 0x22, 0x22,
+ // padding:
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ if (isL2) {
+ expectedMatch[12] = (byte) 0x08;
+ expectedMatch[13] = (byte) 0x00;
+ }
+ AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMatch, expectedMatch.length, request.match, vlanTags * VLAN_TAG_LEN);
+
+ }
+
+ @Test
+ public void testCreateTable() throws Exception {
+ final int nextTableIndex = 42;
+ final ClassifyAddDelTable request = writer.createTable(aceIp, InterfaceMode.L3, nextTableIndex, 0);
+ verifyTableRequest(request, nextTableIndex, 0, false);
+ }
+
+ @Test
+ public void testCreateTableForL2Interface() throws Exception {
+ final int nextTableIndex = 42;
+ final ClassifyAddDelTable request = writer.createTable(aceIp, InterfaceMode.L2, nextTableIndex, 0);
+ verifyTableRequest(request, nextTableIndex, 0, true);
+ }
+
+ @Test
+ public void testCreateTable1VlanTag() throws Exception {
+ final int nextTableIndex = 42;
+ final int vlanTags = 1;
+ final ClassifyAddDelTable request = writer.createTable(aceIp, InterfaceMode.L3, nextTableIndex, vlanTags);
+ verifyTableRequest(request, nextTableIndex, vlanTags, false);
+ }
+
+ @Test
+ public void testCreateTable2VlanTags() throws Exception {
+ final int nextTableIndex = 42;
+ final int vlanTags = 2;
+ final ClassifyAddDelTable request = writer.createTable(aceIp, InterfaceMode.L3, nextTableIndex, vlanTags);
+ verifyTableRequest(request, nextTableIndex, vlanTags, false);
+ }
+
+ @Test
+ public void testCreateClassifySession() throws Exception {
+ final int tableIndex = 123;
+ final ClassifyAddDelSession request = writer.createSession(action, aceIp, InterfaceMode.L3, tableIndex, 0).get(0);
+ verifySessionRequest(request, tableIndex, 0, false);
+ }
+
+ @Test
+ public void testCreateClassifySessionForL2Interface() throws Exception {
+ final int tableIndex = 123;
+ final ClassifyAddDelSession request = writer.createSession(action, aceIp, InterfaceMode.L2, tableIndex, 0).get(0);
+ verifySessionRequest(request, tableIndex, 0, true);
+ }
+
+ @Test
+ public void testCreateClassifySession1VlanTag() throws Exception {
+ final int tableIndex = 123;
+ final int vlanTags = 1;
+ final ClassifyAddDelSession request = writer.createSession(action, aceIp, InterfaceMode.L3, tableIndex, vlanTags).get(0);
+ verifySessionRequest(request, tableIndex, vlanTags, false);
+ }
+
+ @Test
+ public void testCreateClassifySession2VlanTags() throws Exception {
+ final int tableIndex = 123;
+ final int vlanTags = 2;
+ final ClassifyAddDelSession request = writer.createSession(action, aceIp, InterfaceMode.L3, tableIndex, vlanTags).get(0);
+
+ verifySessionRequest(request, tableIndex, vlanTags, false);
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIp6WriterTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIp6WriterTest.java
new file mode 100644
index 000000000..4fee862a7
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIp6WriterTest.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.acl.common;
+
+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 org.junit.Before;
+import org.junit.Test;
+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 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.DestinationPortRangeBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.SourcePortRangeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.InterfaceMode;
+
+public class AceIp6WriterTest {
+
+ private AceIp6Writer writer;
+ private PacketHandling action;
+ private AceIp aceIp;
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+ writer = new AceIp6Writer();
+ action = new DenyBuilder().setDeny(true).build();
+ aceIp = new AceIpBuilder()
+ .setProtocol((short) 132)
+ .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())
+ .setSourcePortRange(new SourcePortRangeBuilder().setLowerPort(new PortNumber(0x1111)).build())
+ .setDestinationPortRange(new DestinationPortRangeBuilder().setLowerPort(new PortNumber(0x2222)).build())
+ .build();
+ }
+
+
+ private static void verifyTableRequest(final ClassifyAddDelTable request, final int nextTableIndex,
+ final int vlanTags, final boolean isL2) {
+ assertEquals(1, request.isAdd);
+ assertEquals(-1, request.tableIndex);
+ assertEquals(1, request.nbuckets);
+ assertEquals(nextTableIndex, request.nextTableIndex);
+ assertEquals(0, request.skipNVectors);
+ assertEquals(vlanTags == 2 ? 5 : 4, 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,
+ // dscp, flow:
+ (byte) 0x0f, (byte) 0xcf, (byte) 0xff, (byte) 0xff,
+ // protocol:
+ 0, 0, (byte) 0xff, 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,
+ // source and destination port:
+ -1, -1, -1, -1,
+ // padding to multiple of 16B:
+ 0, 0, 0, 0, 0, 0
+ };
+
+ if (isL2) {
+ expectedMask[12] = (byte) 0xff;
+ expectedMask[13] = (byte) 0xff;
+ }
+ AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMask, vlanTags == 2 ? 80 : 64, request.mask, vlanTags * AclTranslator.VLAN_TAG_LEN);
+ }
+
+ private static void verifySessionRequest(final ClassifyAddDelSession request, final int tableIndex,
+ final int vlanTags, final boolean isL2) {
+ 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,
+ // dscp(11), flow(123):
+ (byte) 0x02, (byte) 0xc0, (byte) 0x00, (byte) 0x7b,
+ // protocol (132):
+ 0, 0, (byte) 132, 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,
+ // source and destination port:
+ 0x11, 0x11, 0x22, 0x22,
+ // padding to multiple of 16B:
+ 0, 0, 0, 0, 0, 0
+ };
+
+ if (isL2) {
+ expectedMatch[12] = (byte) 0x86;
+ expectedMatch[13] = (byte) 0xdd;
+ }
+ AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMatch, vlanTags == 2 ? 80 : 64, request.match, vlanTags * AclTranslator.VLAN_TAG_LEN);
+
+ }
+
+ @Test
+ public void testCreateTable() {
+ final int nextTableIndex = 42;
+ final ClassifyAddDelTable request =
+ writer.createTable(aceIp, InterfaceMode.L3, nextTableIndex, 0);
+ verifyTableRequest(request, nextTableIndex, 0, false);
+ }
+
+ @Test
+ public void testCreateTableForL2Interface() {
+ final int nextTableIndex = 42;
+ final ClassifyAddDelTable request =
+ writer.createTable(aceIp, InterfaceMode.L2, nextTableIndex, 0);
+ verifyTableRequest(request, nextTableIndex, 0, true);
+ }
+
+ @Test
+ public void testCreateTable1VlanTag() {
+ final int nextTableIndex = 42;
+ final int vlanTags = 1;
+ final ClassifyAddDelTable request =
+ writer.createTable(aceIp, InterfaceMode.L3, nextTableIndex, vlanTags);
+ verifyTableRequest(request, nextTableIndex, vlanTags, false);
+ }
+
+ @Test
+ public void testCreateTable2VlanTags() {
+ final int nextTableIndex = 42;
+ final int vlanTags = 2;
+ final ClassifyAddDelTable request =
+ writer.createTable(aceIp, InterfaceMode.L3, nextTableIndex, vlanTags);
+ verifyTableRequest(request, nextTableIndex, vlanTags, false);
+ }
+
+ @Test
+ public void testCreateClassifySession() {
+ final int tableIndex = 123;
+ final ClassifyAddDelSession request =
+ writer.createSession(action, aceIp, InterfaceMode.L3, tableIndex, 0).get(0);
+ verifySessionRequest(request, tableIndex, 0, false);
+ }
+
+ @Test
+ public void testCreateClassifySessionForL2Interface() {
+ final int tableIndex = 123;
+ final ClassifyAddDelSession request =
+ writer.createSession(action, aceIp, InterfaceMode.L2, tableIndex, 0).get(0);
+ verifySessionRequest(request, tableIndex, 0, true);
+ }
+
+ @Test
+ public void testCreateClassifySession1VlanTag() {
+ final int tableIndex = 123;
+ final int vlanTags = 1;
+ final ClassifyAddDelSession request =
+ writer.createSession(action, aceIp, InterfaceMode.L3, tableIndex, vlanTags).get(0);
+ verifySessionRequest(request, tableIndex, vlanTags, false);
+ }
+
+ @Test
+ public void testCreateClassifySession2VlanTags() {
+ final int tableIndex = 123;
+ final int vlanTags = 2;
+ final ClassifyAddDelSession request =
+ writer.createSession(action, aceIp, InterfaceMode.L3, tableIndex, vlanTags).get(0);
+ verifySessionRequest(request, tableIndex, vlanTags, false);
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIpAndEthWriterTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIpAndEthWriterTest.java
new file mode 100644
index 000000000..56cad9140
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIpAndEthWriterTest.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.acl.common;
+
+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 org.junit.Before;
+import org.junit.Test;
+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.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.DestinationPortRangeBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.SourcePortRangeBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.InterfaceMode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpAndEth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpAndEthBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.and.eth.AceIpAndEthNodesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.and.eth.ace.ip.and.eth.nodes.ace.ip.version.AceIpv4Builder;
+
+public class AceIpAndEthWriterTest {
+
+ private AceIpAndEthWriter writer;
+ private PacketHandling action;
+ private AceIpAndEth ace;
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+ writer = new AceIpAndEthWriter();
+ action = new DenyBuilder().setDeny(true).build();
+ ace = new AceIpAndEthBuilder().setAceIpAndEthNodes(new AceIpAndEthNodesBuilder()
+ .setDestinationMacAddress(new MacAddress("11:22:33:44:55:66"))
+ .setSourceMacAddress(new MacAddress("aa:bb:cc:dd:ee:ff"))
+ .setAceIpVersion(new AceIpv4Builder()
+ .setSourceIpv4Network(new Ipv4Prefix("1.2.3.4/32")).build())
+ .setSourcePortRange(new SourcePortRangeBuilder().setLowerPort(new PortNumber(0x1111)).build())
+ .setDestinationPortRange(new DestinationPortRangeBuilder().setLowerPort(new PortNumber(0x2222)).build())
+ .build()).build();
+ }
+
+ @Test
+ public void testCreateTable() {
+ final int nextTableIndex = 42;
+ final ClassifyAddDelTable request = writer.createTable(ace, InterfaceMode.L2, nextTableIndex, 0);
+
+ assertEquals(1, request.isAdd);
+ assertEquals(-1, request.tableIndex);
+ assertEquals(1, request.nbuckets);
+ assertEquals(nextTableIndex, request.nextTableIndex);
+ assertEquals(0, request.skipNVectors);
+ assertEquals(3, request.matchNVectors);
+ assertEquals(AceEthWriter.TABLE_MEM_SIZE, request.memorySize);
+
+ byte[] expectedMask = new byte[] {
+ // destination MAC:
+ -1, -1, -1, -1, -1, -1,
+ // source MAC:
+ -1, -1, -1, -1, -1, -1,
+ // ether type:
+ -1, -1,
+ // IP header
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // source address:
+ -1, -1, -1, -1,
+ // destination address:
+ 0, 0, 0, 0,
+ // source and destination port:
+ -1, -1, -1, -1,
+ // padding:
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+ assertArrayEquals(expectedMask, request.mask);
+ }
+
+ @Test
+ public void testCreateClassifySession() {
+ final int tableIndex = 123;
+ final ClassifyAddDelSession request = writer.createSession(action, ace, InterfaceMode.L2, tableIndex, 0).get(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,
+ // ether type (IP4):
+ 0x08, 0,
+ // IP header
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // source address:
+ 1, 2, 3, 4,
+ // destination address:
+ 0, 0, 0, 0,
+ // source and destination port:
+ 0x11, 0x11, 0x22, 0x22,
+ // padding:
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+ assertArrayEquals(expectedMatch, request.match);
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIpWriterTestUtils.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AceIpWriterTestUtils.java
new file mode 100644
index 000000000..257840169
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/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.hc2vpp.vpp.classifier.write.acl.common;
+
+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 int expectedLength, final byte[] actual,
+ final int offset) {
+ byte[] expected = new byte[expectedLength];
+ System.arraycopy(baseExpected, 0, expected, offset, Math.min(baseExpected.length, expectedLength-offset));
+
+ assertArrayEquals(expected, actual);
+ }
+}
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AclTableContextManagerImplTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AclTableContextManagerImplTest.java
new file mode 100644
index 000000000..f2b73b44b
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/AclTableContextManagerImplTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.acl.common;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import io.fd.honeycomb.translate.MappingContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.MappingTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.mapping.table.MappingEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.mapping.table.MappingEntryBuilder;
+
+public class AclTableContextManagerImplTest {
+
+ private AclTableContextManagerImpl ctx;
+ @Mock
+ private MappingContext mappingContext;
+ private static final int INDEX = 42;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ ctx = new AclTableContextManagerImpl(MappingTable.Direction.Ingress);
+ }
+
+ @Test
+ public void testAddEntry() throws Exception {
+ final MappingEntry entry =
+ new MappingEntryBuilder().setL2TableId(1).setIp4TableId(2).setIp6TableId(3).setIndex(INDEX).build();
+ ctx.addEntry(entry, mappingContext);
+ verify(mappingContext).put(ctx.getId(INDEX), entry);
+ }
+
+ @Test
+ public void testRemoveEntry() throws Exception {
+ ctx.removeEntry(INDEX, mappingContext);
+ verify(mappingContext).delete(ctx.getId(INDEX));
+ }
+
+ @Test
+ public void testReadEntry() throws Exception {
+ ctx.getEntry(INDEX, mappingContext);
+ verify(mappingContext).read(ctx.getId(INDEX));
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/PortPairTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/PortPairTest.java
new file mode 100644
index 000000000..9126d8c01
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/common/PortPairTest.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.acl.common;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.hasSize;
+
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.DestinationPortRange;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.DestinationPortRangeBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.SourcePortRange;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.SourcePortRangeBuilder;
+
+public class PortPairTest {
+
+ @Test
+ public void testSingleSrc() {
+ final SourcePortRange src = new SourcePortRangeBuilder().setLowerPort(new PortNumber(123)).build();
+ final List<PortPair> portPairs = PortPair.fromRange(src, null);
+ assertThat(portPairs, hasSize(1));
+ assertThat(portPairs, contains(new PortPair(123, null)));
+ }
+
+ @Test
+ public void testSrcRange() {
+ final SourcePortRange src = new SourcePortRangeBuilder()
+ .setLowerPort(new PortNumber(123))
+ .setUpperPort(new PortNumber(125)).build();
+ final List<PortPair> portPairs = PortPair.fromRange(src, null);
+ assertThat(portPairs, hasSize(3));
+ assertThat(portPairs, contains(new PortPair(123, null), new PortPair(124, null), new PortPair(125, null)));
+ }
+
+ @Test
+ public void testSrcRangeWithDst() {
+ final SourcePortRange src = new SourcePortRangeBuilder()
+ .setLowerPort(new PortNumber(123))
+ .setUpperPort(new PortNumber(125)).build();
+ final DestinationPortRange dst = new DestinationPortRangeBuilder().setLowerPort(new PortNumber(111)).build();
+ final List<PortPair> portPairs = PortPair.fromRange(src, dst);
+ assertThat(portPairs, hasSize(3));
+ assertThat(portPairs, contains(new PortPair(123, 111), new PortPair(124, 111), new PortPair(125, 111)));
+ }
+
+ @Test
+ public void testSingleDst() {
+ final DestinationPortRange dst = new DestinationPortRangeBuilder().setLowerPort(new PortNumber(123)).build();
+ final List<PortPair> portPairs = PortPair.fromRange(null, dst);
+ assertThat(portPairs, hasSize(1));
+ assertThat(portPairs, contains(new PortPair(null, 123)));
+ }
+
+ @Test
+ public void testDstRange() {
+ final DestinationPortRange dst = new DestinationPortRangeBuilder()
+ .setLowerPort(new PortNumber(10))
+ .setUpperPort(new PortNumber(11)).build();
+ final List<PortPair> portPairs = PortPair.fromRange(null, dst);
+ assertThat(portPairs, hasSize(2));
+ assertThat(portPairs, contains(new PortPair(null, 10), new PortPair(null, 11)));
+ }
+
+ @Test
+ public void testDstRangeWithSrc() {
+ final SourcePortRange src = new SourcePortRangeBuilder().setLowerPort(new PortNumber(111)).build();
+ final DestinationPortRange dst = new DestinationPortRangeBuilder()
+ .setLowerPort(new PortNumber(10))
+ .setUpperPort(new PortNumber(11)).build();
+ final List<PortPair> portPairs = PortPair.fromRange(src, dst);
+ assertThat(portPairs, hasSize(2));
+ assertThat(portPairs, contains(new PortPair(111, 10), new PortPair(111, 11)));
+ }
+
+ @Test
+ public void testSinglePair() {
+ final SourcePortRange src = new SourcePortRangeBuilder().setLowerPort(new PortNumber(123)).build();
+ final DestinationPortRange dst = new DestinationPortRangeBuilder().setLowerPort(new PortNumber(321)).build();
+ final List<PortPair> portPairs = PortPair.fromRange(src, dst);
+ assertThat(portPairs, hasSize(1));
+ assertThat(portPairs, contains(new PortPair(123, 321)));
+ }
+
+ @Test
+ public void testCartesianProduct() {
+ final SourcePortRange src = new SourcePortRangeBuilder()
+ .setLowerPort(new PortNumber(1))
+ .setUpperPort(new PortNumber(2)).build();
+ final DestinationPortRange dst = new DestinationPortRangeBuilder()
+ .setLowerPort(new PortNumber(1))
+ .setUpperPort(new PortNumber(3)).build();
+ final List<PortPair> portPairs = PortPair.fromRange(src, dst);
+ assertThat(portPairs, hasSize(6));
+ assertThat(portPairs,
+ contains(new PortPair(1, 1), new PortPair(1, 2), new PortPair(1, 3), new PortPair(2, 1), new PortPair(2, 2),
+ new PortPair(2, 3)));
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/egress/EgressIetfAclWriterTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/egress/EgressIetfAclWriterTest.java
new file mode 100644
index 000000000..911350562
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/egress/EgressIetfAclWriterTest.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.hc2vpp.vpp.classifier.write.acl.egress;
+
+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.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.vpp.classifier.write.acl.common.AclTableContextManager;
+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.ClassifySetInterfaceL2Tables;
+import io.fd.vpp.jvpp.core.dto.ClassifySetInterfaceL2TablesReply;
+import java.util.Collections;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.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.PermitBuilder;
+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.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.mapping.table.MappingEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.InterfaceMode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.AccessLists;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.AccessListsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.access.lists.AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.ietf.acl.Egress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.ietf.acl.EgressBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class EgressIetfAclWriterTest extends WriterCustomizerTest {
+
+ private static final int IF_INDEX = 1;
+ private static final String ACL_NAME = "acl1";
+ private static final Class<? extends AclBase> ACL_TYPE = EthAcl.class;
+
+ private EgressIetfAclWriter writer;
+ @Mock
+ private AclTableContextManager aclCtx;
+ @Mock
+ private InstanceIdentifier<?> id;
+
+ private static ClassifyAddDelTable classifyAddDelTable(final int tableIndex) {
+ final ClassifyAddDelTable reply = new ClassifyAddDelTable();
+ reply.tableIndex = tableIndex;
+ reply.delChain = 1;
+ return reply;
+ }
+
+ @Override
+ protected void setUpTest() throws Exception {
+ writer = new EgressIetfAclWriter(api, aclCtx);
+ }
+
+ private ClassifySetInterfaceL2Tables classifySetInterfaceL2TablesRequest() {
+ final ClassifySetInterfaceL2Tables request = new ClassifySetInterfaceL2Tables();
+ request.isInput = 0;
+ request.ip4TableIndex = -1;
+ request.ip6TableIndex = -1;
+ request.otherTableIndex = -1;
+ request.swIfIndex = IF_INDEX;
+ return request;
+ }
+
+ @Test
+ public void testDeleteAcl() throws Exception {
+ when(api.classifyAddDelTable(any())).thenReturn(future(new ClassifyAddDelTableReply()));
+ when(api.classifySetInterfaceL2Tables(any())).thenReturn(future(new ClassifySetInterfaceL2TablesReply()));
+ when(aclCtx.getEntry(IF_INDEX, mappingContext)).thenReturn(Optional.of(
+ new MappingEntryBuilder()
+ .setIndex(IF_INDEX)
+ .setL2TableId(1)
+ .setIp4TableId(2)
+ .setIp6TableId(3)
+ .build()));
+
+ writer.deleteAcl(id, IF_INDEX, mappingContext);
+
+ verify(api).classifySetInterfaceL2Tables(classifySetInterfaceL2TablesRequest());
+ verify(api).classifyAddDelTable(classifyAddDelTable(1));
+ verify(api).classifyAddDelTable(classifyAddDelTable(2));
+ verify(api).classifyAddDelTable(classifyAddDelTable(3));
+ verify(aclCtx).removeEntry(IF_INDEX, mappingContext);
+ }
+
+ @Test
+ public void testWrite() throws Exception {
+ when(api.classifyAddDelTable(any())).thenReturn(future(new ClassifyAddDelTableReply()));
+ when(api.classifyAddDelSession(any())).thenReturn(future(new ClassifyAddDelSessionReply()));
+ when(api.classifySetInterfaceL2Tables(any())).thenReturn(future(new ClassifySetInterfaceL2TablesReply()));
+
+ final Egress
+ acl = new EgressBuilder().setAccessLists(
+ new AccessListsBuilder().setAcl(
+ Collections.singletonList(new AclBuilder()
+ .setName(ACL_NAME)
+ .setType(ACL_TYPE)
+ .build())
+ ).setMode(InterfaceMode.L2).build()
+ ).build();
+
+ final AccessLists accessLists = acl.getAccessLists();
+
+ 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 AceIpv4Builder().build())
+ .setProtocol((short) 1)
+ .build()
+ ).build())
+ .setActions(new ActionsBuilder().setPacketHandling(new PermitBuilder().build()).build())
+ .build())).build()
+ ).build()
+
+ ));
+
+ writer.write(id, IF_INDEX, accessLists.getAcl(), accessLists.getDefaultAction(), accessLists.getMode(),
+ writeContext, mappingContext);
+
+ final ClassifySetInterfaceL2Tables request = new ClassifySetInterfaceL2Tables();
+ request.isInput = 0;
+ request.swIfIndex = IF_INDEX;
+ request.otherTableIndex = -1;
+ request.ip4TableIndex = 0;
+ request.ip6TableIndex = -1;
+ verify(api).classifySetInterfaceL2Tables(request);
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/egress/IetfAclCustomizerTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/egress/IetfAclCustomizerTest.java
new file mode 100644
index 000000000..96e638548
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/egress/IetfAclCustomizerTest.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.acl.egress;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.vpp.classifier.write.acl.common.IetfAclWriter;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import java.util.Collections;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AclBase;
+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.vpp._interface.acl.rev161214.VppInterfaceAclAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.InterfaceMode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.MixedAcl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.AccessLists;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.AccessListsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.access.lists.AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.IetfAcl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.ietf.acl.Egress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.ietf.acl.EgressBuilder;
+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<Egress> IID =
+ InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation(
+ VppInterfaceAclAugmentation.class).child(IetfAcl.class).child(Egress.class);
+ private static final String ACL_NAME = "acl1";
+ private static final Class<? extends AclBase> ACL_TYPE = MixedAcl.class;
+
+ @Mock
+ private IetfAclWriter aclWriter;
+ private IetfAclCustomizer customizer;
+
+ private static Egress acl(final InterfaceMode mode) {
+ return new EgressBuilder().setAccessLists(
+ new AccessListsBuilder().setAcl(
+ Collections.singletonList(new AclBuilder()
+ .setName(ACL_NAME)
+ .setType(ACL_TYPE)
+ .build())
+ ).setMode(mode)
+ .build()
+ ).build();
+ }
+
+ @Override
+ protected void setUpTest() {
+ customizer = new IetfAclCustomizer(aclWriter, new NamingContext("prefix", IFC_TEST_INSTANCE));
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
+ }
+
+ private void verifyWrite(final AccessLists accessLists) throws WriteFailedException {
+ verify(aclWriter)
+ .write(IID, IF_INDEX, accessLists.getAcl(), accessLists.getDefaultAction(), accessLists.getMode(),
+ writeContext, mappingContext);
+ }
+
+ private void verifyDelete() throws WriteFailedException {
+ verify(aclWriter).deleteAcl(IID, IF_INDEX, mappingContext);
+ }
+
+ @Test
+ public void testWriteL3() throws Exception {
+ customizer.writeCurrentAttributes(IID, acl(InterfaceMode.L3), writeContext);
+ verifyZeroInteractions(aclWriter);
+ }
+
+ @Test
+ public void testWriteL2() throws Exception {
+ final Egress acl = acl(InterfaceMode.L2);
+ customizer.writeCurrentAttributes(IID, acl, writeContext);
+ verifyWrite(acl.getAccessLists());
+ }
+
+ @Test
+ public void testUpdate() throws Exception {
+ final Egress aclBefore = acl(InterfaceMode.L3);
+ final Egress aclAfter = acl(InterfaceMode.L2);
+ customizer.updateCurrentAttributes(IID, aclBefore, aclAfter, writeContext);
+ verifyDelete();
+ verifyWrite(aclAfter.getAccessLists());
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ final Egress acl = acl(InterfaceMode.L2);
+ customizer.deleteCurrentAttributes(IID, acl, writeContext);
+ verifyDelete();
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/egress/SubInterfaceIetfAclCustomizerTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/egress/SubInterfaceIetfAclCustomizerTest.java
new file mode 100644
index 000000000..2370c25b6
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/egress/SubInterfaceIetfAclCustomizerTest.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.acl.egress;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.vpp.classifier.write.acl.common.IetfAclWriter;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import java.util.Collections;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AclBase;
+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.vpp.classifier.acl.rev161214.InterfaceMode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.MixedAcl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.AccessLists;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.AccessListsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.access.lists.AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.IetfAcl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.ietf.acl.Egress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.ietf.acl.EgressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.subinterface.acl.rev161214.VppSubinterfaceAclAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.SubInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceKey;
+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.0";
+ private static final int SUBIF_INDEX = 11;
+ private static final long SUBIF_ID = 0;
+ private static final InstanceIdentifier<Egress> 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))
+ .augmentation(VppSubinterfaceAclAugmentation.class)
+ .child(IetfAcl.class).child(Egress.class);
+ private static final String ACL_NAME = "acl1";
+ private static final Class<? extends AclBase> ACL_TYPE = MixedAcl.class;
+
+ @Mock
+ private IetfAclWriter aclWriter;
+ private SubInterfaceIetfAclCustomizer customizer;
+
+ private static Egress acl(final InterfaceMode mode) {
+ return new EgressBuilder().setAccessLists(
+ new AccessListsBuilder().setAcl(
+ Collections.singletonList(new AclBuilder()
+ .setName(ACL_NAME)
+ .setType(ACL_TYPE)
+ .build())
+ ).setMode(mode)
+ .build()
+ ).build();
+ }
+
+ @Override
+ protected void setUpTest() {
+ customizer = new SubInterfaceIetfAclCustomizer(aclWriter, new NamingContext("prefix", IFC_TEST_INSTANCE));
+ 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()
+ ));
+ }
+
+ private void verifyWrite(final AccessLists accessLists) throws WriteFailedException {
+ verify(aclWriter)
+ .write(IID, SUBIF_INDEX, accessLists.getAcl(), accessLists.getDefaultAction(), accessLists.getMode(),
+ writeContext, 0, mappingContext);
+ }
+
+ private void verifyDelete() throws WriteFailedException {
+ verify(aclWriter).deleteAcl(IID, SUBIF_INDEX, mappingContext);
+ }
+
+ @Test
+ public void testWriteL3() throws Exception {
+ customizer.writeCurrentAttributes(IID, acl(InterfaceMode.L3), writeContext);
+ verifyZeroInteractions(aclWriter);
+ }
+
+ @Test
+ public void testWriteL2() throws Exception {
+ final Egress acl = acl(InterfaceMode.L2);
+ customizer.writeCurrentAttributes(IID, acl, writeContext);
+ verifyWrite(acl.getAccessLists());
+ }
+
+ @Test
+ public void testUpdate() throws Exception {
+ final Egress aclBefore = acl(InterfaceMode.L3);
+ final Egress aclAfter = acl(InterfaceMode.L2);
+ customizer.updateCurrentAttributes(IID, aclBefore, aclAfter, writeContext);
+ verifyDelete();
+ verifyWrite(aclAfter.getAccessLists());
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ final Egress acl = acl(InterfaceMode.L2);
+ customizer.deleteCurrentAttributes(IID, acl, writeContext);
+ verifyDelete();
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/ingress/IetfAclCustomizerTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/ingress/IetfAclCustomizerTest.java
new file mode 100644
index 000000000..58f7ea1a2
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/ingress/IetfAclCustomizerTest.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.acl.ingress;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.vpp.classifier.write.acl.common.AclTableContextManager;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession;
+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.InputAclSetInterface;
+import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply;
+import java.util.Arrays;
+import java.util.Collections;
+import org.junit.Test;
+import org.mockito.ArgumentMatcher;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+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.Ace;
+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.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.Deny;
+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.actions.packet.handling.Permit;
+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.PermitBuilder;
+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.vpp._interface.acl.rev161214.VppInterfaceAclAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.mapping.table.MappingEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.AccessListsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.access.lists.AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.IetfAcl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.ietf.acl.Ingress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.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<Ingress> IID =
+ InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation(
+ VppInterfaceAclAugmentation.class).child(IetfAcl.class).child(Ingress.class);
+ private static final String ACL_NAME = "acl1";
+ private static final Class<? extends AclBase> ACL_TYPE = EthAcl.class;
+
+ @Mock
+ private AclTableContextManager aclCtx;
+
+ private IetfAclCustomizer customizer;
+ private Ingress acl;
+ private int DENY = 0;
+ private int PERMIT = -1;
+
+ private static Ace ace(final PacketHandling action) {
+ return new AceBuilder()
+ .setMatches(new MatchesBuilder().setAceType(
+ new AceIpBuilder()
+ .setAceIpVersion(new AceIpv6Builder().build())
+ .setProtocol((short) 1)
+ .build()
+ ).build())
+ .setActions(new ActionsBuilder().setPacketHandling(action).build())
+ .build();
+ }
+
+ private static InputAclSetInterface inputAclSetInterfaceDeleteRequest() {
+ final InputAclSetInterface request = new InputAclSetInterface();
+ request.swIfIndex = IF_INDEX;
+ 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;
+ reply.delChain = 1;
+ 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;
+ }
+
+ @Override
+ protected void setUpTest() {
+ customizer = new IetfAclCustomizer(new IngressIetfAclWriter(api, aclCtx), 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(Arrays.asList(ace(permit()), ace(permit()), ace(deny())
+ )).build()
+ ).build()
+
+ ));
+ when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
+
+ customizer.writeCurrentAttributes(IID, acl, writeContext);
+
+ final InOrder inOrder = Mockito.inOrder(api);
+ inOrder.verify(api).classifyAddDelTable(argThat(actionOnMissEquals(DENY))); // default action
+ inOrder.verify(api).classifyAddDelTable(any());
+ inOrder.verify(api).classifyAddDelSession(argThat(actionOnHitEquals(DENY))); // last deny ACE
+ inOrder.verify(api).classifyAddDelTable(any());
+ inOrder.verify(api).classifyAddDelSession(argThat(actionOnHitEquals(PERMIT)));
+ inOrder.verify(api).classifyAddDelTable(any());
+ inOrder.verify(api).classifyAddDelSession(argThat(actionOnHitEquals(PERMIT)));
+ inOrder.verify(api).inputAclSetInterface(inputAclSetInterfaceWriteRequest()); // assignment
+ }
+
+ private ArgumentMatcher<ClassifyAddDelTable> actionOnMissEquals(final int action) {
+ return table -> table.missNextIndex == action;
+ }
+
+ private ArgumentMatcher<ClassifyAddDelSession> actionOnHitEquals(final int action) {
+ return session -> session.hitNextIndex == action;
+ }
+
+ private Deny deny() {
+ return new DenyBuilder().build();
+ }
+
+ private Permit permit() {
+ return new PermitBuilder().build();
+ }
+
+ @Test
+ public void testDelete() throws WriteFailedException {
+ when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
+ when(api.classifyAddDelTable(any())).thenReturn(future(new ClassifyAddDelTableReply()));
+ when(aclCtx.getEntry(IF_INDEX, mappingContext)).thenReturn(Optional.of(
+ new MappingEntryBuilder()
+ .setIndex(IF_INDEX)
+ .setL2TableId(1)
+ .setIp4TableId(2)
+ .setIp6TableId(3)
+ .build()));
+
+ customizer.deleteCurrentAttributes(IID, acl, writeContext);
+
+ final ClassifyTableByInterface expectedRequest = new ClassifyTableByInterface();
+ expectedRequest.swIfIndex = IF_INDEX;
+ verify(api).inputAclSetInterface(inputAclSetInterfaceDeleteRequest());
+ verify(api).classifyAddDelTable(classifyAddDelTable(1));
+ verify(api).classifyAddDelTable(classifyAddDelTable(2));
+ verify(api).classifyAddDelTable(classifyAddDelTable(3));
+ }
+} \ No newline at end of file
diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/ingress/SubInterfaceAclCustomizerTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/ingress/SubInterfaceAclCustomizerTest.java
new file mode 100644
index 000000000..b606b71cc
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/ingress/SubInterfaceAclCustomizerTest.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.acl.ingress;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+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.vpp.classifier.acl.rev161214.acl.base.attributes.Ip4Acl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.acl.base.attributes.Ip4AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.acl.base.attributes.Ip6Acl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.acl.base.attributes.Ip6AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.Acl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.acl.Ingress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.acl.IngressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.subinterface.acl.rev161214.VppSubinterfaceAclAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.SubInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceKey;
+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<Ingress> 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))
+ .augmentation(VppSubinterfaceAclAugmentation.class)
+ .child(Acl.class).child(Ingress.class);
+
+ @Mock
+ private VppClassifierContextManager classifyTableContext;
+
+ private SubInterfaceAclCustomizer customizer;
+
+ @Override
+ protected void setUpTest() 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.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.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/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/ingress/SubInterfaceIetfAclCustomizerTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/ingress/SubInterfaceIetfAclCustomizerTest.java
new file mode 100644
index 000000000..d6e7d4010
--- /dev/null
+++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/acl/ingress/SubInterfaceIetfAclCustomizerTest.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vpp.classifier.write.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.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.vpp.classifier.write.acl.IetfAclWriter;
+import io.fd.hc2vpp.vpp.classifier.write.acl.common.AclTableContextManager;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterface;
+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.mockito.Mock;
+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.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.mapping.table.MappingEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.AccessListsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.ietf.acl.base.attributes.access.lists.AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.IetfAcl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.ietf.acl.Ingress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.acl.rev161214.vpp.acl.attributes.ietf.acl.IngressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.subinterface.acl.rev161214.VppSubinterfaceAclAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.SubInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceKey;
+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<Ingress> 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))
+ .augmentation(VppSubinterfaceAclAugmentation.class)
+ .child(IetfAcl.class).child(Ingress.class);
+ private static final String ACL_NAME = "acl1";
+ private static final Class<? extends AclBase> ACL_TYPE = EthAcl.class;
+
+ private SubInterfaceIetfAclCustomizer customizer;
+ private Ingress acl;
+
+ @Mock
+ private AclTableContextManager aclCtx;
+
+ 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;
+ }
+
+ private static InputAclSetInterface inputAclSetInterfaceDeleteRequest() {
+ final InputAclSetInterface request = new InputAclSetInterface();
+ request.swIfIndex = SUBIF_INDEX;
+ request.l2TableIndex = -1;
+ request.ip4TableIndex = -1;
+ request.ip6TableIndex = -1;
+ return request;
+ }
+
+ @Override
+ protected void setUpTest() {
+ customizer =
+ new SubInterfaceIetfAclCustomizer(new IngressIetfAclWriter(api, aclCtx), 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 testDelete() throws WriteFailedException {
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
+ defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
+ when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
+ when(aclCtx.getEntry(SUBIF_INDEX, mappingContext)).thenReturn(Optional.of(
+ new MappingEntryBuilder()
+ .setIndex(SUBIF_INDEX)
+ .setL2TableId(-1)
+ .setIp4TableId(-1)
+ .setIp6TableId(-1)
+ .build()));
+
+ customizer.deleteCurrentAttributes(IID, acl, writeContext);
+
+ final ClassifyTableByInterface expectedRequest = new ClassifyTableByInterface();
+ expectedRequest.swIfIndex = SUBIF_INDEX;
+ verify(api).inputAclSetInterface(inputAclSetInterfaceDeleteRequest());
+ }
+
+ @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