~ubuntu-branches/ubuntu/trusty/net-snmp/trusty

« back to all changes in this revision

Viewing changes to perl/SNMP/t/set.t

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-13 12:06:21 UTC
  • Revision ID: james.westby@ubuntu.com-20040913120621-g952ntonlleihcvm
Tags: upstream-5.1.1
ImportĀ upstreamĀ versionĀ 5.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 { plan tests => 7 }
 
11
use SNMP;
 
12
use vars qw($agent_port $comm $agent_host);
 
13
require "t/startagent.pl";
 
14
 
 
15
 
 
16
my $junk_oid = ".1.3.6.1.2.1.1.1.1.1.1";
 
17
my $oid = ".1.3.6.1.2.1.1.1";
 
18
my $junk_name = 'fooDescr';
 
19
my $junk_host = 'no.host.here';
 
20
my $name = "gmarzot\@nortelnetworks.com";
 
21
 
 
22
$SNMP::debugging = 0;
 
23
$n = 15;  # Number of tests to run
 
24
 
 
25
#print "1..$n\n";
 
26
if ($n == 0) { exit 0; }
 
27
 
 
28
# create list of varbinds for GETS, val field can be null or omitted
 
29
my $vars = new SNMP::VarList (
 
30
                           ['sysDescr', '0', ''],
 
31
                           ['sysObjectID', '0'],
 
32
                           ['sysUpTime', '0'],
 
33
                           ['sysContact', '0'],
 
34
                           ['sysName', '0'],
 
35
                           ['sysLocation', '0'],
 
36
                           ['sysServices', '0'],
 
37
                           ['ifNumber', '0'],
 
38
                           ['ifDescr', '1'],
 
39
                           ['ifSpeed', '1'],
 
40
 
 
41
                           ['snmpInPkts', '0'],
 
42
                           ['snmpInBadVersions', '0'],
 
43
                           ['snmpInBadCommunityNames', '0'],
 
44
                           ['snmpInBadCommunityUses', '0'],
 
45
                           ['snmpInASNParseErrs', '0'],
 
46
                           ['snmpEnableAuthenTraps', '0'],
 
47
#                          ['snmpSilentDrops', '0'],
 
48
#                          ['snmpProxyDrops', '0'],
 
49
#                          ['snmpTrapEnterprise', '2'],
 
50
 
 
51
#                          ['hrStorageType', '2'],
 
52
#                          ['hrSystemDate', '0'],
 
53
                           ['sysORIndex', '1'],
 
54
                           ['sysORID', '2'],
 
55
                           ['sysORDescr', '3'],
 
56
                           ['sysORUpTime', '4'],
 
57
#                          ['ifName', '1'],
 
58
                           ['sysORLastChange', '0'],
 
59
                           ['ipInHdrErrors', '0'],
 
60
                           ['ipDefaultTTL', '0'],
 
61
                           ['ipInHdrErrors', '0'],
 
62
                          );
 
63
################################################################
 
64
#                          ['ipNetToMediaPhysAddress', '0'],
 
65
#                          ['ipAdEntAddr', '0'],
 
66
#                          ['snmpTrapOID', '0'],
 
67
#                          ['hrSystemNumUsers', '0'],
 
68
#                          ['hrFSLastFullBackupDate', '0'],
 
69
#                          ['ifPromiscuousMode', '0'],
 
70
 
 
71
 
 
72
 
 
73
#########################  1  #######################################
 
74
# Fire up a session.
 
75
    my $s1 =
 
76
    new SNMP::Session (DestHost=>$agent_host,Version=>1,Community=>$comm,RemotePort=>$agent_port);
 
77
    ok(defined($s1));
 
78
 
 
79
#######################  2  ##########################################
 
80
# Set some value and see if the value is set properly.
 
81
 
 
82
$originalLocation = $s1->get('sysLocation.0');
 
83
$value = 'Router Management Labs';
 
84
$s1->set('sysLocation.0', $value);
 
85
$finalvalue = $s1->get('sysLocation.0');
 
86
ok($originalLocation ne $finalvalue);
 
87
#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
 
88
#print("set value is: $finalvalue\n\n");
 
89
$s1->set('sysLocation.0', $originalLocation);
 
90
 
 
91
########################   3   #######################################
 
92
 
 
93
# Now, reset that string with a non-string value.
 
94
# This will FAIL. :)
 
95
 
 
96
#$nonstrvalue = '.9.23.56.7';
 
97
#$s1->set('sysLocation.0', $nonstrvalue);
 
98
#$finalvalue = $s1->get('sysLocation.0');
 
99
#ok(!defined($finalvalue));
 
100
 
 
101
#if (($initialvalue cmp $finalvalue) != 0 ) {
 
102
#    ok(1);
 
103
#}
 
104
#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
 
105
#print("set value is: $finalvalue\n\n");
 
106
#$s1->set('sysLocation.0', $originalLocation);
 
107
 
 
108
#######################   4   #####################################
 
