KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmsMibComponents > IpNodeFactoryProviderComposition > IpNodeFactoryProviderImpl


1 /*====================================================================
2 Tnis file was produced by the OpenCCM ir3_jimpl generator.
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 USA
18 Initial developer(s): Philippe Merle, Mathieu Vadet.
19 Contributor(s): Sylvain Leblanc_______________________.
20 ====================================================================*/

21 package ist.coach.coachEmsMibComponents.IpNodeFactoryProviderComposition;
22
23 import org.omg.CosNaming.NameComponent JavaDoc;
24
25 import ist.coach.coachEmfCommon.Utils;
26 import ist.coach.coachEmfCommon.CreateController;
27 import ist.coach.coachEmfCommon.CreateBindingInfo;
28 import ist.coach.coachEmfCommon.DataTypeImpl;
29 import ist.coach.coachEmfCommon.ExceptionMessages;
30 import ist.coach.coachEmfCommon.CreateErrorInfoTypeImpl;
31 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl;
32 import ist.coach.coachEmsCommon.SnmpUtils;
33
34 import ist.coach.coachEmfServices.SnmpAdapter.DataType;
35 import ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError;
36 import ist.coach.coachEmsCommon.SnmpIdentifiers;
37
38 import ist.coach.coachEmsMib.conditionalPackages.sysInfoSetPackageType;
39 import ist.coach.coachEmsMib.conditionalPackages.snmpEnableAuthenTrapPackageType;
40
41 import ist.coach.coachEmsMib.IpNodeFactory;
42 import ist.coach.coachEmsMib.IpAddressDataFactory;
43 import ist.coach.coachEmsMib.LogicalInterfaceFactory;
44 import ist.coach.coachEmsMib.IpProtocolMonitorFactory;
45 import ist.coach.coachEmsMib.SnmpProtocolMonitorFactory;
46 //import ist.coach.coachEmsMib.LogicalInterfaceFactoryHelper;
47
//import ist.coach.coachEmsMib.IpProtocolMonitorFactoryHelper;
48

49 import ist.coach.coachEmsMib.IpNodeFactoryHelper;
50
51 import intt.itu.itut_x780.UIDType;
52 import intt.itu.itut_x780.CreateError;
53 import intt.itu.itut_x780.ApplicationError;
54 import intt.itu.itut_x780.ManagedObjectFactoryHelper;
55 import intt.itu.itut_x780.ManagedObjectFactory;
56
57 import intt.itu.itut_m3120.conditionalPackages.*;
58
59 import org.opennms.protocols.snmp.SnmpSMI;
60
61 import ist.coach.coachEmsMibComponents.IpNodeMgmt;
62 import ist.coach.coachEmfServices.EmfBasicLog.*;
63
64 /**
65  ** Implementation skeleton class for the ::coachEmsMibComponents::IpNodeFactoryProvider component.
66  **/

