Calculate Finish Times Weighted Fair Queueing

Weighted Fair Queueing Finish Time Calculator :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ddd; –card-background: #fff; –shadow: 0 2px 5px rgba(0,0,0,0.1); } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); line-height: 1.6; margin: 0; padding: 20px; display: flex; flex-direction: column; align-items: center; } .container { width: 100%; max-width: 960px; background-color: var(–card-background); padding: 30px; border-radius: 8px; box-shadow: var(–shadow); margin-bottom: 30px; } h1, h2, h3 { color: var(–primary-color); text-align: center; margin-bottom: 20px; } h1 { font-size: 2.5em; } h2 { font-size: 1.8em; border-bottom: 2px solid var(–primary-color); padding-bottom: 10px; margin-top: 40px; } h3 { font-size: 1.4em; margin-top: 30px; } .loan-calc-container { background-color: var(–card-background); padding: 25px; border-radius: 8px; box-shadow: var(–shadow); margin-bottom: 30px; border: 1px solid var(–border-color); } .input-group { margin-bottom: 20px; text-align: left; } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group select { width: calc(100% – 22px); padding: 10px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; box-sizing: border-box; } .input-group .helper-text { font-size: 0.85em; color: #666; margin-top: 5px; display: block; } .error-message { color: red; font-size: 0.85em; margin-top: 5px; display: block; min-height: 1.2em; /* Prevent layout shifts */ } .button-group { display: flex; justify-content: space-between; margin-top: 25px; flex-wrap: wrap; gap: 10px; } button { padding: 12px 20px; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; font-weight: bold; transition: background-color 0.3s ease; flex: 1; min-width: 150px; } button.primary { background-color: var(–primary-color); color: white; } button.primary:hover { background-color: #003366; } button.secondary { background-color: #6c757d; color: white; } button.secondary:hover { background-color: #5a6268; } button.reset { background-color: #ffc107; color: #212529; } button.reset:hover { background-color: #e0a800; } #results-container { margin-top: 30px; padding: 25px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); border: 1px solid var(–border-color); } #results-container h3 { margin-top: 0; text-align: left; color: var(–primary-color); } .result-item { margin-bottom: 15px; font-size: 1.1em; } .result-item strong { color: var(–primary-color); display: inline-block; min-width: 200px; } .highlighted-result { background-color: var(–success-color); color: white; padding: 15px; border-radius: 5px; text-align: center; font-size: 1.5em; margin-top: 20px; margin-bottom: 20px; box-shadow: inset 0 0 10px rgba(0,0,0,0.2); } .highlighted-result strong { color: white; min-width: auto; } .formula-explanation { font-size: 0.9em; color: #555; margin-top: 15px; padding: 10px; background-color: #e9ecef; border-radius: 4px; } table { width: 100%; border-collapse: collapse; margin-top: 20px; margin-bottom: 30px; box-shadow: var(–shadow); } th, td { padding: 12px 15px; text-align: left; border: 1px solid var(–border-color); } thead { background-color: var(–primary-color); color: white; } tbody tr:nth-child(even) { background-color: #f2f2f2; } caption { font-size: 1.1em; font-weight: bold; color: var(–primary-color); margin-bottom: 10px; text-align: left; } canvas { display: block; margin: 20px auto; background-color: var(–card-background); border-radius: 5px; box-shadow: var(–shadow); } .article-content { width: 100%; max-width: 960px; background-color: var(–card-background); padding: 30px; border-radius: 8px; box-shadow: var(–shadow); margin-top: 30px; text-align: left; } .article-content p, .article-content ul, .article-content ol { margin-bottom: 20px; font-size: 1.05em; } .article-content li { margin-bottom: 10px; } .article-content a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .article-content a:hover { text-decoration: underline; } .faq-item { margin-bottom: 20px; padding: 15px; background-color: #f8f9fa; border-radius: 5px; border-left: 4px solid var(–primary-color); } .faq-item strong { display: block; color: var(–primary-color); margin-bottom: 5px; font-size: 1.1em; } .related-links ul { list-style: none; padding: 0; } .related-links li { margin-bottom: 15px; } .related-links a { font-weight: bold; } .related-links span { font-size: 0.9em; color: #555; display: block; margin-top: 3px; } @media (max-width: 768px) { .container, .article-content { padding: 20px; } h1 { font-size: 2em; } h2 { font-size: 1.5em; } button { flex: none; width: 100%; } .button-group { flex-direction: column; align-items: center; } .result-item strong { min-width: auto; display: block; margin-bottom: 5px; } }

