Skip to content

Commit 7a3a185

Browse files
Added PHY BCM81724 support for vs in thrift client (#106)
Signed-off-by: Taras Keryk <[email protected]>
1 parent 3e68cae commit 7a3a185

File tree

7 files changed

+259
-0
lines changed

7 files changed

+259
-0
lines changed

common/sai_phy.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class SaiPhy(Sai):
88
def __init__(self, cfg):
99
super().__init__(cfg)
1010
self.switch_oid = "oid:0x0"
11+
self.port_oids = []
1112

1213
def get_switch_id(self):
1314
return self.switch_oid
@@ -31,6 +32,50 @@ def init(self, attr):
3132
self.switch_oid = self.create(SaiObjType.SWITCH, sw_attr)
3233
self.rec2vid[self.switch_oid] = self.switch_oid
3334

35+
# Update PHY SKU
36+
if self.sku_config is not None:
37+
self.set_sku_mode(self.sku_config)
38+
39+
port_num = self.get(self.switch_oid, ["SAI_SWITCH_ATTR_NUMBER_OF_ACTIVE_PORTS", ""]).uint32()
40+
if port_num > 0:
41+
self.port_oids = self.get(self.switch_oid,
42+
["SAI_SWITCH_ATTR_PORT_LIST", self.make_list(port_num, "oid:0x0")]).oids()
43+
44+
def set_sku_mode(self, sku):
45+
port_map = dict()
46+
for port in sku["port"]:
47+
# Create port for system or line side
48+
port_attr = []
49+
alias = port["alias"]
50+
lanes = port["lanes"]
51+
lanes = str(lanes.count(',') + 1) + ":" + lanes
52+
port_attr.extend(["SAI_PORT_ATTR_HW_LANE_LIST", lanes])
53+
54+
# Speed
55+
speed = port["speed"] if "speed" in port else sku["speed"]
56+
port_attr.extend(["SAI_PORT_ATTR_SPEED", speed])
57+
58+
# Autoneg
59+
autoneg = port["autoneg"] if "autoneg" in port else sku.get("autoneg", "off")
60+
autoneg = "true" if autoneg == "on" else "false"
61+
port_attr.extend(["SAI_PORT_ATTR_AUTO_NEG_MODE", autoneg])
62+
63+
# FEC
64+
fec = port["fec"] if "fec" in port else sku.get("fec", "none")
65+
port_attr.extend(["SAI_PORT_ATTR_FEC_MODE", "SAI_PORT_FEC_MODE_" + fec.upper()])
66+
67+
port_map[alias] = self.create(SaiObjType.PORT, port_attr)
68+
69+
for port_connector in sku["connector"]:
70+
# Create port connector
71+
system_port = port_connector["system_side"]
72+
line_port = port_connector["line_side"]
73+
conn_port_oid = self.create(SaiObjType.PORT_CONNECTOR,
74+
[
75+
"SAI_PORT_CONNECTOR_ATTR_SYSTEM_SIDE_PORT_ID", port_map[system_port],
76+
"SAI_PORT_CONNECTOR_ATTR_LINE_SIDE_PORT_ID", port_map[line_port]
77+
])
78+
3479
def cleanup(self):
3580
super().cleanup()
3681

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
FROM sc-base
2+
3+
# Install generic packages
4+
RUN apt-get install -y \
5+
libtemplate-perl \
6+
libconst-fast-perl \
7+
libmoosex-aliases-perl \
8+
libnamespace-autoclean-perl \
9+
libgetopt-long-descriptive-perl \
10+
aspell-en \
11+
bison flex g++ libboost-all-dev libevent-dev libssl-dev \
12+
libthrift-dev libthrift-0.11.0 thrift-compiler
13+
14+
RUN pip3 install ctypesgen thrift==0.11.0
15+
16+
WORKDIR /sai
17+
18+
ENV SAITHRIFTV2=y
19+
ENV platform=vs
20+
21+
## Install Thrift code gen
22+
#RUN wget "http://archive.apache.org/dist/thrift/0.11.0/thrift-0.11.0.tar.gz" \
23+
# && tar -xf thrift-0.11.0.tar.gz \
24+
# && cd thrift-0.11.0 \
25+
# && ./bootstrap.sh \
26+
# && ./configure --prefix=/usr --with-cpp --with-python \
27+
# --with-qt4=no --with-qt5=no --with-csharp=no --with-java=no --with-erlang=no \
28+
# --with-nodejs=no --with-lua=no --with-per=no --with-php=no --with-dart=no \
29+
# --with-ruby=no --with-haskell=no --with-go=no --with-rs=no --with-haxe=no \
30+
# --with-dotnetcore=no --with-d=no \
31+
# && make && make install \
32+
# && pip3 install lib/py \
33+
# && cd /sai \
34+
# && rm -rf thrift-0.11.0 thrift-0.11.0.tar.gz
35+
36+
RUN git clone https://github.com/sonic-net/sonic-sairedis.git \
37+
&& cd sonic-sairedis \
38+
&& . /sai.env \
39+
&& git checkout ${SAIREDIS_ID} \
40+
&& git submodule update --init \
41+
&& cd SAI && git fetch origin \
42+
&& git checkout ${SAI_ID} \
43+
&& cd .. \
44+
# Exclude sairedis tests that require Redis to be running
45+
&& find . -type f -name Makefile.am | xargs sed -ri 's/^TESTS =/# TESTS =/' \
46+
&& ./autogen.sh \
47+
&& dpkg-buildpackage -us -uc -b --target=binary-syncd-vs --jobs=auto \
48+
&& cd .. \
49+
&& dpkg -i libsaimetadata_1.0.0_amd64.deb \
50+
&& dpkg -i libsaimetadata-dev_1.0.0_amd64.deb \
51+
&& dpkg -i libsairedis_1.0.0_amd64.deb \
52+
&& dpkg -i libsaivs_1.0.0_amd64.deb \
53+
&& dpkg -i libsaivs-dev_1.0.0_amd64.deb \
54+
&& dpkg -i syncd-vs_1.0.0_amd64.deb \
55+
&& cd sonic-sairedis/SAI && make saithrift-install \
56+
&& cp meta/saimetadatautils.c /sai/gen_attr_list/ \
57+
&& cp meta/saimetadata.c /sai/gen_attr_list/ \
58+
&& cp meta/saiserialize.c /sai/gen_attr_list/ \
59+
&& mv /sai/sonic-sairedis/tests /sai/ \
60+
&& rm -rf /sai/sonic-sairedis/* \
61+
&& mv /sai/tests /sai/sonic-sairedis/
62+
63+
# Build SAI attributes metadata JSON generator and generate /etc/sai/sai.json
64+
RUN cd /sai/gen_attr_list \
65+
&& mkdir build && cd build \
66+
&& cmake .. \
67+
&& make -j$(nproc) \
68+
&& mkdir -p /etc/sai \
69+
&& ./attr_list_generator > /etc/sai/sai.json.tmp \
70+
&& python -mjson.tool /etc/sai/sai.json.tmp > /etc/sai/sai.json \
71+
&& rm /etc/sai/sai.json.tmp
72+
73+
# Install PTF dependencies
74+
RUN pip3 install pysubnettree
75+
76+
# Setup supervisord
77+
COPY configs/sai.profile /etc/sai.d/sai.profile
78+
COPY configs/supervisord.conf.saithrift /etc/supervisor/conf.d/supervisord.conf
79+
80+
WORKDIR /sai-challenger/tests
81+
82+
CMD ["/usr/bin/supervisord"]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SAI_WARM_BOOT_READ_FILE=/var/cache/sai_warmboot.bin
2+
SAI_WARM_BOOT_WRITE_FILE=/var/cache/sai_warmboot.bin
3+
SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM81724
4+
SAI_VS_SAI_SWITCH_TYPE=SAI_SWITCH_TYPE_PHY
5+
SAI_VS_HOSTIF_USE_TAP_DEVICE=false
6+
SAI_VS_USE_BCMSIM_LINK_MON=true
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[supervisord]
2+
logfile_maxbytes=1MB
3+
logfile_backups=2
4+
nodaemon=true
5+
6+
[eventlistener:dependent-startup]
7+
command=python3 -m supervisord_dependent_startup
8+
autostart=true
9+
autorestart=unexpected
10+
startretries=0
11+
exitcodes=0,3
12+
events=PROCESS_STATE
13+
buffer_size=1024
14+
15+
[program:rsyslogd]
16+
command=/usr/sbin/rsyslogd -n -iNONE
17+
priority=1
18+
autostart=true
19+
autorestart=false
20+
stdout_logfile=syslog
21+
stderr_logfile=syslog
22+
dependent_startup=true
23+
24+
[program:veth-creator]
25+
command=/usr/bin/veth-create.sh
26+
priority=2
27+
startsecs=0
28+
autostart=false
29+
autorestart=false
30+
dependent_startup=true
31+
32+
[program:redis]
33+
command=/usr/bin/redis_start.sh --bind 127.0.0.1 --port 6379
34+
priority=2
35+
autostart=true
36+
autorestart=true
37+
stdout_logfile=syslog
38+
stderr_logfile=syslog
39+
dependent_startup_wait_for=rsyslogd:running
40+
41+
[program:saiserver]
42+
command=/usr/sbin/saiserver -p /etc/sai.d/sai.profile
43+
priority=3
44+
autostart=true
45+
autorestart=true
46+
stdout_logfile=syslog
47+
stderr_logfile=syslog
48+
dependent_startup_wait_for=rsyslogd:running redis:running veth-creator:exited
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"port": [
3+
{"alias": 1, "lanes": "200,201"},
4+
{"alias": 2, "lanes": "202,203"},
5+
{"alias": 3, "lanes": "204,205"},
6+
{"alias": 4, "lanes": "206,207"},
7+
{"alias": 5, "lanes": "208,209,210,211"},
8+
{"alias": 6, "lanes": "212,213,214,215"},
9+
{"alias": 7, "lanes": "216,217,218,219"},
10+
{"alias": 8, "lanes": "220,221,222,223"}
11+
],
12+
"connector": [
13+
{"system_side": 1, "line_side": 5},
14+
{"system_side": 2, "line_side": 6},
15+
{"system_side": 3, "line_side": 7},
16+
{"system_side": 4, "line_side": 8}
17+
],
18+
"autoneg": "off",
19+
"speed": "100000",
20+
"fec": "none"
21+
}

phy/broadcom/sai_phy.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import time
2+
from saichallenger.common.sai_phy import SaiPhy
3+
4+
5+
class SaiPhyImpl(SaiPhy):
6+
7+
def __init__(self, cfg):
8+
super().__init__(cfg)
9+
10+
def reset(self):
11+
self.cleanup()
12+
attr = [
13+
"SAI_SWITCH_ATTR_SWITCH_PROFILE_ID", "0",
14+
"SAI_SWITCH_ATTR_REGISTER_READ", "0",
15+
"SAI_SWITCH_ATTR_REGISTER_WRITE", "0",
16+
"SAI_SWITCH_ATTR_HARDWARE_ACCESS_BUS", "SAI_SWITCH_HARDWARE_ACCESS_BUS_MDIO",
17+
"SAI_SWITCH_ATTR_PLATFROM_CONTEXT", "0"
18+
]
19+
self.init(attr)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
3+
"phy": [
4+
{
5+
"alias": "vs",
6+
"asic": "BCM81724",
7+
"target": "saivs",
8+
"sku": "8x100g",
9+
"client": {
10+
"type": "thrift",
11+
"config": {
12+
"ip": "localhost",
13+
"port": "9092",
14+
"loglevel": "NOTICE"
15+
}
16+
}
17+
}
18+
],
19+
20+
"dataplane": [
21+
{
22+
"alias": "ptf",
23+
"type": "ptf",
24+
"mode": "eth",
25+
"port_groups": [
26+
{"alias": 0, "name": "veth1"},
27+
{"alias": 1, "name": "veth2"},
28+
{"alias": 2, "name": "veth3"},
29+
{"alias": 3, "name": "veth4"},
30+
{"alias": 4, "name": "veth5"},
31+
{"alias": 5, "name": "veth6"},
32+
{"alias": 6, "name": "veth7"},
33+
{"alias": 7, "name": "veth8"}
34+
]
35+
}
36+
]
37+
38+
}

0 commit comments

Comments
 (0)