Skip to content

Commit

Permalink
Enhance the y_cable driver to support hook y_cable_simulator_client (#…
Browse files Browse the repository at this point in the history
…153)

In SONiC testbed, y_cable is simulated by OVS in test server. An OVS
bridge is created for each of the y_cable. The PTF interface and
test server VLAN interfaces are attached to the bridge. The VLAN
interfaces are connected to DUT ports through fanout switches.

                          +--------------+
                          |              +----- upper_if
          PTF (host_if) --+  OVS bridge  |
                          |              +----- lower_if
                          +--------------+

Open flow rules are configured for the OVS bridge to simulate upstream
broadcasting and downstream dropping traffic from standby side.

To further simulate y_cable active/standby querying and switching, a
process can be started in the test server. The process needs to expose
APIs for querying and switching active/standby status. When the APIs are
called, the process checks and updates open flow configurations of the
OVS bridge accordingly.

On SONiC side, we need to intercept the calls to y_cable driver and call
the APIs exposed by the process running in test server.

This change is to enhance the y_cable driver to support calling hook
functions defined in y_cable_simulator_client when the module is found.
To do that, a decorator is added to each of the functions in the y_cable
driver. When a y_cable function is called, it firstly checks if module
y_cable_simulator_client is found and the module has function with the
same name. If yes, then call the function of y_cable_simulator_client
and return the result. Otherwise, call the original y_cable driver
function.

Signed-off-by: Xin Wang <[email protected]>
  • Loading branch information
wangxin authored Dec 10, 2020
1 parent fb05b3c commit e6557ac
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion sonic_y_cable/y_cable.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
except ImportError as e:
raise ImportError(str(e) + " - required module not found")

# definitions of the offset with width accomodated for values
# definitions of the offset with width accommodated for values
# of MUX register specs of upper page 0x04 starting at 640
# info eeprom for Y Cable
Y_CABLE_IDENTFIER_LOWER_PAGE = 0
Expand All @@ -40,6 +40,31 @@
helper_logger.log_warning("Failed to load chassis due to {}".format(repr(e)))


def hook_y_cable_simulator(target):
"""Decorator to add hook for calling y_cable_simulator_client.
This decorator updates the y_cable driver functions to call hook functions defined in the y_cable_simulator_client
module if importing the module is successful. If importing the y_cable_simulator_client module failed, just call
the original y_cable driver functions defined in this module.
Args:
target (function): The y_cable driver function to be updated.
"""
def wrapper(*args, **kwargs):
try:
import y_cable_simulator_client
y_cable_func = getattr(y_cable_simulator_client, target.__name__, None)
if y_cable_func and callable(y_cable_func):
return y_cable_func(*args, **kwargs)
else:
return target(*args, **kwargs)
except ImportError:
return target(*args, **kwargs)
wrapper.__name__ = target.__name__
return wrapper


@hook_y_cable_simulator
def toggle_mux_to_torA(physical_port):
"""
This API specifically does a hard switch toggle of the Y cable's MUX regardless of link state to
Expand Down Expand Up @@ -77,6 +102,7 @@ def toggle_mux_to_torA(physical_port):
return result


@hook_y_cable_simulator
def toggle_mux_to_torB(physical_port):
"""
This API specifically does a hard switch toggle of the Y cable's MUX regardless of link state to
Expand Down Expand Up @@ -114,6 +140,7 @@ def toggle_mux_to_torB(physical_port):
return result


@hook_y_cable_simulator
def check_read_side(physical_port):
"""
This API specifically checks which side of the Y cable the reads are actually getting performed
Expand Down Expand Up @@ -181,6 +208,7 @@ def check_read_side(physical_port):
return -1


@hook_y_cable_simulator
def check_mux_direction(physical_port):
"""
This API specifically checks which side of the Y cable mux is currently point to
Expand Down Expand Up @@ -243,6 +271,7 @@ def check_mux_direction(physical_port):
return -1


@hook_y_cable_simulator
def check_active_linked_tor_side(physical_port):
"""
This API specifically checks which side of the Y cable is actively linked and routing
Expand Down Expand Up @@ -309,6 +338,7 @@ def check_active_linked_tor_side(physical_port):
return -1


@hook_y_cable_simulator
def check_if_link_is_active_for_NIC(physical_port):
"""
This API specifically checks if NIC side of the Y cable's link is active
Expand Down Expand Up @@ -363,6 +393,7 @@ def check_if_link_is_active_for_NIC(physical_port):
return False


@hook_y_cable_simulator
def check_if_link_is_active_for_torA(physical_port):
"""
This API specifically checks if TOR A side of the Y cable's link is active
Expand Down Expand Up @@ -418,6 +449,7 @@ def check_if_link_is_active_for_torA(physical_port):
return False


@hook_y_cable_simulator
def check_if_link_is_active_for_torB(physical_port):
"""
This API specifically checks if TOR B side of the Y cable's link is active
Expand Down

0 comments on commit e6557ac

Please sign in to comment.