Skip to content
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

CLI skeletion for VLAN feature: config, show and its templates #129

Merged
merged 5 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/CLI/actioner/sonic-cli-if.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def call_method(name, args):

def generate_body(func, args):
body = None
keypath = []
# Get the rules of all ACL table entries.
if func.__name__ == 'patch_openconfig_interfaces_interfaces_interface_config_description':
keypath = [ args[0] ]
Expand Down Expand Up @@ -98,6 +99,11 @@ def run(func, args):
keypath, body = generate_body(func, args)

try:
# Temporary code for #show vlan command with dummy data
if func.__name__ == "get_openconfig_vlan_interfaces_interface_ethernet_switched_vlan_state":
api_response = {'Vlan100': {'Ethernet20': 'tagged', 'Ethernet40': 'untagged'}}
show_cli_output(args[0], api_response)
return
if body is not None:
api_response = getattr(aa,func.__name__)(*keypath, body=body)
else :
Expand Down
287 changes: 238 additions & 49 deletions src/CLI/clitree/cli-xml/interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,31 @@ limitations under the License.
ptype="SUBCOMMAND"
>
<PARAM
name="counters"
help="Counters for Physical Interfaces"
ptype="SUBCOMMAND"
mode="subcommand"
>
</PARAM>
name="counters"
help="Counters for Physical Interfaces"
ptype="SUBCOMMAND"
mode="subcommand"
>
</PARAM>
<PARAM
name="Ethernet"
help="Physical Interface"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="Ethernet"
help="Physical Interface"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="phy-if-id"
help="Physical interface(Multiples of 4)"
ptype="UINT"
ptype="UINT"
optional="true"
>
</PARAM>
</PARAM>
</PARAM>
<PARAM
name="status"
help="Physical interfaces status"
ptype="SUBCOMMAND"
mode="subcommand"
name="status"
help="Physical interfaces status"
ptype="SUBCOMMAND"
mode="subcommand"
>
</PARAM>
</PARAM>
Expand All @@ -77,33 +77,92 @@ limitations under the License.
fi
</ACTION>
</COMMAND>
<COMMAND
name="show vlan"
help="show vlan commands"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="id"
help="vlan identifier"
ptype="VLAN_ID"
optional="true"
>
</PARAM>
<ACTION>
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_vlan_interfaces_interface_ethernet_switched_vlan_state show_vlan.j2
</ACTION>
</COMMAND>

</VIEW>

<VIEW
name="configure-view"
>
<!-- interface commands -->
<COMMAND
name="interface"
help="Select an interface"
/>

<COMMAND
name="interface"
name="interface Ethernet"
help="Select an interface"
view="configure-if-view"
viewid="iface=Ethernet${phy-if-name}"
>
<PARAM
name="Ethernet"
help="Interface commands"
mode="subcommand"
ptype="SUBCOMMAND"
>
<PARAM
name="phy-if-name"
help="Physical interface(Multiples of 4)"
ptype="UINT"
view="configure-if-view"
viewid="iface=Ethernet${phyifname}"
/>
</PARAM>
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>
>
<PARAM
name="phy-if-name"
help="Physical interface(Multiples of 4)"
ptype="UINT"
>
</PARAM>
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>
<COMMAND
name="interface vlan"
help="Vlan Interface Configuration"
mode="subcommand"
ptype="SUBCOMMAND"
view="configure-vlan-view"
viewid="vlan_id=vlan${vlan-id}"
>
<PARAM
name="vlan-id"
help="Vlan identifier(1-4094)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for not using VLAN_ID ptype?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

ptype="UINT"
>
</PARAM>
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>

<!-- no interface commands -->
<COMMAND
name="no interface"
help="Delete interface"
>
<PARAM
name="if-subcommands"
help="Interface sub-commands"
mode="switch"
ptype="SUBCOMMAND"
>
<PARAM
name="vlan"
help="Delete vlan"
mode="subcommand"
ptype="SUBCOMMAND"
>
<PARAM
name="vlan-id"
help="Vlan identifier(1-4094)"
ptype="UINT"
/>
</PARAM>
</PARAM>
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>
</VIEW>
<VIEW
name="configure-if-view"
Expand All @@ -120,17 +179,7 @@ limitations under the License.
name="no"
help="Negate a command or set its defaults"
/>
<COMMAND
name="shutdown"
help="Disable the interface">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} False </ACTION>
</COMMAND>
<COMMAND
name="no shutdown"
help="Enable the interface">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} True </ACTION>
</COMMAND>
<COMMAND
<COMMAND
name="description"
help="Textual description">
<PARAM
Expand All @@ -153,11 +202,151 @@ limitations under the License.
ptype="RANGE_MTU" />
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} ${mtu} </ACTION>
</COMMAND>
<COMMAND
<COMMAND
name="no mtu"
help="Remove MTU">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} 9100 </ACTION>
</COMMAND>
</VIEW>
<COMMAND
name="shutdown"
help="Disable the interface">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} False </ACTION>
</COMMAND>
<COMMAND
name="no shutdown"
help="Enable the interface">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} True </ACTION>
</COMMAND>
<COMMAND
name="switchport"
help="Configure switchport parameters"
>
<PARAM
name="switchport-subcommands"
help="Switchport subcommands"
ptype="SUBCOMMAND"
mode="switch"
>
<PARAM
name="access"
help="Set access mode characteristics of the interface"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="vlan"
help="Set VLAN when interface is in access mode"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="vlan-id"
help="VLAN ID of the VLAN when this port is in access mode"
ptype="UINT"
>
</PARAM>
</PARAM>
</PARAM>

