KENS
 All Data Structures Files Functions Variables Typedefs Macros Pages
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
ktcp_easy_impl.c File Reference

Template for easy-KTCP project. More...

#include "ktcp_easy_impl.h"
#include "log.h"
#include "linked_list.h"
#include <errno.h>
#include <assert.h>

Data Structures

struct  send_packet
 
struct  receive_packet
 
struct  context
 
struct  pseudoheader
 
struct  global_context_t
 

Macros

#define MIN(x, y)   ((x) <= (y) ? (x) : (y))
 
#define MAX(x, y)   ((x) >= (y) ? (x) : (y))
 
#define DEFAULT_WINDOW_SIZE   (3072)
 
#define TCP_DUPLICATED_ACK_LIMIT   (3)
 
#define TCP_RETRY_COUNT   (10)
 
#define TCP_MAX_SEQ_RANGE   (4294967295U >> 1)
 
#define TCP_MAX_PACKET   (512)
 
#define TCP_RECV_BUFFER   (3072)
 
#define TCP_SAFE_CLOSE
 
#define TCP_MIN_TIME_WAIT   (5000)
 
#define TCP_DEFAULT_RTT   (1000)
 
#define TCP_MIN_RTT   (50)
 

Typedefs

typedef struct send_packet send_packet_t
 
typedef struct receive_packet receive_packet_t
 
typedef struct context context_t
 

Enumerations

enum  {
  CSTATE_CLOSED = 0, CSTATE_LISTEN = 1, CSTATE_SYN_SENT = 2, CSTATE_SYN_RECV = 3,
  CSTATE_ESTABLISHED = 4, CSTATE_FIN_WAIT1 = 5, CSTATE_FIN_WAIT2 = 6, CSTATE_CLOSING = 7,
  CSTATE_TIME_WAIT = 8, CSTATE_CLOSE_WAIT = 9, CSTATE_LAST_ACK = 10
}
 

Functions

bool my_startup (void)
 
void my_shutdown (void)
 
my_context my_open (int *err)
 
void my_close (my_context handle, int *err)
 
bool my_bind (my_context handle, const struct sockaddr *my_addr, socklen_t addrlen, int *err)
 
bool my_listen (my_context handle, int backlog, int *err)
 
bool my_connect (my_context handle, const struct sockaddr *serv_addr, socklen_t addrlen, int *err)
 
bool my_accept (my_context handle, int *err)
 
bool my_getsockname (my_context handle, struct sockaddr *name, socklen_t *namelen, int *err)
 
bool my_getpeername (my_context handle, struct sockaddr *name, socklen_t *namelen, int *err)
 
int app_dispatch_tcp (my_context handle, const void *data, size_t data_size)
 
void ip_dispatch_tcp (struct in_addr src_addr, struct in_addr dest_addr, const void *data, size_t data_size)
 
void my_timer (my_context handle, int actual_called)
 

Variables

const char * CSTATE_strs []
 
global_context_t my_tcp
 

Detailed Description

Template for easy-KTCP project.

Author
leeopop
Date
Aug 2013
Version
Revision:
1.00

This is the main project template for transport layer implementation. All functions below are linked with KENS kernel, so do not change the name or type of function.

Function Documentation

int app_dispatch_tcp ( my_context  handle,
const void *  data,
size_t  data_size 
)
Todo:

Every time application calls 'write', this function is called.

Parameters
handleTCP context linked with application socket
dest_addrdestination IP address (in network ordering)
datawritten data via 'write'
data_sizesize of data
Returns
actual written bytes (-1 means closed socket)
void ip_dispatch_tcp ( struct in_addr  src_addr,
struct in_addr  dest_addr,
const void *  data,
size_t  data_size 
)
Todo:

When ip packet is received, this callback function is called. Most IP headers are removed, and only data part is passed. However, source IP address and destination IP address are passed for header computation.

Parameters
src_addrsource IP address (in network ordering)
dest_addrdestination IP address (in network ordering)
dataIP payload
data_sizesize of data
bool my_accept ( my_context  handle,
int *  err 
)
Todo:

Mapped with 'kaccept'. 'kaccept' is immediately blocked (my_accept is not blocked). Even if 'kaccept' is called after connection is established, it is blocked. 'kaccept' can be waken up via tcp_passive_open.

Parameters
handleTCP context created via 'my_open' (listening socket)
errERRNO value
Returns
whether this operation is successful
bool my_bind ( my_context  handle,
const struct sockaddr *  my_addr,
socklen_t  addrlen,
int *  err 
)
Todo:

Mapped with 'kbind'.

Parameters
handleTCP context created via 'my_open'
my_addraddress of this socket
addrlenlength of my_addr structure
errERRNO value
Returns
whether this operation is successful
void my_close ( my_context  handle,
int *  err 
)
Todo:

Mapped with 'kclose'.

Parameters
handleTCP context created via 'my_open'
errERRNO value
bool my_connect ( my_context  handle,
const struct sockaddr *  serv_addr,
socklen_t  addrlen,
int *  err 
)
Todo:

Mapped with 'kconnect'.

Parameters
handleTCP context created via 'my_open'
serv_addrremote address connecting to
addrlenlength of serv_addr structure
errERRNO value
Returns
whether this operation is successful
bool my_getpeername ( my_context  handle,
struct sockaddr *  name,
socklen_t *  namelen,
int *  err 
)
Todo:

Mapped with 'kgetpeername'.

Parameters
handleTCP context created via 'my_open'
nameaddress of socket address structure Write peer address here.
namelenlength of address structure Write length of my address structure size here. This value should be initialized with the actual size of 'name' structure.
errERRNO value
Returns
whether this operation is successful
bool my_getsockname ( my_context  handle,
struct sockaddr *  name,
socklen_t *  namelen,
int *  err 
)
Todo:

Mapped with 'kgetsockname'.

Parameters
handleTCP context created via 'my_open'
nameaddress of socket address structure Write my address here.
namelenlength of address structure Write length of my address structure size here. This value should be initialized with the actual size of 'name' structure.
errERRNO value
Returns
whether this operation is successful
bool my_listen ( my_context  handle,
int  backlog,
int *  err 
)
Todo:

Mapped with 'klisten'.

Parameters
handleTCP context created via 'my_open'
backlogmaximum number of concurrently opening connections
errERRNO value
Returns
whether this operation is successful
my_context my_open ( int *  err)
Todo:

Mapped with 'ksocket'.

Parameters
errERRNO value
Returns
TCP context data to be used (used to identify each application sockets)
void my_shutdown ( void  )
Todo:

This function is called when KENS TCP layer is exiting.

bool my_startup ( void  )
Todo:

This function is called when KENS TCP layer is starting.

Returns
whether this operation is successful
void my_timer ( my_context  handle,
int  actual_called 
)
Todo:

This function is called when timer activated. Each timer is bound to each context.

Parameters
handleTCP context bound to this timer
actual_calledactual time this timer called (in mtime)

Variable Documentation

const char* CSTATE_strs[]
Initial value:
= {
"CSTATE_CLOSED",
"CSTATE_LISTEN",
"CSTATE_SYN_SENT",
"CSTATE_SYN_RECV",
"CSTATE_ESTABLISHED",
"CSTATE_FIN_WAIT1",
"CSTATE_FIN_WAIT2",
"CSTATE_CLOSING",
"CSTATE_TIME_WAIT",
"CSTATE_CLOSE_WAIT",
"CSTATE_LAST_ACK"
}