Main Page | Class List | File List | Class Members | File Members

scheduler.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <semaphore.h>
#include <pthread.h>
#include <sys/socket.h>
#include <linux/tcp.h>
#include <linux/ip.h>
#include <linux/in.h>
#include "tcpproxy.h"
#include "misc.h"
#include "tcptimer.h"
#include "tcp.h"
#include "scheduler.h"

Go to the source code of this file.

Typedefs

typedef packet_sent Tpacket_sent
typedef packet_queue Tpacket_queue

Enumerations

enum  queue_state { QUEUE_STATE_FREE = 0, QUEUE_STATE_USED, QUEUE_STATE_CLOSED }

Functions

void init_sched ()
int queue_size (Tpacket_queue *q)
int queue_empty (Tpacket_queue *q)
void packet_timeout (void *arg)
void add_tcp_sent (Tpacket_data *pd, unsigned size, Tpacket_queue *q)
int alloc_tcp_queue (unsigned weight)
int close_tcp_queue (int queue_num)
int clear_tcp_queue (int queue_num)
int reset_tcp_queue (int queue_num)
int check_dealloc_tcp_queue (int queue_num)
void cleanup_sched ()
int send_packet (Tpacket_data *pd)
int queue_packet (Tpacket_data *pd, Tpacket_queue *q)
Tpacket_datadequeue_packet (Tpacket_queue *q)
void mh_ack_rcvd (unsigned ack_seq, int queue_num)
int queue_tcp (Tpacket_data *pd, int queue_num)
int queue_hipri (Tpacket_data *pd)
int queue_lowpri (Tpacket_data *pd)
void scheduler (void *sig_mask)

Variables

enum queue_state Tqueue_state
static int sock
static Tpacket_queue tcp_pq [TCP_MAX_QUEUES]
static Tpacket_queue hipri_pq
static Tpacket_queue lowpri_pq
static pthread_mutex_t sched_mut
static sem_t send_sem
static long queued_pkts
static unsigned tcp_in_flight
static int max_tcp_in_flight = TCP_WIN_CLAMP_SIZE


Typedef Documentation

typedef struct packet_queue Tpacket_queue
 

typedef struct packet_sent Tpacket_sent
 


Enumeration Type Documentation

enum queue_state
 

Enumeration values:
QUEUE_STATE_FREE 
QUEUE_STATE_USED 
QUEUE_STATE_CLOSED 

Definition at line 23 of file scheduler.c.


Function Documentation

void add_tcp_sent Tpacket_data pd,
unsigned  size,
Tpacket_queue q
 

Definition at line 198 of file scheduler.c.

References add_timer(), get_mclock(), packet_sent::mtime, packet_sent::next, packet_timeout(), packet_sent::prev, packet_sent::q, packet_queue::sent_hd, packet_sent::seq, seq_cmp(), packet_sent::size, TCP_PACKET_TIMEOUT, packet_data::trans, and xmalloc().

Referenced by scheduler().

int alloc_tcp_queue unsigned  weight  ) 
 

Definition at line 239 of file scheduler.c.

References DPRINT, mutex_lock(), mutex_unlock(), QUEUE_STATE_FREE, QUEUE_STATE_USED, sched_mut, packet_queue::state, TCP_MAX_QUEUES, and packet_queue::weight.

Referenced by alloc_tcp_cb().

int check_dealloc_tcp_queue int  queue_num  )  [inline]
 

Definition at line 380 of file scheduler.c.

References DPRINT, packet_queue::head, packet_queue::in_flight, queue_empty(), QUEUE_STATE_CLOSED, QUEUE_STATE_FREE, packet_queue::state, packet_queue::tail, and TCP_MAX_QUEUES.

Referenced by mh_ack_rcvd(), and scheduler().

void cleanup_sched  ) 
 

Definition at line 400 of file scheduler.c.

References clear_tcp_queue(), QUEUE_STATE_FREE, send_sem, sock, packet_queue::state, packet_queue::tab, TCP_MAX_QUEUES, and xfree().

