






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







The objective of this assignment is to familiarize you with UNIX socket programming. This assignment is worth 10% of your overall grade in this course. It is an individual assignment and no collaborations are allowed. Any cheating will result in an automatic F in the course (not just in the assignment). If you have any doubts/questions please feel free to contact the TAs and cc professor Zahid as usual.
In this project you will be simulating transfer of fragmented messages over TCP and UDP sockets in a network with client-server architecture. The project has 3 major phases: Fragmentation/distribution, Routing and Verification. In Phase 1, all communications are through TCP sockets. In phases 2 and 3 however, all communications are over UDP sockets.
You must write your programs either in C or C++ on UNIX. In fact, you will be writing (at least) 3 different pieces of code:
1- Messenger a. You must use one of these names for this piece of code: messenger.c or messenger.cc or messenger.cpp (all small letters). Also you must call the corresponding header file (if any) messenger.h (all small letters). You must follow this naming convention. 2- Router a. You must create 3 concurrent Routers i. Either by using fork() or a similar Unix system call. In this case, you probably have only one piece of code for which you need to use one of these names: router.c or router.cc or router.cpp (all small letters). Also you must call the corresponding header file (if any) router.h (all small letters). You must follow this naming convention. ii. Or by running 3 instances of the Router code. However in this case, you probably have 3 pieces of code for which you need to use one of these sets of names: ( router1.c, router2.c, router3.c ) or ( router1.cc, router2.cc, router3.cc) or ( router1.cpp, router2.cpp and router3.cpp) (all small letters). Also you must call the corresponding header file (if any) router.h (all small letters) or router1.h, router2.h and router3.h (all small letters). You must follow this naming convention. 3- Receiver a. You must create 2 concurrent Receivers i. Either by using fork() or a similar Unix system call. In this case, you probably have only one piece of code for which you need to use one of these names: receiver.c or receiver.cc or receiver.cpp (all small letters). Also you must call the corresponding header file (if any) receiver.h (all small letters). You must follow this naming convention. ii. Or by running 2 instances of the Router code. However in this case, you probably have 2 pieces of code for which you need to use one of these sets of names: ( receiver1.c, receiver2.c ) or ( receiver1.cc, receiver2.cc) or ( receiver1.cpp, receiver2.cpp ) (all small letters). Also you must call the corresponding header file (if any) receiver.h (all small
letters) or receiver1.h, receiver2.h (all small letters). You must follow this naming convention.
4- Input file : message.txt a. There is one input file for this project, message.txt. This input file contains two English sentences. Here is the format of a sample input file:
5 This is the EE450 class 7 We are in the Fall 2007 semester
In this sample input file each line starts with a number between 2 and 8 which corresponds to the number of words in the sentence on that line. In this example, the number of words in the first sentence is 5 and the number of words in the second sentence is 7. As can be seen the delimiter used between the words is one space. You are given a sample input file message.txt to test your code, however when your project is graded, the TA may use a different input file with the exact same format to test your project. Please note that there are always two lines (hence only two sentences) in this file.
This project is divided into 3 phases. It is not possible to proceed to one phase without completing the previous phase and in each phase you will have multiple concurrent processes that will communicate either over TCP or UDP sockets.
Phase1:
In this phase, Messenger opens the input file and reads the contents of the file (i.e. the two English sentences) and generates some packets using a specific header format (shown in Figure1). Each packet carries (or encapsulates) exactly one English word as its payload or data. For example with the current input file, Messenger will create a total of 12 packets (5 packets for the words in sentence #1 and 7 packets for the words in sentence#2). The packets that carry words of sentence#1 are destined for Receiver#1 and packets that carry words of sentence#2 are destined for Receiver #2.
Next, Messenger must contact the 3 Routers in a round-robin fashion to distribute these packets among them over TCP sockets. Therefore Messenger must know the TCP port number of each Router in advance. In other words you must hardcode the TCP port number of each Router, in the Messenger code. Table 1 shows how static TCP and UDP port numbers should be defined for each entity in this project.
Messenger will use 3 different dynamically-assigned TCP port numbers (NOT statically defined) and establishes 3 TCP connections to 3 Routers. You are free to implement these 3 TCP connections either in parallel or serially. In other words, Messenger can use its first TCP port number and establish a TCP connection to Router1, send all the necessary packets to Router1and close this connection. It can then repeat this process for Router#2 and Router #3 serially. It’s also possible for Messenger to open 3 concurrent or parallel TCP connections to 3 Routers over 3 different TCP port numbers. This is entirely your choice to implement this part in parallel or serially.
Whether the TCP connections are established serially or in parallel, the packets that are required to be transferred to each Router are pre-determined based on the contents of the input file. For example with the given sample input file, packet #1,#4,#7 and #10 will be sent to Router1, packet #2, #5, #8 and #11 will be sent to Router #2 and packets #3, #6, #9 and #12 will be sent to Router #3. Please note that in this case each Router
Messenger
Router
Router
Router
UDP
CISCO SYSTEMS
3 Com
Receiver1 Receiver
UDP (^) UDP UDP UDP UDP
Static UDP Port =3100+xxx
Dynamic UDP Port
Static UDP Port =3200+xxx
Dynamic UDP Port
Dynamic UDP Port
Figure3: Phase 2, Routing
receives the same number of packets because there are a total of 12 English words in the input file and 12 is evenly divisible by 3 (the number of Routers).However in the test-case used for grading, the total number of words may not be a multiple of 3, hence some Routers may receive less packets than others. Your code should work for the general case. Figure2 illustrates phase1 of this project.
Phase2:
In phase2 of this project, each Router must inspect the header of each data packet (received from Messenger), correctly identify the destination of each packet and forward them through the correct outgoing interface toward the destination. In this case the outgoing interface corresponds to a UDP socket. Since there are two Receivers in this project, each Router has two outgoing interfaces, in other words you must hardcode the static UDP port for each Receiver inside the Router code. Each Router will then change the identifier string in the packet, from Messenger to its name (i.e. Router1, or Router2 or Router3).It must then create a UDP socket to communicate with a Receiver and send the packets that are destined for that Receiver over that UDP socket. The Routers can contact the Receivers in any arbitrary order. Upon successful completion of this phase, Receiver1 should have received all the words in sentence#1 and Receiver2 should have received all the words in sentence#2. Figure illustrates the communications over UDP sockets in phase2.
Messenger
Router
Router
Router
UDP
CISCO S YSTEMS
3 Com
Receiver1 Receiver
UDP
Dynamic UDP Port
Static UDP Port =4100+xxx
Dynamic UDP Port
Figure4: Phase 3, Verification
Phase3:
In this phase, each Receiver must assemble the words that it received in phase2, in the correct order and form the original sentence. Each Receiver then generates one packet (according to the provided format in Figure #1) that carries the complete sentence as its payload. It then creates a new UDP socket to communicate with Messenger and sends that packet to Messenger. It is therefore implied that Messenger has a UDP port number that is statically defined and is already hardcoded in both Receiver codes. Messenger will then extract the payload of each packet received from each Receiver, compares it to the corresponding sentence in the input file, e.g. if the packet is received from receiver1 it will be compared to sentence#1 and verifies whether it is a match. It will then announce the results on the screen. This marks the end of Phase3, i.e. the verification.
Table 1: A Summary of Static and Dynamic assignment of TCP and UDP Ports and IP addresses Process Dynamic ports Static Ports IP address obtained from Messenger 3 TCP Ports (Phase1) 1 UDP Port, 4100+ xxx of your ID (Phase3) local host or nunki.usc.edu Router1 1 UDP Port (Phase2) 1 TCP Port, 21100+ xxx of your ID (Phase1) local host or nunki.usc.edu Router2 1 UDP Port (Phase2) 1 TCP Port, 21200+ xxx of your ID (Phase1) local host or nunki.usc.edu Router3 1 UDP Port (Phase2) 1 TCP Port, 21300+ xxx of your ID (Phase1) local host or nunki.usc.edu Receiver1 1 UDP Port (Phase3) 1 UDP Port, 3100+ xxx of your ID (Phase2) local host or nunki.usc.edu Receiver2 1 UDP Port (Phase3) 1 UDP Port, 3200+ xxx of your ID (Phase2) local host or nunki.usc.edu
Assumptions:
Requirements:
//Retrieve the locally-bound name of the specified socket and store it in the sockaddr structure getsock_check=getsockname(TCP_Connect_Sock,(struct sockaddr *)&my_addr, (socklen_t *)&addrlen) ; //Error checking if (getsock_check== -1) { perror("getsockname"); exit(1); }
Programming platform and environment:
a. Open software.usc.edu in you web browser. b. Log in using your username and password (the one you use to check your USC email). c. Select your operating system (e.g. click on windows XP) and download the latest xwin. d. Install it on your computer. e. Then check the following webpage: http://www.usc.edu/its/connect/index.html for more information as to how to connect to USC machines.
Programming languages and compilers:
You must use only C/C++ on UNIX as well as UNIX Socket programming commands and functions. Here are the pointers for Beej's Guide to C Programming and Network Programming (socket programming):
http://www.beej.us/guide/bgnet/
(If you are new to socket programming please do study this tutorial carefully as soon as possible and before starting the project)
http://www.beej.us/guide/bgc/
Once you run xwin and open an ssh connection to nunki.usc.edu, you can use a unix text editor like emacs to type your code and then use compilers such as g++ (for C++) and gcc (for C) that are already installed on nunki
a. On nunki.usc.edu, go to the directory which has all your project files. Remove all executable and other unnecessary files. Only include the required source code files and the README file. Now run the following commands:
b. you@nunki>> tar cvf ee450_yourUSCusername_session#.tar * - Now, you will find a file named “ee450_yourUSCusername_session#.tar” in the same directory.
c. you@nunki>> gzip ee450_yourUSCusername_session#.tar – Now, you will find a file named “ee450_yourUSCusername_session#.tar.gz” in the same directory.
d. Transfer this file from your directory on nunki.usc.edu to your local machine. You need to use an FTP program such as CoreFtp to do so. (The FTP programs are available at software.usc.edu and you can download and install them on your windows machine.)
Grading Criteria:
Your project grade will depend on the following: