Rich Lane | 629393f | 2013-01-10 15:37:33 -0800 | [diff] [blame] | 1 | |
| 2 | # Python OpenFlow action wrapper classes |
| 3 | |
| 4 | from cstruct import * |
| 5 | from match import roundup |
| 6 | from match_list import match_list |
| 7 | |
| 8 | class action_pop_mpls(ofp_action_pop_mpls): |
| 9 | """ |
| 10 | Wrapper class for pop_mpls action object |
| 11 | |
| 12 | Data members inherited from ofp_action_pop_mpls: |
| 13 | @arg type |
| 14 | @arg len |
| 15 | @arg ethertype |
| 16 | |
| 17 | """ |
| 18 | def __init__(self): |
| 19 | ofp_action_pop_mpls.__init__(self) |
| 20 | self.type = OFPAT_POP_MPLS |
| 21 | self.len = self.__len__() |
| 22 | def show(self, prefix=''): |
| 23 | outstr = prefix + "action_pop_mpls\n" |
| 24 | outstr += ofp_action_pop_mpls.show(self, prefix) |
| 25 | return outstr |
| 26 | |
| 27 | |
| 28 | class action_push_vlan(ofp_action_push): |
| 29 | """ |
| 30 | Wrapper class for push_vlan action object |
| 31 | |
| 32 | Data members inherited from ofp_action_push: |
| 33 | @arg type |
| 34 | @arg len |
| 35 | @arg ethertype |
| 36 | |
| 37 | """ |
| 38 | def __init__(self): |
| 39 | ofp_action_push.__init__(self) |
| 40 | self.type = OFPAT_PUSH_VLAN |
| 41 | self.len = self.__len__() |
| 42 | def show(self, prefix=''): |
| 43 | outstr = prefix + "action_push_vlan\n" |
| 44 | outstr += ofp_action_push.show(self, prefix) |
| 45 | return outstr |
| 46 | |
| 47 | |
| 48 | class action_experimenter(ofp_action_experimenter_header): |
| 49 | """ |
| 50 | Wrapper class for experimenter action object |
| 51 | |
| 52 | Data members inherited from ofp_action_experimenter_header: |
| 53 | @arg type |
| 54 | @arg len |
| 55 | @arg experimenter |
| 56 | |
| 57 | """ |
| 58 | def __init__(self): |
| 59 | ofp_action_experimenter_header.__init__(self) |
| 60 | self.type = OFPAT_EXPERIMENTER |
| 61 | self.len = self.__len__() |
| 62 | def show(self, prefix=''): |
| 63 | outstr = prefix + "action_experimenter\n" |
| 64 | outstr += ofp_action_experimenter_header.show(self, prefix) |
| 65 | return outstr |
| 66 | |
| 67 | |
| 68 | class action_dec_mpls_ttl(ofp_action_header): |
| 69 | """ |
| 70 | Wrapper class for dec_mpls_ttl action object |
| 71 | |
| 72 | Data members inherited from ofp_action_header: |
| 73 | @arg type |
| 74 | @arg len |
| 75 | |
| 76 | """ |
| 77 | def __init__(self): |
| 78 | ofp_action_header.__init__(self) |
| 79 | self.type = OFPAT_DEC_MPLS_TTL |
| 80 | self.len = self.__len__() |
| 81 | def show(self, prefix=''): |
| 82 | outstr = prefix + "action_dec_mpls_ttl\n" |
| 83 | outstr += ofp_action_header.show(self, prefix) |
| 84 | return outstr |
| 85 | |
| 86 | |
| 87 | class action_set_nw_ttl(ofp_action_nw_ttl): |
| 88 | """ |
| 89 | Wrapper class for set_nw_ttl action object |
| 90 | |
| 91 | Data members inherited from ofp_action_nw_ttl: |
| 92 | @arg type |
| 93 | @arg len |
| 94 | @arg nw_ttl |
| 95 | |
| 96 | """ |
| 97 | def __init__(self): |
| 98 | ofp_action_nw_ttl.__init__(self) |
| 99 | self.type = OFPAT_SET_NW_TTL |
| 100 | self.len = self.__len__() |
| 101 | def show(self, prefix=''): |
| 102 | outstr = prefix + "action_set_nw_ttl\n" |
| 103 | outstr += ofp_action_nw_ttl.show(self, prefix) |
| 104 | return outstr |
| 105 | |
| 106 | |
| 107 | class action_copy_ttl_in(ofp_action_header): |
| 108 | """ |
| 109 | Wrapper class for copy_ttl_in action object |
| 110 | |
| 111 | Data members inherited from ofp_action_header: |
| 112 | @arg type |
| 113 | @arg len |
| 114 | |
| 115 | """ |
| 116 | def __init__(self): |
| 117 | ofp_action_header.__init__(self) |
| 118 | self.type = OFPAT_COPY_TTL_IN |
| 119 | self.len = self.__len__() |
| 120 | def show(self, prefix=''): |
| 121 | outstr = prefix + "action_copy_ttl_in\n" |
| 122 | outstr += ofp_action_header.show(self, prefix) |
| 123 | return outstr |
| 124 | |
| 125 | |
| 126 | class action_group(ofp_action_group): |
| 127 | """ |
| 128 | Wrapper class for group action object |
| 129 | |
| 130 | Data members inherited from ofp_action_group: |
| 131 | @arg type |
| 132 | @arg len |
| 133 | @arg group_id |
| 134 | |
| 135 | """ |
| 136 | def __init__(self): |
| 137 | ofp_action_group.__init__(self) |
| 138 | self.type = OFPAT_GROUP |
| 139 | self.len = self.__len__() |
| 140 | def show(self, prefix=''): |
| 141 | outstr = prefix + "action_group\n" |
| 142 | outstr += ofp_action_group.show(self, prefix) |
| 143 | return outstr |
| 144 | def __len__(self): |
| 145 | return roundup(4 + 4,8) |
| 146 | |
| 147 | |
| 148 | class action_set_queue(ofp_action_set_queue): |
| 149 | """ |
| 150 | Wrapper class for set_queue action object |
| 151 | |
| 152 | Data members inherited from ofp_action_set_queue: |
| 153 | @arg type |
| 154 | @arg len |
| 155 | @arg queue_id |
| 156 | |
| 157 | """ |
| 158 | def __init__(self): |
| 159 | ofp_action_set_queue.__init__(self) |
| 160 | self.type = OFPAT_SET_QUEUE |
| 161 | self.len = self.__len__() |
| 162 | def show(self, prefix=''): |
| 163 | outstr = prefix + "action_set_queue\n" |
| 164 | outstr += ofp_action_set_queue.show(self, prefix) |
| 165 | return outstr |
| 166 | |
| 167 | |
| 168 | class action_push_mpls(ofp_action_push): |
| 169 | """ |
| 170 | Wrapper class for push_mpls action object |
| 171 | |
| 172 | Data members inherited from ofp_action_push: |
| 173 | @arg type |
| 174 | @arg len |
| 175 | @arg ethertype |
| 176 | |
| 177 | """ |
| 178 | def __init__(self): |
| 179 | ofp_action_push.__init__(self) |
| 180 | self.type = OFPAT_PUSH_MPLS |
| 181 | self.len = self.__len__() |
| 182 | def show(self, prefix=''): |
| 183 | outstr = prefix + "action_push_mpls\n" |
| 184 | outstr += ofp_action_push.show(self, prefix) |
| 185 | return outstr |
| 186 | |
| 187 | |
| 188 | class action_copy_ttl_out(ofp_action_header): |
| 189 | """ |
| 190 | Wrapper class for copy_ttl_out action object |
| 191 | |
| 192 | Data members inherited from ofp_action_header: |
| 193 | @arg type |
| 194 | @arg len |
| 195 | |
| 196 | """ |
| 197 | def __init__(self): |
| 198 | ofp_action_header.__init__(self) |
| 199 | self.type = OFPAT_COPY_TTL_OUT |
| 200 | self.len = self.__len__() |
| 201 | def show(self, prefix=''): |
| 202 | outstr = prefix + "action_copy_ttl_out\n" |
| 203 | outstr += ofp_action_header.show(self, prefix) |
| 204 | return outstr |
| 205 | |
| 206 | |
| 207 | class action_set_field(ofp_action_set_field): |
| 208 | """ |
| 209 | Wrapper class for set_field action object |
| 210 | |
| 211 | Data members inherited from ofp_action_set_field: |
| 212 | @arg type |
| 213 | @arg len |
| 214 | @arg field |
| 215 | |
| 216 | """ |
| 217 | def __init__(self): |
| 218 | ofp_action_set_field.__init__(self) |
| 219 | self.type = OFPAT_SET_FIELD |
| 220 | self.len = self.__len__() |
| 221 | self.field = match_list() |
| 222 | |
| 223 | def pack(self): |
| 224 | packed = "" |
| 225 | if len(self.field) <= 4: |
| 226 | packed += ofp_action_set_field.pack() |
| 227 | else: |
| 228 | self.len = len(self) |
| 229 | packed += struct.pack("!HH", self.type, self.len) |
| 230 | packed += self.field.pack() |
| 231 | padding_size = roundup(len(self.field) -4,8) - (len(self.field) -4) |
| 232 | if padding_size: |
| 233 | padding = [0] * padding_size |
| 234 | packed += struct.pack("!" + str(padding_size) + "B", *padding) |
| 235 | return packed |
| 236 | |
| 237 | def unpack(self, binary_string): |
| 238 | if len(binary_string) <= 8: |
| 239 | binary_string = ofp_action_set_field.unpack(self) |
| 240 | else: |
| 241 | (self.type, self.len) = struct.unpack("!HH", binary_string[0:4]) |
| 242 | binary_string = binary_string[4:] |
| 243 | binary_string = self.field.unpack(binary_string, bytes = self.len - 4) |
| 244 | padding_size = roundup(len(self.field) -4,8) - (len(self.field) -4) |
| 245 | if padding_size: |
| 246 | binary_string = binary_string[padding_size:] |
| 247 | return binary_string |
| 248 | |
| 249 | def show(self, prefix=''): |
| 250 | outstr = prefix + "action_set_field\n" |
| 251 | outstr += ofp_action_set_field.show(self, prefix) |
| 252 | return outstr |
| 253 | |
| 254 | def __len__(self): |
| 255 | return roundup(4 + len(self.field),8) |
| 256 | |
| 257 | |
| 258 | class action_set_mpls_ttl(ofp_action_mpls_ttl): |
| 259 | """ |
| 260 | Wrapper class for set_mpls_ttl action object |
| 261 | |
| 262 | Data members inherited from ofp_action_mpls_ttl: |
| 263 | @arg type |
| 264 | @arg len |
| 265 | @arg mpls_ttl |
| 266 | |
| 267 | """ |
| 268 | def __init__(self): |
| 269 | ofp_action_mpls_ttl.__init__(self) |
| 270 | self.type = OFPAT_SET_MPLS_TTL |
| 271 | self.len = self.__len__() |
| 272 | def show(self, prefix=''): |
| 273 | outstr = prefix + "action_set_mpls_ttl\n" |
| 274 | outstr += ofp_action_mpls_ttl.show(self, prefix) |
| 275 | return outstr |
| 276 | |
| 277 | |
| 278 | class action_pop_vlan(ofp_action_header): |
| 279 | """ |
| 280 | Wrapper class for pop_vlan action object |
| 281 | |
| 282 | Data members inherited from ofp_action_header: |
| 283 | @arg type |
| 284 | @arg len |
| 285 | |
| 286 | """ |
| 287 | def __init__(self): |
| 288 | ofp_action_header.__init__(self) |
| 289 | self.type = OFPAT_POP_VLAN |
| 290 | self.len = self.__len__() |
| 291 | def show(self, prefix=''): |
| 292 | outstr = prefix + "action_pop_vlan\n" |
| 293 | outstr += ofp_action_header.show(self, prefix) |
| 294 | return outstr |
| 295 | |
| 296 | |
| 297 | class action_dec_nw_ttl(ofp_action_header): |
| 298 | """ |
| 299 | Wrapper class for dec_nw_ttl action object |
| 300 | |
| 301 | Data members inherited from ofp_action_header: |
| 302 | @arg type |
| 303 | @arg len |
| 304 | |
| 305 | """ |
| 306 | def __init__(self): |
| 307 | ofp_action_header.__init__(self) |
| 308 | self.type = OFPAT_DEC_NW_TTL |
| 309 | self.len = self.__len__() |
| 310 | def show(self, prefix=''): |
| 311 | outstr = prefix + "action_dec_nw_ttl\n" |
| 312 | outstr += ofp_action_header.show(self, prefix) |
| 313 | return outstr |
| 314 | |
| 315 | |
| 316 | class action_output(ofp_action_output): |
| 317 | """ |
| 318 | Wrapper class for output action object |
| 319 | |
| 320 | Data members inherited from ofp_action_output: |
| 321 | @arg type |
| 322 | @arg len |
| 323 | @arg port |
| 324 | @arg max_len |
| 325 | |
| 326 | """ |
| 327 | def __init__(self): |
| 328 | ofp_action_output.__init__(self) |
| 329 | self.type = OFPAT_OUTPUT |
| 330 | self.len = self.__len__() |
| 331 | def show(self, prefix=''): |
| 332 | outstr = prefix + "action_output\n" |
| 333 | outstr += ofp_action_output.show(self, prefix) |
| 334 | return outstr |
| 335 | |
| 336 | action_class_list = ( |
| 337 | action_copy_ttl_in, |
| 338 | action_copy_ttl_out, |
| 339 | action_dec_mpls_ttl, |
| 340 | action_dec_nw_ttl, |
| 341 | action_experimenter, |
| 342 | action_group, |
| 343 | action_output, |
| 344 | action_pop_mpls, |
| 345 | action_pop_vlan, |
| 346 | action_push_mpls, |
| 347 | action_push_vlan, |
| 348 | action_set_field, |
| 349 | action_set_mpls_ttl, |
| 350 | action_set_nw_ttl, |
| 351 | action_set_queue) |
| 352 | |