use of org.opendaylight.protocol.pcep.PCEPCloseTermination in project bgpcep by opendaylight.
the class Stateful07TopologySessionListenerTest method testOnSessionTermination.
@Test
public void testOnSessionTermination() throws Exception {
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;
});
assertFalse(this.session.isClosed());
// node should be removed after termination
this.listener.onSessionTerminated(this.session, new PCEPCloseTermination(TerminationReason.UNKNOWN));
assertTrue(this.session.isClosed());
checkNotPresentOperational(getDataBroker(), this.pathComputationClientIId);
}
use of org.opendaylight.protocol.pcep.PCEPCloseTermination in project bgpcep by opendaylight.
the class AbstractTopologySessionListener method onSessionUp.
@Override
public final synchronized void onSessionUp(final PCEPSession psession) {
/*
* The session went up. Look up the router in Inventory model,
* create it if it is not there (marking that fact for later
* deletion), and mark it as synchronizing. Also create it in
* the topology model, with empty LSP list.
*/
final InetAddress peerAddress = psession.getRemoteAddress();
this.syncOptimization = new SyncOptimization(psession);
final TopologyNodeState state = this.serverSessionManager.takeNodeState(peerAddress, this, isLspDbRetreived());
// takeNodeState(..) may fail when the server session manager is being restarted due to configuration change
if (state == null) {
LOG.error("Unable to fetch topology node state for PCEP session. Closing session {}", psession);
psession.close(TerminationReason.UNKNOWN);
this.onSessionTerminated(psession, new PCEPCloseTermination(TerminationReason.UNKNOWN));
return;
}
if (this.session != null || this.nodeState != null) {
LOG.error("PCEP session is already up with {}. Closing session {}", psession.getRemoteAddress(), psession);
psession.close(TerminationReason.UNKNOWN);
this.onSessionTerminated(psession, new PCEPCloseTermination(TerminationReason.UNKNOWN));
return;
}
this.session = psession;
this.nodeState = state;
this.serverSessionManager.bind(this.nodeState.getNodeId(), this.listenerState);
LOG.trace("Peer {} resolved to topology node {}", peerAddress, state.getNodeId());
// Our augmentation in the topology node
final PathComputationClientBuilder pccBuilder = new PathComputationClientBuilder();
onSessionUp(psession, pccBuilder);
this.synced.set(isSynchronized());
pccBuilder.setIpAddress(IpAddressBuilder.getDefaultInstance(peerAddress.getHostAddress()));
final InstanceIdentifier<Node1> topologyAugment = state.getNodeId().augmentation(Node1.class);
this.pccIdentifier = topologyAugment.child(PathComputationClient.class);
final Node initialNodeState = state.getInitialNodeState();
final boolean isNodePresent = isLspDbRetreived() && initialNodeState != null;
if (isNodePresent) {
loadLspData(initialNodeState, this.lspData, this.lsps, isIncrementalSynchro());
pccBuilder.setReportedLsp(initialNodeState.getAugmentation(Node1.class).getPathComputationClient().getReportedLsp());
}
state.storeNode(topologyAugment, new Node1Builder().setPathComputationClient(pccBuilder.build()).build(), this.session);
this.listenerState.init(psession);
LOG.info("Session with {} attached to topology node {}", psession.getRemoteAddress(), state.getNodeId());
}
use of org.opendaylight.protocol.pcep.PCEPCloseTermination in project bgpcep by opendaylight.
the class PCEPSessionImpl method handleMessage.
/**
* Handles incoming message. If the session is up, it notifies the user. The user is notified about every message
* except KeepAlive.
*
* @param msg incoming message
*/
public synchronized void handleMessage(final Message msg) {
if (this.closed.get()) {
LOG.debug("PCEP Session {} is already closed, skip handling incoming message {}", this, msg);
return;
}
// Update last reception time
this.lastMessageReceivedAt = TICKER.read();
this.sessionState.updateLastReceivedMsg();
if (!(msg instanceof KeepaliveMessage)) {
LOG.debug("PCEP message {} received.", msg);
}
// Internal message handling. The user does not see these messages
if (msg instanceof KeepaliveMessage) {
// Do nothing, the timer has been already reset
} else if (msg instanceof OpenMessage) {
this.sendErrorMessage(PCEPErrors.ATTEMPT_2ND_SESSION);
} else if (msg instanceof CloseMessage) {
/*
* Session is up, we are reporting all messages to user. One notable
* exception is CLOSE message, which needs to be converted into a
* session DOWN event.
*/
close();
this.listener.onSessionTerminated(this, new PCEPCloseTermination(TerminationReason.forValue(((CloseMessage) msg).getCCloseMessage().getCClose().getReason())));
} else {
// This message needs to be handled by the user
if (msg instanceof PcerrMessage) {
this.sessionState.setLastReceivedError(msg);
}
this.listener.onMessage(this, msg);
}
}
use of org.opendaylight.protocol.pcep.PCEPCloseTermination in project bgpcep by opendaylight.
the class PCEPSessionImpl method terminate.
private synchronized void terminate(final TerminationReason reason) {
if (this.closed.get()) {
LOG.debug("Session {} is already closed.", this);
return;
}
close(reason);
this.listener.onSessionTerminated(this, new PCEPCloseTermination(reason));
}
Aggregations