Example #1
0
def print_instruction(instructions):
    print('Flow Instructions:')
    for instruction in instructions:
        print(' Instruction: Type %s Length: %s' % (dissector.get_instructions(
            instruction.instruction_type.value), instruction.length))
        # GotoTable
        if instruction.instruction_type.value == 1:
            print(" Goto Table_ID: %s" % green(instruction.table_id.value))
        # WriteMetadata
        if instruction.instruction_type.value == 2:
            print(" MetaData: %s MetaData_Mask: %s" %
                  (green(hex(instruction.metadata.value)),
                   green(hex(instruction.metadata_mask.value))))
        # WriteActions, ApplyActions, ClearActions
        if instruction.instruction_type.value in [3, 4, 5]:
            for action in instruction.actions:
                print('  Action - Type %s Length %s' %
                      (green(action.action_type), action.length),
                      end='')
                print_action(action)
        # Meter
        if instruction.instruction_type.value == 6:
            print("Meter_ID: %s" % green(hex(instruction.meter_id.value)))
        # Experimenter
        if instruction.instruction_type.value == 65535:
            print("Experimenter")
Example #2
0
def print_ofp_phy_port(port):
    port_id = '%s' % green(port.port_no)

    print('Port_id: %s - hw_addr: %s name: %s' % (
          port_id, green(port.hw_addr), green(port.name)))

    print('Port_id: %s - config: ' % port_id, end='')
    printed = False
    config = _parse_phy_config(port.config.value)
    for i in config:
        print(dissector.get_phy_config(i), end='')
        printed = True
    else:
        printed = _dont_print_0(printed)
    print()

    print('Port_id: %s - state: ' % port_id, end='')
    state = _parse_phy_state(port.state.value)
    for i in state:
        print(dissector.get_phy_state(i), end='')
        printed = True
    else:
        _dont_print_0(printed)
    print()

    print_port_field(port_id, port.curr, 'curr')
    print_port_field(port_id, port.advertised, 'advertised')
    print_port_field(port_id, port.supported, 'supported')
    print_port_field(port_id, port.peer, 'peer')
Example #3
0
def print_lldp(lldp):
    """
        Print LLDP fields
    Args:
        lldp: LLDP class
    """
    if lldp.c_type is not 1 or lldp.p_type is not 2 \
            or lldp.t_type is not 3 or lldp.e_type is not 0:
        print('LLDP: Malformed packet')
        return

    if lldp.c_type is 1:
        if isinstance(lldp.c_id, bytes):
            lldp.c_id = lldp.c_id.decode("utf-8")
        print('LLDP: Chassis Type(%s) Length: %s SubType: %s ID: %s' %
              (lldp.c_type, lldp.c_length, lldp.c_subtype, green(lldp.c_id)))
    if lldp.p_type is 2:
        print('LLDP: Port Type(%s) Length: %s SubType: %s ID: %s' %
              (lldp.p_type, lldp.p_length, lldp.p_subtype, green(lldp.p_id)))
    if lldp.t_type is 3:
        print('LLDP: TTL(%s) Length: %s Seconds: %s' %
              (lldp.t_type, lldp.t_length, lldp.t_ttl))

    if lldp.e_type is 0:
        print('LLDP: END(%s) Length: %s' % (lldp.e_type, lldp.e_length))
Example #4
0
    def print_print_ofpt_multipart_request_queue(msg):
        """

        Args:
            msg: OpenFlow message unpacked by python-openflow
        """
        port_number = dissector.get_phy_port_no(msg.port_no.value)
        flags = green(dissector.get_multipart_request_flags(msg.flags.value))
        print('  Queue(5): Flags: %s Pad: %s Port_Number: %s Queue_id: %s' %
              (flags, msg.pad, green(port_number), msg.queue_id))
Example #5
0
def print_ofpt_packet_in(msg):
    """

    Args:
        msg: OpenFlow message unpacked by python-openflow
    """
    print('PacketIn: buffer_id: %s total_len: %s in_port: %s reason: %s '
          'pad: %s' %
          (hex(msg.buffer_id.value), msg.total_len.value,
           green(msg.in_port.value), green(msg.reason.value), msg.pad))
    print_data(msg.data)
Example #6
0
def print_ofpt_meter_mod(msg):
    """
           These  commands  manage  the  meter  table  in  an  OpenFlow  switch.  In each case, meter
       specifies a meter entry in the format described in Meter Syntax.
    """
    # Print main meter_mod options
    string = 'Body - Command: %s Flags: %s Meter_OD: %s'

    flags = green(dissector.get_meter_mod_flags(msg.flags.value))
    command = green(dissector.get_meter_mod_command(msg.command.value))

    print(string % (command, flags, msg.meter_id,))
