[SNMP4J] V2c error codes

Frank Fock fock at agentpp.com
Wed Apr 25 23:05:27 CEST 2007


Hi Nidhin,

Although there is no clear evidence whether the current MOScalar
behavior violates RFC 3416 (in section 4.2.1) or not:

    (2)   Otherwise, if the variable binding's name does not have an
          OBJECT IDENTIFIER prefix which exactly matches the OBJECT
          IDENTIFIER prefix of any (potential) variable accessible by
          this request, then its value field is set to "noSuchObject".

    (3)   Otherwise, the variable binding's value field is set to
          "noSuchInstance".

I think it does and thus I changed MOScalar as indicated below.
It seems to fix it. Please try it out. You can also download the
latest snapshot from http://oosnmp.com/~katz/snapshot/
in a few hours.

Best regards,
Frank


@@ -40,6 +40,7 @@
      SerializableManagedObject {

    private OID oid;
+  private volatile OID upperBound;
    private Variable value;
    private MOAccess access;
    private boolean isVolatile;
@@ -80,12 +81,35 @@
      }
    }

+  /**
+   * Returns the scope of OIDs that are covered by this scalar's object
+   * registration. This range is
+   * <code>1.3.6...n</code> <= x <  <code>1.3.6...n+1</code> where n is the
+   * last subidentifier of the OID registred by the corresponding 
OBJECT-TYPE
+   * definition. Prior to version 1.1.2, this method returned a scope equal
+   * to the scope now returned by {@link #getSingleInstanceScope()}.
+   *
+   * @return
+   *    a MOScope that covers the OIDs by this scalar object registration.
+   */
    public MOScope getScope() {
      return this;
    }