Weighted Fair Queueing Finish Time Calculator

Calculate the precise finish times for packets in a Weighted Fair Queueing (WFQ) system, considering packet sizes, weights, and service rates.

WFQ Finish Time Inputs

The size of the data packet in bytes.
The relative importance or priority assigned to this flow. Higher weight means higher priority.
The maximum data rate the queue can provide for this flow.
The virtual finish time of the previously scheduled packet for this flow. For the first packet, this is typically 0.
The maximum number of packets the queue can hold. Used for overflow checks.

Calculation Results

Packet Service Time (μs):
Normalized Packet Size:
Virtual Start Time (μs):
Actual Finish Time (μs):
Formula Used:
1. Packet Service Time (PST) = (Packet Size / Service Rate) * 1,000,000 (to convert seconds to microseconds)
2. Normalized Packet Size (NPS) = Packet Size / Weight
3. Virtual Start Time (VST) = max(Previous Virtual Finish Time, Current Virtual Start Time of Queue) – This is simplified in this calculator to VST = Previous Virtual Finish Time for a single flow context.
4. Virtual Finish Time (VFT) = VST + NPS
5. Actual Finish Time (AFT) = VFT * (Total Weight / Flow Weight) – This is simplified in this calculator to AFT = VFT, assuming a single flow or a simplified model where total weight is implicitly handled by the service rate.
*Note: This calculator provides a simplified model focusing on individual flow finish times. A full WFQ implementation involves a global virtual time and queue state.*

WFQ Finish Time Data Table

WFQ Packet Scheduling Simulation
Packet # Packet Size (Bytes) Flow Weight Service Rate (Mbps) Prev VFT (μs) PST (μs) NPS VST (μs) VFT (μs) AFT (μs)

Understanding Weighted Fair Queueing (WFQ) and Finish Times

What is Weighted Fair Queueing (WFQ)?

Weighted Fair Queueing (WFQ) is a sophisticated packet scheduling algorithm used in computer networks to provide differentiated Quality of Service (QoS). Unlike simple First-Come, First-Served (FCFS) or strict priority queues, WFQ aims to allocate network bandwidth proportionally among different traffic flows based on assigned weights. Each flow receives a share of the bandwidth that is proportional to its weight relative to the total weight of all active flows. This ensures that high-priority traffic receives preferential treatment without completely starving lower-priority traffic.

Who should use it: Network administrators, engineers, and researchers involved in network design, performance optimization, and QoS implementation. It's particularly relevant for networks carrying diverse traffic types, such as voice, video, and data, where guaranteeing certain performance levels for specific applications is crucial. Understanding WFQ helps in configuring routers and switches to manage traffic effectively.

Common misconceptions:

  • WFQ guarantees absolute bandwidth: WFQ guarantees *proportional* bandwidth, not a fixed amount. If the total network load is low, all flows might receive more than their weighted share. If the load exceeds capacity, flows will receive bandwidth according to their weights, but the absolute amount might be less than desired.
  • WFQ is the same as strict priority: While WFQ prioritizes flows with higher weights, it doesn't completely block lower-weighted flows. Strict priority would starve lower-priority queues if a higher-priority queue is active. WFQ ensures fairness even under congestion.
  • WFQ is simple to implement: WFQ requires maintaining per-flow state, calculating virtual finish times, and managing a complex scheduling logic, making it more resource-intensive than simpler algorithms.

Weighted Fair Queueing Finish Time Formula and Mathematical Explanation

The core idea behind WFQ is to simulate a hypothetical bit-by-bit round-robin scheduler. Instead of scheduling packets directly, WFQ assigns a "virtual finish time" to each packet. The packet with the earliest virtual finish time is scheduled next. This virtual finish time is calculated based on the packet's size, its assigned weight, and the system's current virtual time.