Example #7
0
def print_ofpt_packet_in(msg):
    """
    Args:
        msg: OpenFlow message unpacked by python-openflow
    """
    print('PacketIn: buffer_id: %s total_len: %s reason: %s table_id: %s '
          'cookie: %s ' %
          (hex(msg.buffer_id.value), msg.total_len.value,
           green(dissector.get_packet_in_reason(msg.reason.value)),
           green(msg.table_id.value), msg.cookie.value))
    print('Match: ', end='')
    print_match_type(msg.match)
    print('Pad: %s' % msg.pad)
    print_data(msg.data)
Example #8
0
        def print_ofpt_multipart_reply_queue(queue):
            """

            Args:
                queue: OpenFlow message unpacked by python-openflow
            """
            flags = green(dissector.get_multipart_reply_flags(msg.flags.value))
            port_no = green(dissector.get_phy_port_no(msg.port_no.value))
            print(
                '  Queue(5): Flags: %s port_no: %s queue_id: %s tx_bytes: %s tx_packets: %s tx_errors: %s'
                'duration_sec: %s duration_nsec: %s' %
                (flags, port_no, queue.queue_id, queue.tx_bytes,
                 queue.tx_packets, queue.tx_errors, queue.duration_sec,
                 queue.duration_nsec))
Example #9
0
def print_ofp_body(msg):
    """

    Args:
        msg: OpenFlow message unpacked by python-openflow
    """
    string = ('Body - Cookie: %s Command: %s Idle/Hard Timeouts: '
              '%s/%s\nBody - Priority: %s Buffer ID: %s Out Port: %s Flags: %s')
    command = green(dissector.get_ofp_command(msg.command.value))
    flags = green(dissector.get_ofp_flags(msg.flags.value))
    out_port = green(dissector.get_phy_port_id(msg.out_port.value))

    print(string % (msg.cookie.value, command, msg.idle_timeout, msg.hard_timeout,
                    green(msg.priority), msg.buffer_id.value, out_port, flags))
Example #10
0
def print_ofpt_flow_mod(msg):
    # Print main flow_mod options
    string = ('FlowMod - Cookie/Mask: %s/%s Table_id: %s Command: %s '
              'Idle/Hard Timeouts: %s/%s\nFlowMod - Priority: %s '
              'Buffer ID: %s Out Port: %s Out Group: %s Flags: %s Pad: %s')

    flags = green(dissector.get_flow_mod_flags(msg.flags.value))
    port = green(dissector.get_phy_port_no(msg.out_port.value))
    command = green(dissector.get_flow_mod_command(msg.command.value))
    print(string % (green(hex(msg.cookie.value)), hex(
        msg.cookie_mask.value), msg.table_id, command, msg.idle_timeout,
                    msg.hard_timeout, green(msg.priority), msg.buffer_id, port,
                    msg.out_group, flags, print_pad(msg.pad)))

    print_match_type(msg.match)
    print_instruction(msg.instructions)
Example #11
0
    def print_ofpt_multipart_reply_meter_config(msg):
        """
            Args:
                    msg: OpenFlow message unpacked by python-openflow
        """
        flags = green(dissector.get_multipart_reply_flags(msg.flags.value))
        print('  Meter_Config(10): Flags: %s length: %s meter_id: %s' %
              (flags, msg.len, msg.meter_id.value))

        for band in msg.meter_band_header[0].band:
            if band.type == "drop":
                print(
                    'Band[type]: %s Band[len]: %s Band[rate]: %s Band[burst_size]: %s Band[pad]: %s'
                    % (band.type.value, band.len.value, band.rate.value,
                       band.burst_size.value, band.pad))
            if band.type == "dscp_remark":
                print(
                    'Band[type]: %s Band[len]: %s Band[rate]: %s Band[burst_size]: %s Band[prec]: %s '
                    'Band[pad]: %s' %
                    (band.type.value, band.len.value, band.rate.value,
                     band.burst_size.value, band.prec.value, band.pad))
            if band.type == "experimenter":
                print(
                    'Band[type]: %s Band[len]: %s Band[rate]: %s Band[burst_size]: %s Band[experimenter_id]: %s'
                    % (band.type.value, band.len.value, band.rate.value,
                       band.burst_size.value, band.experimenter_id.value))

        if len(msg.body) == 0:
            print('Multipart Reply Type Meter_config(10):\nNo meter_configs')
            return
