3a50b76737800136a59c8b1c1fdad1124487e042
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / interfaces / acl / common / 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.common;
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 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.AceEth;
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.AceEthBuilder;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.InterfaceMode;
33
34 public class AceEthWriterTest {
35
36     private AceEthWriter writer;
37     private PacketHandling action;
38     private AceEth aceEth;
39
40     @Before
41     public void setUp() {
42         initMocks(this);
43         writer = new AceEthWriter();
44         action = new DenyBuilder().setDeny(true).build();
45         aceEth = new AceEthBuilder()
46             .setDestinationMacAddress(new MacAddress("11:22:33:44:55:66"))
47             .setDestinationMacAddressMask(new MacAddress("ff:ff:ff:ff:ff:ff"))
48             .setSourceMacAddress(new MacAddress("aa:bb:cc:dd:ee:ff"))
49             .setSourceMacAddressMask(new MacAddress("ff:ff:ff:00:00:00"))
50             .build();
51     }
52
53     @Test
54     public void testCreateTable() {
55         final int nextTableIndex = 42;
56         final ClassifyAddDelTable request = writer.createTable(aceEth, InterfaceMode.L2, nextTableIndex, 0);
57
58         assertEquals(1, request.isAdd);
59         assertEquals(-1, request.tableIndex);
60         assertEquals(1, request.nbuckets);
61         assertEquals(nextTableIndex, request.nextTableIndex);
62         assertEquals(0, request.skipNVectors);
63         assertEquals(AceEthWriter.MATCH_N_VECTORS, request.matchNVectors);
64         assertEquals(AceEthWriter.TABLE_MEM_SIZE, request.memorySize);
65
66         byte[] expectedMask = new byte[] {
67             // destination MAC:
68             (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
69             // source MAC:
70             (byte) 0xff, (byte) 0xff, (byte) 0xff, 0, 0, 0,
71             0, 0, 0, 0
72         };
73         assertArrayEquals(expectedMask, request.mask);
74     }
75
76     @Test
77     public void testCreateClassifySession() {
78         final int tableIndex = 123;
79         final ClassifyAddDelSession request = writer.createSession(action, aceEth, InterfaceMode.L2, tableIndex, 0).get(0);
80
81         assertEquals(1, request.isAdd);
82         assertEquals(tableIndex, request.tableIndex);
83         assertEquals(0, request.hitNextIndex);
84
85         byte[] expectedMatch = new byte[] {
86             // destination MAC:
87             (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44, (byte) 0x55, (byte) 0x66,
88             // source MAC:
89             (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd, (byte) 0xee, (byte) 0xff,
90             0, 0, 0, 0
91         };
92         assertArrayEquals(expectedMatch, request.match);
93     }
94 }