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