1 20 21 22 package org.snmp4j.agent.mo.ext; 23 24 25 28 import org.snmp4j.smi.*; 29 import org.snmp4j.mp.SnmpConstants; 30 import org.snmp4j.agent.*; 31 import org.snmp4j.agent.mo.*; 32 import org.snmp4j.agent.mo.snmp.*; 33 import org.snmp4j.agent.request.*; 34 import org.snmp4j.log.LogFactory; 35 import org.snmp4j.log.LogAdapter; 36 37 40 public class AgentppSimulationMib 41 implements MOGroup 44 { 47 48 private static final LogAdapter LOGGER = 49 LogFactory.getLogger(AgentppSimulationMib.class); 50 51 54 private static MOFactory moFactory = DefaultMOFactory.getInstance(); 56 57 public static final OID oidAgentppSimMode = 59 new OID(new int[] { 1,3,6,1,4,1,4976,2,1,1,0 }); 60 public static final OID oidAgentppSimDeleteRow = 61 new OID(new int[] { 1,3,6,1,4,1,4976,2,1,2,0 }); 62 public static final OID oidAgentppSimDeleteTableContents = 63 new OID(new int[] { 1,3,6,1,4,1,4976,2,1,3,0 }); 64 65 public static final class AgentppSimModeEnum { 67 public static final int oper = 1; 68 public static final int config = 2; 69 } 70 71 72 74 private MOScalar agentppSimMode; 76 private MOScalar agentppSimDeleteRow; 77 private MOScalar agentppSimDeleteTableContents; 78 79 81 82 private MOServer moServer; 84 private OctetString myContext; 85 87 public AgentppSimulationMib() { 88 agentppSimMode = 89 new AgentppSimMode(oidAgentppSimMode, MOAccessImpl.ACCESS_READ_WRITE); 90 agentppSimDeleteRow = 91 new AgentppSimDeleteRow(oidAgentppSimDeleteRow, 92 MOAccessImpl.ACCESS_READ_WRITE); 93 agentppSimDeleteTableContents = 94 new AgentppSimDeleteTableContents(oidAgentppSimDeleteTableContents, 95 MOAccessImpl.ACCESS_READ_WRITE); 96 } 99 100 103 104 105 106 public void registerMOs(MOServer server, OctetString context) 107 throws DuplicateRegistrationException 108 { 109 server.register(this.agentppSimMode, context); 111 server.register(this.agentppSimDeleteRow, context); 112 server.register(this.agentppSimDeleteTableContents, context); 113 moServer = server; 115 myContext = context; 116 } 118 119 public void unregisterMOs(MOServer server, OctetString context) { 120 server.unregister(this.agentppSimMode, context); 122 server.unregister(this.agentppSimDeleteRow, context); 123 server.unregister(this.agentppSimDeleteTableContents, context); 124 moServer = null; 126 myContext = null; 127 } 129 130 132 public class AgentppSimMode extends EnumeratedScalar { 134 AgentppSimMode(OID oid, MOAccess access) { 135 super(oid, access, new Integer32(), 136 new int[] { AgentppSimModeEnum.oper, 137 AgentppSimModeEnum.config }); 138 setValue(new Integer32(AgentppSimModeEnum.oper)); 140 setVolatile(true); 141 } 143 144 public int setValue(Variable newValue) { 145 SimMOFactory.setSimulationModeEnabled(((Integer32)newValue).getValue() == 147 AgentppSimModeEnum.config); 148 return super.setValue(newValue); 150 } 151 152 155 } 156 157 public class AgentppSimDeleteRow extends MOScalar { 158 AgentppSimDeleteRow(OID oid, MOAccess access) { 159 super(oid, access, new OID()); 160 super.setValue(SnmpConstants.zeroDotZero); 162 setVolatile(true); 163 } 165 166 public int isValueOK(SubRequest request) { 167 Variable newValue = 168 request.getVariableBinding().getVariable(); 169 int valueOK = super.isValueOK(request); 170 if (valueOK != SnmpConstants.SNMP_ERROR_SUCCESS) { 171 return valueOK; 172 } 173 if (AgentppSimulationMib.this.moServer == null) { 175 return SnmpConstants.SNMP_ERROR_RESOURCE_UNAVAILABLE; 176 } 177 OID oid = (OID)newValue; 178 ManagedObject mo = getManagedObject(oid); 179 if (!(mo instanceof MOTable)) { 180 return SnmpConstants.SNMP_ERROR_WRONG_VALUE; 181 } 182 MOTable table = (MOTable)mo; 183 OID index = new OID(oid.getValue(), table.getOID().size(), 184 oid.size()-table.getOID().size()); 185 MOTableRow row = table.getModel().getRow(index); 186 if (row == null) { 187 return SnmpConstants.SNMP_ERROR_WRONG_VALUE; 188 } 189 return valueOK; 191 } 192 193 public int setValue(Variable newValue) { 194 if (AgentppSimulationMib.this.moServer == null) { 196 return SnmpConstants.SNMP_ERROR_COMMIT_FAILED; 197 } 198 OID oid = (OID)newValue; 199 ManagedObject mo = getManagedObject(oid); 200 if (!(mo instanceof MOTable)) { 201 return SnmpConstants.SNMP_ERROR_COMMIT_FAILED; 202 } 203 MOTable table = (MOTable)mo; 204 OID index = new OID(oid.getValue(), table.getOID().size(), 205 oid.size()-table.getOID().size()); 206 MOTableRow row = table.removeRow(index); 207 if (row == null) { 208 return SnmpConstants.SNMP_ERROR_COMMIT_FAILED; 209 } 210 return super.setValue(newValue); 212 } 213 214 217 } 218 219 public class AgentppSimDeleteTableContents extends MOScalar { 220 AgentppSimDeleteTableContents(OID oid, MOAccess access) { 221 super(oid, access, new OID()); 222 setVolatile(true); 224 } 226 227 public int isValueOK(SubRequest request) { 228 Variable newValue = 229 request.getVariableBinding().getVariable(); 230 int valueOK = super.isValueOK(request); 231 if (valueOK != SnmpConstants.SNMP_ERROR_SUCCESS) { 232 return valueOK; 233 } 234 if (AgentppSimulationMib.this.moServer == null) { 236 return SnmpConstants.SNMP_ERROR_RESOURCE_UNAVAILABLE; 237 } 238 OID oid = (OID)newValue; 239 oid.append(0); 240 ManagedObject mo = getManagedObject(oid); 241 if ((!(mo instanceof MOTable)) || 242 (!(((MOTable)mo).getModel() instanceof MOMutableTableModel))) { 243 return SnmpConstants.SNMP_ERROR_WRONG_VALUE; 244 } 245 return valueOK; 247 } 248 249 public int setValue(Variable newValue) { 250 if (AgentppSimulationMib.this.moServer == null) { 252 return SnmpConstants.SNMP_ERROR_COMMIT_FAILED; 253 } 254 OID oid = (OID)newValue; 255 oid.append(0); 256 ManagedObject mo = getManagedObject(oid); 257 if ((!(mo instanceof MOTable)) && 258 (!(((MOTable)mo).getModel() instanceof MOMutableTableModel))) { 259 return SnmpConstants.SNMP_ERROR_COMMIT_FAILED; 260 } 261 MOTable table = (MOTable)mo; 262 ((MOMutableTableModel)table.getModel()).clear(); 263 return super.setValue(newValue); 265 } 266 267 270 } 271 272 273 275 277 278 private synchronized ManagedObject getManagedObject(OID oid) { 280 MOQuery query = new DefaultMOQuery(new DefaultMOContextScope(myContext, 281 oid, true, oid, true), true); 282 ManagedObject mo = AgentppSimulationMib.this.moServer.lookup(query); 283 return mo; 284 } 285 287 290 } 293 294 295 | Popular Tags |