Skip to content

ldpd: json support for show commands#13

Closed
dwalton76 wants to merge 1 commit intoFRRouting:masterfrom
dwalton76:ldp-json
Closed

ldpd: json support for show commands#13
dwalton76 wants to merge 1 commit intoFRRouting:masterfrom
dwalton76:ldp-json

Conversation

@dwalton76
Copy link
Copy Markdown
Contributor

Signed-off-by: Daniel Walton dwalton@cumulusnetworks.com

Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
@dwalton76
Copy link
Copy Markdown
Contributor Author

superm-redxp-05# show mpls ldp interface 
AF   Interface   State  Uptime   Hello Timers  ac
ipv4 swp1        ACTIVE 00:02:04 5/15           1
ipv4 swp2        ACTIVE 00:02:04 5/15           1
ipv4 swp3        ACTIVE 00:02:04 5/15           1
ipv4 swp4        ACTIVE 00:02:04 5/15           1

superm-redxp-05# 

superm-redxp-05# show mpls ldp interface json

{
  "swp1":{
    "addressFamily":"ipv4",
    "state":"ACTIVE",
    "uptime":"00:02:08",
    "helloInterval":5,
    "holdtime":15,
    "adjacencyCount":1
  },
  "swp2":{
    "addressFamily":"ipv4",
    "state":"ACTIVE",
    "uptime":"00:02:08",
    "helloInterval":5,
    "holdtime":15,
    "adjacencyCount":1
  },
  "swp3":{
    "addressFamily":"ipv4",
    "state":"ACTIVE",
    "uptime":"00:02:08",
    "helloInterval":5,
    "holdtime":15,
    "adjacencyCount":1
  },
  "swp4":{
    "addressFamily":"ipv4",
    "state":"ACTIVE",
    "uptime":"00:02:08",
    "helloInterval":5,
    "holdtime":15,
    "adjacencyCount":1
  }
}
superm-redxp-05# 

@dwalton76
Copy link
Copy Markdown
Contributor Author

superm-redxp-05# show mpls ldp binding 
6.0.0.3/32
        Local binding: label: imp-null
        Remote bindings:
            Peer                Label
            -----------------   ---------
            6.0.0.7             24
            6.0.0.8             24
            6.0.0.9             23
            6.0.0.10            23
6.0.0.4/32
        Local binding: label: 20
        Remote bindings:
            Peer                Label
            -----------------   ---------
            6.0.0.7             18
            6.0.0.8             18
            6.0.0.9             16
            6.0.0.10            16
6.0.0.5/32
        Local binding: label: 21
        Remote bindings:
            Peer                Label
            -----------------   ---------
            6.0.0.7             16
            6.0.0.8             16
            6.0.0.9             17
            6.0.0.10            17
6.0.0.6/32
        Local binding: label: 22
        Remote bindings:
            Peer                Label
            -----------------   ---------
            6.0.0.7             19
            6.0.0.8             17
            6.0.0.9             18
            6.0.0.10            18
6.0.0.7/32
        Local binding: label: 16
        Remote bindings:
            Peer                Label
            -----------------   ---------
            6.0.0.7             imp-null
            6.0.0.8             19
            6.0.0.9             19
            6.0.0.10            19
6.0.0.8/32
        Local binding: label: 17
        Remote bindings:
            Peer                Label
            -----------------   ---------
            6.0.0.7             17
            6.0.0.8             imp-null
            6.0.0.9             20
            6.0.0.10            20
6.0.0.9/32
        Local binding: label: 18
        Remote bindings:
            Peer                Label
            -----------------   ---------
            6.0.0.7             20
            6.0.0.8             20
            6.0.0.9             imp-null
            6.0.0.10            21
6.0.0.10/32
        Local binding: label: 19
        Remote bindings:
            Peer                Label
            -----------------   ---------
            6.0.0.7             22
            6.0.0.8             21
            6.0.0.9             21
            6.0.0.10            imp-null
10.0.0.0/22
        Local binding: label: imp-null
        No remote bindings
