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.checkNotNull;
21 import io.fd.honeycomb.translate.MappingContext;
22 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
23 import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
24 import io.fd.honeycomb.translate.vpp.util.WriteTimeoutException;
25 import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
26 import io.fd.honeycomb.translate.write.WriteFailedException;
27 import java.util.concurrent.CompletionStage;
28 import javax.annotation.Nonnegative;
29 import javax.annotation.Nonnull;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.AclBaseAttributes;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4Acl;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6Acl;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.L2Acl;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import io.fd.vpp.jvpp.VppBaseCallException;
36 import io.fd.vpp.jvpp.core.dto.InputAclSetInterface;
37 import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply;
38 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
40 interface AclWriter extends ByteDataTranslator, JvppReplyConsumer {
42 default void inputAclSetInterface(@Nonnull final FutureJVppCore futureJVppCore, final boolean isAdd,
43 @Nonnull final InstanceIdentifier<?> id, @Nonnull final AclBaseAttributes acl,
44 @Nonnegative final int ifIndex,
45 @Nonnull final VppClassifierContextManager classifyTableContext,
46 @Nonnull final MappingContext mappingContext) throws WriteFailedException {
47 final InputAclSetInterface request = new InputAclSetInterface();
48 request.isAdd = booleanToByte(isAdd);
49 request.swIfIndex = ifIndex;
50 request.l2TableIndex = ~0; // skip
51 request.ip4TableIndex = ~0; // skip
52 request.ip6TableIndex = ~0; // skip
54 final L2Acl l2Acl = acl.getL2Acl();
56 final String tableName = checkNotNull(l2Acl.getClassifyTable(), "L2 classify table is null");
57 request.l2TableIndex = classifyTableContext.getTableIndex(tableName, mappingContext);
59 final Ip4Acl ip4Acl = acl.getIp4Acl();
61 final String tableName = checkNotNull(ip4Acl.getClassifyTable(), "IPv4 classify table is null");
62 request.ip4TableIndex = classifyTableContext.getTableIndex(tableName, mappingContext);
64 final Ip6Acl ip6Acl = acl.getIp6Acl();
66 final String tableName = checkNotNull(ip6Acl.getClassifyTable(), "IPv6 classify table is null");
67 request.ip6TableIndex = classifyTableContext.getTableIndex(tableName, mappingContext);
70 final CompletionStage<InputAclSetInterfaceReply> inputAclSetInterfaceReplyCompletionStage =
71 futureJVppCore.inputAclSetInterface(request);
73 getReplyForWrite(inputAclSetInterfaceReplyCompletionStage.toCompletableFuture(), id);