MBSE iNsightsMBSE iNsights

· 7 min read

Ports and Interfaces in SysML v2: One Contract, Both Sides

How to model the places where parts meet in SysML v2: one port definition per contract, conjugation for the other side, and an interface that holds both ends to it. With textual and graphical notation from the Fish On! model.

Every system has places where one part hands something to another: a radio packet, a message, a signal on a wire. Usually a different person builds each side, and each looks mostly at their own. The model’s job at those places is to say what crosses, in which direction, and what both sides have agreed to.

SysML v2 does that with two pairs, each a definition and its usages, the same pattern as part def and part:

  • A port definition (port def) states the contract once, from one side. Each part carries a port, a usage of that definition. The part on the other side uses the definition’s conjugate, written with a tilde, which reverses every direction.
  • An interface definition (interface def) says what a connection between two ports must be. An interface in the assembled system is a usage of it that joins two ports and holds both ends to the contract.

A port or an interface can be written without a definition, and starting usage-first is fine. A definition earns its place when two teams build to the same contract, which is the case at every crossing in this article.

This article builds both pairs from the Fish On! rod sensor system, the running example in Models That Answer. A sensor on each fishing rod sends a radio packet when a fish bites, a base station on the bank receives it, and the base station passes the alert to the angler’s phone. Then it shows what happens when the pattern is skipped, and how a reasoner catches the result.

A port says what crosses

SysML v1 asked you to make a decision before you drew a port: a proxy port, which stands in for features of the block that owns it and must be typed by an interface block, or a full port, a separate element of the system that may have its own parts and behavior. The specification also allows a port that is neither.

SysML v2 has no proxy ports and no full ports. It has one kind of port: a point on a part’s boundary where something crosses. A port definition says what crosses and in which direction, using directed features. An out feature leaves through the port; an in feature arrives.

Here are the two alert ports in the Fish On! model:

port def LoRaUplink {
    doc /* Rod sensor to base station: bite alerts and heartbeats. */
    out item packet : LoRaPacket;
}
port def AppLink {
    doc /* Base station to phone: messages out, commands in. */
    out item appMessage : AppMessage;
    in item command : AppCommand;
}

The LoRa uplink is one-way: a packet leaves the rod sensor through it. The app link is two-way: a message goes out to the phone, and a command comes back in. Each definition is written from the side that owns it, and what crosses is typed by an item definition, LoRaPacket or AppMessage, so the contract says exactly what moves, not only that something does.

Conjugation: the other side of the same port

The base station receives the same packet the rod sensor sends. The tempting way to model that is a second port definition, a mirror image with in where the first had out. Then the two say one thing twice, and the first time someone edits one and forgets the other, the two sides quietly stop matching.

SysML v2’s answer is one character. A tilde in front of a port definition’s name means conjugated: the same definition, seen from the other side, with every in and out swapped.

part def RodSensor :> LoRaNode, BatteryPowered {
    // ...
    port uplink : LoRaUplink;
    // ...
}

part def BaseStation :> LoRaNode {
    // ...
    port uplink : ~LoRaUplink;
    port appLink : AppLink;
    port discovery : DiscoveryResponder;
    // ...
}

part def PhoneApp {
    // ...
    port baseLink : ~AppLink;
    // ...
}

The rod sensor’s uplink is LoRaUplink, so the packet goes out. The base station’s is ~LoRaUplink, so the same packet comes in. The base station sends app messages, so its app link is plain AppLink, and the phone’s is ~AppLink.

A SysML v2 general view. The port definition LoRaUplink has an items compartment reading 'out packet : LoRaPacket'. Below it, the part definition RodSensor has a port 'uplink : LoRaUplink' with an outward arrow, and the part definition BaseStation has a port 'uplink : ~LoRaUplink' with an inward arrow.
One port definition, used from both sides. The rod sensor's port is typed by LoRaUplink, so the packet goes out. The base station's port is typed by its conjugate, ~LoRaUplink, so the same packet comes in.

There is one definition of each contract, and it cannot drift from its mirror, because there is no mirror to maintain. The conjugate is never written anywhere: every port definition already owns its conjugated port definition, and the tilde is only how a model reaches for it.

An interface holds both ends to the contract

A port says what crosses one boundary. An interface says what a connection between two ports must be:

