meta data for this page


This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
courses:ct30a5000:assignment3 [2011/09/21 13:14]
courses:ct30a5000:assignment3 [2012/09/10 13:26] (current)
Line 1: Line 1:
-Network programming [[https://​​noppa/​opintojakso/​ct30a5000/etusivu|@ Noppa]] | [[courses:​ct30a5000:​start|@ wiki]] -  +Network programming [[https://​​noppa/​opintojakso/​ct30a5001/etusivu|@ Noppa]] | [[courses:​ct30a5000:​start|@ wiki]] -  
-Updated: --- //​[[|Jussi Laakkonen]] ​2011/09/21 12:05//+Updated: ​ --- //​[[|Jussi Laakkonen]] ​2012/09/10 11:42//
 ---- ----
 Updates: Updates:
-21.9.2011Updated the demonstration code & further specification +22.8.2012Initial version. 
-21.9.2011Memory leak point -> MSC creation point+22.8.2012Text-file based database set as a requirement. 
 +22.8.2012: Added sequence diagram. 
 +> 10.9.2012: Added clarification for error message sending.
-====== Assignment3: ​Read, learn and implement tic-tac-toe ​ ​======+====== Assignment3: ​Aphorism exchange system ​ ​======
-The third assignment is about Stream Control Transfer Protocol ​(SCTP). In this exercise the approach is different, ​you will have to+Third assignment is to implement an aphorism exchange system according to protocol described below. The system must be implemented with UDP. One has to implement a client and a server. Server listens in certain port (remember that you have no rights ​to use system ports between 1 – 1024 on class 6325 machines) and client sends UDP datagrams into that particular port using the IP address or the hostname of the server ​and server responds based on the message contents.
-  * Read the material +
-  * UNDERSTAND ​the material +
-  * Answer ​the [[assignment3?&#​questions|questions]] +
-  * Look at the [[assignment3?&#​example_code|example code]] +
-  * UNDERSTAND the [[assignment3?&#​example_code|example code]] +
-  * Implement required parts (tic-tac-toe) ​and send the result as all other assignments +
-    * This time it is recommended to use the example code as basis for assignment +
-    * Remember to rename the folder!+
-Grading of this assignment: total points ​== **11**: +===== Description =====
-  * 1 point for each question (5 total) +
-    * Answers do not have be long (no essays!) but descriptive. +
-    * **Return the question answers as __separate__ ''​answers.txt/​pdf''​** (no other formats!) +
-  * 6 points for the implementation of the tic-tac-toe +
-    * 2 points for properly using SCTP with the help of example code +
-    * 2 points for following the game protocol (and the game works!) +
-    * 1 point for __creating the MSC chart for the game protocol!__ +
-      * Based on [[assignment3?&#​protocol_messages|protocol packets]] and the [[assignment3?&#​game_description|description]] +
-      * Return the chart(s) along the assignment as **png/​jpg**. +
-    * 1 point for following the instructions (commands work, generic features fulfilled, returned as requested etc.)+
-===== Reading material ​about SCTP =====+Client can either add aphorisms to the database of the server or retrieve them from the server'​s database. The client sends a message to server, waits for a response from the server, informs the user about response and then quits. Client should get the command from a command line parameter. When adding an aphorism the client must request the aphorism from the user (via standard input).
 +Server can store up to 10 aphorisms and serves one request at a time. It is required to store the IP-address of the sender with the exact date and time along the sent aphorism (feel free to select the format). Save this information to a text file when server is quitting and load it at startup. When server is run for the first time (no database exists yet) it will start with an empty database and the text file is created. **OPTIONAL** update the content of the text file every time new aphorism is added. If the database is full server should response with appropriate message. If the command is not recognized server should return usage instructions in a message.
-  * READ AT LEAST THESE: +Server must not crash if it receives something else than described in the protocolSame applies for clientClient must inform the user if server is not foundClient must not 
-    * [[http://​​html/​rfc3286|SCTP introduction RFC]] +crash because of the invalid input given by user.
-    * [[http://​​developerworks/​linux/​library/​l-sctp/​|Better networking with SCTP]] by IBM/M. Tim Jones +
-    * W. R. Stevens, B. Fenner & A. M. Rudoff, Unix Network Programming:​ The Sockets Networking API, Chapters: 2.5, 9.1 and 9.2 +
-    * [[http://​​html/​rfc4960|SCTP specification RFC]] +
-    * A huge tutorial into SCTP by Cisco [ {{:​courses:​ct30a5000:​sctp_cisco_tutorial.pdf|pdf @ wiki}} | [[http://​​SCTP_tutorial.ppt|original @]] ] (recommended) +
-    * W. R. Stevens, B. Fenner & A. M. Rudoff, Unix Network Programming:​ The Sockets Networking API, Chapters: 9 and 10.+
- +IPv4 and IPv6 must be supportedUse ''​PF_INET6'' ​type socket ​and allow data from IPv4 mapped addresses although there exists some risks with thisFor more details see [[​Linux+IPv6-HOWTO/#​CHAPTER-SECTION-USING-API| Linux IPv6 HOWTO IPv4 Mapped Addresses]] ​and/​or ​read chapter IPv6 Network Programming book.
-===== Questions ===== +
- +
-  * What are the major differences when comparing SCTP to UDP? How about TCP? +
-  * Explain 3 benefits that SCTP offers when compared to existing transport layer protocols. +
-  * What are the differences between SCTP one-to-one and one-to-many styles? Why there are 2 "​different"​ styles? +
-  * Explain the difference between a connection (TCP) and an association (SCTP). +
-  * What benefits does the multihoming feature of SCTP give? Give at least 3 examples. +
-===== Example code ===== +
- +
-Example code will contain a server and a client using SCTP for communication. Server address multihoming is enabled by getting address and interface information of each running interface on the machine. Server and client support ​IPv4 and IPv6 addressesData sending and receiving is implemented in demonstrative manner as well as SCTP notification handling. +
- +
-{{:​courses:​ct30a5000:​sctp_demo.tar.gz|SCTP demonstration code}} +
-> Updated on 21.9.2011 @ 11:25 +
- +
-Compile: +
-  * ''​make'' ​to compile without tests +
-  * ''​make tests''​ to compile test server ​and client +
-  * ''​make debug''​ make with ''​-g''​ flag +
-  * ''​make bybook''​ make with a method ​from a book for address structure packing ​  +
-  * ''​make bybookdebug''​ make previous ​with ''​-g''​ flag +
- +
-Start the test server with ''​./testsctps <​port>''​ +
- +
-And the client ''​./testsctpc <IPv4/IPv6 address> <​port>''​ +
-  * When using IPv6 link local addresses add the interface to the end of the address: e.g. ''​fe80::​7a2b:​cbff:​fea5:​68e0%eth0''​ +
- +
-Close server with Ctrl+C, client quits after the demonstrative tests quit. +
- +
-The server starts listening on all interfaces that are available and running and accepts incoming data from clients. Client sends some amount of data to server twice and server echoes the data back to client. +
- +
-Notification information is just printed to stdout on both server and client ​reaction not implemented as this is just a demonstration. +
- +
-===== Tasks ===== +
- +
-Your task in this third assignment is to see what the code is doing and understand it. In addition you are required to implement a simple tic-tac-toe game according to protocol described below. +
- +
-==== Game description ==== +
- +
-The game is played between 2 players, server does not need to support more than one game at a timeThe game happens in 3x3 grid where indexes are from 0 to 2Player has to give 2 coordinates (e.g. '0,1') for his/her markerPosition 0,0 is the top left corner. +
- +
-Server awaits for connections in given port and when a client connects to server with correct ''​ppid''​ and introduction message (HELLO) server replies (HREPLY) and gives '​x'​ for the first player, response to second player is similar but '​o'​ is assigned to that player. +
- +
-When 2nd player has connected server sends a turn indication message (TURN) to the first player and the player responds to it with a POSITION message which contains the position for the marker. If the position is not used and position is valid server replies to both players with GRID message containing the current state of game . After this server gives the turn to the other player. +
- +
-After the grid is full or either of the players gets 3 of his/her markers in a row (horizontal,​ vertical, ​or diagonal) the server reports ending of the game to both players (WINNER) and disconnects themAfter this clients quit and server awaits for new players. +
- +
-Add own files for client or server if necessary. Add client specific source files into ''​SOURCES_CLI''​ variable ​in the provided ''​Makefile''​ and server specific into ''​SOURCES_SRV''​. Common source files can be added into ''​SOURCES_GEN''​ variable in the ''​Makefile''​.+
 ==== Requirements ==== ==== Requirements ====
   * [[generic_features_to_implement|Generic features]]   * [[generic_features_to_implement|Generic features]]
-  * Send the numbers in network order+  * Use UDP-protocol for data transfer (remember that UDP is connectionless protocol)
-  * Client: +  ​* Sending and receiving messages over UDP. 
-    * Start: <​code>​./​sctpc <​server ​IPv4/​IPv6 ​address> <server listening ​port> +  * Do not use ''​connect()''​ -function 
-    Commands: +  * IPv4 & IPv6 support.  
-      /join join to specified ​server +  * Implement client and server. 
-      /grid show latest grid +    ​* Client: 
-      * /place x,y - place own mark into x,y position, where x = x coordinate, y = y coordinate +      * Start: <​code>​./​aphorismclient -h <server address> ​-p <​port ​number> -c <​command></​code
-      * /quit - shut down connection to server ​and quit the client +        <server address> - The IP address or hostname of the server 
-  * Server: +        <port number> ​Listening port of the server 
-    * Start: <​code>​./​sctps <server ​listening port> +        <​command> ​ADD or GET 
-    * Runs until stopped with Ctrl+(implemented into example code) +      * When ADD command is used the client waits for user to input the aphorism. 
-    Serves supports 2 clients ​at a time per gameRuns only one game at a time+      * Quit after receiving a response from server 
-    * Iterative, no threads or ''​fork()''​.+    * Server: 
 +      * Start: <​code>​./​aphorismserver -p <​listening port></​code
 +        * <​listening port> - Port that server listens for incoming datagrams 
 +      * Can store 10 aphorisms. 
 +        * Data to save: aphorism, who sent (IP), when (date & time) 
 +        * Save aphorisms into a text-file when the server is terminated. 
 +        * Read aphorisms from a text-file into database when starting the server. 
 +      ​* Runs until is stopped with Ctrl-or ''​quit''​ command from command line. 
 +      Server must serve one request ​at a time. After serving one request process the next one. 
 +      * Iterative, no threads or ''​fork()''​.
-==== Protocol ​messages ​====+===== Protocol ​=====
-**HELLO**:+==== Protocol packets and data types from client to server ====
-^ unsigned 8bit int ^ +=== Add an aphorism ===
-| 0x01              |+
-Hello message sent by client ​to server as first message.+^ 3 characters ^ 10 to 509 characters ​ ^ 
 +| ADD          | aphorism ​      |
----- +For adding an aphorism to server. If the adding of an aphorism succeeded (database not full) server responds with AOK -message, ​otherwise with ERRMinimum length ​for an aphorism is 10 characters. If the aphorism is less than this server responds with ERR. 
- +Example: ADDThat which does not kill us makes us stronger.\0
-**HREPLY**:​ +
- +
-^ unsigned 8bit int ^ 1 char                    ^ +
-| 0x02              | players mark as character | +
- +
-Reply message ​to HELLOsent by server to client when client was acceptedContains the playing character ​for the player ('​x'​ or '​o'​)+
 ---- ----
-**TURN**:+=== Get an aphorism ===
-unsigned 8bit int +3 characters ​
-0x03              ​|+GET          ​|
-Turn indication ​message sent by server to the client ​whose turn is to place a mark into the grid.+For requesting an aphorism from server. Server responds with an aphorism (APH message). Or if there is no aphorisms an ERR message is sent
 +==== Protocol packets and data types from server to client ​====
-----+=== AOK (Aphorism OK) message ===
-unsigned 8bit int ^ unsigned 8bit int ^ unsigned 8bit int +3 characters ​
-0x04              | x coordinate ​     | y coordinate ​     ​|+AOK          ​|
-Player reply to TURN message, this message tells that in which position player wishes to put his/her mark on the grid. Sent by client to the server.+Sent by server ​when adding of an aphorism was a success.
 ---- ----
-**GRID**:+=== Aphorism reply message ===
-unsigned 8bit int char         ^ char         ^ char         ^ char         ^ char         ^ char         ^ char        ^ char        ^ char        ​+3 characters ​10 to 509 characters ​
-0x05              | mark at 0,0  | mark at 0,1  | mark at 0,2  | mark at 1,0  | mark at 1,1  | mark at 1,2  | mark at 2,0 | mark at 2,1 mark at 2,2 |+APH          ​aphorism ​            |
-E.g +Aphorism sent by server
- +ExampleAPHBelieve nothing you hear, and only half of what you see.\0
-^ unsigned 8bit int ^ char         ^ char         ^ char         ^ char         ^ char         ^ char         ^ char        ^ char        ^ char        ^ +
-| 0x05              | x | o  | -  | -  | -  | -  | - | x | o | +
- +
-Where: +
-  * '​x'​ is mark of first player +
-  * '​o'​ is mark of second player +
-  * '​-'​ is empty place in grid +
- +
-The game grid message sent by server to clients after each new mark placement. Contains markers placed by players+
 ---- ----
-**WINNER**:+=== Error message ===
-unsigned 8bit int 1 char                      ​+3 characters ​0 to 509 characters ​
-0x06              ​players mark as character ​|+ERR          ​Error message ​      |
-Message that indicates the winner of the gameincludes ​the mark of the winning player.+Error messagesent when database is empty (response to GET) or full (response to ADD). Sent also when the aphorism is too long or command is not recognized, in this case usage instructions are sent to client (separate commands to multiple lines). 
 +Example:​ERRDatabase is full.\0
-----+==== Sequence diagram ====
-^ unsigned 8bit int ^ unsigned 16bit int ^ 
-| 0x07              | error type        | 
-  * Error types +===== Additional notes and hints =====
-    * 1 game full +
-    * 2 invalid position+
-Error message, sent by server when game was full or given position was invalid ​(invalid coordinates or position taken).+  * Server and client can not accept ​or send messages longer than 512 characters. Remember the terminating NULL in character strings! 
 +  * Hints: ''​sendto()'',​ ''​recvfrom()'',​ ''​socket()'',​ ''​bind()'',​ ''​getaddrinfo()'',​ ''​getnameinfo()''​ 
 +  * **OPTIONAL** (remember to mention this in readme!): 
 +    * Use dynamic list for aphorismsDefine a adjustable limit for maximum number of aphorisms (hardcoded, using ''#​define''​ or with additional startup parameter for the server)
-===== Additional notes and hints ===== +===== Questions ​=====
- +
-  * Hints ''​socket()''​ ''​getaddrinfo()''​ ''​getifaddrs()''​ ''​setsockopt()''​ ''​connect()''​ ''​sctp_sendmsg()''​ ''​sctp_recvmsg()''​ ''​sendto()''​ ''​recvfrom()''​ ''​listen()''​ ''​select()''​ ''​inet_ntop()''​ ''​inet_pton()''​ ''​sctp_bindx()''​ ''​sctp_connectx()''​ ''​sctp_getpaddrs()''​ ''​sctp_getladdrs()''​ ''​shutdown()''​ +
-  * Note that with SCTP ''​connect()''​ function is not needed in one-to-many style. +
-  * **Required packages for Ubuntu to develop applications on top of SCTP: ''​libsctp-dev'',​ ''​libsctp1''​.**+
 +  * How to detect when connection is lost / application has crashed at the other end with UDP?
 +  * What is the maximum size for UDP datagram in class 6325? 
 ---- ----
 Network programming [[https://​​noppa/​opintojakso/​ct30a5000/​etusivu|@ Noppa]] | [[courses:​ct30a5000:​start|@ wiki]] Network programming [[https://​​noppa/​opintojakso/​ct30a5000/​etusivu|@ Noppa]] | [[courses:​ct30a5000:​start|@ wiki]]