Overview of network layer
Transport segments from sending to receiving host
- On sending side encapsulate segments into datagrams
- On receiving side, delivers segment to transport layer
Difference with network and the rest is that this protocol is the core of the internet
Every single component in the network has this layer
- Router examines header fields in all IP datagrams passing though it
Two key network layer
Forwarding:
Moves packets from router input to appropriate router output
e.g Process of getting though single interchange
Routing:
Determine route taken by packets from source to destination
Determine route taken by packets from source to destination
This is for a single router to determine where to go
It will look at the packet header, extract the ip address
Through the forwarding table, it tries to match the ip address with the destination to see which output link to output to
It is determine by the routing algorithm inside the router
The routing algo determines the value in the routing table
e.g process of planning trip from source to destination
Data plane
- Local, per router function
- Determines how datagram arriving on router input port is forward to router output port
- Forwarding function
Control Plane
- Network wide logic
- Determines how datagram is routed among routers along end to end path from source host to destination host
- To control plane:
Traditional (In routers) or software defined networking (Remote server)
<Insert 9>
Network layer have different protocols, there are different type of routing protocols
This is use to determine the content of the forwarding table
The single IP protocol is the most important
IP protocol
- Addressing convention
- Datagram format
- Packet handling convention
IP: Internet protocol
IP address: 32 bit identifier for host, router interface
e.g 233.1.1.1
Interface: Connection between host/router and physical link
The ip address is associated with the interface
- Router typically have multiple interfaces
- Hosts has one or two interface (Ethernet or wireless 802.11)
IPaddress associated with each interface not with a host
A host can have multiple interfaces
Q How are these interfaces actually connected?
A: Wired ethernet interfaces connected by ethernet switches
This is for local internet
A: Wireless WIFI interfaces
//DO not need to worry about how are they connected
Subnets
Subnet is a network formed by a group of directly connected hosts
- Hosts in the same subnet can physically reach each other without intervening router
(Physically: Communication between the interfaces does not need a router)
- They can connect to the outside world through a router
- Hosts in the same subnet must have the same network prefix of IP address (the left most bits)
To determine the subnets, detach each interface from its host or router, creating island of isolated networks.
CIDR (Classless interdomain Routing)
<SLide 15>
Ip address comprises of two parts
- Network subnet prefix
- Host ID
Address format: a.b.c.d/x where x is the number of bits in subnet/network portion of address
The routers if they want to route to the host, they only need the first x bits to be able to forward.
The network inside this network will be able to use the host part to identify the host needed to forward.
This helps reduces the number of contents in the routing list.
Subnet mask
Is made by setting all network prefix bits to 1 and host ID bits to 0s
e.g For IP address 200.23.16.42/23
<| Host |>
11001000 00010111 00010000 00101010
11111111 11111111 11111110 00000000 <= subnet mask
Q: How does ISP gets block of address
A: ICANN (Internet corporation for assigned Names and Numbers)
- Allocates address
- Manages DNS
- Assigns domains names, resolves disputes
<SLide 18 special IP address>
Q: How does an organisation obtain a block of IP address
A: Buy from registry or rent from ISP address space
Hierarchical Address: Route aggregation
Each ISP controls a block of IP addresses
Allows efficient advertisment of routing infomation
Within organisation
The ISP can differentiate which orgnaisation to forward their packet to
<Slide 20>
They use bit by bit to identify which network to forward
What is they want to change one block to another from ISP 1 to ISP2
Under the current internet, ISP 2 will simply add one more entry to the neighbouring routers and update the x.
This is called Longest prefix matching.
It advertises to nearby routers the block of ip address it is handling.
Nearby routers will then route to them instead
The entries must match up to x bits starting from the left.
This will let it determine which is the next hop
Q: How does a host get a IP address
- Hard coded by system admin in a file
Windows: control-panel>network> configuration > tcp/ip >properties
Unix: /etc/rc.config
- DHCP
DHCP: Dynamic Host Configuration Protocol
Dynamically get address from as server
"Plug and Play"
Goal: Allow host to obtain IP address when it joins a network
- Can renew its lease on address in use
- Allow reuse of address (only holds address while connected)
- Support for mobile users who want to join network
DHCP runs using UDP
= DHCP server port number: 67
= DHCP client port number: 68
It does not need to be reliable
DHCP can return:
- Address of first hop router for client
- Address of first hop router for client
- Name and ipaddress of server
We can use one DHCP server to serve multiple subnets.
These request can be forwarded through the routers.
1. Arriving client construct a new DHCP message
- special IP thats all 0
Destination: 255.255.255.255 (Broadcast)
yiaddr: 0.0.0.0 This field will be filled by servers
Trans ID: For client to differentiates the reply from other clients and its server
2. DHCP offer
If its within the subnet, it is easy.
But if it is in another subnet, the broadcast message have to be broadcast to a router which will then relay the message to another subnet
The DHCP will make the allocation
- Echos the ID
- Life time
- Assigns a address (But it is not used yet)
- Srcs (Its server address)
Server will broadcast it back
3. Receiving the message
Check if the Trans ID is mine, else drop
- Make a formal request to the DHCP server
But there might be multiple DHCP server, might get multiple offers,
Client choose one and echo back to that DHCP server
- New trans ID
- Source IP still 0
4. DHCP ACK
Confirms by sending an ack back
Confirms by sending an ack back
- Echo the yiaddr back
- The first two times might be optional
- The client does not know the existence of a dhcp server
- The client can skip step 1 and jump to 2 if it already knows where to get the request from
(returning)
IPV4
Network layer services
- Network layer delivers packets to receiving host
- router examine header fields of IP datagrams passing it
- Use of many protocols
Datagram format
The socket is represented by a set of API. The transport layer add a header which include the destination and src port. In the network layer, the ip address will be added to the header.
IP header is 20 bytes and has 5 rows in total.
Fields:
- IP protocol version number (IPV4)
- IP protocol version number (IPV4)
- IP datagram length - the length of the entire packet including the header
- Headerchecksum - only for header
- Source IP address - sending host
- Destin IP - receiving host
- upper layer protocol - udp/tcp
-ttl - Time to live (Specified by the sender)
Each router decrease the TTL as it received it.
This is to ensure that the packet will not circulate the network forever.
- Flags/Frag offset - IP fragmentation
Fragmentation
- Packet might pass through different routers before reaching destination and different links may have different MTU (Max transfer Unit) - The maximum size of the ip packet that the link level frame can carry
- To large IP datagrams will be fragmented by routers
- Fragmented packets will be reassembled by destination host
when all fragmented packets are received. It needs to know
- How to reassembled
- How many packets are there
- The order
- What is the length
- Each Fragmented packet will have its own header (20byte),
- length of packet
- ID (Same for all fragments)
- Flag to state how many trailing packets are there (0 if its the last)
- offset (show the relative order of the packets from the first packet in units of 8 bytes)
We only have 13 bits for offset thus we have to represent in 8 bytes in order to be able to
Network address translation
Recap
- 32 bits -> a.b.c.d/x (where x is the prefix and a,b,c,d are 8 bits each)
- Subnets -> A set of directly connected host
- Addressing -> CIDR (A fix subnets with the use of prefix)
- Getting IP address -> Get a block from ICANN/IANA; get from ISP; DHCP
- Hierarchical addressing -> Longest prefix matching
Router - Function as an DHCP server and a client
DHCP server: To our home devices
DHCP client : To the ISP provider
Non unique IP address is not routable
LAN
- Local area network
e.g school network
WAN
- Public IP
- Public IP
Implementation
- Replace the source Ip and port of every outgoing datagram to (Nat IP and new port)
- Remember the mapping of the source ip to port number of NAT Ip and new port
- Remember the mapping of the source ip to port number of NAT Ip and new port
- Replace in destination fields of every incoming datagram with corresponding source IP and port number stored in NAT translation table
Sending a packet to a server in WAN from LAN
Translation
1. The router will replace the IP of the received packet with the public IP (Usually the IP of the NAT router).
2, Translate the port number to another port number
3. Sends the packet to the outside server
- All datagrams leaving the local network will have the same source NAT ip address
- There cannot be a collision of port number within the LAN
Receiving a packet from WAN to a host in LAN
Translation
1. Reverse translation
2. Send to the original host
Motivation and Benefits
- Do not need a range of public ip address from IP, just one public for NAT router
- All host use private IP address, can change address of host in the local network without notifying the outside word
- Change ISP without changing addresses of host in local network
- Host inside the local network are not explicitly addressable and visible by outside world (security plus)
Challengers
- Peer to peer does not work directly
The receiving Nat device does not have the information of the peer it suppose to send to in its LAN
- This can be countered by using a 3rd party
Routing Algorithms
The internet is a networks of networks, there is no single organisation that own every single router
THus routing is done hierachyally
AS - Automonous system
Routing in the internet
Intra- AS routing
- Finds a good path between two routers within an AS
- Commonly use protocols: RIP, OSPF
- Single admin, no policy decisions are neeeded
- Routing focus on performance
Inter-AS routing (Not covered)
- Handles the interfaces between ASs
- The standard protocol: BGP
- different admin to control traffic and who routes
- Policy may dominate over performance
Abstract view of Intra AS routing
- Graph
- Vertices: routers
- Edges: Physical links
Routing algo classification (Not tested)
- All routers have the complete knowledge of network topology and link cost
- Periodically send link cost
Distance Vector algorithms
- Router know physically connected neighbours and link cost to neighbours
- Router exchange 'local views' with neighbours and update own 'local views' (based on neighbor' view)
- Iteraative process of computation
- Swap local view with direct neighbours
- Update own local view
- Repeat till no more change to local view
KEY POINT: It will only contact neighbours and not indirect neighbours
Pros: Will not be overflooded
Cons: Longer
c(x,y) is the cost of link between routers x and y
- =infinite if x and y are not direct neighbours
dx(y): the cost of the least cost path from x to y from x's view
Bellman ford equation
dx(y) = minv{c(x,v) + dv(y)}
where the min is taken over all direct neighbours of v of x
Refer to CS2040 > Graph Theory
- Every router send it distance vector to its directly connected neighbor
- x finds out that y is advertising
- Update its distance to z accordingly
- Not down that all packets for z should be sent to y, This info will be use to create forwarding table of the router x
- After every router exchange several rounds of update with its direct neighbours, all router will know the least cost path to all the other router.
RIP
Routing information protocol implements the DV algorithms. It use hop count as the cost metric and is insensitive to network congestion
ICMP
Internet control message protocol is use by host
ICMP type and Code
Ping and traceroute:
The command ping sees if a remote host will respond -> is there a connection
The command ping sees if a remote host will respond -> is there a connection
The command traceroute sends a series of small packets across a network and attempts to display the route that the message will take to get to a remote host.
Traceroute will show all the path, it sends the packet using ttl incremementally since the router have to forward back its own ip address if ttl reaches 0.
ICMP is use to send error message and to trouble shoot networks.