1da23072b3639dca9d08a919a0de6a75cccf6385
[hc2vpp.git] /
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 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.inet.types.rev130715.Ipv4Prefix;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.InterfaceMode;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpAndEth;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpAndEthBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.and.eth.ace.ip.version.AceIpv4Builder;
35
36 public class AceIpAndEthWriterTest {
37
38     private AceIpAndEthWriter writer;
39     private PacketHandling action;
40     private AceIpAndEth ace;
41
42     @Before
43     public void setUp() {
44         initMocks(this);
45         writer = new AceIpAndEthWriter();
46         action = new DenyBuilder().setDeny(true).build();
47         ace = new AceIpAndEthBuilder()
48             .setDestinationMacAddress(new MacAddress("11:22:33:44:55:66"))
49             .setSourceMacAddress(new MacAddress("aa:bb:cc:dd:ee:ff"))
50             .setAceIpVersion(new AceIpv4Builder()
51                 .setSourceIpv4Network(new Ipv4Prefix("1.2.3.4/32")).build())
52             .build();
53     }
54
55     @Test
56     public void testCreateTable() {
57         final int nextTableIndex = 42;
58         final ClassifyAddDelTable request = writer.createTable(ace, InterfaceMode.L2, nextTableIndex, 0);
59
60         assertEquals(1, request.isAdd);
61         assertEquals(-1, request.tableIndex);
62         assertEquals(1, request.nbuckets);
63         assertEquals(nextTableIndex, request.nextTableIndex);
64         assertEquals(0, request.skipNVectors);
65         assertEquals(3, request.matchNVectors);
66         assertEquals(AceEthWriter.TABLE_MEM_SIZE, request.memorySize);
67
68         byte[] expectedMask = new byte[] {
69             // destination MAC:
70             -1, -1, -1, -1, -1, -1,
71             // source MAC:
72             -1, -1, -1, -1, -1, -1,
73             // ether type:
74             -1, -1,
75             // IP header
76             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77             // source address:
78             -1, -1, -1, -1,
79             // destination address:
80             0, 0, 0, 0,
81             // padding:
82             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
83         };
84         assertArrayEquals(expectedMask, request.mask);
85     }
86
87     @Test
88     public void testCreateClassifySession() {
89         final int tableIndex = 123;
90         final ClassifyAddDelSession request = writer.createSession(action, ace, 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             // ether type (IP4):
102             0x08, 0,
103             // IP header
104             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105             // source address:
106             1, 2, 3, 4,
107             // destination address:
108             0, 0, 0, 0,
109             // padding:
110             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
111         };
112         assertArrayEquals(expectedMatch, request.match);
113     }
114 }