Sie sind auf Seite 1von 11

Open Shortest Path First

Posted on 8/31/2011 in: Networking 12345 Please rate the blog post.

The need for a dynamic routing protocol

As you probably know, in order for a Router to be able to forward the packets to the network, it must know how to reach that network. The information how to reach a network is stored in a router's routing table. If the router doesn't have a network in it's routing table it simply discards the packet. Dynamic routing protocols enable the routers to LEARN about the networks from other Routers and then store those routes to their routing tables. For a better understanding of basic routing concepts visit my previous blog post: Introduction to Routing.

What is OSPF?
OSPF is probably the most used interior gateway protocol, because unlike EIGRP it isn't vendor - proprietary. OSPF has support for Variable Length Subnet Masks (VLSM). OSPF is designed to operate inside an autonomous system. OSPF doesn't advertise routes as distance/cost vectors like RIP or EIGRP for example, but instead it advertises states of interfaces and links. OSPF stores the link-state information in the Link State Database (LSDB). OSPF uses the Shortest Path First algorithm to populate the routing table.

How does OSPF work?

As we already stated, OSPF is designed to operate inside an autonomous system. OSPF has the concept of "areas", meaning our network can be divided into routing areas. Dividing the network into areas simplifies network maintenance and saves the resources, because the networks in an area can be summarized. There's a backbone area in OSPF network (area 0) and all the areas must connect to it. For now, we'll stick to one area, and later we'll get into multiple-areas OSPF design. Like EIGRP OSPF has the concept of "neighbors". OSPF establishes neighbor relationships in order to exchange routing information. There are different types of neighborships called

adjacencies. As EIGRP, in OSPF routers exchange Hello messages to become adjacent. OSPF routers become fully adjacent only with routers that are directly connected to the local router. Depending on the type of network Routers elect a DR (Designated Router) and a BDR (Backup Designated Router). Designated Router reduces the need for network resources. The role of DR is to maintain the topology table of an entire network. Designated Router basically sends updates to other routers. This way all routers get their updates from a single source. It basically comes down to: 1. Router sends update to DR using multicast. 2. DR sends multicast updates to all other routers in the area. BDR is just that - a Backup Designated Router. It listens to all the network updates, but it doesn't update others. The moment DR goes down, BDR takes it's place. If that happens, another BDR is elected.

Just how are the DR/BDR elected?

Contrary to the popular belief, a DR/BDR is actually a Router Interface, and not an entire Router. DR is elected during the election process. Basically election process goes through the following steps:

The Router with the highest OSPF priority. By default all routers have an OSPF interface priority of 1. If there's a Interface that has a higher priority than other it will win the election. If all the interfaces have the same priority, DR is elected based on highest Router ID among all the participating routers.

Router ID is obtained in the following way: 1. It can be configured manually. If it's configured manually router uses the configured value as Router ID. If it isn't configured manually router calculates it's own Router ID. 2. If there are Loopback interfaces, the highest IP address assigned to any Loopback interface of the router becomes Router ID. 3. If there aren't any Loopback interfaces, Router ID is the highest IP address of ANY active interface. There are a couple of things worth remembering when talking about the OSPF election process. First of all, if Router interface is configured with an priority of 0, it can NEVER become DR or BDR. It simply doesn't participate in the election process. Second of all, if the Router with the higher priority has joined the network AFTER the election is over, it won't have any impact. The DRs/BDRs remain the same. It can't become a DR or BDR until they both fail.

Which OSPF route is used?

There are different types of OSPF routes, each with it's own Administrative Distance.

Intra-area route is a route for a network that's inside the same area as the local router. For now this is really the only type you need to know, because we'll deal with a single-area OSPF first. But, for the sake of completeness, let's list other types as well.

Inter-Area route is a route that goes beyond an Area Border Router (Router that connects two OSPF areas).

External route is a route that has been redistributed into OSPF from another routing protocol. It originates from an ASBR. (Autonomous System Border Router). The difference between External Type 1 and External Type 2 is how the cost is calculated. 1. External Type 1 This is the cost of an external route as advertised plus the internal cost to reach the ASBR. 2. External Type 2 This is simply an external cost, it doesn't take into account the cost to reach the ASBR. Because the External Type 1 is more precise, it's preferred over External Type 2.

NOTE: We'll get into the details of what is ABR and what is ASBR in some other blog post.

OSPF cost
As with all routing protocols, OSPF calculates the cost of reaching a network. By default cost is calculated via a formula: cost = 108 / bandwidth. However, the cost can only be compared in the same types of routes. I think by now, you have a basic understanding of OSPF, enough for a simple configuration example. For first post about OSPF, let's configure a single-area OSPF, and we'll leave multi area OSPF and stubby areas for a future blog post.

Single-area OSPF

The configuration will be simple, just how to enable OSPF and advertise networks so that every point inside our network can be pinged. After that we'll configure a Loopback interface to simulate ISP connection and advertise that route through our network. As always, routers will play the part of the hosts. First, let's configure them with addresses and default routes: ? 1HOST1>en 2HOST1#conf t 3Enter configuration commands, one per line. End with CNTL/Z. 4HOST1(config)#int f0 5HOST1(config-if)#ip address HOST1(config-if)#no shut 6 And default route: ? 1HOST1(config-if)#ip route And now for HOST2: ? 1HOST2(config-if)#ip add

