# Path: sts/util/procutils.py
# def popen_filtered(name, args, cwd=None, env=None, redirect_output=True,
#                    shell=False):
#   if shell and type(args) == list:
#     args = ' '.join(args)
#   try:
#     # note: the preexec_fn below makes the process its own session leader.
#     # This means that a CTRL-C on the shell will not be passed on to the process,
#     # which enables us to jump between Fuzzing/Replay and Interactive mode.
#     cmd = subprocess.Popen(args, stdout=subprocess.PIPE, shell=shell,
#                            stderr=subprocess.PIPE, stdin=sys.stdin, cwd=cwd, env=env,
#                            preexec_fn=lambda: os.setsid())
#   except OSError as e:
#     raise OSError("Error launching %s in directory %s: %s (error %d)" % (args, cwd, e.strerror, e.errno))
#   if redirect_output:
#     cmd._stdout_thread = _prefix_thread(cmd.stdout, partial(color_normal, label=name))
#     cmd._stderr_thread = _prefix_thread(cmd.stderr, partial(color_error, label=name))
#   return cmd
# 
# Path: sts/util/convenience.py
# def object_fullname(obj):
#   """Return the fullname of an object"""
#   return obj.__module__ + "." + obj.__class__.__name__
# 
# Path: sts/util/convenience.py
# def class_fullname(cls):
#   """Return the fullname of a class"""
#   return cls.__module__ + "." + cls.__name__
# 
# Path: sts/util/convenience.py
# def load_class(str_full_type):
#   """
#   Load a python class given full qualified name.
#   """
#   type_s = str_full_type.split('.')
#   mod = importlib.import_module('.'.join(type_s[:-1]))
#   cls = getattr(mod, type_s[-1])
#   return cls
# 
# Path: sts/util/convenience.py
# def get_json_attr(obj):
#   """
#   Returns the serialized version of the object if it has to_json() defined
#   """
#   if hasattr(obj, "to_json"):
#     return getattr(obj, "to_json")()
#   else:
#     return obj


import abc
import logging
        import paramiko
      import paramiko
from functools import partial
from pox.openflow.libopenflow_01 import ofp_phy_port
from sts.util.procutils import popen_filtered
from sts.util.convenience import object_fullname
from sts.util.convenience import class_fullname
from sts.util.convenience import load_class
from sts.util.convenience import get_json_attr
    from sts.util.procutils import _prefix_thread
    from sts.util.procutils import color_normal
    from sts.util.procutils import color_error

"""
Define base (mostly abstract) entities used by sts.
"""






def serialize_ofp_phy_port(port):
  """
  Serializes OpenFlow physical port to JSON Dict
  """
  attrs = ['port_no', 'hw_addr', 'name', 'config', 'state', 'curr',
           'advertised', 'supported', 'peer']
  json_dict = {'__type__': object_fullname(port)}
  print class_fullname(ofp_phy_port)
  for attr in attrs:
    value = getattr(port, attr, None)
    if hasattr(value, 'toStr'):
      value = value.toStr()
    json_dict[attr] = value
  return json_dict


def deserialize_ofp_phy_port(cls, json_dict):
  """
  De-Serializes JSON Dict to OpenFlow physical port
  """

# Path: sts/util/procutils.py
# def popen_filtered(name, args, cwd=None, env=None, redirect_output=True,
#                    shell=False):
#   if shell and type(args) == list:
#     args = ' '.join(args)
#   try:
#     # note: the preexec_fn below makes the process its own session leader.
#     # This means that a CTRL-C on the shell will not be passed on to the process,
#     # which enables us to jump between Fuzzing/Replay and Interactive mode.
#     cmd = subprocess.Popen(args, stdout=subprocess.PIPE, shell=shell,
#                            stderr=subprocess.PIPE, stdin=sys.stdin, cwd=cwd, env=env,
#                            preexec_fn=lambda: os.setsid())
#   except OSError as e:
#     raise OSError("Error launching %s in directory %s: %s (error %d)" % (args, cwd, e.strerror, e.errno))
#   if redirect_output:
#     cmd._stdout_thread = _prefix_thread(cmd.stdout, partial(color_normal, label=name))
#     cmd._stderr_thread = _prefix_thread(cmd.stderr, partial(color_error, label=name))
#   return cmd
# 
# Path: sts/util/convenience.py
# def object_fullname(obj):
#   """Return the fullname of an object"""
#   return obj.__module__ + "." + obj.__class__.__name__
# 
# Path: sts/util/convenience.py
# def class_fullname(cls):
#   """Return the fullname of a class"""
#   return cls.__module__ + "." + cls.__name__
# 
# Path: sts/util/convenience.py
# def load_class(str_full_type):
#   """
#   Load a python class given full qualified name.
#   """
#   type_s = str_full_type.split('.')
#   mod = importlib.import_module('.'.join(type_s[:-1]))
#   cls = getattr(mod, type_s[-1])
#   return cls
# 
# Path: sts/util/convenience.py
# def get_json_attr(obj):
#   """
#   Returns the serialized version of the object if it has to_json() defined
#   """
#   if hasattr(obj, "to_json"):
#     return getattr(obj, "to_json")()
#   else:
#     return obj


# Path: sts/entities/base.py
import abc
import logging
        import paramiko
      import paramiko
from functools import partial
from pox.openflow.libopenflow_01 import ofp_phy_port
from sts.util.procutils import popen_filtered
from sts.util.convenience import object_fullname
from sts.util.convenience import class_fullname
from sts.util.convenience import load_class
from sts.util.convenience import get_json_attr
    from sts.util.procutils import _prefix_thread
    from sts.util.procutils import color_normal
    from sts.util.procutils import color_error


"""
Define base (mostly abstract) entities used by sts.
"""






def serialize_ofp_phy_port(port):
  """
  Serializes OpenFlow physical port to JSON Dict
  """
  attrs = ['port_no', 'hw_addr', 'name', 'config', 'state', 'curr',
           'advertised', 'supported', 'peer']
  json_dict = {'__type__': object_fullname(port)}
  print class_fullname(ofp_phy_port)
  for attr in attrs:
    value = getattr(port, attr, None)
    if hasattr(value, 'toStr'):
      value = value.toStr()
    json_dict[attr] = value
  return json_dict


def deserialize_ofp_phy_port(cls, json_dict):
  """
  De-Serializes JSON Dict to OpenFlow physical port
  """

  assert json_dict['__type__'] == class_fullname(cls)