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.common;
19 import static com.google.common.base.Preconditions.checkArgument;
21 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession;
22 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable;
23 import javax.annotation.Nonnegative;
24 import javax.annotation.Nonnull;
25 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;
26 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;
29 * Utility that helps translating of ietf-acl model ACEs to VPP's classify tables and sessions.
31 interface AclTranslator {
32 int TABLE_MEM_SIZE = 8 * 1024;
35 default ClassifyAddDelTable createTable(final int nextTableIndex) {
36 return createTable(nextTableIndex, 1);
39 default ClassifyAddDelTable createTable(final int nextTableIndex, @Nonnegative final int numberOfSessions) {
40 final ClassifyAddDelTable request = new ClassifyAddDelTable();
42 request.tableIndex = -1; // value not present
43 request.nbuckets = numberOfSessions;
44 request.nextTableIndex = nextTableIndex;
47 // TODO: HONEYCOMB-181 minimise memory used by classify tables (we create a lot of them to make ietf-acl model
48 // mapping more convenient):
49 // according to https://wiki.fd.io/view/VPP/Introduction_To_N-tuple_Classifiers#Creating_a_classifier_table,
50 // classify table needs 16*(1 + match_n_vectors) bytes, but this does not quite work,
51 // so setting 8K +1k*numberOfSessions for now
52 checkArgument(numberOfSessions>0, "negative numberOfSessions %s", numberOfSessions);
53 request.memorySize = TABLE_MEM_SIZE+1024*(numberOfSessions-1);
54 request.missNextIndex = -1; // value not set, but anyway it is ignored for tables in chain
58 default ClassifyAddDelSession createSession(@Nonnull final PacketHandling action, final int tableIndex) {
59 final ClassifyAddDelSession request = new ClassifyAddDelSession();
61 request.tableIndex = tableIndex;
62 request.opaqueIndex = ~0; // value not used
64 if (action instanceof Permit) {
65 request.hitNextIndex = -1;
66 } // deny (0) is default value
71 default int getVlanTagsLen(final int vlanTags) {
72 return vlanTags * VLAN_TAG_LEN;