1 28 29 package ist.coach.coachEmsMibComponents.IpNodeProviderComposition; 30 31 import intt.itu.itut_x780.CreateError; 32 import intt.itu.itut_x780.UIDType; 33 34 import intt.itu.itut_x780.ApplicationError; 35 import intt.itu.itut_x780.ManagedObjectValueType; 36 import intt.itu.itut_x780.AttributeValueChangeType; 37 import intt.itu.itut_x780.AttributeValueType; 38 import intt.itu.itut_x780.SourceIndicatorType; 39 import intt.itu.itut_x780.OperationalStateTypeHelper; 40 41 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl; 42 43 import ist.coach.coachEmfCommon.CreateErrorInfoTypeImpl; 44 import ist.coach.coachEmfCommon.Utils; 45 import ist.coach.coachEmfCommon.ExceptionMessages; 46 import ist.coach.coachEmfCommon.ObjectCreationImpl; 47 import ist.coach.coachEmfCommon.StateChangedEventImpl; 48 49 import ist.coach.coachEmsCommon.SnmpIdentifiers; 50 import org.omg.CORBA.TCKind ; 51 57 public class mgmtSegImpl 58 extends ist.coach.coachEmsMibComponents.IpNodeProviderComposition.mgmtSeg 59 { 60 org.omg.CORBA.ORB orb = null; 66 72 public mgmtSegImpl() 73 { 74 orb = org.objectweb.ccm.CORBA.TheORB.getORB(); 75 } 76 77 83 86 87 public void 88 create( org.omg.CosNaming.NameComponent [] name, 89 String objectClass, 90 java.lang.String [] packages, 91 short deletePolicy, 92 intt.itu.itut_x780.SourceIndicatorType sourceIndicator, 93 java.lang.String domainName, 94 java.lang.String hostname, 95 byte[] managementIPAddress, 96 int supportedSnmpVersions, 97 intt.itu.itut_x780.AdministrativeStateType administrativeState, 98 java.lang.String userLabel, 99 java.lang.String vendorName, 100 java.lang.String version, 101 java.lang.String locationName, 102 int snmpPort, 103 java.lang.String sysName, 104 java.lang.String sysContact) 105 throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.CreateError 106 { 107 ist.coach.coachEmfServices.SnmpAdapter.SnmpTrapDaemon config = null; 111 if ((config = get_context().get_connection_config()) == null) { 112 CreateErrorInfoTypeImpl errorCode = 113 new CreateErrorInfoTypeImpl(); 114 115 errorCode.error = new UIDType( 116 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 117 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 118 119 errorCode.details = new String (ExceptionMessages.components_connect_error); 120 throw new intt.itu.itut_x780.CreateError(errorCode); 121 } 122 boolean sysInfoSetPackageIsSupported = false; 123 124 125 if (IpNodeProviderImpl.elements.containsKey(Utils.name2string(name))) { 126 127 CreateErrorInfoTypeImpl errorCode = 128 new CreateErrorInfoTypeImpl(); 129 130 errorCode.error = new UIDType( 131 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 132 intt.itu.itut_x780.CreateErrorConst.duplicateName.value); 133 134 errorCode.details = new String (Utils.name2string(name) + 135 " object already exists."); 136 throw new intt.itu.itut_x780.CreateError(errorCode); 137 138 } 139 140 IpNodeDataStructure ipNodeData = new IpNodeDataStructure( 141 domainName, 142 hostname, 143 managementIPAddress, 144 name, 145 packages, 146 supportedSnmpVersions, 147 administrativeState, 148 userLabel, 149 vendorName, 150 version, 151 locationName, 152 snmpPort, 153 sysName, 154 sysContact, 155 objectClass, 156 deletePolicy, 157 sourceIndicator, 158 intt.itu.itut_x780.OperationalStateType.enabled); 159 synchronized(IpNodeProviderImpl.elements) { 160 IpNodeProviderImpl.elements.put(Utils.name2string(name), ipNodeData); 161 } 162 164 String ipAddress = new String (); 165 if (managementIPAddress != null) 166 ipAddress = new String (managementIPAddress); 167 168 try { 169 config.registerIP(name, ipAddress); 170 } 171 catch( ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError snmp_ex) { 172 System.err.println("Could not register IpNode " + 173 Utils.name2string(name) + " to the SNMP Trap Service"); 174 System.err.println("Reason= " + snmp_ex.reason); 175 ApplicationErrorInfoTypeImpl error_code = new ApplicationErrorInfoTypeImpl(); 176 error_code.error = new UIDType( 177 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 178 intt.itu.itut_x780.ApplicationErrorConst.downstreamError.value); 179 180 error_code.details = snmp_ex.reason; 181 182 throw new ApplicationError(error_code); 183 } 184 185 org.omg.TimeBase.UtcT eventTime = new org.omg.TimeBase.UtcT(System.currentTimeMillis(), 186 0,(short) 0,(short) 0); 187 188 get_context().push_objectCreation(new ObjectCreationImpl(eventTime, name, 190 objectClass, 191 IpNodeProviderImpl.getUniqueNotificationIdentifier(), 192 sourceIndicator, 194 new AttributeValueType[0])); 195 196 } 198 199 202 public void 203 notifyTrap(org.omg.CosNaming.NameComponent [] name, 204 java.lang.String community, 205 int trapID, int trapType, 206 ist.coach.coachEmfServices.SnmpAdapter.DataType[] trapData) 207 throws intt.itu.itut_x780.ApplicationError, ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError 208 { 209 213 System.err.println("IpNode_F: Notify trap is called for " + 214 Utils.name2string(name)); 215 216 String key = Utils.name2string(name); 217 218 if (IpNodeProviderImpl.elements.containsKey(key) == false) { 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 error_code.details = new String ("object with name" + 228 key + " does not exist."); 229 230 throw new ApplicationError(error_code); 231 } 232 233 IpNodeDataStructure data = (IpNodeDataStructure) IpNodeProviderImpl.elements.get(key); 234 235 intt.itu.itut_x780.OperationalStateType oldValue = data.operationalState; 236 237 intt.itu.itut_x780.OperationalStateType newValue = null; 238 239 240 if (trapType == IpNodeProviderImpl.COLDSTART_TRAP) { 241 242 newValue = intt.itu.itut_x780.OperationalStateType.enabled; 243 244 } 245 else 246 if (trapType == IpNodeProviderImpl.NETSNMP_SHUTDOWN_TRAP) { 247 248 newValue = intt.itu.itut_x780.OperationalStateType.disabled; 249 250 } 251 else { 252 253 System.err.println("IpNode_F does not know how to handle trap of type " + 254 trapType); 255 256 ApplicationErrorInfoTypeImpl error_code = 257 new ApplicationErrorInfoTypeImpl(); 258 259 error_code.error = new UIDType( 260 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 261 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 262 263 error_code.details = new String ("IpNode_F does not know how to handle" + 264 " trap of type " + trapType + "."); 265 266 throw new ApplicationError(error_code); 267 268 } 269 270 if (newValue == oldValue) { 271 272 274 ApplicationErrorInfoTypeImpl error_code = 275 new ApplicationErrorInfoTypeImpl(); 276 277 error_code.error = new UIDType( 278 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 279 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 280 281 error_code.details = new String (" Cannot emmit StateChange Event when no" + 282 " state change has occured for IpNode with name " + 283 Utils.name2string(name)); 284 285 throw new ApplicationError(error_code); 286 } 287 288 data.operationalState = newValue; 289 290 long trapTime = 0; 291 boolean trapTimeFound = false; 292 293 for (int i = 0; i < trapData.length; i++) { 294 295 if (trapData[i].identifier.equals(SnmpIdentifiers.TIME_OID)) { 296 297 org.omg.CORBA.Any value = trapData[i].value; 298 299 if(value.type().kind().value() != TCKind._tk_longlong) { 300 301 ApplicationErrorInfoTypeImpl error_code = 302 new ApplicationErrorInfoTypeImpl(); 303 304 error_code.error = new UIDType( 305 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 306 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 307 308 error_code.details = new String ("Could not retrieve event time " + 309 " for trap. Object with Snmp Object Identifier " + SnmpIdentifiers.TIME_OID + 310 " is not of type long, as expected."); 311 312 throw new ApplicationError(error_code); 313 314 } 315 316 trapTime = value.extract_longlong(); 317 trapTimeFound = true; 318 break; 319 } 320 321 } 322 323 if (trapTimeFound == false) { 324 ApplicationErrorInfoTypeImpl error_code = 325 new ApplicationErrorInfoTypeImpl(); 326 327 error_code.error = new UIDType( 328 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 329 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 330 331 error_code.details = new String ("Could not retrieve event time " + 332 " for trap."); 333 334 throw new ApplicationError(error_code); 335 } 336 337 org.omg.TimeBase.UtcT eventTime = new org.omg.TimeBase.UtcT(System.currentTimeMillis(), 339 0,(short) 0,(short) 0); 340 341 int notificationId = IpNodeProviderImpl.getUniqueNotificationIdentifier(); 343 344 String sourceClass = data.objectclass; 345 346 SourceIndicatorType sourceIndicator = SourceIndicatorType.unknown; 347 348 org.omg.CORBA.Any oldValue_any = orb.create_any(); 349 OperationalStateTypeHelper.insert(oldValue_any, oldValue); 350 351 org.omg.CORBA.Any newValue_any = orb.create_any(); 352 OperationalStateTypeHelper.insert(newValue_any, newValue); 353 354 AttributeValueChangeType [] changedValues = new AttributeValueChangeType[1]; 355 changedValues[0] = new AttributeValueChangeType( 356 "operationalState", 357 oldValue_any, 358 newValue_any); 359 360 StateChangedEventImpl stateChangedEvent = new StateChangedEventImpl( 361 eventTime, 362 name, 363 sourceClass, 364 notificationId, 365 sourceIndicator, 366 changedValues); 368 369 System.err.println("IpNodeProvider>Before pushing StateChange event with identifier " + 370 stateChangedEvent.notificationIdentifier + " for " + 371 Utils.name2string(stateChangedEvent.source) + " of objectclass " + 372 stateChangedEvent.sourceClass + " generated after SNMP agent " + 373 "has been up for " + stateChangedEvent.eventTime.time + 374 " caused by an action of type " + sourceIndicator + "." ); 375 376 get_context().push_stateChange(stateChangedEvent); 377 378 } 379 380 381 384 public String 385 facade_name() 386 { 387 return get_main_segment().facade_name(); 391 } 392 393 } 394 | Popular Tags |