Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / perl / SNMP / t / get.t
1 #!./perl
2
3 BEGIN {
4     unless(grep /blib/, @INC) {
5         chdir 't' if -d 't';
6         @INC = '../lib' if -d '../lib';
7     }
8 }
9 use Test;
10 BEGIN { $n = 17; plan tests => $n }
11 use SNMP;
12 use vars qw($agent_port $comm $agent_host);
13 require "t/startagent.pl";
14 $SNMP::debugging = 0;
15 $SNMP::verbose = 0;
16 $SNMP::dump_packet = 0;
17
18 my $junk_oid = ".1.3.6.1.2.1.1.1.1.1.1";
19 my $oid = '.1.3.6.1.2.1.1.1';
20 my $junk_name = 'fooDescr';
21 my $junk_host = 'no.host.here';
22 my $name = "gmarzot\@nortelnetworks.com";
23 my $s1;
24
25 # create list of varbinds for GETS, val field can be null or omitted
26 $vars = new SNMP::VarList (
27                            ['sysDescr', '0', ''],
28                            ['sysObjectID', '0'],
29                            ['sysUpTime', '0'],
30                            ['sysContact', '0'],
31                            ['sysName', '0'],
32                            ['sysLocation', '0'],
33                            ['sysServices', '0'],
34                            ['ifNumber', '0'],
35                            ['ifDescr', '1'],
36                            ['ifSpeed', '1'],
37
38                            ['snmpInPkts', '0'],
39                            ['snmpInBadVersions', '0'],
40                            ['snmpInBadCommunityNames', '0'],
41                            ['snmpInBadCommunityUses', '0'],
42                            ['snmpInASNParseErrs', '0'],
43                            ['snmpEnableAuthenTraps', '0'],
44 #                          ['snmpSilentDrops', '0'],
45 #                          ['snmpProxyDrops', '0'],
46 #                          ['snmpTrapEnterprise', '2'],
47
48 #                          ['hrStorageType', '2'],
49 #                          ['hrSystemDate', '0'],
50 #                          ['sysORIndex', '1'],
51                            ['sysORID', '1'],
52                            ['sysORDescr', '1'],
53                            ['sysORUpTime', '1'],
54 #                          ['ifName', '1'],
55                            ['sysORLastChange', '0'],
56                            ['ipInHdrErrors', '0'],
57                            ['ipDefaultTTL', '0'],
58                            ['ipInHdrErrors', '0'],
59                           );
60 ################################################################
61 # Yet to do:
62 # test for the max limit the 'get' can provide.
63 # Figure out why the IP and Physical address are not getting printed.
64 # why ifname is not getting printed?
65 ################################################################
66 #                          ['ipNetToMediaPhysAddress', '0'],
67 #                          ['ipAdEntAddr', '0'],
68 #                          ['snmpTrapOID', '0'],
69 #                          ['hrSystemNumUsers', '0'],
70 #                          ['hrFSLastFullBackupDate', '0'],
71 #                          ['ifPromiscuousMode', '0'],
72
73
74
75 ######################################################################
76 # Fire up a session.
77     $s1 =
78     new SNMP::Session (DestHost=>$agent_host,Version=>1,Community=>$comm,RemotePort=>$agent_port);
79     ok(defined($s1));
80
81 ######################################################################
82 # Get the standard Vars and check that we got some defined vars back
83 @ret = $s1->get($vars);
84 ok(!$s1->{ErrorStr} and defined($ret[0]));
85 #print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
86 ######################################################################
87 # Check that we got back the number we asked for.
88 ok($#ret == $#{$vars});
89 #print("dude : $#ret\n");
90 ################################################
91
92 # Test for a string
93 $contact = $s1->get('sysContact.0');
94 #print("contact is : $contact\n");
95 ok( defined($contact));
96
97
98 $name = $s1->get('sysName.0');
99 #print("Name is : $name\n");
100 ok( defined($name));
101
102
103 $location = $s1->get('sysLocation.0');
104 #print("Location is : $location\n");
105 ok( defined($location));
106 #########################################
107
108
109 # Test for an integer
110 $ttl = $s1->get('ipDefaultTTL.0');
111 #print("TTL is : $ttl\n");
112 ok( defined($ttl));
113 ########################################
114
115
116 # Test for a TimeTicks
117 $time = $s1->get('sysUpTime.0');
118 #print("up time is : $time hundredths of a second\n");
119 ok( defined($time));
120 #########################################
121
122
123 #Test for a Counter32 type.
124 $totalDatagramsReceived = $s1->get('ipInHdrErrors.0');
125 #print("totalDatagramsReceived is : $totalDatagramsReceived\n");
126 ok( defined($totalDatagramsReceived));
127 ################################################
128
129
130 #Test for a PhysicalAddr type
131 $physaddr = $s1->get('ipNetToMediaPhysAddress.0');
132 #print("physical addr is : $physaddr \n");
133 ok( defined($physaddr));
134 ##############################################
135
136
137 #Test for a IpAddr type
138 $ipaddr = $s1->get('ipAdEntAddr.0');
139 #print("Ip address is : $ipaddr \n");
140 ok( defined($ipaddr));
141 ##############################################
142
143
144 #Test for a OID type
145 $trapOID = $s1->get('snmpTrapOID.0');
146 #print("trap OID is : $trapOID $s1->{ErrorStr}\n");
147 ok( defined($trapOID));
148 ##############################################
149
150
151 #Test for a Gauge type
152 #$numusers = $s1->get('hrSystemNumUsers.0');
153 #print("Number of users is : $numusers \n");
154 #ok( defined($numusers));
155 ##############################################
156
157 #nosuchname
158 #Test for a date & time type
159 #$datetime = $s1->get('hrFSLastFullBackupDate.0');
160 #print("Number of users is : $datetime \n");
161 #ok( defined($datetime));
162 ##############################################
163
164 #nosuchname
165 #Test for a Truth value type
166 #$mode = $s1->get('ifPromiscuousMode.16');
167 #print("Truth value(1 true, 2 false) is : $mode \n");
168 #ok( defined($mode));
169 ##############################################
170
171 # Time stamp test
172 $time = $s1->get('sysORLastChange.0');
173 #print("time stamp is : $time \n");
174 ok(defined($time));
175 #############################################
176
177 # Integer test
178 #$index = $s1->get('sysORIndex.0');
179 #print("index is : $index\n");
180 #ok(defined($index));
181 #############################################
182
183 # OID test
184 $oid = $s1->get('sysORID.1');
185 #print("index is : $oid\n");
186 ok(defined($oid));
187 #############################################
188
189 # String test
190 $descr = $s1->get('sysORDescr.1');
191 #print("Sys Descr is : $descr\n");
192 ok(defined($descr));
193 #############################################
194
195 # string String test
196 $ifname = $s1->get('ifDescr.1');
197 #print("ifname is : $ifname $s1->{ErrorStr}\n");
198 ok(defined($ifname));
199 #############################################
200
201
202 # Try getting some unknown(wrong ?) data
203 $unknown = $s1->get('ifmyData.0');
204 ok(!defined($unknown));
205 ##############################################
206
207
208 snmptest_cleanup();
209
210