EE450SocketProgrammingProject_Spring2017.1.1
Problem Statement:
In this project you will implement a simple model of computational offloading where a single
client offloads some computation to a server (edge server) which in turn distributes the load
over 2 backend servers. The server facing the client then collects the results from the backend
and communicates the same to the client in the required format. As a result, the system is
comprised of three different parts:
1. Client: submits jobs to Google Compute Engine for processing.
2. Edge Server: Communicates with the client, receives the job, dispatches the job to back
end servers, receives their responses, builds the final output and sends the result back
to client.
3. Backend Servers: They perform specific computations they are assigned to. In our case,
one server performs bitwise and and the other performs bitwise or operations.
The servers together constitute Google Compute Engine (edge and backend servers, in total 3
servers). The client and the edge server communicate over a TCP connection while the
communication between the edge server and the Back-Servers is connectionless and over
UDP. This setup is illustrated in Figure 1.
Figure 1. Problem Setup for Socket Programming Project
Input Files Used:
The files specified below will be used as inputs in your programs in order to dynamically
configure the state of the system.
The contents of the files must NOT be hardcoded in your source code, because during
grading, the input files will be different, but the formats of the files will remain the same.
If you are working in an environment other than UNIX, pay particular attention to line endings
or newlines. For this project, it is assumed that all files follow the UNIX line ending
convention. This is particularly important while handling the input file(s). See the articles here
and here for more information.
Input file is an ASCII file that contains three columns of strings all in lowercase. Each row
specifies three elements: an operation and two operands. The first column is the operation in
string format which is either and or or. The other columns specify two strings of zeros and
ones representing two binary numbers. This file includes at most 100 rows and each binary
number is at most 10 digits (0s or 1s). This file will always reside in the same directory as the
client. Each row shall be processed independently.
Source Files:
Your implementation should include the source code files described below, for each component
of the system.
1. Edge Server: You must name your code file: edge.c or edge.cc or edge.cpp (all small
letters). Also you must call the corresponding header file (if you have one; it is not
mandatory) edge.h (all small letters).
2. Back-Server AND and OR: You must use one of these names for this piece of code:
server_#.c or server_#.cc or server_#.cpp. Also you must call the corresponding header
file (if you have one; it is not mandatory) server_#.h. The # character must be replaced
by the server identifier (i.e. or or and), depending on the server it corresponds to (such
as server_or.cpp and server_and.cpp).
3. Client: The name of this piece of code must be client.c or client.cc or client.cpp (all
small letters) and the header file (if you have one; it is not mandatory) must be called
client.h (all small letters).
https://blog.codinghorror.com/the-great-newline-schism/
https://en.wikipedia.org/wiki/Newline
https://en.wikipedia.org/wiki/ASCII
Makefile:
Makefile should support following functions. TAs will first compile all codes using make
all. They will then open 4 different terminal windows. On 3 terminals they will start
servers AND, OR, and Edge using commands make server_and, make server_or, and
make edge. On the fourth terminal they will start the client such as ./client job.txt. The
terminals should display the messages shown in table 4, 5, 6, 7.
make all Compiles all your files and creates
executables
make server_or Runs server_or server
make server_and Runs server_and server
make edge Runs edge server
./client
Phase1: (25 points)
All three server programs (Edge, Backend-Server or and Backend-Server and) boot
up in this phase. While booting up, the servers must display a boot message on the
terminal. The format of the boot message for each server is given in the onscreen
messages tables 4, 5, 6, 7. As the boot message indicates (look at the table of
messages down below), each server must listen on the appropriate port for incoming
packets/connections.
Once the server programs have booted up, the client program is run. The client displays
a boot message as indicated in the onscreen messages table. Note that the client code
takes an input argument from the command line, that specifies the computation that is
to be run. The format for running the client code is
./client
where
operands as explained above. For instance, to open a job.txt file right besides the client
binary use:
./client job.txt
After booting up, the client establishes a TCP connection with the edge server. After
successfully establishing the connection, the client reads all lines from the input file and
proceeds to send them to edge server over our TCP connection. After successfully
sending the lines, the client should print the number of lines sent to edge server. This
ends Phase 1 and we now proceed to Phase 2.
Example of job.txt:
and,10111,101
or,10,1011
and,0,101
Every line ends with a
, the last line might or might
not end with
https://en.wikibooks.org/wiki/A_Little_C_Primer/C_Command_Line_Arguments
Phase 2: (40 points)
After receiving data from the client, the edge server uses UDP to communicate with two
backend servers and relays the data to corresponding backend server. For example,
and,101,1001 should only be relayed to the backend server and, and the backend
server or should not receive this line. The operation type are randomly distributed in
the file, so you need to make a decision about the destination of the data. The data sent
to the backend server is not required to be the same as the original data. You can
add/delete some information if you need (like a key to sort the lines later, such as line
#). But if you dont need to do that, its totally fine. Youre free to implement your code in
any way as long as it works and conforms to the rules.
Once the backend server receives a line of data, it should complete the operation on the
binary numbers. We will only have two types of operations: and / or. They are all basic
binary operations. For example, 0 and 1 = 0, 0 or 1 =1. The binary number should be
calculated bit by bit and the result of bit operation is shown in the following Table. The
length of the binary numbers (operands) is not guaranteed to be the same. They may
have different lengths. You need to pad 0 before the shorter one to make it as long as
the longer one for the operations (or you can do it in other ways as you wish). For
example, 1010 and 110 should be calculated as 1010 and 0110 = 0010.
Backend server and only makes and operations while backend server or only
deals with or operations. These two backend servers are totally independent and
there is no communication between them.
After calculation, the backend server need to print an equation of the result to the
screen. Please dont print those padded 0s. The leftmost bit of every binary number
must be 1, except when it is all 0s. Please see Phase 3 for subsequent actions and
example outputs.
Table 2. Results for bit operations
Result for bit operation andResult for bit operation or
and 0 1or 0 1
0 0 00 0 1
1 0 11 1 1
Phase 3: (25 points)
At the end of Phase 2, two backend-servers should have their computation results ready. Those
results should be sent to the edge server using UDP. When the edge server receives the
computation result, it needs to print the result on the screen and forward the result to the client
using TCP. The order of lines printed on the edge servers screen can be any regardless
of the order of input file.
When the client receives the results, it prints results on the screen line by line. The order of
lines printed on clients screen should stick to the order of input file.
For example, if the input file job.txt is:
and,10111,101
or,10,1011
and,0,101
then the output order of final result on clients screen should be:
101
1011
0
Once all lines are printed on clients screen in order, we are done!
Ports and Message Formats:
The ports to be used by the clients and the servers for the exercise are specified in the following
table:
Table 3. Static and Dynamic assignments for TCP and UDP ports.
Process Dynamic
Ports
Static Ports
Backend-Server OR 1 UDP, 21000+xxx (last three digits of your USC ID)
Backend-Server AND 1 UDP, 22000+xxx (last three digits of your USC ID)
Edge-Server 1 TCP, 23000+xxx (last three digits of your USC ID)
1 UDP, 24000+xxx (last three digits of your USC ID)
Client 1 TCP
NOTE: For example, if the last 3 digits of your USC ID are 319, you should use the
port: 21000+319 = 21319 for the Backend-Server (A). It is NOT going to be 21000319.
ON SCREEN MESSAGES:
Table 4. Backend-Server OR on screen messages
Event On Screen Message (inside quotes)
Booting Up: The Server OR is up and running using UDP on port
The Server OR start receiving lines from the edge server for OR
computation. The computation results are:
Upon receiving every line for OR
computation:
After receiving all lines and finishing all
OR computation:
The Server OR has successfully received
server and finished all OR computations.
After sending all computation results to
the edge server:
The Server OR has successfully finished sending all computation results
to the edge server.
ON SCREEN MESSAGES:
Table 5. Backend-Server AND on screen messages
Event On Screen Message (inside quotes)
Booting Up: The Server AND is up and running using UDP on port
The Server AND start receiving lines from the edge server for AND
computation. The computation results are:
Upon receiving one line for AND
computation:
After receiving all lines and finishing all
AND computation:
The Server AND has successfully received
server and finished all AND computations
After sending all computation results to
the edge server:
The Server AND has successfully finished sending all computation results
to the edge server.
ON SCREEN MESSAGES:
Table 6. Edge Server on screen messages
Event On Screen Message (inside quotes)
Booting Up: The edge server is up and running.
After receiving all lines from the client: The edge server has received
over port
After sending all OR computation lines
to the Backend-Server OR
The edge has successfully sent
After sending all AND computation
lines to the Backend-Server AND
The edge has successfully sent
Start receiving the computation results
from Backend-Server OR and
Backend-Server AND using UDP
The edge server start receiving the computation results from
Backend-Server OR and Backend-Server AND using UDP over port
The computation results are:
Upon receiving one computation result
from Backend-Server OR or
Backend-Server AND
or (depending on operation print the above or below line)
After receiving all computation results
from Backend-Server OR and
Backend-Server AND
The edge server has successfully finished receiving all computation
results from Backend-Server OR and Backend-Server And.
After sending all computation results to
the client
The edge server has successfully finished sending all computation results
to the client.
ON SCREEN MESSAGES:
Table 7. Client on screen messages
Event On Screen Message (inside quotes)
Booting Up: The client is up and running.
After sending all lines to the edge
server:
The client has successfully finished sending
server.
After receiving all computation results
from the edge server
The client has successfully finished receiving all computation results from
the edge server.
After sorting the computation resultThe final computation result are:
Example job.txt:
and,10111,101
or,10,1011
or,11,10001
and,1001,111
Example Output:
Backend-Server OR Terminal:
The Server OR is up and running using UDP on port 21319.
The Server OR start receiving lines from the edge server for OR computation. The
computation results are:
10 or 1011 = 1011
11 or 10001 = 10011
The Server OR has successfully received 2 lines from the edge server and finished
all OR computations.
The Server OR has successfully finished sending all computation results to the
edge server
Backend-Server AND Terminal:
The Server AND is up and running using UDP on port 22319.
The Server AND start receiving lines from the edge server for AND computation.
The computation results are:
10111 and 101 = 101
1001 and 111 = 1
The Server AND has successfully received 2 lines from the edge server and
finished all AND computations.
The Server AND has successfully finished sending all computation results to the
edge server
Edge server Terminal:
The edge server is up and running.
The edge server has received 4 lines from the client using TCP over port 23319
The edge server has successfully sent 2 lines to Backend-Server OR.
The edge server has successfully sent 2 lines to Backend-Server AND.
The edge server start receiving the computation results from Backend-Server OR
and Backend-Server AND using UDP port 24319.
The computation results are:
10 or 1011 = 1011
11 or 10001 = 10011
10111 and 101 = 101
1001 and 111 = 1
The edge server has successfully finished receiving all computation results from
the Backend-Server OR and Backend-Server AND.
The edge server has successfully finished sending all computation results to the
client.
Client Terminal:
The client is up and running.
The client has successfully finished sending 4 lines to the edge server.
The client has successfully finished receiving all computation results from the edge
server.
The final computation results are:
101
1011
10011
1
Reviews
There are no reviews yet.