1 28 29 package ist.coach.coachEmsMibComponents.IpAddressDataProviderComposition; 30 31 import intt.itu.itut_x780.UIDType; 32 import intt.itu.itut_x780.CreateError; 33 import intt.itu.itut_x780.ApplicationError; 34 import intt.itu.itut_x780.SourceIndicatorType; 35 import intt.itu.itut_x780.AttributeValueType; 36 37 import ist.coach.coachEmfCommon.Utils; 38 39 import ist.coach.coachEmfCommon.ObjectDeletionImpl; 40 import ist.coach.coachEmfCommon.ExceptionMessages; 41 42 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl; 43 import ist.coach.coachEmfCommon.DataTypeImpl; 44 import ist.coach.coachEmfServices.SnmpAdapter.DataType; 45 import ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError; 46 47 import ist.coach.coachEmsMib.IpAddressDataValueType; 48 import ist.coach.coachEmsCommon.SnmpIdentifiers; 49 import ist.coach.coachEmsCommon.IpAddressDataValueTypeImpl; 50 51 import org.omg.CosNaming.NameComponent ; 52 import org.omg.CORBA.TCKind ; 53 import ist.coach.coachEmfServices.EmfBasicLog.*; 54 import org.opennms.protocols.snmp.SnmpSMI; 55 56 import java.util.Hashtable ; 57 63 public class IpAddressDataProviderImpl 64 extends ist.coach.coachEmsMibComponents.IpAddressDataProviderComposition.IpAddressDataProvider_impl 65 { 66 org.omg.CORBA.ORB orb = null; 72 private String _facade_name; 73 74 protected static Hashtable elements; 75 private static int notifId = 13000; 76 private BasicLog logSupport; 77 78 ist.coach.coachEmfServices.SnmpAdapter.SnmpConnector connector = null; 79 80 private static final String READ_COMMUNITY = SnmpIdentifiers.READ_COMMUNITY; 81 private static final String WRITE_COMMUNITY = SnmpIdentifiers.WRITE_COMMUNITY; 82 83 89 public IpAddressDataProviderImpl() 90 { 91 elements = new Hashtable (); 92 } 93 102 public void 103 configuration_complete() 104 throws org.omg.Components.InvalidConfiguration 105 { 106 110 if ((connector = get_context().get_connection_connector()) == null) 111 throw new org.omg.Components.InvalidConfiguration(); 112 orb = org.objectweb.ccm.CORBA.TheORB.getORB(); 113 if ((logSupport = get_context().get_connection_basic_log()) == null) 114 throw new org.omg.Components.InvalidConfiguration(); 115 116 System.err.println("IpAddressDataProvider configuration completed..."); 117 118 } 119 125 128 public String 129 facade_name() 130 { 131 return _facade_name; 135 } 136 137 140 public void 141 facade_name(String val) 142 { 143 if (val != null) 147 _facade_name = new String (val); 148 149 } 150 151 154 public byte[] 155 ipAdEntAddrGet(org.omg.CosNaming.NameComponent [] name) 156 throws intt.itu.itut_x780.ApplicationError 157 { 158 159 String key = Utils.name2string(name); 160 161 if (elements.containsKey(key) == false) { 162 ApplicationErrorInfoTypeImpl error_code = 163 new ApplicationErrorInfoTypeImpl(); 164 165 error_code.error = new UIDType( 166 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 167 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 168 169 error_code.details = new String ("object with name " + 170 key + " does not exist."); 171 172 throw new ApplicationError(error_code); 173 } 174 175 IpAddressDataStructure data = 176 (IpAddressDataStructure) elements.get(key); 177 178 return data.ipAdEntAddress.getBytes(); 179 } 180 181 184 public int 185 ipAdEntIfIndexGet(org.omg.CosNaming.NameComponent [] name) 186 throws intt.itu.itut_x780.ApplicationError 187 { 188 String key = Utils.name2string(name); 189 190 if (elements.containsKey(key) == false) { 191 ApplicationErrorInfoTypeImpl error_code = 192 new ApplicationErrorInfoTypeImpl(); 193 194 error_code.error = new UIDType( 195 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 196 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 197 198 error_code.details = new String ("object with name " + 199 key + " does not exist."); 200 201 throw new ApplicationError(error_code); 202 } 203 IpAddressDataStructure data = 204 (IpAddressDataStructure) elements.get(key); 205 206 String ipAdEntAddress = new String (data.ipAdEntAddress); 207 String ifIndexOid = SnmpIdentifiers.IP_ADDR_IFINDEX_OID + "." + ipAdEntAddress; 208 209 DataType ifIndexData = null; 210 211 try { 212 ifIndexData = connector.get( 213 ifIndexOid, 214 new String (data.getMgmtIpAddress()), 215 data.getSnmpPort(), 216 READ_COMMUNITY); 217 } 218 catch (SnmpApplicationError e) { 219 220 ApplicationErrorInfoTypeImpl error_code = 221 new ApplicationErrorInfoTypeImpl(); 222 223 error_code.error = new UIDType( 224 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 225 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 226 227 if (e.reason.equals(ExceptionMessages.agent_response_error)) 228 error_code.details = ExceptionMessages.agent_response_error; 229 else 230 error_code.details = new String ("Could not retrieve ipAdEntIfIndex " + 231 "for IpAddressData Object with name " + key + ":" + 232 "\n Object with Snmp Object Identifier " + ifIndexOid + 233 " does not exist."); 234 235 Utils.pretty_log(logSupport, Utils.name2string(name), objectClassGet(name), 236 (short) LogSeverity._Error, 237 "SNMP Error getting the ipAdEntIfIndex: " + e.reason); 238 239 throw new ApplicationError (error_code); 240 } 241 242 org.omg.CORBA.Any value = ifIndexData.value; 243 244 245 if (value.type().kind().value() != TCKind._tk_long) { 246 ApplicationErrorInfoTypeImpl error_code = 247 new ApplicationErrorInfoTypeImpl(); 248 249 error_code.error = new UIDType( 250 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 251 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 252 253 error_code.details = new String ("IpAddressData> Could not retrieve ipAdEntIfIndex " + 254 "for IpAddressData Object with name " + key + ":" + 255 " Object with Snmp Object Identifier " + ifIndexOid + 256 " is not of expected type."); 257 258 throw new ApplicationError (error_code); 259 260 } 261 262 int ipAdEntIfIndex = value.extract_long(); 263 return ipAdEntIfIndex; 264 } 265 266 269 public byte[] 270 ipAdEntNetMaskGet(org.omg.CosNaming.NameComponent [] name) 271 throws intt.itu.itut_x780.ApplicationError 272 { 273 String key = Utils.name2string(name); 274 275 if (elements.containsKey(key) == false) { 276 ApplicationErrorInfoTypeImpl error_code = 277 new ApplicationErrorInfoTypeImpl(); 278 279 error_code.error = new UIDType( 280 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 281 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 282 283 error_code.details = new String ("object with name " + 284 key + " does not exist."); 285 286 throw new ApplicationError(error_code); 287 } 288 IpAddressDataStructure data = 289 (IpAddressDataStructure) elements.get(key); 290 291 String ipAdEntAddress = new String (data.ipAdEntAddress); 292 String ipNetMaskOid = SnmpIdentifiers.IP_ADDR_NETMASK_OID + "." + ipAdEntAddress; 293 294 DataType ipNetMaskData = null; 295 296 try { 297 ipNetMaskData = connector.get( 298 ipNetMaskOid, 299 new String (data.getMgmtIpAddress()), 300 data.getSnmpPort(), 301 READ_COMMUNITY); 302 } 303 catch (SnmpApplicationError e) { 304 305 ApplicationErrorInfoTypeImpl error_code = 306 new ApplicationErrorInfoTypeImpl(); 307 308 error_code.error = new UIDType( 309 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 310 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 311 312 if (e.reason.equals(ExceptionMessages.agent_response_error)) 313 error_code.details = ExceptionMessages.agent_response_error; 314 else 315 error_code.details = new String ("Could not retrieve ipAdEntNetMask " + 316 "for IpAddressData Object with name " + key + ":" + 317 "\n Object with Snmp Object Identifier " + ipNetMaskOid + 318 " does not exist."); 319 320 Utils.pretty_log(logSupport, Utils.name2string(name), objectClassGet(name), 321 (short) LogSeverity._Error, 322 "SNMP Error getting the ipAdEntNetMask: " + e.reason); 323 324 throw new ApplicationError (error_code); 325 } 326 327 org.omg.CORBA.Any value = ipNetMaskData.value; 328 329 if (value.type().kind().value() != TCKind._tk_string) { 330 ApplicationErrorInfoTypeImpl error_code = 331 new ApplicationErrorInfoTypeImpl(); 332 333 error_code.error = new UIDType( 334 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 335 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 336 337 error_code.details = new String ("IpAddressData> Could not retrieve ipAdEntNetMask " + 338 "for IpAddressData Object with name " + key + ":" + 339 "\n Object with Snmp Object Identifier " + ipNetMaskOid + 340 " is not of expected type."); 341 342 throw new ApplicationError (error_code); 343 344 } 345 346 String ipNetMask = value.extract_string(); 347 return ipNetMask.getBytes(); 348 } 349 350 353 public int 354 ipAdEntBcastAddrGet(org.omg.CosNaming.NameComponent [] name) 355 throws intt.itu.itut_x780.ApplicationError 356 { 357 String key = Utils.name2string(name); 358 359 if (elements.containsKey(key) == false) { 360 ApplicationErrorInfoTypeImpl error_code = 361 new ApplicationErrorInfoTypeImpl(); 362 363 error_code.error = new UIDType( 364 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 365 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 366 367 error_code.details = new String ("object with name " + 368 key + " does not exist."); 369 370 throw new ApplicationError(error_code); 371 } 372 IpAddressDataStructure data = 373 (IpAddressDataStructure) elements.get(key); 374 375 String ipAdEntAddress = new String (data.ipAdEntAddress); 376 String ipAdEntBcastOid = SnmpIdentifiers.IP_ADDR_BCASTADDR_OID + "." + ipAdEntAddress; 377 378 DataType ipAdEntBcastData = null; 379 380 try { 381 ipAdEntBcastData = connector.get( 382 ipAdEntBcastOid, 383 new String (data.getMgmtIpAddress()), 384 data.getSnmpPort(), 385 READ_COMMUNITY); 386 } 387 catch (SnmpApplicationError e) { 388 389 ApplicationErrorInfoTypeImpl error_code = 390 new ApplicationErrorInfoTypeImpl(); 391 392 error_code.error = new UIDType( 393 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 394 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 395 396 if (e.reason.equals(ExceptionMessages.agent_response_error)) 397 error_code.details = ExceptionMessages.agent_response_error; 398 else 399 error_code.details = new String ("Could not retrieve ipAdEntBcastAddr " + 400 "for IpAddressData Object with name " + key + ":" + 401 "\n Object with Snmp Object Identifier " + ipAdEntBcastOid + 402 " does not exist."); 403 404 Utils.pretty_log(logSupport, Utils.name2string(name), objectClassGet(name), 405 (short) LogSeverity._Error, 406 "SNMP Error getting the ipAdEntBcastAddr: " + e.reason); 407 408 throw new ApplicationError (error_code); 409 } 410 411 org.omg.CORBA.Any value = ipAdEntBcastData.value; 412 413 414 if (value.type().kind().value() != TCKind._tk_long) { 415 ApplicationErrorInfoTypeImpl error_code = 416 new ApplicationErrorInfoTypeImpl(); 417 418 error_code.error = new UIDType( 419 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 420 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 421 422 error_code.details = new String ("IpAddressData> Could not retrieve ipAdEntBcastAddr " + 423 "for IpAddressData Object with name " + key + ":" + 424 "\n Object with Snmp Object Identifier " + ipAdEntBcastOid + 425 " is not of expected type."); 426 427 throw new ApplicationError (error_code); 428 429 } 430 431 int ipAdEntBcastAddr = value.extract_long(); 432 return ipAdEntBcastAddr; 433 } 434 435 438 public short 439 ipAdEntReasmMaxSizeGet(org.omg.CosNaming.NameComponent [] name) 440 throws intt.itu.itut_x780.ApplicationError 441 { 442 String key = Utils.name2string(name); 443 444 if (elements.containsKey(key) == false) { 445 ApplicationErrorInfoTypeImpl error_code = 446 new ApplicationErrorInfoTypeImpl(); 447 448 error_code.error = new UIDType( 449 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 450 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 451 452 error_code.details = new String ("object with name " + 453 key + " does not exist."); 454 455 throw new ApplicationError(error_code); 456 } 457 IpAddressDataStructure data = 458 (IpAddressDataStructure) elements.get(key); 459 460 String ipAdEntAddress = new String (data.ipAdEntAddress); 461 String ipAdEntReasmMaxSizeOid = SnmpIdentifiers.IP_ADDR_REASMMAX_OID + "." + ipAdEntAddress; 462 463 DataType ipAdEntReasmMaxSizeData = null; 464 465 try { 466 ipAdEntReasmMaxSizeData = connector.get( 467 ipAdEntReasmMaxSizeOid, 468 new String (data.getMgmtIpAddress()), 469 data.getSnmpPort(), 470 READ_COMMUNITY); 471 } 472 catch (SnmpApplicationError e) { 473 474 ApplicationErrorInfoTypeImpl error_code = 475 new ApplicationErrorInfoTypeImpl(); 476 477 error_code.error = new UIDType( 478 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 479 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 480 481 if (e.reason.equals(ExceptionMessages.agent_response_error)) 482 error_code.details = ExceptionMessages.agent_response_error; 483 else 484 error_code.details = new String ("Could not retrieve ipAdEntReasmMaxSize " + 485 "for IpAddressData Object with name " + key + ":" + 486 "\n Object with Snmp Object Identifier " + ipAdEntReasmMaxSizeOid + 487 " does not exist."); 488 Utils.pretty_log(logSupport, Utils.name2string(name), objectClassGet(name), 489 (short) LogSeverity._Error, 490 "SNMP Error getting the ipAdEntReasmMaxSize: " + e.reason); 491 492 throw new ApplicationError (error_code); 493 494 495 } 496 497 org.omg.CORBA.Any value = ipAdEntReasmMaxSizeData.value; 498 499 if (value.type().kind().value() != TCKind._tk_long) { 501 ApplicationErrorInfoTypeImpl error_code = 502 new ApplicationErrorInfoTypeImpl(); 503 504 error_code.error = new UIDType( 505 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 506 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 507 508 error_code.details = new String ("IpAddressData> Could not retrieve ipAdEntReasmMaxSize " + 509 "for IpAddressData Object with name " + key + ":" + 510 "\n Object with Snmp Object Identifier " + ipAdEntReasmMaxSizeOid + 511 " is not of expected type."); 512 513 return -1; 516 } 517 518 int ipAdEntReasmMaxSize = (int) value.extract_long(); 519 return (short) ipAdEntReasmMaxSize; 520 521 } 522 523 526 public org.omg.CosNaming.NameComponent [] 527 nameGet() 528 { 529 return Utils.string2name(_facade_name); 533 } 534 535 538 public String 539 objectClassGet(org.omg.CosNaming.NameComponent [] name) 540 throws intt.itu.itut_x780.ApplicationError 541 { 542 String key = Utils.name2string(name); 546 547 if (elements.containsKey(key) == false) { 548 ApplicationErrorInfoTypeImpl error_code = 549 new ApplicationErrorInfoTypeImpl(); 550 551 error_code.error = new UIDType( 552 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 553 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 554 555 error_code.details = new String ("object with name " + 556 key + " does not exist."); 557 558 throw new ApplicationError(error_code); 559 } 560 561 IpAddressDataStructure data = 562 (IpAddressDataStructure) elements.get(key); 563 564 return data.objectclass; 565 566 } 567 568 571 public intt.itu.itut_x780.ManagedObjectValueType 572 attributesGet(org.omg.CosNaming.NameComponent [] name, intt.itu.itut_x780.StringSetTypeHolder attributeNames) 573 throws intt.itu.itut_x780.ApplicationError 574 { 575 String key = Utils.name2string(name); 579 580 if (elements.containsKey(key) == false) { 581 ApplicationErrorInfoTypeImpl error_code = 582 new ApplicationErrorInfoTypeImpl(); 583 584 error_code.error = new UIDType( 585 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 586 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 587 588 error_code.details = new String ("object with name " + 589 key + " does not exist."); 590 591 throw new ApplicationError(error_code); 592 } 593 594 IpAddressDataStructure data = 595 (IpAddressDataStructure) elements.get(key); 596 597 IpAddressDataValueTypeImpl ipAddressDataValueType = 598 new IpAddressDataValueTypeImpl( 599 ipAdEntAddrGet(name), 600 ipAdEntIfIndexGet(name), 601 ipAdEntNetMaskGet(name), 602 ipAdEntBcastAddrGet(name), 603 ipAdEntReasmMaxSizeGet(name), 604 data.name, 605 data.objectclass, 606 data.packages, 607 data.sourceIndicator, 608 data.deletePolicy 609 ); 610 Utils.pretty_log(logSupport, Utils.name2string(name), objectClassGet(name), (short) LogSeverity._Info, 611 "attributesGet finished OK"); 612 613 return ipAddressDataValueType; 614 } 615 616 619 public String [] 620 packagesGet(org.omg.CosNaming.NameComponent [] name) 621 throws intt.itu.itut_x780.ApplicationError 622 { 623 String key = Utils.name2string(name); 627 628 if (elements.containsKey(key) == false) { 629 ApplicationErrorInfoTypeImpl error_code = 630 new ApplicationErrorInfoTypeImpl(); 631 632 error_code.error = new UIDType( 633 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 634 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 635 636 error_code.details = new String ("object with name " + 637 key + " does not exist."); 638 639 throw new ApplicationError(error_code); 640 } 641 642 IpAddressDataStructure data = 643 (IpAddressDataStructure) elements.get(key); 644 645 return data.packages; 646 } 647 648 651 public intt.itu.itut_x780.SourceIndicatorType 652 creationSourceGet(org.omg.CosNaming.NameComponent [] name) 653 throws intt.itu.itut_x780.ApplicationError 654 { 655 String key = Utils.name2string(name); 656 657 if (elements.containsKey(key) == false) { 658 ApplicationErrorInfoTypeImpl error_code = 659 new ApplicationErrorInfoTypeImpl(); 660 661 error_code.error = new UIDType( 662 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 663 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 664 665 error_code.details = new String ("object with name " + 666 key + " does not exist."); 667 668 throw new ApplicationError(error_code); 669 } 670 671 IpAddressDataStructure data = 672 (IpAddressDataStructure) elements.get(key); 673 674 return data.sourceIndicator; 675 } 676 677 680 public short 681 deletePolicyGet(org.omg.CosNaming.NameComponent [] name) 682 throws intt.itu.itut_x780.ApplicationError 683 { 684 String key = Utils.name2string(name); 685 686 if (elements.containsKey(key) == false) { 687 ApplicationErrorInfoTypeImpl error_code = 688 new ApplicationErrorInfoTypeImpl(); 689 690 error_code.error = new UIDType( 691 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 692 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 693 694 error_code.details = new String ("object with name " + 695 key + " does not exist."); 696 697 throw new ApplicationError(error_code); 698 } 699 700 IpAddressDataStructure data = 701 (IpAddressDataStructure) elements.get(key); 702 703 return data.deletePolicy; 704 } 705 706 709 public void 710 destroy(org.omg.CosNaming.NameComponent [] name) 711 throws intt.itu.itut_x780.ApplicationError, 712 713 intt.itu.itut_x780.DeleteError 714 { 715 716 717 if (!elements.containsKey(Utils.name2string(name))) { 718 719 ApplicationErrorInfoTypeImpl error_code = 720 new ApplicationErrorInfoTypeImpl(); 721 722 error_code.error = new UIDType( 723 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 724 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 725 726 error_code.details = new String ("object with name " + 727 Utils.name2string(name) + " does not exist."); 728 729 throw new ApplicationError(error_code); 730 731 } 732 IpAddressDataStructure ipAddressData = null; 733 synchronized(elements) { 734 ipAddressData = 735 (IpAddressDataStructure) elements.remove( 736 Utils.name2string(name)); 737 } 738 org.omg.TimeBase.UtcT eventTime = new org.omg.TimeBase.UtcT(System.currentTimeMillis(), 739 0, (short) 0, (short) 0); 740 get_context().push_objectDeletion(new ObjectDeletionImpl(eventTime, name, 741 ipAddressData.objectclass, 742 getUniqueNotificationIdentifier(), 743 ipAddressData.sourceIndicator, 744 new AttributeValueType[0])); 745 Utils.pretty_log(logSupport, Utils.name2string(name), 746 ipAddressData.objectclass, (short) LogSeverity._Info, 748 "successfully removed from management system"); 749 750 } 751 752 protected static int getUniqueNotificationIdentifier() { 753 754 notifId++; 755 return notifId; 756 } 757 758 } 759 | Popular Tags |