Junos Automation (Scripting)
Reply
Contributor
vahag84
Posts: 11
Registered: ‎08-23-2010
0

Explain enable-primary-nexthop script

Hi all!!!

May be it is stupid question but...

Can somebody explain the enable-primary-nexthop script in detail??? I can't understand how it is work. What I must change in it.

Somebody pls help ( in detail) !!!!

 

 

Recognized Expert
ccall
Posts: 235
Registered: ‎06-18-2008
0

Re: Explain enable-primary-nexthop script

This script reacts to RPM events from a specifically configured RPM test. You can find details on the configuration required in the PDF README file, available for download on the same page where you download the code.

 

Part of the configuration includes two event policies, which executes either the enable-primary-nexthop.slax or enable-alternate-next-hop.slax script, and provides them with a single argument: next-hop-interface.

 

So, when these scripts start, their $next-hop-interface parameter has been set to the value provided by your event policy. Execution starts within the match / template, where the first action is to open a management connection via jcs:smileysurprised:pen(). Next, the $next-hop-interface parameter is combined with a ".0" to form a new $logical-interface variable. This is important because it indicates that the script is written to work only with the .0 logical interface of the physical interface. If you wish to disable a VLAN for example you would have to modify it.

 

A configuration change is then created and assigned to the $change-route variable. This configuration change does three things: First, it delete the existing default route. Second, it adds a default route pointing to the $logical-interface, and third, it deletes the disable statement from the $next-hop-interface.

 

The fact that the script makes the interface the next-hop of the route indicates that the interface must be p2p. Otherwise the configuration will fail.

 

Finally, the configuration change is applied via the jcs:load-configuration template.

 

The companion script, enable-alternate-next-hop.slax, is similar. But in this case it disables the $next-hop-interface and makes the default route point towards a hard-coded alternate interface of "dl2.0". You would need to modify that alternate next-hop to whatever interface you prefer.

Contributor
vahag84
Posts: 11
Registered: ‎08-23-2010
0

Re: Explain enable-primary-nexthop script

Thank you for your replay I read the pdf but can't understand it

my primary next-hop is fe-0/0/6.0 and second next hop is fe-0/0/7.0 and in attachment file is my configure file can you help me to edit the slax file and configure file.

Thank you!!!

Contributor
vahag84
Posts: 11
Registered: ‎08-23-2010
0

Re: Explain enable-primary-nexthop script

 
Recognized Expert
ccall
Posts: 235
Registered: ‎06-18-2008
0

Re: Explain enable-primary-nexthop script

Would you actually want the primary interface to be disabled when the RPM test fails, or would you just want the next-hop of the default route to switch to the backup? For example, if your RPM test is to a destination out of the primary then disabling it is a good way of ensuring that the test will never succeed.

Contributor
vahag84
Posts: 11
Registered: ‎08-23-2010
0

Re: Explain enable-primary-nexthop script

my ISP1 interface is fe-0/0/6.0, ISP2 interface is fe_0/0/7.0.

my goal is change default rout fe-0/0/6.0 to fe-0/0/7.0 ( 0.0.0.0/0 > 192.168.0.113 to 0.0.0.0/0 > 10.10.20.3) if ping test fail,

and when ping test complete i want to have default route to fe-0/0/6.0 ( 0.0.0.0/0 > 192.168.0.113). I don't wont disable any interface, i wont only change default route

Recognized Expert
ccall
Posts: 235
Registered: ‎06-18-2008
0

Re: Explain enable-primary-nexthop script

In that case, change your 0/0 static route config to this:

 

     route 0.0.0.0/0 {
            qualified-next-hop 192.168.0.113;
            qualified-next-hop 10.10.20.3 {
                preference 200;
            }
        }

 

And your event-options config to this:

 

event-options {
    policy test-failed {
        events PING_TEST_FAILED;
        within 240 events [ PING_TEST_COMPLETED KERNEL SYSTEM ];
        attributes-match {
            ping_test_failed.test-owner matches icmp-ping-probe;
            ping_test_failed.test-name matches ping-probe-test;
            ping_test_completed.test-owner matches icmp-ping-probe;
            ping_test_completed.test-name matches ping-probe-test;
            SYSTEM.message matches "Starting of initial processes complete";
            KERNEL.message matches "event-processing \(PID.*\)started";
        }
        then {
            event-script watch-default-route.slax {
                arguments {
                    next-hop 192.168.0.113;
                }
            }
        }
    }
    policy test-completed {
        events PING_TEST_COMPLETED;
        within 240 events [ PING_TEST_FAILED KERNEL SYSTEM ];
        attributes-match {
            ping_test_completed.test-owner matches icmp-ping-probe;
            ping_test_completed.test-name matches ping-probe-test;
            ping_test_failed.test-owner matches icmp-ping-probe;
            ping_test_failed.test-name matches ping-probe-test;
            SYSTEM.message matches "Starting of initial processes complete";
            KERNEL.message matches "event-processing \(PID .*\) started";
        }
        then {
            event-script watch-default-route.slax {
                arguments {
                    next-hop 192.168.0.113;
                }
            }
        }
    }
    event-script {
        file watch-default-route.slax;
    }
}

 

And then copy the attached event script to your /var/db/scripts/event directory.

Contributor
jzaidman
Posts: 14
Registered: ‎02-22-2008
0

Re: Explain enable-primary-nexthop script

Hello,

 

Is this solution going to work if the two ISP connections are DHCP-assigned and there is no way of knowing and hardcoding their next-hop addresses in the script?

 

Thanks!

 

Jakov

Jakov
Recognized Expert
ccall
Posts: 235
Registered: ‎06-18-2008
0

Re: Explain enable-primary-nexthop script

No, the above solution is only intended for static routes that have next hops manually configured in the configuration. If they are coming via DHCP then the script would have to be altered, but I'm not sure what changes are required as I'm not familiar with the particular scenario you're referring to.

Contributor
jzaidman
Posts: 14
Registered: ‎02-22-2008
0

Re: Explain enable-primary-nexthop script

Thanks ccal, the search continues... 

Jakov
Copyright© 1999-2013 Juniper Networks, Inc. All rights reserved.