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.ByteDataTranslator;
24 import io.fd.honeycomb.translate.v3po.util.NamingContext;
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.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.interconnection.BridgeBasedBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2Builder;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.openvpp.jvpp.core.dto.SwInterfaceSetL2Bridge;
40 import org.openvpp.jvpp.core.dto.SwInterfaceSetL2BridgeReply;
42 public class SubInterfaceL2CustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
43 private static final String IFACE_CTX_NAME = "interface-ctx";
44 private static final String IF_NAME = "local0";
45 private static final int IF_INDEX = 1;
46 private static final String SUBIF_NAME = "local0.0";
47 private static final int SUBIF_INDEX = 11;
48 private static final long SUBIF_ID = 0;
50 private static final InstanceIdentifier<L2> IID =
51 InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation(
52 SubinterfaceAugmentation.class).child(SubInterfaces.class)
53 .child(SubInterface.class, new SubInterfaceKey(SUBIF_ID)).child(L2.class);
56 private static final String BD_CTX_NAME = "bd-ctx";
57 private static final String BD_NAME = "test_bd";
58 private static final int BD_INDEX = 13;
60 private SubInterfaceL2Customizer customizer;
63 protected void setUp() throws Exception {
64 customizer = new SubInterfaceL2Customizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME),
65 new NamingContext("bdPrefix", BD_CTX_NAME));
66 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME);
67 defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFACE_CTX_NAME);
68 defineMapping(mappingContext, BD_NAME, BD_INDEX, BD_CTX_NAME);
72 public void testWrite() throws WriteFailedException {
73 final boolean bvi = true;
74 when(api.swInterfaceSetL2Bridge(any())).thenReturn(future(new SwInterfaceSetL2BridgeReply()));
75 customizer.writeCurrentAttributes(IID, l2(bvi), writeContext);
76 verify(api).swInterfaceSetL2Bridge(bridgeRequest(bvi, true));
80 public void testUpdate() throws WriteFailedException {
81 final boolean bvi = false;
82 when(api.swInterfaceSetL2Bridge(any())).thenReturn(future(new SwInterfaceSetL2BridgeReply()));
83 customizer.updateCurrentAttributes(IID, l2(true), l2(bvi), writeContext);
84 verify(api).swInterfaceSetL2Bridge(bridgeRequest(bvi, true));
88 public void testDelete() throws WriteFailedException {
89 final boolean bvi = true;
90 when(api.swInterfaceSetL2Bridge(any())).thenReturn(future(new SwInterfaceSetL2BridgeReply()));
91 customizer.deleteCurrentAttributes(IID, l2(bvi), writeContext);
92 verify(api).swInterfaceSetL2Bridge(bridgeRequest(bvi, false));
95 private L2 l2(final boolean bvi) {
96 return new L2Builder().setInterconnection(new BridgeBasedBuilder().setBridgedVirtualInterface(bvi)
97 .setBridgeDomain(BD_NAME).setSplitHorizonGroup((short) 123).build()).build();
100 private SwInterfaceSetL2Bridge bridgeRequest(final boolean bvi, final boolean enable) {
101 final SwInterfaceSetL2Bridge request = new SwInterfaceSetL2Bridge();
102 request.bdId = BD_INDEX;
103 request.rxSwIfIndex = SUBIF_INDEX;
104 request.bvi = booleanToByte(bvi);
105 request.enable = booleanToByte(enable);