/* * Copyright (c) 2020 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include static void scoreboard_remove_hole (sack_scoreboard_t * sb, sack_scoreboard_hole_t * hole) { sack_scoreboard_hole_t *next, *prev; if (hole->next != TCP_INVALID_SACK_HOLE_INDEX) { next = pool_elt_at_index (sb->holes, hole->next); next->prev = hole->prev; } else { sb->tail = hole->prev; } if (hole->prev != TCP_INVALID_SACK_HOLE_INDEX) { prev = pool_elt_at_index (sb->holes, hole->prev); prev->next = hole->next; } else { sb->head = hole->next; } if (scoreboard_hole_index (sb, hole) == sb->cur_rxt_hole) sb->cur_rxt_hole = TCP_INVALID_SACK_HOLE_INDEX; /* Poison the entry */ if (CLIB_DEBUG > 0) clib_memset (hole, 0xfe, sizeof (*hole)); pool_put (sb->holes, hole); } static sack_scoreboard_hole_t * scoreboard_insert_hole (sack_scoreboard_t * sb, u32 prev_index, u32 start, u32 end) { sack_scoreboard_hole_t *hole, *next, *prev; u32 hole_index; pool_get (sb->holes, hole); clib_memset (hole, 0, sizeof (*hole)); hole->start = start; hole->end = end; hole_index = scoreboard_hole_index (sb, hole); prev = scoreboard_get_hole (sb, prev_index); if (prev) { hole->prev = prev_index; hole->next = prev->next; if ((next = scoreboard_next_hole (sb, hole))) next->prev = hole_index; else sb->tail = hole_index; prev->next = hole_index; } else { sb->head = hole_index; hole->prev = TCP_INVALID_SACK_HOLE_INDEX; hole->next = TCP_INVALID_SACK_HOLE_INDEX; } return hole; } always_inline void scoreboard_update_sacked (sack_scoreboard_t * sb, u32 start, u32 end, u8 has_rxt, u16 snd_mss) { if (!has_rxt) { /* Sequence was not retransmitted but it was sacked. Estimate reorder * only if not in congestion recovery */ if (seq_lt (start, sb->high_sacked)) { u32 reord = (sb->high_sacked - start + snd_mss - 1) / snd_mss; reord = clib_min (reord, TCP_MAX_SACK_REORDER); sb->reorder = clib_max (sb->reorder, reord); } return; } if (seq_geq (start, sb->high_rxt)) return; sb->rxt_sacked += seq_lt (end, sb->high_rxt) ? (end - start) : (sb->high_rxt - start); } always_inline void scoreboard_update_bytes (sack_scoreboard_t * sb, u32 ack, u32 snd_mss) { sack_scoreboard_hole_t *left, *right; u32 sacked = 0, blks = 0, old_sacked; old_sacked = sb->sacked_bytes; sb->last_lost_bytes = 0; sb->lost_bytes = 0; sb->sacked_bytes = 0; right = scoreboard_last_hole (sb); if (!right) { sb->sacked_bytes = sb->high_sacked - ack; sb->last_sacked_bytes = sb->sacked_bytes - (old_sacked - sb->last_bytes_delivered); return; } if (seq_gt (sb->high_sacked, right->end)) { sacked = sb->high_sacked - right->end; blks = 1; } /* As per RFC 6675 a sequence number is lost if: * DupThresh discontiguous SACKed sequences have arrived above * 'SeqNum' or more than (DupThresh - 1) * SMSS bytes with sequence * numbers greater than 'SeqNum' have been SACKed. * To avoid spurious retransmits, use reordering estimate instead of * DupThresh to detect loss. */ while (sacked <= (sb->reorder - 1) * snd_mss && blks < sb->reorder) { if (right->is_lost) sb->lost_bytes += scoreboard_hole_bytes (right); left = scoreboard_prev_hole (sb, right); if (!left) { ASSERT (right->start == ack || sb->is_reneging); sacked += right->start - ack; right = 0; break; } sacked += right->start - left->end; blks++; right = left; } /* right is first lost */ while (right) { sb->lost_bytes += scoreboard_hole_bytes (right); sb->last_lost_bytes += right->is_lost ? 0 : (right->end - right->start); right->is_lost = 1; left = scoreboard_prev_hole (sb, right); if (!left) { ASSERT (right->start == ack || sb->is_reneging); sacked += right->start - ack; break; } sacked += right->start - left->end; right = left; } sb->sacked_bytes = sacked; sb->last_sacked_bytes = sacked - (old_sacked - sb->last_bytes_delivered); } /** * Figure out the next hole to retransmit * * Follows logic proposed in RFC6675 Sec. 4, NextSeg() */ sack_scoreboard_hole_t * scoreboard_next_rxt_hole (sack_scoreboard_t * sb, sack_scoreboard_hole_t * start, u8 have_unsent, u8 * can_rescue, u8 * snd_limited) { sack_scoreboard_hole_t *hole = 0; hole = start ? start : scoreboard_first_hole (sb); while (hole && seq_leq (hole->end, sb->high_rxt) && hole->is_lost) hole = scoreboard_next_hole (sb, hole); /* Nothing, return */ if (!hole) { sb->cur_rxt_hole = TCP_INVALID_SACK_HOLE_INDEX; return 0; } /* Rule (1): if higher than rxt, less than high_sac
.. _interfacecommands:

Interface Commands
==================

.. toctree::

   hardware
   interface
   subinterface
hole after high sacked */ hole = scoreboard_last_hole (sb); if (seq_gt (tc->snd_nxt, hole->end)) { if (seq_geq (hole->start, sb->high_sacked)) { hole->end = tc->snd_nxt; } /* New hole after high sacked block */ else if (seq_lt (sb->high_sacked, tc->snd_nxt)) { scoreboard_insert_hole (sb, sb->tail, sb->high_sacked, tc->snd_nxt); } } /* Keep track of max byte sacked for when the last hole * is acked */ high_sacked = seq_max (rcv_sacks[vec_len (rcv_sacks) - 1].end, sb->high_sacked); } /* Walk the holes with the SACK blocks */ hole = pool_elt_at_index (sb->holes, sb->head); if (PREDICT_FALSE (sb->is_reneging)) { sb->last_bytes_delivered += clib_min (hole->start - tc->snd_una, ack - tc->snd_una); sb->is_reneging = seq_lt (ack, hole->start); } while (hole && blk_index < vec_len (rcv_sacks)) { blk = &rcv_sacks[blk_index]; if (seq_leq (blk->start, hole->start)) { /* Block covers hole. Remove hole */ if (seq_geq (blk->end, hole->end)) { next_hole = scoreboard_next_hole (sb, hole); /* If covered by ack, compute delivered bytes */ if (blk->end == ack) { u32 sacked = next_hole ? next_hole->start : seq_max (sb->high_sacked, hole->end); if (PREDICT_FALSE (seq_lt (ack, sacked))) { sb->last_bytes_delivered += ack - hole->end; sb->is_reneging = 1; } else { sb->last_bytes_delivered += sacked - hole->end; sb->is_reneging = 0; } }