-Remove deprecated class AbstractDataBrokerTest on tests.
-Perform some code clean up under tests.
Change-Id: Iee8bdb1e190c80aa0ae883e52963afb6b29cc4f0
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
eventLoopGroup, eventLoopGroup);
Mockito.doReturn("mockChannel").when(this.mockChannel).toString();
- final PCEPDispatcherImpl dispatcher2 = new PCEPDispatcherImpl(msgReg, new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0), eventLoopGroup, eventLoopGroup);
+ final PCEPDispatcherImpl dispatcher2 = new PCEPDispatcherImpl(msgReg,
+ new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0),
+ eventLoopGroup, eventLoopGroup);
this.disp2Spy = Mockito.spy(dispatcher2);
this.pccMock = new PCCMock(new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0),
final InetSocketAddress serverAddr = new InetSocketAddress("0.0.0.0", port);
final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
waitFutureSuccess(this.dispatcher.createServer(serverAddr, SimpleSessionListener::new, null));
- final PCEPSessionImpl session1 = (PCEPSessionImpl) this.pccMock.createClient(clientAddr,
- RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
+ final Future<PCEPSession> futureClient = this.pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT,
+ SimpleSessionListener::new);
+ waitFutureSuccess(futureClient);
+ final PCEPSessionImpl session1 = (PCEPSessionImpl) futureClient.get();
try {
this.pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT,
});
}
- Future<PCEPSession> createClient(final InetSocketAddress address, final int retryTimer, final int connectTimeout,
- final PCEPDispatcherImpl.ChannelPipelineInitializer initializer) {
+ Future<PCEPSession> createClient(final InetSocketAddress address, final int retryTimer,
+ final int connectTimeout, final PCEPDispatcherImpl.ChannelPipelineInitializer initializer) {
final Bootstrap b = new Bootstrap();
final PCEPProtocolSessionPromise p = new PCEPProtocolSessionPromise(this.executor, address, retryTimer,
connectTimeout, b);
package org.opendaylight.protocol.pcep.segment.routing;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
+
import com.google.common.collect.Lists;
import java.nio.charset.StandardCharsets;
import java.util.List;
-import java.util.concurrent.ExecutionException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.bgpcep.pcep.topology.provider.AbstractPCEPSessionTest;
import org.opendaylight.bgpcep.pcep.topology.provider.AbstractTopologySessionListener;
import org.opendaylight.bgpcep.pcep.topology.provider.Stateful07TopologySessionListenerFactory;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.protocol.pcep.PCEPSession;
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.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupTypeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
public class TopologyProviderTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
}
@Test
- public void testOnReportMessage() throws InterruptedException, ExecutionException {
+ public void testOnReportMessage() throws ReadFailedException {
this.listener.onSessionUp(this.session);
Pcrpt pcRptMsg = createSrPcRpt("1.1.1.1", "sr-path1", 1L, true);
this.listener.onMessage(this.session, pcRptMsg);
- //check sr-path
- Topology topology = getTopology().get();
- List<ReportedLsp> reportedLsps = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient().getReportedLsp();
- Assert.assertEquals(1, reportedLsps.size());
- final ReportedLsp lsp = reportedLsps.get(0);
- Assert.assertEquals("sr-path1", lsp.getName());
- Assert.assertEquals(1, lsp.getPath().get(0).getAugmentation(Path1.class).getPathSetupType().getPst().intValue());
- List<Subobject> subobjects = lsp.getPath().get(0).getEro().getSubobject();
- Assert.assertEquals(1, subobjects.size());
- Assert.assertEquals("1.1.1.1", ((IpNodeId)((SrEroType)subobjects.get(0).getSubobjectType()).getNai()).getIpAddress().getIpv4Address().getValue());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check sr-path
+ final List<ReportedLsp> reportedLsps = pcc.getReportedLsp();
+ Assert.assertEquals(1, reportedLsps.size());
+ final ReportedLsp lsp = reportedLsps.get(0);
+ Assert.assertEquals("sr-path1", lsp.getName());
+ Assert.assertEquals(1, lsp.getPath().get(0).getAugmentation(Path1.class).getPathSetupType()
+ .getPst().intValue());
+ final List<Subobject> subobjects = lsp.getPath().get(0).getEro().getSubobject();
+ Assert.assertEquals(1, subobjects.size());
+ Assert.assertEquals("1.1.1.1", ((IpNodeId)((SrEroType)subobjects.get(0).getSubobjectType())
+ .getNai()).getIpAddress().getIpv4Address().getValue());
+ return pcc;
+ });
pcRptMsg = createSrPcRpt("1.1.1.3", "sr-path2", 2L, false);
this.listener.onMessage(this.session, pcRptMsg);
- //check second lsp sr-path
- topology = getTopology().get();
- reportedLsps = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient().getReportedLsp();
- Assert.assertEquals(2, reportedLsps.size());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check second lsp sr-path
+ Assert.assertEquals(2, pcc.getReportedLsp().size());
+ return pcc;
+ });
+
pcRptMsg = createSrPcRpt("1.1.1.2", "sr-path1", 1L, true);
this.listener.onMessage(this.session, pcRptMsg);
- //check updated sr-path
- topology = getTopology().get();
- reportedLsps = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient().getReportedLsp();
- Assert.assertEquals(2, reportedLsps.size());
- for (final ReportedLsp rlsp : reportedLsps) {
- if (rlsp.getName().equals("sr-path1")) {
- subobjects = rlsp.getPath().get(0).getEro().getSubobject();
- Assert.assertEquals(1, subobjects.size());
- Assert.assertEquals("1.1.1.2", ((IpNodeId)((SrEroType)subobjects.get(0).getSubobjectType()).getNai()).getIpAddress().getIpv4Address().getValue());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check updated sr-path
+ final List<ReportedLsp> reportedLsps = pcc.getReportedLsp();
+ Assert.assertEquals(2, reportedLsps.size());
+ for (final ReportedLsp rlsp : reportedLsps) {
+ if (rlsp.getName().equals("sr-path1")) {
+ final List<Subobject> subobjects = rlsp.getPath().get(0).getEro().getSubobject();
+ Assert.assertEquals(1, subobjects.size());
+ Assert.assertEquals("1.1.1.2", ((IpNodeId)((SrEroType)subobjects.get(0)
+ .getSubobjectType()).getNai()).getIpAddress().getIpv4Address().getValue());
+ }
}
- }
+ return pcc;
+ });
}
private static Pcrpt createSrPcRpt(final String nai, final String pathName, final long plspId, final boolean hasLspIdTlv) {
</dependency>
<!-- Test dependencies -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>testtool-util</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-import com.google.common.base.Optional;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoop;
-import io.netty.util.concurrent.Future;
-import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.Promise;
import java.lang.reflect.ParameterizedType;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.opendaylight.controller.config.yang.pcep.topology.provider.ListenerStateRuntimeMXBean;
import org.opendaylight.controller.config.yang.pcep.topology.provider.ListenerStateRuntimeRegistration;
import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderRuntimeMXBean;
import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderRuntimeRegistration;
import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderRuntimeRegistrator;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.NetworkTopologyPcepService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
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.TopologyKey;
+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.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.Notification;
-public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerFactory> extends AbstractDataBrokerTest {
+public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerFactory> extends AbstractConcurrentDataBrokerTest {
protected static final String TEST_TOPOLOGY_NAME = "testtopo";
- protected static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(
+ static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(
Topology.class, new TopologyKey(new TopologyId(TEST_TOPOLOGY_NAME))).build();
protected static final String IPV4_MASK = "/32";
protected static final short DEAD_TIMER = 30;
protected static final int RPC_TIMEOUT = 4;
protected final String testAddress = InetSocketAddressUtil.getRandomLoopbackIpAddress();
- protected final NodeId nodeId = new NodeId("pcc://" + testAddress);
- protected final String eroIpPrefix = testAddress + IPV4_MASK;
+ protected final NodeId nodeId = new NodeId("pcc://" + this.testAddress);
+ protected final InstanceIdentifier<PathComputationClient> pathComputationClientIId = TOPO_IID.builder().child(Node.class,
+ new NodeKey(this.nodeId)).augmentation(Node1.class).child(PathComputationClient.class).build();
+ protected final String eroIpPrefix = this.testAddress + IPV4_MASK;
protected final String newDestinationAddress = InetSocketAddressUtil.getRandomLoopbackIpAddress();
- protected final String dstIpPrefix = newDestinationAddress + IPV4_MASK;
+ protected final String dstIpPrefix = this.newDestinationAddress + IPV4_MASK;
protected List<Notification> receivedMsgs;
private final Open localPrefs = new OpenBuilder().setDeadTimer((short) 30).setKeepalive((short) 10).setSessionId((short) 0).build();
- private final Open remotePrefs = localPrefs;
+ private final Open remotePrefs = this.localPrefs;
protected ServerSessionManager manager;
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
this.receivedMsgs = new ArrayList<>();
- doAnswer(new Answer<Object>() {
- @Override
- public Object answer(final InvocationOnMock invocation) {
- final Object[] args = invocation.getArguments();
- AbstractPCEPSessionTest.this.receivedMsgs.add((Notification) args[0]);
- return channelFuture;
- }
+ doAnswer(invocation -> {
+ final Object[] args = invocation.getArguments();
+ AbstractPCEPSessionTest.this.receivedMsgs.add((Notification) args[0]);
+ return this.channelFuture;
}).when(this.clientListener).writeAndFlush(any(Notification.class));
doReturn(null).when(this.channelFuture).addListener(Mockito.any());
doReturn("TestingChannel").when(this.clientListener).toString();
doReturn(this.eventLoop).when(this.clientListener).eventLoop();
doReturn(null).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
doReturn(true).when(this.clientListener).isActive();
- final SocketAddress ra = new InetSocketAddress(testAddress, 4189);
+ final SocketAddress ra = new InetSocketAddress(this.testAddress, 4189);
doReturn(ra).when(this.clientListener).remoteAddress();
- final SocketAddress la = new InetSocketAddress(testAddress, InetSocketAddressUtil.getRandomPort());
+ final SocketAddress la = new InetSocketAddress(this.testAddress, InetSocketAddressUtil.getRandomPort());
doReturn(la).when(this.clientListener).localAddress();
doReturn(mock(ChannelFuture.class)).when(this.clientListener).close();
this.manager.close();
}
- protected Optional<Topology> getTopology() throws InterruptedException, ExecutionException {
- try (ReadOnlyTransaction t = getDataBroker().newReadOnlyTransaction()) {
- return t.read(LogicalDatastoreType.OPERATIONAL, TOPO_IID).get();
- }
- }
-
protected Ero createEroWithIpPrefixes(final List<String> ipPrefixes) {
- final List<Subobject> subobjs = new ArrayList<Subobject>(ipPrefixes.size());
+ final List<Subobject> subobjs = new ArrayList<>(ipPrefixes.size());
final SubobjectBuilder subobjBuilder = new SubobjectBuilder();
for (final String ipPrefix : ipPrefixes) {
subobjBuilder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(
}
protected final PCEPSession getPCEPSession(final Open localOpen, final Open remoteOpen) {
- return neg.createSession(this.clientListener, localOpen, remoteOpen);
+ return this.neg.createSession(this.clientListener, localOpen, remoteOpen);
}
}
package org.opendaylight.bgpcep.pcep.topology.provider;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
import com.google.common.base.Optional;
import java.math.BigInteger;
import java.util.Collections;
-import java.util.concurrent.ExecutionException;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
public class IncrementalSynchronizationProcedureTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
private Stateful07TopologySessionListener listener;
- private PCEPSession session;
-
@Override
@Before
public void setUp() throws Exception {
}
@Test
- public void testStateSynchronizationPerformed() throws InterruptedException, ExecutionException {
- this.session = getPCEPSession(getOpen(null), getOpen(null));
+ public void testStateSynchronizationPerformed() throws Exception {
+ PCEPSession session = getPCEPSession(getOpen(null), getOpen(null));
this.listener.onSessionUp(session);
//report LSP + LSP-DB version number
final Pcrpt pcRpt = getPcrpt(1L, "test");
this.listener.onMessage(session, pcRpt);
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertFalse(pcc.getReportedLsp().isEmpty());
+ return pcc;
+ });
- final PathComputationClient pcc = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- Assert.assertFalse(pcc.getReportedLsp().isEmpty());
this.listener.onSessionDown(session, new IllegalArgumentException());
this.listener = (Stateful07TopologySessionListener) getSessionListener();
//session up - expect sync (LSP-DBs do not match)
final LspDbVersion localDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(2L)).build();
- this.session = getPCEPSession(getOpen(localDbVersion), getOpen(null));
+ session = getPCEPSession(getOpen(localDbVersion), getOpen(null));
this.listener.onSessionUp(session);
-
- final PathComputationClient pcc2 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- //check node - IncrementalSync state
- Assert.assertEquals(PccSyncState.IncrementalSync, pcc2.getStateSync());
- //check reported LSP - persisted from previous session
- Assert.assertFalse(pcc2.getReportedLsp().isEmpty());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check node - IncrementalSync state
+ assertEquals(PccSyncState.IncrementalSync, pcc.getStateSync());
+ //check reported LSP - persisted from previous session
+ assertFalse(pcc.getReportedLsp().isEmpty());
+ return pcc;
+ });
//report LSP2 + LSP-DB version number 2
final Pcrpt pcRpt2 = getPcrpt(2L,"testsecond");
this.listener.onMessage(session, pcRpt2);
-
- final PathComputationClient pcc3 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-
- //check node - synchronized
- Assert.assertEquals(PccSyncState.IncrementalSync, pcc3.getStateSync());
- //check reported LSP is not empty
- Assert.assertEquals(2, pcc3.getReportedLsp().size());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check node - synchronized
+ assertEquals(PccSyncState.IncrementalSync, pcc.getStateSync());
+ //check reported LSP is not empty
+ assertEquals(2, pcc.getReportedLsp().size());
+ return pcc;
+ });
//sync rpt + LSP-DB
final Pcrpt syncMsg = getSyncPcrt();
this.listener.onMessage(session, syncMsg);
- final PathComputationClient pcc4 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- //check node - synchronized
- Assert.assertEquals(PccSyncState.Synchronized, pcc4.getStateSync());
- //check reported LSP is empty, LSP state from previous session was purged
- Assert.assertEquals(2, pcc4.getReportedLsp().size());
-
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check node - synchronized
+ assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+ //check reported LSP is empty, LSP state from previous session was purged
+ assertEquals(2, pcc.getReportedLsp().size());
+ return pcc;
+ });
//report LSP3 + LSP-DB version number 4
final Pcrpt pcRpt3 = getPcrpt(3L,"testthird");
this.listener.onMessage(session, pcRpt3);
-
- final PathComputationClient pcc5 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-
- //check node - synchronized
- Assert.assertEquals(PccSyncState.Synchronized, pcc5.getStateSync());
- Assert.assertEquals(3,pcc5.getReportedLsp().size());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check node - synchronized
+ assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+ assertEquals(3,pcc.getReportedLsp().size());
+ return pcc;
+ });
}
private Open getOpen(final LspDbVersion dbVersion) {
- return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder()
- .addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build())
- .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder()
+ return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class,
+ new Tlvs1Builder().setStateful(new StatefulBuilder().addAugmentation(Stateful1.class,
+ new Stateful1Builder().setInitiation(Boolean.TRUE).build())
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.
+ optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
+ .ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder()
.setIncludeDbVersion(Boolean.TRUE).setDeltaLspSyncCapability(Boolean.TRUE).build())
- .build()).build()).addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(dbVersion).build()).build()).build();
+ .build()).build()).addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(dbVersion).build())
+ .build()).build();
}
- private Pcrpt getPcrpt(Long val, String pathname) {
+ private Pcrpt getPcrpt(final Long val, final String pathname) {
return MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setPlspId(new PlspId(val)).setTlvs(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.
- TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setLspId(new LspId(val)).build())
- .setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(pathname.getBytes())).build())
- .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync
- .optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(val)).build()).build()).build()).setPlspId(new PlspId(val)
- ).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.absent(), createPath(Collections.emptyList()));
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.
+ object.lsp.TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setLspId(new LspId(val)).build())
+ .setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(
+ pathname.getBytes())).build()).addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params
+ .xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class, new org.opendaylight.yang.gen.v1.
+ urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder()
+ .setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(val)).build())
+ .build()).build()).setPlspId(new PlspId(val)
+ ).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.absent(),
+ createPath(Collections.emptyList()));
}
private Pcrpt getSyncPcrt() {
return MsgBuilderUtil.createPcRtpMessage(createLsp(0, false, Optional.of(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.
+ lsp.object.lsp.TlvsBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.
+ xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync
- .optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(3L)).build()).build()).build()), true, false), Optional.<Srp>absent(),
+ .optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder()
+ .setLspDbVersionValue(BigInteger.valueOf(3L)).build()).build()).build()),
+ true, false), Optional.absent(),
createPath(Collections.emptyList()));
}
}
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
.child(Topology.class, new TopologyKey(new TopologyId("topology")));
private static final NodeId NODE_ID = new NodeId("node");
private static final LspDbVersion LSP_DB_VERSION = new LspDbVersionBuilder().setLspDbVersionValue(
- BigInteger.valueOf(1L)).build();
+ BigInteger.ONE).build();
@Mock
private DataBroker dataBroker;
new StatefulBuilder().addAugmentation(Stateful1.class, new Stateful1Builder().build()).build())
.build());
final ReadOnlyTransaction rTxMock = Mockito.mock(ReadOnlyTransaction.class);
- Mockito.doReturn(rTxMock).when(dataBroker).newReadOnlyTransaction();
- Mockito.doReturn(listenableFutureMock).when(rTxMock)
+ Mockito.doReturn(rTxMock).when(this.dataBroker).newReadOnlyTransaction();
+ Mockito.doReturn(this.listenableFutureMock).when(rTxMock)
.read(Mockito.any(LogicalDatastoreType.class), Mockito.any(InstanceIdentifier.class));
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Runnable runnable = (Runnable) invocation.getArguments()[0];
- runnable.run();
- return null;
- }
- }).when(listenableFutureMock).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
+ Mockito.doAnswer(invocation -> {
+ final Runnable runnable = (Runnable) invocation.getArguments()[0];
+ runnable.run();
+ return null;
+ }).when(this.listenableFutureMock).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
}
@Test
public void testSetPeerProposalSuccess() throws InterruptedException, ExecutionException {
- Mockito.doReturn(Optional.of(LSP_DB_VERSION)).when(listenableFutureMock).get();
- final PCEPStatefulPeerProposal peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(dataBroker,
+ Mockito.doReturn(Optional.of(LSP_DB_VERSION)).when(this.listenableFutureMock).get();
+ final PCEPStatefulPeerProposal peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(this.dataBroker,
TOPOLOGY_IID);
- peerProposal.setPeerProposal(NODE_ID, tlvsBuilder);
- assertEquals(LSP_DB_VERSION, tlvsBuilder.getAugmentation(Tlvs3.class).getLspDbVersion());
+ peerProposal.setPeerProposal(NODE_ID, this.tlvsBuilder);
+ assertEquals(LSP_DB_VERSION, this.tlvsBuilder.getAugmentation(Tlvs3.class).getLspDbVersion());
}
@Test
public void testSetPeerProposalAbsent() throws InterruptedException, ExecutionException {
- Mockito.doReturn(Optional.absent()).when(listenableFutureMock).get();
- final PCEPStatefulPeerProposal peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(dataBroker,
+ Mockito.doReturn(Optional.absent()).when(this.listenableFutureMock).get();
+ final PCEPStatefulPeerProposal peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(this.dataBroker,
TOPOLOGY_IID);
- peerProposal.setPeerProposal(NODE_ID, tlvsBuilder);
- assertNull(tlvsBuilder.getAugmentation(Tlvs3.class));
+ peerProposal.setPeerProposal(NODE_ID, this.tlvsBuilder);
+ assertNull(this.tlvsBuilder.getAugmentation(Tlvs3.class));
}
@Test
public void testSetPeerProposalFailure() throws InterruptedException, ExecutionException {
- Mockito.doThrow(new RuntimeException()).when(listenableFutureMock).get();
- final PCEPStatefulPeerProposal peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(dataBroker,
+ Mockito.doThrow(new RuntimeException()).when(this.listenableFutureMock).get();
+ final PCEPStatefulPeerProposal peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(this.dataBroker,
TOPOLOGY_IID);
- peerProposal.setPeerProposal(NODE_ID, tlvsBuilder);
- assertNull(tlvsBuilder.getAugmentation(Tlvs3.class));
+ peerProposal.setPeerProposal(NODE_ID, this.tlvsBuilder);
+ assertNull(this.tlvsBuilder.getAugmentation(Tlvs3.class));
}
}
*/
package org.opendaylight.bgpcep.pcep.topology.provider;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
import com.google.common.base.Optional;
import java.math.BigInteger;
import java.util.Collections;
import java.util.List;
-import java.util.concurrent.ExecutionException;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.SrpBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
private Stateful07TopologySessionListener listener;
private PCEPSession session;
+ private final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.ONE).build();
@Override
@Before
}
@Test
- public void testTriggeredResynchronization() throws InterruptedException, ExecutionException {
+ public void testTriggeredResynchronization() throws Exception {
//session up - sync skipped (LSP-DBs match)
- final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build();
- this.session = getPCEPSession(getOpen(lspDbVersion), getOpen(lspDbVersion));
- this.listener.onSessionUp(session);
+ this.session = getPCEPSession(getOpen(), getOpen());
+ this.listener.onSessionUp(this.session);
//report LSP + LSP-DB version number
final Pcrpt pcRpt = getPcrt();
- this.listener.onMessage(session, pcRpt);
+ this.listener.onMessage(this.session, pcRpt);
- final PathComputationClient pcc = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- Assert.assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
- Assert.assertFalse(pcc.getReportedLsp().isEmpty());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+ assertFalse(pcc.getReportedLsp().isEmpty());
+ return pcc;
+ });
//PCEP Trigger Full Resync
- this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(nodeId).build());
-
- final PathComputationClient pcc1 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- Assert.assertEquals(PccSyncState.PcepTriggeredResync, pcc1.getStateSync());
+ this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).build());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertEquals(PccSyncState.PcepTriggeredResync, pcc.getStateSync());
+ return pcc;
+ });
//end of sync
final Pcrpt syncMsg = getSyncMsg();
- this.listener.onMessage(session, syncMsg);
- final PathComputationClient pcc2 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- //check node - synchronized
- Assert.assertEquals(PccSyncState.Synchronized, pcc2.getStateSync());
-
- this.listener.onMessage(session, pcRpt);
- final PathComputationClient pcc3 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- Assert.assertEquals(1, pcc3.getReportedLsp().size());
+ this.listener.onMessage(this.session, syncMsg);
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check node - synchronized
+ assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+ return pcc;
+ });
+
+ this.listener.onMessage(this.session, pcRpt);
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertEquals(1, pcc.getReportedLsp().size());
+ return pcc;
+ });
//Trigger Full Resync
- this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(nodeId).build());
- this.listener.onMessage(session, pcRpt);
+ this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).build());
+ this.listener.onMessage(this.session, pcRpt);
//end of sync
- this.listener.onMessage(session, syncMsg);
- final PathComputationClient pcc4 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- //check node - synchronized
- Assert.assertEquals(PccSyncState.Synchronized, pcc4.getStateSync());
- //check reported LSP is not empty, Stale LSP state were purged
- Assert.assertEquals(1, pcc4.getReportedLsp().size());
+ this.listener.onMessage(this.session, syncMsg);
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check node - synchronized
+ assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+ //check reported LSP is not empty, Stale LSP state were purged
+ assertEquals(1, pcc.getReportedLsp().size());
+ return pcc;
+ });
}
@Test
- public void testTriggeredResynchronizationLsp() throws InterruptedException, ExecutionException {
+ public void testTriggeredResynchronizationLsp() throws Exception {
//session up - sync skipped (LSP-DBs match)
- final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build();
- this.session = getPCEPSession(getOpen(lspDbVersion), getOpen(lspDbVersion));
- this.listener.onSessionUp(session);
+
+ this.session = getPCEPSession(getOpen(), getOpen());
+ this.listener.onSessionUp(this.session);
//report LSP + LSP-DB version number
final Pcrpt pcRpt = getPcrt();
- this.listener.onMessage(session, pcRpt);
-
- final PathComputationClient pcc = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- Assert.assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
- final List<ReportedLsp> reportedLspPcc = pcc.getReportedLsp();
- Assert.assertFalse(reportedLspPcc.isEmpty());
+ this.listener.onMessage(this.session, pcRpt);
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+ final List<ReportedLsp> reportedLspPcc = pcc.getReportedLsp();
+ assertFalse(reportedLspPcc.isEmpty());
+ return pcc;
+ });
//Trigger Full Resync
- this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(nodeId).setName("test").build());
-
- final PathComputationClient pcc1 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- Assert.assertEquals(PccSyncState.PcepTriggeredResync, pcc1.getStateSync());
- Assert.assertFalse(pcc1.getReportedLsp().isEmpty());
-
- this.listener.onMessage(session, pcRpt);
-
- Assert.assertFalse(reportedLspPcc.isEmpty());
+ this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).setName("test").build());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertEquals(PccSyncState.PcepTriggeredResync, pcc.getStateSync());
+ assertFalse(pcc.getReportedLsp().isEmpty());
+ return pcc;
+ });
+
+ this.listener.onMessage(this.session, pcRpt);
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertFalse(pcc.getReportedLsp().isEmpty());
+ return pcc;
+ });
//sync rpt + LSP-DB
final Pcrpt syncMsg = getSyncMsg();
- this.listener.onMessage(session, syncMsg);
- final PathComputationClient pcc2 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- //check node - synchronized
- Assert.assertEquals(PccSyncState.Synchronized, pcc2.getStateSync());
- //check reported LSP
- Assert.assertEquals(1, pcc2.getReportedLsp().size());
+ this.listener.onMessage(this.session, syncMsg);
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check node - synchronized
+ assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+ //check reported LSP
+ assertEquals(1, pcc.getReportedLsp().size());
+ return pcc;
+ });
//Trigger Full Resync
- this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(nodeId).setName("test").build());
- this.listener.onMessage(session, syncMsg);
-
- final PathComputationClient pcc3 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- //check node - synchronized
- Assert.assertEquals(PccSyncState.Synchronized, pcc3.getStateSync());
- //check reported LSP
- Assert.assertEquals(0, pcc3.getReportedLsp().size());
-
+ this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).setName("test").build());
+ this.listener.onMessage(this.session, syncMsg);
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check node - synchronized
+ assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+ //check reported LSP
+ assertEquals(0, pcc.getReportedLsp().size());
+ return pcc;
+ });
}
- private Open getOpen(final LspDbVersion dbVersion) {
- return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder()
- .addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build())
- .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1.class,
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder()
- .setIncludeDbVersion(Boolean.TRUE).setTriggeredResync(Boolean.TRUE).build())
- .build()).build()).addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(dbVersion).build()).build()).build();
+ private Open getOpen() {
+ return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class,
+ new Tlvs1Builder().setStateful(new StatefulBuilder().addAugmentation(Stateful1.class, new Stateful1Builder()
+ .setInitiation(Boolean.TRUE).build()).addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight
+ .params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations
+ .rev150714.Stateful1Builder().setIncludeDbVersion(Boolean.TRUE).setTriggeredResync(Boolean.TRUE)
+ .build()).build()).build()).addAugmentation(Tlvs3.class, new Tlvs3Builder()
+ .setLspDbVersion(this.lspDbVersion).build()).build()).build();
}
private Pcrpt getSyncMsg() {
new SymbolicPathNameBuilder().setPathName(new SymbolicPathName("test".getBytes())).build())
.addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder()
- .setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build()).build()).build())
+ .setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.ONE).build()).build()).build())
.setPlspId(new PlspId(1L)).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.absent(),
createPath(Collections.emptyList()));
}
package org.opendaylight.bgpcep.pcep.topology.provider;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
import com.google.common.base.Optional;
import java.math.BigInteger;
import java.util.Collections;
-import java.util.concurrent.ExecutionException;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
public class PCETriggeredInitialSyncProcedureTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
private Stateful07TopologySessionListener listener;
- private PCEPSession session;
-
@Override
@Before
public void setUp() throws Exception {
* Test Triggered Initial Sync procedure
**/
@Test
- public void testPcepTriggeredInitialSyncPerformed() throws InterruptedException, ExecutionException {
+ public void testPcepTriggeredInitialSyncPerformed() throws Exception {
this.listener = (Stateful07TopologySessionListener) getSessionListener();
//session up - expect triggered sync (LSP-DBs do not match)
- final LspDbVersion localDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build();
+ final LspDbVersion localDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.ONE).build();
final LspDbVersion localDbVersion2 = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(2L)).build();
- this.session = getPCEPSession(getOpen(localDbVersion, Boolean.FALSE), getOpen(localDbVersion2, Boolean.FALSE));
+ final PCEPSession session = getPCEPSession(getOpen(localDbVersion, Boolean.FALSE), getOpen(localDbVersion2, Boolean.FALSE));
this.listener.onSessionUp(session);
- final PathComputationClient pcc2 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- //check node - not synchronized and TriggeredInitialSync state
- Assert.assertEquals(PccSyncState.TriggeredInitialSync, pcc2.getStateSync());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check node - not synchronized and TriggeredInitialSync state
+ assertEquals(PccSyncState.TriggeredInitialSync, pcc.getStateSync());
+ return pcc;
+ });
+
//sync rpt + LSP-DB
final Pcrpt syncMsg = getsyncMsg();
this.listener.onMessage(session, syncMsg);
- final PathComputationClient pcc3 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- //check node - synchronized
- Assert.assertEquals(PccSyncState.Synchronized, pcc3.getStateSync());
- //check reported LSP is empty, LSP state from previous session was purged
- Assert.assertTrue(pcc3.getReportedLsp().isEmpty());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check node - synchronized
+ assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+ //check reported LSP is empty, LSP state from previous session was purged
+ assertTrue(pcc.getReportedLsp().isEmpty());
+ return pcc;
+ });
//report LSP + LSP-DB version number
final Pcrpt pcRpt = getPcrpt();
this.listener.onMessage(session, pcRpt);
- final PathComputationClient pcc = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- Assert.assertFalse(pcc.getReportedLsp().isEmpty());
+
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertFalse(pcc.getReportedLsp().isEmpty());
+ return pcc;
+ });
+
}
private Open getOpen(final LspDbVersion dbVersion, final boolean incremental) {
package org.opendaylight.bgpcep.pcep.topology.provider;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
import com.google.common.base.Optional;
import java.math.BigInteger;
import java.util.Collections;
-import java.util.concurrent.ExecutionException;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.PathComputationClient1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-public class StateSynchronizationAvoidanceProcedureTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
+public class StateSynchronizationAvoidanceProcedureTest extends
+ AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
private Stateful07TopologySessionListener listener;
- private PCEPSession session;
-
@Override
@Before
public void setUp() throws Exception {
}
@Test
- public void testNodePersisted() throws InterruptedException, ExecutionException {
- this.session = getPCEPSession(getOpen(null), getOpen(null));
+ public void testNodePersisted() throws ReadFailedException {
+ final PCEPSession session = getPCEPSession(getOpen(null), getOpen(null));
this.listener.onSessionUp(session);
//report LSP + LSP-DB version number
final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setTlvs(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder()
.addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build()).build()).build()).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(1L)), null);
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.ONE).build()).build()).build()).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(1L)), null);
this.listener.onMessage(session, pcRpt);
//check topology
- final Topology topo1 = getTopology().get();
- final LspDbVersion lspDb1 = topo1.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient().getAugmentation(PathComputationClient1.class).getLspDbVersion();
- Assert.assertEquals(1L, lspDb1.getLspDbVersionValue().longValue());
+ readData(getDataBroker(), this.pathComputationClientIId.builder().augmentation(PathComputationClient1.class)
+ .child(LspDbVersion.class).build(), dbVersion -> {
+ assertEquals(1L, dbVersion.getLspDbVersionValue().longValue());
+ return dbVersion;
+ });
+
//drop session
this.listener.onSessionDown(session, new IllegalStateException());
+ readData(getDataBroker(), TOPO_IID, topology -> {
+ assertFalse(topology.getNode().isEmpty());
+ return topology;
+ });
//check topology - node is persisted
- final Topology topo2 = getTopology().get();
- Assert.assertFalse(topo2.getNode().isEmpty());
}
@Test
- public void testStateSynchronizationSkipped() throws InterruptedException, ExecutionException {
+ public void testStateSynchronizationSkipped() throws Exception {
//session up - sync skipped (LSP-DBs match)
- final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build();
- this.session = getPCEPSession(getOpen(lspDbVersion), getOpen(lspDbVersion));
+ final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.ONE).build();
+ final PCEPSession session = getPCEPSession(getOpen(lspDbVersion), getOpen(lspDbVersion));
this.listener.onSessionUp(session);
//check node - synchronized
- final Topology topo = getTopology().get();
- Assert.assertEquals(PccSyncState.Synchronized, topo.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient().getStateSync());
- }
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+ return pcc;
+ });
+ }
@Test
- public void testStateSynchronizationPerformed() throws InterruptedException, ExecutionException {
- this.session = getPCEPSession(getOpen(null), getOpen(null));
+ public void testStateSynchronizationPerformed() throws Exception {
+ PCEPSession session = getPCEPSession(getOpen(null), getOpen(null));
this.listener.onSessionUp(session);
//report LSP + LSP-DB version number
final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setPlspId(new PlspId(1L)).setTlvs(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setLspId(new LspId(1L)).build()).setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(new SymbolicPathName("test".getBytes())).build())
- .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build()).build()).build()).setPlspId(new PlspId(1L)).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.absent(), createPath(Collections.emptyList()));
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.
+ object.lsp.TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder()
+ .setLspId(new LspId(1L)).build()).setSymbolicPathName(new SymbolicPathNameBuilder()
+ .setPathName(new SymbolicPathName("test".getBytes())).build()).addAugmentation(org.opendaylight.
+ yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714
+ .Tlvs1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller
+ .pcep.sync.optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder()
+ .setLspDbVersionValue(BigInteger.ONE).build()).build()).build())
+ .setPlspId(new PlspId(1L)).setSync(true).setRemove(false).setOperational(OperationalStatus.Active)
+ .build(), Optional.absent(), createPath(Collections.emptyList()));
this.listener.onMessage(session, pcRpt);
- final Topology topo = getTopology().get();
- final PathComputationClient pcc = topo.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- Assert.assertFalse(pcc.getReportedLsp().isEmpty());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertFalse(pcc.getReportedLsp().isEmpty());
+ return pcc;
+ });
+
this.listener.onSessionDown(session, new IllegalArgumentException());
this.listener = (Stateful07TopologySessionListener) getSessionListener();
//session up - expect sync (LSP-DBs do not match)
- final LspDbVersion localDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(2L)).build();
- this.session = getPCEPSession(getOpen(localDbVersion), getOpen(null));
+ final LspDbVersion localDbVersion = new LspDbVersionBuilder()
+ .setLspDbVersionValue(BigInteger.valueOf(2L)).build();
+ session = getPCEPSession(getOpen(localDbVersion), getOpen(null));
this.listener.onSessionUp(session);
- final Topology topo2 = getTopology().get();
- final PathComputationClient pcc2 = topo2.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- //check node - not synchronized
- Assert.assertEquals(PccSyncState.InitialResync, pcc2.getStateSync());
- //check reported LSP - persisted from previous session
- Assert.assertFalse(pcc2.getReportedLsp().isEmpty());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check node - not synchronized
+ assertEquals(PccSyncState.InitialResync, pcc.getStateSync());
+ //check reported LSP - persisted from previous session
+ assertFalse(pcc.getReportedLsp().isEmpty());
+ return pcc;
+ });
+
//sync rpt + LSP-DB
final Pcrpt syncMsg = MsgBuilderUtil.createPcRtpMessage(createLsp(0, false, Optional.of(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(2L)).build()).build()).build()), true, false), Optional.absent(),
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222
+ .lsp.object.lsp.TlvsBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.
+ params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync
+ .optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder()
+ .setLspDbVersionValue(BigInteger.valueOf(2L)).build()).build()).build()),
+ true, false), Optional.absent(),
createPath(Collections.emptyList()));
this.listener.onMessage(session, syncMsg);
- final Topology topo3 = getTopology().get();
- final PathComputationClient pcc3 = topo3.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- //check node - synchronized
- Assert.assertEquals(PccSyncState.Synchronized, pcc3.getStateSync());
- //check reported LSP is empty, LSP state from previous session was purged
- Assert.assertTrue(pcc3.getReportedLsp().isEmpty());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ //check node - synchronized
+ assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+ //check reported LSP is empty, LSP state from previous session was purged
+ assertTrue(pcc.getReportedLsp().isEmpty());
+ return pcc;
+ });
}
- protected Open getOpen(final LspDbVersion dbVersion) {
- return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder()
+ private Open getOpen(final LspDbVersion dbVersion) {
+ return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class,
+ new Tlvs1Builder().setStateful(new StatefulBuilder()
.addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build())
- .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder().setIncludeDbVersion(Boolean.TRUE).build())
- .build()).build()).addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(dbVersion).build()).build()).build();
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.
+ optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.
+ xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder()
+ .setIncludeDbVersion(Boolean.TRUE).build()).build()).build()).addAugmentation(Tlvs3.class,
+ new Tlvs3Builder().setLspDbVersion(dbVersion).build()).build()).build();
}
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLspTlvs;
+import static org.opendaylight.protocol.util.CheckUtil.checkNull;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
+
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import java.net.UnknownHostException;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.config.yang.pcep.topology.provider.SessionState;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.protocol.pcep.PCEPCloseTermination;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.FailureType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.add.lsp.args.ArgumentsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yangtools.yang.common.RpcResult;
public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
- private final String TUNNEL_NAME = "pcc_" + testAddress + "_tunnel_0";
+ private final String TUNNEL_NAME = "pcc_" + this.testAddress + "_tunnel_0";
private Stateful07TopologySessionListener listener;
public void testStateful07TopologySessionListener() throws Exception {
this.listener.onSessionUp(this.session);
- assertEquals(testAddress, this.listener.getPeerId());
+ assertEquals(this.testAddress, this.listener.getPeerId());
final SessionState state = this.listener.getSessionState();
assertNotNull(state);
assertEquals(DEAD_TIMER, state.getLocalPref().getDeadtimer().shortValue());
assertEquals(KEEP_ALIVE, state.getLocalPref().getKeepalive().shortValue());
assertEquals(0, state.getLocalPref().getSessionId().intValue());
- assertEquals(testAddress, state.getLocalPref().getIpAddress());
+ assertEquals(this.testAddress, state.getLocalPref().getIpAddress());
assertEquals(DEAD_TIMER, state.getPeerPref().getDeadtimer().shortValue());
assertEquals(KEEP_ALIVE, state.getPeerPref().getKeepalive().shortValue());
assertEquals(0, state.getPeerPref().getSessionId().intValue());
- assertEquals(testAddress, state.getPeerPref().getIpAddress());
+ assertEquals(this.testAddress, state.getPeerPref().getIpAddress());
// add-lsp
this.topologyRpcs.addLsp(createAddLspInput());
final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
final long srpId = req.getSrp().getOperationId().getValue();
final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
- testAddress, testAddress, testAddress, Optional.absent());
- final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
- final Pcrpt esm = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setSync(false).build(), Optional.of(MsgBuilderUtil.createSrp(0L)), null);
+ this.testAddress, this.testAddress, this.testAddress, Optional.absent());
+ final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp())
+ .setTlvs(tlvs).setPlspId(new PlspId(1L)).setSync(false).setRemove(false)
+ .setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)),
+ MsgBuilderUtil.createPath(req.getEro().getSubobject()));
+ final Pcrpt esm = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setSync(false).build(),
+ Optional.of(MsgBuilderUtil.createSrp(0L)), null);
this.listener.onMessage(this.session, esm);
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertEquals(this.testAddress, pcc.getIpAddress().getIpv4Address().getValue());
+ // reported lsp so far empty, has not received response (PcRpt) yet
+ assertTrue(pcc.getReportedLsp().isEmpty());
+ return pcc;
+ });
- final Optional<Topology> topoOptional = getTopology();
- assertTrue(topoOptional.isPresent());
- Topology topology = topoOptional.get();
- assertEquals(1, topology.getNode().size());
- final Node1 node = topology.getNode().get(0).getAugmentation(Node1.class);
- assertNotNull(node);
- PathComputationClient pcc = node.getPathComputationClient();
- assertEquals(testAddress, pcc.getIpAddress().getIpv4Address().getValue());
- // reported lsp so far empty, has not received response (PcRpt) yet
- assertTrue(pcc.getReportedLsp().isEmpty());
this.listener.onMessage(this.session, pcRpt);
// check created lsp
- topology = getTopology().get();
- pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- assertEquals(1, pcc.getReportedLsp().size());
- ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
- assertEquals(TUNNEL_NAME, reportedLsp.getName());
- assertEquals(1, reportedLsp.getPath().size());
- Path path = reportedLsp.getPath().get(0);
- assertEquals(1, path.getEro().getSubobject().size());
- assertEquals(eroIpPrefix, getLastEroIpPrefix(path.getEro()));
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertEquals(1, pcc.getReportedLsp().size());
+ final ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
+ assertEquals(this.TUNNEL_NAME, reportedLsp.getName());
+ assertEquals(1, reportedLsp.getPath().size());
+ final Path path = reportedLsp.getPath().get(0);
+ assertEquals(1, path.getEro().getSubobject().size());
+ assertEquals(this.eroIpPrefix, getLastEroIpPrefix(path.getEro()));
+ return pcc;
+ });
+
// check stats
assertEquals(1, this.listener.getDelegatedLspsCount().intValue());
assertTrue(this.listener.getSynchronized());
assertNotNull(this.listener.getSessionState());
// update-lsp
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
- updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix, dstIpPrefix)));
- updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
- final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args
+ .ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.
+ topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
+ updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(this.eroIpPrefix, this.dstIpPrefix)));
+ updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder()
+ .setDelegate(true).setAdministrative(true).build()).build());
+ final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build())
+ .setName(this.TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID))
+ .setNode(this.nodeId).build();
this.topologyRpcs.updateLsp(update);
assertEquals(2, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(1) instanceof Pcupd);
final Updates upd = updateMsg.getPcupdMessage().getUpdates().get(0);
final long srpId2 = upd.getSrp().getOperationId().getValue();
final Tlvs tlvs2 = createLspTlvs(upd.getLsp().getPlspId().getValue(), false,
- newDestinationAddress, testAddress, testAddress, Optional.absent());
- final Pcrpt pcRpt2 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(upd.getLsp()).setTlvs(tlvs2).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId2)), MsgBuilderUtil.createPath(upd.getPath().getEro().getSubobject()));
+ this.newDestinationAddress, this.testAddress, this.testAddress, Optional.absent());
+ final Pcrpt pcRpt2 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(upd.getLsp()).setTlvs(tlvs2)
+ .setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(),
+ Optional.of(MsgBuilderUtil.createSrp(srpId2)), MsgBuilderUtil.createPath(upd.getPath()
+ .getEro().getSubobject()));
this.listener.onMessage(this.session, pcRpt2);
+
//check updated lsp
- topology = getTopology().get();
- pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- assertEquals(1, pcc.getReportedLsp().size());
- reportedLsp = pcc.getReportedLsp().get(0);
- assertEquals(TUNNEL_NAME, reportedLsp.getName());
- assertEquals(1, reportedLsp.getPath().size());
- path = reportedLsp.getPath().get(0);
- assertEquals(2, path.getEro().getSubobject().size());
- assertEquals(dstIpPrefix, getLastEroIpPrefix(path.getEro()));
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertEquals(1, pcc.getReportedLsp().size());
+ final ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
+ assertEquals(this.TUNNEL_NAME, reportedLsp.getName());
+ assertEquals(1, reportedLsp.getPath().size());
+ final Path path = reportedLsp.getPath().get(0);
+ assertEquals(2, path.getEro().getSubobject().size());
+ assertEquals(this.dstIpPrefix, getLastEroIpPrefix(path.getEro()));
+ return pcc;
+ });
+
// check stats
assertEquals(1, this.listener.getDelegatedLspsCount().intValue());
assertTrue(this.listener.getSynchronized());
assertTrue(this.listener.getPeerCapabilities().getStateful());
// ensure-operational
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.ensure.lsp.operational.args.ArgumentsBuilder ensureArgs = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.ensure.lsp.operational.args.ArgumentsBuilder();
- ensureArgs.addAugmentation(Arguments1.class, new Arguments1Builder().setOperational(OperationalStatus.Active).build());
- final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.ensure.lsp.
+ operational.args.ArgumentsBuilder ensureArgs = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.
+ xml.ns.yang.topology.pcep.rev131024.ensure.lsp.operational.args.ArgumentsBuilder();
+ ensureArgs.addAugmentation(Arguments1.class, new Arguments1Builder().setOperational(OperationalStatus.Active)
+ .build());
+ final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build())
+ .setName(this.TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID))
+ .setNode(this.nodeId).build();
final OperationResult result = this.topologyRpcs.ensureLspOperational(ensure).get().getResult();
//check result
assertNull(result.getFailure());
// remove-lsp
- final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
+ final RemoveLspInput remove = new RemoveLspInputBuilder().setName(this.TUNNEL_NAME)
+ .setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(this.nodeId).build();
this.topologyRpcs.removeLsp(remove);
assertEquals(3, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(2) instanceof Pcinitiate);
final Requests req2 = pcinitiate2.getPcinitiateMessage().getRequests().get(0);
final long srpId3 = req2.getSrp().getOperationId().getValue();
final Tlvs tlvs3 = createLspTlvs(req2.getLsp().getPlspId().getValue(), false,
- testAddress, testAddress, testAddress, Optional.absent());
- final Pcrpt pcRpt3 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req2.getLsp()).setTlvs(tlvs3).setRemove(true).setSync(true).setOperational(OperationalStatus.Down).build(), Optional.of(MsgBuilderUtil.createSrp(srpId3)), MsgBuilderUtil.createPath(Collections.emptyList()));
+ this.testAddress, this.testAddress, this.testAddress, Optional.absent());
+ final Pcrpt pcRpt3 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req2.getLsp()).setTlvs(tlvs3)
+ .setRemove(true).setSync(true).setOperational(OperationalStatus.Down).build(),
+ Optional.of(MsgBuilderUtil.createSrp(srpId3)), MsgBuilderUtil.createPath(Collections.emptyList()));
this.listener.onMessage(this.session, pcRpt3);
+
// check if lsp was removed
- topology = getTopology().get();
- pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
- assertEquals(0, pcc.getReportedLsp().size());
+ readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+ assertEquals(0, pcc.getReportedLsp().size());
+ return pcc;
+ });
// check stats
assertEquals(0, this.listener.getDelegatedLspsCount().intValue());
assertTrue(this.listener.getSynchronized());
* @throws TransactionCommitFailedException
*/
@Test
- public void testOnServerSessionManagerDown() throws InterruptedException, ExecutionException, TransactionCommitFailedException {
+ public void testOnServerSessionManagerDown() throws InterruptedException, ExecutionException,
+ TransactionCommitFailedException {
this.listener.onSessionUp(this.session);
verify(this.listenerReg, times(0)).close();
// send request
* @throws TransactionCommitFailedException
*/
@Test
- public void testOnServerSessionManagerUnstarted() throws InterruptedException, ExecutionException, TransactionCommitFailedException {
+ public void testOnServerSessionManagerUnstarted() throws InterruptedException, ExecutionException,
+ TransactionCommitFailedException, ReadFailedException {
this.manager.close();
// the registration should not be closed since it's never initialized
verify(this.listenerReg, times(0)).close();
this.listener.onSessionUp(this.session);
// verify the session was NOT added to topology
- assertFalse(getTopology().isPresent());
+ checkNull(getDataBroker(), TOPO_IID);
// still, the session should not be registered and thus close() is never called
verify(this.listenerReg, times(0)).close();
// send request
}
@Test
- public void testOnSessionTermination() throws UnknownHostException, InterruptedException, ExecutionException {
+ public void testOnSessionTermination() throws Exception {
this.listener.onSessionUp(this.session);
verify(this.listenerReg, times(0)).close();
final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
final long srpId = req.getSrp().getOperationId().getValue();
final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
- testAddress, testAddress, testAddress, Optional.absent());
- final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
+ this.testAddress, this.testAddress, this.testAddress, Optional.absent());
+ final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setSync(true)
+ .setRemove(false).setOperational(OperationalStatus.Active).build(),
+ Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
this.listener.onMessage(this.session, pcRpt);
- assertEquals(1, getTopology().get().getNode().size());
+ readData(getDataBroker(), TOPO_IID, topology -> {
+ assertEquals(1, topology.getNode().size());
+ return topology;
+ });
// node should be removed after termination
this.listener.onSessionTerminated(this.session, new PCEPCloseTermination(TerminationReason.UNKNOWN));
verify(this.listenerReg, times(1)).close();
- assertEquals(0, getTopology().get().getNode().size());
+ checkNull(getDataBroker(), this.pathComputationClientIId);
}
@Test
public void testUnknownLsp() throws Exception {
- final List<Reports> reports = Lists.newArrayList(new ReportsBuilder().setPath(new PathBuilder().setEro(new EroBuilder().build()).build()).setLsp(
- new LspBuilder().setPlspId(new PlspId(5L)).setSync(false).setRemove(false).setTlvs(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setLspId(new LspId(1L)).build()).setSymbolicPathName(
- new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(new byte[] { 22, 34 })).build()).build()).build()).build());
- final Pcrpt rptmsg = new PcrptBuilder().setPcrptMessage(new PcrptMessageBuilder().setReports(reports).build()).build();
+ final List<Reports> reports = Lists.newArrayList(new ReportsBuilder().setPath(new PathBuilder()
+ .setEro(new EroBuilder().build()).build()).setLsp(new LspBuilder().setPlspId(new PlspId(5L))
+ .setSync(false).setRemove(false).setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.
+ yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().setLspIdentifiers(
+ new LspIdentifiersBuilder().setLspId(new LspId(1L)).build()).setSymbolicPathName(
+ new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(new byte[] { 22, 34 }))
+ .build()).build()).build()).build());
+ final Pcrpt rptmsg = new PcrptBuilder().setPcrptMessage(new PcrptMessageBuilder().setReports(reports).build())
+ .build();
this.listener.onSessionUp(this.session);
this.listener.onMessage(this.session, rptmsg);
- final Topology topology = getTopology().get();
- assertFalse(topology.getNode().isEmpty());
+ readData(getDataBroker(), TOPO_IID, node -> {
+ assertFalse(node.getNode().isEmpty());
+ return node;
+ });
}
@Test
public void testUpdateUnknownLsp() throws InterruptedException, ExecutionException {
this.listener.onSessionUp(this.session);
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
- updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix, dstIpPrefix)));
- updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
- final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args
+ .ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.
+ topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
+ updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(this.eroIpPrefix, this.dstIpPrefix)));
+ updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder()
+ .setDelegate(true).setAdministrative(true).build()).build());
+ final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build())
+ .setName(this.TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(this.nodeId)
+ .build();
final UpdateLspOutput result = this.topologyRpcs.updateLsp(update).get().getResult();
assertEquals(FailureType.Unsent, result.getFailure());
assertEquals(1, result.getError().size());
@Test
public void testRemoveUnknownLsp() throws InterruptedException, ExecutionException {
this.listener.onSessionUp(this.session);
- final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
+ final RemoveLspInput remove = new RemoveLspInputBuilder().setName(this.TUNNEL_NAME).setNetworkTopologyRef(
+ new NetworkTopologyRef(TOPO_IID)).setNode(this.nodeId).build();
final OperationResult result = this.topologyRpcs.removeLsp(remove).get().getResult();
assertEquals(FailureType.Unsent, result.getFailure());
assertEquals(1, result.getError().size());
final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
final long srpId = req.getSrp().getOperationId().getValue();
final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
- testAddress, testAddress, testAddress, Optional.absent());
- final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
+ this.testAddress, this.testAddress, this.testAddress, Optional.absent());
+ final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs)
+ .setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active)
+ .build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro()
+ .getSubobject()));
this.listener.onMessage(this.session, pcRpt);
//try to add already existing LSP
assertEquals(1, result.getError().size());
final ErrorObject errorObject = result.getError().get(0).getErrorObject();
assertNotNull(errorObject);
- assertEquals(PCEPErrors.USED_SYMBOLIC_PATH_NAME, PCEPErrors.forValue(errorObject.getType(), errorObject.getValue()));
+ assertEquals(PCEPErrors.USED_SYMBOLIC_PATH_NAME, PCEPErrors.forValue(errorObject.getType(),
+ errorObject.getValue()));
}
@Test
public void testPccResponseTimeout() throws InterruptedException, ExecutionException {
this.listener.onSessionUp(this.session);
- Future<RpcResult<AddLspOutput>> addLspResult = this.topologyRpcs.addLsp(createAddLspInput());
+ final Future<RpcResult<AddLspOutput>> addLspResult = this.topologyRpcs.addLsp(createAddLspInput());
try {
addLspResult.get(2, TimeUnit.SECONDS);
fail();
- } catch (Exception e) {
+ } catch (final Exception e) {
assertTrue(e instanceof TimeoutException);
}
Thread.sleep(AbstractPCEPSessionTest.RPC_TIMEOUT);
- RpcResult<AddLspOutput> rpcResult = addLspResult.get();
+ final RpcResult<AddLspOutput> rpcResult = addLspResult.get();
assertNotNull(rpcResult);
assertEquals(rpcResult.getResult().getFailure(), FailureType.Unsent);
}
@Override
protected Open getLocalPref() {
- return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder()
+ return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class,
+ new Tlvs1Builder().setStateful(new StatefulBuilder()
.addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build())
- .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder().setTriggeredInitialSync(Boolean.TRUE).build())
+ .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.
+ optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.
+ ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder()
+ .setTriggeredInitialSync(Boolean.TRUE).build())
.build()).build()).build()).build();
}
private AddLspInput createAddLspInput() {
final ArgumentsBuilder argsBuilder = new ArgumentsBuilder();
final Ipv4CaseBuilder ipv4Builder = new Ipv4CaseBuilder();
- ipv4Builder.setIpv4(new Ipv4Builder().setSourceIpv4Address(new Ipv4Address(testAddress)).setDestinationIpv4Address(new Ipv4Address(testAddress)).build());
+ ipv4Builder.setIpv4(new Ipv4Builder().setSourceIpv4Address(new Ipv4Address(this.testAddress))
+ .setDestinationIpv4Address(new Ipv4Address(this.testAddress)).build());
argsBuilder.setEndpointsObj(new EndpointsObjBuilder().setAddressFamily(ipv4Builder.build()).build());
- argsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix)));
- argsBuilder.addAugmentation(Arguments2.class, new Arguments2Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
- return new AddLspInputBuilder().setName(TUNNEL_NAME).setArguments(argsBuilder.build()).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
+ argsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(this.eroIpPrefix)));
+ argsBuilder.addAugmentation(Arguments2.class, new Arguments2Builder().setLsp(new LspBuilder()
+ .setDelegate(true).setAdministrative(true).build()).build());
+ return new AddLspInputBuilder().setName(this.TUNNEL_NAME).setArguments(argsBuilder.build())
+ .setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(this.nodeId).build();
}
}
@Test
public void testDoesLspDbMatchPositive() {
final Tlvs tlvs = createTlvs(1L, false, false);
- Mockito.doReturn(tlvs).when(pcepSession).localSessionCharacteristics();
- Mockito.doReturn(tlvs).when(pcepSession).getRemoteTlvs();
- final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+ Mockito.doReturn(tlvs).when(this.pcepSession).localSessionCharacteristics();
+ Mockito.doReturn(tlvs).when(this.pcepSession).getRemoteTlvs();
+ final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
assertTrue(syncOpt.doesLspDbMatch());
}
public void testDoesLspDbMatchNegative() {
final Tlvs localTlvs = createTlvs(1L, false, false);
final Tlvs remoteTlvs = createTlvs(2L, false, false);
- Mockito.doReturn(localTlvs).when(pcepSession).localSessionCharacteristics();
- Mockito.doReturn(remoteTlvs).when(pcepSession).getRemoteTlvs();
- final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+ Mockito.doReturn(localTlvs).when(this.pcepSession).localSessionCharacteristics();
+ Mockito.doReturn(remoteTlvs).when(this.pcepSession).getRemoteTlvs();
+ final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
assertFalse(syncOpt.doesLspDbMatch());
}
@Test
public void testIsSyncAvoidanceEnabledPositive() {
final Tlvs tlvs = createTlvs(1L, true, false);
- Mockito.doReturn(tlvs).when(pcepSession).localSessionCharacteristics();
- Mockito.doReturn(tlvs).when(pcepSession).getRemoteTlvs();
- final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+ Mockito.doReturn(tlvs).when(this.pcepSession).localSessionCharacteristics();
+ Mockito.doReturn(tlvs).when(this.pcepSession).getRemoteTlvs();
+ final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
assertTrue(syncOpt.isSyncAvoidanceEnabled());
}
public void testIsSyncAvoidanceEnabledNegative() {
final Tlvs localTlvs = createTlvs(1L, true, false);
final Tlvs remoteTlvs = createTlvs(2L, false, false);
- Mockito.doReturn(localTlvs).when(pcepSession).localSessionCharacteristics();
- Mockito.doReturn(remoteTlvs).when(pcepSession).getRemoteTlvs();
- final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+ Mockito.doReturn(localTlvs).when(this.pcepSession).localSessionCharacteristics();
+ Mockito.doReturn(remoteTlvs).when(this.pcepSession).getRemoteTlvs();
+ final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
assertFalse(syncOpt.isSyncAvoidanceEnabled());
}
@Test
public void testIsDeltaSyncEnabledPositive() {
final Tlvs tlvs = createTlvs(1L, true, true);
- Mockito.doReturn(tlvs).when(pcepSession).localSessionCharacteristics();
- Mockito.doReturn(tlvs).when(pcepSession).getRemoteTlvs();
- final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+ Mockito.doReturn(tlvs).when(this.pcepSession).localSessionCharacteristics();
+ Mockito.doReturn(tlvs).when(this.pcepSession).getRemoteTlvs();
+ final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
assertTrue(syncOpt.isDeltaSyncEnabled());
}
public void testIsDeltaSyncEnabledNegative() {
final Tlvs localTlvs = createTlvs(1L, true, true);
final Tlvs remoteTlvs = createTlvs(2L, false, false);
- Mockito.doReturn(localTlvs).when(pcepSession).localSessionCharacteristics();
- Mockito.doReturn(remoteTlvs).when(pcepSession).getRemoteTlvs();
- final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+ Mockito.doReturn(localTlvs).when(this.pcepSession).localSessionCharacteristics();
+ Mockito.doReturn(remoteTlvs).when(this.pcepSession).getRemoteTlvs();
+ final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
assertFalse(syncOpt.isDeltaSyncEnabled());
}
public void testIsDbVersionPresentPositive() {
final Tlvs localTlvs = createTlvs(null, false, false);
final Tlvs remoteTlvs = createTlvs(2L, false, false);
- Mockito.doReturn(localTlvs).when(pcepSession).localSessionCharacteristics();
- Mockito.doReturn(remoteTlvs).when(pcepSession).getRemoteTlvs();
- final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+ Mockito.doReturn(localTlvs).when(this.pcepSession).localSessionCharacteristics();
+ Mockito.doReturn(remoteTlvs).when(this.pcepSession).getRemoteTlvs();
+ final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
assertTrue(syncOpt.isDbVersionPresent());
}
@Test
public void testIsDbVersionPresentNegative() {
final Tlvs tlvs = createTlvs(null, true, false);
- Mockito.doReturn(tlvs).when(pcepSession).localSessionCharacteristics();
- Mockito.doReturn(tlvs).when(pcepSession).getRemoteTlvs();
- final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+ Mockito.doReturn(tlvs).when(this.pcepSession).localSessionCharacteristics();
+ Mockito.doReturn(tlvs).when(this.pcepSession).getRemoteTlvs();
+ final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
assertFalse(syncOpt.isDbVersionPresent());
}
.addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(
new LspDbVersionBuilder().setLspDbVersionValue(lspDbVersion != null ? BigInteger.valueOf(lspDbVersion) : null).build()).build()).build();
}
-
}
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
-import java.util.concurrent.Future;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.opendaylight.bgpcep.pcep.topology.provider.TopologyProgrammingTest.MockedTopologySessionListenerFactory;
import org.opendaylight.bgpcep.programming.spi.Instruction;
import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
private TopologyProgramming topologyProgramming;
- private PCEPSession session;
-
@Override
@Before
public void setUp() throws Exception {
super.setUp();
Mockito.doReturn(true).when(this.instruction).checkedExecutionStart();
Mockito.doNothing().when(this.instruction).executionCompleted(InstructionStatus.Failed, null);
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Runnable callback = (Runnable) invocation.getArguments()[0];
- callback.run();
- return null;
- }
+ Mockito.doAnswer(invocation -> {
+ final Runnable callback = (Runnable) invocation.getArguments()[0];
+ callback.run();
+ return null;
}).when(this.instructionFuture).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Runnable callback = (Runnable) invocation.getArguments()[0];
- callback.run();
- return null;
- }
+ Mockito.doAnswer(invocation -> {
+ final Runnable callback = (Runnable) invocation.getArguments()[0];
+ callback.run();
+ return null;
}).when(this.futureAddLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Runnable callback = (Runnable) invocation.getArguments()[0];
- callback.run();
- return null;
- }
+ Mockito.doAnswer(invocation -> {
+ final Runnable callback = (Runnable) invocation.getArguments()[0];
+ callback.run();
+ return null;
}).when(this.futureUpdateLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Runnable callback = (Runnable) invocation.getArguments()[0];
- callback.run();
- return null;
- }
+ Mockito.doAnswer(invocation -> {
+ final Runnable callback = (Runnable) invocation.getArguments()[0];
+ callback.run();
+ return null;
}).when(this.futureRemoveLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Runnable callback = (Runnable) invocation.getArguments()[0];
- callback.run();
- return null;
- }
+ Mockito.doAnswer(invocation -> {
+ final Runnable callback = (Runnable) invocation.getArguments()[0];
+ callback.run();
+ return null;
}).when(this.futureTriggerSyncOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Runnable callback = (Runnable) invocation.getArguments()[0];
- callback.run();
- return null;
- }
+ Mockito.doAnswer(invocation -> {
+ final Runnable callback = (Runnable) invocation.getArguments()[0];
+ callback.run();
+ return null;
}).when(this.futureEnsureLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
- Mockito.doAnswer(new Answer<Future<RpcResult<AddLspOutput>>>() {
- @Override
- public Future<RpcResult<AddLspOutput>> answer(final InvocationOnMock invocation) throws Throwable {
- TopologyProgrammingTest.this.addLspArgs = (AddLspArgs) invocation.getArguments()[0];
- return TopologyProgrammingTest.this.futureAddLspOutput;
- }
+ Mockito.doAnswer(invocation -> {
+ TopologyProgrammingTest.this.addLspArgs = (AddLspArgs) invocation.getArguments()[0];
+ return TopologyProgrammingTest.this.futureAddLspOutput;
}).when(listener).addLsp(Mockito.any(AddLspInput.class));
- Mockito.doAnswer(new Answer<Future<RpcResult<UpdateLspOutput>>>() {
- @Override
- public Future<RpcResult<UpdateLspOutput>> answer(final InvocationOnMock invocation) throws Throwable {
- TopologyProgrammingTest.this.updateLspArgs = (UpdateLspArgs) invocation.getArguments()[0];
- return TopologyProgrammingTest.this.futureUpdateLspOutput;
- }
+ Mockito.doAnswer(invocation -> {
+ TopologyProgrammingTest.this.updateLspArgs = (UpdateLspArgs) invocation.getArguments()[0];
+ return TopologyProgrammingTest.this.futureUpdateLspOutput;
}).when(listener).updateLsp(Mockito.any(UpdateLspInput.class));
- Mockito.doAnswer(new Answer<Future<RpcResult<RemoveLspOutput>>>() {
- @Override
- public Future<RpcResult<RemoveLspOutput>> answer(final InvocationOnMock invocation) throws Throwable {
- TopologyProgrammingTest.this.removeLspArgs = (RemoveLspArgs) invocation.getArguments()[0];
- return TopologyProgrammingTest.this.futureRemoveLspOutput;
- }
+ Mockito.doAnswer(invocation -> {
+ TopologyProgrammingTest.this.removeLspArgs = (RemoveLspArgs) invocation.getArguments()[0];
+ return TopologyProgrammingTest.this.futureRemoveLspOutput;
}).when(listener).removeLsp(Mockito.any(RemoveLspInput.class));
- Mockito.doAnswer(new Answer<Future<RpcResult<TriggerSyncOutput>>>() {
- @Override
- public Future<RpcResult<TriggerSyncOutput>> answer(final InvocationOnMock invocation) throws Throwable {
- TopologyProgrammingTest.this.triggerSyncArgs = (TriggerSyncArgs) invocation.getArguments()[0];
- return TopologyProgrammingTest.this.futureTriggerSyncOutput;
- }
+ Mockito.doAnswer(invocation -> {
+ TopologyProgrammingTest.this.triggerSyncArgs = (TriggerSyncArgs) invocation.getArguments()[0];
+ return TopologyProgrammingTest.this.futureTriggerSyncOutput;
}).when(listener).triggerSync(Mockito.any(TriggerSyncInput.class));
- Mockito.doAnswer(new Answer<Future<RpcResult<EnsureLspOperationalOutput>>>() {
- @Override
- public Future<RpcResult<EnsureLspOperationalOutput>> answer(final InvocationOnMock invocation) throws Throwable {
- TopologyProgrammingTest.this.ensureLspInput = (EnsureLspOperationalInput) invocation.getArguments()[0];
- return TopologyProgrammingTest.this.futureEnsureLspOutput;
- }
+ Mockito.doAnswer(invocation -> {
+ TopologyProgrammingTest.this.ensureLspInput = (EnsureLspOperationalInput) invocation.getArguments()[0];
+ return TopologyProgrammingTest.this.futureEnsureLspOutput;
}).when(listener).ensureLspOperational(Mockito.any(EnsureLspOperationalInput.class));
Mockito.doNothing().when(listener).close();
- Mockito.doReturn(instruction).when(this.instructionFuture).get();
+ Mockito.doReturn(this.instruction).when(this.instructionFuture).get();
Mockito.doNothing().when(this.instruction).executionCompleted(Mockito.any(InstructionStatus.class), Mockito.any(Details.class));
Mockito.doReturn(this.instructionFuture).when(this.scheduler).scheduleInstruction(Mockito.any(SubmitInstructionInput.class));
this.topologyProgramming = new TopologyProgramming(this.scheduler, this.manager);
- this.session = getPCEPSession(getLocalPref(), getRemotePref());
- listener.onSessionUp(this.session);
+ final PCEPSession session = getPCEPSession(getLocalPref(), getRemotePref());
+ listener.onSessionUp(session);
}
@Test
public void testSubmitAddLsp() throws InterruptedException, ExecutionException {
final SubmitAddLspInputBuilder inputBuilder = new SubmitAddLspInputBuilder();
inputBuilder.setName(NAME);
- inputBuilder.setNode(nodeId);
+ inputBuilder.setNode(this.nodeId);
inputBuilder.setArguments(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.add.lsp.args.ArgumentsBuilder().build());
this.topologyProgramming.submitAddLsp(inputBuilder.build());
Assert.assertNotNull(this.addLspArgs);
Assert.assertEquals(NAME, this.addLspArgs.getName());
- Assert.assertEquals(nodeId, this.addLspArgs.getNode());
+ Assert.assertEquals(this.nodeId, this.addLspArgs.getNode());
}
@Test
public void testSubmitUpdateLsp() {
final SubmitUpdateLspInputBuilder inputBuilder = new SubmitUpdateLspInputBuilder();
inputBuilder.setName(NAME);
- inputBuilder.setNode(nodeId);
+ inputBuilder.setNode(this.nodeId);
this.topologyProgramming.submitUpdateLsp(inputBuilder.build());
Assert.assertNotNull(this.updateLspArgs);
Assert.assertEquals(NAME, this.updateLspArgs.getName());
- Assert.assertEquals(nodeId, this.updateLspArgs.getNode());
+ Assert.assertEquals(this.nodeId, this.updateLspArgs.getNode());
}
@Test
public void testSubmitEnsureLsp() {
final SubmitEnsureLspOperationalInputBuilder inputBuilder = new SubmitEnsureLspOperationalInputBuilder();
inputBuilder.setName(NAME);
- inputBuilder.setNode(nodeId);
+ inputBuilder.setNode(this.nodeId);
inputBuilder.setArguments(new ArgumentsBuilder().build());
this.topologyProgramming.submitEnsureLspOperational(inputBuilder.build());
Assert.assertNotNull(this.ensureLspInput);
Assert.assertEquals(NAME, this.ensureLspInput.getName());
- Assert.assertEquals(nodeId, this.ensureLspInput.getNode());
+ Assert.assertEquals(this.nodeId, this.ensureLspInput.getNode());
}
@Test
public void testSubmitRemoveLsp() {
final SubmitRemoveLspInputBuilder inputBuilder = new SubmitRemoveLspInputBuilder();
inputBuilder.setName(NAME);
- inputBuilder.setNode(nodeId);
+ inputBuilder.setNode(this.nodeId);
this.topologyProgramming.submitRemoveLsp(inputBuilder.build());
Assert.assertNotNull(this.removeLspArgs);
Assert.assertEquals(NAME, this.removeLspArgs.getName());
- Assert.assertEquals(nodeId, this.removeLspArgs.getNode());
+ Assert.assertEquals(this.nodeId, this.removeLspArgs.getNode());
}
@Test
public void testSubmitTriggerSync() {
final SubmitTriggerSyncInputBuilder inputBuilder = new SubmitTriggerSyncInputBuilder();
inputBuilder.setName(NAME);
- inputBuilder.setNode(nodeId);
+ inputBuilder.setNode(this.nodeId);
this.topologyProgramming.submitTriggerSync(inputBuilder.build());
Assert.assertNotNull(this.triggerSyncArgs);
Assert.assertEquals(NAME, this.triggerSyncArgs.getName());
- Assert.assertEquals(nodeId, this.triggerSyncArgs.getNode());
+ Assert.assertEquals(this.nodeId, this.triggerSyncArgs.getNode());
}
protected static final class MockedTopologySessionListenerFactory implements TopologySessionListenerFactory {
</dependency>
<!-- Testing dependencies -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>testtool-util</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
package org.opendaylight.bgpcep.pcep.tunnel.provider;
-import com.google.common.base.Optional;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
+
import com.google.common.collect.Lists;
+import java.util.Collections;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class NodeChangedListenerTest extends AbstractDataBrokerTest {
+public class NodeChangedListenerTest extends AbstractConcurrentDataBrokerTest {
private static final TopologyId PCEP_TOPOLOGY_ID = new TopologyId("pcep-topology");
private static final TopologyId TUNNEL_TOPOLOGY_ID = new TopologyId("tunnel-topology");
private static final String LSP2_NAME = "lsp2";
private static final long LSP2_ID = 2;
- private static final InstanceIdentifier<Topology> PCEP_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(PCEP_TOPOLOGY_ID)).build();
- private static final InstanceIdentifier<Topology> TUNNEL_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TUNNEL_TOPOLOGY_ID)).build();
+ private static final InstanceIdentifier<Topology> PCEP_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(PCEP_TOPOLOGY_ID)).build();
+ private static final InstanceIdentifier<Topology> TUNNEL_TOPO_IID = InstanceIdentifier.
+ builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TUNNEL_TOPOLOGY_ID)).build();
private ListenerRegistration<NodeChangedListener> listenerRegistration;
@Before
public void setUp() throws TransactionCommitFailedException {
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
- wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID, new TopologyBuilder().setKey(new TopologyKey(PCEP_TOPOLOGY_ID)).setNode(Lists.newArrayList()).setTopologyId(PCEP_TOPOLOGY_ID).build(), true);
- wTx.put(LogicalDatastoreType.OPERATIONAL, TUNNEL_TOPO_IID, new TopologyBuilder().setKey(new TopologyKey(TUNNEL_TOPOLOGY_ID)).setTopologyId(TUNNEL_TOPOLOGY_ID).build(), true);
+ wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID, new TopologyBuilder()
+ .setKey(new TopologyKey(PCEP_TOPOLOGY_ID)).setNode(Lists.newArrayList())
+ .setTopologyId(PCEP_TOPOLOGY_ID).build(), true);
+ wTx.put(LogicalDatastoreType.OPERATIONAL, TUNNEL_TOPO_IID, new TopologyBuilder()
+ .setKey(new TopologyKey(TUNNEL_TOPOLOGY_ID)).setTopologyId(TUNNEL_TOPOLOGY_ID).build(), true);
wTx.submit().checkedGet();
- final NodeChangedListener nodeListener = new NodeChangedListener(getDataBroker(), PCEP_TOPOLOGY_ID, TUNNEL_TOPO_IID);
- this.listenerRegistration = getDataBroker().registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.child(Node.class)), nodeListener);
+ final NodeChangedListener nodeListener = new NodeChangedListener(getDataBroker(),
+ PCEP_TOPOLOGY_ID, TUNNEL_TOPO_IID);
+ this.listenerRegistration = getDataBroker().registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.child(Node.class)), nodeListener);
}
@Test
public void testNodeChangedListener() throws ReadFailedException, TransactionCommitFailedException {
// add node -> create two nodes with TPs and link
createNode(NODE1_ID, NODE1_IPV4, LSP1_NAME, LSP1_ID, NODE2_IPV4);
- final Topology tunnelTopo = readTunnelTopology().get();
- Assert.assertEquals(2, tunnelTopo.getNode().size());
+ final Topology tunnelTopo = readData(getDataBroker(), TUNNEL_TOPO_IID, tunnelTopo1 -> {
+ assertNotNull(tunnelTopo1.getNode());
+ assertEquals(2, tunnelTopo1.getNode().size());
+ return tunnelTopo1;
+ });
final NodeId srcId = new NodeId("ip://" + new IpAddress(new Ipv4Address(NODE1_IPV4)));
final NodeId dstId = new NodeId("ip://" + new IpAddress(new Ipv4Address(NODE2_IPV4)));
- Node dst;
- Node src;
+ final Node dst;
+ final Node src;
if (tunnelTopo.getNode().get(0).getNodeId().equals(srcId)) {
src = tunnelTopo.getNode().get(0);
- dst = tunnelTopo.getNode().get(1);
+ dst = tunnelTopo.getNode().get(1);
} else {
src = tunnelTopo.getNode().get(1);
- dst = tunnelTopo.getNode().get(0);
+ dst = tunnelTopo.getNode().get(0);
}
Assert.assertEquals(srcId, src.getNodeId());
// update second node -> adds supporting node and second link
createNode(NODE2_ID, NODE2_IPV4, LSP2_NAME, LSP2_ID, NODE1_IPV4);
- final Topology updatedNodeTopo = readTunnelTopology().get();
- Assert.assertEquals(2, updatedNodeTopo.getNode().size());
-
- Node updatedNode;
-
- if (updatedNodeTopo.getNode().get(0).getNodeId().equals(srcId)) {
- updatedNode = updatedNodeTopo.getNode().get(1);
- } else {
- updatedNode = updatedNodeTopo.getNode().get(0);
- }
-
- Assert.assertEquals(1, updatedNode.getSupportingNode().size());
- final SupportingNode sNode2 = updatedNode.getSupportingNode().get(0);
- Assert.assertEquals(NODE2_ID, sNode2.getNodeRef());
-
- Assert.assertEquals(2, updatedNodeTopo.getLink().size());
-
- Link link2;
- if (updatedNodeTopo.getLink().get(0).getSource().getSourceNode().equals(srcId)) {
- link2 = updatedNodeTopo.getLink().get(1);
- } else {
- link2 = updatedNodeTopo.getLink().get(0);
- }
-
- Assert.assertEquals(dstId, link2.getSource().getSourceNode());
- Assert.assertEquals(dstNodeTpId, link2.getSource().getSourceTp());
- Assert.assertEquals(srcId, link2.getDestination().getDestNode());
- Assert.assertEquals(srcNodeTpId, link2.getDestination().getDestTp());
+ readData(getDataBroker(), TUNNEL_TOPO_IID, updatedNodeTopo -> {
+ assertNotNull(updatedNodeTopo.getNode());
+ Assert.assertEquals(2, updatedNodeTopo.getNode().size());
+ final Node updatedNode;
+ if (updatedNodeTopo.getNode().get(0).getNodeId().equals(srcId)) {
+ updatedNode = updatedNodeTopo.getNode().get(1);
+ } else {
+ updatedNode = updatedNodeTopo.getNode().get(0);
+ }
+
+ assertNotNull(updatedNode.getSupportingNode());
+ Assert.assertEquals(1, updatedNode.getSupportingNode().size());
+ final SupportingNode sNode2 = updatedNode.getSupportingNode().get(0);
+ Assert.assertEquals(NODE2_ID, sNode2.getNodeRef());
+ Assert.assertEquals(2, updatedNodeTopo.getLink().size());
+ return updatedNodeTopo;
+
+ });
+
+ readData(getDataBroker(), TUNNEL_TOPO_IID, updatedNodeTopo -> {
+ final Link link2;
+ if (updatedNodeTopo.getLink().get(0).getSource().getSourceNode().equals(srcId)) {
+ link2 = updatedNodeTopo.getLink().get(1);
+ } else {
+ link2 = updatedNodeTopo.getLink().get(0);
+ }
+ assertEquals(dstId, link2.getSource().getSourceNode());
+ assertEquals(dstNodeTpId, link2.getSource().getSourceTp());
+ assertEquals(srcId, link2.getDestination().getDestNode());
+ assertEquals(srcNodeTpId, link2.getDestination().getDestTp());
+ return updatedNodeTopo;
+ });
// remove nodes -> remove link
removeNode(NODE1_ID);
removeNode(NODE2_ID);
- final Topology removedNodeTopo = readTunnelTopology().get();
- Assert.assertEquals(0, removedNodeTopo.getNode().size());
- Assert.assertEquals(0, removedNodeTopo.getLink().size());
+ readData(getDataBroker(), TUNNEL_TOPO_IID, removedNodeTopo -> {
+ assertEquals(0, removedNodeTopo.getNode().size());
+ assertEquals(0, removedNodeTopo.getLink().size());
+ return removedNodeTopo;
+ });
}
@After
this.listenerRegistration.close();
}
- private void createNode(final NodeId nodeId, final String ipv4Address, final String lspName, final long lspId, final String dstIpv4Address) throws TransactionCommitFailedException {
+ private void createNode(final NodeId nodeId, final String ipv4Address, final String lspName, final long lspId,
+ final String dstIpv4Address) throws TransactionCommitFailedException {
final NodeBuilder nodeBuilder = new NodeBuilder();
nodeBuilder.setKey(new NodeKey(nodeId));
nodeBuilder.setNodeId(nodeId);
final PathBuilder pathBuilder = new PathBuilder();
pathBuilder.setKey(new PathKey(new LspId(lspId)));
- pathBuilder.setBandwidth(new BandwidthBuilder().setBandwidth(new Bandwidth(new byte[] {0x00, 0x00, (byte) 0xff, (byte) 0xff})).build());
- pathBuilder.addAugmentation(Path1.class, new Path1Builder().setLsp(new LspBuilder().setTlvs(new TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(new Ipv4Builder().setIpv4TunnelSenderAddress(new Ipv4Address(ipv4Address)).setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(ipv4Address)).setIpv4TunnelEndpointAddress(new Ipv4Address(dstIpv4Address)).build()).build()).build()).build()).setAdministrative(true).setDelegate(true).build()).build());
- final ReportedLsp reportedLps = new ReportedLspBuilder().setKey(new ReportedLspKey(lspName)).setPath(Lists.newArrayList(pathBuilder.build())).build();
+ pathBuilder.setBandwidth(new BandwidthBuilder().setBandwidth(
+ new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0xff})).build());
+ pathBuilder.addAugmentation(Path1.class, new Path1Builder().setLsp(new LspBuilder().setTlvs(new TlvsBuilder()
+ .setLspIdentifiers(new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(
+ new Ipv4Builder().setIpv4TunnelSenderAddress(new Ipv4Address(ipv4Address)).setIpv4ExtendedTunnelId(
+ new Ipv4ExtendedTunnelId(ipv4Address)).setIpv4TunnelEndpointAddress(new Ipv4Address(dstIpv4Address))
+ .build()).build()).build()).build()).setAdministrative(true).setDelegate(true).build()).build());
+ final ReportedLsp reportedLps = new ReportedLspBuilder().setKey(new ReportedLspKey(lspName)).setPath(
+ Collections.singletonList(pathBuilder.build())).build();
final Node1Builder node1Builder = new Node1Builder();
- node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized).setReportedLsp(Lists.newArrayList(reportedLps)).setIpAddress(new IpAddress(new Ipv4Address(ipv4Address))).build());
+ node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized)
+ .setReportedLsp(Lists.newArrayList(reportedLps)).setIpAddress(new IpAddress(new Ipv4Address(ipv4Address)))
+ .build());
nodeBuilder.addAugmentation(Node1.class, node1Builder.build());
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
- wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build(), nodeBuilder.build());
+ wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class,
+ new NodeKey(nodeId)).build(), nodeBuilder.build());
wTx.submit().checkedGet();
}
wTx.delete(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build());
wTx.submit().checkedGet();
}
-
- private Optional<Topology> readTunnelTopology() throws ReadFailedException {
- final ReadTransaction rTx = getDataBroker().newReadOnlyTransaction();
- return rTx.read(LogicalDatastoreType.OPERATIONAL, TUNNEL_TOPO_IID).checkedGet();
- }
}
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
-import java.util.concurrent.Future;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.opendaylight.bgpcep.programming.spi.Instruction;
import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
import org.opendaylight.bgpcep.programming.spi.SchedulerException;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
-public class TunnelProgrammingTest extends AbstractDataBrokerTest {
+public class TunnelProgrammingTest extends AbstractConcurrentDataBrokerTest {
private static final TopologyId TOPOLOGY_ID = new TopologyId("tunnel-topo");
private static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TOPOLOGY_ID)).build();
MockitoAnnotations.initMocks(this);
Mockito.doReturn(true).when(this.instruction).checkedExecutionStart();
Mockito.doNothing().when(this.instruction).executionCompleted(InstructionStatus.Failed, null);
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Runnable callback = (Runnable) invocation.getArguments()[0];
- callback.run();
- return null;
- }
+ Mockito.doAnswer(invocation -> {
+ final Runnable callback = (Runnable) invocation.getArguments()[0];
+ callback.run();
+ return null;
}).when(this.instructionFuture).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Runnable callback = (Runnable) invocation.getArguments()[0];
- callback.run();
- return null;
- }
+ Mockito.doAnswer(invocation -> {
+ final Runnable callback = (Runnable) invocation.getArguments()[0];
+ callback.run();
+ return null;
}).when(this.futureAddLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Runnable callback = (Runnable) invocation.getArguments()[0];
- callback.run();
- return null;
- }
+ Mockito.doAnswer(invocation -> {
+ final Runnable callback = (Runnable) invocation.getArguments()[0];
+ callback.run();
+ return null;
}).when(this.futureUpdateLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Runnable callback = (Runnable) invocation.getArguments()[0];
- callback.run();
- return null;
- }
+ Mockito.doAnswer(invocation -> {
+ final Runnable callback = (Runnable) invocation.getArguments()[0];
+ callback.run();
+ return null;
}).when(this.futureRemoveLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
- Mockito.doAnswer(new Answer<Future<RpcResult<AddLspOutput>>>() {
- @Override
- public Future<RpcResult<AddLspOutput>> answer(final InvocationOnMock invocation) throws Throwable {
- TunnelProgrammingTest.this.addLspInput = (AddLspInput) invocation.getArguments()[0];
- return TunnelProgrammingTest.this.futureAddLspOutput;
- }
+ Mockito.doAnswer(invocation -> {
+ TunnelProgrammingTest.this.addLspInput = (AddLspInput) invocation.getArguments()[0];
+ return TunnelProgrammingTest.this.futureAddLspOutput;
}).when(this.topologyService).addLsp(Mockito.any(AddLspInput.class));
- Mockito.doAnswer(new Answer<Future<RpcResult<UpdateLspOutput>>>() {
- @Override
- public Future<RpcResult<UpdateLspOutput>> answer(final InvocationOnMock invocation) throws Throwable {
- TunnelProgrammingTest.this.updateLspInput = (UpdateLspInput) invocation.getArguments()[0];
- return TunnelProgrammingTest.this.futureUpdateLspOutput;
- }
+ Mockito.doAnswer(invocation -> {
+ TunnelProgrammingTest.this.updateLspInput = (UpdateLspInput) invocation.getArguments()[0];
+ return TunnelProgrammingTest.this.futureUpdateLspOutput;
}).when(this.topologyService).updateLsp(Mockito.any(UpdateLspInput.class));
- Mockito.doAnswer(new Answer<Future<RpcResult<RemoveLspOutput>>>() {
- @Override
- public Future<RpcResult<RemoveLspOutput>> answer(final InvocationOnMock invocation) throws Throwable {
- TunnelProgrammingTest.this.removeLspInput = (RemoveLspInput) invocation.getArguments()[0];
- return TunnelProgrammingTest.this.futureRemoveLspOutput;
- }
+ Mockito.doAnswer(invocation -> {
+ TunnelProgrammingTest.this.removeLspInput = (RemoveLspInput) invocation.getArguments()[0];
+ return TunnelProgrammingTest.this.futureRemoveLspOutput;
}).when(this.topologyService).removeLsp(Mockito.any(RemoveLspInput.class));
- Mockito.doReturn(instruction).when(this.instructionFuture).get();
+ Mockito.doReturn(this.instruction).when(this.instructionFuture).get();
Mockito.doReturn(this.instructionFuture).when(this.scheduler).scheduleInstruction(Mockito.any(SubmitInstructionInput.class));
createInitialTopology();
- this.tunnelProgramming = new TunnelProgramming(scheduler, getDataBroker(), topologyService);
+ this.tunnelProgramming = new TunnelProgramming(this.scheduler, getDataBroker(), this.topologyService);
}
@Test