/*
* Copyright (c) 2003 Nils-Erik Mattsson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Id: dccp_tfrc.c,v 1.47 2003/05/28 17:36:15 nilmat-8 Exp
*/
/*
* This implementation conforms to the drafts of DCCP dated Mars 2003.
* The options used are window counter, elapsed time, loss event rate
* and receive rate. No support for history discounting or oscillation
* prevention.
*/
/*
* Function called by the send timer (to send packet)
* args: cb - sender congestion control block
*/
void
tfrc_time_send(void *ccb)
{
struct tfrc_send_ccb *cb = (struct tfrc_send_ccb *) ccb;
int s;
/*struct inpcb *inp;*/
if (cb->state == TFRC_SSTATE_TERM) {
TFRC_DEBUG((LOG_INFO,
"TFRC - Send timer is ordered to terminate. (tfrc_time_send)\n"));
return;
}
if (callout_pending(&cb->ch_stimer)) {
TFRC_DEBUG((LOG_INFO,
"TFRC - Callout pending. (tfrc_time_send)\n"));
return;
}
/* acquire locks for dccp_output */
s = splsoftnet();
INP_INFO_RLOCK(&dccpbinfo);
/*inp = cb->pcb->d_inpcb;*/
INP_LOCK(inp);
INP_INFO_RUNLOCK(&dccpbinfo);
callout_stop(&cb->ch_stimer);
dccp_output(cb->pcb, 1);
/* make sure we schedule next send time */
tfrc_send_packet_sent(cb, 0, -1);
/* release locks */
INP_UNLOCK(inp);
splx(s);
}
/*
* Calculate and set when the send timer should expire
* args: cb - sender congestion control block
* t_now - timeval struct containing actual time
* Tested u:OK
*/
void
tfrc_set_send_timer(struct tfrc_send_ccb * cb, struct timeval t_now)
{
struct timeval t_temp;
long t_ticks;
/* set send timer to fire in t_ipi - (t_now-t_nom_old) or in other
* words after t_nom - t_now */
t_temp = cb->t_nom;
timersub(&t_temp, &t_now, &t_temp);
#ifdef TFRCDEBUG
if (t_temp.tv_sec < 0 || t_temp.tv_usec < 0)
panic("TFRC - scheduled a negative time! (tfrc_set_send_timer)");
#endif
/* Empty packet history */
elm = TAILQ_FIRST(&(cb->hist));
while (elm != NULL) {
elm2 = TAILQ_NEXT(elm, linfo);
free(elm, M_TEMP); /* M_TEMP ?? */
elm = elm2;
}
TAILQ_INIT(&(cb->hist));
mutex_exit(&(cb->mutex));
/* schedule the removal of ccb */
callout_reset(&cb->ch_stimer, TFRC_SEND_WAIT_TERM * hz, tfrc_send_term, cb);
}
/*
* Ask TFRC whether one can send a packet or not
* args: ccb - ccb block for current connection
* returns: 1 if ok, else 0.
*/
int
tfrc_send_packet(void *ccb, long datasize)
{
struct s_hist_entry *new_packet;
u_int8_t answer = 0;
u_int8_t win_count = 0;
u_int32_t uw_win_count = 0;
struct timeval t_now, t_temp;
struct tfrc_send_ccb *cb = (struct tfrc_send_ccb *) ccb;
#ifdef NOTFRCSENDER
return 1;
#endif
/* check if pure ACK or Terminating */
if (datasize == 0 || cb->state == TFRC_SSTATE_TERM) {
return 1;
} else if (cb->state == TFRC_SSTATE_TERM) {
TFRC_DEBUG((LOG_INFO, "TFRC - Asked to send packet when terminating!\n"));
return 0;
}
/* we have data to send */
mutex_enter(&(cb->mutex));
/* check to see if we already have allocated memory last time */
new_packet = TAILQ_FIRST(&(cb->hist));
if ((new_packet != NULL && new_packet->t_sent.tv_sec >= 0) || new_packet == NULL) {
/* check to see if we have memory to add to packet history */
new_packet = malloc(sizeof(struct s_hist_entry), M_TEMP, M_NOWAIT); /* M_TEMP?? */
if (new_packet == NULL) {
TFRC_DEBUG((LOG_INFO, "TFRC - Not enough memory to add packet to packet history (send refused)! (tfrc_send_packet)\n"));
answer = 0;
dccpstat.tfrcs_send_nomem++;
goto sp_release;
}
new_packet->t_sent.tv_sec = -1; /* mark as unsent */
TAILQ_INSERT_HEAD(&(cb->hist), new_packet, linfo);
}
switch (cb->state) {
case TFRC_SSTATE_NO_SENT:
TFRC_DEBUG((LOG_INFO, "TFRC - DCCP ask permission to send first data packet (tfrc_send_packet)\n"));
microtime(&(cb->t_nom)); /* set nominal send time for initial packet */
t_now = cb->t_nom;
if (answer) {
cb->pcb->ccval = win_count;
new_packet->win_count = win_count;
}
sp_release:
mutex_exit(&(cb->mutex));
return answer;
}
/* Notify sender that a packet has been sent
* args: ccb - ccb block for current connection
* moreToSend - if there exists more packets to send
* dataSize - packet size
*/
void
tfrc_send_packet_sent(void *ccb, int moreToSend, long datasize)
{
struct timeval t_now, t_temp;
struct s_hist_entry *packet;
struct tfrc_send_ccb *cb = (struct tfrc_send_ccb *) ccb;
#ifdef NOTFRCSENDER
return;
#endif
if (cb->state == TFRC_SSTATE_TERM) {
TFRC_DEBUG((LOG_INFO, "TFRC - Packet sent when terminating!\n"));
return;
}
mutex_enter(&(cb->mutex));
microtime(&t_now);
/* check if we have sent a data packet */
if (datasize > 0) {
/* add send time to history */
packet = TAILQ_FIRST(&(cb->hist));
if (packet == NULL)
panic("TFRC - Packet does not exist in history! (tfrc_send_packet_sent)");
else if (packet != NULL && packet->t_sent.tv_sec >= 0)
panic("TFRC - No unsent packet in history! (tfrc_send_packet_sent)");
packet->t_sent = t_now;
packet->seq = cb->pcb->seq_snd;
/* check if win_count have changed */
if (packet->win_count != cb->last_win_count) {
cb->t_last_win_count = t_now;
cb->last_win_count = packet->win_count;
}
TFRC_DEBUG((LOG_INFO, "TFRC - Packet sent (%llu, %u, (%lu.%lu)",
packet->seq, packet->win_count, packet->t_sent.tv_sec, packet->t_sent.tv_usec));
cb->idle = 0;
}
/* if timer is running, do nothing */
if (callout_pending(&cb->ch_stimer)) {
goto sps_release;
}
switch (cb->state) {
case TFRC_SSTATE_NO_SENT:
/* if first was pure ack */
if (datasize == 0) {
goto sps_release;
} else
panic("TFRC - First packet sent is noted as a data packet in tfrc_send_packet_sent\n");
break;
case TFRC_SSTATE_NO_FBACK:
case TFRC_SSTATE_FBACK:
if (datasize <= 0) { /* we have ack (or simulate a sent
* packet which never can have
* moreToSend */
moreToSend = 0;
} else {
/* Calculate new t_ipi */
CALCNEWTIPI(cb);
timeradd(&cb->t_nom, &cb->t_ipi, &cb->t_nom);
/* Calculate new delta */
CALCNEWDELTA(cb);
}
if (!moreToSend) {
/* loop until we find a send time in the future */
microtime(&t_now);
t_temp = t_now;
timeradd(&t_temp, &cb->delta, &t_temp);
while ((timercmp(&(t_temp), &(cb->t_nom), >))) {
/* Calculate new t_ipi */
CALCNEWTIPI(cb);
timeradd(&cb->t_nom, &cb->t_ipi, &cb->t_nom);
/* Check if next packet can not be sent immediately */
if (!(timercmp(&(t_temp), &(cb->t_nom), >))) {
tfrc_set_send_timer(cb, t_now); /* if so schedule sendtimer */
}
}
break;
default:
panic("tfrc_send_packet_sent: Illegal state!");
break;
}
sps_release:
mutex_exit(&(cb->mutex));
}
/* Notify that a an ack package was received (i.e. a feedback packet)
* args: ccb - ccb block for current connection
*/
void
tfrc_send_packet_recv(void *ccb, char *options, int optlen)
{
u_int32_t next_time_out;
struct timeval t_now;
struct fixpoint x,y;
int res;
u_int16_t t_elapsed = 0;
u_int32_t t_elapsed_l = 0;
u_int32_t pinv;
u_int32_t x_recv;
if (cb->state == TFRC_SSTATE_TERM) {
TFRC_DEBUG((LOG_INFO, "TFRC - Sender received a packet when terminating!\n"));
return;
}
/* we are only interested in ACKs */
if (!(cb->pcb->type_rcv == DCCP_TYPE_ACK || cb->pcb->type_rcv == DCCP_TYPE_DATAACK))
return;
res = dccp_get_option(options, optlen, TFRC_OPT_LOSS_RATE, (char *) &pinv, 6);
if (res == 0) {
TFRC_DEBUG((LOG_INFO, "TFRC - Missing Loss rate option! (tfrc_send_packet_recv)\n"));
dccpstat.tfrcs_send_noopt++;
return;
}
res = dccp_get_option(options, optlen, DCCP_OPT_ELAPSEDTIME, (char *) &t_elapsed_l, 6);
if (res == 0) {
/* try 2 bytes elapsed time */
res = dccp_get_option(options, optlen, DCCP_OPT_ELAPSEDTIME, (char *) &t_elapsed, 4);
if (res == 0){
TFRC_DEBUG((LOG_INFO, "TFRC - Missing elapsed time option! (tfrc_send_packet_recv)\n"));
dccpstat.tfrcs_send_noopt++;
return;
}
}
res = dccp_get_option(options, optlen, TFRC_OPT_RECEIVE_RATE, (char *) &x_recv, 4);
if (res == 0) {
TFRC_DEBUG((LOG_INFO, "TFRC - Missing x_recv option! (tfrc_send_packet_recv)\n"));
dccpstat.tfrcs_send_noopt++;
return;
}
dccpstat.tfrcs_send_fbacks++;
/* change byte order */
if (t_elapsed)
t_elapsed = ntohs(t_elapsed);
else
t_elapsed_l = ntohl(t_elapsed_l);
x_recv = ntohl(x_recv);
pinv = ntohl(pinv);
if (pinv == 0xFFFFFFFF) pinv = 0;
if (t_elapsed)
TFRC_DEBUG((LOG_INFO, "TFRC - Received options on ack %llu: pinv=%u, t_elapsed=%u, x_recv=%u ! (tfrc_send_packet_recv)\n", cb->pcb->ack_rcv, pinv, t_elapsed, x_recv));
else
TFRC_DEBUG((LOG_INFO, "TFRC - Received options on ack %llu: pinv=%u, t_elapsed=%u, x_recv=%u ! (tfrc_send_packet_recv)\n", cb->pcb->ack_rcv, pinv, t_elapsed_l, x_recv));
mutex_enter(&(cb->mutex));
switch (cb->state) {
case TFRC_SSTATE_NO_FBACK:
case TFRC_SSTATE_FBACK:
/* Calculate new round trip sample by R_sample = (t_now -
* t_recvdata)-t_delay; */
/* get t_recvdata from history */
elm = TAILQ_FIRST(&(cb->hist));
while (elm != NULL) {
if (elm->seq == cb->pcb->ack_rcv)
break;
elm = TAILQ_NEXT(elm, linfo);
}
if (elm == NULL) {
TFRC_DEBUG((LOG_INFO,
"TFRC - Packet does not exist in history (seq=%llu)! (tfrc_send_packet_recv)", cb->pcb->ack_rcv));
goto sar_release;
}
/* Update RTT */
microtime(&t_now);
timersub(&t_now, &(elm->t_sent), &t_now);
r_sample = t_now.tv_sec * 1000000 + t_now.tv_usec;
if (t_elapsed)
r_sample = r_sample - ((u_int32_t) t_elapsed * 10); /* t_elapsed in us */
else
r_sample = r_sample - (t_elapsed_l * 10); /* t_elapsed in us */
/* Update RTT estimate by If (No feedback recv) R = R_sample;
* Else R = q*R+(1-q)*R_sample; */
if (cb->state == TFRC_SSTATE_NO_FBACK) {
cb->state = TFRC_SSTATE_FBACK;
cb->rtt = r_sample;
} else {
cb->rtt = (u_int32_t) (TFRC_RTT_FILTER_CONST * cb->rtt +
(1 - TFRC_RTT_FILTER_CONST) * r_sample);
}
TFRC_DEBUG((LOG_INFO, "TFRC - New RTT estimate %u (tfrc_send_packet_recv)\n", cb->rtt));
/* unschedule no feedback timer */
if (!callout_pending(&cb->ch_nftimer)) {
callout_stop(&cb->ch_nftimer);
}
/* Update sending rate */
microtime(&t_now);
tfrc_updateX(cb, t_now);
/* Update next send time */
timersub(&cb->t_nom, &cb->t_ipi, &cb->t_nom);
/* Calculate new t_ipi */
CALCNEWTIPI(cb);
timeradd(&cb->t_nom, &cb->t_ipi, &cb->t_nom);
/* Calculate new delta */
CALCNEWDELTA(cb);
if (callout_pending(&cb->ch_stimer)) {
callout_stop(&cb->ch_stimer);
}
#if 0 /* XXX do not send ack of ack so far */
dccp_output(cb->pcb, 1);
tfrc_send_packet_sent(cb, 0, -1); /* make sure we schedule next send time */
#endif
/* remove all packets older than the one acked from history */
/* elm points to acked package! */
/* Find a data packet in history
* args: cb - ccb of receiver
* elm - pointer to element (variable)
* num - number in history (variable)
* returns: elm points to found packet, otherwise NULL
* Tested u:OK
*/
#define TFRC_RECV_FINDDATAPACKET(cb,elm,num) \
do { \
elm = TAILQ_FIRST(&((cb)->hist)); \
while ((elm) != NULL) { \
if ((elm)->type == DCCP_TYPE_DATA || (elm)->type == DCCP_TYPE_DATAACK) \
(num)--; \
if (num == 0) \
break; \
elm = TAILQ_NEXT((elm), linfo); \
} \
} while (0)
/* Find next data packet in history
* args: cb - ccb of receiver
* elm - pointer to element (variable)
* returns: elm points to found packet, otherwise NULL
* Tested u:OK
*/
#define TFRC_RECV_NEXTDATAPACKET(cb,elm) \
do { \
if (elm != NULL) { \
elm = TAILQ_NEXT(elm, linfo); \
while ((elm) != NULL && (elm)->type != DCCP_TYPE_DATA && (elm)->type != DCCP_TYPE_DATAACK) { \
elm = TAILQ_NEXT((elm), linfo); \
} \
} \
} while (0)
/*
* Calculate avarage loss Interval I_mean
* args: cb - ccb of receiver
* returns: avarage loss interval
* Tested u:OK
*/
long
tfrc_calclmean(struct tfrc_recv_ccb * cb)
{
struct li_hist_entry *elm;
struct fixpoint l_tot;
struct fixpoint l_tot0 = {0,0};
struct fixpoint l_tot1 = {0,0};
struct fixpoint W_tot = {0, 0};
struct fixpoint tmp;
int i;
elm = TAILQ_FIRST(&(cb->li_hist));
for (i = 0; i < TFRC_RECV_IVAL_F_LENGTH; i++) {
#ifdef TFRCDEBUG
if (elm == 0)
goto I_panic;
#endif
/* trim history (remove all packets after the NUM_LATE_LOSS+1 data
* packets) */
if (TAILQ_FIRST(&(cb->li_hist)) != NULL) {
num_later = TFRC_RECV_NUM_LATE_LOSS + 1;
TFRC_RECV_FINDDATAPACKET(cb, elm, num_later);
if (elm != NULL) {
elm2 = TAILQ_NEXT(elm, linfo);
while (elm2 != NULL) {
TAILQ_REMOVE(&(cb->hist), elm2, linfo);
free(elm2, M_TEMP);
elm2 = TAILQ_NEXT(elm, linfo);
}
}
} else {
/* we have no loss interval history so we need at least one
* rtt:s of data packets to approximate rtt */
num_later = TFRC_RECV_NUM_LATE_LOSS + 1;
TFRC_RECV_FINDDATAPACKET(cb, elm2, num_later);
if (elm2 != NULL) {
num_later = 1;
TFRC_RECV_FINDDATAPACKET(cb, elm, num_later);
win_count = elm->win_count;
elm = elm2;
TFRC_RECV_NEXTDATAPACKET(cb, elm2);
while (elm2 != NULL) {
temp = win_count - (int) (elm2->win_count);
if (temp < 0)
temp = temp + TFRC_WIN_COUNT_LIMIT;
if (temp > TFRC_WIN_COUNT_PER_RTT + 1) {
/* we have found a packet older than
* one rtt remove the rest */
elm = TAILQ_NEXT(elm2, linfo);
while (elm != NULL) {
TAILQ_REMOVE(&(cb->hist), elm, linfo);
free(elm, M_TEMP);
elm = TAILQ_NEXT(elm2, linfo);
}
break;
}
elm = elm2;
TFRC_RECV_NEXTDATAPACKET(cb, elm2);
}
} /* end if (exist atleast 4 data packets) */
}
return 0;
}
/*
* Detect loss events and update loss interval history
* args: cb - ccb of the receiver
* Tested u:OK
*/
void
tfrc_recv_detectLoss(struct tfrc_recv_ccb * cb)
{
struct r_hist_entry *bLoss, *aLoss, *elm, *elm2;
u_int8_t num_later = TFRC_RECV_NUM_LATE_LOSS;
long seq_temp = 0;
long seq_loss = -1;
u_int8_t win_loss = 0;
TFRC_RECV_FINDDATAPACKET(cb, bLoss, num_later);
if (bLoss == NULL) {
/* not enough packets yet to cause the first loss event */
} else { /* bloss != NULL */
num_later = TFRC_RECV_NUM_LATE_LOSS + 1;
TFRC_RECV_FINDDATAPACKET(cb, aLoss, num_later);
if (aLoss == NULL) {
if (TAILQ_EMPTY(&(cb->li_hist))) {
/* no loss event have occurred yet */
/* todo: find a lost data packet by comparing
* to initial seq num */
} else {
panic("Less than 4 data packets in history (tfrc_recv_detecLossEvent)\n");
}
} else { /* aLoss != NULL */
/* locate a lost data packet */
elm = bLoss;
elm2 = TAILQ_NEXT(elm, linfo);
do {
seq_temp = ((long) (elm->seq)) - ((long) elm2->seq);
if (seq_temp < 0)
seq_temp = seq_temp + DCCP_SEQ_NUM_LIMIT;
if (seq_temp != 1) {
/* check no data packets */
if (elm->type == DCCP_TYPE_DATA || elm->type == DCCP_TYPE_DATAACK)
seq_temp = seq_temp - 1;
if (seq_temp % DCCP_NDP_LIMIT != ((int) elm->ndp - (int) elm2->ndp + DCCP_NDP_LIMIT) % DCCP_NDP_LIMIT)
seq_loss = (elm2->seq + 1) % DCCP_SEQ_NUM_LIMIT;
}
elm = elm2;
elm2 = TAILQ_NEXT(elm2, linfo);
} while (elm != aLoss);
if (seq_loss != -1) {
win_loss = aLoss->win_count;
}
}
} /* end if (bLoss == NULL) */
tfrc_recv_updateLI(cb, seq_loss, win_loss);
}
/* Updates the loss interval history
* cb - congestion control block
* seq_loss - sequence number of lost packet (-1 for none)
* win_loss - window counter for previous (from the lost packet view) packet
* Tested u:OK
*/
void
tfrc_recv_updateLI(struct tfrc_recv_ccb * cb, long seq_loss, u_int8_t win_loss)
{
struct r_hist_entry *elm;
struct li_hist_entry *li_elm, *li_elm2;
u_int8_t num_later = TFRC_RECV_NUM_LATE_LOSS;
long seq_temp = 0;
int i;
u_int8_t win_start;
int debug_info = 0;
if (seq_loss != -1) { /* we have found a packet loss! */
dccpstat.tfrcs_recv_losts++;
TFRC_DEBUG((LOG_INFO, "TFRC - seqloss=%i, winloss=%i\n", (int) seq_loss, (int) win_loss));
if (TAILQ_EMPTY(&(cb->li_hist))) {
debug_info = 1;
/* first loss detected */
TFRC_DEBUG((LOG_INFO, "TFRC - First loss event detected! (tfrc_recv_updateLI)\n"));
/* create history */
for (i = 0; i < TFRC_RECV_IVAL_F_LENGTH + 1; i++) {
li_elm = malloc(sizeof(struct li_hist_entry),
M_TEMP, M_NOWAIT | M_ZERO); /* M_TEMP?? */
if (li_elm == NULL) {
TFRC_DEBUG((LOG_INFO, "TFRC - Not enough memory for loss interval history!\n"));
/* Empty loss interval history */
li_elm = TAILQ_FIRST(&(cb->li_hist));
while (li_elm != NULL) {
li_elm2 = TAILQ_NEXT(li_elm, linfo);
free(li_elm, M_TEMP); /* M_TEMP ?? */
li_elm = li_elm2;
}
return;
}
TAILQ_INSERT_HEAD(&(cb->li_hist), li_elm, linfo);
}
} else { /* we have a loss interval history */
debug_info = 2;
/* Check if the loss is in the same loss event as
* interval start */
win_start = (TAILQ_FIRST(&(cb->li_hist)))->win_count;
if ((win_loss > win_start
&& win_loss - win_start > TFRC_WIN_COUNT_PER_RTT) ||
(win_loss < win_start
&& win_start - win_loss < TFRC_WIN_COUNT_LIMIT - TFRC_WIN_COUNT_PER_RTT)) {
/* new loss event detected */
/* calculate last interval length */
seq_temp = seq_loss - ((long) ((TAILQ_FIRST(&(cb->li_hist)))->seq));
if (seq_temp < 0)
seq_temp = seq_temp + DCCP_SEQ_NUM_LIMIT;
/* insert it into history */
TAILQ_INSERT_HEAD(&(cb->li_hist), li_elm, linfo);
} else
TFRC_DEBUG((LOG_INFO, "TFRC - Loss belongs to previous loss event (tfrc_recv_updateLI)!\n"));
}
}
if (TAILQ_FIRST(&(cb->li_hist)) != NULL) {
/* calculate interval to last loss event */
num_later = 1;
TFRC_RECV_FINDDATAPACKET(cb, elm, num_later);
TFRC_DEBUG((LOG_INFO, "TFRC receiver is destroyed\n"));
}
/*
* Tell TFRC that a packet has been received
* args: ccb - ccb block for current connection
*/
void
tfrc_recv_packet_recv(void *ccb, char *options, int optlen)
{
struct r_hist_entry *packet;
u_int8_t win_count = 0;
struct fixpoint p_prev;
int ins = 0;
struct tfrc_recv_ccb *cb = (struct tfrc_recv_ccb *) ccb;
#ifdef NOTFRCRECV
return;
#endif
if (!(cb->state == TFRC_RSTATE_NO_DATA || cb->state == TFRC_RSTATE_DATA)) {
panic("TFRC - Illegal state! (tfrc_recv_packet_recv)\n");
return;
}
/* Check which type */
switch (cb->pcb->type_rcv) {
case DCCP_TYPE_ACK:
if (cb->state == TFRC_RSTATE_NO_DATA)
return;
break;
case DCCP_TYPE_DATA:
case DCCP_TYPE_DATAACK:
break;
default:
TFRC_DEBUG((LOG_INFO, "TFRC - Received not data/dataack/ack packet! (tfrc_recv_packet_recv)"));
return;
}
mutex_enter(&(cb->mutex));
/* Add packet to history */
packet = malloc(sizeof(struct r_hist_entry), M_TEMP, M_NOWAIT); /* M_TEMP?? */
if (packet == NULL) {
TFRC_DEBUG((LOG_INFO, "TFRC - Not enough memory to add received packet to history (consider it lost)! (tfrc_recv_packet_recv)"));
dccpstat.tfrcs_recv_nomem++;
goto rp_release;
}
microtime(&(packet->t_recv));
packet->seq = cb->pcb->seq_rcv;
packet->type = cb->pcb->type_rcv;
packet->ndp = cb->pcb->ndp_rcv;
if (fixpoint_cmp(x, &flargex) >= 0) {
if (x->num == 0)
return NULL;
i = x->denom / x->num;
#ifdef TFRCDEBUG
if (i >= sizeof(flarge_table) / sizeof(flarge_table[0]))
panic("flarge_table lookup failed");
#endif
return &flarge_table[i];
} else {
fixpoint_mul(&z, x, &y);
if (z.num == 0)
return NULL;
i = fixpoint_getlong(&z);
#ifdef TFRCDEBUG
if (i >= sizeof(fsmall_table) / sizeof(fsmall_table[0]))
panic("fsmall_table lookup failed");
#endif
return &fsmall_table[i];
}
}
/*
* Inverse of the FLOOKUP above
* args: fvalue - function value to match
* returns: p closest to that value
* Tested u:OK
*/
const struct fixpoint *
tfrc_flookup_reverse(const struct fixpoint *fvalue)
{
static struct fixpoint x;
int ctr;