2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.bgp.openconfig.impl.util;
11 import static org.junit.Assert.assertEquals;
12 import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.getModuleName;
13 import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.toAfiSafi;
15 import com.google.common.base.Optional;
16 import com.google.common.collect.Lists;
17 import java.lang.reflect.Constructor;
18 import java.lang.reflect.InvocationTargetException;
19 import java.util.Collections;
20 import java.util.List;
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.opendaylight.protocol.bgp.mode.impl.add.all.paths.AllPathSelection;
24 import org.opendaylight.protocol.bgp.mode.impl.add.n.paths.AddPathBestNPathSelection;
25 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
26 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
27 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder;
28 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.use.multiple.paths.UseMultiplePaths;
29 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.AfiSafi1;
30 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.AfiSafi2;
31 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.SendReceive;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamiliesBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
39 public class OpenConfigUtilTest {
41 private static final BgpTableType BGP_TABLE_TYPE_IPV4 = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
42 private static final AfiSafi AFISAFI_IPV4 = new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class).build();
43 private static final String TEST = "/modules/module[type='dom-concurrent-data-broker'][name='concurrent-data-broker']";
47 final String moduleName = getModuleName(TEST);
48 assertEquals("concurrent-data-broker", moduleName);
52 public void testGetModuleType() {
53 final String moduleType = OpenConfigUtil.getModuleType(TEST);
54 assertEquals("dom-concurrent-data-broker", moduleType);
58 public void testToAfiSafi() {
59 assertEquals(toAfiSafi(BGP_TABLE_TYPE_IPV4).get(),
64 public void testToBgpTableType() {
65 final Optional<BgpTableType> bgpTableType = OpenConfigUtil.toBgpTableType(IPV4UNICAST.class);
66 assertEquals(BGP_TABLE_TYPE_IPV4, bgpTableType.get());
70 public void testToAfiSafis() {
71 final List<AfiSafi> afiSafis = OpenConfigUtil.toAfiSafis(Lists.<BgpTableType>newArrayList(BGP_TABLE_TYPE_IPV4),
72 (afisafi, tableType) -> afisafi);
73 Assert.assertEquals(Collections.singletonList(AFISAFI_IPV4), afiSafis);
77 public void toNeigborAfiSafiMultiPathMatch() {
78 final AfiSafi afiSafi = OpenConfigUtil.toNeigborAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4,
79 Lists.newArrayList(new AddressFamiliesBuilder(BGP_TABLE_TYPE_IPV4).setSendReceive(SendReceive.Both).build()));
80 Assert.assertTrue(afiSafi.getAugmentation(AfiSafi2.class).getUseMultiplePaths().getConfig().isEnabled());
84 public void toNeigborAfiSafiMultiPathNoMatch() {
85 final AfiSafi afiSafi = OpenConfigUtil.toNeigborAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, Collections.emptyList());
86 Assert.assertEquals(AFISAFI_IPV4, afiSafi);
90 public void toGlobalAfiSafiMultiPathNPaths() {
91 final AfiSafi afiSafi = OpenConfigUtil.toGlobalAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4,
92 Collections.singletonMap(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), new AddPathBestNPathSelection(5L)));
93 final UseMultiplePaths multiplePaths = afiSafi.getAugmentation(AfiSafi1.class).getUseMultiplePaths();
94 Assert.assertTrue(multiplePaths.getConfig().isEnabled());
95 Assert.assertEquals(5, multiplePaths.getIbgp().getConfig().getMaximumPaths().intValue());
96 Assert.assertEquals(5, multiplePaths.getEbgp().getConfig().getMaximumPaths().intValue());
100 public void toGlobalAfiSafiMultiPathAllPaths() {
101 final AfiSafi afiSafi = OpenConfigUtil.toGlobalAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4,
102 Collections.singletonMap(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), new AllPathSelection()));
103 final UseMultiplePaths multiplePaths = afiSafi.getAugmentation(AfiSafi1.class).getUseMultiplePaths();
104 Assert.assertTrue(multiplePaths.getConfig().isEnabled());
105 Assert.assertNull(multiplePaths.getIbgp());
106 Assert.assertNull(multiplePaths.getEbgp());
110 public void toGlobalAfiSafiMultiPathNoMatch() {
111 final AfiSafi afiSafi = OpenConfigUtil.toGlobalAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4,
112 Collections.emptyMap());
113 Assert.assertEquals(AFISAFI_IPV4, afiSafi);
116 @Test(expected=UnsupportedOperationException.class)
117 public void testPrivateConstructor() throws Throwable {
118 final Constructor<OpenConfigUtil> c = OpenConfigUtil.class.getDeclaredConstructor();
119 c.setAccessible(true);
122 } catch (final InvocationTargetException e) {