Skip to content

Commit

Permalink
Management interface cli tree, actioner implementation and sonic yang…
Browse files Browse the repository at this point in the history
… for management port and interface config handling. (#153)
  • Loading branch information
rvasanthm authored and jeff-yin committed Oct 3, 2019
1 parent c1239f3 commit 1043f56
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/CLI/actioner/sonic-cli-if.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ def generate_body(func, args):
elif func.__name__ == 'patch_openconfig_interfaces_interfaces_interface_config_mtu':
keypath = [ args[0] ]
body = { "openconfig-interfaces:mtu": int(args[1]) }
elif func.__name__ == 'patch_openconfig_if_ethernet_interfaces_interface_ethernet_config_auto_negotiate':
keypath = [ args[0] ]
if args[1] == "true":
body = { "openconfig-if-ethernet:auto-negotiate": True }
else :
body = { "openconfig-if-ethernet:auto-negotiate": False }
elif func.__name__ == 'patch_openconfig_if_ethernet_interfaces_interface_ethernet_config_port_speed':
keypath = [ args[0] ]
speed_map = {"10MBPS":"SPEED_10MB", "100MBPS":"SPEED_100MB", "1GIGE":"SPEED_1GB", "auto":"SPEED_1GB" }
if args[1] not in speed_map.keys():
print("%Error: Invalid port speed config")
exit(1)
else:
speed = speed_map.get(args[1])

body = { "openconfig-if-ethernet:port-speed": speed }
elif func.__name__ == 'patch_openconfig_if_ip_interfaces_interface_subinterfaces_subinterface_ipv4_addresses_address_config':
sp = args[1].split('/')
keypath = [ args[0], 0, sp[0] ]
Expand Down
118 changes: 118 additions & 0 deletions src/CLI/clitree/cli-xml/interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ limitations under the License.
>
</PARAM>
</PARAM>
<PARAM
name="Management"
help="Management Interface"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="mgmt-if-id"
help="Management interface id"
ptype="MGMT_INTF_ID"
optional="true"
>
</PARAM>
</PARAM>
<PARAM
name="status"
help="Physical interfaces status"
Expand All @@ -68,6 +82,12 @@ limitations under the License.
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_status.j2 ${__full_line}&#xA;
elif test "${if-subcommands}" = "counters"; then&#xA;
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_counters.j2 ${__full_line}&#xA;
elif test "${if-subcommands}" = "Management"; then&#xA;
if test "${mgmt-if-id}" = ""; then&#xA;
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface.j2 ${__full_line}&#xA;
else&#xA;
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces_interface eth${mgmt-if-id} show_interface_id.j2 ${__full_line}&#xA;
fi&#xA;
else&#xA;
if test "${phy-if-id}" = ""; then&#xA;
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface.j2 ${__full_line}&#xA;
Expand Down Expand Up @@ -136,6 +156,22 @@ limitations under the License.
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>

<COMMAND
name="interface Management"
help="Management Interface commands"
view="configure-if-mgmt-view"
viewid="iface=eth${mgmt-if-id}"
mode="subcommand"
ptype="SUBCOMMAND"
>
<PARAM
name="mgmt-if-id"
help="Management interface"
ptype="MGMT_INTF_ID"
>
</PARAM>
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>
<COMMAND
name="interface vlan"
help="Vlan Interface Configuration"
Expand Down Expand Up @@ -518,5 +554,87 @@ limitations under the License.
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>
</VIEW>
<VIEW
name="configure-if-mgmt-view"
prompt="${SYSTEM_NAME}(conf-if-${iface})# "
depth="2"
>

<NAMESPACE
ref="configure-view"
help="false"
completion="false"
/>
<COMMAND
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
name="description"
help="Textual description">
<PARAM
name="desc"
help="Textual description of the interface"
ptype="STRING" />
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} ${desc} </ACTION>
</COMMAND>
<COMMAND
name="no description"
help="Remove description" >
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} "" </ACTION>
</COMMAND>
<COMMAND
name="mtu"
help="Configure MTU">
<PARAM
name="mtu"
help="MTU of the interface"
ptype="RANGE_MTU" />
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} ${mtu} </ACTION>
</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>
<COMMAND
name="autoneg"
help="Configure autoneg">
<PARAM
name="autoneg"
help="Autoneg config of the interface"
ptype="ON_OFF" />
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_ethernet_interfaces_interface_ethernet_config_auto_negotiate ${iface} ${autoneg} </ACTION>
</COMMAND>
<COMMAND
name="no autoneg"
help="Set default autoneg config">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_ethernet_interfaces_interface_ethernet_config_auto_negotiate ${iface} false </ACTION>
</COMMAND>
<COMMAND
name="speed"
help="Configure speed">
<PARAM
name="speed"
help="Speed config of the interface"
ptype="INTF_SPEED" />
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_ethernet_interfaces_interface_ethernet_config_port_speed ${iface} ${speed} </ACTION>
</COMMAND>
<COMMAND
name="no speed"
help="Set default speed config">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_ethernet_interfaces_interface_ethernet_config_port_speed ${iface} 1000 </ACTION>
</COMMAND>
</VIEW>
</CLISH_MODULE>

