KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - SnmpCommunityMIB.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
23 package org.snmp4j.agent.mo.snmp;
24
25 //--AgentGen BEGIN=_BEGIN
26
//--AgentGen END
27

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 java.util.Map JavaDoc;
34 import java.util.Collections JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.*;
38 import org.snmp4j.agent.mo.snmp.SnmpTargetMIB.SnmpTargetAddrEntryRow;
39 import org.snmp4j.log.LogAdapter;
40 import org.snmp4j.log.LogFactory;
41
42 //--AgentGen BEGIN=_IMPORT
43
//--AgentGen END
44

45 public class SnmpCommunityMIB
46
47 //--AgentGen BEGIN=_EXTENDS
48
//--AgentGen END
49
implements MOGroup
50 //--AgentGen BEGIN=_IMPLEMENTS
51
, CoexistenceInfoProvider
52 //--AgentGen END
53
{
54
55   // Factory
56
private static MOFactory moFactory = DefaultMOFactory.getInstance();
57
58   // Constants
59

60   private static final OID oidSnmpCommunityEntry =
61     new OID(new int[] { 1,3,6,1,6,3,18,1,1,1 });
62
63   // Column sub-identifer defintions for snmpCommunityEntry:
64
private static final int colSnmpCommunityName = 2;
65   private static final int colSnmpCommunitySecurityName = 3;
66   private static final int colSnmpCommunityContextEngineID = 4;
67   private static final int colSnmpCommunityContextName = 5;
68   private static final int colSnmpCommunityTransportTag = 6;
69   private static final int colSnmpCommunityStorageType = 7;
70   private static final int colSnmpCommunityStatus = 8;
71
72   // Column index defintions for snmpCommunityEntry:
73
private static final int idxSnmpCommunityName = 0;
74   private static final int idxSnmpCommunitySecurityName = 1;
75   private static final int idxSnmpCommunityContextEngineID = 2;
76   private static final int idxSnmpCommunityContextName = 3;
77   private static final int idxSnmpCommunityTransportTag = 4;
78   private static final int idxSnmpCommunityStorageType = 5;
79   private static final int idxSnmpCommunityStatus = 6;
80   private static MOTableSubIndex[] snmpCommunityEntryIndexes =
81     new MOTableSubIndex[] {
82         moFactory.createSubIndex(SMIConstants.SYNTAX_OCTET_STRING, 1, 32)
83   };
84
85   private static MOTableIndex snmpCommunityEntryIndex =
86       moFactory.createIndex(snmpCommunityEntryIndexes,
87                             true);
88
89
90   private MOTable snmpCommunityEntry;
91   private MOMutableTableModel snmpCommunityEntryModel;
92   private static final OID oidSnmpTargetAddrExtEntry =
93     new OID(new int[] { 1,3,6,1,6,3,18,1,2,1 });
94
95   // Column sub-identifer defintions for snmpTargetAddrExtEntry:
96
private static final int colSnmpTargetAddrTMask = 1;
97   private static final int colSnmpTargetAddrMMS = 2;
98
99   // Column index defintions for snmpTargetAddrExtEntry:
100
private static final int idxSnmpTargetAddrTMask = 0;
101   private static final int idxSnmpTargetAddrMMS = 1;
102   private static MOTableSubIndex[] snmpTargetAddrExtEntryIndexes =
103     new MOTableSubIndex[] {
104         moFactory.createSubIndex(SMIConstants.SYNTAX_OCTET_STRING, 1, 32)
105   };
106
107   private static MOTableIndex snmpTargetAddrExtEntryIndex =
108       moFactory.createIndex(snmpTargetAddrExtEntryIndexes,
109                             true);
110
111
112   private MOTable snmpTargetAddrExtEntry;
113   private MOMutableTableModel snmpTargetAddrExtEntryModel;
114
115   private MOTableRelation snmpTargetAddrEntryRelation;
116
117 //--AgentGen BEGIN=_MEMBERS
118
private static final LogAdapter logger =
119       LogFactory.getLogger(SnmpCommunityMIB.class);
120
121   private Map JavaDoc coexistenceInfo;
122   private Map JavaDoc communityInfo;
123   private SnmpTargetMIB targetMIB;
124   private boolean sourceAddressFiltering;
125
126   public SnmpCommunityMIB(SnmpTargetMIB targetMIB) {
127     this();
128     this.targetMIB = targetMIB;
129     setBaseTableSnmpTargetAddrEntry(targetMIB.getSnmpTargetAddrEntry());
130   }
131
132 //--AgentGen END
133

134   private SnmpCommunityMIB() {
135     createSnmpCommunityEntry();
136     createSnmpTargetAddrExtEntry();
137   }
138
139
140   public MOTable getSnmpCommunityEntry() {
141     return snmpCommunityEntry;
142   }
143
144
145   private void createSnmpCommunityEntry() {
146     MOColumn[] snmpCommunityEntryColumns = new MOColumn[7];
147     snmpCommunityEntryColumns[idxSnmpCommunityName] =
148       new MOMutableColumn(colSnmpCommunityName,
149                           SMIConstants.SYNTAX_OCTET_STRING,
150                           MOAccessImpl.ACCESS_READ_CREATE,
151                           null,
152                           true);
153     snmpCommunityEntryColumns[idxSnmpCommunitySecurityName] =
154       new MOMutableColumn(colSnmpCommunitySecurityName,
155                           SMIConstants.SYNTAX_OCTET_STRING,
156                           MOAccessImpl.ACCESS_READ_CREATE,
157                           null,
158                           true);
159     ((MOMutableColumn)snmpCommunityEntryColumns[idxSnmpCommunitySecurityName]).
160       addMOValueValidationListener(new SnmpCommunitySecurityNameValidator());
161     snmpCommunityEntryColumns[idxSnmpCommunityContextEngineID] =
162       new MOMutableColumn(colSnmpCommunityContextEngineID,
163                           SMIConstants.SYNTAX_OCTET_STRING,
164                           MOAccessImpl.ACCESS_READ_CREATE,
165                           null,
166                           true);
167     ((MOMutableColumn)snmpCommunityEntryColumns[idxSnmpCommunityContextEngineID]).
168       addMOValueValidationListener(new SnmpCommunityContextEngineIDValidator());
169     snmpCommunityEntryColumns[idxSnmpCommunityContextName] =
170       new MOMutableColumn(colSnmpCommunityContextName,
171                           SMIConstants.SYNTAX_OCTET_STRING,
172                           MOAccessImpl.ACCESS_READ_CREATE,
173                           new OctetString(new byte[] { }),
174                           true);
175     ((MOMutableColumn)snmpCommunityEntryColumns[idxSnmpCommunityContextName]).
176       addMOValueValidationListener(new SnmpCommunityContextNameValidator());
177     snmpCommunityEntryColumns[idxSnmpCommunityTransportTag] =
178       new MOMutableColumn(colSnmpCommunityTransportTag,
179                           SMIConstants.SYNTAX_OCTET_STRING,
180                           MOAccessImpl.ACCESS_READ_CREATE,
181                           new OctetString(new byte[] { }),
182                           true);
183     ((MOMutableColumn)snmpCommunityEntryColumns[idxSnmpCommunityTransportTag]).
184       addMOValueValidationListener(new SnmpCommunityTransportTagValidator());
185     snmpCommunityEntryColumns[idxSnmpCommunityStorageType] =
186       new StorageType(colSnmpCommunityStorageType,
187                       MOAccessImpl.ACCESS_READ_CREATE,
188                       null,
189                       true);
190     snmpCommunityEntryColumns[idxSnmpCommunityStatus] =
191       new RowStatus(colSnmpCommunityStatus);
192
193     snmpCommunityEntryModel = new DefaultMOMutableTableModel();
194     snmpCommunityEntryModel.setRowFactory(new SnmpCommunityEntryRowFactory());
195     snmpCommunityEntry =
196       moFactory.createTable(oidSnmpCommunityEntry,
197                             snmpCommunityEntryIndex,
198                             snmpCommunityEntryColumns,
199                             snmpCommunityEntryModel);
200   }
201
202   public MOTable getSnmpTargetAddrExtEntry() {
203     return snmpTargetAddrExtEntry;
204   }
205
206   public void setBaseTableSnmpTargetAddrEntry(MOTable baseTable) {
207      snmpTargetAddrEntryRelation =
208        moFactory.createTableRelation(baseTable, snmpTargetAddrExtEntry);
209      snmpTargetAddrEntryRelation.createRelationShip();
210   }
211
212   private void createSnmpTargetAddrExtEntry() {
213     MOColumn[] snmpTargetAddrExtEntryColumns = new MOColumn[2];
214     snmpTargetAddrExtEntryColumns[idxSnmpTargetAddrTMask] =
215       new MOMutableColumn(colSnmpTargetAddrTMask,
216                           SMIConstants.SYNTAX_OCTET_STRING,
217                           MOAccessImpl.ACCESS_READ_CREATE,
218                           new OctetString(new byte[] { }),
219                           true);
220     ((MOMutableColumn)snmpTargetAddrExtEntryColumns[idxSnmpTargetAddrTMask]).
221       addMOValueValidationListener(new SnmpTargetAddrTMaskValidator());
222     snmpTargetAddrExtEntryColumns[idxSnmpTargetAddrMMS] =
223       new MOMutableColumn(colSnmpTargetAddrMMS,
224                           SMIConstants.SYNTAX_INTEGER32,
225                           MOAccessImpl.ACCESS_READ_CREATE,
226                           new Integer32(484),
227                           true);
228     ((MOMutableColumn)snmpTargetAddrExtEntryColumns[idxSnmpTargetAddrMMS]).
229       addMOValueValidationListener(new SnmpTargetAddrMMSValidator());
230
231     snmpTargetAddrExtEntryModel = new DefaultMOMutableTableModel();
232     snmpTargetAddrExtEntryModel.setRowFactory(new SnmpTargetAddrExtEntryRowFactory());
233     snmpTargetAddrExtEntry =
234       moFactory.createTable(oidSnmpTargetAddrExtEntry,
235                             snmpTargetAddrExtEntryIndex,
236                             snmpTargetAddrExtEntryColumns,
237                             snmpTargetAddrExtEntryModel);
238   }
239
240
241   public void registerMOs(MOServer server, OctetString context)
242     throws DuplicateRegistrationException
243   {
244     // Scalar Objects
245
server.register(this.snmpCommunityEntry, context);
246     server.register(this.snmpTargetAddrExtEntry, context);
247 //--AgentGen BEGIN=_registerMOs
248
//--AgentGen END
249
}
250
251   public void unregisterMOs(MOServer server, OctetString context) {
252     // Scalar Objects
253
server.unregister(this.snmpCommunityEntry, context);
254     server.unregister(this.snmpTargetAddrExtEntry, context);
255 //--AgentGen BEGIN=_unregisterMOs
256
//--AgentGen END
257
}
258
259   // Notifications
260

261   // Scalars
262

263   // Value Validators
264

265   /**
266    * The <code>SnmpCommunitySecurityNameValidator</code> implements the value
267    * validation for <code>SnmpCommunitySecurityName</code>.
268    */

269   static class SnmpCommunitySecurityNameValidator implements MOValueValidationListener {
270
271     public void validate(MOValueValidationEvent validationEvent) {
272       Variable newValue = validationEvent.getNewValue();
273       OctetString os = (OctetString)newValue;
274       if (!(((os.length() >= 1) && (os.length() <= 32)))) {
275         validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
276         return;
277       }
278      //--AgentGen BEGIN=snmpCommunitySecurityName::validate
279
//--AgentGen END
280
}
281   }
282   /**
283    * The <code>SnmpCommunityContextEngineIDValidator</code> implements the value
284    * validation for <code>SnmpCommunityContextEngineID</code>.
285    */

286   static class SnmpCommunityContextEngineIDValidator implements MOValueValidationListener {
287
288     public void validate(MOValueValidationEvent validationEvent) {
289       Variable newValue = validationEvent.getNewValue();
290       OctetString os = (OctetString)newValue;
291       if (!(((os.length() >= 5) && (os.length() <= 32)))) {
292         validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
293         return;
294       }
295      //--AgentGen BEGIN=snmpCommunityContextEngineID::validate
296
//--AgentGen END
297
}
298   }
299   /**
300    * The <code>SnmpCommunityContextNameValidator</code> implements the value
301    * validation for <code>SnmpCommunityContextName</code>.
302    */

303   static class SnmpCommunityContextNameValidator implements MOValueValidationListener {
304
305     public void validate(MOValueValidationEvent validationEvent) {
306       Variable newValue = validationEvent.getNewValue();
307       OctetString os = (OctetString)newValue;
308       if (!(((os.length() >= 0) && (os.length() <= 32)))) {
309         validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
310         return;
311       }
312      //--AgentGen BEGIN=snmpCommunityContextName::validate
313
//--AgentGen END
314
}
315   }
316   /**
317    * The <code>SnmpCommunityTransportTagValidator</code> implements the value
318    * validation for <code>SnmpCommunityTransportTag</code>.
319    */

320   static class SnmpCommunityTransportTagValidator implements MOValueValidationListener {
321
322     public void validate(MOValueValidationEvent validationEvent) {
323       Variable newValue = validationEvent.getNewValue();
324       OctetString os = (OctetString)newValue;
325       if (!(((os.length() >= 0) && (os.length() <= 255)))) {
326         validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
327         return;
328       }
329      //--AgentGen BEGIN=snmpCommunityTransportTag::validate
330
//--AgentGen END
331
}
332   }
333   /**
334    * The <code>SnmpTargetAddrTMaskValidator</code> implements the value
335    * validation for <code>SnmpTargetAddrTMask</code>.
336    */

337   static class SnmpTargetAddrTMaskValidator implements MOValueValidationListener {
338
339     public void validate(MOValueValidationEvent validationEvent) {
340       Variable newValue = validationEvent.getNewValue();
341       OctetString os = (OctetString)newValue;
342       if (!(((os.length() >= 0) && (os.length() <= 255)))) {
343         validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
344         return;
345       }
346      //--AgentGen BEGIN=snmpTargetAddrTMask::validate
347
//--AgentGen END
348
}
349   }
350   /**
351    * The <code>SnmpTargetAddrMMSValidator</code> implements the value
352    * validation for <code>SnmpTargetAddrMMS</code>.
353    */

354   static class SnmpTargetAddrMMSValidator implements MOValueValidationListener {
355
356     public void validate(MOValueValidationEvent validationEvent) {
357       Variable newValue = validationEvent.getNewValue();
358       long v = ((Integer32)newValue).getValue();
359       if (!(((v >= 0L) && (v <= 0L)) ||
360           ((v >= 484L)))) {
361         validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_VALUE);
362         return;
363       }
364      //--AgentGen BEGIN=snmpTargetAddrMMS::validate
365
//--AgentGen END
366
}
367   }
368
369
370
371   // Rows and Factories
372
class SnmpCommunityEntryRowFactory
373         extends DefaultMOMutableRow2PCFactory
374   {
375     public synchronized MOTableRow createRow(OID index, Variable[] values)
376         throws UnsupportedOperationException JavaDoc
377     {
378       SnmpCommunityEntryRow row = new SnmpCommunityEntryRow(index, values);
379       //--AgentGen BEGIN=snmpCommunityEntry::createRow
380
if (coexistenceInfo == null) {
381         coexistenceInfo = Collections.synchronizedMap(new HashMap JavaDoc());
382       }
383       coexistenceInfo.put(values[idxSnmpCommunityName], row);
384       if (communityInfo == null) {
385         communityInfo = Collections.synchronizedMap(new HashMap JavaDoc());
386       }
387       List JavaDoc l = (List JavaDoc) communityInfo.get(values[idxSnmpCommunitySecurityName]);
388       if (l == null) {
389         l = new LinkedList();
390         communityInfo.put(values[idxSnmpCommunitySecurityName], l);
391       }
392       l.add(row);
393       //--AgentGen END
394
return row;
395     }
396
397     public synchronized void freeRow(MOTableRow row) {
398      //--AgentGen BEGIN=snmpCommunityEntry::freeRow
399
coexistenceInfo.remove(row.getValue(idxSnmpCommunityName));
400      List JavaDoc l =
401          (List JavaDoc) communityInfo.get(row.getValue(idxSnmpCommunitySecurityName));
402      if (l != null) {
403        l.remove(row);
404        if (l.size() == 0) {
405          communityInfo.remove(row.getValue(idxSnmpCommunitySecurityName));
406        }
407      }
408      //--AgentGen END
409
}
410   }
411
412   class SnmpCommunityEntryRow extends DefaultMOMutableRow2PC {
413     public SnmpCommunityEntryRow(OID index, Variable[] values) {
414       super(index, values);
415     }
416
417     public OctetString getSnmpCommunityName() {
418       return (OctetString) getValue(idxSnmpCommunityName);
419     }
420
421     public void setSnmpCommunityName(OctetString newValue) {
422       setValue(idxSnmpCommunityName, newValue);
423     }
424
425     public OctetString getSnmpCommunitySecurityName() {
426       return (OctetString) getValue(idxSnmpCommunitySecurityName);
427     }
428
429     public void setSnmpCommunitySecurityName(OctetString newValue) {
430       setValue(idxSnmpCommunitySecurityName, newValue);
431     }
432
433     public OctetString getSnmpCommunityContextEngineID() {
434       return (OctetString) getValue(idxSnmpCommunityContextEngineID);
435     }
436
437     public void setSnmpCommunityContextEngineID(OctetString newValue) {
438       setValue(idxSnmpCommunityContextEngineID, newValue);
439     }
440
441     public OctetString getSnmpCommunityContextName() {
442       return (OctetString) getValue(idxSnmpCommunityContextName);
443     }
444
445     public void setSnmpCommunityContextName(OctetString newValue) {
446       setValue(idxSnmpCommunityContextName, newValue);
447     }
448
449     public OctetString getSnmpCommunityTransportTag() {
450       return (OctetString) getValue(idxSnmpCommunityTransportTag);
451     }
452
453     public void setSnmpCommunityTransportTag(OctetString newValue) {
454       setValue(idxSnmpCommunityTransportTag, newValue);
455     }
456
457     public Integer32 getSnmpCommunityStorageType() {
458       return (Integer32) getValue(idxSnmpCommunityStorageType);
459     }
460
461     public void setSnmpCommunityStorageType(Integer32 newValue) {
462       setValue(idxSnmpCommunityStorageType, newValue);
463     }
464
465     public Integer32 getSnmpCommunityStatus() {
466       return (Integer32) getValue(idxSnmpCommunityStatus);
467     }
468
469     public void setSnmpCommunityStatus(Integer32 newValue) {
470       setValue(idxSnmpCommunityStatus, newValue);
471     }
472
473
474      //--AgentGen BEGIN=snmpCommunityEntry::RowFactory
475
//--AgentGen END
476
}
477
478   class SnmpTargetAddrExtEntryRowFactory
479         extends DefaultMOMutableRow2PCFactory
480   {
481     public MOTableRow createRow(OID index, Variable[] values)
482         throws UnsupportedOperationException JavaDoc
483     {
484       SnmpTargetAddrExtEntryRow row = new SnmpTargetAddrExtEntryRow(index, values);
485      //--AgentGen BEGIN=snmpTargetAddrExtEntry::createRow
486
//--AgentGen END
487
return row;
488     }
489
490     public void freeRow(MOTableRow row) {
491      //--AgentGen BEGIN=snmpTargetAddrExtEntry::freeRow
492
//--AgentGen END
493
}
494   }
495
496   class SnmpTargetAddrExtEntryRow extends DefaultMOMutableRow2PC {
497     public SnmpTargetAddrExtEntryRow(OID index, Variable[] values) {
498       super(index, values);
499     }
500
501     public OctetString getSnmpTargetAddrTMask() {
502       return (OctetString) getValue(idxSnmpTargetAddrTMask);
503     }
504
505     public void setSnmpTargetAddrTMask(OctetString newValue) {
506       setValue(idxSnmpTargetAddrTMask, newValue);
507     }
508
509     public Integer32 getSnmpTargetAddrMMS() {
510       return (Integer32) getValue(idxSnmpTargetAddrMMS);
511     }
512
513     public void setSnmpTargetAddrMMS(Integer32 newValue) {
514       setValue(idxSnmpTargetAddrMMS, newValue);
515     }
516
517
518      //--AgentGen BEGIN=snmpTargetAddrExtEntry::RowFactory
519
//--AgentGen END
520
}
521
522
523
524 //--AgentGen BEGIN=_METHODS
525