67 public class IpNodeFactoryProviderImpl
68 extends ist.coach.coachEmsMibComponents.IpNodeFactoryProviderComposition.IpNodeFactoryProvider_impl
69 {
70     // ==================================================================
71
//
72
// Internal State.
73
//
74
// ===================================================================
75
/**
76      ** Context reference.
77      **/

78
79    /* Business logic **/
80     intt.itu.itut_q816.ContainmentComponent c_admin = null;
81     intt.itu.itut_q816.Containment c_query = null;
82     //ist.coach.coachEmsMib.LogicalInterfaceFactory logicalInterfaceFactory = null;
83

84     private static final String JavaDoc FACTORY_CLASS = "IpNodeFactory";
85     IpNodeMgmt facade = null;
86
87     ist.coach.coachEmfServices.SnmpAdapter.SnmpConnector connector = null;
88
89     private org.omg.CORBA.ORB JavaDoc orb = null;
90
91     private static final String JavaDoc SYS_CONTACT_OID = SnmpIdentifiers.SYS_CONTACT_OID;
92     private static final String JavaDoc SYS_NAME_OID = SnmpIdentifiers.SYS_NAME_OID;
93     private static final String JavaDoc SYS_LOCATION_OID = SnmpIdentifiers.SYS_LOCATION_OID;
94     private static final String JavaDoc [] IP_GROUP_OIDS = {
95
96                     SnmpIdentifiers.IP_FWD_TYPE_OID,
97                     SnmpIdentifiers.IP_DEFAULT_TTL_OID,
98                     SnmpIdentifiers.IP_INRECEIVE_OID,
99                     SnmpIdentifiers.IP_INHDRERRORS_OID,
100                     SnmpIdentifiers.IP_INADDRERRORRS_OID,
101                     SnmpIdentifiers.IP_FWDDATAGRAMS_OID,
102                     SnmpIdentifiers.IP_INUNKNOWNPROTO_OID,
103                     SnmpIdentifiers.IP_INDISCARDS_OID,
104                     SnmpIdentifiers.IP_INDELIVERS_OID,
105                     SnmpIdentifiers.IP_OUTREQUESTS_OID,
106                     SnmpIdentifiers.IP_OUTDISCARDS_OID,
107                     SnmpIdentifiers.IP_NOROUTE_OID,
108                     SnmpIdentifiers.IP_REASMTIMEOUT_OID,
109                     SnmpIdentifiers.IP_REASMREQ_OID,
110                     SnmpIdentifiers.IP_REASMOK_OID,
111                     SnmpIdentifiers.IP_REASMFAIL_OID,
112                     SnmpIdentifiers.IP_FRAGOK_OID,
113                     SnmpIdentifiers.IP_FRAGFAIL_OID,
114                     SnmpIdentifiers.IP_FRAGCREATE_OID,
115                     SnmpIdentifiers.IP_ROUTING_DISCARDS_OID
116     };
117     private static final String JavaDoc [] SNMP_GROUP_OIDS = {
118
119             SnmpIdentifiers.SNMP_INPKTS_OID,
120             SnmpIdentifiers.SNMP_OUTPKTS_OID,
121             SnmpIdentifiers.SNMP_INBADVERSIONS_OID,
122             SnmpIdentifiers.SNMP_INBADCOMMUNITYNAME_OID,
123             SnmpIdentifiers.SNMP_INBADCOMMUNITYUSES_OID,
124             SnmpIdentifiers.SNMP_INASNPARSEERRORS_OID,
125             SnmpIdentifiers.SNMP_INTOOBIG_OID,
126             SnmpIdentifiers.SNMP_INNOSUCHNAMES_OID,
127             SnmpIdentifiers.SNMP_INBADVALUES_OID,
128             SnmpIdentifiers.SNMP_INREADONLYS_OID,
129             SnmpIdentifiers.SNMP_INGENERRS_OID,
130             SnmpIdentifiers.SNMP_INTOTALREQVARS_OID,
131             SnmpIdentifiers.SNMP_INTOTALSETVARS_OID,
132             SnmpIdentifiers.SNMP_INGETREQS_OID,
133             SnmpIdentifiers.SNMP_INGETNEXTS_OID,
134             SnmpIdentifiers.SNMP_INSETREQS_OID,
135             SnmpIdentifiers.SNMP_INGETRESPONSES_OID,
136             SnmpIdentifiers.SNMP_INTRAPS_OID,
137             SnmpIdentifiers.SNMP_OUTTOOBIG_OID,
138             SnmpIdentifiers.SNMP_OUTNOSUCHNAMES_OID,
139             SnmpIdentifiers.SNMP_OUTBADVALUES_OID,
140             SnmpIdentifiers.SNMP_OUTGENERRS_OID,
141             SnmpIdentifiers.SNMP_OUTGETREQS_OID,
142             SnmpIdentifiers.SNMP_OUTGETNEXTS_OID,
143             SnmpIdentifiers.SNMP_OUTSETREQS_OID,
144             SnmpIdentifiers.SNMP_OUTGETRESPONSES_OID,
145             SnmpIdentifiers.SNMP_OUTTRAPS_OID,
146             SnmpIdentifiers.SNMP_ENABLEAUTHTRAPS_OID
147     };
148
149     private static final String JavaDoc READ_COMMUNITY = SnmpIdentifiers.READ_COMMUNITY;
150     private static final String JavaDoc NO_SUCH_OBJECT = "No Such Object";
151     private static final String JavaDoc NO_SUCH_INSTANCE = "No Such Instance";
152
153     private BasicLog logSupport;
154
155     // ==================================================================
156
//
157
// Constructor.
158
//
159
// ===================================================================
160
/**
161      ** The default constructor.
162      **/

163     public
164     IpNodeFactoryProviderImpl()
165     {
166     }
167
168     // ==================================================================
169
//
170
// Methods for the OMG IDL Components::EnterpriseComponent local interface.
171
//
172
// ==================================================================
173
//
174
//
175
// IDL:omg.org/Components/EnterpriseComponent/configuration_complete:1.0
176
//
177
/**
178      ** Completes the component configuration.
179      **
180      ** @throws org.omg.Components.InvalidConfiguration
181      ** Thrown if the configuration is invalid.
182      **/

183     public void
184     configuration_complete()
185     throws org.omg.Components.InvalidConfiguration
186     {
187         //
188
// DONE : implement !!!
189
//
190
if ((facade = get_context().get_connection_facade()) == null)
191             throw new org.omg.Components.InvalidConfiguration();
192
193         if ((c_admin = get_context().get_connection_containment_admin()) == null)
194             throw new org.omg.Components.InvalidConfiguration();
195
196         if ((c_query = get_context().get_connection_containment_query()) == null)
197             throw new org.omg.Components.InvalidConfiguration();
198
199             // If managers may create, then the factory must register to the
200
// factory finder service
201
intt.itu.itut_q816.FactoryFinderComponent factoryfinder_admin =
202             get_context().get_connection_factoryfinder_admin();
203
204         if ((connector = get_context().get_connection_connector()) == null)
205             throw new org.omg.Components.InvalidConfiguration();
206
207         if ((logSupport = get_context().get_connection_basic_log()) == null)
208             throw new org.omg.Components.InvalidConfiguration();
209
210          org.omg.CORBA.Object JavaDoc myself_o;
211          IpNodeFactory myself = null;
212
213         try {
214             myself_o = ((org.omg.Components.SessionContext) get_context()).get_CCM_object();
215             myself = IpNodeFactoryHelper.narrow(myself_o);
216
217             factoryfinder_admin.register(FACTORY_CLASS, myself);
218         }
219         catch(intt.itu.itut_x780.ApplicationError ex) {
220             throw new org.omg.Components.InvalidConfiguration();
221         }
222         catch(Exception JavaDoc e) {
223             System.err.println("IpNodeFactory has problems retrieving CCM component");
224         }
225
226         this.orb = org.objectweb.ccm.CORBA.TheORB.getORB();
227
228         System.err.println("IpNodeFactoryProvider configuration completed...");
229
230     }
231
232     // ==================================================================
233
//
234
// Public methods for the CCM_IpNodeFactoryProvider local interface.
235
//
236
// ==================================================================
237
//
238
// IDL:coach.ist/coachEmsMib/IpNodeFactory/create_ipNode:1.0
239
//
240
/**
241      ** Implementation of the ::coachEmsMib::IpNodeFactory::create operation.
242      **/

243     public org.omg.CosNaming.NameComponent JavaDoc[]
244     create( java.lang.String JavaDoc nameBinding,
245             org.omg.CosNaming.NameComponent JavaDoc[] superior,
246             java.lang.String JavaDoc reqID,
247             java.lang.String JavaDoc[] packageNameList,
248             java.lang.String JavaDoc domainName,
249             java.lang.String JavaDoc hostname,
250             byte[] managementIPAddress,
251             int supportedSnmpVersions,
252             intt.itu.itut_x780.AdministrativeStateType administrativeState,
253             java.lang.String JavaDoc userLabel,
254             java.lang.String JavaDoc vendorName,
255             java.lang.String JavaDoc version,
256             java.lang.String JavaDoc locationName,
257             int snmpPort,
258             java.lang.String JavaDoc sysName,
259             java.lang.String JavaDoc sysContact)
260     throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.CreateError
261     {
262         //
263
// DONE : implement
264
//
265

266         String JavaDoc nameBinding_str = "ist.coach.coachEmsMib.NameBindings." +
267                 nameBinding;
268
269 // String objectKind = CreateController.checkNameBinding(nameBinding_str);
270

271         CreateBindingInfo info = CreateController.checkNameBinding(nameBinding_str);
272
273         String JavaDoc objectKind = info.objectKind;
274         short deletePolicy = info.deletePolicy;
275
276         // Check if the parent exists
277
if (! c_query.exists(superior)) {
278             ApplicationErrorInfoTypeImpl error_code = new ApplicationErrorInfoTypeImpl();
279             error_code.error = new UIDType(
280                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
281                 intt.itu.itut_x780.ApplicationErrorConst.objectNotFound.value);
282
283             error_code.details = Utils.name2string(superior) +
284                             ExceptionMessages.parent_object_error;
285
286             throw new ApplicationError(error_code);
287         }
288
289         // The system must have the capability of auto-naming objects
290
String JavaDoc allocatedId = reqID;
291         if (reqID == null || reqID.length() == 0) {
292
293             org.omg.CosNaming.NameComponent JavaDoc[][] siblings =
294                 c_query.getContained(superior);
295
296                 allocatedId = CreateController.autoCreateId(siblings);
297         }
298
299         // Construct the name of the new object
300
org.omg.CosNaming.NameComponent JavaDoc[] name = CreateController.createFullName(
301                     superior,
302                     allocatedId,
303                     Utils.name2facade(facade.facade_name()),
304                     objectKind);
305
306         // Decide the conditional packages that are supported.
307
String JavaDoc [] supportedConditionalPackages = packageNameList;
308
309         Utils.pretty_log(logSupport, FACTORY_CLASS, "Factory", (short) LogSeverity._Info,
310           "proceed to create " + Utils.name2string(name));
311
312         if (packageNameList.length == 0) {
313
314             //System.err.println("No packages are specified." +
315
// "Trying to determine supported packages...");
316

317             if (vendorName.equalsIgnoreCase("Linux") ||
318                 vendorName.equalsIgnoreCase("RedHat Linux") ||
319                 vendorName.equalsIgnoreCase("RedHat")) {
320
321                 //System.err.println("IpNodeFactoryProvider>Found linux System...");
322
/*****
323                 System.err.println("supported packages:");
324                 System.err.println("\t" + sysInfoSetPackageType.value);
325                 System.err.println("\t" + locationNamePackageType.value);
326                 System.err.println("\t" + userLabelPackageType.value);
327                 System.err.println("\t" + vendorNamePackageType.value);
328                 System.err.println("\t" + versionPackageType.value);
329 *******/

330                 supportedConditionalPackages = new String JavaDoc[5];
331
332                 supportedConditionalPackages[0] = sysInfoSetPackageType.value;
333                 supportedConditionalPackages[1] = locationNamePackageType.value;
334                 supportedConditionalPackages[2] = userLabelPackageType.value;
335                 supportedConditionalPackages[3] = vendorNamePackageType.value;
336                 supportedConditionalPackages[4] = versionPackageType.value;
337             }
338         }
339         else {
340             System.err.println("Factory will not determine supported conditional Packages," +
341                 " because Manager already specified them.");
342         }
343
344
345         if (Utils.packageIsSupported(sysInfoSetPackageType.value, supportedConditionalPackages)) {
346
347             //System.err.println("sysName: " + sysName);
348

349             org.omg.CORBA.Any JavaDoc sysNameValue = orb.create_any();
350             org.omg.CORBA.OctetSeqHelper.insert(sysNameValue, sysName.getBytes());
351
352             DataTypeImpl sysNameDataType = new DataTypeImpl(SYS_NAME_OID,
353               sysNameValue, SnmpSMI.SMI_STRING);
354
355
356                //by digi
357
//sysNameValue.insert_string(sysName);
358
//DataTypeImpl sysNameDataType = new DataTypeImpl(SYS_NAME_OID,
359
// sysNameValue, SnmpSMI.SMI_STRING);
360

361             //System.err.println("sysContact: " + sysContact);
362
org.omg.CORBA.Any JavaDoc sysContactValue = orb.create_any();
363             org.omg.CORBA.OctetSeqHelper.insert(sysContactValue, sysContact.getBytes());//sysName.getBytes());
364

365             DataTypeImpl sysContactDataType = new DataTypeImpl(SYS_CONTACT_OID,
366                 sysContactValue, SnmpSMI.SMI_STRING);
367                 //by digi
368
//sysContactValue.insert_string(sysContact);
369
//DataTypeImpl sysContactDataType = new DataTypeImpl(SYS_CONTACT_OID,
370
//sysContactValue, SnmpSMI.SMI_STRING);
371

372             DataTypeImpl [] sysData = {sysNameDataType, sysContactDataType};
373
374             try {
375                 connector.setBulk(
376                     sysData,
377                     new String JavaDoc(managementIPAddress),
378                     snmpPort,
379                     SnmpIdentifiers.WRITE_COMMUNITY); //"private"
380
}
381             catch (SnmpApplicationError e) {
382
383                 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
384                 error_code.error = new UIDType(
385                     intt.itu.itut_x780.CreateErrorConst.moduleName.value,
386                     intt.itu.itut_x780.CreateErrorConst.unsupportedPackages.value);
387
388                     error_code.details = e.reason;
389
390                  throw new CreateError(error_code);
391             }
392             catch(Exception JavaDoc e) {
393               System.err.println("IpNodeFactory> Exception caught:" + e.getMessage());
394               e.printStackTrace(System.err);
395             }
396         }
397
398         if (Utils.packageIsSupported(locationNamePackageType.value, supportedConditionalPackages)) {
399
400             org.omg.CORBA.Any JavaDoc sysLocationValue = orb.create_any();
401
402             org.omg.CORBA.OctetSeqHelper.insert(sysLocationValue, locationName.getBytes());
403
404            // by digi
405
//sysLocationValue.insert_string(locationName);
406
DataTypeImpl sysLocationDataType = new DataTypeImpl(SYS_LOCATION_OID,
407                 sysLocationValue, SnmpSMI.SMI_STRING);
408
409             try {
410                 connector.set(
411                     sysLocationDataType,
412                     new String JavaDoc(managementIPAddress),
413                     snmpPort,
414                     "private");
415             }
416             catch (SnmpApplicationError e) {
417
418              CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
419              error_code.error = new UIDType(
420                  intt.itu.itut_x780.CreateErrorConst.moduleName.value,
421                  intt.itu.itut_x780.CreateErrorConst.unsupportedPackages.value);
422
423              error_code.details = e.reason;
424              throw new CreateError(error_code);
425             }
426             catch (Exception JavaDoc e) {
427               System.err.println("System exception caught:" + e.getMessage());
428               e.printStackTrace(System.err);
429             }
430
431         }
432
433         //System.err.println("IpNodeFactory> Before invoking the facade " +
434
// Utils.name2facade(facade.facade_name()) + " to create " + Utils.name2string(name));
435

436         facade.create(name, objectKind, supportedConditionalPackages, deletePolicy,
437                     intt.itu.itut_x780.SourceIndicatorType.managementOperation,
438                     domainName,
439                     hostname,
440                     managementIPAddress,
441                     supportedSnmpVersions,
442                     administrativeState,
443                     userLabel,
444                     vendorName,
445                     version,
446                     locationName,
447                     (short)snmpPort,
448                     sysName,
449                     sysContact);
450
451          //System.err.println("IpNodeFactory>Before registering to the containment service");
452
c_admin.addName(name, superior);
453         //System.err.println("IpNodeFactory>After registering to the containment service");
454

455         System.err.println("IpNodeFactory> Proceeding to perform SNMP updates...");
456         NameComponent JavaDoc[][] logical_interface_subordinates = new NameComponent JavaDoc[0][0];
457         DataType[] ifTable = new DataType[0];
458         try {
459             ifTable = this.connector.getSnmpTable(
460                 //LogicalInterfaceProviderImpl.IF_TABLE_OID,
461
SnmpIdentifiers.IF_TABLE_OID,
462                     new String JavaDoc(managementIPAddress),
463                     snmpPort,
464                     SnmpIdentifiers.READ_COMMUNITY); // "public"
465
}
466         catch(ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError snmp_ex) {
467             System.err.println("SnmpApplicationError caught> " +
468                         snmp_ex.reason);
469                 return name;
470         }
471         catch(Exception JavaDoc e) {
472           System.err.println("IpNodeFactory: create>Exception caught: " + e.getMessage());
473           e.printStackTrace(System.err);
474         }
475
476         int[] indexRows = { 1 };
477         int [] ifTableIndexes = SnmpUtils.getIntColumnData(ifTable,
478             18, indexRows);
479
480         int[] ifDescrIndexRows = { 2 };
481         String JavaDoc [] ifTableIfDescrs = SnmpUtils.getOctetColumnData(ifTable,
482             18, ifDescrIndexRows);
483
484         if (ifTableIndexes == null) {
485             System.err.println("Indexes could not be determined for" +
486                 " Logical Interfaces. No Logical Interface objects will" +
487                 " be created.");
488         }
489         else
490         if (ifTableIndexes.length == 0)
491             System.err.println("No LogicalInterface objects found");
492         else
493         if (ifTableIfDescrs.length == 0)
494             System.err.println("Could not determine interface descriptions " +
495                 "for Logical Interface Objects");
496         else
497         if (ifTableIfDescrs.length != ifTableIndexes.length)
498             System.err.println("Mapping of ifDescr is not one-to-one with " +
499                 "Logical Interface objects");
500         else {
501
502             LogicalInterfaceFactory lif =
503               get_context().get_connection_logicalInterfaceFactory();
504
505             if (lif == null)
506                 System.err.println("Factory is null..." +
507                     " No LogicalInterface Objects will be created.");
508             else {
509
510                 //System.err.println("IpNodeFactoryProvider>******FOUND " +
511
// ifTableIndexes.length +
512
// " LogicalInterface Objects");
513

514                 String JavaDoc [] logicalInterfacePackages = new String JavaDoc[0];
515
516                 if (vendorName.equalsIgnoreCase("Linux") ||
517                     vendorName.equalsIgnoreCase("RedHat Linux") ||
518                     vendorName.equalsIgnoreCase("RedHat")) {
519
520                     //System.err.println("IpNodeFactoryProvider:create> Found linux System..." +
521
// "No package is supported for LogicalInterface");
522
}
523                 logical_interface_subordinates = new NameComponent JavaDoc[ifTableIndexes.length][0];
524                 for (int i = 0; i < ifTableIndexes.length; i++) {
525
526                         logical_interface_subordinates[i] = lif.create(
527                                                               "LogicalInterface_IpNode",
528                                                               name,
529                                                               ifTableIfDescrs[i],
530                                                               logicalInterfacePackages,
531                                                               ifTableIndexes[i],
532                                                               managementIPAddress,
533                                                               snmpPort,
534                                                               supportedSnmpVersions,
535                                                               ifTableIfDescrs[i]);
536                 }
537             }
538         }
539
540         // IpProtocolMonitor creation
541
try {
542
543             DataType[] res = this.connector.getBulk(
544                     IP_GROUP_OIDS,
545                     new String JavaDoc(managementIPAddress),
546                     snmpPort,
547                     READ_COMMUNITY);
548
549             int count = 0;
550
551             for (int i = 0; i < res.length; i++) {
552                 try {
553                     if ( (res[i].value.extract_string().equalsIgnoreCase(
554                         NO_SUCH_OBJECT)) ||
555                         (res[i].value.extract_string().equalsIgnoreCase(
556                         NO_SUCH_INSTANCE)) )
557                     count ++;
558                 }
559                 catch (org.omg.CORBA.BAD_OPERATION JavaDoc badOp) {
560                     // If a string cannot be extracted, then the result
561
// will not be "No Such Object", or "No Such Instance"
562
// so no problem then! Catch this exception and ignore it.
563
}
564             }
565
566             if (count < res.length) {
567                 //System.err.println("IpProtocolMonitor must be created.");
568

569                 IpProtocolMonitorFactory ipf =
570                    get_context().get_connection_ipProtocolMonitorFactory();
571
572                 if (ipf == null) {
573                     System.err.println("IpProtocolMonitorFactory is null..." +
574                         " No IpProtocolMonitor Object will be created!");
575                 }
576                 else {
577                     //System.err.println("Invoking IpProtocolMonitorFactory...");
578

579                     String JavaDoc [] ipProtocolMonitorPackages = new String JavaDoc[0];
580
581                     if (vendorName.equalsIgnoreCase("Linux") ||
582                         vendorName.equalsIgnoreCase("RedHat Linux") ||
583                         vendorName.equalsIgnoreCase("RedHat")) {
584
585                         //System.err.println("Found linux System..." +
586
// "No package is supported for IpProtocolMonitor");
587
}
588
589                     ipf.create(
590                         "IpProtocolMonitor_IpNode",
591                         name,
592                         "IpProtocol",
593                         ipProtocolMonitorPackages,
594                         managementIPAddress,
595                         snmpPort,
596                         supportedSnmpVersions
597                     );
598
599                 }
600             } // IpProtocolMonitor must be created
601
}
602         catch (SnmpApplicationError e) {
603             System.err.println("\nIpNodeFactory:SnmpApplicationError while trying to create IpProtocolMonitorFactory");
604             System.err.println("Reason:" + e.reason);
605
606             // Continue to create other objects, if possible...
607
}
608         //System.err.println("IpNodeFactory>create returns for " + Utils.name2string(name));
609

610               //IpAddressData creation
611
//
612
//FSET TESTS FOR IPADDTRESSDATA
613
//
614

615         DataType[] ipTable = new DataType[0];
616         try {
617             ipTable = this.connector.getSnmpTable(
618                     SnmpIdentifiers.IP_ADDR_TABLE_OID,
619                     new String JavaDoc(managementIPAddress),
620                     snmpPort,
621                     READ_COMMUNITY);
622         }
623         catch(ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError snmp_ex) {
624             System.err.println("SnmpApplicationError caught> " +
625                         snmp_ex.reason);
626                 return name;
627         }
628         catch(Exception JavaDoc e) {
629           System.err.println("IpNodeFactory: create>Exception caught: " + e.getMessage());
630           e.printStackTrace(System.err);
631         }
632 // System.err.println("IP Address Table Size = " + ipTable.length);
633

634         int[] ipAdEntAddrIndexRows = { 1 };
635         String JavaDoc [] ipAdEntAddresses = SnmpUtils.getStringColumnData(ipTable,
636             4, ipAdEntAddrIndexRows);
637 /***************************************
638         System.err.println("ipAdEntAddresses Table Size = " + ipAdEntAddresses.length);
639         for(int ip_index = 0; ip_index < ipAdEntAddresses.length; ip_index++) {
640             System.err.println("ipAdEntAddresses[" + ip_index + "] = " +
641                 ipAdEntAddresses[ip_index]);
642         }
643 ******************************************/

644         int[] ipAdEntIfIndexRows = { 2 };
645         int [] ipAdEntIfIndexes = SnmpUtils.getIntColumnData(ipTable,
646             4, ipAdEntIfIndexRows);
647
648     /********************
649         System.err.println("ipAdEntIfIndexRows Table Size = " + ipAdEntIfIndexRows.length);
650         for(int ip_index = 0; ip_index < ipAdEntIfIndexes.length; ip_index++) {
651             System.err.println("ipAdEntIfIndexes[" + ip_index + "] = " +
652                   ipAdEntIfIndexes[ip_index]);
653         }
654     ***********************/

655         if (ipAdEntAddresses == null) {
656             System.err.println("IpNodeFactory> Indexes could not be determined for" +
657                 " Ip Address Data. No IPAddressData objects will" +
658                 " be created.");
659         }
660         else
661         if (ipAdEntAddresses.length == 0)
662             System.err.println("IpNodeFactory> No IPAddressData objects found");
663         else
664         if (ipAdEntIfIndexes.length == 0)
665             System.err.println("IpNodeFactory> Could not determine interface index " +
666                 "for IpAddressData Objects");
667         else
668         if (ipAdEntIfIndexes.length != ipAdEntAddresses.length)
669             System.err.println("IpNodeFactory> Mapping of IpAddressData is not one-to-one with " +
670                 "Logical Interface objects");
671         else {
672         // System.err.println("IpNodeFactory> Proceeding to get ip_address_factory");
673
IpAddressDataFactory ip_address_factory =
674               get_context().get_connection_ipAddressDataFactory();
675
676             if (ip_address_factory == null)
677                 System.err.println("IpNodeFactory> IpAddressDataFactory can not be located..." +
678                     " No IpAddressData Objects will be created.");
679             else {
680
681             // System.err.println("IpNodeFactoryProvider>******FOUND " +
682
// ipAdEntAddresses.length +
683
// " IpAddressData Objects");
684

685                 int interface_index;
686                 for (int k = 0; k < ipAdEntAddresses.length; k++) {
687
688                   interface_index = -1;
689                   for (int l = 0; l < ifTableIndexes.length; l++) {
690                       if (ipAdEntIfIndexes[k] == ifTableIndexes[l]) {
691                           interface_index = l;
692                           break;
693                     }
694                   }
695                   if (interface_index < 0) {
696                     System.err.println("IpNodeFactoryProvider> IpAddressData can not be associated with " +
697                         " existing lofical interfaces..." + ipAdEntIfIndexes[k]);
698                     continue;
699
700                   }
701                   NameComponent JavaDoc[] superior_interface = logical_interface_subordinates[interface_index];
702
703                   ip_address_factory.create("IpAddressData_LogicalInterface",
704                                               superior_interface,
705                                               new String JavaDoc(),
706                                               new String JavaDoc[0],
707                                               ipAdEntAddresses[k].getBytes(),
708                                               managementIPAddress,
709                                               snmpPort,
710                                               supportedSnmpVersions
711                     );
712                 }
713             }
714           }
715
716           //proceed to create SnmpMonitor object
717
String JavaDoc[] snmpSupportedConditionalPackages = new String JavaDoc[0];
718           if (vendorName.equalsIgnoreCase("Linux") ||
719                         vendorName.equalsIgnoreCase("RedHat Linux") ||
720                         vendorName.equalsIgnoreCase("RedHat")) {
721
722             snmpSupportedConditionalPackages = new String JavaDoc[1];
723             snmpSupportedConditionalPackages[0] = snmpEnableAuthenTrapPackageType.value;
724           }
725           create_snmp_monitor(name, managementIPAddress, snmpPort, supportedSnmpVersions,
726                               snmpSupportedConditionalPackages);
727
728         Utils.pretty_log(logSupport, FACTORY_CLASS, "Factory", (short) LogSeverity._Info,
729           "successfully created " + Utils.name2string(name));
730         return name;
731
732     }
733
734     public void create_snmp_monitor(org.omg.CosNaming.NameComponent JavaDoc[] superior,
735                                       byte[] managementIPAddress,
736                                       int snmpPort,
737                                       int supportedSnmpVersions,
738                                       String JavaDoc[] supportedConditionalPackages) {
739
740         // SnmpMonitor creation
741
try {
742             //System.err.println("Create SNMP Monitor is called for parent " +
743
// Utils.name2string(superior) + "," + SNMP_GROUP_OIDS[0]);
744
DataType[] res = this.connector.getBulk(
745                     SNMP_GROUP_OIDS,
746                     new String JavaDoc(managementIPAddress),
747                     snmpPort,
748                     READ_COMMUNITY);
749
750             int count = 0;
751
752             for (int i = 0; i < res.length; i++) {
753                 try {
754                     if ( (res[i].value.extract_string().equalsIgnoreCase(
755                         NO_SUCH_OBJECT)) ||
756                         (res[i].value.extract_string().equalsIgnoreCase(
757                         NO_SUCH_INSTANCE)) )
758                     count ++;
759                 }
760                 catch (org.omg.CORBA.BAD_OPERATION JavaDoc badOp) {
761                     // If a string cannot be extracted, then the result
762
// will not be "No Such Object", or "No Such Instance"
763
// so no problem then! Catch this exception and ignore it.
764
}
765             }
766             //System.err.println("Res = " + res.length + " count = " + count);
767
//if (count < res.length) {
768
System.err.println("SnmpProtocolMonitor must be created.");
769
770                 SnmpProtocolMonitorFactory snmpf =
771                    get_context().get_connection_snmpProtocolMonitorFactory();
772
773                 if (snmpf == null) {
774                     System.err.println("SnmpProtocolMonitorFactory can not be found..." +
775                         " No SnmpProtocolMonitor Object will be created!");
776                 }
777                 else {
778                     System.err.println("IpNodeFactoryProvider>Invoking SnmpProtocolMonitorFactory...");
779
780                     snmpf.create(
781                         "SnmpProtocolMonitor_IpNode",
782                         superior,
783                         "SnmpProtocol",
784                         supportedConditionalPackages,
785                         managementIPAddress,
786                         snmpPort,
787                         supportedSnmpVersions
788                     );
789
790                 }
791             //if}
792
}
793         catch (SnmpApplicationError e) {
794             System.err.println("\nIpNodeFactory:SnmpApplicationError while trying to create SnmpProtocolMonitorFactory");
795             System.err.println("Reason:" + e.reason);
796         }
797         catch (ApplicationError appl_e) {
798             System.err.println("\nIpNodeFactory:ApplicationError while trying to create SnmpProtocolMonitorFactory");
799             System.err.println("Reason:" + appl_e.getMessage());
800         }
801         catch (CreateError create_e) {
802             System.err.println("\nIpNodeFactory:CreateError while trying to create SnmpProtocolMonitorFactory");
803             System.err.println("Reason:" + create_e.getMessage());
804         }
805
806     }
807     /*** TEMP ******/
808     // ==================================================================
809
//
810
// Public methods for the CCM_ManagedObjectFactoryProvider local interface.
811
//
812
// ==================================================================
813
public org.omg.CosNaming.NameComponent JavaDoc[]
814     create_base(String JavaDoc nameBinding,
815                 org.omg.CosNaming.NameComponent JavaDoc[] superior,
816                 String JavaDoc reqId)
817     throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.CreateError {
818
819         return new NameComponent JavaDoc[0];
820     }
821 }
822
Popular Tags