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.hc2vpp.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.hc2vpp.common.test.write.WriterCustomizerTest;
25 import io.fd.hc2vpp.common.translate.util.NamingContext;
26 import io.fd.hc2vpp.v3po.interfaces.acl.IetfAclWriter;
27 import io.fd.hc2vpp.v3po.interfaces.acl.common.AclTableContextManager;
28 import io.fd.honeycomb.translate.write.WriteFailedException;
29 import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterface;
30 import io.fd.vpp.jvpp.core.dto.InputAclSetInterface;
31 import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply;
32 import java.util.Collections;
33 import org.junit.Test;
34 import org.mockito.Mock;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AclBase;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.EthAcl;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclKey;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.AccessListEntriesBuilder;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
42 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;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classfier.acl.rev161214.ietf.acl.base.attributes.AccessListsBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classfier.acl.rev161214.ietf.acl.base.attributes.access.lists.AclBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceAugmentation;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.SubInterfaces;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterface;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceKey;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.IetfAcl;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.ietf.acl.Ingress;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.ietf.acl.IngressBuilder;
53 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
55 public class SubInterfaceIetfAclCustomizerTest extends WriterCustomizerTest {
57 private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
58 private static final String IF_NAME = "local0";
59 private static final int IF_INDEX = 1;
60 private static final String SUBIF_NAME = "local0.123";
61 private static final int SUBIF_INDEX = 2;
62 private static final long SUB_IF_ID = 123;
63 private static final InstanceIdentifier<Ingress> IID =
64 InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation(
65 SubinterfaceAugmentation.class).child(SubInterfaces.class)
66 .child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(IetfAcl.class).child(Ingress.class);
67 private static final String ACL_NAME = "acl1";
68 private static final Class<? extends AclBase> ACL_TYPE = EthAcl.class;
70 private SubInterfaceIetfAclCustomizer customizer;
74 private AclTableContextManager aclCtx;
76 private static InputAclSetInterface inputAclSetInterfaceWriteRequest() {
77 final InputAclSetInterface request = new InputAclSetInterface();
78 request.swIfIndex = SUBIF_INDEX;
80 request.l2TableIndex = -1;
81 request.ip4TableIndex = -1;
82 request.ip6TableIndex = -1;
86 private static InputAclSetInterface inputAclSetInterfaceDeleteRequest() {
87 final InputAclSetInterface request = new InputAclSetInterface();
88 request.swIfIndex = SUBIF_INDEX;
89 request.l2TableIndex = -1;
90 request.ip4TableIndex = -1;
91 request.ip6TableIndex = -1;
96 protected void setUpTest() {
98 new SubInterfaceIetfAclCustomizer(new IngressIetfAclWriter(api, aclCtx), new NamingContext("prefix", IFC_TEST_INSTANCE));
99 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
101 acl = new IngressBuilder().setAccessLists(
102 new AccessListsBuilder().setAcl(
103 Collections.singletonList(new AclBuilder()
112 public void testDelete() throws WriteFailedException {
113 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
114 defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
115 when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
116 when(aclCtx.getEntry(SUBIF_INDEX, mappingContext)).thenReturn(Optional.of(
117 new MappingEntryBuilder()
118 .setIndex(SUBIF_INDEX)
124 customizer.deleteCurrentAttributes(IID, acl, writeContext);
126 final ClassifyTableByInterface expectedRequest = new ClassifyTableByInterface();
127 expectedRequest.swIfIndex = SUBIF_INDEX;
128 verify(api).inputAclSetInterface(inputAclSetInterfaceDeleteRequest());
132 public void testWrite() throws WriteFailedException {
133 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
134 defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
136 when(writeContext.readAfter(IID.firstIdentifierOf(SubInterface.class))).thenReturn(Optional.of(
137 new SubInterfaceBuilder().build()
140 when(writeContext.readAfter(IetfAclWriter.ACL_ID.child(
141 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl.class,
142 new AclKey(ACL_NAME, ACL_TYPE)))).thenReturn(Optional.of(
143 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclBuilder()
144 .setAccessListEntries(
145 new AccessListEntriesBuilder().setAce(Collections.emptyList()).build()
149 when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
151 customizer.writeCurrentAttributes(IID, acl, writeContext);
153 verify(api).inputAclSetInterface(inputAclSetInterfaceWriteRequest());