38 changes: 37 additions & 1 deletion src/CLI/clitree/cli-xml/ipv4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,42 @@ limitations under the License.
python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_if_ip_interfaces_interface_subinterfaces_subinterface_ipv4_addresses_address_config_prefix_length ${iface} ${addr}
</ACTION>
</COMMAND>
</VIEW>
</VIEW>

<VIEW name="configure-if-mgmt-view">

<COMMAND
name="ip"
help="Interface Internet Protocol config commands"
/>
<COMMAND
name="no ip"
help="Interface Internet Protocol config commands"
>
</COMMAND>

<COMMAND
name="ip address"
help="IP address" >
<PARAM
name="addr"
help="IP address with mask"
ptype="IP_ADDR_MASK" />
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_ip_interfaces_interface_subinterfaces_subinterface_ipv4_addresses_address_config ${iface} ${addr} </ACTION>
</COMMAND>

<COMMAND
name="no ip address"
help="Interface Internet Protocol config commands"
>
<PARAM
name="addr"
help="IP address"
ptype="IP_ADDR" />
<ACTION>
python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_if_ip_interfaces_interface_subinterfaces_subinterface_ipv4_addresses_address_config_prefix_length ${iface} ${addr}
</ACTION>
</COMMAND>
</VIEW>

</CLISH_MODULE>
30 changes: 30 additions & 0 deletions src/CLI/clitree/cli-xml/ipv6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,34 @@ limitations under the License.
</COMMAND>
</VIEW>

<VIEW name="configure-if-mgmt-view">
<COMMAND
name="ipv6"
help="Interface Internet Protocol config commands"
/>
<COMMAND
name="no ipv6"
help="Interface Internet Protocol config commands"
/>
<COMMAND
name="ipv6 address"
help="IPv6 address" >
<PARAM
name="addr"
help="IPv6 address with mask"
ptype="IPV6_ADDR_MASK" />
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_ip_interfaces_interface_subinterfaces_subinterface_ipv6_addresses_address_config ${iface} ${addr} </ACTION>
</COMMAND>

<COMMAND
name="no ipv6 address"
help="IPv6 address" >
<PARAM
name="addr"
help="IPv6 address"
ptype="IPV6_ADDR" />
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_if_ip_interfaces_interface_subinterfaces_subinterface_ipv6_addresses_address_config_prefix_length ${iface} ${addr} </ACTION>
</COMMAND>
</VIEW>

</CLISH_MODULE>
7 changes: 7 additions & 0 deletions src/CLI/clitree/cli-xml/sonic_types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ limitations under the License.
help=""
/>
<!--=======================================================-->
<PTYPE
name="MGMT_INTF_ID"
method="integer"
pattern="0..0"
help=""
/>
<!--=======================================================-->
<PTYPE
name="MIN_LINK"
method="integer"
Expand Down
55 changes: 55 additions & 0 deletions src/cvl/schema/sonic-mgmt-interface.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module sonic-mgmt-interface {
namespace "http://github.com/Azure/sonic-mgmt-interface";
prefix sint;

import ietf-yang-types {
prefix yang;
}

import ietf-inet-types {
prefix inet;
}

import sonic-common {
prefix scommon;
}

import sonic-mgmt-port {
prefix mgmtprt;
}

organization
"DELL";

contact
"DELL";

description
"SONIC MANAGEMENT INTERFACE";

revision 2019-07-02 {
description
"Initial revision.";
}

container sonic-mgmt-interface {
list MGMT_INTERFACE {
key "portname ip_prefix";

leaf portname{
type leafref {
path "/mgmtprt:sonic-mgmt-port/mgmtprt:MGMT_PORT/mgmtprt:ifname";
}
}

leaf ip_prefix {
mandatory true;
type inet:ip-prefix;

}
leaf gwaddr {
type inet:ip-prefix;
}
}
}
}
66 changes: 66 additions & 0 deletions src/cvl/schema/sonic-mgmt-port.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module sonic-mgmt-port {
namespace "http://github.com/Azure/sonic-mgmt-port";
prefix prt;

import ietf-yang-types {
prefix yang;
}

import sonic-common {
prefix scommon;
}

organization
"DELL";

contact
"DELL";

description
"SONIC Management Interface";

revision 2019-09-17 {
description
"Initial revision.";
}


container sonic-mgmt-port {
list MGMT_PORT {
key "ifname";

leaf ifname {
type string {
pattern "eth([1-3][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])"{
error-message "Invalid interface name";
error-app-tag interface-name-invalid;
}
}
}

leaf speed {
type uint64;
}

leaf autoneg {
type boolean;
}

leaf alias {
type string;
}

leaf description {
type string;
}

leaf mtu{
type uint32;
}

leaf admin_status {
type scommon:admin-status;
}
}
}
}

0 comments on commit 1043f56

Please sign in to comment.