Changeset 3e2291a9 in mainline


Ignore:
Timestamp:
2017-09-17T23:37:43Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
797dc79e
Parents:
6969eea3
Message:

TCP tests for ucall module and some more for conn module. Implement tcp_uc_abort(). Fix tcp_uc_open() leaking connection of connecting failed. Fix missing transition Closing → Time-Wait. Fix wrong SEG.ACK in response to FIN.

Location:
uspace/srv/net/tcp
Files:
1 added
5 edited

Legend:

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

    r6969eea3 r3e2291a9  
    6464        test/segment.c \
    6565        test/seq_no.c \
    66         test/tqueue.c
     66        test/tqueue.c \
     67        test/ucall.c
    6768
    6869include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/net/tcp/conn.c

    r6969eea3 r3e2291a9  
    100100void tcp_conns_fini(void)
    101101{
     102        assert(list_empty(&conn_list));
     103
    102104        amap_destroy(amap);
    103105        amap = NULL;
    104 
    105         assert(list_empty(&conn_list));
    106106}
    107107
     
    458458
    459459        log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_conn_reset()", conn->name);
     460
     461        if (conn->cstate == st_closed)
     462                return;
     463
    460464        conn->reset = true;
    461465        tcp_conn_state_set(conn, st_closed);
     
    910914                return cp_done;
    911915
    912         /* TODO */
     916        if (conn->fin_is_acked) {
     917                log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: FIN acked -> Time-Wait",
     918                    conn->name);
     919                tcp_conn_state_set(conn, st_time_wait);
     920        }
     921
    913922        return cp_continue;
    914923}
     
    11071116                log_msg(LOG_DEFAULT, LVL_DEBUG, " - FIN found in segment.");
    11081117
     1118                conn->rcv_nxt++;
     1119                conn->rcv_wnd--;
     1120
    11091121                /* Send ACK */
    11101122                tcp_tqueue_ctrl_seg(conn, CTL_ACK);
    1111 
    1112                 conn->rcv_nxt++;
    1113                 conn->rcv_wnd--;
    11141123
    11151124                /* Change connection state */
  • uspace/srv/net/tcp/test/conn.c

    r6969eea3 r3e2291a9  
    5757        tcp_rqueue_init(&test_rqueue_cb);
    5858        tcp_rqueue_fibril_start();
     59
     60        /* Enable internal loopback */
     61        tcp_conn_lb = tcp_lb_segment;
    5962}
    6063
     
    118121        int rc;
    119122
    120         tcp_conn_lb = tcp_lb_segment;
    121 
    122123        inet_ep2_init(&epp);
    123124        inet_addr(&epp.local.addr, 127, 0, 0, 1);
     
    146147}
    147148
     149/** Test establishing a connection */
     150PCUT_TEST(conn_establish)
     151{
     152        tcp_conn_t *cconn, *sconn;
     153        inet_ep2_t cepp, sepp;
     154        int rc;
     155
     156        /* Client EPP */
     157        inet_ep2_init(&cepp);
     158        inet_addr(&cepp.local.addr, 127, 0, 0, 1);
     159        inet_addr(&cepp.remote.addr, 127, 0, 0, 1);
     160        cepp.remote.port = inet_port_user_lo;
     161
     162        /* Server EPP */
     163        inet_ep2_init(&sepp);
     164        inet_addr(&sepp.local.addr, 127, 0, 0, 1);
     165        sepp.local.port = inet_port_user_lo;
     166
     167        /* Client side of the connection */
     168        cconn = tcp_conn_new(&cepp);
     169        PCUT_ASSERT_NOT_NULL(cconn);
     170
     171        rc = tcp_conn_add(cconn);
     172        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     173
     174        PCUT_ASSERT_INT_EQUALS(st_listen, cconn->cstate);
     175        PCUT_ASSERT_FALSE(tcp_conn_got_syn(cconn));
     176
     177        /* Server side of the connection */
     178        sconn = tcp_conn_new(&sepp);
     179        PCUT_ASSERT_NOT_NULL(sconn);
     180
     181        rc = tcp_conn_add(sconn);
     182        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     183
     184        PCUT_ASSERT_INT_EQUALS(st_listen, sconn->cstate);
     185        PCUT_ASSERT_FALSE(tcp_conn_got_syn(sconn));
     186
     187        /* Start establishing the connection */
     188
     189        tcp_conn_lock(cconn);
     190        tcp_conn_sync(cconn);
     191        PCUT_ASSERT_INT_EQUALS(st_syn_sent, cconn->cstate);
     192        PCUT_ASSERT_FALSE(tcp_conn_got_syn(cconn));
     193
     194        /* Wait for client-side state to transition */
     195        while (cconn->cstate == st_syn_sent)
     196                fibril_condvar_wait(&cconn->cstate_cv, &cconn->lock);
     197
     198        PCUT_ASSERT_INT_EQUALS(st_established, cconn->cstate);
     199        PCUT_ASSERT_TRUE(tcp_conn_got_syn(cconn));
     200        tcp_conn_unlock(cconn);
     201
     202        /* Wait for server-side state to transition */
     203        tcp_conn_lock(sconn);
     204        while (sconn->cstate == st_listen || sconn->cstate == st_syn_received)
     205                fibril_condvar_wait(&sconn->cstate_cv, &sconn->lock);
     206
     207        PCUT_ASSERT_INT_EQUALS(st_established, sconn->cstate);
     208        PCUT_ASSERT_TRUE(tcp_conn_got_syn(sconn));
     209
     210        /* Verify counters */
     211        PCUT_ASSERT_EQUALS(cconn->iss + 1, cconn->snd_nxt);
     212        PCUT_ASSERT_EQUALS(cconn->iss + 1, cconn->snd_una);
     213        PCUT_ASSERT_EQUALS(sconn->iss + 1, sconn->snd_nxt);
     214        PCUT_ASSERT_EQUALS(sconn->iss + 1, sconn->snd_una);
     215
     216        tcp_conn_unlock(sconn);
     217
     218        tcp_conn_lock(cconn);
     219        tcp_conn_reset(cconn);
     220        tcp_conn_unlock(cconn);
     221        tcp_conn_delete(cconn);
     222
     223        tcp_conn_lock(sconn);
     224        tcp_conn_reset(sconn);
     225        tcp_conn_unlock(sconn);
     226        tcp_conn_delete(sconn);
     227}
     228
     229PCUT_TEST(ep2_flipped)
     230{
     231        inet_ep2_t a, fa;
     232
     233        inet_addr(&a.local.addr, 1, 2, 3, 4);
     234        a.local.port = 1234;
     235        inet_addr(&a.remote.addr, 5, 6, 7, 8);
     236        a.remote.port = 5678;
     237
     238        tcp_ep2_flipped(&a, &fa);
     239
     240        PCUT_ASSERT_INT_EQUALS(a.local.port, fa.remote.port);
     241        PCUT_ASSERT_INT_EQUALS(a.remote.port, fa.local.port);
     242
     243        PCUT_ASSERT_TRUE(inet_addr_compare(&a.local.addr, &fa.remote.addr));
     244        PCUT_ASSERT_TRUE(inet_addr_compare(&a.remote.addr, &fa.local.addr));
     245}
     246
    148247PCUT_EXPORT(conn);
  • uspace/srv/net/tcp/test/main.c

    r6969eea3 r3e2291a9  
    6464PCUT_IMPORT(seq_no);
    6565PCUT_IMPORT(tqueue);
     66PCUT_IMPORT(ucall);
    6667
    6768PCUT_MAIN()
  • uspace/srv/net/tcp/ucall.c

    r6969eea3 r3e2291a9  
    108108                assert(nconn->cstate == st_closed);
    109109                tcp_conn_unlock(nconn);
     110                tcp_conn_delete(nconn);
    110111                return TCP_ERESET;
    111112        }
     
    280281{
    281282        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_abort()");
     283\
     284        tcp_conn_lock(conn);
     285        tcp_conn_reset(conn);
     286        tcp_conn_unlock(conn);
    282287}
    283288
Note: See TracChangeset for help on using the changeset viewer.