Software Developer / Photography Enthusiast 

Facebook Flickr LinkedIn RSS

MicroInternet

During my graduate studies, one of my projects for a networking class involved simulating TCP/IP at the application layer between nodes across a network. This “micro-Internet” consists of hosts and routers, each having the capability to emulate TCP’s reliable communication and IP’s packet forwarding. The source code is available for download here.

Host

The host consists of six parts:

  1. Host class
    1. Loads the host configuration file
    2. Starts all other host threads
    3. Contains window structures
    4. Contains TCP buffer and IP Queue
    5. Writes to the host log file
  2. Host command thread
    1. Processes all of the host’s requests
    2. Quit
    3. Send
  3. Host TCP
    1. Takes segments from the TCP buffer
    2. Transfers segments to the IP layer
    3. Maintains the window structures
    4. Maintains the timeout and retransmission
    5. Provides reliability
  4. Host IP
    1. Takes packets from the IP queue
    2. Sends segments to the destination (outgoing packets)
    3. Forwards segments to the TCP layer (incoming packets)
  5. Host IP Server
    1. Receives packets from other hosts
    2. Reassembles fragmented packets
    3. Adds packets to IP queue for the IP layer to handle
  6. Timeout class
    1. Schedules a timer to execute for each segment sent
    2. Resends the segment (adds it back to the queue) if the timer runs out
    3. Also creates a new timer for each timeout

Router

The router consists of six parts:

  1. Router class
    1. Keeps a list of hosts directly connected and their MTU
    2. Maintains the IP queue
    3. Maintains a queue for commands
    4. Starts all other router threads
    5. Writes the router log file
  2. Command class
    1. Auxiliary class used to keep track of commands issued
  3. Router command thread
    1. Reads each line that the router operator enters
    2. Creates command objects based on identifying parameters
  4. Router IP
    1. Continuously gets the router’s issued commands
    2. Sends or drops packets
    3. Gets the next hop for packets destined outside of the immediate network
    4. Fragments packets for smaller MTU data sizes of the next hop
  5. Router IP Server
    1. Multi-threaded server used to accept connections from multiple hosts concurrently
    2. Uses Router IP Server User thread
  6. Router IP Server User thread
    1. Receives packets from a host
    2. Forwards packets to the IP layer by adding them to the IP queue
    3. Recognizes fragments and reports the total size

Configuration

Both the host and routers require configuration files to properly run.  These files, host.conf and router.conf, respectively, are kept within the default package (the root of the project directory).  These two files MUST be edited according to the machine and virtual host-to-router setup you are planning to run and test.

Host Configuration

The host configuration must contain the following fields and values.  Note that, in order to prevent error, all fields must end with a colon and all values must end with a semicolon.

RouterIP: 128.235.44.21;
RouterPort: 2222;
LocalIP: 128.235.44.25;
MTU: 1500;
Retransmit_Timeout: 30;

Note that this file must be edited for every host that you plan on running, requiring the IP address to be updated, and possibly the router IP address.

Router Configuration

The router configuration must contain the following fields and values. Note that, in order to prevent error, all fields must end with a colon and all values must end with a semicolon.

############################
# Router Information
############################

LocalIP: 128.235.44.21;
Port: 2222;

#################################
# Connected nodes
# ——————————-
# Please enter the IP addresses
# of all directly connected hosts
#################################

HostIP: 128.235.44.22;
HostIP: 128.235.44.23;
HostIP: 128.235.44.24;
HostIP: 128.235.44.25;

################################
# Forwarding Information
# ——————————
# Please enter the host IP
# address, router IP address, &
# MTU size for all known hosts
# NOT connected to this router.
################################

#————————————–
# Host 1
# ————————————-
Destination: 128.235.44.26;
Router: 128.235.44.27;
MTU: 1500;
# ————————————-

#————————————–
# Host 2
# ————————————-
Destination: 128.235.44.28;
Router: 128.235.44.29;
MTU: 1500;
# ————————————-

#————————————–
# ETC
# ————————————-
#Destination: xxx.xxx.xx.xx;
#Router: xxx.xxx.xx.xx;
#MTU: xxxx;
# ————————————-

Running the Application

Host

  1. Configure the host.conf file according to the machine IP address and router IP address you are planning to use (to get the IP address, type in the command “ifconfig -a” in the Unix shell).
  2. Usage: java Host
  3. If you experience any compiler errors, please delete all class files and re-compile: javac Host
  4. To send a message to another host: /send destination_ip message_size

Router

  1. Configure the router.conf file according to the machine IP address (to get the IP address, type in the command “ifconfig -a” in the Unix shell).  Also, add all connected hosts and other forwarding information (as specified in the file).
  2. Usage: java Router
  3. If you experience any compiler errors, please delete all class files and re-compile: javac Router
  4. To send a received packet: /sendPacket source_ip
  5. To drop a received packet: /dropPacket source_ip

Logging

All router and host events (application, TCP, IP, server events) are stored in appropriate log files in the “/logs/” directory. A separate log file is created for each host and router, and is identified by the IP address. For example, a router running on IP 192.168.0.1 will save a log file called “Router_192.168.0.1_log.txt”; a host running on IP 192.168.0.2 will save a log file called “Host_192.168.0.2_log.txt”.

Please note that lines are separated by the system line separator (in this case, Unix). If a log file is created on AFS and later opened on the Windows operating system, Notepad will not terminate the lines properly (as Windows terminates lines differently than Unix). Instead, Wordpad or Microsoft Word may be used to view log files within Windows.

 

Leave a Reply

Home Projects MicroInternet