2HOST2(config-if)#no shut 3*Mar 1 00:01:02.527: %LINK-3-UPDOWN: Interface FastEthernet0, changed state to up 4*Mar 1 00:01:03.527: %LINEPROTO-5-UPDOWN: Line protocol on Interface 5FastEthernet0, changed state to up
HOST2(config-if)#ip route

Next, let's configure R1's interfaces: ? 1 2 R1(config)#int f2/0 R1(config-if)#ip add 3 R1(config-if)#no shutdown 4 5 R1(config-if)#int f1/0 6 R1(config-if)#ip add 7 R1(config-if)#no shut 8 serial 0/0 9 R1(config-if)#intadd R1(config-if)#ip 10R1(config-if)#no shut 11 Now, let's configure OSPF on R1. NOTE that when configuring OSPF on a Router we need to configure Process ID. This is only locally important, so we can enter any number. We can even use the same OSPF process-id on multiple routers. This is used to differentiate multiple OSPF processes on a single router. Also, for this Router, let's manually configure Router ID: ? 1 2 R1(config)#router ospf ? <1-65535> Process ID 3 4 R1(config)#router ospf 100 5 R1(config-router)#router-id ? A.B.C.D OSPF router-id in IP address format 6 7 8 R1(config-router)#router-id area 9 R1(config-router)#network area 0 0 R1(config-router)#network 10R1(config-router)#network area 0 11 Now, let's configure R2, so that R1 can learn about the network, and R2 about the network, meaning the hosts will be able to communicate. First, let's configure interfaces:

? 1 2 R2(config)#int f2/0 3 R2(config-if)#ip address R2(config-if)#no shutdown 4 R2(config-if)# 5 R2(config-if)#int fast 1/0 6 R2(config-if)#ip add 7 R2(config-if)#no shut 8 R2(config-if)# R2(config-if)#int s0/0 9 R2(config-if)#ip add 10R2(config-if)#no shut 11 This time, we'll use the IP address of an Loopback Interface for OSPF Router ID. So, let's now just configure the Loopback interface: ? 1R2(config-if)#interface loopback 0 2R2(config-if)# *Mar 1 00:05:51.363: %LINEPROTO-5-UPDOWN: Line protocol on Interface 3Loopback0, changed state to up 4R2(config-if)#ip address And now for OSPF: ? 1R2(config)#router ospf 202 2R2(config-router)#network area 0 3R2(config-router)#network area 0 R2(config-router)#network area 0 4R2(config-router)# 5*Mar 1 00:07:46.367: %OSPF-5-ADJCHG: Process 202, Nbr on Serial0/0 6from LOADING to FULL, Loading Done See that? We got the message stating there's new adjacency, meaning R1 and R2 are now neighbors. Also, each R2 should have some routes from R1. Let's verify the neighborship and routing table: ? 1 R2#show ip ospf neighbor 2 3Neighbor ID Pri State Dead Time Address 0 FULL/ 00:00:38 5R2# 6R2#show ip route ospf is subnetted, 3 subnets 7 O [110/65] via, 00:02:20, Serial0/0 8O [110/65] via, 00:02:20, Serial0/0 9

Interface Serial0/0

OK, let's try to ping HOST1 from HOST2: ? 1HOST2>ping 2 3Type escape sequence to abort. 4Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds: 5!!!!! 6Success rate is 100 percent (5/5), round-trip min/avg/max = 568/1260/1988 ms As you can see, we already have connectivity. But now, let's just complicate things a bit and include R3 into our little network. First, let's configure the interfaces. ? 1R3(config)#int f0/0 2R3(config-if)#ip add 3R3(config-if)#no shut 4 5R3(config-if)#int f1/0 6R3(config-if)#ip add R3(config-if)#no shutdown 7 OK, now for OSPF on R3. This time, we won't configure Router ID, or Loopback Interface and the highest IP address will be chosen as a Router ID. ? 1R3(config)#router ospf 300 R3(config-router)#network area 0 2R3(config-router)# 3*Mar 1 00:10:48.491: %OSPF-5-ADJCHG: Process 300, Nbr on 4FastEthernet1/0 from LOADING to FULL, Loading Done 5R3(config-router)#network area 0 6R3(config-router)# *Mar 1 00:11:08.647: %OSPF-5-ADJCHG: Process 300, Nbr on 7FastEthernet0/0 from LOADING to FULL, Loading Done Now, let's verify the Router ID: ? 1R3#show ip ospf 300 2 Routing Process "ospf 300" with ID 3 4!!!! OUTPUT OMITTED !!!!!!!!!!!!!!!!!!!!!!!!!!! NOTE that because R3 joined the network later after the DR has been chosen it isn't a DR even if it has the highest Router ID. ?

