c5781624ad15de471b74dc0cfefb92c4dc9ab2d7
[hc2vpp.git] /
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.v3po.translate.v3po.interfacesstate;
18
19 import static org.junit.Assert.assertEquals;
20
21 import org.junit.Test;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Tap;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanGpeTunnel;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel;
27
28 public class InterfaceUtilsTest {
29
30     @Test
31     public void testVppPhysAddrToYang() throws Exception {
32         assertEquals("01:02:03:04:05:06", InterfaceUtils.vppPhysAddrToYang(new byte[]{1, 2, 3, 4, 5, 6}));
33         assertEquals("0a:0b:0c:0d:0e:0f", InterfaceUtils.vppPhysAddrToYang(new byte[]{0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 0}));
34     }
35
36     @Test(expected = NullPointerException.class)
37     public void testVppPhysAddrToYangFailNullArgument() throws Exception {
38         InterfaceUtils.vppPhysAddrToYang(null);
39     }
40
41     @Test(expected = IllegalArgumentException.class)
42     public void testVppPhysAddrToYangInvalidByteArrayLength() throws Exception {
43         InterfaceUtils.vppPhysAddrToYang(new byte[]{1, 2, 3, 4, 5});
44     }
45
46     @Test
47     public void testGetInterfaceType() {
48         assertEquals(Tap.class, InterfaceUtils.getInterfaceType("tap0"));
49         assertEquals(VxlanTunnel.class, InterfaceUtils.getInterfaceType("vxlan0"));
50         assertEquals(VxlanGpeTunnel.class, InterfaceUtils.getInterfaceType("vxlan_gpe0"));
51         assertEquals(VhostUser.class, InterfaceUtils.getInterfaceType("VirtualEthernet0/0/0"));
52         assertEquals(EthernetCsmacd.class, InterfaceUtils.getInterfaceType("eth0.0"));
53         assertEquals(EthernetCsmacd.class, InterfaceUtils.getInterfaceType("local0"));
54     }
55 }