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;
19 import static io.fd.honeycomb.translate.v3po.interfaces.acl.AbstractAceWriter.VLAN_TAG_LEN;
20 import static io.fd.honeycomb.translate.v3po.interfaces.acl.AceIpWriterTestUtils.assertArrayEqualsWithOffset;
21 import static org.junit.Assert.assertEquals;
22 import static org.mockito.MockitoAnnotations.initMocks;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.Mock;
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.AceIpv4Builder;
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.Ipv4Prefix;
34 import org.openvpp.jvpp.core.dto.ClassifyAddDelSession;
35 import org.openvpp.jvpp.core.dto.ClassifyAddDelTable;
36 import org.openvpp.jvpp.core.dto.InputAclSetInterface;
37 import org.openvpp.jvpp.core.future.FutureJVppCore;
39 public class AceIp4WriterTest {
42 private FutureJVppCore jvpp;
43 private AceIp4Writer writer;
44 private PacketHandling action;
48 public void setUp() throws Exception {
50 writer = new AceIp4Writer(jvpp);
51 action = new DenyBuilder().setDeny(true).build();
52 aceIp = new AceIpBuilder()
53 .setProtocol((short) 4)
54 .setDscp(new Dscp((short) 11))
55 .setAceIpVersion(new AceIpv4Builder()
56 .setSourceIpv4Network(new Ipv4Prefix("1.2.3.4/32"))
57 .setDestinationIpv4Network(new Ipv4Prefix("1.2.4.5/24"))
62 private static void verifyTableRequest(final ClassifyAddDelTable request, final int nextTableIndex,
64 assertEquals(1, request.isAdd);
65 assertEquals(-1, request.tableIndex);
66 assertEquals(1, request.nbuckets);
67 assertEquals(-1, request.missNextIndex);
68 assertEquals(nextTableIndex, request.nextTableIndex);
69 assertEquals(0, request.skipNVectors);
70 assertEquals(AceIp4Writer.MATCH_N_VECTORS, request.matchNVectors);
71 assertEquals(AceIp4Writer.TABLE_MEM_SIZE, request.memorySize);
73 byte[] expectedMask = new byte[] {
74 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0xf0, (byte) 0xfc,
75 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1,
76 -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
78 assertArrayEqualsWithOffset(expectedMask, request.mask, vlanTags * VLAN_TAG_LEN);
82 private static void verifySessionRequest(final ClassifyAddDelSession request, final int tableIndex,
84 assertEquals(1, request.isAdd);
85 assertEquals(tableIndex, request.tableIndex);
86 assertEquals(0, request.hitNextIndex);
88 byte[] expectedMatch = new byte[] {
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0x40, (byte) 0x2c,
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 1, 2,
91 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
93 assertArrayEqualsWithOffset(expectedMatch, request.match, vlanTags * VLAN_TAG_LEN);
98 public void testGetClassifyAddDelTableRequest() throws Exception {
99 final int nextTableIndex = 42;
100 final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, 0);
101 verifyTableRequest(request, nextTableIndex, 0);
105 public void testGetClassifyAddDelTableRequest1VlanTag() throws Exception {
106 final int nextTableIndex = 42;
107 final int vlanTags = 1;
108 final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags);
109 verifyTableRequest(request, nextTableIndex, vlanTags);
113 public void testGetClassifyAddDelTableRequest2VlanTags() throws Exception {
114 final int nextTableIndex = 42;
115 final int vlanTags = 2;
116 final ClassifyAddDelTable request = writer.createClassifyTable(action, aceIp, nextTableIndex, vlanTags);
117 verifyTableRequest(request, nextTableIndex, vlanTags);
121 public void testGetClassifyAddDelSessionRequest() throws Exception {
122 final int tableIndex = 123;
123 final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, 0);
124 verifySessionRequest(request, tableIndex, 0);
128 public void testGetClassifyAddDelSessionRequest1VlanTag() throws Exception {
129 final int tableIndex = 123;
130 final int vlanTags = 1;
131 final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags);
132 verifySessionRequest(request, tableIndex, vlanTags);
136 public void testGetClassifyAddDelSessionRequest2VlanTags() throws Exception {
137 final int tableIndex = 123;
138 final int vlanTags = 2;
139 final ClassifyAddDelSession request = writer.createClassifySession(action, aceIp, tableIndex, vlanTags);
141 verifySessionRequest(request, tableIndex, vlanTags);
145 public void testSetClassifyTable() throws Exception {
146 final int tableIndex = 321;
147 final InputAclSetInterface request = new InputAclSetInterface();
148 writer.setClassifyTable(request, tableIndex);
149 assertEquals(tableIndex, request.ip4TableIndex);