Skip to content

Commit f66ffd2

Browse files
committed
Add command-line option --no-etc-hosts
1 parent 70737cd commit f66ffd2

File tree

5 files changed

+101
-11
lines changed

5 files changed

+101
-11
lines changed

nets/8r-1c-in-band-isis/isis8d.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
# to be added to /etc/hosts
4747
ETC_HOSTS_FILE = './etc-hosts'
4848

49+
# Define whether to add Mininet nodes to /etc/hosts file or not
50+
ADD_ETC_HOSTS = True
51+
4952
# Define whether to start the node managers on the routers or not
5053
START_NODE_MANAGERS = False
5154

@@ -288,12 +291,14 @@ def simpleTest():
288291
file.write("%s %d\n" % (host, extractHostPid( repr(host) )) )
289292

290293
# Add Mininet nodes to /etc/hosts
291-
add_nodes_to_etc_hosts()
294+
if ADD_ETC_HOSTS:
295+
add_nodes_to_etc_hosts()
292296

293297
CLI( net )
294298

295299
# Remove Mininet nodes from /etc/hosts
296-
remove_nodes_from_etc_hosts(net)
300+
if ADD_ETC_HOSTS:
301+
remove_nodes_from_etc_hosts(net)
297302

298303
net.stop()
299304
stopAll()
@@ -310,6 +315,11 @@ def parse_arguments():
310315
action='store_true', default=False,
311316
help='Define whether to start node manager on routers or not'
312317
)
318+
parser.add_argument(
319+
'--no-etc-hosts', dest='add_etc_hosts',
320+
action='store_false', default=True,
321+
help='Define whether to add Mininet nodes to /etc/hosts file or not'
322+
)
313323
# Parse input parameters
314324
args = parser.parse_args()
315325
# Return the arguments
@@ -338,6 +348,8 @@ def parse_arguments():
338348
'NODE_MANAGER_GRPC_PORT variable')
339349
print('NODE_MANAGER_GRPC_PORT variable not set in .env file\n')
340350
exit(-2)
351+
# Define whether to add Mininet nodes to /etc/hosts file or not
352+
ADD_ETC_HOSTS = args.add_etc_hosts
341353
# Tell mininet to print useful information
342354
setLogLevel('info')
343355
simpleTest()

nets/8r-1c-out-band-isis/isis8d.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
# to be added to /etc/hosts
4747
ETC_HOSTS_FILE = './etc-hosts'
4848

49+
# Define whether to add Mininet nodes to /etc/hosts file or not
50+
ADD_ETC_HOSTS = True
51+
4952
# Define whether to start the node managers on the routers or not
5053
START_NODE_MANAGERS = False
5154

@@ -341,12 +344,14 @@ def simpleTest():
341344
file.write("%s %d\n" % (host, extractHostPid( repr(host) )) )
342345

343346
# Add Mininet nodes to /etc/hosts
344-
add_nodes_to_etc_hosts()
347+
if ADD_ETC_HOSTS:
348+
add_nodes_to_etc_hosts()
345349

346350
CLI( net )
347351

348352
# Remove Mininet nodes from /etc/hosts
349-
remove_nodes_from_etc_hosts(net)
353+
if ADD_ETC_HOSTS:
354+
remove_nodes_from_etc_hosts(net)
350355

351356
net.stop()
352357
stopAll()
@@ -363,6 +368,11 @@ def parse_arguments():
363368
action='store_true', default=False,
364369
help='Define whether to start node manager on routers or not'
365370
)
371+
parser.add_argument(
372+
'--no-etc-hosts', dest='add_etc_hosts',
373+
action='store_false', default=True,
374+
help='Define whether to add Mininet nodes to /etc/hosts file or not'
375+
)
366376
# Parse input parameters
367377
args = parser.parse_args()
368378
# Return the arguments
@@ -391,6 +401,8 @@ def parse_arguments():
391401
'NODE_MANAGER_GRPC_PORT variable')
392402
print('NODE_MANAGER_GRPC_PORT variable not set in .env file\n')
393403
exit(-2)
404+
# Define whether to add Mininet nodes to /etc/hosts file or not
405+
ADD_ETC_HOSTS = args.add_etc_hosts
394406
# Tell mininet to print useful information
395407
setLogLevel('info')
396408
simpleTest()

nets/8r-1c-srv6-pm/isis8d.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
# to be added to /etc/hosts
4747
ETC_HOSTS_FILE = './etc-hosts'
4848

49+
# Define whether to add Mininet nodes to /etc/hosts file or not
50+
ADD_ETC_HOSTS = True
51+
4952
# Define whether to start the node managers on the routers or not
5053
START_NODE_MANAGERS = False
5154

@@ -341,12 +344,14 @@ def simpleTest():
341344
file.write("%s %d\n" % (host, extractHostPid( repr(host) )) )
342345

343346
# Add Mininet nodes to /etc/hosts
344-
add_nodes_to_etc_hosts()
347+
if ADD_ETC_HOSTS:
348+
add_nodes_to_etc_hosts()
345349

346350
CLI( net )
347351

348352
# Remove Mininet nodes from /etc/hosts
349-
remove_nodes_from_etc_hosts(net)
353+
if ADD_ETC_HOSTS:
354+
remove_nodes_from_etc_hosts(net)
350355

