Middle device R2 does not receive default route export to ospf protocol from R3, but received the default route export to ospf protocol from R1, customer wants the R2 to receive the default route from both R1 and R3.
Topology: R1 ge-0/0/0------ge-0/0/0 R2 ge-0/0/1------ge-0/0/0 R3There are 2 data centers, one is R1 , the other is R3.R1, R2 and R3 are ospf neighbor.Currently, R1 advertise default route 0.0.0.0/0 and ::/0 via ospf protocol to R2 device.There is a request which needs the R3 to advertise default route 0.0.0.0/0 and ::/0 via ospf protocol to R2 device too.However, after configuring R3 to advertise default route to R2 via ospf protocol, from R2, we can only see the default router is advertised from R1, not receive the default route advertised from R3. Ospf neighbor is established with no issue.Configuration on R3:Set routing-options rib inet6.0 static route ::/0 discardSet routing-options static route 0.0.0.0/0 discardset protocols ospf area 0.0.0.0 interface lo0.0 passiveset protocols ospf area 0.0.0.0 interface ge-0/0/0.0set protocols ospf export defaultrouteset policy-options policy-statement defaultroute term default from route-filter-list default-v4set policy-options policy-statement defaultroute term default then acceptset policy-options route-filter-list default-v4 0.0.0.0/0 exactset protocols ospf3 area 0.0.0.0 interface lo0.0 passiveset protocols ospf3 area 0.0.0.0 interface ge-0/0/0.0set protocols ospf3 export defaultroutev6set policy-options policy-statement defaultroutev6 term default from protocol staticset policy-options policy-statement defaultroutev6 term default from route-filter-list default-v6set policy-options policy-statement defaultroutev6 term default then acceptset policy-options policy-statement defaultroutev6 term implicit-deny then rejectset policy-options route-filter-list default-v6 ::/0 exactlabroot@R3# run show route 0.0.0.0/0inet.0: 13 destinations, 14 routes (13 active, 0 holddown, 0 hidden)+ = Active Route, - = Last Active, * = Both0.0.0.0/0 *[Static/1] 01:06:26 Discard [OSPF/110] 00:12:15, metric 0, tag 0 > to 23.1.1.1 via ge-0/0/0.0labroot@R3# run show route ::/0inet6.0: 13 destinations, 14 routes (13 active, 0 holddown, 0 hidden)+ = Active Route, - = Last Active, * = Both::/0 *[OSPF3/110] 00:24:21, metric 0, tag 0 > to fe80::5604:1eff:fe00:38a2 via ge-0/0/0.0 [Static/255] 00:39:50 Discard
On R3, run the command below to check if ospf neighbor is established and the default route has been advertised to ospf database.
> show ospf neighbor> show ospf databaseWe can see that neighbor is established and in full status , and default route has been advertised to ospf database: labroot@R3# run show ospf neighborAddress Interface State ID Pri Dead12.1.1.1 ge-0/0/0.0 Full 203.119.104.2 128 38 [edit]labroot@R3# run show ospf database OSPF database, Area 0.0.0.0Type ID Adv Rtr Seq Age Opt Cksum LenRouter 203.119.104.2 203.119.104.2 0x80000077 738 0x22 0x5368 60Router *203.119.104.4 203.119.104.4 0x80000078 489 0x22 0x2629 60Router 203.119.104.13 203.119.104.13 0x80000081 490 0x22 0x396 84 OSPF AS SCOPE link state databaseType ID Adv Rtr Seq Age Opt Cksum LenExtern 0.0.0.0 203.119.104.2 0x8000006e 2863 0x22 0x593e 36Extern *0.0.0.0 203.119.104.4 0x8000006e 489 0x22 0x4d48 36 [edit]labroot@R3# run show ospf3 database OSPF3 database, Area 0.0.0.0Type ID Adv Rtr Seq Age Cksum LenRouter 0.0.0.0 203.119.104.2 0x8000006e 2231 0xe342 40Router *0.0.0.0 203.119.104.4 0x8000006e 2860 0x6399 40Router 0.0.0.0 203.119.104.13 0x8000006e 2679 0xcf92 56IntraArPfx 0.0.0.1 203.119.104.2 0x80000070 731 0x657f 72IntraArPfx *0.0.0.1 203.119.104.4 0x8000006e 1360 0xd6e0 72IntraArPfx 0.0.0.1 203.119.104.13 0x80000070 1179 0xd130 92 OSPF3 AS SCOPE link state databaseType ID Adv Rtr Seq Age Cksum LenExtern 0.0.0.1 203.119.104.2 0x8000006e 2981 0x4f8 28Extern *0.0.0.1 203.119.104.4 0x80000065 2110 0xaf9 28 OSPF3 Link-Local database, interface ge-0/0/0.0 Area 0.0.0.0Type ID Adv Rtr Seq Age Cksum LenLink *0.0.0.1 203.119.104.4 0x8000006f 610 0x47ad 64Link 0.0.0.3 203.119.104.13 0x8000006e 429 0xf9dd 64 If ospf neighbor already established in full status and default route already been advertised to ospf database, this means that the default route should be advertised to ospf neighbor, the thing we need to focus on is why we can’t see the default route advertised from R3 on the neighbor device R2.Upon checking the default route type on R2, we can see the default route advertised from R1 is Type 1 , however, on R3, we didn’t set metric type for the default route.If we didn’t set static route metric type, the default route advertised to ospf will be external metric type 2 by default.From the output below, we can see that R2 selects the path with metric type 1 as best path, which is the path from R1:R2# sh ip route 0/00.0.0.0/0, *via 203.110.1.37, Eth5/23, [110/9], 1d01h, ospf-4608, type-1, tag 4608EX# sh ipv6 route ::/00::/0, *via fe80::23c:9dee:fe60:1888, Eth5/23, [110/9], 1d01h, ospfv3-4608, type-1,----------------------------------Conclusion: This is related with OSPF path selection rules, not an issue. OSPF will install the best path into routing table when device received several paths to the same destination.When set the default route on R3 by using the same metric type 1 and set metric value to the one lower than the value of the default route on R2, R2 will select R3 as the best path to the default route and install the path into routing table.For configuring static route metric type, please refer to the document below: https://www.juniper.net/documentation/us/en/software/junos/cli-reference/topics/ref/statement/metric-edit-routing-options.htmlFor ospf route selections on MX platform, please check the details below: 1. When there are multiple routes available to the same network with different route types, routers use this order of preference (from highest to lowest):Intra-area routesInter-area routesExternal Type-1 routesExternal Type-2 routesType 1 external paths are always preferred over Type 2 external paths.2.If there are multiple routes to a network with the same route type, the OSPF metric calculated as cost based on the bandwidth is used for selecting the best route. The route with the lowest value for cost is chosen as the best route.3.If there are multiple routes to a network with the same route type and cost, it chooses all the routes to be installed in the routing table, and the router does equal cost load balancing across multiple paths.----------------------------------Lab verified: ospf path selection based on metric type and metric value: 1. If 2 paths set same metric value, but different metric type -- one of the path is metric type 1, the other is metric type 2. OSPF will select the path with metric type 1 as best path:lab test 1: On R3, set static route metric value 0 and metric type to 1[edit routing-options]labroot@R3# set static route 0.0.0.0/0 metric 0[edit routing-options]labroot@R3# set static route 0.0.0.0/0 metric type 1On R1, set static route metric value 0 and metric type to 2.[edit routing-options]labroot@R1# set static route 0.0.0.0/0 metric 0[edit routing-options]labroot@R1# set static route 0.0.0.0/0 metric type 2With same metric value, different metric type, R2 selects the default route advertised from R3 which is set type 1 as the best path.labroot@R2> show route 0.0.0.0/0inet.0: 12 destinations, 12 routes (12 active, 0 holddown, 0 hidden)+ = Active Route, - = Last Active, * = Both0.0.0.0/0 *[OSPF/150] 00:07:15, metric 1, tag 0 > to 23.1.1.2 via ge-0/0/1.0----------------------------------2. If 2 paths have different metric value and different metric type path, ospf will select the metric type 1 as best path even the metric value is higher.lab test 2 : with different metric value, different metric type advertised from both R1 and R2.R3 set metric value 10 and metric type 1.[edit routing-options]labroot@R3# set static route 0.0.0.0/0 metric type 1[edit routing-options]labroot@R3# set static route 0.0.0.0/0 metric 10R1 set metric value 0 and metric type 2: [edit routing-options]labroot@R1# set static route 0.0.0.0/0 metric 0[edit routing-options]labroot@R1# set static route 0.0.0.0/0 metric type 2R2 selects the metric type 1 with higher metric value as best path.labroot@R2> show route 0.0.0.0/0inet.0: 12 destinations, 12 routes (12 active, 0 holddown, 0 hidden)+ = Active Route, - = Last Active, * = Both0.0.0.0/0 *[OSPF/150] 00:00:28, metric 11, tag 0 > to 23.1.1.2 via ge-0/0/1.0----------------------------------3. If 2 paths have the same metric value and same metric type, it will select both of the paths as the next hop to default route.lab test 3With same metric type, same metric value: R3 set metric type 1 and metric value 10[edit routing-options]labroot@R3# set static route 0.0.0.0/0 metric 10[edit routing-options]labroot@R3# set static route 0.0.0.0/0 metric type 1R1 set metric type 1 and metric value 10[edit routing-options]labroot@R1# set static route 0.0.0.0/0 metric type 1[edit routing-options]labroot@R1# set static route 0.0.0.0/0 metric 10R2 selects both the paths to R1 and R3 to the default route labroot@R2> show route 0.0.0.0/0inet.0: 12 destinations, 12 routes (12 active, 0 holddown, 0 hidden)+ = Active Route, - = Last Active, * = Both0.0.0.0/0 *[OSPF/150] 00:00:04, metric 11, tag 0 > to 23.1.1.2 via ge-0/0/1.0 to 12.1.1.1 via ge-0/0/0.0----------------------------------4. If 2 paths have same metric type, but different metric value, it will select the path with lower metric as best path to the destination.lab test 4:Same metric type, different metric value: R3 set metric value 10 and metric type 1[edit routing-options]labroot@R3# set static route 0.0.0.0/0 metric 10[edit routing-options]labroot@R3# set static route 0.0.0.0/0 metric type 1R1 set metric value 5 and metric type 1 [edit routing-options]labroot@R1# set static route 0.0.0.0/0 metric 5[edit routing-options]labroot@R1# set static route 0.0.0.0/0 metric type 1R2 selects the path to R1 as the best path to default route 0.0.0.0/0labroot@R2> show route 0.0.0.0/0inet.0: 12 destinations, 12 routes (12 active, 0 holddown, 0 hidden)+ = Active Route, - = Last Active, * = Both0.0.0.0/0 *[OSPF/150] 00:02:18, metric 6, tag 0 > to 12.1.1.1 via ge-0/0/0.0