2 * Copyright (c) 2013 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
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.assertTrue;
14 import com.google.common.collect.Sets;
15 import java.util.Collections;
16 import org.junit.Before;
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.linkstate.rev180329.LinkstateAddressFamily;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateSubsequentAddressFamily;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.UpdateBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.update.message.NlriBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
33 public class SynchronizationTest {
35 private final TablesKey ipv4
36 = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
37 private final TablesKey linkstate
38 = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
40 private BGPSynchronization bs;
42 private SimpleSessionListener listener;
54 this.listener = new SimpleSessionListener();
55 this.ipv4m = new UpdateBuilder()
56 .setNlri(Collections.singletonList(new NlriBuilder()
57 .setPrefix(new Ipv4Prefix("1.1.1.1/32")).build()))
60 MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
61 mpBuilder.setAfi(Ipv6AddressFamily.class);
62 mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
64 AttributesBuilder paBuilder = new AttributesBuilder().addAugmentation(Attributes1.class,
65 new Attributes1Builder().setMpReachNlri(mpBuilder.build()).build());
67 this.ipv6m = new UpdateBuilder().setAttributes(paBuilder.build()).build();
69 mpBuilder = new MpReachNlriBuilder();
70 mpBuilder.setAfi(LinkstateAddressFamily.class);
71 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
73 paBuilder = new AttributesBuilder().addAugmentation(Attributes1.class,
74 new Attributes1Builder().setMpReachNlri(mpBuilder.build()).build());
76 this.lsm = new UpdateBuilder().setAttributes(paBuilder.build()).build();
78 this.eorm = new UpdateBuilder().build();
80 this.bs = new BGPSynchronization(this.listener, Sets.newHashSet(this.ipv4, this.linkstate));
84 public void testSynchronize() {
86 this.bs.updReceived(this.ipv6m);
87 this.bs.updReceived(this.ipv4m);
88 this.bs.updReceived(this.lsm);
89 this.bs.kaReceived(); // nothing yet
90 assertFalse(this.bs.syncStorage.get(this.linkstate).getEor());
91 assertFalse(this.bs.syncStorage.get(this.ipv4).getEor());
92 this.bs.updReceived(this.ipv4m);
93 this.bs.kaReceived(); // linkstate
94 assertTrue(this.bs.syncStorage.get(this.linkstate).getEor());
95 this.bs.kaReceived(); // ipv4 sync
96 assertTrue(this.bs.syncStorage.get(this.ipv4).getEor());
100 public void testSynchronizeWithEOR() {
101 this.bs.updReceived(this.ipv4m);
102 this.bs.updReceived(this.lsm);
103 // Ipv4 Unicast synchronized by EOR message
104 assertFalse(this.bs.syncStorage.get(this.ipv4).getEor());
105 this.bs.updReceived(this.eorm);
106 assertTrue(this.bs.syncStorage.get(this.ipv4).getEor());
107 // Linkstate not synchronized yet
108 assertFalse(this.bs.syncStorage.get(this.linkstate).getEor());
109 this.bs.kaReceived();
110 // no message sent by BGPSychchronization
111 assertEquals(0, this.listener.getListMsg().size());
112 this.bs.kaReceived();
113 assertTrue(this.bs.syncStorage.get(this.linkstate).getEor());