20.0.9.0/24
        Local binding: label: 23
        Remote bindings:
            Peer                Label
            -----------------   ---------
            6.0.0.7             21
            6.0.0.8             22
            6.0.0.9             imp-null
            6.0.0.10            22
20.0.10.0/24
        Local binding: label: 24
        Remote bindings:
            Peer                Label
            -----------------   ---------
            6.0.0.7             23
            6.0.0.8             23
            6.0.0.9             22
            6.0.0.10            imp-null
192.168.0.0/24
        Local binding: label: -
        Remote bindings:
            Peer                Label
            -----------------   ---------
            6.0.0.7             imp-null
            6.0.0.8             imp-null
            6.0.0.9             imp-null
            6.0.0.10            imp-null

superm-redxp-05#



superm-redxp-05# show mpls ldp binding json

{
  "6.0.0.3\/32":{
    "localLabel":"imp-null",
    "remoteLabel":[
      {
        "nexthop":"6.0.0.7",
        "label":"24"
      },
      {
        "nexthop":"6.0.0.8",
        "label":"24"
      },
      {
        "nexthop":"6.0.0.9",
        "label":"23"
      },
      {
        "nexthop":"6.0.0.10",
        "label":"23"
      }
    ]
  },
  "6.0.0.4\/32":{
    "localLabel":"20",
    "remoteLabel":[
      {
        "nexthop":"6.0.0.7",
        "label":"18"
      },
      {
        "nexthop":"6.0.0.8",
        "label":"18"
      },
      {
        "nexthop":"6.0.0.9",
        "label":"16"
      },
      {
        "nexthop":"6.0.0.10",
        "label":"16"
      }
    ]
  },
  "6.0.0.5\/32":{
    "localLabel":"21",
    "remoteLabel":[
      {
        "nexthop":"6.0.0.7",
        "label":"16"
      },
      {
        "nexthop":"6.0.0.8",
        "label":"16"
      },
      {
        "nexthop":"6.0.0.9",
        "label":"17"
      },
      {
        "nexthop":"6.0.0.10",
        "label":"17"
      }
    ]
  },
  "6.0.0.6\/32":{
    "localLabel":"22",
    "remoteLabel":[
      {
        "nexthop":"6.0.0.7",
        "label":"19"
      },
      {
        "nexthop":"6.0.0.8",
        "label":"17"
      },
      {
        "nexthop":"6.0.0.9",
        "label":"18"
      },
      {
        "nexthop":"6.0.0.10",
        "label":"18"
      }
    ]
  },
  "6.0.0.7\/32":{
    "localLabel":"16",
    "remoteLabel":[
      {
        "nexthop":"6.0.0.7",
        "label":"imp-null"
      },
      {
        "nexthop":"6.0.0.8",
        "label":"19"
      },
      {
        "nexthop":"6.0.0.9",
        "label":"19"
      },
      {
        "nexthop":"6.0.0.10",
        "label":"19"
      }
    ]
  },
  "6.0.0.8\/32":{
    "localLabel":"17",
    "remoteLabel":[
      {
        "nexthop":"6.0.0.7",
        "label":"17"
      },
      {
        "nexthop":"6.0.0.8",
        "label":"imp-null"
      },
      {
        "nexthop":"6.0.0.9",
        "label":"20"
      },
      {
        "nexthop":"6.0.0.10",
        "label":"20"
      }
    ]
  },
  "6.0.0.9\/32":{
    "localLabel":"18",
    "remoteLabel":[
      {
        "nexthop":"6.0.0.7",
        "label":"20"
      },
      {
        "nexthop":"6.0.0.8",
        "label":"20"
      },
      {
        "nexthop":"6.0.0.9",
        "label":"imp-null"
      },
      {
        "nexthop":"6.0.0.10",
        "label":"21"
      }
    ]
  },
  "6.0.0.10\/32":{
    "localLabel":"19",
    "remoteLabel":[
      {
        "nexthop":"6.0.0.7",
        "label":"22"
      },
      {
        "nexthop":"6.0.0.8",
        "label":"21"
      },
      {
        "nexthop":"6.0.0.9",
        "label":"21"
      },
      {
        "nexthop":"6.0.0.10",
        "label":"imp-null"
      }
    ]
  },
  "10.0.0.0\/22":{
    "localLabel":"imp-null",
    "remoteLabel":[
    ]
  },
  "20.0.9.0\/24":{
    "localLabel":"23",
    "remoteLabel":[
      {
        "nexthop":"6.0.0.7",
        "label":"21"
      },
      {
        "nexthop":"6.0.0.8",
        "label":"22"
      },
      {
        "nexthop":"6.0.0.9",
        "label":"imp-null"
      },
      {
        "nexthop":"6.0.0.10",
        "label":"22"
      }
    ]
  },
  "20.0.10.0\/24":{
    "localLabel":"24",
    "remoteLabel":[
      {
        "nexthop":"6.0.0.7",
        "label":"23"
      },
      {
        "nexthop":"6.0.0.8",
        "label":"23"
      },
      {
        "nexthop":"6.0.0.9",
        "label":"22"
      },
      {
        "nexthop":"6.0.0.10",
        "label":"imp-null"
      }
    ]
  },
  "192.168.0.0\/24":{
    "localLabel":"-",
    "remoteLabel":[
      {
        "nexthop":"6.0.0.7",
        "label":"imp-null"
      },
      {
        "nexthop":"6.0.0.8",
        "label":"imp-null"
      },
      {
        "nexthop":"6.0.0.9",
        "label":"imp-null"
      },
      {
        "nexthop":"6.0.0.10",
        "label":"imp-null"
      }
    ]
  }
}
superm-redxp-05# 