526   public CoexistenceInfo getCoexistenceInfo(OctetString community) {
527     if (logger.isDebugEnabled()) {
528       logger.debug("Looking up coexistence info for '"+community+"'");
529     }
530     if (coexistenceInfo == null) {
531       return null;
532     }
533     SnmpCommunityEntryRow row =
534         (SnmpCommunityEntryRow) coexistenceInfo.get(community);
535     if (row != null) {
536       CoexistenceInfo info =
537           new CoexistenceInfo(row.getSnmpCommunitySecurityName(),
538                               row.getSnmpCommunityContextEngineID(),
539                               row.getSnmpCommunityContextName(),
540                               row.getSnmpCommunityTransportTag());
541       if (logger.isDebugEnabled()) {
542         logger.debug("Found coexistence info for '"+community+"'="+info);
543       }
544       return info;
545     }
546     return null;
547   }
548
549   /**
550    * Checks whether the supplied address passes the source address filter
551    * configured for the supplied transport tag. The tag identifies a set of
552    * addresses configured in the snmpTargetAddrTable which is extended by
553    * the snmpTargetAddrExtTable. The transport address mask allows entries
554    * in the snmpTargetAddrTable to define a set of addresses instead of
555    * just a single address.
556    *
557    * @param address
558    * the address of the incoming packet to check.
559    * @param coexistenceInfo
560    * a set of coexistence information that provides the transport tag that
561    * is used to identify allowed source addresses. On return, the maximum
562    * message size attribute of the coexistence info set will be set
563    * according to the values defined for the matched source address in
564    * the snmpTargetAddrExtTable.
565    * @return boolean
566    */

