Skip to content

Commit 59a511d

Browse files
[config/show] Add CLI support for proxy arp (sonic-net#1168)
* Add `config vlan proxy_arp <vlan id> <enable/disable>` * Add proxy ARP info to `show vlan brief`
1 parent 510d0ad commit 59a511d

File tree

5 files changed

+240
-111
lines changed

5 files changed

+240
-111
lines changed

config/vlan.py

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import click
2-
32
import utilities_common.cli as clicommon
3+
4+
from time import sleep
45
from .utils import log
56

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

54+
def restart_ndppd():
55+
verify_swss_running_cmd = "docker container inspect -f '{{.State.Status}}' swss"
56+
docker_exec_cmd = "docker exec -it swss {}"
57+
ndppd_config_gen_cmd = "sonic-cfggen -d -t /usr/share/sonic/templates/ndppd.conf.j2,/etc/ndppd.conf"
58+
ndppd_restart_cmd = "supervisorctl restart ndppd"
59+
60+
output = clicommon.run_command(verify_swss_running_cmd, return_cmd=True)
61+
62+
if output and output.strip() != "running":
63+
click.echo(click.style('SWSS container is not running, changes will take effect the next time the SWSS container starts', fg='red'),)
64+
return
65+
66+
clicommon.run_command(docker_exec_cmd.format(ndppd_config_gen_cmd), display_cmd=True)
67+
sleep(3)
68+
clicommon.run_command(docker_exec_cmd.format(ndppd_restart_cmd), display_cmd=True)
69+
70+
71+
@vlan.command('proxy_arp')
72+
@click.argument('vid', metavar='<vid>', required=True, type=int)
73+
@click.argument('mode', metavar='<mode>', required=True, type=click.Choice(["enabled", "disabled"]))
74+
@clicommon.pass_db
75+
def config_proxy_arp(db, vid, mode):
76+
"""Configure proxy ARP for a VLAN"""
77+
78+
log.log_info("'setting proxy ARP to {} for Vlan{}".format(mode, vid))
79+
80+
ctx = click.get_current_context()
81+
82+
vlan = 'Vlan{}'.format(vid)
83+
84+
if not clicommon.is_valid_vlan_interface(db.cfgdb, vlan):
85+
ctx.fail("Interface {} does not exist".format(vlan))
86+
87+
db.cfgdb.set_entry('VLAN_INTERFACE', vlan, {"proxy_arp": mode})
88+
click.echo('Proxy ARP setting saved to ConfigDB')
89+
restart_ndppd()
5390
#
5491
# 'member' group ('config vlan member ...')
5592
#

doc/Command-Reference.md

+23-8
Original file line numberDiff line numberDiff line change
@@ -6134,7 +6134,7 @@ Go Back To [Beginning of the document](#) or [Beginning of this section](#System
61346134
61356135
**show vlan brief**
61366136
6137-
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.
6137+
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
61386138
61396139
- Usage:
61406140
```
@@ -6145,13 +6145,13 @@ This command displays brief information about all the vlans configured in the de
61456145
```
61466146
admin@sonic:~$ show vlan brief
61476147
6148-
+-----------+--------------+-----------+----------------+-----------------------+
6149-
| VLAN ID | IP Address | Ports | Port Tagging | DHCP Helper Address |
6150-
+===========+==============+===========+================+=======================+
6151-
| 100 | 1.1.2.2/16 | Ethernet0 | tagged | 192.0.0.1 |
6152-
| | | Ethernet4 | tagged | 192.0.0.2 |
6153-
| | | | | 192.0.0.3 |
6154-
+-----------+--------------+-----------+----------------+-----------------------+
6148+
+-----------+--------------+-----------+----------------+-----------------------+-------------+
6149+
| VLAN ID | IP Address | Ports | Port Tagging | DHCP Helper Address | Proxy ARP |
6150+
+===========+==============+===========+================+=======================+=============+
6151+
| 100 | 1.1.2.2/16 | Ethernet0 | tagged | 192.0.0.1 | disabled |
6152+
| | | Ethernet4 | tagged | 192.0.0.2 | |
6153+
| | | | | 192.0.0.3 | |
6154+
+-----------+--------------+-----------+----------------+-----------------------+-------------+
61556155
```
61566156
61576157
**show vlan config**
@@ -6212,6 +6212,21 @@ This command is to add or delete a member port into the already created vlan.
62126212
This command will add Ethernet4 as member of the vlan 100.
62136213
```
62146214
6215+
**config proxy_arp enabled/disabled**
6216+
6217+
This command is used to enable or disable proxy ARP for a VLAN interface
6218+
6219+
- Usage:
6220+
```
6221+
config vlan proxy_arp <vlan_id> enabled/disabled
6222+
```
6223+
6224+
- Example:
6225+
```
6226+
admin@sonic:~$ sudo config vlan proxy_arp 1000 enabled
6227+
This command will enable proxy ARP for the interface 'Vlan1000'
6228+
```
6229+
62156230
Go Back To [Beginning of the document](#) or [Beginning of this section](#vlan--FDB)
62166231
62176232
### FDB

show/vlan.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def vlan():
1414
@clicommon.pass_db
1515
def brief(db, verbose):
1616
"""Show all bridge information"""
17-
header = ['VLAN ID', 'IP Address', 'Ports', 'Port Tagging', 'DHCP Helper Address']
17+
header = ['VLAN ID', 'IP Address', 'Ports', 'Port Tagging', 'DHCP Helper Address', 'Proxy ARP']
1818
body = []
1919

2020
# Fetching data from config db for VLAN, VLAN_INTERFACE and VLAN_MEMBER
@@ -28,6 +28,7 @@ def brief(db, verbose):
2828
vlan_ip_dict = {}
2929
vlan_ports_dict = {}
3030
vlan_tagging_dict = {}
31+
vlan_proxy_arp_dict = {}
3132

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

4041
# Parsing VLAN Gateway info
4142
for key in natsorted(vlan_ip_data.keys()):
42-
if not clicommon.is_ip_prefix_in_key(key):
43-
continue
44-
interface_key = str(key[0].strip("Vlan"))
45-
interface_value = str(key[1])
46-
if interface_key in vlan_ip_dict:
47-
vlan_ip_dict[interface_key].append(interface_value)
43+
44+
if clicommon.is_ip_prefix_in_key(key):
45+
interface_key = str(key[0].strip("Vlan"))
46+
interface_value = str(key[1])
47+
48+
if interface_key in vlan_ip_dict:
49+
vlan_ip_dict[interface_key].append(interface_value)
50+
else:
51+
vlan_ip_dict[interface_key] = [interface_value]
4852
else:
49-
vlan_ip_dict[interface_key] = [interface_value]
53+
interface_key = str(key.strip("Vlan"))
54+
if 'proxy_arp' in vlan_ip_data[key]:
55+
proxy_arp_status = vlan_ip_data[key]['proxy_arp']
56+
else:
57+
proxy_arp_status = "disabled"
58+
59+
vlan_proxy_arp_dict[interface_key] = proxy_arp_status
60+
61+
5062

5163
iface_alias_converter = clicommon.InterfaceAliasConverter(db)
5264

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

94107
@vlan.command()

0 commit comments

Comments
 (0)