There are different approaches in VMM to inject error , each one selects a way which is comfortable for them. But when finalizing on an approach it is good to know the advantages and disadvantages in terms of test bench reuse and code organization.
Error injection in transaction class attributes
Design a transaction class with virtual fields specifying the error types and control the physical fields based on the virtual error types.
This error injection code can be placed with basic transaction class or the error injection code can be a separate class extending the basic transaction class. I would prefer the error injection class to be a separate class extending the basic transaction class as the code become better organized and you don’t end up having one big monolithic transaction class.
Most of the transaction based error injection should be done using this approach. Sequence involving error injection can be easily generated using this approach.
Error injection through call back registered through driver.
Error injection on the signal level protocol controlling the driver attributes should be done through call back registers to the driver. Transaction class error injection should not be handled through driver call backs.