@dwalton76
Copy link
Copy Markdown
Contributor Author

superm-redxp-05# show mpls ldp discovery 
Local LDP Identifier: 6.0.0.3:0
Discovery Sources:
  Interfaces:
    swp1: xmit/recv
      LDP Id: 6.0.0.7:0, Transport address: 6.0.0.7
          Hold time: 15 sec
    swp2: xmit/recv
      LDP Id: 6.0.0.8:0, Transport address: 6.0.0.8
          Hold time: 15 sec
    swp3: xmit/recv
      LDP Id: 6.0.0.9:0, Transport address: 6.0.0.9
          Hold time: 15 sec
    swp4: xmit/recv
      LDP Id: 6.0.0.10:0, Transport address: 6.0.0.10
          Hold time: 15 sec
  Targeted Hellos:

superm-redxp-05# 
superm-redxp-05# 
superm-redxp-05# show mpls ldp discovery json
{
  "interfaces":{
    "swp1":{
      "transmit":true
    },
    "swp2":{
      "transmit":true
    },
    "swp3":{
      "transmit":true
    },
    "swp4":{
      "transmit":true
    }
  },
  "adjacencyLink":[
    {
      "id":"6.0.0.7",
      "transportAddress":"6.0.0.7",
      "holdtime":15
    },
    {
      "id":"6.0.0.8",
      "transportAddress":"6.0.0.8",
      "holdtime":15
    },
    {
      "id":"6.0.0.9",
      "transportAddress":"6.0.0.9",
      "holdtime":15
    },
    {
      "id":"6.0.0.10",
      "transportAddress":"6.0.0.10",
      "holdtime":15
    }
  ],
  "id":"6.0.0.3"
}
superm-redxp-05# 

@dwalton76
Copy link
Copy Markdown
Contributor Author

superm-redxp-05# show mpls ldp neighbor 
Peer LDP Identifier: 6.0.0.7:0
  TCP connection: 6.0.0.3:646 - 6.0.0.7:44386
  Session Holdtime: 180 sec
  State: OPERATIONAL; Downstream-Unsolicited
  Up time: 00:06:51
  LDP Discovery Sources:
    IPv4:
      Interface: swp1

