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.ingress;
19 import com.google.common.annotations.VisibleForTesting;
20 import io.fd.honeycomb.translate.vpp.util.MacTranslator;
21 import java.util.List;
22 import javax.annotation.Nonnull;
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.PacketHandling;
24 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;
25 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession;
26 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable;
27 import io.fd.vpp.jvpp.core.dto.InputAclSetInterface;
28 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 final class AceEthWriter extends AbstractAceWriter<AceEth> implements MacTranslator {
35 static final int MATCH_N_VECTORS = 1;
36 private static final Logger LOG = LoggerFactory.getLogger(AceEthWriter.class);
38 public AceEthWriter(@Nonnull final FutureJVppCore futureJVppCore) {
39 super(futureJVppCore);
43 public ClassifyAddDelTable createClassifyTable(@Nonnull final PacketHandling action,
44 @Nonnull final AceEth aceEth,
45 @Nonnull final int nextTableIndex,
47 final ClassifyAddDelTable request = createClassifyTable(action, nextTableIndex);
49 request.mask = new byte[16];
50 boolean aceIsEmpty = true;
52 // destination-mac-address or destination-mac-address-mask is present =>
53 // ff:ff:ff:ff:ff:ff:00:00:00:00:00:00:00:00:00:00
54 if (aceEth.getDestinationMacAddressMask() != null) {
56 final String macAddress = aceEth.getDestinationMacAddressMask().getValue();
57 final List<String> parts = COLON_SPLITTER.splitToList(macAddress);
59 for (String part : parts) {
60 request.mask[i++] = parseHexByte(part);
62 } else if (aceEth.getDestinationMacAddress() != null) {
64 for (int i = 0; i < 6; ++i) {
65 request.mask[i] = (byte) 0xff;
69 // source-mac-address or source-mac-address-mask =>
70 // 00:00:00:00:00:00:ff:ff:ff:ff:ff:ff:00:00:00:00
71 if (aceEth.getSourceMacAddressMask() != null) {
73 final String macAddress = aceEth.getSourceMacAddressMask().getValue();
74 final List<String> parts = COLON_SPLITTER.splitToList(macAddress);
76 for (String part : parts) {
77 request.mask[i++] = parseHexByte(part);
79 } else if (aceEth.getSourceMacAddress() != null) {
81 for (int i = 6; i < 12; ++i) {
82 request.mask[i] = (byte) 0xff;
87 throw new IllegalArgumentException(
88 String.format("Ace %s does not define packet field match values", aceEth.toString()));
91 request.skipNVectors = 0;
92 request.matchNVectors = MATCH_N_VECTORS;
94 LOG.debug("ACE action={}, rule={} translated to table={}.", action, aceEth, request);
99 public ClassifyAddDelSession createClassifySession(@Nonnull final PacketHandling action,
100 @Nonnull final AceEth aceEth,
101 @Nonnull final int tableIndex,
102 final int vlanTags) {
103 final ClassifyAddDelSession request = createClassifySession(action, tableIndex);
105 request.match = new byte[16];
106 boolean noMatch = true;
108 if (aceEth.getDestinationMacAddress() != null) {
110 final String macAddress = aceEth.getDestinationMacAddress().getValue();
111 final List<String> parts = COLON_SPLITTER.splitToList(macAddress);
113 for (String part : parts) {
114 request.match[i++] = parseHexByte(part);
118 if (aceEth.getSourceMacAddress() != null) {
120 final String macAddress = aceEth.getSourceMacAddress().getValue();
121 final List<String> parts = COLON_SPLITTER.splitToList(macAddress);
123 for (String part : parts) {
124 request.match[i++] = parseHexByte(part);
129 throw new IllegalArgumentException(
130 String.format("Ace %s does not define neither source nor destination MAC address",
134 LOG.debug("ACE action={}, rule={} translated to session={}.", action, aceEth, request);
139 protected void setClassifyTable(@Nonnull final InputAclSetInterface request, final int tableIndex) {
140 request.l2TableIndex = tableIndex;