# Path: sts/util/console.py
# class msg():
#   global_io_master = None
# 
#   BEGIN = '\033[1;'
#   END = '\033[1;m'
# 
#   GRAY, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, CRIMSON = map(lambda num: str(num) + "m", range(30, 39))
#   B_BLACK, B_RED, B_GREEN, B_YELLOW, B_BLUE, B_MAGENTA, B_CYAN, B_GRAY, B_CRIMSON =  map(lambda num: str(num) + "m", range(40, 49))
# 
#   @staticmethod
#   def interactive(message):
#     # todo: would be nice to simply give logger a color arg, but that doesn't exist...
#     print msg.BEGIN + msg.WHITE + message + msg.END
# 
#   @staticmethod
#   def event(message):
#     print msg.BEGIN + msg.CYAN + message + msg.END
# 
#   @staticmethod
#   def openflow_event(message):
#     print msg.BEGIN + msg.BLUE + message + msg.END
# 
#   @staticmethod
#   def special_event(message):
#     print msg.BEGIN + msg.MAGENTA + message + msg.END
# 
#   @staticmethod
#   def replay_event_success(message):
#     print msg.BEGIN + msg.CYAN + msg.BEGIN + msg.B_BLUE + message + msg.END
# 
#   @staticmethod
#   def replay_event_timeout(message):
#     print msg.BEGIN + msg.MAGENTA + msg.BEGIN + msg.B_RED + message + msg.END
# 
#   @staticmethod
#   def mcs_event(message):
#     print msg.BEGIN + msg.B_MAGENTA + message + msg.END
# 
#   @staticmethod
#   def raw_input(message):
#     prompt = msg.BEGIN + msg.WHITE + message + msg.END
#     if msg.global_io_master:
#       s = msg.global_io_master.raw_input(prompt)
#     else:
#       s = raw_input(prompt)
# 
#     if s == "debug":
#       import pdb
#       pdb.set_trace()
#     return s
# 
#   @staticmethod
#   def success(message):
#     print msg.BEGIN + msg.B_GREEN + msg.BEGIN + msg.WHITE + message + msg.END
# 
#   @staticmethod
#   def fail(message):
#     print msg.BEGIN + msg.B_RED + msg.BEGIN + msg.WHITE + message + msg.END
# 
#   @staticmethod
#   def set_io_master(io_master):
#     msg.global_io_master = io_master
# 
#   @staticmethod
#   def unset_io_master():
#     msg.global_io_master = None


from pox.openflow.software_switch import OFConnection
from pox.openflow.libopenflow_01 import ofp_flow_mod
from pox.lib.addresses import EthAddr, IPAddr
from sts.util.console import msg
import time
import re
import os
import sys
import errno
import socket
import random
import types
import struct
import shutil
import base64
import subprocess
import warnings
import functools
import importlib
    if address in IPAddressSpace._claimed_addresses:
      raise ValueError("Address %s already claimed" % address)
    IPAddressSpace._claimed_addresses.add(address)

  @staticmethod
  def find_unclaimed_address(ip_prefix="192.168.1"):
    ''' Find an unclaimed IP address in the given /24 range (may be specified
        as a full IP address for convenience).
    '''
    octects = ip_prefix.split(".")
    if len(octects) == 4:
      ip_prefix = ".".join(octects[0:3])
    host_octect = 2
    address = "%s.%d" % (ip_prefix, host_octect)
    while host_octect <= 255 and address in IPAddressSpace._claimed_addresses:
      host_octect += 1
      address = "%s.%d" % (ip_prefix, host_octect)

    if address in IPAddressSpace._claimed_addresses:
      raise RuntimeError("Out of IP addresses in prefix %s" % ip_prefix)
    return address

def backtick(cmd, *args, **kwargs):
  return subprocess.Popen(cmd, *args, shell=True, stdout=subprocess.PIPE, **kwargs).stdout.read().strip()

def system(cmd, *args, **kwargs):
  return subprocess.call(cmd, *args, shell=True, **kwargs)

def show_flow_tables(simulation):
  for switch in simulation.topology.switches:

