Esempio n. 1
0
    def _exec_cmd_set_table(self, event):
        try:
            msg = event.msg
            dpid = strToDPID(msg["dpid"])
            con = core.openflow.getConnection(dpid)
            if con is None:
                raise RuntimeError("No such switch")

            xid = of.generate_xid()

            fm = of.ofp_flow_mod()
            fm.xid = xid
            fm.command = of.OFPFC_DELETE
            con.send(fm)
            bar = of.ofp_barrier_request()
            bar.xid = xid
            con.send(bar)

            for flow in msg.get("flows", []):
                fm = dict_to_flow_mod(flow)
                fm.xid = xid

                con.send(fm)
                # con.send(of.ofp_barrier_request(xid=xid))
            con.send(of.ofp_barrier_request(xid=xid))

            self.reply(event, **{"type": "set_table", "xid": xid})

        except:
            # log.exception("Exception in set_table")
            log.debug("Exception in set_table - %s:%s", sys.exc_info()[0].__name__, sys.exc_info()[1])
            self.reply(
                event, exception="%s: %s" % (sys.exc_info()[0], sys.exc_info()[1]), traceback=traceback.format_exc()
            )
Esempio n. 2
0
    def _modify_flow(self, command_type):

        global Barrier_Modifyxid
        msg = of.ofp_flow_mod()

        if command_type == "MOD_ST":
            msg.command = of.OFPFC_MODIFY_STRICT
        elif command_type == "MOD":
            msg.command = of.OFPFC_MODIFY

        self._match_field(msg)

        for connection in core.openflow._connections.values():

            if str(dpidToStr(connection.dpid)) == self.dpid:
                """match actions"""
                self._match_action(msg)
                connection.send(msg)

                barrier = of.ofp_barrier_request()
                barrier.xid = of.generate_xid()
                Barrier_Modifyxid = barrier.xid
                connection.send(barrier)

                # for recover
                self._record_rules(dpid=self.dpid, msg=msg)
Esempio n. 3
0
  def _modify_flow(self,command_type):
    
    global Modifyxid 
    Modifyxid = of.generate_xid()
    msg = of.ofp_flow_mod()
    
    # print "====mod payload ====\n",self.payload
    
    if command_type == "MOD_ST":
      msg.command = of.OFPFC_MODIFY_STRICT
    elif command_type == "MOD":
      msg.command = of.OFPFC_MODIFY
    
    self._match_field(msg)

    for connection in core.openflow._connections.values() :

      if str(dpidToStr(connection.dpid)) == self.dpid:
        """match actions"""
        self._match_action(msg)
        connection.send(msg)

        barrier = of.ofp_barrier_request()
        barrier.xid = xid
        connection.send(barrier)

        # for recover
        self._record_rules(dpid = self.dpid , msg = msg)
    def _init(self, flows=[]):
        self.done = False

        xid = of.generate_xid()
        self.xid = xid
        self.clear_table(xid=xid)

        self.count = 1 + len(flows)

        for flow in flows:
            fm = dict_to_flow_mod(flow)
            fm.xid = xid

            self._con.send(fm)
            self._con.send(of.ofp_barrier_request(xid=xid))
  def _init (self, flows = []):
    self.done = False

    xid = of.generate_xid()
    self.xid = xid
    self.clear_table(xid=xid)

    self.count = 1 + len(flows)

    for flow in flows:
      fm = dict_to_flow_mod(flow)
      fm.xid = xid

      self._con.send(fm)
      self._con.send(of.ofp_barrier_request(xid=xid))
Esempio n. 6
0
def _of_test_once():

    log.info("get connections...")

    for connection in core.openflow._connections.values():
        if connection.dpid == g1_dpid:
            global start_time
            start_time = time.time()

            msg = of.ofp_flow_mod()
            msg.match.in_port = 1
            msg.xid = of.generate_xid()
            global xid
            xid = msg.xid
            connection.send(msg)

            connection.send(of.ofp_barrier_request(xid=msg.xid))
            connection.addListenerByName("BarrierIn", _handle_BarrierIn)
Esempio n. 7
0
    def _add_flow(self, command_type):

        global Barrier_Addxid
        msg = of.ofp_flow_mod()
        msg.command = of.OFPFC_ADD

        self._match_field(msg)

        for connection in core.openflow._connections.values():
            if str(dpidToStr(connection.dpid)) == self.dpid:
                """match actions"""
                self._match_action(msg)
                connection.send(msg)
                barrier = of.ofp_barrier_request()
                barrier.xid = of.generate_xid()
                Barrier_Addxid = barrier.xid
                connection.send(barrier)
                # for recover
                self._record_rules(dpid=self.dpid, msg=msg)