Referenced by main().

int clear_tcp_queue int  queue_num  ) 
 

Definition at line 289 of file scheduler.c.

References clear_timer(), dealloc_packet_data(), DEBUG, DPRINT, packet_queue::head, packet_queue::in_flight, packet_queue::max, packet_sent::next, packet_timeout(), queue_empty(), queue_size(), queued_pkts, send_sem, packet_queue::sent_hd, packet_sent::size, packet_queue::tab, tcp_in_flight, TCP_MAX_QUEUES, and xfree().

Referenced by cleanup_sched(), and reset_tcp_queue().

int close_tcp_queue int  queue_num  ) 
 

Definition at line 267 of file scheduler.c.

References DPRINT, mutex_lock(), mutex_unlock(), QUEUE_STATE_CLOSED, QUEUE_STATE_USED, sched_mut, packet_queue::state, and TCP_MAX_QUEUES.

Referenced by dealloc_tcp_cb().

Tpacket_data* dequeue_packet Tpacket_queue q  )  [inline]
 

Definition at line 496 of file scheduler.c.

References packet_queue::head, packet_queue::max, queue_empty(), queued_pkts, and packet_queue::tab.

Referenced by scheduler().

void init_sched  ) 
 

Definition at line 67 of file scheduler.c.

References packet_queue::dc, EPRINT, EXIT_ERR_SEM_INIT, EXIT_ERR_SOCKET, packet_queue::head, packet_queue::in_flight, packet_queue::max, QUEUE_SIZE_HI_PRI, QUEUE_SIZE_LOW_PRI, QUEUE_SIZE_TCP, QUEUE_STATE_FREE, QUEUE_STATE_USED, QUEUE_WEIGHT_NORMAL, queued_pkts, safe_exit(), sched_mut, send_sem, packet_queue::sent_hd, sock, packet_queue::state, packet_queue::tab, packet_queue::tail, tcp_in_flight, TCP_MAX_QUEUES, packet_queue::weight, and xmalloc().

Referenced by main().

void mh_ack_rcvd unsigned  ack_seq,
int  queue_num
 

Definition at line 515 of file scheduler.c.

References check_dealloc_tcp_queue(), clear_timer(), DPRINT, packet_queue::in_flight, mutex_lock(), mutex_unlock(), packet_sent::next, packet_timeout(), packet_sent::prev, sched_mut, send_sem, packet_queue::sent_hd, packet_sent::seq, seq_cmp(), packet_sent::size, tcp_in_flight, and xfree().

Referenced by handle_tcp().

void packet_timeout void *  arg  ) 
 

Definition at line 167 of file scheduler.c.

References DPRINT, packet_queue::in_flight, mutex_lock(), mutex_unlock(), packet_sent::next, packet_sent::prev, packet_sent::q, sched_mut, packet_queue::sent_hd, packet_sent::seq, packet_sent::size, tcp_in_flight, and xfree().

Referenced by add_tcp_sent(), clear_tcp_queue(), and mh_ack_rcvd().

int queue_empty Tpacket_queue q  )  [inline]
 

Definition at line 156 of file scheduler.c.

References packet_queue::head, and packet_queue::tail.

Referenced by check_dealloc_tcp_queue(), clear_tcp_queue(), dequeue_packet(), and scheduler().

int queue_hipri Tpacket_data pd  ) 
 

Definition at line 582 of file scheduler.c.

References packet_data::dir, DPRINT, PACKET_DIR_IN, PACKET_DIR_OUT, queue_packet(), send_packet(), and UNREACHABLE.

Referenced by handle_icmp(), handle_tcp(), and send_tcp_rst().

int queue_lowpri Tpacket_data pd  ) 
 

Definition at line 599 of file scheduler.c.

References packet_data::dir, DPRINT, PACKET_DIR_IN, PACKET_DIR_OUT, queue_packet(), send_packet(), and UNREACHABLE.

Referenced by handle_other().

int queue_packet Tpacket_data pd,
Tpacket_queue q
 

Definition at line 455 of file scheduler.c.

