Download presentation
Presentation is loading. Please wait.
1
Building an Internet Router
2018/6/10
2
Overview Introduction Requirements Implementing Details Coding Tips
Reference
3
Introduction Implement a fully functional internet router.
Route real packets. Virtual Network System (VNS) VNS server runs at Stanford VNS client connects to the server Each of you will be assigned a topology Login with username and password ed to you Browse to the “Your Profile” page and click on the “Topologies” link. Click on README, then on routing table
5
How it really works … VR Client Socket 2. Virtual router “server” forwards packet to students “vr” client 3. Student’s client tells the server, which interface to route packet to Instructional machines PC Linux 1. Packet arrives destined for web server ‘C’. Firewall Campus Network “Virtual Router Server” Web/ftp servers
6
Requirement (1) Example :
“ping” IP addresses of your router. The router is configured with 3 Ethernet interfaces, which are assigned different IP addresses. Example : eth eth eth $ ping Functionality: The router responds correctly to ARP requests packet. The router responds correctly to ICMP echo requests packet.
7
Requirement (2) Example
The router can successfully route packets to and from your application servers. Two application servers IP address of application server 1: IP address of eth1 + 1. IP address of application server 2: IP address of eth2 + 1. Example $ ping
8
Requirement (2) Functionality The router correctly sends ARP requests.
The router correctly handles ARP replies. The router correctly forward packets to and from the application servers. The router maintains an ARP cache. Timeout; queue packet; ICMP host unreachable message for 5 ARP requests
9
Step 1: The stub code for the client is available in your project repository. It is also available at “ The stub code handles all the required work for connecting and communicating with the VNS server. Compile the code using the Makefile. To execute the program: ./sr -s vns-1.stanford.edu -t r rtable -v vrhost –l LOGFILE –u username –a authfilename “–t <topo-id>” is used to specify the topology id. “-s vns-1.stanford.edu ” or “-s vns-2.standford.edu” specifies the VNS server “-l <logfile>” is used for log packets. “-u <username>” is used to specify your username. “-a <authfilename>” is used to specify the path to the authentication key. “-r <rtable>” is used to specify the path to the routing table. DO NOT change the “DEFAULT_PORT” in “sr_main.c”, and compile code via make.
10
Step 1: (contd.) The routing table is stored in the file “rtable”. You can copy it from your Topology page. The routing table format: ip gateway mask interface Example: eth1 eth2 eth0 To test if the stub code is actually receiving packets, try “ping <eth0>”. The sr should print out that it receives a packet.
11
Step 2 – Get a feel for how your router ought to behave.
The router's interface addresses in topology 56: eth eth eth Two application servers with the following addresses: application server application server Try: Ping router’s addresses Traceroute router’s addresses Ping application servers Traceroute application servers Connect to application servers via Internet browser.
12
Step 3: requirement 1- Ping
Ping program sends an ICMP echo request destined to your virtual router (R). It will be routed to a host or router (H) that is locally connected to your router (R). Host (H) must convert the 32-bit IP address of router (R) into a 48-bit Ethernet address. If host (H) can not find it in ARP cache, it will broadcast an ARP request to every host on the network. ARP request contains the IP address of your router (R) and request “who has this IP address, tell H”. Upon receiving this ARP request, your router (R) will reply with an ARP reply. This reply contains its IP address and the corresponding hardware address. When the host (H) receives the ARP reply, H will forward ICMP echo request to your router (R). Your router (R) responds with an ICMP echo reply to the host that is running ping program.
13
Step 4: requirement 2 – Routing
When your router intercepts a packet that is destined to an application server. If TTL field = 0 or 1 – Discards it and send back an ICMP time exceed. If not, decrements the TTL field in the IP header and recalculate the checksum. Consults routing table and identifies the next hop. Looks up ARP cache for the hardware address belonging to the next hop. If can not find, broadcast ARP request, queue packet. Your application server responds with an ARP reply. Receiving the ARP reply – forward the queue packet, and cache the hardware address. No ARP reply for 5 ARP requests – send ICMP host unreachable to source.
14
Trouble compiling the code on Ubuntu:
If you get the error: h_addr not a member of struct hostent In the file /usr/include/netdb.h: struct hostent { char *h_name; /* Official name of host. */ char **h_aliases; /* Alias list. */ int h_addrtype; /* Host address type. */ int h_length; /* Length of address. */ char **h_addr_list; /* List of addresses from name server. */ #if defined __USE_MISC || defined __USE_GNU #define h_addr h_addr_list[0] /* Address, for backward compatibility.*/ #endif }; Comment out the #if defined and #endif statements (highlighted in green) and re-compile the code. ( You may have to use "sudo" to edit the file.)
15
Some Coding Tips PLEASE START EARLY!!!!
The usage of htons, ntohs, htonl, ntohl Log packets and viewing the logfile in tcpdump. For logging packets, when script invokes “sr” it uses the “-l” flag to create a file “LOGFILE” ./sr –t s vns-2.stanford.edu –l LOGFILE To view the logfile using tcpdump command, execute: prompt % sudo tcpdump –e –vvv –x –r LOGFILE You can also use Wireshark to monitor the incoming and outgoing packets
16
Coding Tips- checksum calculation
IP checksum -- cover IP header ICMP checksum – (header and data) Compute the checksum Set checksum field to F203 F4F5 F6F7 0000 Compute 16-bit one’s complement sum. 0100+F203+F4F5+F6F = 0002 DEEF DEEF = DEF1 Store 16-bit one’s complement sum to check sum field. ~DEF1 = 210E 0100 F203 F4F5 F6F7 210E Verify the checksum. Compute the sum (including the checksum). 0100 F203 F4F5 F6F7 210E = 0002 FFFD 0002+FFFD = FFFF If the result is not all one bits, checksum error. discard packet.
17
Coding Tips For the stub code,
sr_router.c/h - data structures and utility functions about the router. sr_if.c/h - data structures of the interfaces and utility functions for handling the interface list. sr_rt.c/h - data structures of the routing table and utility functions for handling the routing table. You might need to modify other files for bugfixes or generate your own files and update Makefile to support them.
18
Coding Tips Receiving a packet
void sr_handlepacket(struct sr_instance *sr, uint8_t *packet, unsigned int len, char *interface) “packet” points to the packet with Ethernet header. Sending a packet to the network. int sr_send_packet(struct sr_instance *sr, uint8_t *buf, const char *iface)
20
Ethernet review
21
ARP review Hard type: 1 for Ethernet Protocol type: 0x0800 for IP
Hard size: 6 Protocol size: 4 Op: arp request arp reply
22
IP header review
23
IP datagram review
24
ICMP message review Type Code Description Echo reply 8 Echo request 3
Echo reply 8 Echo request 3 1 Host unreachable Port unreachable 11 Time exceeded
25
Some References It is highly recommended that you read the Frequently Asked Question in that web site. RFC 826 (ARP) RFC 791 (IP) RFC 792 (ICMP) /usr/include/netinet/ip.h /usr/include/netinet/icmp.h /usr/include/netinet/arp.h /usr/include/netinet/udp.h for checksum calculation
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.