Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
geo_distributed_checkpoint_sync.c File Reference

Example: two rte_channel_t links (one per "machine"), registered into a rte_voter_t and synchronized via rte_checkpoint (ADR-017, rewired onto rte_voter_t by ADR-025) instead of wall-clock agreement. More...

#include <setjmp.h>
#include <stdio.h>
#include <string.h>
#include "rte/checkpoint/rte_checkpoint.h"
#include "rte/checksum/rte_checksum.h"
#include "rte/clocksync/rte_clocksync.h"
#include "rte_osadapter/clocksync/rte_osadapter_clocksync.h"
#include "rte/safestate/rte_safestate.h"
#include "rte/voter/rte_voter.h"
Include dependency graph for geo_distributed_checkpoint_sync.c:

Go to the source code of this file.

Macros

#define SITE_WEST   0
#define SITE_EAST   1
#define SITE_COUNT   2U

Functions

static rte_status_t mock_send (void *channel, const void *data, size_t data_size)
static rte_status_t mock_recv (void *channel, void *data, size_t data_size, uint32_t timeout_ms)
static rte_status_t clocksync_get_offset_ms (int64_t *out_offset_ms)
static rte_status_t clocksync_get_quality (rte_clocksync_quality_t *out_quality)
static void demo_safestate_handler (rte_safestate_level_t level, rte_safestate_reason_t reason, const char *file, int32_t line, const char *message)
int main (void)

Variables

static int g_site_index [SITE_COUNT] = { SITE_WEST, SITE_EAST }
static void * g_channel_handles [SITE_COUNT] = { &g_site_index[SITE_WEST], &g_site_index[SITE_EAST] }
static rte_vital_message_t g_mailbox [SITE_COUNT]
static bool g_mail_ready [SITE_COUNT]
static bool g_link_down [SITE_COUNT]
static jmp_buf g_safestate_jmp

Detailed Description

Example: two rte_channel_t links (one per "machine"), registered into a rte_voter_t and synchronized via rte_checkpoint (ADR-017, rewired onto rte_voter_t by ADR-025) instead of wall-clock agreement.

Demonstrates the answer to "how do channels on different hardware, in different locations, get compared as if they were the same silicon": not by making their clocks agree (rte_clocksync is diagnostic only - see its header), but by having both sites confirm the same checkpoint_id to each other within a bounded timeout before the real vote happens. If a site doesn't confirm in time, that's a fault and the framework enters safe-state itself - it is not left to the application to notice.

This example simulates the network with in-memory mailboxes (one per site) instead of a real socket/serial link, so it runs standalone with no external dependencies - swap mock_backend_send/recv for a real transport (e.g. built on rte_ipc, TCP, or a serial link) to deploy this for real, per ADR-017 section 2.2 ("no new OSAdapter of its own - reuses whatever transport is already registered on each channel").

Scenario: Cycle 1: both sites confirm checkpoint 1 in time -> vote succeeds. Cycle 2: WEST's confirmation is deliberately dropped (simulating a lost/delayed message) -> checkpoint fails -> safe-state.

Compile: gcc -std=c99 -Wall -Wextra -o geo_checkpoint_sync \ geo_distributed_checkpoint_sync.c \ -I../include -L../build \ -lrte_channels -lrte_oal -lrte_core

Definition in file geo_distributed_checkpoint_sync.c.

Macro Definition Documentation

◆ SITE_WEST

#define SITE_WEST   0

Definition at line 51 of file geo_distributed_checkpoint_sync.c.

◆ SITE_EAST

#define SITE_EAST   1

Definition at line 52 of file geo_distributed_checkpoint_sync.c.

◆ SITE_COUNT

#define SITE_COUNT   2U

Definition at line 53 of file geo_distributed_checkpoint_sync.c.

Function Documentation

◆ mock_send()

rte_status_t mock_send ( void * channel,
const void * data,
size_t data_size )
static

Definition at line 66 of file geo_distributed_checkpoint_sync.c.

◆ mock_recv()

rte_status_t mock_recv ( void * channel,
void * data,
size_t data_size,
uint32_t timeout_ms )
static

Definition at line 84 of file geo_distributed_checkpoint_sync.c.

◆ clocksync_get_offset_ms()

rte_status_t clocksync_get_offset_ms ( int64_t * out_offset_ms)
static

Definition at line 106 of file geo_distributed_checkpoint_sync.c.

◆ clocksync_get_quality()

rte_status_t clocksync_get_quality ( rte_clocksync_quality_t * out_quality)
static

Definition at line 112 of file geo_distributed_checkpoint_sync.c.

◆ demo_safestate_handler()

void demo_safestate_handler ( rte_safestate_level_t level,
rte_safestate_reason_t reason,
const char * file,
int32_t line,
const char * message )
static

Definition at line 127 of file geo_distributed_checkpoint_sync.c.

◆ main()

int main ( void )

Definition at line 137 of file geo_distributed_checkpoint_sync.c.

Variable Documentation

◆ g_site_index

int g_site_index[SITE_COUNT] = { SITE_WEST, SITE_EAST }
static

Definition at line 55 of file geo_distributed_checkpoint_sync.c.

◆ g_channel_handles

void* g_channel_handles[SITE_COUNT] = { &g_site_index[SITE_WEST], &g_site_index[SITE_EAST] }
static

Definition at line 56 of file geo_distributed_checkpoint_sync.c.

◆ g_mailbox

rte_vital_message_t g_mailbox[SITE_COUNT]
static

Definition at line 58 of file geo_distributed_checkpoint_sync.c.

◆ g_mail_ready

bool g_mail_ready[SITE_COUNT]
static

Definition at line 59 of file geo_distributed_checkpoint_sync.c.

◆ g_link_down

bool g_link_down[SITE_COUNT]
static

Definition at line 64 of file geo_distributed_checkpoint_sync.c.

◆ g_safestate_jmp

jmp_buf g_safestate_jmp
static

Definition at line 125 of file geo_distributed_checkpoint_sync.c.