예제 #1
0
def print_ofp_phy_port(port):
    port_id = '%s' % green(port.port_id)

    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),
    printed = False
    for i in port.config:
        print of10.dissector.get_phy_config(i),
        printed = True
    else:
        printed = _dont_print_0(printed)
    print

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

    # TODO: fix it
    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')
예제 #2
0
def print_ofp_body(msg):
    string = (
        'Body - Cookie: %s Command: %s Idle/Hard Timeouts: '
        '%s/%s\nBody - Priority: %s Buffer ID: %s Out Port: %s Flags: %s')
    command = green(of10.dissector.get_ofp_command(msg.command))
    flags = green(of10.dissector.get_ofp_flags(msg.flags))
    out_port = green(of10.dissector.get_phy_port_id(msg.out_port))

    print string % (msg.cookie, command, msg.idle_timeout, msg.hard_timeout,
                    green(msg.priority), msg.buffer_id, out_port, flags)
예제 #3
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(of13.dissector.get_flow_mod_command(msg.command))
    flags = green(of13.dissector.get_flow_mod_flags(msg.flags))
    port = green(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)
예제 #4
0
def print_of_packetOut(msg):
    print(
        'PacketOut: buffer_id: %s in_port: %s actions_len: %s' %
        (hex(msg.buffer_id), green(of10.dissector.get_phy_port_id(
            msg.in_port)), msg.actions_len))
    if msg.actions_len is not 0:
        print_actions(msg.actions)
        print_data(msg.data)
예제 #5
0
def print_lldp(lldp):
    """
        Print LLDP fields
    Args:
        lldp: LLDP class
    """
    if lldp.c_type is 1:
        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))
    else:
        print('LLDP: Malformed packet')
예제 #6
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)),
    for i in variable:
        print of10.dissector.get_phy_feature(i),
        printed = True
    else:
        printed = _dont_print_0(printed)
    print
예제 #7
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(tcpiplib.prints.datapath_id(
            msg.datapath_id)), msg.n_buffers, msg.n_tbls, msg.auxiliary_id,
         print_pad(msg.pad), green(msg.reserved)))
    print("Capabilities: "),
    for i in msg.caps:
        print of13.dissector.get_feature_res_capabilities(i),
    print
예제 #8
0
def print_of_feature_res(msg):
    dpid = datapath_id(msg.datapath_id)
    print('FeatureRes - datapath_id: %s n_buffers: %s n_tbls: %s, pad: %s' %
          (green(dpid), msg.n_buffers, msg.n_tbls, print_pad(msg.pad)))
    print('FeatureRes - Capabilities:'),
    for i in msg.capabilities:
        print of10.dissector.get_feature_res_capabilities(i),
    print
    print('FeatureRes - Actions:'),
    for i in msg.actions:
        print of10.dissector.get_feature_res_actions(i),
    print
    print_of_ports(msg.ports)
예제 #9
0
def print_ofp_match(match):
    print 'Match -',
    # Collect all variables from class ofp_match
    # print those that are not 'None'
    for match_item in match.__dict__:
        match_item_value = match.__dict__[match_item]
        if match_item_value is not None:
            if match_item is 'dl_vlan':
                match_item_value = of10.dissector.get_vlan(match_item_value)
            elif match_item is 'wildcards':
                match_item_value = hex(match_item_value)
            elif match_item is 'dl_type':
                match_item_value = tcpiplib.tcpip.get_ethertype(
                    match_item_value)

            print("%s: %s" % (match_item, green(match_item_value))),
    print
