|
1 /* |
|
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
|
3 * |
|
4 * U.S. Government Rights - Commercial software. Government users are subject |
|
5 * to the Sun Microsystems, Inc. standard license agreement and applicable |
|
6 * provisions of the FAR and its supplements. |
|
7 * |
|
8 * |
|
9 * This distribution may include materials developed by third parties. Sun, |
|
10 * Sun Microsystems, the Sun logo and Solaris are trademarks or registered |
|
11 * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. |
|
12 */ |
|
13 |
|
14 |
|
15 README for demo_module_3 |
|
16 ******************************************************************** |
|
17 |
|
18 This code example shows you how to modify the code generated by |
|
19 "mib2c -c mib2c.iterate.conf" command to perform data retrieval for |
|
20 a general table. |
|
21 |
|
22 |
|
23 Introduction |
|
24 ------------ |
|
25 |
|
26 General tables are different from simple tables in one of the following |
|
27 ways: |
|
28 - index is not a single integer |
|
29 - maximum index is not easily determinable |
|
30 - not all indexes are valid |
|
31 - table data is not directly accessible, such as the interfaces table |
|
32 |
|
33 See the System Management Agent Developer's Guide |
|
34 for more information about general tables data retrieval. |
|
35 |
|
36 |
|
37 This example uses some dummy data to perform data retrieval for a |
|
38 two-index table. It was generated by using "mib2c -c mib2c.iterate.conf" |
|
39 against the me1ContactInfoTable group in the SDK-DEMO1-MIB. |
|
40 Some functions have been added to the generated code to implement a |
|
41 link list to provide the test data. |
|
42 |
|
43 mib2c created templates called me1ContactInfoTable.c and me1ContactInfoTable.h. |
|
44 |
|
45 These were renamed demo_module_3.c and demo_module_3.h for this demo. |
|
46 Within me1ContactInfoTable.c, mib2c generated init_me1ContactInfoTable, and |
|
47 this was renamed to init_demo_module_3. |
|
48 |
|
49 Note that even though the SDK-DEMO1-MIB file contains the specification of |
|
50 tables and scalar, running mib2c with mib2c.iterate.conf |
|
51 generates template code only for the general table in the MIB. |
|
52 |
|
53 |
|
54 |
|
55 How to Use the demo_module_3 Code Example |
|
56 ========================================== |
|
57 |
|
58 The demo_module_3 code example includes the following files, by default |
|
59 located in the directory /usr/demo/sma_snmp/demo_module_3. |
|
60 |
|
61 Files: |
|
62 |
|
63 o Makefile - Compiles the module source code |
|
64 o demo_module_3.c - Source code for the module |
|
65 o demo_module_3.h - Header file for the module |
|
66 o SDK-DEMO1-MIB.txt - MIB file used in the module |
|
67 |
|
68 |
|
69 To set up your environment for the demo: |
|
70 |
|
71 1. Copy the demo code to a directory for which you have write permission. |
|
72 For example: |
|
73 |
|
74 % cp -R /usr/demo/sma_snmp/demo_module_3 /home/username/demo |
|
75 |
|
76 |
|
77 2. Create a lib directory that you can use to store shared object libraries |
|
78 that you generate from demo code examples, if you have not already done so. |
|
79 For example: |
|
80 |
|
81 % mkdir /home/username/demo/lib |
|
82 |
|
83 |
|
84 3. Create a mibs directory that you can use to store MIB files for the demo |
|
85 code examples, if you have not already done so. |
|
86 For example: |
|
87 |
|
88 % mkdir /home/username/demo/mibs |
|
89 |
|
90 |
|
91 4. Set the CC environment variable to the location of the C compiler to |
|
92 be used. |
|
93 For example, if you are using Sun ONE Studio: |
|
94 |
|
95 % setenv CC /opt/SUNWspro/bin/cc |
|
96 |
|
97 |
|
98 5. Set your PATH environment variable to include the appropriate paths, so that |
|
99 needed binaries can be found during the compilation process. |
|
100 For example, in the csh: |
|
101 |
|
102 % setenv PATH .:/usr/bin:$PATH |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 To generate code templates from the sample MIB: |
|
108 |
|
109 |
|
110 1. Change to the directory where you copied the demo module files. |
|
111 For example: |
|
112 |
|
113 % cd /home/username/demo/demo_module_3 |
|
114 |
|
115 |
|
116 2. Copy the SDK-DEMO1-MIB.txt file to the mibs directory you created for the |
|
117 demos, if you have not already done so. |
|
118 For example: |
|
119 |
|
120 % cp SDK-DEMO1-MIB.txt /home/username/demo/mibs |
|
121 |
|
122 |
|
123 3. Set your MIBS and MIBDIRS environment variables to |
|
124 include the appropriate paths. |
|
125 For example, in the csh: |
|
126 |
|
127 % setenv MIBDIRS .:/home/username/demo/mibs:/etc/sma/snmp/mibs |
|
128 % setenv MIBS +SDK-DEMO1-MIB |
|
129 |
|
130 |
|
131 4. Run mib2c on the me1ContactInfoTable group in the SDK-DEMO1-MIB. |
|
132 For example: |
|
133 |
|
134 % mib2c -c mib2c.iterate.conf me1ContactInfoTable |
|
135 |
|
136 The mib2c utility generates the following template files: |
|
137 me1ContactInfoTable.c |
|
138 me1ContactInfoTable.h |
|
139 |
|
140 |
|
141 5. Compare the template files with the demo_module_3.c and the |
|
142 demo_module_3.h files. |
|
143 |
|
144 The demo_module_3 files were created by modifying the templates. |
|
145 |
|
146 The following code is to set up the table with two indexes: |
|
147 netsnmp_table_helper_add_indexes(table_info, |
|
148 ASN_INTEGER, /* index: me1FloorNumber */ |
|
149 ASN_INTEGER, /* index: me1RoomNumber */ |
|
150 0); |
|
151 |
|
152 Care must be taken in returning the "NEXT" data when function |
|
153 me1ContactInfoTable_get_next_data_point() is called. |
|
154 |
|
155 For instance, in the example code: |
|
156 me1ContactEntry* nextNode = (me1ContactEntry*) *my_loop_context; |
|
157 nextNode = nextNode->pNext; |
|
158 |
|
159 The table data is pre-sorted so the next data is conveniently pointed by |
|
160 the pNext pointer. If your implementation is more complicated you should |
|
161 make sure the OIDs increase with the immediate next OID. (xxx.1.1, xxx.1.2, |
|
162 etc). |
|
163 |
|
164 |
|
165 |
|
166 To build the example: |
|
167 |
|
168 1. Change to the directory where you copied the demo module files. |
|
169 For example: |
|
170 |
|
171 % cd /home/username/demo/demo_module_3 |
|
172 |
|
173 |
|
174 2. Use the make command to generate object files. |
|
175 |
|
176 If you are running the 64-bit SPARC Solaris kernel, type: |
|
177 % /usr/ccs/bin/make |
|
178 |
|
179 If you are running the 32-bit SPARC Solaris kernel, type: |
|
180 % /usr/ccs/bin/make ARCH=32 |
|
181 |
|
182 If you are running the Solaris x86 kernel, type: |
|
183 % /usr/ccs/bin/make ARCH=32 |
|
184 |
|
185 |
|
186 3. Copy the module shared library object to the lib directory you created. |
|
187 For example: |
|
188 |
|
189 % cp demo_module_3.so /home/username/demo/lib |
|
190 |
|
191 |
|
192 |
|
193 Setting Up Agent to Run demo_module_3 |
|
194 ===================================== |
|
195 |
|
196 1. As root, edit the agent's configuration file /etc/sma/snmp/snmpd.conf, |
|
197 and insert a dlmod statement for the module. This statement enables |
|
198 the agent to load the module. |
|
199 For example: |
|
200 |
|
201 dlmod demo_module_3 /home/username/demo/lib/demo_module_3.so |
|
202 |
|
203 |
|
204 2. As root, start the SMA snmp agent. If the agent is already running, |
|
205 stop and restart it in debug mode. |
|
206 For example: |
|
207 |
|
208 # /etc/init.d/init.sma stop |
|
209 # /usr/sbin/snmpd -Ddemo_module_3 |
|
210 |
|
211 The optional -Ddemo_module_3 argument sends debugging statements from |
|
212 demo_module_3 to the /var/log/snmpd.log file. You can also use |
|
213 the -L and -f options to send debugging statements to the screen instead. |
|
214 |
|
215 |
|
216 |
|
217 Testing the Module |
|
218 ================== |
|
219 |
|
220 1. As a non-root user, issue snmptable commands to retrieve table data from |
|
221 the module. |
|
222 For example: |
|
223 |
|
224 |
|
225 % snmptable -v1 -c public localhost SDK-DEMO1-MIB::me1ContactInfoTable |
|
226 |
|
227 SNMP table: SDK-DEMO1-MIB::me1ContactInfoTable |
|
228 |
|
229 me1FloorNumber me1RoomNumber me1Name me1Extension |
|
230 1 1004 John Doe 8004 |
|
231 1 1007 John Doe 8007 |
|
232 1 1010 John Doe 8000 |
|
233 2 2003 John Doe 8003 |
|
234 2 2006 John Doe 8006 |
|
235 2 2009 John Doe 8009 |
|
236 2 2012 John Doe 8002 |
|
237 3 3005 John Doe 8005 |
|
238 3 3008 John Doe 8008 |
|
239 3 3011 John Doe 8001 |
|
240 |
|
241 or |
|
242 |
|
243 % snmptable -v1 -c public localhost .1.3.6.1.4.1.42.2.2.4.4.1.3.1 |
|
244 |
|
245 |
|
246 |
|
247 SNMP table: SDK-DEMO1-MIB::me1ContactInfoTable |
|
248 |
|
249 me1Extension me1Name me1RoomNumber me1FloorNumber |
|
250 8004 John Doe 1004 1 |
|
251 8007 John Doe 1007 1 |
|
252 8000 John Doe 1010 1 |
|
253 8003 John Doe 2003 2 |
|
254 8006 John Doe 2006 2 |
|
255 8009 John Doe 2009 2 |
|
256 8002 John Doe 2012 2 |
|
257 8005 John Doe 3005 3 |
|
258 8008 John Doe 3008 3 |
|
259 8001 John Doe 3011 3 |
|
260 |
|
261 |