Routing
Highlighted
Routing

Routing Policy

‎05-26-2019 04:31 PM

Based on below BGP export policy "bgp-redistrib-ospf " , I have two questions

1, Will this policy accept route 10.61.11.17/24 and re-distribute into BGP ?

2. Will it re-distribute OSPF routes into BGP ?

 

Thanks in advance

 

policy-statement bgp-redistrib-ospf {
        term ospf-connected-advs {
            from {
                route-filter 10.61.0.0/20 longer accept;
                route-filter 10.80.0.0/21 exact accept;
                route-filter 10.135.0.0/16 longer accept;
                route-filter 0.0.0.0/0 exact;
  route-filter 10.61.11.0/24 exact accept;
                route-filter 172.30.2.192/26 longer accept;
                route-filter 10.148.14.0/23 orlonger reject;
                route-filter 10.148.114.0/23 orlonger reject;
                route-filter 10.61.16.0/21 exact accept;
                route-filter 10.86.0.0/23 exact accept;
                route-filter 10.138.0.0/23 exact accept;
                route-filter 10.64.16.0/23 exact accept;
                route-filter 10.148.4.0/23 exact accept;
                route-filter 10.148.104.0/23 exact accept;
                route-filter 10.0.0.0/8 orlonger reject;
            }
            then next term;
        }
        term from-bgp {
            from protocol bgp;
            then next policy;
        }
        term connected {
            from {
                protocol direct;
                interface [ lo0.0 ge-0/0/0.0 ];
            }
            then accept;
        }

protocols {
    bgp {
        path-selection cisco-non-deterministic;
        log-updown;
        export bgp-redistrib-ospf;
        group jweb-bgp {               
            type external;
            metric-out 0;
            local-address X.X.X.X;
            peer-as 209;
            neighbor X.X.X.X {
                metric-out 0;

    ospf {
        export ospf-redistributes;
        area 0.0.0.0 {
            interface lo0.0;
            interface ge-0/0/0.0;
        }

policy-statement ospf-redistributes {
        term bgp {
            from protocol bgp;
            then accept;
        }
        term from-ospf {
            from protocol ospf;
            then next policy;
        }
        term connected {
            from protocol direct;
            then accept;
        }

2 REPLIES 2
Highlighted
Routing

Re: Routing Policy

‎05-26-2019 06:16 PM

Hi Irfan,

 


@Irfan wrote:

Based on below BGP export policy "bgp-redistrib-ospf " , I have two questions

1, Will this policy accept route 10.61.11.17/24 and re-distribute into BGP ?

[ANS] This route is accepted based on the first term in the policy, yes.  However, the right way to match an OSPF route and redistribute into BGP is:

https://www.juniper.net/documentation/en_US/junos/topics/example/routing-policy-security-opspf-route...
https://forums.juniper.net/t5/Routing/How-to-redistribute-bgp-into-ospf-with-different-area/td-p/295...

set policy-options policy-statement injectpolicy1 term injectterm1 from protocol ospf
set policy-options policy-statement injectpolicy1 term injectterm1 from area 0.0.0.1
set policy-options policy-statement injectpolicy1 term injectterm1 then accept
set protocols bgp export injectpolicy1

 

Plesae note that the match conditions and the usage of "next policy" and "next term" is making the policy a bit messy.  Do you have a description of the intended behavior of which routes do you need to import from which protocol to which protocol? Its better to modify the action taken by the policy after "then" accordingly.  Please see if these link will clarify and help you with this:

https://www.juniper.net/documentation/en_US/junos/topics/example/isis-community-policy.html
https://www.juniper.net/documentation/en_US/junos/topics/example/routing-policy-security-opspf-route...

https://forums.juniper.net/t5/Routing/How-to-redistribute-bgp-into-ospf-with-different-area/td-p/295...

https://www.juniper.net/documentation/en_US/junos/topics/concept/policy-routing-policies-chain-evalu...

 

2. Will it re-distribute OSPF routes into BGP ?

[ANS] To export OSPF routes into BGP, we need to have a term in policy to match "from protocol ospf" and "then accept" and then apply that as a export policy in BGP.  You don't need to apply the export policy under OSPF.  For example: 
https://www.juniper.net/documentation/en_US/junos/topics/example/routing-policy-security-opspf-route...

set policy-options policy-statement injectpolicy1 term injectterm1 from protocol ospf
set policy-options policy-statement injectpolicy1 term injectterm1 from area 0.0.0.1
set policy-options policy-statement injectpolicy1 term injectterm1 then accept
set protocols bgp export injectpolicy1

 

Thanks in advance

 

policy-statement bgp-redistrib-ospf {
        term ospf-connected-advs {
            from {
                route-filter 10.61.0.0/20 longer accept;
                route-filter 10.80.0.0/21 exact accept;
                route-filter 10.135.0.0/16 longer accept;
                route-filter 0.0.0.0/0 exact;
  route-filter 10.61.11.0/24 exact accept;
                route-filter 172.30.2.192/26 longer accept;
                route-filter 10.148.14.0/23 orlonger reject;
                route-filter 10.148.114.0/23 orlonger reject;
                route-filter 10.61.16.0/21 exact accept;
                route-filter 10.86.0.0/23 exact accept;
                route-filter 10.138.0.0/23 exact accept;
                route-filter 10.64.16.0/23 exact accept;
                route-filter 10.148.4.0/23 exact accept;
                route-filter 10.148.104.0/23 exact accept;
                route-filter 10.0.0.0/8 orlonger reject;
            }
            then next term;
        }
        term from-bgp {
            from protocol bgp;
            then next policy;
        }
        term connected {
            from {
                protocol direct;
                interface [ lo0.0 ge-0/0/0.0 ];
            }
            then accept;
        }

protocols {
    bgp {
        path-selection cisco-non-deterministic;
        log-updown;
        export bgp-redistrib-ospf;
        group jweb-bgp {               
            type external;
            metric-out 0;
            local-address X.X.X.X;
            peer-as 209;
            neighbor X.X.X.X {
                metric-out 0;

    ospf {
        export ospf-redistributes;
        area 0.0.0.0 {
            interface lo0.0;
            interface ge-0/0/0.0;
        }

policy-statement ospf-redistributes {
        term bgp {
            from protocol bgp;
            then accept;
        }
        term from-ospf {
            from protocol ospf;
            then next policy;
        }
        term connected {
            from protocol direct;
            then accept;
        }


Hope this helps.

 

Regards,
-r.

--------------------------------------------------

If this solves your problem, please mark this post as "Accepted Solution."
Kudos are always appreciated :).

Highlighted
Routing

Re: Routing Policy

‎05-26-2019 11:22 PM

Hi,

Just a small clarification here:

>>> 1, Will this policy accept route 10.61.11.17/24 and re-distribute into BGP ?

There could not be such a route strictly speaking. If you have /24 route, the last octect has to be 0 (e.g. 10.61.11.0/24)

Feedback