summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2009-06-25 17:46:36 +0200
committerLinus Nordberg <linus@nordberg.se>2009-06-25 17:46:36 +0200
commit55edcd04e99000409cd7860b6ae14956ad7ec43c (patch)
treeaef4296cf360967479e80b6088003d4edd9804ae
parent20ce3cf62447e4b6019b1403ba33d02884362b21 (diff)
First working version.
Missing some crucial things: - [ ] store timestamp and precision-time - [ ] store as-path
-rw-r--r--bgp-logger.org15
-rw-r--r--src/bgpstore.lisp9
-rw-r--r--src/data.lisp69
-rwxr-xr-xsrc/start-bgpstore.sh6
-rw-r--r--src/util.lisp2
5 files changed, 62 insertions, 39 deletions
diff --git a/bgp-logger.org b/bgp-logger.org
index db20c13..e4f4071 100644
--- a/bgp-logger.org
+++ b/bgp-logger.org
@@ -25,11 +25,16 @@ should've read
so now it does.
* TODO
-** Store in SQL db
-The data is basically what's in a BGP packet.
-
-We should store everything. We should be able to do this in a single
-table.
+- [ ] store timestamp and precision-time
+- [ ] store as-path
+- [ ] move to victoria
+- [ ] store nexthop
+- [ ] limit access to bgpmon stream (acl's)
+- [ ] auto-start on boot
+- [ ] get an idea of disk footprint
+- [ ] get an idea of RAM footprint
+- [ ] get an idea of CPU load, sbcl and postgres
+- [ ] store bgp-octets as binary
* Running postgresql
To start the server
diff --git a/src/bgpstore.lisp b/src/bgpstore.lisp
index 2afa210..5abc348 100644
--- a/src/bgpstore.lisp
+++ b/src/bgpstore.lisp
@@ -1,9 +1,12 @@
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+
(defun start-bgpstore (host port)
(let ((reader (new-reader host port)))
(do ((e (next-xml-blurb reader "BGP_MESSAGE")
(next-xml-blurb reader "BGP_MESSAGE")))
- (e)
- (dolist (obj (new-entries e))
- (print (describe obj))))))
+ ((null e))
+ (dolist (obj (new-entries (xml-top-elem-from-octets e)))
+ (insert-dao obj)))
+ (close-reader)))
(defun stop-bgpstore ())
diff --git a/src/data.lisp b/src/data.lisp
index 138fea7..ea8a7a4 100644
--- a/src/data.lisp
+++ b/src/data.lisp
@@ -1,5 +1,6 @@
-;; http://common-lisp.net/project/postmodern/
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+;; http://common-lisp.net/project/postmodern/
(defparameter *xmlns* "urn:ietf:params:xml:ns:xfb-0.1")
(defparameter *version* 0.1)
@@ -12,37 +13,36 @@
; (use-package 'postmodern)
(defclass bgp-message ()
((id :col-type serial)
- (timestamp :col-type integer :accessor :timestamp :initform 0)
- (precision-time :col-type (or db-null smallint) :accessor :precision-time :initform 0)
- (prefix :col-type cidr :accessor :prefix :initarg :prefix)
- (label :col-type smallint :accessor :label :initarg :label
+ (timestamp :col-type integer :accessor timestamp :initform 0)
+ (precision-time :col-type (or db-null smallint) :accessor precision-time :initform 0)
+ (prefix :col-type cidr :accessor prefix :initarg :prefix)
+ (label :col-type string ;FIXME: smallint or enum
+ :accessor label :initarg :label
:documentation "1-NANN, 2-WITH, 3-DANN, 4-DUPW, 5-DPATH, 6-SPATH")
- (path :col-type (or db-null integer[]) :accessor :path :initform nil)
- (nexthop :col-type (or db-null inet) :accessor :nexthop :initform "")
+ (path :col-type (or db-null integer[]) :accessor path :initform "{}")
+ (nexthop :col-type (or db-null inet) :accessor nexthop :initform "0.0.0.0")
(bgp-octets :col-type string :accessor bgp-octets)) ; FIXME: binary to save space.
(:metaclass dao-class)
(:keys id))
-;; (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} } }
-
-;; elements: dom:tag-name
-;; text: dom:data
+;; Database.
+;; Create table by evaluating
+;; (connect-toplevel "linus" "linus" "" "localhost")
+;; (execute (dao-table-definition 'bgp-message))
-(defun prefix (node)
- (list (dom:data (aref (dom:child-nodes node) 0))
- (dom:get-attribute node "label")))
+;; XML.
+;; node elements have dom:tag-name
+;; text elements have dom:data
-(defun xml-top-elem-from-octets (xml-octets)
- (dom:document-element
- (cxml:parse xml-octets (cxml-dom:make-dom-builder))))
+(defun prefix-pair (node)
+ )
(defun new-bgp-message (templ pref)
(let ((msg (make-instance 'bgp-message
:prefix (car pref)
:label (cadr pref))))
+ ;; FIXME: Use accessor functions.
+ ;; FIXME2: Move this to a method of the class.
(setf (slot-value msg 'timestamp) (slot-value templ 'timestamp)
(slot-value msg 'precision-time) (slot-value templ 'precision-time)
(slot-value msg 'path) (slot-value templ 'path)
@@ -50,11 +50,15 @@
(slot-value msg 'bgp-octets) (slot-value templ 'bgp-octets))
msg))
+(defun xml-top-elem-from-octets (xml-octets)
+ (dom:document-element
+ (cxml:parse xml-octets (cxml-dom:make-dom-builder))))
(defun new-entries (top-elem)
"Return BGP-MESSAGE's, one per prefix mentioned in TOP-ELEM.
TOP-ELEM is an XML document element."
;; We assume that top-elem is "BGP_MESSAGE".
+ ;(print (describe top-elem))
(let ((updates (dom:get-elements-by-tag-name top-elem "UPDATE"))
(new-elements nil))
(when (> (length updates) 0)
@@ -64,16 +68,23 @@ TOP-ELEM is an XML document element."
(new-prefs nil)
(octet-msgs (dom:get-elements-by-tag-name top-elem "OCTET_MSG"))
(prefixes (dom:get-elements-by-tag-name top-elem "PREFIX")))
- ;;(format t "found update, prefixes=~A~%" prefixes)
+
+ ;; Populate new-prefs.
(when (> (length prefixes) 0)
(setf new-prefs
(concatenate
'list
new-elements
- (map 'list (lambda (pref)
- (prefix pref))
+ (map 'list
+ (lambda (p)
+ (list (dom:data (aref (dom:child-nodes p) 0))
+ (dom:get-attribute p "label")))
prefixes))))
- ;; todo: create new elements and populate template
+
+ ;; Populate the template.
+ ;; TODO: just do it!
+
+ ;; Add octets to templ.
(when (> (length octet-msgs) 0)
;;(format t "found octet-msg~%")
(let* ((oct (aref (dom:get-elements-by-tag-name
@@ -82,13 +93,11 @@ TOP-ELEM is an XML document element."
(txt (aref (dom:child-nodes oct) 0)))
(setf (bgp-octets templ) (dom:data txt))))
- ;; Create new elements from template.
- (format t "templ: ~A~%" (describe templ))
- (format t "new-prefs: ~A~%" new-prefs)
+ ;; Create new elements from new-prefs and the template.
+ ;(format t "templ: ~A~%" (describe templ))
+ ;(format t "new-prefs: ~A~%" new-prefs)
(dolist (p new-prefs)
- (push (new-bgp-message templ p) new-elements))
- ))))
- ;; Return new elements.
+ (push (new-bgp-message templ p) new-elements))))))
new-elements))
(defun new-entry-klacks (xml-doc)
diff --git a/src/start-bgpstore.sh b/src/start-bgpstore.sh
index 9b0696b..ce40c02 100755
--- a/src/start-bgpstore.sh
+++ b/src/start-bgpstore.sh
@@ -1,5 +1,8 @@
#! /bin/sh
+HOST=$1
+PORT=$2
+
# FIXME: The use-package postmodern should've been taken care of in
# package.lisp.
@@ -7,4 +10,5 @@ sbcl --no-userinit \
--eval "(require 'asdf)" \
--eval "(asdf:oos 'asdf:load-op 'postmodern)" \
--eval "(use-package 'postmodern)" \
- --eval "(require 'bgpstore)"
+ --eval "(require 'bgpstore)" \
+ --eval "(start-bgpstore $HOST $PORT)"
diff --git a/src/util.lisp b/src/util.lisp
index 3494493..32f7d73 100644
--- a/src/util.lisp
+++ b/src/util.lisp
@@ -1,3 +1,5 @@
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+
(defparameter *debug* nil)
(defun next-xml-blurb (reader tag)