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.vpp.util.NamingContext;
25 import io.fd.honeycomb.translate.write.WriteFailedException;
26 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
27 import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterface;
28 import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply;
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.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AclBase;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.EthAcl;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclKey;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.AccessListEntriesBuilder;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.ietf.acl.base.attributes.AccessListsBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.ietf.acl.base.attributes.access.lists.AclBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceAugmentation;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.SubInterfaces;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterface;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceKey;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.IetfAcl;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.ietf.acl.Ingress;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.ietf.acl.IngressBuilder;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
52 public class SubInterfaceIetfAclCustomizerTest extends WriterCustomizerTest {
54 private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
55 private static final String IF_NAME = "local0";
56 private static final int IF_INDEX = 1;
57 private static final String SUBIF_NAME = "local0.123";
58 private static final int SUBIF_INDEX = 2;
59 private static final long SUB_IF_ID = 123;
60 private static final InstanceIdentifier<Ingress> IID =
61 InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation(
62 SubinterfaceAugmentation.class).child(SubInterfaces.class)
63 .child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(IetfAcl.class).child(Ingress.class);
64 private static final String ACL_NAME = "acl1";
65 private static final Class<? extends AclBase> ACL_TYPE = EthAcl.class;
67 private SubInterfaceIetfAclCustomizer customizer;
71 protected void setUp() {
73 new SubInterfaceIetfAclCustomizer(new IetfAclWriter(api), new NamingContext("prefix", IFC_TEST_INSTANCE));
74 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
76 acl = new IngressBuilder().setAccessLists(
77 new AccessListsBuilder().setAcl(
78 Collections.singletonList(new AclBuilder()
86 private static InputAclSetInterface inputAclSetInterfaceWriteRequest() {
87 final InputAclSetInterface request = new InputAclSetInterface();
88 request.swIfIndex = SUBIF_INDEX;
90 request.l2TableIndex = -1;
91 request.ip4TableIndex = -1;
92 request.ip6TableIndex = -1;
97 public void testDelete() throws WriteFailedException {
98 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
99 defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
100 when(api.classifyTableByInterface(any())).thenReturn(future(noClassifyTablesAssigned()));
101 when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
103 customizer.deleteCurrentAttributes(IID, acl, writeContext);
105 final ClassifyTableByInterface expectedRequest = new ClassifyTableByInterface();
106 expectedRequest.swIfIndex = SUBIF_INDEX;
107 verify(api).classifyTableByInterface(expectedRequest);
108 verify(api).inputAclSetInterface(inputAclSetInterfaceDeleteRequest());
111 private static ClassifyTableByInterfaceReply noClassifyTablesAssigned() {
112 final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply();
113 reply.l2TableId = -1;
114 reply.ip4TableId = -1;
115 reply.ip6TableId = -1;
119 private static InputAclSetInterface inputAclSetInterfaceDeleteRequest() {
120 final InputAclSetInterface request = new InputAclSetInterface();
121 request.l2TableIndex = -1;
122 request.ip4TableIndex = -1;
123 request.ip6TableIndex = -1;
128 public void testWrite() throws WriteFailedException {
129 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
130 defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
132 when(writeContext.readAfter(IID.firstIdentifierOf(SubInterface.class))).thenReturn(Optional.of(
133 new SubInterfaceBuilder().build()
136 when(writeContext.readAfter(io.fd.honeycomb.translate.v3po.interfaces.acl.IetfAclWriter.ACL_ID.child(
137 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl.class,
138 new AclKey(ACL_NAME, ACL_TYPE)))).thenReturn(Optional.of(
139 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclBuilder()
140 .setAccessListEntries(
141 new AccessListEntriesBuilder().setAce(Collections.emptyList()).build()
145 when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
147 customizer.writeCurrentAttributes(IID, acl, writeContext);
149 verify(api).inputAclSetInterface(inputAclSetInterfaceWriteRequest());