Merge branch 'snmp'
This commit is contained in:
commit
1d78241115
47 changed files with 8494 additions and 46 deletions
|
|
@ -67,6 +67,8 @@ You can prefix a test with `BE=0` if you want to run your own backend.
|
|||
|
||||
You can prefix a test with `RC=0` if you want to run your own restconf process.
|
||||
|
||||
You can prefix a test with `SN=0` if you want to run your own SNMP process (in combination with `BE=0`)
|
||||
|
||||
To run with debug flags, use the `DBG=<number>` environment variable.
|
||||
|
||||
Other variables include:
|
||||
|
|
@ -150,6 +152,26 @@ If you do not have them, generate self-signed certs, eg as follows:
|
|||
|
||||
There are also client-cert tests, eg `test_ssl_certs.sh`
|
||||
|
||||
## SNMP
|
||||
|
||||
Clixon snmp frontend tests require a running netsnmpd and converted YANG files from MIB.
|
||||
|
||||
Netsnmpd is 5.9 or later and can be started via systemd. For the tests
|
||||
to run, the systems IFMIB should be disabled: `-I -ifTable,ifNumber,ifXTable,`, etc.
|
||||
|
||||
One way to start snmpd on Ubuntu, known to be working for the tests are: snmpd -Lo -p /var/run/snmpd.pid -I -ifXTable -I -ifTable -I -system_mib -I -sysORTable -I -snmpNotifyFilterTable -I -snmpNotifyTable -I -snmpNotifyFilterProfileTable
|
||||
|
||||
Converted YANG files are available at `https://github.com/clicon/mib-yangs` or alternatively use `smidump` version 0.5 or later. Clixon expects them to be at `/usr/local/share/mib-yangs/` by default, or configured by `--with-mib-generated-yang-dir=DIR`.
|
||||
|
||||
You also need to configure a unix socket for agent. Example of /etc/snmp/snmpd.conf:
|
||||
```
|
||||
master agentx
|
||||
agentaddress 127.0.0.1,[::1]
|
||||
rwcommunity public localhost
|
||||
agentXSocket unix:/var/run/snmp.sock
|
||||
agentxperms 777 777
|
||||
```
|
||||
|
||||
## Known issues
|
||||
|
||||
[Workaround: Unicode double-quote in iana-if-type@2022-03-07.yang](https://github.com/clicon/clixon/issues/315)
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ HAVE_HTTP1=@HAVE_HTTP1@
|
|||
# use it you need to set Clixon config option CLICON_YANG_REGEXP to libxml2
|
||||
WITH_LIBXML2=@with_libxml2@
|
||||
|
||||
# Check if we have support for Net-SNMP enabled or not.
|
||||
ENABLE_NETSNMP=@enable_netsnmp@
|
||||
|
||||
# C++ compiler
|
||||
CXX=@CXX@
|
||||
|
||||
|
|
@ -92,3 +95,4 @@ YANG_STANDARD_DIR=@YANG_STANDARD_DIR@
|
|||
|
||||
YANG_INSTALLDIR=@YANG_INSTALLDIR@
|
||||
|
||||
MIB_GENERATED_YANG_DIR=@MIB_GENERATED_YANG_DIR@
|
||||
|
|
|
|||
119
test/lib.sh
119
test/lib.sh
|
|
@ -53,6 +53,7 @@ testname=
|
|||
# 1: Start valgrind at every new testcase. Check result every next new
|
||||
# 2: Start valgrind every new backend start. Check when backend stops
|
||||
# 3: Start valgrind every new restconf start. Check when restconf stops
|
||||
# 4: Start valgrind every new snmp start. Check when snmp stops
|
||||
#
|
||||
: ${valgrindtest=0}
|
||||
|
||||
|
|
@ -73,6 +74,9 @@ testname=
|
|||
# eg logging to a file: RCLOG="-l f/www-data/restconf.log"
|
||||
: ${RCLOG:=}
|
||||
|
||||
# If set to 0, override starting of clixon_snmp in test (you bring your own)
|
||||
: ${SN:=1}
|
||||
|
||||
# Namespace: netconf base
|
||||
BASENS='urn:ietf:params:xml:ns:netconf:base:1.0'
|
||||
|
||||
|
|
@ -182,6 +186,13 @@ BUSER=clicon
|
|||
|
||||
: ${clixon_backend:=clixon_backend}
|
||||
|
||||
: ${clixon_snmp:=$(type -p clixon_snmp)}
|
||||
|
||||
: ${clixon_snmp_pidfile:="/var/tmp/clixon_snmp.pid"}
|
||||
|
||||
# Temporary debug var, set to trigger remaining snmp errors
|
||||
: ${snmp_debug:=false}
|
||||
|
||||
# Source the site-specific definitions for test script variables, if site.sh
|
||||
# exists. The variables defined in site.sh override any variables of the same
|
||||
# names in the environment in the current execution.
|
||||
|
|
@ -204,6 +215,76 @@ if [ ! -z ${YANG_STANDARD_DIR} ]; then
|
|||
: ${IETFRFC=$YANG_STANDARD_DIR/ietf/RFC}
|
||||
fi
|
||||
|
||||
: ${SNMPCHECK:=true}
|
||||
|
||||
if $SNMPCHECK; then
|
||||
snmpget="$(type -p snmpget) -On -c public -v2c localhost "
|
||||
snmpbulkget="$(type -p snmpbulkget) -On -c public -v2c localhost "
|
||||
snmpset="$(type -p snmpset) -On -c public -v2c localhost "
|
||||
snmpgetstr="$(type -p snmpget) -c public -v2c localhost "
|
||||
snmpgetnext="$(type -p snmpgetnext) -On -c public -v2c localhost "
|
||||
snmpgetnextstr="$(type -p snmpgetnext) -c public -v2c localhost "
|
||||
snmptable="$(type -p snmptable) -c public -v2c localhost "
|
||||
snmpwalk="$(type -p snmpwalk) -c public -v2c localhost "
|
||||
snmptranslate="$(type -p snmptranslate) "
|
||||
|
||||
if [ "${ENABLE_NETSNMP}" == "yes" ]; then
|
||||
pgrep snmpd > /dev/null
|
||||
if [ $? != 0 ]; then
|
||||
echo -e "\e[31m\nenable-netsnmp set but snmpd not running, start with:"
|
||||
echo "systemctl start snmpd"
|
||||
echo ""
|
||||
echo "snmpd must be configured to use a Unix socket for agent communication"
|
||||
echo "and have a rwcommunity configured, make sure the following lines are"
|
||||
echo "added to /etc/snmp/snmpd.conf:"
|
||||
echo ""
|
||||
echo " rwcommunity public localhost"
|
||||
echo " agentXSocket unix:/var/run/snmp.sock"
|
||||
echo " agentxperms 777 777"
|
||||
echo ""
|
||||
echo "If you don't rely on systemd you can configure the lines above"
|
||||
echo "and start snmpd manually with 'snmpd -Lo -p /var/run/snmpd.pid'."
|
||||
echo -e "\e[0m"
|
||||
exit -1
|
||||
fi
|
||||
fi
|
||||
|
||||
function validate_oid(){
|
||||
oid=$1
|
||||
oid2=$2
|
||||
type=$3
|
||||
value=$4
|
||||
result=$5
|
||||
|
||||
name="$($snmptranslate $oid)"
|
||||
name2="$($snmptranslate $oid2)"
|
||||
|
||||
if [[ $oid =~ ^([0-9]|\.)+$ ]]; then
|
||||
get=$snmpget
|
||||
getnext=$snmpgetnext
|
||||
else
|
||||
get=$snmpgetstr
|
||||
getnext=$snmpgetnextstr
|
||||
fi
|
||||
|
||||
if [ $oid == $oid2 ]; then
|
||||
if [ -z "$result" ]; then
|
||||
result="$oid = $type: $value"
|
||||
fi
|
||||
|
||||
new "Validating OID: $oid2 = $type: $value"
|
||||
expectpart "$($get $oid)" 0 "$result"
|
||||
else
|
||||
if [ -z "$result" ]; then
|
||||
result="$oid2 = $type: $value"
|
||||
fi
|
||||
|
||||
new "Validating next OID: $oid2 = $type: $value"
|
||||
expectpart "$($getnext $oid)" 0 "$result"
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
# Check sanity between --with-restconf setting and if nginx is started by systemd or not
|
||||
# This check is optional because some installs, such as vagrant make a non-systemd/direct
|
||||
# start
|
||||
|
|
@ -413,6 +494,31 @@ function chunked_framing()
|
|||
printf "\n#%s\n%s\n##\n" ${length} "${str}"
|
||||
}
|
||||
|
||||
# Start clixon_snmp
|
||||
function start_snmp(){
|
||||
cfg=$1
|
||||
|
||||
rm -f ${clixon_snmp_pidfile}
|
||||
|
||||
$clixon_snmp -f $cfg -D $DBG &
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
err
|
||||
fi
|
||||
}
|
||||
|
||||
# Stop clixon_snmp and Valgrind if needed
|
||||
function stop_snmp(){
|
||||
if [ $valgrindtest -eq 4 ]; then
|
||||
pkill -f clixon_snmp
|
||||
sleep 1
|
||||
checkvalgrind
|
||||
else
|
||||
killall -q clixon_snmp
|
||||
fi
|
||||
rm -f ${clixon_snmp_pidfile}
|
||||
}
|
||||
|
||||
# Start backend with all varargs.
|
||||
# If valgrindtest == 2, start valgrind
|
||||
function start_backend(){
|
||||
|
|
@ -544,6 +650,19 @@ function wait_restconf_stopped(){
|
|||
fi
|
||||
}
|
||||
|
||||
# Use pidfile to check snmp started. pidfile is created after init in clixon_snmp
|
||||
function wait_snmp()
|
||||
{
|
||||
let i=0;
|
||||
while [ ! -f ${clixon_snmp_pidfile} ]; do
|
||||
if [ $i -ge $DEMLOOP ]; then
|
||||
err1 "snmp timeout $DEMWAIT seconds"
|
||||
fi
|
||||
sleep $DEMSLEEP
|
||||
let i++;
|
||||
done
|
||||
}
|
||||
|
||||
# End of test, final tests before normal exit of test
|
||||
# Note this is a single test started by new, not a total test suite
|
||||
function endtest()
|
||||
|
|
|
|||
16
test/mem.sh
16
test/mem.sh
|
|
@ -18,6 +18,7 @@ function memonce(){
|
|||
clixon_netconf=
|
||||
clixon_backend=
|
||||
clixon_restconf=
|
||||
clixon_snmp=
|
||||
case "$what" in
|
||||
'cli')
|
||||
valgrindtest=1
|
||||
|
|
@ -43,8 +44,15 @@ function memonce(){
|
|||
clixon_restconf="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_restconf"
|
||||
|
||||
;;
|
||||
'snmp')
|
||||
valgrindtest=4 # This means snmp valgrind test
|
||||
sudo chmod 660 $valgrindfile
|
||||
: ${DEMWAIT:=15} # valgrind snmp needs some time to get up
|
||||
clixon_snmp="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_snmp"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "usage: $0 cli|netconf|restconf|backend" # valgrind memleak checks
|
||||
echo "usage: $0 cli|netconf|restconf|backend|snmp" # valgrind memleak checks
|
||||
rm -f $valgrindfile
|
||||
exit -1
|
||||
;;
|
||||
|
|
@ -86,16 +94,16 @@ function println(){
|
|||
}
|
||||
|
||||
if [ -z "$*" ]; then
|
||||
cmds="backend restconf cli netconf"
|
||||
cmds="backend restconf cli netconf snmp"
|
||||
else
|
||||
cmds=$*
|
||||
fi
|
||||
|
||||
# First run sanity
|
||||
for c in $cmds; do
|
||||
if [ $c != cli -a $c != netconf -a $c != restconf -a $c != backend ]; then
|
||||
if [ $c != cli -a $c != netconf -a $c != restconf -a $c != backend -a $c != snmp ]; then
|
||||
echo "c:$c"
|
||||
echo "usage: $0 [cli|netconf|restconf|backend]+"
|
||||
echo "usage: $0 [cli|netconf|restconf|backend|snmp]+"
|
||||
echo " with no args run all"
|
||||
exit -1
|
||||
fi
|
||||
|
|
|
|||
450
test/mibs/CLIXON-TYPES-MIB.txt
Normal file
450
test/mibs/CLIXON-TYPES-MIB.txt
Normal file
|
|
@ -0,0 +1,450 @@
|
|||
CLIXON-TYPES-MIB DEFINITIONS ::= BEGIN
|
||||
--
|
||||
-- Example MIB objects for agent module example implementations
|
||||
--
|
||||
IMPORTS
|
||||
MODULE-IDENTITY, OBJECT-TYPE, Integer32,
|
||||
TimeTicks, Counter32, Gauge32, Counter64,
|
||||
NOTIFICATION-TYPE, IpAddress FROM SNMPv2-SMI
|
||||
SnmpAdminString FROM SNMP-FRAMEWORK-MIB
|
||||
netSnmp FROM NET-SNMP-MIB
|
||||
TruthValue, TimeStamp,
|
||||
RowStatus, StorageType FROM SNMPv2-TC
|
||||
InetAddressType, InetAddress FROM INET-ADDRESS-MIB
|
||||
IANAifType FROM IANAifType-MIB
|
||||
;
|
||||
clixonExamples MODULE-IDENTITY
|
||||
LAST-UPDATED "200406150000Z"
|
||||
ORGANIZATION "www.net-snmp.org"
|
||||
CONTACT-INFO
|
||||
"postal: Wes Hardaker
|
||||
P.O. Box 382
|
||||
Davis CA 95617
|
||||
email: net-snmp-coders@lists.sourceforge.net"
|
||||
DESCRIPTION
|
||||
"Example MIB objects for agent module example implementations"
|
||||
REVISION "200406150000Z"
|
||||
DESCRIPTION
|
||||
"Corrected notification example definitions"
|
||||
REVISION "200202060000Z"
|
||||
DESCRIPTION
|
||||
"First draft"
|
||||
::= { netSnmp 200 }
|
||||
--
|
||||
-- top level structure
|
||||
--
|
||||
clixonExampleScalars OBJECT IDENTIFIER ::= { clixonExamples 1 }
|
||||
clixonExampleTables OBJECT IDENTIFIER ::= { clixonExamples 2 }
|
||||
clixonExampleNotifications OBJECT IDENTIFIER ::= { clixonExamples 3 }
|
||||
clixonTables OBJECT IDENTIFIER ::= { clixonExamples 4 }
|
||||
clixonInetTables OBJECT IDENTIFIER ::= { clixonExamples 5 }
|
||||
clixonExampleNotificationPrefix OBJECT IDENTIFIER
|
||||
::= { clixonExampleNotifications 0 }
|
||||
clixonExampleNotificationObjects OBJECT IDENTIFIER
|
||||
::= { clixonExampleNotifications 2 }
|
||||
-- clixonTutorial OBJECT IDENTIFIER ::= { clixonExamples 4 }
|
||||
--
|
||||
-- Example scalars
|
||||
--
|
||||
|
||||
clixonExampleInteger OBJECT-TYPE
|
||||
SYNTAX Integer32
|
||||
MAX-ACCESS read-write
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"This is a simple object which merely houses a writable
|
||||
integer. It's only purposes is to hold the value of a single
|
||||
integer. Writing to it will simply change the value for
|
||||
subsequent GET/GETNEXT/GETBULK retrievals.
|
||||
This example object is implemented in the
|
||||
agent/mibgroup/examples/scalar_int.c file."
|
||||
DEFVAL { 42 }
|
||||
::= { clixonExampleScalars 1 }
|
||||
clixonExampleSleeper OBJECT-TYPE
|
||||
SYNTAX Integer32
|
||||
MAX-ACCESS read-write
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"This is a simple object which is a basic integer. It's value
|
||||
indicates the number of seconds that the agent will take in
|
||||
responding to requests of this object. This is implemented
|
||||
in a way which will allow the agent to keep responding to
|
||||
other requests while access to this object is blocked. It is
|
||||
writable, and changing it's value will change the amount of
|
||||
time the agent will effectively wait for before returning a
|
||||
response when this object is manipulated. Note that SET
|
||||
requests through this object will take longer, since the
|
||||
delay is applied to each internal transaction phase, which
|
||||
could result in delays of up to 4 times the value of this
|
||||
object.
|
||||
This example object is implemented in the
|
||||
agent/mibgroup/examples/delayed_instance.c file."
|
||||
DEFVAL { 1 }
|
||||
::= { clixonExampleScalars 2 }
|
||||
clixonExampleString OBJECT-TYPE
|
||||
SYNTAX SnmpAdminString
|
||||
MAX-ACCESS read-write
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"This is a simple object which merely houses a writable
|
||||
string. It's only purposes is to hold the value of a single
|
||||
string. Writing to it will simply change the value for
|
||||
subsequent GET/GETNEXT/GETBULK retrievals.
|
||||
This example object is implemented in the
|
||||
agent/mibgroup/examples/watched.c file."
|
||||
DEFVAL { "So long, and thanks for all the fish!" }
|
||||
::= { clixonExampleScalars 3 }
|
||||
ifTableLastChange OBJECT-TYPE
|
||||
SYNTAX TimeTicks
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The value of sysUpTime at the time of the last creation or
|
||||
deletion of an entry in the ifTable. If the number of
|
||||
entries has been unchanged since the last re-initialization
|
||||
of the local network management subsystem, then this object
|
||||
contains a zero value."
|
||||
::= { clixonExampleScalars 4 }
|
||||
ifType OBJECT-TYPE
|
||||
SYNTAX IANAifType
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The type of interface. Additional values for ifType are
|
||||
assigned by the Internet Assigned Numbers Authority (IANA),
|
||||
through updating the syntax of the IANAifType textual
|
||||
convention."
|
||||
::= { clixonExampleScalars 5 }
|
||||
ifSpeed OBJECT-TYPE
|
||||
SYNTAX Gauge32
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"An estimate of the interface's current bandwidth in bits
|
||||
per second. For interfaces which do not vary in bandwidth
|
||||
or for those where no accurate estimation can be made, this
|
||||
object should contain the nominal bandwidth. If the
|
||||
bandwidth of the interface is greater than the maximum value
|
||||
reportable by this object then this object should report its
|
||||
maximum value (4,294,967,295) and ifHighSpeed must be used
|
||||
to report the interace's speed. For a sub-layer which has
|
||||
no concept of bandwidth, this object should be zero."
|
||||
::= { clixonExampleScalars 6 }
|
||||
ifAdminStatus OBJECT-TYPE
|
||||
SYNTAX INTEGER {
|
||||
up(1), -- ready to pass packets
|
||||
down(2),
|
||||
testing(3) -- in some test mode
|
||||
}
|
||||
MAX-ACCESS read-write
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The desired state of the interface. The testing(3) state
|
||||
indicates that no operational packets can be passed. When a
|
||||
managed system initializes, all interfaces start with
|
||||
ifAdminStatus in the down(2) state. As a result of either
|
||||
explicit management action or per configuration information
|
||||
retained by the managed system, ifAdminStatus is then
|
||||
changed to either the up(1) or testing(3) states (or remains
|
||||
in the down(2) state)."
|
||||
::= { clixonExampleScalars 7}
|
||||
ifInOctets OBJECT-TYPE
|
||||
SYNTAX Counter32
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The total number of octets received on the interface,
|
||||
including framing characters.
|
||||
Discontinuities in the value of this counter can occur at
|
||||
re-initialization of the management system, and at other
|
||||
times as indicated by the value of
|
||||
ifCounterDiscontinuityTime."
|
||||
::= { clixonExampleScalars 8}
|
||||
ifHCInOctets OBJECT-TYPE
|
||||
SYNTAX Counter64
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The total number of octets received on the interface,
|
||||
including framing characters. This object is a 64-bit
|
||||
version of ifInOctets.
|
||||
Discontinuities in the value of this counter can occur at
|
||||
re-initialization of the management system, and at other
|
||||
times as indicated by the value of
|
||||
ifCounterDiscontinuityTime."
|
||||
::= { clixonExampleScalars 9}
|
||||
ifPromiscuousMode OBJECT-TYPE
|
||||
SYNTAX TruthValue
|
||||
MAX-ACCESS read-write
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"This object has a value of false(2) if this interface only
|
||||
accepts packets/frames that are addressed to this station.
|
||||
This object has a value of true(1) when the station accepts
|
||||
all packets/frames transmitted on the media. The value
|
||||
true(1) is only legal on certain types of media. If legal,
|
||||
setting this object to a value of true(1) may require the
|
||||
interface to be reset before becoming effective.
|
||||
The value of ifPromiscuousMode does not affect the reception
|
||||
of broadcast and multicast packets/frames by the interface."
|
||||
::= { clixonExampleScalars 10 }
|
||||
ifCounterDiscontinuityTime OBJECT-TYPE
|
||||
SYNTAX TimeStamp
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The value of sysUpTime on the most recent occasion at which
|
||||
any one or more of this interface's counters suffered a
|
||||
discontinuity. The relevant counters are the specific
|
||||
instances associated with this interface of any Counter32 or
|
||||
Counter64 object contained in the ifTable or ifXTable. If
|
||||
no such discontinuities have occurred since the last re-
|
||||
initialization of the local management subsystem, then this
|
||||
object contains a zero value."
|
||||
::= { clixonExampleScalars 11 }
|
||||
ifStackStatus OBJECT-TYPE
|
||||
SYNTAX RowStatus
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The status of the relationship between two sub-layers.
|
||||
Changing the value of this object from 'active' to
|
||||
'notInService' or 'destroy' will likely have consequences up
|
||||
and down the interface stack. Thus, write access to this
|
||||
object is likely to be inappropriate for some types of
|
||||
interfaces, and many implementations will choose not to
|
||||
support write-access for any type of interface."
|
||||
::= { clixonExampleScalars 12 }
|
||||
|
||||
ifIpAddr OBJECT-TYPE
|
||||
SYNTAX IpAddress
|
||||
MAX-ACCESS read-write
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"IP address example."
|
||||
::= { clixonExampleScalars 13 }
|
||||
|
||||
--
|
||||
-- Example Tables
|
||||
--
|
||||
clixonIETFWGTable OBJECT-TYPE
|
||||
SYNTAX SEQUENCE OF ClixonIETFWGEntry
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"This table merely contains a set of data which is otherwise
|
||||
useless for true network management. It is a table which
|
||||
describes properies about a IETF Working Group, such as the
|
||||
names of the two working group chairs.
|
||||
This example table is implemented in the
|
||||
agent/mibgroup/examples/data_set.c file."
|
||||
::= { clixonExampleTables 1 }
|
||||
clixonIETFWGEntry OBJECT-TYPE
|
||||
SYNTAX ClixonIETFWGEntry
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"A row describing a given working group"
|
||||
INDEX { nsIETFWGName }
|
||||
::= {clixonIETFWGTable 1 }
|
||||
ClixonIETFWGEntry ::= SEQUENCE {
|
||||
nsIETFWGName INTEGER,
|
||||
nsIETFWGChair1 OCTET STRING,
|
||||
nsIETFWGChair2 OCTET STRING
|
||||
}
|
||||
nsIETFWGName OBJECT-TYPE
|
||||
SYNTAX INTEGER (1..2147483647)
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The name of the IETF Working Group this table describes."
|
||||
::= { clixonIETFWGEntry 1 }
|
||||
nsIETFWGChair1 OBJECT-TYPE
|
||||
SYNTAX OCTET STRING
|
||||
MAX-ACCESS read-write
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"One of the names of the chairs for the IETF working group."
|
||||
::= { clixonIETFWGEntry 2 }
|
||||
nsIETFWGChair2 OBJECT-TYPE
|
||||
SYNTAX OCTET STRING
|
||||
MAX-ACCESS read-create
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The other name, if one exists, of the chairs for the IETF
|
||||
working group."
|
||||
::= { clixonIETFWGEntry 3 }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
clixonTable OBJECT-TYPE
|
||||
SYNTAX SEQUENCE OF ClixonEntry
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"This table merely contains a set of data which is otherwise
|
||||
useless for true network management. It is a table which
|
||||
describes properies about a IETF Working Group, such as the
|
||||
names of the two working group chairs.
|
||||
This example table is implemented in the
|
||||
agent/mibgroup/examples/data_set.c file."
|
||||
::= { clixonTables 1 }
|
||||
clixonEntry OBJECT-TYPE
|
||||
SYNTAX ClixonEntry
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"A row describing a given working group"
|
||||
INDEX { nsName }
|
||||
::= {clixonTable 1 }
|
||||
ClixonEntry ::= SEQUENCE {
|
||||
nsName INTEGER,
|
||||
nsChair1 OCTET STRING,
|
||||
nsChair2 OCTET STRING
|
||||
}
|
||||
nsName OBJECT-TYPE
|
||||
SYNTAX INTEGER (1..2147483647)
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The name of the IETF Working Group this table describes."
|
||||
::= { clixonEntry 1 }
|
||||
nsChair1 OBJECT-TYPE
|
||||
SYNTAX OCTET STRING
|
||||
MAX-ACCESS read-write
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"One of the names of the chairs for the IETF working group."
|
||||
::= { clixonEntry 2 }
|
||||
nsChair2 OBJECT-TYPE
|
||||
SYNTAX OCTET STRING
|
||||
MAX-ACCESS read-create
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The other name, if one exists, of the chairs for the IETF
|
||||
working group."
|
||||
::= { clixonEntry 3 }
|
||||
|
||||
|
||||
--
|
||||
-- A table used in a table_iterator example
|
||||
-- (agent/mibgroup/examples/clixonHostsTable*.[ch])
|
||||
--
|
||||
clixonHostsTable OBJECT-TYPE
|
||||
SYNTAX SEQUENCE OF ClixonHostsEntry
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"An example table that implements a wrapper around the
|
||||
/etc/hosts file on a machine using the iterator helper API."
|
||||
::= { clixonExampleTables 2 }
|
||||
clixonHostsEntry OBJECT-TYPE
|
||||
SYNTAX ClixonHostsEntry
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"A host name mapped to an ip address"
|
||||
INDEX { clixonHostName }
|
||||
::= { clixonHostsTable 1 }
|
||||
ClixonHostsEntry ::= SEQUENCE {
|
||||
clixonHostName OCTET STRING,
|
||||
clixonHostAddressType InetAddressType,
|
||||
clixonHostAddress InetAddress,
|
||||
clixonHostStorage StorageType,
|
||||
clixonHostRowStatus RowStatus
|
||||
}
|
||||
|
||||
clixonHostName OBJECT-TYPE
|
||||
SYNTAX OCTET STRING (SIZE(0..64))
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"A host name that exists in the /etc/hosts (unix) file."
|
||||
::= { clixonHostsEntry 1 }
|
||||
clixonHostAddressType OBJECT-TYPE
|
||||
SYNTAX InetAddressType
|
||||
MAX-ACCESS read-create
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The address type of then given host."
|
||||
::= { clixonHostsEntry 2 }
|
||||
clixonHostAddress OBJECT-TYPE
|
||||
SYNTAX InetAddress
|
||||
MAX-ACCESS read-create
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The address of then given host."
|
||||
::= { clixonHostsEntry 3 }
|
||||
clixonHostStorage OBJECT-TYPE
|
||||
SYNTAX StorageType
|
||||
MAX-ACCESS read-create
|
||||
STATUS current
|
||||
DESCRIPTION "The storage type for this conceptual row."
|
||||
DEFVAL { nonVolatile }
|
||||
::= { clixonHostsEntry 4 }
|
||||
clixonHostRowStatus OBJECT-TYPE
|
||||
SYNTAX RowStatus
|
||||
MAX-ACCESS read-create
|
||||
STATUS current
|
||||
DESCRIPTION "The status of this conceptual row."
|
||||
::= { clixonHostsEntry 5 }
|
||||
|
||||
clixonObjectID OBJECT-TYPE
|
||||
SYNTAX OBJECT IDENTIFIER
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The vendor's authoritative identification of the
|
||||
network management subsystem contained in the entity.
|
||||
This value is allocated within the SMI enterprises
|
||||
subtree (1.3.6.1.4.1) and provides an easy and
|
||||
unambiguous means for determining `what kind of box' is
|
||||
being managed. For example, if vendor `Flintstones,
|
||||
Inc.' was assigned the subtree 1.3.6.1.4.1.424242,
|
||||
it could assign the identifier 1.3.6.1.4.1.424242.1.1
|
||||
to its `Fred Router'."
|
||||
::= { netSnmp 3 }
|
||||
|
||||
|
||||
clixonInetTable OBJECT-TYPE
|
||||
SYNTAX SEQUENCE OF ClixonInetEntry
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"This table merely contains a set of data which is otherwise
|
||||
useless for true network management. It is a table which
|
||||
describes properies about a IETF Working Group, such as the
|
||||
names of the two working group chairs.
|
||||
This example table is implemented in the
|
||||
agent/mibgroup/examples/data_set.c file."
|
||||
::= { clixonExampleTables 3 }
|
||||
clixonInetEntry OBJECT-TYPE
|
||||
SYNTAX ClixonInetEntry
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"A row describing a given working group"
|
||||
INDEX { clixonAddress }
|
||||
::= {clixonInetTable 1 }
|
||||
ClixonInetEntry ::= SEQUENCE {
|
||||
clixonAddress InetAddress,
|
||||
clixonString OCTET STRING
|
||||
}
|
||||
clixonAddress OBJECT-TYPE
|
||||
SYNTAX InetAddress
|
||||
MAX-ACCESS not-accessible
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The name of the IETF Working Group this table describes."
|
||||
::= { clixonInetEntry 2 }
|
||||
clixonString OBJECT-TYPE
|
||||
SYNTAX OCTET STRING
|
||||
MAX-ACCESS read-write
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"One of the names of the chairs for the IETF working group."
|
||||
::= { clixonInetEntry 3 }
|
||||
|
||||
END
|
||||
1411
test/mibs/ENTITY-MIB
Normal file
1411
test/mibs/ENTITY-MIB
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -208,6 +208,12 @@ wait_backend
|
|||
new "expand identityref 1st level"
|
||||
expectpart "$(echo "set identityrefs identityref ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 "ex:des" "ex:des2" "ex:des3"
|
||||
|
||||
# XXX something wrong sometimes in this test on docker.
|
||||
# Expected:
|
||||
# <name>
|
||||
# CLI syntax error: "set leafrefs leafref": Incomplete command
|
||||
echo "set leafrefs leafref ?" | $clixon_cli -f $cfg -o CLICON_CLI_EXPAND_LEAFREF=false
|
||||
|
||||
new "expand leafref 1st level"
|
||||
expectpart "$(echo "set leafrefs leafref ?" | $clixon_cli -f $cfg -o CLICON_CLI_EXPAND_LEAFREF=false 2> /dev/null)" 0 "<name>" --not-- "91" "92" "93"
|
||||
|
||||
|
|
|
|||
516
test/test_snmp_entity.sh
Executable file
516
test/test_snmp_entity.sh
Executable file
|
|
@ -0,0 +1,516 @@
|
|||
#!/usr/bin/env bash
|
||||
# SNMP "smoketest" Basic snmpget test for a scalar
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
# Re-use main example backend state callbacks
|
||||
APPNAME=example
|
||||
|
||||
if [ ${ENABLE_NETSNMP} != "yes" ]; then
|
||||
echo "Skipping test, Net-SNMP support not enabled."
|
||||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
fi
|
||||
|
||||
cfg=$dir/conf_startup.xml
|
||||
fyang=$dir/clixon-example.yang
|
||||
fstate=$dir/state.xml
|
||||
|
||||
# AgentX unix socket
|
||||
SOCK=/var/run/snmp.sock
|
||||
|
||||
# Relies on example_backend.so for $fstate file handling
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${YANG_STANDARD_DIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${MIB_GENERATED_YANG_DIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_BACKEND_PIDFILE>/var/tmp/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
|
||||
<CLICON_SNMP_MIB>ENTITY-MIB</CLICON_SNMP_MIB>
|
||||
<CLICON_VALIDATE_STATE_XML>true</CLICON_VALIDATE_STATE_XML>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
cat <<EOF > $fyang
|
||||
module clixon-example{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:clixon";
|
||||
prefix ex;
|
||||
import ENTITY-MIB {
|
||||
prefix "entity-mib";
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# This is state data written to file that backend reads from (on request)
|
||||
# integer and string have values, sleeper does not and uses default (=1)
|
||||
|
||||
cat <<EOF > $fstate
|
||||
<ENTITY-MIB xmlns="urn:ietf:params:xml:ns:yang:smiv2:ENTITY-MIB">
|
||||
<entPhysicalTable>
|
||||
<entPhysicalEntry>
|
||||
<entPhysicalIndex>1</entPhysicalIndex>
|
||||
<entPhysicalDescr>Entity 1</entPhysicalDescr>
|
||||
<entPhysicalVendorType>1.3.6.1.2.1.4</entPhysicalVendorType>
|
||||
<entPhysicalContainedIn>9</entPhysicalContainedIn>
|
||||
<entPhysicalClass>powerSupply</entPhysicalClass>
|
||||
<entPhysicalParentRelPos>123</entPhysicalParentRelPos>
|
||||
<entPhysicalName>ABCD1234</entPhysicalName>
|
||||
<entPhysicalHardwareRev>REV 099</entPhysicalHardwareRev>
|
||||
<entPhysicalFirmwareRev>REV 123</entPhysicalFirmwareRev>
|
||||
<entPhysicalSoftwareRev>Clixon Version XXX.YYY year ZZZ</entPhysicalSoftwareRev>
|
||||
<entPhysicalSerialNum>1234-1234-ABCD-ABCD</entPhysicalSerialNum>
|
||||
<entPhysicalMfgName>Olof Hagsand Datakonsult AB</entPhysicalMfgName>
|
||||
<entPhysicalModelName>Model AA.BB</entPhysicalModelName>
|
||||
<entPhysicalAlias>Alias 123</entPhysicalAlias>
|
||||
<entPhysicalAssetID>Asset 123</entPhysicalAssetID>
|
||||
<entPhysicalIsFRU>true</entPhysicalIsFRU>
|
||||
<entPhysicalMfgDate>11111111</entPhysicalMfgDate>
|
||||
<!-- <entPhysicalUris></entPhysicalUris>-->
|
||||
<!-- <entPhysicalUUID></entPhysicalUUID> -->
|
||||
</entPhysicalEntry>
|
||||
<entPhysicalEntry>
|
||||
<entPhysicalIndex>2</entPhysicalIndex>
|
||||
<entPhysicalDescr>Entity 2</entPhysicalDescr>
|
||||
<entPhysicalVendorType>1.3.6.1.2.1.4</entPhysicalVendorType>
|
||||
<entPhysicalContainedIn>4</entPhysicalContainedIn>
|
||||
<entPhysicalClass>powerSupply</entPhysicalClass>
|
||||
<entPhysicalParentRelPos>999</entPhysicalParentRelPos>
|
||||
<entPhysicalName>XXZZ11994</entPhysicalName>
|
||||
<entPhysicalHardwareRev>REV 100</entPhysicalHardwareRev>
|
||||
<entPhysicalFirmwareRev>REV 234</entPhysicalFirmwareRev>
|
||||
<entPhysicalSoftwareRev>Clixon Version XXX.YYY year ZZZ</entPhysicalSoftwareRev>
|
||||
<entPhysicalSerialNum>2345-2345-ABCD-ABCD</entPhysicalSerialNum>
|
||||
<entPhysicalMfgName>Olof Hagsand Datakonsult AB</entPhysicalMfgName>
|
||||
<entPhysicalModelName>Model CC.DD</entPhysicalModelName>
|
||||
<entPhysicalAlias>Alias 456</entPhysicalAlias>
|
||||
<entPhysicalAssetID>Asset 456</entPhysicalAssetID>
|
||||
<entPhysicalIsFRU>false</entPhysicalIsFRU>
|
||||
<entPhysicalMfgDate>22222222</entPhysicalMfgDate>
|
||||
<!-- <entPhysicalUris></entPhysicalUris> -->
|
||||
<!-- <entPhysicalUUID></entPhysicalUUID> -->
|
||||
</entPhysicalEntry>
|
||||
</entPhysicalTable>
|
||||
</ENTITY-MIB>
|
||||
EOF
|
||||
|
||||
function testinit(){
|
||||
new "test params: -f $cfg -- -sS $fstate"
|
||||
if [ $BE -ne 0 ]; then
|
||||
# Kill old backend and start a new one
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err "Failed to start backend"
|
||||
fi
|
||||
|
||||
sudo pkill -f clixon_backend
|
||||
|
||||
new "Starting backend"
|
||||
start_backend -s init -f $cfg -- -sS $fstate
|
||||
fi
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
if [ $SN -ne 0 ]; then
|
||||
# Kill old clixon_snmp, if any
|
||||
new "Terminating any old clixon_snmp processes"
|
||||
sudo killall -q clixon_snmp
|
||||
|
||||
new "Starting clixon_snmp"
|
||||
start_snmp $cfg &
|
||||
fi
|
||||
|
||||
new "wait snmp"
|
||||
wait_snmp
|
||||
}
|
||||
|
||||
function testexit(){
|
||||
stop_snmp
|
||||
}
|
||||
|
||||
ENTITY_OID=".1.3.6.1.2.1.47.1.1.1"
|
||||
|
||||
OID1="${ENTITY_OID}.1.1.1"
|
||||
OID2="${ENTITY_OID}.1.1.2"
|
||||
OID3="${ENTITY_OID}.1.2.1"
|
||||
OID4="${ENTITY_OID}.1.2.2"
|
||||
OIDX="${ENTITY_OID}.1.3.1"
|
||||
OIDY="${ENTITY_OID}.1.3.2"
|
||||
OID5="${ENTITY_OID}.1.4.1"
|
||||
OID6="${ENTITY_OID}.1.4.2"
|
||||
OID7="${ENTITY_OID}.1.5.1"
|
||||
OID8="${ENTITY_OID}.1.5.2"
|
||||
OID9="${ENTITY_OID}.1.6.1"
|
||||
OID10="${ENTITY_OID}.1.6.2"
|
||||
OID11="${ENTITY_OID}.1.7.1"
|
||||
OID12="${ENTITY_OID}.1.7.2"
|
||||
OID13="${ENTITY_OID}.1.8.1"
|
||||
OID14="${ENTITY_OID}.1.8.2"
|
||||
OID15="${ENTITY_OID}.1.9.1"
|
||||
OID16="${ENTITY_OID}.1.9.2"
|
||||
OID17="${ENTITY_OID}.1.10.1"
|
||||
OID18="${ENTITY_OID}.1.10.2"
|
||||
OID19="${ENTITY_OID}.1.11.1"
|
||||
OID20="${ENTITY_OID}.1.11.2"
|
||||
OID21="${ENTITY_OID}.1.12.1"
|
||||
OID22="${ENTITY_OID}.1.12.2"
|
||||
OID23="${ENTITY_OID}.1.13.1"
|
||||
OID24="${ENTITY_OID}.1.13.2"
|
||||
OID25="${ENTITY_OID}.1.14.1"
|
||||
OID26="${ENTITY_OID}.1.14.2"
|
||||
OID27="${ENTITY_OID}.1.15.1"
|
||||
OID28="${ENTITY_OID}.1.15.2"
|
||||
OID29="${ENTITY_OID}.1.16.1"
|
||||
OID30="${ENTITY_OID}.1.16.2"
|
||||
OID31="${ENTITY_OID}.1.17.1"
|
||||
OID32="${ENTITY_OID}.1.17.2"
|
||||
|
||||
NAME1="ENTITY-MIB::entPhysicalIndex.1"
|
||||
NAME2="ENTITY-MIB::entPhysicalIndex.2"
|
||||
NAME3="ENTITY-MIB::entPhysicalDescr.1"
|
||||
NAME4="ENTITY-MIB::entPhysicalDescr.2"
|
||||
NAMEX="ENTITY-MIB::entPhysicalVendorType.1"
|
||||
NAMEY="ENTITY-MIB::entPhysicalVendorType.2"
|
||||
NAME5="ENTITY-MIB::entPhysicalContainedIn.1"
|
||||
NAME6="ENTITY-MIB::entPhysicalContainedIn.2"
|
||||
NAME7="ENTITY-MIB::entPhysicalClass.1"
|
||||
NAME8="ENTITY-MIB::entPhysicalClass.2"
|
||||
NAME9="ENTITY-MIB::entPhysicalParentRelPos.1"
|
||||
NAME10="ENTITY-MIB::entPhysicalParentRelPos.2"
|
||||
NAME11="ENTITY-MIB::entPhysicalName.1"
|
||||
NAME12="ENTITY-MIB::entPhysicalName.2"
|
||||
NAME13="ENTITY-MIB::entPhysicalHardwareRev.1"
|
||||
NAME14="ENTITY-MIB::entPhysicalHardwareRev.2"
|
||||
NAME15="ENTITY-MIB::entPhysicalFirmwareRev.1"
|
||||
NAME16="ENTITY-MIB::entPhysicalFirmwareRev.2"
|
||||
NAME17="ENTITY-MIB::entPhysicalSoftwareRev.1"
|
||||
NAME18="ENTITY-MIB::entPhysicalSoftwareRev.2"
|
||||
NAME19="ENTITY-MIB::entPhysicalSerialNum.1"
|
||||
NAME20="ENTITY-MIB::entPhysicalSerialNum.2"
|
||||
NAME21="ENTITY-MIB::entPhysicalMfgName.1"
|
||||
NAME22="ENTITY-MIB::entPhysicalMfgName.2"
|
||||
NAME23="ENTITY-MIB::entPhysicalModelName.1"
|
||||
NAME24="ENTITY-MIB::entPhysicalModelName.2"
|
||||
NAME25="ENTITY-MIB::entPhysicalAlias.1"
|
||||
NAME26="ENTITY-MIB::entPhysicalAlias.2"
|
||||
NAME27="ENTITY-MIB::entPhysicalAssetID.1"
|
||||
NAME28="ENTITY-MIB::entPhysicalAssetID.2"
|
||||
NAME29="ENTITY-MIB::entPhysicalIsFRU.1"
|
||||
NAME30="ENTITY-MIB::entPhysicalIsFRU.2"
|
||||
NAME31="ENTITY-MIB::entPhysicalMfgDate.1"
|
||||
NAME32="ENTITY-MIB::entPhysicalMfgDate.2"
|
||||
NAME33="ENTITY-MIB::entPhysicalUris.1"
|
||||
NAME34="ENTITY-MIB::entPhysicalUris.2"
|
||||
NAME35="ENTITY-MIB::entPhysicalUris.2"
|
||||
|
||||
new "SNMP system tests"
|
||||
testinit
|
||||
|
||||
new "Get index, $OID1"
|
||||
validate_oid $OID1 $OID1 "INTEGER" "1"
|
||||
validate_oid $NAME1 $NAME1 "INTEGER" "1"
|
||||
|
||||
new "Get next $OID1"
|
||||
validate_oid $OID1 $OID2 "INTEGER" "2"
|
||||
validate_oid $NAME1 $NAME2 "INTEGER" "2"
|
||||
|
||||
new "Get index, $OID2"
|
||||
validate_oid $OID2 $OID2 "INTEGER" "2"
|
||||
validate_oid $NAME2 $NAME2 "INTEGER" "2"
|
||||
|
||||
new "Get next $OID2"
|
||||
validate_oid $OID2 $OID3 "STRING" "\"Entity 1\""
|
||||
validate_oid $NAME2 $NAME3 "STRING" "Entity 1"
|
||||
|
||||
new "Get index, $OID3"
|
||||
validate_oid $OID3 $OID3 "STRING" "\"Entity 1\""
|
||||
validate_oid $NAME3 $NAME3 "STRING" "Entity 1"
|
||||
|
||||
new "Get next $OID4"
|
||||
validate_oid $OID3 $OID4 "STRING" "\"Entity 2\""
|
||||
validate_oid $NAME3 $NAME4 "STRING" "Entity 2"
|
||||
|
||||
new "Get index, $OID4"
|
||||
validate_oid $OID4 $OID4 "STRING" "\"Entity 2\""
|
||||
validate_oid $NAME4 $NAME4 "STRING" "Entity 2"
|
||||
|
||||
new "Get next $OID4"
|
||||
validate_oid $OID4 $OIDX "OID" ".1.3.6.1.2.1.4"
|
||||
validate_oid $NAME4 $NAMEX "OID" "IP-MIB::ip"
|
||||
|
||||
new "Get $NAMEX"
|
||||
validate_oid $OIDX $OIDX "OID" ".1.3.6.1.2.1.4"
|
||||
validate_oid $NAMEX $NAMEX "OID" "IP-MIB::ip"
|
||||
|
||||
new "Get next $NAMEX"
|
||||
validate_oid $OIDX $OIDY "OID" ".1.3.6.1.2.1.4"
|
||||
validate_oid $NAMEX $NAMEY "OID" "IP-MIB::ip"
|
||||
|
||||
new "Get $NAMEY"
|
||||
validate_oid $OIDY $OIDY "OID" ".1.3.6.1.2.1.4"
|
||||
validate_oid $NAMEY $NAMEY "OID" "IP-MIB::ip"
|
||||
|
||||
new "Get next $NAMEY"
|
||||
validate_oid $OIDY $OID5 "INTEGER" 9
|
||||
validate_oid $NAMEY $NAME5 "INTEGER" 9
|
||||
|
||||
new "Get container, $OID5"
|
||||
validate_oid $OID5 $OID5 "INTEGER" "9"
|
||||
validate_oid $NAME5 $NAME5 "INTEGER" "9"
|
||||
|
||||
new "Get next container, $OID5"
|
||||
validate_oid $OID5 $OID6 "INTEGER" "4"
|
||||
validate_oid $NAME5 $NAME6 "INTEGER" "4"
|
||||
|
||||
new "Get container, $OID6"
|
||||
validate_oid $OID6 $OID6 "INTEGER" "4"
|
||||
validate_oid $NAME6 $NAME6 "INTEGER" "4"
|
||||
|
||||
new "Get next container, $OID6"
|
||||
validate_oid $OID6 $OID7 "INTEGER" "6"
|
||||
validate_oid $NAME6 $NAME7 "INTEGER" "powerSupply(6)"
|
||||
|
||||
new "Get container, $OID7"
|
||||
validate_oid $OID7 $OID7 "INTEGER" "6"
|
||||
validate_oid $NAME7 $NAME7 "INTEGER" "powerSupply(6)"
|
||||
|
||||
new "Get next container, $OID7"
|
||||
validate_oid $OID7 $OID8 "INTEGER" "6"
|
||||
validate_oid $NAME7 $NAME8 "INTEGER" "powerSupply(6)"
|
||||
|
||||
new "Get container, $OID8"
|
||||
validate_oid $OID8 $OID8 "INTEGER" "6"
|
||||
validate_oid $NAME8 $NAME8 "INTEGER" "powerSupply(6)"
|
||||
|
||||
new "Get next container, $OID8"
|
||||
validate_oid $OID8 $OID9 "INTEGER" 123
|
||||
validate_oid $NAME8 $NAME9 "INTEGER" 123
|
||||
|
||||
new "Get name, $OID9"
|
||||
validate_oid $OID9 $OID9 "INTEGER" 123
|
||||
validate_oid $NAME9 $NAME9 "INTEGER" 123
|
||||
|
||||
new "Get next, $OID9"
|
||||
validate_oid $OID9 $OID10 "INTEGER" 999
|
||||
validate_oid $NAME9 $NAME10 "INTEGER" 999
|
||||
|
||||
new "Get name, $OID10"
|
||||
validate_oid $OID10 $OID10 "INTEGER" 999
|
||||
validate_oid $NAME10 $NAME10 "INTEGER" 999
|
||||
|
||||
new "Get name, $OID11"
|
||||
validate_oid $OID11 $OID11 "STRING" "\"ABCD1234\""
|
||||
validate_oid $NAME11 $NAME11 "STRING" "ABCD1234"
|
||||
|
||||
new "Get next, $OID11"
|
||||
validate_oid $OID11 $OID12 "STRING" "\"XXZZ11994\""
|
||||
validate_oid $NAME11 $NAME12 "STRING" "XXZZ11994"
|
||||
|
||||
new "Get name, $OID12"
|
||||
validate_oid $OID12 $OID12 "STRING" "\"XXZZ11994\""
|
||||
validate_oid $NAME12 $NAME12 "STRING" "XXZZ11994"
|
||||
|
||||
new "Get next, $OID12"
|
||||
validate_oid $OID12 $OID13 "STRING" "\"REV 099\""
|
||||
validate_oid $NAME12 $NAME13 "STRING" "REV 099"
|
||||
|
||||
new "Get rev, $OID13"
|
||||
validate_oid $OID13 $OID13 "STRING" "\"REV 099\""
|
||||
validate_oid $NAME13 $NAME13 "STRING" "REV 099"
|
||||
|
||||
new "Get next hw rev, $OID13"
|
||||
validate_oid $OID13 $OID14 "STRING" "\"REV 100\""
|
||||
validate_oid $NAME13 $NAME14 "STRING" "REV 100"
|
||||
|
||||
new "Get hw rev, $OID14"
|
||||
validate_oid $OID14 $OID14 "STRING" "\"REV 100\""
|
||||
validate_oid $NAME14 $NAME14 "STRING" "REV 100"
|
||||
|
||||
new "Get next hw rev, $OID14"
|
||||
validate_oid $OID14 $OID15 "STRING" "\"REV 123\""
|
||||
validate_oid $NAME14 $NAME15 "STRING" "REV 123"
|
||||
|
||||
new "Get fw rev, $OID15"
|
||||
validate_oid $OID15 $OID15 "STRING" "\"REV 123\""
|
||||
validate_oid $NAME15 $NAME15 "STRING" "REV 123"
|
||||
|
||||
new "Get next fw rev, $OID15"
|
||||
validate_oid $OID15 $OID16 "STRING" "\"REV 234\""
|
||||
validate_oid $NAME15 $NAME16 "STRING" "REV 234"
|
||||
|
||||
new "Get fw rev, $OID16"
|
||||
validate_oid $OID16 $OID16 "STRING" "\"REV 234\""
|
||||
validate_oid $NAME16 $NAME16 "STRING" "REV 234"
|
||||
|
||||
new "Get next fw rev, $OID16"
|
||||
validate_oid $OID16 $OID17 "STRING" "\"Clixon Version XXX.YYY year ZZZ\""
|
||||
validate_oid $NAME16 $NAME17 "STRING" "Clixon Version XXX.YYY year ZZZ"
|
||||
|
||||
new "Get sw rev, $OID7"
|
||||
validate_oid $OID17 $OID17 "STRING" "\"Clixon Version XXX.YYY year ZZZ\""
|
||||
validate_oid $NAME17 $NAME17 "STRING" "Clixon Version XXX.YYY year ZZZ"
|
||||
|
||||
new "Get next sw rev, $OID17"
|
||||
validate_oid $OID17 $OID18 "STRING" "\"Clixon Version XXX.YYY year ZZZ\""
|
||||
validate_oid $NAME17 $NAME18 "STRING" "Clixon Version XXX.YYY year ZZZ"
|
||||
|
||||
new "Get sw rev, $OID18"
|
||||
validate_oid $OID18 $OID18 "STRING" "\"Clixon Version XXX.YYY year ZZZ\""
|
||||
validate_oid $NAME18 $NAME18 "STRING" "Clixon Version XXX.YYY year ZZZ"
|
||||
|
||||
new "Get next sw rev, $OID18"
|
||||
validate_oid $OID18 $OID19 "STRING" "\"1234-1234-ABCD-ABCD\""
|
||||
validate_oid $NAME18 $NAME19 "STRING" "1234-1234-ABCD-ABCD"
|
||||
|
||||
new "Get serial, $OID19"
|
||||
validate_oid $OID19 $OID19 "STRING" "\"1234-1234-ABCD-ABCD\""
|
||||
validate_oid $NAME19 $NAME19 "STRING" "1234-1234-ABCD-ABCD"
|
||||
|
||||
new "Get next serial, $OID19"
|
||||
validate_oid $OID19 $OID20 "STRING" "\"2345-2345-ABCD-ABCD\""
|
||||
validate_oid $NAME19 $NAME20 "STRING" "2345-2345-ABCD-ABCD"
|
||||
|
||||
new "Get serial, $OID20"
|
||||
validate_oid $OID20 $OID20 "STRING" "\"2345-2345-ABCD-ABCD\""
|
||||
validate_oid $NAME20 $NAME20 "STRING" "2345-2345-ABCD-ABCD"
|
||||
|
||||
new "Get next serial, $OID20"
|
||||
validate_oid $OID20 $OID21 "STRING" "\"Olof Hagsand Datakonsult AB\""
|
||||
validate_oid $NAME20 $NAME21 "STRING" "Olof Hagsand Datakonsult AB"
|
||||
|
||||
new "Get manufacturer, $OID21"
|
||||
validate_oid $OID21 $OID21 "STRING" "\"Olof Hagsand Datakonsult AB\""
|
||||
validate_oid $NAME21 $NAME21 "STRING" "Olof Hagsand Datakonsult AB"
|
||||
|
||||
new "Get next manufacturer, $OID21"
|
||||
validate_oid $OID21 $OID22 "STRING" "\"Olof Hagsand Datakonsult AB\""
|
||||
validate_oid $NAME21 $NAME22 "STRING" "Olof Hagsand Datakonsult AB"
|
||||
|
||||
new "Get manufacturer, $OID22"
|
||||
validate_oid $OID22 $OID22 "STRING" "\"Olof Hagsand Datakonsult AB\""
|
||||
validate_oid $NAME22 $NAME22 "STRING" "Olof Hagsand Datakonsult AB"
|
||||
|
||||
new "Get next manufacturer, $OID22"
|
||||
validate_oid $OID22 $OID23 "STRING" "\"Model AA.BB\""
|
||||
validate_oid $NAME22 $NAME23 "STRING" "Model AA.BB"
|
||||
|
||||
new "Get model, $OID23"
|
||||
validate_oid $OID23 $OID23 "STRING" "\"Model AA.BB\""
|
||||
validate_oid $NAME23 $NAME23 "STRING" "Model AA.BB"
|
||||
|
||||
new "Get next model, $OID23"
|
||||
validate_oid $OID23 $OID24 "STRING" "\"Model CC.DD\""
|
||||
validate_oid $NAME23 $NAME24 "STRING" "Model CC.DD"
|
||||
|
||||
new "Get model, $OID24"
|
||||
validate_oid $OID24 $OID24 "STRING" "\"Model CC.DD\""
|
||||
validate_oid $NAME24 $NAME24 "STRING" "Model CC.DD"
|
||||
|
||||
new "Get next model, $OID24"
|
||||
validate_oid $OID24 $OID25 "STRING" "\"Alias 123\""
|
||||
validate_oid $NAME24 $NAME25 "STRING" "Alias 123"
|
||||
|
||||
new "Get alias, $OID25"
|
||||
validate_oid $OID25 $OID25 "STRING" "\"Alias 123\""
|
||||
validate_oid $NAME25 $NAME25 "STRING" "Alias 123"
|
||||
|
||||
new "Get next alias, $OID25"
|
||||
validate_oid $OID25 $OID26 "STRING" "\"Alias 456\""
|
||||
validate_oid $NAME25 $NAME26 "STRING" "Alias 456"
|
||||
|
||||
new "Get alias, $OID26"
|
||||
validate_oid $OID26 $OID26 "STRING" "\"Alias 456\""
|
||||
validate_oid $NAME26 $NAME26 "STRING" "Alias 456"
|
||||
|
||||
new "Get next alias, $OID26"
|
||||
validate_oid $OID26 $OID27 "STRING" "\"Asset 123\""
|
||||
validate_oid $NAME26 $NAME27 "STRING" "Asset 123"
|
||||
|
||||
new "Get asset, $OID27"
|
||||
validate_oid $OID27 $OID27 "STRING" "\"Asset 123\""
|
||||
validate_oid $NAME27 $NAME27 "STRING" "Asset 123"
|
||||
|
||||
new "Get next asset, $OID27"
|
||||
validate_oid $OID27 $OID28 "STRING" "\"Asset 456\""
|
||||
validate_oid $NAME27 $NAME28 "STRING" "Asset 456"
|
||||
|
||||
new "Get asset, $OID28"
|
||||
validate_oid $OID28 $OID28 "STRING" "\"ASSET 456\""
|
||||
validate_oid $NAME28 $NAME28 "STRING" "ASSET 456"
|
||||
|
||||
new "Get next asset, $OID28"
|
||||
validate_oid $OID28 $OID29 "INTEGER" "1"
|
||||
validate_oid $NAME28 $NAME29 "INTEGER" "true(1)"
|
||||
|
||||
new "Get fru, $OID29"
|
||||
validate_oid $OID29 $OID29 "INTEGER" "1"
|
||||
validate_oid $NAME29 $NAME29 "INTEGER" "true(1)"
|
||||
|
||||
new "Get next fru, $OID29"
|
||||
validate_oid $OID29 $OID30 "INTEGER" "0"
|
||||
validate_oid $NAME29 $NAME30 "INTEGER" "0"
|
||||
|
||||
new "Get fru 2, $OID30"
|
||||
validate_oid $OID30 $OID30 "INTEGER" "0"
|
||||
validate_oid $NAME30 $NAME30 "INTEGER" "0"
|
||||
|
||||
new "Get next fru 2, $OID30"
|
||||
validate_oid $NAME30 $NAME31 "STRING" "12593-49-49,49:49:49.49"
|
||||
|
||||
new "Get mfg date, $OID31"
|
||||
validate_oid $NAME31 $NAME31 "STRING" "12593-49-49,49:49:49.49"
|
||||
|
||||
new "Get next mfg date, $OID31"
|
||||
validate_oid $NAME31 $NAME32 "STRING" "12850-50-50,50:50:50.50"
|
||||
|
||||
new "Get mfg date, $OID32"
|
||||
validate_oid $NAME32 $NAME32 "STRING" "12850-50-50,50:50:50.50"
|
||||
|
||||
new "Validate snmpwalk"
|
||||
expectpart "$($snmpwalk $ENTITY_OID)" 0 "SNMPv2-SMI::mib-2.47.1.1.1.1.1.1 = INTEGER: 1" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.1.2 = INTEGER: 2" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.2.1 = STRING: \"Entity 1\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.2.2 = STRING: \"Entity 2\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.3.1 = OID: IP-MIB::ip" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.3.2 = OID: IP-MIB::ip" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.4.1 = INTEGER: 9" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.4.2 = INTEGER: 4" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.5.1 = INTEGER: 6" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.5.2 = INTEGER: 6" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.6.1 = INTEGER: 123" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.6.2 = INTEGER: 999" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.7.1 = STRING: \"ABCD1234\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.7.2 = STRING: \"XXZZ11994\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.8.1 = STRING: \"REV 099\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.8.2 = STRING: \"REV 100\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.9.1 = STRING: \"REV 123\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.9.2 = STRING: \"REV 234\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.10.1 = STRING: \"Clixon Version XXX.YYY year ZZZ\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.10.2 = STRING: \"Clixon Version XXX.YYY year ZZZ\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.11.1 = STRING: \"1234-1234-ABCD-ABCD\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.11.2 = STRING: \"2345-2345-ABCD-ABCD\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.12.1 = STRING: \"Olof Hagsand Datakonsult AB\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.12.2 = STRING: \"Olof Hagsand Datakonsult AB\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.13.1 = STRING: \"Model AA.BB\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.13.2 = STRING: \"Model CC.DD\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.14.1 = STRING: \"Alias 123\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.14.2 = STRING: \"Alias 456\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.15.1 = STRING: \"Asset 123\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.15.2 = STRING: \"Asset 456\"" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.16.1 = INTEGER: 1" \
|
||||
"SNMPv2-SMI::mib-2.47.1.1.1.1.16.2 = INTEGER: 0" \
|
||||
|
||||
new "Cleaning up"
|
||||
# testexit
|
||||
|
||||
new "endtest"
|
||||
endtest
|
||||
286
test/test_snmp_get.sh
Executable file
286
test/test_snmp_get.sh
Executable file
|
|
@ -0,0 +1,286 @@
|
|||
#!/usr/bin/env bash
|
||||
# SNMP "smoketest" Basic snmpget test for a scalar
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
# Re-use main example backend state callbacks
|
||||
APPNAME=example
|
||||
|
||||
if [ ${ENABLE_NETSNMP} != "yes" ]; then
|
||||
echo "Skipping test, Net-SNMP support not enabled."
|
||||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
fi
|
||||
|
||||
cfg=$dir/conf_startup.xml
|
||||
fyang=$dir/clixon-example.yang
|
||||
fstate=$dir/state.xml
|
||||
|
||||
# AgentX unix socket
|
||||
SOCK=/var/run/snmp.sock
|
||||
|
||||
# Relies on example_backend.so for $fstate file handling
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${YANG_STANDARD_DIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${MIB_GENERATED_YANG_DIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_BACKEND_PIDFILE>/var/tmp/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
|
||||
<CLICON_SNMP_MIB>CLIXON-TYPES-MIB</CLICON_SNMP_MIB>
|
||||
<CLICON_VALIDATE_STATE_XML>true</CLICON_VALIDATE_STATE_XML>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
cat <<EOF > $fyang
|
||||
module clixon-example{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:clixon";
|
||||
prefix ex;
|
||||
import CLIXON-TYPES-MIB {
|
||||
prefix "clixon-types";
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# This is state data written to file that backend reads from (on request)
|
||||
# integer and string have values, sleeper does not and uses default (=1)
|
||||
|
||||
cat <<EOF > $fstate
|
||||
<CLIXON-TYPES-MIB xmlns="urn:ietf:params:xml:ns:yang:smiv2:CLIXON-TYPES-MIB">
|
||||
<clixonExampleScalars>
|
||||
<clixonExampleInteger>0x7fffffff</clixonExampleInteger>
|
||||
<clixonExampleSleeper>-1</clixonExampleSleeper>
|
||||
<clixonExampleString>This is not default</clixonExampleString>
|
||||
<ifTableLastChange>12345</ifTableLastChange>
|
||||
<ifType>modem</ifType>
|
||||
<ifSpeed>123123123</ifSpeed>
|
||||
<ifAdminStatus>testing</ifAdminStatus>
|
||||
<ifInOctets>123456</ifInOctets>
|
||||
<ifHCInOctets>4294967296</ifHCInOctets>
|
||||
<ifPromiscuousMode>true</ifPromiscuousMode>
|
||||
<ifCounterDiscontinuityTime>1234567890</ifCounterDiscontinuityTime>
|
||||
<ifStackStatus>active</ifStackStatus>
|
||||
</clixonExampleScalars>
|
||||
<clixonIETFWGTable>
|
||||
<clixonIETFWGEntry>
|
||||
<nsIETFWGName>42</nsIETFWGName>
|
||||
<nsIETFWGChair1>Name1</nsIETFWGChair1>
|
||||
<nsIETFWGChair2>Name2</nsIETFWGChair2>
|
||||
</clixonIETFWGEntry>
|
||||
</clixonIETFWGTable>
|
||||
<clixonHostsTable>
|
||||
<clixonHostsEntry>
|
||||
<clixonHostName>test</clixonHostName>
|
||||
<clixonHostAddressType>ipv4</clixonHostAddressType>
|
||||
<clixonHostAddress>10.20.30.40</clixonHostAddress>
|
||||
<clixonHostStorage>permanent</clixonHostStorage>
|
||||
<clixonHostRowStatus>active</clixonHostRowStatus>
|
||||
</clixonHostsEntry>
|
||||
</clixonHostsTable>
|
||||
<clixonInetTable>
|
||||
<clixonInetEntry>
|
||||
<clixonAddress>1.2.3.4</clixonAddress>
|
||||
<clixonString>foo</clixonString>
|
||||
</clixonInetEntry>
|
||||
<clixonInetEntry>
|
||||
<clixonAddress>2.2.2.2</clixonAddress>
|
||||
<clixonString>bar</clixonString>
|
||||
</clixonInetEntry>
|
||||
</clixonInetTable>
|
||||
</CLIXON-TYPES-MIB>
|
||||
EOF
|
||||
|
||||
function testinit(){
|
||||
new "test params: -f $cfg -- -sS $fstate"
|
||||
if [ $BE -ne 0 ]; then
|
||||
# Kill old backend and start a new one
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err "Failed to start backend"
|
||||
fi
|
||||
|
||||
sudo pkill -f clixon_backend
|
||||
|
||||
new "Starting backend"
|
||||
start_backend -s init -f $cfg -- -sS $fstate
|
||||
fi
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
if [ $SN -ne 0 ]; then
|
||||
# Kill old clixon_snmp, if any
|
||||
new "Terminating any old clixon_snmp processes"
|
||||
sudo killall -q clixon_snmp
|
||||
|
||||
new "Starting clixon_snmp"
|
||||
start_snmp $cfg &
|
||||
fi
|
||||
|
||||
new "wait snmp"
|
||||
wait_snmp
|
||||
}
|
||||
|
||||
function testexit(){
|
||||
stop_snmp
|
||||
}
|
||||
|
||||
new "SNMP tests"
|
||||
testinit
|
||||
|
||||
MIB=".1.3.6.1.4.1.8072.200"
|
||||
OID1="${MIB}.1.1" # netSnmpExampleInteger
|
||||
OID2="${MIB}.1.2" # netSnmpExampleSleeper
|
||||
OID3="${MIB}.1.3" # netSnmpExampleString
|
||||
OID4="${MIB}.1.4" # ifTableLastChange 12345678
|
||||
OID5="${MIB}.1.5" # ifType modem(48)
|
||||
OID6="${MIB}.1.6" # ifSpeed 123123123
|
||||
OID7="${MIB}.1.7" # ifAdminStatus testing(3)
|
||||
OID8="${MIB}.1.8" # ifInOctets 123456
|
||||
OID9="${MIB}.1.9" # ifHCInOctets 4294967296
|
||||
OID10="${MIB}.1.10" # ifPromiscuousMode true(1)
|
||||
OID11="${MIB}.1.11" # ifCounterDiscontinuityTime 1234567890 TimeStamp
|
||||
OID12="${MIB}.1.12" # ifStackStatus active(1)
|
||||
OID13="${MIB}.2.1" # netSnmpIETFWGTable
|
||||
OID14="${MIB}.2.1.1" # netSnmpIETFWGEntry
|
||||
OID15="${MIB}.2.1.1.1.42" # nsIETFWGName
|
||||
OID16="${MIB}.2.1.1.2.42" # nsIETFWGChair1
|
||||
OID17="${MIB}.2.1.1.3.42" # nsIETFWGChair2
|
||||
OID18="${MIB}.2.2" # netSnmpHostsTable
|
||||
OID19="${MIB}.2.2.1.1.4.116.101.115.116" # netSnmpHostName
|
||||
OID20="${MIB}.2.2.1.2.4.116.101.115.116" # netSnmpHostAddressType
|
||||
OID21="${MIB}.2.2.1.3" # netSnmpHostAddress
|
||||
OID22="${MIB}.2.2.1.4" # netSnmpHostStorage
|
||||
OID23="${MIB}.2.2.1.5" # netSnmpHostRowStatus
|
||||
|
||||
NAME1="CLIXON-TYPES-MIB::clixonExampleInteger"
|
||||
NAME2="CLIXON-TYPES-MIB::clixonExampleSleeper"
|
||||
NAME3="CLIXON-TYPES-MIB::clixonExampleString"
|
||||
NAME4="CLIXON-TYPES-MIB::ifTableLastChange"
|
||||
NAME5="CLIXON-TYPES-MIB::ifType"
|
||||
NAME6="CLIXON-TYPES-MIB::ifSpeed"
|
||||
NAME7="CLIXON-TYPES-MIB::ifAdminStatus"
|
||||
NAME8="CLIXON-TYPES-MIB::ifInOctets"
|
||||
NAME9="CLIXON-TYPES-MIB::ifHCInOctets"
|
||||
NAME10="CLIXON-TYPES-MIB::ifPromiscuousMode"
|
||||
NAME11="CLIXON-TYPES-MIB::ifCounterDiscontinuityTime"
|
||||
NAME12="CLIXON-TYPES-MIB::ifStackStatus"
|
||||
NAME13="CLIXON-TYPES-MIB::netSnmpIETFWGTable"
|
||||
NAME14="CLIXON-TYPES-MIB::netSnmpIETFWGEntry"
|
||||
NAME15="CLIXON-TYPES-MIB::nsIETFWGName"
|
||||
NAME16="CLIXON-TYPES-MIB::nsIETFWGChair1"
|
||||
NAME17="CLIXON-TYPES-MIB::nsIETFWGChair2"
|
||||
NAME18="CLIXON-TYPES-MIB::netSnmpHostsTable"
|
||||
NAME19="CLIXON-TYPES-MIB::netSnmpHostName"
|
||||
NAME20="CLIXON-TYPES-MIB::netSnmpHostAddressType"
|
||||
NAME21="CLIXON-TYPES-MIB::netSnmpHostAddress"
|
||||
NAME22="CLIXON-TYPES-MIB::netSnmpHostStorage"
|
||||
NAME23="CLIXON-TYPES-MIB::netSnmpHostRowStatus"
|
||||
|
||||
new "$snmpget"
|
||||
|
||||
new "Get netSnmpExampleInteger"
|
||||
validate_oid $OID1 $OID1 "INTEGER" 2147483647
|
||||
validate_oid $OID1 $OID2 "INTEGER" -1
|
||||
validate_oid $NAME1 $NAME1 "INTEGER" 2147483647
|
||||
validate_oid $NAME1 $NAME2 "INTEGER" -1
|
||||
|
||||
new "Get netSnmpExampleSleeper"
|
||||
validate_oid $OID2 $OID2 "INTEGER" -1
|
||||
validate_oid $OID2 $OID3 "STRING" "\"This is not default\""
|
||||
validate_oid $NAME2 $NAME2 "INTEGER" -1
|
||||
validate_oid $NAME2 $NAME3 "STRING" "This is not default"
|
||||
|
||||
new "Get netSnmpExampleString"
|
||||
validate_oid $OID3 $OID3 "STRING" "\"This is not default\""
|
||||
validate_oid $OID3 $OID4 "Timeticks" "(12345) 0:02:03.45"
|
||||
validate_oid $NAME3 $NAME3 "STRING" "This is not default"
|
||||
validate_oid $NAME3 $NAME4 "Timeticks" "(12345) 0:02:03.45"
|
||||
|
||||
new "Get ifTableLastChange"
|
||||
validate_oid $OID4 $OID4 "Timeticks" "(12345) 0:02:03.45"
|
||||
validate_oid $OID4 $OID5 "INTEGER" 48
|
||||
validate_oid $NAME4 $NAME4 "Timeticks" "(12345) 0:02:03.45"
|
||||
validate_oid $NAME4 $NAME5 "INTEGER" "modem(48)"
|
||||
|
||||
new "Get ifType"
|
||||
validate_oid $OID5 $OID5 "INTEGER" 48
|
||||
validate_oid $OID5 $OID6 "Gauge32" 123123123
|
||||
validate_oid $NAME5 $NAME5 "INTEGER" "modem(48)"
|
||||
validate_oid $NAME5 $NAME6 "Gauge32" 123123123
|
||||
|
||||
new "Get ifSpeed"
|
||||
validate_oid $OID6 $OID6 "Gauge32" 123123123
|
||||
validate_oid $OID6 $OID7 "INTEGER" 3
|
||||
validate_oid $NAME6 $NAME6 "Gauge32" 123123123
|
||||
validate_oid $NAME6 $NAME7 "INTEGER" "testing(3)"
|
||||
|
||||
new "Get ifAdminStatus"
|
||||
validate_oid $OID7 $OID7 "INTEGER" 3
|
||||
validate_oid $OID7 $OID8 "Counter32" 123456
|
||||
validate_oid $NAME7 $NAME7 "INTEGER" "testing(3)"
|
||||
validate_oid $NAME7 $NAME8 "Counter32" 123456
|
||||
|
||||
new "Get ifInOctets"
|
||||
validate_oid $OID8 $OID8 "Counter32" 123456
|
||||
validate_oid $OID8 $OID9 "Counter64" 4294967296
|
||||
validate_oid $NAME8 $NAME8 "Counter32" 123456
|
||||
validate_oid $NAME8 $NAME9 "Counter64" 4294967296
|
||||
|
||||
new "Get ifInHCOctets"
|
||||
validate_oid $OID9 $OID9 "Counter64" 4294967296
|
||||
validate_oid $OID9 $OID10 "INTEGER" 1
|
||||
|
||||
validate_oid $NAME9 $NAME9 "Counter64" 4294967296
|
||||
validate_oid $NAME9 $NAME10 "INTEGER" "true(1)"
|
||||
|
||||
new "Get ifPromiscuousMode"
|
||||
validate_oid $OID10 $OID10 "INTEGER" 1
|
||||
validate_oid $OID10 $OID11 "Timeticks" "(1234567890) 142 days, 21:21:18.90"
|
||||
validate_oid $NAME10 $NAME10 "INTEGER" "true(1)"
|
||||
validate_oid $NAME10 $NAME11 "Timeticks" "(1234567890) 142 days, 21:21:18.90"
|
||||
|
||||
new "Get ifCounterDiscontinuityTime"
|
||||
validate_oid $OID11 $OID11 "Timeticks" "(1234567890) 142 days, 21:21:18.90"
|
||||
validate_oid $OID11 $OID12 "INTEGER" 1
|
||||
validate_oid $NAME11 $NAME11 "Timeticks" "(1234567890) 142 days, 21:21:18.90"
|
||||
validate_oid $NAME11 $NAME12 "INTEGER" "active(1)"
|
||||
|
||||
new "Get ifStackStatus"
|
||||
validate_oid $OID12 $OID12 "INTEGER" 1
|
||||
validate_oid $NAME12 $NAME12 "INTEGER" "active(1)"
|
||||
|
||||
new "Get bulk OIDs"
|
||||
expectpart "$($snmpbulkget $OID1)" 0 "$OID2 = INTEGER: -1" "$OID3 = STRING: \"This is not default\"" "$OID4 = Timeticks: (12345) 0:02:03.45" "$OID5 = INTEGER: 48" "$OID6 = Gauge32: 123123123" "$OID7 = INTEGER: 3" "$OID8 = Counter32: 123456" "$OID9 = Counter64: 4294967296" "$OID10 = INTEGER: 1" "$OID11 = Timeticks: (1234567890) 142 days, 21:21:18.90"
|
||||
|
||||
new "Test SNMP getnext netSnmpIETFWGTable"
|
||||
validate_oid $OID15 $OID15 "INTEGER" 42
|
||||
|
||||
new "Test SNMP get nsIETFWGName"
|
||||
validate_oid $OID15 $OID15 "INTEGER" 42
|
||||
|
||||
new "Test SNMP getnext nsIETFWGName"
|
||||
expectpart "$($snmpgetnext $OID15)" 0 "Hex-STRING: 4E 61 6D 65 31 00"
|
||||
|
||||
new "Test SNMP getnext netSnmpHostsTable"
|
||||
expectpart "$($snmpgetnext $OID18)" 0 "$OID19 = Hex-STRING: 74 65 73 74 00"
|
||||
|
||||
new "Test SNMP get netSnmpHostName"
|
||||
expectpart "$($snmpget $OID19)" 0 "$OID19 = Hex-STRING: 74 65 73 74 00"
|
||||
|
||||
new "Test SNMP getnext netSnmpHostName"
|
||||
expectpart "$($snmpgetnext $OID19)" 0 "$OID20 = INTEGER: 1"
|
||||
|
||||
new "Cleaning up"
|
||||
testexit
|
||||
|
||||
new "endtest"
|
||||
endtest
|
||||
469
test/test_snmp_ifmib.sh
Executable file
469
test/test_snmp_ifmib.sh
Executable file
|
|
@ -0,0 +1,469 @@
|
|||
#!/usr/bin/env bash
|
||||
# SNMP "smoketest" Basic snmpget test for a scalar
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
# Re-use main example backend state callbacks
|
||||
APPNAME=example
|
||||
|
||||
if [ ${ENABLE_NETSNMP} != "yes" ]; then
|
||||
echo "Skipping test, Net-SNMP support not enabled."
|
||||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
fi
|
||||
|
||||
snmpd=$(type -p snmpd)
|
||||
snmpget="$(type -p snmpget) -On -c public -v2c localhost "
|
||||
snmpgetnext="$(type -p snmpgetnext) -On -c public -v2c localhost "
|
||||
snmptable="$(type -p snmptable) -c public -v2c localhost "
|
||||
snmpwalk="$(type -p snmpwalk) -c public -v2c localhost "
|
||||
|
||||
cfg=$dir/conf_startup.xml
|
||||
fyang=$dir/clixon-example.yang
|
||||
fstate=$dir/state.xml
|
||||
|
||||
# AgentX unix socket
|
||||
SOCK=/var/run/snmp.sock
|
||||
|
||||
# Relies on example_backend.so for $fstate file handling
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${YANG_STANDARD_DIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${MIB_GENERATED_YANG_DIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_BACKEND_PIDFILE>/var/tmp/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
|
||||
<CLICON_SNMP_MIB>IF-MIB</CLICON_SNMP_MIB>
|
||||
<CLICON_VALIDATE_STATE_XML>false</CLICON_VALIDATE_STATE_XML>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
cat <<EOF > $fyang
|
||||
module clixon-example{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:clixon";
|
||||
prefix ex;
|
||||
import IF-MIB {
|
||||
prefix "if-mib";
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# This is state data written to file that backend reads from (on request)
|
||||
# integer and string have values, sleeper does not and uses default (=1)
|
||||
|
||||
cat <<EOF > $fstate
|
||||
<IF-MIB xmlns="urn:ietf:params:xml:ns:yang:smiv2:IF-MIB">
|
||||
<interfaces>
|
||||
<ifNumber>1</ifNumber>
|
||||
</interfaces>
|
||||
<ifMIBObjects>
|
||||
<ifTableLastChange>0</ifTableLastChange>
|
||||
<ifStackLastChange>0</ifStackLastChange>
|
||||
</ifMIBObjects>
|
||||
<ifTable>
|
||||
<ifEntry>
|
||||
<ifIndex>1</ifIndex>
|
||||
<ifDescr>Test</ifDescr>
|
||||
<ifType>ethernetCsmacd</ifType>
|
||||
<ifMtu>1500</ifMtu>
|
||||
<ifSpeed>10000000</ifSpeed>
|
||||
<ifPhysAddress>aa:bb:cc:dd:ee:ff</ifPhysAddress>
|
||||
<ifAdminStatus>testing</ifAdminStatus>
|
||||
<ifOperStatus>up</ifOperStatus>
|
||||
<ifLastChange>0</ifLastChange>
|
||||
<ifInOctets>123</ifInOctets>
|
||||
<ifInUcastPkts>124</ifInUcastPkts>
|
||||
<ifInNUcastPkts>124</ifInNUcastPkts>
|
||||
<ifInDiscards>125</ifInDiscards>
|
||||
<ifInErrors>126</ifInErrors>
|
||||
<ifInUnknownProtos>127</ifInUnknownProtos>
|
||||
<ifOutOctets>128</ifOutOctets>
|
||||
<ifOutUcastPkts>129</ifOutUcastPkts>
|
||||
<ifOutNUcastPkts>129</ifOutNUcastPkts>
|
||||
<ifOutDiscards>130</ifOutDiscards>
|
||||
<ifOutErrors>131</ifOutErrors>
|
||||
<ifOutQLen>132</ifOutQLen>
|
||||
<ifSpecific>0.0</ifSpecific>
|
||||
</ifEntry>
|
||||
<ifEntry>
|
||||
<ifIndex>2</ifIndex>
|
||||
<ifDescr>Test 2</ifDescr>
|
||||
<ifType>ethernetCsmacd</ifType>
|
||||
<ifMtu>1400</ifMtu>
|
||||
<ifSpeed>1000</ifSpeed>
|
||||
<ifPhysAddress>11:22:33:44:55:66</ifPhysAddress>
|
||||
<ifAdminStatus>down</ifAdminStatus>
|
||||
<ifOperStatus>down</ifOperStatus>
|
||||
<ifLastChange>0</ifLastChange>
|
||||
<ifInOctets>111</ifInOctets>
|
||||
<ifInUcastPkts>222</ifInUcastPkts>
|
||||
<ifInNUcastPkts>333</ifInNUcastPkts>
|
||||
<ifInDiscards>444</ifInDiscards>
|
||||
<ifInErrors>555</ifInErrors>
|
||||
<ifInUnknownProtos>666</ifInUnknownProtos>
|
||||
<ifOutOctets>777</ifOutOctets>
|
||||
<ifOutUcastPkts>888</ifOutUcastPkts>
|
||||
<ifOutNUcastPkts>999</ifOutNUcastPkts>
|
||||
<ifOutDiscards>101010</ifOutDiscards>
|
||||
<ifOutErrors>111111</ifOutErrors>
|
||||
<ifOutQLen>111</ifOutQLen>
|
||||
<ifSpecific>1.2.3</ifSpecific>
|
||||
</ifEntry>
|
||||
</ifTable>
|
||||
<ifRcvAddressTable>
|
||||
<ifRcvAddressEntry>
|
||||
<ifIndex>1</ifIndex>
|
||||
<ifRcvAddressAddress>11:bb:cc:dd:ee:ff</ifRcvAddressAddress>
|
||||
<ifRcvAddressStatus>active</ifRcvAddressStatus>
|
||||
<ifRcvAddressType>other</ifRcvAddressType>
|
||||
</ifRcvAddressEntry>
|
||||
<ifRcvAddressEntry>
|
||||
<ifIndex>2</ifIndex>
|
||||
<ifRcvAddressAddress>aa:22:33:44:55:66</ifRcvAddressAddress>
|
||||
<ifRcvAddressStatus>createAndGo</ifRcvAddressStatus>
|
||||
<ifRcvAddressType>volatile</ifRcvAddressType>
|
||||
</ifRcvAddressEntry>
|
||||
</ifRcvAddressTable>
|
||||
</IF-MIB>
|
||||
EOF
|
||||
|
||||
# This is the expected result from snmpwalk:
|
||||
# $ snmpwalk -cpublic -v2c localhost IF-MIB::ifTable # .1.3.6.1.2.1.2.2
|
||||
# IF-MIB::ifIndex.1 = INTEGER: 1
|
||||
# IF-MIB::ifDescr.1 = STRING: Test
|
||||
# IF-MIB::ifType.1 = INTEGER: ethernetCsmacd(6)
|
||||
# IF-MIB::ifMtu.1 = INTEGER: 1500
|
||||
# IF-MIB::ifSpeed.1 = Gauge32: 10000000
|
||||
# IF-MIB::ifPhysAddress.1 = STRING: aa:bb:cc:dd:ee:ff
|
||||
# IF-MIB::ifAdminStatus.1 = INTEGER: up(1)
|
||||
# IF-MIB::ifOperStatus.1 = INTEGER: up(1)
|
||||
# IF-MIB::ifLastChange.1 = Timeticks: (0) 0:00:00.00
|
||||
# IF-MIB::ifInOctets.1 = Counter32: 123
|
||||
# IF-MIB::ifInUcastPkts.1 = Counter32: 123
|
||||
# IF-MIB::ifInNUcastPkts.1 = Counter32: 123
|
||||
# IF-MIB::ifInDiscards.1 = Counter32: 123
|
||||
# IF-MIB::ifInErrors.1 = Counter32: 123
|
||||
# IF-MIB::ifInUnknownProtos.1 = Counter32: 123
|
||||
# IF-MIB::ifOutOctets.1 = Counter32: 123
|
||||
# IF-MIB::ifOutUcastPkts.1 = Counter32: 123
|
||||
# IF-MIB::ifOutNUcastPkts.1 = Counter32: 123
|
||||
# IF-MIB::ifOutDiscards.1 = Counter32: 123
|
||||
# IF-MIB::ifOutErrors.1 = Counter32: 123
|
||||
# IF-MIB::ifOutQLen.1 = Gauge32: 123
|
||||
# IF-MIB::ifSpecific.1 = OID: SNMPv2-SMI::zeroDotZero
|
||||
|
||||
function testinit(){
|
||||
new "test params: -f $cfg -- -sS $fstate"
|
||||
if [ $BE -ne 0 ]; then
|
||||
# Kill old backend and start a new one
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err "Failed to start backend"
|
||||
fi
|
||||
|
||||
sudo pkill -f clixon_backend
|
||||
|
||||
new "Starting backend"
|
||||
start_backend -s init -f $cfg -- -sS $fstate
|
||||
fi
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
if [ $SN -ne 0 ]; then
|
||||
# Kill old clixon_snmp, if any
|
||||
new "Terminating any old clixon_snmp processes"
|
||||
sudo killall -q clixon_snmp
|
||||
|
||||
new "Starting clixon_snmp"
|
||||
start_snmp $cfg &
|
||||
fi
|
||||
|
||||
new "wait snmp"
|
||||
wait_snmp
|
||||
}
|
||||
|
||||
function testexit(){
|
||||
stop_snmp
|
||||
}
|
||||
|
||||
new "SNMP tests"
|
||||
testinit
|
||||
|
||||
# IF-MIB::interfaces
|
||||
MIB=".1.3.6.1.2.1"
|
||||
for (( i=1; i<23; i++ )); do
|
||||
eval OID${i}="${MIB}.2.2.1.$i.1"
|
||||
done
|
||||
|
||||
OID24=".1.3.6.1.2.1.31.1.4.1.1.1.17.49.49.58.98.98.58.99.99.58.100.100.58.101.101.58.102.102"
|
||||
OID25=".1.3.6.1.2.1.31.1.4.1.1.2.17.97.97.58.50.50.58.51.51.58.52.52.58.53.53.58.54.54"
|
||||
OID26=".1.3.6.1.2.1.31.1.4.1.2.1.17.49.49.58.98.98.58.99.99.58.100.100.58.101.101.58.102.102"
|
||||
OID27=".1.3.6.1.2.1.31.1.4.1.2.2.17.97.97.58.50.50.58.51.51.58.52.52.58.53.53.58.54.54"
|
||||
OID28=".1.3.6.1.2.1.31.1.4.1.3.1.17.49.49.58.98.98.58.99.99.58.100.100.58.101.101.58.102.102"
|
||||
OID29=".1.3.6.1.2.1.31.1.4.1.3.2.17.97.97.58.50.50.58.51.51.58.52.52.58.53.53.58.54.54"
|
||||
|
||||
NAME1="IF-MIB::ifIndex"
|
||||
NAME2="IF-MIB::ifDescr"
|
||||
NAME3="IF-MIB::ifType"
|
||||
NAME4="IF-MIB::ifMtu"
|
||||
NAME5="IF-MIB::ifSpeed"
|
||||
NAME6="IF-MIB::ifPhysAddress"
|
||||
NAME7="IF-MIB::ifAdminStatus"
|
||||
NAME8="IF-MIB::ifOperStatus"
|
||||
NAME9="IF-MIB::ifLastChange"
|
||||
NAME10="IF-MIB::ifInOctets"
|
||||
NAME11="IF-MIB::ifInUcastPkts"
|
||||
NAME12="IF-MIB::ifInNUcastPkts"
|
||||
NAME13="IF-MIB::ifInDiscards"
|
||||
NAME14="IF-MIB::ifInErrors"
|
||||
NAME15="IF-MIB::ifInUnknownProtos"
|
||||
NAME16="IF-MIB::ifOutOctets"
|
||||
NAME17="IF-MIB::ifOutUcastPkts"
|
||||
NAME18="IF-MIB::ifOutNUcastPkts"
|
||||
NAME19="IF-MIB::ifOutDiscards"
|
||||
NAME20="IF-MIB::ifOutErrors"
|
||||
NAME21="IF-MIB::ifOutQLen"
|
||||
NAME22="IF-MIB::ifSpecific"
|
||||
|
||||
NAME24="IF-MIB::ifRcvAddressAddress.1.17.49.49.58.98.98.58.99.99.58.100.100.58.101.101.58.102.102"
|
||||
NAME25="IF-MIB::ifRcvAddressAddress.2.17.97.97.58.50.50.58.51.51.58.52.52.58.53.53.58.54.54"
|
||||
NAME26="IF-MIB::ifRcvAddressStatus.1.17.49.49.58.98.98.58.99.99.58.100.100.58.101.101.58.102.102"
|
||||
NAME27="IF-MIB::ifRcvAddressStatus.2.17.97.97.58.50.50.58.51.51.58.52.52.58.53.53.58.54.54"
|
||||
NAME28="IF-MIB::ifRcvAddressType.1.17.49.49.58.98.98.58.99.99.58.100.100.58.101.101.58.102.102"
|
||||
NAME29="IF-MIB::ifRcvAddressType.2.17.97.97.58.50.50.58.51.51.58.52.52.58.53.53.58.54.54"
|
||||
|
||||
new "$snmpget"
|
||||
|
||||
new "Test SNMP get all entries in ifTable"
|
||||
|
||||
new "Test $OID1 ifIndex"
|
||||
validate_oid $OID1 $OID1 "INTEGER" "1"
|
||||
validate_oid "$NAME1.1" "$NAME1.1" "INTEGER" 1
|
||||
validate_oid "$NAME1.1" "$NAME1.2" "INTEGER" 2
|
||||
|
||||
new "Test $OID2 ifDescr"
|
||||
validate_oid $OID2 $OID2 "STRING" "Test"
|
||||
validate_oid $NAME2.1 $NAME2.1 "STRING" "Test"
|
||||
validate_oid $NAME2.2 $NAME2.2 "STRING" "Test"
|
||||
|
||||
new "Test $OID3 ifType"
|
||||
validate_oid $OID3 $OID3 "INTEGER" "ethernetCsmacd(6)"
|
||||
validate_oid $NAME3.1 $NAME3.1 "INTEGER" "ethernetCsmacd(6)"
|
||||
validate_oid $NAME3.2 $NAME3.2 "INTEGER" "ethernetCsmacd(6)"
|
||||
|
||||
new "Test $OID4 ifMtu"
|
||||
validate_oid $OID4 $OID4 "INTEGER" "1500"
|
||||
validate_oid $NAME4.1 $NAME4.1 "INTEGER" 1500
|
||||
validate_oid $NAME4.2 $NAME4.2 "INTEGER" 1400
|
||||
|
||||
new "Test $OID5 ifSpeed"
|
||||
validate_oid $OID5 $OID5 "Gauge32" "10000000"
|
||||
validate_oid $NAME5.1 $NAME5.1 "Gauge32" 10000000
|
||||
validate_oid $NAME5.2 $NAME5.2 "Gauge32" 1000
|
||||
|
||||
new "Test $OID6 ifPhysAddress yang:phys-address"
|
||||
validate_oid $OID6 $OID6 "STRING" "aa.bb:cc:dd:ee:ff"
|
||||
validate_oid $NAME6.1 $NAME6.1 "STRING" "aa.bb:cc:dd:ee:ff"
|
||||
validate_oid $NAME6.2 $NAME6.2 "STRING" "11:22:33:44:55:66"
|
||||
|
||||
new "Test $OID7 ifAdminStatus"
|
||||
validate_oid $OID7 $OID7 "INTEGER" "testing(3)"
|
||||
validate_oid $NAME7.1 $NAME7.1 "INTEGER" "testing(3)"
|
||||
validate_oid $NAME7.2 $NAME7.2 "INTEGER" "down(2)"
|
||||
|
||||
new "Test $OID8 ifOperStatus"
|
||||
validate_oid $OID8 $OID8 "INTEGER" "up(1)"
|
||||
validate_oid $NAME8.1 $NAME8.1 "INTEGER" "up(1)"
|
||||
validate_oid $NAME8.2 $NAME8.2 "INTEGER" "down(2)"
|
||||
|
||||
new "Test $OID9 ifLastChange"
|
||||
validate_oid $OID9 $OID9 "Timeticks" "(0) 0:00:00.00"
|
||||
validate_oid $NAME9.1 $NAME9.1 "Timeticks" "(0) 0:00:00.00"
|
||||
validate_oid $NAME9.2 $NAME9.2 "Timeticks" "(0) 0:00:00.00"
|
||||
|
||||
new "Test $OID10 ifInOctets"
|
||||
validate_oid $OID10 $OID10 "Counter32" 123
|
||||
validate_oid $NAME10.1 $NAME10.1 "Counter32" 123
|
||||
validate_oid $NAME10.2 $NAME10.2 "Counter32" 111
|
||||
|
||||
new "Test $OID11 ifInUcastPkts"
|
||||
validate_oid $OID11 $OID11 "Counter32" 124
|
||||
validate_oid $NAME11.1 $NAME11.1 "Counter32" 124
|
||||
validate_oid $NAME11.2 $NAME11.2 "Counter32" 222
|
||||
|
||||
new "Test $OID12 ifInNUcastPkts"
|
||||
validate_oid $OID12 $OID12 "Counter32" 124
|
||||
validate_oid $NAME12.1 $NAME12.1 "Counter32" 124
|
||||
validate_oid $NAME12.2 $NAME12.2 "Counter32" 333
|
||||
|
||||
new "Test $OID13 ifInDiscards"
|
||||
validate_oid $OID13 $OID13 "Counter32" 125
|
||||
validate_oid $NAME13.1 $NAME13.1 "Counter32" 125
|
||||
validate_oid $NAME13.2 $NAME13.2 "Counter32" 444
|
||||
|
||||
new "Test $OID14 ifInErrors"
|
||||
validate_oid $OID14 $OID14 "Counter32" 126
|
||||
validate_oid $NAME14.1 $NAME14.1 "Counter32" 126
|
||||
validate_oid $NAME14.2 $NAME14.2 "Counter32" 555
|
||||
|
||||
new "Test $OID15 ifInUnknownProtos"
|
||||
validate_oid $OID15 $OID15 "Counter32" 127
|
||||
validate_oid $NAME15.1 $NAME15.1 "Counter32" 127
|
||||
validate_oid $NAME15.2 $NAME15.2 "Counter32" 666
|
||||
|
||||
new "Test $OID16 ifOutOctets"
|
||||
validate_oid $OID16 $OID16 "Counter32" 128
|
||||
validate_oid $NAME16.1 $NAME16.1 "Counter32" 128
|
||||
validate_oid $NAME16.2 $NAME16.2 "Counter32" 777
|
||||
|
||||
new "Test $OID17 ifOutUcastPkts"
|
||||
validate_oid $OID17 $OID17 "Counter32" 129
|
||||
validate_oid $NAME17.1 $NAME17.1 "Counter32" 129
|
||||
validate_oid $NAME17.2 $NAME17.2 "Counter32" 888
|
||||
|
||||
new "Test $OID18 ifOutNUcastPkts"
|
||||
validate_oid $OID18 $OID18 "Counter32" 129
|
||||
validate_oid $NAME18.1 $NAME18.1 "Counter32" 129
|
||||
validate_oid $NAME18.2 $NAME18.2 "Counter32" 999
|
||||
|
||||
new "Test $OID19 ifOutDiscards"
|
||||
validate_oid $OID19 $OID19 "Counter32" 130
|
||||
validate_oid $NAME19.1 $NAME19.1 "Counter32" 130
|
||||
validate_oid $NAME19.2 $NAME19.2 "Counter32" 101010
|
||||
|
||||
new "Test $OID20 ifOutErrors"
|
||||
validate_oid $OID20 $OID20 "Counter32" 131
|
||||
validate_oid $NAME20.1 $NAME20.1 "Counter32" 131
|
||||
validate_oid $NAME20.2 $NAME20.2 "Counter32" 111111
|
||||
|
||||
new "Test $OID21 ifOutQLen"
|
||||
validate_oid $OID21 $OID21 "Gauge32" 132
|
||||
validate_oid $NAME21.1 $NAME21.1 "Gauge32" 132
|
||||
validate_oid $NAME21.2 $NAME21.2 "Gauge32" 111
|
||||
|
||||
new "Test $OID22 ifSpecific"
|
||||
validate_oid $OID22 $OID22 "OID" ".0.0"
|
||||
validate_oid $NAME22.1 $NAME22.1 "OID" "SNMPv2-SMI::zeroDotZero"
|
||||
validate_oid $NAME22.2 $NAME22.2 "OID" "iso.2.3"
|
||||
|
||||
new "Test ifTable"
|
||||
expectpart "$($snmptable IF-MIB::ifTable)" 0 "Test 2" "1400" "1000" "11:22:33:44:55:66" "down" "111" "222" "333" "444" "555" "666" "777" "888" "999" "101010" "111111" "111"
|
||||
|
||||
new "Walk the walk..."
|
||||
expectpart "$($snmpwalk IF-MIB::ifTable)" 0 "IF-MIB::ifIndex.1 = INTEGER: 1" \
|
||||
"IF-MIB::ifIndex.2 = INTEGER: 2" \
|
||||
"IF-MIB::ifDescr.1 = STRING: Test." \
|
||||
"IF-MIB::ifDescr.2 = STRING: Test 2." \
|
||||
"IF-MIB::ifType.1 = INTEGER: ethernetCsmacd(6)" \
|
||||
"IF-MIB::ifType.2 = INTEGER: ethernetCsmacd(6)" \
|
||||
"IF-MIB::ifMtu.1 = INTEGER: 1500" \
|
||||
"IF-MIB::ifMtu.2 = INTEGER: 1400" \
|
||||
"IF-MIB::ifSpeed.1 = Gauge32: 10000000" \
|
||||
"IF-MIB::ifSpeed.2 = Gauge32: 1000" \
|
||||
"IF-MIB::ifPhysAddress.1 = STRING: aa:bb:cc:dd:ee:ff" \
|
||||
"IF-MIB::ifPhysAddress.2 = STRING: 11:22:33:44:55:66" \
|
||||
"IF-MIB::ifAdminStatus.1 = INTEGER: testing(3)" \
|
||||
"IF-MIB::ifAdminStatus.2 = INTEGER: down(2)" \
|
||||
"IF-MIB::ifOperStatus.1 = INTEGER: up(1)" \
|
||||
"IF-MIB::ifOperStatus.2 = INTEGER: down(2)" \
|
||||
"IF-MIB::ifLastChange.1 = Timeticks: (0) 0:00:00.00" \
|
||||
"IF-MIB::ifLastChange.2 = Timeticks: (0) 0:00:00.00" \
|
||||
"IF-MIB::ifInOctets.1 = Counter32: 123" \
|
||||
"IF-MIB::ifInOctets.2 = Counter32: 111" \
|
||||
"IF-MIB::ifInUcastPkts.1 = Counter32: 124" \
|
||||
"IF-MIB::ifInUcastPkts.2 = Counter32: 222" \
|
||||
"IF-MIB::ifInNUcastPkts.1 = Counter32: 124" \
|
||||
"IF-MIB::ifInNUcastPkts.2 = Counter32: 333" \
|
||||
"IF-MIB::ifInDiscards.1 = Counter32: 125" \
|
||||
"IF-MIB::ifInDiscards.2 = Counter32: 444" \
|
||||
"IF-MIB::ifInErrors.1 = Counter32: 126" \
|
||||
"IF-MIB::ifInErrors.2 = Counter32: 555" \
|
||||
"IF-MIB::ifInUnknownProtos.1 = Counter32: 127" \
|
||||
"IF-MIB::ifInUnknownProtos.2 = Counter32: 666" \
|
||||
"IF-MIB::ifOutOctets.1 = Counter32: 128" \
|
||||
"IF-MIB::ifOutOctets.2 = Counter32: 777" \
|
||||
"IF-MIB::ifOutUcastPkts.1 = Counter32: 129" \
|
||||
"IF-MIB::ifOutUcastPkts.2 = Counter32: 888" \
|
||||
"IF-MIB::ifOutNUcastPkts.1 = Counter32: 129" \
|
||||
"IF-MIB::ifOutNUcastPkts.2 = Counter32: 999" \
|
||||
"IF-MIB::ifOutDiscards.1 = Counter32: 130" \
|
||||
"IF-MIB::ifOutDiscards.2 = Counter32: 101010" \
|
||||
"IF-MIB::ifOutErrors.1 = Counter32: 131" \
|
||||
"IF-MIB::ifOutErrors.2 = Counter32: 111111" \
|
||||
"IF-MIB::ifOutQLen.1 = Gauge32: 132" \
|
||||
"IF-MIB::ifOutQLen.2 = Gauge32: 111" \
|
||||
"IF-MIB::ifSpecific.1 = OID: SNMPv2-SMI::zeroDotZero" \
|
||||
"IF-MIB::ifSpecific.2 = OID: iso.2.3"
|
||||
|
||||
new "Test $OID24"
|
||||
validate_oid $OID24 $OID24 "STRING" "11:bb:cc:dd:ee:ff"
|
||||
validate_oid $NAME24 $NAME24 "STRING" "11:bb:cc:dd:ee:ff" "IF-MIB::ifRcvAddressAddress.1.\"11:bb:cc:dd:ee:ff\" = STRING: 11:bb:cc:dd:ee:ff"
|
||||
|
||||
new "Get next $OID24"
|
||||
validate_oid $OID24 $OID25 "STRING" "aa:22:33:44:55:66"
|
||||
validate_oid $NAME24 $NAME25 "STRING" "aa:22:33:44:55:66" "IF-MIB::ifRcvAddressAddress.2.\"aa:22:33:44:55:66\" = STRING: aa:22:33:44:55:66"
|
||||
|
||||
new "Get $NAME25"
|
||||
|
||||
validate_oid $OID25 $OID25 "STRING" "aa:22:33:44:55:66"
|
||||
validate_oid $NAME25 $NAME25 "STRING" "aa:22:33:44:55:66" "IF-MIB::ifRcvAddressAddress.2.\"aa:22:33:44:55:66\" = STRING: aa:22:33:44:55:66"
|
||||
|
||||
new "Get next $OID25"
|
||||
|
||||
validate_oid $OID25 $OID26 "INTEGER" "active(1)"
|
||||
validate_oid $NAME25 $NAME26 "INTEGER" "active(1)" "IF-MIB::ifRcvAddressStatus.1.\"11:bb:cc:dd:ee:ff\" = INTEGER: active(1)"
|
||||
|
||||
new "Get $OID26"
|
||||
|
||||
validate_oid $OID26 $OID26 "INTEGER" "active(1)"
|
||||
validate_oid $NAME26 $NAME26 "INTEGER" "active(1)" "IF-MIB::ifRcvAddressStatus.1.\"11:bb:cc:dd:ee:ff\" = INTEGER: active(1)"
|
||||
|
||||
new "Get next $OID26"
|
||||
|
||||
validate_oid $OID26 $OID27 "INTEGER" "createAndGo(4)"
|
||||
validate_oid $NAME26 $NAME27 "INTEGER" "createAndGo(4)" "IF-MIB::ifRcvAddressStatus.2.\"aa:22:33:44:55:66\" = INTEGER: createAndGo(4)"
|
||||
|
||||
new "Get $OID27"
|
||||
|
||||
validate_oid $OID27 $OID27 "INTEGER" "createAndGo(4)"
|
||||
validate_oid $NAME27 $NAME27 "INTEGER" "createAndGo(4)" "IF-MIB::ifRcvAddressStatus.2.\"aa:22:33:44:55:66\" = INTEGER: createAndGo(4)"
|
||||
|
||||
new "Get next $OID27"
|
||||
|
||||
validate_oid $OID27 $OID28 "INTEGER" "other(1)"
|
||||
validate_oid $NAME27 $NAME28 "INTEGER" "other(1)" "IF-MIB::ifRcvAddressType.1.\"11:bb:cc:dd:ee:ff\" = INTEGER: other(1)"
|
||||
|
||||
new "Get $OID28"
|
||||
|
||||
validate_oid $OID28 $OID28 "INTEGER" "other(1)"
|
||||
validate_oid $NAME28 $NAME28 "INTEGER" "other(1)" "IF-MIB::ifRcvAddressType.1.\"11:bb:cc:dd:ee:ff\" = INTEGER: other(1)"
|
||||
|
||||
new "Get next $OID28"
|
||||
|
||||
validate_oid $OID28 $OID29 "INTEGER" "volatile(2)"
|
||||
validate_oid $NAME28 $NAME29 "INTEGER" "volatile(2)" "IF-MIB::ifRcvAddressType.2.\"aa:22:33:44:55:66\" = INTEGER: volatile(2)"
|
||||
|
||||
new "Test ifTable"
|
||||
expectpart "$($snmptable IF-MIB::ifRcvAddressTable)" 0 "SNMP table: IF-MIB::ifRcvAddressTable" "ifRcvAddressStatus" "ifRcvAddressType" "active" "other" "createAndGo" "volatile"
|
||||
|
||||
new "Walk ifRcvTable"
|
||||
expectpart "$($snmpwalk IF-MIB::ifRcvAddressTable)" 0 "IF-MIB::ifRcvAddressAddress.1.\"11:bb:cc:dd:ee:ff\" = STRING: 11:bb:cc:dd:ee:ff" \
|
||||
"IF-MIB::ifRcvAddressAddress.2.\"aa:22:33:44:55:66\" = STRING: aa:22:33:44:55:66" \
|
||||
"IF-MIB::ifRcvAddressStatus.1.\"11:bb:cc:dd:ee:ff\" = INTEGER: active(1)" \
|
||||
"IF-MIB::ifRcvAddressStatus.2.\"aa:22:33:44:55:66\" = INTEGER: createAndGo(4)" \
|
||||
"IF-MIB::ifRcvAddressType.1.\"11:bb:cc:dd:ee:ff\" = INTEGER: other(1)" \
|
||||
"IF-MIB::ifRcvAddressType.2.\"aa:22:33:44:55:66\" = INTEGER: volatile(2)"
|
||||
|
||||
testexit
|
||||
|
||||
new "endtest"
|
||||
endtest
|
||||
226
test/test_snmp_rowstatus.sh
Executable file
226
test/test_snmp_rowstatus.sh
Executable file
|
|
@ -0,0 +1,226 @@
|
|||
#!/usr/bin/env bash
|
||||
# SNMP table rowstatus tests
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
APPNAME=example
|
||||
|
||||
# XXX skip for now
|
||||
if [ ${ENABLE_NETSNMP} != "yes" ]; then
|
||||
echo "Skipping test, Net-SNMP support not enabled."
|
||||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
fi
|
||||
|
||||
snmpd=$(type -p snmpd)
|
||||
snmpget="$(type -p snmpget) -c public -v2c localhost "
|
||||
snmpset="$(type -p snmpset) -c public -v2c localhost "
|
||||
|
||||
cfg=$dir/conf.xml
|
||||
fyang=$dir/clixon-example.yang
|
||||
|
||||
# AgentX unix socket
|
||||
SOCK=/var/run/snmp.sock
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${YANG_STANDARD_DIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${MIB_GENERATED_YANG_DIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_PIDFILE>/var/tmp/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
|
||||
<CLICON_SNMP_MIB>SNMP-NOTIFICATION-MIB</CLICON_SNMP_MIB>
|
||||
<CLICON_VALIDATE_STATE_XML>true</CLICON_VALIDATE_STATE_XML>
|
||||
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
cat <<EOF > $fyang
|
||||
module clixon-example{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:clixon";
|
||||
prefix ex;
|
||||
import SNMP-NOTIFICATION-MIB {
|
||||
prefix "snmp-notification";
|
||||
}
|
||||
deviation "/snmp-notification:SNMP-NOTIFICATION-MIB" {
|
||||
deviate replace {
|
||||
config true;
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF > $dir/startup_db
|
||||
<${DATASTORE_TOP}>
|
||||
</${DATASTORE_TOP}>
|
||||
EOF
|
||||
|
||||
function testinit(){
|
||||
new "test params: -f $cfg"
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
# Kill old backend and start a new one
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err "Failed to start backend"
|
||||
fi
|
||||
|
||||
sudo pkill -f clixon_backend
|
||||
|
||||
new "Starting backend"
|
||||
start_backend -s startup -f $cfg
|
||||
fi
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
if [ $SN -ne 0 ]; then
|
||||
# Kill old clixon_snmp, if any
|
||||
new "Terminating any old clixon_snmp processes"
|
||||
sudo killall -q clixon_snmp
|
||||
|
||||
new "Starting clixon_snmp"
|
||||
start_snmp $cfg &
|
||||
fi
|
||||
|
||||
new "wait snmp"
|
||||
wait_snmp
|
||||
}
|
||||
|
||||
function testrun_createAndGo()
|
||||
{
|
||||
index=go
|
||||
|
||||
new "Configuring a value without a row is a failure"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2 2>&1)" 2 "Reason: inconsistentValue"
|
||||
|
||||
new "Set RowStatus to CreateAndGo and set tag"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndGo SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: createAndGo(4)"
|
||||
|
||||
new "Check rowstatus is active"
|
||||
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: active(1)"
|
||||
|
||||
new "Get tag"
|
||||
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: 2"
|
||||
|
||||
new "Get tag via netconf: candidate"
|
||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/sn:SNMP-NOTIFICATION-MIB/sn:snmpNotifyTable/sn:snmpNotifyEntry[sn:snmpNotifyName='$index']/sn:snmpNotifyTag\" xmlns:sn=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"/></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data><SNMP-NOTIFICATION-MIB xmlns=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"><snmpNotifyTable><snmpNotifyEntry><snmpNotifyName>$index</snmpNotifyName><snmpNotifyTag>2</snmpNotifyTag></snmpNotifyEntry></snmpNotifyTable></SNMP-NOTIFICATION-MIB></data></rpc-reply>"
|
||||
|
||||
new "Get tag via netconf: running"
|
||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><running/></source><filter type=\"xpath\" select=\"/sn:SNMP-NOTIFICATION-MIB/sn:snmpNotifyTable/sn:snmpNotifyEntry[sn:snmpNotifyName='$index']/sn:snmpNotifyTag\" xmlns:sn=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"/></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data><SNMP-NOTIFICATION-MIB xmlns=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"><snmpNotifyTable><snmpNotifyEntry><snmpNotifyName>$index</snmpNotifyName><snmpNotifyTag>2</snmpNotifyTag></snmpNotifyEntry></snmpNotifyTable></SNMP-NOTIFICATION-MIB></data></rpc-reply>"
|
||||
|
||||
new "set storage type"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.\'$index\' = 1)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.'$index' = INTEGER: other(1)"
|
||||
}
|
||||
|
||||
function testrun_createAndWait()
|
||||
{
|
||||
index=wait
|
||||
|
||||
new "Configuring a value without a row is a failure"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2 2>&1)" 2 "Reason: inconsistentValue"
|
||||
|
||||
new "Set RowStatus to CreateAndWait and set tag"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndWait SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: createAndWait(5)"
|
||||
|
||||
new "Get tag"
|
||||
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: 2"
|
||||
|
||||
new "Get tag via netconf: candidate expect fail"
|
||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/sn:SNMP-NOTIFICATION-MIB/sn:snmpNotifyTable/sn:snmpNotifyEntry[sn:snmpNotifyName='$index']/sn:snmpNotifyTag\" xmlns:sn=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"/></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data/></rpc-reply>"
|
||||
|
||||
new "Get rowstatus"
|
||||
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: notInService(2)"
|
||||
|
||||
new "Set storagetype"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.\'$index\' = 1)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.'$index' = INTEGER: other(1)"
|
||||
|
||||
new "Set rowstatus to active/ commit"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = active)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: active(1)"
|
||||
|
||||
new "Set storagetype again"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.\'$index\' = 5)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.'$index' = INTEGER: readOnly(5)"
|
||||
|
||||
new "Set rowstatus to createAndWait"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndWait)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: createAndWait(5)"
|
||||
|
||||
new "Set second rowstatus to createAndGo"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'${index}2\' = createAndGo)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'${index}2' = INTEGER: createAndGo(4)"
|
||||
|
||||
new "Set third rowstatus to createAndWait"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'${index}3\' = createAndWait)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'${index}3' = INTEGER: createAndWait(5)"
|
||||
|
||||
new "Set third rowstatus to active"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'${index}3\' = active)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'${index}3' = INTEGER: active(1)"
|
||||
|
||||
new "Get rowstatus"
|
||||
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: notInService(2)"
|
||||
}
|
||||
|
||||
function testrun_removeRows()
|
||||
{
|
||||
index=remove
|
||||
|
||||
new "Set RowStatus to CreateAndGo and set tag"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndGo SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: createAndGo(4)"
|
||||
|
||||
new "Get tag"
|
||||
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: 2"
|
||||
|
||||
new "Get tag via netconf"
|
||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/sn:SNMP-NOTIFICATION-MIB/sn:snmpNotifyTable/sn:snmpNotifyEntry[sn:snmpNotifyName='$index']/sn:snmpNotifyTag\" xmlns:sn=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"/></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data><SNMP-NOTIFICATION-MIB xmlns=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"><snmpNotifyTable><snmpNotifyEntry><snmpNotifyName>$index</snmpNotifyName><snmpNotifyTag>2</snmpNotifyTag></snmpNotifyEntry></snmpNotifyTable></SNMP-NOTIFICATION-MIB></data></rpc-reply>"
|
||||
|
||||
new "Set rowstatus to destroy"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = destroy)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: destroy(6)"
|
||||
|
||||
new "Get rowstatus"
|
||||
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = No Such Instance currently exists at this OID"
|
||||
|
||||
# Default value is ""
|
||||
new "Get tag"
|
||||
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: " --not-- "= STRING: 2"
|
||||
|
||||
new "Get tag via netconf: candidate expect fail"
|
||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/sn:SNMP-NOTIFICATION-MIB/sn:snmpNotifyTable/sn:snmpNotifyEntry[sn:snmpNotifyName='$index']/sn:snmpNotifyTag\" xmlns:sn=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"/></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data/></rpc-reply>"
|
||||
|
||||
new "Set rowstatus to createandwait"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndWait)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index'"
|
||||
|
||||
new "Set rowstatus to destroy"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = destroy)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: destroy(6)"
|
||||
|
||||
new "Get rowstatus"
|
||||
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = No Such Instance currently exists at this OID"
|
||||
}
|
||||
|
||||
function testexit()
|
||||
{
|
||||
stop_snmp
|
||||
}
|
||||
|
||||
new "SNMP tests"
|
||||
testinit
|
||||
|
||||
new "createAndGo"
|
||||
testrun_createAndGo
|
||||
|
||||
new "createAndWait"
|
||||
testrun_createAndWait
|
||||
|
||||
new "removeRows"
|
||||
testrun_removeRows
|
||||
|
||||
new "Cleaning up"
|
||||
testexit
|
||||
|
||||
new "endtest"
|
||||
endtest
|
||||
248
test/test_snmp_set.sh
Executable file
248
test/test_snmp_set.sh
Executable file
|
|
@ -0,0 +1,248 @@
|
|||
#!/usr/bin/env bash
|
||||
# snmpset. This requires deviation of MIB-YANG to make write operations
|
||||
# Get default value, set new value via SNMP and check it, set new value via NETCONF and check
|
||||
# Selected types from CLIXON/IF-MIB/ENTITY mib
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
APPNAME=example
|
||||
|
||||
# XXX skip for now
|
||||
if [ ${ENABLE_NETSNMP} != "yes" ]; then
|
||||
echo "Skipping test, Net-SNMP support not enabled."
|
||||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
fi
|
||||
|
||||
snmpd=$(type -p snmpd)
|
||||
snmpget="$(type -p snmpget) -On -c public -v2c localhost "
|
||||
snmpset="$(type -p snmpset) -On -c public -v2c localhost "
|
||||
|
||||
cfg=$dir/conf.xml
|
||||
fyang=$dir/clixon-example.yang
|
||||
|
||||
# AgentX unix socket
|
||||
SOCK=/var/run/snmp.sock
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${YANG_STANDARD_DIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${MIB_GENERATED_YANG_DIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_PIDFILE>/var/tmp/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
|
||||
<CLICON_SNMP_MIB>CLIXON-TYPES-MIB</CLICON_SNMP_MIB>
|
||||
<CLICON_SNMP_MIB>IF-MIB</CLICON_SNMP_MIB>
|
||||
<CLICON_SNMP_MIB>ENTITY-MIB</CLICON_SNMP_MIB>
|
||||
<CLICON_VALIDATE_STATE_XML>true</CLICON_VALIDATE_STATE_XML>
|
||||
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
cat <<EOF > $fyang
|
||||
module clixon-example{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:clixon";
|
||||
prefix ex;
|
||||
import CLIXON-TYPES-MIB {
|
||||
prefix "clixon-types";
|
||||
}
|
||||
import IF-MIB {
|
||||
prefix "if-mib";
|
||||
}
|
||||
import ENTITY-MIB {
|
||||
prefix "entity-mib";
|
||||
}
|
||||
deviation "/clixon-types:CLIXON-TYPES-MIB" {
|
||||
deviate replace {
|
||||
config true;
|
||||
}
|
||||
}
|
||||
deviation "/if-mib:IF-MIB" {
|
||||
deviate replace {
|
||||
config true;
|
||||
}
|
||||
}
|
||||
deviation "/entity-mib:ENTITY-MIB" {
|
||||
deviate replace {
|
||||
config true;
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
if true; then # Dont start with a state (default)
|
||||
cat <<EOF > $dir/startup_db
|
||||
<${DATASTORE_TOP}>
|
||||
</${DATASTORE_TOP}>
|
||||
EOF
|
||||
|
||||
else # Start with a state (debug)
|
||||
|
||||
cat <<EOF > $dir/startup_db
|
||||
<${DATASTORE_TOP}>
|
||||
<CLIXON-TYPES-MIB xmlns="urn:ietf:params:xml:ns:yang:smiv2:CLIXON-TYPES-MIB">
|
||||
<clixonExampleScalars>
|
||||
<clixonExampleInteger>42</clixonExampleInteger>
|
||||
<ifIpAddr>4.3.2.1</ifIpAddr>
|
||||
</clixonExampleScalars>
|
||||
</CLIXON-TYPES-MIB>
|
||||
<IF-MIB xmlns="urn:ietf:params:xml:ns:yang:smiv2:IF-MIB">
|
||||
<ifStackTable>
|
||||
<ifStackEntry>
|
||||
<ifStackHigherLayer>9</ifStackHigherLayer>
|
||||
<ifStackLowerLayer>9</ifStackLowerLayer>
|
||||
</ifStackEntry>
|
||||
</ifStackTable>
|
||||
<ifTable>
|
||||
<ifEntry>
|
||||
<ifIndex>1</ifIndex>
|
||||
<ifPhysAddress>aa:bb:cc:dd:ee:ff</ifPhysAddress>
|
||||
</ifEntry>
|
||||
</ifTable>
|
||||
</IF-MIB>
|
||||
</${DATASTORE_TOP}>
|
||||
EOF
|
||||
fi
|
||||
|
||||
function testinit(){
|
||||
new "test params: -f $cfg"
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
# Kill old backend and start a new one
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err "Failed to start backend"
|
||||
fi
|
||||
|
||||
sudo pkill -f clixon_backend
|
||||
|
||||
new "Starting backend"
|
||||
start_backend -s startup -f $cfg
|
||||
fi
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
if [ $SN -ne 0 ]; then
|
||||
# Kill old clixon_snmp, if any
|
||||
new "Terminating any old clixon_snmp processes"
|
||||
sudo killall -q clixon_snmp
|
||||
|
||||
new "Starting clixon_snmp"
|
||||
start_snmp $cfg &
|
||||
fi
|
||||
|
||||
new "wait snmp"
|
||||
wait_snmp
|
||||
}
|
||||
|
||||
# Set value via SNMP, read value via SNMP and CLI
|
||||
# Args:
|
||||
# 1: name
|
||||
# 2: type
|
||||
# 3: value SNMP value
|
||||
# 4: value2 SNMP value2 (as shown "after" snmpset)
|
||||
# 5: xvalue XML/Clixon value
|
||||
# 6: OID
|
||||
function testrun()
|
||||
{
|
||||
name=$1
|
||||
type=$2
|
||||
value=$3
|
||||
value2=$4
|
||||
xvalue=$5
|
||||
oid=$6
|
||||
|
||||
# Type from man snmpset
|
||||
case $type in
|
||||
"INTEGER")
|
||||
set_type="i"
|
||||
;;
|
||||
"STRING")
|
||||
set_type="s"
|
||||
;;
|
||||
"HEX STRING")
|
||||
set_type="x"
|
||||
;;
|
||||
"TIMETICKS")
|
||||
set_type="t"
|
||||
;;
|
||||
"IPADDRESS")
|
||||
set_type="a"
|
||||
;;
|
||||
"OBJID")
|
||||
set_type="o"
|
||||
;;
|
||||
"BITS")
|
||||
set_type="b"
|
||||
;;
|
||||
*)
|
||||
set_type="s"
|
||||
;;
|
||||
esac
|
||||
|
||||
new "Set $name via SNMP"
|
||||
if [ $type == "STRING" ]; then
|
||||
echo "$snmpset $oid $set_type $value"
|
||||
expectpart "$($snmpset $oid $set_type $value)" 0 "$type:" "$value"
|
||||
else
|
||||
echo "$snmpset $oid $set_type $value"
|
||||
expectpart "$($snmpset $oid $set_type $value)" 0 "$type: $value2"
|
||||
fi
|
||||
new "Check $name via SNMP"
|
||||
if [ "$type" == "STRING" ]; then
|
||||
expectpart "$($snmpget $oid)" 0 "$type:" "$value"
|
||||
else
|
||||
expectpart "$($snmpget $oid)" 0 "$type: $value2"
|
||||
fi
|
||||
|
||||
new "Check $name via CLI"
|
||||
expectpart "$($clixon_cli -1 -f $cfg show config xml)" 0 "<$name>$xvalue</$name>"
|
||||
}
|
||||
|
||||
function testexit(){
|
||||
stop_snmp
|
||||
}
|
||||
|
||||
new "SNMP tests"
|
||||
testinit
|
||||
|
||||
MIB=".1.3.6.1.4.1.8072.200"
|
||||
IFMIB=".1.3.6.1.2.1"
|
||||
ENTMIB=".1.3.6.1.2.1.47.1.1.1"
|
||||
|
||||
testrun clixonExampleInteger INTEGER 1234 1234 1234 ${MIB}.1.1
|
||||
testrun clixonExampleSleeper INTEGER -1 -1 -1 ${MIB}.1.2
|
||||
testrun clixonExampleString STRING foobar foobar foobar ${MIB}.1.3
|
||||
testrun ifPromiscuousMode INTEGER 1 1 true ${MIB}.1.10 # boolean
|
||||
testrun ifIpAddr IPADDRESS 1.2.3.4 1.2.3.4 1.2.3.4 ${MIB}.1.13 # InetAddress
|
||||
testrun ifPhysAddress STRING ff:ee:dd:cc:bb:aa ff:ee:dd:cc:bb:aa ff:ee:dd:cc:bb:aa ${IFMIB}.2.2.1.6.1
|
||||
|
||||
# Inline testrun for rowstatus complicated logic
|
||||
name=ifStackStatus
|
||||
type=INTEGER
|
||||
oid=${IFMIB}.31.1.2.1.3.5.9
|
||||
|
||||
new "Set $name via SNMP"
|
||||
expectpart "$($snmpset $oid i 4)" 0 "$type: createAndGo(4)"
|
||||
|
||||
new "Check $name via SNMP"
|
||||
expectpart "$($snmpget $oid)" 0 "$type: active(1)"
|
||||
|
||||
new "Check $name via CLI"
|
||||
expectpart "$($clixon_cli -1 -f $cfg show config xml)" 0 "<$name>active</$name>"
|
||||
|
||||
new "Cleaning up"
|
||||
testexit
|
||||
|
||||
new "endtest"
|
||||
endtest
|
||||
239
test/test_snmp_system.sh
Executable file
239
test/test_snmp_system.sh
Executable file
|
|
@ -0,0 +1,239 @@
|
|||
#!/usr/bin/env bash
|
||||
# SNMP system MIB test
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
# Re-use main example backend state callbacks
|
||||
APPNAME=example
|
||||
|
||||
if [ ${ENABLE_NETSNMP} != "yes" ]; then
|
||||
echo "Skipping test, Net-SNMP support not enabled."
|
||||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
fi
|
||||
|
||||
snmpd=$(type -p snmpd)
|
||||
snmpget="$(type -p snmpget) -On -c public -v2c localhost "
|
||||
snmpwalk="$(type -p snmpwalk) -On -c public -v2c localhost "
|
||||
snmpwalkstr="$(type -p snmpwalk) -c public -v2c localhost "
|
||||
snmpgetnext="$(type -p snmpgetnext) -On -c public -v2c localhost "
|
||||
snmptable="$(type -p snmptable) -c public -v2c localhost "
|
||||
|
||||
cfg=$dir/conf_startup.xml
|
||||
fyang=$dir/clixon-example.yang
|
||||
fstate=$dir/state.xml
|
||||
|
||||
# AgentX unix socket
|
||||
SOCK=/var/run/snmp.sock
|
||||
|
||||
# Relies on example_backend.so for $fstate file handling
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${YANG_STANDARD_DIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${MIB_GENERATED_YANG_DIR}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_BACKEND_PIDFILE>/var/tmp/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
|
||||
<CLICON_SNMP_MIB>SNMPv2-MIB</CLICON_SNMP_MIB>
|
||||
<CLICON_VALIDATE_STATE_XML>true</CLICON_VALIDATE_STATE_XML>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
cat <<EOF > $fyang
|
||||
module clixon-example{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:clixon";
|
||||
prefix ex;
|
||||
import SNMPv2-MIB {
|
||||
prefix "snmpv2-mib";
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# This is state data written to file that backend reads from (on request)
|
||||
# integer and string have values, sleeper does not and uses default (=1)
|
||||
|
||||
cat <<EOF > $fstate
|
||||
<SNMPv2-MIB xmlns="urn:ietf:params:xml:ns:yang:smiv2:SNMPv2-MIB">
|
||||
<system>
|
||||
<sysName>Test</sysName>
|
||||
<sysContact>clixon@clicon.com</sysContact>
|
||||
<sysLocation>Clixon HQ</sysLocation>
|
||||
<sysDescr>System description</sysDescr>
|
||||
<sysUpTime>11223344</sysUpTime>
|
||||
<sysServices>72</sysServices>
|
||||
</system>
|
||||
<sysORTable>
|
||||
<sysOREntry>
|
||||
<sysORIndex>1</sysORIndex>
|
||||
<sysORID>1.3.6.1.2.1.4</sysORID>
|
||||
<sysORDescr>Entry 1 description</sysORDescr>
|
||||
<sysORUpTime>11223344</sysORUpTime>
|
||||
</sysOREntry>
|
||||
<sysOREntry>
|
||||
<sysORIndex>2</sysORIndex>
|
||||
<sysORID>1.3.6.1.2.1.2.2</sysORID>
|
||||
<sysORDescr>Entry 2 description</sysORDescr>
|
||||
<sysORUpTime>1122111111</sysORUpTime>
|
||||
</sysOREntry>
|
||||
</sysORTable>
|
||||
</SNMPv2-MIB>
|
||||
EOF
|
||||
|
||||
function testinit(){
|
||||
new "test params: -f $cfg -- -sS $fstate"
|
||||
if [ $BE -ne 0 ]; then
|
||||
# Kill old backend and start a new one
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err "Failed to start backend"
|
||||
fi
|
||||
|
||||
sudo pkill -f clixon_backend
|
||||
|
||||
new "Starting backend"
|
||||
start_backend -s init -f $cfg -- -sS $fstate
|
||||
fi
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
if [ $SN -ne 0 ]; then
|
||||
# Kill old clixon_snmp, if any
|
||||
new "Terminating any old clixon_snmp processes"
|
||||
sudo killall -q clixon_snmp
|
||||
|
||||
new "Starting clixon_snmp"
|
||||
start_snmp $cfg &
|
||||
fi
|
||||
|
||||
new "wait snmp"
|
||||
wait_snmp
|
||||
}
|
||||
|
||||
function testexit(){
|
||||
stop_snmp
|
||||
}
|
||||
|
||||
new "SNMP tests"
|
||||
testinit
|
||||
|
||||
OID_SYS=".1.3.6.1.2.1.1"
|
||||
OID_DESCR="${OID_SYS}.1"
|
||||
OID_UPTIME="${OID_SYS}.3"
|
||||
OID_CONTACT="${OID_SYS}.4"
|
||||
OID_SYSNAME="${OID_SYS}.5"
|
||||
OID_LOCATION="${OID_SYS}.6"
|
||||
OID_SERVICES="${OID_SYS}.7"
|
||||
OID_ORTABLE="${OID_SYS}.9"
|
||||
OID_ORTABLE1_IDX="${OID_SYS}.9.1.1.1"
|
||||
OID_ORTABLE2_IDX="${OID_SYS}.9.1.1.2"
|
||||
OID_ORTABLE1="${OID_SYS}.9.1.3.1"
|
||||
OID_ORTABLE2="${OID_SYS}.9.1.3.2"
|
||||
|
||||
NAME_DESCR="SNMPv2-MIB::sysDescr"
|
||||
NAME_UPTIME="SNMPv2-MIB::sysUpTime"
|
||||
NAME_CONTACT="SNMPv2-MIB::sysContact"
|
||||
NAME_SYSNAME="SNMPv2-MIB::sysName"
|
||||
NAME_LOCATION="SNMPv2-MIB::sysLocation"
|
||||
NAME_SERVICES="SNMPv2-MIB::sysServices"
|
||||
NAME_ORTABLE="SNMPv2-MIB::sysORTable"
|
||||
NAME_ORTABLE1_IDX="SNMPv2-MIB::sysORIndex.1"
|
||||
NAME_ORTABLE2_IDX="SNMPv2-MIB::sysORIndex.2"
|
||||
NAME_ORTABLE1="SNMPv2-MIB::sysORDescr.1"
|
||||
NAME_ORTABLE2="SNMPv2-MIB::sysORDescr.2"
|
||||
|
||||
new "Get description, $OID_DESCR"
|
||||
validate_oid $OID_DESCR $OID_DESCR "STRING" "System description"
|
||||
validate_oid $NAME_DESCR $NAME_DESCR "STRING" "System description"
|
||||
|
||||
new "Get next $OID_DESCR"
|
||||
validate_oid $OID_DESCR $OID_UPTIME "Timeticks" "(11223344) 1 day, 7:10:33.44"
|
||||
validate_oid $NAME_DESCR $NAME_UPTIME "Timeticks" "(11223344) 1 day, 7:10:33.44"
|
||||
|
||||
new "Get contact, $OID_CONTACT"
|
||||
validate_oid $OID_CONTACT $OID_CONTACT "STRING" "clixon@clicon.com"
|
||||
validate_oid $NAME_CONTACT $NAME_CONTACT "STRING" "clixon@clicon.com"
|
||||
|
||||
new "Get next OID after contact $OID_CONTACT"
|
||||
validate_oid $OID_CONTACT $OID_SYSNAME "STRING" "Test"
|
||||
validate_oid $NAME_CONTACT $NAME_SYSNAME "STRING" "Test"
|
||||
|
||||
new "Get sysName $OID_SYSNAME"
|
||||
validate_oid $OID_SYSNAME $OID_SYSNAME "STRING" "Test"
|
||||
validate_oid $NAME_SYSNAME $NAME_SYSNAME "STRING" "Test"
|
||||
|
||||
new "Get next OID after sysName $OID_SYSNAME"
|
||||
validate_oid $OID_SYSNAME $OID_LOCATION "STRING" "Clixon HQ"
|
||||
validate_oid $NAME_SYSNAME $NAME_LOCATION "STRING" "Clixon HQ"
|
||||
|
||||
new "Get sysLocation $OID_LOCATION"
|
||||
validate_oid $OID_LOCATION $OID_LOCATION "STRING" "Clixon HQ"
|
||||
validate_oid $NAME_LOCATION $NAME_LOCATION "STRING" "Clixon HQ"
|
||||
|
||||
new "Get next OID after sysLocation $OID_LOCATION"
|
||||
validate_oid $OID_LOCATION $OID_SERVICES "INTEGER" 72
|
||||
validate_oid $NAME_LOCATION $NAME_SERVICES "INTEGER" 72
|
||||
|
||||
new "Get sysServices $OID_SERVICES"
|
||||
validate_oid $OID_SERVICES $OID_SERVICES "INTEGER" "72"
|
||||
validate_oid $NAME_SERVICES $NAME_SERVICES "INTEGER" "72"
|
||||
|
||||
new "Get next OID after sysServices $OID_SERVICES"
|
||||
validate_oid $OID_SERVICES $OID_ORTABLE1_IDX "INTEGER" 1
|
||||
validate_oid $NAME_SERVICES $NAME_ORTABLE1_IDX "INTEGER" 1
|
||||
|
||||
new "Get first index of OR table $OID_ORTABLE1_IDX"
|
||||
validate_oid $OID_ORTABLE1_IDX $OID_ORTABLE1_IDX "INTEGER" 1
|
||||
validate_oid $NAME_ORTABLE1_IDX $NAME_ORTABLE1_IDX "INTEGER" 1
|
||||
|
||||
new "Get next OID after index $OID_ORTABLE1_IDX"
|
||||
validate_oid $OID_ORTABLE1_IDX $OID_ORTABLE2_IDX "INTEGER" 2
|
||||
validate_oid $NAME_ORTABLE1_IDX $NAME_ORTABLE2_IDX "INTEGER" 2
|
||||
|
||||
new "Get second index $OID_ORTABLE2_IDX"
|
||||
validate_oid $OID_ORTABLE2_IDX $OID_ORTABLE2_IDX "INTEGER" 2
|
||||
validate_oid $NAME_ORTABLE2_IDX $NAME_ORTABLE2_IDX "INTEGER" 2
|
||||
|
||||
new "Get sysORTable, entry 1 $OID_ORTABLE1"
|
||||
validate_oid $OID_ORTABLE1 $OID_ORTABLE1 "STRING" "Entry 1 description"
|
||||
validate_oid $NAME_ORTABLE1 $NAME_ORTABLE1 "STRING" "Entry 1 description"
|
||||
|
||||
new "Get sysORTable, entry 2 $OID_ORTABLE2"
|
||||
validate_oid $OID_ORTABLE2 $OID_ORTABLE2 "STRING" "Entry 2 description"
|
||||
validate_oid $NAME_ORTABLE2 $NAME_ORTABLE2 "STRING" "Entry 2 description"
|
||||
|
||||
new "Get table sysORTable $OID_ORTABLE"
|
||||
expectpart "$($snmptable $OID_ORTABLE)" 0 ".*Entry 1 description.*" "IP-MIB::ip" "1:7:10:33.44"
|
||||
expectpart "$($snmptable $OID_ORTABLE)" 0 ".*Entry 2 description.*" "IF-MIB::ifTable" "129:20:58:31.11"
|
||||
expectpart "$($snmptable $NAME_ORTABLE)" 0 ".*Entry 1 description.*" "IP-MIB::ip" "1:7:10:33.44"
|
||||
expectpart "$($snmptable $NAME_ORTABLE)" 0 ".*Entry 2 description.*" "IF-MIB::ifTable" "129:20:58:31.11"
|
||||
|
||||
new "Walk the tabbles..."
|
||||
expectpart "$($snmpwalkstr system)" 0 "SNMPv2-MIB::sysDescr = STRING: System description." \
|
||||
"SNMPv2-MIB::sysUpTime = Timeticks: (11223344) 1 day, 7:10:33.44" \
|
||||
"SNMPv2-MIB::sysContact = STRING: clixon@clicon.com." \
|
||||
"SNMPv2-MIB::sysName = STRING: Test." \
|
||||
"SNMPv2-MIB::sysLocation = STRING: Clixon HQ." \
|
||||
"SNMPv2-MIB::sysServices = INTEGER: 72" \
|
||||
"SNMPv2-MIB::sysORIndex.1 = INTEGER: 1" \
|
||||
"SNMPv2-MIB::sysORIndex.2 = INTEGER: 2" \
|
||||
"SNMPv2-MIB::sysORID.1 = OID: IP-MIB::ip" \
|
||||
"SNMPv2-MIB::sysORID.2 = OID: IF-MIB::ifTable" \
|
||||
"SNMPv2-MIB::sysORDescr.1 = STRING: Entry 1 description." \
|
||||
"SNMPv2-MIB::sysORDescr.2 = STRING: Entry 2 description." \
|
||||
"SNMPv2-MIB::sysORUpTime.1 = Timeticks: (11223344) 1 day, 7:10:33.44" \
|
||||
"SNMPv2-MIB::sysORUpTime.2 = Timeticks: (1122111111) 129 days, 20:58:31.11"
|
||||
|
||||
new "Cleaning up"
|
||||
testexit
|
||||
|
||||
new "endtest"
|
||||
endtest
|
||||
Loading…
Add table
Add a link
Reference in a new issue