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 java.util.ArrayList;
24 import java.util.List;
25 import javax.annotation.Nonnull;
26 import javax.annotation.Nullable;
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.actions.PacketHandling;
28 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.AceIp;
29 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.ace.ip.ace.ip.version.AceIpv6;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.InterfaceMode;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 final class AceIp6Writer implements AceWriter<AceIp>, AclTranslator, Ip6AclTranslator {
36 private static final Logger LOG = LoggerFactory.getLogger(AceIp6Writer.class);
39 public ClassifyAddDelTable createTable(@Nonnull final AceIp aceIp,
40 @Nullable final InterfaceMode mode,
41 final int nextTableIndex,
43 checkArgument(aceIp.getAceIpVersion() instanceof AceIpv6, "Expected AceIpv6 version, but was %", aceIp);
44 final AceIpv6 ipVersion = (AceIpv6) aceIp.getAceIpVersion();
46 final int numberOfSessions = PortPair.fromRange(aceIp.getSourcePortRange(), aceIp.getDestinationPortRange()).size();
47 final ClassifyAddDelTable request = createTable(nextTableIndex, numberOfSessions);
48 request.skipNVectors = 0; // match entire L2 and L3 header
49 request.mask = new byte[getTableMaskLength(vlanTags)];
50 request.matchNVectors = request.mask.length/16;
52 final int baseOffset = getVlanTagsLen(vlanTags);
53 boolean aceIsEmpty = ip6Mask(baseOffset, mode, aceIp, ipVersion, request);
55 throw new IllegalArgumentException(
56 String.format("Ace %s does not define packet field match values", aceIp.toString()));
59 LOG.debug("ACE rule={} translated to table={}.", aceIp, request);
63 private static int getTableMaskLength(final int vlanTags) {
72 public List<ClassifyAddDelSession> createSession(@Nonnull final PacketHandling action,
73 @Nonnull final AceIp aceIp,
74 @Nullable final InterfaceMode mode,
77 checkArgument(aceIp.getAceIpVersion() instanceof AceIpv6, "Expected AceIpv6 version, but was %", aceIp);
78 final AceIpv6 ipVersion = (AceIpv6) aceIp.getAceIpVersion();
79 final List<PortPair> portPairs =
80 PortPair.fromRange(aceIp.getSourcePortRange(), aceIp.getDestinationPortRange());
82 final List<ClassifyAddDelSession> requests = new ArrayList<>(portPairs.size());
83 for (final PortPair pair : portPairs) {
84 final ClassifyAddDelSession request = createSession(action, tableIndex);
85 request.match = new byte[getTableMaskLength(vlanTags)];
87 final int baseOffset = getVlanTagsLen(vlanTags);
88 boolean noMatch = ip6Match(baseOffset, mode, aceIp, ipVersion, pair.getSrc(), pair.getDst(), request);
90 throw new IllegalArgumentException(
91 String.format("Ace %s does not define packet field match values", aceIp.toString()));
94 LOG.debug("ACE action={}, rule={} translated to session={}.", action, aceIp, request);
95 requests.add(request);