Commits

Anonymous committed a5010a0

Fixed the unit tests. Via REST API most of the snmp v3 parameters can be set.

Comments (0)

Files changed (10)

core/snmp/api/src/main/java/org/opennms/netmgt/snmp/SnmpAgentConfig.java

             	agentConfig.setContextName(value);
             } else if ("enterprise-id".equalsIgnoreCase(key)) {
             	agentConfig.setEnterpriseId(value);
+            } else if ("write-community".equalsIgnoreCase(key)) {
+            	agentConfig.setWriteCommunity(value);
             } else {
                 s_logger.warn("Unexpected attribute in protocol configuration string for SnmpAgentConfig: '{}'", attribute);
             }
             buff.append(",security-name=" + getSecurityName());
             buff.append(",auth-passphrase=" + getAuthPassPhrase());
             buff.append(",auth-protocol=" + getAuthProtocol());
-            buff.append(",priv-passprhase=" + getPrivPassPhrase());
+            buff.append(",priv-passphrase=" + getPrivPassPhrase());
             buff.append(",priv-protocol=" + getPrivProtocol());
             buff.append(",engine-id=" + getEngineId());
             buff.append(",context-engine-id=" + getContextEngineId());
             buff.append(",enterprise-id=" + getEnterpriseId());
         } else {
             buff.append(",read-community=" + getReadCommunity());
+            buff.append(",write-community=" + getWriteCommunity());
         }
         return buff.toString();
     }
 
     public String toString() {
-        StringBuffer buff = new StringBuffer("AgentConfig[");
+        StringBuffer buff = new StringBuffer("SnmpAgentConfig[");
         buff.append("Address: " + InetAddressUtils.str(m_address));
         buff.append(", ProxyForAddress: " + InetAddressUtils.str(m_proxyFor));
         buff.append(", Port: " + getPort());
-        buff.append(", Community: " + getReadCommunity()); // TODO mvr this is not equally to toProtocolConfigString. why?
         buff.append(", Timeout: " + getTimeout());
         buff.append(", Retries: " + getRetries());
         buff.append(", MaxVarsPerPdu: " + getMaxVarsPerPdu());
         buff.append(", MaxRepetitions: " + getMaxRepetitions());
-        buff.append(", Max request size: " + getMaxRequestSize());
+        buff.append(", MaxRequestSize: " + getMaxRequestSize());
         buff.append(", Version: " + versionToString(getVersion()));
         if (isVersion3()) {
-            buff.append(", Security level: " + getSecurityLevel());
-            buff.append(", Security name: " + getSecurityName());
-            buff.append(", auth-passphrase: " + getAuthPassPhrase());
-            buff.append(", auth-protocol: " + getAuthProtocol());
-            buff.append(", priv-passprhase: " + getPrivPassPhrase());
-            buff.append(", priv-protocol: " + getPrivProtocol());
-            buff.append(", engine-id: " + getEngineId());
-            buff.append(", context-engine-id: " + getContextEngineId());
-            buff.append(", context-name: " + getContextName());
-            buff.append(", enterprise-id:" + getEnterpriseId());
+            buff.append(", SecurityLevel: " + getSecurityLevel());
+            buff.append(", SecurityName: " + getSecurityName());
+            buff.append(", AuthPassPhrase: " + getAuthPassPhrase());
+            buff.append(", AuthProtocol: " + getAuthProtocol());
+            buff.append(", PrivPassprhase: " + getPrivPassPhrase());
+            buff.append(", PrivProtocol: " + getPrivProtocol());
+            buff.append(", EngineId: " + getEngineId());
+            buff.append(", ContextEngineId: " + getContextEngineId());
+            buff.append(", ContextName: " + getContextName());
+            buff.append(", EnterpriseId:" + getEnterpriseId());
+        } else {
+        	buff.append(", ReadCommunity: " + getReadCommunity());
+        	buff.append(", WriteCommunity: " + getWriteCommunity());
         }
         buff.append("]");
         return buff.toString();

core/snmp/api/src/main/java/org/opennms/netmgt/snmp/SnmpConfiguration.java

     private String m_authProtocol;
     private String m_privProtocol;
     private String m_privPassPhrase;
-    
-    // TODO mvr defaults?
     private String m_engineId;
-    // TODO mvr defaults?
     private String m_contextEngineId;
-    // TODO mvr defaults?
     private String m_contextName;
-    // TODO mvr defaults?
     private String m_enterpriseId;
     
     public SnmpConfiguration() {

opennms-config/src/main/java/org/opennms/netmgt/config/MergeableDefinition.java

 
 package org.opennms.netmgt.config;
 
-import java.math.BigInteger;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.ListIterator;
-
-import org.opennms.core.utils.InetAddressUtils;
-import org.opennms.core.utils.ThreadCategory;
 import org.opennms.netmgt.config.snmp.Definition;
 import org.opennms.netmgt.config.snmp.Range;
 import org.opennms.netmgt.model.discovery.IPAddressRange;
                 getConfigDef().addRange(xmlRange);
             }
             
-        }
-        
-        
-//        if (eventDefinition.isSpecific()) {
-//            handleSpecificMerge(eventDefinition.getConfigDef());
-//        } else {
-//            handleRangeMerge(eventDefinition.getConfigDef());
-//        }
-        
-        
-    }
-    
-    /**
-     * Little helper method for determining if this definition
-     * from a configureSNMP event containts a specific IP address vs.
-     * a range.
-     *
-     * @return true if the number of ranges in the def is 0.
-     */
-    public boolean isSpecific() {
-        
-        boolean specific = false;
-        if (getConfigDef().getRangeCount() == 0) {
-            specific = true;
-        }
-        return specific;
-    }
-    
-    /**
-     * This method handles the updating of the SnmpConfig when
-     * the definition to be merged contains a specific IP address.
-     * 
-     * @param eventDef a definition created to represent the values
-     *  passed in the configureSNMP event params
-     */
-    @SuppressWarnings("unused")
-	private void handleSpecificMerge(final Definition eventDef)  {
-        
-        if (hasRangeMatchingSpecific(eventDef.getSpecific(0))) {
-            log().error("handleSpecificMerge: definition already contains a range that matches requested SNMP specific change: " + this);
-        } else if (hasMatchingSpecific(eventDef.getSpecific(0))) {
-            log().error("handleSpecificMerge: definition already contains a specific that matches requested SNMP specific change: " + this);
-        } else {
-            getConfigDef().addSpecific(eventDef.getSpecific(0));
-            sortSpecifics();
-        }
-    }
-
-    private ThreadCategory log() {
-        return ThreadCategory.getInstance(getClass());
-    }
-    
-    /**
-     * This method handles the updating of the SnmpConfig when
-     * the definition to be merged contains a range.
-     * 
-     * @param eventDef a definition created to represent the values
-     *  passed in the configureSNMP event params
-     */
-    @SuppressWarnings("unused")
-	private void handleRangeMerge(final Definition eventDef) {
-        
-        //first remove any specifics that would be eclipsed by this new range
-        while (hasSpecificMatchingNewRange(eventDef.getRange(0))) {
-            String spec = findSpecificMatchingNewRange(eventDef.getRange(0));
-            getConfigDef().removeSpecific(spec);
-        }
-        mergeNewRangeIntoDef(eventDef.getRange(0));
-    }
-    
-    /**
-     * Enumerates over the list of specifics in a definition
-     * looking for a matching specific element.  Assumes isSpecific()
-     * returns true.
-     *
-     * @param specific IP address as a string
-     * @return true if def has a matching specific IP address already
-     */
-    public boolean hasMatchingSpecific(final String specific) {
-        boolean specificMatches = false;
-        for (String defSpecific : getConfigDef().getSpecificCollection()) {
-            if (defSpecific.equals(specific)) {
-                specificMatches = true;
-                break;
-            }
-        }
-        return specificMatches;
-    }
-    
-    /**
-     * Simple method to add readability
-     *
-     * @param specific IP address
-     * @return true if the definition has a range covering
-     *  the specified specific IP address
-     */
-    public boolean hasRangeMatchingSpecific(final String specific) {
-        return (findRangeMatchingSpecific(specific) != null);
-    }
-    
-    /**
-     * Analyzes the definition to determine if one of its ranges
-     * matches the specified specific IP address
-     *
-     * @param specific a {@link java.lang.String} object.
-     * @return the matching range
-     */
-    public Range findRangeMatchingSpecific(final String specific) {
-        Range matchingRange = null;
-        for (Range erange : getConfigDef().getRangeCollection()) {
-            MergeableRange range = new MergeableRange(erange);
-            if (range.coversSpecific(specific)) {
-                matchingRange = range.getRange();
-                break;
-            }
-        }
-        return matchingRange;
-    }
-    
-    /**
-     * Responsible for merging new ranges in to this definition.
-     *
-     * @param newRange a {@link org.opennms.netmgt.config.common.Range} object.
-     */
-    public void mergeNewRangeIntoDef(final Range newRange) {
-        purgeEclipsedRangesInDef(newRange);
-        
-        if (getConfigDef().getRangeCount() == 0) {
-            getConfigDef().addRange(newRange);
-        } else {
-            boolean overlapped = mergeOverlappingRanges(newRange);
-            if(!overlapped) {
-                getConfigDef().addRange(newRange);
-            }
-        }
-    }
-    
-    /**
-     * Removes in ranges in the defintion that are eclipsed
-     * by the new range.
-     *
-     * @param range a {@link org.opennms.netmgt.config.common.Range} object.
-     */
-    public void purgeEclipsedRangesInDef(final Range range) {
-        Range[] ranges = getConfigDef().getRange();
-        MergeableRange newRange = new MergeableRange(range);
-        
-        for (int i = 0; i < ranges.length; i++) {
-            Range rng = ranges[i];
-            
-            if (newRange.eclipses(rng)) {
-                getConfigDef().removeRange(rng);
-            }
-        }
-    }
-    
-    /**
-     * The passed range is evaluated against the existing ranges in the
-     * definition and updates the def range if it overlaps or eclipses
-     * a def range.
-     *
-     * @param range a {@link org.opennms.netmgt.config.common.Range} object.
-     * @return the state of having updated any ranges in the definition
-     *   due to being affected by the new range.
-     */
-    public boolean mergeOverlappingRanges(final Range range) {
-        boolean overlapped = false;
-        sortRanges();
-        MergeableRange newRange = new MergeableRange(range);
-        Range[] ranges = getConfigDef().getRange();
-        for (int i = 0; i < ranges.length; i++) {
-            Range defRange = ranges[i];
-            
-            if (newRange.equals(defRange)) {
-                overlapped = true;
-            } else if (newRange.overlapsBegin(defRange)) {
-                defRange.setBegin(newRange.getRange().getBegin());
-                overlapped = true;
-            } else if (newRange.overlapsEnd(defRange)) {
-                defRange.setEnd(newRange.getRange().getEnd());
-                overlapped = true;
-            } else if (newRange.eclipses(defRange)) {
-                defRange.setBegin(newRange.getRange().getBegin());
-                defRange.setEnd(newRange.getRange().getEnd());
-                overlapped = true;
-            }
-        }
-        sortRanges();
-        return overlapped;
-    }
-    
-    /**
-     * Sorts the specifics in the current wrapped definition.
-     */
-    public void sortSpecifics() {
-        String[] specifics = getConfigDef().getSpecific();
-        Arrays.sort(specifics, new SpecificComparator());
-        getConfigDef().setSpecific(specifics);
-    }
-    
-    /**
-     * Sorts ranges with the current wrapped definition.
-     */
-    public void sortRanges() {
-        Range[] ranges = getConfigDef().getRange();
-        Arrays.sort(ranges, new RangeComparator());
-        getConfigDef().setRange(ranges);
-    }
-    
-    /**
-     * <p>hasSpecificMatchingNewRange</p>
-     *
-     * @param eventRange a {@link org.opennms.netmgt.config.common.Range} object.
-     * @return a boolean.
-     */
-    public boolean hasSpecificMatchingNewRange(final Range eventRange) {
-        return (findSpecificMatchingNewRange(eventRange) != null);
-    }
-    
-    /**
-     * <p>findSpecificMatchingNewRange</p>
-     *
-     * @param eventRange a {@link org.opennms.netmgt.config.common.Range} object.
-     * @return a {@link java.lang.String} object.
-     */
-    public String findSpecificMatchingNewRange(final Range eventRange) {
-        String matchingSpecific = null;
-        for (String spec : getConfigDef().getSpecificCollection()) {
-            MergeableRange range = new MergeableRange(eventRange);
-            
-            if (range.coversSpecific(spec)) {
-                matchingSpecific = spec;
-                break;
-            }
-        }
-        return matchingSpecific;
+        }        
     }
     
     /**
     	return SnmpConfigManager.areEquals(object1, object2);
     }
 
-    /**
-     * Removes the specified specific from the wrapped definition.
-     *
-     * @param specific a {@link java.lang.String} object.
-     */
-    public void purgeSpecificFromDef(final String specific) {
-        String[] specs = getConfigDef().getSpecific();
-        for (int i = 0; i < specs.length; i++) {
-            String spec = specs[i];
-
-            if (spec.equals(specific)) {
-                getConfigDef().removeSpecific(spec);
-            }
-        }
-        
-        Range[] ranges = getConfigDef().getRange();
-        for (int i = 0; i < ranges.length; i++) {
-            MergeableRange range = new MergeableRange(ranges[i]);
-            
-            if (range.coversSpecific(specific)) {
-                Range newRange = range.removeSpecificFromRange(specific);
-                if (newRange != null) {
-                    getConfigDef().addRange(newRange);
-                }
-            }
-        }
-    }
-    
-    /**
-     * Call this method to optimize the specifics in the wrapped definition.
-     */
-    public void optimizeSpecifics() {
-        adjustRangesWithAdjacentSpecifics();
-        removeSpecificsEclipsedByRanges();
-        convertAdjacentSpecficsIntoRange();
-    }
-    
-    /**
-     * This method moves specifics that are adjacent to ranges in to the range.
-     */
-    private void adjustRangesWithAdjacentSpecifics() {
-        sortSpecifics();
-        sortRanges();
-        String[] specifics = getConfigDef().getSpecific();
-        
-        for (int i = 0; i < specifics.length; i++) {
-            MergeableSpecific specific = new MergeableSpecific(specifics[i]);
-            for (Range range : getConfigDef().getRangeCollection()) {
-                if (new BigInteger("-1").equals(InetAddressUtils.difference(specific.getSpecific(), range.getBegin()))) {
-                    getConfigDef().removeSpecific(specific.getSpecific());
-                    range.setBegin(specific.getSpecific());
-                } else if (new BigInteger("1").equals(InetAddressUtils.difference(specific.getSpecific(), range.getEnd()))) {
-                    getConfigDef().removeSpecific(specific.getSpecific());
-                    range.setEnd(specific.getSpecific());
-                }
-            }
-        }
-        sortSpecifics();
-        sortRanges();
-    }
-    
-    /**
-     * This method removes any specifics from the wrapped definition that are covered one of its ranges.
-     *
-     */
-    private void removeSpecificsEclipsedByRanges() {
-        sortSpecifics();
-        String[] specifics = getConfigDef().getSpecific();
-        for (int i = 0; i < specifics.length; i++) {
-            String specific = specifics[i];
-            if (hasRangeMatchingSpecific(specific)) {
-                getConfigDef().removeSpecific(specific);
-            }
-        }
-        sortSpecifics();
-    }
-    
-    /**
-     * Converts specifics into ranges when their diffs are abs() 1
-     */
-    private void convertAdjacentSpecficsIntoRange() {
-        sortSpecifics();
-        List<String> specificList = new ArrayList<String>(new LinkedHashSet<String>(getConfigDef().getSpecificCollection()));
-        List<Range> definedRanges = Arrays.asList(getConfigDef().getRange());
-        ArrayList<Range> newRanges = new ArrayList<Range>();
-        
-        if (specificList.size() > 1) {
-            for (ListIterator<String> it = specificList.listIterator(); it.hasNext();) {
-                final MergeableSpecific specific = new MergeableSpecific(it.next());
-                final Range newRange = new Range();
-                newRange.setBegin(specific.getSpecific());
-                while (it.hasNext()) {
-                    String nextSpecific = (String)it.next();
-                    if (new BigInteger("-1").equals(InetAddressUtils.difference(specific.getSpecific(), nextSpecific))) {
-                        newRange.setEnd(nextSpecific);
-                        getConfigDef().removeSpecific(specific.getSpecific());
-                        getConfigDef().removeSpecific(nextSpecific);
-                        specific.setSpecific(nextSpecific);
-                    } else {
-                        it.previous();
-                        break;
-                    }
-                }
-                
-                if (newRange.getEnd() != null) {
-                    newRanges.add(newRange);
-                }
-            }
-            newRanges.addAll(definedRanges);
-            getConfigDef().setRange(newRanges);
-            sortRanges();
-        }
-    }
-    
-    /**
-     * Removes the specifics and ranges covered by the range specified in the parameter from the current wrapped definition.
-     *
-     * @param eventRange a {@link org.opennms.netmgt.config.common.Range} object.
-     */
-    public void purgeRangeFromDef(final Range eventRange) {
-        MergeableRange range = new MergeableRange(eventRange);
-        
-        sortSpecifics();
-        String[] specs = getConfigDef().getSpecific();
-        
-        for (int i = 0; i < specs.length; i++) {
-            String spec = specs[i];
-            if (range.coversSpecific(spec)) {
-                getConfigDef().removeSpecific(spec);
-            }
-        }
-        
-        sortRanges();
-        Range[] ranges = getConfigDef().getRange();
-        for (int i = 0; i < ranges.length; i++) {
-            Range defRng = ranges[i];
-
-            try {
-                if (range.eclipses(defRng)) {
-                    getConfigDef().removeRange(defRng);
-                } else if (range.withInRange(defRng)) {
-                    Range newRange = new Range();
-                    newRange.setBegin(InetAddressUtils.incr(range.getLast().getSpecific()));
-                    newRange.setEnd(defRng.getEnd());
-                    getConfigDef().addRange(newRange);
-                    defRng.setEnd(InetAddressUtils.decr(range.getFirst().getSpecific()));
-                } else if (range.overlapsBegin(defRng)) {
-                    defRng.setBegin(InetAddressUtils.incr(range.getLast().getSpecific()));
-                } else if (range.overlapsEnd(defRng)) {
-                    defRng.setEnd(InetAddressUtils.decr(range.getFirst().getSpecific()));
-                }
-            } catch (UnknownHostException e) {
-                ThreadCategory.getInstance(getClass()).error("Error converting string to IP address: " + e.getMessage(), e);
-            }
-        }
-    }
-    
-    /**
-     * Optimizes the ranges in the wrapped definition by making the definition as small and
-     * as ordered as possible.
-     */
-    public void optimizeRanges() {
-        sortRanges();
-        Range[] ranges = getConfigDef().getRange();
-        
-        for (int i = 0; i < ranges.length-1; i++) {
-            Range firstRange = ranges[i];
-            Range nextRange = ranges[i+1];
-            optimizeAdjacentRanges(firstRange, nextRange);
-        }
-        optimizeZeroLengthRanges();
-    }
-    
-    /**
-     * Converts ranges in the wrapped defintion that have equal begin and end addresses.
-     */
-    private void optimizeZeroLengthRanges() {
-        Range[] ranges = getConfigDef().getRange();
-        
-        for (int i = 0; i < ranges.length; i++) {
-            Range range = ranges[i];
-            
-            if (range.getBegin().equals(range.getEnd())) {
-                if (!hasMatchingSpecific(range.getBegin())) {
-                    getConfigDef().addSpecific(range.getBegin());
-                }
-                getConfigDef().removeRange(range);
-            }
-        }
-    }
-    
-    /**
-     * Adjusts 2 ordered ranges in the wrapped definition by determining if the nextRange is
-     * either eclipsed, or overlapped by its previousRange.
-     * 
-     * @param previousRange
-     * @param nextRange
-     */
-    private void optimizeAdjacentRanges(final Range previousRange, final Range nextRange) {
-        MergeableRange range = new MergeableRange(previousRange);
-        
-        if (range.equals(nextRange)) {
-            getConfigDef().removeRange(previousRange);
-            
-        } else if (range.eclipses(nextRange)) {
-            
-            //We have to do this because of the side effects of object references
-            nextRange.setBegin(previousRange.getBegin());
-            nextRange.setEnd(previousRange.getEnd());
-            getConfigDef().removeRange(previousRange);
-            
-        } else if (range.isAdjacentToBegin(nextRange) || range.overlapsBegin(nextRange)){
-            nextRange.setBegin(previousRange.getBegin());
-            getConfigDef().removeRange(previousRange);
-            
-        } else if (range.isAdjacentToEnd(nextRange) || range.overlapsEnd(nextRange)) {
-            
-            //this "probably" should never happen
-            nextRange.setEnd(previousRange.getEnd());
-            getConfigDef().removeRange(previousRange);
-        }
-    }
-
     boolean matches(MergeableDefinition other) {
         return areEquals(getConfigDef().getReadCommunity(), other.getConfigDef().getReadCommunity())
                 && areEquals(getConfigDef().getPort(), other.getConfigDef().getPort()) 
             }
             
         }
