snmp 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +193 -0
- data/Rakefile +52 -0
- data/data/ruby/snmp/mibs/ACCOUNTING-CONTROL-MIB.yaml +44 -0
- data/data/ruby/snmp/mibs/ADSL-LINE-EXT-MIB.yaml +66 -0
- data/data/ruby/snmp/mibs/ADSL-LINE-MIB.yaml +238 -0
- data/data/ruby/snmp/mibs/ADSL-TC-MIB.yaml +2 -0
- data/data/ruby/snmp/mibs/AGENTX-MIB.yaml +40 -0
- data/data/ruby/snmp/mibs/APM-MIB.yaml +98 -0
- data/data/ruby/snmp/mibs/APPC-MIB.yaml +295 -0
- data/data/ruby/snmp/mibs/APPLETALK-MIB.yaml +284 -0
- data/data/ruby/snmp/mibs/APPLICATION-MIB.yaml +161 -0
- data/data/ruby/snmp/mibs/APPN-DLUR-MIB.yaml +41 -0
- data/data/ruby/snmp/mibs/APPN-MIB.yaml +356 -0
- data/data/ruby/snmp/mibs/APPN-TRAP-MIB.yaml +8 -0
- data/data/ruby/snmp/mibs/APS-MIB.yaml +62 -0
- data/data/ruby/snmp/mibs/ATM-ACCOUNTING-INFORMATION-MIB.yaml +37 -0
- data/data/ruby/snmp/mibs/ATM-MIB.yaml +112 -0
- data/data/ruby/snmp/mibs/ATM-TC-MIB.yaml +19 -0
- data/data/ruby/snmp/mibs/ATM2-MIB.yaml +182 -0
- data/data/ruby/snmp/mibs/BGP4-MIB.yaml +56 -0
- data/data/ruby/snmp/mibs/BLDG-HVAC-MIB.yaml +35 -0
- data/data/ruby/snmp/mibs/BRIDGE-MIB.yaml +63 -0
- data/data/ruby/snmp/mibs/CHARACTER-MIB.yaml +48 -0
- data/data/ruby/snmp/mibs/CIRCUIT-IF-MIB.yaml +21 -0
- data/data/ruby/snmp/mibs/CLNS-MIB.yaml +116 -0
- data/data/ruby/snmp/mibs/COFFEE-POT-MIB.yaml +13 -0
- data/data/ruby/snmp/mibs/COPS-CLIENT-MIB.yaml +54 -0
- data/data/ruby/snmp/mibs/DECNET-PHIV-MIB.yaml +237 -0
- data/data/ruby/snmp/mibs/DIAL-CONTROL-MIB.yaml +84 -0
- data/data/ruby/snmp/mibs/DIFFSERV-CONFIG-MIB.yaml +15 -0
- data/data/ruby/snmp/mibs/DIFFSERV-DSCP-TC.yaml +2 -0
- data/data/ruby/snmp/mibs/DIFFSERV-MIB.yaml +171 -0
- data/data/ruby/snmp/mibs/DIRECTORY-SERVER-MIB.yaml +52 -0
- data/data/ruby/snmp/mibs/DISMAN-EVENT-MIB.yaml +110 -0
- data/data/ruby/snmp/mibs/DISMAN-EXPRESSION-MIB.yaml +55 -0
- data/data/ruby/snmp/mibs/DISMAN-NSLOOKUP-MIB.yaml +23 -0
- data/data/ruby/snmp/mibs/DISMAN-PING-MIB.yaml +57 -0
- data/data/ruby/snmp/mibs/DISMAN-SCHEDULE-MIB.yaml +32 -0
- data/data/ruby/snmp/mibs/DISMAN-SCRIPT-MIB.yaml +80 -0
- data/data/ruby/snmp/mibs/DISMAN-TRACEROUTE-MIB.yaml +72 -0
- data/data/ruby/snmp/mibs/DLSW-MIB.yaml +193 -0
- data/data/ruby/snmp/mibs/DNS-RESOLVER-MIB.yaml +87 -0
- data/data/ruby/snmp/mibs/DNS-SERVER-MIB.yaml +73 -0
- data/data/ruby/snmp/mibs/DOCS-BPI-MIB.yaml +101 -0
- data/data/ruby/snmp/mibs/DOCS-CABLE-DEVICE-MIB.yaml +107 -0
- data/data/ruby/snmp/mibs/DOCS-IF-MIB.yaml +143 -0
- data/data/ruby/snmp/mibs/DOT12-IF-MIB.yaml +33 -0
- data/data/ruby/snmp/mibs/DS0-MIB.yaml +18 -0
- data/data/ruby/snmp/mibs/DS0BUNDLE-MIB.yaml +17 -0
- data/data/ruby/snmp/mibs/DS1-MIB.yaml +118 -0
- data/data/ruby/snmp/mibs/DS3-MIB.yaml +106 -0
- data/data/ruby/snmp/mibs/DSA-MIB.yaml +44 -0
- data/data/ruby/snmp/mibs/DSMON-MIB.yaml +219 -0
- data/data/ruby/snmp/mibs/EBN-MIB.yaml +47 -0
- data/data/ruby/snmp/mibs/ENTITY-MIB.yaml +51 -0
- data/data/ruby/snmp/mibs/ENTITY-SENSOR-MIB.yaml +16 -0
- data/data/ruby/snmp/mibs/ETHER-CHIPSET-MIB.yaml +79 -0
- data/data/ruby/snmp/mibs/ETHER-WIS.yaml +28 -0
- data/data/ruby/snmp/mibs/EtherLike-MIB.yaml +58 -0
- data/data/ruby/snmp/mibs/FDDI-SMT73-MIB.yaml +128 -0
- data/data/ruby/snmp/mibs/FIBRE-CHANNEL-FE-MIB.yaml +122 -0
- data/data/ruby/snmp/mibs/FLOW-METER-MIB.yaml +112 -0
- data/data/ruby/snmp/mibs/FR-ATM-PVC-SERVICE-IWF-MIB.yaml +45 -0
- data/data/ruby/snmp/mibs/FR-MFR-MIB.yaml +52 -0
- data/data/ruby/snmp/mibs/FRAME-RELAY-DTE-MIB.yaml +54 -0
- data/data/ruby/snmp/mibs/FRNETSERV-MIB.yaml +109 -0
- data/data/ruby/snmp/mibs/FRSLD-MIB.yaml +82 -0
- data/data/ruby/snmp/mibs/Finisher-MIB.yaml +53 -0
- data/data/ruby/snmp/mibs/GSMP-MIB.yaml +82 -0
- data/data/ruby/snmp/mibs/HC-ALARM-MIB.yaml +32 -0
- data/data/ruby/snmp/mibs/HC-PerfHist-TC-MIB.yaml +2 -0
- data/data/ruby/snmp/mibs/HC-RMON-MIB.yaml +193 -0
- data/data/ruby/snmp/mibs/HCNUM-TC.yaml +2 -0
- data/data/ruby/snmp/mibs/HDSL2-SHDSL-LINE-MIB.yaml +115 -0
- data/data/ruby/snmp/mibs/HOST-RESOURCES-MIB.yaml +98 -0
- data/data/ruby/snmp/mibs/HOST-RESOURCES-TYPES.yaml +56 -0
- data/data/ruby/snmp/mibs/HPR-IP-MIB.yaml +24 -0
- data/data/ruby/snmp/mibs/HPR-MIB.yaml +81 -0
- data/data/ruby/snmp/mibs/IF-INVERTED-STACK-MIB.yaml +9 -0
- data/data/ruby/snmp/mibs/IF-MIB.yaml +73 -0
- data/data/ruby/snmp/mibs/IGMP-STD-MIB.yaml +33 -0
- data/data/ruby/snmp/mibs/INET-ADDRESS-MIB.yaml +2 -0
- data/data/ruby/snmp/mibs/INTEGRATED-SERVICES-GUARANTEED-MIB.yaml +13 -0
- data/data/ruby/snmp/mibs/INTEGRATED-SERVICES-MIB.yaml +44 -0
- data/data/ruby/snmp/mibs/INTERFACETOPN-MIB.yaml +29 -0
- data/data/ruby/snmp/mibs/IP-FORWARD-MIB.yaml +42 -0
- data/data/ruby/snmp/mibs/IP-MIB.yaml +66 -0
- data/data/ruby/snmp/mibs/IPATM-IPMC-MIB.yaml +203 -0
- data/data/ruby/snmp/mibs/IPMROUTE-STD-MIB.yaml +64 -0
- data/data/ruby/snmp/mibs/IPOA-MIB.yaml +85 -0
- data/data/ruby/snmp/mibs/IPV6-FLOW-LABEL-MIB.yaml +2 -0
- data/data/ruby/snmp/mibs/IPV6-ICMP-MIB.yaml +42 -0
- data/data/ruby/snmp/mibs/IPV6-MIB.yaml +88 -0
- data/data/ruby/snmp/mibs/IPV6-MLD-MIB.yaml +30 -0
- data/data/ruby/snmp/mibs/IPV6-TCP-MIB.yaml +14 -0
- data/data/ruby/snmp/mibs/IPV6-UDP-MIB.yaml +11 -0
- data/data/ruby/snmp/mibs/ISDN-MIB.yaml +71 -0
- data/data/ruby/snmp/mibs/Job-Monitoring-MIB.yaml +43 -0
- data/data/ruby/snmp/mibs/L2TP-MIB.yaml +156 -0
- data/data/ruby/snmp/mibs/MALLOC-MIB.yaml +83 -0
- data/data/ruby/snmp/mibs/MAU-MIB.yaml +110 -0
- data/data/ruby/snmp/mibs/MIOX25-MIB.yaml +38 -0
- data/data/ruby/snmp/mibs/MIP-MIB.yaml +180 -0
- data/data/ruby/snmp/mibs/MPLS-FTN-STD-MIB.yaml +44 -0
- data/data/ruby/snmp/mibs/MPLS-LDP-ATM-STD-MIB.yaml +35 -0
- data/data/ruby/snmp/mibs/MPLS-LDP-FRAME-RELAY-STD-MIB.yaml +28 -0
- data/data/ruby/snmp/mibs/MPLS-LDP-GENERIC-STD-MIB.yaml +15 -0
- data/data/ruby/snmp/mibs/MPLS-LDP-STD-MIB.yaml +118 -0
- data/data/ruby/snmp/mibs/MPLS-LSR-STD-MIB.yaml +98 -0
- data/data/ruby/snmp/mibs/MPLS-TC-STD-MIB.yaml +3 -0
- data/data/ruby/snmp/mibs/MPLS-TE-STD-MIB.yaml +120 -0
- data/data/ruby/snmp/mibs/MTA-MIB.yaml +64 -0
- data/data/ruby/snmp/mibs/Modem-MIB.yaml +106 -0
- data/data/ruby/snmp/mibs/NETWORK-SERVICES-MIB.yaml +33 -0
- data/data/ruby/snmp/mibs/NHRP-MIB.yaml +163 -0
- data/data/ruby/snmp/mibs/NOTIFICATION-LOG-MIB.yaml +51 -0
- data/data/ruby/snmp/mibs/OPT-IF-MIB.yaml +431 -0
- data/data/ruby/snmp/mibs/OSPF-MIB.yaml +150 -0
- data/data/ruby/snmp/mibs/OSPF-TRAP-MIB.yaml +11 -0
- data/data/ruby/snmp/mibs/P-BRIDGE-MIB.yaml +51 -0
- data/data/ruby/snmp/mibs/PARALLEL-MIB.yaml +24 -0
- data/data/ruby/snmp/mibs/PIM-MIB.yaml +66 -0
- data/data/ruby/snmp/mibs/PINT-MIB.yaml +51 -0
- data/data/ruby/snmp/mibs/POWER-ETHERNET-MIB.yaml +36 -0
- data/data/ruby/snmp/mibs/PPP-BRIDGE-NCP-MIB.yaml +25 -0
- data/data/ruby/snmp/mibs/PPP-IP-NCP-MIB.yaml +13 -0
- data/data/ruby/snmp/mibs/PPP-LCP-MIB.yaml +47 -0
- data/data/ruby/snmp/mibs/PPP-SEC-MIB.yaml +20 -0
- data/data/ruby/snmp/mibs/PTOPO-MIB.yaml +39 -0
- data/data/ruby/snmp/mibs/PerfHist-TC-MIB.yaml +2 -0
- data/data/ruby/snmp/mibs/Printer-MIB.yaml +209 -0
- data/data/ruby/snmp/mibs/Q-BRIDGE-MIB.yaml +99 -0
- data/data/ruby/snmp/mibs/RADIUS-ACC-CLIENT-MIB.yaml +26 -0
- data/data/ruby/snmp/mibs/RADIUS-ACC-SERVER-MIB.yaml +35 -0
- data/data/ruby/snmp/mibs/RADIUS-AUTH-CLIENT-MIB.yaml +28 -0
- data/data/ruby/snmp/mibs/RADIUS-AUTH-SERVER-MIB.yaml +37 -0
- data/data/ruby/snmp/mibs/RDBMS-MIB.yaml +82 -0
- data/data/ruby/snmp/mibs/RFC1065-SMI.yaml +9 -0
- data/data/ruby/snmp/mibs/RFC1155-SMI.yaml +9 -0
- data/data/ruby/snmp/mibs/RFC1158-MIB.yaml +202 -0
- data/data/ruby/snmp/mibs/RFC1213-MIB.yaml +202 -0
- data/data/ruby/snmp/mibs/RFC1269-MIB.yaml +29 -0
- data/data/ruby/snmp/mibs/RFC1271-MIB.yaml +214 -0
- data/data/ruby/snmp/mibs/RFC1285-MIB.yaml +104 -0
- data/data/ruby/snmp/mibs/RFC1316-MIB.yaml +42 -0
- data/data/ruby/snmp/mibs/RFC1381-MIB.yaml +60 -0
- data/data/ruby/snmp/mibs/RFC1382-MIB.yaml +169 -0
- data/data/ruby/snmp/mibs/RFC1414-MIB.yaml +10 -0
- data/data/ruby/snmp/mibs/RIPv2-MIB.yaml +34 -0
- data/data/ruby/snmp/mibs/RMON-MIB.yaml +219 -0
- data/data/ruby/snmp/mibs/RMON2-MIB.yaml +282 -0
- data/data/ruby/snmp/mibs/ROHC-MIB.yaml +64 -0
- data/data/ruby/snmp/mibs/ROHC-RTP-MIB.yaml +29 -0
- data/data/ruby/snmp/mibs/ROHC-UNCOMPRESSED-MIB.yaml +11 -0
- data/data/ruby/snmp/mibs/RS-232-MIB.yaml +54 -0
- data/data/ruby/snmp/mibs/RSVP-MIB.yaml +156 -0
- data/data/ruby/snmp/mibs/RTP-MIB.yaml +57 -0
- data/data/ruby/snmp/mibs/SFLOW-MIB.yaml +22 -0
- data/data/ruby/snmp/mibs/SIP-MIB.yaml +70 -0
- data/data/ruby/snmp/mibs/SLAPM-MIB.yaml +144 -0
- data/data/ruby/snmp/mibs/SMON-MIB.yaml +63 -0
- data/data/ruby/snmp/mibs/SNA-NAU-MIB.yaml +137 -0
- data/data/ruby/snmp/mibs/SNA-SDLC-MIB.yaml +147 -0
- data/data/ruby/snmp/mibs/SNMP-COMMUNITY-MIB.yaml +22 -0
- data/data/ruby/snmp/mibs/SNMP-FRAMEWORK-MIB.yaml +14 -0
- data/data/ruby/snmp/mibs/SNMP-MPD-MIB.yaml +11 -0
- data/data/ruby/snmp/mibs/SNMP-NOTIFICATION-MIB.yaml +25 -0
- data/data/ruby/snmp/mibs/SNMP-PROXY-MIB.yaml +17 -0
- data/data/ruby/snmp/mibs/SNMP-REPEATER-MIB.yaml +135 -0
- data/data/ruby/snmp/mibs/SNMP-TARGET-MIB.yaml +29 -0
- data/data/ruby/snmp/mibs/SNMP-USER-BASED-SM-MIB.yaml +35 -0
- data/data/ruby/snmp/mibs/SNMP-USM-DH-OBJECTS-MIB.yaml +21 -0
- data/data/ruby/snmp/mibs/SNMP-VIEW-BASED-ACM-MIB.yaml +37 -0
- data/data/ruby/snmp/mibs/SNMPv2-MIB.yaml +58 -0
- data/data/ruby/snmp/mibs/SNMPv2-SMI.yaml +17 -0
- data/data/ruby/snmp/mibs/SNMPv2-TM.yaml +9 -0
- data/data/ruby/snmp/mibs/SNMPv2-USEC-MIB.yaml +19 -0
- data/data/ruby/snmp/mibs/SONET-MIB.yaml +131 -0
- data/data/ruby/snmp/mibs/SOURCE-ROUTING-MIB.yaml +30 -0
- data/data/ruby/snmp/mibs/SYSAPPL-MIB.yaml +81 -0
- data/data/ruby/snmp/mibs/TCP-MIB.yaml +27 -0
- data/data/ruby/snmp/mibs/TCPIPX-MIB.yaml +24 -0
- data/data/ruby/snmp/mibs/TN3270E-MIB.yaml +105 -0
- data/data/ruby/snmp/mibs/TN3270E-RT-MIB.yaml +43 -0
- data/data/ruby/snmp/mibs/TOKEN-RING-RMON-MIB.yaml +183 -0
- data/data/ruby/snmp/mibs/TOKENRING-MIB.yaml +58 -0
- data/data/ruby/snmp/mibs/TOKENRING-STATION-SR-MIB.yaml +12 -0
- data/data/ruby/snmp/mibs/TRANSPORT-ADDRESS-MIB.yaml +19 -0
- data/data/ruby/snmp/mibs/TUNNEL-MIB.yaml +23 -0
- data/data/ruby/snmp/mibs/UDP-MIB.yaml +14 -0
- data/data/ruby/snmp/mibs/UPS-MIB.yaml +117 -0
- data/data/ruby/snmp/mibs/VDSL-LINE-MIB.yaml +173 -0
- data/data/ruby/snmp/mibs/VRRP-MIB.yaml +50 -0
- data/data/ruby/snmp/mibs/WWW-MIB.yaml +91 -0
- data/examples/dump.rb +15 -0
- data/examples/get.rb +7 -0
- data/examples/iftable.rb +14 -0
- data/examples/log_traps.rb +23 -0
- data/examples/set.rb +8 -0
- data/examples/walk.rb +9 -0
- data/lib/snmp.rb +10 -0
- data/lib/snmp/agent.rb +74 -0
- data/lib/snmp/ber.rb +332 -0
- data/lib/snmp/manager.rb +502 -0
- data/lib/snmp/mib.rb +259 -0
- data/lib/snmp/pdu.rb +363 -0
- data/lib/snmp/varbind.rb +520 -0
- data/setup.rb +1360 -0
- data/test/test_ber.rb +236 -0
- data/test/test_manager.rb +192 -0
- data/test/test_mib.rb +66 -0
- data/test/test_pdu.rb +184 -0
- data/test/test_varbind.rb +270 -0
- metadata +251 -0
data/test/test_pdu.rb
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'snmp/pdu'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestProtocol < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include SNMP
|
7
|
+
|
8
|
+
def test_message_decode_v1
|
9
|
+
message = SNMP::Message.decode("0'\002\001\000\004\006public\240\032\002\002\003\350\002\001\000\002\001\0000\0160\f\006\010+\006\001\002\001\001\001\000\005\000")
|
10
|
+
assert_equal(:SNMPv1, message.version)
|
11
|
+
assert_equal("public", message.community)
|
12
|
+
assert_equal(SNMP::GetRequest, message.pdu.class)
|
13
|
+
varbind_list = message.pdu.varbind_list;
|
14
|
+
assert_equal(1, varbind_list.length)
|
15
|
+
assert_equal([1,3,6,1,2,1,1,1,0], varbind_list.first.name)
|
16
|
+
assert_equal(SNMP::Null, varbind_list.first.value)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_message_decode_v2c
|
20
|
+
message = SNMP::Message.decode("0)\002\001\001\004\006public\240\034\002\0040\265\020\202\002\001\000\002\001\0000\0160\f\006\010+\006\001\002\001\001\001\000\005\000")
|
21
|
+
assert_equal(:SNMPv2c, message.version)
|
22
|
+
assert_equal("public", message.community)
|
23
|
+
varbind_list = message.pdu.varbind_list;
|
24
|
+
assert_equal(1, varbind_list.length)
|
25
|
+
assert_equal([1,3,6,1,2,1,1,1,0], varbind_list.first.name)
|
26
|
+
assert_equal(SNMP::Null, varbind_list.first.value)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_message_decoder_v3
|
30
|
+
assert_raise(SNMP::UnsupportedVersion) do
|
31
|
+
message = SNMP::Message.decode("0>\002\001\0030\021\002\004&\266\342\314\002\003\000\377\343\004\001\004\002\001\003\004\0200\016\004\000\002\001\000\002\001\000\004\000\004\000\004\0000\024\004\000\004\000\240\016\002\004\v\3623\233\002\001\000\002\001\0000\000")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_encode_message
|
36
|
+
varbind = SNMP::VarBind.new([1,3,6,1234], SNMP::OctetString.new("value"))
|
37
|
+
list = SNMP::VarBindList.new
|
38
|
+
list << varbind << varbind;
|
39
|
+
pdu = SNMP::Response.new(12345, list)
|
40
|
+
message = SNMP::Message.new(:SNMPv2c, "public", pdu)
|
41
|
+
assert_equal("07\002\001\001\004\006public\242*\002\00209\002\001\000\002\001\0000\0360\r\006\004+\006\211R\004\005value0\r\006\004+\006\211R\004\005value", message.encode)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_get_request_from_single_string
|
45
|
+
request = SNMP::GetRequest.new(42, VarBindList.new(["1.3.6.1"]))
|
46
|
+
assert_equal(42, request.request_id)
|
47
|
+
assert_equal(1, request.varbind_list.length)
|
48
|
+
assert_equal([1,3,6,1], request.varbind_list.first.name)
|
49
|
+
assert_equal(SNMP::Null, request.varbind_list.first.value)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_get_request_from_multi_string
|
53
|
+
request = SNMP::GetRequest.new(42, VarBindList.new(["1.3.6.1", "1.3.6.2"]))
|
54
|
+
assert_equal(2, request.varbind_list.length)
|
55
|
+
assert_equal([1,3,6,1], request.varbind_list.first.name)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_get_request_from_varbind
|
59
|
+
request = GetRequest.new(42, VarBindList.new(VarBind.new([1,3,6,1], Null)))
|
60
|
+
assert_equal(1, request.varbind_list.length)
|
61
|
+
assert_equal([1,3,6,1], request.varbind_list.first.name)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_get_next_from_single_string
|
65
|
+
request = SNMP::GetNextRequest.new(42, VarBindList.new("1.3.5.1"))
|
66
|
+
assert_equal(42, request.request_id)
|
67
|
+
assert_equal(1, request.varbind_list.length)
|
68
|
+
assert_equal([1,3,5,1], request.varbind_list.first.name)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_get_next_from_single_object_id
|
72
|
+
request = SNMP::GetNextRequest.new(42, VarBindList.new([ObjectId.new("1.3.5.1")]))
|
73
|
+
assert_equal(42, request.request_id)
|
74
|
+
assert_equal(1, request.varbind_list.length)
|
75
|
+
assert_equal([1,3,5,1], request.varbind_list.first.name)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_each_varbind
|
79
|
+
request = SNMP::GetRequest.new(42, VarBindList.new(["1.3.6.1", "1.3.6.2"]))
|
80
|
+
count = 0
|
81
|
+
request.each_varbind do |v|
|
82
|
+
case count
|
83
|
+
when 0
|
84
|
+
assert_equal(ObjectName.new("1.3.6.1"), v.name)
|
85
|
+
when 1
|
86
|
+
assert_equal(ObjectName.new("1.3.6.2"), v.name)
|
87
|
+
else
|
88
|
+
fail "Unexpected count"
|
89
|
+
end
|
90
|
+
count +=1
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_get_bulk_create
|
95
|
+
request = SNMP::GetBulkRequest.new(1234, VarBindList.new("1.3.6.2"), 0, 10)
|
96
|
+
assert_equal(1234, request.request_id)
|
97
|
+
assert_equal(0, request.non_repeaters)
|
98
|
+
assert_equal(10, request.max_repetitions)
|
99
|
+
assert_equal(1, request.varbind_list.length)
|
100
|
+
assert_equal("1.3.6.2", request.varbind_list.first.name.to_s)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_get_bulk_encode
|
104
|
+
request = SNMP::GetBulkRequest.new(1234, VarBindList.new, 0, 10)
|
105
|
+
assert_equal("\245\f\002\002\004\322\002\001\000\002\001\n0\000", request.encode)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_error_status
|
109
|
+
request = GetRequest.new(42, VarBindList.new("1.3.12.23.4"))
|
110
|
+
assert_equal(:noError, request.error_status)
|
111
|
+
|
112
|
+
request.error_status = :noCreation
|
113
|
+
assert_equal(:noCreation, request.error_status)
|
114
|
+
|
115
|
+
request.error_status = 2
|
116
|
+
assert_equal(:noSuchName, request.error_status)
|
117
|
+
|
118
|
+
assert_raise(InvalidErrorStatus) {request.error_status = 42}
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_snmpv2_trap
|
122
|
+
sys_up_varbind = VarBind.new(ObjectId.new("1.3.6.1.2.1.1.3.0"),
|
123
|
+
TimeTicks.new(1234))
|
124
|
+
trap_oid_varbind = VarBind.new(ObjectId.new("1.3.6.1.6.3.1.1.4.1.0"),
|
125
|
+
ObjectId.new("1.2.3"))
|
126
|
+
trap = SNMPv2_Trap.new(42, VarBindList.new([sys_up_varbind, trap_oid_varbind]))
|
127
|
+
assert_equal("\247-\002\001*\002\001\000\002\001\0000\"0\016\006\010+\006\001\002\001\001\003\000C\002\004\3220\020\006\n+\006\001\006\003\001\001\004\001\000\006\002*\003", trap.encode)
|
128
|
+
assert_equal(1234, trap.sys_up_time.to_i)
|
129
|
+
assert_equal("1.2.3", trap.trap_oid.to_s)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_snmpv2_invalid_trap
|
133
|
+
trap = SNMPv2_Trap.new(42, VarBindList.new([]))
|
134
|
+
assert_raise(InvalidTrapVarbind) { trap.sys_up_time }
|
135
|
+
assert_raise(InvalidTrapVarbind) { trap.trap_oid }
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_snmpv1_generic_trap
|
139
|
+
trap = SNMPv1_Trap.new(nil, nil, 0, nil, nil, nil)
|
140
|
+
assert_equal(:coldStart, trap.generic_trap)
|
141
|
+
|
142
|
+
trap.generic_trap = :warmStart
|
143
|
+
assert_equal(:warmStart, trap.generic_trap)
|
144
|
+
|
145
|
+
trap.generic_trap = 6
|
146
|
+
assert_equal(:enterpriseSpecific, trap.generic_trap)
|
147
|
+
|
148
|
+
assert_raise(InvalidGenericTrap) { trap.generic_trap = -1 }
|
149
|
+
assert_raise(InvalidGenericTrap) { trap.generic_trap = 7 }
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_snmpv1_trap_encode
|
153
|
+
enterprise = ObjectId.new("1.3.6.1.123")
|
154
|
+
agent_addr = IpAddress.new("1.2.3.4")
|
155
|
+
generic_trap = :linkDown
|
156
|
+
specific_trap = 0
|
157
|
+
timestamp = TimeTicks.new(1234)
|
158
|
+
varbinds = VarBindList.new([VarBind.new("1.3.6.2", Integer.new(1))])
|
159
|
+
trap = SNMPv1_Trap.new(enterprise, agent_addr, generic_trap, specific_trap, timestamp, varbinds)
|
160
|
+
assert_equal("\244\"\006\004+\006\001{@\004\001\002\003\004\002\001\002\002\001\000C\002\004\3220\n0\010\006\003+\006\002\002\001\001", trap.encode)
|
161
|
+
|
162
|
+
encoded = Message.new(:SNMPv1, "public", trap).encode
|
163
|
+
trap = Message.decode(encoded).pdu
|
164
|
+
assert_equal(enterprise, trap.enterprise)
|
165
|
+
assert_equal(agent_addr, trap.agent_addr)
|
166
|
+
assert_equal(:linkDown, trap.generic_trap)
|
167
|
+
assert_equal(0, trap.specific_trap)
|
168
|
+
assert_equal(1, trap.varbind_list.length)
|
169
|
+
assert_equal(ObjectId.new("1.3.6.2"), trap.varbind_list.first.name)
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_response_pdu
|
173
|
+
pdu = Response.new(2147483647, VarBindList.new, :noError, 0)
|
174
|
+
assert_equal("\242\016\002\004\177\377\377\377\002\001\000\002\001\0000\000", pdu.encode)
|
175
|
+
|
176
|
+
encoded = Message.new(:SNMPv2c, "public", pdu).encode
|
177
|
+
pdu = Message.decode(encoded).pdu
|
178
|
+
assert_equal(2147483647, pdu.request_id)
|
179
|
+
assert_equal(:noError, pdu.error_status)
|
180
|
+
assert_equal(0, pdu.error_index)
|
181
|
+
assert_equal(0, pdu.varbind_list.length)
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
@@ -0,0 +1,270 @@
|
|
1
|
+
require 'snmp/varbind'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestVarBind < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include SNMP
|
7
|
+
|
8
|
+
def test_varbind_encode
|
9
|
+
v = VarBind.new([1,3,6,1], OctetString.new("test"))
|
10
|
+
assert_equal("0\v\006\003+\006\001\004\004test", v.encode)
|
11
|
+
assert_not_nil(v.asn1_type)
|
12
|
+
assert_equal("[name=1.3.6.1, value=test (OCTET STRING)]", v.to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_varbind_decode
|
16
|
+
varbind, remainder = VarBind.decode("0\f\006\010+\006\001\002\001\001\001\000\005\000")
|
17
|
+
assert_equal(Null, varbind.value)
|
18
|
+
assert_equal("", remainder)
|
19
|
+
|
20
|
+
varbind, remainder = VarBind.decode("0\f\006\010+\006\001\002\001\001\001\000\005\0000\f\006\010+\006\001\002\001\001\002\000\005\000")
|
21
|
+
assert_equal(Null, varbind.value)
|
22
|
+
assert_equal("0\f\006\010+\006\001\002\001\001\002\000\005\000", remainder)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_varbind_list_create
|
26
|
+
list = VarBindList.new
|
27
|
+
assert_equal(0, list.length)
|
28
|
+
|
29
|
+
check_varbind_list_create(VarBindList.new(["1.2.3.4.5"]))
|
30
|
+
check_varbind_list_create(VarBindList.new([ObjectId.new("1.2.3.4.5")]))
|
31
|
+
check_varbind_list_create(VarBindList.new([VarBind.new("1.2.3.4.5", Null)]))
|
32
|
+
|
33
|
+
check_varbind_list_create(VarBindList.new(
|
34
|
+
["1.2.3.4.5", "1.2.3.4.6"]), 2)
|
35
|
+
|
36
|
+
check_varbind_list_create(VarBindList.new(
|
37
|
+
[ObjectId.new("1.2.3.4.5"),
|
38
|
+
ObjectId.new("1.2.3.4.6")]
|
39
|
+
), 2)
|
40
|
+
|
41
|
+
check_varbind_list_create(VarBindList.new(
|
42
|
+
[VarBind.new("1.2.3.4.5", Null),
|
43
|
+
VarBind.new("1.2.3.4.6", Integer.new(123)),
|
44
|
+
ObjectId.new("1.2.3.4.7")]
|
45
|
+
), 3)
|
46
|
+
|
47
|
+
list = VarBindList.new([VarBind.new("1.3.6.2", Integer.new(1))])
|
48
|
+
assert_equal(1, list.length)
|
49
|
+
assert_equal("1.3.6.2", list.first.name.to_s)
|
50
|
+
assert_equal(1, list.first.value.to_i)
|
51
|
+
end
|
52
|
+
|
53
|
+
def check_varbind_list_create(list, n=1)
|
54
|
+
assert_equal(n, list.length)
|
55
|
+
assert_equal("1.2.3.4.5", list.first.name.to_s)
|
56
|
+
assert_equal(Null, list.first.value)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_varbind_list_encode
|
60
|
+
list = VarBindList.new
|
61
|
+
assert_equal("0\000", list.encode)
|
62
|
+
assert_not_nil(list.asn1_type)
|
63
|
+
|
64
|
+
list << VarBind.new([1,3,6,1], OctetString.new("test"))
|
65
|
+
assert_equal("0\r0\v\006\003+\006\001\004\004test", list.encode)
|
66
|
+
|
67
|
+
list << VarBind.new([1,3,6,1], OctetString.new("blah"))
|
68
|
+
assert_equal("0\0320\v\006\003+\006\001\004\004test0\v\006\003+\006\001\004\004blah", list.encode)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_varbind_list_decode
|
72
|
+
list, remainder = VarBindList.decode("0\r0\v\006\003+\006\001\004\004test")
|
73
|
+
assert_equal(1, list.length)
|
74
|
+
assert_equal("", remainder)
|
75
|
+
|
76
|
+
list, remainder = VarBindList.decode("0\0320\v\006\003+\006\001\004\004test0\v\006\003+\006\001\004\004blah")
|
77
|
+
assert_equal(2, list.length)
|
78
|
+
assert_equal("", remainder)
|
79
|
+
|
80
|
+
list, remainder = VarBindList.decode("0\000")
|
81
|
+
assert_equal(0, list.length)
|
82
|
+
assert_equal("", remainder)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_octet_string
|
86
|
+
string = OctetString.new("test")
|
87
|
+
assert_equal("test", string.to_s)
|
88
|
+
assert_equal("\004\004test", string.encode)
|
89
|
+
assert_not_nil(string.asn1_type)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_octet_string_equals
|
93
|
+
s1 = OctetString.new("test")
|
94
|
+
s2 = "test"
|
95
|
+
s3 = OctetString.new("test")
|
96
|
+
assert_equal(s1, s2)
|
97
|
+
assert(s1 == s2)
|
98
|
+
assert_not_same(s1, s3)
|
99
|
+
assert_equal(s1, s3)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_object_id
|
103
|
+
id = ObjectId.new([1,3,6,1])
|
104
|
+
assert_equal("1.3.6.1", id.to_s)
|
105
|
+
assert_equal("\006\003+\006\001", id.encode)
|
106
|
+
assert_not_nil(id.asn1_type)
|
107
|
+
assert_equal("1.3.6.1", id.to_varbind.name.to_s)
|
108
|
+
|
109
|
+
assert_raise(ArgumentError) {
|
110
|
+
ObjectId.new("xyzzy")
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_object_id_create
|
115
|
+
assert_equal("1.3.6.1", ObjectId.new("1.3.6.1").to_s)
|
116
|
+
assert_equal("1.3.6.1", ObjectId.new([1,3,6,1]).to_s)
|
117
|
+
assert_equal("1.3.6.1", ObjectId.new(ObjectId.new("1.3.6.1")).to_s)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_object_id_equals
|
121
|
+
id1 = ObjectId.new("1.3.3.4")
|
122
|
+
id2 = ObjectId.new([1,3,3,4])
|
123
|
+
assert_not_same(id1, id2)
|
124
|
+
assert(id1 == id2)
|
125
|
+
assert_equal(id1, id2)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_object_id_comparable
|
129
|
+
id1 = ObjectId.new("1.3.3.4")
|
130
|
+
id2 = ObjectId.new("1.3.3.4.1")
|
131
|
+
id3 = ObjectId.new("1.3.3.4.5")
|
132
|
+
id4 = ObjectId.new("1.3.3.5")
|
133
|
+
assert(id1 < id2)
|
134
|
+
assert(id2 > id1)
|
135
|
+
assert(id2 < id3)
|
136
|
+
assert(id3 > id2)
|
137
|
+
assert(id3 < id4)
|
138
|
+
assert(id4 > id3)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_object_id_subtree
|
142
|
+
id1 = ObjectId.new("1.3.3.4")
|
143
|
+
id2 = ObjectId.new("1.3.3.4.1")
|
144
|
+
id3 = ObjectId.new("1.3.3.4.5")
|
145
|
+
id4 = ObjectId.new("1.3.3.5")
|
146
|
+
assert(id2.subtree_of?(id1))
|
147
|
+
assert(id3.subtree_of?(id1))
|
148
|
+
assert(!id3.subtree_of?(id2))
|
149
|
+
assert(!id1.subtree_of?(id2))
|
150
|
+
assert(!id4.subtree_of?(id1))
|
151
|
+
assert(!id4.subtree_of?(id3))
|
152
|
+
assert(id1.subtree_of?("1.3.3.4"))
|
153
|
+
assert(!id4.subtree_of?("1.3.3.4"))
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_object_name_from_string
|
157
|
+
id = ObjectName.new("1.3.4.5.6")
|
158
|
+
assert_equal("1.3.4.5.6", id.to_s)
|
159
|
+
assert_equal("\006\004+\004\005\006", id.encode)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_integer_create
|
163
|
+
i = Integer.new(12345)
|
164
|
+
assert_equal("12345", i.to_s)
|
165
|
+
assert_equal(12345, i.to_i)
|
166
|
+
assert_equal("\002\00209", i.encode)
|
167
|
+
assert_not_nil(i.asn1_type)
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_integer_decode
|
171
|
+
i = Integer.decode("09")
|
172
|
+
assert_equal(12345, i.to_i)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_integer_equal
|
176
|
+
i1 = Integer.new(12345)
|
177
|
+
i2 = Integer.new(12345)
|
178
|
+
i3 = 12345.2
|
179
|
+
i4 = 12345
|
180
|
+
assert_not_same(i1, i2)
|
181
|
+
assert_equal(i1, i2)
|
182
|
+
assert_equal(i4, i1)
|
183
|
+
assert_equal(i1, i4)
|
184
|
+
assert_equal(i1, i3)
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_integer_comparable
|
188
|
+
i1 = Integer.new(12345)
|
189
|
+
i2 = Integer.new(54321.0)
|
190
|
+
assert(i1 < i2)
|
191
|
+
assert(i2 > i1)
|
192
|
+
assert(123 < i1)
|
193
|
+
assert(123.0 < i1)
|
194
|
+
assert(i2 > 54000)
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_ip_address_from_string
|
198
|
+
ip = IpAddress.new("10.0.255.1")
|
199
|
+
assert_equal("10.0.255.1", ip.to_s)
|
200
|
+
assert_raise(InvalidIpAddress) { IpAddress.new("1233.2.3.4") }
|
201
|
+
assert_raise(InvalidIpAddress) { IpAddress.new("1.2.3.-1") }
|
202
|
+
assert_raise(InvalidIpAddress) { IpAddress.new("1.2.3") }
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_ip_address_create
|
206
|
+
ip = IpAddress.new("\001\002\003\004")
|
207
|
+
assert_equal("1.2.3.4", ip.to_s)
|
208
|
+
assert_equal("\001\002\003\004", ip.to_str)
|
209
|
+
assert_equal("@\004\001\002\003\004", ip.encode)
|
210
|
+
assert_not_nil(ip.asn1_type)
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_ip_address_decode
|
214
|
+
ip = IpAddress.decode("\001\002\003\004")
|
215
|
+
assert_equal("1.2.3.4", ip.to_s)
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_ip_address_equals
|
219
|
+
ip1 = IpAddress.new("1.2.3.4")
|
220
|
+
ip2 = IpAddress.new("1.2.3.4")
|
221
|
+
ip3 = IpAddress.new("10.2.3.4")
|
222
|
+
assert(ip1 == ip2)
|
223
|
+
assert(ip1.eql?(ip2))
|
224
|
+
assert(!ip1.equal?(ip2))
|
225
|
+
assert(ip1 != ip3)
|
226
|
+
assert(ip1.hash == ip2.hash)
|
227
|
+
assert(ip1.hash != ip3.hash)
|
228
|
+
assert(!ip1.eql?(12))
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_counter32_create
|
232
|
+
i = Counter32.new(12345)
|
233
|
+
assert_equal("12345", i.to_s)
|
234
|
+
assert_equal(12345, i.to_i)
|
235
|
+
assert_equal("\x41\00209", i.encode)
|
236
|
+
assert_not_nil(i.asn1_type)
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_counter32_decode
|
240
|
+
i = Counter32.decode("09")
|
241
|
+
assert_equal(12345, i.to_i)
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_counter64
|
245
|
+
i = Counter64.new(18446744073709551615)
|
246
|
+
assert_equal(18446744073709551615, i.to_i)
|
247
|
+
assert_equal("18446744073709551615", i.to_s)
|
248
|
+
assert_equal("F\t\000\377\377\377\377\377\377\377\377", i.encode)
|
249
|
+
assert_equal(i, Counter64.decode("\000\377\377\377\377\377\377\377\377"))
|
250
|
+
assert_not_nil(i.asn1_type)
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_opaque
|
254
|
+
q = Opaque.new("test")
|
255
|
+
assert_equal("D\004test", q.encode)
|
256
|
+
assert_equal("test", Opaque.decode("test"))
|
257
|
+
assert_equal("test", q.to_s)
|
258
|
+
assert_not_nil(q.asn1_type)
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_exception_methods
|
262
|
+
exception_types = [NoSuchObject, NoSuchInstance, EndOfMibView]
|
263
|
+
exception_types.each do |type|
|
264
|
+
assert(type.respond_to?(:decode))
|
265
|
+
assert(type.respond_to?(:encode))
|
266
|
+
assert_equal(type.asn1_type, type.to_s)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|