use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project bgpcep by opendaylight.
the class Stateful07TopologySessionListenerTest method testOnServerSessionManagerRestartAndSessionRecovery.
@Test
public void testOnServerSessionManagerRestartAndSessionRecovery() throws Exception {
// close server session manager first
stopSessionManager();
assertFalse(this.session.isClosed());
this.listener.onSessionUp(this.session);
// verify the session was NOT added to topology
checkNotPresentOperational(getDataBroker(), TOPO_IID);
// verify the session is closed due to server session manager is closed
assertTrue(this.session.isClosed());
// send request
final Future<RpcResult<AddLspOutput>> futureOutput = this.topologyRpcs.addLsp(createAddLspInput());
final AddLspOutput output = futureOutput.get().getResult();
// deal with unsent request after session down
assertEquals(FailureType.Unsent, output.getFailure());
// PCC client is not there
checkNotPresentOperational(getDataBroker(), this.pathComputationClientIId);
// reset received message queue
this.receivedMsgs.clear();
// now we restart the session manager
startSessionManager();
// try to start the session again
// notice since the session was terminated before, it is not usable anymore.
// we need to get a new session instance. the new session will have the same local / remote preference
this.session = getPCEPSession(getLocalPref(), getRemotePref());
assertFalse(this.session.isClosed());
this.listener.onSessionUp(this.session);
assertFalse(this.session.isClosed());
// create node
this.topologyRpcs.addLsp(createAddLspInput());
final Pcinitiate pcinitiate = (Pcinitiate) this.receivedMsgs.get(0);
final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
final long srpId = req.getSrp().getOperationId().getValue();
final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true, 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);
readDataOperational(getDataBroker(), TOPO_IID, topology -> {
assertEquals(1, topology.getNode().size());
return topology;
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project bgpcep by opendaylight.
the class Stateful07TopologySessionListenerTest method testDuplicatedSession.
/**
* When a session is somehow duplicated in controller, the controller should drop existing session.
*/
@Test
public void testDuplicatedSession() throws ReadFailedException {
this.listener.onSessionUp(this.session);
// create node
this.topologyRpcs.addLsp(createAddLspInput());
final Pcinitiate pcinitiate = (Pcinitiate) this.receivedMsgs.get(0);
final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
final long srpId = req.getSrp().getOperationId().getValue();
final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true, 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);
readDataOperational(getDataBroker(), TOPO_IID, topology -> {
assertEquals(1, topology.getNode().size());
return topology;
});
// now we do session up again
this.listener.onSessionUp(this.session);
assertTrue(this.session.isClosed());
// node should be removed after termination
checkNotPresentOperational(getDataBroker(), this.pathComputationClientIId);
assertFalse(this.receivedMsgs.isEmpty());
// the last message should be a Close message
assertTrue(this.receivedMsgs.get(this.receivedMsgs.size() - 1) instanceof Close);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project bgpcep by opendaylight.
the class TopologyProgrammingTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
doReturn(true).when(this.instruction).checkedExecutionStart();
doNothing().when(this.instruction).executionCompleted(InstructionStatus.Failed, null);
doAnswer(invocation -> {
final Runnable callback = (Runnable) invocation.getArguments()[0];
callback.run();
return null;
}).when(this.instructionFuture).addListener(any(Runnable.class), any(Executor.class));
doAnswer(invocation -> {
final Runnable callback = (Runnable) invocation.getArguments()[0];
callback.run();
return null;
}).when(this.futureAddLspOutput).addListener(any(Runnable.class), any(Executor.class));
doAnswer(invocation -> {
final Runnable callback = (Runnable) invocation.getArguments()[0];
callback.run();
return null;
}).when(this.futureUpdateLspOutput).addListener(any(Runnable.class), any(Executor.class));
doAnswer(invocation -> {
final Runnable callback = (Runnable) invocation.getArguments()[0];
callback.run();
return null;
}).when(this.futureRemoveLspOutput).addListener(any(Runnable.class), any(Executor.class));
doAnswer(invocation -> {
final Runnable callback = (Runnable) invocation.getArguments()[0];
callback.run();
return null;
}).when(this.futureTriggerSyncOutput).addListener(any(Runnable.class), any(Executor.class));
doAnswer(invocation -> {
final Runnable callback = (Runnable) invocation.getArguments()[0];
callback.run();
return null;
}).when(this.futureEnsureLspOutput).addListener(any(Runnable.class), any(Executor.class));
doAnswer(invocation -> {
TopologyProgrammingTest.this.addLspArgs = (AddLspArgs) invocation.getArguments()[0];
return TopologyProgrammingTest.this.futureAddLspOutput;
}).when(listener).addLsp(any(AddLspInput.class));
doAnswer(invocation -> {
TopologyProgrammingTest.this.updateLspArgs = (UpdateLspArgs) invocation.getArguments()[0];
return TopologyProgrammingTest.this.futureUpdateLspOutput;
}).when(listener).updateLsp(any(UpdateLspInput.class));
doAnswer(invocation -> {
TopologyProgrammingTest.this.removeLspArgs = (RemoveLspArgs) invocation.getArguments()[0];
return TopologyProgrammingTest.this.futureRemoveLspOutput;
}).when(listener).removeLsp(any(RemoveLspInput.class));
doAnswer(invocation -> {
TopologyProgrammingTest.this.triggerSyncArgs = (TriggerSyncArgs) invocation.getArguments()[0];
return TopologyProgrammingTest.this.futureTriggerSyncOutput;
}).when(listener).triggerSync(any(TriggerSyncInput.class));
doAnswer(invocation -> {
TopologyProgrammingTest.this.ensureLspInput = (EnsureLspOperationalInput) invocation.getArguments()[0];
return TopologyProgrammingTest.this.futureEnsureLspOutput;
}).when(listener).ensureLspOperational(any(EnsureLspOperationalInput.class));
doNothing().when(listener).close();
doReturn(this.instruction).when(this.instructionFuture).get();
doReturn(true).when(this.instructionFuture).isDone();
doNothing().when(this.instruction).executionCompleted(any(InstructionStatus.class), any(Details.class));
doReturn(this.instructionFuture).when(this.scheduler).scheduleInstruction(any(SubmitInstructionInput.class));
this.topologyProgramming = new TopologyProgramming(this.scheduler, this.manager);
final PCEPSession session = getPCEPSession(getLocalPref(), getRemotePref());
listener.onSessionUp(session);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project bgpcep by opendaylight.
the class PCEPSessionImplTest method testCapabilityNotSupported.
@Test
public void testCapabilityNotSupported() {
this.session.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
Assert.assertEquals(2, this.msgsSend.size());
Assert.assertTrue(this.msgsSend.get(0) instanceof Pcerr);
final Pcerr pcErr = (Pcerr) this.msgsSend.get(0);
final ErrorObject errorObj = pcErr.getPcerrMessage().getErrors().get(0).getErrorObject();
Assert.assertEquals(PCEPErrors.CAPABILITY_NOT_SUPPORTED, PCEPErrors.forValue(errorObj.getType(), errorObj.getValue()));
Assert.assertEquals(1, this.session.getMessages().getUnknownMsgReceived().intValue());
// exceeded max. unknown messages count - terminate session
Assert.assertTrue(this.msgsSend.get(1) instanceof CloseMessage);
final CloseMessage closeMsg = (CloseMessage) this.msgsSend.get(1);
Assert.assertEquals(TerminationReason.TOO_MANY_UNKNOWN_MSGS, TerminationReason.forValue(closeMsg.getCCloseMessage().getCClose().getReason()));
Mockito.verify(this.channel, Mockito.times(1)).close();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project bgpcep by opendaylight.
the class PCEPSessionNegotiator method startNegotiation.
@Override
protected void startNegotiation() throws ExecutionException {
final Object lock = this;
LOG.debug("Bootstrap negotiation for channel {} started", this.channel);
/*
* We have a chance to see if there's a client session already
* registered for this client.
*/
final byte[] clientAddress = ((InetSocketAddress) this.channel.remoteAddress()).getAddress().getAddress();
final PCEPPeerRegistry sessionReg = this.negFactory.getSessionRegistry();
synchronized (lock) {
if (sessionReg.getSessionReference(clientAddress).isPresent()) {
final byte[] serverAddress = ((InetSocketAddress) this.channel.localAddress()).getAddress().getAddress();
if (COMPARATOR.compare(serverAddress, clientAddress) > 0) {
final Optional<SessionReference> sessionRefMaybe = sessionReg.removeSessionReference(clientAddress);
try {
if (sessionRefMaybe.isPresent()) {
sessionRefMaybe.get().close();
}
} catch (final Exception e) {
LOG.error("Unexpected failure to close old session", e);
}
} else {
negotiationFailed(new IllegalStateException("A conflicting session for address " + ((InetSocketAddress) this.channel.remoteAddress()).getAddress() + " found."));
return;
}
}
final Short sessionId = sessionReg.nextSession(clientAddress);
final AbstractPCEPSessionNegotiator n = this.negFactory.createNegotiator(this.nfd, this.promise, this.channel, sessionId);
sessionReg.putSessionReference(clientAddress, new SessionReference() {
@Override
public void close() throws ExecutionException {
try {
sessionReg.releaseSession(clientAddress, sessionId);
} finally {
PCEPSessionNegotiator.this.channel.close();
}
}
@Override
public Short getSessionId() {
return sessionId;
}
});
this.channel.closeFuture().addListener((ChannelFutureListener) future -> {
synchronized (lock) {
sessionReg.removeSessionReference(clientAddress);
}
});
LOG.info("Replacing bootstrap negotiator for channel {}", this.channel);
this.channel.pipeline().replace(this, "negotiator", n);
n.startNegotiation();
}
}
Aggregations