Skip to content

Commit

Permalink
mininet ip fix. (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
henry54809 committed Sep 22, 2021
1 parent 4ca3be1 commit 15c8366
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion daq/base_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def _initialize(self):
vol_maps = [os.path.abspath(os.path.join(DAQ_RUN_DIR, 'config')) + ':/config/inst']
host = self.runner.add_host(host_name, port=host_port, cls=cls, tmpdir=self.tmpdir,
vol_maps=vol_maps, env_vars=env_vars)
host.activate()
self.host = host
host.activate()
self.host_intf = self.runner.get_host_interface(host)
LOGGER.info("Added networking host %s on port %d at %s as %s",
host_name, host_port, host.IP(), self.host_intf)
Expand Down
2 changes: 1 addition & 1 deletion daq/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def _shorten_filename(self, long_name):
def _monitor_scan(self, output_file, timeout=None):
assert not self._monitor_ref, 'tcp_monitor already active'
network = self.runner.network
tcp_filter = ''
tcp_filter = 'ether broadcast or ether host %s' % self.device.mac
self.logger.info('Target device %s pcap intf %s for %s seconds output in %s',
self, self._mirror_intf_name, timeout if timeout else 'infinite',
self._shorten_filename(output_file))
Expand Down
16 changes: 12 additions & 4 deletions daq/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ def add_host(self, name, cls=DAQHost, ip_addr=None, env_vars=None, vol_maps=None
params['tmpdir'] = os.path.join(tmpdir, 'nodes') if tmpdir else None
params['env_vars'] = env_vars if env_vars else []
params['vol_maps'] = vol_maps if vol_maps else []
host = self.net.addHost(name, cls, **params)
try:
host = self._retry_func(partial(self.net.addHost, name, cls, **params))
except Exception as e:
# If addHost fails, ip allocation needs to be explicityly cleaned up.
self._reset_mininet_next_ip()
raise e
try:
switch_link = self._retry_func(
partial(self.net.addLink, self.pri, host, port1=port, fast=False))
Expand Down Expand Up @@ -145,14 +150,17 @@ def _switch_del_intf(self, switch, intf):
del switch.ports[intf]
del switch.nameToIntf[intf.name]

def _reset_mininet_next_ip(self):
# Resets Mininet's next ip so subnet ips don't run out.
# IP overrides are excluded from this set.
self.net.nextIP = max(self._used_ip_indices or [0]) + 1

def remove_host(self, host):
"""Remove a host from the ecosystem"""
index = self.net.hosts.index(host)
if host.IP() and self._get_host_ip_index(host) in self._used_ip_indices:
# Resets Mininet's next ip so subnet ips don't run out.
# IP overrides are excluded from this set.
self._used_ip_indices.remove(self._get_host_ip_index(host))
self.net.nextIP = max(self._used_ip_indices or [0]) + 1
self._reset_mininet_next_ip()
if index:
del self.net.hosts[index]
if host in self.switch_links:
Expand Down
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Depends: python3-mininet,
python3-cairocffi,
arp-scan,
nmap,
jq,
weasyprint,
python3-pypandoc,
python3-netifaces,
Expand Down

0 comments on commit 15c8366

Please sign in to comment.