Peer LDP Identifier: 6.0.0.8:0
  TCP connection: 6.0.0.3:646 - 6.0.0.8:41463
  Session Holdtime: 180 sec
  State: OPERATIONAL; Downstream-Unsolicited
  Up time: 00:06:51
  LDP Discovery Sources:
    IPv4:
      Interface: swp2

Peer LDP Identifier: 6.0.0.9:0
  TCP connection: 6.0.0.3:646 - 6.0.0.9:60726
  Session Holdtime: 180 sec
  State: OPERATIONAL; Downstream-Unsolicited
  Up time: 00:06:51
  LDP Discovery Sources:
    IPv4:
      Interface: swp3

Peer LDP Identifier: 6.0.0.10:0
  TCP connection: 6.0.0.3:646 - 6.0.0.10:39119
  Session Holdtime: 180 sec
  State: OPERATIONAL; Downstream-Unsolicited
  Up time: 00:06:51
  LDP Discovery Sources:
    IPv4:
      Interface: swp4

superm-redxp-05# 
superm-redxp-05# 
superm-redxp-05# show mpls ldp neighbor  json
{
  "6.0.0.7":{
    "peerId":"6.0.0.7",
    "tcpLocalAddress":"6.0.0.3",
    "tcpLocalPort":646,
    "tcpRemoteAddress":"6.0.0.7",
    "tcpRemotePort":44386,
    "holdtime":180,
    "state":"OPERATIONAL",
    "downstreamUnsolicited":true,
    "upTime":"00:06:53",
    "adjacencyLink":[
      "swp1"
    ]
  },
  "6.0.0.8":{
    "peerId":"6.0.0.8",
    "tcpLocalAddress":"6.0.0.3",
    "tcpLocalPort":646,
    "tcpRemoteAddress":"6.0.0.8",
    "tcpRemotePort":41463,
    "holdtime":180,
    "state":"OPERATIONAL",
    "downstreamUnsolicited":true,
    "upTime":"00:06:53",
    "adjacencyLink":[
      "swp2"
    ]
  },
  "6.0.0.9":{
    "peerId":"6.0.0.9",
    "tcpLocalAddress":"6.0.0.3",
    "tcpLocalPort":646,
    "tcpRemoteAddress":"6.0.0.9",
    "tcpRemotePort":60726,
    "holdtime":180,
    "state":"OPERATIONAL",
    "downstreamUnsolicited":true,
    "upTime":"00:06:53",
    "adjacencyLink":[
      "swp3"
    ]
  },
  "6.0.0.10":{
    "peerId":"6.0.0.10",
    "tcpLocalAddress":"6.0.0.3",
    "tcpLocalPort":646,
    "tcpRemoteAddress":"6.0.0.10",
    "tcpRemotePort":39119,
    "holdtime":180,
    "state":"OPERATIONAL",
    "downstreamUnsolicited":true,
    "upTime":"00:06:53",
    "adjacencyLink":[
      "swp4"
    ]
  }
}
superm-redxp-05# 

@dwalton76
Copy link
Copy Markdown
Contributor Author

@rwestphal can you take a look at this one

@rwestphal
Copy link
Copy Markdown
Member

A few additional issues:

1 - There's no "json" option for the L2VPN commands (which are only two by now).

2 - This is the output of "show mpls ldp neighbor json" on my dual-stack ldpd test network:

ubuntu# show mpls ldp neighbor json 
  "3.3.3.3":{
    "peerId":"3.3.3.3",
    "tcpLocalAddress":"2001:db8:1000::2",
    "tcpLocalPort":646,
    "tcpRemoteAddress":"2001:db8:1000::3",
    "tcpRemotePort":42501,
    "holdtime":180,
    "state":"OPERATIONAL",
    "downstreamUnsolicited":true,
    "upTime":"00:00:11",
    "adjacencyLink":[
      "rt2-eth1",
      "rt2-eth1",
      "rt2-eth2",
      "rt2-eth2"
    ]
  },
(...)

We are not showing the address-family of the adjacencies.

