Feat: début du la préparation des roles pour la simulation réseau
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bertrand Benjamin 2021-02-02 09:27:51 +01:00
parent dc4f5b987f
commit 27e032b919
4 changed files with 377 additions and 0 deletions

View File

@ -0,0 +1,45 @@
import yaml
import cairosvg
import jinja2
from pathlib import Path
import networkx as nx
import matplotlib.pyplot as plt
#cairosvg.svg2pdf(url="role.svg", write_to="role.pdf")
def graph(roles):
g = nx.Graph()
g.add_nodes_from([str(role["num"]) for role in roles])
for role in roles:
for lien in role["liens"]:
g.add_edge(str(role["num"]), str(list(lien.keys())[0]))
return g
with open("roles.yml", "r") as f:
topos = yaml.load(f, Loader=yaml.SafeLoader)
with open("role.svg", "r") as f:
template = jinja2.Template(f.read())
for topo, desc in topos.items():
for role in desc["roles"]:
card = template.render(**role)
Path(topo).mkdir(exist_ok=True)
dest = f"{topo}/role{role['num']}.svg"
with open(dest, "w") as f:
f.write(card)
cairosvg.svg2pdf(url=dest, write_to=dest.replace("svg", "pdf"))
plt.figure(figsize=(5,5))
ax = plt.gca()
ax.set_title('Random graph')
ax.set_title(f"Forme du réseau: {topo}")
g = graph(desc['roles'])
nx.draw(g, with_labels=True,
node_color='lightgreen',
node_size=700,
ax=ax)
_ = ax.axis('off')
plt.savefig(f"{topo}/forme.pdf")
plt.cla()

View File

@ -0,0 +1,17 @@
@page {
margin: 0;
height: 8cm;
width: 25cm;
}
html {
height: 100%;
}
body {
background: #fff;
box-sizing: border-box;
color: #2A3239;
display: flex;
flex-wrap: rows;
justify-content: space-between;
margin: 0;
}

