| 1 |
#!./perl |
| 2 |
|
| 3 |
# Written by John Stoffel ([email protected]) - 10/13/1997 |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
|
| 8 |
BEGIN { |
| 9 |
eval "use Cwd qw(abs_path)"; |
| 10 |
$ENV{'MIBS'} = 'ALL'; |
| 11 |
} |
| 12 |
|
| 13 |
# to print the description... |
| 14 |
$SNMP::save_descriptions = 1; |
| 15 |
|
| 16 |
use Test; |
| 17 |
BEGIN {plan tests => 38} |
| 18 |
use SNMP; |
| 19 |
use Data::Dumper; |
| 20 |
|
| 21 |
$SNMP::verbose = 0; |
| 22 |
$SNMP::best_guess = 2; |
| 23 |
|
| 24 |
require "t/startagent.pl"; |
| 25 |
use vars qw($bad_name $bad_oid $name $name_long $name_module $name_module2 |
| 26 |
$name_module_long $name_module_long2 $oid); |
| 27 |
require "t/startagent.pl"; |
| 28 |
|
| 29 |
my $DEBUG; |
| 30 |
|
| 31 |
############################# 1 ###################################### |
| 32 |
#check if |
| 33 |
my $res = $SNMP::MIB{sysDescr}{label}; |
| 34 |
print STDERR ("Test 1: label is $res\n") if ($DEBUG); |
| 35 |
ok("sysDescr" eq $res); |
| 36 |
print STDERR ("\n") if ($DEBUG); |
| 37 |
############################# 2 ###################################### |
| 38 |
$res = $SNMP::MIB{sysDescr}{objectID}; |
| 39 |
print STDERR ("Test 2: OID is $res\n") if ($DEBUG); |
| 40 |
ok(defined($res)); |
| 41 |
print STDERR ("\n") if ($DEBUG); |
| 42 |
############################# 3 ###################################### |
| 43 |
$res = $SNMP::MIB{sysDescr}{access}; |
| 44 |
print STDERR ("Test 3: access is $res\n") if ($DEBUG); |
| 45 |
ok($res eq 'ReadOnly'); |
| 46 |
print STDERR ("\n") if ($DEBUG); |
| 47 |
############################## 4 ################################### |
| 48 |
$res = $SNMP::MIB{sysLocation}{access}; |
| 49 |
#$res = $SNMP::MIB{sysORIndex}{access}; |
| 50 |
ok($res eq 'ReadWrite'); |
| 51 |
############################## 5 ################################### |
| 52 |
$res = $SNMP::MIB{sysLocation}{type}; |
| 53 |
ok($res eq 'OCTETSTR'); |
| 54 |
############################# 6 #################################### |
| 55 |
$res = $SNMP::MIB{sysLocation}{status}; |
| 56 |
print STDERR ("Test 6: status is $res\n") if ($DEBUG); |
| 57 |
ok($res eq 'Current'); |
| 58 |
print STDERR ("\n") if ($DEBUG); |
| 59 |
############################# 7 ################################# |
| 60 |
$res = $SNMP::MIB{sysORTable}{access}; |
| 61 |
print STDERR ("Test 7: access is $res\n") if ($DEBUG); |
| 62 |
ok($res eq 'NoAccess'); |
| 63 |
print STDERR ("\n") if ($DEBUG); |
| 64 |
############################# 8 ############################### |
| 65 |
$res = $SNMP::MIB{sysLocation}{subID}; |
| 66 |
print STDERR ("Test 8: subID is $res\n") if ($DEBUG); |
| 67 |
ok(defined($res)); |
| 68 |
print STDERR ("\n") if ($DEBUG); |
| 69 |
############################ 9 ############################## |
| 70 |
$res = $SNMP::MIB{sysLocation}{syntax}; |
| 71 |
print STDERR ("Test 9: syntax is $res\n") if ($DEBUG); |
| 72 |
ok($res eq 'DisplayString'); |
| 73 |
print STDERR ("\n") if ($DEBUG); |
| 74 |
############################ 10 ########################### |
| 75 |
$res = $SNMP::MIB{ipAdEntAddr}{syntax}; |
| 76 |
print STDERR ("Test 10: syntax is $res\n") if ($DEBUG); |
| 77 |
ok($res eq 'IPADDR'); |
| 78 |
print STDERR ("\n") if ($DEBUG); |
| 79 |
########################## 11 ########################## |
| 80 |
$res = $SNMP::MIB{atNetAddress}{syntax}; |
| 81 |
print STDERR ("Test 11: syntax is $res\n") if ($DEBUG); |
| 82 |
ok($res eq 'NETADDR'); |
| 83 |
print STDERR ("\n") if ($DEBUG); |
| 84 |
######################## 12 ############################### |
| 85 |
$res = $SNMP::MIB{ipReasmOKs}{syntax}; |
| 86 |
print STDERR ("Test 12: syntax is $res\n") if ($DEBUG); |
| 87 |
ok($res eq 'COUNTER'); |
| 88 |
print STDERR ("\n") if ($DEBUG); |
| 89 |
###################### 13 ############################## |
| 90 |
$res = $SNMP::MIB{sysDescr}{moduleID}; |
| 91 |
print STDERR ("Test 13: module ID is $res\n") if ($DEBUG); |
| 92 |
ok(defined($res)); |
| 93 |
print STDERR ("\n") if ($DEBUG); |
| 94 |
###################### 14 ######################### |
| 95 |
my $des = $SNMP::MIB{atNetAddress}{description}; |
| 96 |
print STDERR ("Test 14: des is $des\n") if ($DEBUG); |
| 97 |
ok(defined($des)); |
| 98 |
print STDERR ("\n") if ($DEBUG); |
| 99 |
|
| 100 |
###################### 15 ######################### |
| 101 |
$res = $SNMP::MIB{atNetAddress}{nextNode}; |
| 102 |
print STDERR ("Test 15: res is $res\n") if ($DEBUG); |
| 103 |
ok(ref($res) eq "HASH"); |
| 104 |
print STDERR ("\n") if ($DEBUG); |
| 105 |
|
| 106 |
######################## 16 ######################### |
| 107 |
$res = $SNMP::MIB{sysDescr}{children}; |
| 108 |
print STDERR ("Test 16: res is " . Dumper($res) . "\n") if ($DEBUG); |
| 109 |
ok(ref($res) eq "ARRAY"); |
| 110 |
print STDERR ("\n") if ($DEBUG); |
| 111 |
#################### 17 ######################### |
| 112 |
|
| 113 |
$res = $SNMP::MIB{sysDescr}{badField}; |
| 114 |
ok(!defined($res)); |
| 115 |
|
| 116 |
|
| 117 |
###################### 18 ######################### |
| 118 |
$res = $SNMP::MIB{sysDescr}{hint}; |
| 119 |
print STDERR ("Test 18: res is " . Dumper($res) . "\n") if ($DEBUG); |
| 120 |
ok(defined($res) && $res =~ /^255a/); |
| 121 |
print STDERR ("\n") if ($DEBUG); |
| 122 |
###################### 19 ######################### |
| 123 |
|
| 124 |
$res = $SNMP::MIB{ifPhysAddress}{hint}; |
| 125 |
print STDERR ("Test 19: res is " . Dumper($res) . "\n") if ($DEBUG); |
| 126 |
ok(defined($res) && $res =~ /^1x:/); |
| 127 |
print STDERR ("\n") if ($DEBUG); |
| 128 |
|
| 129 |
|
| 130 |
###################### some translate tests ####### |
| 131 |
|
| 132 |
##################### 20 ######################### |
| 133 |
# Garbage names return Undef. |
| 134 |
|
| 135 |
my $type1 = SNMP::getType($bad_name); |
| 136 |
ok(!defined($type1)); |
| 137 |
#printf "%s %d\n", (!defined($type1)) ? "ok" :"not ok", $n++; |
| 138 |
|
| 139 |
###################################################################### |
| 140 |
# getType() supports numeric OIDs now |
| 141 |
|
| 142 |
my $type2 = SNMP::getType($oid); |
| 143 |
ok(defined($type2) && $type2 =~ /OCTETSTR/); |
| 144 |
|
| 145 |
###################################################################### |
| 146 |
# This tests that sysDescr returns a valid type. |
| 147 |
|
| 148 |
my $type3 = SNMP::getType($name); |
| 149 |
ok(defined($type3)); |
| 150 |
|
| 151 |
###################################################################### |
| 152 |
# Translation tests from Name -> OID |
| 153 |
# sysDescr to .1.3.6.1.2.1.1.1 |
| 154 |
my $oid_tag = SNMP::translateObj($name); |
| 155 |
ok($oid eq $oid_tag); |
| 156 |
|
| 157 |
###################################################################### |
| 158 |
# Translation tests from Name -> OID |
| 159 |
# RFC1213-MIB::sysDescr to .1.3.6.1.2.1.1.1 |
| 160 |
$oid_tag = SNMP::translateObj($name_module); |
| 161 |
ok($oid eq $oid_tag); |
| 162 |
|
| 163 |
###################################################################### |
| 164 |
# Translation tests from Name -> OID |
| 165 |
# .iso.org.dod.internet.mgmt.mib-2.system.sysDescr to .1.3.6.1.2.1.1.1 |
| 166 |
$oid_tag = SNMP::translateObj($name_long); |
| 167 |
ok($oid eq $oid_tag); |
| 168 |
|
| 169 |
###################################################################### |
| 170 |
# bad name returns 'undef' |
| 171 |
$oid_tag = ''; |
| 172 |
$oid_tag = SNMP::translateObj($bad_name); |
| 173 |
ok(!defined($oid_tag)); |
| 174 |
|
| 175 |
|
| 176 |
###################################################################### |
| 177 |
# OID -> name |
| 178 |
# .1.3.6.1.2.1.1.1 to sysDescr |
| 179 |
my $name_tag = SNMP::translateObj($oid); |
| 180 |
ok($name eq $name_tag); |
| 181 |
|
| 182 |
###################################################################### |
| 183 |
# OID -> name |
| 184 |
# .1.3.6.1.2.1.1.1 to RFC1213-MIB::sysDescr or |
| 185 |
# .1.3.6.1.2.1.1.1 to SNMPv2-MIB::sysDescr |
| 186 |
$name_tag = SNMP::translateObj($oid,0,1); |
| 187 |
ok(($name_module eq $name_tag) || ($name_module2 eq $name_tag)); |
| 188 |
|
| 189 |
###################################################################### |
| 190 |
# OID -> name |
| 191 |
# .1.3.6.1.2.1.1.1 to .iso.org.dod.internet.mgmt.mib-2.system.sysDescr |
| 192 |
$name_tag = SNMP::translateObj($oid,1); |
| 193 |
ok($name_long eq $name_tag); |
| 194 |
|
| 195 |
###################################################################### |
| 196 |
# OID -> name |
| 197 |
# .1.3.6.1.2.1.1.1 to RFC1213-MIB::.iso.org.dod.internet.mgmt.mib-2.system.sysDescr or |
| 198 |
# .1.3.6.1.2.1.1.1 to SNMPv2-MIB::.iso.org.dod.internet.mgmt.mib-2.system.sysDescr |
| 199 |
$name_tag = SNMP::translateObj($oid,1,1); |
| 200 |
ok(($name_module_long eq $name_tag) || ($name_module_long2 eq $name_tag)); |
| 201 |
|
| 202 |
###################################################################### |
| 203 |
# bad OID -> Name |
| 204 |
|
| 205 |
$name_tag = SNMP::translateObj($bad_oid); |
| 206 |
ok($name ne $name_tag); |
| 207 |
#printf "%s %d\n", ($name ne $name_tag) ? "ok" :"not ok", $n++; |
| 208 |
|
| 209 |
|
| 210 |
###################################################################### |
| 211 |
# ranges |
| 212 |
|
| 213 |
my $node = $SNMP::MIB{snmpTargetAddrMMS}; |
| 214 |
ok($node); |
| 215 |
my $ranges = $node->{ranges}; |
| 216 |
ok($ranges and ref $ranges eq 'ARRAY'); |
| 217 |
ok(@$ranges == 2); |
| 218 |
ok($$ranges[0]{low} == 0); |
| 219 |
ok($$ranges[0]{high} == 0); |
| 220 |
ok($$ranges[1]{low} == 484); |
| 221 |
ok($$ranges[1]{high} == 2147483647); |
| 222 |
|
| 223 |
snmptest_cleanup(); |