Author: ctian Date: Tue Oct 16 15:53:58 2007 New Revision: 67
Added: trunk/fli-templates.lisp Modified: trunk/deliver.lisp trunk/mib/build.lisp trunk/smi/message.lisp trunk/smi/pdu.lisp trunk/snmp/package.lisp trunk/snmp/session.lisp trunk/snmp/snmp-get.lisp trunk/snmp/snmp-walk.lisp Log: SNMP Walk fixed
Modified: trunk/deliver.lisp ============================================================================== --- trunk/deliver.lisp (original) +++ trunk/deliver.lisp Tue Oct 16 15:53:58 2007 @@ -4,14 +4,14 @@
;;; Where we are going to deliver the image.
-(defvar *delivered-image-name* "mbrowse") +(defvar *delivered-image-name* "~/mbrowse")
;;; Load the "application".
(clc:clc-require :net-snmp)
-(mib:build-mib-tree) +(mib:build-tree)
;; Deliver.
-(deliver 'mib:browser *delivered-image-name* 5 :interface :capi) +(deliver 'mib:browser *delivered-image-name* 0 :interface :capi)
Added: trunk/fli-templates.lisp ==============================================================================
Modified: trunk/mib/build.lisp ============================================================================== --- trunk/mib/build.lisp (original) +++ trunk/mib/build.lisp Tue Oct 16 15:53:58 2007 @@ -114,3 +114,6 @@ (format t "Parsing ~A" i) (read-mib (mib-pathname i)) (format t ".~%"))) + +(eval-when (:load-toplevel :execute) + (build-tree))
Modified: trunk/smi/message.lisp ============================================================================== --- trunk/smi/message.lisp (original) +++ trunk/smi/message.lisp Tue Oct 16 15:53:58 2007 @@ -8,7 +8,7 @@ :initarg :community :reader message-comminity) (data :initarg :data - :reader message-data))) + :accessor message-data)))
(defmethod ber-encode ((value message)) (with-slots (version community data) value
Modified: trunk/smi/pdu.lisp ============================================================================== --- trunk/smi/pdu.lisp (original) +++ trunk/smi/pdu.lisp Tue Oct 16 15:53:58 2007 @@ -2,11 +2,11 @@
(defclass base-pdu () ((request-id :type (unsigned-byte 32) - :reader request-id + :accessor request-id :initform 0 :initarg :request-id) (variable-bindings :type list - :reader variable-bindings + :accessor variable-bindings :initform nil :initarg :variable-bindings)))
Modified: trunk/snmp/package.lisp ============================================================================== --- trunk/snmp/package.lisp (original) +++ trunk/snmp/package.lisp Tue Oct 16 15:53:58 2007 @@ -3,7 +3,8 @@ (defpackage :com.netease.snmp (:nicknames snmp) (:use :common-lisp :smi :asn.1 :mib #-win32 :net.sockets #-win32 :io.streams) - (:export v1-session v2c-session v3-session + (:export v1-session v2c-session v3-session make-session + *default-version* *default-community* *default-port* snmp-get snmp-walk))
(in-package :snmp)
Modified: trunk/snmp/session.lisp ============================================================================== --- trunk/snmp/session.lisp (original) +++ trunk/snmp/session.lisp Tue Oct 16 15:53:58 2007 @@ -1,5 +1,10 @@ (in-package :snmp)
+(defvar *default-version* +snmp-version-1+) +(defvar *default-port* 161) +(defvar *default-community* "public") +(defvar *default-class* 'v1-session) + #-win32 (defclass session () ((socket :reader socket @@ -8,20 +13,20 @@ (version :reader version :initarg :version :type integer - :initform +snmp-version-1+))) + :initform *default-version*)))
#+win32 (defclass session () ((version :reader version :initarg :version :type integer - :initform +snmp-version-1+))) + :initform *default-version*)))
(defclass v1-session (session) ((community :reader community :initarg :community :type string - :initform "public")) + :initform *default-community*)) (:documentation "SNMP v1 session, community based"))
(defmethod initialize-instance :after ((instance v1-session) @@ -57,3 +62,13 @@ &rest initargs &key &allow-other-keys) (declare (ignore initargs)) (setf (slot-value instance 'version) +snmp-version-3+)) + +(defun make-session (host &key (class *default-class*) + (port *default-port*) + (community *default-community*)) + (let ((socket (make-socket :remote-host host + :remote-port port + :type :datagram + :ipv6 nil))) + (set-socket-option socket :receive-timeout :timeval '(1 0)) + (make-instance class :socket socket :community community)))
Modified: trunk/snmp/snmp-get.lisp ============================================================================== --- trunk/snmp/snmp-get.lisp (original) +++ trunk/snmp/snmp-get.lisp Tue Oct 16 15:53:58 2007 @@ -4,15 +4,7 @@ (:documentation "SNMP Get"))
(defmethod snmp-get ((host string) &rest vars) - (let ((socket (make-socket :remote-host host - :remote-port 161 - :type :datagram - :ipv6 nil))) - (let ((session (make-instance 'v2c-session - :socket socket - :community "public"))) - (values (apply #'snmp-get session vars) - session)))) + (apply #'snmp-get (make-session host) vars))
#-win32 (defmethod snmp-get ((session v1-session) &rest vars)
Modified: trunk/snmp/snmp-walk.lisp ============================================================================== --- trunk/snmp/snmp-walk.lisp (original) +++ trunk/snmp/snmp-walk.lisp Tue Oct 16 15:53:58 2007 @@ -3,48 +3,21 @@ (defgeneric snmp-walk (object var) (:documentation "SNMP Walk"))
-#-win32 (defmethod snmp-walk ((host string) var) - (let ((socket (make-socket :remote-host host - :remote-port 161 - :type :datagram - :ipv6 nil))) - (let ((session (make-instance 'v1-session - :socket socket - :community "public"))) - (values (snmp-walk session var) session)))) + (apply #'snmp-walk (make-session host) var))
#-win32 (defmethod snmp-walk ((session v1-session) (var object-id)) - (labels ((iter (acc) - (let ((message (make-instance 'message - :version (version session) - :community (community session) - :data (make-instance 'get-next-request-pdu - :request-id 0 - :variable-bindings (list (list var nil)))))) - (let ((data (ber-encode message))) - (socket-send (make-array (length data) - :element-type '(unsigned-byte 8) - :adjustable nil - :initial-contents data - #+lispworks :allocation #+lispworks :static) - (socket session)) - (let ((result (decode-message (socket session)))) - (if (= (error-status (message-data result)) +snmp-err-nosuchname+) - (nreverse acc) - (iter (cons (car (variable-bindings (message-data result))) acc)))))))) - (iter nil))) - -#-win32 -(defmethod snmp-walk ((session v2c-session) (var object-id)) - (labels ((iter (acc) - (let ((message (make-instance 'message - :version (version session) - :community (community session) - :data (make-instance 'get-next-request-pdu - :request-id 0 - :variable-bindings (list (list var nil)))))) + "SNMP Walk for v1 and v2c" + (let ((message (make-instance 'message + :version (version session) + :community (community session) + :data (make-instance 'get-next-request-pdu + :request-id 0 + :variable-bindings (list nil))))) + (labels ((iter (v id acc) + (setf (car (variable-bindings (message-data message))) (list v nil) + (request-id (message-data message)) id) (let ((data (ber-encode message))) (socket-send (make-array (length data) :element-type '(unsigned-byte 8) @@ -54,10 +27,10 @@ (socket session)) (let ((result (decode-message (socket session)))) (let ((vb (car (variable-bindings (message-data result))))) - (if (null (second vb)) - (nreverse acc) - (iter (cons vb acc))))))))) - (iter nil))) + (if (not (oid-< (car vb) var)) + (nreverse acc) + (iter (first vb) (1+ id) (cons vb acc)))))))) + (iter var 0 nil))))
(defmethod snmp-walk ((session v1-session) (var string)) (let ((oid (resolve var)))