aboutsummaryrefslogtreecommitdiff
path: root/convert.lisp
diff options
context:
space:
mode:
authorLoic GUEGAN <loic.guegan@yahoo.fr>2019-02-12 16:55:17 +0100
committerLoic GUEGAN <loic.guegan@yahoo.fr>2019-02-12 16:55:17 +0100
commit8b32ec55b7151bbbeb33ea857454689ce9e1d6a0 (patch)
tree69fe53e9a4917713f62c2f78df83aa89fe73468d /convert.lisp
Create repo
Diffstat (limited to 'convert.lisp')
-rw-r--r--convert.lisp42
1 files changed, 42 insertions, 0 deletions
diff --git a/convert.lisp b/convert.lisp
new file mode 100644
index 0000000..4cb503e
--- /dev/null
+++ b/convert.lisp
@@ -0,0 +1,42 @@
+(in-package :sgp2dot)
+
+
+(defparameter *hosts* nil "Contains hosts found in the Simgrid XML platform file")
+(defparameter *links* nil "Contains links found in the Simgrid XML platform file")
+
+
+(defun handle-host (attributes)
+ (push (cdr (assoc :|id| attributes)) *hosts*))
+
+(defun handle-route (attributes)
+ (push `(,(cdr (assoc :|src| attributes)) . ,(cdr (assoc :|dst| attributes))) *links* ))
+
+(defun handle-element (name attributes seed)
+ (declare (ignore seed)) ; Ignore "unused argument" warning
+ (cond ((eq name :|host|) (handle-host attributes))
+ ((eq name :|route|) (handle-route attributes))))
+
+
+;;; Program entry point
+(defun convert (platform dot-file)
+ "Parse Simgrid platform then write it into a dot file."
+ (let ((xml-parser (make-instance 'xml-parser-state
+ :seed (cons 0 0)
+ :new-element-hook #'handle-element)))
+ ;; Parse Simgrid Platform
+ (with-open-file (stream-file platform :direction :input)
+ (start-parse-xml stream-file xml-parser))
+ ;; Write parsed host and list to a dot file
+ (with-open-file (stream dot-file :direction :output :if-exists :overwrite :if-does-not-exist :create)
+ ;; Add header
+ (format stream "graph Network {~%")
+ (format stream "graph [outputorder=\"edgesfirst\"]")
+ (format stream "node [shape=circle,style=filled]")
+ ;; Add links
+ (dolist (link *links*)
+ (format stream "~t~a -- ~a ~%" (car link) (cdr link)))
+ ;; Add hosts
+ (dolist (host *hosts*)
+ (format stream "~t~a~%" host))
+ ;; Add footer
+ (format stream "}~%"))))