1 28 29 package ist.coach.coachEmsMibComponents.LogicalInterfaceProviderComposition; 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.AttributeValueChangeType; 36 import intt.itu.itut_x780.AttributeValueType; 37 import intt.itu.itut_x780.SourceIndicatorType; 38 import intt.itu.itut_x780.OperationalStateTypeHelper; 39 import intt.itu.itut_x780.OperationalStateType; 40 41 import ist.coach.coachEmfCommon.Utils; 42 import ist.coach.coachEmfCommon.StateChangedEventImpl; 43 import ist.coach.coachEmfCommon.StateChangedEventImpl; 44 import ist.coach.coachEmfCommon.ObjectCreationImpl; 45 import ist.coach.coachEmfCommon.ObjectDeletionImpl; 46 import ist.coach.coachEmfCommon.ExceptionMessages; 47 import ist.coach.coachEmfCommon.CreateErrorInfoTypeImpl; 48 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl; 49 import ist.coach.coachEmfCommon.DataTypeImpl; 50 import ist.coach.coachEmfServices.SnmpAdapter.DataType; 51 import ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError; 52 53 import ist.coach.coachEmsMib.LogicalInterfaceValueType; 54 57 import ist.coach.coachEmsCommon.SnmpIdentifiers; 58 60 import org.omg.CosNaming.NameComponent ; 61 import org.omg.CORBA.TCKind ; 62 63 import org.opennms.protocols.snmp.SnmpSMI; 64 65 import java.util.Hashtable ; 66 67 73 public class mgmtSegImpl 74 extends ist.coach.coachEmsMibComponents.LogicalInterfaceProviderComposition.mgmtSeg 75 { 76 org.omg.CORBA.ORB orb = null; 82 88 public mgmtSegImpl() 89 { 90 orb = org.objectweb.ccm.CORBA.TheORB.getORB(); 91 } 92 93 99 102 public void 103 create(org.omg.CosNaming.NameComponent [] name, 104 String objectClass, 105 String [] packages, 106 short deletePolicy, 107 intt.itu.itut_x780.SourceIndicatorType sourceIndicator, 108 org.omg.CosNaming.NameComponent [] superior, 109 int ifIndex, 110 byte[] mgmtIpAddress, 111 int supportedSnmpVersions, 112 int snmpPort, 113 String ifDescr) 114 throws intt.itu.itut_x780.ApplicationError, 115 116 intt.itu.itut_x780.CreateError 117 { 118 ist.coach.coachEmfServices.SnmpAdapter.SnmpTrapDaemon config = null; 122 123 if ((config = get_context().get_connection_config()) == null) { 124 CreateErrorInfoTypeImpl errorCode = 125 new CreateErrorInfoTypeImpl(); 126 127 errorCode.error = new UIDType( 128 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 129 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 130 131 errorCode.details = new String (ExceptionMessages.components_connect_error); 132 throw new intt.itu.itut_x780.CreateError(errorCode); 133 } 134 135 if (LogicalInterfaceProviderImpl.elements.containsKey(Utils.name2string(name))) { 136 137 CreateErrorInfoTypeImpl errorCode = 138 new CreateErrorInfoTypeImpl(); 139 140 errorCode.error = new UIDType( 141 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 142 intt.itu.itut_x780.CreateErrorConst.duplicateName.value); 143 144 errorCode.details = new String (Utils.name2string(name) + 145 " object already exists."); 146 throw new intt.itu.itut_x780.CreateError(errorCode); 147 } 148 149 151 LogicalInterfaceDataStructure logicalInterfaceData = 152 new LogicalInterfaceDataStructure( 153 ifIndex, 154 name, 155 objectClass, 156 packages, 157 sourceIndicator, 158 deletePolicy, 159 new String (mgmtIpAddress), 160 snmpPort, 161 supportedSnmpVersions, 162 ifDescr); 163 164 synchronized(LogicalInterfaceProviderImpl.elements) { 165 LogicalInterfaceProviderImpl.elements.put(Utils.name2string(name), logicalInterfaceData); 166 } 167 169 try { 172 org.omg.CORBA.Any ifDescrAny = orb.create_any(); 173 org.omg.CORBA.OctetSeqHelper.insert(ifDescrAny, ifDescr.getBytes()); 175 176 config.registerValue(name, new String (mgmtIpAddress), ifDescrAny); 179 } 180 catch (ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError snmp_ex) { 181 182 System.err.println("Could not register LogicalInterface " + 183 Utils.name2string(name) + " to the SNMP Trap Service"); 184 System.err.println("Reason = " + snmp_ex.reason); 185 186 ApplicationErrorInfoTypeImpl error_code = new ApplicationErrorInfoTypeImpl(); 187 188 error_code.error = new UIDType( 189 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 190 intt.itu.itut_x780.ApplicationErrorConst.downstreamError.value); 191 192 error_code.details = snmp_ex.reason; 193 194 throw new ApplicationError(error_code); 195 } 196 catch(Exception e) { 197 System.err.println("LogicalInterfaceProvider Exception caught: " + e.getMessage()); 198 e.printStackTrace(); 199 } 200 201 org.omg.TimeBase.UtcT eventTime = new org.omg.TimeBase.UtcT (System.currentTimeMillis(), 202 0, (short) 0, (short) 0); 203 get_context().push_objectCreation(new ObjectCreationImpl(eventTime, 204 name, 205 objectClass, 206 LogicalInterfaceProviderImpl.getUniqueNotificationIdentifier(), 207 sourceIndicator, 209 new AttributeValueType[0])); 210 211 } 212 213 216 public void 217 notifyTrap(org.omg.CosNaming.NameComponent [] name, String community, int trapID, int trapType, ist.coach.coachEmfServices.SnmpAdapter.DataType[] trapData) 218 throws intt.itu.itut_x780.ApplicationError, 219 220 ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError 221 { 222 226 String key = Utils.name2string(name); 227 228 if (LogicalInterfaceProviderImpl.elements.containsKey(Utils.name2string(name)) == false) { 229 230 ApplicationErrorInfoTypeImpl errorCode = 231 new ApplicationErrorInfoTypeImpl(); 232 233 errorCode.error = new UIDType( 234 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 235 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 236 237 errorCode.details = new String ("object with name " + 238 key + " does not exists."); 239 240 242 throw new intt.itu.itut_x780.ApplicationError(errorCode); 243 } 244 245 LogicalInterfaceDataStructure data = 246 (LogicalInterfaceDataStructure) LogicalInterfaceProviderImpl.elements.get(key); 247 248 intt.itu.itut_x780.OperationalStateType newValue = null; 249 intt.itu.itut_x780.OperationalStateType oldValue = null; 250 251 if (trapType == LogicalInterfaceProviderImpl.COACH_LINK_UP) { 252 newValue = intt.itu.itut_x780.OperationalStateType.enabled; 253 oldValue = intt.itu.itut_x780.OperationalStateType.disabled; 254 } 255 else 256 if (trapType == LogicalInterfaceProviderImpl.COACH_LINK_DOWN) { 257 newValue = intt.itu.itut_x780.OperationalStateType.disabled; 258 oldValue = intt.itu.itut_x780.OperationalStateType.enabled; 259 } 260 else { 261 System.err.println("LogicalInterface_F down not know how to handle trap of type " + 262 trapType); 263 264 ApplicationErrorInfoTypeImpl error_code = 265 new ApplicationErrorInfoTypeImpl(); 266 267 error_code.error = new UIDType( 268 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 269 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 270 error_code.details = new String ("LogicalInterface_F does not know how to handle trap of type " + trapType + "."); 271 272 throw new ApplicationError(error_code); 273 } 274 275 long trapTime = 0; 276 boolean trapTimeFound = false; 277 278 for (int i = 0; i < trapData.length; i++) { 279 if (trapData[i].identifier.equals(SnmpIdentifiers.TIME_OID)) { 280 org.omg.CORBA.Any value = trapData[i].value; 282 283 if (value.type().kind().value() != TCKind._tk_longlong) { 284 285 ApplicationErrorInfoTypeImpl error_code = 286 new ApplicationErrorInfoTypeImpl(); 287 288 error_code.error = new UIDType( 289 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 290 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 291 292 293 error_code.details = new String ("Could not retrieve event time " + 294 "for trap. Object with Snmp Object Identifier " + SnmpIdentifiers.TIME_OID + 295 " is not of type long, as expected."); 296 297 299 throw new ApplicationError(error_code); 300 } 301 302 trapTime = value.extract_longlong(); 303 trapTimeFound = true; 304 break; 305 } 306 } 307 308 if (trapTimeFound == false) { 309 310 System.err.println("Trap Time could not be determined. No such VarBinding"); 311 312 ApplicationErrorInfoTypeImpl error_code = 313 new ApplicationErrorInfoTypeImpl(); 314 315 error_code.error = new UIDType( 316 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 317 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value); 318 319 error_code.details = new String ("Could not retrieve event time " + 320 "for trap."); 321 322 throw new ApplicationError(error_code); 323 } 324 325 org.omg.TimeBase.UtcT eventTime = new org.omg.TimeBase.UtcT(System.currentTimeMillis(), 327 0,(short) 0,(short) 0); 328 329 330 int notificationId = LogicalInterfaceProviderImpl.getUniqueNotificationIdentifier(); 332 333 String sourceClass = data.objectclass; 334 335 SourceIndicatorType sourceIndicator = SourceIndicatorType.unknown; 336 337 org.omg.CORBA.Any oldValue_any = orb.create_any(); 338 OperationalStateTypeHelper.insert(oldValue_any, oldValue); 339 340 org.omg.CORBA.Any newValue_any = orb.create_any(); 341 OperationalStateTypeHelper.insert(newValue_any, newValue); 342 343 AttributeValueChangeType [] changedValues = new AttributeValueChangeType[1]; 344 345 changedValues[0] = new AttributeValueChangeType( 346 "operationalState", 347 oldValue_any, 348 newValue_any); 349 350 StateChangedEventImpl stateChangedEvent = new StateChangedEventImpl( 351 eventTime, 352 name, 353 sourceClass, 354 notificationId, 355 sourceIndicator, 356 changedValues); 357 System.err.println("LogicalInterfaceProvider> Before pushing StateChange event with identifier " + 358 stateChangedEvent.notificationIdentifier + " for " + 359 Utils.name2string(stateChangedEvent.source) + " of objectclass " + 360 stateChangedEvent.sourceClass + " generated after SNMP agent " + 361 "has been up for " + stateChangedEvent.eventTime.time + 362 " caused by an action of type " + sourceIndicator + "."); 363 get_context().push_stateChange(stateChangedEvent); 364 365 } 366 367 370 public String 371 facade_name() 372 { 373 return get_main_segment().facade_name(); 377 } 378 379 } 380 | Popular Tags |