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.mockito.Mockito.mock;
13 import java.util.Collections;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.protocol.bgp.concepts.BGPAddressFamily;
18 import org.opendaylight.protocol.bgp.concepts.BGPObject;
19 import org.opendaylight.protocol.bgp.concepts.BGPSubsequentAddressFamily;
20 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
21 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
22 import org.opendaylight.protocol.bgp.parser.BGPLink;
23 import org.opendaylight.protocol.bgp.parser.BGPUpdateMessage;
24 import org.opendaylight.protocol.bgp.parser.impl.BGPUpdateMessageImpl;
25 import org.opendaylight.protocol.bgp.rib.impl.BGPSynchronization;
26 import org.opendaylight.protocol.bgp.rib.impl.BGPUpdateSynchronizedImpl;
27 import org.opendaylight.protocol.bgp.util.BGPIPv4RouteImpl;
28 import org.opendaylight.protocol.bgp.util.BGPIPv6RouteImpl;
30 import org.opendaylight.protocol.concepts.IPv4;
31 import org.opendaylight.protocol.concepts.IPv6;
32 import com.google.common.collect.Sets;
34 public class SynchronizationTest {
36 private BGPSynchronization bs;
38 private SimpleSessionListener listener;
40 private BGPUpdateMessage ipv4m;
42 private BGPUpdateMessage ipv6m;
44 private BGPUpdateMessage lsm;
48 this.listener = new SimpleSessionListener();
49 final BGPIPv4RouteImpl i4 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("1.1.1.1/32"), new BaseBGPObjectState(null, null), null);
50 this.ipv4m = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(i4), Collections.EMPTY_SET);
51 final BGPIPv6RouteImpl i6 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("::1/32"), new BaseBGPObjectState(null, null), null);
52 this.ipv6m = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(i6), Collections.EMPTY_SET);
53 this.lsm = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(mock(BGPLink.class)), Collections.EMPTY_SET);
54 this.bs = new BGPSynchronization(this.listener);
55 this.bs.addTableTypes(Sets.newHashSet(new BGPTableType(BGPAddressFamily.IPv4, BGPSubsequentAddressFamily.Unicast),
56 new BGPTableType(BGPAddressFamily.LinkState, BGPSubsequentAddressFamily.Linkstate)));
60 public void testSynchronize() {
62 this.bs.updReceived(this.ipv6m);
64 this.bs.updReceived(this.ipv4m);
65 this.bs.updReceived(this.lsm);
66 this.bs.kaReceived(); // nothing yet
67 this.bs.updReceived(this.ipv4m);
68 this.bs.kaReceived(); // linkstate
69 assertEquals(1, this.listener.getListMsg().size());
70 this.bs.kaReceived(); // ipv4 sync
71 assertEquals(2, this.listener.getListMsg().size());
72 assertEquals(BGPAddressFamily.IPv4,
73 ((BGPUpdateSynchronizedImpl) this.listener.getListMsg().get(1)).getTableType().getAddressFamily());