2 * Copyright (c) 2018 AT&T Intellectual Property. 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
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertTrue;
16 import java.util.Collections;
17 import org.junit.Test;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.UpdateBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlri;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
32 public class BgpPeerUtilTest {
34 private final TablesKey IPV4_TABLE_KEY = new TablesKey(Ipv4AddressFamily.class,
35 UnicastSubsequentAddressFamily.class);
36 private final TablesKey IPV6_TABLE_KEY = new TablesKey(Ipv6AddressFamily.class,
37 UnicastSubsequentAddressFamily.class);
40 public void createIpv4EORTest() {
41 final Update endOfRib = BgpPeerUtil.createEndOfRib(IPV4_TABLE_KEY);
42 assertNull(endOfRib.getNlri());
43 assertNull(endOfRib.getWithdrawnRoutes());
44 assertNull(endOfRib.getAttributes());
48 public void createNonIpv4EORTest() {
49 final Update endOfRib = BgpPeerUtil.createEndOfRib(IPV6_TABLE_KEY);
50 assertNull(endOfRib.getNlri());
51 assertNull(endOfRib.getWithdrawnRoutes());
52 final Attributes attributes = endOfRib.getAttributes();
53 assertNotNull(attributes);
54 final Attributes2 augmentation = attributes.augmentation(Attributes2.class);
55 assertNotNull(augmentation);
56 final MpUnreachNlri mpUnreachNlri = augmentation.getMpUnreachNlri();
57 assertNotNull(mpUnreachNlri);
58 assertEquals(IPV6_TABLE_KEY.getAfi(), mpUnreachNlri.getAfi());
59 assertEquals(IPV6_TABLE_KEY.getSafi(), mpUnreachNlri.getSafi());
60 assertNull(mpUnreachNlri.getWithdrawnRoutes());
64 public void isEndOfTableTest() {
65 final Update ipv4EOT = new UpdateBuilder().build();
66 final MpUnreachNlri ipv6EOTnlri = new MpUnreachNlriBuilder()
67 .setAfi(IPV6_TABLE_KEY.getAfi())
68 .setSafi(IPV6_TABLE_KEY.getSafi())
70 final Update ipv6EOT = new UpdateBuilder()
71 .setAttributes(new AttributesBuilder()
72 .addAugmentation(Attributes2.class, new Attributes2Builder()
73 .setMpUnreachNlri(ipv6EOTnlri)
78 assertTrue(BgpPeerUtil.isEndOfRib(ipv4EOT));
79 assertTrue(BgpPeerUtil.isEndOfRib(ipv6EOT));
81 final Update ipv4NonEOT = new UpdateBuilder()
82 .setNlri(Collections.emptyList())
84 final MpUnreachNlri ipv6NonEOTnlri = new MpUnreachNlriBuilder(ipv6EOTnlri)
85 .setWithdrawnRoutes(new WithdrawnRoutesBuilder().build())
87 final Update ipv6NonEOT = new UpdateBuilder()
88 .setAttributes(new AttributesBuilder()
89 .addAugmentation(Attributes2.class, new Attributes2Builder()
90 .setMpUnreachNlri(ipv6NonEOTnlri)
95 assertFalse(BgpPeerUtil.isEndOfRib(ipv4NonEOT));
96 assertFalse(BgpPeerUtil.isEndOfRib(ipv6NonEOT));