Rich Lane | 5ec97b8 | 2013-01-06 18:04:25 -0800 | [diff] [blame^] | 1 | |
| 2 | from base_list import ofp_base_list |
| 3 | from bucket import bucket |
| 4 | |
| 5 | class bucket_list(ofp_base_list): |
| 6 | """ |
| 7 | Maintain a list of instructions |
| 8 | |
| 9 | Data members: |
| 10 | @arg instructions An array of instructions such as write_actions |
| 11 | |
| 12 | Methods: |
| 13 | @arg pack: Pack the structure into a string |
| 14 | @arg unpack: Unpack a string to objects, with proper typing |
| 15 | @arg add: Add an action to the list; you can directly access |
| 16 | the action member, but add will validate that the added object |
| 17 | is an action. |
| 18 | |
| 19 | """ |
| 20 | |
| 21 | def __init__(self): |
| 22 | ofp_base_list.__init__(self) |
| 23 | self.buckets = self.items |
| 24 | self.name = "buckets" |
| 25 | self.class_list = (bucket,) |
| 26 | |
| 27 | def unpack(self, binary_string, bytes=None): |
| 28 | """ |
| 29 | Unpack a list of buckets |
| 30 | |
| 31 | Unpack buckets from a binary string, creating an array |
| 32 | of objects of the appropriate type |
| 33 | |
| 34 | @param binary_string The string to be unpacked |
| 35 | |
| 36 | @param bytes The total length of the instruction list in bytes. |
| 37 | Ignored if decode is True. If bytes is None and decode is false, the |
| 38 | list is assumed to extend through the entire string. |
| 39 | |
| 40 | @return The remainder of binary_string that was not parsed |
| 41 | |
| 42 | """ |
| 43 | if bytes == None: |
| 44 | bytes = len(binary_string) |
| 45 | bytes_done = 0 |
| 46 | cur_string = binary_string |
| 47 | while bytes_done < bytes: |
| 48 | b = bucket() |
| 49 | cur_string = b.unpack(cur_string) |
| 50 | self.buckets.append(b) |
| 51 | bytes_done += len(b) |
| 52 | return cur_string |