IP Addressing and Routing

Introduction

- Definitions:
    Interface
    Link

- Questions:
   1. We know at each interface needs an IP address - how do we decide what
      it is?
   2. How do hosts and routers know where to send the packet to?
   The answer to 1 is to assign addresses such that it makes the solution to
   2 easier, so lets look at 2 first.

The IP Address

What gets addressed
- each destination on the Internet gets an address
- destinations are host interfaces, not hosts
- hosts can have multiple interfaces

Address Format

- 32 bits (4 bytes) long
- 2^32 = 4294967296 (4.2 billion) combinations
- commonly written in "dotted quads", but of course there are other reps
- ex: 18.70.0.158 (to base 2 by quad)
      /  |   \___\____________     (to base 10)
00010010 01000110 00000000 10011110 = 306577566 {address}

Routing {net1}

- Most unicast IP forwarding devices use "next hop routing" i.e. a host or
  router needs to know only where NEXT to send a packet with a
  particular address to.

- this forwarding information is stored in something called a routing table

Routing tables: {rtable}
- all machines store the data from routing tables, either explictly or
  implicitly
- ex. PC host only knows a few things: route to local net (added based on
  knowledge of ip address / netmask), default router (manually input),
  loopback (standardized)
- has IP address prefix and interface/gateway

IP Prefix
- only the first part of the IP number is significant
- can express by giving a bitmask (ex 255.255.255.0) or number of bits (ex. 24)
- address-length pairs often written either as: 18.70.0.158 255.255.0.0
  or 18.70.0.158/16
- you always want to match the most specific (most bits) prefix in table
- Trailer zeros often omitted.

Routing Procedure
- when you want to send or forward a packet, look up the IP address in
  routing table
- if it's an interface, just send it out that interface
- if it's a gateway, look up the gateway in the routing table and send out
  interface to get to gateway

How you get routes:

Loopback address (one per machine) - hosts & routers
- for testing
- doesn't leave machine 
- 127.0.0.1
- uses loopback interface
- adds entry: 127.0.0.1 via lo0

Netmask (one per interface) - hosts & routers
- tells you what's local and what's not (routing info - 1st clue for
  allocation - machines on same net should have same prefix)
- notation for expressing netmask same as IP prefix
- what do you know - notation not the only thing the same - netmask
  implies routing information!
- adds entry: 18.70 via (interface names)

Default route (one per machine) - hosts & most routers
- matches as a last resort / if nothing else matches / least specific route
- typically represented by 0.0.0.0/0
- a small subset of routers (with a lot (eg: 64mb) of memory!) on the Internet
  don't have a default, since they know all the routes they need to
- either configured in machine (just like IP address) or use:

Router Discovery - RFC1256 - hosts
- if there's more than one choice for default, or if you don't want to
  fix the default router's IP address
- routers announce their existance via periodic multicast ICMP messages with
  a preference number 
- hosts use most preferred router as default
- not widely used

ICMP Redirects - RFC792
- if there's multiple routers, your default may not actually be the router
  that a packet for a particular destination ought to go through
- the router will still forward the packet to the right destination, but
  may also send you an ICMP redirect, telling you the router that the packet
  should have been sent to
- you can then add that to your routing table, and save yourself a hop
- how does the router know? it knows if it forwards the packet out the same
  interface it came in
- Only interesting between endhosts and their next-hop routers.

Routing protocols - Routers
- hosts shouldn't really do this, but some do
- routers speak routing protocols with each other
- dynamic routing, adjustment during failure, optimal paths, policy routing,
  reduced administration
- Two main kinds: Internal (in an Autonomous System)
  and External (between ASes)
- Autonomous System / AS: set of routers under common admin control
- internal (optimization of path length): RIP, RIPv2, OSPF, ISIS
- external (policy): BGP
- {int-ext-route}

Internal Routing
- amongst the routers of one AS
- routers share routing information with each other in order to find the
  "optimal" route
- "optimal" is with reference to a metric
- static routing
- distance vector (RIP, RIPv2) or link-state (OSPF, ISIS)

Static routing
- 
-
- 

Distance vector (RIP/RIPv2)
- a.k.a. Bellman-Ford algorithm
- metric is number of hops (distance)
- tell your neighbours about all the networks you know about, and how far
  away they are
- neighbours add their distance to you to the number, and keep if they
  don't have a route to the network, or your route is a lower cost route
(need to firm up details - look at Huitema)
- XXX Split Horizon and Poison Reverse

Link state (OSPF, ISIS)
- tell neighbours about all the links you are connected to
- eventually all routers know about all links, and have a link-state
  database (matrix of metrics) [diagram]
- each router runs Dijkstra's Shortest Path algorithm to work out the
  optimal path to all destinations, and records the next hop

External Routing (BGP - RFC1771)
- chooses routes acording to policy
- policies can be economic (only send routes to people who pay me),
  political (only send routes to universities), or technical (send this
  group of routes to an AS, since we're closest to them)

Addressing
- reduce routing information exchanged over network
  -> reduce prefixes
- increase stability of routing tables
  -> more nets per prefix
- reduce size of routing tables maintained on router
  -> reduce prefixes
- reduce computation required for routing protocols
  -> reduce prefixes
- conserve the address space (more artificial)
  -> appropriately sized prefixes

--> reduce the number of prefixes

Hierarchical addressing
- the Internet is (mostly) hierarchical:
  national ISPs -> national POPs/regionals -> customers -> customers subnets
- assign addresses hierarchically!
- it's what you and the post office do:
  USA, Cambridge, Massachusetts Avenue, 77
- if someone asks you where a specific address is, you can always give them
  a general direction

What's all this Class A, B, and C business I always here about?
  - a bad idea
  - a way of encoding netmask/subnet information into the address
  - problems: inefficient allocation of address space, more routing load
  - almost gone