# Path: sts/util/console.py
# class msg():
#   global_io_master = None
# 
#   BEGIN = '\033[1;'
#   END = '\033[1;m'
# 
#   GRAY, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, CRIMSON = map(lambda num: str(num) + "m", range(30, 39))
#   B_BLACK, B_RED, B_GREEN, B_YELLOW, B_BLUE, B_MAGENTA, B_CYAN, B_GRAY, B_CRIMSON =  map(lambda num: str(num) + "m", range(40, 49))
# 
#   @staticmethod
#   def interactive(message):
#     # todo: would be nice to simply give logger a color arg, but that doesn't exist...
#     print msg.BEGIN + msg.WHITE + message + msg.END
# 
#   @staticmethod
#   def event(message):
#     print msg.BEGIN + msg.CYAN + message + msg.END
# 
#   @staticmethod
#   def openflow_event(message):
#     print msg.BEGIN + msg.BLUE + message + msg.END
# 
#   @staticmethod
#   def special_event(message):
#     print msg.BEGIN + msg.MAGENTA + message + msg.END
# 
#   @staticmethod
#   def replay_event_success(message):
#     print msg.BEGIN + msg.CYAN + msg.BEGIN + msg.B_BLUE + message + msg.END
# 
#   @staticmethod
#   def replay_event_timeout(message):
#     print msg.BEGIN + msg.MAGENTA + msg.BEGIN + msg.B_RED + message + msg.END
# 
#   @staticmethod
#   def mcs_event(message):
#     print msg.BEGIN + msg.B_MAGENTA + message + msg.END
# 
#   @staticmethod
#   def raw_input(message):
#     prompt = msg.BEGIN + msg.WHITE + message + msg.END
#     if msg.global_io_master:
#       s = msg.global_io_master.raw_input(prompt)
#     else:
#       s = raw_input(prompt)
# 
#     if s == "debug":
#       import pdb
#       pdb.set_trace()
#     return s
# 
#   @staticmethod
#   def success(message):
#     print msg.BEGIN + msg.B_GREEN + msg.BEGIN + msg.WHITE + message + msg.END
# 
#   @staticmethod
#   def fail(message):
#     print msg.BEGIN + msg.B_RED + msg.BEGIN + msg.WHITE + message + msg.END
# 
#   @staticmethod
#   def set_io_master(io_master):
#     msg.global_io_master = io_master
# 
#   @staticmethod
#   def unset_io_master():
#     msg.global_io_master = None


# Path: sts/util/convenience.py
from pox.openflow.software_switch import OFConnection
from pox.openflow.libopenflow_01 import ofp_flow_mod
from pox.lib.addresses import EthAddr, IPAddr
from sts.util.console import msg
import time
import re
import os
import sys
import errno
import socket
import random
import types
import struct
import shutil
import base64
import subprocess
import warnings
import functools
import importlib

    if address in IPAddressSpace._claimed_addresses:
      raise ValueError("Address %s already claimed" % address)
    IPAddressSpace._claimed_addresses.add(address)

  @staticmethod
  def find_unclaimed_address(ip_prefix="192.168.1"):
    ''' Find an unclaimed IP address in the given /24 range (may be specified
        as a full IP address for convenience).
    '''
    octects = ip_prefix.split(".")
    if len(octects) == 4:
      ip_prefix = ".".join(octects[0:3])
    host_octect = 2
    address = "%s.%d" % (ip_prefix, host_octect)
    while host_octect <= 255 and address in IPAddressSpace._claimed_addresses:
      host_octect += 1
      address = "%s.%d" % (ip_prefix, host_octect)

    if address in IPAddressSpace._claimed_addresses:
      raise RuntimeError("Out of IP addresses in prefix %s" % ip_prefix)
    return address

def backtick(cmd, *args, **kwargs):
  return subprocess.Popen(cmd, *args, shell=True, stdout=subprocess.PIPE, **kwargs).stdout.read().strip()

def system(cmd, *args, **kwargs):
  return subprocess.call(cmd, *args, shell=True, **kwargs)

def show_flow_tables(simulation):
  for switch in simulation.topology.switches:

    msg.interactive("Switch %s" % switch.dpid)