def unpack(self, buff): """Unpack according to :attr:`body_type`.""" super().unpack(buff) if self.body_type == StatsTypes.OFPST_PORT: buff = self.body.value self.body = PortStatsRequest() self.body.unpack(buff) elif self.body_type == StatsTypes.OFPST_FLOW: buff = self.body.value self.body = FlowStatsRequest() self.body.unpack(buff) elif self.body_type == StatsTypes.OFPST_AGGREGATE: buff = self.body.value self.body = AggregateStatsRequest() self.body.unpack(buff)
class TestFlowStatsRequest(unittest.TestCase): """Test class for TestFlowStatsRequest.""" def setUp(self): """Test basic setup.""" self.message = FlowStatsRequest() self.message.match = flow_match.Match() self.message.table_id = 1 self.message.out_port = 80 self.message.match.in_port = 80 self.message.match.dl_src = [1, 2, 3, 4, 5, 6] self.message.match.dl_dst = [1, 2, 3, 4, 5, 6] self.message.match.dl_vlan = 1 self.message.match.dl_vlan_pcp = 1 self.message.match.dl_type = 1 self.message.match.nw_tos = 1 self.message.match.nw_proto = 1 self.message.match.nw_src = [192, 168, 0, 1] self.message.match.nw_dst = [192, 168, 0, 1] self.message.match.tp_src = 80 self.message.match.tp_dst = 80 def test_get_size(self): """[Controller2Switch/FlowStatsRequest] - size 44.""" self.assertEqual(self.message.get_size(), 44) @unittest.skip('Not yet implemented') def test_pack(self): """[Controller2Switch/FlowStatsRequest] - packing.""" # TODO pass @unittest.skip('Not yet implemented') def test_unpack(self): """[Controller2Switch/FlowStatsRequest] - unpacking.""" # TODO pass
def request(self, conn): """Ask for flow stats.""" body = FlowStatsRequest() # Port.OFPP_NONE and All Tables req = StatsRequest(body_type=StatsTypes.OFPST_FLOW, body=body) self._send_event(req, conn) log.debug('Flow Stats request for switch %s sent.', conn.switch.dpid)
def _get_flow_stats_request(): return FlowStatsRequest(match=_get_match(), table_id=1, out_port=80)