X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=bgp%2Frib-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fbgp%2Frib%2Fimpl%2FSynchronizationTest.java;h=d7af3f5a75b3fdbd7c0a2829424ad7e8bd926116;hb=afb392da82ae72a9f12c5c527bc2f86ab7b154ca;hp=9bc64875f2ed7479ad747d27cc4a7acd7a4dad83;hpb=a9f58bf67f4d76295a0e8521dec6a22d0227d819;p=bgpcep.git diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationTest.java index 9bc64875f2..d7af3f5a75 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationTest.java @@ -8,80 +8,131 @@ package org.opendaylight.protocol.bgp.rib.impl; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import java.util.Collections; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import java.util.Set; - import org.junit.Before; import org.junit.Test; -import org.opendaylight.protocol.bgp.concepts.BGPAddressFamily; -import org.opendaylight.protocol.bgp.concepts.BGPObject; -import org.opendaylight.protocol.bgp.concepts.BGPSubsequentAddressFamily; -import org.opendaylight.protocol.bgp.concepts.BGPTableType; -import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState; -import org.opendaylight.protocol.bgp.parser.BGPLink; -import org.opendaylight.protocol.bgp.parser.BGPSession; -import org.opendaylight.protocol.bgp.parser.BGPUpdateMessage; -import org.opendaylight.protocol.bgp.parser.impl.BGPUpdateMessageImpl; -import org.opendaylight.protocol.bgp.util.BGPIPv4RouteImpl; -import org.opendaylight.protocol.bgp.util.BGPIPv6RouteImpl; -import org.opendaylight.protocol.concepts.IPv4; -import org.opendaylight.protocol.concepts.IPv6; - -import com.google.common.collect.Sets; +import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl; +import org.opendaylight.protocol.bgp.rib.spi.BGPSession; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateSubsequentAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.NlriBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily; public class SynchronizationTest { - private BGPSynchronization bs; - - private SimpleSessionListener listener; - - private BGPUpdateMessage ipv4m; - - private BGPUpdateMessage ipv6m; - - private BGPUpdateMessage lsm; - - @Before - public void setUp() { - this.listener = new SimpleSessionListener(); - final BGPIPv4RouteImpl i4 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("1.1.1.1/32"), new BaseBGPObjectState(null, null), null); - this.ipv4m = new BGPUpdateMessageImpl(Sets. newHashSet(i4), Collections.EMPTY_SET); - final BGPIPv6RouteImpl i6 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("::1/32"), new BaseBGPObjectState(null, null), null); - this.ipv6m = new BGPUpdateMessageImpl(Sets. newHashSet(i6), Collections.EMPTY_SET); - this.lsm = new BGPUpdateMessageImpl(Sets. newHashSet(mock(BGPLink.class)), Collections.EMPTY_SET); - - final Set types = Sets.newHashSet(new BGPTableType(BGPAddressFamily.IPv4, BGPSubsequentAddressFamily.Unicast), - new BGPTableType(BGPAddressFamily.LinkState, BGPSubsequentAddressFamily.Linkstate)); - - this.bs = new BGPSynchronization(new BGPSession() { - - @Override - public void close() { - } - - @Override - public Set getAdvertisedTableTypes() { - return types; - } - }, this.listener, types); - } - - @Test - public void testSynchronize() { - // simulate sync - this.bs.updReceived(this.ipv6m); - - this.bs.updReceived(this.ipv4m); - this.bs.updReceived(this.lsm); - this.bs.kaReceived(); // nothing yet - this.bs.updReceived(this.ipv4m); - this.bs.kaReceived(); // linkstate - assertEquals(1, this.listener.getListMsg().size()); - this.bs.kaReceived(); // ipv4 sync - assertEquals(2, this.listener.getListMsg().size()); - assertEquals(BGPAddressFamily.IPv4, - ((BGPUpdateSynchronizedImpl) this.listener.getListMsg().get(1)).getTableType().getAddressFamily()); - } + private BGPSynchronization bs; + + private SimpleSessionListener listener; + + private Update ipv4m; + + private Update ipv6m; + + private Update lsm; + + private Update eorm; + + @Before + public void setUp() { + this.listener = new SimpleSessionListener(); + this.ipv4m = new UpdateBuilder().setNlri(new NlriBuilder().setNlri(Lists.newArrayList(new Ipv4Prefix("1.1.1.1/32"))).build()).build(); + + MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder(); + mpBuilder.setAfi(Ipv6AddressFamily.class); + mpBuilder.setSafi(UnicastSubsequentAddressFamily.class); + + PathAttributesBuilder paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes1.class, + new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build()); + + this.ipv6m = new UpdateBuilder().setPathAttributes(paBuilder.build()).build(); + + mpBuilder = new MpReachNlriBuilder(); + mpBuilder.setAfi(LinkstateAddressFamily.class); + mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class); + + paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri( + mpBuilder.build()).build()); + + this.lsm = new UpdateBuilder().setPathAttributes(paBuilder.build()).build(); + + this.eorm = new UpdateBuilder().build(); + + final Set types = Sets.newHashSet(); + types.add(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)); + types.add(new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class)); + + this.bs = new BGPSynchronization(new BGPSession() { + + @Override + public void close() { + } + + @Override + public Set getAdvertisedTableTypes() { + final Set types = Sets.newHashSet(); + types.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)); + types.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class)); + return types; + } + + @Override + public Ipv4Address getBgpId() { + return new Ipv4Address("127.0.0.1"); + } + + @Override + public AsNumber getAsNumber() { + return new AsNumber(30L); + } + }, this.listener, types); + } + + @Test + public void testSynchronize() { + // simulate sync + this.bs.updReceived(this.ipv6m); + this.bs.updReceived(this.ipv4m); + this.bs.updReceived(this.lsm); + this.bs.kaReceived(); // nothing yet + this.bs.updReceived(this.ipv4m); + this.bs.kaReceived(); // linkstate + assertEquals(1, this.listener.getListMsg().size()); + assertEquals(LinkstateAddressFamily.class, ((Update) this.listener.getListMsg().get(0)).getPathAttributes().getAugmentation( + PathAttributes2.class).getMpUnreachNlri().getAfi()); + this.bs.kaReceived(); // ipv4 sync + assertEquals(2, this.listener.getListMsg().size()); + } + + @Test + public void testSynchronizeWithEOR() { + this.bs.updReceived(this.ipv4m); + this.bs.updReceived(this.lsm); + // Ipv4 Unicast synchronized by EOR message + this.bs.updReceived(this.eorm); + // Linkstate not synchronized yet + this.bs.kaReceived(); + // no message sent by BGPSychchronization + assertEquals(0, this.listener.getListMsg().size()); + this.bs.kaReceived(); + assertEquals(1, this.listener.getListMsg().size()); + assertEquals(LinkstateAddressFamily.class, ((Update) this.listener.getListMsg().get(0)).getPathAttributes().getAugmentation( + PathAttributes2.class).getMpUnreachNlri().getAfi()); + } }