Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Internet technology. Please please HELP ASAP. Its due in 24 hours. THANKS Thanks Server1.py Client1.py Sock352.py CS 352 Spring 2017 Programming Project Part 1 1.

Internet technology. Please please HELP ASAP. Its due in 24 hours. THANKS
Thanks
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Server1.py
image text in transcribed
image text in transcribed
image text in transcribed
Client1.py
image text in transcribed
image text in transcribed
image text in transcribed
Sock352.py
image text in transcribed
CS 352 Spring 2017 Programming Project Part 1 1. Overview: For part 1 of the project, your team will implement a simple go-back-N protocol similar to TCP. This protocol is called the 352 Reliable Data Protocol (RDP) version 1 (352 RDP v1) You will realize it as a Python (version 2) module that uses UDP as the underlying transport protocol. Later versions will add security, port spaces, and concurrency As part of the project part 1, you will be given 3 files. You can find them in the Sakai site under "Resources" -> "Project resources"-Part 1" 1. sock352.py This is a skeleton definition of the class and methods you need to write. You should modify this file with your implementation. That is, fill in the methods with your own code 2. client1.py : A Python client program that uses CS 352 sockers. You may not alter the source code for this file. 3. serverl.py: APython server program that uses CS 352 sockets. You may not alter the source code for this file. Your library must implement the following methods as defined in the sock352 py file: init (udp portl, udp port2) socket) bind (address) connect (address) Listen(backlog) accept) close() send (buffer) recv (nunBytes) These function map to the existing Python methods for sockets. See this link: for the definitions of these functions. The one exception init) call. This call takes a single parameter, which is the UDP port that the rest of the CS 352 RDP library will use for communication between hosts. Setting the udp_port to zero should use the default port of 27182 For part 1 of the project, you will only need to make a single connection work over a single port for a single thread. The goal is to correctly implement a go-back-N protocol for one connection, for example, when sending a single file between a client and server. Later versions of the project will build on part to add port-spaces and handle multiple simultaneous connections. Packet structure: The CS 352 RDP v1 packet as defined as a C structure, which must be translated into a Python struct: /*a CS 352 RDP protocol packet header/ tructattributepacked) sock352 pkt hdr uint8 t version uint8 tflags; uint8 t opt ptr uint8 t protocol; uint16 t header len; length of the header/ uint16 t checksum uint32 t source port: source port uint 32 t dest uint64 t sequence no; sequence number uint64 t ack no; uint32 t window uint32 t payload len; length of the payload version number /* for connection set up, tear-down, control option type between the header and payload / higher-level protocol / checksum of the packet / rt; destination port / number /* receiver advertised window in bytes 1: typedef struct sock352 pkt hdr sock352_pkt hdr t; typedef shortcut* Fields in Red (version, flags,header Len, sequence no,ack no, payload len) must be filled in correctly in part 1, while the Blue fields can be ignored for this part of the project. Note that uintXt is an X-bit unsigned integer, as defined in . At the packet level, all these fields are defined to be in network byte-order (big-endian, most significant byte first). In Python, you will need to use the struct module to pack and unpack binary data (see this link for a description of the struct library: https-/ldocs python.org2Mibrary/stuct.html) A struct object takes a formating string and allows you to create a binary object based on the format and Python variables. This is called a pack operation. The inverse, or unpack, takes a binary object and unpacks it into a set of Python variables. Recall for the format string, B Byte, H Half-Word (16 bits), L-Long (32 bits) Q-Quad (64bits), and the "" means use network byte order. Some example code to pack a CS 352 packet header might look like this: sock 352PkthdrDataBBBBHHLLOOLL udpPkt hdr_data -struct.Struct (sock352PktHdrDatal header = udpPkt-header-data-pack (version, flags, opt.,ptr, protocol, checksum source port, dest port, sequence no, ack no, window, payload len) For part 1, in the packet, the version field should be set of 0x1. The protocol, opt ptr, source port and dest port fields should all be set to zero. Future versions of the protocol wil add port spaces and options. The header len field will always be set to the size of the header, in bytes. An address for the CS 352 RDP is slightly different from the normal socket address, as found in the sock352.h file. The main difference is the addition of a port layer on top of the UDP port space, as seen in the cs352 port field. This will be used in later versions of the protocol. Connection Set-up: 352 RDP follows the same connection management protocol as TCP. See Chapter 3.5.6, pages 252-258 of Kurose and Ross for a more detailed description. The version field of the header should always be set to 1 Flags: The bit flags needed are set in the flags field of the packet header. The exact bit definitions of the flags are: Flag Name SOCK352 SYN SOCK352 FIN SOCK352 ACK SOCK352 RESET SOCK352 HAS OPT Byte Value (Hex) 0x01 Byte Value (Binary) 00000001 00000010 00000100 00001000 00010000 Meaning Connection initiation Connection end 0x02 Reset the connection Option field is valid OxA0 The client initiates a connection by sending a packet with the SYN bit set in the flags field, picking a random sequence number, and setting the sequence no field to this number. If no connection is currently open, the server responds with both the SYN and ACK bits set, picks a random number for it's sequence no field and sets the ack no field to the client's incoming sequence no+1. If there is an existing connection, the server responds with the sequence no+1, but the RESET flag set. Data exchange: 352 RDP follows a simplified Go-Back-N protocol for data exchange, as described in section Kurose and Ross., Chapter 3.4.3, pages 218-223 and extended to TCP style byte streams as described in Chapter 3.5.2, pages 233-238. When the client sends data, if it is larger than the maximum UDP packet size (64K bytes), it is first broken up into segments, that is, parts of the application byte-stream, of up to 64K. If the client makes a call smaller than 64K, then the data is sent in a single UDP packet of that size, with the payload1en field set appropriately. Segments are acknowledged as the last segment received in- order (that is, go-back-N). Data is delivered to the higher level application in-order based on the recv) calls made. If insufficient data exists for a recv ) call, partial data can be returned and the number of bytes set in the call's return value For CS 352 RDP version 1, the window size can be ignored. Timeouts and retransmissions: 352 RDP v1 uses a single timer model of timeouts and re-transmission, similar to TCP in that there should be a single timer per connection, although each segment has a logical timeout. The timeout for a segment is 0.2 seconds. That is, if a packet has not been acknowledged after 0.2 seconds it should be re-transmitted, and the logical timeout would be set again set to 0.2 seconds in the future for that segment. The timeout used for a connection should be the timeout of the oldest segment There are two strategies for implementing timeouts. One approaches uses Unix signals and other uses a separate thread. These will be covered in class and recitation. Connection termination will follow a similar algorithm as TCP, although simplified. In this model, each side closes it's send side separately, see pages 255-256 of Kurose and Ross and pages 39-40 of Stevens, In version 1, it is OK for the client to end the connection with a FIN bit set when it both gets the last ACK and close has been called. That is, close cannot terminate until the last ACK is received from the server. The sever can terminate the connection under the same conditions. 3. Invoking the client and server: The client and server take a number of arguments -f -d -u the UDP port to use for receiving? -V FRAGMENTSIZE) fragment -s2.recv(FRAGMENTSIZE) else: Eragment -s2.recv(bytes to receive) ndhash.update(fragnent) bytes to receive bytes to receive -len(fragnent) Ed.write(fragment) end stamp time.clock) lapsed seconds-end stamp start stamp # finish computing the MD5 hash local digestndhash.digest # receive the size of the remote hash dllongPacker.unpack(s2.recv(4)) digestlen di0 renote digests2.rec (digestlen) # check is the size matches if (len(remote digest)-digestlen): raise RuntineError( "socket error) 2/2619, 12-53 PM Page 2 of 3 , compare the two digests, byte for byte for i, server byte in enumerate(local digest): client byte remote digestli if (client byte server byte): print( digest failed at byte d tc c .client byte, server byte)) if (lapsed seconds>0.0) print serverl: received td bytes in t0.6f seconds, 0.6 MB/s (filelen, lapsed seconds, ilelen/lapsed seconds)/(04 1024)1 else: print "serverl: received id bytes in id seconds, inf MB/s (ilelen, lapsed seconds)) fd.close s2.close # create a main function in Python if nane main main() Mtpscontent.sakalrutgers.edulacc 33012e0/server.py 2/26/19 12 53 PM Page 3 of #1 /usr/bin/python # This is the CS 352 Spring 2017 Client for the 1st programing # project import argparse import time import struct import md5 import 08 import sock 352 def main() # parse all the arguments to the client parser-argparse.ArgunentParser (description-CS 352 Socket Client parser.add argument ("-f.filename,help- File to Send, reguired-False) parser.add argument(-d',-destination',help- Destination IP Host required True) parser.add argument ("-P--port,help- 'remote sock 352 port, required-False) parser.add-argument(.-u.,.--udpportRx., help-.UDP port to use for receiving. , required-True) parser.add argument("-v-udpportTx',help- UDP port to use for sending. required-False) # get the arguments into local variables args vars (parser parse args() filenane args 'tilename' destination args[ 'destination' 1 udpportRx argsl 'udpportRx1 if (args udpportTx']) udpportTxargs[ 'udpportTx'1 else . . udpportTx # the port is not used in part 1 assignment, except as a placeholder if (argsl port'1 port- args port' else: port 1111 # open the file for reading if (filenane): try filesize os.path.getsize(filenane) fdopen(filename, "rb usefile-True except print ( "error opening file: %s" % (filename)) exit(-1 else: pass # This is where we set the transmit and receive # ports the client uses for the underlying UDP # sockets. If we are running the client and server on the sane machine, these ports 2618 1254 PM Page 1 of 3 # need to be different. If they are running on # different machines, we can re-use the same # ports if (udpportTx): sock352.init(udpportTx, udpportRx else: sock352.init(udpportRx,udpportRx # create a socket and connect to the remote server $ sock352.socket () s .connect (destination, port ) ) # send the size of the file as a 4 byte integer to the server, so it knows how much to read FRAGHENTSIZE-8192 LongPacker struct.StructIL" fileLenPackedlongPacker.pack(filesize)i s.send( fileLenPacked) use the MD5 hash algorithm to validate all the data is correct ndhashmd5.new) # loop for the size of the file, sending the fragments bytes to sendfilesize start stamp time.clock while (bytes to send 0) fragment d.read (FRAGMENTSIZE) ndhash.update(fragment totalsent0 # make sure we sent the whole fragment while (totalsent "Project resources"-Part 1" 1. sock352.py This is a skeleton definition of the class and methods you need to write. You should modify this file with your implementation. That is, fill in the methods with your own code 2. client1.py : A Python client program that uses CS 352 sockers. You may not alter the source code for this file. 3. serverl.py: APython server program that uses CS 352 sockets. You may not alter the source code for this file. Your library must implement the following methods as defined in the sock352 py file: init (udp portl, udp port2) socket) bind (address) connect (address) Listen(backlog) accept) close() send (buffer) recv (nunBytes) These function map to the existing Python methods for sockets. See this link: for the definitions of these functions. The one exception init) call. This call takes a single parameter, which is the UDP port that the rest of the CS 352 RDP library will use for communication between hosts. Setting the udp_port to zero should use the default port of 27182 For part 1 of the project, you will only need to make a single connection work over a single port for a single thread. The goal is to correctly implement a go-back-N protocol for one connection, for example, when sending a single file between a client and server. Later versions of the project will build on part to add port-spaces and handle multiple simultaneous connections. Packet structure: The CS 352 RDP v1 packet as defined as a C structure, which must be translated into a Python struct: /*a CS 352 RDP protocol packet header/ tructattributepacked) sock352 pkt hdr uint8 t version uint8 tflags; uint8 t opt ptr uint8 t protocol; uint16 t header len; length of the header/ uint16 t checksum uint32 t source port: source port uint 32 t dest uint64 t sequence no; sequence number uint64 t ack no; uint32 t window uint32 t payload len; length of the payload version number /* for connection set up, tear-down, control option type between the header and payload / higher-level protocol / checksum of the packet / rt; destination port / number /* receiver advertised window in bytes 1: typedef struct sock352 pkt hdr sock352_pkt hdr t; typedef shortcut* Fields in Red (version, flags,header Len, sequence no,ack no, payload len) must be filled in correctly in part 1, while the Blue fields can be ignored for this part of the project. Note that uintXt is an X-bit unsigned integer, as defined in . At the packet level, all these fields are defined to be in network byte-order (big-endian, most significant byte first). In Python, you will need to use the struct module to pack and unpack binary data (see this link for a description of the struct library: https-/ldocs python.org2Mibrary/stuct.html) A struct object takes a formating string and allows you to create a binary object based on the format and Python variables. This is called a pack operation. The inverse, or unpack, takes a binary object and unpacks it into a set of Python variables. Recall for the format string, B Byte, H Half-Word (16 bits), L-Long (32 bits) Q-Quad (64bits), and the "" means use network byte order. Some example code to pack a CS 352 packet header might look like this: sock 352PkthdrDataBBBBHHLLOOLL udpPkt hdr_data -struct.Struct (sock352PktHdrDatal header = udpPkt-header-data-pack (version, flags, opt.,ptr, protocol, checksum source port, dest port, sequence no, ack no, window, payload len) For part 1, in the packet, the version field should be set of 0x1. The protocol, opt ptr, source port and dest port fields should all be set to zero. Future versions of the protocol wil add port spaces and options. The header len field will always be set to the size of the header, in bytes. An address for the CS 352 RDP is slightly different from the normal socket address, as found in the sock352.h file. The main difference is the addition of a port layer on top of the UDP port space, as seen in the cs352 port field. This will be used in later versions of the protocol. Connection Set-up: 352 RDP follows the same connection management protocol as TCP. See Chapter 3.5.6, pages 252-258 of Kurose and Ross for a more detailed description. The version field of the header should always be set to 1 Flags: The bit flags needed are set in the flags field of the packet header. The exact bit definitions of the flags are: Flag Name SOCK352 SYN SOCK352 FIN SOCK352 ACK SOCK352 RESET SOCK352 HAS OPT Byte Value (Hex) 0x01 Byte Value (Binary) 00000001 00000010 00000100 00001000 00010000 Meaning Connection initiation Connection end 0x02 Reset the connection Option field is valid OxA0 The client initiates a connection by sending a packet with the SYN bit set in the flags field, picking a random sequence number, and setting the sequence no field to this number. If no connection is currently open, the server responds with both the SYN and ACK bits set, picks a random number for it's sequence no field and sets the ack no field to the client's incoming sequence no+1. If there is an existing connection, the server responds with the sequence no+1, but the RESET flag set. Data exchange: 352 RDP follows a simplified Go-Back-N protocol for data exchange, as described in section Kurose and Ross., Chapter 3.4.3, pages 218-223 and extended to TCP style byte streams as described in Chapter 3.5.2, pages 233-238. When the client sends data, if it is larger than the maximum UDP packet size (64K bytes), it is first broken up into segments, that is, parts of the application byte-stream, of up to 64K. If the client makes a call smaller than 64K, then the data is sent in a single UDP packet of that size, with the payload1en field set appropriately. Segments are acknowledged as the last segment received in- order (that is, go-back-N). Data is delivered to the higher level application in-order based on the recv) calls made. If insufficient data exists for a recv ) call, partial data can be returned and the number of bytes set in the call's return value For CS 352 RDP version 1, the window size can be ignored. Timeouts and retransmissions: 352 RDP v1 uses a single timer model of timeouts and re-transmission, similar to TCP in that there should be a single timer per connection, although each segment has a logical timeout. The timeout for a segment is 0.2 seconds. That is, if a packet has not been acknowledged after 0.2 seconds it should be re-transmitted, and the logical timeout would be set again set to 0.2 seconds in the future for that segment. The timeout used for a connection should be the timeout of the oldest segment There are two strategies for implementing timeouts. One approaches uses Unix signals and other uses a separate thread. These will be covered in class and recitation. Connection termination will follow a similar algorithm as TCP, although simplified. In this model, each side closes it's send side separately, see pages 255-256 of Kurose and Ross and pages 39-40 of Stevens, In version 1, it is OK for the client to end the connection with a FIN bit set when it both gets the last ACK and close has been called. That is, close cannot terminate until the last ACK is received from the server. The sever can terminate the connection under the same conditions. 3. Invoking the client and server: The client and server take a number of arguments -f -d -u the UDP port to use for receiving? -V FRAGMENTSIZE) fragment -s2.recv(FRAGMENTSIZE) else: Eragment -s2.recv(bytes to receive) ndhash.update(fragnent) bytes to receive bytes to receive -len(fragnent) Ed.write(fragment) end stamp time.clock) lapsed seconds-end stamp start stamp # finish computing the MD5 hash local digestndhash.digest # receive the size of the remote hash dllongPacker.unpack(s2.recv(4)) digestlen di0 renote digests2.rec (digestlen) # check is the size matches if (len(remote digest)-digestlen): raise RuntineError( "socket error) 2/2619, 12-53 PM Page 2 of 3 , compare the two digests, byte for byte for i, server byte in enumerate(local digest): client byte remote digestli if (client byte server byte): print( digest failed at byte d tc c .client byte, server byte)) if (lapsed seconds>0.0) print serverl: received td bytes in t0.6f seconds, 0.6 MB/s (filelen, lapsed seconds, ilelen/lapsed seconds)/(04 1024)1 else: print "serverl: received id bytes in id seconds, inf MB/s (ilelen, lapsed seconds)) fd.close s2.close # create a main function in Python if nane main main() Mtpscontent.sakalrutgers.edulacc 33012e0/server.py 2/26/19 12 53 PM Page 3 of #1 /usr/bin/python # This is the CS 352 Spring 2017 Client for the 1st programing # project import argparse import time import struct import md5 import 08 import sock 352 def main() # parse all the arguments to the client parser-argparse.ArgunentParser (description-CS 352 Socket Client parser.add argument ("-f.filename,help- File to Send, reguired-False) parser.add argument(-d',-destination',help- Destination IP Host required True) parser.add argument ("-P--port,help- 'remote sock 352 port, required-False) parser.add-argument(.-u.,.--udpportRx., help-.UDP port to use for receiving. , required-True) parser.add argument("-v-udpportTx',help- UDP port to use for sending. required-False) # get the arguments into local variables args vars (parser parse args() filenane args 'tilename' destination args[ 'destination' 1 udpportRx argsl 'udpportRx1 if (args udpportTx']) udpportTxargs[ 'udpportTx'1 else . . udpportTx # the port is not used in part 1 assignment, except as a placeholder if (argsl port'1 port- args port' else: port 1111 # open the file for reading if (filenane): try filesize os.path.getsize(filenane) fdopen(filename, "rb usefile-True except print ( "error opening file: %s" % (filename)) exit(-1 else: pass # This is where we set the transmit and receive # ports the client uses for the underlying UDP # sockets. If we are running the client and server on the sane machine, these ports 2618 1254 PM Page 1 of 3 # need to be different. If they are running on # different machines, we can re-use the same # ports if (udpportTx): sock352.init(udpportTx, udpportRx else: sock352.init(udpportRx,udpportRx # create a socket and connect to the remote server $ sock352.socket () s .connect (destination, port ) ) # send the size of the file as a 4 byte integer to the server, so it knows how much to read FRAGHENTSIZE-8192 LongPacker struct.StructIL" fileLenPackedlongPacker.pack(filesize)i s.send( fileLenPacked) use the MD5 hash algorithm to validate all the data is correct ndhashmd5.new) # loop for the size of the file, sending the fragments bytes to sendfilesize start stamp time.clock while (bytes to send 0) fragment d.read (FRAGMENTSIZE) ndhash.update(fragment totalsent0 # make sure we sent the whole fragment while (totalsent

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

How can sensitivity to pain be altered?

Answered: 1 week ago