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;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.protocol.bgp.concepts.BGPObject;
19 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
20 import org.opendaylight.protocol.bgp.parser.BGPLink;
21 import org.opendaylight.protocol.bgp.parser.BGPSession;
22 import org.opendaylight.protocol.bgp.parser.BGPTableType;
23 import org.opendaylight.protocol.bgp.parser.BGPUpdateMessage;
24 import org.opendaylight.protocol.bgp.parser.impl.BGPUpdateMessageImpl;
25 import org.opendaylight.protocol.bgp.util.BGPIPv4RouteImpl;
26 import org.opendaylight.protocol.bgp.util.BGPIPv6RouteImpl;
27 import org.opendaylight.protocol.concepts.IPv4;
28 import org.opendaylight.protocol.concepts.IPv6;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
34 import com.google.common.collect.Sets;
36 public class SynchronizationTest {
38 private BGPSynchronization bs;
40 private SimpleSessionListener listener;
42 private BGPUpdateMessage ipv4m;
44 private BGPUpdateMessage ipv6m;
46 private BGPUpdateMessage lsm;
50 this.listener = new SimpleSessionListener();
51 final BGPIPv4RouteImpl i4 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("1.1.1.1/32"), new BaseBGPObjectState(null, null), null);
52 this.ipv4m = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(i4), Collections.EMPTY_SET);
53 final BGPIPv6RouteImpl i6 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("::1/32"), new BaseBGPObjectState(null, null), null);
54 this.ipv6m = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(i6), Collections.EMPTY_SET);
55 this.lsm = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(mock(BGPLink.class)), Collections.EMPTY_SET);
57 final Set<BGPTableType> types = Sets.newHashSet(new BGPTableType(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class),
58 new BGPTableType(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
60 this.bs = new BGPSynchronization(new BGPSession() {
67 public Set<BGPTableType> getAdvertisedTableTypes() {
70 }, this.listener, types);
74 public void testSynchronize() {
76 this.bs.updReceived(this.ipv6m);
78 this.bs.updReceived(this.ipv4m);
79 this.bs.updReceived(this.lsm);
80 this.bs.kaReceived(); // nothing yet
81 this.bs.updReceived(this.ipv4m);
82 this.bs.kaReceived(); // linkstate
83 assertEquals(1, this.listener.getListMsg().size());
84 this.bs.kaReceived(); // ipv4 sync
85 assertEquals(2, this.listener.getListMsg().size());
86 assertEquals(Ipv4AddressFamily.class,
87 ((BGPUpdateSynchronizedImpl) this.listener.getListMsg().get(1)).getTableType().getAddressFamily());