Exemplo n.º 1
0
Arquivo: parse.py Projeto: CPqD/oftest
def _of_message_to_object(binary_string):
    """
    Map a binary string to the corresponding class.

    Appropriately resolves subclasses
    """
    hdr = ofp.ofp_header()
    hdr.unpack(binary_string)
    # FIXME: Add error detection
    if not hdr.type in msg_type_subclassed:
        return msg_type_to_class_map[hdr.type]()
    if hdr.type == ofp.OFPT_STATS_REQUEST:
        sub_hdr = ofp.ofp_stats_request()
        sub_hdr.unpack(binary_string[ofp.OFP_HEADER_BYTES:])
        try:
            obj = stats_request_to_class_map[sub_hdr.type]()
        except LookupError:
            obj = None
        return obj
    elif hdr.type == ofp.OFPT_STATS_REPLY:
        sub_hdr = ofp.ofp_stats_reply()
        sub_hdr.unpack(binary_string[ofp.OFP_HEADER_BYTES:])
        try:
            obj = stats_reply_to_class_map[sub_hdr.type]()
        except LookupError:
            obj = None
        return obj
    elif hdr.type == ofp.OFPT_ERROR:
        sub_hdr = ofp.ofp_error_msg()
        sub_hdr.unpack(binary_string[ofp.OFP_HEADER_BYTES:])
        return error_to_class_map[sub_hdr.type]()
    else:
        parse_logger.error("Cannot parse pkt to message")
        return None
Exemplo n.º 2
0
Arquivo: parse.py Projeto: CPqD/oftest
def of_header_parse(binary_string, raw=False):
    """
    Parse only the header from an OpenFlow packet

    Parses the header from a raw OpenFlow packet into a
    an ofp_header Python class.

    @param binary_string The packet (string) to be parsed
    @param raw If true, interpret the packet as an L2 packet.  Not
    yet supported.
    @return An ofp_header object

    """

    if raw:
        parse_logger.error("raw packet message parsing not supported")
        return None

    hdr = ofp.ofp_header()
    hdr.unpack(binary_string)

    return hdr