-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add CLI Support for IPv6 Helpers and DHCPv6 Relay Counters #8593
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
453d419
Add CLI support for ipv6 helper and DHCPv6 Relay counter
kellyyeh 41cb3c2
Add new lines at the end
kellyyeh 4308fda
Updated naming
kellyyeh 3d257b8
Added code comments and updated docker files
kellyyeh 20424a0
Updated clear counter
kellyyeh 3669d73
Updated show_dhcpv6_helper naming
kellyyeh 97dfa44
Merge branch 'master' of https://github.com/kellyyeh/sonic-buildimage…
kellyyeh dc5ec41
Added cli-plugin-tests
kellyyeh ca16c7a
Update dhcp relay CLI test
kellyyeh 9e6e1ed
Add mock config db
kellyyeh 9abff86
Remove unused import
kellyyeh 35bbde9
Remove unused import
kellyyeh 38a0c9a
Merge show plugins into show_dhcp_relay.py
kellyyeh 057b55d
Add new line at end
kellyyeh 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
23 changes: 23 additions & 0 deletions
23
dockers/docker-dhcp-relay/cli/clear/plugins/dhcp6relay_counter_clear.py
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import click | ||
sys.path.insert(0, '../../show/plugins/') | ||
import show_dhcp6relay_counters | ||
|
||
|
||
# sonic-clear dhcp6relay_counters | ||
@click.command() | ||
@click.option('-i', '--interface', required=False) | ||
@click.option('--verbose', is_flag=True, help="Enable verbose output") | ||
def dhcp6relay_counters(interface, verbose): | ||
"""Clear dhcp6relay message counts""" | ||
|
||
counter = DHCPv6_Counter() | ||
counter_intf = counter.get_interface() | ||
|
||
if interface: | ||
counter.clear_table(interface) | ||
else: | ||
for intf in counter_intf: | ||
counter.clear_table(intf) | ||
|
||
def register(cli): | ||
cli.add_command(dhcp6relay_counters) |
79 changes: 79 additions & 0 deletions
79
dockers/docker-dhcp-relay/cli/show/plugins/show_dhcp6relay_counters.py
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import click | ||
import utilities_common.cli as clicommon | ||
|
||
import argparse | ||
import sys | ||
from tabulate import tabulate | ||
|
||
from swsscommon.swsscommon import SonicV2Connector | ||
|
||
|
||
# STATE_DB Table | ||
DHCPv6_COUNTER_TABLE = 'DHCPv6_COUNTER_TABLE' | ||
|
||
# DHCPv6 Counter Messages | ||
messages = ["Solicit", "Advertise", "Request", "Confirm", "Renew", "Rebind", "Reply", "Release", "Decline", "Relay-Forward", "Relay-Reply"] | ||
|
||
class DHCPv6_Counter(object): | ||
def __init__(self): | ||
self.db = SonicV2Connector(use_unix_socket_path=False) | ||
self.db.connect(self.db.STATE_DB) | ||
self.table_name = DHCPv6_COUNTER_TABLE + self.db.get_db_separator(self.db.STATE_DB) | ||
|
||
|
||
def get_interface(self): | ||
vlans = [] | ||
for key in self.db.keys(self.db.STATE_DB): | ||
if DHCPv6_COUNTER_TABLE in key: | ||
vlans.append(key[21:]) | ||
return vlans | ||
|
||
|
||
def get_dhcp6relay_msg_count(self, interface, msg): | ||
count = self.db.get(self.db.STATE_DB, self.table_name + str(interface), str(msg)) | ||
data = [str(msg), count] | ||
return data | ||
|
||
|
||
def clear_table(self, interface): | ||
for msg in messages: | ||
self.db.set(self.db.STATE_DB, self.table_name + str(interface), str(msg), '0') | ||
|
||
def print_count(counter, intf): | ||
data = [] | ||
for i in messages: | ||
data.append(counter.get_dhcp6relay_msg_count(intf, i)) | ||
print(tabulate(data, headers = ["Message Type", intf], tablefmt='simple', stralign='right') + "\n") | ||
|
||
|
||
# | ||
# 'dhcp6relay_counters' group ### | ||
# | ||
|
||
|
||
@click.group(cls=clicommon.AliasedGroup) | ||
def dhcp6relay_counters(): | ||
"""Show DHCPv6 counter""" | ||
pass | ||
|
||
|
||
# 'counts' subcommand ("show dhcp6relay_counters counts") | ||
@dhcp6relay_counters.command('counts') | ||
@click.option('-i', '--interface', required=False) | ||
@click.option('--verbose', is_flag=True, help="Enable verbose output") | ||
def counts(interface, verbose): | ||
"""Show dhcp6relay message counts""" | ||
|
||
counter = DHCPv6_Counter() | ||
counter_intf = counter.get_interface() | ||
|
||
if interface: | ||
print_count(counter, interface) | ||
else: | ||
for intf in counter_intf: | ||
print_count(counter, intf) | ||
|
||
|
||
def register(cli): | ||
cli.commands['dhcp6realy_counters'].add_command(dhcp6relay_counters) | ||
|
31 changes: 31 additions & 0 deletions
31
dockers/docker-dhcp-relay/cli/show/plugins/show_dhcpv6_helper.py
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import click | ||
from tabulate import tabulate | ||
from swsscommon.swsscommon import ConfigDBConnector | ||
|
||
import utilities_common.cli as clicommon | ||
|
||
DHCP_RELAY = 'DHCP_RELAY' | ||
|
||
@click.group(cls=clicommon.AliasedGroup, name="dhcp_relay_helper") | ||
def dhcp_relay_helper(): | ||
"""Show DHCP_Relay helper information""" | ||
pass | ||
|
||
@dhcp_relay_helper.command('ipv6') | ||
def get_dhcpv6_helper_address(): | ||
config_db = ConfigDBConnector() | ||
if config_db is not None: | ||
config_db.connect() | ||
table_data = config_db.get_table(DHCP_RELAY) | ||
if table_data is not None: | ||
for vlan in config_db.get_keys(DHCP_RELAY): | ||
vlan_data = table_data.get(vlan) | ||
helpers_data = vlan_data.get('dhcpv6_server') | ||
if helpers_data is not None: | ||
addr = {vlan:[]} | ||
for ip in helpers_data.split(','): | ||
addr[vlan].append(ip) | ||
print(tabulate({'Interface':[vlan], vlan:addr.get(vlan)}, tablefmt='simple', stralign='right') + '\n') | ||
|
||
def register(cli): | ||
cli.commands['dhcp_relay_helper'].add_command(dhcp_relay_helper) |
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.
nit: Please add code comment