File tree Expand file tree Collapse file tree 3 files changed +36
-12
lines changed
Expand file tree Collapse file tree 3 files changed +36
-12
lines changed Original file line number Diff line number Diff line change 1+ source /bp/common.sh
2+
13SCENARIO=" error"
24if [ -f /bp/.scenario ]; then
35 SCENARIO=$( < /bp/.scenario)
@@ -24,13 +26,6 @@ alias _exec='exec'
2426alias help=" /bp/help.sh"
2527alias describe=" /bp/describe.sh"
2628
27- _check_ns (){
28- if ! ip netns list | grep -qw ${1} ; then
29- echo " Invalid namespace: '${1} '"
30- return 1
31- fi
32- }
33-
3429exec (){
3530 if [ -z " ${1:- } " ] || [ -z " ${2:- } " ] ; then
3631 echo " Usage: exec <namespace_name> <command>"
@@ -43,7 +38,7 @@ exec(){
4338}
4439
4540export IGNOREEOF=3
46- exit () {
41+ exit (){
4742 if [ " ${NS} " != " " ]; then
4843 builtin exit ;
4944 fi
@@ -66,7 +61,7 @@ shell(){
6661 ip netns exec ${1} bash --rcfile /bp/.bashrc -i
6762}
6863
69- _shell_completion () {
64+ _shell_completion (){
7065 local cur
7166 cur=" ${COMP_WORDS[COMP_CWORD]} "
7267 local namespaces=($( ip netns list | awk ' {print $1}' ) )
Original file line number Diff line number Diff line change @@ -24,6 +24,35 @@ log_debug(){
2424 _log " DBG" " ${1} "
2525}
2626
27+ # $1 namespace name
28+ _check_ns (){
29+ if ! ${SUDO} ip netns exec ${1} true > /dev/null 2>&1 ; then
30+ log_err " Invalid namespace: '${1} '"
31+ return 1
32+ fi
33+ }
34+
35+ # $1 namespace
36+ # $2 iface
37+ _check_ns_iface (){
38+ if ! ${SUDO} ip netns exec ${1} ip link show dev ${2} > /dev/null 2>&1 ; then
39+ log_err " Invalid iface: '${2} ' in namespace '${1} '!"
40+ return 1
41+ fi
42+
43+ }
44+
45+ # Parses namespace and interface
46+ # and sets them to CMD_NS and CMD_IFACE
47+ # $1 namespace.interface
48+ _parse_ns_iface (){
49+ CMD_NS=" $( echo ${1} | awk -F. ' {print $1}' ) "
50+ CMD_IFACE=" $( echo ${1} | awk -F. ' {print $2}' ) "
51+ echo " Checking ${CMD_NS} and ${CMD_IFACE} "
52+ _check_ns ${CMD_NS}
53+ _check_ns_iface ${CMD_NS} ${CMD_IFACE}
54+ }
55+
2756# $1 namespace name
2857create_ns () {
2958 ${SUDO} ip netns add ${1}
Original file line number Diff line number Diff line change @@ -16,14 +16,14 @@ echo""
1616
1717cat /bp/${SCENARIO} /TOPOLOGY.md
1818echo" "
19- for ns in $( ip netns list | awk ' {print $1}' ) ; do
19+ for ns in $( ${SUDO} ip netns list | awk ' {print $1}' ) ; do
2020 echo " ================================================="
2121 echo -e " \033[1;34mNamespace: $ns \033[0m"
2222 echo " -------------------------------------------------"
2323 echo " IP addressing:"
24- ip netns exec ${ns} ip -brief addr
24+ ${SUDO} ip netns exec ${ns} ip -brief addr
2525 echo " "
2626 echo " Routing table:"
27- ip netns exec ${ns} ip -brief route
27+ ${SUDO} ip netns exec ${ns} ip -brief route
2828 echo -e " \n"
2929done
You can’t perform that action at this time.
0 commit comments