summaryrefslogtreecommitdiff
path: root/src/defs.lisp
blob: a02a7e95398922ade79ecf28e83f686726471af1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-

(in-package :bgp-logger)

;; FIXME: Remove password.
(defparameter *db-spec* '("bgpstore" "bgpstore" "bgpstore" "localhost" ))

;; 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 ()
  ((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 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 "{}")
   (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))

;; Database.
;; Create table by evaluating
;;   (connect-toplevel "bgpstore" "bgpstore" "bgpstore" "localhost")
;;   (execute (dao-table-definition 'bgp-message))

;; XML.
;; node elements have dom:tag-name
;; text elements have dom:data

;(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)
 	  (slot-value msg 'nexthop) (slot-value templ 'nexthop)
 	  (slot-value msg 'bgp-octets) (slot-value templ 'bgp-octets))
    msg))