SD-WAN

 View Only
last person joined: 13 days ago 

Ask questions and share experiences with SD-WAN and Session Smart Router (formerly 128T).
  • 1.  Linux script to grab arp table from 128T router

     
    Posted 12-07-2018 20:11
    Is there a script, or can one be created relatively quickly leveraging our REST or NETCONF APIs, to run in Linux shell, which will print out the 128T router's ARP table?

    ------------------------------
    Gene Shtirmer
    Sales Engineer
    Randolph, NJ
    ------------------------------


  • 2.  RE: Linux script to grab arp table from 128T router

     
    Posted 12-07-2018 20:39
    Hey @Gene as the root user you can do a PCLI one-liner with `su - admin -c "<pcli-command>"`, which will load, run, then exit. Example:
    [root@pilchuck t128]# su - admin -c "show arp"
    Starting the PCLI...
    Fri 2018-12-07 20:17:11 EST
    
    Node: node1
    
    ========== ====== ================= =================== =======
     Dev Name   VLAN   IP                Dest MAC            State
    ========== ====== ================= =================== =======
     enp1s0        6   172.25.128.1      00:01:ff:ab:30:14   Valid
     enp2s0        0   192.168.1.126     74:d0:2b:c5:d8:e8   Valid
     enp2s0        0   192.168.1.128     48:a4:72:34:f3:14   Valid
     enp2s0        0   192.168.1.160     ac:37:43:dd:29:cb   Valid
     enp2s0        0   192.168.1.161     e8:b2:ac:a3:6d:42   Valid
     enp2s0        0   192.168.1.162     40:4e:36:3b:55:35   Valid
     enp2s0        0   192.168.1.193     54:60:09:04:93:7c   Valid
     enp2s0        0   192.168.1.195     00:0e:58:58:aa:a2   Valid
     enp2s0        0   192.168.1.196     00:0e:58:53:75:9a   Valid
     enp2s0        0   192.168.1.224     18:b4:30:9f:bf:b3   Valid
     enp2s0        0   192.168.1.225     18:b4:30:a8:64:8f   Valid
     enp2s0        0   192.168.1.226     18:b4:30:a8:50:f6   Valid
     enp2s0        0   192.168.1.227     18:b4:30:a5:2a:15   Valid
     enp2s0        0   192.168.1.228     18:b4:30:a8:5e:e1   Valid
     enp2s0        0   192.168.1.229     18:b4:30:9f:a5:50   Valid
     enp2s0        0   192.168.1.230     18:b4:30:a8:53:9f   Valid
     enp2s0        0   192.168.1.232     18:b4:30:82:db:eb   Valid
     kni254        0   169.254.127.127   06:29:f1:63:9e:3c   Valid
    
    Completed in 0.11 seconds
    [root@pilchuck t128]# 
    ​

    ​Note that this method is fairly inefficient, since it takes a while to load the entire PCLI. Looks like you can accomplish the same with GraphQL. Here would be an example:
    curl -k -X POST \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    --header 'Authorization: Bearer <token_string>' \
    -d '{"query":"query getArp($routerName: String!, $filterNodes: [String], $filterString: String) {\n allRouters(name: $routerName) {\n nodes {\n nodes(names: $filterNodes) {\n        nodes {\n _id\n name\n arp(first: 250, filter: $filterString) {\n networkInterface\n deviceInterface\n vlan\n ipAddress\n destinationMac\nstate\n}\n}\n}\n}\n}\n}","variables":{"routerName":"<my_router_name>","filterString":null,"filter":""}}' \
    https://<my_128t_node>/api/v1/graphql​


    ------------------------------
    - Reid
    ------------------------------



  • 3.  RE: Linux script to grab arp table from 128T router

     
    Posted 12-08-2018 02:09
    @Gene I hacked together a bit of ES6 code you could place into a file, make it executable, modify the authToken and t128HostAddress variables...and you should be able to call it from your Linux shell. It will return all MAC addresses in a CSV format.

    Note when I say all, I mean ALL. If you point this at a conductor, it will grab all arp entries from all routers in your authority! If you want to scope it to specific routers, you'll have to mess with the graphql query.
    #!/usr/bin/env node
    "use strict";
    
    const https = require('https');
    const authToken = '<your_token_string>'
    const t128HostAddress = '<your_128T_host>'
    
    var graphqlQuery = {
      query: `query getArp($filterNodes: [String], $filterRouters: [String]) {
        allRouters(names: $filterRouters) {
          nodes {
            name
            nodes(names: $filterNodes) {
              nodes {
                _id
                name
                arp {
                  networkInterface
                  ipAddress
                  destinationMac
                  state
                }
              }
            }
          }
        }
      }`,
      variables: null,
      operationName: 'getArp'
    }
    
    const options = {
      host : t128HostAddress,
      port : 443,
      path : '/api/v1/graphql',
      method : 'POST',
      rejectUnauthorized : false,
      headers : {
        'Content-Type' : 'application/json',
        'Content-Length' : Buffer.byteLength(JSON.stringify(graphqlQuery), 'utf8'),
        'Authorization' : `Bearer ${authToken}`,
        'Accept' : 'application/json'
      }
    }
    
    var req = https.request(options, (res) => {
      var responseData = ''
      res.setEncoding('utf8')
    
      res.on('data', (resDataChunk) => {
        responseData += resDataChunk
      })
    
      res.on('end', () => {
        var arpResultsGraph = JSON.parse(responseData).data.allRouters.nodes
    
        process.stdout.write(`Router,Node,Interface,IP,MAC,State\n`)
    
        arpResultsGraph.forEach((router) => {
          if (router.nodes.nodes instanceof Array) {
            router.nodes.nodes.forEach((t128node) => {
              if (t128node.arp instanceof Array) {
                t128node.arp.forEach((arpEntry) => {
                  process.stdout.write(`${router.name},${t128node.name},${arpEntry.networkInterface},${arpEntry.ipAddress},${arpEntry.destinationMac},${arpEntry.state}\n`)
                })
              }
            })
          }
        })
      })
    })
    
    req.write(JSON.stringify(graphqlQuery))
    
    req.on('error', (error) => {
      console.log('debug', 'REST request failed:', error)
    });
    
    req.end()


    ------------------------------
    - Reid
    ------------------------------



  • 4.  RE: Linux script to grab arp table from 128T router

     
    Posted 12-08-2018 09:03
    Nice work @Reid!!!  Thank you.  On an HA router, will this return ARP entrie​s from both nodes?

    ------------------------------
    Gene Shtirmer
    Sales Engineer
    Burlington MA
    ------------------------------



  • 5.  RE: Linux script to grab arp table from 128T router

     
    Posted 12-08-2018 09:13
    Yes, all node's and router's ARP entries from the 128T host that you target with that script.

    ------------------------------
    - Reid
    ------------------------------



  • 6.  RE: Linux script to grab arp table from 128T router

     
    Posted 09-21-2019 00:18
    Hey @Reid, does the output from your script get paginated if there are a lot of arp entries to printout?​

    ------------------------------
    Gene Shtirmer
    Sales Engineer
    Randolph NJ
    (973) 610-5676
    ------------------------------



  • 7.  RE: Linux script to grab arp table from 128T router

     
    Posted 09-21-2019 01:02
    No, it is just going to print everything it gets.

    ------------------------------
    - Reid
    ------------------------------