interface def LoRaLink {
    end sensor : LoRaUplink;
    end base : ~LoRaUplink;
}
interface def AppConnection {
    end base : AppLink;
    end phone : ~AppLink;
}
Two SysML v2 interface definitions. LoRaLink has an ends compartment reading 'sensor : LoRaUplink' and 'base : ~LoRaUplink'. AppConnection has an ends compartment reading 'base : AppLink' and 'phone : ~AppLink'.
The two interface definitions in the Fish On! model. Each end is typed by a port definition or its conjugate, so both ends are held to one contract.

The tilde appears again, for the same reason: the two ends of an interface are the two sides of one contract.

The question every newcomer asks is what separates an interface from a connection. In the SysML v2 metamodel, InterfaceDefinition specializes ConnectionDefinition, and the only change is one redefinition: a connection’s ends can be any usage, and an interface narrows them to ports. So the rule is short. If both ends are ports and the model should hold you to that, write interface. If the ends are anything else, write connection.

The Fish On! model uses both. The route a bite takes is a connection between whole units, not between their ports, so it could not be an interface:

connection def AlertPath {
    doc /* The route one bite takes: a rod sensor, the base station, a phone. */
    end part rod : RodSensor;
    end part base : BaseStation;
    end part app : PhoneApp;
}

Connecting the kit

With ports on the units and interfaces defined, the Rev B kit is wired with interface usages, and flows say what actually moves on them:

part revB : FishOnSystem {
    // ...
    // Radio and network links
    interface lora1 : LoRaLink connect rod1.uplink to base.uplink;
    interface lora2 : LoRaLink connect rod2.uplink to base.uplink;
    interface lora3 : LoRaLink connect rod3.uplink to base.uplink;
    interface lora4 : LoRaLink connect rod4.uplink to base.uplink;
    flow of BitePacket from rod1.uplink to base.uplink;
    interface wifi1 : AppConnection connect base.appLink to phone.baseLink;
    interface wifi2 : AppConnection connect base.appLink to tablet.baseLink;
    flow of AppMessage from base.appLink to phone.baseLink;
    // ...
}
A SysML v2 interconnection view of revB : FishOnSystem. rod1 : RevBRodSensor has port 'uplink : LoRaUplink' with an outward arrow, joined by the interface 'lora1 : LoRaLink' to the base station's port 'uplink : ~LoRaUplink', with a BitePacket flow. The base station's port 'appLink : AppLink' is joined by the interface 'wifi1 : AppConnection' to the phone's port 'baseLink : ~AppLink', with an AppMessage flow.
Part of the Rev B kit: one rod sensor, the base station and the phone. Each link is an interface usage, and each flow is drawn on the interface it travels along.

Every connection here can be checked, because every end has a definition that says what it carries. The bite packet flow also shows why items are worth specializing: the port carries any LoRaPacket, and the flow says that what moves here is specifically a BitePacket, a kind of LoRa packet. The flow agrees with the port and says more than the port alone could.

A worked example: finding the base station

One more crossing shows the pattern from start to finish. Before the Android app can receive alerts, it has to find the base station on the local network. It does that by broadcasting a short JSON probe to every device; whatever answers is a base station. The product specification describes that JSON probe and a JSON reply.

Modeled the right way, discovery is one contract, written once from the side that sends:

item def DiscoveryRequest;
item def JsonDiscovery :> DiscoveryRequest {
    doc /* The JSON probe the Android app and the simulator send. */
}

port def DiscoveryClient {
    out item probe : JsonDiscovery;
}

interface def DiscoveryLink {
    end client : DiscoveryClient;
    end responder : ~DiscoveryClient;
}

part def AndroidApp :> PhoneApp {
    port discovery : DiscoveryClient;   // the UDP probe; iOS uses Bonjour
    // ...
}
part def BaseStation :> LoRaNode {
    // ...
    port discovery : ~DiscoveryClient;
    // ...
}

interface discoveryLink : DiscoveryLink connect tablet.discovery to base.discovery;
flow of JsonDiscovery from tablet.discovery to base.discovery;
A SysML v2 interconnection view of revB : FishOnSystem. The base station has port 'discovery : ~DiscoveryClient' with an inward arrow. The tablet : AndroidApp has port 'discovery : DiscoveryClient' with an outward arrow. The interface 'discoveryLink : DiscoveryLink' joins them, with a JsonDiscovery flow toward the base station.
Discovery modeled as one contract. The tablet's port is DiscoveryClient, the base station's is its conjugate, and the interface usage discoveryLink holds both ends to it. This version is illustrative: the next section shows what the Fish On! model records for Rev B.

