Use Tcl script to change the interface status

During network troubleshooting or proof-of-concept testing, I often change the state of a loopback interface (to insert or remove IP prefix from the routing protocols) or flap it to test the impact on network stability. The traditional approach to this procedure should be known to everyone:

  • Enter configuration mode;
  • Select the appropriate interface with the interface loopback x command;
  • Try to remember whether you need to disable or enable it;
  • Issue the shutdown or no shutdown command;
  • Exit the configuration mode and continue your debugging/testing process.

After a particularly boring testing session I decided to write a Tcl script to automate the job. To use it, download it and store it into ifchange.tcl. Download the Tcl file to your router (Flash or NVRAM) and define an alias: alias exec ifchange tclsh flash:ifchange.tcl. Now you can use the new ifchange command to change interface status.

A sample router printout is included below:
a1#ifchange
Syntax: tclsh ifchange.tcl interface [on|off|change|flap]
a1#ifchange loop0 off
Interface loop0 changed state to off
a1#
%LINK-5-CHANGED: Interface Loopback0, changed state to administratively down
%LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to down
a1#ifchange loop0 on
Interface loop0 changed state to on
a1#
%LINK-3-UPDOWN: Interface Loopback0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up
a1#ifchange loop0 flap
changing state of loop0
shut down interface loop0
... waiting ...
%LINK-5-CHANGED: Interface Loopback0, changed state to administratively down
%LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to down
changing state of loop0
enable interface loop0
a1#
%LINK-3-UPDOWN: Interface Loopback0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up

0 comments:

Post a Comment

You don't have to log in to post a comment, but please do provide your real name/URL. Anonymous comments might get deleted.

Ivan Pepelnjak, CCIE#1354, is the chief technology advisor for NIL Data Communications. He has been designing and implementing large-scale data communications networks as well as teaching and writing books about advanced technologies since 1990. See his full profile, contact him or follow @ioshints on Twitter.