Changeset 9520af7 in mainline


Ignore:
Timestamp:
2017-09-12T15:48:01Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1d40c93d
Parents:
0a1e7e4
Message:

Allow TCP conn tests that involve transferring data by enabling an internal loopback. Add simple →SYN, ←RST test.

Location:
uspace/srv/net/tcp
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tcp/conn.c

    r0a1e7e4 r9520af7  
    4747#include "iqueue.h"
    4848#include "pdu.h"
     49#include "rqueue.h"
    4950#include "segment.h"
    5051#include "seq_no.h"
     
    6566/** Connection association map */
    6667static amap_t *amap;
     68/** Taken after tcp_conn_t lock */
    6769static FIBRIL_MUTEX_INITIALIZE(amap_lock);
     70
     71/** Internal loopback configuration */
     72tcp_lb_t tcp_conn_lb = tcp_lb_none;
    6873
    6974static void tcp_conn_seg_process(tcp_conn_t *, tcp_segment_t *);
     
    7176static void tcp_conn_tw_timer_clear(tcp_conn_t *);
    7277static void tcp_transmit_segment(inet_ep2_t *, tcp_segment_t *);
     78static void tcp_conn_trim_seg_to_wnd(tcp_conn_t *, tcp_segment_t *);
     79static void tcp_reply_rst(inet_ep2_t *, tcp_segment_t *);
    7380
    7481static tcp_tqueue_cb_t tcp_conn_tqueue_cb = {
     
    324331 * Remove connection from the connection map.
    325332 */
    326 void tcp_conn_remove(tcp_conn_t *conn)
     333static void tcp_conn_remove(tcp_conn_t *conn)
    327334{
    328335        if (!conn->mapped)
     
    369376void tcp_conn_sync(tcp_conn_t *conn)
    370377{
     378        assert(fibril_mutex_is_locked(&conn->lock));
     379
    371380        /* XXX select ISS */
    372381        conn->iss = 1;
     
    13581367 * @param seg           Segment
    13591368 */
    1360 void tcp_conn_trim_seg_to_wnd(tcp_conn_t *conn, tcp_segment_t *seg)
     1369static void tcp_conn_trim_seg_to_wnd(tcp_conn_t *conn, tcp_segment_t *seg)
    13611370{
    13621371        uint32_t left, right;
     
    13821391}
    13831392
     1393/** Transmit segment over network.
     1394 *
     1395 * @param epp Endpoint pair with source and destination information
     1396 * @param seg Segment (ownership retained by caller)
     1397 */
    13841398static void tcp_transmit_segment(inet_ep2_t *epp, tcp_segment_t *seg)
    13851399{
     1400        tcp_pdu_t *pdu;
     1401        tcp_segment_t *dseg;
     1402        inet_ep2_t rident;
     1403
    13861404        log_msg(LOG_DEFAULT, LVL_DEBUG,
    13871405            "tcp_transmit_segment(l:(%u),f:(%u), %p)",
     
    13931411        tcp_segment_dump(seg);
    13941412
    1395 //      tcp_rqueue_bounce_seg(sp, seg);
    1396 //      tcp_ncsim_bounce_seg(sp, seg);
    1397 
    1398         tcp_pdu_t *pdu;
     1413        if (tcp_conn_lb == tcp_lb_segment) {
     1414                /* Loop back segment */
     1415//              tcp_ncsim_bounce_seg(sp, seg);
     1416
     1417                /* Reverse the identification */
     1418                tcp_ep2_flipped(epp, &rident);
     1419
     1420                /* Insert segment back into rqueue */
     1421                dseg = tcp_segment_dup(seg);
     1422                tcp_rqueue_insert_seg(&rident, dseg);
     1423                return;
     1424        }
    13991425
    14001426        if (tcp_pdu_encode(epp, seg, &pdu) != EOK) {
     
    14031429        }
    14041430
     1431        if (tcp_conn_lb == tcp_lb_pdu) {
     1432                /* Loop back PDU */
     1433                if (tcp_pdu_decode(pdu, &rident, &dseg) != EOK) {
     1434                        log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped.");
     1435                        tcp_pdu_delete(pdu);
     1436                        return;
     1437                }
     1438
     1439                tcp_pdu_delete(pdu);
     1440
     1441                /* Insert decoded segment into rqueue */
     1442                tcp_rqueue_insert_seg(&rident, dseg);
     1443                return;
     1444        }
     1445
    14051446        tcp_transmit_pdu(pdu);
    14061447        tcp_pdu_delete(pdu);
     
    14251466 * @param seg           Incoming segment
    14261467 */
    1427 void tcp_reply_rst(inet_ep2_t *epp, tcp_segment_t *seg)
     1468static void tcp_reply_rst(inet_ep2_t *epp, tcp_segment_t *seg)
    14281469{
    14291470        tcp_segment_t *rseg;
  • uspace/srv/net/tcp/conn.h

    r0a1e7e4 r9520af7  
    4545extern void tcp_conn_delete(tcp_conn_t *);
    4646extern int tcp_conn_add(tcp_conn_t *);
    47 extern void tcp_conn_remove(tcp_conn_t *);
    4847extern void tcp_conn_reset(tcp_conn_t *conn);
    4948extern void tcp_conn_sync(tcp_conn_t *);
    5049extern void tcp_conn_fin_sent(tcp_conn_t *);
    51 extern void tcp_conn_ack_of_fin_rcvd(tcp_conn_t *);
    5250extern tcp_conn_t *tcp_conn_find_ref(inet_ep2_t *);
    5351extern void tcp_conn_addref(tcp_conn_t *);
     
    5856extern void tcp_conn_segment_arrived(tcp_conn_t *, inet_ep2_t *,
    5957    tcp_segment_t *);
    60 extern void tcp_conn_trim_seg_to_wnd(tcp_conn_t *, tcp_segment_t *);
    6158extern void tcp_unexpected_segment(inet_ep2_t *, tcp_segment_t *);
    6259extern void tcp_ep2_flipped(inet_ep2_t *, inet_ep2_t *);
    63 extern void tcp_reply_rst(inet_ep2_t *, tcp_segment_t *);
     60
     61extern tcp_lb_t tcp_conn_lb;
    6462
    6563#endif
  • uspace/srv/net/tcp/ncsim.c

    r0a1e7e4 r9520af7  
    7373        tcp_squeue_entry_t *sqe;
    7474        tcp_squeue_entry_t *old_qe;
     75        inet_ep2_t rident;
    7576        link_t *link;
    7677
    7778        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_ncsim_bounce_seg()");
    78         tcp_rqueue_bounce_seg(epp, seg);
     79        tcp_ep2_flipped(epp, &rident);
     80        tcp_rqueue_insert_seg(&rident, seg);
    7981        return;
    8082
     
    125127        link_t *link;
    126128        tcp_squeue_entry_t *sqe;
     129        inet_ep2_t rident;
    127130        int rc;
    128131
     
    148151
    149152                log_msg(LOG_DEFAULT, LVL_DEBUG, "NCSim - End Sleep");
    150                 tcp_rqueue_bounce_seg(&sqe->epp, sqe->seg);
     153                tcp_ep2_flipped(&sqe->epp, &rident);
     154                tcp_rqueue_insert_seg(&rident, sqe->seg);
    151155                free(sqe);
    152156        }
  • uspace/srv/net/tcp/rqueue.c

    r0a1e7e4 r9520af7  
    4343#include <fibril_synch.h>
    4444#include "conn.h"
    45 #include "pdu.h"
    4645#include "rqueue.h"
    4746#include "segment.h"
    4847#include "tcp_type.h"
    4948#include "ucall.h"
    50 
    51 /** Transcode bounced segments.
    52  *
    53  * If defined, segments bounced via the internal debugging loopback will
    54  * be encoded to a PDU and the decoded. Otherwise they will be bounced back
    55  * directly without passing the encoder-decoder.
    56  */
    57 #define BOUNCE_TRANSCODE
    5849
    5950static prodcons_t rqueue;
     
    8778}
    8879
    89 /** Bounce segment directy into receive queue without constructing the PDU.
    90  *
    91  * This is for testing purposes only.
    92  *
    93  * @param sp    Endpoint pair, oriented for transmission
    94  * @param seg   Segment
    95  */
    96 void tcp_rqueue_bounce_seg(inet_ep2_t *epp, tcp_segment_t *seg)
    97 {
    98         inet_ep2_t rident;
    99 
    100         log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_rqueue_bounce_seg()");
    101 
    102 #ifdef BOUNCE_TRANSCODE
    103         tcp_pdu_t *pdu;
    104         tcp_segment_t *dseg;
    105 
    106         if (tcp_pdu_encode(epp, seg, &pdu) != EOK) {
    107                 log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped.");
    108                 return;
    109         }
    110 
    111         if (tcp_pdu_decode(pdu, &rident, &dseg) != EOK) {
    112                 log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped.");
    113                 return;
    114         }
    115 
    116         tcp_pdu_delete(pdu);
    117 
    118         /** Insert decoded segment into rqueue */
    119         tcp_rqueue_insert_seg(&rident, dseg);
    120         tcp_segment_delete(seg);
    121 #else
    122         /* Reverse the identification */
    123         tcp_ep2_flipped(epp, &rident);
    124 
    125         /* Insert segment back into rqueue */
    126         tcp_rqueue_insert_seg(&rident, seg);
    127 #endif
    128 }
    129 
    13080/** Insert segment into receive queue.
    13181 *
    13282 * @param epp   Endpoint pair, oriented for reception
    133  * @param seg   Segment
     83 * @param seg   Segment (ownership transferred to rqueue)
    13484 */
    13585void tcp_rqueue_insert_seg(inet_ep2_t *epp, tcp_segment_t *seg)
  • uspace/srv/net/tcp/rqueue.h

    r0a1e7e4 r9520af7  
    4242extern void tcp_rqueue_fibril_start(void);
    4343extern void tcp_rqueue_fini(void);
    44 extern void tcp_rqueue_bounce_seg(inet_ep2_t *, tcp_segment_t *);
    4544extern void tcp_rqueue_insert_seg(inet_ep2_t *, tcp_segment_t *);
    4645
  • uspace/srv/net/tcp/tcp_type.h

    r0a1e7e4 r9520af7  
    379379} tcp_client_t;
    380380
     381/** Internal loopback type */
     382typedef enum {
     383        /** No loopback */
     384        tcp_lb_none,
     385        /** Segment loopback */
     386        tcp_lb_segment,
     387        /** PDU loopback */
     388        tcp_lb_pdu
     389} tcp_lb_t;
     390
    381391#endif
    382392
  • uspace/srv/net/tcp/test/conn.c

    r0a1e7e4 r9520af7  
    3333
    3434#include "../conn.h"
     35#include "../rqueue.h"
     36#include "../ucall.h"
    3537
    3638PCUT_INIT
    3739
    3840PCUT_TEST_SUITE(conn);
     41
     42static tcp_rqueue_cb_t test_rqueue_cb = {
     43        .seg_received = tcp_as_segment_arrived
     44};
    3945
    4046PCUT_TEST_BEFORE
     
    4854        rc = tcp_conns_init();
    4955        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     56
     57        tcp_rqueue_init(&test_rqueue_cb);
     58        tcp_rqueue_fibril_start();
    5059}
    5160
    5261PCUT_TEST_AFTER
    5362{
     63        tcp_rqueue_fini();
    5464        tcp_conns_fini();
    5565}
     
    7181}
    7282
    73 /** Test adding, finding and removing a connection */
    74 PCUT_TEST(add_find_remove)
     83/** Test adding, finding and deleting a connection */
     84PCUT_TEST(add_find_delete)
    7585{
    7686        tcp_conn_t *conn, *cfound;
     
    101111}
    102112
     113/** Test trying to connect to endpoint that sends RST back */
     114PCUT_TEST(connect_rst)
     115{
     116        tcp_conn_t *conn;
     117        inet_ep2_t epp;
     118        int rc;
     119
     120        tcp_conn_lb = tcp_lb_segment;
     121
     122        inet_ep2_init(&epp);
     123        inet_addr(&epp.local.addr, 127, 0, 0, 1);
     124        inet_addr(&epp.remote.addr, 127, 0, 0, 1);
     125        epp.remote.port = inet_port_user_lo;
     126
     127        conn = tcp_conn_new(&epp);
     128        PCUT_ASSERT_NOT_NULL(conn);
     129
     130        rc = tcp_conn_add(conn);
     131        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     132
     133        PCUT_ASSERT_INT_EQUALS(st_listen, conn->cstate);
     134
     135        tcp_conn_lock(conn);
     136        tcp_conn_sync(conn);
     137        PCUT_ASSERT_INT_EQUALS(st_syn_sent, conn->cstate);
     138
     139        while (conn->cstate == st_syn_sent)
     140                fibril_condvar_wait(&conn->cstate_cv, &conn->lock);
     141
     142        PCUT_ASSERT_INT_EQUALS(st_closed, conn->cstate);
     143
     144        tcp_conn_unlock(conn);
     145        tcp_conn_delete(conn);
     146}
     147
    103148PCUT_EXPORT(conn);
  • uspace/srv/net/tcp/tqueue.c

    r0a1e7e4 r9520af7  
    106106        tcp_segment_t *seg;
    107107
     108        assert(fibril_mutex_is_locked(&conn->lock));
     109
    108110        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_tqueue_ctrl_seg(%p, %u)", conn, ctrl);
    109111
     
    117119        tcp_segment_t *rt_seg;
    118120        tcp_tqueue_entry_t *tqe;
     121
     122        assert(fibril_mutex_is_locked(&conn->lock));
    119123
    120124        log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_tqueue_seg(%p, %p)", conn->name, conn,
     
    366370static void tcp_tqueue_timer_set(tcp_conn_t *conn)
    367371{
     372        assert(fibril_mutex_is_locked(&conn->lock));
     373
    368374        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_set() begin", conn->name);
    369375
     
    381387static void tcp_tqueue_timer_clear(tcp_conn_t *conn)
    382388{
     389        assert(fibril_mutex_is_locked(&conn->lock));
     390
    383391        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_clear() begin", conn->name);
    384392
Note: See TracChangeset for help on using the changeset viewer.