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 static com.google.common.base.Preconditions.checkArgument;
21 import com.google.common.annotations.VisibleForTesting;
22 import io.fd.honeycomb.translate.vpp.util.MacTranslator;
23 import java.util.List;
24 import javax.annotation.Nonnull;
25 import javax.annotation.Nullable;
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.PacketHandling;
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.matches.ace.type.AceEth;
28 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession;
29 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable;
30 import io.fd.vpp.jvpp.core.dto.InputAclSetInterface;
31 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.InterfaceMode;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 final class AceEthWriter extends AbstractAceWriter<AceEth> implements MacTranslator {
39 static final int MATCH_N_VECTORS = 1;
40 private static final Logger LOG = LoggerFactory.getLogger(AceEthWriter.class);
42 public AceEthWriter(@Nonnull final FutureJVppCore futureJVppCore) {
43 super(futureJVppCore);
46 private static void checkInterfaceMode(@Nullable final InterfaceMode mode) {
47 checkArgument(InterfaceMode.L2.equals(mode), "L2 rules are not allowed for interface in L3 mode");
51 public ClassifyAddDelTable createClassifyTable(@Nonnull final PacketHandling action,
52 @Nonnull final AceEth aceEth,
53 @Nullable final InterfaceMode mode,
54 final int nextTableIndex,
56 checkInterfaceMode(mode);
58 final ClassifyAddDelTable request = createClassifyTable(action, nextTableIndex);
60 request.mask = new byte[16];
61 boolean aceIsEmpty = true;
63 // destination-mac-address or destination-mac-address-mask is present =>
64 // ff:ff:ff:ff:ff:ff:00:00:00:00:00:00:00:00:00:00
65 if (aceEth.getDestinationMacAddressMask() != null) {
67 final String macAddress = aceEth.getDestinationMacAddressMask().getValue();
68 final List<String> parts = COLON_SPLITTER.splitToList(macAddress);
70 for (String part : parts) {
71 request.mask[i++] = parseHexByte(part);
73 } else if (aceEth.getDestinationMacAddress() != null) {
75 for (int i = 0; i < 6; ++i) {
76 request.mask[i] = (byte) 0xff;
80 // source-mac-address or source-mac-address-mask =>
81 // 00:00:00:00:00:00:ff:ff:ff:ff:ff:ff:00:00:00:00
82 if (aceEth.getSourceMacAddressMask() != null) {
84 final String macAddress = aceEth.getSourceMacAddressMask().getValue();
85 final List<String> parts = COLON_SPLITTER.splitToList(macAddress);
87 for (String part : parts) {
88 request.mask[i++] = parseHexByte(part);
90 } else if (aceEth.getSourceMacAddress() != null) {
92 for (int i = 6; i < 12; ++i) {
93 request.mask[i] = (byte) 0xff;
98 throw new IllegalArgumentException(
99 String.format("Ace %s does not define packet field match values", aceEth.toString()));
102 request.skipNVectors = 0;
103 request.matchNVectors = MATCH_N_VECTORS;
105 LOG.debug("ACE action={}, rule={} translated to table={}.", action, aceEth, request);
110 public ClassifyAddDelSession createClassifySession(@Nonnull final PacketHandling action,
111 @Nonnull final AceEth aceEth,
112 @Nullable final InterfaceMode mode,
113 final int tableIndex,
114 final int vlanTags) {
115 checkInterfaceMode(mode);
117 final ClassifyAddDelSession request = createClassifySession(action, tableIndex);
119 request.match = new byte[16];
120 boolean noMatch = true;
122 if (aceEth.getDestinationMacAddress() != null) {
124 final String macAddress = aceEth.getDestinationMacAddress().getValue();
125 final List<String> parts = COLON_SPLITTER.splitToList(macAddress);
127 for (String part : parts) {
128 request.match[i++] = parseHexByte(part);
132 if (aceEth.getSourceMacAddress() != null) {
134 final String macAddress = aceEth.getSourceMacAddress().getValue();
135 final List<String> parts = COLON_SPLITTER.splitToList(macAddress);
137 for (String part : parts) {
138 request.match[i++] = parseHexByte(part);
143 throw new IllegalArgumentException(
144 String.format("Ace %s does not define neither source nor destination MAC address",
148 LOG.debug("ACE action={}, rule={} translated to session={}.", action, aceEth, request);
153 protected void setClassifyTable(@Nonnull final InputAclSetInterface request, final int tableIndex) {
154 request.l2TableIndex = tableIndex;