Signed-off-by: Alexey Kodanev <alexey.koda...@oracle.com>
---
v2: replace TST_EXEC_SUFFIX with TST_IPV6

 testcases/lib/test_net.sh |   47 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index b6d4e7d..f8f3f61 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -174,3 +174,50 @@ tst_ipaddr()
                echo "${IPV4_NETWORK}.${tst_host}"
        fi
 }
+
+# tst_init_iface [TYPE] [LINK]
+# TYPE: { lhost | rhost }; Default value is 'lhost'.
+# LINK: link number starting from 0. Default value is '0'.
+tst_init_iface()
+{
+       local type=${1:-"lhost"}
+       local link_num=${2:-"0"}
+
+       local iface=$(tst_iface $type $link_num)
+       tst_resm TINFO "initialize '$type' '$iface' interface"
+
+       if [ "$type" = "lhost" ]; then
+               ip link set $iface down || tst_brkm TBROK "interface down 
failed"
+               ip route flush dev $iface || tst_brkm TBROK "route flush failed"
+               ip addr flush dev $iface || tst_brkm TBROK "addr flush failed"
+               ip link set $iface up || tst_brkm TBROK "interface up failed"
+       else
+               tst_rhost_run -s -c "ip link set $iface down"
+               tst_rhost_run -s -c "ip route flush dev $iface"
+               tst_rhost_run -s -c "ip addr flush dev $iface"
+               tst_rhost_run -s -c "ip link set $iface up"
+       fi
+}
+
+# tst_set_ipaddr [LINK]
+# LINK: link number starting from 0. Default value is '0'.
+tst_set_ipaddr()
+{
+       local link_num=${1:-"0"}
+       local ipv=${TST_IPV6:-"4"}
+
+       tst_init_iface lhost $link_num
+       tst_init_iface rhost $link_num
+
+       local iface=$(tst_iface $type $link_num)
+
+       local mask=24
+       [ "$TST_IPV6" ] && mask=64
+
+       tst_resm TINFO "set local ipv${ipv} addr $(tst_ipaddr)/$mask"
+       ip addr add $(tst_ipaddr)/$mask dev $iface || \
+               tst_brkm TBROK "failed to add IP address"
+
+       tst_resm TINFO "set remote ipv${ipv} addr $(tst_ipaddr rhost)/$mask"
+       tst_rhost_run -s -c "ip addr add $(tst_ipaddr rhost)/$mask dev $iface"
+}
-- 
1.7.1


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to