1 28 29 package ist.coach.coachEmfServicesComponents.SnmpAdapterProviderComposition; 30 31 import org.opennms.protocols.snmp.*; 33 34 import ist.coach.coachEmfCommon.Utils; 35 import ist.coach.coachEmfCommon.ExceptionMessages; 36 import ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError; 37 import ist.coach.coachEmfCommon.DataTypeImpl; 38 import ist.coach.coachEmfServices.SnmpAdapter.DataType; 39 import ist.coach.coachEmfServicesComponents.SnmpAdapterProviderPackage.trap_targetConnection; 40 42 import org.omg.CORBA.Any ; 43 49 public class connectorSegImpl 50 extends ist.coach.coachEmfServicesComponents.SnmpAdapterProviderComposition.connectorSeg 51 { 52 60 private org.omg.CORBA.ORB orb; 61 67 public connectorSegImpl() 68 { 69 orb = org.objectweb.ccm.CORBA.TheORB.getORB(); 70 } 71 72 78 81 public ist.coach.coachEmfServices.SnmpAdapter.DataType[] 82 getSnmpTable(String tableStart, String host, int port, String community) 83 throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError 84 { 85 89 90 SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, tableStart); 91 92 snmpConverter.snmpWalk(); 93 94 if (snmpConverter.agentResponded() == false) { 95 96 System.err.println("Agent did not respond!"); 97 throw new SnmpApplicationError(ExceptionMessages.agent_response_error); 98 } 99 100 101 DataTypeImpl [] snmpTable = new DataTypeImpl[snmpConverter.resultSet.size()]; 102 103 for (int i = 0; i < snmpConverter.resultSet.size(); i++) { 104 105 SnmpVarBind vb = (SnmpVarBind)snmpConverter.resultSet.get(i); 106 Any value = orb.create_any(); 107 value = SnmpAdapterProviderImpl.convertSnmpSyntaxToAny(vb.getValue()); 108 if (value == null) { 109 System.err.println("SnmpAdapter>Could not encapsulate SNMP attribute value into a CORBA Any"); 110 throw new SnmpApplicationError(ExceptionMessages.agent_create_error); 111 } 112 else { 113 snmpTable[i] = new DataTypeImpl(vb.getName().toString(), value, vb.getValue().typeId()); 114 115 } 116 } 117 118 return snmpTable; 119 } 120 121 124 public ist.coach.coachEmfServices.SnmpAdapter.DataType 125 getNext(String identifier, String host, int port, String community) 126 throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError 127 { 128 132 SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null); 133 134 snmpConverter.snmpGetNext(new SnmpObjectId(identifier)); 135 136 if (snmpConverter.agentResponded() == false) { 137 138 System.err.println("Agent did not respond!"); 139 throw new SnmpApplicationError(ExceptionMessages.agent_response_error); 140 } 141 142 if (snmpConverter.resultSet.size() == 0) { 143 144 System.err.println("Could not retrieve attribute with oid " + identifier); 145 throw new SnmpApplicationError(ExceptionMessages.agent_get_error); 146 } 147 148 Any value = this.orb.create_any(); 149 SnmpVarBind vb = (SnmpVarBind)snmpConverter.resultSet.elementAt(0); 150 String oid = vb.getName().toString(); 151 value = SnmpAdapterProviderImpl.convertSnmpSyntaxToAny(vb.getValue()); 152 153 if (value == null) { 154 System.err.println("Could not retrieve attribute with oid " + identifier); 155 throw new SnmpApplicationError(ExceptionMessages.agent_get_error); 156 } 157 158 DataTypeImpl result = new DataTypeImpl(oid, value, vb.getValue().typeId()); 159 160 return result; 161 162 } 163 164 167 public ist.coach.coachEmfServices.SnmpAdapter.DataType 168 get(String identifier, String host, int port, String community) 169 throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError 170 { 171 SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null); 177 178 SnmpVarBind [] vblist = new SnmpVarBind[1]; 179 vblist[0] = new SnmpVarBind(new SnmpObjectId(identifier)); 180 181 snmpConverter.snmpGet(vblist); 182 183 if (snmpConverter.agentResponded() == false) { 184 185 System.err.println("Agent did not respond!"); 186 throw new SnmpApplicationError(ExceptionMessages.agent_response_error); 187 } 188 189 if (snmpConverter.resultSet.size() == 0) { 190 191 System.err.println("Could not retrieve attribute with oid " + identifier); 192 throw new SnmpApplicationError(ExceptionMessages.agent_get_error); 193 } 194 195 197 Any value = this.orb.create_any(); 198 SnmpVarBind vb = (SnmpVarBind)snmpConverter.resultSet.elementAt(0); 199 String oid = vb.getName().toString(); 200 value = SnmpAdapterProviderImpl.convertSnmpSyntaxToAny(vb.getValue()); 201 202 if (value == null) { 203 System.err.println("Could not retrieve attribute with oid " + identifier); 204 throw new SnmpApplicationError(ExceptionMessages.agent_get_error); 205 } 206 207 DataTypeImpl result = new DataTypeImpl(oid, value, vb.getValue().typeId()); 208 209 return result; 210 } 211 212 215 public ist.coach.coachEmfServices.SnmpAdapter.DataType[] 216 getBulk(String [] identifiers, String host, int port, String community) 217 throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError 218 { 219 SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null); 223 224 int numRequested = identifiers.length; 225 226 SnmpVarBind [] vblist = new SnmpVarBind[numRequested]; 227 228 for (int i = 0; i < numRequested; i++) 229 vblist[i] = new SnmpVarBind(new SnmpObjectId(identifiers[i])); 230 231 snmpConverter.snmpGet(vblist); 232 233 if (snmpConverter.agentResponded() == false) { 234 235 System.err.println("Agent did not respond!"); 236 throw new SnmpApplicationError(ExceptionMessages.agent_response_error); 237 } 238 239 if (snmpConverter.resultSet.size() == 0) { 240 System.err.println("Could not retrieve attributes with requested identifiers"); 241 throw new SnmpApplicationError(ExceptionMessages.agent_get_error); 242 } 243 244 DataTypeImpl [] result = new DataTypeImpl[snmpConverter.resultSet.size()]; 245 246 247 for (int i = 0; i < snmpConverter.resultSet.size(); i++) { 248 249 Any value = this.orb.create_any(); 250 SnmpVarBind vb = (SnmpVarBind)snmpConverter.resultSet.elementAt(i); 251 String oid = vb.getName().toString(); 252 value = SnmpAdapterProviderImpl.convertSnmpSyntaxToAny(vb.getValue()); 253 254 if (value == null) { 255 System.err.println("Could not encapsulate SNMP attribute value into a CORBA Any"); 256 throw new SnmpApplicationError(ExceptionMessages.agent_create_error); 257 } 258 else 259 result[i] = new DataTypeImpl(((SnmpVarBind)snmpConverter.resultSet.elementAt(i)).getName().toString(), value, vb.getValue().typeId()); 260 } 261 262 return result; 264 265 } 266 267 270 public void 271 set(ist.coach.coachEmfServices.SnmpAdapter.DataType data, String host, int port, String community) 272 throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError 273 { 274 SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null); 278 279 SnmpVarBind [] vblist = new SnmpVarBind[1]; 280 SnmpSyntax value = SnmpAdapterProviderImpl.convertAnyToSnmpSyntax(data.value, data.code); 281 if (value == null) { 282 System.err.println("Could not convert DataType to an SnmpSyntax"); 283 throw new SnmpApplicationError(ExceptionMessages.agent_create_error); 284 } 285 286 vblist[0] = new SnmpVarBind(new SnmpObjectId(data.identifier), value); 287 288 snmpConverter.snmpSet(vblist); 289 290 if (snmpConverter.agentResponded() == false) { 291 292 System.err.println("Agent did not respond!"); 293 throw new SnmpApplicationError(ExceptionMessages.agent_response_error); 294 } 295 296 if (snmpConverter.resultSet.size() == 0) { 297 298 System.err.println("Could not set attribute with oid " + data.identifier); 299 throw new SnmpApplicationError(ExceptionMessages.agent_set_error); 300 } 301 } 302 303 306 public void 307 setBulk(ist.coach.coachEmfServices.SnmpAdapter.DataType[] data, String host, int port, String community) 308 throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError 309 { 310 SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null); 314 int numRequested = data.length; 315 SnmpVarBind [] vblist = new SnmpVarBind[numRequested]; 317 318 for (int i = 0; i < numRequested; i++) { 319 321 SnmpSyntax value = SnmpAdapterProviderImpl.convertAnyToSnmpSyntax(data[i].value, data[i].code); 322 vblist[i] = new SnmpVarBind(new SnmpObjectId(data[i].identifier), value); 323 } 326 327 snmpConverter.snmpSet(vblist); 328 329 if (snmpConverter.agentResponded() == false) { 330 331 System.err.println("Agent did not respond!"); 332 throw new SnmpApplicationError(ExceptionMessages.agent_response_error); 333 } 334 335 if (snmpConverter.resultSet.size() == 0) { 336 System.err.println("setBulk>Could not set attributes"); 337 338 throw new SnmpApplicationError(ExceptionMessages.agent_get_error); 339 } 340 } 341 342 } 343 | Popular Tags |