351356
net.stop()
352357
stopAll()
@@ -363,6 +368,11 @@ def parse_arguments():
363368
action='store_true', default=False,
364369
help='Define whether to start node manager on routers or not'
365370
)
371+
parser.add_argument(
372+
'--no-etc-hosts', dest='add_etc_hosts',
373+
action='store_false', default=True,
374+
help='Define whether to add Mininet nodes to /etc/hosts file or not'
375+
)
366376
# Parse input parameters
367377
args = parser.parse_args()
368378
# Return the arguments
@@ -391,6 +401,8 @@ def parse_arguments():
391401
'NODE_MANAGER_GRPC_PORT variable')
392402
print('NODE_MANAGER_GRPC_PORT variable not set in .env file\n')
393403
exit(-2)
404+
# Define whether to add Mininet nodes to /etc/hosts file or not
405+
ADD_ETC_HOSTS = args.add_etc_hosts
394406
# Tell mininet to print useful information
395407
setLogLevel('info')
396408
simpleTest()

nets/8routers-isis-ipv6/isis8d.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
code = compile(f.read(), venv_path, 'exec')
2424
# Execute the activation script to activate the venv
2525
exec(code, {'__file__': venv_path})
26-
26+
27+
from argparse import ArgumentParser
2728
import python_hosts
2829
import shutil
2930
from mininet.topo import Topo
@@ -44,6 +45,9 @@
4445
# to be added to /etc/hosts
4546
ETC_HOSTS_FILE = './etc-hosts'
4647

48+
# Define whether to add Mininet nodes to /etc/hosts file or not
49+
ADD_ETC_HOSTS = True
50+
4751
class BaseNode(Host):
4852

4953
def __init__(self, name, *args, **kwargs):
@@ -257,19 +261,42 @@ def simpleTest():
257261
file.write("%s %d\n" % (host, extractHostPid( repr(host) )) )
258262

259263
# Add Mininet nodes to /etc/hosts
260-
add_nodes_to_etc_hosts()
264+
if ADD_ETC_HOSTS:
265+
add_nodes_to_etc_hosts()
261266

262267
CLI( net )
263268

264269
# Remove Mininet nodes from /etc/hosts
265-
remove_nodes_from_etc_hosts(net)
270+
if ADD_ETC_HOSTS:
271+
remove_nodes_from_etc_hosts(net)
266272

267273
net.stop()
268274
stopAll()
269275

270276

277+
def parse_arguments():
278+
# Get parser
279+
parser = ArgumentParser(
280+
description='Emulation of a Mininet topology (8 routers running '
281+
'IS-IS, 1 controller out-of-band'
282+
)
283+
parser.add_argument(
284+
'--no-etc-hosts', dest='add_etc_hosts',
285+
action='store_false', default=True,
286+
help='Define whether to add Mininet nodes to /etc/hosts file or not'
287+
)
288+
# Parse input parameters
289+
args = parser.parse_args()
290+
# Return the arguments
291+
return args
292+
293+
271294

272295
if __name__ == '__main__':
296+
# Parse command-line arguments
297+
args = parse_arguments()
298+
# Define whether to add Mininet nodes to /etc/hosts file or not
299+
ADD_ETC_HOSTS = args.add_etc_hosts
273300
# Tell mininet to print useful information
274301
setLogLevel('info')
275302
simpleTest()

nets/8routers/ospf8r.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# Execute the activation script to activate the venv
2525
exec(code, {'__file__': venv_path})
2626

27+
from argparse import ArgumentParser
2728
import python_hosts
2829
import shutil
2930
from mininet.topo import Topo
@@ -44,6 +45,9 @@
4445
# to be added to /etc/hosts
4546
ETC_HOSTS_FILE = './etc-hosts'
4647

48+
# Define whether to add Mininet nodes to /etc/hosts file or not
49+
ADD_ETC_HOSTS = True
50+
4751
class BaseNode(Host):
4852

4953
def __init__(self, name, *args, **kwargs):
@@ -247,19 +251,42 @@ def simpleTest():
247251
file.write("%s %d\n" % (host, extractHostPid( repr(host) )) )
248252

249253
# Add Mininet nodes to /etc/hosts
250-
add_nodes_to_etc_hosts()
254+
if ADD_ETC_HOSTS:
255+
add_nodes_to_etc_hosts()
251256

252257
CLI( net )
253258

254259
# Remove Mininet nodes from /etc/hosts
255-
remove_nodes_from_etc_hosts(net)
260+
if ADD_ETC_HOSTS:
261+
remove_nodes_from_etc_hosts(net)
256262

257263
net.stop()
258264
stopAll()
259265

260266

267+
def parse_arguments():
268+
# Get parser
269+
parser = ArgumentParser(
270+
description='Emulation of a Mininet topology (8 routers running '
271+
'IS-IS, 1 controller out-of-band'
272+
)
273+
parser.add_argument(
274+
'--no-etc-hosts', dest='add_etc_hosts',
275+
action='store_false', default=True,
276+
help='Define whether to add Mininet nodes to /etc/hosts file or not'
277+
)
278+
# Parse input parameters
279+
args = parser.parse_args()
280+
# Return the arguments
281+
return args
282+
283+
261284

262285
if __name__ == '__main__':
286+
# Parse command-line arguments
287+
args = parse_arguments()
288+
# Define whether to add Mininet nodes to /etc/hosts file or not
289+
ADD_ETC_HOSTS = args.add_etc_hosts
263290
# Tell mininet to print useful information
264291
setLogLevel('info')
265292
simpleTest()

0 commit comments

Comments
 (0)