REPL command reference

IP

Both your vhost and vrouter programs must have support a command-line interface (a REPL) to enter commands. This page explains how each command should operate and what the output should look like.

li: List interfaces

Example

> li
Name  Addr/Prefix State
 if0  10.0.0.2/24 down
 if1  10.1.0.1/24   up

Format (after header):

<ifname> <addr>/<prefix> <down|up>
Param Example Description
ifname if0 Interface name
addr 10.1.0.1 This node’s virtual IP on this interface
prefix 24 Prefix size that defines the network on this interface. For example, the text 10.1.0.1/24 means the node’s IP address is 10.1.0.1 on the network 10.1.0.0/24.
state down or up up if interface is enabled (can send/recv packets), down otherwise

ln: List neighbors

Lists IP addresses of reachable neighbors. For interfaces that are up, lists each neighbor specified for that interface in the lnx file.

Example

> ln
Iface          VIP          UDPAddr
 if0     10.1.0.1   127.0.0.1:5002
 if1     10.2.0.2   127.0.0.1:5005
 if1     10.2.0.3   127.0.0.1:5006
Specification

Format (after first line):

<ifname> <vip> <UDP addr:port>
Param Example Description
ifname if0 Interface name
vip 10.1.0.1 Virtual IP of neighbor
UDP addr:port 127.0.0.1:5002 UDP address and port where this node can be reached

Notes

  • Neighbors for interfaces that are down MUST NOT be included in this list

lr: List routes

List each node’s routes and cost information. The cost of each route depends on the route’s type, as described below.

Example

Here’s an example table for a router:

> lr
T       Prefix   Next hop   Cost
R  10.2.0.0/24   10.1.0.2      1
L  10.0.0.0/24   LOCAL:if0     0
L  10.1.0.0/24   LOCAL:if1     0

Here’s an example table for a host:

> lr
T       Prefix   Next hop   Cost
L  10.1.0.0/24   LOCAL:if0     0
S    0.0.0.0/0   10.1.0.1      -

Specification

Each entry in the route list has a type (T), depending on how the route was learned. There are 3 route types:

Route type Identifier Description
Local L Used for routes directly-connected to this node (ie, assigned to the node’s interface)
RIP R Routes learned via RIP
Static S Routes manually-specified using the route directive. Under normal operation, this is only used to specify the default route for hosts. You MAY use static routes on routers for debugging/testing, but we will not test this.

The format of each row depends on the route type.

Route type Next hop Cost Description
Local (L) LOCAL:<ifname> Always 0  
RIP (R) <vip> RIP cost  
Static (S) <vip> Always -  

Note: Static routes are not intended to be used on routers that are also using RIP. RIP behavior when static routes are present is undefined–we will not test this, and you don’t need to go out of your way to do any extra work for it.

down: Disable interface

Disable an interface. When disabled, no packets may be sent or received on this interface–this is equivalent to unplugging a cable from a port on the router. When an interface is disabled, any UDP packets received on that interface MUST be dropped.

For routers using RIP, disabling an interface MAY cause a triggered update to be sent to neighboring routers (on non-disabled links) to inform them of any updates, but this is not required (details here).

Format:

down <ifname>

where <ifname> is the name of any interface.

No output is expected after running this command.

up: Enable interface

Enable an interface. When enabled, a disabled interface returns to its enabled state and can now be used to send/receive packets.

For routers using RIP, enabling an interface MAY send a triggered update, but this is not required (details here).

Format:

up <ifname>

where <ifname> is the name of any interface.

No output is expected after running this command.

send: Send a test packet

Sends a test packet to a given IP address. Test packets are simply strings sent as the payload of an IP packet using protocol number zero (0).

Format:

send <addr> <message ...>

Sends a test packet to the given IP address. The contents of the packet must be the string provided as <message ...>. Messages may contain spaces, but will not contain a newline (ie, you can stop parsing command line input when encountering a newline).

For example:

> send 10.0.0.1 hello

This sends the text “hello” in a test packet to virtual IP 10.0.0.1. You may assume that strings sent as test packets are less than 1380 bytes (the maximum IP packet size (1400), minus the IP header (20 bytes)).

Receiving a test packet

When a node receives a test packet, it should print the packet in the following format followed by a newline:

Received test packet: Src: <source IP>, Dst: <destination IP>, TTL: <ttl>, Data: <message ...>
Param Example Description
source IP 10.0.0.1 Source IP
destination IP 10.0.0.2 Destination IP
TTL 28 The packet’s TTL
message hello The string contained in the packet

For the purpose of printing, you may assume that all test packets contain ASCII strings and are less than 1380 bytes.

Example

Received test packet:  Src: 10.0.0.1, Dst: 10.6.0.2, TTL: 28, Data:  hello