Commit c55677dd03d4d0003b9f6a7b547b806b255f1b90

Authored by Alejandro Blanco
1 parent 53fa4601
Exists in master

Uploading Containernet scripts

Containernet/analysis-cpu-mem.py 0 → 100644
... ... @@ -0,0 +1,49 @@
  1 +# -*- coding: utf-8 -*-
  2 +"""
  3 +Created on Tue Jun 19 10:34:31 2018
  4 +
  5 +@author: imdea
  6 +"""
  7 +
  8 +import csv
  9 +from collections import defaultdict
  10 +import numpy as np
  11 +import matplotlib.pyplot as plt
  12 +from datetime import datetime, timedelta
  13 +import dateutil.parser
  14 +import matplotlib.dates as mdates
  15 +
  16 +cpu_vector = []
  17 +memory_vector = []
  18 +time_vector = []
  19 +
  20 +columns = defaultdict(list) # each value in each column is appended to a list
  21 +
  22 +with open('monitor-cpu-memory-load.csv') as f: # obtained through glances
  23 + reader = csv.DictReader(f) # read rows into a dictionary format
  24 + for row in reader: # read a row as {column1: value1, column2: value2,...}
  25 + for (k,v) in row.items(): # go over each column name and value
  26 + columns[k].append(v) # append the value into the appropriate list
  27 + # based on column name k
  28 +
  29 +#print(columns['now'])
  30 +#print(columns['cpu.user'])
  31 +#print(columns['mem.used'])
  32 +#print(len(columns['now']),len(columns['mem.used']))
  33 +
  34 +for j in range (len(columns['now'])):
  35 + d = dateutil.parser.parse(columns['now'][j])
  36 + time_vector.append(d.strftime('%H:%M:%S'))
  37 + #print(d.strftime('%H:%M:%S')) #==> '09/26/2008'
  38 +
  39 +for k in range (len(columns['mem.used'])):
  40 + memory_vector.append(int(columns['mem.used'][k]))
  41 + print(time_vector[k],int(columns['mem.used'][k]))# printing the file for the mem.used
  42 +
  43 +for i in range (len(columns['cpu.user'])):
  44 + memory_vector.append(float(columns['cpu.user'][i]))
  45 + #print(time_vector[i],float(columns['cpu.user'][i]))# printing the file for the cpu.user
  46 +
  47 +for l in range (len(columns['cpu.system'])):
  48 + memory_vector.append(float(columns['cpu.system'][l]))
  49 + #print(time_vector[l],float(columns['cpu.system'][l]))# printing the file for the cpu.system
