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 com.google.common.annotations.VisibleForTesting;
20 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession;
21 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable;
22 import java.util.Collections;
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 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.InterfaceMode;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 final class AceEthWriter implements AceWriter<AceEth>, AclTranslator, L2AclTranslator {
35 static final int MATCH_N_VECTORS = 1;
36 private static final Logger LOG = LoggerFactory.getLogger(AceEthWriter.class);
39 public ClassifyAddDelTable createTable(@Nonnull final AceEth aceEth,
40 @Nullable final InterfaceMode mode,
41 final int nextTableIndex,
43 final ClassifyAddDelTable request = createTable(nextTableIndex);
45 request.mask = new byte[16];
47 destinationMacAddressMask(aceEth.getDestinationMacAddressMask(), aceEth.getDestinationMacAddress(),
50 sourceMacAddressMask(aceEth.getSourceMacAddressMask(), aceEth.getSourceMacAddress(), request);
53 throw new IllegalArgumentException(
54 String.format("Ace %s does not define packet field match values", aceEth.toString()));
57 request.skipNVectors = 0;
58 request.matchNVectors = MATCH_N_VECTORS;
60 LOG.debug("ACE rule={} translated to table={}.", aceEth, request);
65 public List<ClassifyAddDelSession> createSession(@Nonnull final PacketHandling action,
66 @Nonnull final AceEth aceEth,
67 @Nullable final InterfaceMode mode,
70 final ClassifyAddDelSession request = createSession(action, tableIndex);
72 request.match = new byte[16];
73 boolean noMatch = destinationMacAddressMatch(aceEth.getDestinationMacAddress(), request);
74 noMatch &= sourceMacAddressMatch(aceEth.getSourceMacAddress(), request);
77 throw new IllegalArgumentException(
78 String.format("Ace %s does not define neither source nor destination MAC address",
82 LOG.debug("ACE action={}, rule={} translated to session={}.", action, aceEth, request);
83 return Collections.singletonList(request);