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.interfacesstate;
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.honeycomb.translate.read.ReadFailedException;
25 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
26 import io.fd.honeycomb.translate.v3po.util.NamingContext;
27 import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
28 import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
29 import org.junit.Test;
30 import org.mockito.Mock;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4AclBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6AclBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentation;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfaces;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterface;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.AclBuilder;
43 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
44 import org.openvpp.jvpp.core.dto.ClassifyTableByInterfaceReply;
46 public class SubInterfaceAclCustomizerTest extends ReaderCustomizerTest<Acl, AclBuilder> {
47 private static final String IFC_CTX_NAME = "ifc-test-instance";
48 private static final String IF_NAME = "local0";
49 private static final int IF_INDEX = 1;
50 private static final String SUB_IF_NAME = "local0.1";
51 private static final long SUB_IF_ID = 1;
52 private static final int SUB_IF_INDEX = 11;
53 private static final int TABLE_INDEX = 123;
54 private static final String TABLE_NAME = "table123";
56 private static final InstanceIdentifier<Acl> IID =
57 InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
58 .augmentation(SubinterfaceStateAugmentation.class).child(SubInterfaces.class)
59 .child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(Acl.class);
61 private NamingContext interfaceContext;
64 private VppClassifierContextManager classifyTableContext;
66 public SubInterfaceAclCustomizerTest() {
67 super(Acl.class, SubInterfaceBuilder.class);
71 protected void setUp() throws Exception {
72 interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
73 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
74 defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME);
78 protected ReaderCustomizer<Acl, AclBuilder> initCustomizer() {
79 return new SubInterfaceAclCustomizer(api, interfaceContext, classifyTableContext);
83 public void testRead() throws ReadFailedException {
84 final AclBuilder builder = mock(AclBuilder.class);
86 final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply();
87 reply.swIfIndex = SUB_IF_INDEX;
89 reply.ip4TableId = TABLE_INDEX;
90 reply.ip6TableId = TABLE_INDEX;
91 when(api.classifyTableByInterface(any())).thenReturn(future(reply));
93 when(classifyTableContext.getTableName(TABLE_INDEX, mappingContext)).thenReturn(TABLE_NAME);
95 getCustomizer().readCurrentAttributes(IID, builder, ctx);
97 verify(builder).setL2Acl(null);
98 verify(builder).setIp4Acl(new Ip4AclBuilder().setClassifyTable(TABLE_NAME).build());
99 verify(builder).setIp6Acl(new Ip6AclBuilder().setClassifyTable(TABLE_NAME).build());
102 @Test(expected = ReadFailedException.class)
103 public void testReadFailed() throws ReadFailedException {
104 when(api.classifyTableByInterface(any())).thenReturn(failedFuture());
105 getCustomizer().readCurrentAttributes(IID, mock(AclBuilder.class), ctx);