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))
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))
def print_action(action): """Function to print the content of openflow actions""" if action.action_type == 0: port_name = dissector.get_phy_port_no(action.port.value) print(" Output Port %s Max_Len %s Pad %s" % (green(port_name), action.max_length, print_pad(action.pad))) # SetMPLSTTL elif action.action_type == 15: print("ATTENTION!!!!!") # PUSH_VLAN elif action.action_type == 17: print(" Ethertype: %s" % green(hex(action.ethertype.value))) # CopyTTLOut, CopyTTLIn, DecMPLSTTL, POP_VLAN, PopMPLS, DecNWTTL, PopPBB elif action.action_type in [11, 12, 16, 18, 20, 24, 27]: print() # PushMPLS elif action.action_type == 19: print("ATTENTION!!!!!") # SET_QUEUE elif action.action_type == 21: print(' Queue ID: %s' % green(action.queue_id.value)) # Group elif action.action_type == 22: print("ATTENTION!!!!!") # SetNWTTL elif action.action_type == 23: print("ATTENTION!!!!!") # SET_FIELD elif action.action_type == 25: # TODO: LEVERAGE FUNCTION BELOW IN THE FUTURE FOR ALL THE OXM_MATCH # print_match_oxm(action.field) if action.field.oxm_field == 6: # VLAN vlan = unpack('!H', action.field.oxm_value)[0] & 4095 print(" Set VLAN_VID: %s" % green(vlan)) elif action.field.oxm_field == 3: # ETH_DST print(" Set ETH_DST: %s" % green(libs.tcpiplib.prints.eth_addr(action.field.oxm_value))) elif action.field.oxm_field == 4: # ETH_SRC print(" Set ETH_SRC: %s" % green(libs.tcpiplib.prints.eth_addr(action.field.oxm_value))) else: print(" ATTENTION!!!!!") print(action.field.oxm_field) # PushPBB elif action.action_type == 26: print("ATTENTION!!!!!") # Experimenter elif action.action_type == 65535: print("ATTENTION!!!!!")
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)
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)))
def print_ofpt_packet_out(msg): """ Args: msg: OpenFlow message unpacked by python-openflow ; PAGE 107 MANUAL """ print('PacketOut: buffer_id: %s in_port: %s actions_len: %s' % (hex(msg.buffer_id.value), green(dissector.get_phy_port_no( msg.in_port.value)), msg.actions_len.value)) if msg.actions_len is not 0: print(" Actions:") for action in msg.actions: print(" ", end="") print_action(action) print_data(msg.data) return 0
def print_ofpt_multipart_request_flow_aggregate(msg): """ Args: msg: OpenFlow message unpacked by python-openflow """ out_port = dissector.get_phy_port_no(msg.out_port.value) flags = green(dissector.get_multipart_request_flags(msg.flags.value)) if msg.multipart_type.value == 1: print(' Flow(1): ', end='') else: print(' Aggregate(2): ', end='') print( 'Flags: % s Pad: % s Table_id: % s Pad: % s Out_Port: % s Out_group: % s Pad: %s Cookie: %s ' 'Cookie_Mask: %s' % (flags, msg.pad, msg.table_id.value, msg.pad, out_port, msg.out_group, msg.pad, msg.cookie, msg.cookie_mask)) print_match_type(msg.match)