]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/ip/tst.ipv4localudplite.ksh
MFV r362565:
[FreeBSD/FreeBSD.git] / cddl / contrib / opensolaris / cmd / dtrace / test / tst / common / ip / tst.ipv4localudplite.ksh
1 #!/usr/bin/env ksh
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25 #
26
27 #
28 # Test {ip,udplite}:::{send,receive} of IPv4 UDP-Lite to a local address.
29 #
30 # This may fail due to:
31 #
32 # 1. A change to the ip stack breaking expected probe behavior,
33 #    which is the reason we are testing.
34 # 2. No physical network interface is plumbed and up.
35 # 3. No other hosts on this subnet are reachable and listening on rpcbind.
36 # 4. An unlikely race causes the unlocked global send/receive
37 #    variables to be corrupted.
38 #
39 # This test sends a UDP-Lite message using perl and checks that at least the
40 # following counts were traced:
41 #
42 # 1 x ip:::send (UDPLite sent to UDP-Lite port 33434)
43 # 1 x udplite:::send (UDPLite sent to UDP-Lite port 33434)
44 # 1 x ip:::receive (UDP-Lite received)
45 # 1 x udplite:::receive (UDP-Lite received)
46
47 # A udplite:::receive event is expected even if the received UDP-Lite packet
48 # elicits an ICMP PORT_UNREACHABLE message since there is no UDP-Lite
49 # socket for receiving the packet.
50 #
51
52 if (( $# != 1 )); then
53         print -u2 "expected one argument: <dtrace-path>"
54         exit 2
55 fi
56
57 dtrace=$1
58 local=127.0.0.1
59 port=33434
60 DIR=/var/tmp/dtest.$$
61
62 mkdir $DIR
63 cd $DIR
64
65 cat > test.pl <<-EOPERL
66         use IO::Socket;
67         my \$s = IO::Socket::INET->new(
68             Type => SOCK_DGRAM,
69             Proto => "udplite",
70             PeerAddr => "$local",
71             PeerPort => $port);
72         die "Could not create UDP-Lite socket $local port $port" unless \$s;
73         send \$s, "Hello", 0;
74         close \$s;
75         sleep(2);
76 EOPERL
77
78 $dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE
79 BEGIN
80 {
81         ipsend = udplitesend = ipreceive = udplitereceive = 0;
82 }
83
84 ip:::send
85 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
86     args[4]->ipv4_protocol == IPPROTO_UDPLITE/
87 {
88         ipsend++;
89 }
90
91 udplite:::send
92 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local"/
93 {
94         udplitesend++;
95 }
96
97 ip:::receive
98 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
99     args[4]->ipv4_protocol == IPPROTO_UDPLITE/
100 {
101         ipreceive++;
102 }
103
104 udplite:::receive
105 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local"/
106 {
107         udplitereceive++;
108 }
109
110 END
111 {
112         printf("Minimum UDP-Lite events seen\n\n");
113         printf("ip:::send - %s\n", ipsend >= 1 ? "yes" : "no");
114         printf("ip:::receive - %s\n", ipreceive >= 1 ? "yes" : "no");
115         printf("udplite:::send - %s\n", udplitesend >= 1 ? "yes" : "no");
116         printf("udplite:::receive - %s\n", udplitereceive >= 1 ? "yes" : "no");
117 }
118 EODTRACE
119
120 status=$?
121
122 cd /
123 /bin/rm -rf $DIR
124
125 exit $status