1 21 package ist.coach.coachEmsMibComponents; 22 import org.omg.CosNaming.NameComponent ; 23 24 import ist.coach.coachEmfCommon.Utils; 25 import ist.coach.coachEmfCommon.CreateController; 26 import ist.coach.coachEmfCommon.CreateBindingInfo; 27 import ist.coach.coachEmfCommon.DataTypeImpl; 28 import ist.coach.coachEmfCommon.ExceptionMessages; 29 import ist.coach.coachEmfCommon.CreateErrorInfoTypeImpl; 30 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl; 31 32 import ist.coach.coachEmfServices.SnmpAdapter.DataType; 33 import ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError; 34 35 36 import ist.coach.coachEmsMib.conditionalPackages.sysInfoSetPackageType; 37 import ist.coach.coachEmsMib.LogicalInterfaceFactory; 38 import ist.coach.coachEmsMib.LogicalInterfaceFactoryHelper; 39 import ist.coach.coachEmsMib.IpProtocolMonitorFactory; 40 import ist.coach.coachEmsMib.IpProtocolMonitorFactoryHelper; 41 42 import ist.coach.coachEmsMib.IpNodeFactory; 43 import ist.coach.coachEmsMib.IpNodeFactoryHelper; 44 45 import intt.itu.itut_x780.UIDType; 46 import intt.itu.itut_x780.CreateError; 47 import intt.itu.itut_x780.ApplicationError; 48 import intt.itu.itut_x780.ManagedObjectFactoryHelper; 49 import intt.itu.itut_x780.ManagedObjectFactory; 50 51 import intt.itu.itut_m3120.conditionalPackages.*; 52 53 54 import org.opennms.protocols.snmp.SnmpSMI; 55 56 57 60 public class IpNodeFactoryProviderMonolithicImpl 61 extends org.omg.CORBA.LocalObject 62 implements CCM_IpNodeFactoryProvider, 63 org.omg.Components.SessionComponent 64 { 65 73 private CCM_IpNodeFactoryProvider_Context the_context_; 74 75 intt.itu.itut_q816.ContainmentComponent c_admin = null; 76 intt.itu.itut_q816.Containment c_query = null; 77 79 private static final String FACTORY_CLASS = "IpNodeFactory"; 80 IpNodeMgmt facade = null; 81 82 ist.coach.coachEmfServices.SnmpAdapter.SnmpConnector connector = null; 83 84 private org.omg.CORBA.ORB orb = null; 85 86 private static final String SYS_CONTACT_OID = ".1.3.6.1.2.1.1.4.0"; 87 private static final String SYS_NAME_OID = ".1.3.6.1.2.1.1.5.0"; 88 private static final String SYS_LOCATION_OID = ".1.3.6.1.2.1.1.6.0"; 89 private static final String [] IP_GROUP_OIDS = { 90 91 IpProtocolMonitorProviderMonolithicImpl.IP_FWD_TYPE_OID, 92 IpProtocolMonitorProviderMonolithicImpl.IP_DEFAULT_TTL_OID, 93 IpProtocolMonitorProviderMonolithicImpl.IP_INRECEIVE_OID, 94 IpProtocolMonitorProviderMonolithicImpl.IP_INHDRERRORS_OID, 95 IpProtocolMonitorProviderMonolithicImpl.IP_INADDRERRORRS_OID, 96 IpProtocolMonitorProviderMonolithicImpl.IP_FWDDATAGRAMS_OID, 97 IpProtocolMonitorProviderMonolithicImpl.IP_INUNKNOWNPROTO_OID, 98 IpProtocolMonitorProviderMonolithicImpl.IP_INDISCARDS_OID, 99 IpProtocolMonitorProviderMonolithicImpl.IP_INDELIVERS_OID, 100 IpProtocolMonitorProviderMonolithicImpl.IP_OUTREQUESTS_OID, 101 IpProtocolMonitorProviderMonolithicImpl.IP_OUTDISCARDS_OID, 102 IpProtocolMonitorProviderMonolithicImpl.IP_NOROUTE_OID, 103 IpProtocolMonitorProviderMonolithicImpl.IP_REASMTIMEOUT_OID, 104 IpProtocolMonitorProviderMonolithicImpl.IP_REASMREQ_OID, 105 IpProtocolMonitorProviderMonolithicImpl.IP_REASMOK_OID, 106 IpProtocolMonitorProviderMonolithicImpl.IP_REASMFAIL_OID, 107 IpProtocolMonitorProviderMonolithicImpl.IP_FRAGOK_OID, 108 IpProtocolMonitorProviderMonolithicImpl.IP_FRAGFAIL_OID, 109 IpProtocolMonitorProviderMonolithicImpl.IP_FRAGCREATE_OID, 110 IpProtocolMonitorProviderMonolithicImpl.IP_ROUTING_DISCARDS_OID 111 }; 112 113 private static final String READ_COMMUNITY = "public"; 114 private static final String NO_SUCH_OBJECT = "No Such Object"; 115 private static final String NO_SUCH_INSTANCE = "No Such Instance"; 116 117 125 public 126 IpNodeFactoryProviderMonolithicImpl() 127 { 128 the_context_ = null; 129 } 130 136 private int [] getIfTableIndexes( 137 DataType [] ifTable, 138 int tableRows, 139 int[] indexRows) { 140 141 int numOfEntries = ifTable.length; 142 int numOfRows = numOfEntries/tableRows; 143 144 int [] indexes = new int[numOfRows]; 145 146 for (int i = 0; i < numOfRows; i++) { 147 148 for (int j = 0; j < indexRows.length; j++) { 149 150 int position = (indexRows[j] - 1)*numOfRows + i; 151 152 if (position >= numOfEntries) { 153 System.err.println("IpNodeFactory: getIfTableIndexes> " + 154 "Cannot determine table indexes!"); 155 return null; 156 } 157 158 indexes[i] = ifTable[position].value.extract_long(); 159 } 160 } 161 162 return indexes; 163 } 164 165 private String [] getIfTableIfDescrs( 166 DataType [] ifTable, 167 int tableRows, 168 int [] indexRows) { 169 170 int numOfEntries = ifTable.length; 171 int numOfRows = numOfEntries/tableRows; 172 173 String [] ifDescrs = new String [numOfRows]; 174 175 for (int i = 0; i < numOfRows; i++) { 176 177 for (int j = 0; j < indexRows.length; j++) { 178 179 int position = (indexRows[j] - 1)*numOfRows + i; 180 181 if (position >= numOfEntries) { 182 System.err.println("IpNodeFactory: getIfTableIfDescrs> " + 183 "Cannot determine interface descriptions!"); 184 return null; 185 } 186 ifDescrs[i] = new String ( 187 org.omg.CORBA.OctetSeqHelper.extract(ifTable[position].value)); 188 System.err.println("ifDescrs[" + i + "] = " + ifDescrs[i]); 189 } 192 } 193 return ifDescrs; 194 } 195 196 207 public CCM_IpNodeFactoryProvider_Context 208 getContext() 209 { 210 return the_context_; 211 } 212 227 public void 228 configuration_complete() 229 throws org.omg.Components.InvalidConfiguration 230 { 231 if ((facade = the_context_.get_connection_facade()) == null) 235 throw new org.omg.Components.InvalidConfiguration(); 236 237 if ((c_admin = the_context_.get_connection_containment_admin()) == null) 238 throw new org.omg.Components.InvalidConfiguration(); 239 240 if ((c_query = the_context_.get_connection_containment_query()) == null) 241 throw new org.omg.Components.InvalidConfiguration(); 242 243 intt.itu.itut_q816.FactoryFinderComponent factoryfinder_admin = 246 the_context_.get_connection_factoryfinder_admin(); 247 248 if ((connector = the_context_.get_connection_connector()) == null) 249 throw new org.omg.Components.InvalidConfiguration(); 250 251 org.omg.CORBA.Object myself_o; 252 IpNodeFactory myself = null; 253 254 try { 255 myself_o = ((org.omg.Components.SessionContext) the_context_).get_CCM_object(); 256 myself = IpNodeFactoryHelper.narrow(myself_o); 257 258 factoryfinder_admin.register(FACTORY_CLASS, myself); 259 } 260 catch(intt.itu.itut_x780.ApplicationError ex) { 261 throw new org.omg.Components.InvalidConfiguration(); 262 } 263 catch(Exception e) { 264 System.err.println("IpNodeFactory has problems retrieving CCM component"); 265 } 266 267 this.orb = org.objectweb.ccm.CORBA.TheORB.getORB(); 268 269 System.err.println("IpNodeFactoryProvider configuration completed..."); 270 271 } 272 288 public void 289 set_session_context(org.omg.Components.SessionContext context) 290 throws org.omg.Components.CCMException 291 { 292 the_context_ = (CCM_IpNodeFactoryProvider_Context)context; 293 } 294 304 public void 305 ccm_activate() 306 throws org.omg.Components.CCMException 307 { 308 } 312 322 public void 323 ccm_passivate() 324 throws org.omg.Components.CCMException 325 { 326 } 330 340 public void 341 ccm_remove() 342 throws org.omg.Components.CCMException 343 { 344 } 348 359 public org.omg.CosNaming.NameComponent [] 360 create( java.lang.String nameBinding, 361 org.omg.CosNaming.NameComponent [] superior, 362 java.lang.String reqID, 363 java.lang.String [] packageNameList, 364 java.lang.String domainName, 365 java.lang.String hostname, 366 byte[] managementIPAddress, 367 int supportedSnmpVersions, 368 intt.itu.itut_x780.AdministrativeStateType administrativeState, 369 java.lang.String userLabel, 370 java.lang.String vendorName, 371 java.lang.String version, 372 java.lang.String locationName, 373 int snmpPort, 374 java.lang.String sysName, 375 java.lang.String sysContact) 376 throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.CreateError 377 { 378 382 String nameBinding_str = "ist.coach.coachEmsMib.NameBindings." + 383 nameBinding; 384 385 387 CreateBindingInfo info = CreateController.checkNameBinding(nameBinding_str); 388 389 String objectKind = info.objectKind; 390 short deletePolicy = info.deletePolicy; 391 392 if (! c_query.exists(superior)) { 394 ApplicationErrorInfoTypeImpl error_code = new ApplicationErrorInfoTypeImpl(); 395 error_code.error = new UIDType( 396 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 397 intt.itu.itut_x780.ApplicationErrorConst.objectNotFound.value); 398 399 error_code.details = Utils.name2string(superior) + 400 ExceptionMessages.parent_object_error; 401 402 throw new ApplicationError(error_code); 403 } 404 405 String allocatedId = reqID; 407 if (reqID == null || reqID.length() == 0) { 408 409 org.omg.CosNaming.NameComponent [][] siblings = 410 c_query.getContained(superior); 411 412 allocatedId = CreateController.autoCreateId(siblings); 413 } 414 415 org.omg.CosNaming.NameComponent [] name = CreateController.createFullName( 417 superior, 418 allocatedId, 419 Utils.name2facade(facade.facade_name()), 420 objectKind); 421 422 String [] supportedConditionalPackages = packageNameList; 424 425 if (packageNameList.length == 0) { 426 427 System.err.println("No packages are specified." + 428 "Trying to determine supported packages..."); 429 430 if (vendorName.equalsIgnoreCase("Linux") || 431 vendorName.equalsIgnoreCase("RedHat Linux") || 432 vendorName.equalsIgnoreCase("RedHat")) { 433 434 System.err.println("IpNodeFactoryProvider>Found linux System..."); 435 436 System.err.println("supported packages:"); 437 System.err.println("\t" + sysInfoSetPackageType.value); 438 System.err.println("\t" + locationNamePackageType.value); 439 System.err.println("\t" + userLabelPackageType.value); 440 System.err.println("\t" + vendorNamePackageType.value); 441 System.err.println("\t" + versionPackageType.value); 442 443 supportedConditionalPackages = new String [5]; 444 445 supportedConditionalPackages[0] = sysInfoSetPackageType.value; 446 supportedConditionalPackages[1] = locationNamePackageType.value; 447 supportedConditionalPackages[2] = userLabelPackageType.value; 448 supportedConditionalPackages[3] = vendorNamePackageType.value; 449 supportedConditionalPackages[4] = versionPackageType.value; 450 } 451 } 452 else { 453 System.err.println("Factory will not determine supported conditional Packages," + 454 " because Manager already specified them."); 455 } 456 457 458 if (Utils.packageIsSupported(sysInfoSetPackageType.value, supportedConditionalPackages)) { 459 460 System.err.println("sysName: " + sysName); 461 462 org.omg.CORBA.Any sysNameValue = orb.create_any(); 463 org.omg.CORBA.OctetSeqHelper.insert(sysNameValue, sysName.getBytes()); 464 465 DataTypeImpl sysNameDataType = new DataTypeImpl(SYS_NAME_OID, 466 sysNameValue, SnmpSMI.SMI_STRING); 467 468 469 474 System.err.println("sysContact: " + sysContact); 475 org.omg.CORBA.Any sysContactValue = orb.create_any(); 476 org.omg.CORBA.OctetSeqHelper.insert(sysContactValue, sysName.getBytes()); 477 478 DataTypeImpl sysContactDataType = new DataTypeImpl(SYS_CONTACT_OID, 479 sysNameValue, SnmpSMI.SMI_STRING); 480 485 DataTypeImpl [] sysData = {sysNameDataType, sysContactDataType}; 486 487 try { 488 connector.setBulk( 489 sysData, 490 new String (managementIPAddress), 491 snmpPort, 492 "private"); 493 } 494 catch (SnmpApplicationError e) { 495 496 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 497 error_code.error = new UIDType( 498 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 499 intt.itu.itut_x780.CreateErrorConst.unsupportedPackages.value); 500 501 error_code.details = e.reason; 502 503 throw new CreateError(error_code); 504 } 505 catch(Exception e) { 506 System.err.println("IpNodeFactory> Exception caught:" + e.getMessage()); 507 e.printStackTrace(System.err); 508 } 509 } 510 511 if (Utils.packageIsSupported(locationNamePackageType.value, supportedConditionalPackages)) { 512 513 org.omg.CORBA.Any sysLocationValue = orb.create_any(); 514 515 org.omg.CORBA.OctetSeqHelper.insert(sysLocationValue, locationName.getBytes()); 516 517 DataTypeImpl sysLocationDataType = new DataTypeImpl(SYS_LOCATION_OID, 520 sysLocationValue, SnmpSMI.SMI_STRING); 521 522 try { 523 connector.set( 524 sysLocationDataType, 525 new String (managementIPAddress), 526 snmpPort, 527 "private"); 528 } 529 catch (SnmpApplicationError e) { 530 531 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 532 error_code.error = new UIDType( 533 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 534 intt.itu.itut_x780.CreateErrorConst.unsupportedPackages.value); 535 536 error_code.details = e.reason; 537 throw new CreateError(error_code); 538 } 539 catch (Exception e) { 540 System.err.println("System exception caught:" + e.getMessage()); 541 e.printStackTrace(System.err); 542 } 543 544 } 545 546 System.err.println("IpNodeFactory> Before invoking the facade " + 547 Utils.name2facade(facade.facade_name()) + " to create " + Utils.name2string(name)); 548 549 facade.create(name, objectKind, supportedConditionalPackages, deletePolicy, 551 intt.itu.itut_x780.SourceIndicatorType.managementOperation, 552 domainName, 553 hostname, 554 managementIPAddress, 555 supportedSnmpVersions, 556 administrativeState, 557 userLabel, 558 vendorName, 559 version, 560 locationName, 561 (short)snmpPort, 562 sysName, 563 sysContact); 564 565 System.err.println("IpNodeFactory>Before registering to the containment service"); 566 c_admin.addName(name, superior); 567 System.err.println("IpNodeFactory>After registering to the containment service"); 568 569 572 DataType[] ifTable = new DataType[0]; 573 try { 574 ifTable = this.connector.getSnmpTable( 575 LogicalInterfaceProviderMonolithicImpl.IF_TABLE_OID, 576 new String (managementIPAddress), 577 snmpPort, 578 "public"); 579 } 580 catch(ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError snmp_ex) { 581 System.err.println("SnmpApplicationError caught> " + 582 snmp_ex.reason); 583 return name; 584 } 585 catch(Exception e) { 586 System.err.println("IpNodeFactory: create>Exception caught: " + e.getMessage()); 587 e.printStackTrace(System.err); 588 } 589 590 int[] indexRows = { 1 }; 591 int [] ifTableIndexes = getIfTableIndexes(ifTable, 592 18, indexRows); 593 594 int[] ifDescrIndexRows = { 2 }; 595 String [] ifTableIfDescrs = getIfTableIfDescrs(ifTable, 596 18, ifDescrIndexRows); 597 598 if (ifTableIndexes == null) { 599 System.err.println("Indexes could not be determined for" + 600 " Logical Interfaces. No Logical Interface objects will" + 601 " be created."); 602 } 603 else 604 if (ifTableIndexes.length == 0) 605 System.err.println("No LogicalInterface objects found"); 606 else 607 if (ifTableIfDescrs.length == 0) 608 System.err.println("Could not determine interface descriptions " + 609 "for Logical Interface Objects"); 610 else 611 if (ifTableIfDescrs.length != ifTableIndexes.length) 612 System.err.println("Mapping of ifDescr is not one-to-one with " + 613 "Logical Interface objects"); 614 else { 615 616 LogicalInterfaceFactory lif = 617 the_context_.get_connection_logicalInterfaceFactory(); 618 619 if (lif == null) 620 System.err.println("Factory is null..." + 621 " No LogicalInterface Objects will be created."); 622 else { 623 624 System.err.println("IpNodeFactoryProvider>******FOUND " + 625 ifTableIndexes.length + 626 " LogicalInterface Objects"); 627 628 String [] logicalInterfacePackages = new String [0]; 629 630 if (vendorName.equalsIgnoreCase("Linux") || 631 vendorName.equalsIgnoreCase("RedHat Linux") || 632 vendorName.equalsIgnoreCase("RedHat")) { 633 634 System.err.println("IpNodeFactoryProvider:create> Found linux System..." + 635 "No package is supported for LogicalInterface"); 636 } 637 638 for (int i = 0; i < ifTableIndexes.length; i++) { 639 lif.create( 640 "LogicalInterface_IpNode", 641 name, 642 ifTableIfDescrs[i], 643 logicalInterfacePackages, 644 ifTableIndexes[i], 645 managementIPAddress, 646 snmpPort, 647 supportedSnmpVersions, 648 ifTableIfDescrs[i]); 649 } 650 } 651 } 652 653 try { 655 656 DataType[] res = this.connector.getBulk( 657 IP_GROUP_OIDS, 658 new String (managementIPAddress), 659 snmpPort, 660 READ_COMMUNITY); 661 662 int count = 0; 663 664 for (int i = 0; i < res.length; i++) { 665 try { 666 if ( (res[i].value.extract_string().equalsIgnoreCase( 667 NO_SUCH_OBJECT)) || 668 (res[i].value.extract_string().equalsIgnoreCase( 669 NO_SUCH_INSTANCE)) ) 670 count ++; 671 } 672 catch (org.omg.CORBA.BAD_OPERATION badOp) { 673 } 677 } 678 679 if (count < res.length) { 680 682 IpProtocolMonitorFactory ipf = 683 the_context_.get_connection_ipProtocolMonitorFactory(); 684 685 if (ipf == null) { 686 System.err.println("IpProtocolMonitorFactory is null..." + 687 " No IpProtocolMonitor Object will be created!"); 688 } 689 else { 690 System.err.println("Invoking IpProtocolMonitorFactory..."); 691 692 String [] ipProtocolMonitorPackages = new String [0]; 693 694 if (vendorName.equalsIgnoreCase("Linux") || 695 vendorName.equalsIgnoreCase("RedHat Linux") || 696 vendorName.equalsIgnoreCase("RedHat")) { 697 698 } 701 702 ipf.create( 703 "IpProtocolMonitor_IpNode", 704 name, 705 "IpProtocol", 706 ipProtocolMonitorPackages, 707 managementIPAddress, 708 snmpPort, 709 supportedSnmpVersions 710 ); 711 712 } 713 } } 715 catch (SnmpApplicationError e) { 716 System.err.println("\nIpNodeFactory:SnmpApplicationError while trying to create IpProtocolMonitorFactory"); 717 System.err.println("Reason:" + e.reason); 718 } 720 System.err.println("IpNodeFactory>create returns for " + Utils.name2string(name)); 721 722 723 return name; 724 725 } 726 727 728 729 public org.omg.CosNaming.NameComponent [] 735 create_base(String nameBinding, 736 org.omg.CosNaming.NameComponent [] superior, 737 String reqId) 738 throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.CreateError { 739 740 return new NameComponent [0]; 741 } 742 } 743 | Popular Tags |