Пример #1
0
def send_msg(datapath, msg, retries=3):
    """
    Send a message to the given datapath, with retries on failure.
    Prefer the higher-level functions in flows.py before dropping down to
    send_msg.

    Args:
        datapath (ryu.controller.controller.Datapath): The datapath to send the
        message to
        msg: Openflow message to send
        retries: Number of retries on failure

    Raises:
        MagmaOFError: if the message fails to send in the specified number of
        attempts
    """
    for i in range(0, retries):
        try:
            datapath.send_msg(msg)
            return
        except Exception as e:  # pylint: disable=broad-except
            logger.warning(
                'Error sending message, retrying again '
                '(attempt %s/%s)', i, retries,
            )
            if i == retries - 1:    # Only propagate if all retries are up
                logging.error('Send msg error! Type: %s, Reason: %s',
                              type(e).__name__, e)
                DP_SEND_MSG_ERROR.labels(cause=type(e).__name__).inc()
                raise MagmaOFError(e)
            else:
                continue
Пример #2
0
def _get_encoded_imsi_from_packetin(msg):
    """
    Retrieve encoded imsi from the Packet-In message, or raise an exception if
    it doesn't exist.
    """
    imsi = msg.match.get(IMSI_REG)
    if imsi is None:
        raise MagmaOFError('IMSI not found in OFPMatch')
    return imsi
Пример #3
0
 def handle_error(self, ev):
     """
     Error means that a message sent to OVS is unsuccessful. This function
     should be attached to the EventOFPErrorMsg event
     """
     msg = ev.msg
     datapath = msg.datapath
     switch = self._switches.get(datapath.id, None)
     if switch is None:
         self.logger.error('unknown dpid %s', datapath.id)
         return
     if msg.xid not in switch.results_by_msg:
         return
     # for now, result is unused. Just return if there's an exception
     switch.results_by_msg[msg.xid] = MagmaOFError(ev.msg)