KIP document#1

Download Report

Transcript KIP document#1

CS492b Project #3-1
KIP
KAIST
Dept. of CS
NC Lab
Assignment Overview(1/2)

Implements your own IP Layer

Correctly set, handle and verify








IP version number - Ipv4
IP header length
IP packet length
TTL
Protocol number - TCP
Checksum
Source/Destination address
Packet forwarding
Assignment Overview(2/2)

Your IP layer Does NOT support




IP fragmentation
Multicast
IP header options
TOS(type-of-service)
Architecture(1/3)


Based on you STCP,
Make a new process
for IP layer
Use real IP address
LAN
Parent
(appl/T)
Child
(STCP)
IP layer
Architecture(2/3)
Parent(A/T)
Child(STCP)
Data
_sd
[0]
KIP
Data
_sd
[0]
Data_
sd[1]
Data_
sd[1]
Network
UDP
Parent(A/T)
KIP STCP Data
Child(STCP)
Data
_sd
[0]
Data_
sd[1]
KIP
Data
_sd
[0]
Data_
sd[1]
Architecture(3/3)




IP layer operates as an independent
process
IP layer uses network_send() &
network_recv()
Or make a new function
Use the actual IP header

Can get IP header by including <netinet/ip.h>
IP header

struct ip {
u_char ip_v:4, /* version */
u_char ip_hl:4, /* header length */
u_char ip_tos; /* type of service */
u_short ip_len; /* total length */
u_short ip_id; /* identification */
u_short ip_off; /* fragment offset field  should be set to 0 */
u_char ip_ttl; /* time to live */
u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */
};
Packet Sending


STCP calls ip_out()
IN ip_out()


Construct IP header
Calculate checksum




You can use existing checksum() function
Query routing table to find the output interfaces
Etc..
After finishing all the processing, it calls
network_send()
Packet Sending
Transport layer
STCP
routing table
Network layer
Link layer
ip_out()
Network_send()
rt_lookup()
Packet Receiving

In ip_in()

Checks a packet for errors


IP version mismatch, IP checksum error
If the packet is error-free,


If the packet is destined to this host, IP layer send
the packet to STCP
If the packet is destined to some other host, do
packet forwarding(by calling ip_fwd())
Packet Receiving
STCP
Transport layer
Network layer
Link layer
ip_in()
not ours
ip_fwd()
Packet received
ip_out()
Major Functions
1.
2.
3.
4.
5.
ip_init()
/ for IP layer initialization
ip_in()
/ for packet inprocessing
ip_out() / for packet outprocessing
ip_fwd() / for packet forwarding
rt_lookup() / for routing table look up
ip_init()

Do some initializations like transport_init()



Calling localsocketpair()
Fork()
Initialize necessary global variables
ip_in() uses 3 functions

check_ip_state()

Some packets that are invalid should be discarded, in
case



ip_header_checksum()



IP header is less than minimal
Checksum incorrect
Calculate ip header checksum
You can freely use checksum() source code
print_packet()

For debugging purpose
ip_out()




Makes ip header
Calculate checksum
Send the packet with payload
For testing purpose,

Put some codes for generating wrong IP datagrams





Wrong header format
Wrong IP address
Uses rand() functions
See network.c
Make Log file

Write IP header contents, time sent
ip_fwd()


Decrease IP TTL
Does some additional work before sending
the packet
rt_lookup()

Look up the routing entry for next hop
Find next hop IP address by doing
((dst. IP address & mask) = routing table entry)
 Perfect match

Routing Table(1/3)

Uses RouteEntry

Struct RouteEntry{
ip;
/subnet ip address
mask; /network mask
router; /next hop if not directly connected
devindex; / network interface index
}
Routing Table(3/3)



init_route_table()
rt_lookup()
print_tr()



Print routing table
Optional
Currently routing table is static, so just needed
for debugging purpose
Schedule & Deliverables


Due Date : 30th Oct.(midnight) – No Delay
Commented your full source code (e-mail)


Including your Makefile
Report (hard copy & thru e-mail)

Describe about your design in detail




About functions you made for this project
Describe what works and what does not
Describe any peculiar strategies that you have
used
Demonstration (will be scheduled)
Tips(1/2)

Objective


First, Make KIP design carefully!!!



Implementation of KIP itself is easy job
But, might spend a lot of time debugging the structure
Need a clear understanding KTCP helper
functions & UDP socket functions


Based on KTCP, implement simple IP layer
Ex) localsocketpair()
Start early and make steady progress throughout
the next three weeks!!!
Tips(2/2)

Focus on how to make KIP process

Check your STCP code thoroughly


Before implementing KIP, check Client/Server
can communicate each other


Decide where to put you KIP code
Check this by doing 2-way handshake
Implement KIP

Read KIP requirements
Tips(3/3)

If you intent to use localsocketpair(),



It makes TCP connection
Do NOT use network_send() & network_recv()
for this case
Be careful when using socket function

Think how much you can read & write

For 2-way handshake, ONLY TCP headers come &
go