The listing above is not in the book. It is the Fish On! model with discovery rewritten this way, and the SysML v2 Semantic Reasoner, the tool that answers every question in the book, has checked it. Asked whether everything is wired the way it is declared, it answers:

ssr ask FishOn-fixed.sysml -- "wiring"

PROVED — Nothing wrong with any of the 28 connection(s) this model declares.
Ports that say nothing about direction were not guessed at.

What the Rev B model actually says

The Fish On! model in the book records Rev B as it was built, and Rev B did not follow this pattern for discovery. Each side was written on its own, against a different idea of the same exchange. The Android app sends the JSON probe. The base station’s firmware listens for a plain-text string, fishalarm_discover, which no document mentions, and replies only to that. The model records each side faithfully, because a model that records intent instead of fact cannot find the gap between them:

item def TextDiscovery :> DiscoveryRequest {
    doc /* The plain-text probe the base station firmware listens for. */
}
item def JsonDiscovery :> DiscoveryRequest {
    metadata disjointWithText : SSR::disjointWith { targets = TextDiscovery; }
    doc /* The JSON probe the Android app and the simulator send. */
}

port def DiscoveryResponder {
    in item probe : TextDiscovery;
}
port def DiscoveryClient {
    out item probe : JsonDiscovery;
}

Two port definitions for one exchange, and they do not match. The metadata declares that nothing can be both a text probe and a JSON probe, and joining the two sides took a plain connection, not an interface:

// How the Android tablet finds the base station
connect tablet.discovery to base.discovery;
flow of JsonDiscovery from tablet.discovery to base.discovery;
A SysML v2 interconnection view of revB : FishOnSystem. The part ':>> base : RevBBaseStation' has a port 'discovery : DiscoveryResponder' with an inward arrow. The part 'tablet : AndroidApp' has a port 'discovery : DiscoveryClient' with an outward arrow. A plain connection joins the two ports, with a filled flow arrow labeled JsonDiscovery pointing toward the base station.
Rev B as modeled: a plain connection between two ports that do not share a contract. The directions agree, but the base station's DiscoveryResponder accepts only TextDiscovery, and the tablet sends JsonDiscovery.

Nothing here is malformed, and a syntax check passes it. A plain connect says only that two ports are joined, not that they agree, and the directions are right: the tablet’s probe is out and the base station’s is in. The mistake shows only when the flow is read against both ends at once, which is what the reasoner does. Here is its answer on the book’s model, exactly as printed:

ssr ask FishOn.sysml -- "wiring"

PROVED — 1 connection(s) wired other than as declared.
    What flows is not what the end carries — the flow of JsonDiscovery from
    tablet.discovery to base.discovery [CHECKED] base.discovery accepts
    TextDiscovery, not JsonDiscovery — and the two are declared disjoint.

That is the real bug: the tablet’s list of base stations would stay empty, and nothing would report an error. The model does not decide which side changes. The specification does. It describes the JSON probe and a JSON reply, so the firmware moves, and the result is the one-contract version in the previous section.

Writing the interface first would also have caught it from the other direction. With DiscoveryLink in place, a base station port typed DiscoveryResponder does not conform to the interface’s responder end, and the reasoner reports that too, before any flow is drawn.

Habits for ports and interfaces

  • Write one port definition per contract, from one side. Give it the features that side sends or receives, and stop. The other side is the conjugate. If you find yourself writing a mirror definition, delete it.
  • Type the items, not just the ports. A port that says out item packet without saying what a packet is cannot be checked.
  • Use an interface when both ends are ports and two teams depend on them. Starting with a plain connect is fine. A connection between two programs written by different people needs a contract on day one.
  • Use a connection when the ends are not ports, such as a path through whole units that a requirement is written about.
  • Name every flow you care about. A name lets a review, or a reasoner’s finding, cite it.
  • Record what each side actually does. When the model and the code disagree, the model should show the disagreement, not hide it.

Going further

Chapter 5 of Models That Answer: A Practitioner’s Guide to Model-Based Systems Engineering with SysML v2 covers ports, items, conjugation, interfaces and flows across the whole Fish On! kit, from the radio links between units to the buses and the interrupt line inside a single circuit board.

Get the next article by email

One email when a new article goes live, usually Thursday morning. SysML v2 and MBSE practice, no filler. Unsubscribe with one click.

More of this, on video

Walkthroughs in SysML v2 and MBSE tooling, with the model on screen.

Subscribe on YouTube