<PARAM
name="trunk"
help="Configure trunking parameters on an interface"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="allowed"
help="Configure trunking parameters on an interface"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="vlan"
help="Configure trunking parameters on an interface"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="vlan-id"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the help string...it should say trunk mode.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

help="VLAN ID of the VLAN when this port is in access mode"
ptype="UINT"
>
</PARAM>
</PARAM>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the alignment...it's hard to see the tag completions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

</PARAM>
</PARAM>
</PARAM>
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>

<COMMAND
name="no switchport"
help="Remove switchport parameters"
>
<PARAM
name="switchport-subcommands"
help="Switchport subcommands"
ptype="SUBCOMMAND"
mode="switch"
>
<PARAM
name="access"
help="Remove access mode characteristics of the interface"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="vlan"
help="Remove VLAN when interface is in access mode"
ptype="SUBCOMMAND"
mode="subcommand"
>
</PARAM>
</PARAM>

<PARAM
name="trunk"
help="Remove trunking parameters on an interface"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to add this as the MACRO?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will take care of it in the final PR.

ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="allowed"
help="Remove trunking parameters on an interface"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="vlan"
help="Remove trunking parameters on an interface"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="vlan-id"
help="VLAN ID of the VLAN when this port is in access mode"
ptype="UINT"
>
</PARAM>
</PARAM>
</PARAM>
</PARAM>
</PARAM>
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>
</VIEW>

<VIEW
name="configure-vlan-view"
prompt="${SYSTEM_NAME}(conf-if-${vlan_id})# "
depth="2"
>
<!-- Inheritance -->
<NAMESPACE
ref="configure-view"
help="false"
completion="false"
/>
</VIEW>
</CLISH_MODULE>

23 changes: 23 additions & 0 deletions src/CLI/renderer/templates/show_vlan.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% set vars = {'vlanName': ""} %}
{% set vars = {'ifName': ""} %}
{% set vars = {'tagMode': ""} %}
{% set vars = {'tagLetter': ""} %}
{% if json_output -%}
Q: A - Access (Untagged), T - Tagged
{{'%-11s'|format("NUM")}}{{'%-2s'|format("Q Ports")}}
{% for vlanKey, memberEntries in json_output.items() %}
{% if vars.update({'vlanName':vlanKey}) %}{% endif %}
{% for ifKey, ifMode in memberEntries.items() %}
{% if vars.update({'ifName':ifKey}) %}{% endif %}
{% if vars.update({'tagMode':ifMode}) %}{% endif %}
{% if ifMode == "untagged" %}
{% if vars.update({'tagLetter':" U "}) %}{% endif %}
{% else %}
{% if vars.update({'tagLetter':" T "}) %}{% endif %}
{% endif %}
{{'%-10s'|format(vars.vlanName)}}{{'%-2s'|format(vars.tagLetter)}}{{'%-10s'|format(vars.ifName)}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may have to use short form of interface (e.g Eth0 instead of Ethernet0 but this conflicts with "mgmt intf"), we should have the logic to combine multiple intfs in a range and show here.

Copy link
Author

@justinejose91 justinejose91 Sep 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have considered that behavior similar to what we have in OS10. Need more time to investigate inorder to figure it out,I will handle it later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure we follow the below format for "show vlan" output, for example, instead of Vlan100, use just 100 under Num column.

S6K-12# show vlan
Codes: * - Default VLAN, M - Management VLAN, R - Remote Port Mirroring VLANs,
@ ? Attached to Virtual Network
Q: A - Access (Untagged), T - Tagged
NUM Status Description Q Ports

  • 1 Active A Eth1/1/2-1/1/3,1/1/6-1/1/8,1/1/10-1/1/32
    A Po10
    10 Inactive
    20 Inactive
    100 Inactive
    200 Inactive T Eth1/1/10
    S6K-12#

Copy link
Author

@justinejose91 justinejose91 Sep 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will take care of it. Earlier, we didn't had oper-status support.
127.0.0.1:6379> hgetall VLAN_TABLE:Vlan101

  1. "admin_status"
  2. "up"
  3. "mtu"
  4. "9100"
    This is how, it was earlier.
    I think broadcom added the fix for providing oper-status info as well, so I can add that in HLD and final CLI.

{% if vars.update({'vlanName':''}) %}{% endif %}
{% endfor %}
{% endfor %}
{% endif %}