Commit 1d20c100 authored by Bonnefoi Pierre-Francois's avatar Bonnefoi Pierre-Francois
Browse files

version initiale

parents
#!/bin/bash
export PATH=/usr/lib/quagga:$PATH
# graphe : INFRA RIP OSPF LAB
# créer les différents namespaces
ip netns add poste
ip netns add rout1
ip netns add rout2
ip netns add rout3
ip netns add rout4
# créer les switches
ovs-vsctl add-br resA
ovs-vsctl add-br resB
ovs-vsctl add-br resC
ovs-vsctl add-br resD
# créer le répertoire de travail
mkdir -p /run/quagga
# configurer poste
ip link add poste-eth0 type veth peer name resA-poste
ip link set poste-eth0 netns poste
ovs-vsctl add-port resA resA-poste
ip link set dev resA-poste up
ip netns exec poste ip link set dev lo up
ip netns exec poste ip link set dev poste-eth0 up
ip netns exec poste ip a add dev poste-eth0 10.10.10.100/24
ip netns exec poste ip r add default via 10.10.10.254
# configurer rout1
ip link add rout1-eth0 type veth peer name resA-rout1
ip link add rout1-eth1 type veth peer name resB-rout1
ip link set rout1-eth0 netns rout1
ip link set rout1-eth1 netns rout1
ovs-vsctl add-port resA resA-rout1
ip link set dev resA-rout1 up
ovs-vsctl add-port resB resB-rout1
ip link set dev resB-rout1 up
ip netns exec rout1 ip link set dev lo up
ip netns exec rout1 ip link set dev rout1-eth0 up
ip netns exec rout1 ip link set dev rout1-eth1 up
ip netns exec rout1 ip link add link rout1-eth0 name rout1-eth0.100 type vlan id 100
ip netns exec rout1 ip link set dev rout1-eth0.100 up
ip netns exec rout1 ip a add dev rout1-eth0.100 10.10.20.254/24
ip netns exec rout1 ip a add dev rout1-eth0 10.10.10.254/24
ip netns exec rout1 ip a add dev rout1-eth1 172.16.1.253/24
ip netns exec rout1 sysctl net.ipv4.conf.all.forwarding=1
mkdir -p /tmp/quagga1
ip netns exec rout1 bash -c "mount --bind /tmp/quagga1 /run/quagga; chown -R quagga:quagga /run/quagga;zebra -d;ripd -d"
# configurer rout2
ip link add rout2-eth0 type veth peer name resB-rout2
ip link add rout2-eth1 type veth peer name resC-rout2
ip link set rout2-eth0 netns rout2
ip link set rout2-eth1 netns rout2
ovs-vsctl add-port resB resB-rout2
ip link set dev resB-rout2 up
ovs-vsctl add-port resC resC-rout2
ip link set dev resC-rout2 up
ip netns exec rout2 ip link set dev lo up
ip netns exec rout2 ip link set dev rout2-eth0 up
ip netns exec rout2 ip link set dev rout2-eth1 up
ip netns exec rout2 ip a add dev rout2-eth0 172.16.1.254/24
ip netns exec rout2 ip a add dev rout2-eth1 192.168.100.253/24
ip netns exec rout2 sysctl net.ipv4.conf.all.forwarding=1
mkdir -p /tmp/quagga2
ip netns exec rout2 bash -c "mount --bind /tmp/quagga2 /run/quagga; chown -R quagga:quagga /run/quagga;zebra -d;ripd -d"
# configurer rout3
ip link add rout3-eth0 type veth peer name resA-rout3
ip link add rout3-eth1 type veth peer name resD-rout3
ip link set rout3-eth0 netns rout3
ip link set rout3-eth1 netns rout3
ovs-vsctl add-port resA resA-rout3
ip link set dev resA-rout3 up
ovs-vsctl add-port resD resD-rout3
ip link set dev resD-rout3 up
ip netns exec rout3 ip link set dev lo up
ip netns exec rout3 ip link set dev rout3-eth0 up
ip netns exec rout3 ip link set dev rout3-eth1 up
ip netns exec rout3 ip a add dev rout3-eth0 10.10.10.253/24
ip netns exec rout3 ip a add dev rout3-eth1 10.0.0.254/24
ip netns exec rout3 sysctl net.ipv4.conf.all.forwarding=1
mkdir -p /tmp/quagga3
ip netns exec rout3 bash -c "mount --bind /tmp/quagga3 /run/quagga; chown -R quagga:quagga /run/quagga;zebra -d;ripd -d"
# configurer rout4
ip link add rout4-eth0 type veth peer name resC-rout4
ip link add rout4-eth1 type veth peer name resD-rout4
ip link set rout4-eth0 netns rout4
ip link set rout4-eth1 netns rout4
ovs-vsctl add-port resC resC-rout4
ip link set dev resC-rout4 up
ovs-vsctl add-port resD resD-rout4
ip link set dev resD-rout4 up
ip netns exec rout4 ip link set dev lo up
ip netns exec rout4 ip link set dev rout4-eth0 up
ip netns exec rout4 ip link set dev rout4-eth1 up
ip netns exec rout4 ip a add dev rout4-eth0 192.168.100.252/24
ip netns exec rout4 ip a add dev rout4-eth1 10.0.0.253/24
ip netns exec rout4 sysctl net.ipv4.conf.all.forwarding=1
mkdir -p /tmp/quagga4
ip netns exec rout4 bash -c "mount --bind /tmp/quagga4 /run/quagga; chown -R quagga:quagga /run/quagga;zebra -d;ripd -d"
# enlever les switches
BRIDGES=$(cat build_architecture|awk '/^ovs-vsctl add-br/ { print $3 }')
NAMESPACES=$(cat build_architecture| awk '/^ip netns add/ { print $4 }')
LINKS=$(cat build_architecture|awk '/peer name/ { print $9 }')
DIRECTORIES=$(cat build_architecture|awk '/mkdir / { print $3 }')
for BRIDGE in $BRIDGES
do
sudo ovs-vsctl del-br $BRIDGE
done
for NAMESPACE in $NAMESPACES
do
sudo ip netns del $NAMESPACE
done
for LINK in $LINKS
do
sudo ip l del $LINK
done
for DIRECTORY in $DIRECTORIES
do
sudo rm $DIRECTORY/*
done
#!/bin/bash
ip link set resB up
ip address add 172.16.1.252/24 dev resB
sysctl net.ipv4.conf.all.forwarding=1
sudo ip r add 10.10.10.0/24 via 172.16.1.254
sudo ip r add 10.0.0.0/24 via 172.16.1.254
sudo ip r add 192.168.100.0/24 via 172.16.1.254
iptables -t nat -A POSTROUTING -s 10.10.10.0/24 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -j MASQUERADE
digraph G {
label = "INFRA RIP OSPF LAB";
labelloc = top;
node [shape=record];
edge [dir=both];
subgraph cluster_0 {
label = poste;
"poste-eth0" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="lightblue"><b>poste-eth0</b></td></tr>
<tr><td align="left">IP: 10.10.10.100/24</td></tr>
</table>
>];
}
subgraph cluster_1 {
label = rout1;
"rout1-eth0" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="lightblue"><b>rout1-eth0</b></td></tr>
<tr><td align="left">IP: 10.10.10.254/24</td></tr>
</table>
>];
"rout1-eth1" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="lightblue"><b>rout1-eth1</b></td></tr>
<tr><td align="left">IP: 172.16.1.253/24</td></tr>
</table>
>];
}
subgraph cluster_2 {
label = rout2;
"rout2-eth0" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="lightblue"><b>rout2-eth0</b></td></tr>
<tr><td align="left">IP: 172.16.1.254/24</td></tr>
</table>
>];
"rout2-eth1" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="lightblue"><b>rout2-eth1</b></td></tr>
<tr><td align="left">IP: 192.168.100.253/24</td></tr>
</table>
>];
}
subgraph cluster_3 {
label = rout3;
"rout3-eth0" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="lightblue"><b>rout3-eth0</b></td></tr>
<tr><td align="left">IP: 10.10.10.253/24</td></tr>
</table>
>];
"rout3-eth1" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="lightblue"><b>rout3-eth1</b></td></tr>
<tr><td align="left">IP: 10.0.0.254/24</td></tr>
</table>
>];
}
subgraph cluster_4 {
label = rout4;
"rout4-eth0" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="lightblue"><b>rout4-eth0</b></td></tr>
<tr><td align="left">IP: 192.168.100.252/24</td></tr>
</table>
>];
"rout4-eth1" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="lightblue"><b>rout4-eth1</b></td></tr>
<tr><td align="left">IP: 10.0.0.253/24</td></tr>
</table>
>];
}
subgraph cluster_5 {
label = resA;
"resA" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="orange"><b>resA</b></td></tr>
</table>
>];
}
subgraph cluster_6 {
label = resB;
"resB" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="orange"><b>resB</b></td></tr>
</table>
>];
}
subgraph cluster_7 {
label = resC;
"resC" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="orange"><b>resC</b></td></tr>
</table>
>];
}
subgraph cluster_8 {
label = resD;
"resD" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="orange"><b>resD</b></td></tr>
</table>
>];
}
"resA"->"poste-eth0";
"resA"->"rout1-eth0";
"resB"->"rout1-eth1";
"resB"->"rout2-eth0";
"resC"->"rout2-eth1";
"resA"->"rout3-eth0";
"resD"->"rout3-eth1";
"resC"->"rout4-eth0";
"resD"->"rout4-eth1";
}
File added
#!/usr/bin/python
# coding=utf8
# la commande de conversion vers le graph est :
# dot -Tpng graph.dot -o graph.png
import subprocess
def get_list(c):
elements = subprocess.check_output(c,shell=True).splitlines()
return [e.split('#') if ('#' in e) else e for e in elements]
interface_desc = """ "%s" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="lightblue"><b>%s</b></td></tr>
<tr><td align="left">IP: %s</td></tr>
</table>
>];"""
switch_desc = """ "%s" [label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr><td bgcolor="orange"><b>%s</b></td></tr>
</table>
>];"""
nom_fichier = 'build_architecture'
cat_fichier = 'cat '+nom_fichier
list_hosts_command = cat_fichier+"|awk '/ip\s+netns\s+add/ { print $4 }'"
list_switches_command = cat_fichier+"|awk '/ovs-vsctl\s+add-br/ { print $3 }'"
list_veths_command = cat_fichier+"|awk '/ip\s+l(ink)?\s+add/ { print $9 \"#\" $4 }'"
list_ports_command = cat_fichier+"|awk '/ovs-vsctl\s+add-port/ { print $3 \"#\" $4}'"
list_addresses_command = cat_fichier+"|awk '/ip a(ddress)?\s*add\s+dev\s+/ { print $9 \"#\" $10 }'"
titre_graphe_command = cat_fichier+"|sed -n 's/^# graphe : \(.*\)/\\1/p'"
list_hosts = get_list(list_hosts_command)
list_switches = get_list(list_switches_command)
list_veths = get_list(list_veths_command)
list_ports = get_list(list_ports_command)
list_addresses = get_list(list_addresses_command)
titre_graphe = subprocess.check_output(titre_graphe_command,shell=True).rstrip('\n')
nom_graphe = titre_graphe or "Net Lab"
#print list_hosts
#print list_switches
#print list_veths
list_veths = [sorted(x,cmp=lambda x,y: -1 if (x[:x.find('-')] in list_switches) else 1) for x in list_veths]
#print list_veths
#print list_ports
#print list_addresses
print """digraph G {
label = "%s";
labelloc = top;
node [shape=record];
edge [dir=both];"""%(nom_graphe)
compteur = 0
for h in list_hosts:
print """subgraph cluster_%d {
label = %s;
"""%(compteur,h)
compteur+=1
interfaces = [i for i in list_addresses if i[0].startswith(h)]
for i in interfaces:
print interface_desc%(i[0],i[0],i[1])
print """ }"""
for s in list_switches:
print """subgraph cluster_%d {
label = %s;
"""%(compteur,s)
compteur+=1
print switch_desc%(s,s)
print """ }"""
dico_veths = dict(list_veths)
for p in list_ports:
print """ "%s"->"%s"; """%(p[0],dico_veths[p[1]])
print "}"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment