Application-Level Implementation of TCP Team Alaska San Jose State University Fall 2007 CMPE207 Dr. Frank Lin Chris Nelson Ruchir Sutaria Kimsi Singh Gagandeep Singh
Team Alaska – Fall 2007Slide 2 Team Members Gagandeep Singh - Server Application - Concurrency Expert Kimsi Singh - Client Applications - Test Expert Chris Nelson - Team Leader - Documentation - Connection Establishment/ Termination Ruchir Sutaria - Seq/Ack Numbering - Flow Control Guru Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 3 Agenda Project Management Code Control Documentation Design Overview Protocol Code Concurrent Server Client Test Applications Test Overview Test Cases Test Results Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 4 Project Management SourceForge.net: CVS repository for code control Wiki pages for documentation and tasks Google Groups: Archive of team discussions Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 5 Project Management Our main project wiki page... Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 6 Project Management Tracking our tasks and progress... Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 7 Project Management Tracking our discussions... Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 8 Project Management Tracking our code... Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 9 Design Overview General Concept: Create an Additional Layer Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 10 Design Overview Create an API extern int cmpe207_socket (int type); extern int cmpe207_bind (int sockfd, cmpe207_sockaddr *myaddr, int addrlen); extern int cmpe207_listen (int sockfd, int queue_size); extern int cmpe207_accept (int sockfd, cmpe207_sockaddr *claddr, int addrlen); extern int cmpe207_send (int sockfd, const char* buf, int len, int flags); extern int cmpe207_recv (int sockfd, char* buf, int len, int flags); extern int cmpe207_close (int sockfd); extern int cmpe207_connect (int sockfd, cmpe207_sockaddr *myaddr, int addrlen); Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 11 Design Overview Control Structures socket_blocks: Array of socket control blocks /* Socket control block */ typedef struct { int socket_desc;//Socket descriptor short inuse;//In-use flag (TRUE or FALSE) cmpe207_sockaddr local_addr;//Local address, port, UDP port cmpe207_sockaddr remote_addr;//Remote address, port, UDP port int udp_sockfd;//UDP socket descriptor short state;//Connection state int listen_queue_size;//Listen queue size // Send sequence variables... uint32_t snd_una;//send unacknowledged uint32_t snd_nxt;//to keep track of sender seq no uint16_t send_window;//Send window uint16_t snd_wl1;//Seg seq num used for last window uint16_t snd_wl2;//Seg ack num used for last win update uint16_t ISS;// initial send seq number // Receive sequence variables... uint32_t rcv_nxt; //recv next uint16_t rec_window;//Receive window uint16_t IRS;//initisl recv seq number // Current segment variables... uint32_t seg_ack;//ACK Number uint32_t seq_nbr;//Sequence Number uint32_t seg_len;//segment length uint32_t seg_wnd;//segment window // Time variables... uint32_t last_data_snd;//time of last data send uint32_t last_ack_snd; uint32_t last_data_rcvd; uint32_t last_ack_rcvd; } cmpe207_control_block; Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 12 Design Overview Packet Header Structure /* CMPE207 Packet Header */ typedef struct { uint16_t src_port;/* 16-bit source port */ uint16_t dest_port;/* 16-bit destination port */ uint32_t seq_nbr;/* 32-bit sequence number */ uint32_t ack_nbr;/* 32-bit ack number */ uint16_t f_flag : 1,/* Fin flag */ s_flag : 1,/* Sync flag */ r_flag : 1,/* Reset flag */ p_flag : 1,/* Push flag--off except for close */ a_flag : 1,/* Ack flag */ u_flag : 1,/* Urgent flag--always off */ offset : 10;/* Offset--always 0x05 */ uint16_t window;/* 16-bit window field */ uint16_t chksum;/* 16-bit checksum field */ uint16_t urgptr;/* 16-bit urgent pointer--unused */ } cmpe207_pkt_hdr; Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 13 Design Overview Internal Functions int cmpe207_pack (char *udp_data, cmpe207_pkt_hdr *header, char *data_207, int data_207_length); int cmpe207_unpack (char *udp_data, unsigned int udp_data_size, cmpe207_pkt_hdr *header, char *data_207, unsigned int data_207_size); headerdata_207 udp_data headerdata_207 udp_data Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 14 Design Overview Screenshot of cmpe207_unpack()... Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 15 Design Overview Screenshot of cmpe207_scb_print()... Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007Slide 16 Design Overview Flow Control Basic sequencing in cmpe207_connect, cmpe207_accept, cmpe207_send, cmpe207_receive and cmpe207_close Cumulative Ack with no sequence increment for Ack packet Timeouts and retransmission Window Management Slide Prepared/Presented by: R. Sutaria
Team Alaska – Fall 2007Slide 17 Design Overview Basic Sequencing Whenever data sent Seq nbr of segment Length of data sent Segment window length Send unack,Send next, Last data send and send window are set based on values in the TCB Whenever data received Checks for flags Check valid range Store the incoming window length Recv nxt, seq nbr, last data recvd and last ack recvd set based on the received header values Slide Prepared/Presented by: R. Sutaria
Team Alaska – Fall 2007Slide 18 Design Overview Timeouts, Retransmission, and Window Management The timeout done using select() function. Retransmission based on state and the window size Window size is dynamic Have the capability to transmit large chunks of data. Done by splitting the packet according to window size Slide Prepared/Presented by: R. Sutaria
Team Alaska – Fall 2007Slide 19 Design Overview The cmpe207_send function will split the data and send it to the receiver. This provides us a mechanism to send large chunks of data. Slide Prepared/Presented by: R. Sutaria 2000 Bytes Data 500 Bytes Advertised window size = 500 Data Packet Size = 2000
Team Alaska – Fall 2007Slide 20 Design Overview THE SERVER Key Elements Implements the 207 – Protocol API (discussed earlier) In addition, has its own API (For logging any data) - Server_Accept() - Server_Read() - Server_Write() - Server_Close() Concurrent (Can handle upto 10 clients at a given time) Multi-Threaded Slide Prepared/Presented by: G. Singh
Team Alaska – Fall 2007Slide 21 Design Overview THE SERVER (Multi - Threading) master slave 1 slave 2 slave 3 Socket Slide Prepared/Presented by: G. Singh
Team Alaska – Fall 2007Slide 22 Design Overview THE SERVER (Multi - Threading) Socket master slave 1 Request Data Slide Prepared/Presented by: G. Singh
Team Alaska – Fall 2007Slide 23 Design Overview THE SERVER (Our Approach) CRUX: Issue: Race Condition - recvfrom() function, as only ONE socket, but multiple threads Solution: The main thread always yields to the slave thread, except in SYN_RECEIVED state Issue: Shared Memory Solution: Every Thread given its own routine to execute Slide Prepared/Presented by: G. Singh
Team Alaska – Fall 2007Slide 24 Design Overview THE SERVER Features Targeted: Robustness Performance Reliability Slide Prepared/Presented by: G. Singh
Team Alaska – Fall 2007Slide 25 Test Cases INTERACTIVE TEST APPLICATION Includes 25 Test Cases; 25 Cases have been implemented Plan to include 25 more, before submission Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007Slide 26 Test Cases Test Cases: Five chosen test cases All Flags UP (ALL_FLAGS_UP) No Acknowledgment after the received data (NO_ACK_OF_RECEIVED_DATA) Reset after the data sent (RST_AFTER_DATA_SENT) Malformed Header (MALFORMED_HEADER) SYN_ATTACK Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007Slide 27 Test Cases (ALL_FLAGS_UP) SERVER in Listen State Clearly a false packet Listen State All flags set, including SYN PKT Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007Slide 28 Test Cases EXPECTED RESULT Packet should be ignored! Also, THREE WAY HANDSHAKE should not proceed… ACTUAL RESULT Server Proceeded with the Handshake. Failed the Test. Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007Slide 29 Test Cases (NO_ACK_OF_RECEIVED_DATA) The Server waits for an ACK but does not get an ACK! Server ACK Client receives converted data Client Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007Slide 30 The Expected Behavior is: 1) Slave Socket times out and closes. 2) Server remains in the listening mode Actual result: Server passed this test. Test Cases Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007Slide 31 Test Cases (RST_AFTER_DATA_SENT) Sends Data RST Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007Slide 32 Test Cases EXPECTED RESULT Slave socket expected to receive this RST and respond with an RST and Finally close. Server is expected to continue in the listening mode. ACTUAL RESULT Server Failed the Test Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007Slide 33 Test Cases MALFORMED_HEADER Header of 18 bytes instead of 20 bytes ( Corrupted header). ALL Flags : OK EXPECTED BEHAVIOUR Slave Socket is expected to ignore the packet. Actual Behavior = Expected Behavior Server passes the test. Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007Slide 34 Test Cases SYN_ATTACK Client Keeps Sending SYN even after getting a SYN_ACK from the Server SYN Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007Slide 35 Different implementations come up with different solutions to this problem. Bottomline: Server should not be fooled. Our Approach: If Server receives 5 SYN packets from the same IP address and port in SYN_RECEIVED, it sends an RST and goes back to the LISTEN state. Test Cases Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007Slide 36 Test Results Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007Slide 37 References Slide Prepared/Presented by: C. Nelson