moved BGP Table type from concepts to parser-api.
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / SynchronizationTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.rib.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.mock;
12
13 import java.util.Collections;
14 import java.util.Set;
15
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;
33
34 import com.google.common.collect.Sets;
35
36 public class SynchronizationTest {
37
38         private BGPSynchronization bs;
39
40         private SimpleSessionListener listener;
41
42         private BGPUpdateMessage ipv4m;
43
44         private BGPUpdateMessage ipv6m;
45
46         private BGPUpdateMessage lsm;
47
48         @Before
49         public void setUp() {
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);
56
57                 final Set<BGPTableType> types = Sets.newHashSet(new BGPTableType(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class),
58                                 new BGPTableType(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
59
60                 this.bs = new BGPSynchronization(new BGPSession() {
61
62                         @Override
63                         public void close() {
64                         }
65
66                         @Override
67                         public Set<BGPTableType> getAdvertisedTableTypes() {
68                                 return types;
69                         }
70                 }, this.listener, types);
71         }
72
73         @Test
74         public void testSynchronize() {
75                 // simulate sync
76                 this.bs.updReceived(this.ipv6m);
77
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());
88         }
89 }