Skip to content

Commit 15c8366

Browse files
authored
mininet ip fix. (#924)
1 parent 4ca3be1 commit 15c8366

4 files changed

Lines changed: 15 additions & 6 deletions

File tree

daq/base_gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def _initialize(self):
7171
vol_maps = [os.path.abspath(os.path.join(DAQ_RUN_DIR, 'config')) + ':/config/inst']
7272
host = self.runner.add_host(host_name, port=host_port, cls=cls, tmpdir=self.tmpdir,
7373
vol_maps=vol_maps, env_vars=env_vars)
74-
host.activate()
7574
self.host = host
75+
host.activate()
7676
self.host_intf = self.runner.get_host_interface(host)
7777
LOGGER.info("Added networking host %s on port %d at %s as %s",
7878
host_name, host_port, host.IP(), self.host_intf)

daq/host.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def _shorten_filename(self, long_name):
558558
def _monitor_scan(self, output_file, timeout=None):
559559
assert not self._monitor_ref, 'tcp_monitor already active'
560560
network = self.runner.network
561-
tcp_filter = ''
561+
tcp_filter = 'ether broadcast or ether host %s' % self.device.mac
562562
self.logger.info('Target device %s pcap intf %s for %s seconds output in %s',
563563
self, self._mirror_intf_name, timeout if timeout else 'infinite',
564564
self._shorten_filename(output_file))

daq/network.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ def add_host(self, name, cls=DAQHost, ip_addr=None, env_vars=None, vol_maps=None
100100
params['tmpdir'] = os.path.join(tmpdir, 'nodes') if tmpdir else None
101101
params['env_vars'] = env_vars if env_vars else []
102102
params['vol_maps'] = vol_maps if vol_maps else []
103-
host = self.net.addHost(name, cls, **params)
103+
try:
104+
host = self._retry_func(partial(self.net.addHost, name, cls, **params))
105+
except Exception as e:
106+
# If addHost fails, ip allocation needs to be explicityly cleaned up.
107+
self._reset_mininet_next_ip()
108+
raise e
104109
try:
105110
switch_link = self._retry_func(
106111
partial(self.net.addLink, self.pri, host, port1=port, fast=False))
@@ -145,14 +150,17 @@ def _switch_del_intf(self, switch, intf):
145150
del switch.ports[intf]
146151
del switch.nameToIntf[intf.name]
147152

153+
def _reset_mininet_next_ip(self):
154+
# Resets Mininet's next ip so subnet ips don't run out.
155+
# IP overrides are excluded from this set.
156+
self.net.nextIP = max(self._used_ip_indices or [0]) + 1
157+
148158
def remove_host(self, host):
149159
"""Remove a host from the ecosystem"""
150160
index = self.net.hosts.index(host)
151161
if host.IP() and self._get_host_ip_index(host) in self._used_ip_indices:
152-
# Resets Mininet's next ip so subnet ips don't run out.
153-
# IP overrides are excluded from this set.
154162
self._used_ip_indices.remove(self._get_host_ip_index(host))
155-
self.net.nextIP = max(self._used_ip_indices or [0]) + 1
163+
self._reset_mininet_next_ip()
156164
if index:
157165
del self.net.hosts[index]
158166
if host in self.switch_links:

debian/control

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Depends: python3-mininet,
2020
python3-cairocffi,
2121
arp-scan,
2222
nmap,
23+
jq,
2324
weasyprint,
2425
python3-pypandoc,
2526
python3-netifaces,

0 commit comments

Comments
 (0)