def print_vlan(vlan): """ Print VLAN fields Args: vlan: VLAN class """ print('VLAN: PCP: %s CFI: %s VID: %s Protocol: %s' % (vlan.pcp, vlan.cfi, red(vlan.vid), red(get_ethertype( vlan.ethertype))))
def print_oessfvd(fvd): """ Print FVD fields Args: fvd: OessFvd class """ timestamp = str(datetime.fromtimestamp(fvd.timestamp)) print('OESS FVD: %s:%s -> %s:%s time: %s' % (red(fvd.side_a), blue(fvd.port_a), red(fvd.side_z), blue( fvd.port_z), blue(timestamp)))
def print_ofpt_features_reply(msg): print("Datapath_id: %s N_Buffers: %s N_Tables: %s " "Auxiliary_id: %s Pad: %s Reserved: %s" % (red(msg.datapath_id), msg.n_buffers, red( msg.n_tables), msg.auxiliary_id, msg.pad, msg.reserved)) print("Capabilities: ", end="") caps = parse_capabilities(msg.capabilities) for i in caps: print(libs.openflow.of13.dissector.get_feature_res_capabilities(i), end=" "), print()
def print_ofpt_error(msg): """ Prints OFPT_ERROR messages. msg.data is the error payload, which is the OpenFlow message that triggered the error. Args: msg: OpenFlow message unpacked by python-openflow """ etype, ecode = dissector.get_ofp_error(msg.error_type.value, msg.code.value) print('OpenFlow Error - Type: %s Code: %s' % (red(etype), red(ecode))) if not isinstance(msg.data, BinaryData): print('OpenFlow Error Message:\n------ BEGIN ------') print_openflow_header(msg.data) prints_ofp(msg.data) print('OpenFlow Error Message:\n------- END -------') else: print(red('OpenFlow Error Data could not be processed!!'))
def print_ofpt_stats_reply_port(port): """ Args: msg: OpenFlow message unpacked by python-openflow """ print('StatRes Type: Port(4)') print('StatRes port_number: %s rx_packets: %s rx_bytes: %s rx_errors: %s' ' rx_crc_err: %s rx_dropped: %s rx_over_err: %s rx_frame_err: %s\n' 'StatRes port_number: %s tx_packets: %s tx_bytes: %s tx_errors: %s' ' tx_dropped: %s collisions: %s pad: %s' % (red(port.port_no), port.rx_packets, port.rx_bytes, port.rx_errors, port.rx_crc_err, port.rx_dropped, port.rx_over_err, port.rx_frame_err, red(port.port_no), port.tx_packets, port.tx_bytes, port.tx_errors, port.tx_dropped, port.collisions, port.pad))
def print_connection_restablished(pkt): """ Just prints that the TCP connection was restablished. Args: pkt: Packet class """ print_headers(pkt, overwrite_min=0) print(red("!!!! Attention: Connection Re-Established!!\n"))
def print_connection_terminated(pkt): """ Just prints that the TCP connection was terminated (FIN or RST flag). Args: pkt: Packet class """ print_headers(pkt, overwrite_min=0) print(red("!!!! Attention: TCP/OpenFlow Connection Terminated!!\n"))
def print_layer2(eth): """ Prints the Ethernet frame Args: eth: Ethernet class """ print('Ethernet: Destination MAC: %s Source MAC: %s Protocol: %s' % (eth_addr(eth.dst_mac), eth_addr(eth.src_mac), red(libs.tcpiplib.tcpip.get_ethertype(eth.protocol))))
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
def _print_port_mod_config_mask(variable, name): print('PortMod %s: ' % name, end='') printed = False variable = _parse_phy_curr(variable) for i in variable: print(red(dissector.get_phy_config(i)), end='') printed = True else: _dont_print_0(printed) print()
def _print_port_mod_config_mask(variable, name): """The mask field is used to select bits in the config field to change. The advertise field has no mask; all port features change together.""" print('PortMod %s: ' % name, end='') printed = False variable = _parse_phy_curr(variable) for i in variable: print(red(dissector.get_phy_config(i)), end='') printed = True else: _dont_print_0(printed) print()
def print_openflow_header(ofp): """ Print OpenFlow header Args: ofp: OFMessage class """ version = libs.tcpiplib.tcpip.get_ofp_version(ofp.header.version.value) name_version = '%s(%s)' % (version, ofp.header.version.value) name = "%s" % ofp.header.message_type name_type = '%s(%s)' % (name.split('.')[1], ofp.header.message_type.value) print('OpenFlow Version: %s Type: %s Length: %s XID: %s' % (name_version, yellow(name_type), ofp.header.length, red(ofp.header.xid)))
def print_ofpt_flow_removed(msg): """ Args: msg: OpenFlow message unpacked by python-openflow """ print_ofp_match(msg.match) string = ('Body - Cookie: %s Priority: %s Reason: %s Pad: %s\nBody - ' 'Duration Secs/NSecs: %s/%s Idle Timeout: %s Pad2: %s' ' Packet Count: %s Byte Count: %s') print(string % (msg.cookie, msg.priority, red(msg.reason), msg.pad, msg.duration_sec, msg.duration_nsec, msg.idle_timeout, msg.pad2, msg.packet_count, msg.byte_count))
def print_ofpt_multipart_reply_port(port): """ Args: msg: OpenFlow message unpacked by python-openflow """ flags = green(dissector.get_multipart_reply_flags(msg.flags.value)) print( ' Port(4): Flags: %s port_number: %s pad: %s rx_packets: %s tx_packets: %s rx_bytes: %s tx_bytes: %s' 'rx_dropped: %s tx_dropped: %s rx_errors: %s tx_errors: %s rx_frame_err: %s rx_over_err: %s' 'rx_crc_err: %s collisions: %s duration_sec: %s duration_nsec: %s\n' % (flags, red(port.port_no), port.pad, port.rx_packets, port.tx_packets, port.rx_bytes, port.tx_bytes, port.rx_dropped, port.tx_dropped, port.rx_errors, port.tx_errors, port.rx_frame_err, port.rx_over_err, port.rx_crc_err, port.collisions, port.duration_sec, port.duration_nsec))
def print_ofpt_flow_removed(msg): """ Args: msg: OpenFlow message unpacked by python-openflow """ # Print main flow_removed options string = ('Body - Cookie: %s Priority: %s Reason: %s table_id: %s\nBody - ' 'Duration Secs/NSecs: %s/%s Idle Timeout: %s Hard Timeout: %s' ' Packet Count: %s Byte Count: %s') print(string % (msg.cookie, msg.priority, red(msg.reason), msg.table_id, msg.duration_sec, msg.duration_nsec, msg.idle_timeout, msg.hard_timeout, msg.packet_count, msg.byte_count)) print_match_type(msg.match)
def print_ofpt_stats_reply_vendor(msg): """ Args: msg: OpenFlow message unpacked by python-openflow """ def print_ofpt_stats_reply_vendor_data(data): """ Args: msg: OpenFlow message unpacked by python-openflow """ print('StatRes Vendor Data: ') hexdump(data) print('StatRes Type: Vendor(%s)' % hex(msg.body_type.value)) print('StatRes Vendor_Id: %s' % red(hex(msg.body[0].vendor.value))) print_ofpt_stats_reply_vendor_data(msg.body[0].body.value)