예제 #10
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 = 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(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 = 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(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 = tcpiplib.prints.eth_addr(oxm.payload.value)
            oxm.payload.mask = tcpiplib.prints.eth_addr(oxm.payload.mask)
        if oxm.field in [11, 12, 22, 23]:
            oxm.payload.value = tcpiplib.prints.get_ip_from_long(
                oxm.payload.value)
            oxm.payload.mask = tcpiplib.prints.get_ip_from_long(
                oxm.payload.mask)

        print('%s/%s' % (green(oxm.payload.value), green(oxm.payload.mask)))
예제 #11
0
def print_match_generic(oxm):
    print(' OXM Match: Class: %s Length: %s HasMask: %s Field: %s:' %
          (hex(oxm.oxm_class), oxm.length, oxm.hasmask,
           green(of13.dissector.get_flow_match_fields(oxm.field)))),
예제 #12
0
def print_of_packetIn(msg):
    print(
        'PacketIn: buffer_id: %s total_len: %s in_port: %s reason: %s '
        'pad: %s' % (hex(msg.buffer_id), msg.total_len, green(
            msg.in_port), green(msg.reason), print_pad(msg.pad)))
    print_data(msg.data)
예제 #13
0
def print_ofp_statReqQueue(msg):
    port_number = of10.dissector.get_phy_port_id(msg.stats.port_number)
    print('StatReq Type: Queue(%s): Port_Number: %s Pad: %s Queue_id: %s' %
          (msg.stat_type, green(port_number), print_pad(
              msg.stats.pad), msg.stats.queue_id))
예제 #14
0
def print_ofp_action(action_type, length, payload):
    if action_type == 0:
        port, max_len = of10.parser.get_action(action_type, payload)

        port = of10.dissector.get_phy_port_id(port)
        print('Action - Type: %s Length: %s Port: %s '
              'Max Length: %s' %
              (green('OUTPUT'), length, green(port), max_len))
        return 'output:' + port

    elif action_type == 1:
        vlan, pad = of10.parser.get_action(action_type, payload)
        print('Action - Type: %s Length: %s VLAN ID: %s Pad: %s' %
              (green('SetVLANID'), length, green(str(vlan)), print_pad(pad)))
        return 'mod_vlan_vid:' + str(vlan)

    elif action_type == 2:
        vlan_pc, pad = of10.parser.get_action(action_type, payload)
        print(
            'Action - Type: %s Length: %s VLAN PCP: %s Pad: %s' %
            (green('SetVLANPCP'), length, green(str(vlan_pc)), print_pad(pad)))
        return 'mod_vlan_pcp:' + str(vlan_pc)

    elif action_type == 3:
        print('Action - Type: %s Length: %s' % (green('StripVLAN'), length))
        return 'strip_vlan'

    elif action_type == 4:
        setDLSrc, pad = of10.parser.get_action(action_type, payload)
        print('Action - Type: %s Length: %s SetDLSrc: %s Pad: %s' %
              (green('SetDLSrc'), length, green(str(
                  eth_addr(setDLSrc))), print_pad(pad)))
        return 'mod_dl_src:' + str(eth_addr(setDLSrc))

    elif action_type == 5:
        setDLDst, pad = of10.parser.get_action(action_type, payload)
        print('Action - Type: %s Length: %s SetDLDst: %s Pad: %s' %
              (green('SetDLDst'), length, green(str(
                  eth_addr(setDLDst))), print_pad(pad)))
        return 'mod_dl_dst:' + str(eth_addr(setDLDst))

    elif action_type == 6:
        nw_addr = of10.parser.get_action(action_type, payload)
        print('Action - Type: %s Length: %s SetNWSrc: %s' %
              (green('SetNWSrc'), length, green(str(nw_addr))))
        return 'mod_nw_src:' + str(nw_addr)

    elif action_type == 7:
        nw_addr = of10.parser.get_action(action_type, payload)
        print('Action - Type: %s Length: %s SetNWDst: %s' %
              (green('SetNWDst'), length, green(str(nw_addr))))
        return 'mod_nw_src:' + str(nw_addr)

    elif action_type == 8:
        nw_tos, pad = of10.parser.get_action(action_type, payload)
        print('Action - Type: %s Length: %s SetNWTos: %s Pad: %s' %
              (green('SetNWTos'), length, green(str(nw_tos)), print_pad(pad)))
        return 'mod_nw_tos:' + str(nw_tos)

    elif action_type == 9:
        port, pad = of10.parser.get_action(action_type, payload)
        print('Action - Type: %s Length: %s SetTPSrc: %s Pad: %s' %
              (green('SetTPSrc'), length, green(str(port)), print_pad(pad)))
        return 'mod_tp_src:' + str(port)

    elif action_type == int('a', 16):
        port, pad = of10.parser.get_action(action_type, payload)
        print('Action - Type: %s Length: %s SetTPDst: %s Pad: %s' %
              (green('SetTPDst'), length, green(str(port)), print_pad(pad)))
        return 'mod_tp_dst:' + str(port)

    elif action_type == int('b', 16):
        port, pad, queue_id = of10.parser.get_action(action_type, payload)
        print(('Action - Type: %s Length: %s Enqueue: %s Pad: %s'
               ' Queue: %s') % (green('Enqueue'), length, green(
                   str(port)), print_pad(pad), green(str(queue_id))))
        return 'set_queue:' + str(queue_id)

    elif action_type == int('ffff', 16):
        vendor = of10.parser.get_action(action_type, payload)
        print('Action - Type:  %s Length: %s Vendor: %s' %
              (green('VENDOR'), length, green(str(vendor))))
        return 'VendorType'

    else:
        return 'Error'