... ...
Containernet/openleon-datacenter.py 0 → 100644
... ... @@ -0,0 +1,113 @@
  1 +# This is a test example
  2 +
  3 +import unittest
  4 +import sys
  5 +import time
  6 +import os
  7 +import random
  8 +import subprocess
  9 +sys.path.append('.')
  10 +from time import sleep
  11 +from mininet.net import Containernet
  12 +from mininet.node import Ryu, OVSSwitch
  13 +from mininet.node import Host
  14 +from mininet.clean import cleanup
  15 +from mininet.link import TCLink
  16 +from mininet.cli import CLI
  17 +from openleon_datacenter_tier3 import MyTopo
  18 +from mininet.term import cleanUpScreens, makeTerms
  19 +
  20 +
  21 +class testSwitchTopo(object):
  22 + "Test ping with the specified topology"
  23 + topoClass = None # Override with topology
  24 + ryuParams = ['ryu.app.simple_switch_13']
  25 + mayDrop = 0
  26 + top=MyTopo(2, 2, 4, 2)
  27 +
  28 +
  29 + # This is to enable the RYU controller, which enables loop-free routes that the standard SDN controller doesn't enable
  30 + def controller(self, name, **params):
  31 + return Ryu(name, *self.ryuParams, **params)
  32 +
  33 + @staticmethod
  34 + def tearDown():
  35 + "Clean up the network"
  36 + if sys.exc_info != (None, None, None):
  37 + cleanup()
  38 +
  39 +
  40 +
  41 + def testPing(self):
  42 + "Create the network and run a ping test"
  43 + #
  44 + print("*** Creating the datacenter topology")
  45 + net = Containernet(topo=self.topoClass(2, 2, 4, 2), controller=self.controller, host=Host,
  46 + #net = Containernet(topo=self.topoClass(2, 4, 8, 8), controller=self.controller, host=Host,
  47 + switch=OVSSwitch, link=TCLink, waitConnected=True)
  48 +
  49 + """Test with the dockers"""
  50 + d1 = net.addDocker('d1', ip='10.0.0.112', dimage="ubuntu:trusty")
  51 + d2 = net.addDocker('d2', ip='10.0.0.113', dimage="ubuntu:trusty")
  52 + net.addLink('d1','s4')
  53 + net.addLink('d2','s4')
  54 +
  55 + #net.link.bw=10000
  56 + net.addNAT().configDefault()
  57 + net.hosts[0].cmd('sysctl net.ipv4.ip_forward=1')
  58 + print net.hosts[-1]
  59 + print("*** End printing hosts")
  60 +
  61 + for i in range (len(net.hosts)-1):
  62 + print(net.hosts[i+1])
  63 + net.hosts[1+i].cmd('sudo ip route add 10.16.0.0/12 via 10.0.0.1')
  64 +
  65 + #net.hosts[-1].cmd('sudo ip route add 10.16.0.0/12 via 10.0.0.1')
  66 +
  67 + net.hosts[0].cmd('iptables -t nat -A POSTROUTING -j MASQUERADE')
  68 + #net.hosts[-1].cmd('sudo ip route add 10.0.0.8 via 10.0.0.1')
  69 + net.start()
  70 + client=[]
  71 + server=[]
  72 + for i in range ((len(net.hosts)-1)/2):
  73 + client.append(net.hosts[2*(i)])
  74 + server.append(net.hosts[2*(i)+1])
  75 +
  76 +
  77 + b= server[:]
  78 + b_shuffle = [x for x in range(0, len(server))]
  79 + random.shuffle(b)
  80 + #print b
  81 + #print b_shuffle
  82 +
  83 + CLI(net)
  84 + # This open the mininet terminal and it allows to launch Mininet's commands
  85 +
  86 +
  87 +
  88 +
  89 + """for i in range (len(client)):
  90 + b[i].cmd('iperf -s -u &')
  91 + client[i].cmd('iperf -c ' + b[i].IP() + ' -t 10000 -i 1 -u -b 10M &')
  92 + net.hosts[0].cmd('wireshark')"""
  93 +
  94 +
  95 + """sleep(10)
  96 + net.hosts[0].cmd('iperf -s &')
  97 + net.hosts[1].cmd('iperf -c 10.0.0.1 -t 10000 -i 1 -u -b 50M &')
  98 + net.hosts[2].cmd('iperf -s &')
  99 + net.hosts[3].cmd('iperf -c 10.0.0.1 -t 10000 -i 1 -u -b 50M &')"""
  100 +
  101 + net.stop()
  102 + #net.ping()
  103 +
  104 + #net.myiperf(net.hosts,10)
  105 +
  106 +class TestDatacenter_tier3(testSwitchTopo, unittest.TestCase):
  107 + "Test the HA Root datacenter topolog"
  108 + topoClass= MyTopo
  109 + ryuParams= ['ryu.app.simple_switch_stp']
  110 + mayDrop = 15
  111 +
  112 +if __name__ == '__main__':
  113 + unittest.main()
