[j-nsp] aggregated-ethernet and metric adjustment, if one link fails

Serge Vautour sergevautour at yahoo.ca
Fri Jan 13 15:32:11 EST 2012


Hello,

There is a minimum member option in LAG links which will allow you to shutdown the whole bundle if 1 member fails.

If you just want to increase metrics when 1 interface fails, you can do that with an event-script. Here's an example for OSPF. Adjust as required.

Serge

version 1.0;

ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";

import "../import/junos.xsl";

/*
 * Increase OSPF cost when interface goes Down.

 * Note: This script only works when OSPF interfaces use unit 0 and with area 0.

 * Version 2: Updated to allow 2 instances to be called simultaneously

*/

var $arguments = {
   <argument> {
      <name> "interface";
      <description> "Interface to lower cost";
   }
   <argument> {
      <name> "metric";
      <description> "New OSPF metric";
   }
}

var $area = "0.0.0.0";

/* Decides where the output will go, 0 -> stdout, 1 -> syslog, 2 -> none */
var $silent = "1";

var $maxattempts = "5"; /* Number of times to try before giving up */

match / {

       /*
        * xml config to set interface metric
       */

       var $xml = {
            <configuration> {
              <protocols> {
                  <ospf> {
                      <area> {
                          <name>$area;
                          <interface> {
                              <name>$interface;
                              <metric>$metric;
                          }
                      }       
                  }
              }
            }
       }
       var $attempt = "1";
       call doConfigChange($xml, $attempt);


}

template doConfigChange($xml, $attempt) {
   /*
    * Open connection with mgd
    */
    var $con = jcs:open();

    if (not($con)) {
       call emit-error($message = "Not able to connect to local mgd");
    }
    var $config-private = <open-configuration> {
       <private>;
    }
    var $private-results = jcs:execute($con, $config-private);
    var $load-configuration = <load-configuration> {
       copy-of $xml;
    }

   var $load-results = jcs:execute($con, $load-configuration);
  /*
   * Use load-configuration template defined in junos.xsl to load and
   * commit the configuration
   */

   var $commit-configuration = <commit-configuration>;
   var $commit-results = jcs:execute($con, $commit-configuration);

   /* Keep trying if we get an error while committing. This could be because another
    * instance of the script is committing.
   */

   if( $attempt > $maxattempts ) {
     /* Give up */

     for-each ($commit-results//xnm:error) {
        call emit-error($message = message);
     }

     var $giveupmessage = "ChangeOSPFMetric.slax configuration changes could not be made after " _ $attempt _ " attempts. - Script is exiting.";
     expr jcs:syslog("user.error", "ChangeOSPFMetric.slax[Error]: ", $giveupmessage);
   } 
   else {
     /* if we have an error, wait 10sec, increment attempts and perform recursive call to try again */
     if ($commit-results//xnm:error) {
       var $error-msg = "configuration change failed, a user may be editing the config or the script attempted to load a bad config.  Configuration change error info follows - " _ $commit-results _ " - trying again in 10 seconds . . . ";
       expr jcs:syslog(5, $error-msg);
       expr jcs:sleep(10);
       call doConfigChange($xml, $attempt = $attempt + 1 );          
     } 
     else {
      call emit-success($message = "Changed Metric");

      for-each ($commit-results//xnm:warning) {
       call emit-warn($message = message);
      }

     } /* end if commit-results */
   }  /* end if attempt statement */

   var $close-private = <close-configuration>;
   var $close-configuration-results = jcs:execute($con, $close-private);
   var $close-results = jcs:close($con);
}


template emit-success($message) {

   if ($silent == 0) {
      expr jcs:output($message);
   } else if ($silent == 1) {
      expr jcs:syslog("user.info","ChangeOSPFMetric.slax[Success]: ", $message);
   }
}
 
template emit-error($message) {

   if ($silent == 0) {
      expr jcs:output($message);
   } else if ($silent == 1) {
      expr jcs:syslog("user.error", "ChangeOSPFMetric.slax[Error]: ", $message);
  }
}

template emit-warn($message) {

   if ($silent == 0) {
      expr jcs:output($message);
   } else if ($silent == 1) {
      expr jcs:syslog("user.warning", "ChangeOSPFMetric.slax[Warning]: ", $message);
   }
}


Config to activate the script:

event-options {
    policy TrackCoreInt {
        events snmp_trap_link_down;
        attributes-match {
            snmp_trap_link_down.interface-name matches "(xe-0/0/0)|(xe-0/1/0)";
        }
        then {
            execute-commands {
                commands {
                    "show interfaces {$$.interface-name}";
                    "show conf interfaces {$$.interface-name}";
                    "show conf protocols ospf";
                }
                output-filename TrackCore_show_commands.txt;
                destination local;
                output-format text;
            }
            event-script ChangeOSPFMetric.slax {
                output-filename ChangeOSPFMetric.txt;
                destination local;
                output-format text;
                arguments {
                    interface "{$$.interface-name}";
                    metric "25";
                }
            }
        }
    }
    event-script {
        inactive: traceoptions {
            file event-trace.log;
            flag all;
        }           
        file ChangeOSPFMetric.slax;
    }
    destinations {
        local {
            archive-sites {
                /var/home/;
            }
        }
    }
}





________________________________
 From: Alex D. <listensammler at gmx.de>
To: Juniper-Nsp <juniper-nsp at puck.nether.net> 
Sent: Friday, January 13, 2012 3:25:43 PM
Subject: [j-nsp] aggregated-ethernet and metric adjustment, if one link fails
 
Hi list,

is it possible to automatically raise IS-IS metric, if one or more link(s) of an aggregated-ethernet fails ?

Exp.:
We have an aggregated-ethernet interface with 2x 1Gbps. Our IS-IS metric for this interface is 50. Metric for a single Gigabit interface is 100.

It would be nice, if the metric could be automatically raised to 100 when one member link fails.
Does anyone know a way to accomplish this goal ?

Regards,
Alex
_______________________________________________
juniper-nsp mailing list juniper-nsp at puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp


More information about the juniper-nsp mailing list