Explain how you would implement subnetting and then code a classical networking concept such as the three-way handshake or virtual memory, while also reasoning about semaphores.
Implement the subnetting and three-way handshake option. The function receives an IPv4 CIDR, a power-of-two subnet count, an ordered event stream, and a semaphore capacity. Return the generated subnet CIDRs and each connection's final state.
def subnet_and_handshake(network_cidr, subnet_count, events, semaphore_limit): Input events are dictionaries with connection and event, where events are SYN, SYN-ACK, ACK, or RST. Each connection must complete SYN -> SYN-ACK -> ACK to become established.
def subnet_and_handshake(network_cidr, subnet_count, events, semaphore_limit):