* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.bgpcep.bgp.topology.provider;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.RETURNS_SMART_NULLS;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
-import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import io.netty.buffer.Unpooled;
-import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.AdministrativeGroup;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Identifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4RouterIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.IsisAreaIdentifier;
-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.linkstate.rev150210.ProtocolId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.UnreservedBandwidthBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.UnreservedBandwidthKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LocalNodeDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.RemoteNodeDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.node._case.NodeDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.AdvertisingNodeDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.NodeAttributesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.PrefixAttributesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.LinkstateRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRoute;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRouteBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRouteKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.linkstate.route.Attributes1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.linkstate.route.Attributes1Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisNodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
-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.rib.rev130925.rib.Tables;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.AdministrativeGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Identifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Ipv4RouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.IsisAreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkstateSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.bgp.rib.rib.loc.rib.tables.routes.LinkstateRoutesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.SrAdjIdsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.UnreservedBandwidthBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.UnreservedBandwidthKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.link._case.LinkDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.link._case.LocalNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.link._case.RemoteNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.node._case.NodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.prefix._case.AdvertisingNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.prefix._case.PrefixDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.NodeAttributesCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.PrefixAttributesCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.LinkstateRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.linkstate.routes.LinkstateRoute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.linkstate.routes.LinkstateRouteBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.linkstate.routes.LinkstateRouteKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.linkstate.routes.linkstate.route.Attributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.IsisNodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.state.SrCapabilitiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.OriginBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.LocRib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.Algorithm;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.LocalLabelCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.SidCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpOrigin;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IgpMetric;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.Prefix;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
- private static final byte[] LINKSTATE_ROUTE_KEY = Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode("linkstate-route")).array();
private static final String ROUTER_1_ID = "127.0.0.1";
private static final String ROUTER_2_ID = "127.0.0.2";
private static final String NODE_1_PREFIX = "127.0.1.1/32";
- private static final AsNumber NODE_1_AS = new AsNumber(1L);
- private static final AsNumber NODE_2_AS = new AsNumber(2L);
+ private static final AsNumber NODE_1_AS = new AsNumber(Uint32.ONE);
+ private static final AsNumber NODE_2_AS = new AsNumber(Uint32.TWO);
private static final String NODE_1_ISIS_ID = "bgpls://IsisLevel2:1/type=node&as=1&router=0000.0102.0304";
private static final String NODE_2_ISIS_ID = "bgpls://IsisLevel2:1/type=node&as=2";
private static final String NODE_1_OSPF_ID = "bgpls://Ospf:1/type=node&as=1&router=0000.0102.0304";
private static final String NODE_2_OSPF_ID = "bgpls://Ospf:1/type=node&as=2";
- private static final Identifier IDENTIFIER = new Identifier(new BigInteger("1"));
+ private static final Identifier IDENTIFIER = new Identifier(Uint64.ONE);
+ private static final long LISTENER_RESTART_TIME = 20000;
+ private static final int LISTENER_ENFORCE_COUNTER = 2;
+ private static final int SRGB_START = 90000;
+ private static final int SRGB_RANGE = 16;
+ private static final int NODE_SID_INDEX = 4;
+ private static final int ADJ_SID = 24001;
private LinkstateTopologyBuilder linkstateTopoBuilder;
- private InstanceIdentifier<LinkstateRoute> linkstateRouteIID;
-
+ private InstanceIdentifier<Tables> tablePathIID;
+ private String linkstateNodeRouteKey;
+ private String linkstatePrefixRouteKey;
+ private String linkstateLinkRouteKey;
+ private InstanceIdentifier<LinkstateRoute> linkstateNodeRouteIID;
+ private InstanceIdentifier<LinkstateRoute> linkstatePrefixRouteIID;
+ private InstanceIdentifier<LinkstateRoute> linkstateLinkRouteIID;
+ @Before
@Override
- protected void setupWithDataBroker(final DataBroker dataBroker) {
- super.setupWithDataBroker(dataBroker);
- this.linkstateTopoBuilder = new LinkstateTopologyBuilder(dataBroker, LOC_RIB_REF, TEST_TOPOLOGY_ID);
- this.linkstateTopoBuilder.start(dataBroker, LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
- final InstanceIdentifier<Tables> path = this.linkstateTopoBuilder.tableInstanceIdentifier(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
- this.linkstateRouteIID = path.builder().child((Class)LinkstateRoutes.class).child(LinkstateRoute.class, new LinkstateRouteKey(LINKSTATE_ROUTE_KEY)).build();
+ public void setUp() {
+ super.setUp();
+ this.linkstateTopoBuilder = new LinkstateTopologyBuilder(getDataBroker(), LOC_RIB_REF, TEST_TOPOLOGY_ID,
+ LISTENER_RESTART_TIME, LISTENER_ENFORCE_COUNTER);
+ this.linkstateTopoBuilder.start();
+ this.tablePathIID =
+ LOC_RIB_REF.getInstanceIdentifier().builder().child(LocRib.class)
+ .child(Tables.class,
+ new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class))
+ .build();
+ this.linkstateNodeRouteKey = getLinkstateRouteKey("node-route");
+ this.linkstatePrefixRouteKey = getLinkstateRouteKey("prefix-route");
+ this.linkstateLinkRouteKey = getLinkstateRouteKey("link-route");
+ this.linkstateNodeRouteIID = createLinkstateRouteIID(this.linkstateNodeRouteKey);
+ this.linkstatePrefixRouteIID = createLinkstateRouteIID(this.linkstatePrefixRouteKey);
+ this.linkstateLinkRouteIID = createLinkstateRouteIID(this.linkstateLinkRouteKey);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ this.linkstateTopoBuilder.close();
+ checkNotPresentOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier());
}
@Test
- public void testLinkstateTopologyBuilderTopologyTypes() {
- final Optional<Topology> topologyMaybe = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier());
- assertTrue(topologyMaybe.isPresent());
- final Topology topology = topologyMaybe.get();
- assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
- assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpLinkstateTopology());
+ public void testLinkstateTopologyBuilderTopologyTypes() throws InterruptedException, ExecutionException {
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(LinkstateTopologyBuilder.LINKSTATE_TOPOLOGY_TYPE, topology.getTopologyTypes());
+ return topology;
+ });
}
@Test
- public void testIsisLinkstateTopologyBuilder() throws TransactionCommitFailedException {
+ public void testIsisLinkstateTopologyBuilder() throws InterruptedException, ExecutionException {
// create node
- updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.IsisLevel2, "node1", NODE_1_AS, ROUTER_1_ID));
- final Optional<Topology> topologyMaybe = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier());
- assertTrue(topologyMaybe.isPresent());
- final Topology topology1 = topologyMaybe.get();
- assertEquals(1, topology1.getNode().size());
- final Node node1 = topology1.getNode().get(0);
- assertEquals(NODE_1_ISIS_ID, node1.getNodeId().getValue());
- final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
- assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
- assertEquals("node1", igpNode1.getName().getValue());
- final IgpNodeAttributes1 igpNodeAttributes1 = igpNode1.getAugmentation(IgpNodeAttributes1.class);
- assertEquals("0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getIso().getIsoSystemId().getValue());
- assertEquals(ROUTER_1_ID, igpNodeAttributes1.getIsisNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
- assertEquals("47.0000.0000.0000.0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getNet().get(0).getValue());
- assertNull(igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class));
+ updateLinkstateRoute(this.linkstateNodeRouteIID,
+ createLinkstateNodeRoute(ProtocolId.IsisLevel2, "node1", NODE_1_AS, ROUTER_1_ID));
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(1, topology.nonnullNode().size());
+ final Node node1 = topology.nonnullNode().values().iterator().next();
+ assertEquals(NODE_1_ISIS_ID, node1.getNodeId().getValue());
+ final IgpNodeAttributes igpNode1 = node1.augmentation(Node1.class).getIgpNodeAttributes();
+ assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
+ assertEquals("node1", igpNode1.getName().getValue());
+ final IgpNodeAttributes1 igpNodeAttributes1 = igpNode1.augmentation(IgpNodeAttributes1.class);
+ assertEquals("0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getIso().getIsoSystemId()
+ .getValue());
+ assertEquals(ROUTER_1_ID, igpNodeAttributes1.getIsisNodeAttributes().getTed().getTeRouterIdIpv4()
+ .getValue());
+ assertEquals("47.0000.0000.0000.0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes()
+ .getNet().get(0).getValue());
+ assertNull(igpNode1.augmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf
+ .topology.rev131021.IgpNodeAttributes1.class));
+ assertEquals(LinkstateTopologyBuilder.LINKSTATE_TOPOLOGY_TYPE, topology.getTopologyTypes());
+ assertNull(node1.augmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.Node1.class));
+ return topology;
+ });
// create link
- updateLinkstateRoute(createLinkstateLinkRoute(ProtocolId.IsisLevel2, NODE_1_AS, NODE_2_AS, "link1"));
- final Topology topology2 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
- assertEquals(1, topology2.getLink().size());
- final Link link1 = topology2.getLink().get(0);
- assertEquals(2, topology2.getNode().size());
- assertEquals(1, topology2.getNode().get(0).getTerminationPoint().size());
- assertEquals(1, topology2.getNode().get(1).getTerminationPoint().size());
- assertEquals("bgpls://IsisLevel2:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
- assertEquals(NODE_1_ISIS_ID, link1.getSource().getSourceNode().getValue());
- assertEquals(NODE_2_ISIS_ID, link1.getDestination().getDestNode().getValue());
- final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
- assertEquals("link1", igpLink1.getName());
- assertEquals((short) 1, igpLink1.getAugmentation(IgpLinkAttributes1.class).getIsisLinkAttributes().getMultiTopologyId().shortValue());
- assertNull(igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class));
+ updateLinkstateRoute(this.linkstateLinkRouteIID,
+ createLinkstateLinkRoute(ProtocolId.IsisLevel2, NODE_1_AS, NODE_2_AS, "link1"));
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(1, topology.nonnullLink().size());
+ final Link link1 = topology.nonnullLink().values().iterator().next();
+ assertEquals(2, topology.nonnullNode().size());
+ assertEquals(1, Iterables.get(topology.getNode().values(), 0).getTerminationPoint().size());
+ assertEquals(1, Iterables.get(topology.getNode().values(), 1).getTerminationPoint().size());
+ assertEquals("bgpls://IsisLevel2:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as"
+ + "=2&mt=1", link1.getLinkId().getValue());
+ assertEquals(NODE_1_ISIS_ID, link1.getSource().getSourceNode().getValue());
+ assertEquals(NODE_2_ISIS_ID, link1.getDestination().getDestNode().getValue());
+ final IgpLinkAttributes igpLink1 = link1.augmentation(Link1.class).getIgpLinkAttributes();
+ assertEquals("link1", igpLink1.getName());
+ assertEquals((short) 1, igpLink1.augmentation(IgpLinkAttributes1.class).getIsisLinkAttributes()
+ .getMultiTopologyId().shortValue());
+ assertNull(igpLink1.augmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf
+ .topology.rev131021.IgpLinkAttributes1.class));
+ assertEquals(LinkstateTopologyBuilder.SR_AWARE_LINKSTATE_TOPOLOGY_TYPE, topology.getTopologyTypes());
+ assertEquals(2, topology.getNode().size());
+ final Node srcNode;
+ if (topology.getNode().values().iterator().next().getNodeId().getValue().contains("0000.0102.0304")) {
+ srcNode = topology.getNode().values().iterator().next();
+ } else {
+ srcNode = Iterables.get(topology.getNode().values(), 1);
+ }
+ assertEquals(1, srcNode.augmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.Node1.class)
+ .getSegments().size());
+ assertEquals(ADJ_SID, link1.augmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.Link1.class)
+ .getSegment().getValue().intValue());
+ return topology;
+ });
+ removeLinkstateRoute(this.linkstateLinkRouteIID);
// update node
- updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.IsisLevel2, "updated-node", NODE_1_AS, ROUTER_2_ID));
- final Topology topology3 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
- final IgpNodeAttributes igpNode2 = topology3.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
- assertEquals(ROUTER_2_ID, igpNode2.getRouterId().get(0).getIpv4Address().getValue());
- assertEquals("updated-node", igpNode2.getName().getValue());
+ updateLinkstateRoute(this.linkstateNodeRouteIID,
+ createLinkstateNodeRoute(ProtocolId.IsisLevel2, "updated-node", NODE_1_AS, ROUTER_2_ID));
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(1, topology.getNode().size());
+ final IgpNodeAttributes igpNode2 = topology.getNode().values().iterator().next().augmentation(Node1.class)
+ .getIgpNodeAttributes();
+ assertEquals(ROUTER_2_ID, igpNode2.getRouterId().get(0).getIpv4Address().getValue());
+ assertEquals("updated-node", igpNode2.getName().getValue());
+ return topology;
+ });
// remove
- final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
- wTx.delete(LogicalDatastoreType.OPERATIONAL, this.linkstateRouteIID);
- wTx.submit();
- final Topology topology4 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
- assertEquals(0, topology4.getNode().size());
- assertEquals(0, topology4.getLink().size());
+ removeLinkstateRoute(this.linkstateNodeRouteIID);
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(LinkstateTopologyBuilder.LINKSTATE_TOPOLOGY_TYPE, topology.getTopologyTypes());
+ assertNull(topology.getNode());
+ assertNull(topology.getLink());
+ return topology;
+ });
}
@Test
- public void testOspfLinkstateTopologyBuilder() throws TransactionCommitFailedException {
+ public void testOspfLinkstateTopologyBuilder() throws InterruptedException, ExecutionException {
// create node
- updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.Ospf, "node1", NODE_1_AS, ROUTER_1_ID));
- final Optional<Topology> topologyMaybe = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier());
- assertTrue(topologyMaybe.isPresent());
- final Topology topology1 = topologyMaybe.get();
- assertEquals(1, topology1.getNode().size());
- final Node node1 = topology1.getNode().get(0);
- assertEquals(NODE_1_OSPF_ID, node1.getNodeId().getValue());
- final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
- assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
- assertEquals("node1", igpNode1.getName().getValue());
- assertNull(igpNode1.getAugmentation(IgpNodeAttributes1.class));
- assertEquals(ROUTER_1_ID, igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class).getOspfNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
+ updateLinkstateRoute(this.linkstateNodeRouteIID,
+ createLinkstateNodeRoute(ProtocolId.Ospf, "node1", NODE_1_AS, ROUTER_1_ID));
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(1, topology.nonnullNode().size());
+ final Node node1 = topology.nonnullNode().values().iterator().next();
+ assertEquals(NODE_1_OSPF_ID, node1.getNodeId().getValue());
+ final IgpNodeAttributes igpNode1 = node1.augmentation(Node1.class).getIgpNodeAttributes();
+ assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
+ assertEquals("node1", igpNode1.getName().getValue());
+ assertNull(igpNode1.augmentation(IgpNodeAttributes1.class));
+ assertEquals(ROUTER_1_ID, igpNode1.augmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns
+ .yang.ospf.topology.rev131021.IgpNodeAttributes1.class).getOspfNodeAttributes().getTed()
+ .getTeRouterIdIpv4().getValue());
+ assertEquals(LinkstateTopologyBuilder.LINKSTATE_TOPOLOGY_TYPE, topology.getTopologyTypes());
+ assertNull(node1.augmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.Node1.class));
+ return topology;
+ });
// update node with prefix
- updateLinkstateRoute(createLinkstatePrefixRoute(ProtocolId.Ospf, NODE_1_AS, NODE_1_PREFIX, 500L, ROUTER_1_ID));
- final Topology topology3 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
- final IgpNodeAttributes igpNode2 = topology3.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
- assertEquals(1, igpNode2.getPrefix().size());
- final Prefix prefix = igpNode2.getPrefix().get(0);
- assertEquals(NODE_1_PREFIX, prefix.getPrefix().getIpv4Prefix().getValue());
- assertEquals(500L, prefix.getMetric().longValue());
+ updateLinkstateRoute(this.linkstatePrefixRouteIID,
+ createLinkstatePrefixRoute(ProtocolId.Ospf, NODE_1_AS, NODE_1_PREFIX, 500L, ROUTER_1_ID));
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ final Node node1 = topology.nonnullNode().values().iterator().next();
+ final IgpNodeAttributes igpNode1 = node1.augmentation(Node1.class).getIgpNodeAttributes();
+ assertEquals(1, igpNode1.nonnullPrefix().size());
+ final Prefix prefix = igpNode1.nonnullPrefix().values().iterator().next();
+ assertEquals(NODE_1_PREFIX, prefix.getPrefix().getIpv4Prefix().getValue());
+ assertEquals(500L, prefix.getMetric().longValue());
+ assertEquals(LinkstateTopologyBuilder.SR_AWARE_LINKSTATE_TOPOLOGY_TYPE, topology.getTopologyTypes());
+ assertEquals(1, node1.augmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.Node1.class)
+ .nonnullSegments().size());
+ assertEquals(SRGB_START + NODE_SID_INDEX, node1.augmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.Node1.class)
+ .nonnullSegments().values().iterator().next().getSegmentId().getValue().intValue());
+ return topology;
+ });
// create link
- updateLinkstateRoute(createLinkstateLinkRoute(ProtocolId.Ospf, NODE_1_AS, NODE_2_AS, "link1"));
- final Topology topology2 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
- assertEquals(1, topology2.getLink().size());
- final Link link1 = topology2.getLink().get(0);
- assertEquals(2, topology2.getNode().size());
- assertEquals(1, topology2.getNode().get(0).getTerminationPoint().size());
- assertEquals(1, topology2.getNode().get(1).getTerminationPoint().size());
- assertEquals("bgpls://Ospf:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
- assertEquals(NODE_1_OSPF_ID, link1.getSource().getSourceNode().getValue());
- assertEquals(NODE_2_OSPF_ID, link1.getDestination().getDestNode().getValue());
- final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
- assertEquals("link1", igpLink1.getName());
- assertNull(igpLink1.getAugmentation(IgpLinkAttributes1.class));
- assertEquals((short) 1, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getMultiTopologyId().shortValue());
- assertEquals(2, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getTed().getSrlg().getSrlgValues().size());
+ updateLinkstateRoute(this.linkstateLinkRouteIID,
+ createLinkstateLinkRoute(ProtocolId.Ospf, NODE_1_AS, NODE_2_AS, "link1"));
+ readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+ assertEquals(1, topology.nonnullLink().size());
+ final Link link1 = topology.nonnullLink().values().iterator().next();
+ assertEquals(2, topology.getNode().size());
+ assertEquals(1, Iterables.get(topology.getNode().values(), 0).getTerminationPoint().size());
+ assertEquals(1, Iterables.get(topology.getNode().values(), 1).getTerminationPoint().size());
+ assertEquals("bgpls://Ospf:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1",
+ link1.getLinkId().getValue());
+ assertEquals(NODE_1_OSPF_ID, link1.getSource().getSourceNode().getValue());
+ assertEquals(NODE_2_OSPF_ID, link1.getDestination().getDestNode().getValue());
+ final IgpLinkAttributes igpLink1 = link1.augmentation(Link1.class).getIgpLinkAttributes();
+ assertEquals("link1", igpLink1.getName());
+ assertNull(igpLink1.augmentation(IgpLinkAttributes1.class));
+ assertEquals((short) 1, igpLink1.augmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang
+ .ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getMultiTopologyId()
+ .shortValue());
+ assertEquals(2, igpLink1.augmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns
+ .yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getTed().getSrlg()
+ .getSrlgValues().size());
+ assertEquals(LinkstateTopologyBuilder.SR_AWARE_LINKSTATE_TOPOLOGY_TYPE, topology.getTopologyTypes());
+ assertEquals(2, topology.getNode().size());
+ final Node srcNode;
+ if (topology.getNode().values().iterator().next().getNodeId().getValue().contains("0000.0102.0304")) {
+ srcNode = topology.getNode().values().iterator().next();
+ } else {
+ srcNode = Iterables.get(topology.getNode().values(), 1);
+ }
+ assertEquals(2, srcNode.augmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.Node1.class)
+ .getSegments().size());
+ assertEquals(ADJ_SID, link1.augmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.Link1.class)
+ .getSegment().getValue().intValue());
+ return topology;
+ });
+ }
- this.linkstateTopoBuilder.close();
- assertFalse(getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).isPresent());
+ /**
+ * This test is to verify if the AbstractTopologyBuilder/LinkstateTopologyBuilder is handling exception correctly.
+ */
+ @Test
+ @SuppressWarnings("checkstyle:IllegalCatch")
+ public void testRouteChangedError() throws Exception {
+ final LinkstateTopologyBuilder spiedLinkstateTopologyBuilder = spy(this.linkstateTopoBuilder);
+ doThrow(RuntimeException.class).when(spiedLinkstateTopologyBuilder).routeChanged(any(), any());
+ try {
+ spiedLinkstateTopologyBuilder.routeChanged(null, null);
+ fail("Mockito failed to spy routeChanged() method");
+ } catch (final Exception e) {
+ assertTrue(e instanceof RuntimeException);
+ }
+ assertEquals(0L, spiedLinkstateTopologyBuilder.listenerScheduledRestartTime);
+ assertEquals(0L, spiedLinkstateTopologyBuilder.listenerScheduledRestartEnforceCounter);
+ // first we examine if the chain is being reset when no exception is thrown
+ spiedLinkstateTopologyBuilder.onDataTreeChanged(new ArrayList<>());
+ verify(spiedLinkstateTopologyBuilder, times(1)).restartTransactionChainOnDemand();
+ verify(spiedLinkstateTopologyBuilder, never()).scheduleListenerRestart();
+ verify(spiedLinkstateTopologyBuilder, never()).resetTransactionChain();
+ assertEquals(0L, spiedLinkstateTopologyBuilder.listenerScheduledRestartTime);
+ assertEquals(0L, spiedLinkstateTopologyBuilder.listenerScheduledRestartEnforceCounter);
+ // now pass some invalid data to cause onDataTreeChanged fail
+ final DataTreeModification<LinkstateRoute> modification = mock(DataTreeModification.class, RETURNS_SMART_NULLS);
+ final List<DataTreeModification<LinkstateRoute>> changes = new ArrayList<>();
+ changes.add(modification);
+ spiedLinkstateTopologyBuilder.onDataTreeChanged(changes);
+ // one restart transaction chain check in onDataTreeChanged()
+ // we are introducing some timeout here as transaction may be executed in a delay manner
+ verify(spiedLinkstateTopologyBuilder, timeout(5000).times(1)).scheduleListenerRestart();
+ verify(spiedLinkstateTopologyBuilder, times(2)).restartTransactionChainOnDemand();
+ assertNotEquals(0L, spiedLinkstateTopologyBuilder.listenerScheduledRestartTime);
+ assertEquals(0, spiedLinkstateTopologyBuilder.listenerScheduledRestartEnforceCounter);
+ final long listenerScheduledRestartTime = spiedLinkstateTopologyBuilder.listenerScheduledRestartTime;
+ // call again with empty change to invoke restartTransactionChainOnDemand()
+ spiedLinkstateTopologyBuilder.onDataTreeChanged(new ArrayList<>());
+ verify(spiedLinkstateTopologyBuilder, times(3)).restartTransactionChainOnDemand();
+ // transaction chain should be reset while listener should not
+ verify(spiedLinkstateTopologyBuilder, times(1)).resetTransactionChain();
+ verify(spiedLinkstateTopologyBuilder, never()).resetListener();
+ // now apply a change with bad modification again
+ spiedLinkstateTopologyBuilder.onDataTreeChanged(changes);
+ verify(spiedLinkstateTopologyBuilder, times(4)).restartTransactionChainOnDemand();
+ // listener scheduled again
+ verify(spiedLinkstateTopologyBuilder, timeout(5000).times(2)).scheduleListenerRestart();
+ // listener timer shouldn't have changed
+ assertEquals(listenerScheduledRestartTime, spiedLinkstateTopologyBuilder.listenerScheduledRestartTime);
+ assertEquals(0, spiedLinkstateTopologyBuilder.listenerScheduledRestartEnforceCounter);
+ verify(spiedLinkstateTopologyBuilder, times(2)).resetTransactionChain();
+ verify(spiedLinkstateTopologyBuilder, never()).resetListener();
+ Thread.sleep(LISTENER_RESTART_TIME);
+ // manually invoke onTransactionChainFailed() to have the listener restart scheduled again
+ spiedLinkstateTopologyBuilder.onTransactionChainFailed(null, null, null);
+ assertEquals(spiedLinkstateTopologyBuilder.listenerScheduledRestartTime, listenerScheduledRestartTime
+ + LISTENER_RESTART_TIME);
+ verify(spiedLinkstateTopologyBuilder, times(5)).restartTransactionChainOnDemand();
+ verify(spiedLinkstateTopologyBuilder, times(3)).scheduleListenerRestart();
+ // enforce counter get increased
+ assertEquals(1, spiedLinkstateTopologyBuilder.listenerScheduledRestartEnforceCounter);
+ verify(spiedLinkstateTopologyBuilder, times(3)).resetTransactionChain();
+ verify(spiedLinkstateTopologyBuilder, never()).resetListener();
+ // sleep to let the listener restart timer times out
+ Thread.sleep(LISTENER_RESTART_TIME);
+ // apply a good modification (empty change)
+ spiedLinkstateTopologyBuilder.onDataTreeChanged(new ArrayList<>());
+ assertEquals(0, spiedLinkstateTopologyBuilder.listenerScheduledRestartTime);
+ assertEquals(0, spiedLinkstateTopologyBuilder.listenerScheduledRestartEnforceCounter);
+ verify(spiedLinkstateTopologyBuilder, times(6)).restartTransactionChainOnDemand();
+ // listener restarted didn't get rescheduled again
+ verify(spiedLinkstateTopologyBuilder, times(3)).scheduleListenerRestart();
+ verify(spiedLinkstateTopologyBuilder, times(4)).resetTransactionChain();
+ verify(spiedLinkstateTopologyBuilder, times(1)).resetListener();
+ }
+
+ private static String getLinkstateRouteKey(final String routeKey) {
+ return Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode(routeKey)).array().toString();
+ }
+
+ private InstanceIdentifier<LinkstateRoute> createLinkstateRouteIID(final String linkstateRouteKey) {
+ return this.tablePathIID.builder().child(LinkstateRoutesCase.class, LinkstateRoutes.class)
+ .child(LinkstateRoute.class, new LinkstateRouteKey(new PathId(Uint32.ZERO), linkstateRouteKey)).build();
}
- private void updateLinkstateRoute(final LinkstateRoute data) {
+ private void updateLinkstateRoute(final InstanceIdentifier<LinkstateRoute> linkstateRouteIID,
+ final LinkstateRoute data) {
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
- wTx.put(LogicalDatastoreType.OPERATIONAL, this.linkstateRouteIID, data, true);
- wTx.submit();
+ wTx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, linkstateRouteIID, data);
+ wTx.commit();
}
- private LinkstateRoute createLinkstateNodeRoute(final ProtocolId protocolId, final String nodeName, final AsNumber asNumber, final String ipv4RouterId) {
- return createBaseBuilder(protocolId)
- .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder().setNodeDescriptors(new NodeDescriptorsBuilder().setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{ 0, 0, 1, 2, 3, 4 })).build()).build()).setAsNumber(asNumber).build()).build())
- .setAttributes(new AttributesBuilder()
- .addAugmentation(Attributes1.class, new Attributes1Builder().setLinkStateAttribute(new NodeAttributesCaseBuilder().setNodeAttributes(new NodeAttributesBuilder()
- .setDynamicHostname(nodeName)
- .setIpv4RouterId(new Ipv4RouterIdentifier(ipv4RouterId))
- .setIsisAreaId(Collections.singletonList(new IsisAreaIdentifier(new byte[]{0x47}))).build()).build()).build()).build()).build();
+ private void removeLinkstateRoute(final InstanceIdentifier<LinkstateRoute> linkstateRouteIID) {
+ final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
+ wTx.delete(LogicalDatastoreType.OPERATIONAL, linkstateRouteIID);
+ wTx.commit();
}
- private LinkstateRoute createLinkstatePrefixRoute(final ProtocolId protocolId, final AsNumber asNumber, final String ipv4Prefix, final long igpMetric, final String ospfFwdAddress) {
- return createBaseBuilder(protocolId)
- .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCaseBuilder()
- .setAdvertisingNodeDescriptors(new AdvertisingNodeDescriptorsBuilder().setAsNumber(asNumber).build())
- .setPrefixDescriptors(new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix(ipv4Prefix))).build())
- .build())
- .setAttributes(new AttributesBuilder()
- .addAugmentation(Attributes1.class, new Attributes1Builder().setLinkStateAttribute(new PrefixAttributesCaseBuilder().setPrefixAttributes(new PrefixAttributesBuilder().setOspfForwardingAddress(new IpAddress(new Ipv4Address(ospfFwdAddress))).setPrefixMetric(new IgpMetric(igpMetric)).build()).build()).build()).build())
- .build();
+ private LinkstateRoute createLinkstateNodeRoute(final ProtocolId protocolId, final String nodeName,
+ final AsNumber asNumber, final String ipv4RouterId) {
+ return createBaseBuilder(this.linkstateNodeRouteKey, protocolId)
+ .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate
+ .rev200120.linkstate.object.type.NodeCaseBuilder()
+ .setNodeDescriptors(new NodeDescriptorsBuilder()
+ .setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder()
+ .setIsoSystemId(new IsoSystemIdentifier(new byte[]{0, 0, 1, 2, 3, 4})).build())
+ .build())
+ .setAsNumber(asNumber).build()).build())
+ .setAttributes(new AttributesBuilder()
+ .setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
+ .addAugmentation(new Attributes1Builder()
+ .setLinkStateAttribute(new NodeAttributesCaseBuilder()
+ .setNodeAttributes(new NodeAttributesBuilder()
+ .setDynamicHostname(nodeName)
+ .setIpv4RouterId(new Ipv4RouterIdentifier(ipv4RouterId))
+ .setIsisAreaId(Collections.singletonList(
+ new IsisAreaIdentifier(new byte[]{0x47})))
+ .setSrCapabilities(new SrCapabilitiesBuilder()
+ .setRangeSize(new Uint24(Uint32.valueOf(SRGB_RANGE)))
+ .setSidLabelIndex(new LocalLabelCaseBuilder()
+ .setLocalLabel(
+ new MplsLabel(Uint32.valueOf(SRGB_START)))
+ .build())
+ .build())
+ .build()).build()).build()).build()).build();
}
- private LinkstateRoute createLinkstateLinkRoute(final ProtocolId protocolId, final AsNumber localAs, final AsNumber remoteAs, final String linkName) {
- return createBaseBuilder(protocolId)
- .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCaseBuilder()
- .setLocalNodeDescriptors(new LocalNodeDescriptorsBuilder().setAsNumber(localAs).setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{ 0, 0, 1, 2, 3, 4 })).build()).build()).build())
- .setRemoteNodeDescriptors(new RemoteNodeDescriptorsBuilder().setAsNumber(remoteAs).build())
- .setLinkDescriptors(new LinkDescriptorsBuilder().setMultiTopologyId(new TopologyIdentifier(1)).build())
- .build())
+ private LinkstateRoute createLinkstatePrefixRoute(final ProtocolId protocolId, final AsNumber asNumber,
+ final String ipv4Prefix, final long igpMetric, final String ospfFwdAddress) {
+ return createBaseBuilder(this.linkstatePrefixRouteKey, protocolId)
+ .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120
+ .linkstate.object.type.PrefixCaseBuilder()
+ .setAdvertisingNodeDescriptors(new AdvertisingNodeDescriptorsBuilder()
+ .setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder()
+ .setIsoSystemId(new IsoSystemIdentifier(new byte[]{0, 0, 1, 2, 3, 4})).build())
+ .build()).setAsNumber(asNumber).build())
+ .setPrefixDescriptors(new PrefixDescriptorsBuilder()
+ .setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix(ipv4Prefix))).build()).build())
.setAttributes(new AttributesBuilder()
- .addAugmentation(Attributes1.class, new Attributes1Builder().setLinkStateAttribute(new LinkAttributesCaseBuilder().setLinkAttributes(
- new LinkAttributesBuilder().setSharedRiskLinkGroups(Lists.newArrayList(new SrlgId(5L), new SrlgId(15L))).setAdminGroup(new AdministrativeGroup(0L))
- .setMaxLinkBandwidth(new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0xff}))
- .setMaxReservableBandwidth(new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0x1f}))
- .setUnreservedBandwidth(Lists.newArrayList(new UnreservedBandwidthBuilder().setKey(new UnreservedBandwidthKey((short) 1)).setBandwidth(new Bandwidth(new byte[]{0x00, 0x00, 0x00, (byte) 0xff})).build()))
- .setTeMetric(new TeMetric(100L)).setLinkName(linkName).build()).build()).build())
+ .setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
+ .addAugmentation(new Attributes1Builder()
+ .setLinkStateAttribute(new PrefixAttributesCaseBuilder()
+ .setPrefixAttributes(new PrefixAttributesBuilder()
+ .setOspfForwardingAddress(new IpAddressNoZone(new Ipv4AddressNoZone(ospfFwdAddress)))
+ .setPrefixMetric(new IgpMetric(Uint32.valueOf(igpMetric)))
+ .setSrPrefix(new SrPrefixBuilder()
+ .setAlgorithm(Algorithm.ShortestPathFirst)
+ .setSidLabelIndex(new SidCaseBuilder()
+ .setSid(Uint32.valueOf(NODE_SID_INDEX)).build())
+ .build())
+ .build())
+ .build())
+ .build())
.build())
.build();
}
- private LinkstateRouteBuilder createBaseBuilder(final ProtocolId protocolId) {
+ private LinkstateRoute createLinkstateLinkRoute(final ProtocolId protocolId, final AsNumber localAs,
+ final AsNumber remoteAs, final String linkName) {
+ return createBaseBuilder(this.linkstateLinkRouteKey, protocolId)
+ .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate
+ .rev200120.linkstate.object.type.LinkCaseBuilder()
+ .setLocalNodeDescriptors(new LocalNodeDescriptorsBuilder().setAsNumber(localAs)
+ .setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder()
+ .setIsoSystemId(new IsoSystemIdentifier(new byte[]{0, 0, 1, 2, 3, 4}))
+ .build()).build()).build())
+ .setRemoteNodeDescriptors(new RemoteNodeDescriptorsBuilder().setAsNumber(remoteAs).build())
+ .setLinkDescriptors(new LinkDescriptorsBuilder()
+ .setMultiTopologyId(new TopologyIdentifier(Uint16.ONE)).build()).build())
+ .setAttributes(new AttributesBuilder()
+ .setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
+ .addAugmentation(new Attributes1Builder()
+ .setLinkStateAttribute(new LinkAttributesCaseBuilder()
+ .setLinkAttributes(new LinkAttributesBuilder()
+ .setSharedRiskLinkGroups(Lists.newArrayList(
+ new SrlgId(Uint32.valueOf(5)), new SrlgId(Uint32.valueOf(15))))
+ .setAdminGroup(new AdministrativeGroup(Uint32.ZERO))
+ .setMaxLinkBandwidth(
+ new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0xff}))
+ .setMaxReservableBandwidth(
+ new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0x1f}))
+ .setUnreservedBandwidth(Lists.newArrayList(new UnreservedBandwidthBuilder()
+ .withKey(new UnreservedBandwidthKey(Uint8.ONE))
+ .setBandwidth(new Bandwidth(new byte[]{0x00, 0x00, 0x00, (byte) 0xff}))
+ .build()))
+ .setTeMetric(new TeMetric(Uint32.valueOf(100)))
+ .setLinkName(linkName)
+ .setSrAdjIds(Collections.singletonList(new SrAdjIdsBuilder()
+ .setSidLabelIndex(new LocalLabelCaseBuilder()
+ .setLocalLabel(new MplsLabel(Uint32.valueOf(ADJ_SID)))
+ .build())
+ .build()))
+ .build())
+ .build())
+ .build())
+ .build())
+ .build();
+ }
+
+ private static LinkstateRouteBuilder createBaseBuilder(final String linkstateRouteKey,
+ final ProtocolId protocolId) {
return new LinkstateRouteBuilder()
.setIdentifier(IDENTIFIER)
- .setKey(new LinkstateRouteKey(LINKSTATE_ROUTE_KEY))
- .setRouteKey(LINKSTATE_ROUTE_KEY)
+ .withKey(new LinkstateRouteKey(new PathId(Uint32.ZERO), linkstateRouteKey))
+ .setRouteKey(linkstateRouteKey)
.setProtocolId(protocolId);
}
}