not important

edoardoColi
edoardocoli 1 year ago
parent 6a2f5ff321
commit ff04fa7aed

@ -87,6 +87,6 @@ In order to build a custom network topology I used Mininet and Python tools; in
TODO dependencies
```
The *MininetNetPractice.py* program showcases the ability to parse and extract data from the configuration file to define the desired network topology. Using the Mininet API, the program reads and parses the *MininetTopo.conf* file, which contains information about the network topology. By leveraging the parsed data, the program creates a virtual network with the desired topology, replicating the specified network configuration. This allows for the creation of custom and complex network scenarios tailored to specific research or testing requirements.
Referring to a random topology, like the one in the figure below, we can create a configuration file that brings back exactly these parameters within the Mininet topology in order to interact with them. The configuration file *MininetTopo.conf* represents it. Some notes for the creation are reported there as a structure model, together with some constraints to be respected. Another important aspect to allow the network to function is to manage the routers routing table(**TODO in MininetTopo.conf**).
Referring to a random topology, like the one in the figure below, we can create a configuration file that brings back exactly these parameters within the Mininet topology in order to interact with them. The configuration file *MininetTopo.conf* represents it. Some notes for the creation are reported there as a structure model, together with some constraints to be respected. Another important aspect to allow the network to function is to manage the routers routing table(**TODO inside MininetTopo.conf**).
<img src=https://github.com/edoardoColi/5G_Sandbox/blob/edoardoColi/images/MininetConf/topology.jpeg width="105%" height="105%">
I tested the mininet emulation software to reproduce a real situation of a cluster. Within this [file.pdf](https://github.com/edoardoColi/5G_Sandbox/blob/edoardoColi/docs/MininetConf/researchReport.pdf) it is possible to view all my comparison analysis and the conclusions I have reached.

@ -0,0 +1,156 @@
from mininet.net import Mininet
from mininet.link import TCLink
from mininet.topo import Topo
from mininet.node import Node
from mininet.cli import CLI
from mininet.log import setLogLevel
import subprocess
import multiprocessing
#
# for j in {1..20}; do echo "Test for runtest$j"; for i in {1..20}; do awk 'c&&!--c;/steffe'$i'/{c=7}' runtest$j|awk -F " " '{s+=$8}; END {printf "%d\n",s/100}' ;done; done
#
class MyRouter (Node):
def config(self, **params):
super(MyRouter, self).config(**params)
self.cmd('sysctl net.ipv4.ip_forward=1') #Enable forwarding on the router
def terminate(self):
self.cmd('sysctl net.ipv4.ip_forward=0') #Disable forwarding on the router
super(MyRouter, self).terminate
def run_command(host, command):
# print("Sto per eseguire: "+command)
output = host.cmd(command)
# with open('runtestTraffic1', 'a') as file:##############################
# file.write(output)
# file.write(output + '************************************************************\n************************************************************\n')
def build_topology(config_file):
topo = Topo()
elements = {} # Dictionary to store nodes
with open(config_file, 'r') as file:
for line in file:
line = line.strip()
if line.startswith('#'): #Skip comment
continue
parts = line.split(" ") #Parse the topology file using spaces
if parts[0] == 'N_host': #Parse hosts
host_name = parts[1]
elements[host_name] = topo.addHost(host_name)
elif parts[0] == 'N_router': #Parse routers
router_name = parts[1]
elements[router_name] = topo.addNode(router_name)
elif parts[0] == 'N_switch': #Parse switches
switch_name = parts[1]
elements[switch_name] = topo.addSwitch(switch_name)
elif parts[0] == 'NN_link': #Parse general links nodes to nodes
node1 = parts[1]
node2 = parts[2]
topo.addLink(elements.get(node1), elements.get(node2))
elif parts[0] == 'SN_link': #Parse general links switches to nodes
switch = parts[1]
node = parts[2]
bandwidth = int(parts[3])
topo.addLink(elements.get(switch), elements.get(node), bw=bandwidth)
if parts[0] == 'host': #Parse hosts
host_name = parts[1]
host_ip = parts[2]
host_nexthop = 'via ' + parts[3]
elements[host_name] = topo.addHost(host_name, ip=host_ip, defaultRoute=host_nexthop)
elif parts[0] == 'router': #Parse routers
router_name = parts[1]
router_ip = parts[2]
elements[router_name] = topo.addNode(router_name, cls=MyRouter, ip=router_ip)
elif parts[0] == 'linkRR': #Parse links routers to routers
router1 = parts[1]
router1_intfName = parts[2]
router1_intfIP = parts[3]
router2 = parts[4]
router2_intfName = parts[5]
router2_intfIP = parts[6]
topo.addLink(elements.get(router1), elements.get(router2), intfName1=router1_intfName, intfName2=router2_intfName, params1={'ip' : router1_intfIP}, params2={'ip' : router2_intfIP})
elif parts[0] == 'linkRH': #Parse links routers to hosts
host = parts[1]
host_intfName = parts[2]
router = parts[3]
router_intfName = parts[4]
router_intfIP = parts[5]
topo.addLink(elements.get(host), elements.get(router), intfName1=host_intfName, intfName2=router_intfName, params2={'ip' : router_intfIP})
elif parts[0] == 'linkRS': #Parse links routers to switches
switch = parts[1]
router = parts[2]
router_intfName = parts[3]
router_intfIP = parts[4]
topo.addLink(elements.get(switch), elements.get(router), intfName2=router_intfName, params2={'ip' : router_intfIP})
elif parts[0] == 'linkSS': #Parse links switches to switches
switch1 = parts[1]
switch2 = parts[2]
topo.addLink(elements.get(switch1), elements.get(switch2))
elif parts[0] == 'linkSH': #Parse links switches to hosts
switch = parts[1]
host = parts[2]
host_intfName = parts[3]
topo.addLink(elements.get(switch), elements.get(host), intfName2=host_intfName)
return topo
def run_topology(config_file):
setLogLevel('info') #Different logging levels are 'info' 'warning' 'error' 'debug'
topo = build_topology(config_file)
net = Mininet(topo=topo, link=TCLink)
net.start() #Starting the network
with open(config_file, 'r') as file: #Search in the configuration file for routing table
for line in file:
line = line.strip()
if line.startswith('#'): #Skip comment
continue
parts = line.split(" ")
if parts[0] == 'route': #Parse routing tables
name = parts[1]
pck_src = parts[2]
pck_nexthop = parts[3]
interf = parts[4]
cmd = 'ip route add ' + pck_src + ' via ' + pck_nexthop + ' dev ' + interf
(net.getNodeByName(name)).cmd(cmd)
print("QUI PRIMA")
(net.getNodeByName("steffe0")).cmd("iperf -s -P 2000 &")
(net.getNodeByName("steffe1")).cmd("iperf -s -P 2000 &")
(net.getNodeByName("steffe2")).cmd("iperf -s -P 2000 &")
# (net.getNodeByName("steffe0")).cmd("rm -f esito.out")
# (net.getNodeByName("steffe0")).cmd("iperf -P 100 -s > /dev/null &")##############################
# hosts = ["steffe1","steffe2","steffe3","steffe4","steffe5","steffe6","steffe7","steffe8","steffe9","steffe10","steffe11","steffe12","steffe13","steffe14","steffe15","steffe16","steffe17","steffe18","steffe19","steffe20"] # Esempio##############################
# for i in range(0,100):
# print(i)
# processes = []
# for host in hosts:
# command = 'echo -n "Runned on "; date; echo '+host+'; iperf -c 10.0.0.1 -t 5' # Esempio di comando (ping)
# p = multiprocessing.Process(target=run_command, args=(net.getNodeByName(host), command))
# p.start()
# processes.append(p)
# # Attende il completamento di tutti i processi
# for p in processes:
# p.join()
print("QUI DOPO")
CLI(net)
net.stop() #Stopping the network
if __name__ == '__main__':
run_topology('SteffeCluster.conf')

@ -1,77 +0,0 @@
from mininet.net import Mininet
from mininet.node import Node
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import setLogLevel
class MyRouter (Node):
def config(self, **params):
super(MyRouter, self).config(**params)
self.cmd('sysctl net.ipv4.ip_forward=1') #Enable forwarding on the router
def terminate(self):
self.cmd('sysctl net.ipv4.ip_forward=0') #Disable forwarding on the router
super(MyRouter, self).terminate
def run_topology(config_file):
setLogLevel('info') #Different logging levels are 'info' 'warning' 'error' 'debug'
net = Mininet(link=TCLink)
# Create a host with the desired interface and IP
host3 = net.addHost('h4', ip='150.152.40.131/26')
host3.setDefaultRoute('via 150.152.40.129')
host4 = net.addHost('h3', ip='150.152.40.194/30')
host4.setDefaultRoute('via 150.152.40.193')
# Create a router with two interfaces and default routes
router2 = net.addHost('r2', cls=MyRouter)
# Add interfaces to the router
# net.addLink(router2, host3, intfName1='r33', intfName2='h31', params1={'ip': '161.46.247.195/24'}, params2={'ip': '161.46.247.196/24'})
# net.addLink(router, intfName1='r21', params1={'ip': '161.46.247.129/30'})
# Set the default routes on the router
# router2.cmd('ip route add default via 161.46.247.254 dev r33')
# router2.cmd('ip route add default via 161.46.247.130 dev r21')
net.start() #Starting the network
net.pingAll()
CLI(net)
net.stop() #Stopping the network
if __name__ == '__main__':
run_topology('MininetTopo.conf')
# def build_topology(config_file):
# topo = Topo()
# # Create a host with the desired interface and IP
# hh = topo.addHost('h1', ip='161.46.247.196/24', defaultRoute='via 161.45.247.195')
# hh.setDefaultRoute = ''
# topo.addHost('h2', ip='161.46.247.197/24', defaultRoute='via 161.45.247.195')
# # Create a router with an interface and default route
# topo.addNode('r1', cls=MyRouter, ip='161.46.247.195/24')
# # Add a link between the host and router
# topo.addLink('h1', 'r1')
# topo.addLink('h2', 'r1')
# return topo
# class MyTopo (Topo):
# def build( self, *args, **params ):
# host = self.addHost('h1', ip='161.46.247.196/24')
# host.setDefaultRoute('via 161.45.247.195')
# self.addHost('h2')
# self.addNode('r1', cls=MyRouter)
# self.addLink('h1', 'h2')
# # self.addLink('h1', 'r1', intfName1='H11', intfName2='R11', params1={'ip' : '161.46.247.131/26'}, params2={'ip' : '161.46.247.129/26'})
# # self.addLink('h2', 'r1', intfName1='H21', intfName2='R12', params1={'ip' : '161.46.247.196/27'}, params2={'ip' : '161.46.247.195/27'})

Binary file not shown.

@ -1,7 +1,5 @@
# Usefull to know
# sudo fuser -k 6653/tcp
# sudo mn -c
TODO better
Per far funzionare le cose serve:

Loading…
Cancel
Save