Example #12
0
def print_ofp_match(match):
    """

    Args:
        match:
    """
    print('Match - ', end='')
    for match_item in match.__dict__:
        match_item_value = match.__dict__[match_item]
        if match_item_value.value not in [
                0, "00:00:00:00:00:00", "0.0.0.0", 65535
        ]:
            if match_item is 'dl_vlan' and match_item_value.value not in [
                    65535
            ]:
                match_item_value = dissector.get_vlan(match_item_value.value)
            elif match_item is 'wildcards':
                match_item_value = hex(match_item_value.value)
            elif match_item is 'dl_type' and match_item_value.value not in [
                    65535
            ]:
                match_item_value = libs.tcpiplib.tcpip.get_ethertype(
                    match_item_value.value)
            elif match_item in ['pad1', 'pad2']:
                continue

            print("%s: %s " % (match_item, green(match_item_value)), end='')
    print()
Example #13
0
 def print_ofpt_multipart_request_meter_features(msg):
     """
         Args:
                 msg: OpenFlow message unpacked by python-openflow
     """
     flags = green(dissector.get_multipart_request_flags(msg.flags.value))
     print('  Meter_Features(11): Flags: %s Pad: %s' % (flags, msg.pad))
Example #14
0
 def print_ofpt_multipart_request_port_desc(msg):
     """
         Args:
                 msg: OpenFlow message unpacked by python-openflow
     """
     flags = green(dissector.get_multipart_request_flags(msg.flags.value))
     print('  Port_Desc(13): Flags: %s Pad: %s' % (flags, msg.pad))
Example #15
0
def print_match_oxm(oxm):
    if oxm.oxm_hasmask == 0:
        if oxm.oxm_field in [0]:
            oxm.oxm_value = int.from_bytes(oxm.oxm_value, byteorder='big')
            oxm.oxm_value = dissector.get_phy_port_no(oxm.oxm_value)
        # DL_DST or DL_SRC
        elif oxm.oxm_field in [3, 4, 24, 25, 32, 33]:
            print(green(libs.tcpiplib.prints.eth_addr(oxm.oxm_value)))
            return
        # DL_TYPE
        elif oxm.oxm_field in [5]:
            oxm.oxm_value = int.from_bytes(oxm.oxm_value, byteorder='big')
            oxm.oxm_value = hex(oxm.oxm_value)
        # DL_VLAN
        elif oxm.oxm_field == 6:
            if oxm.oxm_value == 0:
                oxm.oxm_value = 'OFPVID_NONE (UNTAGGED)'
            else:
                # 0x1xxx Bit 1 indicates VLAN. Removing this bit to
                # get the VID
                oxm.oxm_value = int.from_bytes(oxm.oxm_value, byteorder='big')
                oxm.oxm_value -= 4096

        # NW_SRC or NW_DST
        elif oxm.oxm_field in [11, 12, 22, 23]:
            oxm.oxm_value = libs.tcpiplib.prints.get_ip_from_long(
                oxm.oxm_value)
        # IPv6 Extensions
        elif oxm.oxm_field in [39]:
            extensions = of13.parser.parse_ipv6_extension_header(oxm.oxm_value)
            for i in extensions:
                print(green(
                    libs.openflow.of13.dissector.get_ipv6_extension(i))),

        print('%s' % green(oxm.oxm_value))

    elif oxm.oxm_hasmask == 1:
        if oxm.oxm_field in [3, 4, 24, 25]:
            oxm.oxm_value = libs.tcpiplib.prints.eth_addr(oxm.oxm_value)
            oxm.payload.mask = libs.tcpiplib.prints.eth_addr(oxm.payload.mask)
        if oxm.oxm_field in [11, 12, 22, 23]:
            oxm.oxm_value = libs.tcpiplib.prints.get_ip_from_long(
                oxm.oxm_value)
            oxm.payload.mask = libs.tcpiplib.prints.get_ip_from_long(
                oxm.payload.mask)

        print('%s/%s' % (green(oxm.payload.value), green(oxm.payload.mask)))
Example #16
0
def print_connection_being_established(pkt):
    """
        Just prints that a new TCP connection is being established.
        Args:
            pkt: Packet class
    """
    print_headers(pkt, overwrite_min=0)
    print(green("!!!! New TCP/OpenFlow Connection being established!!\n"))
