01ae61d062c385b415f037a0c09837e2e65ac407
[honeycomb.git] / v3po / v3po2vpp / src / main / java / io / fd / honeycomb / translate / v3po / interfaces / acl / ingress / AclWriter.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.translate.v3po.interfaces.acl.ingress;
18
19 import static com.google.common.base.Preconditions.checkNotNull;
20
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;
39
40 interface AclWriter extends ByteDataTranslator, JvppReplyConsumer {
41
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
53
54         final L2Acl l2Acl = acl.getL2Acl();
55         if (l2Acl != null) {
56             final String tableName = checkNotNull(l2Acl.getClassifyTable(), "L2 classify table is null");
57             request.l2TableIndex = classifyTableContext.getTableIndex(tableName, mappingContext);
58         }
59         final Ip4Acl ip4Acl = acl.getIp4Acl();
60         if (ip4Acl != null) {
61             final String tableName = checkNotNull(ip4Acl.getClassifyTable(), "IPv4 classify table is null");
62             request.ip4TableIndex = classifyTableContext.getTableIndex(tableName, mappingContext);
63         }
64         final Ip6Acl ip6Acl = acl.getIp6Acl();
65         if (ip6Acl != null) {
66             final String tableName = checkNotNull(ip6Acl.getClassifyTable(), "IPv6 classify table is null");
67             request.ip6TableIndex = classifyTableContext.getTableIndex(tableName, mappingContext);
68         }
69
70         final CompletionStage<InputAclSetInterfaceReply> inputAclSetInterfaceReplyCompletionStage =
71                 futureJVppCore.inputAclSetInterface(request);
72
73         getReplyForWrite(inputAclSetInterfaceReplyCompletionStage.toCompletableFuture(), id);
74     }
75 }