View File

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg8"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07, custom)"
sodipodi:docname="role.svg">
<defs
id="defs2">
<rect
x="141.54318"
y="-27.129943"
width="121.71338"
height="102.64229"
id="rect971" />
<rect
x="0"
y="235.85597"
width="210"
height="61.144028"
id="rect40" />
<rect
x="14.790587"
y="147.87104"
width="181.01243"
height="64.921287"
id="rect32" />
<rect
x="14.093271"
y="66.389189"
width="195.90673"
height="81.350752"
id="rect26" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.45464743"
inkscape:cx="73.57707"
inkscape:cy="476.54345"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
inkscape:document-rotation="0"
showgrid="false"
inkscape:snap-bbox="true"
inkscape:bbox-nodes="true"
inkscape:bbox-paths="true"
inkscape:snap-page="true"
inkscape:window-width="1366"
inkscape:window-height="743"
inkscape:window-x="0"
inkscape:window-y="25"
inkscape:window-maximized="1" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Calque 1"
inkscape:groupmode="layer"
id="layer1">
<rect
style="fill:#ff8080;stroke:#000000;stroke-width:1"
id="rect10"
width="210"
height="52.691414"
x="0"
y="0" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:12.7px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="10.563576"
y="36.444286"
id="text14"><tspan
sodipodi:role="line"
id="tspan12"
x="10.563576"
y="36.444286"
style="font-size:12.7px;stroke-width:0.264583">IP = {{IP}}</tspan></text>
<path
style="fill:#ff2a2a;stroke:#000000;stroke-width:1"
id="path18"
sodipodi:type="arc"
sodipodi:cx="210"
sodipodi:cy="0"
sodipodi:rx="52.018276"
sodipodi:ry="52.018276"
sodipodi:start="1.5707963"
sodipodi:end="3.1369896"
sodipodi:arc-type="slice"
d="M 210,52.018276 A 52.018276,52.018276 0 0 1 157.98227,0.23944207 L 210,0 Z" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="176.42413"
y="24.483652"
id="text22"><tspan
sodipodi:role="line"
id="tspan20"
x="176.42413"
y="24.483652"
style="stroke-width:0.264583">#{{num}}</tspan></text>
<text
xml:space="preserve"
id="text24"
style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;white-space:pre;shape-inside:url(#rect26);fill:#000000;fill-opacity:1;stroke:none;"><tspan
x="14.09375"
y="75.752412"><tspan>Objectifs:
</tspan></tspan><tspan
x="14.09375"
y="88.981538"><tspan>{{objectifs}}</tspan></tspan></text>
<text
xml:space="preserve"
id="text30"
style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;white-space:pre;shape-inside:url(#rect32);fill:#000000;fill-opacity:1;stroke:none;"><tspan
x="14.791016"
y="157.23483"><tspan>Particularités:
</tspan></tspan><tspan
x="14.791016"
y="170.46396"><tspan>{{particularites}}</tspan></tspan></text>
<rect
style="fill:#ffccaa;stroke:#000000;stroke-width:1"
id="rect36"
width="210"
height="61.144024"
x="0"
y="235.85597" />
<text
xml:space="preserve"
id="text38"
style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;white-space:pre;shape-inside:url(#rect40);fill:#000000;fill-opacity:1;stroke:none;"
transform="translate(9.2673019,8.9560368)"><tspan
x="0"
y="245.21921"><tspan>Lié à :
</tspan></tspan><tspan
x="0"
y="258.44833"><tspan>{{liens}}</tspan></tspan></text>
<text
xml:space="preserve"
id="text969"
style="fill:black;fill-opacity:1;line-height:1.25;stroke:none;font-family:sans-serif;font-style:normal;font-weight:normal;font-size:10.58333333px;white-space:pre;shape-inside:url(#rect971);" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -0,0 +1,151 @@
---
lineaire:
roles:
- num: 1
IP: 192.168.0.1
objectifs:
- Envoyer un message à 192.168.3.1
particularites:
liens:
- 2: 192.168.1.1
- num: 2
IP: 192.168.1.1
objectifs:
- Envoyer un message à 192.168.3.1
particularites:
- Ne marche plus après avoir transmis 3 messages
liens:
- 1: 192.168.0.1
- 3: 192.168.2.1
- num: 3
IP: 192.168.2.1
objectifs:
- Envoyer un message à 192.168.0.1
particularites:
liens:
- 2: 192.168.1.1
- 4: 192.168.3.1
- num: 4
IP: 192.168.3.1
objectifs:
- Envoyer un message à 192.168.5.1
particularites:
liens:
- 3: 192.168.2.1
- 5: 192.168.4.1
- num: 5
IP: 192.168.4.1
objectifs:
- Envoyer un message à 192.168.1.1
particularites:
liens:
- 4: 192.168.3.1
- 6: 192.168.5.1
- num: 6
IP: 192.168.5.1
objectifs:
- Envoyer un message à 192.168.2.1
particularites:
- Ne marche plus après avoir transmis 3 messages
liens:
- 5: 192.168.4.1
anneau:
roles:
- num: 1
IP: 10.10.0.1
objectifs:
- Envoyer un message à 10.10.3.1
particularites:
liens:
- 6: 10.10.5.1
- 2: 10.10.1.1
- num: 2
IP: 10.10.1.1
objectifs:
- Envoyer un message à 10.10.5.1
particularites:
liens:
- 1: 10.10.0.1
- 3: 10.10.2.1
- num: 3
IP: 10.10.2.1
objectifs:
- Envoyer un message à 10.10.4.1
particularites:
- Ne marche plus après avoir transmis 5 messages
liens:
- 2: 10.10.1.1
- 4: 10.10.3.1
- num: 4
IP: 10.10.3.1
objectifs:
- Envoyer un message à 10.10.0.1
particularites:
liens:
- 3: 10.10.2.1
- 5: 10.10.4.1
- num: 5
IP: 10.10.4.1
objectifs:
- Envoyer un message à 10.10.1.1
particularites:
liens:
- 4: 10.10.3.1
- 6: 10.10.5.1
- num: 6
IP: 10.10.5.1
objectifs:
- Envoyer un message à 10.10.3.1
particularites:
liens:
- 5: 10.10.4.1
- 1: 10.10.0.1
etoile:
roles:
- num: 1
IP: 77.82.0.1
objectifs:
particularites:
liens:
- 2: 77.82.1.1
- 3: 77.82.2.1
- 4: 77.82.3.1
- 5: 77.82.4.1
- 6: 77.82.5.1
- num: 2
IP: 77.82.1.1
objectifs:
- Envoyer un message à 77.82.5.1
particularites:
liens:
- 1: 77.82.0.1
- num: 3
IP: 77.82.2.1
objectifs:
- Envoyer un message à 77.82.4.1
particularites:
liens:
- 1: 77.82.0.1
- num: 4
IP: 77.82.3.1
objectifs:
- Envoyer un message à 77.82.0.1
particularites:
liens:
- 1: 77.82.0.1
- num: 5
IP: 77.82.4.1
objectifs:
- Envoyer un message à 77.82.1.1
particularites:
liens:
- 1: 77.82.0.1
- num: 6
IP: 77.82.5.1
objectifs:
- Envoyer un message à 77.82.3.1
particularites:
liens:
- 1: 77.82.0.1