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