1 R3#sh ip ospf int fa0/0 2FastEthernet0/0 is up, line protocol is up 3 Internet Address, Area 0 4 Process ID 300, Router ID, Network Type BROADCAST, Cost: 1 5 Transmit Delay is 1 sec, State BDR, Priority 1 Designated Router (ID), Interface address 6 7!!!! OUTPUT OMITTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 8 So, how can there be an election if R3 didn't even participate? Simple. When the Interface is enabled in OSPF, the router starts sending Hellos. If it doesn't find a neighbor it simply elects itself as a DR, just as R1 did. We can even verify that: ? 1 2 R1#debug ip ospf adj 3 OSPF adjacency events 4 R1# 5 *Mar 1 00:01:09.731: 6 *Mar 1 00:01:09.731: *Mar 1 00:01:09.735: 7 *Mar 1 00:01:09.735: 8 *Mar 1 00:01:09.739: 9 *Mar 1 00:01:09.739: 10*Mar 1 00:01:09.743: 11*Mar 1 00:01:09.747: *Mar 1 00:01:09.747: 12*Mar 1 00:01:09.751: 13*Mar 1 00:01:09.751: 14*Mar 1 00:01:09.755: 15R1# 16*Mar 1 00:01:09.755: *Mar 1 00:01:09.759: 17 18

debugging is on OSPF: OSPF: OSPF: OSPF: OSPF: OSPF: OSPF: OSPF: OSPF: OSPF: OSPF: end of Wait on interface FastEthernet1/0 DR/BDR election on FastEthernet1/0 Elect BDR Elect DR Elect BDR Elect DR DR: (Id) BDR: none end of Wait on interface FastEthernet2/0 DR/BDR election on FastEthernet2/0 Elect BDR Elect DR Elect BDR BDR: none

OSPF: Elect DR DR: (Id)

Let's try and disconnect the link between R2 and R3 and see what happens. Simply right-click on the line that represents the cable and click "Delete". This is what happens: ? 1R2(config-if)# *Mar 1 00:14:29.131: %OSPF-5-ADJCHG: Process 202, Nbr on 2FastEthernet1/0 from FULL to DOWN, Neighbor Down: Dead timer expired Now reconnect them. They become neighbors once again. Now, let see what happened with DR election: ? 1R3#show ip ospf interface fastethernet 0/0 2FastEthernet0/0 is up, line protocol is up

3 Internet Address, Area 0 4 Process ID 300, Router ID, Network Type BROADCAST, Cost: 1 Transmit Delay is 1 sec, State DR, Priority 1 5 6!!!! OUTPUT OMITTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 7 OK, enough DR/BDR stuff, I'm sure you get it. Now, let's see what happened to R1's routes when we configured R3: ? 1R1#sh ip route ospf 2 is subnetted, 3 subnets [110/2] via, 00:00:58, FastEthernet1/0 3O is subnetted, 1 subnets 4 [110/3] via, 00:00:58, FastEthernet1/0 5O So, R1 now reaches network via R3. Only one thing left to do now. Let's configure a Loopback interface on R3 to simulate a connection to the ISP. We'll use OSPF to redistribute the default route through the network. ? 1R3(config)#interface Loopback 1 2R3(config-if)# *Mar 1 00:06:19.607: %LINEPROTO-5-UPDOWN: Line protocol on Interface 3Loopback1, changed state to up 4R3(config-if)#ip address Now, let's create a default route and advertise it with OSPF. It simple, really. We use the default-information originate OSPF subcommand: ? 1R3(config)#ip route Loopback 1 2R3(config)#router ospf 300 3R3(config-router)#default-information originate Now, let's verify that the Routers have the default route. Let's see R2: ? 1 2 3 4 5 6 7 8
R2#sh ip route Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route

9 10Gateway of last resort is to network 11 is subnetted, 1 subnets 12 C is directly connected, Loopback0 13 is subnetted, 3 subnets 14C is directly connected, FastEthernet1/0 [110/2] via, 00:01:14, FastEthernet1/0 15O is directly connected, Serial0/0 16C is subnetted, 1 subnets 17C is directly connected, FastEthernet2/0 18O [110/3] via, 00:01:14, FastEthernet1/0 19O*E2 [110/1] via, 00:01:21, FastEthernet1/0 20 21

Passive Interface
OK, we have finished our configuration. Now, just for one little tip. As we said earlier, router sends Hello messages on OSPF-enabled interfaces. But what if we don't want to send Hellos on some interfaces because, for instance, only hosts are connected to that interface, so sending Hellos to them is pointless? Simple, we'll use the passive-interface OSPF subcommand. Passive interfaces simply don't send OSPF traffic, meaning Hellos won't be send via that Interface.

We don't need to send OSPF traffic via R1's Fast Ethernet 2/0 or R2's Fast Ethernet 2/0 because only hosts are connected to those interfaces. So, let's configure it:

? 1R1(config)#router ospf 100 2R1(config-router)#passive-interface fa2/0 3 4R2(config)#router ospf 202 5R2(config-router)#passive fa2/0 NOTE: OSPF adjacency can't be formed if one of the interfaces is passive! If you configure an interface as passive where an adjacency exists, the adjacency will drop!