# Path: cirque/capabilities/basecapability.py
# class BaseCapability:
# 
#   @property
#   def name(self):
#     return ''
# 
#   def get_docker_run_args(self, docker_node):
#     return {}
# 
#   def enable_capability(self, docker_node):
#     pass
# 
#   def disable_capability(self, docker_node):
#     pass
# 
#   @property
#   def description(self):
#     return {}
# 
# Path: cirque/common/cirquelog.py
# class CirqueLog:
# 
#   logger = None
# 
#   @classmethod
#   def setup_cirque_logger(cls, level=logging.INFO):
#     if cls.logger:
#       return
#     cls.logger = logging.getLogger('cirque')
#     cls.logger.setLevel(level)
#     sh = logging.StreamHandler()
#     sh.setFormatter(
#         logging.Formatter('%(asctime)s [%(name)s] %(levelname)s %(message)s'))
#     cls.logger.addHandler(sh)
# 
#   @classmethod
#   def get_cirque_logger(cls, name=None):
#     name = 'cirque' if not name else 'cirque.{}'.format(name)
#     return logging.getLogger(name)
# 
# Path: cirque/common/exceptions.py
# class ConnectivityError(BaseException):
#   pass
# 
# class ContainerExecError(BaseException):
#   pass
# 
# class IpNetnsExecError(BaseException):
#   pass
# 
# class LoadKernelError(BaseException):
#   pass
# 
# class NameSpaceOperatingError(BaseException):
#   pass
# 
# class PHYDeviceError(BaseException):
#   pass


import os
import time
import cirque.common.utils as utils
from subprocess import PIPE
from pyroute2 import NetNS
from cirque.capabilities.basecapability import BaseCapability
from cirque.common.cirquelog import CirqueLog
from cirque.common.exceptions import (
    ConnectivityError,
    ContainerExecError,
    IpNetnsExecError,
    LoadKernelError,
    NameSpaceOperatingError,
    PHYDeviceError,
)
          ret = utils.netns_run(docker_node.logger,
                                "iw phy {} set netns 1".format(phy_device),
                                docker_node.name)
          if ret.returncode != 0:
            raise IpNetnsExecError(
                "Error: {} on removing {} out of namespace".format(
                    ret.stderr, phy_device))
      # del created namespace
      self.logger.debug("removing explored namespace: {}".format(
          docker_node.name))
      ret = utils.host_run(docker_node.logger,
                           "ip netns del {}".format(docker_node.name))
      if ret.returncode != 0:
        raise NameSpaceOperatingError("Error: {} on delete netns: {}".format(
            ret.stderr, docker_node.name))

  @staticmethod
  def is_mac80211_hwsim_loaded():
    ret = utils.host_run(CirqueLog.get_cirque_logger(),
                         "lsmod | grep mac80211_hwsim")
    return ret.returncode == 0

  @staticmethod
  def load_kernel_mac80211_hwsim(radios=DEFAULT_RADIOS):
    logger = CirqueLog.get_cirque_logger()
    logger.info("kernel module mac80211_hwsim is not loaded, loading now...")
    ret = utils.host_run(
        logger, "modprobe mac80211_hwsim \
                                 radios={}".format(radios))
    if ret.returncode != 0:

# Path: cirque/capabilities/basecapability.py
# class BaseCapability:
# 
#   @property
#   def name(self):
#     return ''
# 
#   def get_docker_run_args(self, docker_node):
#     return {}
# 
#   def enable_capability(self, docker_node):
#     pass
# 
#   def disable_capability(self, docker_node):
#     pass
# 
#   @property
#   def description(self):
#     return {}
# 
# Path: cirque/common/cirquelog.py
# class CirqueLog:
# 
#   logger = None
# 
#   @classmethod
#   def setup_cirque_logger(cls, level=logging.INFO):
#     if cls.logger:
#       return
#     cls.logger = logging.getLogger('cirque')
#     cls.logger.setLevel(level)
#     sh = logging.StreamHandler()
#     sh.setFormatter(
#         logging.Formatter('%(asctime)s [%(name)s] %(levelname)s %(message)s'))
#     cls.logger.addHandler(sh)
# 
#   @classmethod
#   def get_cirque_logger(cls, name=None):
#     name = 'cirque' if not name else 'cirque.{}'.format(name)
#     return logging.getLogger(name)
# 
# Path: cirque/common/exceptions.py
# class ConnectivityError(BaseException):
#   pass
# 
# class ContainerExecError(BaseException):
#   pass
# 
# class IpNetnsExecError(BaseException):
#   pass
# 
# class LoadKernelError(BaseException):
#   pass
# 
# class NameSpaceOperatingError(BaseException):
#   pass
# 
# class PHYDeviceError(BaseException):
#   pass


# Path: cirque/capabilities/wificapability.py
import os
import time
import cirque.common.utils as utils
from subprocess import PIPE
from pyroute2 import NetNS
from cirque.capabilities.basecapability import BaseCapability
from cirque.common.cirquelog import CirqueLog
from cirque.common.exceptions import (
    ConnectivityError,
    ContainerExecError,
    IpNetnsExecError,
    LoadKernelError,
    NameSpaceOperatingError,
    PHYDeviceError,
)

          ret = utils.netns_run(docker_node.logger,
                                "iw phy {} set netns 1".format(phy_device),
                                docker_node.name)
          if ret.returncode != 0:
            raise IpNetnsExecError(
                "Error: {} on removing {} out of namespace".format(
                    ret.stderr, phy_device))
      # del created namespace
      self.logger.debug("removing explored namespace: {}".format(
          docker_node.name))
      ret = utils.host_run(docker_node.logger,
                           "ip netns del {}".format(docker_node.name))
      if ret.returncode != 0:
        raise NameSpaceOperatingError("Error: {} on delete netns: {}".format(
            ret.stderr, docker_node.name))

  @staticmethod
  def is_mac80211_hwsim_loaded():
    ret = utils.host_run(CirqueLog.get_cirque_logger(),
                         "lsmod | grep mac80211_hwsim")
    return ret.returncode == 0

  @staticmethod
  def load_kernel_mac80211_hwsim(radios=DEFAULT_RADIOS):
    logger = CirqueLog.get_cirque_logger()
    logger.info("kernel module mac80211_hwsim is not loaded, loading now...")
    ret = utils.host_run(
        logger, "modprobe mac80211_hwsim \
                                 radios={}".format(radios))
    if ret.returncode != 0:

      raise LoadKernelError("unable to load module mac80211_hwsim!!")