Protocol Agent Contracts
Learn how to define the stable interface of a reusable UVM agent so environments can configure, stimulate, monitor, and replace protocol implementations without unnecessary coupling.
Learning objectives
- Define what constitutes a protocol agent contract in a reusable UVM environment.
- Identify the configuration, transaction, sequencer, driver, monitor, and analysis interfaces that an agent exposes.
- Distinguish stable agent interfaces from implementation details that should remain private.
- Design an agent whose active/passive behavior and configuration are predictable to its environment.
- Document transaction semantics such as acceptance, completion, direction, IDs, and error information.
- Validate that an agent satisfies its intended contract through topology, TLM connectivity, stimulus, and monitor evidence.
- Recognize common contract violations that make agents difficult to reuse or replace.
Step 1: Understand the concept
A reusable UVM agent is more than a collection of a driver, sequencer, and monitor. Other components depend on the agent in specific ways: tests configure it, sequences start on its sequencer, scoreboards consume its monitor transactions, and environments may connect its analysis ports to coverage or checking components.
The protocol agent contract is the set of externally observable interfaces and behavioral expectations that allow those users to interact with the agent without knowing how it is implemented internally.
A practical agent contract answers questions such as:
- What configuration object does the agent require?
- Does it support
UVM_ACTIVE,UVM_PASSIVE, or both? - What sequence item type does its sequencer accept?
- What does a sequence item represent?
- When does the driver consider an item accepted?
- What transaction does the monitor publish?
- What does each analysis port mean?
- Which fields are guaranteed to be valid?
- How are reset, errors, IDs, and incomplete operations represented?
This matters because an environment should be able to replace one implementation with another while keeping the surrounding components unchanged whenever both implementations satisfy the same contract.
Contract versus implementation
Suppose a bus agent contains:
bus_agent
|
+-- bus_sequencer
+-- bus_driver
+-- bus_monitor
+-- internal protocol helper
+-- internal state
+-- internal queues
The surrounding environment may need to know about the sequencer, monitor analysis port, and configuration object. It normally does not need to know whether the monitor uses an internal queue, how the driver calculates wait states, or which helper class reconstructs a response.
Those implementation details can change without changing the agent's external behavior.
Step 2: Define the agent's public surface
A useful way to design an agent is to explicitly list the interfaces that other components are allowed to depend on.
| Agent interface | Typical purpose | Contract question |
|---|---|---|
| Configuration object | Select behavior and provide required resources | Which settings are required and what do they mean? |
| Sequencer | Receive sequence items | What transaction type and operations are supported? |
| Driver | Convert sequence items into DUT activity | What does the item mean at the interface? |
| Monitor analysis port | Publish observed protocol transactions | When is a transaction published and what does it contain? |
| Agent mode | Control stimulus ownership | What changes between active and passive operation? |
| Errors/status | Expose protocol problems | How are malformed or incomplete observations reported? |
The contract is strongest when these interfaces have precise semantics rather than simply exposing component names.
Useful contract: "The monitor publishes one
bus_item for every accepted bus transfer, with address, direction, data, response status, and transaction ID populated according to the protocol."
Step 3: Define a transaction contract
The transaction type is one of the most important parts of an agent's public interface. A scoreboard or coverage component cannot use an agent reliably if it does not know what the published transaction represents.
Consider a simplified bus transaction:
class bus_item extends uvm_sequence_item;
`uvm_object_utils(bus_item)
rand bit [31:0] addr;
rand bit [31:0] data;
rand bit write;
rand bit [3:0] byte_en;
bit error;
int unsigned id;
function new(string name = "bus_item");
super.new(name);
endfunction
endclass
The contract should distinguish fields used to request stimulus from fields populated by observing the DUT.
addr,data,write, andbyte_enmay be stimulus fields.errormay be populated by the monitor after observing the response.idmay be generated by the sequence or reconstructed from the protocol, depending on the protocol semantics.
That distinction prevents an important ambiguity: a field in a transaction should have a clearly defined owner and meaning.
Define the transaction boundary
The agent should also specify when a transaction is considered complete enough to publish.
For a ready/valid interface, for example, the monitor may define acceptance as:
if (vif.valid && vif.ready) begin
// Capture one accepted transfer.
end
If the environment's scoreboard assumes that every published transaction represents an accepted transfer, the monitor must not publish speculative transactions merely because valid was asserted.
Step 4: Define the configuration contract
Lesson 42 introduced configuration objects, and Lesson 50 applied them to reusable agent configuration. The next step is to treat configuration as part of the agent's public interface.
class bus_agent_cfg extends uvm_object;
`uvm_object_utils(bus_agent_cfg)
virtual bus_if vif;
uvm_active_passive_enum is_active = UVM_ACTIVE;
int unsigned timeout_cycles = 100;
bit enable_protocol_checks = 1;
bit enable_coverage = 1;
function new(string name = "bus_agent_cfg");
super.new(name);
endfunction
function bit is_valid();
return (vif != null) &&
(timeout_cycles > 0);
endfunction
endclass
The agent can retrieve and validate this object during build_phase:
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(bus_agent_cfg)::get(
this, "", "cfg", cfg)) begin
`uvm_fatal("CFG", "bus_agent_cfg was not provided")
end
if (!cfg.is_valid())
`uvm_fatal("CFG", "Invalid bus_agent_cfg")
is_active = cfg.is_active;
monitor = bus_monitor::type_id::create("monitor", this);
if (is_active == UVM_ACTIVE) begin
sequencer = bus_sequencer::type_id::create("sequencer", this);
driver = bus_driver::type_id::create("driver", this);
end
endfunction
This creates predictable behavior:
- the required configuration is obtained early,
- invalid configuration fails near the source of the problem,
- the standard UVM agent mode is synchronized with the configuration, and
- the monitor remains available in passive mode.
The configuration contract should also specify which settings are structural and which can safely change during simulation. Structural settings such as active/passive mode and virtual-interface selection normally belong in build-time configuration rather than being changed arbitrarily during run_phase.
Step 5: Define the analysis contract
An agent's monitor analysis port is often the most important interface used by scoreboards and coverage components.
class bus_monitor extends uvm_monitor;
`uvm_component_utils(bus_monitor)
uvm_analysis_port #(bus_item) ap;
function new(string name, uvm_component parent);
super.new(name, parent);
ap = new("ap", this);
endfunction
task run_phase(uvm_phase phase);
bus_item item;
forever begin
item = collect_transfer();
ap.write(item);
end
endtask
endclass
The code alone does not define the full contract. The environment needs to know what collect_transfer() means.
A good analysis contract specifies:
- which protocol event creates a transaction,
- whether the transaction represents an accepted, attempted, or completed operation,
- which fields are guaranteed to be populated,
- whether response information is included,
- how transaction IDs are represented, and
- what reset does to partially observed activity.
This becomes critical when connecting the agent to the scoreboards introduced in Module 2. An out-of-order scoreboard cannot correlate responses correctly if the agent's ID semantics are ambiguous.
Step 6: Separate protocol guarantees from implementation details
Suppose a scoreboard connects directly to internal driver state:
// Avoid this style:
env.bus.driver.pending_queue
env.bus.driver.internal_id_counter
env.bus.monitor.internal_state
This creates tight coupling. A future implementation can no longer replace the driver or monitor without potentially breaking the scoreboard.
Prefer the agent's supported interfaces:
env.bus.monitor.ap
env.bus.sequencer
env.bus.cfg
Even then, be selective. Exposing a public handle does not automatically make every field or method a good dependency for external components.
bus_item. If the scoreboard must change, the scoreboard may be depending on implementation details rather than the agent's transaction contract.
Step 7: Define active/passive behavior precisely
Lesson 51 established that a reusable agent can operate in active or passive mode. The agent contract should make the behavior of each mode explicit.
| Behavior | Active | Passive |
|---|---|---|
| Monitor | Enabled | Enabled |
| Sequencer | Created/available | Normally not created |
| Driver | Created/connected | Normally not created |
| Observed transactions | Published | Published |
| Interface stimulus | Generated by UVM | Not generated by UVM |
This makes the agent usable at different verification levels without requiring separate active and passive implementations.
A particularly important requirement is that switching to passive mode should not silently disable observation. Scoreboards and coverage should continue receiving monitor transactions unless the environment explicitly chooses otherwise.
Step 8: Define reset and error semantics
A reusable agent must also explain what happens when the protocol is reset while an operation is in progress.
For example, a monitor may observe:
request accepted
|
|---- reset ----|
|
response never observed
Should the monitor publish an incomplete transaction? Should it discard the partial operation? Should it mark the transaction as aborted?
There is no universal answer. The protocol specification and verification requirements determine the correct behavior.
The important lesson is that the behavior should be defined rather than left as an accidental consequence of the monitor implementation.
The same applies to errors. If a response contains an error status, the transaction should represent that status consistently so scoreboards and negative tests can distinguish:
- an expected protocol error,
- an unexpected DUT error,
- a missing response, and
- a monitor or environment failure.
This connects directly to the error-handling and timeout architecture developed earlier in the learning path.
Step 9: Validate the contract
A contract is useful only if it can be demonstrated through observable behavior. Validate the agent in layers.
- Build validation: confirm the configuration object is present, valid, and associated with the intended agent instance.
- Topology validation: confirm the expected monitor, driver, and sequencer components exist for the selected mode.
- Stimulus validation: in active mode, verify that a known sequence produces the intended protocol activity.
- Observation validation: verify that the monitor publishes exactly the transactions expected from the protocol events.
- TLM validation: confirm that analysis consumers receive the published transactions.
- Passive-mode validation: disable stimulus generation and verify that externally generated activity is still monitored.
- Reset validation: verify the documented behavior for transactions interrupted by reset.
A simple diagnostic can expose the resolved agent implementation:
`uvm_info("AGENT_CONTRACT",
$sformatf("agent=%s mode=%s monitor=%s",
get_full_name(),
(is_active == UVM_ACTIVE) ? "ACTIVE" : "PASSIVE",
monitor.get_type_name()),
UVM_LOW)
The goal is not to print every internal detail. The goal is to make the externally relevant behavior visible enough to diagnose configuration and integration mistakes.
Step 10: Recognize contract violations
Many difficult UVM integration failures are really mismatches between what the environment assumes and what the agent actually provides.
| Failure | Likely contract problem |
|---|---|
| Scoreboard sees transactions before the protocol accepts them | Monitor transaction boundary is ambiguous or incorrect |
| Two consumers interpret the same field differently | Transaction semantics are undocumented or inconsistent |
| Passive agent produces no observations | Passive mode incorrectly disabled the monitor |
| Environment breaks after monitor replacement | Consumers depended on monitor internals |
| Multiple instances observe the same DUT interface | Virtual-interface configuration is wrong |
| OOO scoreboard cannot match responses | ID/key semantics are missing or inconsistent |
| Reset causes stale transactions in checking | Reset behavior was not defined across the agent boundary |
Try it yourself
Take a reusable bus agent and write a one-page contract for it. Your contract should specify:
- The configuration object and required fields.
- The meaning of
UVM_ACTIVEandUVM_PASSIVE. - The sequence item type accepted by the sequencer.
- The protocol event that causes the monitor to publish a transaction.
- The required fields in each published transaction.
- The meaning of the transaction ID, if one exists.
- The behavior when reset interrupts an operation.
- The analysis ports exposed to the environment.
Implementation exercise: connect the monitor's analysis port to a simple subscriber that prints the transaction ID, address, direction, and response status. Verify that the subscriber receives exactly one transaction for each accepted transfer.
Challenge: create a second implementation of the monitor that produces the same bus_item semantics. Replace the original monitor without modifying the scoreboard or coverage component. If those consumers require changes, identify which dependency violates the intended contract.
Production design notes
- Define semantics, not just component names. Saying that an agent has a monitor is less useful than defining exactly what its analysis port publishes.
- Keep transaction meaning stable. Changing whether a transaction represents an attempted or accepted operation can invalidate scoreboards and coverage without causing compilation errors.
- Make configuration typed. A dedicated configuration object makes required settings explicit and easier to validate.
- Keep protocol details inside the agent. External components should not need to understand driver state machines or monitor implementation queues.
- Define reset behavior. Partial transactions and outstanding operations must have predictable semantics across reset.
- Document ID semantics. If downstream checking uses transaction correlation, the uniqueness and lifetime of IDs must be clear.
- Preserve passive observation. Active/passive mode changes stimulus ownership; it should not normally remove the monitor's observation capability.
- Make replacement possible. A well-defined contract allows factory overrides or alternate implementations to change internal behavior without forcing changes throughout the environment.
- Validate the contract at integration time. Build, topology, monitor output, TLM connectivity, reset behavior, and active/passive operation should all be tested.
Knowledge check
- What is the difference between an agent's public contract and its internal implementation?
- Why is the meaning of a monitor transaction part of the agent contract?
- Why should a passive agent normally retain its monitor?
- Which agent settings should generally be established before runtime stimulus begins?
- Why can an undocumented transaction ID cause failures in an out-of-order scoreboard?
- Why is direct access to
driver.internal_queuea poor environment-level dependency? - What should happen to a partially observed transaction when reset occurs?
- How would you test whether two different monitor implementations satisfy the same contract?
Key takeaways
- A protocol agent contract defines the externally relevant behavior and interfaces that the surrounding environment can safely depend on.
- The contract includes configuration, active/passive behavior, sequence-item semantics, monitor transaction boundaries, analysis streams, IDs, reset behavior, and error semantics.
- Protocol-specific implementation details should remain inside the agent whenever they are not required by external consumers.
- Monitor transaction semantics must be precise because scoreboards, predictors, coverage, and cross-interface checkers depend on them.
- Multiple instances of the same agent can satisfy the same contract while using different configurations and virtual interfaces.
- A strong contract makes agent replacement, factory customization, and environment reuse much easier.
- Contract validation should use observable simulation evidence rather than relying only on compilation.
What comes next?
In Lesson 54, Environment Layering, you will apply this contract-oriented thinking above the agent level. You will learn how to separate protocol agents, subsystem environments, virtual sequencing, checking, and higher-level integration so that a verification environment can grow without becoming a tightly coupled hierarchy of special cases.