1 28 29 package ist.coach.coachEmsMibComponents.IpToMACAddressProviderComposition; 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.IpToMACAddressValueType; 48 import ist.coach.coachEmsCommon.SnmpIdentifiers; 49 import ist.coach.coachEmsCommon.IpToMACAddressValueTypeImpl; 50 import ist.coach.coachEmfServices.EmfBasicLog.*; 51 import org.omg.CosNaming.NameComponent ; 52 import org.omg.CORBA.TCKind ; 53 54 import org.opennms.protocols.snmp.SnmpSMI; 55 56 import java.util.Hashtable ; 57 58 64 public class IpToMACAddressProviderImpl 65 extends ist.coach.coachEmsMibComponents.IpToMACAddressProviderComposition.IpToMACAddressProvider_impl 66 { 67 org.omg.CORBA.ORB orb = null; 68 private String _facade_name; 69 70 protected static Hashtable elements; 71 private static int notifId = 15000; 72 private BasicLog logSupport; 73 74 ist.coach.coachEmfServices.SnmpAdapter.SnmpConnector connector = null; 75 76 private static final String READ_COMMUNITY = SnmpIdentifiers.READ_COMMUNITY; 77 private static final String WRITE_COMMUNITY = SnmpIdentifiers.WRITE_COMMUNITY; 78 84 90 public IpToMACAddressProviderImpl() 91 { 92 elements = new Hashtable (); 93 } 94 103 public void 104 configuration_complete() 105 throws org.omg.Components.InvalidConfiguration 106 { 107 111 if ((connector = get_context().get_connection_connector()) == null) 112 throw new org.omg.Components.InvalidConfiguration(); 113 if ((logSupport = get_context().get_connection_basic_log()) == null) 114 throw new org.omg.Components.InvalidConfiguration(); 115 116 orb = org.objectweb.ccm.CORBA.TheORB.getORB(); 117 118 System.err.println("IpToMACAddressProvider configuration completed..."); 119 120 } 121 127 130 public String 131 facade_name() 132 { 133 return _facade_name; 137 } 138 139 142 public void 143 facade_name(String val) 144 { 145 if (val != null) 149 _facade_name = new String (val); 150 } 151 152 155 public int 156 ipNetToMediaIfIndexGet(org.omg.CosNaming.NameComponent [] name) 157 throws intt.itu.itut_x780.ApplicationError 158 { 159 163 String key = Utils.name2string(name); 164 165 if (elements.containsKey(key) == false) { 166 ApplicationErrorInfoTypeImpl error_code = 167 new ApplicationErrorInfoTypeImpl(); 168 169 error_code.error = new UIDType( 170 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 171 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 172 173 error_code.details = new String ("object with name " + 174 key + " does not exist."); 175 176 throw new ApplicationError(error_code); 177 } 178 179 IpToMACAddressDataStructure data = 180 (IpToMACAddressDataStructure) elements.get(key); 181 182 183 return data.getipNetToMediaIfIndex(); 184 } 185 186 189 public void 190 ipNetToMediaIfIndexSet(org.omg.CosNaming.NameComponent [] name, int ipNetToMediaIfIndex) 191 throws intt.itu.itut_x780.ApplicationError, 192 193 ist.coach.coachEmsMib.NOipToMACAddressSetPackageException 194 { 195 } 199 200 203 public byte[] 204 ipNetToMediaPhysAddressGet(org.omg.CosNaming.NameComponent [] name) 205 throws intt.itu.itut_x780.ApplicationError 206 { 207 String key = Utils.name2string(name); 208 209 if (elements.containsKey(key) == false) { 210 ApplicationErrorInfoTypeImpl error_code = 211 new ApplicationErrorInfoTypeImpl(); 212 213 error_code.error = new UIDType( 214 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 215 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 216 217 error_code.details = new String ("object with name " + 218 key + " does not exist."); 219 220 throw new ApplicationError(error_code); 221 } 222 223 IpToMACAddressDataStructure data = 224 (IpToMACAddressDataStructure) elements.get(key); 225 226 227 String mediaIfIndex = String.valueOf(data.getipNetToMediaIfIndex()); 228 String mediaNetAddress = new String (data.getipNetToMediaNetAddress()); 229 230 String attributeOID = SnmpIdentifiers.IP_NETTOMEDIAPHYSADDRESS_OID + "." + 231 mediaIfIndex + "." + mediaNetAddress; 232 DataType attributeData = null; 233 234 try { 235 attributeData = connector.get( 236 attributeOID, 237 new String (data.getMgmtIpAddress()), 238 data.getSnmpPort(), 239 SnmpIdentifiers.READ_COMMUNITY); 240 } 241 catch (SnmpApplicationError e) { 242 243 ApplicationErrorInfoTypeImpl error_code = 244 new ApplicationErrorInfoTypeImpl(); 245 246 error_code.error = new UIDType( 247 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 248 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 249 250 if (e.reason.equals(ExceptionMessages.agent_response_error)) 251 error_code.details = ExceptionMessages.agent_response_error; 252 else 253 error_code.details = new String ("Could not retrieve attribute " + 254 "for IpToMACAddress Object with name " + key + ":" + 255 "\n Object with Snmp Object Identifier " + attributeOID + 256 " does not exist."); 257 258 Utils.pretty_log(logSupport, Utils.name2string(name), objectClassGet(name), 259 (short) LogSeverity._Error, 260 "SNMP Error getting ipNetToMediaPhysAddress: " + e.reason); 261 throw new ApplicationError (error_code); 262 } 263 264 org.omg.CORBA.Any value = attributeData.value; 265 266 267 if (value.type().kind().value() != org.omg.CORBA.OctetSeqHelper.type().kind().value()) { 268 ApplicationErrorInfoTypeImpl error_code = 269 new ApplicationErrorInfoTypeImpl(); 270 271 error_code.error = new UIDType( 272 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 273 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 274 275 error_code.details = new String ("IpToMACAddress> Could not retrieve attribute " + 276 "for IpToMACAddress Object with name " + key + ":" + 277 "\n Object with Snmp Object Identifier " + attributeOID + 278 " is not of expected type."); 279 280 throw new ApplicationError (error_code); 281 282 } 283 284 byte[] attribute_value = org.omg.CORBA.OctetSeqHelper.extract(value); 285 return attribute_value; 286 } 287 288 291 public void 292 ipNetToMediaPhysAddressSet(org.omg.CosNaming.NameComponent [] name, byte[] ipNetToMediaPhysAddress) 293 throws intt.itu.itut_x780.ApplicationError, 294 295 ist.coach.coachEmsMib.NOipToMACAddressSetPackageException 296 { 297 298 } 299 300 303 public byte[] 304 ipNetToMediaNetAddressGet(org.omg.CosNaming.NameComponent [] name) 305 throws intt.itu.itut_x780.ApplicationError 306 { 307 311 String key = Utils.name2string(name); 312 313 if (elements.containsKey(key) == false) { 314 ApplicationErrorInfoTypeImpl error_code = 315 new ApplicationErrorInfoTypeImpl(); 316 317 error_code.error = new UIDType( 318 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 319 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 320 321 error_code.details = new String ("object with name " + 322 key + " does not exist."); 323 324 throw new ApplicationError(error_code); 325 } 326 327 IpToMACAddressDataStructure data = 328 (IpToMACAddressDataStructure) elements.get(key); 329 330 331 return data.getipNetToMediaNetAddress(); 332 } 333 334 337 public void 338 ipNetToMediaNetAddressSet(org.omg.CosNaming.NameComponent [] name, byte[] ipNetToMediaNetAddress) 339 throws intt.itu.itut_x780.ApplicationError, 340 341 ist.coach.coachEmsMib.NOipToMACAddressSetPackageException 342 { 343 } 347 348 351 public int 352 ipNetToMediaTypeGet(org.omg.CosNaming.NameComponent [] name) 353 throws intt.itu.itut_x780.ApplicationError 354 { 355 356 String key = Utils.name2string(name); 357 358 if (elements.containsKey(key) == false) { 359 ApplicationErrorInfoTypeImpl error_code = 360 new ApplicationErrorInfoTypeImpl(); 361 362 error_code.error = new UIDType( 363 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 364 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 365 366 error_code.details = new String ("object with name " + 367 key + " does not exist."); 368 369 throw new ApplicationError(error_code); 370 } 371 372 IpToMACAddressDataStructure data = 373 (IpToMACAddressDataStructure) elements.get(key); 374 375 376 String mediaIfIndex = String.valueOf(data.getipNetToMediaIfIndex()); 377 String mediaNetAddress = new String (data.getipNetToMediaNetAddress()); 378 379 String attributeOID = SnmpIdentifiers.IP_NETTOMEDIATYPE_OID + "." + 380 mediaIfIndex + "." + mediaNetAddress; 381 DataType attributeData = null; 382 383 try { 384 attributeData = connector.get( 385 386 attributeOID, 387 new String (data.getMgmtIpAddress()), 388 data.getSnmpPort(), 389 SnmpIdentifiers.READ_COMMUNITY); 390 } 391 catch (SnmpApplicationError e) { 392 393 ApplicationErrorInfoTypeImpl error_code = 394 new ApplicationErrorInfoTypeImpl(); 395 396 error_code.error = new UIDType( 397 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 398 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 399 400 if (e.reason.equals(ExceptionMessages.agent_response_error)) 401 error_code.details = ExceptionMessages.agent_response_error; 402 else 403 error_code.details = new String ("Could not retrieve attribute " + 404 "for IpToMACAddress Object with name " + key + ":" + 405 "\n Object with Snmp Object Identifier " + attributeOID + 406 " does not exist."); 407 408 Utils.pretty_log(logSupport, Utils.name2string(name), objectClassGet(name), 409 (short) LogSeverity._Error, 410 "SNMP Error getting ipNetToMediaType: " + e.reason); 411 throw new ApplicationError (error_code); 412 } 413 414 org.omg.CORBA.Any value = attributeData.value; 415 416 417 if (value.type().kind().value() != TCKind._tk_long) { 418 ApplicationErrorInfoTypeImpl error_code = 419 new ApplicationErrorInfoTypeImpl(); 420 421 error_code.error = new UIDType( 422 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 423 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 424 425 error_code.details = new String ("IpToMACAddress> Could not retrieve attribute " + 426 "for IpToMACAddress Object with name " + key + ":" + 427 "\n Object with Snmp Object Identifier " + attributeOID + 428 " is not of expected type."); 429 435 throw new ApplicationError (error_code); 436 437 } 438 439 int attribute_value = value.extract_long(); 440 return attribute_value; 441 } 442 443 446 public void 447 ipNetToMediaTypeSet(org.omg.CosNaming.NameComponent [] name, int ipNetToMediaType) 448 throws intt.itu.itut_x780.ApplicationError, 449 450 ist.coach.coachEmsMib.NOipToMACAddressSetPackageException 451 { 452 } 456 457 460 public org.omg.CosNaming.NameComponent [] 461 nameGet() 462 { 463 return Utils.string2name(_facade_name); 464 } 465 466 469 public String 470 objectClassGet(org.omg.CosNaming.NameComponent [] name) 471 throws intt.itu.itut_x780.ApplicationError 472 { 473 String key = Utils.name2string(name); 477 478 if (elements.containsKey(key) == false) { 479 ApplicationErrorInfoTypeImpl error_code = 480 new ApplicationErrorInfoTypeImpl(); 481 482 error_code.error = new UIDType( 483 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 484 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 485 486 error_code.details = new String ("object with name " + 487 key + " does not exist."); 488 489 throw new ApplicationError(error_code); 490 } 491 492 IpToMACAddressDataStructure data = 493 (IpToMACAddressDataStructure) elements.get(key); 494 495 return data.getObjectClass(); 496 } 497 498 501 public intt.itu.itut_x780.ManagedObjectValueType 502 attributesGet(org.omg.CosNaming.NameComponent [] name, intt.itu.itut_x780.StringSetTypeHolder attributeNames) 503 throws intt.itu.itut_x780.ApplicationError 504 { 505 String key = Utils.name2string(name); 509 510 if (elements.containsKey(key) == false) { 511 ApplicationErrorInfoTypeImpl error_code = 512 new ApplicationErrorInfoTypeImpl(); 513 514 error_code.error = new UIDType( 515 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 516 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 517 518 error_code.details = new String ("object with name " + 519 key + " does not exist."); 520 521 throw new ApplicationError(error_code); 522 } 523 IpToMACAddressDataStructure data = 524 (IpToMACAddressDataStructure) elements.get(key); 525 526 IpToMACAddressValueTypeImpl ipToMACAddressValueType = new IpToMACAddressValueTypeImpl( 527 ipNetToMediaIfIndexGet(name), 528 ipNetToMediaPhysAddressGet(name), 529 ipNetToMediaNetAddressGet(name), 530 ipNetToMediaTypeGet(name), 531 data.getName(), 532 data.getObjectClass(), 533 data.getPackages(), 534 data.getSourceIndicator(), 535 data.getDeletePolicy() 536 ); 537 538 Utils.pretty_log(logSupport, Utils.name2string(name), objectClassGet(name), 539 (short) LogSeverity._Info, 540 "attributesGet finished successfully"); 541 return ipToMACAddressValueType; 542 } 543 544 547 public String [] 548 packagesGet(org.omg.CosNaming.NameComponent [] name) 549 throws intt.itu.itut_x780.ApplicationError 550 { 551 String key = Utils.name2string(name); 555 556 if (elements.containsKey(key) == false) { 557 ApplicationErrorInfoTypeImpl error_code = 558 new ApplicationErrorInfoTypeImpl(); 559 560 error_code.error = new UIDType( 561 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 562 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 563 564 error_code.details = new String ("object with name " + 565 key + " does not exist."); 566 567 throw new ApplicationError(error_code); 568 } 569 570 IpToMACAddressDataStructure data = 571 (IpToMACAddressDataStructure) elements.get(key); 572 573 return data.getPackages(); 574 } 575 576 579 public intt.itu.itut_x780.SourceIndicatorType 580 creationSourceGet(org.omg.CosNaming.NameComponent [] name) 581 throws intt.itu.itut_x780.ApplicationError 582 { 583 String key = Utils.name2string(name); 584 585 if (elements.containsKey(key) == false) { 586 ApplicationErrorInfoTypeImpl error_code = 587 new ApplicationErrorInfoTypeImpl(); 588 589 error_code.error = new UIDType( 590 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 591 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 592 593 error_code.details = new String ("object with name " + 594 key + " does not exist."); 595 596 throw new ApplicationError(error_code); 597 } 598 599 IpToMACAddressDataStructure data = 600 (IpToMACAddressDataStructure) elements.get(key); 601 602 return data.sourceIndicator; 603 } 604 605 608 public short 609 deletePolicyGet(org.omg.CosNaming.NameComponent [] name) 610 throws intt.itu.itut_x780.ApplicationError 611 { 612 String key = Utils.name2string(name); 613 614 if (elements.containsKey(key) == false) { 615 ApplicationErrorInfoTypeImpl error_code = 616 new ApplicationErrorInfoTypeImpl(); 617 618 error_code.error = new UIDType( 619 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 620 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 621 622 error_code.details = new String ("object with name " + 623 key + " does not exist."); 624 625 throw new ApplicationError(error_code); 626 } 627 628 IpToMACAddressDataStructure data = 629 (IpToMACAddressDataStructure) elements.get(key); 630 631 return data.deletePolicy; 632 } 633 634 637 public void 638 destroy(org.omg.CosNaming.NameComponent [] name) 639 throws intt.itu.itut_x780.ApplicationError, 640 641 intt.itu.itut_x780.DeleteError 642 { 643 if (!elements.containsKey(Utils.name2string(name))) { 644 645 ApplicationErrorInfoTypeImpl error_code = 646 new ApplicationErrorInfoTypeImpl(); 647 648 error_code.error = new UIDType( 649 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 650 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 651 652 error_code.details = new String ("object with name " + 653 Utils.name2string(name) + " does not exist."); 654 throw new ApplicationError(error_code); 655 656 } 657 658 IpToMACAddressDataStructure ipToMACAddress = null; 659 synchronized(elements) { 660 ipToMACAddress = 661 (IpToMACAddressDataStructure) elements.remove( 662 Utils.name2string(name)); 663 } 664 org.omg.TimeBase.UtcT eventTime = new org.omg.TimeBase.UtcT(System.currentTimeMillis(), 665 0, (short) 0, (short) 0); 666 get_context().push_objectDeletion(new ObjectDeletionImpl(eventTime, 667 name, 668 ipToMACAddress.getObjectClass(), 669 getUniqueNotificationIdentifier(), 670 ipToMACAddress.sourceIndicator, 671 new AttributeValueType[0])); 672 673 Utils.pretty_log(logSupport, Utils.name2string(name), 674 ipToMACAddress.objectclass, (short) LogSeverity._Info, 676 "successfully removed from management system"); 677 } 678 679 680 public static int getUniqueNotificationIdentifier() { 681 682 notifId++; 683 684 return (notifId); 685 } 686 687 } 688 | Popular Tags |