-
-//        if (eventDefinition.isSpecific()) {
-//            purgeSpecificFromDef(eventDefinition.getConfigDef().getSpecific(0));
-//        } else {
-//            purgeRangeFromDef(eventDefinition.getConfigDef().getRange(0));
-//        }
     }
 
     boolean isEmpty() {

opennms-config/src/main/java/org/opennms/netmgt/config/SnmpConfigManager.java

 	}
 
 	/**
-	 * Optimize all definitions in the current configuration.
-	 */
-	public void optimizeAllDefs() {
-		// This needs to be called only by code holding the SnmpPeerFactory
-		// writeLock
-		Definition[] defs = getConfig().getDefinition();
-		for (int i = 0; i < defs.length; i++) {
-			MergeableDefinition definition = new MergeableDefinition(defs[i]);
-			if (definition.getConfigDef().getSpecificCount() > 0) {
-				definition.optimizeSpecifics();
-			}
-			if (definition.getConfigDef().getRangeCount() > 1) {
-				definition.optimizeRanges();
-			}
-		}
-		getConfig().setDefinition(defs);
-	}
-
-	/**
 	 * Checks if the two objects are equal or not. They are equal if 
 	 * <ul>
 	 * 	<li>obj1 and obj2 are null</li>

opennms-config/src/main/java/org/opennms/netmgt/config/SnmpEventInfo.java

 public class SnmpEventInfo {	
     private String m_firstIPAddress = null;
     private String m_lastIPAddress = null;
-    private String m_communityString = null;
+    private String m_readCommunityString = null;
+    private String m_writeCommunityString = null;
     private int m_timeout = 0;
     private int m_retryCount = 0;
     private String m_version = null;
     private String m_securityName = null;
     private int m_maxVarsPerPdu = 0;
     private int m_maxRepetitions = 0;
+    private int m_maxRequestSize = 0;
     private String m_authPassPhrase = null;
     private String m_authProtocol = null;
     private String m_privProtocol = null;
      *
      * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
      */
