OCX transmitter and receiver

!(file:///localhome/saiganeshk/Desktop/link%20to%20Screenshot-1.png)

!(file:///localhome/saiganeshk/Desktop/link%20to%20Screenshot-2.png)

tell me by checking the following code that how can i generate sop for the first element of data_512 and eop for last element of data_512. i have tried in this way but it is not working . sop means start of packet and eop means end of packet

class data_item;
//rand bit sop,eop;
rand bit valid,error;
rand bit[7:0]  data_512[7];
rand bit [6:0] length;
rand byte cycles;

constraint normal
	{
	length inside {[2:63]};
	cycles <=128;
	}
endclass

typedef enum {min_len,max_len,normal,max_cycles} test;
class states;
rand test case_variable;
endclass

class driver;
virtual interface txintf tx_if;
//mailbox seq_drv;
data_item d_item;
states sta_item;
function new(virtual interface txintf tx_if);
d_item=new();
//seq_drv=new();
sta_item=new();
//this.seq_drv	= seq_drv;
this.tx_if  =tx_if;
this.d_item = d_item;
endfunction

task run();
 int i=0;
  logic[7:0] data; 
  forever
   
    begin
  
       if(tx_if.rst_n==0)
		begin
       @(posedge tx_if.clk);
		tx_if.ocx_out.sop	= 0;
		tx_if.ocx_out.valid	= 0;
		tx_if.ocx_out.eop	= 0;
		tx_if.ocx_out.error	= 0;
		tx_if.ocx_out.data_8= 0;
		//seq_drv.get(d_item);
        end
    else
      begin
            assert(d_item.randomize());
           tx_if.ocx_out.valid=$random;
      foreach(d_item.data_512[i])
         begin
       if(d_item.valid)
            begin
              tx_if.ocx_out.data_8 = d_item.data_512[i];
              if(d_item.data_512[0])
              tx_if.ocx_out.sop	= 1;
             else
               tx_if.ocx_out.sop=0;
              if(d_item.data_512[7])
              tx_if.ocx_out.eop=1;
              else
            tx_if.ocx_out.eop=1;
          end
         end
      end  
  //end
  //endcase   
$display("clk=%d,rst_n=%d,sop=%d,valid=%d,eop=%d,error=%d,data=%d",tx_if.clk,tx_if.rst_n,tx_if.ocx_out.sop,tx_if.ocx_out.valid,tx_if.ocx_out.eop,tx_if.ocx_out.error,tx_if.ocx_out.data_8);
 end      
endtask
endclass