Hi all, I was asked this question in the interview and the solution i wrote was -
class broadcast #(pkt) extends uvm_component;
`uvm_component_utils(broadcast)
uvm_analysis_imp #(pkt, broadcast) port_in;
uvm_analysis_port #(pkt) port_out;
function new(string name = "broadcast", uvm_component parent = null);
super.new(name, parent);
endfunction
virtual function void write(pkt p);
port_out.write(p);
endfunction
endclass
class env extends uvm_env;
`uvm_component_utils(env)
uvm_analysis_port #(pkt) analysis_port1;
uvm_analysis_port #(pkt) analysis_port2;
broadcast #(pkt) bcast;
function new(string name = "env", uvm_component parent = "null");
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
bcast = broadcast#(pkt)::type_id::create("bcast",this);
analysis_port1 = new("analysis_port1", this);
analysis_port2 = new("analysis_port2", this);
bcast.outp.connect(analysis_port1);
bcast.outp.connect(analysis_port2);
endfunction
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
producer.analysis_port.connect(bcast.inp);
endfunction
endclass
Is this solution correct? Can you suggest any improvement?