Example #17
0
 def print_ofpt_multipart_request_group(msg):
     """
         Args:
                 msg: OpenFlow message unpacked by python-openflow
     """
     flags = green(dissector.get_multipart_request_flags(msg.flags.value))
     print('  Group(6): Flags: %s Pad: %s Group_ID: %s Pad: %s' %
           (flags, msg.pad, msg.group_id, msg.pad))
Example #18
0
 def print_ofpt_multipart_request_meter_config(msg):
     """
         Args:
                 msg: OpenFlow message unpacked by python-openflow
     """
     flags = green(dissector.get_multipart_request_flags(msg.flags.value))
     print('  Meter_Config(10): Flags: %s Pad: %s Meter_ID: %s Pad: %s' %
           (flags, msg.pad, msg.meter_id, msg.pad))
Example #19
0
def print_match_oxm(oxm):
    if oxm.hasmask == 0:
        if oxm.field in [0]:
            oxm.payload.value = oxm.payload.value & 0xffff
            oxm.payload.value = libs.openflow.of13.dissector.get_phy_port_id(
                oxm.payload.value)
        # DL_DST or DL_SRC
        elif oxm.field in [3, 4, 24, 25, 32, 33]:
            print(green(libs.tcpiplib.prints.eth_addr(oxm.payload.value)))
            return
        # DL_TYPE
        elif oxm.field in [5]:
            oxm.payload.value = hex(oxm.payload.value)
        # DL_VLAN
        elif oxm.field == 6:
            if oxm.payload.value == 0:
                oxm.payload.value = 'UNTAGGED'
            else:
                oxm.payload.value = oxm.payload.value & 0xfff
        # NW_SRC or NW_DST
        elif oxm.field in [11, 12, 22, 23]:
            oxm.payload.value = libs.tcpiplib.prints.get_ip_from_long(
                oxm.payload.value)
        # IPv6 Extensions
        elif oxm.field in [39]:
            extensions = of13.parser.parse_ipv6_extension_header(
                oxm.payload.values)
            for i in extensions:
                print(green(
                    libs.openflow.of13.dissector.get_ipv6_extension(i))),

        print('%s' % green(oxm.payload.value))

    elif oxm.hasmask == 1:
        if oxm.field in [3, 4, 24, 25]:
            oxm.payload.value = libs.tcpiplib.prints.eth_addr(
                oxm.payload.value)
            oxm.payload.mask = libs.tcpiplib.prints.eth_addr(oxm.payload.mask)
        if oxm.field in [11, 12, 22, 23]:
            oxm.payload.value = libs.tcpiplib.prints.get_ip_from_long(
                oxm.payload.value)
            oxm.payload.mask = libs.tcpiplib.prints.get_ip_from_long(
                oxm.payload.mask)

        print('%s/%s' % (green(oxm.payload.value), green(oxm.payload.mask)))
Example #20
0
    def print_ofpt_stats_request_queue(msg):
        """

        Args:
            msg: OpenFlow message unpacked by python-openflow
        """
        port_number = dissector.get_phy_port_id(msg.body[0].port_no.value)
        print('StatReq Type: OFPST_QUEUE: Port_Number: %s Pad: %s Queue_id: %s' %
              (green(port_number), msg.body[0].pad, msg.body[0].queue_id))
Example #21
0
def print_ofpt_group_mod(msg):
    """
        Args:
            msg: OpenFlow message unpacked by python-openflow | PAGE 82
    """
    command = green(dissector.get_group_mod_command(msg.command.value))
    type = green(dissector.get_group_mod_type(msg.command.value))

    print('GroupMod Command: %s Type: %s Pad: %s Group_id: %s\n'
          'Bucket[lenght]: %s Bucket[weight]: %s Bucket[watch_port]: %s Bucket[watch_group]: %s' %
          (command, type, msg.pad, green(msg.group_id.value), msg.buckets[0].length.value,
           msg.buckets[0].weight.value, hex(msg.buckets[0].watch_port.value),
           hex(msg.buckets[0].watch_group.value)))
    print("Bucket[actions]:")
    for action in msg.buckets[0].actions:
        print_action(action)

    return 0
Example #22
0
def print_ofpt_multipart_reply(msg):
    # Print main multipart_reply options
    string = 'Body - Type: %s Flags: %s Pad: %s'

    flags = green(dissector.get_multipart_reply_flags(msg.flags.value))

    print(string % (msg.multipart_type, flags, msg.pad))

    return 0
