2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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.
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.
16 #include <net-snmp/net-snmp-config.h>
17 #include <net-snmp/net-snmp-includes.h>
18 #include <net-snmp/agent/net-snmp-agent-includes.h>
20 #include "entPhysicalTable.h"
21 #include "entLogicalTable.h"
22 #include "entPhysicalContainsTable.h"
23 #include "entAliasMappingTable.h"
24 #include "entLPMappingTable.h"
28 These are global arrays that manage the physical indexes
29 and logical indexes within the scope of this program.
30 Similar index management scheme will be
31 developed within the program that uses the entity MIB
32 skeleton. The array is statically allocated here
33 for convience in the example
36 int physicalIndex
[25], logicalIndex
[25];
40 This is the initialisation function for the library.
41 This function is always named as init_<library name>. This function is called during
42 when this library gets loaded in the agent. Make sure that the libentity.so
43 library is already loaded before this library is loaded.
47 void init_demo_module_11(void) {
49 entPhysicalEntry_t zEntry
;
50 entLogicalEntry_t zLogEntry
;
53 All these are ficitious OIDs created for this example. Do not
54 rely on these OID numbers, these are used just for demonstration
57 oid chassis_oid
[] = { 1, 3, 6, 1, 4, 1, 42, 200, 1 };
58 oid slot_oid
[] = { 1, 3, 6, 1, 4, 1, 42, 201, 1 };
59 oid cpu_oid1
[] = { 1, 3, 6, 1, 4, 1, 42, 202, 14 };
60 oid cpu_oid2
[] = { 1, 3, 6, 1, 4, 1, 42, 202, 15 };
61 oid cpu_oid3
[] = { 1, 3, 6, 1, 4, 1, 42, 202, 25 };
63 oid module_oid1
[] = { 1, 3, 6, 1, 4, 1, 42, 203, 2 };
64 oid module_oid2
[] = { 1, 3, 6, 1, 4, 1, 42, 203, 5 };
66 oid port_oid
[] = { 1, 3, 6, 1, 4, 1, 42, 204, 5 };
68 oid solaris_oid
[] = { 1, 3, 6, 1, 4, 1, 42, 2, 1 };
69 oid SunExample_oid
[] = { 1, 3, 6, 1, 4, 1, 42, 1005 };
71 oid ifIndex_oid1
[] = { 1,3,6,1,2,1,2,2,1,1,1 };
72 oid ifIndex_oid2
[] = { 1,3,6,1,2,1,2,2,1,1,2 };
73 oid ifIndex_oid3
[] = { 1,3,6,1,2,1,2,2,1,1,3 };
77 Assuming that the entity MIB skeleton is already loaded, the
78 following lines adds all the Physical objects that will
79 be present in the modelled system
82 FillentPhysicalEntry(&zEntry
, "Sun Chassis Model b1000", chassis_oid
, sizeof(chassis_oid
),
83 0, 3, -1, "b1000", "A(1.00.02)", "", "", "C100076544",
84 "Sun Microsystems", "CHS-1000", "cl-SJ17-3-006:rack1:rtr-U3",
85 "0007372293", MIB_TRUE
);
86 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
88 FillentPhysicalEntry(&zEntry
, "Sun Chassis Slot Type AA", slot_oid
,
89 sizeof(slot_oid
), 1, 5, 1, "S1", "B(1.00.01)", "", "", "",
90 "Sun Microsystems", "SLT-AA97", "", "", MIB_FALSE
);
91 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
93 FillentPhysicalEntry(&zEntry
, "Sun Chassis Slot Type AA", slot_oid
,
94 sizeof(slot_oid
), 1, 5, 2, "S2", "1.00.07", "", "", "",
95 "Sun Microsystems", "SLT-AA97", "", "", MIB_FALSE
);
96 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
98 FillentPhysicalEntry(&zEntry
, "Sun Chassis Slot Type AA", slot_oid
,
99 sizeof(slot_oid
), 1, 5, 3, "S3", "1.00.07", "", "", "",
100 "Sun Microsystems", "SLT-AA97", "", "", MIB_FALSE
);
101 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
103 FillentPhysicalEntry(&zEntry
, "Sun CPU-100", cpu_oid1
,
104 sizeof(cpu_oid1
), 2, 9, 1, "M1", "1.00.07", "1.5.1", "A(1.1)",
105 "C100087363", "Sun Microsystems", "R10-FE00",
106 "rtr-U3:m1:SJ17-3-eng", "0007372562", MIB_TRUE
);
107 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
110 FillentPhysicalEntry(&zEntry
, "Sun Ultrasparc-III 400MHz", module_oid1
,
111 sizeof(module_oid1
), 5, 1, 1, "P1", "G(1.02)", "", "1.1", "",
112 "Sun Microsystems", "SFE-400M", "", "", MIB_FALSE
);
113 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
115 FillentPhysicalEntry(&zEntry
, "Sun Ultrasparc-III 400MHz", module_oid1
,
116 sizeof(module_oid1
), 5, 1, 2, "P2", "G(1.02)", "", "1.1", "",
117 "Sun Microsystems", "SFE-400M", "", "", MIB_FALSE
);
118 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
120 FillentPhysicalEntry(&zEntry
, "Sun CPU-200", cpu_oid2
,
121 sizeof(cpu_oid2
), 3, 9, 1, "M2", "2.01.00", "3.0.7", "A(1.2)",
122 "C100098732", "Sun Microsystems", "R10-FE0C",
123 "rtr-U3:m2:SJ17-2-eng", "0007373982", MIB_TRUE
);
124 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
126 FillentPhysicalEntry(&zEntry
, "Sun Ultrasparc-III 400MHz", module_oid2
,
127 sizeof(module_oid2
), 8, 1, 1, "P3", "CC(1.07)", "2.0.34", "1.1", "",
128 "Sun Microsystems", "SFE-400M", "", "", MIB_FALSE
);
129 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
131 FillentPhysicalEntry(&zEntry
, "Sun Ultrasparc-III 400MHz", module_oid1
,
132 sizeof(module_oid1
), 8, 1, 2, "P4", "G(1.04)", "", "1.3", "",
133 "Sun Microsystems", "SFE-400M", "", "", MIB_FALSE
);
134 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
136 FillentPhysicalEntry(&zEntry
, "Sun port-200", cpu_oid3
,
137 sizeof(cpu_oid3
), 4, 9, 1, "M2", "2.01.00", "3.0.7", "A(1.2)",
138 "C100098732", "Sun Microsystems", "R11-C100",
139 "rtr-U3:m2:SJ17-2-eng", "0007373982", MIB_TRUE
);
140 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
143 FillentPhysicalEntry(&zEntry
, "Sun Ethernet-100 Port", port_oid
,
144 sizeof(port_oid
), 11, 10, 1, "P3", "CC(1.07)", "2.0.34", "1.1",
145 "", "Sun Microsystems", "SFE-P100", "", "", MIB_FALSE
);
146 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
148 FillentPhysicalEntry(&zEntry
, "Sun Ethernet-100 Port", port_oid
,
149 sizeof(port_oid
), 11, 10, 2, "Ethernet B", "G(1.04)", "", "1.3",
150 "", "Sun Microsystems", "SFE-P100", "", "", MIB_FALSE
);
151 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
153 FillentPhysicalEntry(&zEntry
, "Sun Ethernet-100 Port", port_oid
,
154 sizeof(port_oid
), 11, 10, 3, "Ethernet B", "G(1.04)", "", "1.3",
155 "", "Sun Microsystems", "SFE-P100", "", "", MIB_FALSE
);
156 physicalIndex
[i
++] = allocPhysicalEntry(0, &zEntry
);
159 The following lines adds all the logical instances that will
160 be present in the modelled system. Here first parameter to
161 allocLogicalEntry is ignored for now, it may be used in the
162 future to request a particular index in the table
165 FillentLogicalEntry(&zLogEntry
, "Domain A", solaris_oid
,
166 sizeof(solaris_oid
), "public-dom1", "124.125.126.127:161",
167 SunExample_oid
, sizeof(SunExample_oid
), "", "");
168 logicalIndex
[j
++] = allocLogicalEntry(0, &zLogEntry
);
170 FillentLogicalEntry(&zLogEntry
, "Domain B", solaris_oid
,
171 sizeof(solaris_oid
), "public-dom2", "124.125.126.128:161",
172 SunExample_oid
, sizeof(SunExample_oid
), "", "");
173 logicalIndex
[j
++] = allocLogicalEntry(0, &zLogEntry
);
175 FillentLogicalEntry(&zLogEntry
, "Sun Firewall v2.1.1", solaris_oid
,
176 sizeof(solaris_oid
), "public-firewall1", "124.125.126.129:161",
177 SunExample_oid
, sizeof(SunExample_oid
), "", "");
178 logicalIndex
[j
++] = allocLogicalEntry(0, &zLogEntry
);
180 FillentLogicalEntry(&zLogEntry
, "Sun Firewall v2.1.1", solaris_oid
,
181 sizeof(solaris_oid
), "public-firewall2", "124.125.126.130:161",
182 SunExample_oid
, sizeof(SunExample_oid
), "", "");
183 logicalIndex
[j
++] = allocLogicalEntry(0, &zLogEntry
);
188 Now we add all the relationships into the entity MIB. The
189 physical and logical indexes must be present to create
190 any relationships, and so the relationship table is
191 filled after the physical and logical tables are
196 if (addLPMappingTableEntry(1, 5))
197 snmp_log(LOG_ERR
, "LPMappingTable Addition failed");
199 if (addLPMappingTableEntry(1, 12))
200 snmp_log(LOG_ERR
, "LPMappingTable Addition failed");
202 if (addLPMappingTableEntry(2, 8))
203 snmp_log(LOG_ERR
, "LPMappingTable Addition failed");
205 if (addLPMappingTableEntry(2, 13))
206 snmp_log(LOG_ERR
, "LPMappingTable Addition failed");
208 if (addLPMappingTableEntry(2, 14))
209 snmp_log(LOG_ERR
, "LPMappingTable Addition failed");
211 if (addLPMappingTableEntry(3, 6))
212 snmp_log(LOG_ERR
, "LPMappingTable Addition failed");
214 if (addLPMappingTableEntry(3, 12))
215 snmp_log(LOG_ERR
, "LPMappingTable Addition failed");
217 if (addLPMappingTableEntry(4, 9))
218 snmp_log(LOG_ERR
, "LPMappingTable Addition failed");
220 if (addLPMappingTableEntry(4, 13))
221 snmp_log(LOG_ERR
, "LPMappingTable Addition failed");
223 if (addLPMappingTableEntry(4, 14))
224 snmp_log(LOG_ERR
, "LPMappingTable Addition failed");
228 Any error in addition to the relationship table will
229 be logged in the agent's log file
233 if (addAliasMappingTableEntry(12, 0, ifIndex_oid1
, sizeof(ifIndex_oid1
)))
234 snmp_log(LOG_ERR
, "AliasMappingTable Addition failed");
236 if (addAliasMappingTableEntry(13, 0, ifIndex_oid2
, sizeof(ifIndex_oid2
)))
237 snmp_log(LOG_ERR
, "AliasMappingTable Addition failed");
239 if (addAliasMappingTableEntry(14, 0, ifIndex_oid3
, sizeof(ifIndex_oid3
)))
240 snmp_log(LOG_ERR
, "AliasMappingTable Addition failed");
243 The physical child table must not contains any recursive relationships
244 Care must be taken to avoid them. The entity MIB infrastructure should
245 be able to check this in the future
248 if (addPhysicalContainsTableEntry(1, 2))
249 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
250 if (addPhysicalContainsTableEntry(1, 3))
251 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
252 if (addPhysicalContainsTableEntry(1, 4))
253 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
254 if (addPhysicalContainsTableEntry(2, 5))
255 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
256 if (addPhysicalContainsTableEntry(3, 8))
257 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
258 if (addPhysicalContainsTableEntry(4, 11))
259 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
260 if (addPhysicalContainsTableEntry(4, 6))
261 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
262 if (addPhysicalContainsTableEntry(4, 7))
263 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
264 if (addPhysicalContainsTableEntry(8, 9))
265 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
266 if (addPhysicalContainsTableEntry(8, 10))
267 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
268 if (addPhysicalContainsTableEntry(11, 12))
269 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
270 if (addPhysicalContainsTableEntry(11, 13))
271 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
272 if (addPhysicalContainsTableEntry(11, 14))
273 snmp_log(LOG_ERR
, "PhysicalChild Table Addition failed");
284 This function is just a conveience function to add many physical table
288 void FillentPhysicalEntry(entPhysicalEntry_t
*phyStatic
,
289 char *entPhysicalDescr
,
290 oid
*entPhysicalVendorType
,
291 int entPhysicalVendorTypeSize
,
292 int entPhysicalContainedIn
,
293 int entPhysicalClass
,
294 int entPhysicalParentRelPos
,
295 char *entPhysicalName
,
296 char *entPhysicalHardwareRev
,
297 char *entPhysicalFirmwareRev
,
298 char *entPhysicalSoftwareRev
,
299 char *entPhysicalSerialNum
,
300 char *entPhysicalMfgName
,
301 char *entPhysicalModelName
,
302 char *entPhysicalAlias
,
303 char *entPhysicalAssetID
,
304 int entPhysicalIsFRU
)
306 phyStatic
->entPhysicalDescr
= entPhysicalDescr
;
307 phyStatic
->entPhysicalVendorType
= entPhysicalVendorType
;
308 phyStatic
->entPhysicalVendorTypeSize
= entPhysicalVendorTypeSize
;
309 phyStatic
->entPhysicalContainedIn
= entPhysicalContainedIn
;
310 phyStatic
->entPhysicalClass
= entPhysicalClass
;
311 phyStatic
->entPhysicalParentRelPos
= entPhysicalParentRelPos
;
312 phyStatic
->entPhysicalName
= entPhysicalName
;
313 phyStatic
->entPhysicalHardwareRev
= entPhysicalHardwareRev
;
314 phyStatic
->entPhysicalFirmwareRev
= entPhysicalFirmwareRev
;
315 phyStatic
->entPhysicalSoftwareRev
= entPhysicalSoftwareRev
;
316 phyStatic
->entPhysicalSerialNum
= entPhysicalSerialNum
;
317 phyStatic
->entPhysicalMfgName
= entPhysicalMfgName
;
318 phyStatic
->entPhysicalModelName
= entPhysicalModelName
;
319 phyStatic
->entPhysicalAlias
= entPhysicalAlias
;
320 phyStatic
->entPhysicalAssetID
= entPhysicalAssetID
;
321 phyStatic
->entPhysicalIsFRU
= entPhysicalIsFRU
;
325 This function is just a convenience function to add many logical table
329 void FillentLogicalEntry(entLogicalEntry_t
*xLogicalStatic
,
330 char *entLogicalDescr
,
332 int entLogicalTypeSize
,
333 char *entLogicalCommunity
,
334 char *entLogicalTAddress
,
335 oid
*entLogicalTDomain
,
336 int entLogicalTDomainSize
,
337 char *entLogicalContextEngineId
,
338 char *entLogicalContextName
)
340 xLogicalStatic
->entLogicalDescr
= entLogicalDescr
;
341 xLogicalStatic
->entLogicalType
= entLogicalType
;
342 xLogicalStatic
->entLogicalTypeSize
= entLogicalTypeSize
;
343 xLogicalStatic
->entLogicalCommunity
= entLogicalCommunity
;
344 xLogicalStatic
->entLogicalTAddress
= entLogicalTAddress
;
345 xLogicalStatic
->entLogicalTDomain
= entLogicalTDomain
;
346 xLogicalStatic
->entLogicalTDomainSize
= entLogicalTDomainSize
;
347 xLogicalStatic
->entLogicalContextEngineId
= entLogicalContextEngineId
;
348 xLogicalStatic
->entLogicalContextName
= entLogicalContextName
;
352 void printTableIndex()
355 printf("\n The physical indexes allocated are, \n");
357 printf("%d,", physicalIndex
[k
]);
359 printf("\n The logical indexes allocated are, \n");
361 printf("%d,", logicalIndex
[m
]);