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.Lists;
15 import com.google.common.collect.Sets;
16 import java.util.Collections;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.LinkstateAddressFamily;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.LinkstateSubsequentAddressFamily;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.NlriBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1Builder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
34 public class SynchronizationTest {
36 private final TablesKey ipv4 = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
37 private final TablesKey linkstate = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
39 private BGPSynchronization bs;
41 private SimpleSessionListener listener;
53 this.listener = new SimpleSessionListener();
54 this.ipv4m = new UpdateBuilder()
55 .setNlri(Collections.singletonList(new NlriBuilder()
56 .setPrefix(new Ipv4Prefix("1.1.1.1/32")).build()))
59 MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
60 mpBuilder.setAfi(Ipv6AddressFamily.class);
61 mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
63 AttributesBuilder paBuilder = new AttributesBuilder().addAugmentation(Attributes1.class,
64 new Attributes1Builder().setMpReachNlri(mpBuilder.build()).build());
66 this.ipv6m = new UpdateBuilder().setAttributes(paBuilder.build()).build();
68 mpBuilder = new MpReachNlriBuilder();
69 mpBuilder.setAfi(LinkstateAddressFamily.class);
70 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
72 paBuilder = new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(
73 mpBuilder.build()).build());
75 this.lsm = new UpdateBuilder().setAttributes(paBuilder.build()).build();
77 this.eorm = new UpdateBuilder().build();
79 this.bs = new BGPSynchronization(this.listener, Sets.newHashSet(this.ipv4, this.linkstate));
83 public void testSynchronize() {
85 this.bs.updReceived(this.ipv6m);
86 this.bs.updReceived(this.ipv4m);
87 this.bs.updReceived(this.lsm);
88 this.bs.kaReceived(); // nothing yet
89 assertFalse(this.bs.syncStorage.get(this.linkstate).getEor());
90 assertFalse(this.bs.syncStorage.get(this.ipv4).getEor());
91 this.bs.updReceived(this.ipv4m);
92 this.bs.kaReceived(); // linkstate
93 assertTrue(this.bs.syncStorage.get(this.linkstate).getEor());
94 this.bs.kaReceived(); // ipv4 sync
95 assertTrue(this.bs.syncStorage.get(this.ipv4).getEor());
99 public void testSynchronizeWithEOR() {
100 this.bs.updReceived(this.ipv4m);
101 this.bs.updReceived(this.lsm);
102 // Ipv4 Unicast synchronized by EOR message
103 assertFalse(this.bs.syncStorage.get(this.ipv4).getEor());
104 this.bs.updReceived(this.eorm);
105 assertTrue(this.bs.syncStorage.get(this.ipv4).getEor());
106 // Linkstate not synchronized yet
107 assertFalse(this.bs.syncStorage.get(this.linkstate).getEor());
108 this.bs.kaReceived();
109 // no message sent by BGPSychchronization
110 assertEquals(0, this.listener.getListMsg().size());
111 this.bs.kaReceived();
112 assertTrue(this.bs.syncStorage.get(this.linkstate).getEor());