... ...
Containernet/openleon-distr-datacenters.py 0 → 100644
... ... @@ -0,0 +1,98 @@
  1 +# openleon distributed edge data centers with containers
  2 +
  3 +import unittest
  4 +import sys
  5 +import time
  6 +import os
  7 +import random
  8 +import subprocess
  9 +sys.path.append('.')
  10 +from time import sleep
  11 +from mininet.net import Containernet
  12 +from mininet.node import Ryu, OVSSwitch
  13 +from mininet.node import Node, Host
  14 +from mininet.node import Controller
  15 +from mininet.node import Docker
  16 +from mininet.clean import cleanup
  17 +from mininet.link import TCLink, Link
  18 +from mininet.cli import CLI
  19 +from mininet.term import cleanUpScreens, makeTerms
  20 +from mininet.log import setLogLevel, info
  21 +
  22 +from sys import exit
  23 +import os.path
  24 +from subprocess import Popen, STDOUT, PIPE
  25 +
  26 +def topology():
  27 +
  28 + "Create a network with some docker containers acting as hosts."
  29 + net = Containernet(controller=Controller,switch=OVSSwitch, link=TCLink, waitConnected=True)
  30 +
  31 + info('*** Adding controller\n')
  32 + net.addController('c0')
  33 +
  34 + info('*** Adding switches\n')
  35 + s1 = net.addSwitch('s1')
  36 + s2 = net.addSwitch('s2')
  37 + s3 = net.addSwitch('s3')
  38 +
  39 + info('*** Adding docker containers and hosts\n')
  40 + ###### FIRST edge data center
  41 + hepc = net.addHost('hepc', ip='10.0.0.1/24', mac="00:00:00:00:00:01")
  42 + h1 = net.addHost('h1', ip='10.0.0.2/24', mac="00:00:00:00:00:02")
  43 + d1 = net.addDocker('d1', ip='10.0.0.3/24', dimage="furiousgeorge/cpuload", cpu_period=50000,cpu_quota=25000)
  44 + #d1.sendCmd("./CPULoadGenerator.py -c 0 -l 0.3 -d 30")
  45 + d2 = net.addDocker('d2', ip='10.0.0.4/24', dimage="furiousgeorge/cpuload", cpu_period=50000,cpu_quota=25000)
  46 + d3 = net.addDocker('d3', ip='10.0.0.5/24', dimage="ubuntu:trusty")
  47 + d4 = net.addDocker('d4', ip='10.0.0.6/24', dimage="ubuntu:trusty")
  48 + h2 = net.addHost('h2', ip='10.0.0.7/24',mac="00:00:00:00:00:03")
  49 +
  50 + ###### SECOND edge data center
  51 + h3 = net.addHost('h3', ip='10.0.0.101/24',mac="00:00:00:00:00:04")
  52 + d5 = net.addDocker('d5', ip='10.0.0.102/24', dimage="sofianinho/iperf3:3.6-ubuntu18.04")# this sets up a iperf3 docker
  53 + d6 = net.addDocker('d6', ip='10.0.0.103/24', dimage="ubuntu:trusty")
  54 + d7 = net.addDocker('d7', ip='10.0.0.104/24', dimage="ubuntu:trusty")
  55 + h4 = net.addHost('h4', ip='10.0.0.105/24',mac="00:00:00:00:00:05")
  56 +
  57 + info('*** Creating links\n')
  58 + net.addLink(hepc, s1,bw=1000)# port 2 of s1, link at 1 Gbps
  59 + net.addLink(h1, s2,bw=1000)# port 3 of s1, link at 1 Gbps
  60 + net.addLink(h2, s2,bw=1000)# port 4 of s1, link at 1 Gbps
  61 + net.addLink(d1, s1)
  62 + net.addLink(d2, s1)
  63 + net.addLink(d3, s1)
  64 + net.addLink(d4, s1)
  65 + net.addLink(s1, s2)
  66 + net.addLink(s1, s3, cls=TCLink, delay='4ms')
  67 + net.addLink(s3, h3,bw=1000)# port 2 of s2
  68 + net.addLink(s3, h4,bw=1000)# port 3 of s2
  69 + net.addLink(s3, d5)
  70 + net.addLink(s3, d6)
  71 + net.addLink(s3, d7)
  72 +
  73 + # router configuration
  74 +
  75 + # building the network
  76 + net.build()
  77 +
  78 + # to work, recall to include the NAT right after having created all the links and build the network
  79 + net.addNAT().configDefault()
  80 + net.hosts[0].cmd('sysctl net.ipv4.ip_forward=1')
  81 + net.hosts[0].cmd('iptables -t nat -A POSTROUTING -j MASQUERADE')
  82 +
  83 + for i in range (len(net.hosts)-1):
  84 + #print(net.hosts[i+1])
  85 + net.hosts[1+i].cmd("sudo ip route add 10.16.0.0/12 via 10.0.0.1")
  86 +
  87 + info('*** Starting network\n')
  88 + net.start()
  89 +
  90 + info('*** Running CLI\n')
  91 + CLI(net)
  92 +
  93 + info('*** Stopping network\n')
  94 + net.stop()
  95 +
  96 +if __name__ == '__main__':
  97 + setLogLevel('info')
  98 + topology()
