Advertisement
AppajiC

custom_topology.py

Sep 27th, 2022
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. #!/usr/bin/python
  2. from mininet.topo import Topo
  3.  
  4.  
  5. class CustomTopo(Topo):
  6.     def __init__(self, hosts_count=3, *args, **kwargs):
  7.         Topo.__init__(self, *args, **kwargs)
  8.         switch = self.addSwitch("s1")
  9.         hosts = []
  10.         attacker = self.addHost("attacker", ip=f"10.0.0.{hosts_count + 1}/24")
  11.  
  12.         for id in range(1, hosts_count + 1):
  13.             name = f"h{id}"
  14.             ip = f"10.0.0.{id}/24"
  15.             host = self.addHost(name, ip=ip)
  16.             hosts.append(host)
  17.             self.addLink(host, switch, bw=10, delay="50ms")
  18.         self.addLink(attacker, switch, bw=10, delay="50ms")
  19.         hosts.append(attacker)
  20.  
  21.  
  22. topos = {"mytopo": (lambda: CustomTopo())}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement