HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / interfacesstate / acl / ingress / SubInterfaceAclCustomizerTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.translate.v3po.interfacesstate.acl.ingress;
18
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;
23
24 import io.fd.honeycomb.translate.read.ReadFailedException;
25 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
26 import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
27 import io.fd.honeycomb.translate.vpp.util.NamingContext;
28 import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
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.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.acl.base.attributes.Ip4AclBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.acl.base.attributes.Ip6AclBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceStateAugmentation;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfaces;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.Acl;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.AclBuilder;
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;
46
47 public class SubInterfaceAclCustomizerTest extends ReaderCustomizerTest<Ingress, IngressBuilder> {
48     private static final String IFC_CTX_NAME = "ifc-test-instance";
49     private static final String IF_NAME = "local0";
50     private static final int IF_INDEX = 1;
51     private static final String SUB_IF_NAME = "local0.1";
52     private static final long SUB_IF_ID = 1;
53     private static final int SUB_IF_INDEX = 11;
54     private static final int TABLE_INDEX = 123;
55     private static final String TABLE_NAME = "table123";
56
57     private static final InstanceIdentifier<Ingress> IID =
58         InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
59             .augmentation(SubinterfaceStateAugmentation.class).child(SubInterfaces.class)
60             .child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(Acl.class).child(Ingress.class);
61
62     private NamingContext interfaceContext;
63
64     @Mock
65     private VppClassifierContextManager classifyTableContext;
66
67     public SubInterfaceAclCustomizerTest() {
68         super(Ingress.class, AclBuilder.class);
69     }
70
71     @Override
72     protected void setUp() throws Exception {
73         interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
74         defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
75         defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME);
76     }
77
78     @Override
79     protected ReaderCustomizer<Ingress, IngressBuilder> initCustomizer() {
80         return new SubInterfaceAclCustomizer(api, interfaceContext, classifyTableContext);
81     }
82
83     @Test
84     public void testRead() throws ReadFailedException {
85         final IngressBuilder builder = mock(IngressBuilder.class);
86
87         final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply();
88         reply.swIfIndex = SUB_IF_INDEX;
89         reply.l2TableId = ~0;
90         reply.ip4TableId = TABLE_INDEX;
91         reply.ip6TableId = TABLE_INDEX;
92         when(api.classifyTableByInterface(any())).thenReturn(future(reply));
93
94         when(classifyTableContext.getTableName(TABLE_INDEX, mappingContext)).thenReturn(TABLE_NAME);
95
96         getCustomizer().readCurrentAttributes(IID, builder, ctx);
97
98         verify(builder).setL2Acl(null);
99         verify(builder).setIp4Acl(new Ip4AclBuilder().setClassifyTable(TABLE_NAME).build());
100         verify(builder).setIp6Acl(new Ip6AclBuilder().setClassifyTable(TABLE_NAME).build());
101     }
102
103     @Test(expected = ReadFailedException.class)
104     public void testReadFailed() throws ReadFailedException {
105         when(api.classifyTableByInterface(any())).thenReturn(failedFuture());
106         getCustomizer().readCurrentAttributes(IID, mock(IngressBuilder.class), ctx);
107     }
108 }