commit 8b32ec55b7151bbbeb33ea857454689ce9e1d6a0 Author: Loic GUEGAN Date: Tue Feb 12 16:55:17 2019 +0100 Create repo diff --git a/README.md b/README.md new file mode 100644 index 0000000..881460b --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Simgrid platform to dot file converter + +**sgp2dot** is a [Simgrid](https://simgrid.org) platform to [Graphiz dot file](http://graphviz.org/) convert implemented in Lisp. It require: +- Common Lisp (supporting asdf) +- s-xml + +How to use it ? Compile it using the following lisp code: + + > (asdf:operate :build-op "sgp2dot") +Finally invoke `./sgp2dot-cl.lisp ` + 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 "}~%")))) diff --git a/packages.lisp b/packages.lisp new file mode 100644 index 0000000..96528bd --- /dev/null +++ b/packages.lisp @@ -0,0 +1,4 @@ +(defpackage :sgp2dot + (:use :common-lisp :s-xml) + (:export :convert :main)) + diff --git a/platform.xml b/platform.xml new file mode 100644 index 0000000..e74b8bd --- /dev/null +++ b/platform.xml @@ -0,0 +1,1815 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sgp2dot-cl.lisp b/sgp2dot-cl.lisp new file mode 100755 index 0000000..9646399 --- /dev/null +++ b/sgp2dot-cl.lisp @@ -0,0 +1,8 @@ +#!/usr/bin/sbcl --script + +(load "./sgp2dot.lisp") + +(if (eq (length sb-ext:*posix-argv*) 3) + (sgp2dot:convert (second sb-ext:*posix-argv*) (third sb-ext:*posix-argv*)) + (format t "Usage: ./sgp2dot-cl.lisp ~%")) + diff --git a/sgp2dot.asd b/sgp2dot.asd new file mode 100644 index 0000000..f90feed --- /dev/null +++ b/sgp2dot.asd @@ -0,0 +1,10 @@ + +(defsystem "sgp2dot" + :description "Generate a dot file (graphiz) to the corresponding Simgrid platform" + :version "0.0.1" + :depends-on ("s-xml") + :build-operation "monolithic-concatenate-source-op" + :build-pathname "sgp2dot" + :components ((:file "packages") + (:file "convert"))) +