4 unless(grep /blib/, @INC) {
6 @INC = '../lib' if -d '../lib';
10 BEGIN { plan tests => 7 }
12 use vars qw($agent_port $comm $agent_host);
13 require "t/startagent.pl";
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";
23 $n = 15; # Number of tests to run
26 if ($n == 0) { exit 0; }
28 # create list of varbinds for GETS, val field can be null or omitted
29 my $vars = new SNMP::VarList (
30 ['sysDescr', '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'],
51 # ['hrStorageType', '2'],
52 # ['hrSystemDate', '0'],
58 ['sysORLastChange', '0'],
59 ['ipInHdrErrors', '0'],
60 ['ipDefaultTTL', '0'],
61 ['ipInHdrErrors', '0'],
63 ################################################################
64 # ['ipNetToMediaPhysAddress', '0'],
65 # ['ipAdEntAddr', '0'],
66 # ['snmpTrapOID', '0'],
67 # ['hrSystemNumUsers', '0'],
68 # ['hrFSLastFullBackupDate', '0'],
69 # ['ifPromiscuousMode', '0'],
73 ######################### 1 #######################################
76 new SNMP::Session (DestHost=>$agent_host,Version=>1,Community=>$comm,RemotePort=>$agent_port);
79 ####################### 2 ##########################################
80 # Set some value and see if the value is set properly.
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);
91 ######################## 3 #######################################
93 # Now, reset that string with a non-string value.
96 #$nonstrvalue = '.9.23.56.7';
97 #$s1->set('sysLocation.0', $nonstrvalue);
98 #$finalvalue = $s1->get('sysLocation.0');
99 #ok(!defined($finalvalue));
101 #if (($initialvalue cmp $finalvalue) != 0 ) {
104 #print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
105 #print("set value is: $finalvalue\n\n");
106 #$s1->set('sysLocation.0', $originalLocation);
108 ####################### 4 #####################################
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);
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);
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.
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);
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");
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";
156 ################### 7 ######################
159 #Test for a Counter32 type.
162 #$Pkts = $s1->get('snmpInPkts.0');
163 #print(" pkts is : $Pkts\n");
165 #$s1->set('snmpInPkts.0', $junk_pkts);
166 #$finalPkts = $s1->get('snmpInPkts.0');
167 #print("now pkts is : $finalPkts\n");
168 #ok($finalPkts > $Pkts);
170 #ok($s1->{ErrorStr} =~ /^\(gen/);
171 #print STDERR "pkts is = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
173 ################## 8 ##############################
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";
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");
192 #ok($time =~ /^genErr/);
193 #print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
196 ############## 13 ############################
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";
208 ################ 14 ##########################
210 # Try setting an unregistered OID.
211 $junk_data = 'hehehe';
212 $s1->set('ifmyData.0', $junk_data);
214 #print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
215 ok( $s1->{ErrorStr} =~ /^Unknown/ );
217 ##############################################