IP Lab
Background:
The IP lab deals with fragmentation and reassembly.
In this lab, you will be passed a large
segment and will fragment it into several packets and then reassemble it
at the receive end. You should study the material on pages 248-263
in order to complete this laboratory.
The IP header corresponds to Figure 4.3 in the text. The version
field should be 4 for IPv4. We will not be supporting options, so
the HLen field should be 20 bytes (the value 5 should go in this field since
it counts 4 byte quantities). The TOS field can be set to zero for
this lab. The Length field is the number of bytes in the whole packet,
including the header (remember big endian byte order for multi-byte entities).
You should pick a unique Ident for each push command you receive from the
higher layer (start with zero). When that push has been completed (by sending smaller
pushes to the next lower layer) you will select a new Ident parameter.
| Version(4 bits) |
Hlen(4 bits) |
TOS(8 bits) |
Length (16 bits) |
| Ident (16 bits) |
Flags(3 bits) |
Offset(13 bits) |
| TTL(8 bits) |
Protocol (8 bits) |
Checksum (16 bits) |
| SourceAddr (32 bits) |
| DestinationAddr (32 bits) |
| Options (variable) |
Pad(variable to 32 bit boundary) |
| Data (payload up to ~64KBytes) |
You can set the TTL field to 1 in your packets since your packets won't
pass through a router. It may be easier for you to look at the combination
of Flags and Offset as a single 16 bit entity. It will be harder
if you try to declare a data structure for the 3 bits of flags. If
you view the 16 bit Flag/Offset field together, then the M (more fragments)
bit is 0x2000 (bit #50 in the header). You will want to turn this
bit on when there are more fragments. The Protocol field will define
which higher layer protocol to pass the data to. Protocols are defined
as:
-
IPT_ICMP = 1
-
IPT_IGMP = 2
-
IPT_TCP=6
-
IPT_EGP=8
-
IPT_UDP=17
-
IPT_OSPF=89
You should use IPT_TCP for your packets since that is the protocol that
will be implemented above you. If you receive something else, you
should discard the packet.
You should generate the checksum and fill in the field using the checksum
algorithm we reviewed earlier (page 95) (remember byte order when computing
the checksum). The checksum is computed over the entire IP header, not the payload.
The source address and destination address will be the specified 32
bit IP addresses.
The Offset field will contain the offset of the current packet in the
higher layer large segment (remember that it counts in 8 byte units of
data). You should send the fragments in order, but may receive them
out of order and should be able to reassemble them into the correct order
before passing the segment up to the next higher layer.
You may also receive fragments from different segments and you will
need to reassemble them into their correct segments before passing them
up to the next layer. You can assume that there will be at most 3 segments
active at any time and the maximum segment size will be at most 1000 bytes.
Specifications:
The IP layer object will be similar to the other objects you have written
in prior labs. The IP layer object must support the following methods:
-
init ( char *name, protocol *higher, protocol
*lower, char *addr, int port, int client);
The initialization code will be called with the addr field corresponding
to your machine's IP address. You should save this away so that you
can send it as the source address in your packets.
-
push ( char *buf, int len, char *addr);The
push method will
-
Look at the len field. If it is greater than 30 bytes, then
you should fragment the segment. You will send the first packet with
the M bit on and only the last packet of the segment will have the M bit
off. Remember that the segment must be fragmented on 8 byte boundaries
because of the Offset field.
-
pop ( char *buf, int len);When this method
is called, you should
-
Make sure that your machine is the destination of the packet, if not, print an
error and discard the packet..
-
Use the ident field to identify which segment it is associated with. If
this is a new ident value, allocate a record-keeping structure for this
segment.
-
See if the M bit is on. If so, put the fragment in the correct offset
in the segment (you will need to declare an array to store the fragments
in as they are received).
-
If the M bit is not on, then you can determine the total length of the
segment (Offset*8+length-HLen*4) to pass up to the next layer.
-
When all of the holes (fragments) have been received, pass the segment
up to the next layer.
Tips:
- You will probably want to turn on "Update list of packets in real time"
and "Automatic scrolling in live capture" in the ethereal capture window so you can see
packets as they arrive. Do not enable name resolution.
- You should use ping -n so that ping doesnt do name resolution.
- Use different IP addresses and subnet masks than those specified in this
lab writeup. If you use the same values, other student's code will respond
to your arp requests and you will become confused.
- The length parameter in the pop method is the length of the Ethernet frame, not the length of the IP packet. You need to look at the length inside of the IP header in order to determine how long the data is.
Example:
The arguments to the binary are the same as ARP. The arguments are
(host where daemon is running[this machine]) (port daemon is
listening to[1234]) (src IP address) (src ETH address) (dst IP address)
(dst ETH address) (-c or -s) (-v optional debug flag)(0xff debug level).
The additional arguments were included so that
you can run your code without interfering with
other students. Pick IP addresses and Ethernet addresses with the
same top bytes as this example, then change the
bottom byte to a value between 0 and 200.
On the machine cs460-7 run
./ip cs460-7 1234 192.168.102.7 00:a0:cc:66:99:33 192.168.102.2 00:a0:cc:66:99:35 -c -v 0xff
On the machine cs460-5 run with exactly the same arguments, except for
the hostname and client flag.
./ip cs460-5 1234 192.168.102.7 00:a0:cc:66:99:33 192.168.102.2 00:a0:cc:66:99:35 -s -v 0xff
You will always connect to the daemon on port 1234. The daemon is
"ether_service" and you can use "ps -ef | grep service" to make sure it is running on the machine you are working
on.
While you are getting your code working, you will probably want to turn
on some serious debug statements. If you run
the lab code with something like "./ip cs460-7 1234 192.168.102.1 00:a0:cc:66:99:33
192.168.102.2 00:a0:cc:66:99:35 -c -v 0xff" it will turn on a lot of debug in the lower
layers. Bit 0 turns on the physical layer printfs. Bit 1 (0x2) turns on the
ethernet debug. Bit 2 (0x4)
turns on a printf when something is not destined for
your ethernet address. Bit 3 (0x8) turns on the basic arp debug.
Bit 4 (0x10) just shows what is being put into the
arp table.
Passoff:
We will provide you with the framework at ~cs460ta/labs/ip_template
on one of the 460 lab machines
to help you to test your IP layer. The passoff procedure will test
the following specific items
The
main() code will send a small packet (<30 bytes) from the client to
the server
The
main() code will then send packets of increasing length to make sure that
your code fragments them correctly.
The
server code will then send back a small packet (<30 bytes) and you should
be able to read it correctly.
The
server code will also send fragments with the wrong Ident field, wrong
checksum, wrong version, etc and you should discard these packets.
Run your code using the framework and the lab version of the code from
~cs460ta/labs/ip on another machine in order to pass off your program for the TA
during his office hours. This lab code will basically do the same thing as the
framework code, but may run some different tests. It will first receive all of
the packets you send from main. When you hit the ENTER key on the server window,
it will send you frames to test your responses.
The following passoff levels will apply to this lab:
| Passoff
Level |
Behavior |
Points |
| Minimal
Passoff |
At
least one IP packet is successfully sent to the server |
2
Points |
| Fragmentation |
You
are able to correctly fragment all of the packets sent to the server |
3
Points |
| Minimal
Reassembly |
You
are able to receive a short packet from the server correctly |
1
Point |
| Perfect
behavior |
Passes
all tests and correctly reassembles all long packets |
4
Points |