-
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
Changes from 10 commits
781806f
a26f064
53dde92
ac7549d
bec449c
4fa67ae
0a4e729
674f983
b4f0bbf
cfee553
c20737a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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,84 @@ 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(',') if 'endpoint' in val else [] | ||
if 'endpoint_monitor' in val: | ||
monitors = val.get('endpoint_monitor').split(',') | ||
else: | ||
continue | ||
for idx, endpoint in enumerate(endpoints): | ||
monitor_dict[endpoint] = monitors[idx] | ||
if endpoint not in prefix_count: | ||
prefix_count[endpoint] =0 | ||
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. 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 |
||
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(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os | ||
import sys | ||
import traceback | ||
import mock_tables.dbconnector | ||
from click.testing import CliRunner | ||
from unittest import mock | ||
from utilities_common.db import Db | ||
import show.main as show | ||
|
||
#test_path = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
|
||
class TestShowVnet(object): | ||
@classmethod | ||
def setup_class(cls): | ||
print("SETUP") | ||
os.environ["UTILITIES_UNIT_TESTING"] = "1" | ||
|
||
def test_show_vnet_routes_all_basic(self): | ||
runner = CliRunner() | ||
db = Db() | ||
result = runner.invoke(show.cli.commands['vnet'].commands['routes'].commands['all'], [], obj=db) | ||
assert result.exit_code == 0 | ||
expected_output = """\ | ||
vnet name prefix nexthop interface | ||
----------- -------- --------- ----------- | ||
|
||
vnet name prefix endpoint mac address vni status | ||
--------------- ------------------------ ------------------------------------------- ------------- ----- -------- | ||
Vnet_v6_in_v6-0 fddd:a156:a251::a6:1/128 fddd:a100:a251::a10:1,fddd:a101:a251::a10:1 active | ||
test_v4_in_v4-0 160.162.191.1/32 100.251.7.1 active | ||
test_v4_in_v4-0 160.163.191.1/32 100.251.7.1 active | ||
test_v4_in_v4-0 160.164.191.1/32 100.251.7.1 | ||
""" | ||
assert result.output == expected_output | ||
|
||
def test_show_vnet_endpoint(self): | ||
runner = CliRunner() | ||
db = Db() | ||
result = runner.invoke(show.cli.commands['vnet'].commands['endpoint'], [], obj=db) | ||
assert result.exit_code == 0 | ||
expected_output = """\ | ||
Endpoint prefix count status | ||
--------------------- -------------- -------- | ||
fddd:a100:a251::a10:1 1 Unknown | ||
fddd:a101:a251::a10:1 1 Down | ||
100.251.7.1 3 Up | ||
""" | ||
assert result.output == expected_output | ||
|
||
def test_show_vnet_endpoint_ipv4(self): | ||
runner = CliRunner() | ||
db = Db() | ||
result = runner.invoke(show.cli.commands['vnet'].commands['endpoint'], ['100.251.7.1'], obj=db) | ||
assert result.exit_code == 0 | ||
expected_output = """\ | ||
Endpoint prefix status | ||
----------- ------------------------------------------------------------ -------- | ||
100.251.7.1 ['160.162.191.1/32', '160.163.191.1/32', '160.164.191.1/32'] Up | ||
""" | ||
assert result.output == expected_output | ||
|
||
def test_show_vnet_endpoint_ipv6(self): | ||
runner = CliRunner() | ||
db = Db() | ||
result = runner.invoke(show.cli.commands['vnet'].commands['endpoint'], ['fddd:a101:a251::a10:1'], obj=db) | ||
assert result.exit_code == 0 | ||
expected_output = """\ | ||
Endpoint prefix status | ||
--------------------- ---------------------------- -------- | ||
fddd:a101:a251::a10:1 ['fddd:a156:a251::a6:1/128'] Down | ||
""" | ||
assert result.output == expected_output |
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.
Can we also print the "
endpoint_monitor
" ip so we have a mapping? BFD session just haveendpoint_monitor'
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.
ok
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.
done