Écrire et vérifier un modèle › Choose communication patterns

Écrire et vérifier un modèle

Cette page n’est pas encore traduite : voici la version anglaise.

Communication patterns

A link says that two parts talk. The communication extension says how: who waits, how many receive, what the receiver keeps while it is busy, how long a message takes, and how parts meet when no link is drawn: by a topic or by a service's name.

Extension — not covered by the 1.0 stability promise (communication; the core)

The checker reads every one of these properties. The simulator runs the ones that change what happens in a run: topics, services, a link's latency and a receiver's queue. The others go to archec analyze, to the Arche project and to the generators.

A radar station#

A radar publishes its tracks on a topic, asks a classifier for work by the service's name, and logs every track over a slow link to a recorder that keeps two messages at most.

message TRACK "Track" {
  id:    uint32
  range: float32 unit m
}

message JOB "Job" {
  id: uint32
}

component Radar "Radar" {
  out tracks: data sends TRACK { pattern pub-sub; topic "/tracks/{id}" }
  out jobs:   data sends JOB { service "classify" }
  out log:    data sends TRACK
  fn main "Sweep" ```arche
    wait 1ms
    send tracks TRACK { id: 4, range: 120.0 }
    send jobs JOB { id: 4 }
    for i in 0..<5 {
      send log TRACK { id: i, range: 80.0 }
    }
  ```
}

component Display "Display" {
  in tracks: data receives TRACK {
    pattern pub-sub
    topic "/tracks/*"
    handler TRACK -> show
  }
  var shown: uint32 = 0
  fn show(id: uint32) ```arche
    shown = id
  ```
}

component Classifier "Classifier" {
  in jobs: data receives JOB {
    service "classify"
    handler JOB -> classify
  }
  var done: uint32 = 0
  fn classify(id: uint32) ```arche
    done = id
  ```
}

component Recorder "Recorder" {
  in log: data receives TRACK {
    delivery { buffer queue; depth 2; overflow drop-newest }
    handler TRACK -> write
  }
  var written: uint32 = 0
  fn write(id: uint32) ```arche
    written += 1
    wait 10ms
  ```
}

system Station "Radar station" {
  part radar:      Radar
  part display:    Display
  part classifier: Classifier
  part recorder:   Recorder
  radar.log -> recorder.log { latency 2ms }
}

test-plan TP-COMM "How the parts meet" {
  case TC-MEET "Topic, service and link" {
    at 2ms expect display.shown == 4 && classifier.done == 4
    at 2ms expect recorder.written == 0
    at 4ms expect recorder.written == 1
    at 50ms expect recorder.written == 3
  }
}
Diagramme : Radar station
Ce qu’archec dessine depuis ce code : Radar station
Essayer

