Blame local/README.mib2c

Packit fcad23
This README describes the ./local/mib2c script.
Packit fcad23
Packit fcad23
Author:  Derek Simkowiak
Packit fcad23
         dereks@kd-dev.com
Packit fcad23
         http://www.kd-dev.com
Packit fcad23
         (please mail questions to net-snmp-coders@lists.sourceforge.net,
Packit fcad23
         not to the author directly.  Thanks!)
Packit fcad23
Packit fcad23
Date:    Wed Jan 20 02:51:06 PST 1999
Packit fcad23
-----------------------------------------------------------------------
Packit fcad23
mib2c
Packit fcad23
Packit fcad23
OVERVIEW
Packit fcad23
Packit fcad23
	mib2c is a Perl script that takes a MIB (such as those files found
Packit fcad23
in ./mibs/ ) and converts it into C code.  That C code can then be used as a
Packit fcad23
"template" to implement your MIB.  Then, when you are done editing the C
Packit fcad23
code and recompiling, the UCD-SNMP agent (snmpd) will support your MIB.
Packit fcad23
mib2c takes the place of "MIB Compilers" that come with commercial SNMP
Packit fcad23
agents.
Packit fcad23
Packit fcad23
Packit fcad23
REQUIREMENTS/INSTALLATION
Packit fcad23
Packit fcad23
	mib2c requires the SNMP.pm Perl module.  As of this writing the
Packit fcad23
latest version of the SNMP.pm module is 1.8.
Packit fcad23
Packit fcad23
	The SNMP.pm module can be downloaded from CPAN at 
Packit fcad23
Packit fcad23
http://www.cpan.org/modules/by-module/SNMP/
Packit fcad23
Packit fcad23
	...the file that you want is probably SNMP-1.8b5.tar.gz .
Packit fcad23
If you didn't know that already, most every Perl module can be downloaded
Packit fcad23
from CPAN (www.cpan.org).  Follow the installation instructions for the
Packit fcad23
module.
Packit fcad23
Packit fcad23
	NOTE: If you are running Redhat Linux 5.2 (and perhaps other
Packit fcad23
versions), you might get the following errors during the "make test" phase
Packit fcad23
of the installation of the SNMP.pm module:
Packit fcad23
Packit fcad23
[root@olly SNMP-1.8b5]# make test             # This is the command...
Packit fcad23
PERL_DL_NONLAZY=1 /usr/bin/perl -I./blib/arch -I./blib/lib
Packit fcad23
-I/usr/lib/perl5/i386-linux/5.00404 -I/usr/lib/perl5 -e 'use Test::Harness
Packit fcad23
qw(&runtests $verbose); $verbose=0; runtests @ARGV;' t/*.t
Packit fcad23
t/mib...............ok
Packit fcad23
t/session...........FAILED tests 7-8
Packit fcad23
        Failed 2/14 tests, 85.71% okay
Packit fcad23
t/translate.........ok
Packit fcad23
Failed Test  Status Wstat Total Fail  Failed  List of failed
Packit fcad23
-------------------------------------------------------------------------------
Packit fcad23
t/session.t                  14    2  14.29%  7-8
Packit fcad23
Failed 1/3 test scripts, 66.67% okay. 2/24 subtests failed, 91.67% okay.
Packit fcad23
make: *** [test_dynamic] Error 9
Packit fcad23
Packit fcad23
Packit fcad23
	If the "make" went okay, then you can ignore these test failures.
Packit fcad23
These indicate you don't have write access to the portions of the mib
Packit fcad23
tree that the test script is trying to use.  Please don't email the
Packit fcad23
UCD-SNMP list with other errors regarding the SNMP.pm module.
Packit fcad23
comp.lang.perl.modules is probably the most appropriate spot to
Packit fcad23
discuss problems with the SNMP.pm perl module itself. Interelated
Packit fcad23
problems between net-snmp and SNMP could be discussed on the net-snmp
Packit fcad23
mailing lists though.
Packit fcad23
Packit fcad23
Packit fcad23
USAGE
Packit fcad23
Packit fcad23
	mib2c takes one argument: an OID.  It then traces down that OID
