Factory Override for a virtual interface

Is it possible to use OVM factory instance overrides to override a virtual interface? For example, I have a component low in my class hierarchy that instantiates a virtual interface. I want to use a different interface, so need to override it. I played around with defining the interface as follows:

virtual class some_comp #(type IF_t = virtual some_IF)
IF_t my_if;
`ovm_component_utils_begin(some_comp)
   `ovm_field_object(IF, OVM_DEFAULT)
`ovm_component_utils_end

Then from the ovm_test level I have:

set_inst_override("some_hier.my_if", "IF_t", "another_IF_t");

It doesn’t seem to work for me because I get an error saying "Virtual interface elem. ‘copy’ not found in ‘some_IF’.

Thanks.

Monkey,

You can’t use virtual interfaces directly with the field automation macros, but you can use them indirectly. You can create a container, derived from ovm_object, that holds a virtual interface. Then you can use register the container object and use that with the factory.

interface ifc_a;
endinterface
 
class vif_container_a extends ovm_object;
  virtual ifc_a vif;
 
  `ovm_field_utils_begin(vif_container_a)
  `ovm_field_utils_end
 
  function void do_copy(ovm_object rhs);
    vif_container_a vc;
    if(!rhs || !$cast(vc, rhs)) return;
    vif = vc.vif;
  endfunction
 
  ovm_object_registry #(vif_container_a, "vif_container_a") vc_reg;
 
  function string get_type_name();
    return "vif_container_a";
  endfunction
 
endclass

We use the do_copy hook as part of the container copy to get around the fact that the field automation macros don’t support VIFs. Now you can use the factory to get different VIF containers.

Since the factory creates new instances of objects you still are left with the issue of knowing what kind of VIF you have so you can bind it to an actual interface.

– Mark

Hi Mark,

I don’t think this will help Monkey since he seems to want to replace one type of virtual interface with a different one? For that to work with a virtual interface wrapper class, the wrapper would need to be a parameterised class, e.g. along the lines of JGG’s suggestion in http://ovmworld.org/forums/showthread.php?t=245

However, to maintain flexibility, a parameterised interface wrapper would itself have to be instantiated in a parameterised class, and so on, right up to the top level environment. Unfortunately, the OVM factory does not work with parameterised classes so Monkey’s original wish to use set_inst_override won’t work!

Regards,
Dave

Thanks Mark for you reply.

I tried your code, and it does allow you to use the factory to override the container class, and hence point to a different interface. But you are right, you still can’t effectively use this because you still seem to need to know the container type when you retrieve the interface or container object from the configuration data base in your component. You could maybe use a factory type override, but you can’t seem to use type overrides for specific instances. They seem to be global, so this doesn’t work either.

I guess the best solution is just to not have interfaces in your base classes for components, but to kind of hard code them in the most extended component classes.