def verifyAggFlowStats(self, match, out_port, test_timeout, flow_count, packet_count): stat_req = message.aggregate_stats_request() stat_req.match = match stat_req.table_id = 0xff stat_req.out_port = out_port all_packets_received = 0 for i in range(0,test_timeout): fs_logger.info("Sending stats request") response, pkt = self.controller.transact(stat_req, timeout=test_timeout) self.assertTrue(response is not None, "No response to stats request") self.assertTrue(len(response.stats) == 1, "Did not receive flow stats reply") for obj in response.stats: self.assertTrue(obj.flow_count == flow_count, "Flow count " + str(obj.flow_count) + " does not match expected " + str(flow_count)) fs_logger.info("Received " + str(obj.packet_count) + " packets") if obj.packet_count == packet_count: all_packets_received = 1 if all_packets_received: break sleep(1) self.assertTrue(all_packets_received, "Packet count does not match number sent")
def all_stats_get(parent): """ Get the aggregate stats for all flows in the table @param parent Test instance with controller connection and assert @returns dict with keys flows, packets, bytes, active (flows), lookups, matched """ stat_req = message.aggregate_stats_request() stat_req.match = ofp.ofp_match() stat_req.match.wildcards = ofp.OFPFW_ALL stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_NONE rv = {} (reply, pkt) = parent.controller.transact(stat_req) parent.assertTrue( len(reply.stats) == 1, "Did not receive flow stats reply") for obj in reply.stats: (rv["flows"], rv["packets"], rv["bytes"]) = (obj.flow_count, obj.packet_count, obj.byte_count) break request = message.table_stats_request() (reply, pkt) = parent.controller.transact(request) (rv["active"], rv["lookups"], rv["matched"]) = (0, 0, 0) for obj in reply.stats: rv["active"] += obj.active_count rv["lookups"] += obj.lookup_count rv["matched"] += obj.matched_count return rv
def all_stats_get(parent): """ Get the aggregate stats for all flows in the table @param parent Test instance with controller connection and assert @returns dict with keys flows, packets, bytes, active (flows), lookups, matched """ stat_req = message.aggregate_stats_request() stat_req.match = ofp.ofp_match() stat_req.match.wildcards = ofp.OFPFW_ALL stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_NONE rv = {} (reply, pkt) = parent.controller.transact(stat_req, timeout=2) parent.assertTrue(len(reply.stats) == 1, "Did not receive flow stats reply") for obj in reply.stats: (rv["flows"], rv["packets"], rv["bytes"]) = (obj.flow_count, obj.packet_count, obj.byte_count) break request = message.table_stats_request() (reply , pkt) = parent.controller.transact(request, timeout=2) (rv["active"], rv["lookups"], rv["matched"]) = (0,0,0) for obj in reply.stats: rv["active"] += obj.active_count rv["lookups"] += obj.lookup_count rv["matched"] += obj.matched_count return rv
def verifyAggFlowStats(self, match, out_port, test_timeout, flow_count, packet_count): stat_req = message.aggregate_stats_request() stat_req.match = match stat_req.table_id = 0xff stat_req.out_port = out_port all_packets_received = 0 for i in range(0, test_timeout): fs_logger.info("Sending stats request") response, pkt = self.controller.transact(stat_req, timeout=test_timeout) self.assertTrue(response is not None, "No response to stats request") self.assertTrue( len(response.stats) == 1, "Did not receive flow stats reply") for obj in response.stats: self.assertTrue( obj.flow_count == flow_count, "Flow count " + str(obj.flow_count) + " does not match expected " + str(flow_count)) fs_logger.info("Received " + str(obj.packet_count) + " packets") if obj.packet_count == packet_count: all_packets_received = 1 if all_packets_received: break sleep(1) self.assertTrue(all_packets_received, "Packet count does not match number sent")
def runTest(self): #testutils.clear_switch(self,pa_port_map,pa_logger) testutils.delete_all_flows(self.controller, pa_logger) of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") pkt = testutils.simple_tcp_packet() #match_ls = packet_to_exact_flow_match(pkt = pkt, table_id = 0, in_port = of_ports[0]) match_ls = parse.packet_to_flow_match(pkt) request = message.flow_mod() request.match_fields = match_ls request.flags = 0x18 #set flags OFPFF_NO_PKT_COUNTS and OFPFF_NO_BYT_COUNTS action_list = [] act = action.action_output() act.port = of_ports[1] action_list.append(act) inst = None instruction_list = [] if len(instruction_list) == 0: inst = instruction.instruction_apply_actions() instruction_list.append(inst) for act in action_list: rv = inst.actions.add(act) self.assertTrue(rv, "Could not add action" + act.show()) for i in instruction_list: rv = request.instructions.add(i) self.assertTrue(rv, "Could not add instruction " + i.show()) #testutils.message_send(self, request) rv0 = self.controller.message_send(request) self.assertTrue(rv0 != -1, "Error sending flow mod") testutils.do_barrier(self.controller) #self.send_data(pkt, of_ports[0]) self.dataplane.send(of_ports[0], str(pkt)) aggregate_stats_req = message.aggregate_stats_request() aggregate_stats_req.match_fields = match_ls rv = self.controller.message_send(aggregate_stats_req) self.assertTrue(rv != -1, "Error sending flow stat req") #testutils.message_send(self, aggregate_stats_req) (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2) #print(response.show()) self.assertTrue(response is not None, "No aggregate_stats reply") self.assertEqual(len(response.stats), 1, "Did not receive aggregate stats reply") self.assertEqual(response.stats[0].packet_count, 0) #1) self.assertEqual(response.stats[0].byte_count, 0) #len(packet_in))
def runTest(self): #testutils.clear_switch(self,pa_port_map,pa_logger) testutils.delete_all_flows(self.controller, pa_logger) of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") pkt = testutils.simple_tcp_packet() #match_ls = packet_to_exact_flow_match(pkt = pkt, table_id = 0, in_port = of_ports[0]) match_ls = parse.packet_to_flow_match(pkt) request = message.flow_mod() request.match_fields = match_ls request.flags = 0x18#set flags OFPFF_NO_PKT_COUNTS and OFPFF_NO_BYT_COUNTS action_list = [] act = action.action_output() act.port = of_ports[1] action_list.append(act) inst = None instruction_list = [] if len(instruction_list) == 0: inst = instruction.instruction_apply_actions() instruction_list.append(inst) for act in action_list: rv = inst.actions.add(act) self.assertTrue(rv, "Could not add action" + act.show()) for i in instruction_list: rv = request.instructions.add(i) self.assertTrue(rv, "Could not add instruction " + i.show()) #testutils.message_send(self, request) rv0 = self.controller.message_send(request) self.assertTrue( rv0 != -1, "Error sending flow mod") testutils.do_barrier(self.controller) #self.send_data(pkt, of_ports[0]) self.dataplane.send(of_ports[0],str(pkt)) aggregate_stats_req = message.aggregate_stats_request() aggregate_stats_req.match_fields = match_ls rv = self.controller.message_send(aggregate_stats_req) self.assertTrue( rv != -1, "Error sending flow stat req") #testutils.message_send(self, aggregate_stats_req) (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2) #print(response.show()) self.assertTrue(response is not None, "No aggregate_stats reply") self.assertEqual(len(response.stats), 1, "Did not receive aggregate stats reply") self.assertEqual(response.stats[0].packet_count,0)#1) self.assertEqual(response.stats[0].byte_count,0)#len(packet_in))
def get_aggstats(self, match): # Generate aggregate flow_stats request stats_req = message.aggregate_stats_request() stat_req.match = match stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_NONE logging.info("Sending stats request") (response, pkt) = self.controller.transact(stat_req, timeout=5) self.assertTrue(response is not None, "No response to stats request") return (response, pkt)
def get_aggstats(self,match): # Generate aggregate flow_stats request stats_req = message.aggregate_stats_request() stat_req.match = match stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_NONE logging.info("Sending stats request") (response, pkt) = self.controller.transact(stat_req, timeout=5) self.assertTrue(response is not None,"No response to stats request") return (response,pkt)
def runTest(self): delete_all_flows(self.controller) match = ofp.ofp_match() match.wildcards = 0 stat_req = message.aggregate_stats_request() stat_req.match = match stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_NONE response, pkt = self.controller.transact(stat_req) self.assertTrue(response is not None, "No response to stats request") self.assertTrue(len(response.stats) == 1, "Did not receive flow stats reply") self.assertEquals(response.stats[0].flow_count, 0) self.assertEquals(response.stats[0].packet_count, 0) self.assertEquals(response.stats[0].byte_count, 0)
def runTest(self): rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") match = ofp.ofp_match() match.wildcards = 0 stat_req = message.aggregate_stats_request() stat_req.match = match stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_NONE response, pkt = self.controller.transact(stat_req) self.assertTrue(response is not None, "No response to stats request") self.assertTrue(len(response.stats) == 1, "Did not receive flow stats reply") self.assertEquals(response.stats[0].flow_count, 0) self.assertEquals(response.stats[0].packet_count, 0) self.assertEquals(response.stats[0].byte_count, 0)
def runTest(self): self.clear_switch() group_add_msg1 = \ create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = []) self.send_ctrl_exp_noerror(group_add_msg1, 'group add 1') group_add_msg2 = \ create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 2, buckets = []) self.send_ctrl_exp_noerror(group_add_msg2, 'group add 2') packet_in1 = testutils.simple_tcp_packet(tcp_sport=1000) flow_add_msg1 = \ create_flow_msg(packet = packet_in1, in_port = 1, apply_action_list = [ create_action(action = ofp.OFPAT_GROUP, group_id = 1), create_action(action = ofp.OFPAT_OUTPUT, port = 2) ]) self.send_ctrl_exp_noerror(flow_add_msg1, 'flow add 1') packet_in2 = testutils.simple_tcp_packet(tcp_sport=2000) flow_add_msg2 = \ create_flow_msg(packet = packet_in2, in_port = 1, apply_action_list = [ create_action(action = ofp.OFPAT_GROUP, group_id = 2), create_action(action = ofp.OFPAT_OUTPUT, port = 2) ]) self.send_ctrl_exp_noerror(flow_add_msg2, 'flow add 2') packet_in3 = testutils.simple_tcp_packet(tcp_sport=3000) flow_add_msg3 = \ create_flow_msg(packet = packet_in3, in_port = 1, apply_action_list = [ create_action(action = ofp.OFPAT_GROUP, group_id = 2), create_action(action = ofp.OFPAT_OUTPUT, port = 2) ]) self.send_ctrl_exp_noerror(flow_add_msg3, 'flow add 3') packet_in4 = testutils.simple_tcp_packet(tcp_sport=4000) flow_add_msg4 = \ create_flow_msg(packet = packet_in4, in_port = 1, apply_action_list = [ create_action(action = ofp.OFPAT_OUTPUT, port = 2) ]) self.send_ctrl_exp_noerror(flow_add_msg4, 'flow add 4') aggr_stat_req = message.aggregate_stats_request() aggr_stat_req.match.wildcards = ofp.OFPFW_ALL aggr_stat_req.match.dl_src_mask= [255,255,255,255,255,255] aggr_stat_req.match.dl_dst_mask= [255,255,255,255,255,255] aggr_stat_req.match.nw_src_mask = 0xffffffff aggr_stat_req.match.nw_dst_mask = 0xffffffff aggr_stat_req.table_id = 0xff aggr_stat_req.out_port = ofp.OFPP_ANY aggr_stat_req.out_group = ofp.OFPG_ANY response = \ self.send_ctrl_exp_reply(aggr_stat_req, ofp.OFPT_STATS_REPLY, 'group desc stat') self.assertEqual(response.stats[0].flow_count, 4, 'Did not match expected flow count')
def runTest(self): self.clear_switch() group_add_msg1 = \ create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = []) self.send_ctrl_exp_noerror(group_add_msg1, 'group add 1') group_add_msg2 = \ create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 2, buckets = []) self.send_ctrl_exp_noerror(group_add_msg2, 'group add 2') packet_in1 = testutils.simple_tcp_packet(tcp_sport=1000) flow_add_msg1 = \ testutils.flow_msg_create(self,packet_in1,ing_port = 1,action_list = [ create_action(action = ofp.OFPAT_GROUP, group_id = 1), create_action(action = ofp.OFPAT_OUTPUT, port = 2) ]) self.send_ctrl_exp_noerror(flow_add_msg1, 'flow add 1') packet_in2 = testutils.simple_tcp_packet(tcp_sport=2000) flow_add_msg2 = \ testutils.flow_msg_create(self,packet_in2,ing_port = 1,action_list = [ create_action(action = ofp.OFPAT_GROUP, group_id = 2), create_action(action = ofp.OFPAT_OUTPUT, port = 2) ]) self.send_ctrl_exp_noerror(flow_add_msg2, 'flow add 2') packet_in3 = testutils.simple_tcp_packet(tcp_sport=3000) flow_add_msg3 = \ testutils.flow_msg_create(self,packet_in3,ing_port = 1,action_list = [ create_action(action = ofp.OFPAT_GROUP, group_id = 2), create_action(action = ofp.OFPAT_OUTPUT, port = 2) ]) self.send_ctrl_exp_noerror(flow_add_msg3, 'flow add 3') packet_in4 = testutils.simple_tcp_packet(tcp_sport=4000) flow_add_msg4 = \ testutils.flow_msg_create(self,packet_in4,ing_port = 1,action_list = [ create_action(action = ofp.OFPAT_OUTPUT, port = 2) ]) self.send_ctrl_exp_noerror(flow_add_msg4, 'flow add 4') aggr_stat_req = message.aggregate_stats_request() aggr_stat_req.table_id = 0xff aggr_stat_req.out_port = ofp.OFPP_ANY aggr_stat_req.out_group = ofp.OFPG_ANY response = \ self.send_ctrl_exp_reply(aggr_stat_req, ofp.OFPT_STATS_REPLY, 'group desc stat') self.assertEqual(response.stats[0].flow_count, 4, 'Did not match expected flow count')