Packit fcad23
and generates the template C code.  Here is the documentation, from the
Packit fcad23
top of the script:
Packit fcad23
Packit fcad23
# This program, given an OID reference as an argument, creates some
Packit fcad23
# template mib module files to be used with the net-snmp agent.  It is
Packit fcad23
# far from perfect and will not generate working modules, but it
Packit fcad23
# significantly shortens development time by outlining the basic
Packit fcad23
# structure.
Packit fcad23
#
Packit fcad23
# Its up to you to verify what it does and change the default values
Packit fcad23
# it returns.
Packit fcad23
#
Packit fcad23
# You *must* correct the beginning of the var_XXX() function to
Packit fcad23
# correctly determine mib ownership of the incoming request.
Packit fcad23
Packit fcad23
Packit fcad23
FINDING YOUR MIB
Packit fcad23
Packit fcad23
	Before you can specify the OID for your enterprise/MIB on the
Packit fcad23
command line, the script needs to be able to find your MIB so that it can
Packit fcad23
read it in and generate template code.  Joe Marzot (gmarzot@nortelnetworks.com)
Packit fcad23
tells us:
Packit fcad23
--------------------------------------
Packit fcad23
you should read (man mib_api). The default behaviour for mib loading
Packit fcad23
from within the perl interface uses the environment variables described
Packit fcad23
there. You can also override these and explicitly define mibdirs and
Packit fcad23
load modules through the perl/SNMP api.
Packit fcad23
Packit fcad23
the easiest thing to do is toss the mibs in /usr/local/share/snmp/mibs
Packit fcad23
and set the env. var., MIBS, to 'ALL'.
Packit fcad23
--------------------------------------
Packit fcad23
Packit fcad23
	I recommend following the last two lines of advice.  I simply did
Packit fcad23
Packit fcad23
# cp /home/dereks/MY-MIB-FILE.txt /usr/local/share/snmp/mibs/
Packit fcad23
# export MIBS=ALL
Packit fcad23
Packit fcad23
	...on my Redhat system (with a BASH shell) and it was able to find
Packit fcad23
my MIB just fine.
Packit fcad23
Packit fcad23
Packit fcad23
EXAMPLES
Packit fcad23
Packit fcad23
	Here are some examples from Wes Hardaker (wjhardaker@ucdavis.edu).
Packit fcad23
He's using a C shell.  Wes writes:
Packit fcad23
--------------------------------------
Packit fcad23
Ok, in order to run the thing, you actually need to do something like
Packit fcad23
this:
Packit fcad23
Packit fcad23
setenv MIBS MY-ITEM-MIB          # assumes csh
Packit fcad23
mib2c itemNode
Packit fcad23
Packit fcad23
Where, "itemNode" should be a node in the mib tree that you want to
Packit fcad23
generate C code for.  Note, pick small pieces not large ones.  Yes, it 
Packit fcad23
will generate code for the entire mibII tree if you ask it to, in one
Packit fcad23
very large mib file.
Packit fcad23
Packit fcad23
Examples:
Packit fcad23
Packit fcad23
% mib2c interfaces
Packit fcad23
outputing to interfaces.c and interfaces.h ...
Packit fcad23
  depth: 3
Packit fcad23
  Number of Lines Created:
Packit fcad23
178 interfaces.c
Packit fcad23
84 interfaces.h
Packit fcad23
262 total
Packit fcad23
Done.
Packit fcad23
Packit fcad23
% mib2c mib-2                             # Don't ever do this.
Packit fcad23
outputing to mib-2.c and mib-2.h ...
Packit fcad23
  depth: 5
Packit fcad23
  Number of Lines Created:
