k8s 的网络topology 探测utils

对于calico来说i,创建的interface都是veth类型

ipnet2dev(){
echo $(ip route | grep $1 | awk '{match($0, /.+dev\s([^ ]*)/, a);print a[1];exit}')
}


devtype(){
echo $(ethtool -i $1| grep "driver:" |awk '{print $2}')
}

# https://unix.stackexchange.com/questions/441876/how-to-find-the-network-namespace-of-a-veth-peer-ifindex
# ifindex=$(nsenter -t $pid -n ip link | sed -n -e 's/.*eth0@if\([0-9]*\):.*/\1/p')

ifindex(){
echo $( ip link | sed -n -e 's/.*'"$1"'@if\([0-9]*\):.*/\1/p')
}

# veth=$(ip -o link | grep ^$ifindex | sed -n -e 's/.*\(veth[[:alnum:]]*@if[[:digit:]]*\).*/\1/p')

vethpeer(){
echo $(ip -o link | grep ^$1 | sed -n -e 's/.*\(veth[[:alnum:]]*@if[[:digit:]]*\).*/\1/p')
}

index2peer(){
for peer in `ls /sys/class/net/`; do
  INDEX=`cat /sys/class/net/$peer/ifindex`
  if [[ $INDEX == $1 ]]; then
    echo $peer 
    return 0
  fi
done
echo "Error, not find peer"
return 1
}


index2peer(){
echo $(ip -o link | grep ^$1 | awk -F'[: ]' '{print $3}')
}

 

上一篇:storm学习-基本概念及入门示例


下一篇:C# 读写ini文件