References dealloc_packet_data(), DEBUG, DPRINT, packet_queue::max, mutex_lock(), mutex_unlock(), queue_size(), queued_pkts, sched_mut, send_sem, packet_queue::tab, packet_queue::tail, and TCP_MAX_QUEUES.

Referenced by queue_hipri(), queue_lowpri(), and queue_tcp().

int queue_size Tpacket_queue q  )  [inline]
 

Definition at line 145 of file scheduler.c.

References packet_queue::head, packet_queue::max, and packet_queue::tail.

Referenced by clear_tcp_queue(), queue_packet(), and scheduler().

int queue_tcp Tpacket_data pd,
int  queue_num
 

Definition at line 555 of file scheduler.c.

References packet_data::dir, DPRINT, PACKET_DIR_IN, PACKET_DIR_OUT, queue_packet(), send_packet(), TCP_MAX_QUEUES, packet_data::trans, and UNREACHABLE.

Referenced by handle_tcp().

int reset_tcp_queue int  queue_num  ) 
 

Definition at line 357 of file scheduler.c.

References clear_tcp_queue(), mutex_lock(), mutex_unlock(), QUEUE_STATE_USED, sched_mut, and TCP_MAX_QUEUES.

Referenced by handle_tcp().

void scheduler void *  sig_mask  ) 
 

Definition at line 620 of file scheduler.c.

References add_tcp_sent(), check_dealloc_tcp_queue(), packet_queue::dc, dequeue_packet(), DPRINT, DRR_QUANTUM, EPRINT, packet_queue::head, packet_queue::in_flight, packet_queue::max, max_tcp_in_flight, mutex_lock(), mutex_unlock(), queue_empty(), queue_size(), QUEUE_STATE_FREE, queued_pkts, request_exit, sched_mut, send_packet(), send_sem, packet_queue::state, packet_queue::tab, tcp_data_size(), tcp_in_flight, TCP_MAX_QUEUES, and packet_queue::weight.

Referenced by main().

int send_packet Tpacket_data pd  ) 
 

Definition at line 424 of file scheduler.c.

References dealloc_packet_data(), DPRINT, EPRINT, packet_data::ip, packet_data::ipq_pm, packet_data::payload, and sock.

Referenced by queue_hipri(), queue_lowpri(), queue_tcp(), and scheduler().


Variable Documentation

Tpacket_queue hipri_pq [static]
 

Definition at line 55 of file scheduler.c.

Tpacket_queue lowpri_pq [static]
 

Definition at line 56 of file scheduler.c.

int max_tcp_in_flight = TCP_WIN_CLAMP_SIZE [static]
 

Definition at line 61 of file scheduler.c.

Referenced by scheduler().

long queued_pkts [static]
 

Definition at line 59 of file scheduler.c.

Referenced by clear_tcp_queue(), dequeue_packet(), init_sched(), queue_packet(), and scheduler().

pthread_mutex_t sched_mut [static]
 

Definition at line 57 of file scheduler.c.

Referenced by alloc_tcp_queue(), close_tcp_queue(), init_sched(), mh_ack_rcvd(), packet_timeout(), queue_packet(), reset_tcp_queue(), and scheduler().

sem_t send_sem [static]
 

Definition at line 58 of file scheduler.c.

Referenced by cleanup_sched(), clear_tcp_queue(), init_sched(), mh_ack_rcvd(), queue_packet(), and scheduler().

int sock [static]
 

Definition at line 53 of file scheduler.c.

Referenced by cleanup_sched(), init_sched(), and send_packet().

unsigned tcp_in_flight [static]
 

Definition at line 60 of file scheduler.c.

Referenced by clear_tcp_queue(), init_sched(), mh_ack_rcvd(), packet_timeout(), and scheduler().

Tpacket_queue tcp_pq[TCP_MAX_QUEUES] [static]
 

Definition at line 54 of file scheduler.c.

enum queue_state Tqueue_state
 


Generated on Sun May 14 13:36:53 2006 by  doxygen 1.4.2