Routing
Network Layer
Network Layer: Delivery, Forwarding, and Routing
●   Delivery refers to the way a packet is handled by the underlying networks under the
    control of the network layer.
●   Forwarding refers to the way a packet is delivered to the next station.
●   Routing refers to the way routing tables are created to help in forwarding.
     ○ Routing protocols are used to continuously update the routing tables that are
        consulted for forwarding and routing.
Delivery
     Direct Delivery
 ●   Final destination of the packet is a host connected to the same physical network as the deliverer.
 ●   Direct delivery occurs when the source and destination of the packet are located on the same
     physical network or when the delivery is between the last router and the destination host.
     Indirect Delivery
 ●   If the destination host is not on the same network as the deliverer, the packet is delivered
     indirectly.
 ●   In an indirect delivery, the packet goes from router to router until it reaches the one connected to
     the same physical network as its final destination.
     NOTE:
 ●   A delivery always involves one direct delivery but zero or more indirect deliveries.
 ●   The last delivery is always a direct delivery.
Forwarding
● Forwarding means to place the packet in its route to its destination.
● Forwarding requires a host or a router to have a routing table.
● When a host has a packet to send or when a router has received a packet to be
  forwarded, it looks at this table to find the route to the final destination.
Forwarding Techniques
Next-Hop Method Versus Route Method
 ●   In this technique, the routing table holds only the address of the next hop instead of
     information about the complete route (route method).
Network-Specific Method Versus Host-Specific Method
 ●   Instead of having an entry for every destination host connected to the same physical
     network (host-specific method), we have only one entry that defines the address of
     the destination network itself.
 ●   In other words, we treat all hosts connected to the same network as one single entity.
Routing Table
 ●   A host or a router has a routing table with an entry for each destination, or a combination of destinations, to
     route IP packets.
 ●   A static routing table contains information entered manually. The administrator enters the route for each
     destination into the table.
 ●   A dynamic routing table is updated periodically by using one of the dynamic routing protocols such as RIP,
     OSPF, or BGP.
UNICAST ROUTING PROTOCOLS
 ●   Routing protocols have been created in response to the demand for dynamic routing tables.
 ●   A routing protocol is a combination of rules and procedures that lets routers in the internet
     inform each other of changes.
Optimization
 ● A router receives a packet from a network and passes it to another network.
 ●   When it receives a packet, to which network should it pass the packet?
The decision is based on optimization:
 ● Which of the available pathways is the optimum pathway?
 ● What is the definition of the term optimum?
Intra- and Interdomain Routing
Autonomous systems
●   An autonomous system (AS) is a group of networks and routers under the authority of a
    single administration.
●   Routing inside an autonomous system is referred to as intradomain routing.
●   Routing between autonomous systems is referred to as interdomain routing.
●   Each autonomous system can choose one or more intradomain routing protocols to handle
    routing inside the autonomous system.
●   However, only one interdomain routing protocol handles routing between autonomous
    systems
Distance Vector Routing
the least-cost route between any two nodes is the route with minimum distance.
each node maintains a vector (table) of minimum distances to every node.
The table at each node also guides the packets to the desired node by showing the next stop in the route (next-hop
routing).
●   The table for node A shows how we can reach any node from this node. For e.g., our least cost to reach node E is
    6. The route passes through C.
Initialization
●   At the beginning, each node can know only the distance between itself and its
    immediate neighbors, those directly connected to it.
●   So for the moment, we assume that each node can send a message to the immediate
    neighbors and find the distance between itself and these neighbors.
●   The distance for any entry that is not a neighbor is marked as infinite (unreachable).
Initialization of tables in distance vector routing
Sharing
●   Idea of distance vector routing is the sharing of information between neighbors.
●   In the previous example, although node A does not know about node E, node C does.
    So if node C shares its routing table with A, node A can also know how to reach node
    E.
●   In other words, immediate neighbors, can improve their routing tables if they help
    each other.
