Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit 22a9ea1

Browse files
committed
Added times to CFDP transaction status
1 parent 40231c7 commit 22a9ea1

4 files changed

Lines changed: 78 additions & 66 deletions

File tree

eu.dariolucia.ccsds.cfdp/src/main/java/eu/dariolucia/ccsds/cfdp/entity/CfdpTransactionStatus.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ public class CfdpTransactionStatus {
3838
private final long progress;
3939
private final long totalFileSize;
4040
private final CfdpTransmissionMode transmissionMode;
41+
private final Instant lastReceivedPduTime;
42+
private final Instant lastSentPduTime;
4143

4244
public CfdpTransactionStatus(Instant time, ICfdpEntity managingEntity, long transactionId, long sourceEntityId, long destinationEntityId, // NOSONAR: long constructor
4345
boolean isDestination, ConditionCode lastConditionCode, Long lastFaultEntity, CfdpTransactionState cfdpTransactionState,
44-
long progress, long totalFileSize, CfdpTransmissionMode transmissionMode) {
46+
long progress, long totalFileSize, CfdpTransmissionMode transmissionMode, Instant lastReceivedPduTime, Instant lastSentPduTime) {
4547
this.time = time;
4648
this.managingEntity = managingEntity;
4749
this.transactionId = transactionId;
@@ -54,6 +56,8 @@ public CfdpTransactionStatus(Instant time, ICfdpEntity managingEntity, long tran
5456
this.totalFileSize = totalFileSize;
5557
this.lastFaultEntity = lastFaultEntity;
5658
this.transmissionMode = transmissionMode;
59+
this.lastReceivedPduTime = lastReceivedPduTime;
60+
this.lastSentPduTime = lastSentPduTime;
5761
}
5862

5963
public Instant getTime() {
@@ -104,6 +108,14 @@ public CfdpTransmissionMode getTransmissionMode() {
104108
return transmissionMode;
105109
}
106110

111+
public Instant getLastReceivedPduTime() {
112+
return lastReceivedPduTime;
113+
}
114+
115+
public Instant getLastSentPduTime() {
116+
return lastSentPduTime;
117+
}
118+
107119
@Override
108120
public String toString() {
109121
return "CfdpTransactionStatus{" +
@@ -119,6 +131,8 @@ public String toString() {
119131
", progress=" + getProgress() +
120132
", totalFileSize=" + getTotalFileSize() +
121133
", transmissionMode=" + getTransmissionMode() +
134+
", lastReceivedPduTime=" + getLastReceivedPduTime() +
135+
", lastSentPduTime=" + getLastSentPduTime() +
122136
'}';
123137
}
124138
}

eu.dariolucia.ccsds.cfdp/src/main/java/eu/dariolucia/ccsds/cfdp/entity/internal/CfdpTransaction.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public abstract class CfdpTransaction {
5252
private final int entityIdLength;
5353
private final RemoteEntityConfigurationInformation remoteDestination;
5454
private final IUtLayer transmissionLayer;
55-
55+
private final List<CfdpPdu> pendingUtTransmissionPduList = new LinkedList<>();
5656
private final ExecutorService confiner;
5757

5858
private final Map<ConditionCode, FaultHandlerStrategy.Action> faultHandlers = new EnumMap<>(ConditionCode.class);
@@ -77,6 +77,8 @@ public abstract class CfdpTransaction {
7777
private ConditionCode lastConditionCode = ConditionCode.CC_NOERROR;
7878
private EntityIdTLV lastFaultEntity = null;
7979

80+
private Instant lastReceivedPduTime;
81+
private Instant lastSentPduTime;
8082

8183
public CfdpTransaction(long transactionId, CfdpEntity cfdpEntity, long remoteEntityId) {
8284
this.transactionId = transactionId;
@@ -317,7 +319,11 @@ public void activate() {
317319
}
318320

319321
public void indication(CfdpPdu pdu) {
320-
handle(() -> handleIndication(pdu));
322+
handle(() -> {
323+
// Remember the time of the received PDU
324+
lastReceivedPduTime = Instant.now();
325+
handleIndication(pdu);
326+
});
321327
}
322328

323329
public void cancel(ConditionCode conditionCode) {
@@ -538,7 +544,12 @@ protected void handleReport() {
538544

539545
protected CfdpTransactionStatus createStateObject() {
540546
return new CfdpTransactionStatus(Instant.now(), getEntity(), getTransactionId(), getSourceEntityId(), getDestinationEntityId(), getDestinationEntityId() == getEntity().getMib().getLocalEntity().getLocalEntityId(),
541-
getLastConditionCode(), getLastFaultEntityAsLong(), getCurrentState(), getProgress(), getTotalFileSize(), getTransmissionMode());
547+
getLastConditionCode(), getLastFaultEntityAsLong(), getCurrentState(), getProgress(), getTotalFileSize(), getTransmissionMode(),
548+
lastReceivedPduTime, lastSentPduTime);
549+
}
550+
551+
protected void setLastSentPduTime(Instant lastSentPduTime) {
552+
this.lastSentPduTime = lastSentPduTime;
542553
}
543554

544555
protected abstract long getSourceEntityId();
@@ -572,4 +583,39 @@ protected CfdpTransactionStatus createStateObject() {
572583
protected abstract CfdpTransmissionMode getTransmissionMode();
573584

574585
protected abstract void forwardPdu(CfdpPdu pdu) throws UtLayerException;
586+
587+
protected void internalForwardPdu(CfdpPdu pdu, long destinationId) throws UtLayerException {
588+
// Add to the pending list
589+
this.pendingUtTransmissionPduList.add(pdu);
590+
// Send all PDUs you have to send, stop if you fail
591+
if(LOG.isLoggable(Level.FINER)) {
592+
LOG.log(Level.FINER, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: forwardPdu(), sending %d pending PDUs to UT layer %s", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), this.pendingUtTransmissionPduList.size(), getTransmissionLayer().getName()));
593+
}
594+
while(!this.pendingUtTransmissionPduList.isEmpty()) {
595+
CfdpPdu toSend = pendingUtTransmissionPduList.get(0);
596+
try {
597+
if(LOG.isLoggable(Level.FINEST)) {
598+
LOG.log(Level.FINEST, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: forwardPdu(), pending %d, sending PDU %s to UT layer %s", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), this.pendingUtTransmissionPduList.size(), toSend, getTransmissionLayer().getName()));
599+
}
600+
getTransmissionLayer().request(toSend, destinationId);
601+
if(LOG.isLoggable(Level.FINEST)) {
602+
LOG.log(Level.FINEST, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: forwardPdu(), PDU %s sent, pending %d - 1", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), toSend, this.pendingUtTransmissionPduList.size()));
603+
}
604+
this.pendingUtTransmissionPduList.remove(0);
605+
setLastSentPduTime(Instant.now());
606+
} catch(UtLayerException e) {
607+
if(LOG.isLoggable(Level.WARNING)) {
608+
LOG.log(Level.WARNING, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: forwardPdu(), PDU rejected by UT layer %s: %s", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), getTransmissionLayer().getName(), e.getMessage()), e);
609+
}
610+
throw e;
611+
}
612+
}
613+
if(LOG.isLoggable(Level.FINER)) {
614+
LOG.log(Level.FINER, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: pending PDUs sent to UT layer %s", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), getTransmissionLayer().getName()));
615+
}
616+
}
617+
618+
protected void clearTransmissionQueue() {
619+
this.pendingUtTransmissionPduList.clear();
620+
}
575621
}

eu.dariolucia.ccsds.cfdp/src/main/java/eu/dariolucia/ccsds/cfdp/entity/internal/IncomingCfdpTransaction.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ public class IncomingCfdpTransaction extends CfdpTransaction {
4747
private static final byte[] FILE_PADDING_BUFFER = new byte[4096];
4848

4949
private final CfdpPdu initialPdu;
50-
51-
private final List<CfdpPdu> pendingUtTransmissionPduList = new LinkedList<>();
52-
5350
private MetadataPdu metadataPdu;
5451

5552
private Map<Long, FileDataPduSummary> fileReconstructionMap; // optimisation: use a temporary random access file, use a stripped down version of the FileDataPdu, only offset, length
@@ -1177,30 +1174,7 @@ private <T extends CfdpPdu,K extends CfdpPduBuilder<T, K>> void setCommonPduValu
11771174

11781175
@Override
11791176
protected void forwardPdu(CfdpPdu pdu) throws UtLayerException {
1180-
// Add to the pending list
1181-
this.pendingUtTransmissionPduList.add(pdu);
1182-
// Send all PDUs you have to send, stop if you fail
1183-
if(LOG.isLoggable(Level.FINER)) {
1184-
LOG.log(Level.FINER, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: sending %d pending PDUs to UT layer %s", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), this.pendingUtTransmissionPduList.size(), getTransmissionLayer().getName()));
1185-
}
1186-
while(!pendingUtTransmissionPduList.isEmpty()) {
1187-
CfdpPdu toSend = pendingUtTransmissionPduList.get(0);
1188-
try {
1189-
if(LOG.isLoggable(Level.FINEST)) {
1190-
LOG.log(Level.FINEST, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: sending PDU %s to UT layer %s", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), toSend, getTransmissionLayer().getName()));
1191-
}
1192-
getTransmissionLayer().request(toSend, this.initialPdu.getSourceEntityId());
1193-
this.pendingUtTransmissionPduList.remove(0);
1194-
} catch(UtLayerException e) {
1195-
if(LOG.isLoggable(Level.WARNING)) {
1196-
LOG.log(Level.WARNING, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: PDU rejected by UT layer %s: %s", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), getTransmissionLayer().getName(), e.getMessage()), e);
1197-
}
1198-
throw e;
1199-
}
1200-
}
1201-
if(LOG.isLoggable(Level.FINER)) {
1202-
LOG.log(Level.FINER, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: pending PDUs sent to UT layer %s", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), getTransmissionLayer().getName()));
1203-
}
1177+
internalForwardPdu(pdu, this.initialPdu.getSourceEntityId());
12041178
}
12051179

12061180
/**
@@ -1442,7 +1416,7 @@ protected void handleTransactionInactivity() {
14421416
@Override
14431417
protected void handlePreDispose() {
14441418
// Cleanup resources and memory
1445-
this.pendingUtTransmissionPduList.clear();
1419+
clearTransmissionQueue();
14461420
if(this.fileReconstructionMap != null) {
14471421
this.fileReconstructionMap.clear();
14481422
}

eu.dariolucia.ccsds.cfdp/src/main/java/eu/dariolucia/ccsds/cfdp/entity/internal/OutgoingCfdpTransaction.java

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@
3131
import eu.dariolucia.ccsds.cfdp.protocol.checksum.CfdpUnsupportedChecksumType;
3232
import eu.dariolucia.ccsds.cfdp.protocol.checksum.ICfdpChecksum;
3333
import eu.dariolucia.ccsds.cfdp.protocol.pdu.*;
34-
import eu.dariolucia.ccsds.cfdp.protocol.pdu.tlvs.*;
34+
import eu.dariolucia.ccsds.cfdp.protocol.pdu.tlvs.FaultHandlerOverrideTLV;
35+
import eu.dariolucia.ccsds.cfdp.protocol.pdu.tlvs.FilestoreRequestTLV;
36+
import eu.dariolucia.ccsds.cfdp.protocol.pdu.tlvs.FlowLabelTLV;
37+
import eu.dariolucia.ccsds.cfdp.protocol.pdu.tlvs.MessageToUserTLV;
3538
import eu.dariolucia.ccsds.cfdp.ut.UtLayerException;
3639

37-
import java.util.*;
40+
import java.util.LinkedList;
41+
import java.util.List;
42+
import java.util.Map;
43+
import java.util.TimerTask;
3844
import java.util.logging.Level;
3945
import java.util.logging.Logger;
4046

@@ -46,8 +52,6 @@ public class OutgoingCfdpTransaction extends CfdpTransaction {
4652

4753
// Variables to handle file data transfer
4854
private final List<CfdpPdu> sentPduList = new LinkedList<>();
49-
private final List<CfdpPdu> pendingUtTransmissionPduList = new LinkedList<>();
50-
5155
private ICfdpFileSegmenter segmentProvider;
5256
private ICfdpChecksum checksum;
5357
private long totalFileSize;
@@ -629,7 +633,6 @@ private void handleStartTransaction() throws FaultDeclaredException {
629633
* in chunks of equal, predefined size</li>
630634
* </ol>
631635
* From the point of view of the receiver, nothing changes.
632-
*
633636
* In order to free up the confiner thread, this method does not put all the chunks for transmission, but put in the
634637
* execution queue only a task that:
635638
* <ol>
@@ -759,33 +762,8 @@ private void forwardPdu(CfdpPdu pdu, boolean retransmission) throws UtLayerExcep
759762
// Remember the PDU
760763
this.sentPduList.add(pdu);
761764
}
762-
// Add to the pending list
763-
this.pendingUtTransmissionPduList.add(pdu);
764-
// Send all PDUs you have to send, stop if you fail
765-
if(LOG.isLoggable(Level.FINER)) {
766-
LOG.log(Level.FINER, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: forwardPdu(), sending %d pending PDUs to UT layer %s", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), this.pendingUtTransmissionPduList.size(), getTransmissionLayer().getName()));
767-
}
768-
while(!this.pendingUtTransmissionPduList.isEmpty()) {
769-
CfdpPdu toSend = pendingUtTransmissionPduList.get(0);
770-
try {
771-
if(LOG.isLoggable(Level.FINEST)) {
772-
LOG.log(Level.FINEST, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: forwardPdu(), pending %d, sending PDU %s to UT layer %s", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), this.pendingUtTransmissionPduList.size(), toSend, getTransmissionLayer().getName()));
773-
}
774-
getTransmissionLayer().request(toSend, getRemoteDestination().getRemoteEntityId());
775-
if(LOG.isLoggable(Level.FINEST)) {
776-
LOG.log(Level.FINEST, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: forwardPdu(), PDU %s sent, pending %d - 1", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), toSend, this.pendingUtTransmissionPduList.size()));
777-
}
778-
this.pendingUtTransmissionPduList.remove(0);
779-
} catch(UtLayerException e) {
780-
if(LOG.isLoggable(Level.WARNING)) {
781-
LOG.log(Level.WARNING, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: forwardPdu(), PDU rejected by UT layer %s: %s", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), getTransmissionLayer().getName(), e.getMessage()), e);
782-
}
783-
throw e;
784-
}
785-
}
786-
if(LOG.isLoggable(Level.FINER)) {
787-
LOG.log(Level.FINER, String.format("CFDP Entity [%d]: [%d] with remote entity [%d]: pending PDUs sent to UT layer %s", getLocalEntityId(), getTransactionId(), getRemoteDestination().getRemoteEntityId(), getTransmissionLayer().getName()));
788-
}
765+
// Internal forward
766+
internalForwardPdu(pdu, getRemoteDestination().getRemoteEntityId());
789767
}
790768

791769
private MetadataPdu prepareMetadataPdu() {
@@ -922,7 +900,7 @@ private void handleNoticeOfCompletion(boolean completed) {
922900
// a) release all unreleased portions of the file retransmission buffer
923901
this.sentPduList.clear();
924902
// b) stop transmission of file segments and metadata.
925-
this.pendingUtTransmissionPduList.clear();
903+
clearTransmissionQueue();
926904
this.txRunning = false;
927905

928906
// 4.11.1.1.2 If sending in acknowledged mode,
@@ -988,7 +966,7 @@ private void handleTransactionFinishedCheckTimerElapsed() {
988966
protected void handlePreDispose() {
989967
// Cleanup resources and memory
990968
this.sentPduList.clear();
991-
this.pendingUtTransmissionPduList.clear();
969+
clearTransmissionQueue();
992970
this.txRunning = false;
993971
if(this.segmentProvider != null) {
994972
this.segmentProvider.close();

0 commit comments

Comments
 (0)