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;
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.when;
23 import io.fd.honeycomb.translate.v3po.util.NamingContext;
24 import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
25 import io.fd.honeycomb.translate.write.WriteFailedException;
26 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
27 import org.junit.Test;
28 import org.mockito.Mock;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4Acl;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4AclBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6Acl;
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.SubinterfaceAugmentation;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.AclBuilder;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import org.openvpp.jvpp.core.dto.InputAclSetInterface;
44 import org.openvpp.jvpp.core.dto.InputAclSetInterfaceReply;
46 public class SubInterfaceAclCustomizerTest extends WriterCustomizerTest {
47 private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
48 private static final String IF_NAME = "local0";
49 private static final int IF_INDEX = 1;
50 private static final String SUBIF_NAME = "local0.0";
51 private static final int SUBIF_INDEX = 11;
52 private static final long SUBIF_ID = 0;
53 private static final String TABLE_NAME = "table0";
54 private static final int TABLE_INDEX = 123;
56 private static final InstanceIdentifier<Acl> IID =
57 InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation(
58 SubinterfaceAugmentation.class).child(SubInterfaces.class)
59 .child(SubInterface.class, new SubInterfaceKey(SUBIF_ID)).child(Acl.class);
62 private VppClassifierContextManager classifyTableContext;
64 private SubInterfaceAclCustomizer customizer;
67 protected void setUp() throws Exception {
68 customizer = new SubInterfaceAclCustomizer(api, new NamingContext("prefix", IFC_TEST_INSTANCE),
69 classifyTableContext);
70 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
71 defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
72 when(classifyTableContext.getTableIndex(TABLE_NAME, mappingContext)).thenReturn(TABLE_INDEX);
76 public void testCreate() throws WriteFailedException {
77 when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
78 customizer.writeCurrentAttributes(IID, ip4Acl(), writeContext);
79 verify(api).inputAclSetInterface(expectedIp4AclRequest());
82 @Test(expected = WriteFailedException.CreateFailedException.class)
83 public void testCreateFailed() throws WriteFailedException {
84 when(api.inputAclSetInterface(any())).thenReturn(failedFuture());
85 customizer.writeCurrentAttributes(IID, ip4Acl(), writeContext);
88 @Test(expected = UnsupportedOperationException.class)
89 public void testUpdate() throws WriteFailedException {
90 customizer.updateCurrentAttributes(IID, ip4Acl(), ip6Acl(), writeContext);
94 public void testDelete() throws Exception {
95 when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
96 customizer.deleteCurrentAttributes(IID, ip6Acl(), writeContext);
97 verify(api).inputAclSetInterface(expectedIp6AclRequest());
100 @Test(expected = WriteFailedException.DeleteFailedException.class)
101 public void testDeleteFailed() throws WriteFailedException {
102 when(api.inputAclSetInterface(any())).thenReturn(failedFuture());
103 customizer.deleteCurrentAttributes(IID, ip4Acl(), writeContext);
106 private Acl ip4Acl() {
107 final AclBuilder builder = new AclBuilder();
108 final Ip4Acl acl = new Ip4AclBuilder().setClassifyTable(TABLE_NAME).build();
109 builder.setIp4Acl(acl);
110 return builder.build();
113 private InputAclSetInterface expectedIp4AclRequest() {
114 final InputAclSetInterface request = new InputAclSetInterface();
116 request.l2TableIndex = -1;
117 request.ip4TableIndex = TABLE_INDEX;
118 request.ip6TableIndex = -1;
119 request.swIfIndex = SUBIF_INDEX;
123 private Acl ip6Acl() {
124 final AclBuilder builder = new AclBuilder();
125 final Ip6Acl acl = new Ip6AclBuilder().setClassifyTable(TABLE_NAME).build();
126 builder.setIp6Acl(acl);
127 return builder.build();
130 private InputAclSetInterface expectedIp6AclRequest() {
131 final InputAclSetInterface request = new InputAclSetInterface();
133 request.l2TableIndex = -1;
134 request.ip4TableIndex = -1;
135 request.ip6TableIndex = TABLE_INDEX;
136 request.swIfIndex = SUBIF_INDEX;