send EOR marker after initial route exchange
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / BgpPeerUtilTest.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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 package org.opendaylight.protocol.bgp.rib.impl;
9
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;
15
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;
31
32 public class BgpPeerUtilTest {
33
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);
38
39     @Test
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());
45     }
46
47     @Test
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());
61     }
62
63     @Test
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())
69                 .build();
70         final Update ipv6EOT = new UpdateBuilder()
71                 .setAttributes(new AttributesBuilder()
72                         .addAugmentation(Attributes2.class, new Attributes2Builder()
73                                 .setMpUnreachNlri(ipv6EOTnlri)
74                                 .build())
75                         .build())
76                 .build();
77
78         assertTrue(BgpPeerUtil.isEndOfRib(ipv4EOT));
79         assertTrue(BgpPeerUtil.isEndOfRib(ipv6EOT));
80
81         final Update ipv4NonEOT = new UpdateBuilder()
82                 .setNlri(Collections.emptyList())
83                 .build();
84         final MpUnreachNlri ipv6NonEOTnlri = new MpUnreachNlriBuilder(ipv6EOTnlri)
85                 .setWithdrawnRoutes(new WithdrawnRoutesBuilder().build())
86                 .build();
87         final Update ipv6NonEOT = new UpdateBuilder()
88                 .setAttributes(new AttributesBuilder()
89                         .addAugmentation(Attributes2.class, new Attributes2Builder()
90                                 .setMpUnreachNlri(ipv6NonEOTnlri)
91                                 .build())
92                         .build())
93                 .build();
94
95         assertFalse(BgpPeerUtil.isEndOfRib(ipv4NonEOT));
96         assertFalse(BgpPeerUtil.isEndOfRib(ipv6NonEOT));
97     }
98 }