1 11 12 13 package com.sun.jmx.snmp.daemon; 14 15 16 17 import java.util.Enumeration ; 20 import java.util.Vector ; 21 22 import com.sun.jmx.snmp.SnmpPdu; 25 import com.sun.jmx.snmp.SnmpVarBind; 26 import com.sun.jmx.snmp.SnmpOid; 27 import com.sun.jmx.snmp.SnmpValue; 28 import com.sun.jmx.snmp.SnmpDefinitions; 29 import com.sun.jmx.snmp.SnmpStatusException; 30 import com.sun.jmx.snmp.SnmpEngine; 31 import com.sun.jmx.snmp.agent.SnmpMibAgent; 34 import com.sun.jmx.snmp.agent.SnmpMibRequest; 35 import com.sun.jmx.snmp.ThreadContext; 36 import com.sun.jmx.snmp.daemon.SnmpAdaptorServer; 37 import com.sun.jmx.snmp.internal.SnmpIncomingRequest; 38 import com.sun.jmx.snmp.ThreadContext; 39 40 class SnmpSubBulkRequestHandler extends SnmpSubRequestHandler { 41 private SnmpAdaptorServer server = null; 42 43 47 protected SnmpSubBulkRequestHandler(SnmpEngine engine, 48 SnmpAdaptorServer server, 49 SnmpIncomingRequest incRequest, 50 SnmpMibAgent agent, 51 SnmpPdu req, 52 int nonRepeat, 53 int maxRepeat, 54 int R) { 55 super(engine, incRequest, agent, req); 56 init(server, req, nonRepeat, maxRepeat, R); 57 } 58 59 63 protected SnmpSubBulkRequestHandler(SnmpAdaptorServer server, 64 SnmpMibAgent agent, 65 SnmpPdu req, 66 int nonRepeat, 67 int maxRepeat, 68 int R) { 69 super(agent, req); 70 init(server, req, nonRepeat, maxRepeat, R); 71 } 72 73 public void run() { 74 75 size= varBind.size(); 76 77 try { 78 81 final ThreadContext oldContext = 82 ThreadContext.push("SnmpUserData",data); 83 try { 84 if (isTraceOn()) { 85 trace("run", "[" + Thread.currentThread() + 86 "]:getBulk operation on " + agent.getMibName()); 87 } 88 agent.getBulk(createMibRequest(varBind,version,data), 89 nonRepeat, maxRepeat); 90 } finally { 91 ThreadContext.restore(oldContext); 92 } 93 94 95 } catch(SnmpStatusException x) { 96 errorStatus = x.getStatus() ; 97 errorIndex= x.getErrorIndex(); 98 if (isDebugOn()) { 99 debug("run", "[" + Thread.currentThread() + 100 "]:an Snmp error occured during the operation"); 101 debug("run", x); 102 } 103 } 104 catch(Exception x) { 105 errorStatus = SnmpDefinitions.snmpRspGenErr ; 106 if (isDebugOn()) { 107 debug("run", "[" + Thread.currentThread() + 108 "]:a generic error occured during the operation"); 109 debug("run", x); 110 } 111 } 112 if (isTraceOn()) { 113 trace("run", "[" + Thread.currentThread() + 114 "]:operation completed"); 115 } 116 } 117 118 private void init(SnmpAdaptorServer server, 119 SnmpPdu req, 120 int nonRepeat, 121 int maxRepeat, 122 int R) { 123 this.server = server; 124 this.nonRepeat= nonRepeat; 125 this.maxRepeat= maxRepeat; 126 this.globalR= R; 127 128 final int max= translation.length; 129 final SnmpVarBind[] list= req.varBindList; 130 final NonSyncVector nonSyncVarBind = ((NonSyncVector)varBind); 131 for(int i=0; i < max; i++) { 132 translation[i]= i; 133 final SnmpVarBind newVarBind = 137 new SnmpVarBind(list[i].oid, list[i].value); 138 nonSyncVarBind.addNonSyncElement(newVarBind); 139 } 140 } 141 142 145 private SnmpVarBind findVarBind(SnmpVarBind element, 146 SnmpVarBind result) { 147 148 if (element == null) return null; 149 150 if (result.oid == null) { 151 return element; 152 } 153 154 if (element.value == SnmpVarBind.endOfMibView) return result; 155 156 if (result.value == SnmpVarBind.endOfMibView) return element; 157 158 final SnmpValue val = result.value; 159 160 int comp = element.oid.compareTo(result.oid); 161 if(isDebugOn()) { 162 trace("findVarBind","Comparing OID element : " + element.oid + 163 " with result : " + result.oid); 164 trace("findVarBind","Values element : " + element.value + 165 " result : " + result.value); 166 } 167 if (comp < 0) { 168 return element; 171 } 172 else { 173 if(comp == 0) { 174 if(isDebugOn()) { 177 trace("findVarBind"," oid overlapping. Oid : " + 178 element.oid + "value :" + element.value); 179 trace("findVarBind","Already present varBind : " + 180 result); 181 } 182 SnmpOid oid = result.oid; 183 SnmpMibAgent deeperAgent = server.getAgentMib(oid); 184 185 if(isDebugOn()) 186 trace("findVarBind","Deeper agent : " + deeperAgent); 187 if(deeperAgent == agent) { 188 if(isDebugOn()) 189 trace("updateResult","The current agent is the deeper one. Update the value with the current one"); 190 return element; 191 } else { 192 if(isDebugOn()) 193 trace("updateResult","Current is not the deeper, return the previous one."); 194 return result; 195 } 196 197 216 217 } 218 else { 219 if(isDebugOn()) 220 trace("findVarBind", 221 "The right varBind is the already present one"); 222 return result; 223 } 224 } 225 } 226 233 protected void updateResult(SnmpVarBind[] result) { 234 237 final Enumeration e= varBind.elements(); 238 final int max= result.length; 239 240 for(int i=0; i < size; i++) { 242 if (e.hasMoreElements() == false) 245 return; 246 247 final int pos=translation[i]; 250 if (pos >= max) { 251 debug("updateResult","Position `"+pos+"' is out of bound..."); 252 continue; 253 } 254 255 final SnmpVarBind element= (SnmpVarBind) e.nextElement(); 256 257 if (element == null) continue; 258 if (isDebugOn()) 259 trace("updateResult", "Non repeaters Current element : " + 260 element + " from agent : " + agent); 261 final SnmpVarBind res = findVarBind(element,result[pos]); 262 263 if(res == null) continue; 264 265 result[pos] = res; 266 } 267 268 int localR= size - nonRepeat; 271 for (int i = 2 ; i <= maxRepeat ; i++) { 272 for (int r = 0 ; r < localR ; r++) { 273 final int pos = (i-1)* globalR + translation[nonRepeat + r] ; 274 if (pos >= max) 275 return; 276 if (e.hasMoreElements() ==false) 277 return; 278 final SnmpVarBind element= (SnmpVarBind) e.nextElement(); 279 280 if (element == null) continue; 281 if (isDebugOn()) 282 trace("updateResult", "Repeaters Current element : " + 283 element + " from agent : " + agent); 284 final SnmpVarBind res = findVarBind(element, result[pos]); 285 286 if(res == null) continue; 287 288 result[pos] = res; 289 } 290 } 291 } 292 293 protected String makeDebugTag() { 294 return "SnmpSubBulkRequestHandler"; 295 } 296 297 300 303 protected int nonRepeat=0; 304 305 protected int maxRepeat=0; 306 307 310 protected int globalR=0; 311 312 protected int size=0; 313 } 314 | Popular Tags |