Search in sources :

Example 1 with PCEPCloseTermination

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);
}
Also used : PCEPCloseTermination(org.opendaylight.protocol.pcep.PCEPCloseTermination) Tlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.object.lsp.Tlvs) MsgBuilderUtil.createLspTlvs(org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLspTlvs) Pcrpt(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.Pcrpt) LspBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.object.LspBuilder) Requests(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev171025.pcinitiate.message.pcinitiate.message.Requests) Pcinitiate(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev171025.Pcinitiate) Test(org.junit.Test)

Example 2 with PCEPCloseTermination

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());
}
Also used : PCEPCloseTermination(org.opendaylight.protocol.pcep.PCEPCloseTermination) Node1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1) Node1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1Builder) PathComputationClient(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.pcep.client.attributes.PathComputationClient) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) PathComputationClientBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.pcep.client.attributes.PathComputationClientBuilder) InetAddress(java.net.InetAddress)

Example 3 with PCEPCloseTermination

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);
    }
}
Also used : PCEPCloseTermination(org.opendaylight.protocol.pcep.PCEPCloseTermination) OpenMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage) PcerrMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcerrMessage) CloseMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage) KeepaliveMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage)

Example 4 with PCEPCloseTermination

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));
}
Also used : PCEPCloseTermination(org.opendaylight.protocol.pcep.PCEPCloseTermination)

Aggregations

PCEPCloseTermination (org.opendaylight.protocol.pcep.PCEPCloseTermination)4 InetAddress (java.net.InetAddress)1 Test (org.junit.Test)1 MsgBuilderUtil.createLspTlvs (org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLspTlvs)1 Pcinitiate (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev171025.Pcinitiate)1 Requests (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev171025.pcinitiate.message.pcinitiate.message.Requests)1 Pcrpt (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.Pcrpt)1 LspBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.object.LspBuilder)1 Tlvs (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.object.lsp.Tlvs)1 CloseMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage)1 KeepaliveMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage)1 OpenMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage)1 PcerrMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcerrMessage)1 Node1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1)1 Node1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1Builder)1 PathComputationClient (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.pcep.client.attributes.PathComputationClient)1 PathComputationClientBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.pcep.client.attributes.PathComputationClientBuilder)1 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)1