Different kinds of pkts from a single transaction class?

Dear all,

I need to create different kinds of packets, for eg nested packets(one or more pkts encapsulated in another pkt), simple packets etc, of the same protocol. Can these different kinds of pkts be made/created (as an object) from the same transaction class? If yes, how shall I manage the packing/unpakcing(do_pack/do_unpack functions) of their bytes, as the bytes travel scenerios, will vary from pkt to pkt?
OR if I am creating different classes for each different kind of pkt structure, then will they be controlled properly from sequences, in order to create testcase scenerios? Any guidance will be helpfull.
Thanks

Can some uvm expert please throw some light on this topic? Thanks

Sounds to me like you’ll need to do a layering.

When you have nested packets, I prefer to create separate objects, something like (pseudocode):

class encap_pkt extends uvm_sequence_item;
  `uvm_object_utils(encap_pkt)
  my_pkt pkt[...];
endclass

class my_pkt extends uvm_sequence_item;
  `uvm_object_utils(my_pkt)
  my_payload payld;
  ...
endclass

You can randomize the length of the encap_pkt::pkt array if you wish, and you can randomize the length/content of the my_pkt::payld field (and anything else you want). Then you use the layering to create the encap_pkt packets at the top level and translate those into my_pkt packets at the lower level.
I wouldn’t think you’d need to worry about pack/unpack since ultimately the driver at the lowest level would know what the structure of the packet is that it gets and could manipulate the data accordingly.