Wednesday, November 20, 2013

Running shell scripts on Junos

You can run a shell script in Junos.

user@R1> start shell
% su
Password:
root@R1% sh tpl.sh 
root@R1% ls
op1.txt tpl.sh
root@R1% more op1.txt 
set interfaces xe-0/0/0 description to-R4-xe-0/3/0
set interfaces xe-0/0/0 unit 0 family inet mtu 1500

root@R1% 
root@R1% more tpl.sh 
#!/sbin/sh

cli -c 'show configuration interfaces | display set' >> op1.txt
root@R1% 
root@R1% exit
exit
% exit

Saturday, November 9, 2013

Op script to disable a vc-port in a virtual chassis

A customer asked for a script to disable a vcp-port in case there were flapping issues.

There is a cli command that does this

jnpr@EX4200-VC-2> request virtual-chassis vc-port set interface vcp-0 disable member 0 
fpc0:
--------------------------------------------------------------------------

{master:0}
jnpr@EX4200-VC-2> show virtual-chassis vc-port 
fpc0:
--------------------------------------------------------------------------
Interface   Type              Trunk  Status       Speed        Neighbor
or                             ID                 (mbps)       ID  Interface
PIC / Port
vcp-0       Dedicated           1    Disabled     32000   <<<<<<<<<<<<<<<< HERE
vcp-1       Dedicated           2    Up           32000        1   vcp-0  

fpc1:
--------------------------------------------------------------------------
Interface   Type              Trunk  Status       Speed        Neighbor
or                             ID                 (mbps)       ID  Interface
PIC / Port
vcp-0       Dedicated           1    Up           32000        0   vcp-1  
vcp-1       Dedicated           2    Down         32000

jnpr@EX4200-VC-2> request virtual-chassis vc-port set interface vcp-0 member 0           
fpc0:
--------------------------------------------------------------------------

{master:0}
jnpr@EX4200-VC-2> show virtual-chassis vc-port                                    
fpc0:
--------------------------------------------------------------------------
Interface   Type              Trunk  Status       Speed        Neighbor
or                             ID                 (mbps)       ID  Interface
PIC / Port
vcp-0       Dedicated           1    Up           32000        1   vcp-1  <<<<<<<<<<< re-enabled
vcp-1       Dedicated           2    Up           32000        1   vcp-0  

fpc1:
--------------------------------------------------------------------------
Interface   Type              Trunk  Status       Speed        Neighbor
or                             ID                 (mbps)       ID  Interface
PIC / Port
vcp-0       Dedicated           1    Up           32000        0   vcp-1  
vcp-1       Dedicated           2    Up           32000        0   vcp-0  

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

Demo of the script to disable vc-port

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

jnpr@EX4200-VC-2# run show virtual-chassis vc-port 
fpc0:
--------------------------------------------------------------------------
Interface   Type              Trunk  Status       Speed        Neighbor
or                             ID                 (mbps)       ID  Interface
PIC / Port
vcp-0       Dedicated           1    Up           32000        1   vcp-1  
vcp-1       Dedicated           2    Up           32000        1   vcp-0  

fpc1:
--------------------------------------------------------------------------
Interface   Type              Trunk  Status       Speed        Neighbor
or                             ID                 (mbps)       ID  Interface
PIC / Port
vcp-0       Dedicated           1    Up           32000        0   vcp-1  
vcp-1       Dedicated           2    Up           32000        0   vcp-0  

{master:0}[edit]
jnpr@EX4200-VC-2# run op vcp ?
Possible completions:
  <[Enter]>            Execute this command
  <name>               Argument name
  action               0 to enable, 1 to disable
  detail               Display detailed output
  interface            interface name.
  |                    Pipe through a command
{master:0}[edit]
jnpr@EX4200-VC-2# run op vcp interface vcp-0 action 1 

jnpr@EX4200-VC-2# run show virtual-chassis vc-port 
fpc0:
--------------------------------------------------------------------------
Interface   Type              Trunk  Status       Speed        Neighbor
or                             ID                 (mbps)       ID  Interface
PIC / Port
vcp-0       Dedicated           1    Disabled     32000
vcp-1       Dedicated           2    Up           32000        1   vcp-0  

fpc1:
--------------------------------------------------------------------------
Interface   Type              Trunk  Status       Speed        Neighbor
or                             ID                 (mbps)       ID  Interface
PIC / Port
vcp-0       Dedicated           1    Up           32000        0   vcp-1  
vcp-1       Dedicated           2    Down         32000

{master:0}[edit]
jnpr@EX4200-VC-2# run op vcp interface vcp-0 action 0    

{master:0}[edit]
jnpr@EX4200-VC-2# run show virtual-chassis vc-port       
fpc0:
--------------------------------------------------------------------------
Interface   Type              Trunk  Status       Speed        Neighbor
or                             ID                 (mbps)       ID  Interface
PIC / Port
vcp-0       Dedicated           1    Up           32000        1   vcp-1  
vcp-1       Dedicated           2    Up           32000        1   vcp-0  

fpc1:
--------------------------------------------------------------------------
Interface   Type              Trunk  Status       Speed        Neighbor
or                             ID                 (mbps)       ID  Interface
PIC / Port
vcp-0       Dedicated           1    Up           32000        0   vcp-1  
vcp-1       Dedicated           2    Up           32000        0   vcp-0  


---------------------------- 
Source code
----------------------------

jnpr@EX4200-VC-2# run file show /var/db/scripts/op/vcp.slax 
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";

