2 * Copyright (c) 2017 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.vpp.classifier.read.acl;
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.verify;
22 import static org.mockito.Mockito.when;
24 import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
25 import io.fd.hc2vpp.common.translate.util.NamingContext;
26 import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
27 import io.fd.honeycomb.translate.read.ReadFailedException;
28 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
29 import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply;
30 import org.junit.Test;
31 import org.mockito.Mock;
32 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.Ip4AclBuilder;
33 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.Ip6AclBuilder;
34 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.Acl;
35 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.AclBuilder;
36 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.Ingress;
37 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.IngressBuilder;
38 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.subinterface.acl.rev170315.VppSubinterfaceAclStateAugmentation;
39 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation;
40 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces;
41 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface;
42 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceKey;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
46 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
48 public class SubInterfaceAclCustomizerTest extends ReaderCustomizerTest<Ingress, IngressBuilder> {
49 private static final String IFC_CTX_NAME = "ifc-test-instance";
50 private static final String IF_NAME = "local0";
51 private static final int IF_INDEX = 1;
52 private static final String SUB_IF_NAME = "local0.1";
53 private static final long SUB_IF_ID = 1;
54 private static final int SUB_IF_INDEX = 11;
55 private static final int TABLE_INDEX = 123;
56 private static final String TABLE_NAME = "table123";
58 private static final InstanceIdentifier<Ingress> IID =
59 InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
60 .augmentation(SubinterfaceStateAugmentation.class).child(SubInterfaces.class)
61 .child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID))
62 .augmentation(VppSubinterfaceAclStateAugmentation.class)
63 .child(Acl.class).child(Ingress.class);
65 private NamingContext interfaceContext;
68 private VppClassifierContextManager classifyTableContext;
70 public SubInterfaceAclCustomizerTest() {
71 super(Ingress.class, AclBuilder.class);
75 protected void setUp() throws Exception {
76 interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
77 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
78 defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME);
82 protected ReaderCustomizer<Ingress, IngressBuilder> initCustomizer() {
83 return new SubInterfaceAclCustomizer(api, interfaceContext, classifyTableContext);
87 public void testRead() throws ReadFailedException {
88 final IngressBuilder builder = mock(IngressBuilder.class);
90 final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply();
91 reply.swIfIndex = SUB_IF_INDEX;
93 reply.ip4TableId = TABLE_INDEX;
94 reply.ip6TableId = TABLE_INDEX;
95 when(api.classifyTableByInterface(any())).thenReturn(future(reply));
97 when(classifyTableContext.getTableName(TABLE_INDEX, mappingContext)).thenReturn(TABLE_NAME);
99 getCustomizer().readCurrentAttributes(IID, builder, ctx);
101 verify(builder).setL2Acl(null);
102 verify(builder).setIp4Acl(new Ip4AclBuilder().setClassifyTable(TABLE_NAME).build());
103 verify(builder).setIp6Acl(new Ip6AclBuilder().setClassifyTable(TABLE_NAME).build());
106 @Test(expected = ReadFailedException.class)
107 public void testReadFailed() throws ReadFailedException {
108 when(api.classifyTableByInterface(any())).thenReturn(failedFuture());
109 getCustomizer().readCurrentAttributes(IID, mock(IngressBuilder.class), ctx);