Esempio n. 8
0
  def _add_flow(self,command_type):

    global Barrier_Addxid 
    msg = of.ofp_flow_mod()
    msg.command = of.OFPFC_ADD

    self._match_field(msg)

    for connection in core.openflow._connections.values() :
      if str(dpidToStr(connection.dpid)) == self.dpid:
        
        """match actions"""
        self._match_action(msg)
        connection.send(msg)
        barrier = of.ofp_barrier_request()
        barrier.xid = of.generate_xid()
        Barrier_Addxid = barrier.xid
        connection.send(barrier)
        # for recover
        self._record_rules(dpid = self.dpid , msg = msg)
Esempio n. 9
0
  def _exec_cmd_set_table (self, event):
    try:
      msg = event.msg
      dpid = strToDPID(msg['dpid'])
      con = core.openflow.getConnection(dpid)
      if con is None:
        raise RuntimeError("No such switch")

      xid = of.generate_xid()

      """
      As modificações em um tabela de fluxo do controlador é feito com a mensagem OFPT_FLOW_MOD
      """
      fm = of.ofp_flow_mod()
      fm.xid = xid
      "OFPFC_DELETE: Exclui todos os fluxos correspondentes .."
      fm.command = of.OFPFC_DELETE
      con.send(fm)
      bar = of.ofp_barrier_request()
      bar.xid = xid
      con.send(bar)

      for flow in msg.get('flows',[]):
        fm = dict_to_flow_mod(flow)
        fm.xid = xid

        con.send(fm)
        #con.send(of.ofp_barrier_request(xid=xid))
      con.send(of.ofp_barrier_request(xid=xid))

      self.reply(event,**{'type':'set_table','xid':xid})

    except:
      #log.exception("Exception in set_table")
      log.debug("Exception in set_table - %s:%s",
                sys.exc_info()[0].__name__,
                sys.exc_info()[1])
      self.reply(event,
                 exception="%s: %s" % (sys.exc_info()[0],sys.exc_info()[1]),
                 traceback=traceback.format_exc())
Esempio n. 10
0
  def _delete_flow(self,command_type):
    
    Deletexid = of.generate_xid()
    msg = of.ofp_flow_mod()
    if command_type == "DEL_ST":
      msg.command = of.OFPFC_DELETE_STRICT
    elif command_type == "DEL":
      msg.command = of.OFPFC_DELETE
  
    # print "=== del payload ===\n",self.payload    
    self._match_field(msg)

    for connection in core.openflow._connections.values() :

      if str(dpidToStr(connection.dpid)) == self.dpid:
        connection.send(msg)

        barrier = of.ofp_barrier_request()
        barrier.xid = xid
        connection.send(barrier)

        # for recover
        self._record_rules(dpid = self.dpid , msg = msg)
Esempio n. 11
0
    def _exec_cmd_set_table(self, event):
        try:
            msg = event.msg
            dpid = strToDPID(msg['dpid'])
            con = core.openflow.getConnection(dpid)
            if con is None:
                raise RuntimeError("No such switch")

            xid = of.generate_xid()

            fm = of.ofp_flow_mod()
            fm.xid = xid
            fm.command = of.OFPFC_DELETE
            con.send(fm)
            bar = of.ofp_barrier_request()
            bar.xid = xid
            con.send(bar)

            for flow in msg.get('flows', []):
                fm = dict_to_flow_mod(flow)
                fm.xid = xid

                con.send(fm)
                #con.send(of.ofp_barrier_request(xid=xid))
            con.send(of.ofp_barrier_request(xid=xid))

            self.reply(event, **{'type': 'set_table', 'xid': xid})

        except:
            #log.exception("Exception in set_table")
            log.debug("Exception in set_table - %s:%s",
                      sys.exc_info()[0].__name__,
                      sys.exc_info()[1])
            self.reply(event,
                       exception="%s: %s" %
                       (sys.exc_info()[0], sys.exc_info()[1]),
                       traceback=traceback.format_exc())
Esempio n. 12
0
    def _delete_flow(self, command_type):

        global Barrier_Deletexid
        msg = of.ofp_flow_mod()

        if command_type == "DEL_ST":
            msg.command = of.OFPFC_DELETE_STRICT
        elif command_type == "DEL":
            msg.command = of.OFPFC_DELETE

        self._match_field(msg)

        for connection in core.openflow._connections.values():

            if str(dpidToStr(connection.dpid)) == self.dpid:
                connection.send(msg)

                barrier = of.ofp_barrier_request()
                barrier.xid = of.generate_xid()
                Barrier_Deletexid = barrier.xid
                connection.send(barrier)

                # for recover
                self._record_rules(dpid=self.dpid, msg=msg)
Esempio n. 13
0
 def __init__(self):
   self.done = False
   xid = of.generate_xid()
   self.xid = xid
   self.count = 0