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 io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
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.InputAclSetInterface;
28 import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply;
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.Interfaces;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.Ip4Acl;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.Ip4AclBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.Ip6Acl;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.Ip6AclBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceAugmentation;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.SubInterfaces;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterface;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceKey;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.Acl;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.acl.Ingress;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.acl.IngressBuilder;
45 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
47 public class SubInterfaceAclCustomizerTest extends WriterCustomizerTest {
48 private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
49 private static final String IF_NAME = "local0";
50 private static final int IF_INDEX = 1;
51 private static final String SUBIF_NAME = "local0.0";
52 private static final int SUBIF_INDEX = 11;
53 private static final long SUBIF_ID = 0;
54 private static final String TABLE_NAME = "table0";
55 private static final int TABLE_INDEX = 123;
57 private static final InstanceIdentifier<Ingress> IID =
58 InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation(
59 SubinterfaceAugmentation.class).child(SubInterfaces.class)
60 .child(SubInterface.class, new SubInterfaceKey(SUBIF_ID)).child(Acl.class).child(Ingress.class);
63 private VppClassifierContextManager classifyTableContext;
65 private SubInterfaceAclCustomizer customizer;
68 protected void setUp() throws Exception {
69 customizer = new SubInterfaceAclCustomizer(api, new NamingContext("prefix", IFC_TEST_INSTANCE),
70 classifyTableContext);
71 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
72 defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
73 when(classifyTableContext.getTableIndex(TABLE_NAME, mappingContext)).thenReturn(TABLE_INDEX);
77 public void testCreate() throws WriteFailedException {
78 when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
79 customizer.writeCurrentAttributes(IID, ip4Acl(), writeContext);
80 verify(api).inputAclSetInterface(expectedIp4AclRequest());
83 @Test(expected = WriteFailedException.class)
84 public void testCreateFailed() throws WriteFailedException {
85 when(api.inputAclSetInterface(any())).thenReturn(failedFuture());
86 customizer.writeCurrentAttributes(IID, ip4Acl(), writeContext);
89 @Test(expected = UnsupportedOperationException.class)
90 public void testUpdate() throws WriteFailedException {
91 customizer.updateCurrentAttributes(IID, ip4Acl(), ip6Acl(), writeContext);
95 public void testDelete() throws Exception {
96 when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
97 customizer.deleteCurrentAttributes(IID, ip6Acl(), writeContext);
98 verify(api).inputAclSetInterface(expectedIp6AclRequest());
101 @Test(expected = WriteFailedException.class)
102 public void testDeleteFailed() throws WriteFailedException {
103 when(api.inputAclSetInterface(any())).thenReturn(failedFuture());
104 customizer.deleteCurrentAttributes(IID, ip4Acl(), writeContext);
107 private Ingress ip4Acl() {
108 final IngressBuilder builder = new IngressBuilder();
109 final Ip4Acl acl = new Ip4AclBuilder().setClassifyTable(TABLE_NAME).build();
110 builder.setIp4Acl(acl);
111 return builder.build();
114 private InputAclSetInterface expectedIp4AclRequest() {
115 final InputAclSetInterface request = new InputAclSetInterface();
117 request.l2TableIndex = -1;
118 request.ip4TableIndex = TABLE_INDEX;
119 request.ip6TableIndex = -1;
120 request.swIfIndex = SUBIF_INDEX;
124 private Ingress ip6Acl() {
125 final IngressBuilder builder = new IngressBuilder();
126 final Ip6Acl acl = new Ip6AclBuilder().setClassifyTable(TABLE_NAME).build();
127 builder.setIp6Acl(acl);
128 return builder.build();
131 private InputAclSetInterface expectedIp6AclRequest() {
132 final InputAclSetInterface request = new InputAclSetInterface();
134 request.l2TableIndex = -1;
135 request.ip4TableIndex = -1;
136 request.ip6TableIndex = TABLE_INDEX;
137 request.swIfIndex = SUBIF_INDEX;