def runTest(self): msg = message.flow_stats_entry() match = ofp.ofp_match() match.wildcards &= ~ofp.OFPFW_IN_PORT act = action.action_output() act.port = 3 msg.match = match pkt = msg.pack() self.assertEqual(len(pkt), 136) inst = instruction.instruction_apply_actions() self.assertTrue(inst.actions.add(act), "Could not add action") self.assertTrue(msg.instructions.add(inst), "Could not add instructions") #self.assertTrue(msg.actions.add(act), "Could not add action") pkt = msg.pack() # 160 = 136 for flow_stats_entry and 24 for instruction_list self.assertEqual(len(pkt), 160) rep = message.flow_stats_reply() self.assertEqual(len(rep.pack()),12) rep.stats.append(msg) self.assertEqual(len(rep.pack()),172)
def flow_stats_get(self, flow_stats_request, groups): """ Return an ofp_flow_stats object based on the flow stats request """ replies = [] if flow_stats_request.table_id == 0xff: # do they want all tables? for table in self.tables: replies += table.flow_stats_get(flow_stats_request, groups) else: if flow_stats_request.table_id < len(self.tables): # else specific table replies += self.tables[flow_stats_request.table_id].flow_stats_get(flow_stats_request,groups) else: #@todo find/create an error message library and replace this with it err = message.bad_request_error_msg() err.header.xid = flow_stats_request.header.xid err.data = flow_stats_request err.type = ofp.OFPET_BAD_REQUEST err.code = ofp.OFPBRC_BAD_TABLE_ID return err reply = message.flow_stats_reply() reply.header.xid = flow_stats_request.header.xid reply.stats = replies return reply
def flow_stats_get(self, flow_stats_request, groups): """ Return an ofp_flow_stats object based on the flow stats request """ replies = [] if flow_stats_request.table_id == 0xFF: # do they want all tables? for table in self.tables: replies += table.flow_stats_get(flow_stats_request, groups) else: if flow_stats_request.table_id < len(self.tables): # else specific table replies += self.tables[flow_stats_request.table_id].flow_stats_get(flow_stats_request, groups) else: # @todo find/create an error message library and replace this with it err = message.bad_request_error_msg() err.header.xid = flow_stats_request.header.xid err.data = flow_stats_request err.type = ofp.OFPET_BAD_REQUEST err.code = ofp.OFPBRC_BAD_TABLE_ID return err reply = message.flow_stats_reply() reply.header.xid = flow_stats_request.header.xid reply.stats = replies return reply