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;
39 public class AceIp6WriterTest {
42 private FutureJVppCore jvpp;
43 private AceIp6Writer writer;
44 private PacketHandling action;
48 public void setUp() throws Exception {
50 writer = new AceIp6Writer(jvpp);
51 action = new DenyBuilder().setDeny(true).build();
52 aceIp = new AceIpBuilder()
53 .setProtocol((short) 6)
54 .setDscp(new Dscp((short) 11))
55 .setAceIpVersion(new AceIpv6Builder()
56 .setFlowLabel(new Ipv6FlowLabel(123L))
57 .setSourceIpv6Network(new Ipv6Prefix("2001:db8:85a3:8d3:1319:8a2e:370:7348/128"))
58 .setDestinationIpv6Network(new Ipv6Prefix("fe80:1234:5678:abcd:ef01::/64"))
64 private static void verifyTableRequest(final ClassifyAddDelTable request, final int nextTableIndex,
66 assertEquals(1, request.isAdd);
67 assertEquals(-1, request.tableIndex);
68 assertEquals(1, request.nbuckets);
69 assertEquals(-1, request.missNextIndex);
70 assertEquals(nextTableIndex, request.nextTableIndex);
71 assertEquals(0, request.skipNVectors);
72 assertEquals(AceIp6Writer.MATCH_N_VECTORS, request.matchNVectors);
73 assertEquals(AceIp6Writer.TABLE_MEM_SIZE, request.memorySize);
75 byte[] expectedMask = new byte[] {
77 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
78 // version, dscp, flow:
79 (byte) 0xff, (byte) 0xcf, (byte) 0xff, (byte) 0xff,
82 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
83 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
84 // destination address:
85 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
86 0, 0, 0, 0, 0, 0, 0, 0,
87 // padding to multiple of 16B:
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
90 AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMask, request.mask, vlanTags * VLAN_TAG_LEN);
94 private static void verifySessionRequest(final ClassifyAddDelSession request, final int tableIndex,
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 // version(6), dscp(11), flow(123):
104 (byte) 0x62, (byte) 0xc0, (byte) 0x00, (byte) 0x7b,
107 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8, (byte) 0x85, (byte) 0xa3, (byte) 0x08, (byte) 0xd3,
108 (byte) 0x13, (byte) 0x19, (byte) 0x8a, (byte) 0x2e, (byte) 0x03, (byte) 0x70, (byte) 0x73, (byte) 0x48,
109 // destination address:
110 (byte) 0xfe, (byte) 0x80, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0xab, (byte) 0xcd,
111 0, 0, 0, 0, 0, 0, 0, 0,
112 // padding to multiple of 16B:
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
115 AceIpWriterTestUtils.assertArrayEqualsWithOffset(expectedMatch, request.match, vlanTags * VLAN_TAG_LEN);
120 public void testGetClassifyAddDelTableRequest() throws Exception {
121 final int nextTableIndex = 42;
122 final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, 0);
123 verifyTableRequest(request, nextTableIndex, 0);
127 public void testGetClassifyAddDelTableRequest1VlanTag() throws Exception {
128 final int nextTableIndex = 42;
129 final int vlanTags = 1;
130 final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags);
131 verifyTableRequest(request, nextTableIndex, vlanTags);
135 public void testGetClassifyAddDelTableRequest2VlanTag() throws Exception {
136 final int nextTableIndex = 42;
137 final int vlanTags = 2;
138 final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags);
139 verifyTableRequest(request, nextTableIndex, vlanTags);
143 public void testGetClassifyAddDelSessionRequest() throws Exception {
144 final int tableIndex = 123;
145 final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, 0);
146 verifySessionRequest(request, tableIndex, 0);
150 public void testGetClassifyAddDelSessionRequest1VlanTag() throws Exception {
151 final int tableIndex = 123;
152 final int vlanTags = 1;
153 final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags);
154 verifySessionRequest(request, tableIndex, vlanTags);
158 public void testGetClassifyAddDelSessionRequest2VlanTag() throws Exception {
159 final int tableIndex = 123;
160 final int vlanTags = 2;
161 final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags);
162 verifySessionRequest(request, tableIndex, vlanTags);
166 public void testSetClassifyTable() throws Exception {
167 final int tableIndex = 321;
168 final InputAclSetInterface request = new InputAclSetInterface();
169 writer.setClassifyTable(request, tableIndex);
170 assertEquals(tableIndex, request.ip6TableIndex);