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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.NlriBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlri;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.UnicastSubsequentAddressFamily;
34 public class BgpPeerUtilTest {
36 private static final TablesKey IPV4_TABLE_KEY = new TablesKey(Ipv4AddressFamily.class,
37 UnicastSubsequentAddressFamily.class);
38 private static final TablesKey IPV6_TABLE_KEY = new TablesKey(Ipv6AddressFamily.class,
39 UnicastSubsequentAddressFamily.class);
42 public void createIpv4EORTest() {
43 final Update endOfRib = BgpPeerUtil.createEndOfRib(IPV4_TABLE_KEY);
44 assertNull(endOfRib.getNlri());
45 assertNull(endOfRib.getWithdrawnRoutes());
46 assertNull(endOfRib.getAttributes());
50 public void createNonIpv4EORTest() {
51 final Update endOfRib = BgpPeerUtil.createEndOfRib(IPV6_TABLE_KEY);
52 assertNull(endOfRib.getNlri());
53 assertNull(endOfRib.getWithdrawnRoutes());
54 final Attributes attributes = endOfRib.getAttributes();
55 assertNotNull(attributes);
56 final Attributes2 augmentation = attributes.augmentation(Attributes2.class);
57 assertNotNull(augmentation);
58 final MpUnreachNlri mpUnreachNlri = augmentation.getMpUnreachNlri();
59 assertNotNull(mpUnreachNlri);
60 assertEquals(IPV6_TABLE_KEY.getAfi(), mpUnreachNlri.getAfi());
61 assertEquals(IPV6_TABLE_KEY.getSafi(), mpUnreachNlri.getSafi());
62 assertNull(mpUnreachNlri.getWithdrawnRoutes());
66 public void isEndOfTableTest() {
67 final Update ipv4EOT = new UpdateBuilder().build();
68 final MpUnreachNlri ipv6EOTnlri = new MpUnreachNlriBuilder()
69 .setAfi(IPV6_TABLE_KEY.getAfi())
70 .setSafi(IPV6_TABLE_KEY.getSafi())
72 final Update ipv6EOT = new UpdateBuilder()
73 .setAttributes(new AttributesBuilder()
74 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(ipv6EOTnlri).build())
78 assertTrue(BgpPeerUtil.isEndOfRib(ipv4EOT));
79 assertTrue(BgpPeerUtil.isEndOfRib(ipv6EOT));
81 final Update ipv4NonEOT = new UpdateBuilder()
82 .setNlri(Collections.singletonList(new NlriBuilder().setPrefix(new Ipv4Prefix("0.0.0.0/32")).build()))
84 final MpUnreachNlri ipv6NonEOTnlri = new MpUnreachNlriBuilder(ipv6EOTnlri)
85 .setWithdrawnRoutes(new WithdrawnRoutesBuilder().build())
87 final Update ipv6NonEOT = new UpdateBuilder()
88 .setAttributes(new AttributesBuilder()
89 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(ipv6NonEOTnlri).build())
93 assertFalse(BgpPeerUtil.isEndOfRib(ipv4NonEOT));
94 assertFalse(BgpPeerUtil.isEndOfRib(ipv6NonEOT));