use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp in project bgpcep by opendaylight.
the class Stateful07TopologySessionListener method redelegate.
private ListenableFuture<OperationResult> redelegate(final Lsp reportedLsp, final Srp srp, final Lsp lsp, final UpdateLspArgs input) {
// the D bit that was reported decides the type of PCE message sent
requireNonNull(reportedLsp.isDelegate());
final Message msg;
if (reportedLsp.isDelegate()) {
// we already have delegation, send update
final UpdatesBuilder rb = new UpdatesBuilder();
rb.setSrp(srp);
rb.setLsp(lsp);
final PathBuilder pb = new PathBuilder();
pb.fieldsFrom(input.getArguments());
rb.setPath(pb.build());
final PcupdMessageBuilder ub = new PcupdMessageBuilder(MESSAGE_HEADER);
ub.setUpdates(Collections.singletonList(rb.build()));
msg = new PcupdBuilder().setPcupdMessage(ub.build()).build();
} else {
final Lsp1 lspCreateFlag = reportedLsp.getAugmentation(Lsp1.class);
// we only retake delegation for PCE initiated tunnels
if (lspCreateFlag != null && !lspCreateFlag.isCreate()) {
LOG.warn("Unable to retake delegation of PCC-initiated tunnel: {}", reportedLsp);
return OperationResults.createUnsent(PCEPErrors.UPDATE_REQ_FOR_NON_LSP).future();
}
// we want to revoke delegation, different type of message
// is sent because of specification by Siva
// this message is also sent, when input delegate bit is set to 0
// generating an error in PCC
final List<Requests> reqs = new ArrayList<>();
reqs.add(new RequestsBuilder().setSrp(srp).setLsp(lsp).build());
final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder();
ib.setRequests(reqs);
msg = new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build();
}
return sendMessage(msg, srp.getOperationId(), input.getArguments().getMetadata());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp in project bgpcep by opendaylight.
the class Stateful07TopologySessionListener method removeLsp.
@Override
public synchronized ListenableFuture<OperationResult> removeLsp(@Nonnull final RemoveLspArgs input) {
Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null, MISSING_XML_TAG);
LOG.trace("RemoveLspArgs {}", input);
// Make sure the LSP exists, we need it for PLSP-ID
final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
if (f == null) {
return OperationResults.createUnsent(PCEPErrors.LSP_INTERNAL_ERROR).future();
}
return Futures.transformAsync(f, rep -> {
final Lsp reportedLsp = validateReportedLsp(rep, input);
if (reportedLsp == null) {
return OperationResults.createUnsent(PCEPErrors.UNKNOWN_PLSP_ID).future();
}
final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(MESSAGE_HEADER);
final Requests rb = buildRequest(rep, reportedLsp);
ib.setRequests(Collections.singletonList(rb));
return sendMessage(new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build(), rb.getSrp().getOperationId(), null);
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp in project bgpcep by opendaylight.
the class NodeChangedListener method updateTransaction.
private void updateTransaction(final ReadWriteTransaction trans, final Set<InstanceIdentifier<ReportedLsp>> lsps, final Map<InstanceIdentifier<?>, ? extends DataObject> old, final Map<InstanceIdentifier<?>, DataObject> updated, final Map<InstanceIdentifier<?>, DataObject> created) {
for (final InstanceIdentifier<ReportedLsp> i : lsps) {
final ReportedLsp oldValue = (ReportedLsp) old.get(i);
ReportedLsp newValue = (ReportedLsp) updated.get(i);
if (newValue == null) {
newValue = (ReportedLsp) created.get(i);
}
LOG.debug("Updating lsp {} value {} -> {}", i, oldValue, newValue);
if (oldValue != null) {
try {
remove(trans, i, oldValue);
} catch (final ExecutionException | InterruptedException e) {
LOG.warn("Failed to remove LSP {}", i, e);
}
}
if (newValue != null) {
try {
create(trans, i, newValue);
} catch (final ExecutionException | InterruptedException e) {
LOG.warn("Failed to add LSP {}", i, e);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp in project bgpcep by opendaylight.
the class PCEPTopologySessionListenerTest method testPCEPTopologySessionListener.
@Test
public void testPCEPTopologySessionListener() throws Exception {
listener.onSessionUp(session);
final PcepSessionState listenerState = listener.listenerState;
assertEquals(testAddress, listenerState.getPeerPref().getIpAddress());
final LocalPref state = listener.listenerState.getLocalPref();
assertNotNull(state);
assertEquals(DEAD_TIMER, state.getDeadtimer().shortValue());
assertEquals(KEEP_ALIVE, state.getKeepalive().shortValue());
assertEquals(0, state.getSessionId().intValue());
assertEquals(testAddress, state.getIpAddress());
final PeerPref peerState = listenerState.getPeerPref();
assertEquals(DEAD_TIMER, peerState.getDeadtimer().shortValue());
assertEquals(KEEP_ALIVE, peerState.getKeepalive().shortValue());
assertEquals(0, peerState.getSessionId().intValue());
assertEquals(testAddress, peerState.getIpAddress());
// add-lsp
topologyRpcs.addLsp(createAddLspInput());
assertEquals(1, receivedMsgs.size());
assertTrue(receivedMsgs.get(0) instanceof Pcinitiate);
final Pcinitiate pcinitiate = (Pcinitiate) receivedMsgs.get(0);
final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
final Uint32 srpId = req.getSrp().getOperationId().getValue();
final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true, testAddress, testAddress, testAddress, Optional.empty());
final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setPlspId(new PlspId(Uint32.ONE)).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(Uint32.ZERO)), null);
listener.onMessage(session, esm);
readDataOperational(getDataBroker(), pathComputationClientIId, pcc -> {
assertEquals(testAddress, pcc.getIpAddress().getIpv4AddressNoZone().getValue());
// reported lsp so far empty, has not received response (PcRpt) yet
assertNull(pcc.getReportedLsp());
return pcc;
});
listener.onMessage(session, pcRpt);
// check created lsp
readDataOperational(getDataBroker(), pathComputationClientIId, pcc -> {
assertEquals(1, pcc.nonnullReportedLsp().size());
final ReportedLsp reportedLsp = pcc.getReportedLsp().values().iterator().next();
assertEquals(tunnelName, reportedLsp.getName());
assertEquals(1, reportedLsp.nonnullPath().size());
final Path path = reportedLsp.nonnullPath().values().iterator().next();
assertEquals(1, path.getEro().getSubobject().size());
assertEquals(eroIpPrefix, getLastEroIpPrefix(path.getEro()));
return pcc;
});
// check stats
checkEquals(() -> assertEquals(1, listenerState.getDelegatedLspsCount().intValue()));
checkEquals(() -> assertTrue(listener.isSessionSynchronized()));
checkEquals(() -> assertTrue(listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getLastReceivedRptMsgTimestamp().toJava() > 0));
checkEquals(() -> assertEquals(2, listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getReceivedRptMsgCount().intValue()));
checkEquals(() -> assertEquals(1, listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getSentInitMsgCount().intValue()));
checkEquals(() -> assertEquals(0, listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getSentUpdMsgCount().intValue()));
// update-lsp
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.update.lsp.args.ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.update.lsp.args.ArgumentsBuilder();
updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix, dstIpPrefix)));
updArgsBuilder.addAugmentation(new Arguments3Builder().setLsp(new LspBuilder().setDelegate(TRUE).setAdministrative(FALSE).build()).build());
final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(tunnelName).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
topologyRpcs.updateLsp(update);
assertEquals(2, receivedMsgs.size());
assertTrue(receivedMsgs.get(1) instanceof Pcupd);
final Pcupd updateMsg = (Pcupd) receivedMsgs.get(1);
final Updates upd = updateMsg.getPcupdMessage().getUpdates().get(0);
final Uint32 srpId2 = upd.getSrp().getOperationId().getValue();
final Tlvs tlvs2 = createLspTlvs(upd.getLsp().getPlspId().getValue(), false, newDestinationAddress, testAddress, testAddress, Optional.empty());
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()));
listener.onMessage(session, pcRpt2);
// check updated lsp
readDataOperational(getDataBroker(), pathComputationClientIId, pcc -> {
assertEquals(1, pcc.getReportedLsp().size());
final ReportedLsp reportedLsp = pcc.getReportedLsp().values().iterator().next();
assertEquals(tunnelName, reportedLsp.getName());
assertEquals(1, reportedLsp.getPath().size());
final Path path = reportedLsp.getPath().values().iterator().next();
assertEquals(2, path.getEro().getSubobject().size());
assertEquals(dstIpPrefix, getLastEroIpPrefix(path.getEro()));
assertEquals(1, listenerState.getDelegatedLspsCount().intValue());
assertTrue(listener.isSessionSynchronized());
final StatefulMessagesStatsAug statefulstate = listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class);
assertTrue(statefulstate.getLastReceivedRptMsgTimestamp().toJava() > 0);
assertEquals(3, statefulstate.getReceivedRptMsgCount().intValue());
assertEquals(1, statefulstate.getSentInitMsgCount().intValue());
assertEquals(1, statefulstate.getSentUpdMsgCount().intValue());
final ReplyTime replyTime = listenerState.getMessages().getReplyTime();
assertTrue(replyTime.getAverageTime().toJava() > 0);
assertTrue(replyTime.getMaxTime().toJava() > 0);
final StatefulCapabilitiesStatsAug statefulCapabilities = listenerState.getPeerCapabilities().augmentation(StatefulCapabilitiesStatsAug.class);
assertFalse(statefulCapabilities.getActive());
assertTrue(statefulCapabilities.getInstantiation());
assertTrue(statefulCapabilities.getStateful());
return pcc;
});
// ensure-operational
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.ensure.lsp.operational.args.ArgumentsBuilder ensureArgs = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.ensure.lsp.operational.args.ArgumentsBuilder();
ensureArgs.addAugmentation(new Arguments1Builder().setOperational(OperationalStatus.Active).build());
final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build()).setName(tunnelName).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
final OperationResult result = topologyRpcs.ensureLspOperational(ensure).get().getResult();
// check result
assertNull(result.getFailure());
// remove-lsp
final RemoveLspInput remove = new RemoveLspInputBuilder().setName(tunnelName).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
topologyRpcs.removeLsp(remove);
assertEquals(3, receivedMsgs.size());
assertTrue(receivedMsgs.get(2) instanceof Pcinitiate);
final Pcinitiate pcinitiate2 = (Pcinitiate) receivedMsgs.get(2);
final Requests req2 = pcinitiate2.getPcinitiateMessage().getRequests().get(0);
final Uint32 srpId3 = req2.getSrp().getOperationId().getValue();
final Tlvs tlvs3 = createLspTlvs(req2.getLsp().getPlspId().getValue(), false, testAddress, testAddress, testAddress, Optional.empty());
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()));
listener.onMessage(session, pcRpt3);
// check if lsp was removed
readDataOperational(getDataBroker(), pathComputationClientIId, pcc -> {
assertNull(pcc.getReportedLsp());
return pcc;
});
// check stats
checkEquals(() -> assertEquals(0, listenerState.getDelegatedLspsCount().intValue()));
checkEquals(() -> assertTrue(listener.isSessionSynchronized()));
checkEquals(() -> assertTrue(listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getLastReceivedRptMsgTimestamp().toJava() > 0));
checkEquals(() -> assertEquals(4, listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getReceivedRptMsgCount().intValue()));
checkEquals(() -> assertEquals(2, listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getSentInitMsgCount().intValue()));
checkEquals(() -> assertEquals(1, listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getSentUpdMsgCount().intValue()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp in project bgpcep by opendaylight.
the class TopologyProviderTest method testOnReportMessage.
@Test
public void testOnReportMessage() throws ExecutionException, InterruptedException {
listener.onSessionUp(session);
Pcrpt pcRptMsg = createSrPcRpt("1.1.1.1", "sr-path1", Uint32.ONE, true);
listener.onMessage(session, pcRptMsg);
readDataOperational(getDataBroker(), pathComputationClientIId, pcc -> {
// check sr-path
final Map<ReportedLspKey, ReportedLsp> reportedLsps = pcc.getReportedLsp();
assertNotNull(reportedLsps);
assertEquals(1, reportedLsps.size());
final ReportedLsp lsp = reportedLsps.values().iterator().next();
assertEquals("sr-path1", lsp.getName());
final Map<PathKey, Path> paths = lsp.getPath();
assertNotNull(paths);
final Path path = paths.values().iterator().next();
assertEquals(1, path.augmentation(Path1.class).getPathSetupType().getPst().intValue());
final List<Subobject> subobjects = path.getEro().nonnullSubobject();
assertEquals(1, subobjects.size());
assertEquals("1.1.1.1", ((IpNodeId) ((SrEroType) subobjects.get(0).getSubobjectType()).getNai()).getIpAddress().getIpv4AddressNoZone().getValue());
return pcc;
});
pcRptMsg = createSrPcRpt("1.1.1.3", "sr-path2", Uint32.TWO, false);
listener.onMessage(session, pcRptMsg);
readDataOperational(getDataBroker(), pathComputationClientIId, pcc -> {
// check second lsp sr-path
final Map<ReportedLspKey, ReportedLsp> reportedLsps = pcc.getReportedLsp();
assertNotNull(reportedLsps);
assertEquals(2, reportedLsps.size());
return pcc;
});
pcRptMsg = createSrPcRpt("1.1.1.2", "sr-path1", Uint32.ONE, true);
listener.onMessage(session, pcRptMsg);
readDataOperational(getDataBroker(), pathComputationClientIId, pcc -> {
// check updated sr-path
final Map<ReportedLspKey, ReportedLsp> reportedLsps = pcc.getReportedLsp();
assertNotNull(reportedLsps);
assertEquals(2, reportedLsps.size());
for (final ReportedLsp rlsp : reportedLsps.values()) {
if (rlsp.getName().equals("sr-path1")) {
final List<Subobject> subobjects = rlsp.nonnullPath().values().iterator().next().getEro().nonnullSubobject();
assertEquals(1, subobjects.size());
assertEquals("1.1.1.2", ((IpNodeId) ((SrEroType) subobjects.get(0).getSubobjectType()).getNai()).getIpAddress().getIpv4AddressNoZone().getValue());
}
}
return pcc;
});
}
Aggregations