import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
import org.opendaylight.protocol.pcep.PCEPTerminationReason;
import org.opendaylight.protocol.pcep.TerminationReason;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.LspObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Path1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.Lsp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.MessageHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
}
@Override
- public Integer getDelegatedLspsCount() {
- return this.lsps.size();
+ public synchronized Integer getDelegatedLspsCount() {
+ return Math.toIntExact(this.lspData.values().stream()
+ .map(ReportedLsp::getPath).filter(Objects::nonNull).filter(pathList -> !pathList.isEmpty())
+ // pick the first path, as delegate status should be same in each path
+ .map(pathList -> pathList.get(0))
+ .map(path -> path.getAugmentation(Path1.class)).filter(Objects::nonNull)
+ .map(LspObject::getLsp).filter(Objects::nonNull)
+ .filter(Lsp::isDelegate)
+ .count());
}
@Override
});
}
+ @Test
+ public void testDelegatedLspsCountWithDelegation() throws Exception {
+ this.listener.onSessionUp(this.session);
+ this.topologyRpcs.addLsp(createAddLspInput());
+ assertEquals(1, this.receivedMsgs.size());
+ assertTrue(this.receivedMsgs.get(0) instanceof Pcinitiate);
+ 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());
+ //delegate set to true
+ final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs)
+ .setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active)
+ .setDelegate(true).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(
+ req.getEro().getSubobject()));
+ this.listener.onMessage(this.session, pcRpt);
+ checkEquals(()->assertEquals(1, this.listener.getDelegatedLspsCount().intValue()));
+ }
+
+ @Test
+ public void testDelegatedLspsCountWithoutDelegation() throws Exception {
+ this.listener.onSessionUp(this.session);
+ this.topologyRpcs.addLsp(createAddLspInput());
+ assertEquals(1, this.receivedMsgs.size());
+ assertTrue(this.receivedMsgs.get(0) instanceof Pcinitiate);
+ 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());
+ //delegate set to false
+ final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs)
+ .setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active)
+ .setDelegate(false).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(
+ req.getEro().getSubobject()));
+ this.listener.onMessage(this.session, pcRpt);
+ checkEquals(()->assertEquals(0, this.listener.getDelegatedLspsCount().intValue()));
+ }
+
@Override
protected Open getLocalPref() {
return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class,