-    public SnmpEventInfo(Event event) {
+    @SuppressWarnings("deprecation")
+	public SnmpEventInfo(Event event) {
         String parmName = null;
         Value parmValue = null;
         String parmContent = null;
                     setFirstIPAddress(parmContent);
                 } else if (parmName.equals(EventConstants.PARM_LAST_IP_ADDRESS)) {
                     setLastIPAddress(parmContent);
-                } else if (parmName.equals(EventConstants.PARM_COMMUNITY_STRING)) {
-                    setCommunityString(parmContent);
+                } else if (parmName.equals(EventConstants.PARM_COMMUNITY_STRING) || parmName.equals(EventConstants.PARM_SNMP_READ_COMMUNITY_STRING)) {
+                    setReadCommunityString(parmContent);
+                } else if (parmName.equals(EventConstants.PARM_SNMP_WRITE_COMMUNITY_STRING)) {
+                	setWriteCommunityString(parmContent);
                 } else if (parmName.equals(EventConstants.PARM_RETRY_COUNT)) {
                     setRetryCount(computeIntValue(parmContent));
                 } else if (parmName.equals(EventConstants.PARM_TIMEOUT)) {
                     setTimeout(computeIntValue(parmContent));
                 } else if (parmName.equals(EventConstants.PARM_VERSION)) {
                     setVersion(parmContent);
+                } else if (parmName.equals(EventConstants.PARM_SNMP_MAX_REPETITIONS)) {
+                	setMaxRepetitions(computeIntValue(parmContent));
+                } else if (parmName.equals(EventConstants.PARM_SNMP_MAX_REQUEST_SIZE)) {
+                	setMaxRequestSize(computeIntValue(parmContent));
+                } else if (parmName.equals(EventConstants.PARM_SNMP_MAX_VARS_PER_PDU)) {
+                	setMaxVarsPerPdu(computeIntValue(parmContent));
                 } else if (parmName.equals(EventConstants.PARM_PORT)) {
                     setPort(computeIntValue(parmContent));
                 } else if (parmName.equals(EventConstants.PARM_SNMP_AUTH_PASSPHRASE)) {
     }
     
     /**
-     * <p>getCommunityString</p>
+     * Returns the read community string if there is any, otherwise null is returned.
      *
-     * @return a {@link java.lang.String} object.
+     * @return the read community string if there is any, otherwise null is returned.
+     * @deprecated use {@link #getReadCommunityString()} instead.
      */
+    @Deprecated
     public String getCommunityString() {
-        return m_communityString;
+        return getReadCommunityString();
     }
     
     /**
-     * <p>setCommunityString</p>
+     * <p>sets the read community string.</p>
      *
-     * @param communityString a {@link java.lang.String} object.
+     * @param communityString a read community string.
+     * @deprecated use {@link #setReadCommunityString(String)} instead.
      */
+    @Deprecated
     public void setCommunityString(String communityString) {
-        m_communityString = communityString;
+        setReadCommunityString(communityString);
+    }
+    
+    public void setReadCommunityString(String readCommunityString) {
+    	m_readCommunityString = readCommunityString;
+    }
+    
+    public String getReadCommunityString() {
+    	return m_readCommunityString;
+    }
+    
+    public void setWriteCommunityString(String writeCommunityString) {
+    	m_writeCommunityString = writeCommunityString;
+    }
+    
+    public String getWriteCommunityString() {
+    	return m_writeCommunityString;
     }
     
     /**
     }
     
     /**
-     * <p>getRange</p>
-     *
-     * @return a {@link org.opennms.netmgt.config.common.Range} object.
-     */
-    public Range getRange() {
-        if (isSpecific()) {
-            throw new IllegalStateException("Attempted to create range with a specific."+this);
-        }
-        Range newRange = new Range();
-        newRange.setBegin(getFirstIPAddress());
-        newRange.setEnd(getLastIPAddress());
-        return newRange;
-    }
-    /**
      * <p>getRetryCount</p>
      *
      * @return a int.
         m_port  = port;
     }
     
+    public int getMaxRequestSize() {
+    	return m_maxRequestSize;
+    }
+    
+    public void setMaxRequestSize(int maxRequestSize) {
+    	m_maxRequestSize = maxRequestSize;
+    }
+    
+    /**
+     * <p>getRange</p>
+     *
+     * @return a {@link org.opennms.netmgt.config.common.Range} object.
+     */
+    public Range getRange() {
+        if (isSpecific()) {
+            throw new IllegalStateException("Attempted to create range with a specific."+this);
+        }
+        Range newRange = new Range();
+        newRange.setBegin(getFirstIPAddress());
+        newRange.setEnd(getLastIPAddress());
+        return newRange;
+    }
+    
     /**
      * Determines if the configureSNMP event is for a specific address.
      *
         if (getPort() != 0) definition.setPort(Integer.valueOf(getPort()));
         if (getMaxRepititions() != 0) definition.setMaxRepetitions(Integer.valueOf(getMaxRepititions()));
     	if (getMaxVarsPerPdu() != 0) definition.setMaxVarsPerPdu(Integer.valueOf(getMaxVarsPerPdu()));
+    	if (getMaxRequestSize() != 0) definition.setMaxRequestSize(Integer.valueOf(getMaxRequestSize()));
     	
         // version dependend parameters
         if (getVersion() != null && getVersion().equals("v3")) {
         	if (StringUtils.isNotEmpty(getSecurityName())) definition.setSecurityName(getSecurityName());
         	if (getSecurityLevel() > 0) definition.setSecurityLevel(getSecurityLevel());
         } else { //v1, v2c or invalid version
-        	if (getCommunityString() != null) definition.setReadCommunity(getCommunityString());
+        	if (getReadCommunityString() != null) definition.setReadCommunity(getReadCommunityString());
+        	if (getWriteCommunityString() != null) definition.setWriteCommunity(getWriteCommunityString());
         }
         
         if (isSpecific()) {

opennms-config/src/main/java/org/opennms/netmgt/config/SnmpPeerFactory.java

                 }
 
             } // end DEFLOOP
-
-            if (agentConfig == null) {
-                final Definition def = new Definition();
-                setSnmpAgentConfig(agentConfig, def, requestedSnmpVersion);
-            }
-
             return agentConfig;
         } finally {
             SnmpPeerFactory.getReadLock().unlock();
         agentConfig.setPrivProtocol(determinePrivProtocol(def));
         agentConfig.setReadCommunity(determineReadCommunity(def));
         agentConfig.setWriteCommunity(determineWriteCommunity(def));
+        agentConfig.setEngineId(determineEngineId(def));
+        agentConfig.setEnterpriseId(determineEnterpriseId(def));
+        agentConfig.setContextEngineId(determineContextEngineId(def));
+        agentConfig.setContextName(determineContextName(def));
     }
     
-    /**
+	/**
      * This is a helper method to set all the common attributes in the agentConfig.
      * 
      * @param agentConfig
         return (def.getPort() == 0 ? (m_config.getPort() == 0 ? DEFAULT_SNMP_PORT : m_config.getPort()) : def.getPort());
     }
 
+    // TODO mvr
+    private String determineEngineId(Definition def) {
+    	if (def.getEngineId() != null) return def.getEngineId();
+    	if (m_config.getEngineId() != null) return m_config.getEngineId();
+    	return null;
+	}
+    
+    // TODO mvr
+    private String determineContextEngineId(Definition def) {
+    	if (def.getContextEngineId() != null) return def.getContextEngineId();
+    	if (m_config.getContextEngineId() != null) return m_config.getContextEngineId();
+    	return null;
+	}
+    
+    // TODO mvr
+    private String determineContextName(Definition def) {
+    	if (def.getContextName() != null) return def.getContextName();
+    	if (m_config.getContextName() != null) return m_config.getContextName();
+    	return null;
+	}
+    
+    // TODO mvr
+    private String determineEnterpriseId(Definition def) {
+    	if (def.getEnterpriseId() != null) return def.getEnterpriseId();
+    	if (m_config.getEnterpriseId() != null) return m_config.getEnterpriseId();
+    	return null;
+	}
+    
     /**
      * Helper method to search the snmp-config 
      * @param def

opennms-config/src/test/java/org/opennms/netmgt/config/SnmpEventInfoTest.java

 
 import static org.junit.Assert.*;
 
-import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Scanner;
-import java.util.regex.MatchResult;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.Ignore;
+
+
+
 import org.junit.Test;
 import org.opennms.netmgt.config.snmp.Definition;
-import org.opennms.netmgt.config.snmp.SnmpConfig;
 import org.opennms.netmgt.model.discovery.IPAddress;
 import org.opennms.netmgt.model.discovery.IPAddressRange;
 import org.opennms.netmgt.model.discovery.IPAddressRangeSet;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
 
 /**
  * JUnit tests for the configureSNMP event handling and optimization of
     	SnmpEventInfo snmpEventInfo = new SnmpEventInfo();
     	snmpEventInfo.setAuthPassPhrase("authPassPhrase");
     	snmpEventInfo.setAuthProtocol("authProtocol");
-    	snmpEventInfo.setCommunityString("communityString");
+    	snmpEventInfo.setReadCommunityString("readCommunityString");
+    	snmpEventInfo.setWriteCommunityString("writeCommunityString");
     	snmpEventInfo.setContextEngineId("contextEngineId");
     	snmpEventInfo.setContextName("contextName");
     	snmpEventInfo.setEngineId("engineId");
     	snmpEventInfo.setEnterpriseId("enterpriseId");
     	snmpEventInfo.setMaxRepetitions(1000);
     	snmpEventInfo.setMaxVarsPerPdu(2000);
+    	snmpEventInfo.setMaxRequestSize(7000);
     	snmpEventInfo.setPort(3000);
     	snmpEventInfo.setPrivPassPhrase("privPassPhrase");
     	snmpEventInfo.setPrivProtocol("privProtocol");
     	snmpEventInfo.setTimeout(6000);
     	snmpEventInfo.setVersion("v1");
     	
-    	// check v1 properties
+    	// check v1/commons properties
     	Definition def = snmpEventInfo.createDef();
-    	assertEquals(snmpEventInfo.getCommunityString(), def.getReadCommunity());
+    	assertEquals(snmpEventInfo.getReadCommunityString(), def.getReadCommunity());
     	assertEquals(snmpEventInfo.getMaxRepititions(), def.getMaxRepetitions().intValue());
     	assertEquals(snmpEventInfo.getMaxVarsPerPdu(), def.getMaxVarsPerPdu().intValue());
     	assertEquals(snmpEventInfo.getPort(), def.getPort().intValue());
     	assertEquals(snmpEventInfo.getRetryCount(), def.getRetry().intValue());
     	assertEquals(snmpEventInfo.getTimeout(), def.getTimeout().intValue());
     	assertEquals(snmpEventInfo.getVersion(), def.getVersion());
+    	assertEquals(snmpEventInfo.getMaxRequestSize(), def.getMaxRequestSize().intValue());
+    	assertEquals(snmpEventInfo.getWriteCommunityString(), def.getWriteCommunity());
     	    	
     	// v3 properties must not be set
     	assertNull(def.getAuthPassphrase());
     	SnmpEventInfo snmpEventInfo = new SnmpEventInfo();
     	snmpEventInfo.setAuthPassPhrase("authPassPhrase");
     	snmpEventInfo.setAuthProtocol("authProtocol");
-    	snmpEventInfo.setCommunityString("communityString");
+    	snmpEventInfo.setReadCommunityString("communityString");
+    	snmpEventInfo.setWriteCommunityString("writeCommunityString");
     	snmpEventInfo.setContextEngineId("contextEngineId");
     	snmpEventInfo.setContextName("contextName");
     	snmpEventInfo.setEngineId("engineId");
     	snmpEventInfo.setEnterpriseId("enterpriseId");
     	snmpEventInfo.setMaxRepetitions(1000);
     	snmpEventInfo.setMaxVarsPerPdu(2000);
+    	snmpEventInfo.setMaxRequestSize(7000);
     	snmpEventInfo.setPort(3000);
     	snmpEventInfo.setPrivPassPhrase("privPassPhrase");
     	snmpEventInfo.setPrivProtocol("privProtocol");
     	snmpEventInfo.setTimeout(6000);
     	snmpEventInfo.setVersion("v3");
     	
-    	// check v3 propertiess
+    	// check v3/commons propertiess
     	Definition def = snmpEventInfo.createDef();
     	assertEquals(snmpEventInfo.getAuthPassprase(), def.getAuthPassphrase());
     	assertEquals(snmpEventInfo.getAuthProtcol(), def.getAuthProtocol());
     	assertEquals(snmpEventInfo.getPrivProtocol(), def.getPrivacyProtocol());
     	assertEquals(snmpEventInfo.getMaxRepititions(), def.getMaxRepetitions().intValue());
     	assertEquals(snmpEventInfo.getMaxVarsPerPdu(), def.getMaxVarsPerPdu().intValue());
+    	assertEquals(snmpEventInfo.getMaxRequestSize(), def.getMaxRequestSize().intValue());
     	assertEquals(snmpEventInfo.getPort(), def.getPort().intValue());
     	assertEquals(snmpEventInfo.getRetryCount(), def.getRetry().intValue());
     	assertEquals(snmpEventInfo.getTimeout(), def.getTimeout().intValue());
         assertEquals(snmpConfigXml, SnmpPeerFactory.marshallConfig());
         
         SnmpEventInfo info = new SnmpEventInfo();
-        info.setCommunityString("abc");
+        info.setReadCommunityString("abc");
         info.setFirstIPAddress("192.168.0.5");
         
         SnmpPeerFactory.getInstance().define(info);
         assertEquals(snmpConfigXml, SnmpPeerFactory.marshallConfig());
         
         SnmpEventInfo info = new SnmpEventInfo();
-        info.setCommunityString("abc");
+        info.setReadCommunityString("abc");
         info.setFirstIPAddress("2001:db8::10");
         
         SnmpPeerFactory.getInstance().define(info);
 
           SnmpEventInfo info = new SnmpEventInfo();
           info.setVersion("v2c");
+          info.setTimeout(800);
           info.setFirstIPAddress("192.168.0.8");
           
           SnmpPeerFactory.getInstance().define(info);
         String actualConfig = SnmpPeerFactory.marshallConfig();
         assertEquals(expectedConfig, actualConfig);
     }
-
-    /**
-     * Test method for {@link org.opennms.netmgt.config.SnmpEventInfo#optimizeAllDefs()}.
-     * @throws ValidationException 
-     * @throws MarshalException 
-     * @throws IOException 
-     */
-    @Test
-    @Ignore("This is no longer really valid since we don't have to optimize in a separate pass")
-    public final void testOptimizeAllDefs() throws IOException {
-        
-        String snmpConfigXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + 
-        "<snmp-config retry=\"3\" timeout=\"800\" read-community=\"public\" write-community=\"private\" xmlns=\"http://xmlns.opennms.org/xsd/config/snmp\">\n" + 
-        "    <definition version=\"v2c\">\n" + 
-        "        <specific>192.168.0.5</specific>\n" + 
-        "    </definition>\n" + 
-        "    <definition read-community=\"opennmsrules\">\n" + 
-        "        <range begin=\"192.168.100.1\" end=\"192.168.100.254\"/>\n" + 
-        "        <range begin=\"192.168.101.1\" end=\"192.168.101.254\"/>\n" + 
-        "        <range begin=\"192.168.102.1\" end=\"192.168.102.254\"/>\n" + 
-        "        <range begin=\"192.168.103.1\" end=\"192.168.103.254\"/>\n" + 
-        "        <range begin=\"192.168.104.1\" end=\"192.168.104.254\"/>\n" + 
-        "        <range begin=\"192.168.105.1\" end=\"192.168.105.254\"/>\n" + 
-        "        <range begin=\"192.168.106.1\" end=\"192.168.106.254\"/>\n" + 
-        "        <range begin=\"192.168.107.1\" end=\"192.168.107.254\"/>\n" + 
-        "        <range begin=\"192.168.0.1\" end=\"192.168.0.10\"/>\n" + 
-        "    </definition>\n" + 
-        "    <definition read-community=\"opennmsrules2\">\n" + 
-        "        <range begin=\"192.168.100.0\" end=\"192.168.100.255\"/>\n" + 
-        "        <range begin=\"192.168.101.0\" end=\"192.168.101.255\"/>\n" + 
-        "        <range begin=\"192.168.102.0\" end=\"192.168.102.255\"/>\n" + 
-        "        <range begin=\"192.168.103.0\" end=\"192.168.103.255\"/>\n" + 
-        "        <range begin=\"192.168.104.0\" end=\"192.168.104.255\"/>\n" + 
-        "        <range begin=\"192.168.105.0\" end=\"192.168.105.255\"/>\n" + 
-        "        <range begin=\"192.168.106.0\" end=\"192.168.106.255\"/>\n" + 
-        "        <range begin=\"192.168.107.0\" end=\"192.168.107.255\"/>\n" + 
-        "        <range begin=\"192.168.0.1\" end=\"192.168.0.10\"/>\n" + 
-        "    </definition>\n" + 
-        "    <definition read-community=\"splice-test\" version=\"v2c\">\n" + 
-        "        <range begin=\"10.1.2.1\" end=\"10.1.2.100\"/>\n" + 
-        "        <range begin=\"11.1.2.1\" end=\"11.1.2.100\"/>\n" + 
-        "        <range begin=\"12.1.2.1\" end=\"12.1.2.100\"/>\n" + 
-        "        <specific>10.1.1.1</specific>\n" + 
-        "        <specific>10.1.1.2</specific>\n" + 
-        "        <specific>10.1.1.3</specific>\n" + 
-        "        <specific>10.1.1.5</specific>\n" + 
-        "        <specific>10.1.1.6</specific>\n" + 
-        "        <specific>10.1.1.10</specific>\n" + 
-        "    </definition>\n" + 
-        "    <definition read-community=\"splice2-test\">\n" + 
-        "        <range begin=\"10.1.1.11\" end=\"10.1.1.100\"/>\n" + 
-        "        <range begin=\"11.1.2.1\" end=\"11.1.2.100\"/>\n" + 
-        "        <range begin=\"12.1.2.1\" end=\"12.1.2.100\"/>\n" + 
-        "        <specific>10.1.1.10</specific>\n" + 
-        "    </definition>\n" + 
-        "    <definition read-community=\"splice3-test\">\n" + 
-        "        <range begin=\"10.1.1.11\" end=\"10.1.1.100\"/>\n" + 
-        "        <range begin=\"11.1.2.1\" end=\"11.1.2.1\"/>\n" + 
-        "        <range begin=\"12.1.2.1\" end=\"12.1.2.1\"/>\n" + 
-        "        <specific>10.1.1.10</specific>\n" + 
-        "        <specific>10.1.1.12</specific>\n" + 
-        "    </definition>\n" + 
-        "</snmp-config>\n" + 
-        "";
-        
- 
-        String expectedConfig = 
-        "<?xml version=\"1.0\" encoding=\"UTF-8\"?> standalone=\"yes\"\n" + 
-        "<snmp-config retry=\"3\" timeout=\"800\" read-community=\"public\" write-community=\"private\" xmlns=\"http://xmlns.opennms.org/xsd/config/snmp\">\n" + 
-        "    <definition version=\"v2c\">\n" + 
-        "        <specific>192.168.0.5</specific>\n" + 
-        "    </definition>\n" + 
-        "    <definition read-community=\"opennmsrules\">\n" + 
-        "        <range begin=\"192.168.0.1\" end=\"192.168.0.10\"/>\n" + 
-        "        <range begin=\"192.168.100.1\" end=\"192.168.100.254\"/>\n" + 
-        "        <range begin=\"192.168.101.1\" end=\"192.168.101.254\"/>\n" + 
-        "        <range begin=\"192.168.102.1\" end=\"192.168.102.254\"/>\n" + 
-        "        <range begin=\"192.168.103.1\" end=\"192.168.103.254\"/>\n" + 
-        "        <range begin=\"192.168.104.1\" end=\"192.168.104.254\"/>\n" + 
-        "        <range begin=\"192.168.105.1\" end=\"192.168.105.254\"/>\n" + 
-        "        <range begin=\"192.168.106.1\" end=\"192.168.106.254\"/>\n" + 
-        "        <range begin=\"192.168.107.1\" end=\"192.168.107.254\"/>\n" + 
-        "    </definition>\n" + 
-        "    <definition read-community=\"opennmsrules2\">\n" + 
-        "        <range begin=\"192.168.0.1\" end=\"192.168.0.10\"/>\n" + 
-        "        <range begin=\"192.168.100.0\" end=\"192.168.107.255\"/>\n" + 
-        "    </definition>\n" + 
-        "    <definition read-community=\"splice-test\" version=\"v2c\">\n" + 
-        "        <range begin=\"10.1.1.1\" end=\"10.1.1.3\"/>\n" + 
-        "        <range begin=\"10.1.1.5\" end=\"10.1.1.6\"/>\n" + 
-        "        <range begin=\"10.1.2.1\" end=\"10.1.2.100\"/>\n" + 
-        "        <range begin=\"11.1.2.1\" end=\"11.1.2.100\"/>\n" + 
-        "        <range begin=\"12.1.2.1\" end=\"12.1.2.100\"/>\n" + 
-        "        <specific>10.1.1.10</specific>\n" + 
-        "    </definition>\n" + 
-        "    <definition read-community=\"splice2-test\">\n" + 
-        "        <range begin=\"10.1.1.10\" end=\"10.1.1.100\"/>\n" + 
-        "        <range begin=\"11.1.2.1\" end=\"11.1.2.100\"/>\n" + 
-        "        <range begin=\"12.1.2.1\" end=\"12.1.2.100\"/>\n" + 
-        "    </definition>\n" + 
-        "    <definition read-community=\"splice3-test\">\n" + 
-        "        <range begin=\"10.1.1.10\" end=\"10.1.1.100\"/>\n" + 
-        "        <specific>11.1.2.1</specific>\n" + 
-        "        <specific>12.1.2.1</specific>\n" + 
-        "    </definition>\n" + 
-        "</snmp-config>\n" + 
-        "";
-
-        SnmpPeerFactory.setInstance(new SnmpPeerFactory(snmpConfigXml));
-        
-        assertEquals(snmpConfigXml, SnmpPeerFactory.marshallConfig());
-
-        SnmpEventInfo info = new SnmpEventInfo();
-        
-        SnmpConfig config = SnmpPeerFactory.getSnmpConfig();
-        assertEquals(6, config.getDefinitionCount());
-        
-        info.setCommunityString("opennmsrules2");
-        
-        //do bunch more...
-        
-        new SnmpConfigManager(config).optimizeAllDefs();
-//      String config = SnmpPeerFactory.marshallConfig();
-//      System.err.println(config);
-        
-        String actualConfig = SnmpPeerFactory.marshallConfig();
-        assertEquals(expectedConfig, actualConfig);
-        
-
-    }
-    
-    @Test
-    @Ignore
-    public void testAddSpecificToBigFile() throws Exception {
-        Resource res = new FileSystemResource("/Users/brozow/big-snmp-config.xml");
-        
-        SnmpPeerFactory.setInstance(new SnmpPeerFactory(res));
-
-        
-        SnmpEventInfo info = new SnmpEventInfo();
-        info.setCommunityString("th3l04n3r");
-        info.setFirstIPAddress("192.168.1.15");
-        info.setLastIPAddress("192.168.1.35");
-        
-        SnmpPeerFactory.getInstance().define(info);
-
-        String actualConfig = SnmpPeerFactory.marshallConfig();
-        System.err.println(actualConfig);
-        //assertEquals(expectedConfig, actualConfig);
-        
-
-    }
-
-    @Test
-    @Ignore
-    public void testConfigTheHeckOutOfIt() throws Exception {
-        Resource configResource = new FileSystemResource("/Users/brozow/big-snmp-config.xml");
-        Resource events = new FileSystemResource("/Users/brozow/support/NEN/palin/wave-events.txt");
-        File configDir = new File("/Users/brozow/support/NEN/palin/configs");
-        configDir.mkdirs();
-        
-        SnmpEventInfo[] updates = readEventInfo(events.getInputStream());
-        assertNotNull(updates);
-
-        SnmpPeerFactory.setInstance(new SnmpPeerFactory(configResource));
-
-        
-        int index = 0;
-        for (SnmpEventInfo update : updates) {
-            try {
-                File dir = new File(configDir, String.format("%03d", index));
-                dir.mkdirs();
-                SnmpPeerFactory.saveToFile(new File(dir, "pre-config.xml"));
-                SnmpPeerFactory.getInstance().define(update);
-                File saveUpdate = new File(dir, "update");
-                FileUtils.writeStringToFile(saveUpdate, String.format("%s %s %s\n", update.getFirstIPAddress(), update.getLastIPAddress(), update.getCommunityString()));
-                SnmpPeerFactory.saveToFile(new File(dir, "post-config.xml"));
-            } catch (Exception e) {
-                e.printStackTrace();
-                fail(String.format("Applying update with index %d change community string for %s  to %s failed.", index, update.getFirstIPAddress(), update.getCommunityString()));
-            }
-            index++;
-        }
-
-        String actualConfig = SnmpPeerFactory.marshallConfig();
-        System.err.println(actualConfig);
-        //assertEquals(expectedConfig, actualConfig);
-        
-
-    }
-    
-    private SnmpEventInfo[] readEventInfo(InputStream in) throws UnknownHostException {
-        List<SnmpEventInfo> updates = new ArrayList<SnmpEventInfo>(500);
-        Scanner s = new Scanner(in);
-        int lineCount = 0;
-        while(s.hasNextLine()) {
-            lineCount++;
-            s.findInLine("\\s*firstIPAddress=([0-9.]+) communityString=([^ ]*) lastIPAddress=([0-9.]+)\\s*");
-            MatchResult result = s.match();
-            System.out.printf("%d: %s - %s: %s\n", lineCount, result.group(1), result.group(3), result.group(2));
-            SnmpEventInfo info = new SnmpEventInfo();
-            info.setFirstIPAddress(result.group(1));
-            info.setLastIPAddress(result.group(3));
-            info.setCommunityString(result.group(2));
-            updates.add(info);
-            s.nextLine();
-        }
-        s.close();
-        return updates.toArray(new SnmpEventInfo[0]);
-
-    }
 }

