From 60b26770efd6304ab999feaa2fd9056b19b40c9d Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun <78055940+byeong-gil@users.noreply.github.com> Date: Fri, 19 May 2023 17:16:50 +0900 Subject: [PATCH 1/6] Update lingua-franca-ref.txt --- lingua-franca-ref.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lingua-franca-ref.txt b/lingua-franca-ref.txt index 1f7391f92..a1caa4e59 100644 --- a/lingua-franca-ref.txt +++ b/lingua-franca-ref.txt @@ -1 +1 @@ -master +fix-ts-federated-tests From d44255dcd27407033fbb53956cde7fa02457b89d Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Sun, 21 May 2023 16:13:38 +0900 Subject: [PATCH 2/6] Prevent advancing a federate's tag above the tagBarrier of null --- src/core/federation.ts | 45 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/core/federation.ts b/src/core/federation.ts index 32f7fdda8..4bc7c40ea 100644 --- a/src/core/federation.ts +++ b/src/core/federation.ts @@ -915,12 +915,12 @@ enum StopRequestState { * including the current state and the tag associated with the stop requested or stop granted. */ class StopRequestInfo { - constructor(state: StopRequestState, tag: Tag | null) { + constructor(state: StopRequestState, tag: Tag) { this.state = state; this.tag = tag; } readonly state: StopRequestState; - readonly tag: Tag | null; + readonly tag: Tag; } /** @@ -950,15 +950,15 @@ export class FederatedApp extends App { * Stop request-related information * including the current state and the tag associated with the stop requested or stop granted. */ - private stopRequestInfo: StopRequestInfo = new StopRequestInfo(StopRequestState.NOT_SENT, null); + private stopRequestInfo: StopRequestInfo = new StopRequestInfo(StopRequestState.NOT_SENT, new Tag(TimeValue.FOREVER(), 0)); /** * The largest time advance grant received so far from the RTI, - * or null if no time advance grant has been received yet. + * or NEVER if no time advance grant has been received yet. * An RTI synchronized Federate cannot advance its logical time * beyond this value. */ - private greatestTimeAdvanceGrant: Tag | null = null; + private greatestTimeAdvanceGrant: Tag = new Tag(TimeValue.NEVER(), 0); private upstreamFedIDs: number[] = []; private upstreamFedDelays: TimeValue[] = []; @@ -1031,7 +1031,7 @@ export class FederatedApp extends App { * @param nextEvent */ protected _canProceed(nextEvent: TaggedEvent) { - let tagBarrier = null; + let tagBarrier = new Tag(TimeValue.NEVER()); // Set tag barrier using the tag when stop is requested but not granted yet. // Otherwise, set the tagBarrier using the greated TAG. if (this.stopRequestInfo.state === StopRequestState.SENT) { @@ -1040,24 +1040,22 @@ export class FederatedApp extends App { tagBarrier = this._getGreatestTimeAdvanceGrant(); } - if (tagBarrier !== null) { - if (tagBarrier.isSmallerThan(nextEvent.tag)) { - if (this.minDelayFromPhysicalActionToFederateOutput !== null && - this.downstreamFedIDs.length > 0) { - let physicalTime = getCurrentPhysicalTime() - if (physicalTime.add(this.minDelayFromPhysicalActionToFederateOutput).isEarlierThan(nextEvent.tag.time)) { - Log.debug(this, () => "Adding dummy event for time: " + physicalTime); - this._addDummyEvent(new Tag(physicalTime)); - return false; - } - } - this.sendRTINextEventTag(nextEvent.tag); - Log.debug(this, () => "The greatest time advance grant " + - "received from the RTI is less than the timestamp of the " + - "next event on the event queue"); - Log.global.debug("Exiting _next."); - return false; + if (tagBarrier.isSmallerThan(nextEvent.tag)) { + if (this.minDelayFromPhysicalActionToFederateOutput !== null && + this.downstreamFedIDs.length > 0) { + let physicalTime = getCurrentPhysicalTime() + if (physicalTime.add(this.minDelayFromPhysicalActionToFederateOutput).isEarlierThan(nextEvent.tag.time)) { + Log.debug(this, () => "Adding dummy event for time: " + physicalTime); + this._addDummyEvent(new Tag(physicalTime)); + return false; + } } + this.sendRTINextEventTag(nextEvent.tag); + Log.debug(this, () => "The greatest time advance grant " + + "received from the RTI is less than the timestamp of the " + + "next event on the event queue"); + Log.global.debug("Exiting _next."); + return false; } return true; } @@ -1112,6 +1110,7 @@ export class FederatedApp extends App { */ constructor (config: FederateConfig, success?: () => void, failure?: () => void) { + console.log(config.keepAlive); super(config.executionTimeout, config.keepAlive, config.fast, // Let super class (App) call FederateApp's _shutdown in success and failure. () => { From 0b87f5c435f3475808819e75a2a6b4c2d7df6aaf Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun <78055940+byeong-gil@users.noreply.github.com> Date: Sun, 21 May 2023 17:04:21 +0900 Subject: [PATCH 3/6] Update ci.yml --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18afadf22..b2a39b2c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,7 @@ jobs: repository: lf-lang/lingua-franca ref: ${{ env.lingua-franca-ref }} fetch-depth: 0 + submodules: true - name: Prepare build environment uses: ./.github/actions/prepare-build-env - name: Setup Node.js environment @@ -41,6 +42,9 @@ jobs: node-version: 18 - name: Install pnpm run: npm i -g pnpm + - name: Install RTI + uses: ./.github/actions/install-rti + if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }} - name: Perform Lingua Franca TypeScript tests run: | ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#${{ github.head_ref || github.ref_name }}" From 6bc00031a7d7d1fa724d37b4fae527a1d288b340 Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Sun, 21 May 2023 17:18:26 +0900 Subject: [PATCH 4/6] Let a federate which doesn't have any upstream federates can proceed its tag itself --- src/core/federation.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/core/federation.ts b/src/core/federation.ts index 4bc7c40ea..e3bcf793d 100644 --- a/src/core/federation.ts +++ b/src/core/federation.ts @@ -1040,22 +1040,24 @@ export class FederatedApp extends App { tagBarrier = this._getGreatestTimeAdvanceGrant(); } - if (tagBarrier.isSmallerThan(nextEvent.tag)) { - if (this.minDelayFromPhysicalActionToFederateOutput !== null && - this.downstreamFedIDs.length > 0) { - let physicalTime = getCurrentPhysicalTime() - if (physicalTime.add(this.minDelayFromPhysicalActionToFederateOutput).isEarlierThan(nextEvent.tag.time)) { - Log.debug(this, () => "Adding dummy event for time: " + physicalTime); - this._addDummyEvent(new Tag(physicalTime)); - return false; - } + if (this.upstreamFedIDs.length !== 0) { + if (tagBarrier.isSmallerThan(nextEvent.tag)) { + if (this.minDelayFromPhysicalActionToFederateOutput !== null && + this.downstreamFedIDs.length > 0) { + let physicalTime = getCurrentPhysicalTime() + if (physicalTime.add(this.minDelayFromPhysicalActionToFederateOutput).isEarlierThan(nextEvent.tag.time)) { + Log.debug(this, () => "Adding dummy event for time: " + physicalTime); + this._addDummyEvent(new Tag(physicalTime)); + return false; + } + } + this.sendRTINextEventTag(nextEvent.tag); + Log.debug(this, () => "The greatest time advance grant " + + "received from the RTI is less than the timestamp of the " + + "next event on the event queue"); + Log.global.debug("Exiting _next."); + return false; } - this.sendRTINextEventTag(nextEvent.tag); - Log.debug(this, () => "The greatest time advance grant " + - "received from the RTI is less than the timestamp of the " + - "next event on the event queue"); - Log.global.debug("Exiting _next."); - return false; } return true; } From 6fcb90a597ab44320cc7c00c87894680201e2fe5 Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Sun, 21 May 2023 18:58:29 +0900 Subject: [PATCH 5/6] Remove unnecessary comparing --- src/core/federation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/federation.ts b/src/core/federation.ts index e3bcf793d..aff52217e 100644 --- a/src/core/federation.ts +++ b/src/core/federation.ts @@ -1362,7 +1362,7 @@ export class FederatedApp extends App { this.rtiClient.on('timeAdvanceGrant', (tag: Tag) => { Log.debug(this, () => {return `Time Advance Grant received from RTI for ${tag}.`}); - if (this.greatestTimeAdvanceGrant === null || this.greatestTimeAdvanceGrant?.isSmallerThan(tag)) { + if (this.greatestTimeAdvanceGrant.isSmallerThan(tag)) { // Update the greatest time advance grant and immediately // wake up _next, in case it was blocked by the old time advance grant this.greatestTimeAdvanceGrant = tag; @@ -1373,7 +1373,7 @@ export class FederatedApp extends App { this.rtiClient.on('provisionalTimeAdvanceGrant', (tag: Tag) => { Log.debug(this, () => {return `Provisional Time Advance Grant received from RTI for ${tag}.`}); - if (this.greatestTimeAdvanceGrant === null || this.greatestTimeAdvanceGrant?.isSmallerThan(tag)) { + if (this.greatestTimeAdvanceGrant.isSmallerThan(tag)) { // Update the greatest time advance grant and immediately // wake up _next, in case it was blocked by the old time advance grant From dc9f44a9370931a2a8dd8c3593d13b624c3c2b2b Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Mon, 22 May 2023 13:43:56 +0900 Subject: [PATCH 6/6] Prevent a federate which doesn't have any upstream federate to advance its tag above the stop requested tag --- src/core/federation.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/federation.ts b/src/core/federation.ts index aff52217e..ded84d0f4 100644 --- a/src/core/federation.ts +++ b/src/core/federation.ts @@ -1036,6 +1036,9 @@ export class FederatedApp extends App { // Otherwise, set the tagBarrier using the greated TAG. if (this.stopRequestInfo.state === StopRequestState.SENT) { tagBarrier = this.stopRequestInfo.tag; + if (this.upstreamFedIDs.length === 0 && tagBarrier.isSmallerThan(nextEvent.tag)) { + return false; + } } else { tagBarrier = this._getGreatestTimeAdvanceGrant(); } @@ -1112,7 +1115,6 @@ export class FederatedApp extends App { */ constructor (config: FederateConfig, success?: () => void, failure?: () => void) { - console.log(config.keepAlive); super(config.executionTimeout, config.keepAlive, config.fast, // Let super class (App) call FederateApp's _shutdown in success and failure. () => {