data/full_repos/permissive/129989088/lookup_connTb.v
 line:188: before: "."
1: b'%Error: data/full_repos/permissive/129989088/lookup_connTb.v:176: Cannot find file containing module: \'fifo\'\nfifo meta_buffer(\n^~~~\n        ... Looked in:\n             data/full_repos/permissive/129989088,data/full_repos/permissive/129989088/fifo\n             data/full_repos/permissive/129989088,data/full_repos/permissive/129989088/fifo.v\n             data/full_repos/permissive/129989088,data/full_repos/permissive/129989088/fifo.sv\n             fifo\n             fifo.v\n             fifo.sv\n             obj_dir/fifo\n             obj_dir/fifo.v\n             obj_dir/fifo.sv\n%Warning-WIDTH: data/full_repos/permissive/129989088/lookup_connTb.v:773: Operator ASSIGNDLY expects 16 bits on the Assign RHS, but Assign RHS\'s SEL generates 3 bits.\n                                                                        : ... In instance lookup_connTb\n    conn_closed_info <= connIdx_info_temp[3][b_idx_connIdxInfo+d_connTb-1:b_idx_connIdxInfo];\n                     ^~\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Error: Exiting due to 1 error(s), 1 warning(s)\n'
module lookup_connTb(
clk,
reset,
metadata_in_valid,
metadata_in,
conn_idx_valid,
conn_idx_info,
idx_connTb_search,
idx_connTb_conf,
rdValid_connTb_search,
wrValid_connTb_conf,
data_connTb_conf,
ctx_connTb_search,
action_valid,
action,
eventInfo_valid,
eventInfo,
conn_closed_valid,
conn_closed_info
);




parameter 	w_meta = 104,

			w_eventInfo = 16,

			w_evb = 8,
			w_connTb = 200,



			d_connTb = 3,
			w_state = 4,
			w_seq = 32,
			w_window = 16,
			w_length = 16,
			w_tcpFlag = 8,
			w_flowID = 16,
			w_ip = 32,
			w_connIdx_info = 19,


			d_metaBuffer = 5,
			words_metaBuffer = 32,
			

			b_length_meta = 88,
			b_tcpFlag_meta = 80,
			b_sendSeq_meta = 48,
			b_ackSeq_meta = 16,
			b_window_meta = 0,

			b_hit_connIdxInfo = 18,
			b_add_connIdxInfo = 17,
			b_dir_connIdxInfo = 16,
			b_idx_connIdxInfo = 0,

			b_cliState_connTb = 196,
			b_cliSendSeq_connTb = 164,
			b_cliAckSeq_connTb = 132,
			b_cliWin_connTb = 116,
			b_cliMaxWin_connTb = 100,
			b_serState_connTb = 96,
			b_serSendSeq_connTb = 64,
			b_serAckSeq_connTb = 32,
			b_serWin_connTb = 16,
			b_serMaxWin_connTb = 0,


			NONE_STATE = 8'd0,
			NEW_FLOW = 8'd1,
			HALF_CONN = 8'd2,
			CONN_SETUP = 8'd4,
			TIME_OUT = 8'd8,
			CONN_END_CLI = 8'd16,
			CONN_END_SER = 8'd32,
			STATE_CHANGE = 8'd128,
			

			CLOSED_STATE = 4'd0,
			REQUESTED_STATE = 4'd1,
			ESTABLISHED_STATE = 4'd2,
			WAITING_CLOSE_STATE = 4'd3,
			
			DEFAULT_SEQ = 32'b0,

			b_fin_flag = 0,
			b_syn_flag = 1,
			b_rst_flag = 2,
			b_ack_flag = 4,
			ONLY_FIN = 8'h01,
			ONLY_SYN = 8'h02,
			ONLY_RST = 8'h04,
			ONLY_ACK = 8'h10;

input								clk;
input								reset;
input								metadata_in_valid;
input		[w_meta-1:0]			metadata_in;
input								conn_idx_valid;
input		[w_connIdx_info-1:0]	conn_idx_info;
output	reg	[d_connTb-1:0]			idx_connTb_search;
output	reg	[d_connTb-1:0]			idx_connTb_conf;
output	reg							rdValid_connTb_search;
output	reg							wrValid_connTb_conf;
output	reg	[w_connTb-1:0]			data_connTb_conf;
input		[w_connTb-1:0]			ctx_connTb_search;
output	reg 							action_valid;
output	reg 							action;
output	reg 							eventInfo_valid;
output	reg 	[w_eventInfo-1:0]		eventInfo;
output 	reg 							conn_closed_valid;
output 	reg 	[w_flowID-1:0]			conn_closed_info;




reg 									valid_temp[3:0];
reg			[w_connIdx_info-1:0]	connIdx_info_temp[3:0];
reg 			[w_meta-1:0]			meta_temp[3:0];


wire								empty_meta;
wire		[w_meta-1:0]			ctx_meta;


wire		[w_state-1:0]			stateCli_connTb,stateSer_connTb;
wire		[w_seq-1:0]				sendSeqCli_connTb, sendSeqSer_connTb;
wire		[w_seq-1:0]				ackSeqCli_connTb, ackSeqSer_connTb;
wire		[w_window-1:0]		winCli_connTb, winSer_connTb;
wire		[w_window-1:0]		MwinCli_connTb, MwinSer_connTb;
reg			[w_state-1:0]			stateCli_temp, stateSer_temp;
reg			[w_seq-1:0]				sendSeqCli_temp, sendSeqSer_temp;
reg			[w_seq-1:0]				ackSeqCli_temp, ackSeqSer_temp;
reg			[w_window-1:0]		winCli_temp, winSer_temp;
reg			[w_window-1:0]		MwinCli_temp, MwinSer_temp;
reg 			[w_seq-1:0]				seq_temp, ack_temp;
reg 			[w_length-1:0]			length_temp;
reg 			[w_window-1:0]		wind_temp;
reg 			[w_tcpFlag-1:0]			tcpFlag_temp;


reg			[w_evb-1:0]				event_bitmap_t;









fifo meta_buffer(
.aclr(!reset),
.clock(clk),
.data(metadata_in),
.rdreq(conn_idx_valid),
.wrreq(metadata_in_valid),
.empty(empty_meta),
.full(),
.q(ctx_meta),
.usedw()
);
defparam
	meta_buffer.width = w_meta,
	meta_buffer.depth = d_metaBuffer,
	meta_buffer.words = words_metaBuffer;



integer	i, j;
always @(posedge clk or negedge reset) begin
	if (!reset) begin
		idx_connTb_search <= {d_connTb{1'b0}};
		rdValid_connTb_search <= 1'b0;
		
		for(i = 0; i < 4; i = i+1) begin
			valid_temp[i] <= 1'b0;
			connIdx_info_temp[i] <= {w_connIdx_info{1'b0}};
			meta_temp[i] <= {w_meta{1'b0}};
		end
	end
	else begin
		if(conn_idx_valid == 1'b1) begin
			valid_temp[0] <= 1'b1;
			meta_temp[0] <= ctx_meta;
			connIdx_info_temp[0] <= conn_idx_info;
			rdValid_connTb_search <= 1'b1;
			idx_connTb_search <= conn_idx_info[b_idx_connIdxInfo+d_connTb-1:
				b_idx_connIdxInfo];
		end
		else begin
			valid_temp[0] <= 1'b0;
			meta_temp[0] <= {w_meta{1'b0}};
			connIdx_info_temp[0] <= {w_connIdx_info{1'b0}};
			rdValid_connTb_search <= 1'b0;
		end

		for(j = 0; j < 3; j = j+1) begin
			valid_temp[j+1] <= valid_temp[j];
			connIdx_info_temp[j+1] <= connIdx_info_temp[j];
			meta_temp[j+1] <= meta_temp[j];
		end
	end
end



always @(posedge clk or negedge reset) begin
	if (!reset) begin
		{length_temp,tcpFlag_temp,seq_temp,ack_temp,wind_temp}  <= {w_meta{1'b0}};
	end
	else begin
		{length_temp,tcpFlag_temp,seq_temp,ack_temp,wind_temp}  <= meta_temp[1];
	end
end


assign {stateCli_connTb, sendSeqCli_connTb, ackSeqCli_connTb, winCli_connTb,
		MwinCli_connTb, stateSer_connTb, sendSeqSer_connTb, ackSeqSer_connTb, 
		winSer_connTb, MwinSer_connTb} = ctx_connTb_search;

always @(posedge clk or negedge reset) begin
	if (!reset) begin
		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};
		event_bitmap_t <= {w_evb{1'b0}};
		action_valid <=1 'b0;
		action <= 1'b0;
	end
	else begin
		action_valid <= valid_temp[2];
		if(valid_temp[2] == 1'b1) begin
			if(connIdx_info_temp[2][b_add_connIdxInfo] == 1'b1) begin

				stateCli_temp <= REQUESTED_STATE;
				sendSeqCli_temp <= seq_temp;
				ackSeqCli_temp <= 32'b0;
				winCli_temp <= wind_temp;
				MwinCli_temp <= {w_window{1'b0}};

				stateSer_temp <= REQUESTED_STATE;
				sendSeqSer_temp <= {w_seq{1'b0}}; 
				ackSeqSer_temp <= {w_seq{1'b0}};
				winSer_temp <= {w_window{1'b0}};
				MwinSer_temp <= {w_window{1'b0}};

				event_bitmap_t <= NEW_FLOW | STATE_CHANGE;

				action <= 1'b1;
			end

			else if (connIdx_info_temp[2][b_hit_connIdxInfo] == 1'b1) begin 

				if(connIdx_info_temp[2][b_dir_connIdxInfo] == 1'b0) begin

					case(stateCli_connTb)

CLOSED_STATE: begin

	stateCli_temp <= CLOSED_STATE;
	sendSeqCli_temp <= seq_temp + {16'b0,length_temp};
	ackSeqCli_temp <= ack_temp;
	winCli_temp <= wind_temp;
	MwinCli_temp <= MwinCli_connTb;

	sendSeqSer_temp <= sendSeqSer_connTb;
	ackSeqSer_temp <= ackSeqSer_connTb;
	winSer_temp <= winSer_connTb;
	MwinSer_temp <= MwinSer_connTb;

	action <= check_seq_valid(seq_temp, length_temp, ackSeqSer_connTb, winSer_connTb, sendSeqCli_connTb) & 
		check_ack_valid(ack_temp, sendSeqSer_connTb, ackSeqCli_connTb, MwinCli_connTb);


	if((ack_temp == (sendSeqSer_connTb+32'd1)) && (stateSer_connTb == WAITING_CLOSE_STATE)) begin
		stateSer_temp <= CLOSED_STATE;
		event_bitmap_t <= CONN_END_SER;
	end
	else begin
		stateSer_temp <= stateSer_connTb;
		event_bitmap_t <= NONE_STATE;
	end
end

REQUESTED_STATE: begin
	if((tcpFlag_temp[b_ack_flag] == 1'b1) && (ack_temp == (32'd1 + sendSeqSer_connTb))) 
	begin

		stateCli_temp <= ESTABLISHED_STATE;
		sendSeqCli_temp <= seq_temp + {16'b0,length_temp};
		ackSeqCli_temp <= ack_temp;
		winCli_temp <= wind_temp;
		MwinCli_temp <= MwinCli_connTb;

		stateSer_temp <= ESTABLISHED_STATE;
		sendSeqSer_temp <= sendSeqSer_connTb;
		ackSeqSer_temp <= ackSeqSer_connTb;
		winSer_temp <= winSer_connTb;
		MwinSer_temp <= MwinSer_connTb;

		event_bitmap_t <= STATE_CHANGE | CONN_SETUP;

		action <= check_seq_valid(seq_temp, length_temp, ackSeqSer_connTb, winSer_connTb, sendSeqCli_connTb) & 
			check_ack_valid(ack_temp, sendSeqSer_connTb, ack_temp, MwinCli_connTb);


	end
	else if(tcpFlag_temp[b_rst_flag] == 1'b1) begin

		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};

		event_bitmap_t <= STATE_CHANGE | CONN_END_CLI | CONN_END_SER;
		action <= 1'b1;
	end
	else begin
		action <= 1'b0;
	end
end


ESTABLISHED_STATE: begin

	if(tcpFlag_temp[b_fin_flag] == 1'b1)begin

		stateCli_temp <= WAITING_CLOSE_STATE;
		sendSeqCli_temp <= seq_temp + {16'b0,length_temp};


		if((ack_temp > ackSeqCli_connTb) && (tcpFlag_temp[b_ack_flag] == 1'b1))
			ackSeqCli_temp <= ack_temp;
		else 
			ackSeqCli_temp <= ackSeqCli_connTb;
		winCli_temp <= wind_temp;
		MwinCli_temp <= MwinCli_connTb;

		sendSeqSer_temp <= sendSeqSer_connTb; 
		ackSeqSer_temp <= ackSeqSer_connTb;
		winSer_temp <= winSer_connTb;
		MwinSer_temp <= MwinSer_connTb;

		action <= check_seq_valid(seq_temp, length_temp, ackSeqSer_connTb, winSer_connTb, sendSeqCli_connTb);

		if((ack_temp == (sendSeqSer_connTb+32'd1)) && (stateSer_connTb == WAITING_CLOSE_STATE)) begin
			stateSer_temp <= CLOSED_STATE;
			event_bitmap_t <= STATE_CHANGE | CONN_END_SER;
		end
		else begin
			stateSer_temp <= stateSer_connTb;
			event_bitmap_t <= NONE_STATE;
		end
	end

	else if(tcpFlag_temp[b_rst_flag] == 1'b1) begin
		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};

		event_bitmap_t <= STATE_CHANGE | CONN_END_CLI | CONN_END_SER;
		action <= 1'b1;
	end
	else begin

		action <= check_seq_valid(seq_temp, length_temp, ackSeqSer_connTb, winSer_connTb, sendSeqCli_connTb) & 
			check_ack_valid(ack_temp, sendSeqSer_connTb, ackSeqCli_connTb, MwinCli_connTb);

		stateCli_temp <= stateCli_connTb;

		if((({1'b0,seq_temp} + {17'b0,length_temp}) > {1'b0,sendSeqCli_connTb})||
		({seq_temp[31],sendSeqCli_connTb[31]} == 2'b01)) 
			sendSeqCli_temp <= seq_temp + {16'b0,length_temp};
		else
			sendSeqCli_temp <= sendSeqCli_connTb;
		if(((ack_temp > ackSeqCli_connTb)||({ack_temp[31],ackSeqCli_connTb[31]}==2'b01)) 
		&& (tcpFlag_temp[b_ack_flag] == 1'b1)) 
			ackSeqCli_temp <= ack_temp;
		else 
			ackSeqCli_temp <= ackSeqCli_connTb;
		
		winCli_temp <= wind_temp;
		MwinCli_temp <= MwinCli_connTb;

		sendSeqSer_temp <= sendSeqSer_connTb; 
		ackSeqSer_temp <= ackSeqSer_connTb;
		winSer_temp <= winSer_connTb;
		MwinSer_temp <= MwinSer_connTb;

		if((ack_temp == (sendSeqSer_connTb+32'd1)) && (stateSer_connTb == WAITING_CLOSE_STATE))
		begin
			stateSer_temp <= CLOSED_STATE;
			event_bitmap_t <= STATE_CHANGE | CONN_END_SER;
		end
		else begin
			stateSer_temp <= stateSer_connTb;
			event_bitmap_t <= NONE_STATE;
		end
	end
end
WAITING_CLOSE_STATE: begin
	if(tcpFlag_temp[b_rst_flag] == 1'b1) begin
		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};

		event_bitmap_t <= STATE_CHANGE | CONN_END_CLI | CONN_END_SER;

		action <= 1'b1;
	end

	else begin 


		action <= check_seq_valid(seq_temp, length_temp, ackSeqSer_connTb, winSer_connTb, sendSeqCli_connTb) & 
			check_ack_valid(ack_temp, sendSeqSer_connTb, ackSeqCli_connTb, MwinCli_connTb);





		stateCli_temp <= stateCli_connTb;

		if((({1'b0,seq_temp} + {17'b0,length_temp}) > {1'b0,sendSeqCli_connTb})||
		({seq_temp[31],sendSeqCli_connTb[31]} == 2'b01)) 
			sendSeqCli_temp <= seq_temp + {16'b0,length_temp};
		else
			sendSeqCli_temp <= sendSeqCli_connTb;
		if(((ack_temp > ackSeqCli_connTb)||({ack_temp[31],ackSeqCli_connTb[31]}==2'b01)) 
		&& (tcpFlag_temp[b_ack_flag] == 1'b1)) 
			ackSeqCli_temp <= ack_temp;
		else 
			ackSeqCli_temp <= ackSeqCli_connTb;
		winCli_temp <= wind_temp;
		MwinCli_temp <= MwinCli_connTb;

		sendSeqSer_temp <= sendSeqSer_connTb; 
		ackSeqSer_temp <= ackSeqSer_connTb;
		winSer_temp <= winSer_connTb;
		MwinSer_temp <= MwinSer_connTb;

		if((ack_temp == (sendSeqSer_connTb+32'd1)) && (stateSer_connTb == WAITING_CLOSE_STATE)) begin
			stateSer_temp <= CLOSED_STATE;
			event_bitmap_t <= STATE_CHANGE | CONN_END_SER;
		end
		else begin
			stateSer_temp <= stateSer_connTb;
			event_bitmap_t <= NONE_STATE;
		end
	end
end
default: begin

	event_bitmap_t <= NONE_STATE;
	action <= 1'b0;

	{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
		MwinCli_temp,stateSer_temp,sendSeqSer_temp,
		ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};
end
					endcase
				end
				else begin

					case(stateSer_connTb)

CLOSED_STATE: begin

	stateSer_temp <= CLOSED_STATE;
	sendSeqSer_temp <= seq_temp + {16'b0,length_temp};
	ackSeqSer_temp <= ack_temp;
	winSer_temp <= wind_temp;
	MwinSer_temp <= MwinSer_connTb;

	sendSeqCli_temp <= sendSeqCli_connTb;
	ackSeqCli_temp <= ackSeqCli_connTb;
	winCli_temp <= winCli_connTb;
	MwinCli_temp <= MwinCli_connTb;

	action <= check_seq_valid(seq_temp, length_temp, ackSeqCli_connTb, winCli_connTb, sendSeqSer_connTb) & 
		check_ack_valid(ack_temp, sendSeqCli_connTb, ackSeqSer_connTb, MwinSer_connTb);


	if((ack_temp == (sendSeqCli_connTb+32'd1)) && (stateCli_connTb == WAITING_CLOSE_STATE)) begin
		stateCli_temp <= CLOSED_STATE;
		event_bitmap_t <= CONN_END_SER;
	end
	else begin
		stateCli_temp <= stateCli_connTb;
		event_bitmap_t <= NONE_STATE;
	end
end

REQUESTED_STATE: begin
	if((tcpFlag_temp[b_ack_flag] == 1'b1) && (tcpFlag_temp[b_syn_flag] == 1'b1) &&
		(ack_temp == (32'd1 + sendSeqCli_connTb))) 
	begin

		stateSer_temp <= ESTABLISHED_STATE;
		sendSeqSer_temp <= seq_temp;
		ackSeqSer_temp <= ack_temp;
		winSer_temp <= wind_temp;
		MwinSer_temp <= MwinSer_connTb;

		stateCli_temp <= stateCli_connTb;
		sendSeqCli_temp <= sendSeqCli_connTb;
		ackSeqCli_temp <= ackSeqCli_connTb;
		winCli_temp <= winCli_connTb;
		MwinCli_temp <= MwinCli_connTb;

		event_bitmap_t <= STATE_CHANGE;

		action <= 1'b1;


	end
	else if(tcpFlag_temp[b_rst_flag] == 1'b1) begin

		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};

		event_bitmap_t <= STATE_CHANGE | CONN_END_CLI | CONN_END_SER;
		action <= 1'b1;
	end
	else begin
		action <= 1'b0;
	end
end



ESTABLISHED_STATE: begin

	if(tcpFlag_temp[b_fin_flag] == 1'b1)begin

		stateSer_temp <= WAITING_CLOSE_STATE;
		sendSeqSer_temp <= seq_temp + {16'b0,length_temp};

		if((ack_temp > ackSeqSer_connTb) && (tcpFlag_temp[b_ack_flag] == 1'b1))
			ackSeqSer_temp <= ack_temp;
		else 
			ackSeqSer_temp <= ackSeqSer_connTb;
		winSer_temp <= wind_temp;
		MwinSer_temp <= MwinSer_connTb;

		sendSeqCli_temp <= sendSeqCli_connTb; 
		ackSeqCli_temp <= ackSeqCli_connTb;
		winCli_temp <= winCli_connTb;
		MwinCli_temp <= MwinCli_connTb;
		action <= 1'b1;


		if((ack_temp == (sendSeqCli_connTb+32'd1)) && (stateCli_connTb == WAITING_CLOSE_STATE)) begin
			stateCli_temp <= CLOSED_STATE;
			event_bitmap_t <= STATE_CHANGE | CONN_END_SER;
		end
		else begin
			stateCli_temp <= stateCli_connTb;
			event_bitmap_t <= NONE_STATE;
		end
	end

	else if(tcpFlag_temp[b_rst_flag] == 1'b1) begin
		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};

		event_bitmap_t <= STATE_CHANGE | CONN_END_CLI | CONN_END_SER;
		action <= 1'b1;
	end
	else begin

		action <= check_seq_valid(seq_temp, length_temp, ackSeqCli_connTb, winCli_connTb, sendSeqSer_connTb) & 
			check_ack_valid(ack_temp, sendSeqCli_connTb, ackSeqSer_connTb, MwinSer_connTb);

		stateSer_temp <= stateSer_connTb;

		if((({1'b0,seq_temp} + {17'b0,length_temp}) > {1'b0,sendSeqSer_connTb})||
		({seq_temp[31],sendSeqSer_connTb[31]} == 2'b01)) 
			sendSeqSer_temp <= seq_temp + {16'b0,length_temp};
		else
			sendSeqSer_temp <= sendSeqSer_connTb;
		if(((ack_temp > ackSeqSer_connTb)||({ack_temp[31],ackSeqSer_connTb[31]}==2'b01)) 
		&& (tcpFlag_temp[b_ack_flag] == 1'b1)) 
			ackSeqSer_temp <= ack_temp;
		else 
			ackSeqSer_temp <= ackSeqSer_connTb;
		
		winSer_temp <= wind_temp;
		MwinSer_temp <= MwinSer_connTb;

		sendSeqCli_temp <= sendSeqCli_connTb; 
		ackSeqCli_temp <= ackSeqCli_connTb;
		winCli_temp <= winCli_connTb;
		MwinCli_temp <= MwinCli_connTb;

		if((ack_temp == (sendSeqCli_connTb+32'd1)) && (stateCli_connTb == WAITING_CLOSE_STATE))
		begin
			stateCli_temp <= CLOSED_STATE;
			event_bitmap_t <= STATE_CHANGE | CONN_END_SER;
		end
		else begin
			stateCli_temp <= stateCli_connTb;
			event_bitmap_t <= NONE_STATE;
		end
	end
end
WAITING_CLOSE_STATE: begin
	if(tcpFlag_temp[b_rst_flag] == 1'b1) begin
		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};

		event_bitmap_t <= STATE_CHANGE | CONN_END_CLI | CONN_END_SER;
		action <= 1'b1;
	end

	else begin 


		action <= check_seq_valid(seq_temp, length_temp, ackSeqCli_connTb, winCli_connTb, sendSeqSer_connTb) & 
			check_ack_valid(ack_temp, sendSeqCli_connTb, ackSeqSer_connTb, MwinSer_connTb);

		stateSer_temp <= stateSer_connTb;

		if((({1'b0,seq_temp} + {17'b0,length_temp}) > {1'b0,sendSeqSer_connTb})||
		({seq_temp[31],sendSeqSer_connTb[31]} == 2'b01)) 
			sendSeqSer_temp <= seq_temp + {16'b0,length_temp};
		else
			sendSeqSer_temp <= sendSeqSer_connTb;
		if(((ack_temp > ackSeqSer_connTb)||({ack_temp[31],ackSeqSer_connTb[31]}==2'b01)) 
		&& (tcpFlag_temp[b_ack_flag] == 1'b1)) 
			ackSeqSer_temp <= ack_temp;
		else 
			ackSeqSer_temp <= ackSeqSer_connTb;
			
		winSer_temp <= wind_temp;
		MwinSer_temp <= MwinSer_connTb;

		sendSeqCli_temp <= sendSeqCli_connTb; 
		ackSeqCli_temp <= ackSeqCli_connTb;
		winCli_temp <= winCli_connTb;
		MwinCli_temp <= MwinCli_connTb;

		if((ack_temp == (sendSeqCli_connTb+32'd1)) && (stateCli_connTb == WAITING_CLOSE_STATE)) begin
			stateCli_temp <= CLOSED_STATE;
			event_bitmap_t <= STATE_CHANGE | CONN_END_SER;
		end
		else begin
			stateCli_temp <= stateCli_connTb;
			event_bitmap_t <= NONE_STATE;
		end
	end
end
default: begin

	event_bitmap_t <= NONE_STATE;
	action <= 1'b0;

	{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
		MwinCli_temp,stateSer_temp,sendSeqSer_temp,
		ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};
end
					endcase
				end
			end
			else begin
				action <= 1'b0;
				event_bitmap_t <= {w_evb{1'b0}};
				{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
					MwinCli_temp,stateSer_temp,sendSeqSer_temp,
					ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};
			end
		end
		else begin
			action <= 1'b0;
		end
	end
end



always @(posedge clk or negedge reset) begin
	if (!reset) begin
		idx_connTb_conf <= {d_connTb{1'b0}};
		wrValid_connTb_conf <= 1'b0;
		data_connTb_conf <= {w_connTb{1'b0}};
		eventInfo_valid <= 1'b0;
		eventInfo <= {w_eventInfo{1'b0}};
		conn_closed_valid <= 1'b0;
		conn_closed_info <= {w_flowID{1'b0}};
	end
	else begin
		if((action_valid == 1'b1) && (action == 1'b1)) begin

			idx_connTb_conf <= connIdx_info_temp[3][b_idx_connIdxInfo+d_connTb-1:b_idx_connIdxInfo];
			wrValid_connTb_conf <= 1'b1;
			data_connTb_conf[w_connTb-1:b_cliWin_connTb] <= {stateCli_temp,sendSeqCli_temp,
				ackSeqCli_temp,winCli_temp};
			data_connTb_conf[b_cliMaxWin_connTb-1:b_serWin_connTb] <= {stateSer_temp,sendSeqSer_temp,
				ackSeqSer_temp,winSer_temp};
			if(winCli_temp > MwinCli_temp) 
				data_connTb_conf[b_cliWin_connTb-1:b_cliMaxWin_connTb] <= {winCli_temp};
			else
				data_connTb_conf[b_cliWin_connTb-1:b_cliMaxWin_connTb] <= {MwinCli_temp};
			if(winSer_temp > MwinSer_temp) 
				data_connTb_conf[b_serWin_connTb-1:b_serMaxWin_connTb] <= {winSer_temp};
			else
				data_connTb_conf[b_serWin_connTb-1:b_serMaxWin_connTb] <= {MwinSer_temp};

			if((event_bitmap_t == STATE_CHANGE) && (stateCli_temp == CLOSED_STATE) && 
				(stateSer_temp == CLOSED_STATE))
			begin
				conn_closed_valid <= 1'b1;
				conn_closed_info <= connIdx_info_temp[3][b_idx_connIdxInfo+d_connTb-1:b_idx_connIdxInfo];
			end
		end
		else begin
			wrValid_connTb_conf <= 1'b0;
			conn_closed_valid <= 1'b0;
		end
		eventInfo_valid <= action_valid;
		eventInfo <= {event_bitmap_t, stateCli_temp, stateSer_temp};
	end
end


function	check_seq_valid;
input	[31:0]	seq_temp;
input	[15:0]	length_temp;
input	[31:0]	ackSeqO_connTb;
input	[15:0]	winO_connTb;
input	[31:0]	seq_connTb;
begin

	check_seq_valid = (({seq_temp[31],ackSeqO_connTb[31]} == 2'b01) || 
		({seq_temp[31],seq_connTb[31]} == 2'b01) || 
		((({1'd0,seq_temp} + {17'b0,length_temp}) <= ({1'b0,ackSeqO_connTb} + 
			{10'd0,winO_connTb,7'd0} + 33'd1)) && 
			({1'd1,seq_temp} >= ({1'd1,seq_connTb} -  {10'd0,winO_connTb,7'd0} - 33'd1))))? 1'b1:1'b0;
	
end
endfunction

function	check_ack_valid;
input	[31:0]	ack_temp;
input	[31:0]	seqO_connTb;
input	[31:0]	ackSeq_connTb;
input	[15:0]	Mwin_connTb;
begin

	check_ack_valid = (({ack_temp[31],seqO_connTb[31]} == 2'b10) || 
		(({1'b0,ack_temp} <= ({1'b0,seqO_connTb} +33'd1)) &&
			({1'd1,ack_temp} >= ({1'd1,seqO_connTb} - {10'b0,Mwin_connTb,7'd0}) - 33'd1)))? 1'b1:1'b0;
end
endfunction



									

endmodule
module lookup_connTb(
clk,
reset,
metadata_in_valid,
metadata_in,
conn_idx_valid,
conn_idx_info,
idx_connTb_search,
idx_connTb_conf,
rdValid_connTb_search,
wrValid_connTb_conf,
data_connTb_conf,
ctx_connTb_search,
action_valid,
action,
eventInfo_valid,
eventInfo,
conn_closed_valid,
conn_closed_info
);





parameter 	w_meta = 104,

			w_eventInfo = 16,

			w_evb = 8,
			w_connTb = 200,



			d_connTb = 3,
			w_state = 4,
			w_seq = 32,
			w_window = 16,
			w_length = 16,
			w_tcpFlag = 8,
			w_flowID = 16,
			w_ip = 32,
			w_connIdx_info = 19,


			d_metaBuffer = 5,
			words_metaBuffer = 32,
			

			b_length_meta = 88,
			b_tcpFlag_meta = 80,
			b_sendSeq_meta = 48,
			b_ackSeq_meta = 16,
			b_window_meta = 0,

			b_hit_connIdxInfo = 18,
			b_add_connIdxInfo = 17,
			b_dir_connIdxInfo = 16,
			b_idx_connIdxInfo = 0,

			b_cliState_connTb = 196,
			b_cliSendSeq_connTb = 164,
			b_cliAckSeq_connTb = 132,
			b_cliWin_connTb = 116,
			b_cliMaxWin_connTb = 100,
			b_serState_connTb = 96,
			b_serSendSeq_connTb = 64,
			b_serAckSeq_connTb = 32,
			b_serWin_connTb = 16,
			b_serMaxWin_connTb = 0,


			NONE_STATE = 8'd0,
			NEW_FLOW = 8'd1,
			HALF_CONN = 8'd2,
			CONN_SETUP = 8'd4,
			TIME_OUT = 8'd8,
			CONN_END_CLI = 8'd16,
			CONN_END_SER = 8'd32,
			STATE_CHANGE = 8'd128,
			

			CLOSED_STATE = 4'd0,
			REQUESTED_STATE = 4'd1,
			ESTABLISHED_STATE = 4'd2,
			WAITING_CLOSE_STATE = 4'd3,
			
			DEFAULT_SEQ = 32'b0,

			b_fin_flag = 0,
			b_syn_flag = 1,
			b_rst_flag = 2,
			b_ack_flag = 4,
			ONLY_FIN = 8'h01,
			ONLY_SYN = 8'h02,
			ONLY_RST = 8'h04,
			ONLY_ACK = 8'h10;

input								clk;
input								reset;
input								metadata_in_valid;
input		[w_meta-1:0]			metadata_in;
input								conn_idx_valid;
input		[w_connIdx_info-1:0]	conn_idx_info;
output	reg	[d_connTb-1:0]			idx_connTb_search;
output	reg	[d_connTb-1:0]			idx_connTb_conf;
output	reg							rdValid_connTb_search;
output	reg							wrValid_connTb_conf;
output	reg	[w_connTb-1:0]			data_connTb_conf;
input		[w_connTb-1:0]			ctx_connTb_search;
output	reg 							action_valid;
output	reg 							action;
output	reg 							eventInfo_valid;
output	reg 	[w_eventInfo-1:0]		eventInfo;
output 	reg 							conn_closed_valid;
output 	reg 	[w_flowID-1:0]			conn_closed_info;




reg 									valid_temp[3:0];
reg			[w_connIdx_info-1:0]	connIdx_info_temp[3:0];
reg 			[w_meta-1:0]			meta_temp[3:0];


wire								empty_meta;
wire		[w_meta-1:0]			ctx_meta;


wire		[w_state-1:0]			stateCli_connTb,stateSer_connTb;
wire		[w_seq-1:0]				sendSeqCli_connTb, sendSeqSer_connTb;
wire		[w_seq-1:0]				ackSeqCli_connTb, ackSeqSer_connTb;
wire		[w_window-1:0]		winCli_connTb, winSer_connTb;
wire		[w_window-1:0]		MwinCli_connTb, MwinSer_connTb;
reg			[w_state-1:0]			stateCli_temp, stateSer_temp;
reg			[w_seq-1:0]				sendSeqCli_temp, sendSeqSer_temp;
reg			[w_seq-1:0]				ackSeqCli_temp, ackSeqSer_temp;
reg			[w_window-1:0]		winCli_temp, winSer_temp;
reg			[w_window-1:0]		MwinCli_temp, MwinSer_temp;
reg 			[w_seq-1:0]				seq_temp, ack_temp;
reg 			[w_length-1:0]			length_temp;
reg 			[w_window-1:0]		wind_temp;
reg 			[w_tcpFlag-1:0]			tcpFlag_temp;


reg			[w_evb-1:0]				event_bitmap_t;









fifo meta_buffer(
.aclr(!reset),
.clock(clk),
.data(metadata_in),
.rdreq(conn_idx_valid),
.wrreq(metadata_in_valid),
.empty(empty_meta),
.full(),
.q(ctx_meta),
.usedw()
);
defparam
	meta_buffer.width = w_meta,
	meta_buffer.depth = d_metaBuffer,
	meta_buffer.words = words_metaBuffer;



integer	i, j;
always @(posedge clk or negedge reset) begin
	if (!reset) begin
		idx_connTb_search <= {d_connTb{1'b0}};
		rdValid_connTb_search <= 1'b0;
		
		for(i = 0; i < 4; i = i+1) begin
			valid_temp[i] <= 1'b0;
			connIdx_info_temp[i] <= {w_connIdx_info{1'b0}};
			meta_temp[i] <= {w_meta{1'b0}};
		end
	end
	else begin
		if(conn_idx_valid == 1'b1) begin
			valid_temp[0] <= 1'b1;
			meta_temp[0] <= ctx_meta;
			connIdx_info_temp[0] <= conn_idx_info;
			rdValid_connTb_search <= 1'b1;
			idx_connTb_search <= conn_idx_info[b_idx_connIdxInfo+d_connTb-1:
				b_idx_connIdxInfo];
		end
		else begin
			valid_temp[0] <= 1'b0;
			meta_temp[0] <= {w_meta{1'b0}};
			connIdx_info_temp[0] <= {w_connIdx_info{1'b0}};
			rdValid_connTb_search <= 1'b0;
		end

		for(j = 0; j < 3; j = j+1) begin
			valid_temp[j+1] <= valid_temp[j];
			connIdx_info_temp[j+1] <= connIdx_info_temp[j];
			meta_temp[j+1] <= meta_temp[j];
		end
	end
end



always @(posedge clk or negedge reset) begin
	if (!reset) begin
		{length_temp,tcpFlag_temp,seq_temp,ack_temp,wind_temp}  <= {w_meta{1'b0}};
	end
	else begin
		{length_temp,tcpFlag_temp,seq_temp,ack_temp,wind_temp}  <= meta_temp[1];
	end
end


assign {stateCli_connTb, sendSeqCli_connTb, ackSeqCli_connTb, winCli_connTb,
		MwinCli_connTb, stateSer_connTb, sendSeqSer_connTb, ackSeqSer_connTb, 
		winSer_connTb, MwinSer_connTb} = ctx_connTb_search;

always @(posedge clk or negedge reset) begin
	if (!reset) begin
		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};
		event_bitmap_t <= {w_evb{1'b0}};
		action_valid <=1 'b0;
		action <= 1'b0;
	end
	else begin
		action_valid <= valid_temp[2];
		if(valid_temp[2] == 1'b1) begin
			if(connIdx_info_temp[2][b_add_connIdxInfo] == 1'b1) begin

				stateCli_temp <= REQUESTED_STATE;
				sendSeqCli_temp <= seq_temp;
				ackSeqCli_temp <= 32'b0;
				winCli_temp <= wind_temp;
				MwinCli_temp <= {w_window{1'b0}};

				stateSer_temp <= REQUESTED_STATE;
				sendSeqSer_temp <= {w_seq{1'b0}}; 
				ackSeqSer_temp <= {w_seq{1'b0}};
				winSer_temp <= {w_window{1'b0}};
				MwinSer_temp <= {w_window{1'b0}};

				event_bitmap_t <= NEW_FLOW | STATE_CHANGE;

				action <= 1'b1;
			end

			else if (connIdx_info_temp[2][b_hit_connIdxInfo] == 1'b1) begin 

				if(connIdx_info_temp[2][b_dir_connIdxInfo] == 1'b0) begin

					case(stateCli_connTb)

CLOSED_STATE: begin

	stateCli_temp <= CLOSED_STATE;
	sendSeqCli_temp <= seq_temp + {16'b0,length_temp};
	ackSeqCli_temp <= ack_temp;
	winCli_temp <= wind_temp;
	MwinCli_temp <= MwinCli_connTb;

	sendSeqSer_temp <= sendSeqSer_connTb;
	ackSeqSer_temp <= ackSeqSer_connTb;
	winSer_temp <= winSer_connTb;
	MwinSer_temp <= MwinSer_connTb;

	action <= check_seq_valid(seq_temp, length_temp, ackSeqSer_connTb, winSer_connTb, sendSeqCli_connTb) & 
		check_ack_valid(ack_temp, sendSeqSer_connTb, ackSeqCli_connTb, MwinCli_connTb);


	if((ack_temp == (sendSeqSer_connTb+32'd1)) && (stateSer_connTb == WAITING_CLOSE_STATE)) begin
		stateSer_temp <= CLOSED_STATE;
		event_bitmap_t <= CONN_END_SER;
	end
	else begin
		stateSer_temp <= stateSer_connTb;
		event_bitmap_t <= NONE_STATE;
	end
end

REQUESTED_STATE: begin
	if((tcpFlag_temp[b_ack_flag] == 1'b1) && (ack_temp == (32'd1 + sendSeqSer_connTb))) 
	begin

		stateCli_temp <= ESTABLISHED_STATE;
		sendSeqCli_temp <= seq_temp + {16'b0,length_temp};
		ackSeqCli_temp <= ack_temp;
		winCli_temp <= wind_temp;
		MwinCli_temp <= MwinCli_connTb;

		stateSer_temp <= ESTABLISHED_STATE;
		sendSeqSer_temp <= sendSeqSer_connTb;
		ackSeqSer_temp <= ackSeqSer_connTb;
		winSer_temp <= winSer_connTb;
		MwinSer_temp <= MwinSer_connTb;

		event_bitmap_t <= STATE_CHANGE | CONN_SETUP;

		action <= check_seq_valid(seq_temp, length_temp, ackSeqSer_connTb, winSer_connTb, sendSeqCli_connTb) & 
			check_ack_valid(ack_temp, sendSeqSer_connTb, ack_temp, MwinCli_connTb);


	end
	else if(tcpFlag_temp[b_rst_flag] == 1'b1) begin

		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};

		event_bitmap_t <= STATE_CHANGE | CONN_END_CLI | CONN_END_SER;
		action <= 1'b1;
	end
	else begin
		action <= 1'b0;
	end
end


ESTABLISHED_STATE: begin

	if(tcpFlag_temp[b_fin_flag] == 1'b1)begin

		stateCli_temp <= WAITING_CLOSE_STATE;
		sendSeqCli_temp <= seq_temp + {16'b0,length_temp};


		if((ack_temp > ackSeqCli_connTb) && (tcpFlag_temp[b_ack_flag] == 1'b1))
			ackSeqCli_temp <= ack_temp;
		else 
			ackSeqCli_temp <= ackSeqCli_connTb;
		winCli_temp <= wind_temp;
		MwinCli_temp <= MwinCli_connTb;

		sendSeqSer_temp <= sendSeqSer_connTb; 
		ackSeqSer_temp <= ackSeqSer_connTb;
		winSer_temp <= winSer_connTb;
		MwinSer_temp <= MwinSer_connTb;

		action <= check_seq_valid(seq_temp, length_temp, ackSeqSer_connTb, winSer_connTb, sendSeqCli_connTb);

		if((ack_temp == (sendSeqSer_connTb+32'd1)) && (stateSer_connTb == WAITING_CLOSE_STATE)) begin
			stateSer_temp <= CLOSED_STATE;
			event_bitmap_t <= STATE_CHANGE | CONN_END_SER;
		end
		else begin
			stateSer_temp <= stateSer_connTb;
			event_bitmap_t <= NONE_STATE;
		end
	end

	else if(tcpFlag_temp[b_rst_flag] == 1'b1) begin
		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};

		event_bitmap_t <= STATE_CHANGE | CONN_END_CLI | CONN_END_SER;
		action <= 1'b1;
	end
	else begin

		action <= check_seq_valid(seq_temp, length_temp, ackSeqSer_connTb, winSer_connTb, sendSeqCli_connTb) & 
			check_ack_valid(ack_temp, sendSeqSer_connTb, ackSeqCli_connTb, MwinCli_connTb);

		stateCli_temp <= stateCli_connTb;

		if((({1'b0,seq_temp} + {17'b0,length_temp}) > {1'b0,sendSeqCli_connTb})||
		({seq_temp[31],sendSeqCli_connTb[31]} == 2'b01)) 
			sendSeqCli_temp <= seq_temp + {16'b0,length_temp};
		else
			sendSeqCli_temp <= sendSeqCli_connTb;
		if(((ack_temp > ackSeqCli_connTb)||({ack_temp[31],ackSeqCli_connTb[31]}==2'b01)) 
		&& (tcpFlag_temp[b_ack_flag] == 1'b1)) 
			ackSeqCli_temp <= ack_temp;
		else 
			ackSeqCli_temp <= ackSeqCli_connTb;
		
		winCli_temp <= wind_temp;
		MwinCli_temp <= MwinCli_connTb;

		sendSeqSer_temp <= sendSeqSer_connTb; 
		ackSeqSer_temp <= ackSeqSer_connTb;
		winSer_temp <= winSer_connTb;
		MwinSer_temp <= MwinSer_connTb;

		if((ack_temp == (sendSeqSer_connTb+32'd1)) && (stateSer_connTb == WAITING_CLOSE_STATE))
		begin
			stateSer_temp <= CLOSED_STATE;
			event_bitmap_t <= STATE_CHANGE | CONN_END_SER;
		end
		else begin
			stateSer_temp <= stateSer_connTb;
			event_bitmap_t <= NONE_STATE;
		end
	end
end
WAITING_CLOSE_STATE: begin
	if(tcpFlag_temp[b_rst_flag] == 1'b1) begin
		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};

		event_bitmap_t <= STATE_CHANGE | CONN_END_CLI | CONN_END_SER;

		action <= 1'b1;
	end

	else begin 


		action <= check_seq_valid(seq_temp, length_temp, ackSeqSer_connTb, winSer_connTb, sendSeqCli_connTb) & 
			check_ack_valid(ack_temp, sendSeqSer_connTb, ackSeqCli_connTb, MwinCli_connTb);





		stateCli_temp <= stateCli_connTb;

		if((({1'b0,seq_temp} + {17'b0,length_temp}) > {1'b0,sendSeqCli_connTb})||
		({seq_temp[31],sendSeqCli_connTb[31]} == 2'b01)) 
			sendSeqCli_temp <= seq_temp + {16'b0,length_temp};
		else
			sendSeqCli_temp <= sendSeqCli_connTb;
		if(((ack_temp > ackSeqCli_connTb)||({ack_temp[31],ackSeqCli_connTb[31]}==2'b01)) 
		&& (tcpFlag_temp[b_ack_flag] == 1'b1)) 
			ackSeqCli_temp <= ack_temp;
		else 
			ackSeqCli_temp <= ackSeqCli_connTb;
		winCli_temp <= wind_temp;
		MwinCli_temp <= MwinCli_connTb;

		sendSeqSer_temp <= sendSeqSer_connTb; 
		ackSeqSer_temp <= ackSeqSer_connTb;
		winSer_temp <= winSer_connTb;
		MwinSer_temp <= MwinSer_connTb;

		if((ack_temp == (sendSeqSer_connTb+32'd1)) && (stateSer_connTb == WAITING_CLOSE_STATE)) begin
			stateSer_temp <= CLOSED_STATE;
			event_bitmap_t <= STATE_CHANGE | CONN_END_SER;
		end
		else begin
			stateSer_temp <= stateSer_connTb;
			event_bitmap_t <= NONE_STATE;
		end
	end
end
default: begin

	event_bitmap_t <= NONE_STATE;
	action <= 1'b0;

	{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
		MwinCli_temp,stateSer_temp,sendSeqSer_temp,
		ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};
end
					endcase
				end
				else begin

					case(stateSer_connTb)

CLOSED_STATE: begin

	stateSer_temp <= CLOSED_STATE;
	sendSeqSer_temp <= seq_temp + {16'b0,length_temp};
	ackSeqSer_temp <= ack_temp;
	winSer_temp <= wind_temp;
	MwinSer_temp <= MwinSer_connTb;

	sendSeqCli_temp <= sendSeqCli_connTb;
	ackSeqCli_temp <= ackSeqCli_connTb;
	winCli_temp <= winCli_connTb;
	MwinCli_temp <= MwinCli_connTb;

	action <= check_seq_valid(seq_temp, length_temp, ackSeqCli_connTb, winCli_connTb, sendSeqSer_connTb) & 
		check_ack_valid(ack_temp, sendSeqCli_connTb, ackSeqSer_connTb, MwinSer_connTb);


	if((ack_temp == (sendSeqCli_connTb+32'd1)) && (stateCli_connTb == WAITING_CLOSE_STATE)) begin
		stateCli_temp <= CLOSED_STATE;
		event_bitmap_t <= CONN_END_SER;
	end
	else begin
		stateCli_temp <= stateCli_connTb;
		event_bitmap_t <= NONE_STATE;
	end
end

REQUESTED_STATE: begin
	if((tcpFlag_temp[b_ack_flag] == 1'b1) && (tcpFlag_temp[b_syn_flag] == 1'b1) &&
		(ack_temp == (32'd1 + sendSeqCli_connTb))) 
	begin

		stateSer_temp <= ESTABLISHED_STATE;
		sendSeqSer_temp <= seq_temp;
		ackSeqSer_temp <= ack_temp;
		winSer_temp <= wind_temp;
		MwinSer_temp <= MwinSer_connTb;

		stateCli_temp <= stateCli_connTb;
		sendSeqCli_temp <= sendSeqCli_connTb;
		ackSeqCli_temp <= ackSeqCli_connTb;
		winCli_temp <= winCli_connTb;
		MwinCli_temp <= MwinCli_connTb;

		event_bitmap_t <= STATE_CHANGE;

		action <= 1'b1;


	end
	else if(tcpFlag_temp[b_rst_flag] == 1'b1) begin

		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};

		event_bitmap_t <= STATE_CHANGE | CONN_END_CLI | CONN_END_SER;
		action <= 1'b1;
	end
	else begin
		action <= 1'b0;
	end
end



ESTABLISHED_STATE: begin

	if(tcpFlag_temp[b_fin_flag] == 1'b1)begin

		stateSer_temp <= WAITING_CLOSE_STATE;
		sendSeqSer_temp <= seq_temp + {16'b0,length_temp};

		if((ack_temp > ackSeqSer_connTb) && (tcpFlag_temp[b_ack_flag] == 1'b1))
			ackSeqSer_temp <= ack_temp;
		else 
			ackSeqSer_temp <= ackSeqSer_connTb;
		winSer_temp <= wind_temp;
		MwinSer_temp <= MwinSer_connTb;

		sendSeqCli_temp <= sendSeqCli_connTb; 
		ackSeqCli_temp <= ackSeqCli_connTb;
		winCli_temp <= winCli_connTb;
		MwinCli_temp <= MwinCli_connTb;
		action <= 1'b1;


		if((ack_temp == (sendSeqCli_connTb+32'd1)) && (stateCli_connTb == WAITING_CLOSE_STATE)) begin
			stateCli_temp <= CLOSED_STATE;
			event_bitmap_t <= STATE_CHANGE | CONN_END_SER;
		end
		else begin
			stateCli_temp <= stateCli_connTb;
			event_bitmap_t <= NONE_STATE;
		end
	end

	else if(tcpFlag_temp[b_rst_flag] == 1'b1) begin
		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};

		event_bitmap_t <= STATE_CHANGE | CONN_END_CLI | CONN_END_SER;
		action <= 1'b1;
	end
	else begin

		action <= check_seq_valid(seq_temp, length_temp, ackSeqCli_connTb, winCli_connTb, sendSeqSer_connTb) & 
			check_ack_valid(ack_temp, sendSeqCli_connTb, ackSeqSer_connTb, MwinSer_connTb);

		stateSer_temp <= stateSer_connTb;

		if((({1'b0,seq_temp} + {17'b0,length_temp}) > {1'b0,sendSeqSer_connTb})||
		({seq_temp[31],sendSeqSer_connTb[31]} == 2'b01)) 
			sendSeqSer_temp <= seq_temp + {16'b0,length_temp};
		else
			sendSeqSer_temp <= sendSeqSer_connTb;
		if(((ack_temp > ackSeqSer_connTb)||({ack_temp[31],ackSeqSer_connTb[31]}==2'b01)) 
		&& (tcpFlag_temp[b_ack_flag] == 1'b1)) 
			ackSeqSer_temp <= ack_temp;
		else 
			ackSeqSer_temp <= ackSeqSer_connTb;
		
		winSer_temp <= wind_temp;
		MwinSer_temp <= MwinSer_connTb;

		sendSeqCli_temp <= sendSeqCli_connTb; 
		ackSeqCli_temp <= ackSeqCli_connTb;
		winCli_temp <= winCli_connTb;
		MwinCli_temp <= MwinCli_connTb;

		if((ack_temp == (sendSeqCli_connTb+32'd1)) && (stateCli_connTb == WAITING_CLOSE_STATE))
		begin
			stateCli_temp <= CLOSED_STATE;
			event_bitmap_t <= STATE_CHANGE | CONN_END_SER;
		end
		else begin
			stateCli_temp <= stateCli_connTb;
			event_bitmap_t <= NONE_STATE;
		end
	end
end
WAITING_CLOSE_STATE: begin
	if(tcpFlag_temp[b_rst_flag] == 1'b1) begin
		{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
			MwinCli_temp,stateSer_temp,sendSeqSer_temp,
			ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};

		event_bitmap_t <= STATE_CHANGE | CONN_END_CLI | CONN_END_SER;
		action <= 1'b1;
	end

	else begin 


		action <= check_seq_valid(seq_temp, length_temp, ackSeqCli_connTb, winCli_connTb, sendSeqSer_connTb) & 
			check_ack_valid(ack_temp, sendSeqCli_connTb, ackSeqSer_connTb, MwinSer_connTb);

		stateSer_temp <= stateSer_connTb;

		if((({1'b0,seq_temp} + {17'b0,length_temp}) > {1'b0,sendSeqSer_connTb})||
		({seq_temp[31],sendSeqSer_connTb[31]} == 2'b01)) 
			sendSeqSer_temp <= seq_temp + {16'b0,length_temp};
		else
			sendSeqSer_temp <= sendSeqSer_connTb;
		if(((ack_temp > ackSeqSer_connTb)||({ack_temp[31],ackSeqSer_connTb[31]}==2'b01)) 
		&& (tcpFlag_temp[b_ack_flag] == 1'b1)) 
			ackSeqSer_temp <= ack_temp;
		else 
			ackSeqSer_temp <= ackSeqSer_connTb;
			
		winSer_temp <= wind_temp;
		MwinSer_temp <= MwinSer_connTb;

		sendSeqCli_temp <= sendSeqCli_connTb; 
		ackSeqCli_temp <= ackSeqCli_connTb;
		winCli_temp <= winCli_connTb;
		MwinCli_temp <= MwinCli_connTb;

		if((ack_temp == (sendSeqCli_connTb+32'd1)) && (stateCli_connTb == WAITING_CLOSE_STATE)) begin
			stateCli_temp <= CLOSED_STATE;
			event_bitmap_t <= STATE_CHANGE | CONN_END_SER;
		end
		else begin
			stateCli_temp <= stateCli_connTb;
			event_bitmap_t <= NONE_STATE;
		end
	end
end
default: begin

	event_bitmap_t <= NONE_STATE;
	action <= 1'b0;

	{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
		MwinCli_temp,stateSer_temp,sendSeqSer_temp,
		ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};
end
					endcase
				end
			end
			else begin
				action <= 1'b0;
				event_bitmap_t <= {w_evb{1'b0}};
				{stateCli_temp,sendSeqCli_temp,ackSeqCli_temp,winCli_temp,
					MwinCli_temp,stateSer_temp,sendSeqSer_temp,
					ackSeqSer_temp,winSer_temp,MwinSer_temp} <= {w_connTb{1'b0}};
			end
		end
		else begin
			action <= 1'b0;
		end
	end
end



always @(posedge clk or negedge reset) begin
	if (!reset) begin
		idx_connTb_conf <= {d_connTb{1'b0}};
		wrValid_connTb_conf <= 1'b0;
		data_connTb_conf <= {w_connTb{1'b0}};
		eventInfo_valid <= 1'b0;
		eventInfo <= {w_eventInfo{1'b0}};
		conn_closed_valid <= 1'b0;
		conn_closed_info <= {w_flowID{1'b0}};
	end
	else begin
		if((action_valid == 1'b1) && (action == 1'b1)) begin

			idx_connTb_conf <= connIdx_info_temp[3][b_idx_connIdxInfo+d_connTb-1:b_idx_connIdxInfo];
			wrValid_connTb_conf <= 1'b1;
			data_connTb_conf[w_connTb-1:b_cliWin_connTb] <= {stateCli_temp,sendSeqCli_temp,
				ackSeqCli_temp,winCli_temp};
			data_connTb_conf[b_cliMaxWin_connTb-1:b_serWin_connTb] <= {stateSer_temp,sendSeqSer_temp,
				ackSeqSer_temp,winSer_temp};
			if(winCli_temp > MwinCli_temp) 
				data_connTb_conf[b_cliWin_connTb-1:b_cliMaxWin_connTb] <= {winCli_temp};
			else
				data_connTb_conf[b_cliWin_connTb-1:b_cliMaxWin_connTb] <= {MwinCli_temp};
			if(winSer_temp > MwinSer_temp) 
				data_connTb_conf[b_serWin_connTb-1:b_serMaxWin_connTb] <= {winSer_temp};
			else
				data_connTb_conf[b_serWin_connTb-1:b_serMaxWin_connTb] <= {MwinSer_temp};

			if((event_bitmap_t == STATE_CHANGE) && (stateCli_temp == CLOSED_STATE) && 
				(stateSer_temp == CLOSED_STATE))
			begin
				conn_closed_valid <= 1'b1;
				conn_closed_info <= connIdx_info_temp[3][b_idx_connIdxInfo+d_connTb-1:b_idx_connIdxInfo];
			end
		end
		else begin
			wrValid_connTb_conf <= 1'b0;
			conn_closed_valid <= 1'b0;
		end
		eventInfo_valid <= action_valid;
		eventInfo <= {event_bitmap_t, stateCli_temp, stateSer_temp};
	end
end


function	check_seq_valid;
input	[31:0]	seq_temp;
input	[15:0]	length_temp;
input	[31:0]	ackSeqO_connTb;
input	[15:0]	winO_connTb;
input	[31:0]	seq_connTb;
begin

	check_seq_valid = (({seq_temp[31],ackSeqO_connTb[31]} == 2'b01) || 
		({seq_temp[31],seq_connTb[31]} == 2'b01) || 
		((({1'd0,seq_temp} + {17'b0,length_temp}) <= ({1'b0,ackSeqO_connTb} + 
			{10'd0,winO_connTb,7'd0} + 33'd1)) && 
			({1'd1,seq_temp} >= ({1'd1,seq_connTb} -  {10'd0,winO_connTb,7'd0} - 33'd1))))? 1'b1:1'b0;
	
end
endfunction

function	check_ack_valid;
input	[31:0]	ack_temp;
input	[31:0]	seqO_connTb;
input	[31:0]	ackSeq_connTb;
input	[15:0]	Mwin_connTb;
begin

	check_ack_valid = (({ack_temp[31],seqO_connTb[31]} == 2'b10) || 
		(({1'b0,ack_temp} <= ({1'b0,seqO_connTb} +33'd1)) &&
			({1'd1,ack_temp} >= ({1'd1,seqO_connTb} - {10'b0,Mwin_connTb,7'd0}) - 33'd1)))? 1'b1:1'b0;
end
endfunction



									

endmodule