opennms-model/src/main/java/org/opennms/netmgt/EventConstants.java

     // TODO mvr
     public final static String PARM_SNMP_PRIVACY_PROTOCOL = "privProtocol";
     
+    // TODO mvr
+    public final static String PARM_SNMP_MAX_REPETITIONS = "maxRepetitions";
+    
+    // TODO mvr
+    public final static String PARM_SNMP_MAX_REQUEST_SIZE = "maxRequestSize";
+    
+    // TODO mvr
+    public final static String PARM_SNMP_MAX_VARS_PER_PDU = "maxVarsPerPdu";
+    
     /**
      * The first IP address in a range of IP addresses when sent as an event
      * parm.
     public final static String PARM_LAST_IP_ADDRESS = "lastIPAddress";
 
     /**
-     * The SNMP community string when sent as an event parm.
+     * The SNMP read community string when sent as an event parm.
+     * @deprecated use {@link #PARM_SNMP_READ_COMMUNITY_STRING} instead
      */
+    @Deprecated
     public final static String PARM_COMMUNITY_STRING = "communityString";
+    
+    /**
+     * The SNMP read community string when sent as an event parm.
+     */
+    public final static String PARM_SNMP_READ_COMMUNITY_STRING = "readCommunityString";
+    
+    /**
+     * The SNMP write community string when sent as an event parm.
+     */
+    public final static String PARM_SNMP_WRITE_COMMUNITY_STRING = "writeCommunityString";
 
     /**
      * Service monitor qualifier when sent as an event parm

opennms-webapp/src/main/java/org/opennms/web/snmpinfo/SnmpInfo.java

 
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
 import org.opennms.netmgt.config.SnmpEventInfo;
 import org.opennms.netmgt.snmp.SnmpAgentConfig;
-import org.opennms.netmgt.snmp.SnmpConfiguration;
 
 /**
  * <p>
  */
 @XmlRootElement(name = "snmp-info")
 public class SnmpInfo {
-	private String m_community;
+	private String m_readCommunity;
 	private String m_version;
 	private int m_port;
 	private int m_retries;
 	private int m_timeout;
 	private int m_maxVarsPerPdu;
 	private int m_maxRepetitions;
-
 	private String m_securityName;
 	private Integer m_securityLevel;
 	private String m_authPassPhrase;
 	private String m_contextEngineId;
 	private String m_contextName;
 	private String m_enterpriseId;
-
+	private Integer m_maxRequestSize;
+	private String m_writeCommunity;
+	
 	/**
 	 * <p>
 	 * Constructor for SnmpInfo.
 		m_version = config.getVersionAsString();
 		m_maxRepetitions = config.getMaxRepetitions();
 		m_maxVarsPerPdu = config.getMaxVarsPerPdu();
+		m_maxRequestSize = Integer.valueOf(config.getMaxRequestSize());
 
 		// only set these properties if snmp version is v3
 		if (config.isVersion3()) {
 			m_securityName = config.getSecurityName();
-			m_securityLevel = config.getSecurityLevel();
+			m_securityLevel = Integer.valueOf(config.getSecurityLevel());
 			m_authPassPhrase = config.getAuthPassPhrase();
 			m_authProtocol = config.getAuthProtocol();
 			m_privPassPhrase = config.getPrivPassPhrase();
 			m_contextName = config.getContextName();
 			m_enterpriseId = config.getEnterpriseId();
 		} else { // can only be set if snmp version is not v3
-			m_community = config.getReadCommunity();
+			m_readCommunity = config.getReadCommunity();
+			m_writeCommunity = config.getWriteCommunity();
 		}
 	}
 
 	 * getCommunity
 	 * </p>
 	 * 
-	 * @return the community
+	 * @return the read community string
+	 * @deprecated use {@link #getReadCommunity()} instead.
 	 */
+	@Deprecated
 	public String getCommunity() {
-		return m_community;
+		return getReadCommunity();
 	}
 
 	/**
 	 * </p>
 	 * 
 	 * @param community
-	 *            the community to set
+	 *            the read community string to set
+	 * @deprecated use {@link #setReadCommunity(String)} instead.
 	 */
+	@Deprecated
 	public void setCommunity(String community) {
-		m_community = community;
+		setReadCommunity(community);
 	}
 
 	/**
 		return m_version;
 	}
 
-	/**
-	 * <p>
-	 * Sets the field {@link #m_version}. Be aware that v3 attributes (e.g.
-	 * {@link #m_engineId} will be set to null if version is v1 or v2c. The
-	 * community string is set to null if version is v3.
-	 * </p>
-	 * 
-	 * @param version
-	 *            the version to set.
-	 */
 	public void setVersion(String version) {
 		m_version = version;
-		// if v3, there cannot be a community string
-		if (SnmpConfiguration.VERSION3 == SnmpConfiguration.stringToVersion(version)) {
-			setCommunity(null);
-		} else { // reset all v3 parameters
-			setAuthPassPhrase(null);
-			setAuthProtocol(null);
-			setContextEngineId(null);
-			setContextName(null);
-			setEngineId(null);
-			setEnterpriseId(null);
-			setPrivPassPhrase(null);
-			setPrivProtocol(null);
-			setSecurityLevel(-1);
-			setSecurityName(null);
-		}
 	}
 
 	/**
 	public String getEnterpriseId() {
 		return m_enterpriseId;
 	}
+	
+	public String getReadCommunity() {
+		return m_readCommunity;
+	}
+	
+	public void setReadCommunity(String readCommunity) {
+		m_readCommunity = readCommunity;
+	}
 
+	public String getWriteCommunity() {
+		return m_writeCommunity;
+	}
+	
+	public void setWriteCommunity(String writeCommunity) {
+		m_writeCommunity = writeCommunity;
+	}
+	
+	public Integer getMaxRequestSize() {
+		return m_maxRequestSize;
+	}
+	
+	public void setMaxRequestSize(Integer maxRequestSize) {
+		m_maxRequestSize = maxRequestSize;
+	}
+	
 	@Override
 	public boolean equals(Object obj) {
 		return EqualsBuilder.reflectionEquals(this, obj);
 		return HashCodeBuilder.reflectionHashCode(this);
 	}
 
+	@Override
+	public String toString() {
+		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+	}
+	
 	/**
 	 * <p>
 	 * createEventInfo
 		SnmpEventInfo eventInfo = new SnmpEventInfo();
 		eventInfo.setAuthPassPhrase(m_authPassPhrase);
 		eventInfo.setAuthProtocol(m_authProtocol);
-		eventInfo.setCommunityString(m_community);
+		eventInfo.setReadCommunityString(m_readCommunity);
+		eventInfo.setWriteCommunityString(m_writeCommunity);
 		eventInfo.setContextEngineId(m_contextEngineId);
 		eventInfo.setContextName(m_contextName);
 		eventInfo.setEngineId(m_engineId);
 		eventInfo.setPrivPassPhrase(m_privPassPhrase);
 		eventInfo.setPrivProtocol(m_privProtocol);
 		eventInfo.setRetryCount(m_retries);
-		if (m_securityLevel != null) eventInfo.setSecurityLevel(m_securityLevel.intValue());
 		eventInfo.setSecurityName(m_securityName);
 		eventInfo.setTimeout(m_timeout);
 		eventInfo.setVersion(m_version);
+		if (m_securityLevel != null) eventInfo.setSecurityLevel(m_securityLevel.intValue());
+		if (m_maxRequestSize != null) eventInfo.setMaxRequestSize(m_maxRequestSize.intValue());
 		return eventInfo;
 	}
 }

opennms-webapp/src/test/java/org/opennms/web/rest/SnmpConfigRestServiceTest.java

 		// change values
 		config.setAuthPassPhrase("authPassPhrase");
 		config.setAuthProtocol("authProtocol");
-		config.setCommunity("community");
+		config.setReadCommunity("readCommunity");
+		config.setWriteCommunity("writeCommunity");
 		config.setContextEngineId("contextEngineId");
 		config.setContextName("contextName");
 		config.setEngineId("engineId");
 		config.setSecurityName("securityName");
 		config.setTimeout(6000);
 		config.setVersion("v2c");
+		config.setMaxRequestSize(7000);
 
 		// store them via REST
 		putXmlObject(m_jaxbContext, url, 303, config, "/snmpConfig/1.1.1.1");
 
-		/*
-		 * 1. Check the data in file.
-		 * The data in the file may be invalid (e.g. readCommunity-String in a v3-config) 
-		 */
-		// read data from file
-		SnmpAgentConfig snmpAgentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("1.1.1.1"));
-		assertConfiguration(config, snmpAgentConfig);
+		// prepare expected Result
+		expectedConfig = new SnmpInfo();
+		expectedConfig.setMaxRepetitions(1000);
+		expectedConfig.setMaxVarsPerPdu(2000);
+		expectedConfig.setPort(3000);
+		expectedConfig.setRetries(4000);
+		expectedConfig.setTimeout(6000);
+		expectedConfig.setVersion("v2c");
+		expectedConfig.setMaxRequestSize(7000);
+		expectedConfig.setReadCommunity("readCommunity");
+		expectedConfig.setWriteCommunity("writeCommunity");
+		expectedConfig.setAuthPassPhrase(null);
+		expectedConfig.setAuthProtocol(null);
+		expectedConfig.setContextEngineId(null);
+		expectedConfig.setContextName(null);
+		expectedConfig.setEngineId(null);
+		expectedConfig.setEnterpriseId(null);
+		expectedConfig.setPrivPassPhrase(null);
+		expectedConfig.setPrivProtocol(null);
+		expectedConfig.setSecurityLevel(-1);
+		expectedConfig.setSecurityName(null);
 		
