usertools: define DPDK PCI functional device
[dpdk.git] / usertools / dpdk-devbind.py
1 #! /usr/bin/env python
2 #
3 #   BSD LICENSE
4 #
5 #   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
6 #   All rights reserved.
7 #
8 #   Redistribution and use in source and binary forms, with or without
9 #   modification, are permitted provided that the following conditions
10 #   are met:
11 #
12 #     * Redistributions of source code must retain the above copyright
13 #       notice, this list of conditions and the following disclaimer.
14 #     * Redistributions in binary form must reproduce the above copyright
15 #       notice, this list of conditions and the following disclaimer in
16 #       the documentation and/or other materials provided with the
17 #       distribution.
18 #     * Neither the name of Intel Corporation nor the names of its
19 #       contributors may be used to endorse or promote products derived
20 #       from this software without specific prior written permission.
21 #
22 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 #   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 #   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 #   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 #   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 #   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 #   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 #   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 #   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #
34
35 import sys
36 import os
37 import getopt
38 import subprocess
39 from os.path import exists, abspath, dirname, basename
40
41 # The PCI base class for all devices
42 network_class = {'Class': '02', 'Vendor': None, 'Device': None,
43                     'SVendor': None, 'SDevice': None}
44 encryption_class = {'Class': '10', 'Vendor': None, 'Device': None,
45                    'SVendor': None, 'SDevice': None}
46 intel_processor_class = {'Class': '0b', 'Vendor': '8086', 'Device': None,
47                    'SVendor': None, 'SDevice': None}
48
49 network_devices = [network_class]
50 crypto_devices = [encryption_class, intel_processor_class]
51
52 # global dict ethernet devices present. Dictionary indexed by PCI address.
53 # Each device within this is itself a dictionary of device properties
54 devices = {}
55 # list of supported DPDK drivers
56 dpdk_drivers = ["igb_uio", "vfio-pci", "uio_pci_generic"]
57
58 # command-line arg flags
59 b_flag = None
60 status_flag = False
61 force_flag = False
62 args = []
63
64
65 def usage():
66     '''Print usage information for the program'''
67     argv0 = basename(sys.argv[0])
68     print("""
69 Usage:
70 ------
71
72      %(argv0)s [options] DEVICE1 DEVICE2 ....
73
74 where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax
75 or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may
76 also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc.
77
78 Options:
79     --help, --usage:
80         Display usage information and quit
81
82     -s, --status:
83         Print the current status of all known network and crypto devices.
84         For each device, it displays the PCI domain, bus, slot and function,
85         along with a text description of the device. Depending upon whether the
86         device is being used by a kernel driver, the igb_uio driver, or no
87         driver, other relevant information will be displayed:
88         * the Linux interface name e.g. if=eth0
89         * the driver being used e.g. drv=igb_uio
90         * any suitable drivers not currently using that device
91             e.g. unused=igb_uio
92         NOTE: if this flag is passed along with a bind/unbind option, the
93         status display will always occur after the other operations have taken
94         place.
95
96     -b driver, --bind=driver:
97         Select the driver to use or \"none\" to unbind the device
98
99     -u, --unbind:
100         Unbind a device (Equivalent to \"-b none\")
101
102     --force:
103         By default, network devices which are used by Linux - as indicated by
104         having routes in the routing table - cannot be modified. Using the
105         --force flag overrides this behavior, allowing active links to be
106         forcibly unbound.
107         WARNING: This can lead to loss of network connection and should be used
108         with caution.
109
110 Examples:
111 ---------
112
113 To display current device status:
114         %(argv0)s --status
115
116 To bind eth1 from the current driver and move to use igb_uio
117         %(argv0)s --bind=igb_uio eth1
118
119 To unbind 0000:01:00.0 from using any driver
120         %(argv0)s -u 0000:01:00.0
121
122 To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver
123         %(argv0)s -b ixgbe 02:00.0 02:00.1
124
125     """ % locals())  # replace items from local variables
126
127
128 # This is roughly compatible with check_output function in subprocess module
129 # which is only available in python 2.7.
130 def check_output(args, stderr=None):
131     '''Run a command and capture its output'''
132     return subprocess.Popen(args, stdout=subprocess.PIPE,
133                             stderr=stderr).communicate()[0]
134
135
136 def find_module(mod):
137     '''find the .ko file for kernel module named mod.
138     Searches the $RTE_SDK/$RTE_TARGET directory, the kernel
139     modules directory and finally under the parent directory of
140     the script '''
141     # check $RTE_SDK/$RTE_TARGET directory
142     if 'RTE_SDK' in os.environ and 'RTE_TARGET' in os.environ:
143         path = "%s/%s/kmod/%s.ko" % (os.environ['RTE_SDK'],
144                                      os.environ['RTE_TARGET'], mod)
145         if exists(path):
146             return path
147
148     # check using depmod
149     try:
150         depmod_out = check_output(["modinfo", "-n", mod],
151                                   stderr=subprocess.STDOUT).lower()
152         if "error" not in depmod_out:
153             path = depmod_out.strip()
154             if exists(path):
155                 return path
156     except:  # if modinfo can't find module, it fails, so continue
157         pass
158
159     # check for a copy based off current path
160     tools_dir = dirname(abspath(sys.argv[0]))
161     if tools_dir.endswith("tools"):
162         base_dir = dirname(tools_dir)
163         find_out = check_output(["find", base_dir, "-name", mod + ".ko"])
164         if len(find_out) > 0:  # something matched
165             path = find_out.splitlines()[0]
166             if exists(path):
167                 return path
168
169
170 def check_modules():
171     '''Checks that igb_uio is loaded'''
172     global dpdk_drivers
173
174     # list of supported modules
175     mods = [{"Name": driver, "Found": False} for driver in dpdk_drivers]
176
177     # first check if module is loaded
178     try:
179         # Get list of sysfs modules (both built-in and dynamically loaded)
180         sysfs_path = '/sys/module/'
181
182         # Get the list of directories in sysfs_path
183         sysfs_mods = [os.path.join(sysfs_path, o) for o
184                       in os.listdir(sysfs_path)
185                       if os.path.isdir(os.path.join(sysfs_path, o))]
186
187         # Extract the last element of '/sys/module/abc' in the array
188         sysfs_mods = [a.split('/')[-1] for a in sysfs_mods]
189
190         # special case for vfio_pci (module is named vfio-pci,
191         # but its .ko is named vfio_pci)
192         sysfs_mods = map(lambda a:
193                          a if a != 'vfio_pci' else 'vfio-pci', sysfs_mods)
194
195         for mod in mods:
196             if mod["Name"] in sysfs_mods:
197                 mod["Found"] = True
198     except:
199         pass
200
201     # check if we have at least one loaded module
202     if True not in [mod["Found"] for mod in mods] and b_flag is not None:
203         if b_flag in dpdk_drivers:
204             print("Error - no supported modules(DPDK driver) are loaded")
205             sys.exit(1)
206         else:
207             print("Warning - no supported modules(DPDK driver) are loaded")
208
209     # change DPDK driver list to only contain drivers that are loaded
210     dpdk_drivers = [mod["Name"] for mod in mods if mod["Found"]]
211
212
213 def has_driver(dev_id):
214     '''return true if a device is assigned to a driver. False otherwise'''
215     return "Driver_str" in devices[dev_id]
216
217
218 def get_pci_device_details(dev_id, probe_lspci):
219     '''This function gets additional details for a PCI device'''
220     device = {}
221
222     if probe_lspci:
223         extra_info = check_output(["lspci", "-vmmks", dev_id]).splitlines()
224
225         # parse lspci details
226         for line in extra_info:
227             if len(line) == 0:
228                 continue
229             name, value = line.decode().split("\t", 1)
230             name = name.strip(":") + "_str"
231             device[name] = value
232     # check for a unix interface name
233     device["Interface"] = ""
234     for base, dirs, _ in os.walk("/sys/bus/pci/devices/%s/" % dev_id):
235         if "net" in dirs:
236             device["Interface"] = \
237                 ",".join(os.listdir(os.path.join(base, "net")))
238             break
239     # check if a port is used for ssh connection
240     device["Ssh_if"] = False
241     device["Active"] = ""
242
243     return device
244
245 def clear_data():
246     '''This function clears any old data'''
247     devices = {}
248
249 def get_device_details(devices_type):
250     '''This function populates the "devices" dictionary. The keys used are
251     the pci addresses (domain:bus:slot.func). The values are themselves
252     dictionaries - one for each NIC.'''
253     global devices
254     global dpdk_drivers
255
256     # first loop through and read details for all devices
257     # request machine readable format, with numeric IDs and String
258     dev = {}
259     dev_lines = check_output(["lspci", "-Dvmmnnk"]).splitlines()
260     for dev_line in dev_lines:
261         if len(dev_line) == 0:
262             if device_type_match(dev, devices_type):
263                 # Replace "Driver" with "Driver_str" to have consistency of
264                 # of dictionary key names
265                 if "Driver" in dev.keys():
266                     dev["Driver_str"] = dev.pop("Driver")
267                 # use dict to make copy of dev
268                 devices[dev["Slot"]] = dict(dev)
269             # Clear previous device's data
270             dev = {}
271         else:
272             name, value = dev_line.decode().split("\t", 1)
273             value_list = value.rsplit(' ', 1)
274             if len(value_list) > 1:
275                 # String stored in <name>_str
276                 dev[name.rstrip(":") + '_str'] = value_list[0]
277             # Numeric IDs
278             dev[name.rstrip(":")] = value_list[len(value_list) - 1] \
279                 .rstrip("]").lstrip("[")
280
281     if devices_type == network_devices:
282         # check what is the interface if any for an ssh connection if
283         # any to this host, so we can mark it later.
284         ssh_if = []
285         route = check_output(["ip", "-o", "route"])
286         # filter out all lines for 169.254 routes
287         route = "\n".join(filter(lambda ln: not ln.startswith("169.254"),
288                              route.decode().splitlines()))
289         rt_info = route.split()
290         for i in range(len(rt_info) - 1):
291             if rt_info[i] == "dev":
292                 ssh_if.append(rt_info[i+1])
293
294     # based on the basic info, get extended text details
295     for d in devices.keys():
296         if not device_type_match(devices[d], devices_type):
297             continue
298
299         # get additional info and add it to existing data
300         devices[d] = devices[d].copy()
301         # No need to probe lspci
302         devices[d].update(get_pci_device_details(d, False).items())
303
304         if devices_type == network_devices:
305             for _if in ssh_if:
306                 if _if in devices[d]["Interface"].split(","):
307                     devices[d]["Ssh_if"] = True
308                     devices[d]["Active"] = "*Active*"
309                     break
310
311         # add igb_uio to list of supporting modules if needed
312         if "Module_str" in devices[d]:
313             for driver in dpdk_drivers:
314                 if driver not in devices[d]["Module_str"]:
315                     devices[d]["Module_str"] = \
316                         devices[d]["Module_str"] + ",%s" % driver
317         else:
318             devices[d]["Module_str"] = ",".join(dpdk_drivers)
319
320         # make sure the driver and module strings do not have any duplicates
321         if has_driver(d):
322             modules = devices[d]["Module_str"].split(",")
323             if devices[d]["Driver_str"] in modules:
324                 modules.remove(devices[d]["Driver_str"])
325                 devices[d]["Module_str"] = ",".join(modules)
326
327
328 def device_type_match(dev, devices_type):
329     for i in range(len(devices_type)):
330         param_count = len(
331             [x for x in devices_type[i].values() if x is not None])
332         match_count = 0
333         if dev["Class"][0:2] == devices_type[i]["Class"]:
334             match_count = match_count + 1
335             for key in devices_type[i].keys():
336                 if key != 'Class' and devices_type[i][key]:
337                     value_list = devices_type[i][key].split(',')
338                     for value in value_list:
339                         if value.strip(' ') == dev[key]:
340                             match_count = match_count + 1
341             # count must be the number of non None parameters to match
342             if match_count == param_count:
343                 return True
344             else:
345                 return False
346
347 def dev_id_from_dev_name(dev_name):
348     '''Take a device "name" - a string passed in by user to identify a NIC
349     device, and determine the device id - i.e. the domain:bus:slot.func - for
350     it, which can then be used to index into the devices array'''
351
352     # check if it's already a suitable index
353     if dev_name in devices:
354         return dev_name
355     # check if it's an index just missing the domain part
356     elif "0000:" + dev_name in devices:
357         return "0000:" + dev_name
358     else:
359         # check if it's an interface name, e.g. eth1
360         for d in devices.keys():
361             if dev_name in devices[d]["Interface"].split(","):
362                 return devices[d]["Slot"]
363     # if nothing else matches - error
364     print("Unknown device: %s. "
365           "Please specify device in \"bus:slot.func\" format" % dev_name)
366     sys.exit(1)
367
368
369 def unbind_one(dev_id, force):
370     '''Unbind the device identified by "dev_id" from its current driver'''
371     dev = devices[dev_id]
372     if not has_driver(dev_id):
373         print("%s %s %s is not currently managed by any driver\n" %
374               (dev["Slot"], dev["Device_str"], dev["Interface"]))
375         return
376
377     # prevent us disconnecting ourselves
378     if dev["Ssh_if"] and not force:
379         print("Routing table indicates that interface %s is active. "
380               "Skipping unbind" % (dev_id))
381         return
382
383     # For kernels > 3.15 driver_override is used to bind a device to a driver.
384     # Before unbinding it, overwrite driver_override with empty string so that
385     # the device can be bound to any other driver
386     filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id
387     if os.path.exists(filename):
388         try:
389             f = open(filename, "w")
390         except:
391             print("Error: unbind failed for %s - Cannot open %s"
392                   % (dev_id, filename))
393             sys.exit(1)
394         try:
395             f.write("\00")
396             f.close()
397         except:
398             print("Error: unbind failed for %s - Cannot open %s"
399                   % (dev_id, filename))
400             sys.exit(1)
401
402     # write to /sys to unbind
403     filename = "/sys/bus/pci/drivers/%s/unbind" % dev["Driver_str"]
404     try:
405         f = open(filename, "a")
406     except:
407         print("Error: unbind failed for %s - Cannot open %s"
408               % (dev_id, filename))
409         sys.exit(1)
410     f.write(dev_id)
411     f.close()
412
413
414 def bind_one(dev_id, driver, force):
415     '''Bind the device given by "dev_id" to the driver "driver". If the device
416     is already bound to a different driver, it will be unbound first'''
417     dev = devices[dev_id]
418     saved_driver = None  # used to rollback any unbind in case of failure
419
420     # prevent disconnection of our ssh session
421     if dev["Ssh_if"] and not force:
422         print("Routing table indicates that interface %s is active. "
423               "Not modifying" % (dev_id))
424         return
425
426     # unbind any existing drivers we don't want
427     if has_driver(dev_id):
428         if dev["Driver_str"] == driver:
429             print("%s already bound to driver %s, skipping\n"
430                   % (dev_id, driver))
431             return
432         else:
433             saved_driver = dev["Driver_str"]
434             unbind_one(dev_id, force)
435             dev["Driver_str"] = ""  # clear driver string
436
437     # For kernels >= 3.15 driver_override can be used to specify the driver
438     # for a device rather than relying on the driver to provide a positive
439     # match of the device.  The existing process of looking up
440     # the vendor and device ID, adding them to the driver new_id,
441     # will erroneously bind other devices too which has the additional burden
442     # of unbinding those devices
443     if driver in dpdk_drivers:
444         filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id
445         if os.path.exists(filename):
446             try:
447                 f = open(filename, "w")
448             except:
449                 print("Error: bind failed for %s - Cannot open %s"
450                       % (dev_id, filename))
451                 return
452             try:
453                 f.write("%s" % driver)
454                 f.close()
455             except:
456                 print("Error: bind failed for %s - Cannot write driver %s to "
457                       "PCI ID " % (dev_id, driver))
458                 return
459         # For kernels < 3.15 use new_id to add PCI id's to the driver
460         else:
461             filename = "/sys/bus/pci/drivers/%s/new_id" % driver
462             try:
463                 f = open(filename, "w")
464             except:
465                 print("Error: bind failed for %s - Cannot open %s"
466                       % (dev_id, filename))
467                 return
468             try:
469                 # Convert Device and Vendor Id to int to write to new_id
470                 f.write("%04x %04x" % (int(dev["Vendor"],16),
471                         int(dev["Device"], 16)))
472                 f.close()
473             except:
474                 print("Error: bind failed for %s - Cannot write new PCI ID to "
475                       "driver %s" % (dev_id, driver))
476                 return
477
478     # do the bind by writing to /sys
479     filename = "/sys/bus/pci/drivers/%s/bind" % driver
480     try:
481         f = open(filename, "a")
482     except:
483         print("Error: bind failed for %s - Cannot open %s"
484               % (dev_id, filename))
485         if saved_driver is not None:  # restore any previous driver
486             bind_one(dev_id, saved_driver, force)
487         return
488     try:
489         f.write(dev_id)
490         f.close()
491     except:
492         # for some reason, closing dev_id after adding a new PCI ID to new_id
493         # results in IOError. however, if the device was successfully bound,
494         # we don't care for any errors and can safely ignore IOError
495         tmp = get_pci_device_details(dev_id, True)
496         if "Driver_str" in tmp and tmp["Driver_str"] == driver:
497             return
498         print("Error: bind failed for %s - Cannot bind to driver %s"
499               % (dev_id, driver))
500         if saved_driver is not None:  # restore any previous driver
501             bind_one(dev_id, saved_driver, force)
502         return
503
504
505 def unbind_all(dev_list, force=False):
506     """Unbind method, takes a list of device locations"""
507     dev_list = map(dev_id_from_dev_name, dev_list)
508     for d in dev_list:
509         unbind_one(d, force)
510
511
512 def bind_all(dev_list, driver, force=False):
513     """Bind method, takes a list of device locations"""
514     global devices
515
516     dev_list = map(dev_id_from_dev_name, dev_list)
517
518     for d in dev_list:
519         bind_one(d, driver, force)
520
521     # For kenels < 3.15 when binding devices to a generic driver
522     # (i.e. one that doesn't have a PCI ID table) using new_id, some devices
523     # that are not bound to any other driver could be bound even if no one has
524     # asked them to. hence, we check the list of drivers again, and see if
525     # some of the previously-unbound devices were erroneously bound.
526     if not os.path.exists("/sys/bus/pci/devices/%s/driver_override" % d):
527         for d in devices.keys():
528             # skip devices that were already bound or that we know should be bound
529             if "Driver_str" in devices[d] or d in dev_list:
530                 continue
531
532             # update information about this device
533             devices[d] = dict(devices[d].items() +
534                               get_pci_device_details(d, True).items())
535
536             # check if updated information indicates that the device was bound
537             if "Driver_str" in devices[d]:
538                 unbind_one(d, force)
539
540
541 def display_devices(title, dev_list, extra_params=None):
542     '''Displays to the user the details of a list of devices given in
543     "dev_list". The "extra_params" parameter, if given, should contain a string
544      with %()s fields in it for replacement by the named fields in each
545      device's dictionary.'''
546     strings = []  # this holds the strings to print. We sort before printing
547     print("\n%s" % title)
548     print("="*len(title))
549     if len(dev_list) == 0:
550         strings.append("<none>")
551     else:
552         for dev in dev_list:
553             if extra_params is not None:
554                 strings.append("%s '%s %s' %s" % (dev["Slot"],
555                                                dev["Device_str"],
556                                                dev["Device"],
557                                                extra_params % dev))
558             else:
559                 strings.append("%s '%s'" % (dev["Slot"], dev["Device_str"]))
560     # sort before printing, so that the entries appear in PCI order
561     strings.sort()
562     print("\n".join(strings))  # print one per line
563
564 def show_device_status(devices_type, device_name):
565     global dpdk_drivers
566     kernel_drv = []
567     dpdk_drv = []
568     no_drv = []
569
570     # split our list of network devices into the three categories above
571     for d in devices.keys():
572         if device_type_match(devices[d], devices_type):
573             if not has_driver(d):
574                 no_drv.append(devices[d])
575                 continue
576             if devices[d]["Driver_str"] in dpdk_drivers:
577                 dpdk_drv.append(devices[d])
578             else:
579                 kernel_drv.append(devices[d])
580
581     # print each category separately, so we can clearly see what's used by DPDK
582     display_devices("%s devices using DPDK-compatible driver" % device_name,
583                     dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s")
584     display_devices("%s devices using kernel driver" % device_name, kernel_drv,
585                     "if=%(Interface)s drv=%(Driver_str)s "
586                     "unused=%(Module_str)s %(Active)s")
587     display_devices("Other %s devices" % device_name, no_drv,
588                     "unused=%(Module_str)s")
589
590 def show_status():
591     '''Function called when the script is passed the "--status" option.
592     Displays to the user what devices are bound to the igb_uio driver, the
593     kernel driver or to no driver'''
594
595     show_device_status(network_devices, "Network")
596     show_device_status(crypto_devices, "Crypto")
597
598 def parse_args():
599     '''Parses the command-line arguments given by the user and takes the
600     appropriate action for each'''
601     global b_flag
602     global status_flag
603     global force_flag
604     global args
605     if len(sys.argv) <= 1:
606         usage()
607         sys.exit(0)
608
609     try:
610         opts, args = getopt.getopt(sys.argv[1:], "b:us",
611                                    ["help", "usage", "status", "force",
612                                     "bind=", "unbind"])
613     except getopt.GetoptError as error:
614         print(str(error))
615         print("Run '%s --usage' for further information" % sys.argv[0])
616         sys.exit(1)
617
618     for opt, arg in opts:
619         if opt == "--help" or opt == "--usage":
620             usage()
621             sys.exit(0)
622         if opt == "--status" or opt == "-s":
623             status_flag = True
624         if opt == "--force":
625             force_flag = True
626         if opt == "-b" or opt == "-u" or opt == "--bind" or opt == "--unbind":
627             if b_flag is not None:
628                 print("Error - Only one bind or unbind may be specified\n")
629                 sys.exit(1)
630             if opt == "-u" or opt == "--unbind":
631                 b_flag = "none"
632             else:
633                 b_flag = arg
634
635
636 def do_arg_actions():
637     '''do the actual action requested by the user'''
638     global b_flag
639     global status_flag
640     global force_flag
641     global args
642
643     if b_flag is None and not status_flag:
644         print("Error: No action specified for devices."
645               "Please give a -b or -u option")
646         print("Run '%s --usage' for further information" % sys.argv[0])
647         sys.exit(1)
648
649     if b_flag is not None and len(args) == 0:
650         print("Error: No devices specified.")
651         print("Run '%s --usage' for further information" % sys.argv[0])
652         sys.exit(1)
653
654     if b_flag == "none" or b_flag == "None":
655         unbind_all(args, force_flag)
656     elif b_flag is not None:
657         bind_all(args, b_flag, force_flag)
658     if status_flag:
659         if b_flag is not None:
660             clear_data()
661             # refresh if we have changed anything
662             get_device_details(network_devices)
663             get_device_details(crypto_devices)
664         show_status()
665
666
667 def main():
668     '''program main function'''
669     parse_args()
670     check_modules()
671     clear_data()
672     get_device_details(network_devices)
673     get_device_details(crypto_devices)
674     do_arg_actions()
675
676 if __name__ == "__main__":
677     main()