The calculation for a packet belonging to a specific flow involves several steps:

  1. Calculate Packet Service Time (PST): This is the time it would take to transmit the packet at the flow's allocated service rate.
    PST = (Packet Size / Service Rate)
    To work with microseconds (μs) commonly used in network scheduling, we convert:
    PST (μs) = (Packet Size (Bytes) * 8 bits/Byte) / (Service Rate (bits/sec)) * 1,000,000 μs/sec
    Or, if Service Rate is in Mbps:
    PST (μs) = (Packet Size (Bytes) * 8) / (Service Rate (Mbps) * 1,000,000) * 1,000,000
    PST (μs) = (Packet Size * 8) / Service Rate (Mbps)
  2. Calculate Normalized Packet Size (NPS): This adjusts the packet size by the flow's weight. A larger weight means a smaller normalized size, indicating it consumes less "virtual" resources per bit.
    NPS = Packet Size / Weight
  3. Determine Virtual Start Time (VST): This represents the earliest time the scheduler could *start* processing this packet in the virtual time domain. It's the maximum of the previous packet's virtual finish time for this flow and the current virtual time of the scheduler (which is often approximated by the virtual finish time of the last packet scheduled globally or for this flow). For simplicity in a single-flow context, we often use the previous virtual finish time.
    VST = max(Previous Virtual Finish Time, Current Queue Virtual Time)
    In our calculator's simplified model for a single flow:
    VST = Previous Virtual Finish Time
  4. Calculate Virtual Finish Time (VFT): This is the core WFQ metric. It's the time the packet would finish in the virtual system.
    VFT = VST + NPS
  5. Calculate Actual Finish Time (AFT): This converts the virtual finish time back to real time. It depends on the total weight of all active flows. The formula is:
    AFT = VFT * (Total Weight / Flow Weight)
    However, a more practical implementation often relates the service rate directly. If the service rate is correctly allocated based on weights (e.g., Flow Service Rate = Total Rate * (Flow Weight / Total Weight)), the AFT can be simplified. In many WFQ variants (like Stochastic Fair Queueing – SFQ, or simplified WFQ models), the virtual finish time itself is used as the primary scheduling metric, or the conversion is implicitly handled by the rate allocation. For this calculator, we'll focus on the VFT as the primary scheduling indicator and provide a simplified AFT calculation assuming the service rate already reflects the weight proportion.
    Simplified AFT (for this calculator's context): The virtual finish time (VFT) is often the key metric. If we need a real-time finish, and assuming the service rate is correctly provisioned, the VFT can be directly related. A common approach is to consider the VFT as the primary scheduling decision point. For this calculator, we'll present VFT and a simplified AFT.
    Simplified AFT (μs) = VFT (μs) (This assumes the service rate is correctly provisioned per flow based on weights, effectively making VFT the dominant factor in scheduling order).

Variables Table

Variable Meaning Unit Typical Range
Packet Size Size of the data packet Bytes 64 – 1500 (Ethernet MTU) or larger (Jumbo Frames)
Flow Weight (W) Relative priority assigned to a traffic flow Unitless 0.01 – 1000+ (depends on system configuration)
Service Rate (R) Maximum data rate allocated to the flow Mbps (Megabits per second) 1 – 10000+ (depends on network link capacity)
Previous Virtual Finish Time (PVFT) Virtual finish time of the previously scheduled packet for this flow Microseconds (μs) 0 – Varies greatly
PST Packet Service Time Microseconds (μs) Calculated based on size and rate
NPS Normalized Packet Size Bytes / Unitless Calculated based on size and weight
VST Virtual Start Time Microseconds (μs) Depends on PVFT
VFT Virtual Finish Time Microseconds (μs) Calculated based on VST and NPS
AFT Actual Finish Time Microseconds (μs) Calculated based on VFT and weights
Queue Size Maximum number of packets the queue can hold Packets 10 – 10000+

Practical Examples (Real-World Use Cases)

Example 1: High-Priority VoIP Call

A VoIP call requires low latency and jitter. A network administrator configures the VoIP flow with a high weight.

  • Scenario: A single packet from a VoIP flow needs scheduling.
  • Inputs:
    • Packet Size: 100 Bytes
    • Flow Weight: 50
    • Service Rate: 10 Mbps
    • Previous Virtual Finish Time: 1500 μs
    • Queue Size: 1000 Packets
  • Calculations:
    • PST = (100 * 8) / 10 = 80 μs
    • NPS = 100 / 50 = 2 Bytes
    • VST = 1500 μs
    • VFT = 1500 + 2 = 1502 μs
    • AFT = 1502 μs (Simplified)
  • Interpretation: This VoIP packet, despite its small size, gets a high priority due to its weight. Its virtual finish time is only slightly later than the previous packet's finish time, ensuring it's scheduled quickly. The actual finish time reflects this prompt scheduling.

Example 2: Bulk Data Transfer

A large file transfer is less sensitive to latency but needs a fair share of bandwidth. It's assigned a moderate weight.

  • Scenario: A packet from a bulk data flow.
  • Inputs:
    • Packet Size: 1500 Bytes
    • Flow Weight: 10
    • Service Rate: 100 Mbps
    • Previous Virtual Finish Time: 1500 μs
    • Queue Size: 1000 Packets
  • Calculations:
    • PST = (1500 * 8) / 100 = 120 μs
    • NPS = 1500 / 10 = 150 Bytes
    • VST = 1500 μs
    • VFT = 1500 + 150 = 1650 μs
    • AFT = 1650 μs (Simplified)
  • Interpretation: This larger packet has a significantly higher normalized size (150 Bytes) compared to the VoIP packet (2 Bytes). Even though its virtual start time is the same, its virtual finish time is much later (1650 μs vs 1502 μs). This indicates it will be scheduled after the VoIP packet and other flows with earlier virtual finish times, ensuring fair, albeit delayed, bandwidth allocation.

How to Use This WFQ Finish Time Calculator

This calculator helps you understand the scheduling behavior of Weighted Fair Queueing for individual packets. Follow these steps:

  1. Input Packet Details: Enter the size of the packet in Bytes.
  2. Specify Flow Characteristics: Input the Flow Weight assigned to this traffic type and the Service Rate (in Mbps) allocated to this flow.
  3. Enter Previous State: Provide the Previous Virtual Finish Time (μs) for this flow. If this is the very first packet being considered for this flow, use 0.
  4. Set Queue Limit: Input the maximum Queue Size (in packets) to check for potential overflow conditions (though this calculator primarily focuses on finish times, not queue drops).
  5. Calculate: Click the "Calculate Finish Time" button.
  6. Review Results:
    • Packet Service Time (PST): How long it takes to transmit the packet at its allocated rate.
    • Normalized Packet Size (NPS): Packet size adjusted by flow weight.
    • Virtual Start Time (VST): The earliest virtual time the packet can begin processing.
    • Virtual Finish Time (VFT): The calculated virtual completion time. This is a key metric for WFQ scheduling order.
    • Actual Finish Time (AFT): The estimated real-time finish time (simplified).
  7. Interpret: Compare the VFT and AFT values. Lower values indicate earlier scheduling. The difference between VFTs of consecutive packets helps understand the fairness and latency characteristics.
  8. Reset: Use the "Reset Defaults" button to return all fields to their initial values.
  9. Copy: Use the "Copy Results" button to copy the calculated values for documentation or sharing.

Key Factors That Affect WFQ Results

Several factors influence the calculated finish times and the overall performance of a WFQ system:

  • Flow Weights: This is the most direct factor. Higher weights grant flows earlier virtual finish times and thus quicker scheduling, especially under congestion. A flow with weight 20 will generally be served twice as fast as a flow with weight 10, assuming equal packet sizes and service rates.
  • Packet Size: Larger packets inherently take longer to transmit (higher PST). In WFQ, they also have a larger Normalized Packet Size (NPS), pushing their Virtual Finish Time (VFT) further out. This means smaller packets generally get scheduled sooner than larger packets within the same flow, contributing to lower jitter.
  • Service Rate Allocation: The configured service rate (R) for each flow directly impacts the Packet Service Time (PST). A higher service rate means a shorter PST, which can indirectly affect VFT if the scheduler is highly utilized. Crucially, the *total* service rate available on the link limits how quickly absolute finish times can occur.
  • Network Congestion: WFQ's primary benefit is managing congestion. When the total traffic demand exceeds the link capacity, WFQ ensures that bandwidth is distributed proportionally. The virtual finish times become critical differentiators in deciding which packet gets transmitted next. Without congestion, WFQ behaves similarly to FCFS for each flow.
  • Number of Active Flows: The total weight (sum of weights of all active flows) is used in the conversion from VFT to AFT. More active flows, especially those with high weights, can increase the total weight, potentially affecting the absolute finish times.
  • Queue Management Policies: While this calculator focuses on finish times, real-world WFQ implementations must handle queue overflows. If a queue reaches its maximum size, incoming packets might be dropped. The queue size parameter is a critical input for understanding potential packet loss, which affects the *effective* delivery time.
  • Scheduler Overhead: The computational cost of calculating VFTs and managing per-flow states introduces some delay. This overhead is not explicitly modeled in this simplified calculator but is a factor in real systems.
  • Time Synchronization: Accurate timestamps are crucial for calculating service rates and virtual times. Clock drift between network devices can impact the effectiveness of WFQ.

Frequently Asked Questions (FAQ)

Q1: What is the difference between WFQ and Strict Priority Queueing?

Strict Priority Queueing serves packets from the highest priority queue first, potentially starving lower-priority queues. WFQ provides proportional bandwidth allocation based on weights, ensuring that even low-priority traffic receives a share of the bandwidth, preventing starvation.

Q2: Can WFQ guarantee zero latency?

No. WFQ aims to provide fair and proportional bandwidth, which helps minimize latency and jitter, especially under congestion. However, it does not guarantee zero latency, as packet processing, queuing delays, and transmission times always exist.

Q3: How do I determine the right weights for my traffic flows?

Weights are typically assigned based on application requirements. Real-time applications like VoIP and video conferencing usually get higher weights due to their sensitivity to delay and jitter. Bulk data transfers might receive lower weights. Network administrators often use a combination of experimentation and QoS policies to set appropriate weights. Consider using our WFQ Finish Time Calculator to test different weight scenarios.

Q4: What happens if the sum of flow service rates exceeds the link capacity?

This is the scenario where WFQ is most beneficial. The algorithm ensures that the available bandwidth is distributed proportionally according to the weights. If the total bandwidth is 100 Mbps and flows have weights 10, 20, and 70 (total 100), they will receive approximately 10 Mbps, 20 Mbps, and 70 Mbps respectively. If the total demand is 150 Mbps, the proportions would still be maintained (e.g., 15, 30, 105 Mbps if the link could support it, but capped by the link's actual capacity).

Q5: Is WFQ suitable for all types of network traffic?

WFQ is excellent for traffic requiring differentiated services. However, for applications demanding extremely low latency and jitter (like real-time gaming or critical control systems), strict priority or specialized algorithms like Weighted Round Robin (WRR) with careful configuration might be considered, though WFQ offers better fairness.

Q6: How does the 'Previous Virtual Finish Time' affect the calculation?

The 'Previous Virtual Finish Time' (PVFT) sets the baseline for the current packet's Virtual Start Time (VST). The VST is the maximum of PVFT and the current scheduler virtual time. This ensures that a flow's packets are processed in order and that the scheduler doesn't fall behind. A higher PVFT means the current packet's VFT will also be pushed later.

Q7: What does a 'Normalized Packet Size' of 0.5 mean?

A Normalized Packet Size (NPS) of 0.5 means that this packet, relative to its flow's weight, consumes 0.5 units of the virtual resource. If another packet has an NPS of 1.0, it consumes twice the virtual resource and will therefore have a later virtual finish time, assuming they start at the same virtual time.

Q8: Does this calculator account for packet drops?

This calculator primarily focuses on the theoretical finish times based on WFQ logic. It includes a 'Queue Size' input for context but does not explicitly model packet drops due to queue overflow. In a real network, exceeding the queue size would lead to packet loss, impacting the effective throughput and latency.

var packetSizeInput = document.getElementById('packetSize'); var weightInput = document.getElementById('weight'); var serviceRateInput = document.getElementById('serviceRate'); var virtualFinishTimeInput = document.getElementById('virtualFinishTime'); var queueSizeInput = document.getElementById('queueSize'); var packetSizeError = document.getElementById('packetSizeError'); var weightError = document.getElementById('weightError'); var serviceRateError = document.getElementById('serviceRateError'); var virtualFinishTimeError = document.getElementById('virtualFinishTimeError'); var queueSizeError = document.getElementById('queueSizeError'); var packetServiceTimeSpan = document.getElementById('packetServiceTime'); var normalizedPacketSizeSpan = document.getElementById('normalizedPacketSize'); var virtualStartTimeSpan = document.getElementById('virtualStartTime'); var actualFinishTimeSpan = document.getElementById('actualFinishTime'); var wfqTableBody = document.getElementById('wfqTableBody'); var chart; var chartData = { labels: [], datasets: [{ label: 'Virtual Finish Time (μs)', data: [], borderColor: 'var(–primary-color)', backgroundColor: 'rgba(0, 74, 153, 0.2)', fill: false, tension: 0.1 }, { label: 'Actual Finish Time (μs)', data: [], borderColor: 'var(–success-color)', backgroundColor: 'rgba(40, 167, 69, 0.2)', fill: false, tension: 0.1 }] }; function initializeChart() { var ctx = document.getElementById('wfqChart').getContext('2d'); chart = new Chart(ctx, { type: 'line', data: chartData, options: { responsive: true, maintainAspectRatio: false, scales: { x: { title: { display: true, text: 'Packet Number' } }, y: { title: { display: true, text: 'Time (μs)' } } }, plugins: { tooltip: { mode: 'index', intersect: false }, legend: { position: 'top', } } } }); } function updateChart() { if (chart) { chart.update(); } } function validateInput(input, errorElement, min = null, max = null) { var value = parseFloat(input.value); var isValid = true; errorElement.textContent = "; if (isNaN(value)) { errorElement.textContent = 'Please enter a valid number.'; isValid = false; } else if (min !== null && value max) { errorElement.textContent = 'Value cannot be greater than ' + max + '.'; isValid = false; } input.style.borderColor = isValid ? '#ccc' : 'red'; return isValid; } function calculateWFQ() { // Clear previous table rows and chart data wfqTableBody.innerHTML = "; chartData.labels = []; chartData.datasets[0].data = []; chartData.datasets[1].data = []; var packetSize = parseFloat(packetSizeInput.value); var weight = parseFloat(weightInput.value); var serviceRate = parseFloat(serviceRateInput.value); // in Mbps var prevVirtualFinishTime = parseFloat(virtualFinishTimeInput.value); var queueSize = parseInt(queueSizeInput.value); var valid = true; valid = validateInput(packetSizeInput, packetSizeError, 1) && valid; valid = validateInput(weightInput, weightError, 0.01) && valid; valid = validateInput(serviceRateInput, serviceRateError, 0.01) && valid; valid = validateInput(virtualFinishTimeInput, virtualFinishTimeError, 0) && valid; valid = validateInput(queueSizeInput, queueSizeError, 1) && valid; if (!valid) { packetServiceTimeSpan.textContent = '–'; normalizedPacketSizeSpan.textContent = '–'; virtualStartTimeSpan.textContent = '–'; actualFinishTimeSpan.textContent = '–'; return; } // Calculations // PST (μs) = (Packet Size (Bytes) * 8 bits/Byte) / (Service Rate (Mbps) * 1,000,000 bits/Mbit) * 1,000,000 μs/sec var packetServiceTime = (packetSize * 8) / serviceRate; // in microseconds var normalizedPacketSize = packetSize / weight; // Bytes / unitless var virtualStartTime = prevVirtualFinishTime; // Simplified VST for single flow context var virtualFinishTime = virtualStartTime + normalizedPacketSize; // μs // Simplified Actual Finish Time calculation for this calculator's context // In a full WFQ, this involves total weight. Here, we assume service rate is proportional. var actualFinishTime = virtualFinishTime; // μs // Update results display packetServiceTimeSpan.textContent = packetServiceTime.toFixed(2); normalizedPacketSizeSpan.textContent = normalizedPacketSize.toFixed(2); virtualStartTimeSpan.textContent = virtualStartTime.toFixed(2); actualFinishTimeSpan.textContent = actualFinishTime.toFixed(2); // Add to table and chart data (simulating a few packets for demonstration) var numPacketsToSimulate = 10; // Simulate a few packets for chart/table var currentPrevVFT = 0; // Start simulation from 0 for (var i = 1; i <= numPacketsToSimulate; i++) { var currentPacketSize = packetSize; // Using the input packet size for simulation var currentWeight = weight; var currentServiceRate = serviceRate; var currentPST = (currentPacketSize * 8) / currentServiceRate; var currentNPS = currentPacketSize / currentWeight; var currentVST = currentPrevVFT; // Use previous VFT as VST var currentVFT = currentVST + currentNPS; var currentAFT = currentVFT; // Simplified AFT chartData.labels.push(i); chartData.datasets[0].data.push(currentVFT); chartData.datasets[1].data.push(currentAFT); var row = wfqTableBody.insertRow(); row.insertCell(0).textContent = i; row.insertCell(1).textContent = currentPacketSize; row.insertCell(2).textContent = currentWeight; row.insertCell(3).textContent = currentServiceRate; row.insertCell(4).textContent = currentPrevVFT.toFixed(2); row.insertCell(5).textContent = currentPST.toFixed(2); row.insertCell(6).textContent = currentNPS.toFixed(2); row.insertCell(7).textContent = currentVST.toFixed(2); row.insertCell(8).textContent = currentVFT.toFixed(2); row.insertCell(9).textContent = currentAFT.toFixed(2); currentPrevVFT = currentVFT; // Update for the next packet } // Update the chart after populating data updateChart(); } function resetCalculator() { packetSizeInput.value = 1500; weightInput.value = 10; serviceRateInput.value = 100; virtualFinishTimeInput.value = 0; queueSizeInput.value = 1000; // Clear errors packetSizeError.textContent = ''; weightError.textContent = ''; serviceRateError.textContent = ''; virtualFinishTimeError.textContent = ''; queueSizeError.textContent = ''; // Reset input borders packetSizeInput.style.borderColor = '#ccc'; weightInput.style.borderColor = '#ccc'; serviceRateInput.style.borderColor = '#ccc'; virtualFinishTimeInput.style.borderColor = '#ccc'; queueSizeInput.style.borderColor = '#ccc'; calculateWFQ(); // Recalculate with reset values } function copyResults() { var mainResult = actualFinishTimeSpan.textContent; var intermediateValues = "Packet Service Time (μs): " + packetServiceTimeSpan.textContent + "\n" + "Normalized Packet Size: " + normalizedPacketSizeSpan.textContent + "\n" + "Virtual Start Time (μs): " + virtualStartTimeSpan.textContent; var assumptions = "Key Assumptions:\n" + "- Simplified WFQ model focusing on single flow.\n" + "- Service Rate is correctly provisioned based on weights.\n" + "- Virtual Start Time is based on Previous Virtual Finish Time."; var textToCopy = "WFQ Finish Time Results:\n" + "————————\n" + "Actual Finish Time (μs): " + mainResult + "\n\n" + intermediateValues + "\n\n" + assumptions; navigator.clipboard.writeText(textToCopy).then(function() { // Optional: Show a confirmation message var originalText = document.querySelector('button[onclick="copyResults()"]').textContent; document.querySelector('button[onclick="copyResults()"]').textContent = 'Copied!'; setTimeout(function() { document.querySelector('button[onclick="copyResults()"]').textContent = originalText; }, 1500); }).catch(function(err) { console.error('Failed to copy text: ', err); // Optional: Show an error message }); } // Initialize the chart when the page loads window.onload = function() { initializeChart(); calculateWFQ(); // Perform initial calculation on load };

Leave a Comment