-		/*
-		 * 2. Check the data via REST. 
-		 * The data via REST only returns parameters which are valid according to 
-		 * the snmp version. 
-		 */
 		// read via REST
 		SnmpInfo newConfig = getXmlObject(m_jaxbContext, url, 200, SnmpInfo.class);
 		
 		// check ...
-		assertConfiguration(config, newConfig); // ... if Changes were made
-		assertSnmpV3PropertiesHaveNotBeenSet(newConfig); // ... that no v3 parameters were set
-
+		assertConfiguration(expectedConfig, newConfig); // ... if Changes were made
 		dumpConfig();
 	}
 	
 		String url = "/snmpConfig/1.1.1.1";
 
 		// Testing GET Collection
-		SnmpInfo config = getXmlObject(m_jaxbContext, url, 200, SnmpInfo.class);
+		SnmpInfo changedConfig = getXmlObject(m_jaxbContext, url, 200, SnmpInfo.class);
 		SnmpInfo expectedConfig = createSnmpInfoWithDefaultsForSnmpV3("1.1.1.1");
-		assertConfiguration(expectedConfig, config); // check if expected defaults matches actual defaults
+		assertConfiguration(expectedConfig, changedConfig); // check if expected defaults matches actual defaults
 		
 		// change values
-		config.setAuthPassPhrase("authPassPhrase");
-		config.setAuthProtocol("authProtocol");
-		config.setCommunity("community");
-		config.setContextEngineId("contextEngineId");
-		config.setContextName("contextName");
-		config.setEngineId("engineId");
-		config.setEnterpriseId("enterpriseId");
-		config.setMaxRepetitions(1000);
-		config.setMaxVarsPerPdu(2000);
-		config.setPort(3000);
-		config.setPrivPassPhrase("privPassPhrase");
-		config.setPrivProtocol("privProtocol");
-		config.setRetries(4000);
-		config.setSecurityLevel(5000);
-		config.setSecurityName("securityName");
-		config.setTimeout(6000);
-		config.setVersion("v3");
+		changedConfig.setAuthPassPhrase("authPassPhrase");
+		changedConfig.setAuthProtocol("authProtocol");
+		changedConfig.setReadCommunity("readCommunity");
+		changedConfig.setWriteCommunity("writeCommunity");
+		changedConfig.setContextEngineId("contextEngineId");
+		changedConfig.setContextName("contextName");
+		changedConfig.setEngineId("engineId");
+		changedConfig.setEnterpriseId("enterpriseId");
+		changedConfig.setMaxRepetitions(1000);
+		changedConfig.setMaxVarsPerPdu(2000);
+		changedConfig.setPort(3000);
+		changedConfig.setPrivPassPhrase("privPassPhrase");
+		changedConfig.setPrivProtocol("privProtocol");
+		changedConfig.setRetries(4000);
+		changedConfig.setSecurityLevel(5000);
+		changedConfig.setSecurityName("securityName");
+		changedConfig.setTimeout(6000);
+		changedConfig.setVersion("v3");
+		changedConfig.setMaxRequestSize(7000);
 
 		// store them via REST
