def class_action_test(): """ Test objects that use action lists """ print "Testing action lists: flow mod, packet out, flow stats" for acount in [0, 1, 5, 16, 34]: print " " + str(acount) + " actions in list" obj = flow_mod() obj.actions = action_list_create(acount) packed = obj.pack() header = of_header_parse(packed) obj_check = flow_mod() if obj_check.unpack(packed) != "": error_out("ERROR: flow mod action list test extra " + "string on unpack") obj_comp(obj, obj_check, 'flow_mod', "unpack test " + str(acount)) obj_check = of_message_parse(packed) obj_comp(obj, obj_check, 'flow_mod', "parse test " + str(acount)) # obj.show() # packet out with and without data obj = packet_out() obj.actions = action_list_create(acount) packed = obj.pack() header = of_header_parse(packed) obj_check = packet_out() if obj_check.unpack(packed) != "": error_out("ERROR: packet out packet_out test extra " + "string on unpack") obj_comp(obj, obj_check, 'packet_out', "unpack test " + str(acount)) obj_check = of_message_parse(packed) obj_comp(obj, obj_check, 'packet_out', "parse test " + str(acount)) # obj.show() obj = packet_out() obj.actions = action_list_create(acount) obj.data = "short test string for packet data" packed = obj.pack() header = of_header_parse(packed) obj_check = packet_out() if obj_check.unpack(packed) != "": error_out("ERROR: packet out packet_out test extra " + "string on unpack") obj_comp(obj, obj_check, 'packet_out', "unpack test " + str(acount)) obj_check = of_message_parse(packed) obj_comp(obj, obj_check, 'packet_out', "parse test " + str(acount)) # obj.show() # flow stats entry (not a message) obj = flow_stats_entry() obj.actions = action_list_create(acount) packed = obj.pack() obj_check = flow_stats_entry() if obj_check.unpack(packed) != "": error_out("ERROR: packet out flow stats test extra " + "string on unpack") obj_comp(obj, obj_check, 'packet_out', "unpack test " + str(acount))
print "End of class pack check" print print print "Testing message parsing" print for cls in all_objs: # Can only parse real messages if not cls in of_messages: print "Not testing " + ofmsg_names[cls] continue print "Parse test for class " + ofmsg_names[cls] obj = cls() packed = obj.pack() header = of_header_parse(packed) obj_check = of_message_parse(packed) obj_comp(obj, obj_check, ofmsg_names[cls], "parse test") print "End of parse testing" print print class_action_test() print print # # TO DO # Generate varying actions lists and attach to flow_mod, # packet out and flow_stats_entry objects. # Generate varying lists of stats entries for replies in
print print print "Testing message parsing" print for cls in all_objs: # Can only parse real messages if not cls in of_messages: print "Not testing " + ofmsg_names[cls] continue print "Parse test for class " + ofmsg_names[cls] obj = cls() packed = obj.pack() header = of_header_parse(packed) obj_check = of_message_parse(packed) obj_comp(obj, obj_check, ofmsg_names[cls], "parse test") print "End of parse testing" print print class_action_test() print print # # TO DO # Generate varying actions lists and attach to flow_mod, # packet out and flow_stats_entry objects. # Generate varying lists of stats entries for replies in