How much of the table must be shared with each neighbor?
 ●   In distance vector routing, each node shares its routing table with its immediate neighbors periodically and
     when there is a change.
 ●   Periodic Update: A node sends its routing table, normally every 30s, in a periodic update. The period depends
     on the protocol that is using distance vector routing.
 ●   Triggered Update: A node sends its two-column routing table to its neighbors anytime there is a change in its
     routing table. This is called a triggered update. The change can result from the following.
      ○    A node receives a table from a neighbor, resulting in changes in its own table after updating.
      ○    A node detects some failure in the neighboring links which results in a distance change to infinity.
Updating
When a node receives a two-column table from a neighbor, it needs to update its routing
table. Updating takes three steps:
1.   The receiving node needs to add the cost between itself and the sending node to each
     value in the second column. The logic is clear. If node C claims that its distance to a
     destination is x, and the distance between A and C is y, then the distance between A
     and that destination, via C, is x + y.
2.   The receiving node needs to add the name of the sending node to each row as the
     third column if the receiving node uses information from any row. The sending node
     is the next node in the route.
Updating
3. The receiving node needs to compare each row of its old table with the corresponding
row of the modified version of the received table.
     a. If the next-node entry is different, the receiving node chooses the row with the
          smaller cost. If there is a tie, the old one is kept.
     b. If the next-node entry is the same, the receiving node chooses the new row. For
          example, suppose node C has previously advertised a route to node X with
          distance 3. Suppose that now there is no path between C and X; node C now
          advertises this route with a distance of infinity. Node A must not ignore this
          value even though its old entry is smaller. The old route does not exist any more.
          The new route has a distance of infinity.
Node A updates its routing table after receiving the partial table from node C.
Two-Node Loop Instability
 ●   At the beginning, both nodes A and B know how to reach node X.
 ●   But suddenly, the link between A and X fails. Node A changes its table.
 ●   If A can send its table to B immediately, everything is fine.
 ●   However, the system becomes unstable if B sends its routing table to A before receiving A's routing table.
 ●   Node A receives the update and, assuming that B has found a way to reach X, immediately updates its routing
     table.
 ●   Based on the triggered update strategy, A sends its new update to B.
 ●   Now B thinks that something has been changed around A and updates its routing table.
 ●   The cost of reaching X increases gradually until it reaches infinity. At this moment, both A and B know that X
     cannot be reached. However, during this time the system is not stable.
Overcoming Two-Node Loop Instability
 ●   Defining Infinity:The first obvious solution is to redefine infinity to a smaller number, such as
     100.
 ●   Split Horizon: In this strategy, instead of flooding the table through each interface, each node
     sends only part of its table through each interface. If, according to its table, node B thinks that
     the optimum route to reach X is via A, it does not need to advertise this piece of information to
     A; the information has corne from A (A already knows). Taking information from node A,
     modifying it, and sending it back to node A creates the confusion.
 ●   Split Horizon and Poison Reverse: Normally, the distance vector protocol uses a timer, and if
     there is no news about a route, the node deletes the route from its table. When node B in the
     previous scenario eliminates the route to X from its advertisement to A, node A cannot guess that
     this is due to the split horizon strategy (the source of information was A) or because B has not
     received any news about X recently. The split horizon strategy can be combined with the poison
     reverse strategy. Node B can still advertise the value for X, but if the source of information is A,
     it can replace the distance with infinity as a warning: "Do not use this value; what I know about
     this route comes from you."
Three-Node Instability
Routing Information Protocol (RIP)
 ●   Intradomain routing protocol used inside an autonomous system.
 ●   Simple protocol based on distance vector routing.
      1.   In an autonomous system, we are dealing with routers and networks (links). The routers have routing
           tables; networks do not.
      2.   The destination in a routing table is a network, which means the first column defines a network address.
      3.   The metric used by RIP is very simple; the distance is defined as the number of links (networks) to
           reach the destination. For this reason, the metric in RIP is called a hop count.
      4.   Infinity is defined as 16, which means that any route in an autonomous system using RIP cannot have
           more than 15 hops.
      5.   The next-node column defines the address of the router to which the packet is to be sent to reach its
           destination.
