Dan Talayco | c85e97e | 2010-02-07 22:59:04 -0800 | [diff] [blame] | 1 | import sys |
| 2 | sys.path.append('../../../src/python/oftest/ofmsg') |
| 3 | from message import * |
| 4 | from action import * |
| 5 | from error import * |
| 6 | from ofp_aux import * |
| 7 | |
| 8 | header_fields = ['version', 'xid'] |
| 9 | fixed_header_fields = ['type', 'length'] |
| 10 | |
| 11 | ofmsg_class_map_to_parents = { |
| 12 | action_enqueue : [ofp_action_enqueue], |
| 13 | action_output : [ofp_action_output], |
| 14 | action_set_dl_dst : [ofp_action_dl_addr], |
| 15 | action_set_dl_src : [ofp_action_dl_addr], |
| 16 | action_set_nw_dst : [ofp_action_nw_addr], |
| 17 | action_set_nw_src : [ofp_action_nw_addr], |
| 18 | action_set_nw_tos : [ofp_action_nw_tos], |
| 19 | action_set_tp_dst : [ofp_action_tp_port], |
| 20 | action_set_tp_src : [ofp_action_tp_port], |
| 21 | action_set_vlan_pcp : [ofp_action_vlan_pcp], |
| 22 | action_set_vlan_vid : [ofp_action_vlan_vid], |
| 23 | action_strip_vlan : [ofp_action_header], |
| 24 | action_vendor : [ofp_action_vendor_header], |
| 25 | aggregate_stats_reply : [ofp_stats_reply], |
| 26 | aggregate_stats_request : [ofp_stats_request, |
| 27 | ofp_aggregate_stats_request], |
| 28 | bad_action_error_msg : [ofp_error_msg], |
| 29 | bad_request_error_msg : [ofp_error_msg], |
| 30 | barrier_reply : [], |
| 31 | barrier_request : [], |
| 32 | desc_stats_reply : [ofp_stats_reply], |
| 33 | desc_stats_request : [ofp_stats_request, |
| 34 | ofp_desc_stats_request], |
| 35 | echo_reply : [], |
| 36 | echo_request : [], |
| 37 | error : [ofp_error_msg], |
| 38 | features_reply : [ofp_switch_features], |
| 39 | features_request : [], |
| 40 | flow_mod : [ofp_flow_mod], |
| 41 | flow_mod_failed_error_msg : [ofp_error_msg], |
| 42 | flow_removed : [ofp_flow_removed], |
| 43 | flow_stats_entry : [ofp_flow_stats], |
| 44 | flow_stats_reply : [ofp_stats_reply], |
| 45 | flow_stats_request : [ofp_stats_request, |
| 46 | ofp_flow_stats_request], |
| 47 | get_config_reply : [ofp_switch_config], |
| 48 | get_config_request : [], |
| 49 | hello : [], |
| 50 | hello_failed_error_msg : [ofp_error_msg], |
| 51 | ofp_desc_stats_request : [], |
| 52 | ofp_table_stats_request : [], |
| 53 | packet_in : [ofp_packet_in], |
| 54 | packet_out : [ofp_packet_out], |
| 55 | port_mod : [ofp_port_mod], |
| 56 | port_mod_failed_error_msg : [ofp_error_msg], |
| 57 | port_stats_reply : [ofp_stats_reply], |
| 58 | port_stats_request : [ofp_stats_request, |
| 59 | ofp_port_stats_request], |
| 60 | port_status : [ofp_port_status], |
| 61 | queue_get_config_reply : [ofp_queue_get_config_reply], |
| 62 | queue_get_config_request : [ofp_queue_get_config_request], |
| 63 | queue_op_failed_error_msg : [ofp_error_msg], |
| 64 | queue_stats_reply : [ofp_stats_reply], |
| 65 | queue_stats_request : [ofp_stats_request, |
| 66 | ofp_queue_stats_request], |
| 67 | set_config : [ofp_switch_config], |
| 68 | stats_reply : [ofp_stats_reply], |
| 69 | stats_request : [ofp_stats_request], |
| 70 | table_stats_reply : [ofp_stats_reply], |
| 71 | table_stats_request : [ofp_stats_request, |
| 72 | ofp_table_stats_request], |
| 73 | vendor : [ofp_vendor_header] |
| 74 | } |
| 75 | |
| 76 | ofmsg_names = { |
| 77 | action_enqueue : 'action_enqueue', |
| 78 | action_output : 'action_output', |
| 79 | action_set_dl_dst : 'action_set_dl_dst', |
| 80 | action_set_dl_src : 'action_set_dl_src', |
| 81 | action_set_nw_dst : 'action_set_nw_dst', |
| 82 | action_set_nw_src : 'action_set_nw_src', |
| 83 | action_set_nw_tos : 'action_set_nw_tos', |
| 84 | action_set_tp_dst : 'action_set_tp_dst', |
| 85 | action_set_tp_src : 'action_set_tp_src', |
| 86 | action_set_vlan_pcp : 'action_set_vlan_pcp', |
| 87 | action_set_vlan_vid : 'action_set_vlan_vid', |
| 88 | action_strip_vlan : 'action_strip_vlan', |
| 89 | action_vendor : 'action_vendor', |
| 90 | aggregate_stats_reply : 'aggregate_stats_reply', |
| 91 | aggregate_stats_request : 'aggregate_stats_request', |
| 92 | bad_action_error_msg : 'bad_action_error_msg', |
| 93 | bad_request_error_msg : 'bad_request_error_msg', |
| 94 | barrier_reply : 'barrier_reply', |
| 95 | barrier_request : 'barrier_request', |
| 96 | desc_stats_reply : 'desc_stats_reply', |
| 97 | desc_stats_request : 'desc_stats_request', |
| 98 | echo_reply : 'echo_reply', |
| 99 | echo_request : 'echo_request', |
| 100 | error : 'error', |
| 101 | features_reply : 'features_reply', |
| 102 | features_request : 'features_request', |
| 103 | flow_mod : 'flow_mod', |
| 104 | flow_mod_failed_error_msg : 'flow_mod_failed_error_msg', |
| 105 | flow_removed : 'flow_removed', |
| 106 | flow_stats_entry : 'flow_stats_entry', |
| 107 | flow_stats_reply : 'flow_stats_reply', |
| 108 | flow_stats_request : 'flow_stats_request', |
| 109 | get_config_reply : 'get_config_reply', |
| 110 | get_config_request : 'get_config_request', |
| 111 | hello : 'hello', |
| 112 | hello_failed_error_msg : 'hello_failed_error_msg', |
| 113 | ofp_desc_stats_request : 'ofp_desc_stats_request', |
| 114 | ofp_table_stats_request : 'ofp_table_stats_request', |
| 115 | packet_in : 'packet_in', |
| 116 | packet_out : 'packet_out', |
| 117 | port_mod : 'port_mod', |
| 118 | port_mod_failed_error_msg : 'port_mod_failed_error_msg', |
| 119 | port_stats_reply : 'port_stats_reply', |
| 120 | port_stats_request : 'port_stats_request', |
| 121 | port_status : 'port_status', |
| 122 | queue_get_config_reply : 'queue_get_config_reply', |
| 123 | queue_get_config_request : 'queue_get_config_request', |
| 124 | queue_op_failed_error_msg : 'queue_op_failed_error_msg', |
| 125 | queue_stats_reply : 'queue_stats_reply', |
| 126 | queue_stats_request : 'queue_stats_request', |
| 127 | set_config : 'set_config', |
| 128 | stats_reply : 'stats_reply', |
| 129 | stats_request : 'stats_request', |
| 130 | table_stats_reply : 'table_stats_reply', |
| 131 | table_stats_request : 'table_stats_request', |
| 132 | vendor : 'vendor' |
| 133 | } |
| 134 | |
| 135 | keys = ofmsg_class_map_to_parents.keys() |
| 136 | keys.sort() |
| 137 | |
| 138 | print "Generating all classes with no data init" |
| 139 | print |
| 140 | for cls in keys: |
| 141 | print "Creating class " + ofmsg_names[cls] |
| 142 | obj = cls() |
| 143 | print ofmsg_names[cls] + " length: " + str(len(obj)) |
| 144 | obj.show(" ") |
| 145 | print |
| 146 | |
| 147 | print "End of class generation" |
| 148 | print |
| 149 | print |
| 150 | |
| 151 | print "Generating messages, packing, showing (to verify len)" |
| 152 | print "and calling self unpack" |
| 153 | print |
| 154 | for cls in keys: |
| 155 | print "Pack/unpack test for class " + ofmsg_names[cls] |
| 156 | obj = cls() |
| 157 | packed = obj.pack() |
| 158 | print "Packed object, length ", len(packed) |
| 159 | obj.show(" ") |
| 160 | obj_check = cls() |
| 161 | string = obj_check.unpack(packed) |
| 162 | print "Unpacked obj, length ", len(obj_check) |
| 163 | obj_check.show(" ") |
| 164 | if string != "": |
| 165 | print >> sys.stderr, "WARNING: " + ofmsg_names[cls] + \ |
| 166 | ", unpack returned string " + string |
| 167 | if obj != obj_check: |
| 168 | print >> sys.stderr, "ERROR: " + ofmsg_names[cls] + \ |
| 169 | ", obj != obj_check" |
| 170 | print |
| 171 | |
| 172 | print "End of class pack check" |
| 173 | print |
| 174 | |
| 175 | |
| 176 | # |
| 177 | # TO DO |
| 178 | # Generate varying actions lists and attach to flow_mod, |
| 179 | # packet out and flow_stats_entry objects. |
| 180 | # Generate varying lists of stats entries for replies in |
| 181 | # flow_stats_reply, table_stats_reply, port_stats_reply and |
| 182 | # queue_stats_reply |
| 183 | # Create and test packet-to-flow function |
| 184 | |
| 185 | |
| 186 | f = flow_stats_reply() |
| 187 | ent = flow_stats_entry() |
| 188 | |
| 189 | |
| 190 | act = action_strip_vlan() |
| 191 | alist = action_list() |
| 192 | alist.add(act) |
| 193 | |
| 194 | act = action_set_tp_dst() |
| 195 | act.tp_port = 17 |
| 196 | |
| 197 | m = ofp_match() |
| 198 | m.wildcards = OFPFW_IN_PORT + OFPFW_DL_VLAN + OFPFW_DL_SRC |
| 199 | |
| 200 | # |
| 201 | # Need: Easy reference from action to data members |
| 202 | m.in_port = 12 |
| 203 | m.dl_src= [1,2,3,4,5,6] |
| 204 | m.dl_dst= [11,22,23,24,25,26] |
| 205 | m.dl_vlan = 83 |
| 206 | m.dl_vlan_pcp = 1 |
| 207 | m.dl_type = 0x12 |
| 208 | m.nw_tos = 3 |
| 209 | m.nw_proto = 0x300 |
| 210 | m.nw_src = 0x232323 |
| 211 | m.nw_dst = 0x3232123 |
| 212 | m.tp_src = 32 |
| 213 | m.tp_dst = 2 |
| 214 | |
| 215 | m.show() |
| 216 | |