9a931a923bca5b8c5b224175e0b45d60e00f5509
[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 io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession;
20 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable;
21 import javax.annotation.Nonnull;
22 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;
23 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.Permit;
24
25 /**
26  * Utility that helps translating of ietf-acl model ACEs to VPP's classify tables and sessions.
27  */
28 interface AclTranslator {
29
30     // TODO: HONEYCOMB-181 minimise memory used by classify tables (we create a lot of them to make ietf-acl model
31     // mapping more convenient):
32     // according to https://wiki.fd.io/view/VPP/Introduction_To_N-tuple_Classifiers#Creating_a_classifier_table,
33     // classify table needs 16*(1 + match_n_vectors) bytes, but this does not quite work, so setting 8K for now
34     int TABLE_MEM_SIZE = 8 * 1024;
35     int VLAN_TAG_LEN = 4;
36
37     default ClassifyAddDelTable createTable(final int nextTableIndex) {
38         final ClassifyAddDelTable request = new ClassifyAddDelTable();
39         request.isAdd = 1;
40         request.tableIndex = -1; // value not present
41         request.nbuckets = 1; // we expect exactly one session per table
42         request.nextTableIndex = nextTableIndex;
43         request.memorySize = TABLE_MEM_SIZE;
44         request.missNextIndex = -1; // value not set, but anyway it is ignored for tables in chain
45         return request;
46     }
47
48     default ClassifyAddDelSession createSession(@Nonnull final PacketHandling action, final int tableIndex) {
49         final ClassifyAddDelSession request = new ClassifyAddDelSession();
50         request.isAdd = 1;
51         request.tableIndex = tableIndex;
52         request.opaqueIndex = ~0; // value not used
53
54         if (action instanceof Permit) {
55             request.hitNextIndex = -1;
56         } // deny (0) is default value
57
58         return request;
59     }
60
61     default int getVlanTagsLen(final int vlanTags) {
62         return vlanTags * VLAN_TAG_LEN;
63     }
64 }