Presentation is loading. Please wait.

Presentation is loading. Please wait.

Network LayerDatalink LayerPhysical LayerNetwork LayerDatalink LayerPhysical Layer ClientServer Framework.

Similar presentations


Presentation on theme: "Network LayerDatalink LayerPhysical LayerNetwork LayerDatalink LayerPhysical Layer ClientServer Framework."— Presentation transcript:

1 Network LayerDatalink LayerPhysical LayerNetwork LayerDatalink LayerPhysical Layer ClientServer Framework

2 PHL TCP Connection ClientServer 2. phl_send(…) 3. phl_recv(…) 1. phl_connect(…) 4. phl_close(…) Physical Layer NOTE: Real TCP does the actual transmission for your PHL.

3 ClientServer NWL 3. dll_send(… pkt …)4. dll_recv(… pkt …) 2. read packets from file “testdata.raw” 5. write packets to file “server.out” 1. phl_connect(…) 6. phl_close(…) Network Layer

4 Testdata File Pkt_numthe number of packets Packet_i_lenthe byte number of the i-th packet. Packet_ithe i-th packet in raw byte form …… 2 38 CS4514, computer network course, FL320 31 Worcester Polytechnic Institute

5 The testdata.raw file 0x02 0x47 0x4F 0x03 0x72 0x61 0x77 2 (packets) 2 (bytes) ‘G’ ‘O’ 3 (bytes) ‘r’ ‘a’ ‘w’

6 Client dll_send(… pkt … ) 1. Split a packet into payloads 2. Create a new frame 4. Send the frame to PHL 5. Wait for receiving a ACK frame 6. Retransmit it if timeout !! 3. Start a Timer 7. Receive a ACK frame phl_send(…) phl_recv(…) Force some error Every 6-th Frame client.log Correct Ack Frm? Yes No

7 Create a new frame struct frame { unsigned char start-flag; unsigned char seq; unsigned char crc; unsigned char data[]; unsigned char end-of-pkt; unsigned char end-flag; } Start-flag seq crcdatafield end-of-pkt end-flag NOTE: Byte-stuffing includes those bytes of seq, crc, data, end-of-pkt. 1. Put a payload in a frame 2. End-of-packet byte = ? 3. Compute CRC 4. Byte-stuffing Process

8 Create a new ACK frame struct ackframe { unsigned char start-flag; unsigned char seq; unsigned char crc; unsigned char end-flag; } start-flag seqcrcend-flag 1. Compute CRC 2. Byte-stuffing Process

9 Server dll_recv(…pkt…) 1. Receive a frame from PHL 3. Compute CRC and check it 4. Drop it if there’s an CRC error 6. Reassemble the packet 7. If end-of-packet, return and forward the packet to the Network Layer. phl_send(…) phl_recv(…) 2. Unstuffing the frame server.log 5. Check whether it’s duplicate. If yes, drop it. Send ACK frame Force some error Every 7-th ACK Frame

10 System call: select In this assignment, you can call select and tell the kernel to return only when: - the socket descriptor in physical layer is ready for reading, or - a preset timer timeout

11 System call: select # include int select ( int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, const struct timeval *timeout);

12 Struct timeval struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */ }

13 Example: how to use select { fd_set bvfdRead; FD_SET(sockfd, &bvfdRead); int readyNo; readyNo = select(sockfd+1, struct timeval timeout; &bvfdRead, 0, 0, &timeout); int sockfd; if(readyNo < 0) //some errors error_handler; while (true) { else if(readyNo = = 0) // timeout timeout.tv_sec = 0; timeout_handler; timeout.tv_usec = 500; else // receive data from socket FD_ZERO(&bvfdRead); receive_handler; } }


Download ppt "Network LayerDatalink LayerPhysical LayerNetwork LayerDatalink LayerPhysical Layer ClientServer Framework."

Similar presentations


Ads by Google