430 likes | 557 Views
Network Layer. NETS 3303/3603 Week 4. Problem: Link Delay Test. Develop a UDP-based client/server system to test the round-trip delay (RTD) PDA is chosen to be the server, which passively open a well-known port Upon receiving an array of bytes, it just echo’s the bytes. Link Client.
E N D
Network Layer NETS 3303/3603 Week 4
Problem: Link Delay Test • Develop a UDP-based client/server system to test the round-trip delay (RTD) • PDA is chosen to be the server, which passively open a well-known port • Upon receiving an array of bytes, it just echo’s the bytes
Link Client public class Timestamp implements Serializable { private long time; public Timestamp() { time = System.currentTimeMillis(); } public long getTime() { return time; } public String toString() { return new Long(time).toString(); } } • Gets the host to connect and number of link probes to send from command line • Create a serialised object with current time and send to server using ObjectOutputStream • Waits for echoed object from server • To find link RTD • Extracted object’s time is subtracted from current time
while (probes > 0) { dSocket = new DatagramSocket(); time = new Timestamp(); // object to send! bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(time); mBuff = bos.toByteArray(); outPkt = new DatagramPacket(mBuff, mBuff.length, host, PORT); dSocket.send(outPkt); inPkt = new DatagramPacket(mBuff, mBuff.length); dSocket.receive(inPkt); ois = new ObjectInputStream(newByteArrayInputStream(inPkt.getData())); try { time = (Timestamp)ois.readObject(); } catch (ClassNotFoundException e) {} System.out.println("RTT is => "+ (System.currentTimeMillis()- time.getTime())"); probes--; }
Test Output $ java LinkRttClient Enter host name: pda-wifi Enter required probes: 10 RTT is => 2105 ms RTT is => 43 ms RTT is => 31 ms RTT is => 56 ms RTT is => 34 ms RTT is => 57 ms RTT is => 32 ms RTT is => 56 ms RTT is => 33 ms RTT is => 69 ms Terminating link delay test...
Lesson Outline • intro • IP addresses • subnetting • routing/algorithms/architecture • ARP
Fundamental, IPv4 • fundamental TCP/IP protocol • RFC 791, other related RFCs • Inet checksum, rfc 1071, 1141, 1624 • path mtu, rfc 1191 • ip datagram reassembly, rfc 815 • rfc 1122, communications
Fundamental idea • ip implements an ip logical network on top of different kinds of network technologies where ip address is endpoint • hw is hidden by network layer (except for a few things like MTU)
what does IP do (and not do?) • sends and recvs packets to/from ip addresses - ip datagrams • no retries, doesn’t promise reliable delivery • packets due to various reasons may be lost, duplicated, delayed, delivered out of order, or corrupted • best effort - don’t lose them on purpose but only when nets busy => resources unavailable
IP functions • route packets • routing: process of determining path for data • ip routes packets when they come from • transport layer (down stack) • link layer (up stack) - we are router and forward pkts • fragmentation accrd. to link-layer MTU • handle ip options • send/recv ICMP error and control messages
IP address • 32 bits, “dotted-decimal” notation • 1.2.3.4, big-endian byte order, 0..255 is range • associated with interface, not machine • if machine > 1 i/f, then multi-homed • if multi-homed, not necessarily router • ip address in UNIX assigned to i/f with #ifconfig ed0 inet 131.253.1.2 netmask 255.255.255.0
Example Of Dotted DecimalNotation • A 32-bit number in binary • 10000000 00001010 00000010 00000011 • The same 32-bit number expressed in dotted decimal notation • 128 . 10 . 2 . 3
IP address structure • each address has structure in it: (network, host) • Host may be divided further into (subnet, host) • subnet mask used to determine subnet part • operation: ipaddress & subnet mask • (more later)
IP Address Conventions • When used to refer to a network • Host field contains all 0 bits • Broadcast on the local wire • Network and host fields both contain all 1 bits • Directed broadcast: broadcast on specific (possibly remote) network • Host field contains all 1 bits • a packet is sent to all computers on a network
Limited Broadcast • All 1’s (255.255.255.255) • Broadcast limited to local network only (no forwarding) • Useful for bootstrapping
IP address problems • assigning class by first bits means class A takes 1/2 of range, class B 1/4, class C 1/8, etc. • problems with this setup • class assignment is wasteful • ip host addresses not necessarily utilized well • too many networks in core routers • running out of ip addresses ??
Question • How can we minimize the number of assigned network prefixes (especially class B) without abandoning the 32-bit addressing scheme? • Subnet addressing • Proxy ARP (later)
Subnetting • subnet - use single IP network address to hide multiple physical nets • subnet notion converts (net, host) into slightly more hierarchical (net, subnet, host) • associate subnet mask with i/f ip address • Example, class B, one byte of subnet: ip = 148.1.1.0 subnet=255.255.255.0
Choice Of Subnet Size • How should host portion of address be divided? • Depends on topology at site and number of hosts per network • Each physical network is assigned 32-bit address mask • One bits in mask cover network prefix plus zero or more bits of suffix portion • Logical and between mask and destination IP address extracts the prefix and subnet portions
Subnetting subnetting functions: • 1. you can subnet an ip address and split it up on separate networks across routers (conserve address space) • 2. you hide your routing structure from remote routers, thus reducing routes in their routing tables if (dest ip addr & subnet mask) == (my ip addr & subnet mask) dest is on same subnet else different subnet (send pkt to router)
Fixed-length Subnet Masks • Organization uses same mask on all networks • Advantages • Uniformity • Ease of debugging / maintenance • Disadvantages • Number of nets fixed for entire organization • Size of physical nets fixed for entire organization
Routing • routing - the process of choosing a path over which to send datagrams • hosts and routers route • input: ip destination address • output: next hop ip address and internally an interface to send it out • routing does not change ip dest address
How configure routing table • static routes - by hand, on unix with % route to_dest via_next_hop • dynamically via routing protocol daemon, routed or gated on UNIX, protocols=RIP/OSPF/BGP
View routing table • unix host • % netstat -rn • n is for NO dns, else you may cause DNS queries • Linux • % route -n • cisco router • (router) show ip route
Routing table • entries logically (destination, mask, via gateway, metric/s) • destination - network or host address • mask - subnet mask for dst address • via gateway - next hop (maybe router) • metric/s - depends on routing table algorithm and dynamic routing protocols
SOME possible kinds of routes • host, 210.1.3.21/32 (to specific host) • subnet, 131.253.1.0/24 (to specific subnet) • network, 131.253.0.0/16 (to specific net) • default route - normally the router on a net, send it here when nothing else matches • expressed internally as 0.0.0.0 • note: host route to default route – most specific to least specific
Manual route entries • on FreeBSD unix host: % route add default 204.1.2.3 (default route) % route add 1.1.1.1 2.2.2.2 • 2.2.2.2 is the next-hop router for 1.1.1.1 • we must have direct connection to 2.2.2.2 (i/f must be on same subnet and must exist) % ifconfig ed0 2.2.2.1 (our i/f must exist)
ARP, The problem • problem: how does ip address get mapped to ethernet address? • 2 machines on same enet can only communicate if they know MAC/hw addr • Applications only use Internet addresses • solutions: • configure addresses by hand (ouch!) • encode in IP address (48 bits in 32?) • dynamic mapping
Consequence • Protocol software needs a mechanism that maps an IP address to equivalent hardware address • Known as address resolution problem
Dynamic Binding • Needed when hardware addresses are large (e.g., Ethernet) • Allows computer A to find computer B’s hardware address • A starts with B’s IP address • A knows B is on the local network • Technique: broadcast query and obtain response • Note: dynamic binding only used across one network at a time
ARP • rfc 826 • host A, wants to resolve IP addr B, • send BROADCAST arp request • get UNICAST arp reply from B • ethernet (or MAC) specific, although protocol designed to be extensible • implemented in driver, not IP • intended for LAN
Refinements • Cannot afford to send ARP request for each packet • Solution • Maintain a table of binding • OS will cache arp replies in arp cache (ip , MAC, 20 minute timeout) • don’t need to do arp on every packet
% arp -a (SunOs) # arp -a banshee.cs.pdx.edu (131.252.20.128) at 0:0:a7:0:2d:a0 pdx-gwy.cs.pdx.edu (131.252.20.1) at 0:0:c:0:f9:17 longshot.cs.pdx.edu (131.252.20.129) at 8:0:11:1:44:68 walt-suncs.cs.pdx.edu (131.252.21.2) at 8:0:20:e:21:25 walt-cs.cs.pdx.edu (131.252.20.2) at 8:0:20:e:21:25 connor.cs.pdx.edu (131.252.21.179) at 0:0:c0:c5:57:10 dazzler.cs.pdx.edu (131.252.21.132) at 8:0:11:1:12:82 sprite.cs.pdx.edu (131.252.21.133) at 8:0:11:1:12:e7 (DNS name,ip address,Ethernet address)
Arp command, functions • ping someone and learn MAC address • for debugging • delete out of date ARP entry (you changed the IP address, and you don’t want to wait, OR somebody mucked up)
Header details • header format is not fixed, somewhat dynamic (not used though) • hw type, ethernet == 1 • protocol type, ip = 0x800 • hwlen, 6 (MAC), plen 4 (ip) • operation: (used by rarp too) • 1: arp request, 2: arp reply • 3: rarp request, 4: rarp reply
More Details • sender hw addr, 6 bytes • the answer, if reply • sender ip: 4 bytes • target hw address: 6 bytes • 0 in request • target ip: 4 bytes
Proxy ARP • Allow two physical networks to share a single IP prefix • Arrange special system to answer ARP requests and forward datagrams between networks • Hosts think they are on same network
Proxy ARP pros, cons • pros • same network numbers • transparent to hosts • no change in IP routing tables • cons • does not generalize to complex topology • can drive you nuts -- debugging • not simple and not secure
Summary • IP is a best-effort network • Main IP functions • Routing, fragmentation, some error-handling • Subnetting provide hierarchy => CIDR! • ARP maps IP to hardware address