567   public boolean passesFilter(Address address,
568                               CoexistenceInfo coexistenceInfo) {
569     if (!isSourceAddressFiltering()) {
570       if (logger.isDebugEnabled()) {
571         logger.debug("Address "+address+
572                      " passes filter, "+
573                      "because source address filtering is disabled");
574       }
575       return true;
576     }
577     if ((coexistenceInfo.getTransportTag() == null) ||
578         (coexistenceInfo.getTransportTag().length() == 0)) {
579       if (logger.isDebugEnabled()) {
580         logger.debug("Address "+address+
581                      " passes filter, because transportTag is null");
582       }
583       return true;
584     }
585     Collection matches =
586         targetMIB.getTargetAddrRowsForTag(coexistenceInfo.getTransportTag());
587     for (Iterator it = matches.iterator(); it.hasNext(); ) {
588       SnmpTargetAddrEntryRow row = (SnmpTargetAddrEntryRow) it.next();
589       SnmpTargetAddrExtEntryRow extRow = (SnmpTargetAddrExtEntryRow)
590           snmpTargetAddrExtEntryModel.getRow(row.getIndex());
591       OctetString filterTAddress =
592           (OctetString) row.getValue(SnmpTargetMIB.idxSnmpTargetAddrTAddress);
593       if (extRow != null) {
594         OctetString mask = extRow.getSnmpTargetAddrTMask();
595         OctetString matchAddress = row.getTAddress(address);
596         if ((mask.length() == 0) &&
597             (matchAddress != null) && (matchAddress.equals(filterTAddress))) {
598           coexistenceInfo.setMaxMessageSize(
599               extRow.getSnmpTargetAddrMMS().getValue());
600           return true;
601         }
602         else if ((matchAddress != null) &&
603                  (mask.length() == matchAddress.length()) &&
604                  (matchAddress.length() == filterTAddress.length())) {
605           OctetString maskedFilterTAddress = filterTAddress.mask(mask);
606           OctetString maskedMatchTAddress = matchAddress.mask(mask);
607           if (maskedFilterTAddress.equals(maskedMatchTAddress)) {
608             coexistenceInfo.setMaxMessageSize(
609                 extRow.getSnmpTargetAddrMMS().getValue());
610             return true;
611           }
612         }
613       }
614     }
615     return false;
616   }
617
618   /**
619    * Enables or disables source address filtering for incoming SNMPv1 or SNMPv2c
620    * packets. By default source address filtering is disabled! If enabled, only
621    * messages received for community based security models are processed, that
622    * match an address in the snmpTargetAddressTable with the transport tag
623    * associated with the community used.
624    *
625    * @param sourceAddressFiltering
626    * if <code>true</code> source address filtering is enabled, otherwise
627    * it is disabled.
628    */

