Skip to content

Commit

Permalink
[sfputil] Move disabling SFP port before LPM set on a SONiC layer
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii savka committed Feb 6, 2018
1 parent 7d9d505 commit 630d636
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 28 deletions.
5 changes: 0 additions & 5 deletions device/mellanox/x86_64-mlnx_msn2100-r0/plugins/sfplpmset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ def get_log_ports(handle, sfp_module):
return log_port_list

def set_sfp_admin_status(handle, meta, sfp_module, sfp_log_port_list, admin_status):
# Set admin status for all log_port of sfp
for log_port in sfp_log_port_list:
rc = sx_api_port_state_set(handle, log_port, admin_status)
assert rc == SX_STATUS_SUCCESS, "sx_api_port_state_set failed, rc = %d" % rc

# Get PMAOS
pmaos = ku_pmaos_reg()
pmaos.module = sfp_module
Expand Down
39 changes: 37 additions & 2 deletions device/mellanox/x86_64-mlnx_msn2100-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,52 @@ def set_low_power_mode(self, port_num, lpmode):
if port_num < self.port_start or port_num > self.port_end:
return False

curr_lpmode = self.get_low_power_mode(port_num)
if curr_lpmode == lpmode:
return True

lpm = 'on' if lpmode else 'off'
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmset.py {} {}".format(port_num, lpm)
sfp_port_names = self.physical_to_logical[port_num]

# Get port admin status
try:
enabled_ports = subprocess.check_output("ip link show up", shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to get ports status, err msg: {}".format(e.output)
return False

port_to_disable = []
for port in sfp_port_names:
if port in enabled_ports:
port_to_disable.append(port)

# Disable ports before LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} down".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to DOWN for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False

time.sleep(3)

# Set LPM
try:
subprocess.check_output(lpm_cmd, shell=True)
return True
except subprocess.CalledProcessError as e:
print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False

return False
# Enable ports after LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} up".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to UP for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False

return True

def reset(self, port_num):
# Check for invalid port_num
Expand Down
5 changes: 0 additions & 5 deletions device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfplpmset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ def get_log_ports(handle, sfp_module):
return log_port_list

def set_sfp_admin_status(handle, meta, sfp_module, sfp_log_port_list, admin_status):
# Set admin status for all log_port of sfp
for log_port in sfp_log_port_list:
rc = sx_api_port_state_set(handle, log_port, admin_status)
assert rc == SX_STATUS_SUCCESS, "sx_api_port_state_set failed, rc = %d" % rc

# Get PMAOS
pmaos = ku_pmaos_reg()
pmaos.module = sfp_module
Expand Down
39 changes: 37 additions & 2 deletions device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,52 @@ def set_low_power_mode(self, port_num, lpmode):
if port_num < self.port_start or port_num > self.port_end:
return False

curr_lpmode = self.get_low_power_mode(port_num)
if curr_lpmode == lpmode:
return True

lpm = 'on' if lpmode else 'off'
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmset.py {} {}".format(port_num, lpm)
sfp_port_names = self.physical_to_logical[port_num]

# Get port admin status
try:
enabled_ports = subprocess.check_output("ip link show up", shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to get ports status, err msg: {}".format(e.output)
return False

port_to_disable = []
for port in sfp_port_names:
if port in enabled_ports:
port_to_disable.append(port)

# Disable ports before LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} down".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to DOWN for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False

time.sleep(3)

# Set LPM
try:
subprocess.check_output(lpm_cmd, shell=True)
return True
except subprocess.CalledProcessError as e:
print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False

return False
# Enable ports after LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} up".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to UP for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False

return True

def reset(self, port_num):
# Check for invalid port_num
Expand Down
5 changes: 0 additions & 5 deletions device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ def get_log_ports(handle, sfp_module):
return log_port_list

def set_sfp_admin_status(handle, meta, sfp_module, sfp_log_port_list, admin_status):
# Set admin status for all log_port of sfp
for log_port in sfp_log_port_list:
rc = sx_api_port_state_set(handle, log_port, admin_status)
assert rc == SX_STATUS_SUCCESS, "sx_api_port_state_set failed, rc = %d" % rc

# Get PMAOS
pmaos = ku_pmaos_reg()
pmaos.module = sfp_module
Expand Down
39 changes: 37 additions & 2 deletions device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,52 @@ def set_low_power_mode(self, port_num, lpmode):
if port_num < self.port_start or port_num > self.port_end:
return False

curr_lpmode = self.get_low_power_mode(port_num)
if curr_lpmode == lpmode:
return True

lpm = 'on' if lpmode else 'off'
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmset.py {} {}".format(port_num, lpm)
sfp_port_names = self.physical_to_logical[port_num]

# Get port admin status
try:
enabled_ports = subprocess.check_output("ip link show up", shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to get ports status, err msg: {}".format(e.output)
return False

port_to_disable = []
for port in sfp_port_names:
if port in enabled_ports:
port_to_disable.append(port)

# Disable ports before LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} down".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to DOWN for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False

time.sleep(3)

# Set LPM
try:
subprocess.check_output(lpm_cmd, shell=True)
return True
except subprocess.CalledProcessError as e:
print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False

return False
# Enable ports after LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} up".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to UP for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False

return True

def reset(self, port_num):
# Check for invalid port_num
Expand Down
5 changes: 0 additions & 5 deletions device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfplpmset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ def get_log_ports(handle, sfp_module):
return log_port_list

def set_sfp_admin_status(handle, meta, sfp_module, sfp_log_port_list, admin_status):
# Set admin status for all log_port of sfp
for log_port in sfp_log_port_list:
rc = sx_api_port_state_set(handle, log_port, admin_status)
assert rc == SX_STATUS_SUCCESS, "sx_api_port_state_set failed, rc = %d" % rc

# Get PMAOS
pmaos = ku_pmaos_reg()
pmaos.module = sfp_module
Expand Down
39 changes: 37 additions & 2 deletions device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,52 @@ def set_low_power_mode(self, port_num, lpmode):
if port_num < self.port_start or port_num > self.port_end:
return False

curr_lpmode = self.get_low_power_mode(port_num)
if curr_lpmode == lpmode:
return True

lpm = 'on' if lpmode else 'off'
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmset.py {} {}".format(port_num, lpm)
sfp_port_names = self.physical_to_logical[port_num]

# Get port admin status
try:
enabled_ports = subprocess.check_output("ip link show up", shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to get ports status, err msg: {}".format(e.output)
return False

port_to_disable = []
for port in sfp_port_names:
if port in enabled_ports:
port_to_disable.append(port)

# Disable ports before LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} down".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to DOWN for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False

time.sleep(3)

# Set LPM
try:
subprocess.check_output(lpm_cmd, shell=True)
return True
except subprocess.CalledProcessError as e:
print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False

return False
# Enable ports after LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} up".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to UP for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False

return True

def reset(self, port_num):
# Check for invalid port_num
Expand Down

0 comments on commit 630d636

Please sign in to comment.