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

Added files 
crtchild.c - Program which calls the scripts
parent.sh  - Checks the child NS is pinging from ParentNS
child.sh - Checks the Parent NS is pinging from Child NS 
parentns.sh - Sets up the infrastruture to create NS
childns.sh - This sets up the infra reqd from the child NS

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 2 $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
+    echo $status > /tmp/FIFO6
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
+        debug "INFO: 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`;
+    debug "INFO: network dev name received $vnet1";
+    # Assigning the dev addresses
+    ifconfig $vnet1 $IP2/24 up > /dev/null 2>&1
+    ifconfig lo up ; 
+    sleep 2
+    
+    #starting the sshd inside the child NS
+    /usr/sbin/sshd -p $PORT
+    if [ $? == 0 ]; then
+        debug "INFO: 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
+        cleanup $sshpid $vnet1
+        exit $status
+    fi
+    
+    if [ -f  $childscrpt ]; then
+        source $childscrpt
+    fi
+    
+    cleanup $sshpid $vnet1
+    debug "INFO: Done with executing child script $0"
+    
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,24 @@
+#!/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 -q -c 2 $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
+    stat=`cat /tmp/FIFO6`
+    if [ $stat != 0 ] ; then
+        status=$stat
+    fi
+
Index: containers/netns/parentns.sh
===================================================================
--- /dev/null
+++ containers/netns/parentns.sh
@@ -0,0 +1,63 @@
+#!/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
+status=0
+
+    # Checks if any script is passed as argument.
+    if [ $# == 1 ]; then
+        scrpt=$1
+        debug "INFO: 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
+        debug "INFO: vnet0 = $vnet0 , vnet1 = $vnet1"
+    fi
+    sleep 2
+
+    ifconfig $vnet0 $IP1/24 up > /dev/null 2>&1
+    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`
+    debug "INFO: 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
+
+    debug "INFO: status is $status"
+    debug "INFO: Done 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