Link State Routing
 ●   Each node in the domain has the entire topology of the domain.
      ○   the list of nodes and links, how they are connected including the type, cost (metric), and
          condition of the links (up or down)-the node can use Dijkstra's algorithm to build a routing
          table.
 ●   Each node uses the same topology to create a routing table, but the routing table for each node is
     unique because the calculations are based on different interpretations of the topology.
 ●   The topology must be dynamic, representing the latest state of each node and each link. If there
     are changes in any point in the network (a link is down, for example), the topology must be
     updated for each node.
Concept of link state routing
Link state knowledge
Building Routing Tables
In link state routing, four sets of actions are required to ensure that each node has the
routing table showing the least-cost node to every other node.
1.   Creation of the states of the links by each node, called the link state packet (LSP).
2.   Dissemination of LSPs to every other router, called flooding, in an efficient and
     reliable way.
3.   Formation of a shortest path tree for each node.
4.   Calculation of a routing table based on the shortest path tree.
Creation of Link State Packet (LSP)
●   A link state packet can carry a large amount of information like the node identity, the
    list of links, a sequence number, and age.
●   The node identity and the list of links are needed to make the topology.
●   The sequence number facilitates flooding and distinguishes new LSPs from old ones.
●    The age prevents old LSPs from remaining in the domain for a long time.
LSPs are generated on two occasions:
 ●   When there is a change in the topology of the domain.
 ●   On a periodic basis.
Flooding of LSPs
1.   The creating node sends a copy of the LSP out of each interface.
2.   A node that receives an LSP compares it with the copy it may already have.
3.   If the newly arrived LSP is older than the one it has (found by checking the sequence number), it
     discards the LSP. If it is newer, the node does the following:
      a.   It discards the old LSP and keeps the new one.
     b.    It sends a copy of it out of each interface except the one from which the packet arrived.
           This guarantees that flooding stops somewhere in the domain (where a node has only one
           interface).
Formation of Shortest Path Tree: Dijkstra Algorithm
Calculation of Routing Table from Shortest Path Tree
 ●   Each node uses the shortest path tree protocol to construct its routing table.
 ●   The routing table shows the cost of reaching each node from the root.
                          Routing table for node A
Open Shortest Path First (OSPF)
 ●   Intradomain routing protocol based on link state routing. Its domain is also an autonomous system.
 ●   OSPF divides an autonomous system into areas. An area is a collection of networks, hosts, and routers all
     contained within an autonomous system.
 ●   At the border of an area, special routers called area border routers summarize the information about the area
     and send it to other areas.
 ●   Among the areas inside an autonomous system is a special area called the backbone; all the areas inside an
     autonomous system must be connected to the backbone.
 ●   Each area has an area identification. The area identification of the backbone is zero.
Metric
●   The OSPF protocol allows the administrator to assign a cost, called the metric, to each
    route.
●   The metric can be based on a type of service (minimum delay, maximum throughput, and
    so on).
Types of Links
 ●   In OSPF terminology, a connection is called a link.
 ●   Four types of links have been defined: point-to-point, transient, stub, and virtual
 ●   A point-to-point link connects two routers without any other host or router in between.
 ●   A transient link is a network with several routers attached to it. The data can enter through any of the routers
     and leave through any router.
 ●   A stub link is a network that is connected to only one router. The data packets enter the network through this
     single router and leave the network through this same router.
 ●   When the link between two routers is broken, the administration may create a virtual link between them,
     using a longer path that probably goes through several routers.
