KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > mo > snmp > SnmpProxyMIB


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - SnmpProxyMIB.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21
22 package org.snmp4j.agent.mo.snmp;
23
24 //--AgentGen BEGIN=_BEGIN
25
//--AgentGen END
26

27 import org.snmp4j.smi.*;
28 import org.snmp4j.mp.SnmpConstants;
29 import org.snmp4j.agent.*;
30 import org.snmp4j.agent.mo.*;
31 import org.snmp4j.agent.mo.snmp.*;
32 import java.util.List JavaDoc;
33
34 //--AgentGen BEGIN=_IMPORT
35
//--AgentGen END
36

37 public class SnmpProxyMIB
38 //--AgentGen BEGIN=_EXTENDS
39
//--AgentGen END
40
implements MOGroup
41 //--AgentGen BEGIN=_IMPLEMENTS
42
//--AgentGen END
43
{
44
45   // Constants
46

47   // Scalars
48

49   // Tables
50
private static final OID oidSnmpProxyEntry =
51     new OID(new int[] { 1,3,6,1,6,3,14,1,2,1 });
52
53   // Column sub-identifer defintions for snmpProxyEntry:
54
private static final int colSnmpProxyType = 2;
55   private static final int colSnmpProxyContextEngineID = 3;
56   private static final int colSnmpProxyContextName = 4;
57   private static final int colSnmpProxyTargetParamsIn = 5;
58   private static final int colSnmpProxySingleTargetOut = 6;
59   private static final int colSnmpProxyMultipleTargetOut = 7;
60   private static final int colSnmpProxyStorageType = 8;
61   private static final int colSnmpProxyRowStatus = 9;
62
63   // Column index defintions for snmpProxyEntry:
64
static final int idxSnmpProxyType = 0;
65   static final int idxSnmpProxyContextEngineID = 1;
66   static final int idxSnmpProxyContextName = 2;
67   static final int idxSnmpProxyTargetParamsIn = 3;
68   static final int idxSnmpProxySingleTargetOut = 4;
69   static final int idxSnmpProxyMultipleTargetOut = 5;
70   static final int idxSnmpProxyStorageType = 6;
71   static final int idxSnmpProxyRowStatus = 7;
72   private static MOTableSubIndex[] snmpProxyEntryIndexes =
73     new MOTableSubIndex[] {
74         new MOTableSubIndex(SMIConstants.SYNTAX_OCTET_STRING, 1, 32)
75   };
76
77   private static MOTableIndex snmpProxyEntryIndex =
78       new MOTableIndex(snmpProxyEntryIndexes, true) {
79     public boolean isValidIndex(OID index) {
80       boolean isValidIndex = super.isValidIndex(index);
81       if (isValidIndex) {
82      //--AgentGen BEGIN=snmpProxyEntry::isValidIndex
83
//--AgentGen END
84
}
85       return isValidIndex;
86     }
87   };
88
89
90   private DefaultMOTable snmpProxyEntry;
91   private DefaultMOMutableTableModel snmpProxyEntryModel;
92
93 //--AgentGen BEGIN=_MEMBERS
94
//--AgentGen END
95

96   public SnmpProxyMIB() {
97     createSnmpProxyEntry();
98   }
99
100
101   private void createSnmpProxyEntry() {
102     MOColumn[] snmpProxyEntryColumns = new MOColumn[8];
103     snmpProxyEntryColumns[idxSnmpProxyType] =
104       new Enumerated(colSnmpProxyType,
105                      MOAccessImpl.ACCESS_READ_CREATE,
106                      null,
107                      true,
108                      new int[] { 1, 2, 3, 4 });
109     snmpProxyEntryColumns[idxSnmpProxyContextEngineID] =
110       new MOMutableColumn(colSnmpProxyContextEngineID,
111                           SMIConstants.SYNTAX_OCTET_STRING,
112                           MOAccessImpl.ACCESS_READ_CREATE,
113                           null,
114                           true);
115     ((MOMutableColumn)snmpProxyEntryColumns[idxSnmpProxyContextEngineID]).
116       addMOValueValidationListener(new SnmpProxyContextEngineIDValidator());
117     snmpProxyEntryColumns[idxSnmpProxyContextName] =
118       new MOMutableColumn(colSnmpProxyContextName,
119                           SMIConstants.SYNTAX_OCTET_STRING,
120                           MOAccessImpl.ACCESS_READ_CREATE,
121                           null,
122                           true);
123     ((MOMutableColumn)snmpProxyEntryColumns[idxSnmpProxyContextName]).
124       addMOValueValidationListener(new SnmpProxyContextNameValidator());
125     snmpProxyEntryColumns[idxSnmpProxyTargetParamsIn] =
126       new MOMutableColumn(colSnmpProxyTargetParamsIn,
127                           SMIConstants.SYNTAX_OCTET_STRING,
128                           MOAccessImpl.ACCESS_READ_CREATE,
129                           null,
130                           true);
131     ((MOMutableColumn)snmpProxyEntryColumns[idxSnmpProxyTargetParamsIn]).
132       addMOValueValidationListener(new SnmpProxyTargetParamsInValidator());
133     snmpProxyEntryColumns[idxSnmpProxySingleTargetOut] =
134       new MOMutableColumn(colSnmpProxySingleTargetOut,
135                           SMIConstants.SYNTAX_OCTET_STRING,
136                           MOAccessImpl.ACCESS_READ_CREATE,
137                           null,
138                           true);
139     ((MOMutableColumn)snmpProxyEntryColumns[idxSnmpProxySingleTargetOut]).
140       addMOValueValidationListener(new SnmpProxySingleTargetOutValidator());
141     snmpProxyEntryColumns[idxSnmpProxyMultipleTargetOut] =
142       new MOMutableColumn(colSnmpProxyMultipleTargetOut,
143                           SMIConstants.SYNTAX_OCTET_STRING,
144                           MOAccessImpl.ACCESS_READ_CREATE,
145                           null,
146                           true);
147     ((MOMutableColumn)snmpProxyEntryColumns[idxSnmpProxyMultipleTargetOut]).
148       addMOValueValidationListener(new SnmpProxyMultipleTargetOutValidator());
149     snmpProxyEntryColumns[idxSnmpProxyStorageType] =
150       new StorageType(colSnmpProxyStorageType,
151                       MOAccessImpl.ACCESS_READ_CREATE,
152                       new Integer32(3),
153                       true);
154     snmpProxyEntryColumns[idxSnmpProxyRowStatus] =
155       new RowStatus(colSnmpProxyRowStatus);
156
157     snmpProxyEntry =
158       new DefaultMOTable(oidSnmpProxyEntry,
159                          snmpProxyEntryIndex,
160                          snmpProxyEntryColumns);
161     snmpProxyEntryModel = new DefaultMOMutableTableModel();
162     snmpProxyEntry.setModel(snmpProxyEntryModel);
163     snmpProxyEntryModel.setRowFactory(new SnmpProxyRowFactory());
164   }
165
166
167   public void registerMOs(MOServer server, OctetString context)
168     throws DuplicateRegistrationException
169   {
170     // Scalar Objects
171
server.register(this.snmpProxyEntry, context);
172 //--AgentGen BEGIN=_registerMOs
173
//--AgentGen END
174
}
175
176   public void unregisterMOs(MOServer server, OctetString context) {
177     // Scalar Objects
178
server.unregister(this.snmpProxyEntry, context);
179 //--AgentGen BEGIN=_unregisterMOs
180
//--AgentGen END
181
}
182
183   // Notifications
184

185   // Scalars
186

187   // Value Validators
188

189   /**
190    * The <code>SnmpProxyContextEngineIDValidator</code> implements the value
191    * validation for <code>SnmpProxyContextEngineID</code>.
192    */

193   static class SnmpProxyContextEngineIDValidator implements MOValueValidationListener {
194
195     public void validate(MOValueValidationEvent validationEvent) {
196       Variable newValue = validationEvent.getNewValue();
197       OctetString os = (OctetString)newValue;
198       if (!(((os.length() >= 5) && (os.length() <= 32)))) {
199         validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
200         return;
201       }
202      //--AgentGen BEGIN=snmpProxyContextEngineID::validate
203
//--AgentGen END
204
}
205   }
206   /**
207    * The <code>SnmpProxyContextNameValidator</code> implements the value
208    * validation for <code>SnmpProxyContextName</code>.
209    */

210   static class SnmpProxyContextNameValidator implements MOValueValidationListener {
211
212     public void validate(MOValueValidationEvent validationEvent) {
213       Variable newValue = validationEvent.getNewValue();
214       OctetString os = (OctetString)newValue;
215       if (!(((os.length() >= 0) && (os.length() <= 255)))) {
216         validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
217         return;
218       }
219      //--AgentGen BEGIN=snmpProxyContextName::validate
220
//--AgentGen END
221
}
222   }
223   /**
224    * The <code>SnmpProxyTargetParamsInValidator</code> implements the value
225    * validation for <code>SnmpProxyTargetParamsIn</code>.
226    */

227   static class SnmpProxyTargetParamsInValidator implements MOValueValidationListener {
228
229     public void validate(MOValueValidationEvent validationEvent) {
230       Variable newValue = validationEvent.getNewValue();
231       OctetString os = (OctetString)newValue;
232       if (!(((os.length() >= 0) && (os.length() <= 255)))) {
233         validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
234         return;
235       }
236      //--AgentGen BEGIN=snmpProxyTargetParamsIn::validate
237
//--AgentGen END
238
}
239   }
240   /**
241    * The <code>SnmpProxySingleTargetOutValidator</code> implements the value
242    * validation for <code>SnmpProxySingleTargetOut</code>.
243    */

244   static class SnmpProxySingleTargetOutValidator implements MOValueValidationListener {
245
246     public void validate(MOValueValidationEvent validationEvent) {
247       Variable newValue = validationEvent.getNewValue();
248       OctetString os = (OctetString)newValue;
249       if (!(((os.length() >= 0) && (os.length() <= 255)))) {
250         validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
251         return;
252       }
253      //--AgentGen BEGIN=snmpProxySingleTargetOut::validate
254
//--AgentGen END
255
}
256   }
257   /**
258    * The <code>SnmpProxyMultipleTargetOutValidator</code> implements the value
259    * validation for <code>SnmpProxyMultipleTargetOut</code>.
260    */

261   static class SnmpProxyMultipleTargetOutValidator implements MOValueValidationListener {
262
263     public void validate(MOValueValidationEvent validationEvent) {
264       Variable newValue = validationEvent.getNewValue();
265       OctetString os = (OctetString)newValue;
266       if (!(((os.length() >= 0) && (os.length() <= 255)))) {
267         validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
268         return;
269       }
270      //--AgentGen BEGIN=snmpProxyMultipleTargetOut::validate
271
//--AgentGen END
272
}
273   }
274
275   // Enumerations
276

277   public static final class SnmpProxyTypeEnum {
278     public static final int read = 1;
279     public static final int write = 2;
280     public static final int trap = 3;
281     public static final int inform = 4;
282   }
283
284   // Rows and Factories
285

286   class SnmpProxyRowFactory extends DefaultMOMutableRow2PCFactory {
287     public SnmpProxyRowFactory() {
288     }
289
290     public MOTableRow createRow(OID index, Variable[] values)
291         throws UnsupportedOperationException JavaDoc
292     {
293       return new SnmpProxyRow(index, values);
294     }
295   }
296
297   public class SnmpProxyRow extends DefaultMOMutableRow2PC {
298     public SnmpProxyRow(OID index, Variable[] values) {
299       super(index, values);
300     }
301
302     public Integer32 getSnmpProxyType() {
303        return (Integer32) getValue(idxSnmpProxyType);
304      }
305
306      public void setSnmpProxyType(Integer32 newValue) {
307        setValue(idxSnmpProxyType, newValue);
308      }
309
310      public OctetString getSnmpProxyContextEngineID() {
311        return (OctetString) getValue(idxSnmpProxyContextEngineID);
312      }
313
314      public void setSnmpProxyContextEngineID(OctetString newValue) {
315        setValue(idxSnmpProxyContextEngineID, newValue);
316      }
317
318      public OctetString getSnmpProxyContextName() {
319        return (OctetString) getValue(idxSnmpProxyContextName);
320      }
321
322      public void setSnmpProxyContextName(OctetString newValue) {
323        setValue(idxSnmpProxyContextName, newValue);
324      }
325
326      public OctetString getSnmpProxyTargetParamsIn() {
327        return (OctetString) getValue(idxSnmpProxyTargetParamsIn);
328      }
329
330      public void setSnmpProxyTargetParamsIn(OctetString newValue) {
331        setValue(idxSnmpProxyTargetParamsIn, newValue);
332      }
333
334      public OctetString getSnmpProxySingleTargetOut() {
335        return (OctetString) getValue(idxSnmpProxySingleTargetOut);
336      }
337
338      public void setSnmpProxySingleTargetOut(OctetString newValue) {
339        setValue(idxSnmpProxySingleTargetOut, newValue);
340      }
341
342      public OctetString getSnmpProxyMultipleTargetOut() {
343        return (OctetString) getValue(idxSnmpProxyMultipleTargetOut);
344      }
345
346      public void setSnmpProxyMultipleTargetOut(OctetString newValue) {
347        setValue(idxSnmpProxyMultipleTargetOut, newValue);
348      }
349
350      public Integer32 getSnmpProxyStorageType() {
351        return (Integer32) getValue(idxSnmpProxyStorageType);
352      }
353
354      public void setSnmpProxyStorageType(Integer32 newValue) {
355        setValue(idxSnmpProxyStorageType, newValue);
356      }
357
358      public Integer32 getSnmpProxyRowStatus() {
359        return (Integer32) getValue(idxSnmpProxyRowStatus);
360      }
361
362      public void setSnmpProxyRowStatus(Integer32 newValue) {
363        setValue(idxSnmpProxyRowStatus, newValue);
364      }
365
366   }
367
368
369
370 //--AgentGen BEGIN=_METHODS
371

372   /**
373    * Returns the proxy configuration table defined as "snmpProxyTable".
374    * @return
375    * a MOTable instance.
376    */

377   public MOTable getSnmpProxyEntry() {
378     return snmpProxyEntry;
379   }
380
381   /**
382    * Adds a proxy entry to the snmpProxyTable (descriptions taken from
383    * SNMP-PROXY-MIB definition).
384    * @param name
385    * The locally arbitrary, but unique identifier associated
386    * with this snmpProxyEntry.
387    * @param type
388    * The type of message that may be forwarded using
389    * the translation parameters defined by this entry.
390    * See {@link ProxyTypeEnum} for possible values.
391    * @param contextEngineId
392    * The contextEngineID contained in messages that
393    * may be forwarded using the translation parameters
394    * defined by this entry.
395    * @param contextName
396    * The contextName contained in messages that may be
397    * forwarded using the translation parameters defined
398    * by this entry.
399    * This object is optional, and if not supported, the
400    * contextName contained in a message is ignored when
401    * selecting an entry in the snmpProxyTable.
402    * @param targetParamsIn
403    * This object selects an entry in the snmpTargetParamsTable.
404    * The selected entry is used to determine which row of the
405    * snmpProxyTable to use for forwarding received messages.
406    * @param singleTargetOut
407    * This object selects a management target defined in the
408    * snmpTargetAddrTable (in the SNMP-TARGET-MIB). The
409    * selected target is defined by an entry in the
410    * snmpTargetAddrTable whose index value (snmpTargetAddrName)
411    * is equal to this object.
412    * This object is only used when selection of a single
413    * target is required (i.e. when forwarding an incoming
414    * read or write request).
415    * @param multipleTargetOut
416    * This object selects a set of management targets defined
417    * in the snmpTargetAddrTable (in the SNMP-TARGET-MIB).
418    * This object is only used when selection of multiple
419    * targets is required (i.e. when forwarding an incoming
420    * notification).
421    * @param storageType
422    * The storage type of this conceptual row.
423    * Conceptual rows having the value 'permanent' need not
424    * allow write-access to any columnar objects in the row. See
425    * {@link StorageType} for possible values.
426    * @return
427    * <code>true</code> if the row could be added, <code>false</code>
428    * otherwise.
429    */

430   public boolean addProxyEntry(OctetString name,
431                                int type,
432                                OctetString contextEngineId,
433                                OctetString contextName,
434                                OctetString targetParamsIn,
435                                OctetString singleTargetOut,
436                                OctetString multipleTargetOut,
437                                int storageType)
438   {
439       Variable[] var = new
440           Variable[snmpProxyEntry.getColumnCount()];
441       OID index = name.toSubIndex(true);
442       var[idxSnmpProxyType] = new Integer32(type);
443       var[idxSnmpProxyContextEngineID] = contextEngineId;
444       var[idxSnmpProxyContextName] = contextName;
445       var[idxSnmpProxyTargetParamsIn] = targetParamsIn;
446       var[idxSnmpProxySingleTargetOut] = singleTargetOut;
447       var[idxSnmpProxyMultipleTargetOut] = multipleTargetOut;
448       var[idxSnmpProxyStorageType] = new Integer32(storageType);
449       var[idxSnmpProxyRowStatus] = new Integer32(RowStatus.active);
450       MOTableRow row = snmpProxyEntry.createRow(index, var);
451       return snmpProxyEntry.addRow(row);
452   }
453
454   /**
455    * Removes the proxy entry with the specified name.
456    * @param name
457    * the name of the proxy entry to remove from the proxy configuration.
458    * @return
459    * the removed row or <code>null</code> if no such row exists.
460    */

461   public SnmpProxyRow removeProxyEntry(OctetString name) {
462     OID index = name.toSubIndex(true);
463     SnmpProxyRow removedRow =
464         (SnmpProxyRow) snmpProxyEntryModel.removeRow(index);
465     return removedRow;
466   }
467
468
469   public List JavaDoc getProxyRows(final int proxyType,
470                            final OctetString contextEngineID,
471                            final OctetString context) {
472     MOTableRowFilter filter = new MOTableRowFilter() {
473       public boolean passesFilter(MOTableRow row) {
474         int rowStatus =
475             ((Integer32)row.getValue(idxSnmpProxyRowStatus)).getValue();
476         if (rowStatus != RowStatus.active) {
477           return false;
478         }
479         int type = ((Integer32)row.getValue(idxSnmpProxyType)).getValue();
480         if (type != proxyType) {
481           return false;
482         }
483         OctetString cengineID =
484             (OctetString)row.getValue(idxSnmpProxyContextEngineID);
485         if (!cengineID.equals(contextEngineID)) {
486           return false;
487         }
488         OctetString cname =
489             (OctetString)row.getValue(idxSnmpProxyContextName);
490         if ((cname != null) && (!cname.equals(context))) {
491           return false;
492         }
493         return true;
494       }
495     };
496     return this.snmpProxyEntryModel.getRows(null, null, filter);
497   }
498
499 //--AgentGen END
500

501 //--AgentGen BEGIN=_CLASSES
502

503 //--AgentGen END
504

505 //--AgentGen BEGIN=_END
506
//--AgentGen END
507
}
508
509
510
Popular Tags