檢查一個 port 上面是否有設定 queue:

ovs-vsctl -- get Port eth1 qos

或是使用以下 script:

ovs-vsctl -- get Port eth1 qos | grep -e '\[\]' &> /dev/null

if [ $? != 0 ]; then
    echo"Qos settings is not empty, please clear it first!"
fi

設定一個 port 上面的 Queue(以 eth0 為例):

ovs-vsctl -- \
set Port eth0 qos=@newqos -- \
--id=@newqos create QoS type=linux-htb \
other-config:max-rate=1000000000 \
queues=0=@q0,1=@q1 -- \
--id=@q0 create Queue \
other-config:min-rate=100000000 \
other-config:max-rate=100000000 -- \
--id=@q1 create Queue \
other-config:min-rate=500000000

上述 script 設定了兩個 queue 給 eth0,分別是 q0 以及 q1,並給予不同的 rate,每一個 qos 組合都會有一組新的 id,這一個 id 是由 OVS 隨機產生的,每一次給予 @newqos 時都會有一組,而一次呼叫就會產生一組,除非把他清掉,否則他都會存在。

如果想要一次新增很多個 port 的話,可以用下面這個 script 來設定:

https://github.com/TakeshiTseng/SDN-Work/blob/master/qos/create_queue.sh

#!/bin/bash
# https://github.com/PeterDaveHello/ColorEchoForShell
if [[ ! -s "ColorEcho.bash" ]]; then
    alias echo.BoldRed='echo'
    alias echo.BoldGreen='echo'
    alias echo.BoldYellow='echo'
else
    . ColorEcho.bash
fi

if [ "$(id -u)" != "0" ]; then
   echo.Red "This script must be run as root" 1>&2
   exit 1
fi

ovs-vsctl -- get Port eth0 qos | grep -e '\[\]' &> /dev/null

if [ $? != 0 ]; then
    echo.Red "Qos settings is not empty, please clear it first!"
    exit 1
fi

echo.Yellow "Setting up queue to $PORTS"
PORTS="eth0 eth1 eth2 eth3"
CMD="ovs-vsctl"

for PORT in $PORTS; do
    CMD="$CMD -- set Port $PORT qos=@newqos"
done

CMD="$CMD -- --id=@newqos create QoS type=linux-htb other-config:max-rate=1000000000 queues=0=@q0,1=@q1"
CMD="$CMD -- --id=@q0 create Queue other-config:min-rate=100000000 other-config:max-rate=100000000"
CMD="$CMD -- --id=@q1 create Queue other-config:min-rate=500000000"

$CMD

echo.Green "Done"

Share Your Thought