629   public void setSourceAddressFiltering(boolean sourceAddressFiltering) {
630     this.sourceAddressFiltering = sourceAddressFiltering;
631   }
632
633   /**
634    * Returns <code>true</code> if source address filtering is enabled. In that
635    * case a call to {@link #passesFilter} will always return <code>true</code>.
636    * @return
637    * <code>true</code> if source address filtering is enabled,
638    * <code>false</code> otherwise.
639    */

640   public boolean isSourceAddressFiltering() {
641     return sourceAddressFiltering;
642   }
643
644   public OctetString getCommunity(OctetString securityName,
645                                   OctetString contextEngineID,
646                                   OctetString contextName) {
647     List JavaDoc l = (List JavaDoc) communityInfo.get(securityName);
648     if (l != null) {
649       for (Iterator it = l.iterator(); it.hasNext(); ) {
650         SnmpCommunityEntryRow row = (SnmpCommunityEntryRow) it.next();
651         if (row.getSnmpCommunityStatus().getValue() == RowStatus.active) {
652           if (((contextEngineID == null) ||
653                (contextEngineID.equals(row.getSnmpCommunityContextEngineID()))) &&
654               ((row.getSnmpCommunityContextName().equals(contextName)))) {
655             return row.getSnmpCommunityName();
656           }
657         }
658       }
659     }
660     return null;
661   }
662
663   //--AgentGen END
664

665 //--AgentGen BEGIN=_CLASSES
666
//--AgentGen END
667

668 //--AgentGen BEGIN=_END
669
//--AgentGen END
670
}
671
672
673
Popular Tags