-
Notifications
You must be signed in to change notification settings - Fork 650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[show] vnet endpoint [ip/ipv6] command #2342
Merged
siqbal1986
merged 11 commits into
sonic-net:master
from
siqbal1986:CLI_vnet_endpoint_ip_addition
Oct 3, 2022
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
781806f
Added support for tunnel route status in show vnet routes all.
siqbal1986 a26f064
typo fix.
siqbal1986 53dde92
created a new Cli command.
siqbal1986 ac7549d
Added a test for the CLI. Fixed a bug.
siqbal1986 bec449c
Updated command reference.
siqbal1986 4fa67ae
Merge branch 'master' into CLI_vnet_route_all_tunnel_route_status_add…
siqbal1986 0a4e729
Merge remote-tracking branch 'origin/CLI_vnet_route_all_tunnel_route_…
siqbal1986 674f983
Gixed a bug and added test coverage.
siqbal1986 b4f0bbf
Merge branch 'master' into CLI_vnet_endpoint_ip_addition
siqbal1986 cfee553
added command reference.
siqbal1986 c20737a
Minor fixes. added endpoint monitor in output as suggested in review.
siqbal1986 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
from natsort import natsorted | ||
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector | ||
from tabulate import tabulate | ||
|
||
import ipaddress | ||
|
||
# | ||
# 'vnet' command ("show vnet") | ||
|
@@ -195,6 +195,81 @@ def neighbors(): | |
if not bool(vnet_intfs): | ||
click.echo(tabulate(table, header)) | ||
|
||
@vnet.command() | ||
@click.argument('args', metavar='[IPADDRESS]', nargs=1, required=False) | ||
def endpoint(args): | ||
"""Show Vxlan tunnel endpoint status""" | ||
"""Specify IPv4 or IPv6 address for detail""" | ||
|
||
state_db = SonicV2Connector() | ||
state_db.connect(state_db.STATE_DB) | ||
appl_db = SonicV2Connector() | ||
appl_db.connect(appl_db.APPL_DB) | ||
filter_by_ip = '' | ||
if args and len(args) > 0: | ||
try: | ||
filter_by_ip = ipaddress.ip_network(args) | ||
except ValueError: | ||
# Not ip address just ignore it | ||
print ("wrong parameter",args) | ||
return | ||
# Fetching data from appl_db for VNET TUNNEL ROUTES | ||
vnet_rt_keys = appl_db.keys(appl_db.APPL_DB, "VNET_ROUTE_TUNNEL_TABLE:*") | ||
vnet_rt_keys = natsorted(vnet_rt_keys) if vnet_rt_keys else [] | ||
bfd_keys = state_db.keys(state_db.STATE_DB, "BFD_SESSION_TABLE|*") | ||
if not filter_by_ip: | ||
header = ['Endpoint', 'prefix count', 'status'] | ||
prefix_count ={} | ||
monitor_dict = {} | ||
table = [] | ||
for k in vnet_rt_keys: | ||
val = appl_db.get_all(appl_db.APPL_DB, k) | ||
endpoints = val.get('endpoint').split(',') | ||
monitors = val.get('endpoint_monitor').split(',') | ||
for idx, endpoint in enumerate(endpoints): | ||
monitor_dict[endpoint] = monitors[idx] | ||
if endpoint not in prefix_count: | ||
prefix_count[endpoint] =0 | ||
prefix_count[endpoint] += 1 | ||
for endpoint in prefix_count: | ||
r = [] | ||
r.append(endpoint) | ||
r.append(prefix_count[endpoint]) | ||
bfd_session_key = "BFD_SESSION_TABLE|default|default|" + monitor_dict[endpoint] | ||
if bfd_session_key in bfd_keys: | ||
val_state = state_db.get_all(state_db.STATE_DB, bfd_session_key) | ||
r.append(val_state.get('state')) | ||
else: | ||
r.append('Unknown') | ||
table.append(r) | ||
else: | ||
table = [] | ||
header = ['Endpoint', 'prefix', 'status'] | ||
state = 'Unknown' | ||
prefix =[] | ||
have_status = False | ||
for k in vnet_rt_keys: | ||
val = appl_db.get_all(appl_db.APPL_DB, k) | ||
endpoints = val.get('endpoint').split(',') | ||
monitors = val.get('endpoint_monitor').split(',') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra space after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
for idx, endpoint in enumerate(endpoints): | ||
if args == endpoint: | ||
prefix.append(k.split(":", 2)[2]) | ||
if not have_status: | ||
bfd_session_key = "BFD_SESSION_TABLE|default|default|" + monitors[idx] | ||
if bfd_session_key in bfd_keys: | ||
val_state = state_db.get_all(state_db.STATE_DB, bfd_session_key) | ||
state = val_state.get('state') | ||
have_status = True | ||
break | ||
if prefix: | ||
r = [] | ||
r.append(args) | ||
r.append(prefix) | ||
r.append(state) | ||
table.append(r) | ||
click.echo(tabulate(table, header)) | ||
|
||
|
||
@vnet.group() | ||
def routes(): | ||
|
@@ -207,7 +282,8 @@ def all(): | |
"""Show all vnet routes""" | ||
appl_db = SonicV2Connector() | ||
appl_db.connect(appl_db.APPL_DB) | ||
|
||
state_db = SonicV2Connector() | ||
state_db.connect(state_db.STATE_DB) | ||
header = ['vnet name', 'prefix', 'nexthop', 'interface'] | ||
|
||
# Fetching data from appl_db for VNET ROUTES | ||
|
@@ -227,7 +303,7 @@ def all(): | |
|
||
click.echo() | ||
|
||
header = ['vnet name', 'prefix', 'endpoint', 'mac address', 'vni'] | ||
header = ['vnet name', 'prefix', 'endpoint', 'mac address', 'vni', 'status'] | ||
|
||
# Fetching data from appl_db for VNET TUNNEL ROUTES | ||
vnet_rt_keys = appl_db.keys(appl_db.APPL_DB, "VNET_ROUTE_TUNNEL_TABLE:*") | ||
|
@@ -237,10 +313,13 @@ def all(): | |
for k in vnet_rt_keys: | ||
r = [] | ||
r.extend(k.split(":", 2)[1:]) | ||
state_db_key = '|'.join(k.split(":",2)) | ||
val = appl_db.get_all(appl_db.APPL_DB, k) | ||
val_state = state_db.get_all(state_db.STATE_DB, state_db_key) | ||
r.append(val.get('endpoint')) | ||
r.append(val.get('mac_address')) | ||
r.append(val.get('vni')) | ||
r.append(val_state.get('state')) | ||
table.append(r) | ||
|
||
click.echo(tabulate(table, header)) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after
=
for consistencyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done