Search in sources :

Example 41 with 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 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;
    });
}
Also used : AddLspOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.AddLspOutput) 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) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) 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 42 with 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 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);
}
Also used : 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) Close(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close) 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 43 with 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);
}
Also used : PCEPSession(org.opendaylight.protocol.pcep.PCEPSession) Executor(java.util.concurrent.Executor) InstructionStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionStatus) Details(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.status.changed.Details) RemoveLspInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.RemoveLspInput) EnsureLspOperationalInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.EnsureLspOperationalInput) AddLspInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.AddLspInput) TriggerSyncInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.TriggerSyncInput) UpdateLspInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.UpdateLspInput) SubmitInstructionInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.SubmitInstructionInput) Before(org.junit.Before)

Example 44 with 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 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();
}
Also used : CloseMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage) Pcerr(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr) ErrorObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject) Test(org.junit.Test)

Example 45 with 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();
    }
}
Also used : UnsignedBytes(com.google.common.primitives.UnsignedBytes) Logger(org.slf4j.Logger) Promise(io.netty.util.concurrent.Promise) LoggerFactory(org.slf4j.LoggerFactory) Message(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) ExecutionException(java.util.concurrent.ExecutionException) PCEPSessionNegotiatorFactoryDependencies(org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactoryDependencies) SessionReference(org.opendaylight.protocol.pcep.impl.PCEPPeerRegistry.SessionReference) ChannelFutureListener(io.netty.channel.ChannelFutureListener) Optional(java.util.Optional) Comparator(java.util.Comparator) InetSocketAddress(java.net.InetSocketAddress) SessionReference(org.opendaylight.protocol.pcep.impl.PCEPPeerRegistry.SessionReference) ExecutionException(java.util.concurrent.ExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Test (org.junit.Test)23 InetSocketAddress (java.net.InetSocketAddress)12 Before (org.junit.Before)11 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)9 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)8 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)8 TimeUnit (java.util.concurrent.TimeUnit)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)7 Optional (com.google.common.base.Optional)6 ChannelFuture (io.netty.channel.ChannelFuture)6 ChannelHandler (io.netty.channel.ChannelHandler)6 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)6 Notification (org.opendaylight.yangtools.yang.binding.Notification)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 Channel (io.netty.channel.Channel)4 List (java.util.List)4 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4