@@ -22,12 +22,99 @@ get_hwsku() {
22
22
echo " ${HWSKU} "
23
23
}
24
24
25
+ bind_ports_to_ns () {
26
+ PLATFORM=" $1 "
27
+ HWSKU=" $2 "
28
+ BIND=" $3 "
29
+
30
+ # Check if the directory exists
31
+ if [[ ! -d " /usr/share/sonic/device/$PLATFORM /$HWSKU " ]]; then
32
+ echo " Directory /usr/share/sonic/device/$PLATFORM /$HWSKU does not exist"
33
+ exit 1
34
+ fi
35
+
36
+ # Read NUM_ASIC from asic.conf file
37
+ asic_conf=" /usr/share/sonic/device/$PLATFORM /asic.conf"
38
+ if [[ ! -f " $asic_conf " ]]; then
39
+ echo " Error: $asic_conf file not found"
40
+ exit 1
41
+ fi
42
+
43
+ # Read NUM_ASIC from asic.conf file
44
+ num_asic=$( awk -F " =" ' /^NUM_ASIC=/ {print $2}' " $asic_conf " )
45
+ if [[ -z $num_asic ]]; then
46
+ echo " NUM_ASIC not found in $asic_conf "
47
+ exit 1
48
+ fi
49
+
50
+ for (( asic_num = 0 ; asic_num < num_asic; asic_num++ )) ; do
51
+ echo " Processing $PLATFORM /$HWSKU /$asic_num "
52
+ asic_dir=" /usr/share/sonic/device/$PLATFORM /$HWSKU /$asic_num "
53
+
54
+ # Check if the directory exists for the ASIC number
55
+ if [[ ! -d " $asic_dir " ]]; then
56
+ echo " Directory $asic_dir does not exist"
57
+ exit 1
58
+ fi
59
+
60
+ lanemap_ini=" $asic_dir /lanemap.ini"
61
+
62
+ if [[ ! -f " $lanemap_ini " ]]; then
63
+ echo " lanemap.ini not found in $asic_dir "
64
+ exit 1
65
+ fi
66
+
67
+ # Loop through each line of lanemap.ini
68
+ while IFS= read -r line; do
69
+ # Extract interface before ":"
70
+ intf=$( echo " $line " | cut -d " :" -f 1)
71
+ if [[ $BIND == true ]]; then
72
+ echo " Moving interface $intf to asic$asic_num "
73
+ if [[ $intf == " Cpu0" ]]; then
74
+ # Extract the numeric part of the interface name
75
+ num=" ${prev# eth} "
76
+ # Increment the numeric part
77
+ (( num++ ))
78
+ # Construct the new interface name
79
+ cur=" eth$num "
80
+ echo " Renaming $cur to $intf "
81
+ ip link sev dev $cur down
82
+ ip link set dev $cur name $intf
83
+ fi
84
+ ip link set dev $intf netns asic$asic_num
85
+ sudo ip netns exec asic$asic_num ip link set dev $intf mtu 9100
86
+ sudo ip netns exec asic$asic_num ip link set $intf up
87
+ else
88
+ echo " Moving interface $intf back to default ns"
89
+ sudo ip netns exec asic$asic_num ip link set dev $intf netns 1
90
+ if [[ $intf == " Cpu0" ]]; then
91
+ # Extract the numeric part of the interface name
92
+ num=" ${prev# eth} "
93
+ # Increment the numeric part
94
+ (( num++ ))
95
+ # Construct the new interface name
96
+ cur=" eth$num "
97
+ echo " Renaming $intf to $cur "
98
+ ip link set dev $intf down
99
+ ip link set dev $intf name $cur
100
+ ip link set dev $cur up
101
+ fi
102
+ fi
103
+ prev=$intf
104
+ done < " $lanemap_ini "
105
+ done
106
+ exit 0 # Exit script with success
107
+ }
108
+
109
+
25
110
start () {
26
111
TOPOLOGY_SCRIPT=" topology.sh"
27
112
PLATFORM=` sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
28
113
HWSKU=` get_hwsku`
29
- if [[ $HWSKU != " " ]]; then
114
+ if [[ $HWSKU == " msft_ " * ]]; then
30
115
/usr/share/sonic/device/$PLATFORM /$HWSKU /$TOPOLOGY_SCRIPT start
116
+ elif [[ $HWSKU != " " ]]; then
117
+ bind_ports_to_ns " $PLATFORM " " $HWSKU " true
31
118
else
32
119
echo " Failed to get HWSKU"
33
120
exit 1
@@ -38,8 +125,10 @@ stop() {
38
125
TOPOLOGY_SCRIPT=" topology.sh"
39
126
PLATFORM=` sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
40
127
HWSKU=` get_hwsku`
41
- if [[ $HWSKU != " " ]]; then
128
+ if [[ $HWSKU == " msft_ " * ]]; then
42
129
/usr/share/sonic/device/$PLATFORM /$HWSKU /$TOPOLOGY_SCRIPT stop
130
+ elif [[ $HWSKU != " " ]]; then
131
+ bind_ports_to_ns " $PLATFORM " " $HWSKU " false
43
132
else
44
133
echo " Failed to get HWSKU"
45
134
exit 1
0 commit comments