Changeset e73dbc1 in mainline


Ignore:
Timestamp:
2017-08-31T23:23:55Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1ddbf81
Parents:
94c5bc1
Message:

Add TCP unit tests for segment and seq_no modules. Fix seq_no_segment_acceptable() returning false if receive window is a strict subset of the segment.

Location:
uspace/srv/net/tcp
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tcp/Makefile

    r94c5bc1 re73dbc1  
    3737BINARY = tcp
    3838
    39 SOURCES = \
     39SOURCES_COMMON = \
    4040        conn.c \
    4141        iqueue.c \
     
    4444        rqueue.c \
    4545        segment.c \
    46         service.c \
    4746        seq_no.c \
    48         tcp.c \
    4947        test.c \
    5048        tqueue.c \
    5149        ucall.c
    5250
     51SOURCES = \
     52        $(SOURCES_COMMON) \
     53        service.c \
     54        tcp.c
     55
    5356TEST_SOURCES = \
    54         pdu.c \
    55         segment.c \
    56         seq_no.c \
     57        $(SOURCES_COMMON) \
    5758        test/main.c \
    58         test/pdu.c
     59        test/pdu.c \
     60        test/segment.c \
     61        test/seq_no.c
    5962
    6063include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/net/tcp/seq_no.c

    r94c5bc1 re73dbc1  
    134134}
    135135
    136 /** Determine whether segment is fully acked */
     136/** Determine whether segment is fully acked.
     137 *
     138 * @param conn Connection
     139 * @param seg  Segment
     140 * @param ack  Last received ACK (i.e. SND.UNA)
     141 *
     142 * @return @c true if segment is fully acked, @c false otherwise
     143 */
    137144bool seq_no_segment_acked(tcp_conn_t *conn, tcp_segment_t *seg, uint32_t ack)
    138145{
     
    141148}
    142149
    143 /** Determine whether initial SYN is acked */
     150/** Determine whether initial SYN is acked.
     151 *
     152 * @param conn Connection
     153 * @return @c true if initial SYN is acked, @c false otherwise
     154 */
    144155bool seq_no_syn_acked(tcp_conn_t *conn)
    145156{
     
    147158}
    148159
    149 /** Determine whether segment overlaps the receive window */
     160/** Determine whether segment overlaps the receive window.
     161 *
     162 * @param conn Connection
     163 * @param seg  Segment
     164 * @return @c true if segment overlaps the receive window, @c false otherwise
     165 */
    150166bool seq_no_segment_acceptable(tcp_conn_t *conn, tcp_segment_t *seg)
    151167{
    152168        bool b_in, e_in;
    153 
     169        bool wb_in, we_in;
     170
     171        /* Beginning of segment is inside window */
    154172        b_in = seq_no_le_lt(conn->rcv_nxt, seg->seq, conn->rcv_nxt
    155173            + conn->rcv_wnd);
    156174
     175        /* End of segment is inside window */
    157176        e_in = seq_no_le_lt(conn->rcv_nxt, seg->seq + seg->len - 1,
    158177            conn->rcv_nxt + conn->rcv_wnd);
     178
     179        /* Beginning of window is inside segment */
     180        wb_in = seq_no_le_lt(seg->seq, conn->rcv_nxt,
     181            seg->seq + seg->len);
     182
     183        /* End of window is inside segment */
     184        we_in = seq_no_le_lt(seg->seq, conn->rcv_nxt + conn->rcv_wnd - 1,
     185            seg->seq + seg->len);
    159186
    160187        if (seg->len == 0 && conn->rcv_wnd == 0) {
     
    165192                return false;
    166193        } else {
    167                 return b_in || e_in;
    168         }
    169 }
    170 
    171 /** Determine size that control bits occupy in sequence space. */
     194                return b_in || e_in || wb_in || we_in;
     195        }
     196}
     197
     198/** Determine size that control bits occupy in sequence space.
     199 *
     200 * @param ctrl Control bits combination
     201 * @return Number of sequence space units occupied
     202 */
    172203uint32_t seq_no_control_len(tcp_control_t ctrl)
    173204{
     
    183214}
    184215
    185 /** Calculate the amount of trim needed to fit segment in receive window. */
     216/** Calculate the amount of trim needed to fit segment in receive window.
     217 *
     218 * @param conn  Connection
     219 * @param seg   Segment
     220 * @param left  Place to store number of units to trim at the beginning
     221 * @param right Place to store number of units to trim at the end
     222 */
    186223void seq_no_seg_trim_calc(tcp_conn_t *conn, tcp_segment_t *seg,
    187224    uint32_t *left, uint32_t *right)
  • uspace/srv/net/tcp/test/main.c

    r94c5bc1 re73dbc1  
    2727 */
    2828
     29#include <mem.h>
    2930#include <pcut/pcut.h>
     31
     32#include "main.h"
     33#include "../segment.h"
     34#include "../tcp_type.h"
     35
     36/** Verify that two segments have the same content */
     37void test_seg_same(tcp_segment_t *a, tcp_segment_t *b)
     38{
     39        PCUT_ASSERT_INT_EQUALS(a->ctrl, b->ctrl);
     40        PCUT_ASSERT_INT_EQUALS(a->seq, b->seq);
     41        PCUT_ASSERT_INT_EQUALS(a->ack, b->ack);
     42        PCUT_ASSERT_INT_EQUALS(a->len, b->len);
     43        PCUT_ASSERT_INT_EQUALS(a->wnd, b->wnd);
     44        PCUT_ASSERT_INT_EQUALS(a->up, b->up);
     45        PCUT_ASSERT_INT_EQUALS(tcp_segment_text_size(a),
     46            tcp_segment_text_size(b));
     47        if (tcp_segment_text_size(a) != 0)
     48                PCUT_ASSERT_NOT_NULL(a->data);
     49        if (tcp_segment_text_size(b) != 0)
     50                PCUT_ASSERT_NOT_NULL(b->data);
     51        if (tcp_segment_text_size(a) != 0) {
     52                PCUT_ASSERT_INT_EQUALS(0, memcmp(a->data, b->data,
     53                    tcp_segment_text_size(a)));
     54        }
     55}
    3056
    3157PCUT_INIT
    3258
    3359PCUT_IMPORT(pdu);
     60PCUT_IMPORT(segment);
     61PCUT_IMPORT(seq_no);
    3462
    3563PCUT_MAIN()
  • uspace/srv/net/tcp/test/pdu.c

    r94c5bc1 re73dbc1  
    2929#include <errno.h>
    3030#include <inet/endpoint.h>
     31#include <mem.h>
    3132#include <pcut/pcut.h>
    32 #include <str.h>
    3333#include <stdlib.h>
    3434
     35#include "main.h"
    3536#include "../pdu.h"
    3637#include "../segment.h"
    37 
    38 /** Verify that two segments have the same content */
    39 static void pdu_seg_cmp(tcp_segment_t *a, tcp_segment_t *b)
    40 {
    41         PCUT_ASSERT_INT_EQUALS(a->ctrl, b->ctrl);
    42         PCUT_ASSERT_INT_EQUALS(a->seq, b->seq);
    43         PCUT_ASSERT_INT_EQUALS(a->ack, b->ack);
    44         PCUT_ASSERT_INT_EQUALS(a->len, b->len);
    45         PCUT_ASSERT_INT_EQUALS(a->wnd, b->wnd);
    46         PCUT_ASSERT_INT_EQUALS(a->up, b->up);
    47         PCUT_ASSERT_INT_EQUALS(tcp_segment_text_size(a),
    48             tcp_segment_text_size(b));
    49         if (tcp_segment_text_size(a) != 0)
    50                 PCUT_ASSERT_NOT_NULL(a->data);
    51         if (tcp_segment_text_size(b) != 0)
    52                 PCUT_ASSERT_NOT_NULL(b->data);
    53         if (tcp_segment_text_size(a) != 0) {
    54                 PCUT_ASSERT_INT_EQUALS(0, memcmp(a->data, b->data,
    55                     tcp_segment_text_size(a)));
    56         }
    57 }
    5838
    5939PCUT_INIT
     
    8666        PCUT_ASSERT_INT_EQUALS(EOK, rc);
    8767
    88         pdu_seg_cmp(seg, dseg);
     68        test_seg_same(seg, dseg);
    8969        tcp_segment_delete(seg);
    9070}
     
    124104        PCUT_ASSERT_INT_EQUALS(EOK, rc);
    125105
    126         pdu_seg_cmp(seg, dseg);
     106        test_seg_same(seg, dseg);
    127107        tcp_segment_delete(seg);
    128108        free(data);
Note: See TracChangeset for help on using the changeset viewer.