BUG-2982 : moved path-attributes container to grouping
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / SynchronizationTest.java
index 3a0331866d1214afcb15d349b83979d0995e6b77..c9658aac5ce7e15ce66b8610dbf0ae130a23d863 100644 (file)
@@ -9,103 +9,130 @@ package org.opendaylight.protocol.bgp.rib.impl;
 
 import static org.junit.Assert.assertEquals;
 
+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.parser.BGPSession;
 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.rev130918.LinkstateAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.NlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.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.path.attributes.AttributesBuilder;
+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.multiprotocol.rev130919.Attributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
+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.update.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;
 
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
 public class SynchronizationTest {
 
-       private BGPSynchronization bs;
-
-       private SimpleSessionListener listener;
-
-       private Update ipv4m;
-
-       private Update ipv6m;
-
-       private Update lsm;
-
-       @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();
-
-               final 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();
-
-               final MpUnreachNlriBuilder mpUBuilder = new MpUnreachNlriBuilder();
-               mpUBuilder.setAfi(LinkstateAddressFamily.class);
-               mpUBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
-
-               paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes2.class,
-                               new PathAttributes2Builder().setMpUnreachNlri(mpUBuilder.build()).build());
-
-               this.lsm = new UpdateBuilder().setPathAttributes(paBuilder.build()).build();
-
-               final Set<TablesKey> 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<BgpTableType> getAdvertisedTableTypes() {
-                               final Set<BgpTableType> types = Sets.newHashSet();
-                               types.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
-                               types.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
-                               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());
-               assertEquals(
-                               LinkstateAddressFamily.class,
-                               ((Update) this.listener.getListMsg().get(0)).getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi());
-               this.bs.kaReceived(); // ipv4 sync
-               assertEquals(2, this.listener.getListMsg().size());
-       }
+    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);
+
+        AttributesBuilder paBuilder = new AttributesBuilder().addAugmentation(Attributes1.class,
+                new Attributes1Builder().setMpReachNlri(mpBuilder.build()).build());
+
+        this.ipv6m = new UpdateBuilder().setAttributes(paBuilder.build()).build();
+
+        mpBuilder = new MpReachNlriBuilder();
+        mpBuilder.setAfi(LinkstateAddressFamily.class);
+        mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+
+        paBuilder = new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(
+                mpBuilder.build()).build());
+
+        this.lsm = new UpdateBuilder().setAttributes(paBuilder.build()).build();
+
+        this.eorm = new UpdateBuilder().build();
+
+        final Set<TablesKey> 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<BgpTableType> getAdvertisedTableTypes() {
+                final Set<BgpTableType> 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)).getAttributes().getAugmentation(
+                Attributes2.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)).getAttributes().getAugmentation(
+                Attributes2.class).getMpUnreachNlri().getAfi());
+    }
 }