+  /**
+   * Returns a scope that covers only the scalar instance itself 
without any
+   * possible OIDs down in the tree.
+   * @return
+   *    a scope that covers exactly the OID of this scalar.
+   * @since 1.1.2
+   */
+  public MOScope getSingleInstanceScope() {
+    return new DefaultMOScope(oid, true, oid, true);
+  }
+
    public OID find(MOScope range) {
-    if (access.isAccessibleForRead() && range.isCovered(this)) {
+    if (access.isAccessibleForRead() &&
+        range.isCovered(getSingleInstanceScope())) {
        return oid;
      }
      return null;
@@ -93,19 +117,33 @@

    public void get(SubRequest request) {
      RequestStatus status = request.getStatus();
-    if (access.isAccessibleForRead()) {
+    if (checkRequestScope(request)) {
+      if (access.isAccessibleForRead()) {
+        VariableBinding vb = request.getVariableBinding();
+        vb.setOid(getOid());
+        vb.setVariable((Variable) getValue().clone());
+        request.completed();
+      }
+      else {
+        status.setErrorStatus(SnmpConstants.SNMP_ERROR_NO_ACCESS);
+      }
+    }
+  }
+
+  private boolean checkRequestScope(SubRequest request) {
+    if (!request.getVariableBinding().getOid().equals(oid)) {
        VariableBinding vb = request.getVariableBinding();
        vb.setOid(getOid());
-      vb.setVariable((Variable)getValue().clone());
+      vb.setVariable(Null.noSuchInstance);
        request.completed();
+      return false;
      }
-    else {
-      status.setErrorStatus(SnmpConstants.SNMP_ERROR_NO_ACCESS);
-    }
+    return true;
    }

    public boolean next(SubRequest request) {
-    if (access.isAccessibleForRead() && 
(request.getScope().isCovered(this))) {
+    if (access.isAccessibleForRead() &&
+        (request.getScope().isCovered(getSingleInstanceScope()))) {
        VariableBinding vb = request.getVariableBinding();
        vb.setOid(getOid());
        vb.setVariable((Variable)getValue().clone());
@@ -141,7 +179,8 @@

    public void prepare(SubRequest request) {
      RequestStatus status = request.getStatus();
-    if (access.isAccessibleForWrite()) {
+    if ((access.isAccessibleForWrite()) &&
+        (oid.equals(request.getVariableBinding().getOid()))) {
        VariableBinding vb = request.getVariableBinding();
        if (vb.getVariable().getSyntax() != getValue().getSyntax()) {
          status.setErrorStatus(SnmpConstants.SNMP_ERROR_WRONG_TYPE);
@@ -234,13 +273,19 @@
    }

    public OID getUpperBound() {
-    return oid;
+    if (upperBound == null) {
+      upperBound = oid.nextPeer();
+    }
+    return upperBound;
    }

    public boolean isCovered(MOScope other) {
-    return (other.isLowerIncluded() && other.isUpperIncluded() &&
-            oid.equals(other.getLowerBound()) &&
-            oid.equals(other.getUpperBound()));
+    return (other.getLowerBound().startsWith(oid) &&
+            (other.getLowerBound().size() > oid.size() ||
+             other.isLowerIncluded())) &&
+            (other.getUpperBound().startsWith(oid) &&
+             ((other.getUpperBound().size() > oid.size()) ||
+              other.isUpperIncluded()));
    }

    public boolean isLowerIncluded() {
@@ -248,7 +293,7 @@
    }

    public boolean isUpperIncluded() {
-    return true;
+    return false;
    }

    /**
@@ -348,7 +393,7 @@
    }

    public boolean covers(OID oid) {
-    return this.oid.equals(oid);
+    return oid.startsWith(this.oid);
    }

    public String toString() {


Best regards,
Frank

nidhin wrote:
> Hi,
>    
>   Any inputs regarding the below issue.
>    
>   Regards
>   Nidhin
> 
> nidhin <nidhingj at yahoo.com> wrote:
>   Hi,
> 
> My snmp4j agent fails to send the correct error code for v2c response in case of scalar nodes.
> 
> Test Results: (1)The response value type in the varbind 
> # (NoSuchObject) contained error other than 
> # NoSuchInstance. 
> # Test Rating: POOR
> # Message Exchange:
> # 
> # (Tue Apr 24 13:47:31 2007):
> # Get Request: Version = SNMPv2c, Community = private
> # Request Id = 2, Error Status = No Error , Error Index = 0
> # Oid1 = agentState.0.0.127.128.255.256.32767.32768.65535.65536.8388607.8388608.16777215.16777216.2147483647.2147483648.4294967295.0.127.128.255.256.32767.32768.65535.65536.8388607.8388608.16777215.16777216.2147483647.2147483648.4294967295.0.127.128.255.256.32767.32768.65535.65536.8388607.8388608.16777215.16777216.2147483647.2147483648.4294967295.0.127.128.255.256 , Type = NULL, Value = NULL
> # 
> # (Tue Apr 24 13:47:31 2007):
> # Response: Version = SNMPv2c, Community = private
> # Request Id = 2, Error Status = No Error , Error Index = 0
> # Oid1 = agentState.0.0.127.128.255.256.32767.32768.65535.65536.8388607.8388608.16777215.16777216.2147483647.2147483648.4294967295.0.127.128.255.256.32767.32768.65535.65536.8388607.8388608.16777215.16777216.2147483647.2147483648.4294967295.0.127.128.255.256.32767.32768.65535.65536.8388607.8388608.16777215.16777216.2147483647.2147483648.4294967295.0.127.128.255.256 , Type = NoSuchObject, Value = NULL
> 
> Please let me know if this is a bug in the agent jar or not.
> 
> Regards
> Nidhin
> 
> 
> ---------------------------------
> Ahhh...imagining that irresistible "new car" smell?
> Check outnew cars at Yahoo! Autos.
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j
> 
> 
>        
> ---------------------------------
> Ahhh...imagining that irresistible "new car" smell?
>  Check outnew cars at Yahoo! Autos.
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list