Only one link is drawn. The display gets the track because its topic filter /tracks/* matches /tracks/{id}. The classifier gets the job because it serves "classify". The recorder's five tracks arrive 2 ms after they are sent. It writes the first, keeps two while it is busy, and drops the other two.

$ archec sim main.arche --for 50ms
Radar station — system Station, 50.000 ms simulated
    1.000 ms  radar.tracks → display.tracks  TRACK {"id":4,"range":120}
    1.000 ms  radar.jobs → classifier.jobs  JOB {"id":4}
    1.000 ms  radar.log → recorder.log  TRACK {"id":0,"range":80} (arrives 3.000 ms)
    …
    3.000 ms  recorder.log: TRACK lost, its queue is full (2): the newest is dropped
    3.000 ms  recorder.log: TRACK lost, its queue is full (2): the newest is dropped
$ archec test main.arche
1/1 passed on the browser simulator, 0 failing, 0 known failure(s)

archec test runs this case on the browser simulator and says so. Arche's simulator draws no link for a topic or a service, so it would not deliver them.

How a port talks#

These properties go on a port, or on a link, where the link's own win over its ports'. Written together they make a delivery { … } group, and latency, jitter and bitrate a timing { … } group.

Property What it says Where it counts
pattern fire-and-forget (the default), request-reply, pub-sub, broadcast, dataflow the checker; the generator model; the Arche project
buffer what the receiver keeps: queue, sample (the last one), stream the simulator and Arche's (a sample is a queue of one that drops the oldest)
depth how many messages a queue keeps while the part is busy the simulator and Arche's
overflow what a full queue does: drop-newest (the default), drop-oldest, block the simulator and Arche's
latency how long a message takes on the link the simulator, archec analyze, the Arche project
jitter how much later it may come archec analyze (added to the worst case)
stale-after how old a buffer sample may be the checker; the generator model
timeout, retries, async, deferred how a request waits the checker; the simulator; the generator model
reliability reliable or best-effort the ROS 2 target's QoS
topic what a pub-sub port publishes or subscribes to the simulator; AsyncAPI and ROS 2
service a service called, or served, by its name the simulator; the generator model

Topics#

A topic is a path. Its parts in braces are filled when a message is published, each from the message's field of that name: /tracks/{id} publishes track 4 on /tracks/4. An in port's topic is a filter: * is one level, ** any number, and a part in braces any value.

A port with a topic needs no link. Linking it too is topic-wired. A part that names no field of the message is topic-part, unless it gives its type: {sensor: uint8}. A metric (a message with kind metric) is published on /<part path>/<metric> unless its port names a topic.

Services#

service "classify" on an out port calls the service, and on an in port serves it. The simulator delivers what the caller sends to every part that serves the name, wherever it is in the system. A name that no in port serves is no-service.

Queues, samples and latency#

A part does one thing at a time. A message that comes while it is busy waits. With buffer queue; depth N, at most N wait for one link. With overflow drop-newest the message that came last is lost, with drop-oldest the one that waited longest. The trace shows each loss. buffer sample keeps only the latest.

With overflow block the sender waits: its send goes on once the queue has room, and nothing is lost. A message takes its place from when it is sent until the part takes it, so what is still on the link counts.

A port met by a topic or a service keeps its own queue and latency too.

A link's latency delays each message, and a port's latency adds to it. archec analyze adds jitter and the bus time to the latency of each chain.

Requests and calls#

pattern request-reply says that the sender waits for an answer. The checker asks for a handler on the server's port (no-reply). timeout and retries are only for this pattern (comm-property). In a run:

  • send waits until the server's handler has ended, plus the link's latency back. A message with no handler to take it, or that a full queue drops, gets no reply.
  • With timeout 5ms; retries 2, a request with no reply in 5 ms is sent again, twice at most, then given up, and the sender goes on. The trace shows each one. A slow server may so handle the same request several times.
  • With async true the sender does not wait. The timeout and the retries still run.
  • With deferred true on the server's port, the handler's end is no reply: the next message the server sends to that part is.
  • With several servers on one port, the first reply ends the wait.
  • With no timeout, a request that nothing answers waits for ever, and the run ends with a note that says so.

A part that sends a request from a handler is busy until the reply: what comes meanwhile waits. From fn main it still handles its messages, so a reply message is handled before send returns.

To call a function of another part and use its result, give the ports an interface instead: port.op(…) (calling another part).

HTTP routes#

On a port of a type that answers HTTP (ethernet, or handling http), a handler names a method and a path:

component Orders "Order service" {
  in http: ethernet "HTTP" {
    handler GET "/v1/orders/{id}" -> read_order
    handler POST "/v1/orders" -> place_order
  }
  var count: uint32 = 0
  fn read_order(id: uint32) -> uint32 ```arche
    return id
  ```
  fn place_order(amount: float64) -> uint32 ```arche
    count = count + 1
    return count
  ```
}
Diagramme : Order service
Ce qu’archec dessine depuis ce code : Order service

archec gen --target openapi writes one OpenAPI file per component, an operation per route. {id} is a path parameter, and the function's other parameters are the query or the JSON body. examples/services is a whole order service written this way.

Dataflow#

A dataflow port streams vectors of samples from a source to a sink. Its dataflow { … } group says the sample's type (vector), the header, how many samples are pushed at once, how many the sink needs before it runs (threshold), and whether the sink may make its source wait (backpressure). The checker reports a sink linked to no source of its vector (dataflow-source), and two ends that disagree on back-pressure (dataflow-backpressure). examples/signal-chain shows a chain of algorithms. The table of properties is in the specification.

Interface control documents#

archec gen --target icd writes an interface control document in Markdown for each port type and interface that links use, and for each bus a deployment routes messages over. It lists the messages, their fields and byte layout, who sends and who receives them, and the timing.

A link can also list its own messages with icd, field by field, as the interface document of a project names them. archec build writes them on the link of the Arche project, where Arche shows them:

message POINT {
  az: float64
  el: float64
}

component Antenna {
  in cmd: data receives POINT
}

component Ground {
  out cmd: data sends POINT
}

system Site {
  part ground:  Ground
  part antenna: Antenna
  ground.cmd -> antenna.cmd {
    icd m1 "Pointing" { Azimuth: float64; Elevation: float64 }
  }
}
Diagramme : Site
Ce qu’archec dessine depuis ce code : Site
Essayer

What the checker reports#

  • pattern-mismatch: the two ends, or the link, say different patterns.
  • wrong-side: buffer, depth, overflow or stale-after on an out port. These are what the receiver keeps.
  • comm-property: a property for another pattern or buffer: retries without request-reply, overflow without a queue, stale-after without a sample.
  • no-reply: a request that the server's port does not handle.
  • no-subscriber: a pub-sub port that nothing reads.
  • no-service, topic-wired, topic-part, dataflow-source, dataflow-backpressure: as above.

archec explain <code> says more about each.

Limits#

  • The simulator does not run jitter, stale-after or reliability. A message comes after exactly its latency.
  • Only an arche body, or a Python one the simulator translates to it, waits in send. A TypeScript body, a test's line and a message to an FPGA part or a population do not.
  • A body cannot tell a request that was answered from one given up. Have the reply's handler set a variable. A request sent again may go past the depth of a blocking queue.
  • timeout and retries are for messages. A call, port.op(…), takes no time and always answers.
  • Arche's simulator does not wait in send, so archec test runs such a system's cases on the browser simulator.
  • No code generator waits for a request's reply or sends it again: that is the runtime's or yours. On a full queue they differ: the Rust Embassy target does what overflow says (and waits when it says nothing), Go waits whatever it says, an FPGA part's fn main waits, and C drops the message that came last.
  • A queue is counted for each link. A part with two links into one port keeps depth messages from each.
  • A dataflow sink runs on each message in the simulator. Its threshold, history and back-pressure are checked and exported, not simulated.
  • pattern broadcast and fire-and-forget behave the same in the simulator: every port linked to the sender receives.
  • Arche's simulator does not deliver by topic or service, so archec test runs such a system's cases on the browser simulator.
  • HTTP routes are not simulated: a test cannot send an HTTP request. They are for openapi and for the code generators.
  • A link's icd messages go to the Arche project only. archec gen --target icd documents the messages the ports send, not these.