2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.translate.v3po.interfaces.acl.ingress;
19 import static io.fd.honeycomb.translate.v3po.interfaces.acl.ingress.AbstractAceWriter.VLAN_TAG_LEN;
20 import static org.junit.Assert.assertEquals;
21 import static org.mockito.MockitoAnnotations.initMocks;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.Mock;
26 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;
27 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;
28 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;
29 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;
30 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;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
33 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession;
34 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable;
35 import io.fd.vpp.jvpp.core.dto.InputAclSetInterface;
36 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
38 public class AceIp4WriterTest {
41 private FutureJVppCore jvpp;
42 private AceIp4Writer writer;
43 private PacketHandling action;
47 public void setUp() throws Exception {
49 writer = new AceIp4Writer(jvpp);
50 action = new DenyBuilder().setDeny(true).build();
51 aceIp = new AceIpBuilder()
52 .setProtocol((short) 4)
53 .setDscp(new Dscp((short) 11))
54 .setAceIpVersion(new AceIpv4Builder()
55 .setSourceIpv4Network(new Ipv4Prefix("1.2.3.4/32"))
56 .setDestinationIpv4Network(new Ipv4Prefix("1.2.4.5/24"))
61 private static void verifyTableRequest(final ClassifyAddDelTable request, final int nextTableIndex,
63 assertEquals(1, request.isAdd);
64 assertEquals(-1, request.tableIndex);
65 assertEquals(1, request.nbuckets);
66 assertEquals(-1, request.missNextIndex);
67 assertEquals(nextTableIndex, request.nextTableIndex);
68 assertEquals(0, request.skipNVectors);
69 assertEquals(AceIp4Writer.MATCH_N_VECTORS, request.matchNVectors);
70 assertEquals(AceIp4Writer.TABLE_MEM_SIZE, request.memorySize);
72 byte[] expectedMask = new byte[] {
73 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0xf0, (byte) 0xfc,
74 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1,
75 -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
77 AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMask, request.mask, vlanTags * VLAN_TAG_LEN);
81 private static void verifySessionRequest(final ClassifyAddDelSession request, final int tableIndex,
83 assertEquals(1, request.isAdd);
84 assertEquals(tableIndex, request.tableIndex);
85 assertEquals(0, request.hitNextIndex);
87 byte[] expectedMatch = new byte[] {
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0x40, (byte) 0x2c,
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 1, 2,
90 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
92 AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMatch, request.match, vlanTags * VLAN_TAG_LEN);
97 public void testGetClassifyAddDelTableRequest() throws Exception {
98 final int nextTableIndex = 42;
99 final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, 0);
100 verifyTableRequest(request, nextTableIndex, 0);
104 public void testGetClassifyAddDelTableRequest1VlanTag() throws Exception {
105 final int nextTableIndex = 42;
106 final int vlanTags = 1;
107 final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags);
108 verifyTableRequest(request, nextTableIndex, vlanTags);
112 public void testGetClassifyAddDelTableRequest2VlanTags() throws Exception {
113 final int nextTableIndex = 42;
114 final int vlanTags = 2;
115 final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags);
116 verifyTableRequest(request, nextTableIndex, vlanTags);
120 public void testGetClassifyAddDelSessionRequest() throws Exception {
121 final int tableIndex = 123;
122 final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, 0);
123 verifySessionRequest(request, tableIndex, 0);
127 public void testGetClassifyAddDelSessionRequest1VlanTag() throws Exception {
128 final int tableIndex = 123;
129 final int vlanTags = 1;
130 final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags);
131 verifySessionRequest(request, tableIndex, vlanTags);
135 public void testGetClassifyAddDelSessionRequest2VlanTags() throws Exception {
136 final int tableIndex = 123;
137 final int vlanTags = 2;
138 final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags);
140 verifySessionRequest(request, tableIndex, vlanTags);
144 public void testSetClassifyTable() throws Exception {
145 final int tableIndex = 321;
146 final InputAclSetInterface request = new InputAclSetInterface();
147 writer.setClassifyTable(request, tableIndex);
148 assertEquals(tableIndex, request.ip4TableIndex);