Programming Assignment

Due Date - Sept 13, 2019


Objectives


  1. Learn to create network packets.

  2. Learn how packets can be sent over the network.

  3. Familiarize you with the concept of sockets.

  4. Learn packing structures, endianness, unpacking, and interpreting network data.

  5. Learn how to use actual data from a packet.

  6. Use packet capture to visually inspect protocols.


Overview


$ lightserver -p <PORT> -l <LOG FILE LOCATION>

1.PORT - The port server listens on.

2.Log file location - Where you will keep a record of actions.

For example:
$ lightserver -p 30000 -l /tmp/logfile

Deliverables (each worth 5 points)


  1. Write a server that listens for incoming connections on the specified port.

  2. Server must parse two command line arguments, port and log locations.

  3. The server must not exit after receiving a single packet.

  4. Once a client connects, it logs a message in the following format "Received connection from <CLIENT IP, PORT> "

  5. Once it receives a hello message from the client, it logs the connection and sends a hello back to the client.

  6. You can assume the packet format is the following:

+-----------------+--------------------------+-------------------------+
|                 |                          |                         |
|                 |                          |                         |
|Version(4 bytes) |Message type (4 bytes)    |Message Length (4 bytes) |
|                 |                          |                         |
|                 |                          |                         |
+-----------------+--------------------------+-------------------------+
|                                                                      |
|                                                                      |
|                       Message (Max 8 Bytes)                          |
|                                                                      |
|                                                                      |
+----------------------------------------------------------------------+
  1. It receives the packet header first, followed by the message. Hint: You need two RECV calls.

  2. Check if Version == 17. If not, log an error message VERSION MISMATCH and continue to listen. Do not exit.

  3. If Version == 17, check the message type. If message Type is 1 - the corresponding command is LIGHTON. If message type is 2 - the corresponding command is LIGHTOFF. No other command is supported.

  4. If the server sees a supported command, log “EXECUTING SUPPORTED COMMAND: COMMANDNAME”, else log <"IGNORING UNKNOWN COMMAND: COMMANDNAME”.

  5. Send back a “SUCCESS” message to the client.

  6. Make sure server does not exit on 0 byte messages.


Client Specifications


$ lightclient -s <SERVER-IP> -p <PORT> -l LOGFILE

The client takes three arguments:

1.Server IP - The IP address of the server.

2.PORT - The port the server listens on.

2.Log file location - Where you will keep a record of packets you received.

For example:
$ lightclient -s 192.168.2.1 -p 6543 -l LOGFILE
  1. The client must parse three command line arguments, server, port, and logfile.

  2. The client should connect to the server on the specified port.

  3. Constructs and sends a hello packet to the server.

+-----------------+--------------------------+-------------------------+
|                 |                          |                         |
|                 |                          |                         |
|Version(4 bytes) |Message type (4 bytes)    |Message Length (4 bytes) |
|                 |                          |                         |
|                 |                          |                         |
+-----------------+--------------------------+-------------------------+
|                                                                      |
|                                                                      |
|                       Message (HELLO)                                |
|                                                                      |
|                                                                      |
+----------------------------------------------------------------------+
  1. Receive reply from Server - if version is 17, log “VERSION ACCEPTED”, else log - “VERSION MISMATCH”

  2. If version is accepted, send a command packet.

+-----------------+--------------------------+-------------------------+
|                 |                          |                         |
|                 |                          |                         |
|Version(4 bytes) |Message type (4 bytes)    |Message Length (4 bytes) |
|                 |                          |                         |
|                 |                          |                         |
+-----------------+--------------------------+-------------------------+
|                                                                      |
|                                                                      |
|                       COMMAND (LIGHTON/LIGHTOFF)                     |
|                                                                      |
|                                                                      |
+----------------------------------------------------------------------+
  1. Receive the server’s reply, log the reply, and gracefully shutdown the socket. You can assume the server always replies with a “SUCCESS” message for this assignment.

  2. Use TCPDUMP or Wireshark to capture the interactions, turn the .pcap file in with the assignment.


Additional requirements:


  1. Code must compile/run on Google Cloud Ubuntu VM (18.04) - we will test your code only on the VM.

  2. You must pack the packet in a structure. If you are using python, use the struct module.

  3. Pay extra attention to byte-order encoding before sending the packet. Big-endianness is the dominant ordering in today’s network protocols.