Skip to content

Commit

Permalink
[config/show] Add CLI support for proxy arp (#1168)
Browse files Browse the repository at this point in the history
* Add `config vlan proxy_arp <vlan id> <enable/disable>`
* Add proxy ARP info to `show vlan brief`
  • Loading branch information
theasianpianist authored Oct 20, 2020
1 parent 510d0ad commit 59a511d
Show file tree
Hide file tree
Showing 5 changed files with 240 additions and 111 deletions.
39 changes: 38 additions & 1 deletion config/vlan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click

import utilities_common.cli as clicommon

from time import sleep
from .utils import log

#
Expand Down Expand Up @@ -50,6 +51,42 @@ def del_vlan(db, vid):
db.cfgdb.set_entry('VLAN_MEMBER', k, None)
db.cfgdb.set_entry('VLAN', 'Vlan{}'.format(vid), None)

def restart_ndppd():
verify_swss_running_cmd = "docker container inspect -f '{{.State.Status}}' swss"
docker_exec_cmd = "docker exec -it swss {}"
ndppd_config_gen_cmd = "sonic-cfggen -d -t /usr/share/sonic/templates/ndppd.conf.j2,/etc/ndppd.conf"
ndppd_restart_cmd = "supervisorctl restart ndppd"

output = clicommon.run_command(verify_swss_running_cmd, return_cmd=True)

if output and output.strip() != "running":
click.echo(click.style('SWSS container is not running, changes will take effect the next time the SWSS container starts', fg='red'),)
return

clicommon.run_command(docker_exec_cmd.format(ndppd_config_gen_cmd), display_cmd=True)
sleep(3)
clicommon.run_command(docker_exec_cmd.format(ndppd_restart_cmd), display_cmd=True)


@vlan.command('proxy_arp')
@click.argument('vid', metavar='<vid>', required=True, type=int)
@click.argument('mode', metavar='<mode>', required=True, type=click.Choice(["enabled", "disabled"]))
@clicommon.pass_db
def config_proxy_arp(db, vid, mode):
"""Configure proxy ARP for a VLAN"""

log.log_info("'setting proxy ARP to {} for Vlan{}".format(mode, vid))

ctx = click.get_current_context()

vlan = 'Vlan{}'.format(vid)

if not clicommon.is_valid_vlan_interface(db.cfgdb, vlan):
ctx.fail("Interface {} does not exist".format(vlan))

db.cfgdb.set_entry('VLAN_INTERFACE', vlan, {"proxy_arp": mode})
click.echo('Proxy ARP setting saved to ConfigDB')
restart_ndppd()
#
# 'member' group ('config vlan member ...')
#
Expand Down
31 changes: 23 additions & 8 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -6134,7 +6134,7 @@ Go Back To [Beginning of the document](#) or [Beginning of this section](#System
**show vlan brief**
This command displays brief information about all the vlans configured in the device. It displays the vlan ID, IP address (if configured for the vlan), list of vlan member ports, whether the port is tagged or in untagged mode and the DHCP Helper Address.
This command displays brief information about all the vlans configured in the device. It displays the vlan ID, IP address (if configured for the vlan), list of vlan member ports, whether the port is tagged or in untagged mode, the DHCP Helper Address, and the proxy ARP status
- Usage:
```
Expand All @@ -6145,13 +6145,13 @@ This command displays brief information about all the vlans configured in the de
```
admin@sonic:~$ show vlan brief
+-----------+--------------+-----------+----------------+-----------------------+
| VLAN ID | IP Address | Ports | Port Tagging | DHCP Helper Address |
+===========+==============+===========+================+=======================+
| 100 | 1.1.2.2/16 | Ethernet0 | tagged | 192.0.0.1 |
| | | Ethernet4 | tagged | 192.0.0.2 |
| | | | | 192.0.0.3 |
+-----------+--------------+-----------+----------------+-----------------------+
+-----------+--------------+-----------+----------------+-----------------------+-------------+
| VLAN ID | IP Address | Ports | Port Tagging | DHCP Helper Address | Proxy ARP |
+===========+==============+===========+================+=======================+=============+
| 100 | 1.1.2.2/16 | Ethernet0 | tagged | 192.0.0.1 | disabled |
| | | Ethernet4 | tagged | 192.0.0.2 | |
| | | | | 192.0.0.3 | |
+-----------+--------------+-----------+----------------+-----------------------+-------------+
```
**show vlan config**
Expand Down Expand Up @@ -6212,6 +6212,21 @@ This command is to add or delete a member port into the already created vlan.
This command will add Ethernet4 as member of the vlan 100.
```
**config proxy_arp enabled/disabled**
This command is used to enable or disable proxy ARP for a VLAN interface
- Usage:
```
config vlan proxy_arp <vlan_id> enabled/disabled
```
- Example:
```
admin@sonic:~$ sudo config vlan proxy_arp 1000 enabled
This command will enable proxy ARP for the interface 'Vlan1000'
```
Go Back To [Beginning of the document](#) or [Beginning of this section](#vlan--FDB)
### FDB
Expand Down
31 changes: 22 additions & 9 deletions show/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def vlan():
@clicommon.pass_db
def brief(db, verbose):
"""Show all bridge information"""
header = ['VLAN ID', 'IP Address', 'Ports', 'Port Tagging', 'DHCP Helper Address']
header = ['VLAN ID', 'IP Address', 'Ports', 'Port Tagging', 'DHCP Helper Address', 'Proxy ARP']
body = []

# Fetching data from config db for VLAN, VLAN_INTERFACE and VLAN_MEMBER
Expand All @@ -28,6 +28,7 @@ def brief(db, verbose):
vlan_ip_dict = {}
vlan_ports_dict = {}
vlan_tagging_dict = {}
vlan_proxy_arp_dict = {}

# Parsing DHCP Helpers info
for key in natsorted(vlan_dhcp_helper_data.keys()):
Expand All @@ -39,14 +40,25 @@ def brief(db, verbose):

# Parsing VLAN Gateway info
for key in natsorted(vlan_ip_data.keys()):
if not clicommon.is_ip_prefix_in_key(key):
continue
interface_key = str(key[0].strip("Vlan"))
interface_value = str(key[1])
if interface_key in vlan_ip_dict:
vlan_ip_dict[interface_key].append(interface_value)

if clicommon.is_ip_prefix_in_key(key):
interface_key = str(key[0].strip("Vlan"))
interface_value = str(key[1])

if interface_key in vlan_ip_dict:
vlan_ip_dict[interface_key].append(interface_value)
else:
vlan_ip_dict[interface_key] = [interface_value]
else:
vlan_ip_dict[interface_key] = [interface_value]
interface_key = str(key.strip("Vlan"))
if 'proxy_arp' in vlan_ip_data[key]:
proxy_arp_status = vlan_ip_data[key]['proxy_arp']
else:
proxy_arp_status = "disabled"

vlan_proxy_arp_dict[interface_key] = proxy_arp_status



iface_alias_converter = clicommon.InterfaceAliasConverter(db)

Expand Down Expand Up @@ -88,7 +100,8 @@ def brief(db, verbose):
vlan_tagging = ""
else:
vlan_tagging = ','.replace(',', '\n').join((vlan_tagging_dict[key]))
body.append([key, ip_address, vlan_ports, vlan_tagging, dhcp_helpers])
vlan_proxy_arp = vlan_proxy_arp_dict.get(key, "disabled")
body.append([key, ip_address, vlan_ports, vlan_tagging, dhcp_helpers, vlan_proxy_arp])
click.echo(tabulate(body, header, tablefmt="grid"))

@vlan.command()
Expand Down
Loading

0 comments on commit 59a511d

Please sign in to comment.