var $arguments = {
    <argument> {
        <name> "interface";
        <description> "interface name.";
    }
    <argument> {
        <name> "action";
        <description> "0 to enable, 1 to disable";
    }
}
param $interface;
param $action =0;

                                        
match /
{
    <event-op-results> {

        if ($action = 1) {
           var $interface-info = <command> "request virtual-chassis vc-port set interface " _ $interface _ " disable member 0";
           var $interface-result = jcs:invoke($interface-info);
        }
        if ($action = 0) {
           var $interface-info = <command> "request virtual-chassis vc-port set
interface " _ $interface _ " member 0";
           var $interface-result = jcs:invoke($interface-info);
        }

    }

}

Thursday, November 7, 2013

FEC 129 - VPLS with BGP auto-discovery using LDP

New version of JUNOS supports FEC 129 BGP auto-discovery.
You don't have to manually configure each pseudo wire. You will use BGP to auto discover the other PEs. no need for a site-ids (rsvp based) or vpls-ids (manual ldp psuedowires). 

Two commands to consider is the l2vpn-id which is similar to the vrf-target. And the auto-discovery-only command in BGP. 

Below will connect to various PEs 

user@router# show routing-instances 
VPLS {
    instance-type vpls;
    interface et-0/1/0.1;
    route-distinguisher 2.2.2.2:852;
    l2vpn-id l2vpn-id:100:1;
    vrf-target target:100:1;
    protocols {
        vpls {
            encapsulation-type ethernet-vlan;
            no-tunnel-services;
        }
    }
}

{master}[edit]
user@router# show protocols bgp 
path-selection external-router-id;
log-updown;
group RR {
    type internal;
    local-address 2.2.2.2;
    family l2vpn {
        auto-discovery-only;
    }
    neighbor 192.168.1.1;
    neighbor 192.168.1.2;
    neighbor 192.168.1.3;
    neighbor 192.168.1.4;
    neighbor 192.168.1.5;
    neighbor 192.168.1.6;               
    neighbor 192.168.1.7;
    neighbor 192.168.1.8;
    neighbor 192.168.1.10;
}

{master}[edit]
user@router# show interfaces et-0/1/0 
flexible-vlan-tagging;
encapsulation flexible-ethernet-services;
unit 1 {
    encapsulation vlan-vpls;
    vlan-id 1;
    family vpls;
}


user@router# run show ldp database session 192.168.1.1 
Input label database, 2.2.2.2:0--192.168.1.1:0
  Label     Prefix
     16      FEC129 NoCtrlWord VLAN 000a0064:00000001 c0a80101 02020202

Output label database, 2.2.2.2:0--192.168.1.1:0
  Label     Prefix
      0      2.2.2.2/32
 299920      192.168.1.1/32
 299936      192.168.1.2/32
 299952      192.168.1.3/32
 299968      192.168.1.4/32
 299984      192.168.1.5/32
 300000      192.168.1.6/32
 300016      192.168.1.7/32
 300032      192.168.1.8/32
 300048      192.168.1.9/32
 300064      192.168.1.10/32
 262145      FEC129 NoCtrlWord VLAN 000a0064:00000001 02020202 c0a80101

{master}[edit]
user@router# run show bgp summary 
Groups: 1 Peers: 9 Down peers: 0
Table          Tot Paths  Act Paths Suppressed    History Damp State    Pending
inet.0               
                       0          0          0          0          0          0
inet6.0              
                       0          0          0          0          0          0
bgp.l2vpn.0          
                       9          9          0          0          0          0
inet.2               
                       0          0          0          0          0          0
Peer                     AS      InPkt     OutPkt    OutQ   Flaps Last Up/Dwn State|#Active/Received/Accepted/Damped...
192.168.1.1             852         18         20       0       0        8:07 Establ
  inet.0: 0/0/0/0
  inet6.0: 0/0/0/0
  bgp.l2vpn.0: 1/1/1/0
  inet.2: 0/0/0/0
  VPLS.l2vpn.0: 1/1/1/0

                                        
{master}[edit]
user@router# run show vpls connections 
Layer-2 VPN connections:

Legend for connection status (St)   
EI -- encapsulation invalid      NC -- interface encapsulation not CCC/TCC/VPLS
EM -- encapsulation mismatch     WE -- interface and instance encaps not same
VC-Dn -- Virtual circuit down    NP -- interface hardware not present 
CM -- control-word mismatch      -> -- only outbound connection is up
CN -- circuit not provisioned    <- -- only inbound connection is up
OR -- out of range               Up -- operational
OL -- no outgoing label          Dn -- down                      
LD -- local site signaled down   CF -- call admission control failure      
RD -- remote site signaled down  SC -- local and remote site ID collision
LN -- local site not designated  LM -- local site ID not minimum designated
RN -- remote site not designated RM -- remote site ID not minimum designated
XX -- unknown connection status  IL -- no incoming label
MM -- MTU mismatch               MI -- Mesh-Group ID not available
BK -- Backup connection         ST -- Standby connection
PF -- Profile parse failure      PB -- Profile busy
RS -- remote site standby SN -- Static Neighbor
LB -- Local site not best-site   RB -- Remote site not best-site
VM -- VLAN ID mismatch

Legend for interface status 
Up -- operational           
Dn -- down

Instance: VPLS
  L2vpn-id: 100:1
  Local-id: 2.2.2.2
    Remote-id                 Type  St     Time last up          # Up trans
    192.168.1.1               rmt   Up     Nov  7 20:58:18 2013           1
      Remote PE: 192.168.1.1, Negotiated control-word: No
      Incoming label: 262145, Outgoing label: 16
      Local interface: lsi.1048841, Status: Up, Encapsulation: VLAN
        Description: Intf - vpls VPLS local-id 2.2.2.2 remote-id 192.168.1.1 neighbor 192.168.1.1