... ...
Containernet/openleon_datacenter_tier3.py 0 → 100644
... ... @@ -0,0 +1,72 @@
  1 +# This file creates a 3-tier data center topology
  2 +from mininet.net import Containernet
  3 +from mininet.topo import Topo
  4 +from mininet.link import TCLink
  5 +from mininet.node import CPULimitedHost
  6 +from mininet.node import Controller
  7 +from mininet.nodelib import NAT
  8 +from mininet.log import info, setLogLevel
  9 +"""setLogLevel('info')"""
  10 +
  11 +class MyTopo( Topo ):
  12 + "Simple topology example."
  13 +
  14 + def __init__( self, core=3, aggregation=6, edge=9, h=2, **opts):
  15 + info("*** Creating custom datacenter topology\n")
  16 + Core= [core]
  17 + Aggr= [aggregation]
  18 + Edge=[edge]
  19 + self.Host=[edge*h]
  20 +
  21 + "Topo.__init__(self)"
  22 + super(MyTopo, self).__init__(**opts)
  23 +
  24 + # Add hosts and switches
  25 + info("*** Creating Core Switches\n")
  26 + for i in range(core):
  27 + Core.append(self.addSwitch('s%s' % i))
  28 + print(Core[i+1])
  29 +
  30 + info("*** Creating Aggregation Switches\n")
  31 + for i in range(aggregation):
  32 + Aggr.append(self.addSwitch('s%s' % (i+core)))
  33 +
  34 + info("*** Creating Edge Switches\n")
  35 + for i in range(edge):
  36 + Edge.append(self.addSwitch('s%s' % (i+core+aggregation)))
  37 +
  38 + info("*** Creating Hosts\n")
  39 + for i in range (h*edge):
  40 + self.Host.append(self.addHost('h%s' % i))
  41 +
  42 + # Add links
  43 + "Links between Core and Aggregation Switches: All connected"
  44 + for i in range (core):
  45 + for j in range (aggregation):
  46 + self.addLink( Core[i+1], Aggr[j+1], bw=1000)
  47 +
  48 + """LInks between Aggregation and Edge Switches: We make groups depending on
  49 + the number of core switches"""
  50 + n=0
  51 + m=0
  52 + for k in range (core):
  53 + for i in range(n,aggregation/core+n):
  54 + for j in range (m, edge/core+m):
  55 + self.addLink(Aggr[i+1], Edge[j+1], bw=1000)
  56 + n=n+aggregation/core
  57 + m=m+edge/core
  58 +
  59 + n=0
  60 + """Links between Edge Switches and hosts: h hosts for each Swith"""
  61 + for i in range (edge):
  62 + for j in range(n,h+n):
  63 + self.addLink(Edge[i+1], self.Host[j+1], bw=1000)
  64 +
  65 + n=n+h
  66 +
  67 + def hosts(n=1):
  68 + return self.Host[n]
  69 +
  70 +
  71 +topos = { 'mytopo': MyTopo }
  72 +print("Finished")
... ...
Containernet/ping-from-host.sh 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +#!/bin/bash
  2 +# script for repeated pings interleaved with <x> seconds
  3 +
  4 +touch ../Documents/claudio-openleon-transports-experiments/ping-distr-datacenters/$1
  5 +ping 10.16.0.2 -c 5 | tail -n 1 > ../Documents/claudio-openleon-transports-experiments/ping-distr-datacenters/$1
  6 +
  7 +for ((i=1; i<=49; i++ )) do
  8 + ping 10.16.0.2 -c 5 | tail -n 1 >> ../Documents/claudio-openleon-transports-experiments/ping-distr-datacenters/$1
  9 + sleep 4
  10 +done
... ...
Containernet/pyshark--throughput-analysis.py 0 → 100644
... ... @@ -0,0 +1,71 @@
  1 +# The script analyzes directly a PCAP trace
  2 +# Remember to include the filter in display_filter
  3 +# CF - 2019
  4 +
  5 +import pyshark
  6 +from datetime import datetime
  7 +import time
  8 +import math
  9 +import numpy as np
  10 +from matplotlib import pyplot as plt
  11 +
  12 +###########################################
  13 +#
  14 +# DATA Traffic (code 1)
  15 +#
  16 +###########################################
  17 +
  18 +cap = pyshark.FileCapture('./compressed-trace.pcap',
  19 + display_filter="ip.src==10.16.0.2 && tcp.srcport==60204 && ip.dst==10.0.0.11 && tcp.dstport==5001")
  20 +
  21 +totPkt=0
  22 +totData=0
  23 +
  24 +ref=float(cap[0].sniff_timestamp)
  25 +#print (ref)
  26 +
  27 +# dictionary to store in form of key-value the tuple (time/amount of data in the given time)
  28 +# and compute throughput
  29 +thr_dict = {}
  30 +
  31 +for pkt in cap:
  32 + totData= totData+ int(pkt.tcp.len)
  33 + totPkt= totPkt + 1
  34 + #print (pkt.sniff_timestamp," ", pkt.tcp.len)
  35 +
  36 + # * * * * to check the time
  37 + #inDate=pkt.sniff_time
  38 + #d=datetime.strptime(str(inDate), "%Y-%m-%d %H:%M:%S.%f")
  39 + #print (time.mktime(d.timetuple()), " ", pkt.tcp.len)
  40 +
  41 + # doing the timediff from the first element to check time progress
  42 + timediff=float(pkt.sniff_timestamp)-ref
  43 + i, d = divmod(timediff, 1)
  44 + #print (i,pkt.tcp.len)
  45 +
  46 +
  47 + # insertion in the dictionary: if the value does not exitst,
  48 + # then we create the new tuple, otherwise we just sum the data field
  49 + if i not in thr_dict:
  50 + thr_dict[i] = int(pkt.tcp.len)
  51 + else:
  52 + thr_dict[i] += int(pkt.tcp.len)
  53 +
  54 +
  55 +# printing the dictionary
  56 +for key, value in thr_dict.items() :
  57 + print (key, value)
  58 +
  59 +# plot
  60 +keys = np.fromiter(thr_dict.keys(), dtype=float)
  61 +vals = np.fromiter(thr_dict.values(), dtype=float)
  62 +data=(((vals*8)/1024)/1024)
  63 +timeinterval=keys/1
  64 +plt.plot(timeinterval, data)
  65 +
  66 +plt.xlabel("Time (s)", fontsize = 20)
  67 +plt.ylabel("Throughput (Mbit/s)", fontsize = 20)
  68 +
  69 +plt.show()
  70 +
  71 +#print("Tot pkt - tot data",totPkt,totData)
... ...
Containernet/test.txt
... ... @@ -1 +0,0 @@
1   -Hola