def fill_gap(self, rand, packets, gap_size, last_packet_end, ifg): min_ifg = 96 * self.bit_time if debug_fill: print "fill_gap {}, {} / {} / {}".format(last_packet_end, ifg, gap_size, self.min_packet_time) while gap_size > self.min_packet_time: if (rand.randint(0, self.total_weight_tag) < self.weight_tagged): tag = [ 0x81, 0x00, rand.randint(0, 0xff), rand.randint(0, 0xff) ] else: tag = None mac_choice = rand.randint(0, self.total_weight_tc - 1) if (mac_choice < self.weight_none): dst_mac_addr = self.none_mac_address elif (mac_choice < self.weight_none + self.weight_lp): dst_mac_addr = self.lp_mac_address else: dst_mac_addr = self.other_mac_address frame_size = choose_data_size(rand, self.data_len_min, self.data_len_max) if (rand.randint(0, 100) > 30): burst_len = rand.randint(1, 20) else: burst_len = 1 for j in range(burst_len): # The seq_ids are effectively packet counts if (gap_size < self.min_packet_time): break if dst_mac_addr == self.none_mac_address: packet_type = self.TYPE_NONE seq_id = 0 elif dst_mac_addr == self.lp_mac_address: packet_type = self.TYPE_LP seq_id = self.lp_seq_id self.lp_seq_id += 1 self.lp_data_bytes += frame_size + 14 if tag: self.lp_data_bytes += 4 else: packet_type = self.TYPE_OTHER seq_id = self.other_seq_id self.other_seq_id += 1 self.other_data_bytes += frame_size + 14 if tag: self.other_data_bytes += 4 packet = MiiPacket( rand, dst_mac_addr=dst_mac_addr, create_data_args=['same', (seq_id, frame_size)], vlan_prio_tag=tag, inter_frame_gap=ifg) packet_time = packet.get_packet_time(self.bit_time) if debug_fill: print "FILLER {} -> {} ({})".format( last_packet_end, last_packet_end + packet_time, frame_size) gap_size -= packet_time last_packet_end += packet_time if packet_type == self.TYPE_NONE: # Simply skip this packet ifg += packet_time else: packets.append(packet) ifg = rand.randint(min_ifg, 2 * min_ifg) if debug_fill: print "filled {} {} {} {}".format(packet.inter_frame_gap, packet_time, gap_size, packet_type) return (last_packet_end, ifg)
def fill_gap(self, rand, packets, gap_size, last_packet_end, ifg): min_ifg = 96 * self.bit_time if debug_fill: print "fill_gap {}, {} / {} / {}".format(last_packet_end, ifg, gap_size, self.min_packet_time) while gap_size > self.min_packet_time: if (rand.randint(0, self.total_weight_tag) < self.weight_tagged): tag = [0x81, 0x00, rand.randint(0,0xff), rand.randint(0, 0xff)] else: tag = None mac_choice = rand.randint(0, self.total_weight_tc - 1) if (mac_choice < self.weight_none): dst_mac_addr = self.none_mac_address elif (mac_choice < self.weight_none + self.weight_lp): dst_mac_addr = self.lp_mac_address else: dst_mac_addr = self.other_mac_address frame_size = choose_data_size(rand, self.data_len_min, self.data_len_max) if (rand.randint(0,100) > 30): burst_len = rand.randint(1,20) else: burst_len = 1 for j in range(burst_len): # The seq_ids are effectively packet counts if (gap_size < self.min_packet_time): break if dst_mac_addr == self.none_mac_address: packet_type = self.TYPE_NONE seq_id = 0 elif dst_mac_addr == self.lp_mac_address: packet_type = self.TYPE_LP seq_id = self.lp_seq_id self.lp_seq_id += 1 self.lp_data_bytes += frame_size + 14 if tag: self.lp_data_bytes += 4 else: packet_type = self.TYPE_OTHER seq_id = self.other_seq_id self.other_seq_id += 1 self.other_data_bytes += frame_size + 14 if tag: self.other_data_bytes += 4 packet = MiiPacket(rand, dst_mac_addr=dst_mac_addr, create_data_args=['same', (seq_id, frame_size)], vlan_prio_tag=tag, inter_frame_gap=ifg) packet_time = packet.get_packet_time(self.bit_time) if debug_fill: print "FILLER {} -> {} ({})".format(last_packet_end, last_packet_end + packet_time, frame_size) gap_size -= packet_time last_packet_end += packet_time if packet_type == self.TYPE_NONE: # Simply skip this packet ifg += packet_time else: packets.append(packet) ifg = rand.randint(min_ifg, 2 * min_ifg) if debug_fill: print "filled {} {} {} {}".format(packet.inter_frame_gap, packet_time, gap_size, packet_type) return (last_packet_end, ifg)
def do_test(mac, tx_clk, tx_phy, seed, num_windows=10, num_avb_streams=12, num_avb_data_bytes=400, weight_none=50, weight_lp=50, weight_other=50, data_len_min=46, data_len_max=500, weight_tagged=50, weight_untagged=50): rand = random.Random() rand.seed(seed) bit_time = tx_phy.get_clock().get_bit_time() rxLpControl = RxLpControl('tile[0]:XS1_PORT_1D', bit_time, 0, True, rand.randint(0, sys.maxint)) resources = xmostest.request_resource("xsim") testname = 'test_avb_traffic' level = 'nightly' binary = '{test}/bin/{mac}_{phy}/{test}_{mac}_{phy}.xe'.format( test=testname, mac=mac, phy=tx_phy.get_name()) if xmostest.testlevel_is_at_least(xmostest.get_testlevel(), level): print "Running {test}: {phy} phy at {clk} (seed {seed})".format( test=testname, phy=tx_phy.get_name(), clk=tx_clk.get_name(), seed=seed) stream_mac_addresses = {} stream_seq_id = {} stream_ids = [x for x in range(num_avb_streams)] for i in stream_ids: stream_mac_addresses[i] = [i, 1, 2, 3, 4, 5] stream_seq_id[i] = 0 packets = [] filler = PacketFiller(weight_none, weight_lp, weight_other, weight_tagged, weight_untagged, data_len_min, data_len_max, bit_time) window_size = 125000 min_ifg = 96 * bit_time last_packet_end = 0 ifg = 0 for window in range(num_windows): # Randomly place the streams in the 125us window packet_start_times = sorted( [rand.randint(0, window_size) for x in range(num_avb_streams)]) if debug_fill: print "Window {} - times {}".format(window, packet_start_times) rand.shuffle(stream_ids) for (i, stream) in enumerate(stream_ids): packet_start_time = packet_start_times[i] gap_size = packet_start_time - last_packet_end (last_packet_end, ifg) = filler.fill_gap(rand, packets, gap_size, last_packet_end, ifg) start_ifg = min_ifg avb_packet = MiiPacket(rand, dst_mac_addr=stream_mac_addresses[stream], create_data_args=[ 'same', (stream_seq_id[stream], num_avb_data_bytes) ], vlan_prio_tag=[0x81, 0x00, 0x00, 0x00], inter_frame_gap=ifg) stream_seq_id[stream] += 1 packets.append(avb_packet) ifg = rand.randint(min_ifg, 2 * min_ifg) packet_time = avb_packet.get_packet_time(bit_time) if debug_fill: print "PACKET {} -> {}".format(last_packet_end, last_packet_end + packet_time) last_packet_end += packet_time # Fill the window after the last packet gap_size = window_size - last_packet_end (last_packet_end, ifg) = filler.fill_gap(rand, packets, gap_size, last_packet_end, ifg) # Compute where in the next window the last packet has finished last_packet_end = last_packet_end - window_size tx_phy.set_packets(packets) if xmostest.testlevel_is_at_least(xmostest.get_testlevel(), level): print "Running {w} windows of {s} AVB streams with {b} data bytes each".format( w=num_windows, s=num_avb_streams, b=num_avb_data_bytes) print "Sending {n} lp packets with {b} bytes hp data".format( n=filler.lp_seq_id, b=filler.lp_data_bytes) print "Sending {n} other packets with {b} bytes hp data".format( n=filler.other_seq_id, b=filler.other_data_bytes) expect_folder = create_if_needed("expect") expect_filename = '{folder}/{test}_{mac}_{phy}.expect'.format( folder=expect_folder, test=testname, mac=mac, phy=tx_phy.get_name()) create_expect(packets, expect_filename, num_windows, num_avb_streams, num_avb_data_bytes) tester = xmostest.ComparisonTester(open(expect_filename), 'lib_ethernet', 'basic_tests', testname, { 'mac': mac, 'phy': tx_phy.get_name(), 'clk': tx_clk.get_name(), 'n_stream': num_avb_streams, 'b_p_stream': num_avb_data_bytes, 'len_min': data_len_min, 'len_max': data_len_max, 'w_none': weight_none, 'w_lp': weight_lp, 'w_other': weight_other, 'n_windows': num_windows }, regexp=True) tester.set_min_testlevel(level) simargs = get_sim_args(testname, mac, tx_clk, tx_phy) xmostest.run_on_simulator(resources['xsim'], binary, simthreads=[tx_clk, tx_phy, rxLpControl], tester=tester, simargs=simargs)
def do_test(mac, tx_clk, tx_phy, seed, num_windows=10, num_avb_streams=12, num_avb_data_bytes=400, weight_none=50, weight_lp=50, weight_other=50, data_len_min=46, data_len_max=500, weight_tagged=50, weight_untagged=50): rand = random.Random() rand.seed(seed) bit_time = tx_phy.get_clock().get_bit_time() rxLpControl = RxLpControl('tile[0]:XS1_PORT_1D', bit_time, 0, True, rand.randint(0, sys.maxint)) resources = xmostest.request_resource("xsim") testname = 'test_avb_traffic' level = 'nightly' binary = '{test}/bin/{mac}_{phy}/{test}_{mac}_{phy}.xe'.format( test=testname, mac=mac, phy=tx_phy.get_name()) if xmostest.testlevel_is_at_least(xmostest.get_testlevel(), level): print "Running {test}: {phy} phy at {clk} (seed {seed})".format( test=testname, phy=tx_phy.get_name(), clk=tx_clk.get_name(), seed=seed) stream_mac_addresses = {} stream_seq_id = {} stream_ids = [x for x in range(num_avb_streams)] for i in stream_ids: stream_mac_addresses[i] = [i, 1, 2, 3, 4, 5] stream_seq_id[i] = 0 packets = [] filler = PacketFiller(weight_none, weight_lp, weight_other, weight_tagged, weight_untagged, data_len_min, data_len_max, bit_time) window_size = 125000 min_ifg = 96 * bit_time last_packet_end = 0 ifg = 0 for window in range(num_windows): # Randomly place the streams in the 125us window packet_start_times = sorted([rand.randint(0, window_size) for x in range(num_avb_streams)]) if debug_fill: print "Window {} - times {}".format(window, packet_start_times) rand.shuffle(stream_ids) for (i, stream) in enumerate(stream_ids): packet_start_time = packet_start_times[i] gap_size = packet_start_time - last_packet_end (last_packet_end, ifg) = filler.fill_gap(rand, packets, gap_size, last_packet_end, ifg) start_ifg = min_ifg avb_packet= MiiPacket(rand, dst_mac_addr=stream_mac_addresses[stream], create_data_args=['same', (stream_seq_id[stream], num_avb_data_bytes)], vlan_prio_tag=[0x81, 0x00, 0x00, 0x00], inter_frame_gap=ifg) stream_seq_id[stream] += 1 packets.append(avb_packet) ifg = rand.randint(min_ifg, 2 * min_ifg) packet_time = avb_packet.get_packet_time(bit_time) if debug_fill: print "PACKET {} -> {}".format(last_packet_end, last_packet_end + packet_time) last_packet_end += packet_time # Fill the window after the last packet gap_size = window_size - last_packet_end (last_packet_end, ifg) = filler.fill_gap(rand, packets, gap_size, last_packet_end, ifg) # Compute where in the next window the last packet has finished last_packet_end = last_packet_end - window_size tx_phy.set_packets(packets) if xmostest.testlevel_is_at_least(xmostest.get_testlevel(), level): print "Running {w} windows of {s} AVB streams with {b} data bytes each".format( w=num_windows, s=num_avb_streams, b=num_avb_data_bytes) print "Sending {n} lp packets with {b} bytes hp data".format( n=filler.lp_seq_id, b=filler.lp_data_bytes) print "Sending {n} other packets with {b} bytes hp data".format( n=filler.other_seq_id, b=filler.other_data_bytes) expect_folder = create_if_needed("expect") expect_filename = '{folder}/{test}_{mac}_{phy}.expect'.format( folder=expect_folder, test=testname, mac=mac, phy=tx_phy.get_name()) create_expect(packets, expect_filename, num_windows, num_avb_streams, num_avb_data_bytes) tester = xmostest.ComparisonTester(open(expect_filename), 'lib_ethernet', 'basic_tests', testname, {'mac':mac, 'phy':tx_phy.get_name(), 'clk':tx_clk.get_name(), 'n_stream':num_avb_streams, 'b_p_stream':num_avb_data_bytes, 'len_min':data_len_min, 'len_max':data_len_max, 'w_none':weight_none, 'w_lp':weight_lp, 'w_other':weight_other, 'n_windows':num_windows}, regexp=True) tester.set_min_testlevel(level) simargs = get_sim_args(testname, mac, tx_clk, tx_phy) xmostest.run_on_simulator(resources['xsim'], binary, simthreads=[tx_clk, tx_phy, rxLpControl], tester=tester, simargs=simargs)