mirror of
https://github.com/edoardoColi/Communication_Sandbox.git
synced 2026-10-07 07:05:03 +00:00
tests + colori
This commit is contained in:
+5
-1
@@ -1,4 +1,5 @@
|
||||
import configparser
|
||||
from colorama import Fore, Style
|
||||
from mininet.net import Mininet
|
||||
from mininet.topo import Topo
|
||||
from mininet.node import Node
|
||||
@@ -97,7 +98,10 @@ def run_topology(config_file):
|
||||
interf = parts[4]
|
||||
cmd = 'ip route add ' + pck_src + ' via ' + pck_nexthop + ' dev ' + interf
|
||||
(net.getNodeByName(name)).cmd(cmd)
|
||||
net.pingAll()
|
||||
if net.pingAll():
|
||||
print(Fore.RED + "Network has issues" + Style.RESET_ALL)
|
||||
else:
|
||||
print(Fore.GREEN + "Network working properly" + Style.RESET_ALL)
|
||||
# CLI(net)
|
||||
net.stop() #Stopping the network
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import configparser
|
||||
from mininet.net import Mininet
|
||||
from mininet.topo import Topo
|
||||
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 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'})
|
||||
|
||||
|
||||
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
|
||||
host = net.addHost('h1', ip='161.46.247.196/24')
|
||||
|
||||
# Set the default route on the host
|
||||
host.setDefaultRoute('via 161.45.247.195')
|
||||
|
||||
# Create a router with two interfaces and default routes
|
||||
router = net.addHost('router', cls=MyRouter)
|
||||
|
||||
# Add interfaces to the router
|
||||
net.addLink(router, host, 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
|
||||
router.cmd('ip route add default via 161.46.247.254 dev r33')
|
||||
router.cmd('ip route add default via 161.46.247.130 dev r21')
|
||||
|
||||
|
||||
net.start() #Starting the network
|
||||
# (net.getNodeByName('h1')).cmd('ip route add 0.0.0.0/0 via 161.46.247.129')
|
||||
# (net.getNodeByName('h2')).cmd('ip route add 0.0.0.0/0 via 161.46.247.195')
|
||||
# (net.getNodeByName('r1')).cmd('ip route add 0.0.0.0/0 via 161.46.247.254')
|
||||
|
||||
net.pingAll()
|
||||
CLI(net)
|
||||
net.stop() #Stopping the network
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_topology('MininetTopo.conf')
|
||||
@@ -10,5 +10,7 @@ python3 --version //This command should display the version of Python 3.x that
|
||||
|
||||
sudo apt-get install openvswitch-testcontroller //non serve davvero
|
||||
sudo apt-get install python3-pip
|
||||
sudo pip3 install configparser
|
||||
pip3 install configparser
|
||||
pip3 install colorama
|
||||
pip3 install ryu
|
||||
sudo apt-get install mininet
|
||||
|
||||
Reference in New Issue
Block a user