From 34f67787900a666ab7bdf3056404d6d859cb4e13 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 21 Oct 2019 20:47:41 +0100 Subject: [PATCH] primera publicacion --- IamTheMain | 0 MantenerFIFO | 6 ++ clusterGRE.py | 33 ++++++++ clustersetup.sh | 182 ++++++++++++++++++++++++++++++++++++++++++ cmdcluster.sh | 4 + discover.sh | 6 ++ ejecutarcontroller.sh | 5 ++ fromwebstart.sh | 2 + id.sh | 2 + mininet | 1 + multiscp.sh | 3 + multissh.sh | 4 + resetcluster.sh | 5 ++ ryu | 1 + showtemp.sh | 2 + startvsorc.sh | 6 ++ topotest.py | 48 +++++++++++ 17 files changed, 310 insertions(+) create mode 100644 IamTheMain create mode 100644 MantenerFIFO create mode 100755 clusterGRE.py create mode 100755 clustersetup.sh create mode 100755 cmdcluster.sh create mode 100755 discover.sh create mode 100755 ejecutarcontroller.sh create mode 100755 fromwebstart.sh create mode 100755 id.sh create mode 160000 mininet create mode 100755 multiscp.sh create mode 100755 multissh.sh create mode 100755 resetcluster.sh create mode 160000 ryu create mode 100755 showtemp.sh create mode 100755 startvsorc.sh create mode 100755 topotest.py diff --git a/IamTheMain b/IamTheMain new file mode 100644 index 0000000..e69de29 diff --git a/MantenerFIFO b/MantenerFIFO new file mode 100644 index 0000000..5a60b39 --- /dev/null +++ b/MantenerFIFO @@ -0,0 +1,6 @@ +mkfifo fifo +exec 3>fifo (deja un file descriptor conectado a el fifo par evitar EOF) +programa < fifo (o si no "cat fifo | programa") +echo "comandoVSORC" >> fifo +echo "otro comandoVSORC" >> fifo +exec 3>&- (esto cierra el tercer file descriptor) diff --git a/clusterGRE.py b/clusterGRE.py new file mode 100755 index 0000000..f14e140 --- /dev/null +++ b/clusterGRE.py @@ -0,0 +1,33 @@ +#!/usr/bin/python +"clusterGRE.py: Mininet Raspberry Pi Cluster" +from mininet.examples.cluster import MininetCluster, SwitchBinPlacer, RemoteGRELink +from mininet.topolib import TreeTopo +from mininet.log import setLogLevel +from mininet.examples.clustercli import ClusterCLI as CLI +from mininet.node import RemoteController +from topotest import MiTopo + +def inicia(): + #IPs = '/home/pi/iplist' + c = RemoteController('c1', ip='192.168.25.10', port=6633) + #servers = readIPs(IPs) + servers = ['192.168.25.2', '192.168.25.3', '192.168.25.4','192.168.25.5','192.168.25.6'] + topo1 = TreeTopo(depth=2, fanout=2) + topo2 = MiTopo() + #topo2.build() + net = MininetCluster(topo=topo2, servers=servers, link=RemoteGRELink, placement=SwitchBinPlacer, controller=c) + net.start() + CLI(net) + net.stop() + + +def readIPs(path): + file = open(path, "r") #abre el archivo en read + if file.mode == "r": + servers = file.read().splitlines() #lee el archivo y lo divide por lineas + return servers + + +if __name__ == '__main__': + setLogLevel('info') + inicia() diff --git a/clustersetup.sh b/clustersetup.sh new file mode 100755 index 0000000..e8ad928 --- /dev/null +++ b/clustersetup.sh @@ -0,0 +1,182 @@ +#!/usr/bin/env bash + +# SSH authentication script for cluster edition +# This script will create a single key pair, which is then +# propagated throughout the entire cluster. +# There are two options for setup; temporary setup +# persistent setup. If no options are specified, and the script +# is only given ip addresses or host names, it will default to +# the temporary setup. An ssh directory is then created in +# /tmp/mn/ssh on each node, and mounted with the keys over the +# user's ssh directory. This setup can easily be torn down by running +# clustersetup with the -c option. +# If the -p option is used, the setup will be persistent. In this +# case, the key pair will be be distributed directly to each node's +# ssh directory, but will be called cluster_key. An option to +# specify this key for use will be added to the config file in each +# user's ssh directory. + + +set -e +num_options=0 +persistent=false +showHelp=false +clean=false +declare -a hosts=() +user=$(whoami) +SSHDIR=/tmp/mn/ssh +USERDIR=$HOME/.ssh +usage="./clustersetup.sh [ -p|h|c ] [ host1 ] [ host2 ] ...\n + Authenticate yourself and other cluster nodes to each other + via ssh for mininet cluster edition. By default, we use a + temporary ssh setup. An ssh directory is mounted over + $USERDIR on each machine in the cluster. + + -h: display this help + -p: create a persistent ssh setup. This will add + new ssh keys and known_hosts to each nodes + $USERDIR directory + -c: method to clean up a temporary ssh setup. + Any hosts taken as arguments will be cleaned + " + +persistentSetup() { + echo "***creating key pair" + ssh-keygen -t rsa -C "Cluster_Edition_Key" -f $USERDIR/cluster_key -N '' # &> /dev/null + cat $USERDIR/cluster_key.pub >> $USERDIR/authorized_keys + echo "***configuring ssh" + echo "IdentityFile $USERDIR/cluster_key" >> $USERDIR/config + echo "IdentityFile $USERDIR/id_rsa" >> $USERDIR/config + + for host in $hosts; do + echo "***copying public key to $host" + ssh-copy-id -i $USERDIR/cluster_key.pub $user@$host &> /dev/null + echo "***copying key pair to remote host" + scp $USERDIR/cluster_key $user@$host:$USERDIR + scp $USERDIR/cluster_key.pub $user@$host:$USERDIR + echo "***configuring remote host" + ssh -o ForwardAgent=yes $user@$host " + echo 'IdentityFile $USERDIR/cluster_key' >> $USERDIR/config + echo 'IdentityFile $USERDIR/id_rsa' >> $USERDIR/config" + done + + for host in $hosts; do + echo "***copying known_hosts to $host" + scp $USERDIR/known_hosts $user@$host:$USERDIR/cluster_known_hosts + ssh $user@$host " + cat $USERDIR/cluster_known_hosts >> $USERDIR/known_hosts + rm $USERDIR/cluster_known_hosts" + done +} + +tempSetup() { + + echo "***creating temporary ssh directory" + mkdir -p $SSHDIR + echo "***creating key pair" + ssh-keygen -t rsa -C "Cluster_Edition_Key" -f $SSHDIR/id_rsa -N '' &> /dev/null + + echo "***mounting temporary ssh directory" + sudo mount --bind $SSHDIR $USERDIR + cp $SSHDIR/id_rsa.pub $SSHDIR/authorized_keys + + for host in $hosts; do + echo "***copying public key to $host" + ssh-copy-id $user@$host &> /dev/null + echo "***mounting remote temporary ssh directory for $host" + ssh -o ForwardAgent=yes $user@$host " + mkdir -p $SSHDIR + cp $USERDIR/authorized_keys $SSHDIR/authorized_keys + sudo mount --bind $SSHDIR $USERDIR" + echo "***copying key pair to $host" + scp $SSHDIR/{id_rsa,id_rsa.pub} $user@$host:$SSHDIR + done + + for host in $hosts; do + echo "***copying known_hosts to $host" + scp $SSHDIR/known_hosts $user@$host:$SSHDIR + done +} + +cleanup() { + + for host in $hosts; do + echo "***cleaning up $host" + ssh $user@$host "sudo umount $USERDIR + sudo rm -rf $SSHDIR" + done + + echo "**unmounting local directories" + sudo umount $USERDIR + echo "***removing temporary ssh directory" + sudo rm -rf $SSHDIR + echo "done!" + +} + + +if [ $# -eq 0 ]; then + echo "ERROR: No Arguments" + echo "$usage" + exit +else + while getopts 'hpc' OPTION + do + ((num_options+=1)) + case $OPTION in + h) showHelp=true;; + p) persistent=true;; + c) clean=true;; + ?) showHelp=true;; + esac + done + shift $(($OPTIND - 1)) +fi + +if [ "$num_options" -gt 1 ]; then + echo "ERROR: Too Many Options" + echo "$usage" + exit +fi + +if $showHelp; then + echo "$usage" + exit +fi + +for i in "$@"; do + output=$(getent ahostsv4 "$i") + if [ -z "$output" ]; then + echo '***WARNING: could not find hostname "$i"' + echo "" + else + hosts+="$i " + fi +done + +if $clean; then + cleanup + exit +fi + +echo "***authenticating to:" +for host in $hosts; do + echo "$host" +done + +echo + +if $persistent; then + echo '***Setting up persistent SSH configuration between all nodes' + persistentSetup + echo $'\n*** Sucessfully set up ssh throughout the cluster!' + +else + echo '*** Setting up temporary SSH configuration between all nodes' + tempSetup + echo $'\n***Finished temporary setup. When you are done with your cluster' + echo $' session, tear down the SSH connections with' + echo $' ./clustersetup.sh -c '$hosts'' +fi + +echo diff --git a/cmdcluster.sh b/cmdcluster.sh new file mode 100755 index 0000000..ff513f1 --- /dev/null +++ b/cmdcluster.sh @@ -0,0 +1,4 @@ +#!/bin/bash +#sudo -E mn --controller=remote,ip=192.168.25.10 --custom ~/topotest.py --topo TopoMia --cluster $(awk 'BEGIN { ORS="" } { print p$0; p="," } END { print "\n" }' iplist) -v debug +sudo -E mn --controller=remote,ip=192.168.25.10 --topo tree,2,2 --cluster $(awk 'BEGIN { ORS="" } { print p$0; p="," } END { print "\n" }' iplist) -v debug + diff --git a/discover.sh b/discover.sh new file mode 100755 index 0000000..e7122db --- /dev/null +++ b/discover.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +#nmap -sn 192.168.18.83/25 | grep 192 > log.txt && awk '{print $5}' log.txt | grep 192 | tee log.txt +#for HOST in $(cat log.txt ) ; do ssh $HOST "uname -a" ; done +nmap -sn $1 > log.txt +grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" log.txt > iplist diff --git a/ejecutarcontroller.sh b/ejecutarcontroller.sh new file mode 100755 index 0000000..2258687 --- /dev/null +++ b/ejecutarcontroller.sh @@ -0,0 +1,5 @@ +#!/bin/bash +cd ryu +sudo ./bin/ryu-manager --observe-links /home/pi/flowmanager/flowmanager/flowmanager.py ryu/app/simple_switch_13.py +#./ejecutarcontroller.sh > /dev/null 2>&1 & Para ejecutarlo en segundo plano + diff --git a/fromwebstart.sh b/fromwebstart.sh new file mode 100755 index 0000000..0fcea68 --- /dev/null +++ b/fromwebstart.sh @@ -0,0 +1,2 @@ +#!/bin/bash +sudo ./home/pi/clusterGRE.py > aichivo 2>&1 diff --git a/id.sh b/id.sh new file mode 100755 index 0000000..bde7df4 --- /dev/null +++ b/id.sh @@ -0,0 +1,2 @@ +#!/bin/bash +echo $(ifconfig | grep inet | grep -v inet6 | grep -v 127.0.0.7) | awk '{print $2}' | awk -F "." '{print $4}' diff --git a/mininet b/mininet new file mode 160000 index 0000000..e203808 --- /dev/null +++ b/mininet @@ -0,0 +1 @@ +Subproject commit e203808a20e6eec9e4368757cdccce7010eab548 diff --git a/multiscp.sh b/multiscp.sh new file mode 100755 index 0000000..9e81bfb --- /dev/null +++ b/multiscp.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +pscp -h iplist -A -l pi "$@" diff --git a/multissh.sh b/multissh.sh new file mode 100755 index 0000000..037bea5 --- /dev/null +++ b/multissh.sh @@ -0,0 +1,4 @@ +#!/bin/bash +#Ingresar el comando por parametro y se ejecuta abriendo una sesion ssh +#con las Ip del archivo iplist(todas las pi) +pssh -h iplist -i -l pi "$@" diff --git a/resetcluster.sh b/resetcluster.sh new file mode 100755 index 0000000..2cb3e5e --- /dev/null +++ b/resetcluster.sh @@ -0,0 +1,5 @@ +#!/bin/bash +#Ingresar el comando por parametro y se ejecuta abriendo una sesion ssh +#con las Ip del archivo iplist(todas las pi) +pssh -h iplist -i -l pi "sudo reboot now" +sudo reboot now diff --git a/ryu b/ryu new file mode 160000 index 0000000..6456711 --- /dev/null +++ b/ryu @@ -0,0 +1 @@ +Subproject commit 6456711a343bd9999491bee2eb059c218170cc50 diff --git a/showtemp.sh b/showtemp.sh new file mode 100755 index 0000000..6aa102d --- /dev/null +++ b/showtemp.sh @@ -0,0 +1,2 @@ +watch -n 3 "(vcgencmd measure_temp && ./multissh.sh vcgencmd measure_temp) | grep temp" + diff --git a/startvsorc.sh b/startvsorc.sh new file mode 100755 index 0000000..cc8bd27 --- /dev/null +++ b/startvsorc.sh @@ -0,0 +1,6 @@ +#!/bin/bash +cd /home/pi && mkfifo fifo && touch aichivo +cd /home/pi && cat fifo | sudo ./clusterGRE.py > aichivo 2>&1 & +exec 3>fifo + + diff --git a/topotest.py b/topotest.py new file mode 100755 index 0000000..9061296 --- /dev/null +++ b/topotest.py @@ -0,0 +1,48 @@ +#!/usr/bin/python + +from mininet.topo import Topo +from mininet.log import setLogLevel, info +# from mininet.node import Controller, RemoteController, OVSController +# from mininet.node import CPULimitedHost, Host, Node +# from mininet.node import OVSKernelSwitch, UserSwitch +# from mininet.node import IVSSwitch +# from mininet.cli import CLI +# from mininet.link import TCLink, Intf +# from subprocess import call + + +class MiTopo(Topo): + + def build(self): + #Contructor de topologia custom + s4 = self.addSwitch('s4') + s2 = self.addSwitch('s2') + s3 = self.addSwitch('s3') + s1 = self.addSwitch('s1') + h8 = self.addHost('h8') + h4 = self.addHost('h4') + h6 = self.addHost('h6') + h1 = self.addHost('h1') + h5 = self.addHost('h5') + h2 = self.addHost('h2') + h3 = self.addHost('h3') + h7 = self.addHost('h7') + h9 = self.addHost('h9') + + + self.addLink(h1, s2) + self.addLink(h9, s4) + self.addLink(h2, s2) + self.addLink(s1, s2) + self.addLink(s1, s3) + self.addLink(s3, s4) + self.addLink(h3, s1) + self.addLink(h4, s1) + self.addLink(h5, s3) + self.addLink(h6, s3) + self.addLink(h7, s4) + self.addLink(h8, s4) + info('llegue al final de mitopo\n') + + +#topos = { 'TopoMia': ( lambda: MiTopo() ) } -- 2.25.1