Path Vector Routing
 ●   Distance vector and link state routing are both intradomain routing protocols. They can be used inside
     an autonomous system, but not between autonomous systems.
 ●   Path vector routing proved to be useful for interdomain routing. In path vector routing, we assume that
     there is at least one node in each autonomous system, called the speaker node that acts on behalf of
     the entire autonomous system.
 ●   The speaker node in an AS creates a routing table and advertises it to speaker nodes in the neighboring
     ASs.
 ●   Only speaker nodes in each AS can communicate with each other.
 ●   A speaker node advertises the path, not the metric of the nodes, in its autonomous system or other
     autonomous systems.
Initialization
 ●   At the beginning, each speaker node can know only the reachability of nodes inside its autonomous system.
Sharing
 ●   Just as in distance vector routing, in path vector routing, a speaker in an autonomous system shares its table
     with immediate neighbors.
 ●   In the previous example, Node Al shares its table with nodes Bl and Cl. Node Cl shares its table with nodes
     Dl, Bl, andAl. Node Bl shares its table with Cl andAl. Node Dl shares its table with Cl.
Updating
When a speaker node receives a two-column table from a neighbor, it updates its own table by adding the nodes that
are not in its routing table and adding its own autonomous system and the autonomous system that sent the table.
Loop prevention. When a router receives a message, it checks to see if its autonomous system is in the path list to
the destination. If it is, looping is involved and the message is ignored.
Policy routing. When a router receives a message, it can check the path. If one of the autonomous systems listed in
the path is against its policy, it can ignore that path and that destination. It does not update its routing table with this
path, and it does not send this message to its neighbors.
Optimum path. We are looking for a path to a destination that is the best for the organization that runs the
autonomous system.
Border Gateway Protocol (BGP)
 ●   Border Gateway Protocol (BGP) is an interdomain routing protocol using path vector routing.
Types of Autonomous Systems
 ●   We can divide autonomous systems into three categories: stub, multihomed, and transit.
      ○   Stub AS: A stub AS has only one connection to another AS.
      ○   Multihomed AS: A multihomed AS has more than one connection to other ASs, but it is still
          only a source or sink for data traffic.
      ○   Transit AS: A transit AS is a multihomed AS that also allows transient traffic.
Path Attributes
 ●   The path is presented as a list of autonomous systems, but is, in fact, a list of attributes.
 ●   Each attribute gives some information about the path. The list of attributes helps the receiving router
     make a more-informed decision when applying its policy.
 ●   Attributes are divided into two broad categories: well known and optional.
      ○    A well- known attribute is one that every BGP router must recognize.
      ○    An optional attribute is one that needs not be recognized by every router.
●   Well-known attributes are themselves divided into two categories: mandatory and discretionary.
     ○   A well-known mandatory attribute is one that must appear in the description of a route.
     ○   A well-known discretionary attribute is one that must be recognized by each router, but is
         not required to be included in every update message. One well- known mandatory attribute
         is ORIGIN.
●   The optional attributes can also be subdivided into two categories: transitive and non-transitive.
     ○   An optional transitive attribute is one that must be passed to the next router by the router
         that has not implemented this attribute.
     ○   An optional non-transitive attribute is one that must be discarded if the receiving router
         has not implemented it.
BGP Sessions
●   The exchange of routing information between two routers using BGP takes place in a
    session.
●   A session is a connection that is established between two BGP routers only for the sake of
    exchanging routing information.
●   To create a reliable environment, BGP uses the services of TCP.
External and Internal BGP
●   BGP can have two types of sessions: external BGP (E-BGP) and internal BGP
    (I-BGP) sessions.
●   The E-BGP session is used to exchange information between two speaker nodes
    belonging to two different autonomous systems.
●   The I-BGP session, on the other hand, is used to exchange routing information
    between two routers inside an autonomous system.
●   The session established between AS1 and AS2 is an E-BGP session. The two speaker routers exchange
    information they know about networks in the Internet.
●   However, these two routers need to collect information from other routers in the autonomous systems. This is
    done using I-BOP sessions.