application-level implementation of tcp team alaska san jose state university fall 2007 cmpe207 dr....
Post on 18-Jan-2016
215 Views
Preview:
TRANSCRIPT
Application-Level Implementation of TCP
Team AlaskaSan Jose State UniversityFall 2007
CMPE207Dr. Frank Lin
Chris NelsonRuchir Sutaria
Kimsi SinghGagandeep Singh
Team Alaska – Fall 2007 Slide 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 2007 Slide 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 2007 Slide 4
Project Management
SourceForge.net:
http://cmpe207-alaska.sourceforge.net
CVS repository for code control
Wiki pages for documentation and tasks
Google Groups:
http://groups.google.com/group/cmpe207-alaska-developers
Archive of team e-mail discussions
Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007 Slide 5
Project Management
Our main project wiki page...
Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007 Slide 6
Project Management
Tracking our tasks and progress...
Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007 Slide 7
Project Management
Tracking our discussions...
Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007 Slide 8
Project Management
Tracking our code...
Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007 Slide 9
Design Overview
General Concept: Create an Additional Layer
cmpe207server.cpp (Application) cmpe207client.cpp (Application)
CMPE207 Protocol (Application) CMPE207 Protocol (Application)
UDP Protocol (Transport Layer) UDP Protocol (Transport Layer)
IP Protocol (Network Layer) IP Protocol (Network Layer)
Data Link Layer Data Link Layer
Physical Layer
Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007 Slide 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 2007 Slide 11
Design Overview
Control Structures
socket_blocks: Array of socket control blocks1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ...
/* Socket control block */typedef struct {
int socket_desc; //Socket descriptorshort inuse; //In-use flag (TRUE or FALSE)cmpe207_sockaddr local_addr; //Local address, port, UDP portcmpe207_sockaddr remote_addr; //Remote address, port, UDP portint udp_sockfd; //UDP socket descriptorshort state; //Connection stateint listen_queue_size; //Listen queue size
// Send sequence variables...uint32_t snd_una; //send unacknowledgeduint32_t snd_nxt; //to keep track of sender seq nouint16_t send_window; //Send windowuint16_t snd_wl1; //Seg seq num used for last windowuint16_t snd_wl2; //Seg ack num used for last win updateuint16_t ISS; // initial send seq number
// Receive sequence variables...uint32_t rcv_nxt; //recv nextuint16_t rec_window; //Receive windowuint16_t IRS; //initisl recv seq number
// Current segment variables...uint32_t seg_ack; //ACK Numberuint32_t seq_nbr; //Sequence Numberuint32_t seg_len; //segment length uint32_t seg_wnd; //segment window
// Time variables...uint32_t last_data_snd; //time of last data senduint32_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 2007 Slide 12
Design Overview
Packet Header StructureByte 0 20 28 48... ... up to 999
IP HeaderUDP
Header 207 Header 207 Data
/* 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 2007 Slide 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);
header data_207
udp_data
header data_207
udp_data
Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007 Slide 14
Design Overview
Screenshot of cmpe207_unpack()...
Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007 Slide 15
Design Overview
Screenshot of cmpe207_scb_print()...
Slide Prepared/Presented by: C. Nelson
Team Alaska – Fall 2007 Slide 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 2007 Slide 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 2007 Slide 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 2007 Slide 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
500 Bytes
500 Bytes
500 Bytes
Advertised window size = 500Data Packet Size = 2000
Team Alaska – Fall 2007 Slide 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 2007 Slide 21
Design Overview
THE SERVER (Multi - Threading)
master
slave1 slave2 slave3
Socket
Slide Prepared/Presented by: G. Singh
Team Alaska – Fall 2007 Slide 22
Design Overview
THE SERVER (Multi - Threading)
Socket
master
slave1
Request
Data
Slide Prepared/Presented by: G. Singh
Team Alaska – Fall 2007 Slide 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 2007 Slide 24
Design Overview
THE SERVER Features Targeted:
RobustnessPerformanceReliability
Slide Prepared/Presented by: G. Singh
Team Alaska – Fall 2007 Slide 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 2007 Slide 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 2007 Slide 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 2007 Slide 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 2007 Slide 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 2007 Slide 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 CasesSlide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007 Slide 31
Test Cases(RST_AFTER_DATA_SENT)
Sends Data
RST
Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007 Slide 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 2007 Slide 33
Test CasesMALFORMED_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 2007 Slide 34
Test Cases SYN_ATTACK Client Keeps Sending SYN even after getting a
SYN_ACK from the Server
SYNSYN
SYNSYN
Slide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007 Slide 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 2007 Slide 36
Test ResultsSlide Prepared/Presented by: K. Singh
Team Alaska – Fall 2007 Slide 37
References
http://cmpe207-alaska.sourceforge.net
http://www.ietf.org/rfc/rfc793.txt
http://www.50states.com/maps/alaska.gif
http://www.wunderground.com/data/wximagenew/h/hinzmanb/88.jpg
http://maps.google.com
Slide Prepared/Presented by: C. Nelson
top related