## 4 Implementation and Benchmarking of L4S in FreeBSD
### Step 2: Enqueuing and Filtering Packets Based on Their ECN Flag  
In this step, we must filter the packets into ECN-capable transport and non-ECN marked packets; these are codepoints of the ECN field. ECT-capable packets are given higher priority when enqueuing, meaning when there is congestion, L4S packets are given more priority, and the classic packets are dropped more relative to L4S packets, decreasing the latency for L4S packets. This is why we need to be able to differentiate the packets, as they might have different purposes. Packets related to a certain service, like live streaming and video calls, are latency-sensitive and thus would be marked with the (ip->ip_tos & IPTOS_ECN_MASK)! = 0, meaning it would be 01, 10 or 11 bits.  
Algorithm 5 demonstrates the high-level details of implementing packet enqueuing into the queues. The algorithm is designed for packet filtering and enqueuing, which involves classifying packets and then enqueuing them into the appropriate queue based on certain criteria.  
```
/* * Enqueue a packet into either L4S or Classic queues according to its ECN flag */ static int l4s_enqueue(struct dn_sch_inst *_si, struct dn_queue *_q, struct mbuf *m) {.................. /* classify a packet to queue number, which is half of the total queue size*/ idx = l4s_classify_flow(m, param->flows_cnt/2, si); struct ip *ip; ip = (struct ip *)mtodo(m, dn_tag_get(m)->iphdr_off); /* If the queue number is 0-2 given by Jenkin Hash and if ECN is enabled, * we will put the packet in the later half of the queue buffer meant for * L4S */ if (ip->ip,tos & IPTOS_ECN_MASK)!= 0) idx=idx+(int)(param->flows_cnt / 2); drop = pie_enqueue(&flows[idx], m, si);.................................... }
```  
**Classify a Packet to Queue Number:**  
idx = l4s_classify_flow(m, param->flows_cnt / 2, si);
*  l4s_classify_flow(m, param->flows_cnt / 2, si) is a function that classifies the packet m into a queue number using The Jenkins hash algorithm.
* param->flows_cnt / 2 is used as an argument to split the classification into L4S and native PIE queues.
* si is an additional parameter passed to the classification function.  
**Extract IP Header**  
struct ip *ip; ip = (struct ip *)mtodo(m, dn_tag_get(m)->iphdr_off);
* struct ip *ip; declares a pointer to an IP header structure.
* ip = (struct ip *)mtodo(m, dn_tag_get(m)->iphdr_off); extracts the IP header from the packet m using the offset provided by dn_tag_get(m)->iphdr_off.  
**Check ECN Field in IP Header**  
if ((ip->ip_tos & IPTOS_ECN_MASK) == IPTOS_ECN_ECT1) idx = idx + (int)(param->flows_cnt / 2);
* if ((ip->ip_tos & IPTOS_ECN_MASK) == IPTOS_ECN_ECT1) checks the explicit congestion notification (ECN) field in the IP header's type of service (ToS) field.
* IPTOS_ECN_MASK is a mask to isolate the ECN bits.  
* If the ECN field is not zero, the queue index idx is adjusted by adding half of the total flow count (param->flows_cnt / 2). This effectively classifies the packet into L4S queues based on its ECN status.  
**Enqueue the Packet**  
* drop = pie_enqueue(&flows[idx], m, si); enqueues the packet m into the queue indexed by idx in the flows array using the pie_enqueue function.
* &flows[idx] is a pointer to the specific queue.
* si is likely additional context or parameters needed for the enqueue operation.
* The result of the enqueue operation (whether the packet was dropped or successfully enqueued) is stored in the variable drop.  
The _l4s_classify_flow_ method uses a Jenkins hash function and uses the network configuration settings like the source and destination IP address and ports as parameters. The [PERSON] hash algorithm utilizes a combination of bitwise operations and multiplication with prime numbers to generate the hash value. It is commonly used in software applications for tasks such as hash table lookups, checksum generation, and data indexing.