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.interfacesstate;
19 import static org.mockito.Mockito.mock;
20 import static org.mockito.Mockito.verify;
22 import io.fd.honeycomb.translate.read.ReadFailedException;
23 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
24 import io.fd.honeycomb.translate.vpp.util.NamingContext;
25 import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
26 import io.fd.honeycomb.vpp.test.util.InterfaceDumpHelper;
27 import org.junit.Test;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.EthernetStateAttributes;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Ethernet;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.EthernetBuilder;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
39 public class EthernetCustomizerTest extends ReaderCustomizerTest<Ethernet, EthernetBuilder> implements
41 private static final String IFC_CTX_NAME = "ifc-test-instance";
42 private static final String IF_NAME = "local0";
43 private static final int IF_INDEX = 1;
44 private static final InstanceIdentifier<Ethernet> IID =
45 InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
46 .augmentation(VppInterfaceStateAugmentation.class).child(Ethernet.class);
47 private NamingContext interfaceContext;
49 public EthernetCustomizerTest() {
50 super(Ethernet.class, VppInterfaceStateAugmentationBuilder.class);
54 protected void setUp() throws Exception {
55 interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
56 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
60 protected ReaderCustomizer<Ethernet, EthernetBuilder> initCustomizer() {
61 return new EthernetCustomizer(api, interfaceContext);
64 private void testRead(final int linkDuplex, final EthernetStateAttributes.Duplex duplex) throws ReadFailedException {
65 final EthernetBuilder builder = mock(EthernetBuilder.class);
66 final short mtu = 123;
67 whenSwInterfaceDumpThenReturn(api, ifaceDetails(mtu, linkDuplex));
68 getCustomizer().readCurrentAttributes(IID, builder, ctx);
69 verify(builder).setMtu((int)mtu);
70 verify(builder).setDuplex(duplex);
73 private SwInterfaceDetails ifaceDetails(final short mtu, final int duplex) {
74 final SwInterfaceDetails details = new SwInterfaceDetails();
75 details.swIfIndex = IF_INDEX;
76 details.linkMtu = mtu;
77 details.linkDuplex = (byte)duplex;
82 public void testReadHalfDuplex() throws ReadFailedException {
83 testRead(1, EthernetStateAttributes.Duplex.Half);
87 public void testReadFullDuplex() throws ReadFailedException {
88 testRead(2, EthernetStateAttributes.Duplex.Full);