summaryrefslogtreecommitdiff
path: root/testing/fulltests/perl/T001basic.t
blob: c7af105db8ddfc3a91a4c6f9db53b24f9c253c2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/perl

# HEADER Basic perl functionality to a UDP agent

BEGIN {
    if (exists($ENV{'srcdir'})) {
	push @INC, "$ENV{'srcdir'}/testing/fulltests/support";
    } elsif (-d "fulltests/support") {
	push @INC, "fulltests/support";
    } elsif (-d "../support") {
	push @INC, "../support";
    }
}

use NetSNMPTest;
use Test;
use SNMP;

my $value;

plan(tests => 10);

ok(1,1,"started up");

# use a basic UDP port
my $destination = "udp:localhost:9897";

my $test = new NetSNMPTest(agentaddress => $destination);

# set it up with a snmpv3 USM user
$test->config_agent("createuser testuser MD5 notareallpassword");
$test->config_agent("rwuser testuser");
$test->config_agent("syscontact itworked");

$test->DIE("failed to start the agent") if (!$test->start_agent());

# now create a session to test things with
my $session = new SNMP::Session(DestHost => $destination,
                                Version => '3',
				SecName => 'testuser',
				SecLevel => 'authNoPriv',
				AuthProto => 'MD5',
				AuthPass => 'notareallpassword');

ok(ref($session), 'SNMP::Session', "created a session");


######################################################################
# GET test
$value = $session->get('sysContact.0');

ok($value, 'itworked');

######################################################################
# GETNEXT test
$value = $session->getnext('sysContact');

ok($value, 'itworked');

######################################################################
# SET test
$value = $session->get('sysLocation.0');

ok($value ne 'yep', 1, 'Ensuring the sysLocation setting is not "yep"');

my $varbind = new SNMP::Varbind(['sysLocation', '0', 'yep', 'OCTETSTR']);


$value = $session->set($varbind);

ok(($value == 0), 1, 'return value from set was a success');

my $value = $session->get('sysLocation.0');

ok($value, 'yep');

######################################################################
# GETBULK test
$varbind = new SNMP::Varbind(['sysContact']);
my @values = $session->getbulk(0, 3, $varbind);

ok($#values == 2);
ok($values[0] eq 'itworked');
ok($values[2] eq 'yep');

######################################################################
# gettable() test



######################################################################
# cleanup
$test->stop_agent();