def create_network(self, controller=Controller): """ Adds a switch, a Kali container, and several mininet hosts to the network created in the base class. TODO: An __init__ parameter should be used to allow overriding prefixlen and host count """ Scenario.create_network(self, controller) # Add switch switch = self.net.addSwitch('s1') # Create a random subnet to add hosts to self.prefixlen = random.randint(24, 27) self.subnet = subnet.generate(self.prefixlen) hosts = list(self.subnet.hosts()) # Add kali self.kali = self.net.addDocker('kali', cls=Kali, ip="%s/%s" % (hosts.pop(), self.prefixlen)) self.net.addLink(switch, self.kali) for i in range(0, random.randint(10, 25)): # If the host list is empty, exit if not hosts: break # Get a random IP from the list of hosts ip = hosts.pop(random.randrange(len(hosts))) # Add a host host = self.net.addHost('h' + str(i), ip="%s/%s" % (ip, self.prefixlen)) # Link host to switch self.net.addLink(switch, host)
def create_network(self, controller=None): """Adds a switch, Kali, vsftpd, and some hosts to the network.""" Scenario.create_network(self, controller) self.add_switch() # Create a random subnet to add hosts to prefixlen = random.randint(27, 29) hosts = list(subnet.generate(prefixlen).hosts()) # Add kali self.kali = self.net.addDocker('kali', cls=Kali, ip="%s/%s" % (hosts.pop(), prefixlen)) self.kali.install_package(*self.packages) self.net.addLink(self.switch, self.kali) # Add ftpd self.ftpd = self.net.addDocker('ftp', cls=Vsftpd, ip="%s/%s" % (hosts.pop(), prefixlen)) self.net.addLink(self.switch, self.ftpd) # Add ftp client for i in range(random.randrange(1, 5)): ftpc = self.net.addHost('ftpc'+str(i), ip="%s/%s" % (hosts.pop(), prefixlen)) self.net.addLink(self.switch, ftpc) self.ftp_clients.append(ftpc)