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;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.protocol.bgp.parser.BGPSession;
17 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateAddressFamily;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateSubsequentAddressFamily;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.NlriBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1Builder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2Builder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlriBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
38 import com.google.common.collect.Lists;
39 import com.google.common.collect.Sets;
41 public class SynchronizationTest {
43 private BGPSynchronization bs;
45 private SimpleSessionListener listener;
55 this.listener = new SimpleSessionListener();
56 this.ipv4m = new UpdateBuilder().setNlri(new NlriBuilder().setNlri(Lists.newArrayList(new Ipv4Prefix("1.1.1.1/32"))).build()).build();
58 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
59 mpBuilder.setAfi(Ipv6AddressFamily.class);
60 mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
62 PathAttributesBuilder paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes1.class,
63 new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
65 this.ipv6m = new UpdateBuilder().setPathAttributes(paBuilder.build()).build();
67 final MpUnreachNlriBuilder mpUBuilder = new MpUnreachNlriBuilder();
68 mpUBuilder.setAfi(LinkstateAddressFamily.class);
69 mpUBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
71 paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes2.class,
72 new PathAttributes2Builder().setMpUnreachNlri(mpUBuilder.build()).build());
74 this.lsm = new UpdateBuilder().setPathAttributes(paBuilder.build()).build();
76 final Set<TablesKey> types = Sets.newHashSet();
77 types.add(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
78 types.add(new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
80 this.bs = new BGPSynchronization(new BGPSession() {
87 public Set<BgpTableType> getAdvertisedTableTypes() {
88 final Set<BgpTableType> types = Sets.newHashSet();
89 types.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
90 types.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
95 public byte[] getBgpId() {
96 return new byte[] { (byte) 127, 0, 0, 1 };
100 public AsNumber getAsNumber() {
101 return new AsNumber(30L);
103 }, this.listener, types);
107 public void testSynchronize() {
109 this.bs.updReceived(this.ipv6m);
110 this.bs.updReceived(this.ipv4m);
111 this.bs.updReceived(this.lsm);
112 this.bs.kaReceived(); // nothing yet
113 this.bs.updReceived(this.ipv4m);
114 this.bs.kaReceived(); // linkstate
115 assertEquals(1, this.listener.getListMsg().size());
117 LinkstateAddressFamily.class,
118 ((Update) this.listener.getListMsg().get(0)).getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi());
119 this.bs.kaReceived(); // ipv4 sync
120 assertEquals(2, this.listener.getListMsg().size());