Example #23
0
def print_flow_mod(msg):
    # Print main flow_mod options
    string = ('FlowMod - Cookie/Mask: %s/%s Table_id: %s Command: %s '
              'Idle/Hard Timeouts: %s/%s\nFlowMod - Priority: %s '
              'Buffer ID: %s Out Port: %s Out Group: %s Flags: %s Pad: %s')

    command = green(
        libs.openflow.of13.dissector.get_flow_mod_command(msg.command))
    flags = green(libs.openflow.of13.dissector.get_flow_mod_flags(msg.flags))
    port = green(libs.openflow.of13.dissector.get_phy_port_id(msg.out_port))
    print(string %
          (msg.cookie, msg.cookie_mask, msg.table_id, command,
           msg.idle_timeout, msg.hard_timeout, msg.priority, msg.buffer_id,
           port, msg.out_group, flags, print_pad(msg.pad)))

    # Print print_match_type(msg)
    print_match_type(msg.match)
    print_instruction(msg.instructions)
Example #24
0
    def print_ofpt_multipart_reply_experimenter(msg):
        """

        Args:
            msg: OpenFlow message unpacked by python-openflow
        """
        flags = green(dissector.get_multipart_reply_flags(msg.flags.value))
        print('  Experimenter(65535): Flags: %s Pad: %s Experimenter: %s' %
              (flags, msg.pad, msg.experimenter))
Example #25
0
def print_switch_features(msg):
    print("OpenFlow Switch Features:")
    print("Datapath_id: %s N_Buffers: %s N_Tbls: %s\nAuxiliary_id: %s "
          "Pad: %s Reserved: %s" %
          (red(msg.datapath_id), msg.n_buffers, msg.n_tbls, msg.auxiliary_id,
           msg.pad, green(msg.reserved)))
    print("Capabilities: "),
    caps = parse_capabilities(msg.capabilities)
    for i in caps:
        print(libs.openflow.of13.dissector.get_feature_res_capabilities(i)),
    print
Example #26
0
    def print_ofpt_multipart_reply_aggregate(msg):
        """

        Args:
            msg: OpenFlow message unpacked by python-openflow
        """
        flags = green(dissector.get_multipart_reply_flags(msg.flags.value))
        print(
            '  Aggregate(2): Flags: %s packet_count: %s, byte_count: %s flow_count: %s Pad: %s'
            % (flags, msg.packet_count, msg.byte_count, msg.flow_count,
               msg.pad))  # Is msg.stats included in 1.3?
Example #27
0
    def print_ofpt_multipart_reply_description(msg):
        """

        Args:
                msg: OpenFlow message unpacked by python-openflow
        """
        flags = green(dissector.get_multipart_reply_flags(msg.flags.value))
        print('  Description(0): Flags: %s mfr_desc: %s hw_desc: %s'
              'sw_desc: %s serial_num: %s dp_desc: %s' %
              (flags, msg.mfr_desc, msg.hw_desc, msg.bsw_desc, msg.serial_num,
               msg.dp_desc))
Example #28
0
    def print_ofps_multipart_request_experimenter(msg):
        """

        Args:
            msg: OpenFlow message unpacked by python-openflow
        """
        flags = green(dissector.get_multipart_request_flags(msg.flags.value))
        print(
            '  Experimenter(65535): Flags: %s Pad: %s  Experimenter_ID: %s  Experimenter_Type: %s'
            %
            (flags, msg.pad, msg.experimenter_id.value, msg.experimenter_type))
Example #29
0
    def print_ofpt_multipart_reply_group_desc(msg):
        """
            Args:
                    msg: OpenFlow message unpacked by python-openflow
        """
        flags = green(dissector.get_multipart_reply_flags(msg.flags.value))
        print(
            '  Group_Desc(7): Flags: %s length: %s pad: %s group_id: %s'
            'Bucket[length]: %s Bucket[weight]: %s Bucket[watch_port]: %s Bucket[watch_group]: %s'
            % (flags, msg.length, green(msg.group_id.value), msg.pad,
               msg.buckets[0].length.value, msg.buckets[0].weight.value,
               hex(msg.buckets[0].watch_port.value),
               hex(msg.buckets[0].watch_group.value)))

        print("Bucket[actions]:")
        for action in msg.buckets[0].actions:
            print_action(action)

        if len(msg.body) == 0:
            print('Multipart Reply Type Group_Desc(7):\nNo group_desc')
            return
Example #30
0
def print_port_field(port_id, variable, name):
    port_id = '%s' % green(port_id)
    printed = False

    print('Port_id: %s - %s: ' % (port_id, name), end='')
    variable = _parse_phy_curr(variable)
    for i in variable:
        print(dissector.get_phy_feature(i) + ' ', end='')
        printed = True
    else:
        _dont_print_0(printed)
    print()