AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Files Variables
TCP_CC.vhd
1 ----------------------------------------------------------------------------------
2 -- Company:
3 -- Engineer:
4 --
5 -- Create Date: 09:47:17 10/04/2013
6 -- Design Name:
7 -- Module Name: TCP_CC - Behavioral
8 -- Project Name:
9 -- Target Devices:
10 -- Tool versions:
11 -- Description:
12 --
13 -- Dependencies:
14 --
15 -- Revision:
16 -- Revision 0.01 - File Created
17 -- Additional Comments:
18 --
19 ----------------------------------------------------------------------------------
20 library IEEE;
21 use IEEE.STD_LOGIC_1164.ALL;
22 use IEEE.STD_LOGIC_ARITH.ALL;
23 use IEEE.STD_LOGIC_UNSIGNED.ALL;
24 use IEEE.std_logic_misc.all;
25 use IEEE.numeric_std.all;
26 
27 -- Uncomment the following library declaration if using
28 -- arithmetic functions with Signed or Unsigned values
29 --use IEEE.NUMERIC_STD.ALL;
30 
31 -- Uncomment the following library declaration if instantiating
32 -- any Xilinx primitives in this code.
33 --library UNISIM;
34 --use UNISIM.VComponents.all;
35 
36 entity TCP_CC is
37  Port ( clk : in STD_LOGIC;
38  reset : in STD_LOGIC;
39  SYNRCVD : in STD_LOGIC;
40  RETX_TO : in STD_LOGIC;
41  Save_ReTx : in STD_LOGIC;
42  FastReTxStart : in STD_LOGIC;
43  FR : in STD_LOGIC;
44  PartialACK : in STD_LOGIC;
45  NewDataACK : in STD_LOGIC;
46  DupACK : in STD_LOGIC;
47  MSS : in STD_LOGIC_VECTOR (15 downto 0);
48  CWND_max : in STD_LOGIC_VECTOR (31 downto 0);
49  SEG_WND : in STD_LOGIC_VECTOR (31 downto 0);
50  SND_UNA : in STD_LOGIC_VECTOR (31 downto 0);
51  SND_NXT : in STD_LOGIC_VECTOR (31 downto 0);
52  CWND : out STD_LOGIC_VECTOR (31 downto 0);
53  SND_WND_UL : out STD_LOGIC_VECTOR (31 downto 0);
54  debug : out STD_LOGIC_VECTOR (271 downto 0)
55  );
56 end TCP_CC;
57 
58 architecture Behavioral of TCP_CC is
59 signal SND_UNA_OLD : std_logic_vector(31 downto 0) := (others => '0');
60 signal DataACKed : std_logic_vector(31 downto 0) := (others => '0');
61 signal DataACKedSUM : std_logic_vector(31 downto 0) := (others => '0');
62 signal MSSx2 : std_logic_vector(27 downto 0) := (others => '0');
63 signal MSSx3 : std_logic_vector(27 downto 0) := (others => '0');
64 signal CWND_i : std_logic_vector(27 downto 0) := (others => '0');
65 signal CWND_INC : std_logic_vector(27 downto 0) := (others => '0');
66 signal CWND_FAST : std_logic_vector(27 downto 0) := (others => '0');
67 signal SSTHRESH : std_logic_vector(27 downto 0) := (others => '0');
68 signal CWND_sub_SSTHRESH : std_logic_vector(27 downto 0) := (others => '0');
69 signal FLIGHT_SIZE : std_logic_vector(31 downto 0) := (others => '0');
70 signal FLIGHT_SIZEplusMSS : std_logic_vector(27 downto 0) := (others => '0');
71 signal StartFlightSize : std_logic_vector(27 downto 0) := (others => '0');
72 signal SSTHRESH_RETX : std_logic_vector(27 downto 0) := (others => '0');
73 signal New_TO : std_logic := '0';
74 signal SS : std_logic := '0';
75 signal CA : std_logic := '0';
76 --signal FR : std_logic := '0';
77 signal PartACK : std_logic := '0';
78 signal FullACK : std_logic_vector(2 downto 0) := (others => '0');
79 signal NewDataACK_dl : std_logic_vector(1 downto 0) := (others => '0');
80 signal DataACKedSUM_GT_CWND : std_logic := '0';
81 
82 begin
83 debug(121 downto 94) <= FLIGHT_SIZE(27 downto 0);
84 debug(93 downto 66) <= SSTHRESH;
85 debug(65 downto 38) <= CWND_FAST;
86 debug(37 downto 10) <= CWND_i;
87 debug(9) <= DupACK;
88 debug(8) <= PartialACK ;
89 debug(7) <= New_TO;
90 debug(6) <= RETX_TO;
91 debug(5) <= NewDataACK;
92 debug(4) <= FastReTxStart;
93 debug(3) <= PartACK;
94 debug(2) <= FR;
95 debug(1) <= CA;
96 debug(0) <= SS;
97 --debug(263 downto 232) <= FLIGHT_SIZE;
98 --debug(231 downto 200) <= x"0" & SSTHRESH;
99 --debug(199 downto 168) <= x"0" & CWND_FAST;
100 --debug(167 downto 136) <= x"0" & CWND_INC;
101 --debug(127 downto 96) <= x"0" & CWND_i;
102 --debug(95 downto 64) <= DataACKedSUM;
103 --debug(63) <= DupACK;
104 --debug(62) <= PartialACK ;
105 --debug(61) <= DataACKedSUM_GT_CWND;
106 --debug(59) <= New_TO;
107 --debug(58) <= RETX_TO;
108 --debug(57) <= NewDataACK;
109 --debug(56) <= FastReTxStart;
110 --debug(55) <= PartACK;
111 --debug(54) <= FR;
112 --debug(53) <= CA;
113 --debug(52) <= SS;
114 --debug(51 downto 32) <= DataACKed(19 downto 0);
115 --debug(31 downto 0) <= SND_UNA;
116 MSSx2 <= x"000" & MSS(14 downto 0) & '0';
117 process(clk)
118 begin
119  if(clk'event and clk = '1')then
120  if(CWND_i > CWND_max)then
121  CWND <= CWND_max;
122  else
123  CWND <= x"0" & CWND_i;
124  end if;
125  if(FR = '0')then
126  StartFlightSize <= FLIGHT_SIZE(27 downto 0);
127  end if;
128  if(Save_ReTx = '1')then
129  SND_WND_UL <= SND_NXT + ('0' & StartFlightSize(27 downto 1));
130  end if;
131  SND_UNA_OLD <= SND_UNA;
132  DataACKed <= SND_UNA - SND_UNA_OLD;
133  NewDataACK_dl <= NewDataACK_dl(0) & NewDataACK;
134  if(CA = '0' or DataACKedSUM_GT_CWND = '1')then
135  DataACKedSUM <= (others => '0');
136  elsif(NewDataACK_dl(0) = '1')then
137  DataACKedSUM <= DataACKedSUM + DataACKed;
138  end if;
139  if(CA = '1' and DataACKedSUM > (x"0" & CWND_i) and NewDataACK_dl(1) = '1')then
140  DataACKedSUM_GT_CWND <= '1';
141  else
142  DataACKedSUM_GT_CWND <= '0';
143  end if;
144  if((or_reduce(DataACKed(31 downto 16)) = '1' or DataACKed(15 downto 0) >= MSS) and FR = '1' and NewDataACK_dl(0) = '1' and PartialACK = '1')then
145  PartACK <= '1';
146  else
147  PartACK <= '0';
148  end if;
149  if(SS = '1' and or_reduce(DataACKed(31 downto 16)) = '0' and DataACKed(15 downto 0) < MSS)then
150  CWND_INC(15 downto 0) <= DataACKed(15 downto 0);
151  else
152  CWND_INC(15 downto 0) <= MSS;
153  end if;
154  FullACK <= FullACK(1 downto 0) & (FR and NewDataACK and not PartialACK);
155  CWND_sub_SSTHRESH <= CWND_i - SSTHRESH;
156  if(reset = '1')then
157  CWND_i <= MSSx2;
158  elsif(RETX_TO = '1')then
159  CWND_i <= x"000" & MSS;
160  elsif(FastReTxStart = '1' or FullACK(2) = '1')then
161  CWND_i <= CWND_FAST;
162  elsif(FR = '1' and NewDataACK_dl(0) = '1' and PartialACK = '1')then
163  if(CWND_sub_SSTHRESH > DataACKed(27 downto 0) and DataACKed(31 downto 28) = x"0")then
164  CWND_i <= CWND_i - DataACKed(27 downto 0);
165  else
166  CWND_i <= SSTHRESH;
167  end if;
168  elsif(CWND_i(27) = '0' and ((SS = '1' and NewDataACK_dl(1) = '1') or DataACKedSUM_GT_CWND = '1' or (FR = '1' and DupACK = '1') or PartACK = '1'))then
169  CWND_i <= CWND_i + CWND_INC;
170  end if;
171  MSSx3 <= MSSx2 + (x"000" & MSS);
172  if(FR = '0')then
173  CWND_FAST <= ('0' & FLIGHT_SIZE(27 downto 1)) + MSSx3;
174  elsif(FLIGHT_SIZEplusMSS > SSTHRESH)then
175  CWND_FAST <= SSTHRESH;
176  else
177  CWND_FAST <= FLIGHT_SIZEplusMSS; -- this is MSS added by the flight size before the NewDataACK arrives
178  end if;
179  if(FR = '1')then
180  SS <= '0';
181  CA <= '0';
182  elsif(CWND_i < SSTHRESH)then
183  SS <= '1';
184  CA <= '0';
185  else
186  SS <= '0';
187  CA <= '1';
188  end if;
189  if(reset = '1' or NewDataACK = '1')then
190  New_TO <= '1';
191  elsif(RETX_TO = '1')then
192  New_TO <= '0';
193  end if;
194  if(SYNRCVD = '1')then
195  if(SEG_WND(31 downto 27) = "00000")then
196  SSTHRESH <= SEG_WND(27 downto 0);
197  else
198  SSTHRESH <= x"3ffffff";
199  end if;
200  elsif((RETX_TO = '1' and New_TO = '1') or FastReTxStart = '1')then
201  SSTHRESH <= SSTHRESH_RETX;
202  end if;
203  FLIGHT_SIZE <= SND_NXT - SND_UNA;
204  if(FLIGHT_SIZE > (x"000" & MSS))then
205  FLIGHT_SIZEplusMSS <= FLIGHT_SIZE(27 downto 0) + (x"000" & MSS);
206  else
207  FLIGHT_SIZEplusMSS <= MSSx2;
208  end if;
209  if(FLIGHT_SIZE(27 downto 1) > MSSx2(26 downto 0))then
210  SSTHRESH_RETX <= '0' & FLIGHT_SIZE(27 downto 1);
211  else
212  SSTHRESH_RETX <= MSSx2;
213  end if;
214  end if;
215 end process;
216 
217 end Behavioral;
218