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.AceIpv6Builder;
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.Ipv6FlowLabel;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
34 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession;
35 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable;
36 import io.fd.vpp.jvpp.core.dto.InputAclSetInterface;
37 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.InterfaceMode;
40 public class AceIp6WriterTest {
43 private FutureJVppCore jvpp;
44 private AceIp6Writer writer;
45 private PacketHandling action;
51 writer = new AceIp6Writer(jvpp);
52 action = new DenyBuilder().setDeny(true).build();
53 aceIp = new AceIpBuilder()
54 .setProtocol((short) 6)
55 .setDscp(new Dscp((short) 11))
56 .setAceIpVersion(new AceIpv6Builder()
57 .setFlowLabel(new Ipv6FlowLabel(123L))
58 .setSourceIpv6Network(new Ipv6Prefix("2001:db8:85a3:8d3:1319:8a2e:370:7348/128"))
59 .setDestinationIpv6Network(new Ipv6Prefix("fe80:1234:5678:abcd:ef01::/64"))
65 private static void verifyTableRequest(final ClassifyAddDelTable request, final int nextTableIndex,
66 final int vlanTags, final boolean isL2) {
67 assertEquals(1, request.isAdd);
68 assertEquals(-1, request.tableIndex);
69 assertEquals(1, request.nbuckets);
70 assertEquals(-1, request.missNextIndex);
71 assertEquals(nextTableIndex, request.nextTableIndex);
72 assertEquals(0, request.skipNVectors);
73 assertEquals(AceIp6Writer.MATCH_N_VECTORS, request.matchNVectors);
74 assertEquals(AceIp6Writer.TABLE_MEM_SIZE, request.memorySize);
76 byte[] expectedMask = new byte[] {
78 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
79 // version, dscp, flow:
80 (byte) 0xff, (byte) 0xcf, (byte) 0xff, (byte) 0xff,
83 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
84 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
85 // destination address:
86 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
87 0, 0, 0, 0, 0, 0, 0, 0,
88 // padding to multiple of 16B:
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
93 expectedMask[12] = (byte) 0xff;
94 expectedMask[13] = (byte) 0xff;
96 AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMask, request.mask, vlanTags * VLAN_TAG_LEN);
99 private static void verifySessionRequest(final ClassifyAddDelSession request, final int tableIndex,
100 final int vlanTags, final boolean isL2) {
101 assertEquals(1, request.isAdd);
102 assertEquals(tableIndex, request.tableIndex);
103 assertEquals(0, request.hitNextIndex);
105 byte[] expectedMatch = new byte[] {
107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108 // version(6), dscp(11), flow(123):
109 (byte) 0x62, (byte) 0xc0, (byte) 0x00, (byte) 0x7b,
112 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8, (byte) 0x85, (byte) 0xa3, (byte) 0x08, (byte) 0xd3,
113 (byte) 0x13, (byte) 0x19, (byte) 0x8a, (byte) 0x2e, (byte) 0x03, (byte) 0x70, (byte) 0x73, (byte) 0x48,
114 // destination address:
115 (byte) 0xfe, (byte) 0x80, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0xab, (byte) 0xcd,
116 0, 0, 0, 0, 0, 0, 0, 0,
117 // padding to multiple of 16B:
118 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
122 expectedMatch[12] = (byte) 0x86;
123 expectedMatch[13] = (byte) 0xdd;
125 AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMatch, request.match, vlanTags * VLAN_TAG_LEN);
130 public void testCreateClassifyTable() {
131 final int nextTableIndex = 42;
132 final ClassifyAddDelTable request =
133 writer.createClassifyTable(action, aceIp, InterfaceMode.L3, nextTableIndex, 0);
134 verifyTableRequest(request, nextTableIndex, 0, false);
138 public void testCreateClassifyTableForL2Interface() {
139 final int nextTableIndex = 42;
140 final ClassifyAddDelTable request =
141 writer.createClassifyTable(action, aceIp, InterfaceMode.L2, nextTableIndex, 0);
142 verifyTableRequest(request, nextTableIndex, 0, true);
146 public void testCreateClassifyTable1VlanTag() {
147 final int nextTableIndex = 42;
148 final int vlanTags = 1;
149 final ClassifyAddDelTable request =
150 writer.createClassifyTable(action, aceIp, InterfaceMode.L3, nextTableIndex, vlanTags);
151 verifyTableRequest(request, nextTableIndex, vlanTags, false);
155 public void testCreateClassifyTable2VlanTags() {
156 final int nextTableIndex = 42;
157 final int vlanTags = 2;
158 final ClassifyAddDelTable request =
159 writer.createClassifyTable(action, aceIp, InterfaceMode.L3, nextTableIndex, vlanTags);
160 verifyTableRequest(request, nextTableIndex, vlanTags, false);
164 public void testCreateClassifySession() {
165 final int tableIndex = 123;
166 final ClassifyAddDelSession request =
167 writer.createClassifySession(action, aceIp, InterfaceMode.L3, tableIndex, 0);
168 verifySessionRequest(request, tableIndex, 0, false);
172 public void testCreateClassifySessionForL2Interface() {
173 final int tableIndex = 123;
174 final ClassifyAddDelSession request =
175 writer.createClassifySession(action, aceIp, InterfaceMode.L2, tableIndex, 0);
176 verifySessionRequest(request, tableIndex, 0, true);
180 public void testCreateClassifySession1VlanTag() {
181 final int tableIndex = 123;
182 final int vlanTags = 1;
183 final ClassifyAddDelSession request =
184 writer.createClassifySession(action, aceIp, InterfaceMode.L3, tableIndex, vlanTags);
185 verifySessionRequest(request, tableIndex, vlanTags, false);
189 public void testCreateClassifySession2VlanTags() {
190 final int tableIndex = 123;
191 final int vlanTags = 2;
192 final ClassifyAddDelSession request =
193 writer.createClassifySession(action, aceIp, InterfaceMode.L3, tableIndex, vlanTags);
194 verifySessionRequest(request, tableIndex, vlanTags, false);
198 public void testSetClassifyTable() {
199 final int tableIndex = 321;
200 final InputAclSetInterface request = new InputAclSetInterface();
201 writer.setClassifyTable(request, tableIndex);
202 assertEquals(tableIndex, request.ip6TableIndex);