c334d4a832a75108fb7f704b722f5b5d95dcaef1
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / interfaces / acl / ingress / AceEthWriterTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.translate.v3po.interfaces.acl.ingress;
18
19 import static org.junit.Assert.assertArrayEquals;
20 import static org.junit.Assert.assertEquals;
21 import static org.mockito.MockitoAnnotations.initMocks;
22
23 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession;
24 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable;
25 import io.fd.vpp.jvpp.core.dto.InputAclSetInterface;
26 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.Mock;
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.actions.PacketHandling;
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.actions.packet.handling.DenyBuilder;
32 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.AceEth;
33 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.AceEthBuilder;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.InterfaceMode;
36
37 public class AceEthWriterTest {
38
39     @Mock
40     private FutureJVppCore jvpp;
41     private AceEthWriter writer;
42     private PacketHandling action;
43     private AceEth aceEth;
44
45     @Before
46     public void setUp() {
47         initMocks(this);
48         writer = new AceEthWriter(jvpp);
49         action = new DenyBuilder().setDeny(true).build();
50         aceEth = new AceEthBuilder()
51             .setDestinationMacAddress(new MacAddress("11:22:33:44:55:66"))
52             .setDestinationMacAddressMask(new MacAddress("ff:ff:ff:ff:ff:ff"))
53             .setSourceMacAddress(new MacAddress("aa:bb:cc:dd:ee:ff"))
54             .setSourceMacAddressMask(new MacAddress("ff:ff:ff:00:00:00"))
55             .build();
56     }
57
58     @Test
59     public void testCreateClassifyTable() {
60         final int nextTableIndex = 42;
61         final ClassifyAddDelTable request = writer.createClassifyTable(action, aceEth, InterfaceMode.L2, nextTableIndex, 0);
62
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(AceEthWriter.MATCH_N_VECTORS, request.matchNVectors);
70         assertEquals(AceEthWriter.TABLE_MEM_SIZE, request.memorySize);
71
72         byte[] expectedMask = new byte[] {
73             // destination MAC:
74             (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
75             // source MAC:
76             (byte) 0xff, (byte) 0xff, (byte) 0xff, 0, 0, 0,
77             0, 0, 0, 0
78         };
79         assertArrayEquals(expectedMask, request.mask);
80     }
81
82     @Test(expected = IllegalArgumentException.class)
83     public void testCreateClassifyTableForL3Interface() {
84         writer.createClassifyTable(action, aceEth, InterfaceMode.L3, 42, 0);
85     }
86
87     @Test
88     public void testCreateClassifySession() {
89         final int tableIndex = 123;
90         final ClassifyAddDelSession request = writer.createClassifySession(action, aceEth, InterfaceMode.L2, tableIndex, 0);
91
92         assertEquals(1, request.isAdd);
93         assertEquals(tableIndex, request.tableIndex);
94         assertEquals(0, request.hitNextIndex);
95
96         byte[] expectedMatch = new byte[] {
97             // destination MAC:
98             (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44, (byte) 0x55, (byte) 0x66,
99             // source MAC:
100             (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd, (byte) 0xee, (byte) 0xff,
101             0, 0, 0, 0
102         };
103         assertArrayEquals(expectedMatch, request.match);
104     }
105
106     @Test(expected = IllegalArgumentException.class)
107     public void testCreateClassifySessionForL3Interface() {
108         writer.createClassifySession(action, aceEth, InterfaceMode.L3, 42, 0);
109     }
110
111     @Test
112     public void testSetClassifyTable() {
113         final int tableIndex = 321;
114         final InputAclSetInterface request = new InputAclSetInterface();
115         writer.setClassifyTable(request, tableIndex);
116         assertEquals(tableIndex, request.l2TableIndex);
117     }
118 }