1d0a9063b2618eaee210ef555da3773d86445a43
[bgpcep.git] / bgp / parser-spi / src / test / java / org / opendaylight / protocol / bgp / parser / spi / pojo / MultiPathSupportImplTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.bgp.parser.spi.pojo;
10
11 import com.google.common.collect.Lists;
12 import java.util.List;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
16 import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.SendReceive;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamilies;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamiliesBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
25
26 public class MultiPathSupportImplTest {
27
28     @Test(expected=NullPointerException.class)
29     public void testcreateParserMultiPathSupportNull() {
30         MultiPathSupportImpl.createParserMultiPathSupport(null);
31     }
32
33     @Test
34     public void testIsTableTypeSupported() {
35         final List<AddressFamilies> supportedTables = Lists.newArrayList();
36         final BgpTableType ipv4Unicast = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
37         final BgpTableType ipv4L3vpn = new BgpTableTypeImpl(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class);
38         final BgpTableType ipv6Unicast = new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
39         final BgpTableType ipv6L3vpn = new BgpTableTypeImpl(Ipv6AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class);
40         supportedTables.add(createAddPathCapability(ipv4Unicast, SendReceive.Send));
41         supportedTables.add(createAddPathCapability(ipv4L3vpn, SendReceive.Receive));
42         supportedTables.add(createAddPathCapability(ipv6Unicast, SendReceive.Both));
43         final MultiPathSupport multiPathSupport = MultiPathSupportImpl.createParserMultiPathSupport(supportedTables);
44
45         Assert.assertTrue(multiPathSupport.isTableTypeSupported(ipv4Unicast));
46         Assert.assertTrue(multiPathSupport.isTableTypeSupported(ipv6Unicast));
47         Assert.assertFalse(multiPathSupport.isTableTypeSupported(ipv4L3vpn));
48         Assert.assertFalse(multiPathSupport.isTableTypeSupported(ipv6L3vpn));
49     }
50
51     private static AddressFamilies createAddPathCapability(final BgpTableType afisafi, final SendReceive mode) {
52         return new AddressFamiliesBuilder().setAfi(afisafi.getAfi()).setSafi(afisafi.getSafi()).setSendReceive(mode).build();
53     }
54
55 }