-		putXmlObject(m_jaxbContext, url, 303, config, "/snmpConfig/1.1.1.1");
-
-		/*
-		 * 1. Check the data in file.
-		 * The data in the file may be invalid (e.g. readCommunity-String in a v3-config) 
-		 */
-		// read data from file
-		SnmpAgentConfig snmpAgentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("1.1.1.1"));
-		assertConfiguration(config, snmpAgentConfig);
+		putXmlObject(m_jaxbContext, url, 303, changedConfig, "/snmpConfig/1.1.1.1");
+		
+		// prepare expected Result
+		expectedConfig = new SnmpInfo();
+		expectedConfig.setAuthPassPhrase("authPassPhrase");
+		expectedConfig.setAuthProtocol("authProtocol");
+		expectedConfig.setContextEngineId("contextEngineId");
+		expectedConfig.setContextName("contextName");
+		expectedConfig.setEngineId("engineId");
+		expectedConfig.setEnterpriseId("enterpriseId");
+		expectedConfig.setMaxRepetitions(1000);
+		expectedConfig.setMaxVarsPerPdu(2000);
+		expectedConfig.setPort(3000);
+		expectedConfig.setPrivPassPhrase("privPassPhrase");
+		expectedConfig.setPrivProtocol("privProtocol");
+		expectedConfig.setRetries(4000);
+		expectedConfig.setSecurityLevel(5000);
+		expectedConfig.setSecurityName("securityName");
+		expectedConfig.setTimeout(6000);
+		expectedConfig.setVersion("v3");
+		expectedConfig.setMaxRequestSize(7000);
+		expectedConfig.setReadCommunity(null);
+		expectedConfig.setWriteCommunity(null);
 		
