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.AclTranslator.VLAN_TAG_LEN;
20 import static org.junit.Assert.assertEquals;
21 import static org.mockito.MockitoAnnotations.initMocks;
23 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession;
24 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable;
25 import org.junit.Before;
26 import org.junit.Test;
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.PacketHandling;
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.actions.packet.handling.DenyBuilder;
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.AceIp;
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.AceIpBuilder;
31 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;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.InterfaceMode;
37 public class AceIp6WriterTest {
39 private AceIp6Writer writer;
40 private PacketHandling action;
46 writer = new AceIp6Writer();
47 action = new DenyBuilder().setDeny(true).build();
48 aceIp = new AceIpBuilder()
49 .setProtocol((short) 132)
50 .setDscp(new Dscp((short) 11))
51 .setAceIpVersion(new AceIpv6Builder()
52 .setFlowLabel(new Ipv6FlowLabel(123L))
53 .setSourceIpv6Network(new Ipv6Prefix("2001:db8:85a3:8d3:1319:8a2e:370:7348/128"))
54 .setDestinationIpv6Network(new Ipv6Prefix("fe80:1234:5678:abcd:ef01::/64"))
60 private static void verifyTableRequest(final ClassifyAddDelTable request, final int nextTableIndex,
61 final int vlanTags, final boolean isL2) {
62 assertEquals(1, request.isAdd);
63 assertEquals(-1, request.tableIndex);
64 assertEquals(1, request.nbuckets);
65 assertEquals(nextTableIndex, request.nextTableIndex);
66 assertEquals(0, request.skipNVectors);
67 assertEquals(AceIp6Writer.MATCH_N_VECTORS, request.matchNVectors);
68 assertEquals(AceIp6Writer.TABLE_MEM_SIZE, request.memorySize);
70 byte[] expectedMask = new byte[] {
72 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
74 (byte) 0x0f, (byte) 0xcf, (byte) 0xff, (byte) 0xff,
78 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
79 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
80 // destination address:
81 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
82 0, 0, 0, 0, 0, 0, 0, 0,
83 // padding to multiple of 16B:
84 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
88 expectedMask[12] = (byte) 0xff;
89 expectedMask[13] = (byte) 0xff;
91 AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMask, request.mask, vlanTags * VLAN_TAG_LEN);
94 private static void verifySessionRequest(final ClassifyAddDelSession request, final int tableIndex,
95 final int vlanTags, final boolean isL2) {
96 assertEquals(1, request.isAdd);
97 assertEquals(tableIndex, request.tableIndex);
98 assertEquals(0, request.hitNextIndex);
100 byte[] expectedMatch = new byte[] {
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 // dscp(11), flow(123):
104 (byte) 0x02, (byte) 0xc0, (byte) 0x00, (byte) 0x7b,
108 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8, (byte) 0x85, (byte) 0xa3, (byte) 0x08, (byte) 0xd3,
109 (byte) 0x13, (byte) 0x19, (byte) 0x8a, (byte) 0x2e, (byte) 0x03, (byte) 0x70, (byte) 0x73, (byte) 0x48,
110 // destination address:
111 (byte) 0xfe, (byte) 0x80, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0xab, (byte) 0xcd,
112 0, 0, 0, 0, 0, 0, 0, 0,
113 // padding to multiple of 16B:
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
118 expectedMatch[12] = (byte) 0x86;
119 expectedMatch[13] = (byte) 0xdd;
121 AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMatch, request.match, vlanTags * VLAN_TAG_LEN);
126 public void testCreateTable() {
127 final int nextTableIndex = 42;
128 final ClassifyAddDelTable request =
129 writer.createTable(aceIp, InterfaceMode.L3, nextTableIndex, 0);
130 verifyTableRequest(request, nextTableIndex, 0, false);
134 public void testCreateTableForL2Interface() {
135 final int nextTableIndex = 42;
136 final ClassifyAddDelTable request =
137 writer.createTable(aceIp, InterfaceMode.L2, nextTableIndex, 0);
138 verifyTableRequest(request, nextTableIndex, 0, true);
142 public void testCreateTable1VlanTag() {
143 final int nextTableIndex = 42;
144 final int vlanTags = 1;
145 final ClassifyAddDelTable request =
146 writer.createTable(aceIp, InterfaceMode.L3, nextTableIndex, vlanTags);
147 verifyTableRequest(request, nextTableIndex, vlanTags, false);
151 public void testCreateTable2VlanTags() {
152 final int nextTableIndex = 42;
153 final int vlanTags = 2;
154 final ClassifyAddDelTable request =
155 writer.createTable(aceIp, InterfaceMode.L3, nextTableIndex, vlanTags);
156 verifyTableRequest(request, nextTableIndex, vlanTags, false);
160 public void testCreateClassifySession() {
161 final int tableIndex = 123;
162 final ClassifyAddDelSession request =
163 writer.createSession(action, aceIp, InterfaceMode.L3, tableIndex, 0);
164 verifySessionRequest(request, tableIndex, 0, false);
168 public void testCreateClassifySessionForL2Interface() {
169 final int tableIndex = 123;
170 final ClassifyAddDelSession request =
171 writer.createSession(action, aceIp, InterfaceMode.L2, tableIndex, 0);
172 verifySessionRequest(request, tableIndex, 0, true);
176 public void testCreateClassifySession1VlanTag() {
177 final int tableIndex = 123;
178 final int vlanTags = 1;
179 final ClassifyAddDelSession request =
180 writer.createSession(action, aceIp, InterfaceMode.L3, tableIndex, vlanTags);
181 verifySessionRequest(request, tableIndex, vlanTags, false);
185 public void testCreateClassifySession2VlanTags() {
186 final int tableIndex = 123;
187 final int vlanTags = 2;
188 final ClassifyAddDelSession request =
189 writer.createSession(action, aceIp, InterfaceMode.L3, tableIndex, vlanTags);
190 verifySessionRequest(request, tableIndex, vlanTags, false);