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 runTest(self): basic_logger.info("Running TableStats") testutils.delete_all_flows(self.controller, self.logger) basic_logger.info("Sending table stats request") request = message.table_stats_request() response, _ = self.controller.transact(request, timeout=2) # delete everything, so there should be no entries self.assertEqual(self.get_first_table_active_entries(response), 0) # add two entries to first table m1 = testutils.match_all_generate() m1.dl_type = 0x800 m1.wildcards ^= ofp.OFPFW_DL_TYPE fm1 = testutils.flow_msg_create(self, None, match=m1, egr_port=2) rv = self.controller.message_send(fm1) self.assertEqual(rv, 0) m2 = testutils.match_all_generate() m2.dl_type = 0x806 m2.wildcards ^= ofp.OFPFW_DL_TYPE fm2 = testutils.flow_msg_create(self, None, match=m2, egr_port=2) rv = self.controller.message_send(fm2) self.assertEqual(rv, 0) testutils.do_barrier(self.controller) response, _ = self.controller.transact(request, timeout=2) self.assertEqual(self.get_first_table_active_entries(response), 2)
def runTest(self): basic_logger.info("Running TableStatsGet") basic_logger.info("Sending table stats request") request = message.table_stats_request() response, _ = self.controller.transact(request, timeout=2) self.assertTrue(response is not None, "Did not get response") basic_logger.debug(response.show())
def runTest(self): msg, pkt = self.controller.transact(message.table_stats_request()) num_flows = msg.stats[0].max_entries requests = [] for i in range(num_flows): match = ofp.ofp_match() match.wildcards = ofp.OFPFW_ALL & ~ofp.OFPFW_DL_VLAN & ~ofp.OFPFW_DL_DST match.dl_vlan = ofp.OFP_VLAN_NONE match.dl_dst = [0, 1, 2, 3, i / 256, i % 256] act = action.action_output() act.port = ofp.OFPP_CONTROLLER request = message.flow_mod() request.command = ofp.OFPFC_ADD request.buffer_id = 0xffffffff request.priority = num_flows - i request.out_port = ofp.OFPP_NONE request.match = match request.actions.add(act) requests.append(request) for i in range(5): logging.info("Iteration %d: delete all flows" % i) self.assertEqual(delete_all_flows(self.controller), 0, "Failed to delete all flows") self.checkBarrier() logging.info("Iteration %d: add %s flows" % (i, num_flows)) for request in requests: self.assertNotEqual(self.controller.message_send(request), -1, "Error installing flow mod") self.checkBarrier()
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 runTest(self): basic_logger.info("Running TableStatsGet") basic_logger.info("Sending table stats request") request = message.table_stats_request() response, _ = self.controller.transact(request, timeout=2) self.assertTrue(response is not None, "Did not get response") self.assertEqual(response.header.type, ofp.OFPT_MULTIPART_REPLY, 'response is not OFPT_MULTIPART_REPLY') self.assertEqual(response.type, ofp.OFPMP_TABLE, 'response is not OFPMP_TABLE') basic_logger.debug(response.show())
def runTest(self): basic_logger.info("Running TableStatsGet") basic_logger.info("Inserting trial flow") request = flow_mod_gen(basic_port_map, True) rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to insert test flow") basic_logger.info("Sending table stats request") request = message.table_stats_request() response, pkt = self.controller.transact(request) self.assertTrue(response is not None, "Did not get response") basic_logger.debug(response.show())
def runTest(self): logging.info("Running TableStatsGet") logging.info("Inserting trial flow") request = flow_mod_gen(config["port_map"], True) rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to insert test flow") logging.info("Sending table stats request") request = message.table_stats_request() response, pkt = self.controller.transact(request) self.assertTrue(response is not None, "Did not get reply for table stats") logging.debug(response.show())
def Verify_TableStats(self,active_entries=0): #Verify Table_Stats #Send Table_Stats_Request request = message.table_stats_request() response, pkt = self.controller.transact(request, timeout=1) self.assertTrue(response is not None, "Did not get response") active_count=0 #Verify active_count in the reply for stat in response.stats: active_count += stat.active_count self.assertTrue(active_entries == active_count,"Incorrect no. of flows in Table")
def Verify_TableStats(self,active_entries=0,): #Verify Table_Stats #Send Table_Stats_Request request = message.table_stats_request() response, pkt = self.controller.transact(request, timeout=1) self.assertTrue(response is not None, "Did not get response") active_count=0 #Verify active_count in the reply for stat in response.stats: active_count += stat.active_count self.assertTrue(active_entries == active_count,"Incorrect no. of flows in Table")
def supported_actions_get(parent, use_cache=True): """ Get the bitmap of supported actions from the switch If use_cache is false, the cached value will be updated """ global cached_supported_actions if cached_supported_actions is None or not use_cache: request = message.table_stats_request() (reply, _) = parent.controller.transact(request, timeout=2) parent.assertTrue(reply is not None, "Did not get response to tbl stats req") cached_supported_actions = reply.stats[0].apply_actions pa_logger.info("Supported actions: " + hex(cached_supported_actions)) return cached_supported_actions
def runTest(self): basic_logger.info("Running TableStatsGet") basic_logger.info("Inserting trial flow") request = message.flow_mod() request.match.wildcards = ofp.OFPFW_ALL request.buffer_id = 0xffffffff rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to insert test flow") basic_logger.info("Sending table stats request") request = message.table_stats_request() response, pkt = self.controller.transact(request, timeout=2) self.assertTrue(response is not None, "Did not get response") basic_logger.debug(response.show())
def supported_actions_get(parent, use_cache=True): """ Get the bitmap of supported actions from the switch If use_cache is false, the cached value will be updated """ global cached_supported_actions if cached_supported_actions is None or not use_cache: request = message.table_stats_request() (reply, _) = parent.controller.transact(request, timeout=2) parent.assertTrue(reply is not None, "Did not get response to tbl stats req") # cached_supported_actions = reply.stats[0].apply_actions cached_supported_actions = reply.stats[0].write_actions pa_logger.info("Supported actions: " + hex(cached_supported_actions)) return cached_supported_actions
def get_tablestats(self): # Send Table_Stats request (retrieve current table counters ) stat_req = message.table_stats_request() response, pkt = self.controller.transact(stat_req, timeout=5) self.assertTrue(response is not None, "No response to stats request") current_lookedup = 0 current_matched = 0 current_active = 0 for obj in response.stats: current_lookedup += obj.lookup_count current_matched += obj.matched_count current_active += obj.active_count return (current_lookedup, current_matched, current_active)
def verify_tablestats(self, expect_lookup=None, expect_match=None, expect_active=None): stat_req = message.table_stats_request() for i in range(0, 60): logging.info("Sending stats request") # TODO: move REPLY_MORE handling to controller.transact? response, pkt = self.controller.transact(stat_req, timeout=5) self.assertTrue(response is not None, "No response to stats request") lookedup = 0 matched = 0 active = 0 sleep(1) for item in response.stats: lookedup += item.lookup_count matched += item.matched_count active += item.active_count logging.info("Packets Looked up " + str(lookedup) + " packets") logging.info("Packets matched " + str(matched) + "packets") logging.info("Active flow entries" + str(active) + "flows") if expect_lookup != None and expect_lookup != lookedup: continue if expect_match != None and expect_match != matched: continue if expect_active != None and expect_active != active: continue break if expect_lookup != None: self.assertEqual(expect_lookup, item.lookup_count, "lookup counter is not incremented properly") if expect_match != None: self.assertEqual(expect_match, item.matched_count, "matched counter is not incremented properly") if expect_active != None: self.assertEqual(expect_active, item.active_count, "active counter is not incremented properly")
def verify_tablestats(self,expect_lookup=None,expect_match=None,expect_active=None): stat_req = message.table_stats_request() for i in range(0,60): logging.info("Sending stats request") # TODO: move REPLY_MORE handling to controller.transact? response, pkt = self.controller.transact(stat_req, timeout=5) self.assertTrue(response is not None,"No response to stats request") lookedup = 0 matched = 0 active = 0 sleep(1) for item in response.stats: lookedup += item.lookup_count matched += item.matched_count active += item.active_count logging.info("Packets Looked up " + str(lookedup) + " packets") logging.info("Packets matched " + str(matched) + "packets") logging.info("Active flow entries" + str(active) + "flows") if expect_lookup != None and expect_lookup != lookedup:continue if expect_match != None and expect_match != matched:continue if expect_active != None and expect_active != active:continue break if expect_lookup != None : self.assertEqual(expect_lookup,item.lookup_count,"lookup counter is not incremented properly") if expect_match != None : self.assertEqual(expect_match,item.matched_count, "matched counter is not incremented properly") if expect_active != None : self.assertEqual(expect_active,item.active_count,"active counter is not incremented properly")
def verify_tablestats(self,expect_lookup=None,expect_match=None,expect_active=None): stat_req = message.table_stats_request() for i in range(0,100): logging.info("Sending stats request") # TODO: move REPLY_MORE handling to controller.transact? response, pkt = self.controller.transact(stat_req, timeout=5) self.assertTrue(response is not None,"No response to stats request") lookedup = 0 matched = 0 active = 0 for item in response.stats: lookedup += item.lookup_count matched += item.matched_count active += item.active_count logging.info("Packets Looked up: %d", lookedup) logging.info("Packets matched: %d", matched) logging.info("Active flow entries: %d", active) if (expect_lookup == None or lookedup >= expect_lookup) and \ (expect_match == None or matched >= expect_match) and \ (expect_active == None or active >= expect_active): break sleep(0.1) if expect_lookup != None : self.assertEqual(expect_lookup, lookedup, "lookup counter is not incremented properly") if expect_match != None : self.assertEqual(expect_match, matched, "matched counter is not incremented properly") if expect_active != None : self.assertEqual(expect_active, active ,"active counter is not incremented properly")
def runTest(self): msg, pkt = self.controller.transact(message.table_stats_request()) # Some switches report an extremely high max_entries that would cause # us to run out of memory attempting to create all the flow-mods. num_flows = min(msg.stats[0].max_entries, 32678) logging.info("Creating %d flow-mods messages", num_flows) requests = [] for i in range(num_flows): match = ofp.ofp_match() match.wildcards = ofp.OFPFW_ALL & ~ofp.OFPFW_DL_VLAN & ~ofp.OFPFW_DL_DST match.dl_vlan = ofp.OFP_VLAN_NONE match.dl_dst = [0, 1, 2, 3, i / 256, i % 256] act = action.action_output() act.port = ofp.OFPP_CONTROLLER request = message.flow_mod() request.command = ofp.OFPFC_ADD request.buffer_id = 0xffffffff request.priority = num_flows - i request.out_port = ofp.OFPP_NONE request.match = match request.actions.add(act) requests.append(request) for i in range(3): logging.info("Iteration %d: delete all flows" % i) delete_all_flows(self.controller) self.checkBarrier() logging.info("Iteration %d: add %s flows" % (i, num_flows)) random.shuffle(requests) for request in requests: self.assertNotEqual(self.controller.message_send(request), -1, "Error installing flow mod") self.checkBarrier()
def flow_caps_common(obj, is_exact=True): """ The common function for @param obj The calling object @param is_exact If True, checking exact match; else wildcard """ global caps_port_map of_ports = caps_port_map.keys() of_ports.sort() rv = delete_all_flows(obj.controller, caps_logger) obj.assertEqual(rv, 0, "Failed to delete all flows") pkt = simple_tcp_packet() match = parse.packet_to_flow_match(pkt) obj.assertTrue(match is not None, "Could not generate flow match from pkt") for port in of_ports: break; match.in_port = port match.nw_src = 1 request = message.flow_mod() count_check = 101 # fixme: better way to determine this. if is_exact: match.wildcards = 0 else: match.wildcards |= ofp.OFPFW_DL_SRC request.match = match request.buffer_id = 0xffffffff # set to NONE caps_logger.info(request.show()) tstats = message.table_stats_request() try: # Determine the table index to check (or "all") table_idx = caps_config["caps_table_idx"] except: table_idx = -1 # Accumulate all table counts # Make sure we can install at least one flow caps_logger.info("Inserting initial flow") rv = obj.controller.message_send(request) obj.assertTrue(rv != -1, "Error installing flow mod") obj.assertEqual(do_barrier(obj.controller), 0, "Barrier failed") flow_count = 1 caps_logger.info("Table idx: " + str(table_idx)) caps_logger.info("Check every " + str(count_check) + " inserts") while True: request.match.nw_src += 1 rv = obj.controller.message_send(request) flow_count += 1 if flow_count % count_check == 0: obj.assertEqual(do_barrier(obj.controller), 0, "Barrier failed") response, pkt = obj.controller.transact(tstats) obj.assertTrue(response is not None, "Get tab stats failed") caps_logger.info(response.show()) if table_idx == -1: # Accumulate for all tables active_flows = 0 for stats in response.stats: active_flows += stats.active_count else: # Table index to use specified in config active_flows = response.stats[table_idx].active_count if active_flows != flow_count: break caps_logger.error("RESULT: " + str(flow_count) + " flows inserted") caps_logger.error("RESULT: " + str(active_flows) + " flows reported")
def flow_caps_common(obj, is_exact=True): """ The common function for @param obj The calling object @param is_exact If True, checking exact match; else wildcard """ global caps_port_map of_ports = caps_port_map.keys() of_ports.sort() rv = delete_all_flows(obj.controller, caps_logger) obj.assertEqual(rv, 0, "Failed to delete all flows") pkt = simple_tcp_packet() match = packet_to_flow_match(obj, pkt) obj.assertTrue(match is not None, "Could not generate flow match from pkt") for port in of_ports: break match.in_port = port match.nw_src = 1 request = message.flow_mod() count_check = 101 # fixme: better way to determine this. if is_exact: match.wildcards = 0 else: match.wildcards |= ofp.OFPFW_DL_SRC request.match = match request.buffer_id = 0xffffffff # set to NONE caps_logger.info(request.show()) tstats = message.table_stats_request() try: # Determine the table index to check (or "all") table_idx = caps_config["caps_table_idx"] except: table_idx = -1 # Accumulate all table counts # Make sure we can install at least one flow caps_logger.info("Inserting initial flow") rv = obj.controller.message_send(request) obj.assertTrue(rv != -1, "Error installing flow mod") obj.assertEqual(do_barrier(obj.controller), 0, "Barrier failed") flow_count = 1 caps_logger.info("Table idx: " + str(table_idx)) caps_logger.info("Check every " + str(count_check) + " inserts") while True: request.match.nw_src += 1 rv = obj.controller.message_send(request) flow_count += 1 if flow_count % count_check == 0: obj.assertEqual(do_barrier(obj.controller), 0, "Barrier failed") response, pkt = obj.controller.transact(tstats) obj.assertTrue(response is not None, "Get tab stats failed") caps_logger.info(response.show()) if table_idx == -1: # Accumulate for all tables active_flows = 0 for stats in response.stats: active_flows += stats.active_count else: # Table index to use specified in config active_flows = response.stats[table_idx].active_count if active_flows != flow_count: break caps_logger.error("RESULT: " + str(flow_count) + " flows inserted") caps_logger.error("RESULT: " + str(active_flows) + " flows reported")
def runTest(self): request = message.table_stats_request() response, _ = self.controller.transact(request, timeout=2) #print(response.show()) self.logger.info(response.show())
def flow_caps_common(obj, is_exact=True): """ The common function for @param obj The calling object @param is_exact If True, checking exact match; else wildcard """ obj.logger = caps_logger obj.config = caps_config global caps_port_map of_ports = caps_port_map.keys() of_ports.sort() #rv = delete_all_flows(obj.controller, caps_logger) #obj.assertEqual(rv, 0, "Failed to delete all flows") pkt = simple_tcp_packet(ip_src='0.0.0.0', vlan_tags=[{'type': ETHERTYPE_VLAN, 'vid': 2, 'pcp': 7}]) pkt_metadata = {'metadata_val':0x0000000000000000, 'metadata_msk':None} for ing_port in of_ports: break if is_exact: table_list = [EX_VLAN_TABLE]#, EX_L2_TABLE, EX_VLAN_TABLE, EX_MPLS_TABLE, EX_L3_TABLE, EX_ICMP_TABLE] max_entry = MAX_ENTRY_EX_TABLE else: table_list = [WC_ACL_TABLE]#, WC_SERV_TABLE, WC_L3_TABLE, WC_ALL_TABLE] max_entry = MAX_ENTRY_WC_TABLE for table_idx in table_list: #tfeature = message.table_feature_request() #response,_ = obj.controller.transact(tfeature, timeout=1) #obj.assertTrue(response is not None, "Get tab feature failed") #print response.show() #for feature in table_features: # if feature.table_id = table_idx: # max_entries = feature.max_entries # break #max_entry = response.table_features[table_idx].max_entries #print str(max_entry) request = flow_msg_create(obj,pkt,pkt_metadata,ing_port,egr_port=ofp.OFPP_IN_PORT,table_id=table_idx) #print(request.show()) count_check = max_entry/10 + 1 #print(str(count_check)) tstats = message.table_stats_request() #response, pkt = obj.controller.transact(tstats, timeout=2) #print(response.show()) #Make sure we can install at least one flow flow_msg_install(obj, request, True) flow_count = 1 caps_logger.info("Table idx: " + str(table_idx)) caps_logger.info("Check every " + str(count_check) + " inserts") while True: for member in request.match_fields.tlvs: if member.field == ofp.OFPXMT_OFB_IPV4_SRC: if member.value < 1<<32: member.value += 1 if member.field == ofp.OFPXMT_OFB_VLAN_VID: if member.value < 0x1000: member.value += 1 if member.field == ofp.OFPXMT_OFB_MPLS_LABEL: if member.value < 0x100000: member.value += 1 if member.field == ofp.OFPXMT_OFB_METADATA: member.value += 1 flow_msg_install(obj, request, False) flow_count += 1 #print(flow_count) if flow_count % count_check == 0: response, pkt = obj.controller.transact(tstats, timeout=2) obj.assertTrue(response is not None, "Get tab stats failed") #caps_logger.info(response.show()) #print(response.stats[table_idx].show()) if table_idx == -1: # Accumulate for all tables active_flows = 0 for stats in response.stats: active_flows += stats.active_count else: # Table index to use specified in config active_flows = response.stats[table_idx].active_count if active_flows != flow_count: break #if active_flows != max_entry: if active_flows < max_entry: caps_logger.error("RESULT: " + str(max_entry) + " support") caps_logger.error("RESULT: " + str(active_flows) + " flows reported") error_verify(obj, ofp.OFPET_FLOW_MOD_FAILED, ofp.OFPFMFC_TABLE_FULL) #obj.assertTrue(active_flows == max_entry, "active_flows is not full filled") obj.assertTrue(active_flows >= max_entry, "active_flows is not fullfill max entry requirement")