Packit fcad23
2783 mib-2.c
Packit fcad23
617 mib-2.h
Packit fcad23
3400 total
Packit fcad23
Done.
Packit fcad23
Packit fcad23
It may have some sorting problems with multiple level mib tree
Packit fcad23
branches being generated into one piece of code (reorder the .h file
Packit fcad23
structure to be in OID lexical order if needed).
Packit fcad23
--------------------------------------
Packit fcad23
Packit fcad23
WHAT TO DO WITH THE CODE THAT GETS GENERATED
Packit fcad23
Packit fcad23
	You will need to edit your generated code to work with your
Packit fcad23
hardware.  For instance, if your MIB is for a refrigerator, you will need
Packit fcad23
to write the code that talks to the refridgerator (through the serial
Packit fcad23
port, maybe?) in Fridge Protocol.
Packit fcad23
Packit fcad23
	See the files in ./agent/mibgroup/examples/ and
Packit fcad23
./agent/mibgroup/dummy/ for heavily-commented example code.  Don't ask me
Packit fcad23
questions about this stuff--I'm just now figuring it out myself...
Packit fcad23
Packit fcad23
	[NOTE: If anyone out there has tips about necessary options to
Packit fcad23
./configure, or re-compiling snmpd with custom MIB support, please add
Packit fcad23
them here...]
Packit fcad23
Packit fcad23
WARNING
Packit fcad23
Packit fcad23
	As of this writing, the mib2c compiler is a bit outdated and needs
Packit fcad23
some work.  Wes writes:
Packit fcad23
--------------------------------------
Packit fcad23
It already needs changing, because the architecture has changed in the 
Packit fcad23
3.6 line (though its backwards compatible, I'd prefer to generate
Packit fcad23
code from newer models than older ones).
Packit fcad23
--------------------------------------
Packit fcad23
	When I asked him to elaborate on the new 3.6 archictecture, all I
Packit fcad23
got was:
Packit fcad23
--------------------------------------
Packit fcad23
It hopefully will be in the new documentation about mib module api
Packit fcad23
that Dave Shield is putting together (which is also currently wrong,
Packit fcad23
for that matter)...
Packit fcad23
--------------------------------------
Packit fcad23
	...so I don't know what the hell he's talking about.
Packit fcad23
Packit fcad23
Packit fcad23
SOME ERRORS AND THEIR MEANING
Packit fcad23
Packit fcad23
	If you get a large number of errors that look like:
Packit fcad23
Packit fcad23
[...]
Packit fcad23
unknown type:  INTEGER for prIndex
Packit fcad23
unknown type:  OCTETSTR for prNames
Packit fcad23
unknown type:  INTEGER for prMin
Packit fcad23
[...]
Packit fcad23
Packit fcad23
	...then you are trying to use an old version of the mib2c script
Packit fcad23
that does not support the SNMP.pm module version 1.8.  Get the latest
Packit fcad23
version of the script.
Packit fcad23
Packit fcad23
	If you get the error 
Packit fcad23
Packit fcad23
Couldn't find mib reference: myEnterpriseOID
Packit fcad23
Packit fcad23
	...when you know that it should be finding your MIB file(s), then
Packit fcad23
you forgot to put the word "END" at the very end of your MIB.  (Uh...I'm
Packit fcad23
not speaking from experience here.  Really.)
Packit fcad23
Packit fcad23
ACKNOWLEGMENTS
Packit fcad23
Packit fcad23
	Many thanks to the people on the UCD-SNMP mailing list
Packit fcad23
(net-snmp-users@lists.sourceforge.net).  In particular, many thanks to
Packit fcad23
Packit fcad23
Wes Hardaker <wjhardaker@ucdavis.edu>
Packit fcad23
Ken McNamara <conmara@tcon.net>
Packit fcad23
Joe Marzot <gmarzot@nortelnetworks.com>
Packit fcad23
Packit fcad23
	...since about half this document is just cut'n'pasted from emails
Packit fcad23
they sent me.
Packit fcad23
Packit fcad23
	Good luck with your project.
Packit fcad23
Packit fcad23
Derek Simkowiak
Packit fcad23
dereks@kd-dev.com
Packit fcad23
http://www.kd-dev.com
Packit fcad23