-		/*
-		 * 2. Check the data via REST. 
-		 * The data via REST only returns parameters which are valid according to 
-		 * the snmp version. 
-		 */
 		// read via REST
 		SnmpInfo newConfig = getXmlObject(m_jaxbContext, url, 200, SnmpInfo.class);
 		
 		// check ...
-		assertConfiguration(config, newConfig); // ... if Changes were made
-		assertSnmpV1PropertiesHaveNotBeenSet(newConfig); // ... that no v3 parameters were set
+		assertConfiguration(expectedConfig, newConfig); // ... if changes were made
 
 		dumpConfig();
 	}
 
 	private SnmpInfo createSnmpInfoWithDefaultsForSnmpV3(final String ipAddress) {
 		SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(ipAddress));
-		SnmpInfo config = new SnmpInfo(agentConfig);
-		return config;
+		return new SnmpInfo(agentConfig);
 	}
 	
 	private SnmpInfo createSnmpInfoWithDefaultsForSnmpV1() {
+		SnmpAgentConfig defaults = new SnmpAgentConfig();
 		SnmpInfo config = new SnmpInfo();
 		config.setPort(DEFAULT_PORT);
 		config.setRetries(DEFAULT_RETRIES);
 		config.setTimeout(DEFAULT_TIMEOUT);
-		config.setCommunity(DEFAULT_COMMUNITY);
+		config.setReadCommunity(DEFAULT_COMMUNITY);
 		config.setVersion(DEFAULT_VERSION);
 		config.setMaxVarsPerPdu(DEFAULT_MAX_VARS_PER_PDU);
 		config.setMaxRepetitions(DEFAULT_MAX_REPETITIONS);
+		// defaults are not set via snmp-config.xml, but via defaults in SnmpAgentConfig
+		config.setWriteCommunity(defaults.getWriteCommunity());
+		config.setMaxRequestSize(defaults.getMaxRequestSize());
 		return config;
 	}
