Skip to content

Commit

Permalink
[CUMULUS] tools: gdb macro to print zebra rn
Browse files Browse the repository at this point in the history
gdb macro to print route node entry in zebra. Given a pointer to route
node structure in zebra, it prints the contents of route node, get the
rib_dst_t and print the router entires for that route node.

Testing:
(gdb) source ~/zebra_print_route_node
Redefine command "print_route_entry"? (y or n) [answered Y; input not from terminal]
Redefine command "iterate_route_entries"? (y or n) [answered Y; input not from terminal]
Redefine command "print_route_node"? (y or n) [answered Y; input not from terminal]
(gdb) print 0x55958669a0e0
$1 = 94100693557472
(gdb) print_route_node 0x55958669a0e0
Iterating over route entries:
Route Entry:
  NHE: 0x559586699d50
  NHE ID: 114
  NHE Installed ID: 0
  Type: 2
  VRF ID: 0
  Table: 254
  Metric: 0
  MTU: 0
  Nexthop MTU: 0
  Flags: 264
  Status: 2
  Dplane Sequence: 0
  Instance: 0
  Distance: 0
  Tag: 0
  Uptime: 147628904433685
  Opaque: (nil)
(gdb)

Ticket: #4029525
Signed-off-by: Karthikeya Venkat Muppalla <kmuppalla@nvidia.com>
  • Loading branch information
Karthikeya Venkat Muppalla authored and chiragshah6 committed Jan 6, 2025
1 parent fec3f5b commit 6e857e2
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tools/gdb_macros/zebra_print_route_node
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
command to print a single route_entry
define print_route_entry
# Argument is a pointer to route_entry
set $route_entry = (struct route_entry *)$arg0

printf "Route Entry:\n"
printf " NHE: %p\n", $route_entry->nhe
printf " NHE ID: %u\n", $route_entry->nhe_id
printf " NHE Installed ID: %u\n", $route_entry->nhe_installed_id
printf " Type: %d\n", $route_entry->type
printf " VRF ID: %d\n", $route_entry->vrf_id
printf " Table: %u\n", $route_entry->table
printf " Metric: %u\n", $route_entry->metric
printf " MTU: %u\n", $route_entry->mtu
printf " Nexthop MTU: %u\n", $route_entry->nexthop_mtu
printf " Flags: %u\n", $route_entry->flags
printf " Status: %u\n", $route_entry->status
printf " Dplane Sequence: %u\n", $route_entry->dplane_sequence
printf " Instance: %u\n", $route_entry->instance
printf " Distance: %u\n", $route_entry->distance
printf " Tag: %u\n", $route_entry->tag
printf " Uptime: %ld\n", $route_entry->uptime
printf " Opaque: %p\n", $route_entry->opaque
end

# Define a command to iterate over the route_entries for a given rib_dest_t
define iterate_route_entries
# Argument is a pointer to rib_dest_t
set $rib_dest = (rib_dest_t *)$arg0

printf "Iterating over route entries:\n"

# Access the first slist_item in the routes list
set $re_item = $rib_dest->routes.sh.first

# Get the address of the sentinel value
set $sentinel = &typesafe_slist_sentinel

# Loop through all route entries until reaching the sentinel
while $re_item != $sentinel
# Calculate the address of the containing structure from the list item
set $route_entry = (struct route_entry *)((char *)$re_item - (unsigned long)&((struct route_entry *)0)->next)

# Print the current route_entry
print_route_entry $route_entry

# Move to the next item in the list
set $re_item = $re_item->next
end
end

# Define a command to start from a route_node and process its rib_dest_t
define print_route_node
# Argument is a pointer to route_node
set $rnode = (struct route_node *)$arg0

# Retrieve rib_dest_t from route_node
set $rib_dest = (rib_dest_t *)$rnode->info

# Iterate over all route entries
iterate_route_entries $rib_dest
end

# Document the command
document print_route_node
Take a route_node pointer, retrieve the associated rib_dest_t, and print all route_entries.
end

0 comments on commit 6e857e2

Please sign in to comment.