109
 
 
110
# Test for an integer (READ-ONLY)
 
111
$originalservice = $s1->get('sysServices.0');
 
112
#print("services is: $originalservice\n");
 
113
$junk_service = "Nortel Networks";
 
114
$s1->set('sysServices.0', $junk_service);
 
115
 
 
116
$finalvalue = $s1->get('sysServices.0');
 
117
#print("services is: $finalvalue\n");
 
118
#print("Services is: $originalservice\n");
 
119
ok($originalservice eq $finalvalue);
 
120
#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
 
121
$s1->set('sysServices.0',$originalservice);
 
122
#print("\n");
 
123
 
 
124
##################   5   ######################
 
125
# Test for an integer (READ-WRITE)
 
126
# The snmpEnableAuthenTraps takes only two values - 1 and 2.
 
127
# If any other value is tried to be set, it doesn't set and
 
128
# retains the old value.
 
129
 
 
130
$originalTrap = $s1->get('snmpEnableAuthenTraps.0');
 
131
#print("trap is -- $originalTrap\n");
 
132
$junk_trap = "Nortel Networks";
 
133
$s1->set('snmpEnableAuthenTraps.0', $junk_trap);
 
134
$finalvalue = $s1->get('snmpEnableAuthenTraps.0');
 
135
#print("final trap is: $finalvalue\n");
 
136
ok($finalvalue ne $junk_trap);
 
137
# Should the error be 'Value out of range: SNMPERR_RANGE ?
 
138
#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
 
139
$s1->set('snmpEnableAuthenTraps.0',$originalTrap);
 
140
#print("\n");
 
141
###################  6  #######################
 
142
# Test for a TimeTicks (is this advisable? )
 
143
# Trying to set uptime which cannot be done (READ-ONLY).
 
144
#$time = $s1->get('sysUpTime.0');
 
145
#print("up time is : $time hundredths of a second\n");
 
146
#$junk_time = 12345;
 
147
#$s1->set('sysUpTime.0', $junk_time);
 
148
#$finalvalue = $s1->get('sysUpTime.0');
 
149
#print("final time is: $finalvalue hundredths of a second \n");
 
150
# Will the final value always be equal to the initial value?
 
151
# depends on how fast this piece of code executes?
 
152
#ok($finalvalue == $time);
 
153
#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
 
154
#print("\n");
 
155
 
 
156
###################   7   ######################
 
157
 
 
158
 
 
159
#Test for a Counter32 type.
 
160
# READ-ONLY.
 
161
 
 
162
#$Pkts = $s1->get('snmpInPkts.0');
 
163
#print(" pkts is : $Pkts\n");
 
164
#$junk_pkts = -1234;
 
165
#$s1->set('snmpInPkts.0', $junk_pkts);
 
166
#$finalPkts = $s1->get('snmpInPkts.0');
 
167
#print("now pkts is : $finalPkts\n");
 
168
#ok($finalPkts > $Pkts);
 
169
# Expecting genErr
 
170
#ok($s1->{ErrorStr} =~ /^\(gen/);
 
171
#print STDERR "pkts is = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
 
172
#print("\n");
 
173
##################   8   ##############################
 
174
 
 
175
# Set a non-accessible attribute
 
176
$s1->set('ipAddrEntry.1', 'MyEID');
 
177
# What should I expect - genErr or Bad variable type ?
 
178
# What gets checked first - type or accessibility?
 
179
# if type, then this is right..else, genErr is expected.
 
180
ok($s1->{ErrorStr} =~ /^Bad/ );
 
181
#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
 
182
#print("\n");
 
183
 
 
184
#################  12  ##########################
 
185
# Time stamp test - READ-ONLY
 
186
#$origtime = $s1->get('sysORLastChange.0');
 
187
#print("Time is: $origtime\n");
 
188
#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
 
189
#$time = $s1->set('sysORLastChange.0', 12345);
 
190
#print("time stamp is : $time \n");
 
191
# Should get genErr.
 
192
#ok($time =~ /^genErr/);
 
193
#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
 
194
#print("\n");
 
195
 
 
196
##############   13   ############################
 
197
 
 
198
# OID test
 
199
my $oldoid = $s1->get("sysORID.1");
 
200
#print("OID is : $oldoid\n");
 
201
$junk_OID = ".6.6.6.6.6.6";
 
202
$s1->set('sysORID.1', $junk_OID);
 
203
$newOID = $s1->get("sysORID.1");
 
204
#print("new oid is $newOID\n");
 
205
ok($oldoid eq $newOID);
 
206
#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
 
207
#print("\n");
 
208
################  14  ##########################
 
209
 
 
210
# Try setting an unregistered OID.
 
211
$junk_data = 'hehehe';
 
212
$s1->set('ifmyData.0', $junk_data);
 
213
 
 
214
#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
 
215
ok( $s1->{ErrorStr} =~ /^Unknown/ );
 
216
 
 
217
##############################################
 
218
 
 
219
snmptest_cleanup();
 
220
 
 
221