-	
-	private void assertConfiguration(SnmpInfo configLeft, SnmpAgentConfig configRight) {
-		assertEquals(configLeft.getAuthPassPhrase(), configRight.getAuthPassPhrase());
-		assertEquals(configLeft.getAuthProtocol(), configRight.getAuthProtocol());
-		assertEquals(configLeft.getCommunity(), configRight.getReadCommunity());
-		assertEquals(configLeft.getContextEngineId(), configRight.getContextEngineId());
-		assertEquals(configLeft.getContextName(), configRight.getContextEngineId());
-		assertEquals(configLeft.getEngineId(), configRight.getEngineId());
-		assertEquals(configLeft.getEnterpriseId(), configRight.getEnterpriseId());
-		assertEquals(configLeft.getMaxRepetitions(), configRight.getMaxRepetitions());
-		assertEquals(configLeft.getMaxVarsPerPdu(), configRight.getMaxVarsPerPdu());
-		assertEquals(configLeft.getPort(), configRight.getPort());
-		assertEquals(configLeft.getPrivPassPhrase(), configRight.getPrivPassPhrase());
-		assertEquals(configLeft.getPrivProtocol(), configRight.getPrivProtocol());
-		assertEquals(configLeft.getRetries(), configRight.getRetries());
-		assertEquals(configLeft.getSecurityLevel(), configRight.getSecurityLevel());
-		assertEquals(configLeft.getSecurityName(), configRight.getSecurityName());
-		assertEquals(configLeft.getTimeout(), configRight.getTimeout());
-		assertEquals(configLeft.getVersion(), configRight.getVersionAsString());
-	}
-	
+		
 	private void assertConfiguration(SnmpInfo expectedConfig, SnmpInfo actualConfig) {
 		assertNotNull(expectedConfig);
 		assertNotNull(actualConfig);
 	 * @param config
 	 */
 	private void assertSnmpV1PropertiesHaveNotBeenSet(SnmpInfo config) {
-		assertEquals(null, config.getCommunity()); // community String must be null !
+		assertEquals(null, config.getReadCommunity()); // community String must be null !
+		assertEquals(null, config.getWriteCommunity());
 	}
 }