Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset d14840d in mainline


Ignore:
Timestamp:
2017-09-06T17:08:23Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
fc3d4fd5
Parents:
42f61f01
Message:

Add test for TCP rqueue.

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

Legend:

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

    r42f61f01 rd14840d  
    6060        test/main.c \
    6161        test/pdu.c \
     62        test/rqueue.c \
    6263        test/segment.c \
    6364        test/seq_no.c
  • uspace/srv/net/tcp/rqueue.c

    r42f61f01 rd14840d  
    3838#include <errno.h>
    3939#include <io/log.h>
     40#include <stdbool.h>
    4041#include <stdlib.h>
    4142#include <fibril.h>
     43#include <fibril_synch.h>
    4244#include "conn.h"
    4345#include "pdu.h"
     
    5658
    5759static prodcons_t rqueue;
     60static bool fibril_active;
     61static fibril_mutex_t lock;
     62static fibril_condvar_t cv;
     63static tcp_rqueue_cb_t *rqueue_cb;
    5864
    5965/** Initialize segment receive queue. */
    60 void tcp_rqueue_init(void)
     66void tcp_rqueue_init(tcp_rqueue_cb_t *rcb)
    6167{
    6268        prodcons_initialize(&rqueue);
     69        fibril_mutex_initialize(&lock);
     70        fibril_condvar_initialize(&cv);
     71        fibril_active = false;
     72        rqueue_cb = rcb;
     73}
     74
     75/** Finalize segment receive queue. */
     76void tcp_rqueue_fini(void)
     77{
     78        inet_ep2_t epp;
     79
     80        inet_ep2_init(&epp);
     81        tcp_rqueue_insert_seg(&epp, NULL);
     82
     83        fibril_mutex_lock(&lock);
     84        while (fibril_active)
     85                fibril_condvar_wait(&cv, &lock);
     86        fibril_mutex_unlock(&lock);
    6387}
    6488
     
    112136{
    113137        tcp_rqueue_entry_t *rqe;
    114         log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_rqueue_insert_seg()");
    115 
    116         tcp_segment_dump(seg);
     138
     139        log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_rqueue_insert_seg()");
     140
     141        if (seg != NULL)
     142                tcp_segment_dump(seg);
    117143
    118144        rqe = calloc(1, sizeof(tcp_rqueue_entry_t));
     
    140166                rqe = list_get_instance(link, tcp_rqueue_entry_t, link);
    141167
    142                 tcp_as_segment_arrived(&rqe->epp, rqe->seg);
     168                if (rqe->seg == NULL) {
     169                        free(rqe);
     170                        break;
     171                }
     172
     173                rqueue_cb->seg_received(&rqe->epp, rqe->seg);
    143174                free(rqe);
    144175        }
    145176
    146         /* Not reached */
     177        log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_rqueue_fibril() exiting");
     178
     179        /* Finished */
     180        fibril_mutex_lock(&lock);
     181        fibril_active = false;
     182        fibril_mutex_unlock(&lock);
     183        fibril_condvar_broadcast(&cv);
     184
    147185        return 0;
    148186}
     
    162200
    163201        fibril_add_ready(fid);
     202        fibril_active = true;
    164203}
    165204
  • uspace/srv/net/tcp/rqueue.h

    r42f61f01 rd14840d  
    3939#include "tcp_type.h"
    4040
    41 extern void tcp_rqueue_init(void);
     41extern void tcp_rqueue_init(tcp_rqueue_cb_t *);
     42extern void tcp_rqueue_fibril_start(void);
     43extern void tcp_rqueue_fini(void);
    4244extern void tcp_rqueue_bounce_seg(inet_ep2_t *, tcp_segment_t *);
    4345extern void tcp_rqueue_insert_seg(inet_ep2_t *, tcp_segment_t *);
    44 extern void tcp_rqueue_handler(void *);
    45 extern void tcp_rqueue_fibril_start(void);
    4646
    4747
  • uspace/srv/net/tcp/tcp.c

    r42f61f01 rd14840d  
    4747#include "service.h"
    4848#include "test.h"
     49#include "ucall.h"
    4950
    5051#define NAME       "tcp"
     52
     53static tcp_rqueue_cb_t tcp_rqueue_cb = {
     54        .seg_received = tcp_as_segment_arrived
     55};
    5156
    5257static int tcp_init(void)
     
    6368        }
    6469
    65         tcp_rqueue_init();
     70        tcp_rqueue_init(&tcp_rqueue_cb);
    6671        tcp_rqueue_fibril_start();
    6772
  • uspace/srv/net/tcp/tcp_type.h

    r42f61f01 rd14840d  
    280280} tcp_rqueue_entry_t;
    281281
     282/** Receive queue callbacks */
     283typedef struct {
     284        /** Segment received */
     285        void (*seg_received)(inet_ep2_t *, tcp_segment_t *);
     286} tcp_rqueue_cb_t;
     287
    282288/** NCSim queue entry */
    283289typedef struct {
  • uspace/srv/net/tcp/test/main.c

    r42f61f01 rd14840d  
    5959PCUT_IMPORT(iqueue);
    6060PCUT_IMPORT(pdu);
     61PCUT_IMPORT(rqueue);
    6162PCUT_IMPORT(segment);
    6263PCUT_IMPORT(seq_no);
Note: See TracChangeset for help on using the changeset viewer.