1 IP: putting it all together Part 1 G53ACC Chris Greenhalgh
2 Contents l Scenario l Local network communication –Sending a packet –ARP –Receiving a packet l Remote network communication –Routing
3 Book coverage l Assumed from CCN: –Comer ch. 13 (routing), 17 (internet), 22 (IPv6), 25 (TCP) l Reviewed: –Comer ch. 18 (addresses), 20 (datagram), 21 (frag.) l Additional: –Comer ch. 19 (ARP), 23 (ICMP), 24 (UDP), 26 (NAT), 27 (Internet routing, part)
4 Scenario l Sending a UDP packet –E.g. the ReverseClientUnicast, or DNS client l Pre-configured machine l On an Ethernet l Connected to the Internet l Running the IP protocol suite –How does communication "really" work?
5 Scenario (& see text dump) (monet) (mcclean) (DNS server) Router Ethernet switch(es) / / ( Internet Start Here
6 e.g. ReverseClientUnicast.java l … int port = Integer.parseInt(args[1]); InetAddress server = InetAddress.getByName(args[0]); DatagramSocket socket = new DatagramSocket(); … byte [] data = requestByteStream.toByteArray(); DatagramPacket request = new DatagramPacket(data, data.length, server, port); socket.send(request); …
7 TCP/IP reference model IEEE802 Ethernet, WiFi, … IP TCP, UDP Comer Fig ReverseClient, DNS, … You are here
8 What have you got? (what does the machine know?) l An array of bytes –Application layer data l A destination IP address (not name) –E.g (case 1); (case 2) l A destination UDP port l A sending UDP socket (=> source UDP port) l Local IP configuration (in OS) –See later
9 Goal: send that data to the destination machine l But physical network transports Ethernet frames (only!)… You are here: Application Data
10 Transport layer, UDP: add UDP header l Source port = sending socket l Dest. port = from request l Data = app. Data l Length = data length l Checksum = error check (CRC)
11 TCP/IP reference model IEEE802 Ethernet, WiFi, … IP TCP, UDP Comer Fig ReverseClient, DNS, … You are here
12 What have you got now? (what does the machine know?) l A UDP header and datagram payload –Includes source & dest. UDP ports –Application layer data l A destination IP address (not name) –E.g (case 1); (case 2) l Local IP configuration (in OS) –See later
13 Network Layer, IP: add IP header
14 Selected IP header fields l Version = 4 l Type = UDP l Source IP address = a local IP, probably not filled in yet l Destination IP = from request l TTL = “Time To Live” (network hops), initially high l Header checksum = error check for header l Fragment offset – see fragmentation
15 So… l You have: –IP packet –With IP destination l You need: –Ethernet (or other network) Interface to send it –Ethernet frame –With Ethernet destination
16 Local IP configuration l For now assume set by hand, e.g. on monet: –Own IP address, e.g –Netmask (range of IP addresses on physical segment), e.g –Default router, e.g –DNS server address –(See later notes on auto-configuration) l Built in: –Own Ethernet address (in Network Interface Card (NIC) PROM)
17 IP layer: what shall I do with this packet? l IP datagram forwarding rule: –Send it to another physically reachable machine which is believed to be closer to the IP destination l But: –Which machine is closer? –Which physical interface can be used to reach that machine? l Consult OS IP routing table…
18 Routing table l Lists a set of rules: l What to do with a packet addressed to any destination IP address –Which physical interface to use –Whether the destination is directly reachable –If not, which directly reachable machine to pass the packet on to
19 Routing table example (from scenario, monet) # netstat -r Destination Gateway Genmask Fl M R U Iface U eth U lo UG eth0 # ifconfig eth0 [windows: ipconfig /all] eth0 Link encap:Ethernet HWaddr 00:01:02:AD:0F:08 inet addr: Bcast: Mask: UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 # netstat -r Destination Gateway Genmask Fl M R U Iface U eth U lo UG eth0 # ifconfig eth0 [windows: ipconfig /all] eth0 Link encap:Ethernet HWaddr 00:01:02:AD:0F:08 inet addr: Bcast: Mask: UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 G = gateway (not direct)
20 Routing table example: windows ( not from the scenario) l >netstat –r Network Destination Netmask Gateway Interface Metric l l l l l … l >ipconfig /all l … l Ethernet adapter Local Area Connection: l Connection-specific DNS Suffix. : l Description : 3Com Gigabit NIC (3C2000) l Physical Address : 00-0A-5E-54-2B-65 l IP Address : l Subnet Mask : l … This machine (direct)
21 Case 1: send to (monet) (mcclean) (DNS server) Router Ethernet switch(es) / / ( Internet Start Here
22 Case 1: Send to l Find routing table entry matching destination IP address ( ) l gateway (if any) and interface –No gateway (directly reachable destination) send directly to –Interface “eth0” l Need Ethernet address for direct destination to send on Ethernet…
23 Address Resolution Protocol (ARP) l Internet standard, RFC 826 l Protocol for dynamic mapping of (local) IP addresses to (local) Ethernet address
24 ARP request/response packet l Construct ARP request “who has IP ”: –“H” = “hardware” (Ether.); “P” = “protocol” (IP)
25 ARP/Ethernet encapsulation l Place ARP request in Ethernet frame –Type 806
26 ARP query l Broadcast on identified outgoing interface: Broadcast request Unicast response
27 ARP query handling –all hosts on that Ethernet receive the broadcast request and packet to OS –Each host inspects Ethernet frame type and passes to relevant handler (in OS) –ARP handler inspects request: is this my IP address? –Host sees match and builds and sends back ARP response “ = Ethernet address 0 0:a0:c9:ca:1d:d7” –Sending host caches this information for (near) future re-use in an ARP table…
28 ARP cache Try # arp –a Try # arp –a –table of IP address Ethernet (MAC) address
29 TCP/IP reference model IEEE802 Ethernet, WiFi, … IP TCP, UDP Comer Fig ReverseClient, DNS, … You are here
30 (Finally) Build Ethernet frame l Source IP = sending interface IP l Source MAC address = sending interface MAC address l Destination IP address = original destination l Destination MAC address = next hop MAC address l Ethernet frame type = 0800
31 Send on identified network interface l Ethernet LAN is (logical) broadcast –Packet typically seen by the Ethernet card of every machine on that LAN l (give or take Ethernet switches which learn and route by MAC address)
32 Receiving a packet…
33 Incoming Ethernet frame: NIC l Check dest. Ethernet (MAC) address –Accept if broadcast or = NIC’s MAC address –Interrupt OS…
34 Incoming Ethernet frame: OS l OS is interrupted by NIC and retrieves received Ethernet frame l Inspects frame type field and handles contents (payload) accordingly: –0806 ARP (already considered) –0800 IP v.4…
35 Incoming IP packet (OS) l Inspects IP header –Check header checksum, discard if corrupted –Check destination IP address l If (one of our) local address(es), continue local processing… l Otherwise, consider for forwarding –Forwarding enabled (e.g. router) see later –Forwarding disabled (e.g. most hosts) discard
36 Incoming IP packet with local destination (OS) l (Fragments reassembled first – see later) l Check IP packet type: –1 ICMP Internet Control Message –2 IGMP Internet Group Management –4 IP in IP (encapsulation) –6 TCP Transmission Control –17 UDP User Datagram l Pass to relevant handler…
37 Incoming (e.g.) UDP datagram with local IP address (OS) l Inspects UDP header –Check UDP checksum, discard if corrupt –Check destination UDP port l If not bound to an application Send an error response (ICMP Destination Unreachable – see later) l If currently bound to an application socket pass payload plus source IP and source UDP port to application socket…
38 Receiving application (e.g. ReverseServerUnicast.java) l int port = Integer.parseInt(args[0]); DatagramSocket socket = new DatagramSocket(port); … byte [] requestBytes = new byte[65536]; DatagramPacket request = new DatagramPacket(requestBytes, requestBytes.length); socket.receive(request); … l int port = Integer.parseInt(args[0]); DatagramSocket socket = new DatagramSocket(port); … byte [] requestBytes = new byte[65536]; DatagramPacket request = new DatagramPacket(requestBytes, requestBytes.length); socket.receive(request); …
39 Case 2: send to (different network) (monet) (mcclean) (DNS server) Router Ethernet switch(es) / / ( Internet Start Here
40 Case 2: Send to l Begins as before: –Construct UDP header –Construct IP header – Complete IP datagram
41 Case 2: Routing at sender l Find routing table entry matching destination IP address ( ) (may appear as “default”): # netstat -r Destination Gateway Genmask Fl M R U Iface U eth U lo UG eth0 l Doesn't match local network, So use default route –Gateway (next directly reachable hop) = router –Outgoing network interface = eth0 (IP ) G = gateway (not direct)
42 Case 2: Sending non-local l Destination IP address is l Destination Ethernet address is Ethernet address of gateway/next hop machine – do ARP to find Ethernet address corresponding to IP –Router replies with its MAC address on that LAN l Send IP packet in Ethernet frame on LAN to router MAC address…
43 Routing handling of packet l Initially as for normal host receive –NIC accepts Ethernet frame addressed to it –Passes to OS via interrupt –OS determines frame type and passes for handling as IP –Checks packet is not corrupt –Checks destination IP address l If local, continue processing for local delivery l If not local…
44 Router packet forwarding l OS checks packet Time To Live (TTL) –may discard packet, else decrement TTL l Now send as a normal packet –router OS checks own routing tables l finds next hop IP destination for network portion of IP address –resolves low-level address of next hop (e.g. Ethernet, using ARP) –sends packet on next hop interface
45 Routing in routers l Routers are pre-configured with details of directly connected networks l Routers exchange routing packets with all directly connected routers –e.g. RIP, BGP, OSPF l Routers progressively discover all networks and which interface is "closest" to them, i.e. what the next hop interface should be.
46 Wide-area routing l For scalability (localisation of information) routing is normally divided: –Within a site or organisation = “autonomous unit” –Between autonomous units Note: different protocols, different levels of granularity