Veerendra wrote:
Hi ,

Please find the patches for the testing of network NS.
The patches are created from the path LTP/testcases/kernel/containers .

Signed-off-by: Veerendra C <[EMAIL PROTECTED]>

This patch consists of the files..

containers/netns/child.sh
containers/netns/childns.sh
containers/netns/crtchild.c
containers/netns/parent.sh
containers/netns/parentns.sh


Regards
Veerendra C

Attaching the patch again

Index: containers/netns/child.sh
===================================================================
--- /dev/null
+++ containers/netns/child.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+# This script checks that the parent namespace is reachable from the child
+# The test case ID, the test case count and the total number of test case
+TCID=${TCID:-child.sh}
+TST_TOTAL=1
+TST_COUNT=1
+export TCID
+export TST_COUNT
+export TST_TOTAL
+
+
+ping -qc 5 $IP1 >  /dev/null 
+
+if [ $? == 0 ] ; then
+    tst_resm TINFO "PASS: Pinging ParentNS from ChildNS"
+    status=0
+else
+    tst_resm TFAIL "FAIL: Unable to ping ParentNS from ChildNS"
+    status=-1
+fi
+#cleanup $sshpid $vnet1
Index: containers/netns/childns.sh
===================================================================
--- /dev/null
+++ containers/netns/childns.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+################################################################################
+# This test scripts passes the PID of the child NS to the parent NS.
+# Also it assigns the device address and starts the sshd daemon
+# It checks for basic network connection between parent and child.
+# It renames the network device of the child 
+
+# Arguments:    Accepts an argument 'script' and executes on top of this
+################################################################################
+#set -x
+# The test case ID, the test case count and the total number of test case
+TCID=${TCID:-childns.sh}
+TST_TOTAL=1
+TST_COUNT=1
+export TCID
+export TST_COUNT
+export TST_TOTAL
+
+source  initialize.sh
+status=0
+
+if [ $# == 1 ] ; then
+    childscrpt=$1
+    tst_resm TINFO "The script to be executed in child NS is $childscrpt"
+fi
+
+# Passing the PID of child 
+echo $$ > /tmp/FIFO1
+
+# waiting for the device name from parent
+vnet1=`cat /tmp/FIFO2`;
+tst_resm TINFO "network dev name received $vnet1";
+# Assigning the dev addresses
+ifconfig $vnet1 $IP2/24 up 
+ifconfig lo up ; 
+sleep 2
+
+#starting the sshd inside the child NS
+/usr/sbin/sshd -p $PORT ;
+if [ $? == 0 ]; then
+    tst_resm TINFO "started the sshd @ port no $PORT"
+    sshpid=`ps -ef | grep "sshd -p $PORT" | awk '{ print $2 ; exit 0} ' `
+else
+    tst_resm TFAIL "Failed in starting ssh @ port $PORT"
+    status=-1
+fi
+
+# checking if parent ns responding
+ping -q -c 2 $IP1 > /dev/null
+if [ $? != 0 ] ; then
+    tst_resm TFAIL "FAIL: ParentNS not responding"
+    status=-1
+    exit $status
+fi
+
+if [ -f  $childscrpt ]; then
+    source $childscrpt
+fi
+
+tst_resm TINFO "Done with executing child script $0"
+exit $status
+
Index: containers/netns/crtchild.c
===================================================================
--- /dev/null
+++ containers/netns/crtchild.c
@@ -0,0 +1,36 @@
+/*************************************************************************
+* Copyright (c) International Business Machines Corp., 2008
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+* the GNU General Public License for more details.
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+***************************************************************************/
+/* ============================================================================
+* This testcase uses the libnetns.c from the library to create network NS.
+* In libnetns.c it uses 2 scripts parentns.sh and childns.sh to create this.
+* After creating the NS, this program verifies that the network is reachable
+* from parent-NS to child-NS and vice-versa.
+*
+* Scripts Used: parentns.sh, childns.sh ,  parent.sh , child.sh.
+* 
+* Author: Veerendra C <[EMAIL PROTECTED]> 
+*                      31/07/2008
+* =============================================================================*/
+
+extern int create_net_namespace(char *, char *);
+
+int main()
+{
+    int status;
+    status = create_net_namespace("parent.sh", "child.sh");
+    return status;
+}
Index: containers/netns/parent.sh
===================================================================
--- /dev/null
+++ containers/netns/parent.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+# This script checks whether child NS is reachable from parent NS.
+
+# The test case ID, the test case count and the total number of test case
+TCID=${TCID:-parent.sh}
+TST_TOTAL=1
+TST_COUNT=1
+export TCID
+export TST_COUNT
+export TST_TOTAL
+
+
+ping -c 5 $IP2 > /dev/null
+if [ $? == 0 ] ; then
+    tst_resm TINFO "PASS: Pinging ChildNS from ParentNS"
+    status=0
+else
+    tst_resm TFAIL "FAIL: Unable to ping ChildNS from ParentNS"
+    status=-1
+fi
Index: containers/netns/parentns.sh
===================================================================
--- /dev/null
+++ containers/netns/parentns.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+################################################################################
+# This script creates 2 veth devices.
+# It will assign $IP1 to vnet0 .
+# And defines the $IP2 as route to vnet1
+# Also it assigns the $vnet1 to child network-NS
+#
+# Arguments:    Accepts an argument 'script' and executes on top of this
+################################################################################
+
+
+# The test case ID, the test case count and the total number of test case
+TCID=${TCID:-parentns.sh}
+TST_TOTAL=1
+TST_COUNT=1
+export TCID
+export TST_COUNT
+export TST_TOTAL
+
+# set -x
+
+source initialize.sh
+DEBUG=1
+status=0
+
+# Checks if any script is passed as argument.
+if [ $# == 1 ]; then
+    scrpt=$1
+    tst_resm TINFO "Script to be executed in parent NS is $scrpt"
+fi
+
+# Sets up the infrastructure for creating network NS
+
+        echo 1 > /proc/sys/net/ipv4/ip_forward
+        echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp
+
+        create_veth
+        vnet0=$dev0
+        vnet1=$dev1
+        if [[ -z $vnet0 || -z $vnet1 ]] ; then
+            tst_resm TFAIL  "Error: unable to create veth pair"
+            exit -1
+        else
+            tst_resm TINFO "vnet0 = $vnet0 , vnet1 = $vnet1"
+        fi
+        sleep 2
+
+        ifconfig $vnet0 $IP1/24 up
+        route add -host $IP2 dev $vnet0
+        echo 1 > /proc/sys/net/ipv4/conf/$vnet0/proxy_arp
+
+        # Waits for the Child-NS to get created and reads the PID
+        pid=`cat /tmp/FIFO1`
+        tst_resm TINFO "the pid of child is $pid"
+        ip link set $vnet1 netns $pid
+
+        # Passes the device name to Child NS
+        echo $vnet1 > /tmp/FIFO2
+
+# Executes the script if it is passed as an argument.
+if [ -f $scrpt ] ;  then
+    source $scrpt
+fi
+tst_resm TINFO " Done with executing parent script $0 "
+exit $status
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to