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.vpp.classifier.write.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.hc2vpp.common.test.write.WriterCustomizerTest;
24 import io.fd.hc2vpp.common.translate.util.NamingContext;
25 import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
26 import io.fd.honeycomb.translate.write.WriteFailedException;
27 import io.fd.jvpp.core.dto.InputAclSetInterface;
28 import io.fd.jvpp.core.dto.InputAclSetInterfaceReply;
29 import org.junit.Test;
30 import org.mockito.Mock;
31 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.Ip4Acl;
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.Ip6Acl;
34 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.Ip6AclBuilder;
35 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.Acl;
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.VppSubinterfaceAclAugmentation;
39 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation;
40 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces;
41 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface;
42 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey;
46 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
48 public class SubInterfaceAclCustomizerTest extends WriterCustomizerTest {
49 private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
50 private static final String IF_NAME = "local0";
51 private static final int IF_INDEX = 1;
52 private static final String SUBIF_NAME = "local0.0";
53 private static final int SUBIF_INDEX = 11;
54 private static final long SUBIF_ID = 0;
55 private static final String TABLE_NAME = "table0";
56 private static final int TABLE_INDEX = 123;
58 private static final InstanceIdentifier<Ingress> IID =
59 InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation(
60 SubinterfaceAugmentation.class).child(SubInterfaces.class)
61 .child(SubInterface.class, new SubInterfaceKey(SUBIF_ID))
62 .augmentation(VppSubinterfaceAclAugmentation.class)
63 .child(Acl.class).child(Ingress.class);
66 private VppClassifierContextManager classifyTableContext;
68 private SubInterfaceAclCustomizer customizer;
71 protected void setUpTest() throws Exception {
72 customizer = new SubInterfaceAclCustomizer(api, new NamingContext("prefix", IFC_TEST_INSTANCE),
73 classifyTableContext);
74 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
75 defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
76 when(classifyTableContext.getTableIndex(TABLE_NAME, mappingContext)).thenReturn(TABLE_INDEX);
80 public void testCreate() throws WriteFailedException {
81 when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
82 customizer.writeCurrentAttributes(IID, ip4Acl(), writeContext);
83 verify(api).inputAclSetInterface(expectedIp4AclRequest());
86 @Test(expected = WriteFailedException.class)
87 public void testCreateFailed() throws WriteFailedException {
88 when(api.inputAclSetInterface(any())).thenReturn(failedFuture());
89 customizer.writeCurrentAttributes(IID, ip4Acl(), writeContext);
92 @Test(expected = UnsupportedOperationException.class)
93 public void testUpdate() throws WriteFailedException {
94 customizer.updateCurrentAttributes(IID, ip4Acl(), ip6Acl(), writeContext);
98 public void testDelete() throws Exception {
99 when(api.inputAclSetInterface(any())).thenReturn(future(new InputAclSetInterfaceReply()));
100 customizer.deleteCurrentAttributes(IID, ip6Acl(), writeContext);
101 verify(api).inputAclSetInterface(expectedIp6AclRequest());
104 @Test(expected = WriteFailedException.class)
105 public void testDeleteFailed() throws WriteFailedException {
106 when(api.inputAclSetInterface(any())).thenReturn(failedFuture());
107 customizer.deleteCurrentAttributes(IID, ip4Acl(), writeContext);
110 private Ingress ip4Acl() {
111 final IngressBuilder builder = new IngressBuilder();
112 final Ip4Acl acl = new Ip4AclBuilder().setClassifyTable(TABLE_NAME).build();
113 builder.setIp4Acl(acl);
114 return builder.build();
117 private InputAclSetInterface expectedIp4AclRequest() {
118 final InputAclSetInterface request = new InputAclSetInterface();
120 request.l2TableIndex = -1;
121 request.ip4TableIndex = TABLE_INDEX;
122 request.ip6TableIndex = -1;
123 request.swIfIndex = SUBIF_INDEX;
127 private Ingress ip6Acl() {
128 final IngressBuilder builder = new IngressBuilder();
129 final Ip6Acl acl = new Ip6AclBuilder().setClassifyTable(TABLE_NAME).build();
130 builder.setIp6Acl(acl);
131 return builder.build();
134 private InputAclSetInterface expectedIp6AclRequest() {
135 final InputAclSetInterface request = new InputAclSetInterface();
137 request.l2TableIndex = -1;
138 request.ip4TableIndex = -1;
139 request.ip6TableIndex = TABLE_INDEX;
140 request.swIfIndex = SUBIF_INDEX;