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

Commit

Permalink
Added times to CFDP transaction status
Browse files Browse the repository at this point in the history
  • Loading branch information
dariol83 committed Jun 14, 2023
1 parent 749d052 commit 2af75e7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public class CfdpTransactionStatus {
private final long progress;
private final long totalFileSize;
private final CfdpTransmissionMode transmissionMode;
private final Instant lastReceivedPduTime;
private final Instant lastSentPduTime;

public CfdpTransactionStatus(Instant time, ICfdpEntity managingEntity, long transactionId, long sourceEntityId, long destinationEntityId, // NOSONAR: long constructor
boolean isDestination, ConditionCode lastConditionCode, Long lastFaultEntity, CfdpTransactionState cfdpTransactionState,
long progress, long totalFileSize, CfdpTransmissionMode transmissionMode) {
long progress, long totalFileSize, CfdpTransmissionMode transmissionMode, Instant lastReceivedPduTime, Instant lastSentPduTime) {
this.time = time;
this.managingEntity = managingEntity;
this.transactionId = transactionId;
Expand All @@ -54,6 +56,8 @@ public CfdpTransactionStatus(Instant time, ICfdpEntity managingEntity, long tran
this.totalFileSize = totalFileSize;
this.lastFaultEntity = lastFaultEntity;
this.transmissionMode = transmissionMode;
this.lastReceivedPduTime = lastReceivedPduTime;
this.lastSentPduTime = lastSentPduTime;
}

public Instant getTime() {
Expand Down Expand Up @@ -104,6 +108,14 @@ public CfdpTransmissionMode getTransmissionMode() {
return transmissionMode;
}

public Instant getLastReceivedPduTime() {
return lastReceivedPduTime;
}

public Instant getLastSentPduTime() {
return lastSentPduTime;
}

@Override
public String toString() {
return "CfdpTransactionStatus{" +
Expand All @@ -119,6 +131,8 @@ public String toString() {
", progress=" + getProgress() +
", totalFileSize=" + getTotalFileSize() +
", transmissionMode=" + getTransmissionMode() +
", lastReceivedPduTime=" + getLastReceivedPduTime() +
", lastSentPduTime=" + getLastSentPduTime() +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public abstract class CfdpTransaction {
private final int entityIdLength;
private final RemoteEntityConfigurationInformation remoteDestination;
private final IUtLayer transmissionLayer;

private final List<CfdpPdu> pendingUtTransmissionPduList = new LinkedList<>();
private final ExecutorService confiner;

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

private Instant lastReceivedPduTime;
private Instant lastSentPduTime;

public CfdpTransaction(long transactionId, CfdpEntity cfdpEntity, long remoteEntityId) {
this.transactionId = transactionId;
Expand Down Expand Up @@ -317,7 +319,11 @@ public void activate() {
}

public void indication(CfdpPdu pdu) {
handle(() -> handleIndication(pdu));
handle(() -> {
// Remember the time of the received PDU
lastReceivedPduTime = Instant.now();
handleIndication(pdu);
});
}

public void cancel(ConditionCode conditionCode) {
Expand Down Expand Up @@ -538,7 +544,12 @@ protected void handleReport() {

protected CfdpTransactionStatus createStateObject() {
return new CfdpTransactionStatus(Instant.now(), getEntity(), getTransactionId(), getSourceEntityId(), getDestinationEntityId(), getDestinationEntityId() == getEntity().getMib().getLocalEntity().getLocalEntityId(),
getLastConditionCode(), getLastFaultEntityAsLong(), getCurrentState(), getProgress(), getTotalFileSize(), getTransmissionMode());
getLastConditionCode(), getLastFaultEntityAsLong(), getCurrentState(), getProgress(), getTotalFileSize(), getTransmissionMode(),
lastReceivedPduTime, lastSentPduTime);
}

protected void setLastSentPduTime(Instant lastSentPduTime) {
this.lastSentPduTime = lastSentPduTime;
}

protected abstract long getSourceEntityId();
Expand Down Expand Up @@ -572,4 +583,39 @@ protected CfdpTransactionStatus createStateObject() {
protected abstract CfdpTransmissionMode getTransmissionMode();

protected abstract void forwardPdu(CfdpPdu pdu) throws UtLayerException;

protected void internalForwardPdu(CfdpPdu pdu, long destinationId) throws UtLayerException {
// Add to the pending list
this.pendingUtTransmissionPduList.add(pdu);
// Send all PDUs you have to send, stop if you fail
if(LOG.isLoggable(Level.FINER)) {
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()));
}
while(!this.pendingUtTransmissionPduList.isEmpty()) {
CfdpPdu toSend = pendingUtTransmissionPduList.get(0);
try {
if(LOG.isLoggable(Level.FINEST)) {
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()));
}
getTransmissionLayer().request(toSend, destinationId);
if(LOG.isLoggable(Level.FINEST)) {
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()));
}
this.pendingUtTransmissionPduList.remove(0);
setLastSentPduTime(Instant.now());
} catch(UtLayerException e) {
if(LOG.isLoggable(Level.WARNING)) {
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);
}
throw e;
}
}
if(LOG.isLoggable(Level.FINER)) {
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()));
}
}

