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 = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
36 private final TablesKey linkstate = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
38 private BGPSynchronization bs;
40 private SimpleSessionListener listener;
52 this.listener = new SimpleSessionListener();
53 this.ipv4m = new UpdateBuilder()
54 .setNlri(Collections.singletonList(new NlriBuilder()
55 .setPrefix(new Ipv4Prefix("1.1.1.1/32")).build()))
58 MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
59 mpBuilder.setAfi(Ipv6AddressFamily.class);
60 mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
62 AttributesBuilder paBuilder = new AttributesBuilder().addAugmentation(Attributes1.class,
63 new Attributes1Builder().setMpReachNlri(mpBuilder.build()).build());
65 this.ipv6m = new UpdateBuilder().setAttributes(paBuilder.build()).build();
67 mpBuilder = new MpReachNlriBuilder();
68 mpBuilder.setAfi(LinkstateAddressFamily.class);
69 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
71 paBuilder = new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(
72 mpBuilder.build()).build());
74 this.lsm = new UpdateBuilder().setAttributes(paBuilder.build()).build();
76 this.eorm = new UpdateBuilder().build();
78 this.bs = new BGPSynchronization(this.listener, Sets.newHashSet(this.ipv4, this.linkstate));
82 public void testSynchronize() {
84 this.bs.updReceived(this.ipv6m);
85 this.bs.updReceived(this.ipv4m);
86 this.bs.updReceived(this.lsm);
87 this.bs.kaReceived(); // nothing yet
88 assertFalse(this.bs.syncStorage.get(this.linkstate).getEor());
89 assertFalse(this.bs.syncStorage.get(this.ipv4).getEor());
90 this.bs.updReceived(this.ipv4m);
91 this.bs.kaReceived(); // linkstate
92 assertTrue(this.bs.syncStorage.get(this.linkstate).getEor());
93 this.bs.kaReceived(); // ipv4 sync
94 assertTrue(this.bs.syncStorage.get(this.ipv4).getEor());
98 public void testSynchronizeWithEOR() {
99 this.bs.updReceived(this.ipv4m);
100 this.bs.updReceived(this.lsm);
101 // Ipv4 Unicast synchronized by EOR message
102 assertFalse(this.bs.syncStorage.get(this.ipv4).getEor());
103 this.bs.updReceived(this.eorm);
104 assertTrue(this.bs.syncStorage.get(this.ipv4).getEor());
105 // Linkstate not synchronized yet
106 assertFalse(this.bs.syncStorage.get(this.linkstate).getEor());
107 this.bs.kaReceived();
108 // no message sent by BGPSychchronization
109 assertEquals(0, this.listener.getListMsg().size());
110 this.bs.kaReceived();
111 assertTrue(this.bs.syncStorage.get(this.linkstate).getEor());