def next_step(self):
        time.sleep(0.05)
        self.logical_time += 1
        self._forwarded_this_step = 0

        if len(self.event_list) == 0:
            msg.fail("No more events to inject")
            return

        next_event = self.event_list.pop(0)
        if type(next_event) in InteractiveReplayer.supported_input_events:
            msg.replay_event_success("Injecting %r" % next_event)
            next_event.proceed(self.simulation)
        else:  # type(next_event) in InteractiveReplayer.supported_internal_events
            if type(next_event) == ControlMessageReceive and is_flow_mod(
                    next_event):
                msg.mcs_event("Injecting %r" % next_event)
            else:
                msg.replay_event_success("Injecting %r" % next_event)
            next_event.manually_inject(self.simulation)
            if self.show_flow_tables_each_step:
                for switch in self.simulation.topology.switches:
                    print "Switch %s" % switch.dpid
                    switch.show_flow_table()

        print "\nAdvanced to step %d\n" % self.logical_time
示例#2
0
  def simulate(self):
    simulation = self.initialize_simulation()

    # Some implementations send delete flow mods when disconnecting switches; ignore these flow_mods
    if self.ignore_trailing_flow_mod_deletes:
      # switch -> whether we have observed a flow_mod other than a trailing delete yet
      dpid2seen_non_delete = { switch.dpid : False for switch in simulation.topology.switches }

    # Reproduce the routing table state.
    all_flow_mods = []
    for next_event in self.event_list:
      if is_flow_mod(next_event):
        msg.special_event("Injecting %r" % next_event)
        all_flow_mods.append(next_event)
      else:
        msg.openflow_event("Injecting %r" % next_event)
      next_event.manually_inject(simulation)

    # Now filter out all flow_mods that don't correspond to an entry in the
    # final routing table. Do that by walking backwards through the flow_mods,
    # and checking if they match the flow table. If so, add it to list, and
    # remove all flow entries that currently match it to filter overlapping
    # flow_mods from earlier in the event_list.
    relevant_flow_mods = []
    for last_event in reversed(all_flow_mods):
      switch = simulation.topology.get_switch(last_event.dpid)

      # Ignore all trailing flow mod deletes
      if self.ignore_trailing_flow_mod_deletes:
        flow_mod_command = last_event.get_packet().command
        if (not dpid2seen_non_delete[switch.dpid] and
            (flow_mod_command == OFPFC_DELETE or flow_mod_command == OFPFC_DELETE_STRICT)):
          continue
        else:
          dpid2seen_non_delete[switch.dpid] = True

      if switch.table.matching_entries(last_event.get_packet().match) != []:
        relevant_flow_mods.append(last_event)
        switch.table.remove_matching_entries(last_event.get_packet().match)

    relevant_flow_mods.reverse()

    # Print filtered flow mods
    print "\n"
    msg.event("Filtered flow mods:")
    for next_event in relevant_flow_mods:
      print "%r" % next_event
    print "\n"

    # Add back removed entries.
    for flow_mod_event in relevant_flow_mods:
      flow_mod_event.manually_inject(simulation)

    # Now print flow tables of each switch.
    msg.event("Flow tables:")
    for switch in simulation.topology.switches:
      print "Switch %s" % switch.dpid
      switch.show_flow_table()

    return simulation
示例#3
0
  def next_step(self):
    time.sleep(0.05)
    self.logical_time += 1
    self._forwarded_this_step = 0

    if len(self.event_list) == 0:
      msg.fail("No more events to inject")
    else:
      next_event = self.event_list.pop(0)
      if type(next_event) in InteractiveReplayer.supported_input_events:
        msg.replay_event_success("Injecting %r" % next_event)
        next_event.proceed(self.simulation)
      else: # type(next_event) in InteractiveReplayer.supported_internal_events
	if type(next_event) == ControlMessageReceive and is_flow_mod(next_event):
          msg.mcs_event("Injecting %r" % next_event)
	else:
          msg.replay_event_success("Injecting %r" % next_event)
        next_event.manually_inject(self.simulation)
      if self.show_flow_tables_each_step:
	for switch in self.simulation.topology.switches:
	  print "Switch %s" % switch.dpid
	  switch.show_flow_table()

    print "\nAdvanced to step %d\n" % self.logical_time
示例#4
0
  def _poll_event(self, event, end_time):
    proceed = False
    while True:
      now = time.time()
      if event.proceed(self.simulation):
        proceed = True
        break
      elif now > end_time:
        break
      self.simulation.io_master.select(self.sleep_interval_seconds)
    if proceed:
      event.timed_out = False
      self.stats.event_matched(event)
      self.update_event_time(event)
      if self.show_flow_tables and\
       type(event) == ControlMessageReceive and\
       is_flow_mod(event):
	for switch in self.simulation.topology.switches:
	  msg.interactive("Switch %s" % switch.dpid)
	  switch.show_flow_table()
    else:
      event.timed_out = True
      self.stats.event_timed_out(event)
    event.replay_time = SyncTime.now()
示例#5
0
    def simulate(self):
        simulation = self.initialize_simulation()

        # Some implementations send delete flow mods when disconnecting switches; ignore these flow_mods
        if self.ignore_trailing_flow_mod_deletes:
            # switch -> whether we have observed a flow_mod other than a trailing delete yet
            dpid2seen_non_delete = {
                switch.dpid: False
                for switch in simulation.topology.switches
            }

        # Reproduce the routing table state.
        all_flow_mods = []
        for next_event in self.event_list:
            if is_flow_mod(next_event):
                msg.special_event("Injecting %r" % next_event)
                all_flow_mods.append(next_event)
            else:
                msg.openflow_event("Injecting %r" % next_event)
            next_event.manually_inject(simulation)

        # Now filter out all flow_mods that don't correspond to an entry in the
        # final routing table. Do that by walking backwards through the flow_mods,
        # and checking if they match the flow table. If so, add it to list, and
        # remove all flow entries that currently match it to filter overlapping
        # flow_mods from earlier in the event_list.
        relevant_flow_mods = []
        for last_event in reversed(all_flow_mods):
            switch = simulation.topology.get_switch(last_event.dpid)

            # Ignore all trailing flow mod deletes
            if self.ignore_trailing_flow_mod_deletes:
                flow_mod_command = last_event.get_packet().command
                if (not dpid2seen_non_delete[switch.dpid]
                        and (flow_mod_command == OFPFC_DELETE
                             or flow_mod_command == OFPFC_DELETE_STRICT)):
                    continue
                else:
                    dpid2seen_non_delete[switch.dpid] = True

            if switch.table.matching_entries(
                    last_event.get_packet().match) != []:
                relevant_flow_mods.append(last_event)
                switch.table.remove_matching_entries(
                    last_event.get_packet().match)

        relevant_flow_mods.reverse()

        # Print filtered flow mods
        print "\n"
        msg.event("Filtered flow mods:")
        for next_event in relevant_flow_mods:
            print "%r" % next_event
        print "\n"

        # Add back removed entries.
        for flow_mod_event in relevant_flow_mods:
            flow_mod_event.manually_inject(simulation)

        # Now print flow tables of each switch.
        msg.event("Flow tables:")
        for switch in simulation.topology.switches:
            print "Switch %s" % switch.dpid
            switch.show_flow_table()

        return simulation