protected void clearTransmissionQueue() {
this.pendingUtTransmissionPduList.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ public class IncomingCfdpTransaction extends CfdpTransaction {
private static final byte[] FILE_PADDING_BUFFER = new byte[4096];

private final CfdpPdu initialPdu;

private final List<CfdpPdu> pendingUtTransmissionPduList = new LinkedList<>();

private MetadataPdu metadataPdu;

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

@Override
protected void forwardPdu(CfdpPdu pdu) throws UtLayerException {
// Add to the pending list
this.pendingUtTransmissionPduList.add(pdu);
// Send all PDUs you have to send, stop if you fail
if(LOG.isLoggable(Level.FINER)) {
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()));
}
while(!pendingUtTransmissionPduList.isEmpty()) {
CfdpPdu toSend = pendingUtTransmissionPduList.get(0);
try {
if(LOG.isLoggable(Level.FINEST)) {
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()));
}
getTransmissionLayer().request(toSend, this.initialPdu.getSourceEntityId());
this.pendingUtTransmissionPduList.remove(0);
} catch(UtLayerException e) {
if(LOG.isLoggable(Level.WARNING)) {
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);
}
throw e;
}
}
if(LOG.isLoggable(Level.FINER)) {
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()));
}
internalForwardPdu(pdu, this.initialPdu.getSourceEntityId());
}

/**
Expand Down Expand Up @@ -1442,7 +1416,7 @@ protected void handleTransactionInactivity() {
@Override
protected void handlePreDispose() {
// Cleanup resources and memory
this.pendingUtTransmissionPduList.clear();
clearTransmissionQueue();
if(this.fileReconstructionMap != null) {
this.fileReconstructionMap.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@
import eu.dariolucia.ccsds.cfdp.protocol.checksum.CfdpUnsupportedChecksumType;
import eu.dariolucia.ccsds.cfdp.protocol.checksum.ICfdpChecksum;
import eu.dariolucia.ccsds.cfdp.protocol.pdu.*;
import eu.dariolucia.ccsds.cfdp.protocol.pdu.tlvs.*;
import eu.dariolucia.ccsds.cfdp.protocol.pdu.tlvs.FaultHandlerOverrideTLV;
import eu.dariolucia.ccsds.cfdp.protocol.pdu.tlvs.FilestoreRequestTLV;
import eu.dariolucia.ccsds.cfdp.protocol.pdu.tlvs.FlowLabelTLV;
import eu.dariolucia.ccsds.cfdp.protocol.pdu.tlvs.MessageToUserTLV;
import eu.dariolucia.ccsds.cfdp.ut.UtLayerException;

import java.util.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

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

// Variables to handle file data transfer
private final List<CfdpPdu> sentPduList = new LinkedList<>();
private final List<CfdpPdu> pendingUtTransmissionPduList = new LinkedList<>();

private ICfdpFileSegmenter segmentProvider;
private ICfdpChecksum checksum;
private long totalFileSize;
Expand Down Expand Up @@ -629,7 +633,6 @@ private void handleStartTransaction() throws FaultDeclaredException {
* in chunks of equal, predefined size</li>
* </ol>
* From the point of view of the receiver, nothing changes.
*
* In order to free up the confiner thread, this method does not put all the chunks for transmission, but put in the
* execution queue only a task that:
* <ol>
Expand Down Expand Up @@ -759,33 +762,8 @@ private void forwardPdu(CfdpPdu pdu, boolean retransmission) throws UtLayerExcep
// Remember the PDU
this.sentPduList.add(pdu);
}
// Add to the pending list
this.pendingUtTransmissionPduList.add(pdu);
// Send all PDUs you have to send, stop if you fail
if(LOG.isLoggable(Level.FINER)) {
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()));
}
while(!this.pendingUtTransmissionPduList.isEmpty()) {
CfdpPdu toSend = pendingUtTransmissionPduList.get(0);
try {
if(LOG.isLoggable(Level.FINEST)) {
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()));
}
getTransmissionLayer().request(toSend, getRemoteDestination().getRemoteEntityId());
if(LOG.isLoggable(Level.FINEST)) {
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()));
}
this.pendingUtTransmissionPduList.remove(0);
} catch(UtLayerException e) {
if(LOG.isLoggable(Level.WARNING)) {
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);
}
throw e;
}
}
if(LOG.isLoggable(Level.FINER)) {
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()));
}
// Internal forward
internalForwardPdu(pdu, getRemoteDestination().getRemoteEntityId());
}

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

// 4.11.1.1.2 If sending in acknowledged mode,
Expand Down Expand Up @@ -988,7 +966,7 @@ private void handleTransactionFinishedCheckTimerElapsed() {
protected void handlePreDispose() {
// Cleanup resources and memory
this.sentPduList.clear();
this.pendingUtTransmissionPduList.clear();
clearTransmissionQueue();
this.txRunning = false;
if(this.segmentProvider != null) {
this.segmentProvider.close();
Expand Down

0 comments on commit 2af75e7

Please sign in to comment.