I guess we could change this:

"adjacencyLink":[
   "rt2-eth1",
   "rt2-eth1",
   "rt2-eth2",
   "rt2-eth2"
]

To this (*):

"discoverySources":[  
   ipv4:[  
      "interface: rt2-eth1",
      "interface: rt2-eth2",
      "targetedHello: 1.1.1.1"
   ],
   ipv6:[  
      "interface: rt2-eth1",
      "interface: rt2-eth2"
   ]
]

* I introduced one targeted adjacency in the output to show how it would fit in there.

3 - In the same command above, I think we can remove this line from the json output:

"downstreamUnsolicited":true

ldpd supports only this mode of operation (which is not really a limitation), so it's a moot piece of information.

4 - The "show mpls ldp interface json" command is not showing all interface/address-family combinations:

ubuntu# show run
(...)
mpls ldp
(...)
 !
 address-family ipv4
  (...)
  !
  interface rt2-eth0
  !
  interface rt2-eth1
  !
  interface rt2-eth2
  !
 !
 address-family ipv6
  (...)
  !
  interface rt2-eth0
  !
  interface rt2-eth1
  !
  interface rt2-eth2
  !
 !
!
(...)
ubuntu# 
ubuntu# show mpls ldp interface json 
{
  "rt2-eth0":{
    "addressFamily":"ipv6",
    "state":"ACTIVE",
    "uptime":"00:02:40",
    "helloInterval":5,
    "holdtime":15,
    "adjacencyCount":1
  },
  "rt2-eth1":{
    "addressFamily":"ipv6",
    "state":"ACTIVE",
    "uptime":"00:02:40",
    "helloInterval":5,
    "holdtime":15,
    "adjacencyCount":2
  },
  "rt2-eth2":{
    "addressFamily":"ipv6",
    "state":"ACTIVE",
    "uptime":"00:02:40",
    "helloInterval":5,
    "holdtime":15,
    "adjacencyCount":1
  }
}

5 - ldpd segfaults on "show mpls ldp discovery json" if we have any targeted neighbor to display:

ubuntu# show mpls ldp discovery json 
vtysh: error reading from ldpd: Success (0)Warning: closing connection to ldpd because of an I/O error!

@dwalton76
Copy link
Copy Markdown
Contributor Author

For #1 since ldpd/ldp_vty_cmds.c is auto-generated can we

  • delete this file from the repo and add it to .gitignore
  • have the make do tools/xml2cli.pl ldpd/ldp_vty.xml > ldpd/ldp_vty_cmds.c

RIght now with that file checked in it is very easy to overlook the fact that it should not be edited.

I just tried tools/xml2cli.pl ldpd/ldp_vty.xml > ldpd/ldp_vty_cmds.c but xml2cli.pl does not support the "{}" notation so it is creating another DEFUN where the "json" option is present instead of adding a "{json}" to the end of the existing DEFUN. Now that I think about it since this branch has all of Quentin's parser work it would be "[json]". My PERL is pretty rusty though, can you update xml2cli.pl to have it support the new "[]" format?

@dwalton76
Copy link
Copy Markdown
Contributor Author

For #2 the style in all of quagga is a damn mess and is very inconsistent. ldpd is using a style unlike any of the other components :( I'll search and replace all instances of 8 whitespaces and replace them with a TAB though.

@rwestphal
Copy link
Copy Markdown
Member

Yes, I thought about creating a make target for the auto-generated files. But the problem with that is that it would add another dependency to build FRR, which can be a problem on some platforms. So, since ldp_vty.xml is barely changed, I think doing that is not worth the hassle.

Regarding the "{}" notation, indeed. xml2cli.pl was written a few years ago and I need to extended it to make use of this new feature. But having a new command just to add the "json" option should not be a "show stopper", it's only dumb and inefficient. I should have a patch for this in a few hours.

@dwalton76
Copy link
Copy Markdown
Contributor Author

For #3 yeah that would make more sense...will fix this

@dwalton76
Copy link
Copy Markdown
Contributor Author

