@@ -20,16 +20,30 @@ module Tcp
20
20
input newpkt,
21
21
input dataValid,
22
22
input [7 :0 ] data,
23
- input [15 :0 ] tcp_src_port,
24
- input [31 :0 ] tcp_src_ip,
25
- input [15 :0 ] tcp_dst_port,
26
- input [31 :0 ] tcp_dst_ip,
27
23
28
- output reg outDataValid = 0 ,
24
+ // per session
25
+ input [15 :0 ] tcpA_src_port,
26
+ input [31 :0 ] tcpA_src_ip,
27
+ input [15 :0 ] tcpA_dst_port,
28
+ input [31 :0 ] tcpA_dst_ip,
29
+
30
+ input [15 :0 ] tcpB_src_port,
31
+ input [31 :0 ] tcpB_src_ip,
32
+ input [15 :0 ] tcpB_dst_port,
33
+ input [31 :0 ] tcpB_dst_ip,
34
+
29
35
output reg [7 :0 ] outData = 0 ,
36
+ output reg outDataPayload = 0 ,
37
+ output reg outDataMatchA = 0 ,
38
+ output reg outDataMatchB = 0 ,
39
+
30
40
output reg outnewpkt = 0 ,
31
41
output reg [7 :0 ] mss = 0 ,
32
- output reg gapped = 0
42
+ output reg gappedA = 0 ,
43
+ output reg gappedB = 0 ,
44
+
45
+ output tcp_matchA,
46
+ output tcp_matchB
33
47
);
34
48
35
49
localparam [6 :0 ] sIDLE = 6'd000 ;
@@ -160,16 +174,26 @@ module Tcp
160
174
reg tcpFlagFIN = 0 ;
161
175
reg [15 :0 ] tcpData = 0 ;
162
176
reg [3 :0 ] tcpDataOff = 0 ;
163
- reg [31 :0 ] tcpSeq = 0 ;
164
177
reg [31 :0 ] tcpSeqBuf = 0 ;
165
178
179
+ reg [31 :0 ] tcpSeqA = 0 ;
180
+ reg [31 :0 ] tcpSeqB = 0 ;
181
+
166
182
// we don't need to reset these in sIDLE as they are asigned before tcp_matches is read
167
- reg ms0 = 0 ,ms1 = 0 ,ms2 = 0 ,ms3 = 0 ,ms4 = 0 ,ms5 = 0 ; // match src ip+port
168
- reg md0 = 0 ,md1 = 0 ,md2 = 0 ,md3 = 0 ,md4 = 0 ,md5 = 0 ; // match src ip+port
169
- reg me0 = 0 ,me1 = 0 ,me2 = 0 ,me3 = 0 ,me4 = 0 ,me5 = 0 ; // match src MAC
183
+ reg [ 5 : 0 ] msa = 0 ; // match src ip+port
184
+ reg [ 5 : 0 ] mda = 0 ; // match src ip+port
185
+ // reg [5:0] mea =0; // match src MAC
170
186
171
- wire tcp_matches = ms0 && ms1 && ms2 && ms3 && ms4 && ms5 &&
172
- md0 && md1 && md2 && md3 && md4 && md5;
187
+ reg [5 :0 ] msb= 0 ; // match src ip+port
188
+ reg [5 :0 ] mdb= 0 ; // match src ip+port
189
+ // reg [5:0] meb=0; // match src MAC
190
+
191
+ // reg msb0=0,msb1=0,msb2=0,msb3=0,msb4=0,msb5=0; // match src ip+port
192
+ // reg mdb0=0,mdb1=0,mdb2=0,mdb3=0,mdb4=0,mdb5=0; // match src ip+port
193
+ // reg meb0=0,meb1=0,meb2=0,meb3=0,meb4=0,meb5=0; // match src MAC
194
+
195
+ wire tcp_matchA = (& msa) && (& mda);
196
+ wire tcp_matchB = (& msb) && (& mdb);
173
197
174
198
// counters
175
199
reg [7 :0 ] counterEthTypeARP = 0 ;
@@ -293,32 +317,39 @@ module Tcp
293
317
sIPV4_IPSRC0: begin
294
318
pos <= sIPV4_IPSRC1;
295
319
IPV4_IHeaderLen <= IPV4_IHeaderLen - 1 ; // pipelined sub4 4bytes
296
- ms0 <= (data == tcp_src_ip[31 :24 ]);
320
+ msa[0 ] <= (data == tcpA_src_ip[31 :24 ]);
321
+ msb[0 ] <= (data == tcpB_src_ip[31 :24 ]);
297
322
end
298
323
sIPV4_IPSRC1: begin
299
324
pos <= sIPV4_IPSRC2;
300
- ms1 <= (data == tcp_src_ip[23 :16 ]);
325
+ msa[1 ] <= (data == tcpA_src_ip[23 :16 ]);
326
+ msb[1 ] <= (data == tcpB_src_ip[23 :16 ]);
301
327
end
302
328
sIPV4_IPSRC2: begin
303
329
pos <= sIPV4_IPSRC3;
304
- ms2 <= (data == tcp_src_ip[15 :8 ]);
330
+ msa[2 ] <= (data == tcpA_src_ip[15 :8 ]);
331
+ msb[2 ] <= (data == tcpB_src_ip[15 :8 ]);
305
332
end
306
333
sIPV4_IPSRC3: begin
307
334
pos <= sIPV4_IPDST0;
308
- ms3 <= (data == tcp_src_ip[7 :0 ]);
335
+ msa[3 ] <= (data == tcpA_src_ip[7 :0 ]);
336
+ msb[3 ] <= (data == tcpB_src_ip[7 :0 ]);
309
337
end
310
338
sIPV4_IPDST0: begin
311
339
pos <= sIPV4_IPDST1;
312
340
IPV4_IHeaderLen <= IPV4_IHeaderLen - 1 ; // pipelined sub5 4bytes
313
- md0 <= (data == tcp_dst_ip[31 :24 ]);
341
+ mda[0 ] <= (data == tcpA_dst_ip[31 :24 ]);
342
+ mdb[0 ] <= (data == tcpB_dst_ip[31 :24 ]);
314
343
end
315
344
sIPV4_IPDST1: begin
316
345
pos <= sIPV4_IPDST2;
317
- md1 <= (data == tcp_dst_ip[23 :16 ]);
346
+ mda[1 ] <= (data == tcpA_dst_ip[23 :16 ]);
347
+ mdb[1 ] <= (data == tcpB_dst_ip[23 :16 ]);
318
348
end
319
349
sIPV4_IPDST2: begin
320
350
pos <= sIPV4_IPDST3;
321
- md2 <= (data == tcp_dst_ip[15 :8 ]);
351
+ mda[2 ] <= (data == tcpA_dst_ip[15 :8 ]);
352
+ mdb[2 ] <= (data == tcpB_dst_ip[15 :8 ]);
322
353
end
323
354
sIPV4_IPDST3: begin
324
355
// if options, loop through OPTIONS0-3 to skip 32bit words, else
@@ -334,7 +365,8 @@ module Tcp
334
365
default : pos <= sIPV4_TYPE_ERR;
335
366
endcase
336
367
else pos <= sIPV4_OPTION0;
337
- md3 <= (data == tcp_dst_ip[7 :0 ]);
368
+ mda[3 ] <= (data == tcpA_dst_ip[7 :0 ]);
369
+ mdb[3 ] <= (data == tcpB_dst_ip[7 :0 ]);
338
370
end
339
371
// IPv4 OPTIONS loop
340
372
sIPV4_OPTION0: begin
@@ -387,19 +419,23 @@ module Tcp
387
419
sTCP_SRCP0: begin
388
420
pos <= sTCP_SRCP1;
389
421
counterEthIPTypeTCP <= counterEthIPTypeTCP + 1 ;
390
- ms4 <= (data == tcp_src_port[15 :8 ]);
422
+ msa[4 ] <= (data == tcpA_src_port[15 :8 ]);
423
+ msb[4 ] <= (data == tcpB_src_port[15 :8 ]);
391
424
end
392
425
sTCP_SRCP1: begin
393
426
pos <= sTCP_DSTP0;
394
- ms5 <= (data == tcp_src_port[7 :0 ]);
427
+ msa[5 ] <= (data == tcpA_src_port[7 :0 ]);
428
+ msb[5 ] <= (data == tcpB_src_port[7 :0 ]);
395
429
end
396
430
sTCP_DSTP0: begin
397
431
pos <= sTCP_DSTP1;
398
- md4 <= (data == tcp_dst_port[15 :8 ]);
432
+ mda[4 ] <= (data == tcpA_dst_port[15 :8 ]);
433
+ mdb[4 ] <= (data == tcpB_dst_port[15 :8 ]);
399
434
end
400
435
sTCP_DSTP1: begin
401
436
pos <= sTCP_SEQ0;
402
- md5 <= (data == tcp_dst_port[7 :0 ]);
437
+ mda[5 ] <= (data == tcpA_dst_port[7 :0 ]);
438
+ mdb[5 ] <= (data == tcpB_dst_port[7 :0 ]);
403
439
end
404
440
// it's mandatory to buffer the SEQuence number as we don't know whether to latch
405
441
// to tcpSeqNum (SYN) or compare for gaploss (!SYN)
@@ -468,45 +504,49 @@ module Tcp
468
504
end
469
505
endcase
470
506
471
- if (pos == sETH_MACD0) me0 <= data == mac[47 :40 ];
472
- if (pos == sETH_MACD1) me1 <= data == mac[39 :32 ];
473
- if (pos == sETH_MACD2) me2 <= data == mac[31 :24 ];
474
- if (pos == sETH_MACD3) me3 <= data == mac[23 :16 ];
475
- if (pos == sETH_MACD4) me4 <= data == mac[15 :8 ];
476
- if (pos == sETH_MACD5) me5 <= data == mac[7 :0 ];
477
-
478
- // load TCP data size assuming no IPV4 options, no TCP options, then decrement during any optional states
479
- if (pos == sIPV4_ID0) begin
480
- tcpData <= IPV4_Size - SZ_IP_TCP_NOOPTIONS;
481
- end else if (pos == sIPV4_OPTION0 || pos == sIPV4_OPTION1 || pos == sIPV4_OPTION2 || pos == sIPV4_OPTION3
482
- || pos == sTCP_OPT0 || pos == sTCP_OPT1 || pos == sTCP_OPT2 || pos == sTCP_OPT3
483
- || pos == sTCP_DATA ) begin
484
- tcpData <= tcpData - 1 ;
485
- end
507
+ // if (pos == sETH_MACD0) me0 <= data == mac[47:40];
508
+ // if (pos == sETH_MACD1) me1 <= data == mac[39:32];
509
+ // if (pos == sETH_MACD2) me2 <= data == mac[31:24];
510
+ // if (pos == sETH_MACD3) me3 <= data == mac[23:16];
511
+ // if (pos == sETH_MACD4) me4 <= data == mac[15:8];
512
+ // if (pos == sETH_MACD5) me5 <= data == mac[7:0];
513
+
514
+ end
486
515
516
+ // load TCP data size assuming no IPV4 options, no TCP options, then decrement during any (valid) optional states
517
+ if (pos == sIPV4_ID0) begin
518
+ tcpData <= IPV4_Size - SZ_IP_TCP_NOOPTIONS;
519
+ end else if ((pos == sIPV4_OPTION0 || pos == sIPV4_OPTION1 || pos == sIPV4_OPTION2 || pos == sIPV4_OPTION3
520
+ || pos == sTCP_OPT0 || pos == sTCP_OPT1 || pos == sTCP_OPT2 || pos == sTCP_OPT3
521
+ || pos == sTCP_DATA ) && dataValid) begin
522
+ tcpData <= tcpData - 1 ;
487
523
end
488
524
489
525
// don't raise outnewpkt for SYN/ACK (packets with no data payload)
490
526
// When tcpDataOff has reduced to 5, we have consumed all the TCP header.
491
527
// Independantly, there might not be any tcp payload ("data") in the packet.
492
- outnewpkt <= tcp_matches && dataValid && (
528
+ outnewpkt <= dataValid && (
493
529
( (pos == sTCP_URG1) && (tcpData != 0 ) && (tcpDataOff == 5 ) ) ||
494
530
( (pos == sTCP_OPT3) && (tcpData != 0 ) && (tcpDataOff == 5 ) )
495
531
);
496
532
497
- outDataValid <= dataValid && tcp_matches && pos == sTCP_DATA;
533
+ outDataMatchA <= dataValid && tcp_matchA && pos == sTCP_DATA;
534
+ outDataMatchB <= dataValid && tcp_matchB && pos == sTCP_DATA;
535
+ outDataPayload <= dataValid && pos == sTCP_DATA;
498
536
outData <= data;
499
537
500
538
// some elements of the design are idempotent so can be repeated while a state is held
501
539
// waiting for dataValid. Bring out to this block.
502
540
503
541
if (pos == sTCP_WINSZ0) begin
504
542
if (tcpFlagSYN) begin
505
- tcpSeq <= tcpSeqBuf;
543
+ if (tcp_matchA) tcpSeqA <= tcpSeqBuf;
544
+ if (tcp_matchB) tcpSeqB <= tcpSeqBuf;
506
545
end else begin
507
546
// no SYN... so tcpSeqBuf should match our "calculated" tcpSeq which has been
508
547
// incremented by the last data payload
509
- gapped <= (tcpSeqBuf != tcpSeq);
548
+ gappedA <= (tcpSeqBuf != tcpSeqA) && tcp_matchA;
549
+ gappedB <= (tcpSeqBuf != tcpSeqB) && tcp_matchB;
510
550
end
511
551
end
512
552
0 commit comments