From 1b5255d58308732e9b764427987d5b3e4936fff9 Mon Sep 17 00:00:00 2001
From: lguohan <lguohan@gmail.com>
Date: Wed, 12 Jul 2017 01:27:53 -0700
Subject: [PATCH] add support for Arista-7050-Q16S64 (#798)

---
 .../Arista-7050-Q16S64/port_config.ini        | 57 +++++++++++++++++++
 .../Arista-7050-Q16S64/sai.profile            |  2 +
 .../plugins/led_control.py                    | 15 +++--
 3 files changed, 70 insertions(+), 4 deletions(-)
 create mode 100644 device/arista/x86_64-arista_7050_qx32/Arista-7050-Q16S64/port_config.ini
 create mode 100644 device/arista/x86_64-arista_7050_qx32/Arista-7050-Q16S64/sai.profile

diff --git a/device/arista/x86_64-arista_7050_qx32/Arista-7050-Q16S64/port_config.ini b/device/arista/x86_64-arista_7050_qx32/Arista-7050-Q16S64/port_config.ini
new file mode 100644
index 000000000000..28edbeccf224
--- /dev/null
+++ b/device/arista/x86_64-arista_7050_qx32/Arista-7050-Q16S64/port_config.ini
@@ -0,0 +1,57 @@
+# name          lanes             alias
+Ethernet0       125,126,127,128   Ethernet1/1
+Ethernet4       121,122,123,124   Ethernet2/1
+Ethernet8       13,14,15,16       Ethernet3/1
+Ethernet12      9,10,11,12        Ethernet4/1
+Ethernet16      17,18,19,20       Ethernet5/1
+Ethernet20      21,22,23,24       Ethernet6/1
+Ethernet24      25,26,27,28       Ethernet7/1
+Ethernet28      29,30,31,32       Ethernet8/1
+Ethernet32      37,38,39,40       Ethernet9/1
+Ethernet36      33,34,35,36       Ethernet10/1
+Ethernet40      45,46,47,48       Ethernet11/1
+Ethernet44      41,42,43,44       Ethernet12/1
+Ethernet48      53,54,55,56       Ethernet13/1
+Ethernet52      49,50,51,52       Ethernet14/1
+Ethernet56      69,70,71,72       Ethernet15/1
+Ethernet60      65,66,67,68       Ethernet16/1
+Ethernet64      77                Ethernet17/1
+Ethernet65      78                Ethernet17/2
+Ethernet66      79                Ethernet17/3
+Ethernet67      80                Ethernet17/4
+Ethernet68      73                Ethernet18/1
+Ethernet69      74                Ethernet18/2
+Ethernet70      75                Ethernet18/3
+Ethernet71      76                Ethernet18/4
+Ethernet72      93                Ethernet19/1
+Ethernet73      94                Ethernet19/2
+Ethernet74      95                Ethernet19/3
+Ethernet75      96                Ethernet19/4
+Ethernet76      89                Ethernet20/1
+Ethernet77      90                Ethernet20/2
+Ethernet78      91                Ethernet20/3
+Ethernet79      92                Ethernet20/4
+Ethernet80      101               Ethernet21/1
+Ethernet81      102               Ethernet21/2
+Ethernet82      103               Ethernet21/3
+Ethernet83      104               Ethernet21/4
+Ethernet84      97                Ethernet22/1
+Ethernet85      98                Ethernet22/2
+Ethernet86      99                Ethernet22/3
+Ethernet87      100               Ethernet22/4
+Ethernet88      109               Ethernet23/1
+Ethernet89      110               Ethernet23/2
+Ethernet90      111               Ethernet23/3
+Ethernet91      112               Ethernet23/4
+Ethernet92      105               Ethernet24/1
+Ethernet93      106               Ethernet24/2
+Ethernet94      107               Ethernet24/3
+Ethernet95      108               Ethernet24/4
+Ethernet96      61,62,63,64       Ethernet25
+Ethernet100     57,58,59,60       Ethernet26
+Ethernet104     81,82,83,84       Ethernet27
+Ethernet108     85,86,87,88       Ethernet28
+Ethernet112     117,118,119,120   Ethernet29
+Ethernet116     113,114,115,116   Ethernet30
+Ethernet120     5,6,7,8           Ethernet31
+Ethernet124     1,2,3,4           Ethernet32
diff --git a/device/arista/x86_64-arista_7050_qx32/Arista-7050-Q16S64/sai.profile b/device/arista/x86_64-arista_7050_qx32/Arista-7050-Q16S64/sai.profile
new file mode 100644
index 000000000000..0175b59a5da3
--- /dev/null
+++ b/device/arista/x86_64-arista_7050_qx32/Arista-7050-Q16S64/sai.profile
@@ -0,0 +1,2 @@
+SAI_INIT_CONFIG_FILE=/etc/bcm/td2-a7050-qx32-16x40G+32x10G+8x40G.config.bcm
+SAI_NUM_ECMP_MEMBERS=32
diff --git a/device/arista/x86_64-arista_7050_qx32/plugins/led_control.py b/device/arista/x86_64-arista_7050_qx32/plugins/led_control.py
index 9b8fd2f79186..b7eac3796723 100644
--- a/device/arista/x86_64-arista_7050_qx32/plugins/led_control.py
+++ b/device/arista/x86_64-arista_7050_qx32/plugins/led_control.py
@@ -7,12 +7,14 @@
 
 try:
     from sonic_led.led_control_base import LedControlBase
+    import swsssdk
 except ImportError, e:
     raise ImportError (str(e) + " - required module not found")
 
 
 class LedControl(LedControlBase):
     """Platform specific LED control class"""
+    PORT_TABLE_PREFIX = "PORT_TABLE:"
 
     SONIC_PORT_NAME_PREFIX = "Ethernet"
 
@@ -36,23 +38,28 @@ def _port_name_to_qsfp_index(self, port_name):
 
         sonic_port_num = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):])
 
+        swss = swsssdk.SonicV2Connector()
+        swss.connect(swss.APPL_DB)
+
+        lanes = swss.get(swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
+
         # SONiC port nums are 0-based and increment by 4
         # Arista QSFP indices are 1-based and increment by 1
-        return ((sonic_port_num/4) + 1)
+        return (((sonic_port_num/4) + 1), sonic_port_num%4, len(lanes.split(',')))
 
     # Concrete implementation of port_link_state_change() method
     def port_link_state_change(self, port, state):
-        qsfp_index = self._port_name_to_qsfp_index(port)
+        qsfp_index, lane_index, lanes = self._port_name_to_qsfp_index(port)
         
         # Ignore invalid QSFP indices
-        if qsfp_index <= 0:
+        if qsfp_index <= 0 or lanes <= 0 or lanes > 4:
             return
 
         # QSFP indices 1-24 are breakout-capable and have four LEDs, and each LED indicate one lane.
         # whereas indices 25-32 are not breakout-capable, and only have one
         if qsfp_index <= self.QSFP_BREAKOUT_END_IDX:
             # assuming 40G, then we need to control four lanes
-            led_sysfs_paths = [ self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, i) for i in range(1, 5) ]
+            led_sysfs_paths = [ self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes) ]
         else:
             led_sysfs_paths = [ self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) ]