For #5 (your 2nd #1) right I did not tackle those two for now...we can come back to them later

@dwalton76
Copy link
Copy Markdown
Contributor Author

For #6 ack let me try dual-stack, I did not test that.

@dwalton76
Copy link
Copy Markdown
Contributor Author

Ack #7 will remove "downstreamUnsolicited":true

@dwalton76
Copy link
Copy Markdown
Contributor Author

@rwestphal can you send me your dual-stack config with target neighbors?

@rwestphal
Copy link
Copy Markdown
Member

Sure, will send by email now.

@dwalton76
Copy link
Copy Markdown
Contributor Author

Wow this interface is tough for having multiple conversations...I think if you start a review you can click on "+" to leave a comment and then we can reply to each other. That may be a little easier for both of us :)

Agreed xml2cli.pl isn't a show stopper but if it is something you think you can knock out really quick I'll hold off and wait for it. If not I'm fine with it putting in the extra DEFUNs.

Having xml2cli.pl run as part of the build and removing ldp_vty_cmds.c from the repo seems like a must though. We already depend on PERL for building (extract.pl) so it wouldn't be adding a new dependancy.

Copy link
Copy Markdown
Member

@rwestphal rwestphal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, just clicked on "Add your review". Not really sure if this changes anything regarding the interface for conversation.

Regarding xml2cli.pl. please give me 10 minutes and I should have something ready.

@rwestphal
Copy link
Copy Markdown
Member

@dwalton76 I've just sent to the list a patch to extend xml2cli.pl as you requested.

Now, for each command, you need to modify the XML file as follows:

@@ -272,7 +272,9 @@
    <!-- exec mode commands -->
   <subtree name="ldp_show_af">
-    <option name="binding" help="Label Information Base (LIB) information" function="ldp_vty_show_binding"/>
+    <option name="binding" help="Label Information Base (LIB) information">
+      <option name="json" arg="json" optional="true" help="JavaScript Object Notation" function="ldp_vty_show_binding"/>
+    </option>
     <option name="discovery" help="Discovery Hello Information" function="ldp_vty_show_discovery"/>
     <option name="interface" help="interface information" function="ldp_vty_show_interface"/>
   </subtree>

Then the new output of the script should be exactly what you want:

@@ -1099,15 +1099,20 @@ DEFUN (ldp_show_mpls_ldp_neighbor,
   return ldp_vty_show_neighbor (vty, args);
 }
 
-DEFUN (ldp_show_mpls_ldp_binding,
-       ldp_show_mpls_ldp_binding_cmd,
-       "show mpls ldp binding",
+DEFUN (ldp_show_mpls_ldp_binding_json,
+       ldp_show_mpls_ldp_binding_json_cmd,
+       "show mpls ldp binding [json]",
        "Show running system information\n"
        "MPLS information\n"
        "Label Distribution Protocol\n"
-       "Label Information Base (LIB) information\n")
+       "Label Information Base (LIB) information\n"
+       "JavaScript Object Notation\n")
 {
-  struct vty_arg *args[] = { NULL };
+  struct vty_arg *args[] =
+    {
+      &(struct vty_arg) { .name = "json", .value = (argc > 4 ? argv[4]->arg : NULL) },
+      NULL
+    };
   return ldp_vty_show_binding (vty, args);
 }
 

@donaldsharp
Copy link
Copy Markdown
Member

@dwalton76 and @rwestphal What can I do to help drive this to completion?

@dwalton76
Copy link
Copy Markdown
Contributor Author

sorry, will pick this back up either this week or next and address all of the points that Renato raised

@rwestphal
Copy link
Copy Markdown
Member

I'd say that 95% of the work is already done. @dwalton76, if you don't mind I can update your patch to address the points I mentioned earlier, it's only a few things that need to be changed.

@dwalton76
Copy link
Copy Markdown
Contributor Author

@rwestphal that is fine with me. Thanks!

@abdosi abdosi mentioned this pull request Jan 29, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants