summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2009-06-24 15:37:39 +0200
committerLinus Nordberg <linus@nordberg.se>2009-06-24 15:37:39 +0200
commit385055c116ace4374c5ef8f9c50550a5374b7003 (patch)
tree7b9ecdc32379e37c6c146bd1cc1f2182a1fd75bd
parent057353631cb37b196f93521abad73fbfc3a7b216 (diff)
* src/data.lisp: New (with a stupid with prefixing column names with ASC- and OCT-).
-rw-r--r--src/data.lisp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/data.lisp b/src/data.lisp
new file mode 100644
index 0000000..4674638
--- /dev/null
+++ b/src/data.lisp
@@ -0,0 +1,74 @@
+;; http://common-lisp.net/project/postmodern/
+
+(defparameter *xmlns* "urn:ietf:params:xml:ns:xfb-0.1")
+(defparameter *version* 0.1)
+
+;; XML attributes, all required:
+;; (xmlns :col-type string :initform *xmlns*)
+;; (version :col-type string :initform *version*)
+;; (length :col-type string :initarg length)
+
+; (require 'postmodern)
+; (use-package 'postmodern)
+(defclass bgp-message ()
+ (
+ ;;TIME
+ (timestamp :col-type integer)
+ (datetime :col-type (or db-null string))
+ (precision_time :col-type (or db-null integer))
+
+ ;; PEERING
+ (src_addr :col-type string)
+ (dst_addr :col-type string)
+ (src_port :col-type string)
+ (dst_port :col-type string)
+ (src_as :col-type (or db-null string))
+ (dst_as :col-type (or db-null string))
+
+ ;; OCTET_MSG
+ (oct-marker :col-type string)
+ (oct-length :col-type integer)
+ (oct-type :col-type integer) ; FIXME: is there an enum or small integer?
+ (oct-octets :col-type string)
+
+ ;; ASCII_MSG
+ (asc-marker :col-type string)
+ (asc-length :col-type integer)
+ (asc-type :col-type integer) ; FIXME: is there an enum or small integer?
+ )
+
+ (:metaclass dao-class)
+ (:keys timestamp))
+
+;; (connect-toplevel "linus" "linus" "" "localhost")
+;; (execute (dao-table-definition 'bgp-message))
+
+;; BGP_MESSAGE {TIME {TIMESTAMP {1245842681} DATETIME {2009-06-24T11:24:41Z} PRECISION_TIME {185} } PEERING {SRC_ADDR {193.10.255.88} SRC_PORT {179} SRC_AS {2603} DST_ADDR {193.10.252.3} DST_PORT {179} DST_AS {2603} } ASCII_MSG {MARKER {FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF} LENGTH {87} TYPE {UPDATE} UPDATE {WITHDRAWN_LEN {24} WITHDRAWN {PREFIX {92.46.244/23} PREFIX {95.59.2/23} PREFIX {95.59.4/22} PREFIX {95.59.8/23} PREFIX {89.218.218/23} PREFIX {89.218.220/23} } PATH_ATTRIBUTES_LEN {36} PATH_ATTRIBUTES {ATTRIBUTE {FLAGS {TRANSITIVE {} } LENGTH {1} TYPE {ORIGIN} ORIGIN {IGP} } ATTRIBUTE {FLAGS {TRANSITIVE {} } LENGTH {8} TYPE {AS_PATH} AS_PATH {AS {1299} AS {702} AS {3216} } } ATTRIBUTE {FLAGS {TRANSITIVE {} } LENGTH {4} TYPE {NEXT_HOP} NEXT_HOP {213.248.97.93} } ATTRIBUTE {FLAGS {TRANSITIVE {} } LENGTH {4} TYPE {LOCAL_PREF} LOCAL_PREF {80} } ATTRIBUTE {FLAGS {OPTIONAL {} TRANSITIVE {} } LENGTH {4} TYPE {COMMUNITIES} COMMUNITIES {COMMUNITY {AS {2603} VALUE {666} } } } } NLRI {PREFIX {95.30.48/22} } } } OCTET_MSG {MARKER {FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF} LENGTH {87} TYPE {UPDATE} OCTETS {FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0057020018175C2EF4175F3B02165F3B04175F3B081759DADA1759DADC0024400101004002080203051302BE0C90400304D5F8615D40050400000050C008040A2B029A165F1E30} } }
+
+(defun new-entry (xml-doc)
+ "Return a fresh BGP-MESSAGE built from XML-DOC (array of unsigned bytes)."
+ (let ((s (cxml:make-source xml-doc))
+ (e (make-instance 'bgp-message))
+ (cur-ctxt nil)
+ (cur-name nil))
+ (do ((key (klacks:peek s) (klacks:peek s)))
+ ((null key) e)
+ (case key
+ (:start-element (let ((tag (klacks:current-qname s)))
+ (setf cur-ctxt (cond
+ ((string= tag "OCTET_MSG") "OCT-")
+ ((string= tag "ASCII_MSG") "ASC-")
+ (t cur-ctxt)))
+ (setf cur-name (concatenate 'string cur-ctxt tag))))
+ (:end-element (let ((tag (klacks:current-qname s)))
+ (when *debug2* (print tag))
+ (setf cur-ctxt (cond
+ ((string= tag "OCTET_MSG") nil)
+ ((string= tag "ASCII_MSG") nil)
+ (t cur-ctxt)))
+ (setf cur-name nil)))
+ (:characters (progn
+ (when *debug2* (format t "cur-name: ~A, cur-ctxt: ~A~%" cur-name cur-ctxt))
+ (setf (slot-value e (intern cur-name))
+ (klacks:current-characters s)))))
+ (klacks:consume s))))