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 org.mockito.Matchers.any;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.when;
23 import com.google.common.base.Optional;
24 import io.fd.honeycomb.translate.v3po.interfaces.acl.common.AclTableContextManager;
25 import io.fd.honeycomb.translate.vpp.util.NamingContext;
26 import io.fd.honeycomb.translate.write.WriteFailedException;
27 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
28 import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterface;
29 import io.fd.vpp.jvpp.core.dto.InputAclSetInterface;
30 import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply;
31 import java.util.Collections;
32 import org.junit.Test;
33 import org.mockito.Mock;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AclBase;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.EthAcl;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclKey;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.AccessListEntriesBuilder;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.mapping.table.MappingEntryBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.ietf.acl.base.attributes.AccessListsBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.ietf.acl.base.attributes.access.lists.AclBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceAugmentation;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.SubInterfaces;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterface;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceKey;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.IetfAcl;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.ietf.acl.Ingress;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.ietf.acl.IngressBuilder;
52 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
54 public class SubInterfaceIetfAclCustomizerTest extends WriterCustomizerTest {
56 private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
57 private static final String IF_NAME = "local0";
58 private static final int IF_INDEX = 1;
59 private static final String SUBIF_NAME = "local0.123";
60 private static final int SUBIF_INDEX = 2;
61 private static final long SUB_IF_ID = 123;
62 private static final InstanceIdentifier<Ingress> IID =
63 InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation(
64 SubinterfaceAugmentation.class).child(SubInterfaces.class)
65 .child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(IetfAcl.class).child(Ingress.class);
66 private static final String ACL_NAME = "acl1";
67 private static final Class<? extends AclBase> ACL_TYPE = EthAcl.class;
69 private SubInterfaceIetfAclCustomizer customizer;
73 private AclTableContextManager aclCtx;
76 protected void setUp() {
78 new SubInterfaceIetfAclCustomizer(new IngressIetfAclWriter(api, aclCtx), new NamingContext("prefix", IFC_TEST_INSTANCE));
79 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
81 acl = new IngressBuilder().setAccessLists(
82 new AccessListsBuilder().setAcl(
83 Collections.singletonList(new AclBuilder()
91 private static InputAclSetInterface inputAclSetInterfaceWriteRequest() {
92 final InputAclSetInterface request = new InputAclSetInterface();
93 request.swIfIndex = SUBIF_INDEX;
95 request.l2TableIndex = -1;
96 request.ip4TableIndex = -1;
97 request.ip6TableIndex = -1;
102 public void testDelete() throws WriteFailedException {
103 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
104 defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
105 when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
106 when(aclCtx.getEntry(SUBIF_INDEX, mappingContext)).thenReturn(Optional.of(
107 new MappingEntryBuilder()
108 .setIndex(SUBIF_INDEX)
114 customizer.deleteCurrentAttributes(IID, acl, writeContext);
116 final ClassifyTableByInterface expectedRequest = new ClassifyTableByInterface();
117 expectedRequest.swIfIndex = SUBIF_INDEX;
118 verify(api).inputAclSetInterface(inputAclSetInterfaceDeleteRequest());
121 private static InputAclSetInterface inputAclSetInterfaceDeleteRequest() {
122 final InputAclSetInterface request = new InputAclSetInterface();
123 request.swIfIndex = SUBIF_INDEX;
124 request.l2TableIndex = -1;
125 request.ip4TableIndex = -1;
126 request.ip6TableIndex = -1;
131 public void testWrite() throws WriteFailedException {
132 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
133 defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
135 when(writeContext.readAfter(IID.firstIdentifierOf(SubInterface.class))).thenReturn(Optional.of(
136 new SubInterfaceBuilder().build()
139 when(writeContext.readAfter(io.fd.honeycomb.translate.v3po.interfaces.acl.IetfAclWriter.ACL_ID.child(
140 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl.class,
141 new AclKey(ACL_NAME, ACL_TYPE)))).thenReturn(Optional.of(
142 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclBuilder()
143 .setAccessListEntries(
144 new AccessListEntriesBuilder().setAce(Collections.emptyList()).build()
148 when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
150 customizer.writeCurrentAttributes(IID, acl, writeContext);
152 verify(api).inputAclSetInterface(inputAclSetInterfaceWriteRequest());