3 # $Id: bulkwalk.t,v 5.1.2.1 2003/02/25 18:10:03 rstory Exp $
5 # Test bulkwalk functionality.
9 unless(grep /blib/, @INC) {
11 @INC = '../lib' if -d '../lib';
15 BEGIN { $num = 62; plan test => $num; }
19 require "t/startagent.pl";
21 use vars qw($agent_port $comm2 $agent_host);
28 ######################################################################
30 $s1 = new SNMP::Session(
31 'DestHost' => $agent_host,
32 'Community' => $comm2,
33 'RemotePort' => $agent_port,
41 ######################################################################
43 # Attempt to use the bulkwalk method to get a few variables from the
46 $vars = new SNMP::VarList ( ['sysUpTime'], ['ifNumber'], # NON-repeaters
47 ['ifSpeed'], ['ifDescr']); # Repeated variables.
49 $expect = scalar @$vars;
50 @list = $s1->bulkwalk(2, 16, $vars);
52 ok($s1->{ErrorNum} == 0);
54 # Did we get back the list of references to returned values?
56 ok(scalar @list == $expect);
58 # Sanity check the returned values. list[0] is sysUptime nonrepeater.
59 ok($list[0][0]->tag eq ".1.3.6.1.2.1.1.3"); # check system.sysUptime OID
60 ok($list[0][0]->iid eq "0"); # check system.sysUptime.0 IID
61 ok($list[0][0]->val =~ m/^\d+$/); # Uptime is numeric
62 ok($list[0][0]->type eq "TICKS"); # Uptime should be in ticks.
64 # Find out how many interfaces to expect. list[1] is ifNumber nonrepeater.
65 ok($list[1][0]->tag eq ".1.3.6.1.2.1.2.1"); # Should be system.ifNumber OID.
66 ok($list[1][0]->iid eq "0"); # system.ifNumber.0 IID.
67 ok($list[1][0]->val =~ m/^\d+$/); # Number is all numeric
68 #XXX: test fails due SMIv1 codes being returned intstead of SMIv2...
69 #ok($list[1][0]->type eq "INTEGER32"); # Number should be integer.
71 $ifaces = $list[1][0]->val;
73 # Make sure we got an ifSpeed for each interface. list[2] is ifSpeed repeater.
74 ok(scalar @{$list[2]} == $ifaces);
76 # Make sure we got an ifDescr for each interface. list[3] is ifDescr repeater.
77 ok(scalar @{$list[3]} == $ifaces);
79 # Test for reasonable values from the agent.
80 ok($list[2][0]->tag eq ".1.3.6.1.2.1.2.2.1.5"); # Should be system.ifSpeed OID.
81 ok($list[2][0]->iid eq "1"); # Instance should be 1.
82 ok($list[2][0]->val =~ m/^\d+$/); # Number is all numeric
83 ok($list[2][0]->type eq "GAUGE"); # Number should be a gauge.
85 ok($list[3][0]->tag eq ".1.3.6.1.2.1.2.2.1.2"); # Should be system.ifDescr OID.
86 ok($list[3][0]->iid eq "1"); # Instance should be 1.
88 # The first interface is probably loopback. Check this.
89 ok($list[3][0]->type eq "OCTETSTR"); # Description is a string.
91 # This might fail for some weird (Windows?) systems. Can be safely ignored.
92 $loopback = $list[3][0]->val;
93 ok(($loopback =~ /^lo/));
95 ###############################################################################
96 # Attempt to use the bulkwalk method to get only non-repeaters
98 $vars = new SNMP::VarList ( ['sysUpTime'], ['ifNumber'] ); # NON-repeaters
100 $expect = scalar @$vars;
101 @list = $s1->bulkwalk(2, 16, $vars);
102 ok($s1->{ErrorNum} == 0);
104 # Did we get back the list of references to returned values?
106 ok(scalar @list == $expect);
108 # Sanity check the returned values. list[0] is sysUptime nonrepeater.
109 ok($list[0][0]->tag eq ".1.3.6.1.2.1.1.3"); # check system.sysUptime OID
110 ok($list[0][0]->iid eq "0"); # check system.sysUptime.0 IID
111 ok($list[0][0]->val =~ m/^\d+$/); # Uptime is numeric
112 ok($list[0][0]->type eq "TICKS"); # Uptime should be in ticks.
114 # Find out how many interfaces to expect. list[1] is ifNumber nonrepeater.
115 ok($list[1][0]->tag eq ".1.3.6.1.2.1.2.1"); # Should be system.ifNumber OID.
116 ok($list[1][0]->iid eq "0"); # system.ifNumber.0 IID.
117 ok($list[1][0]->val =~ m/^\d+$/); # Number is all numeric
118 #XXX: test fails due SMIv1 codes being returned intstead of SMIv2...
119 #ok($list[1][0]->type eq "INTEGER32"); # Number should be integer.
120 $ifaces = $list[1][0]->val;
123 ###############################################################################
124 # Attempt to use the bulkwalk method to get only repeated variables
126 $vars = new SNMP::VarList ( ['ifIndex'], ['ifSpeed'] ); # repeaters
128 $expect = scalar @$vars;
129 @list = $s1->bulkwalk(0, 16, $vars);
130 ok($s1->{ErrorNum} == 0);
132 # Did we get back the list of references to returned values?
134 ok(scalar @list == $expect);
136 # Make sure we got an ifIndex for each interface. list[0] is ifIndex repeater.
137 ok(scalar @{$list[0]} == $ifaces);
139 # Make sure we got an ifSpeed for each interface. list[0] is ifSpeed repeater.
140 ok(scalar @{$list[1]} == $ifaces);
142 # Test for reasonable values from the agent.
143 ok($list[0][0]->tag eq ".1.3.6.1.2.1.2.2.1.1"); # Should be system.ifIndex OID.
144 ok($list[0][0]->iid eq "1"); # Instance should be 1.
145 ok($list[0][0]->val =~ m/^\d+$/); # Number is all numeric
146 #XXX: test fails due SMIv1 codes being returned intstead of SMIv2...
147 #ok($list[0][0]->type eq "INTEGER32"); # Number should be an integer.
149 ok($list[1][0]->tag eq ".1.3.6.1.2.1.2.2.1.5"); # Should be system.ifSpeed OID.
150 ok($list[1][0]->iid eq "1"); # Instance should be 1.
151 ok($list[1][0]->val =~ m/^\d+$/); # Number is all numeric
152 ok($list[1][0]->type eq "GAUGE"); # Number should be a gauge.
154 ######################################################################
155 # Asynchronous Bulkwalk Methods
156 ######################################################################
158 # Attempt to use the bulkwalk method to get a few variables from the
162 my ($vars, $list) = @_;
163 ok(defined $list && ref($list) =~ m/ARRAY/);
164 ok(defined $vars && ref($vars) =~ m/SNMP::VarList/);
166 ok(scalar @$list == scalar @$vars);
170 # Sanity check the returned values. First is sysUptime nonrepeater.
171 $vbr = $list->[0][0];
172 ok($vbr->tag eq ".1.3.6.1.2.1.1.3"); # check system.sysUptime OID
173 ok($vbr->iid eq "0"); # check system.sysUptime.0 IID
174 ok($vbr->val =~ m/^\d+$/); # Uptime is numeric
175 ok($vbr->type eq "TICKS"); # Uptime should be in ticks.
177 # Find out how many interfaces to expect. Next is ifNumber nonrepeater.
178 $vbr = $list->[1][0];
179 ok($vbr->tag eq ".1.3.6.1.2.1.2.1"); # Should be system.ifNumber OID.
180 ok($vbr->iid eq "0"); # system.ifNumber.0 IID.
181 ok($vbr->val =~ m/^\d+$/); # Number is all numeric
182 #XXX: test fails due SMIv1 codes being returned intstead of SMIv2...
183 # ok($vbr->type eq "INTEGER32"); # Number should be integer.
186 # Test for reasonable values from the agent.
187 ok(scalar @{$list->[2]} == $ifaces);
188 $vbr = $list->[2][0];
189 ok($vbr->tag eq ".1.3.6.1.2.1.2.2.1.5"); # Should be ifSpeed OID
190 ok($vbr->iid eq "1"); # Instance should be 1.
191 ok($vbr->val =~ m/^\d+$/); # Number is all numeric
192 ok($vbr->type eq "GAUGE"); # Should be a gauge.
194 ok(scalar @{$list->[3]} == $ifaces);
195 $vbr = $list->[3][0];
196 ok($vbr->tag eq ".1.3.6.1.2.1.2.2.1.2"); # Should be ifDescr OID
197 ok($vbr->iid eq "1"); # Instance should be 1.
199 # The first interface is probably loopback. Check this.
200 ok($vbr->type eq "OCTETSTR");
202 # This might fail for some weird (Windows?) systems. Can be safely ignored.
203 ok(($vbr->val =~ /^lo/));
208 $vars = new SNMP::VarList ( ['sysUpTime'], ['ifNumber'], # NON-repeaters
209 ['ifSpeed'], ['ifDescr']); # Repeated variables.
211 @list = $s1->bulkwalk(2, 16, $vars, [ \&async_cb1, $vars ] );
212 ok($s1->{ErrorNum} == 0);