<commit_before>from pox.lib.revent.revent import *
from pox.core import core

log = core.getLogger()

class DatapathEvent (Event):
  def __init__ (self, datapath):
    self.datapath = datapath

class SwitchJoin (DatapathEvent): pass
class SwitchLeave (DatapathEvent): pass

class HostEvent (Event):
  def __init__ (self, host):
    self.host = host

class HostJoin (HostEvent): pass
class HostLeave (HostEvent): pass





class Topology (EventMixin):
  _eventMixin_events = [
    SwitchJoin,
    SwitchLeave,
    HostJoin,
    HostLeave,
  ]

  def __init__ (self):
    #EventMixin.__init__(self)
    self.switches = {}

    if core.hasComponent("openflow"):
      self.listenTo(core.openflow)
    else:
      # We'll wait for openflow to come up
      self.listenTo(core)

  def _handle_ComponentRegistered (self, event):
    if event.name is "openflow":
      self.listenTo(event.component, prefix="OF01")

  def _handle_OF01_ConnectionUp (self, event):
    if event.dpid in self.switches:
      log.warn("Ignoring switch connection for %i because it's already connected" % (event.dpid,))
      return EventHalt
    self.switches[event.dpid] = event.connection
    log.info("Switch " + str(event.dpid) + " connected")

  def _handle_OF01_ConnectionDown (self, event):
    log.info("Switch " + str(event.dpid) + " disconnected")
    del self.switches[event.dpid]<commit_msg>Topology: Started restructing towards the NOM<commit_after>from pox.lib.revent.revent import *
from pox.core import core

log = core.getLogger()

class EntityEvent (Event):
  def __init__ (self, entity):
    self.entity = entity

class SwitchEvent (EntityEvent): pass
class SwitchJoin (SwitchEvent): pass
class SwitchLeave (SwitchEvent): pass

class HostEvent (EntityEvent): pass
class HostJoin (HostEvent): pass
class HostLeave (HostEvent): pass

class EntityJoin (EntityEvent): pass
class EntityLeave (EntityEvent): pass

class Entity (object):
  def __init__ (self, id):
    self.id = id

class Host (Entity):
  pass

class Switch (Entity):
  pass

class Port (Entity):
  def __init__ (self, num, hwAddr, name):
    self.number = num
    self.hwAddr = EthAddr(hwAddr)
    self.name = name

class Topology (EventMixin):
  _eventMixin_events = [
    SwitchJoin,
    SwitchLeave,
    HostJoin,
    HostLeave,
    EntityJoin,
    EntityLeave,
  ]

  def __init__ (self):
    EventMixin.__init__(self)
    self.entities = {}

  def getEntityByID (self, ID):
    return self.entities[ID]

  def addEntity (self, entity):
    assert entity.id not in self.entities
    self.entities[entity.id] = entity
    log.info(str(entity) + " joined")
    if isinstance(entity, Switch):
      self.raiseEvent(SwitchJoin, entity)
    elif isinstance(entity, Host):
      self.raiseEvent(HostJoin, entity)
    else:
      self.raiseEvent(EntityJoin, entity)

  def getEntitiesOfType (self, t=Entity, subtypes=True):
    if subtypes is False:
      return (x for x in self.entities.itervalues() if type(x) is t)
    else:
      return (x for x in self.entities.itervalues() if isinstance(x, t))



{'fraction_non_alphanumeric': 0.10645266950540452, 'fraction_numerical': 0.001965280052407468, 'mean_word_length': 3.6912442396313363, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4406413', 'n_tokens_mistral': 999, 'n_tokens_neox': 982, 'n_words': 274}