Rich Lane | 5ec97b8 | 2013-01-06 18:04:25 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import unittest |
| 4 | import message |
| 5 | import action |
| 6 | import instruction |
| 7 | import cstruct as ofp |
| 8 | |
| 9 | class flow_stats_pack(unittest.TestCase): |
| 10 | def runTest(self): |
| 11 | msg = message.flow_stats_entry() |
| 12 | match = ofp.ofp_match() |
| 13 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 14 | act = action.action_output() |
| 15 | act.port = 3 |
| 16 | msg.match = match |
| 17 | pkt = msg.pack() |
| 18 | self.assertEqual(len(pkt), 136) |
| 19 | inst = instruction.instruction_apply_actions() |
| 20 | self.assertTrue(inst.actions.add(act), "Could not add action") |
| 21 | self.assertTrue(msg.instructions.add(inst), "Could not add instructions") |
| 22 | #self.assertTrue(msg.actions.add(act), "Could not add action") |
| 23 | pkt = msg.pack() |
| 24 | # 160 = 136 for flow_stats_entry and 24 for instruction_list |
| 25 | self.assertEqual(len(pkt), 160) |
| 26 | rep = message.flow_stats_reply() |
| 27 | self.assertEqual(len(rep.pack()),12) |
| 28 | rep.stats.append(msg) |
| 29 | self.assertEqual(len(rep.pack()),172) |
| 30 | |
| 31 | |
| 32 | |
| 33 | class match_pack(unittest.TestCase): |
| 34 | def runTest(self): |
| 35 | match = ofp.ofp_match() |
| 36 | self.assertEqual(len(match.pack()), 88) |
| 37 | |
| 38 | |
| 39 | if __name__ == '__main__': |
| 40 | unittest.main() |