How to randomly pick a valid sequence_item and form a sequence

Hi,

I have a packet header that have different types of encoding allowed (around 65 in actual).
Let’s for simplicity take a case of two types of encoding as shown below:-

Ex:-
bit [64] header; //Actual header width

//valid header type_1
header [63:20] field_1_type_1;
header [19:10] field_2_type_1;
header [9:0] field_3_type_1;

//valid header type_2
header [63:20] field_1_type_2;
header [19:13] field_2_type_2;
header [12:9] field_3_type_2;
header [8:0] field_4_type_2;

My current class organisation is as follows:-
//Base Class
class base_tx extends uvm_sequence_item;
rand bit [64] header;

//No Constraints are present in this class

endclass

//Derived class type_1
class my_tx_1 extends base_tx;
rand bit [44] field_1_type_1;
rand bit [10] field_2_type_1;
rand bit [10] field_3_type_1;

//Some constraints on each of the above fields

//Pack functions to assign the field values to header
header[63:20] = field_1_type_1;
header[19:10] = field_2_type_1;

endclass

//Derived class type_2
class my_tx_2 extends base_tx;
rand bit [44] field_1_type_2;
rand bit [7] field_2_type_2;
rand bit [4] field_3_type_2;
rand bit [9] field_4_type_2;

//Some constraints on each of the above fields

//Pack functions to assign the field values to header
header[63:20] = field_1_type_2;
header[19:13] = field_2_type_2;

endclass

I would like to create random sequences consisting of my_tx_1 and my_tx_2.
The problem here is that if I am calling base_tx.randomize(), it is generating invalid stimulus in some cases.
I am able to create random sequences with my_tx_1 and my_tx_2, which are working.

Do I need to change the base class hierarchy to achieve this?
What would be better hierarchical organisation for my application with UVM?

Thanks in advance.

–Bravo

In reply to Bravo:

I’d recommend to use a union of different structs.

In reply to chr_sue:

Hi,

Can you give a basic example of how this could help me achieve the objective.
Any references should also be good.

Thanks
Bravo

In reply to Bravo:

You can define the random sequence Arbitration with set_arbitration(mode) on your sequencer.

Hi all,

Can I define the base class as the one containing bit [64] header.
Then, extended this to define the different layouts I have for this header?

If this is the case can I access and constraint the different sub-fields in different layouts ?

In reply to Bravo:

I believe you should have a look to OOP. You do not have to define in the base class any array if you want to define different Array for different Layouts.
An extended class has all the data members and methods from the base class available and adds new data members and methods.