+
+/*
+ * Detect if the congestion window is non-vlidated according to
+ * draft-ietf-tcpm-newcwv-07
+ */
+
+inline uint32_t
+tcp_cc_is_cwnd_nonvalidated(struct tcpcb *tp)
+{
+ if (tp->t_pipeack == 0 || tcp_check_cwnd_nonvalidated == 0) {
+ tp->t_flagsext &= ~TF_CWND_NONVALIDATED;
+ return (0);
+ }
+ if (tp->t_pipeack >= (tp->snd_cwnd) >> 1)
+ tp->t_flagsext &= ~TF_CWND_NONVALIDATED;
+ else
+ tp->t_flagsext |= TF_CWND_NONVALIDATED;
+ return (tp->t_flagsext & TF_CWND_NONVALIDATED);
+}
+
+/*
+ * Adjust congestion window in response to congestion in non-validated
+ * phase.
+ */
+inline void
+tcp_cc_adjust_nonvalidated_cwnd(struct tcpcb *tp)
+{
+ tp->t_pipeack = tcp_get_max_pipeack(tp);
+ tcp_clear_pipeack_state(tp);
+ tp->snd_cwnd = (max(tp->t_pipeack, tp->t_lossflightsize) >> 1);
+ tp->snd_cwnd = max(tp->snd_cwnd, TCP_CC_CWND_INIT_BYTES);
+ tp->snd_cwnd += tp->t_maxseg * tcprexmtthresh;
+ tp->t_flagsext &= ~TF_CWND_NONVALIDATED;
+}
+
+/*
+ * Return maximum of all the pipeack samples. Since the number of samples
+ * TCP_PIPEACK_SAMPLE_COUNT is 3 at this time, it will be simpler to do
+ * a comparision. We should change ths if the number of samples increases.
+ */
+inline u_int32_t
+tcp_get_max_pipeack(struct tcpcb *tp)
+{
+ u_int32_t max_pipeack = 0;
+ max_pipeack = (tp->t_pipeack_sample[0] > tp->t_pipeack_sample[1]) ?
+ tp->t_pipeack_sample[0] : tp->t_pipeack_sample[1];
+ max_pipeack = (tp->t_pipeack_sample[2] > max_pipeack) ?
+ tp->t_pipeack_sample[2] : max_pipeack;
+
+ return (max_pipeack);
+}
+
+inline void
+tcp_clear_pipeack_state(struct tcpcb *tp)
+{
+ bzero(tp->t_pipeack_sample, sizeof(tp->t_pipeack_sample));
+ tp->t_pipeack_ind = 0;
+ tp->t_lossflightsize = 0;
+}