### Setup SimPy Process Source: https://github.com/tl-system/ns.py/blob/main/README.md Demonstrates how to initialize a network component by registering its run method with the SimPy environment using env.process(). ```python self.action = env.process(self.run()) ``` -------------------------------- ### Run HTTPS Server Source: https://github.com/tl-system/ns.py/blob/main/README.md Starts a simple HTTPS server that listens on a specified port and uses a provided certificate for secure communication. ```shell python examples/real_traffic/https_server.py 4443 server_cert.pem ``` -------------------------------- ### Install ns.py using pip Source: https://github.com/tl-system/ns.py/blob/main/README.md Installs the ns.py package using pip after setting up a conda environment. This is the primary method for getting the simulator into your Python environment. ```Shell pip install ns.py ``` -------------------------------- ### Generate Self-Signed Certificate Source: https://github.com/tl-system/ns.py/blob/main/README.md Creates a self-signed SSL certificate and private key for use with the HTTPS server example. ```openssl openssl req -new -x509 -keyout server_cert.pem -out server_cert.pem -days 365 -nodes ``` -------------------------------- ### Run TCP Echo Server Source: https://github.com/tl-system/ns.py/blob/main/README.md Starts a TCP echo server that listens on a specified port. This is used to test the ns.py TCP proxy. ```shell python examples/real_traffic/tcp_echo_server.py 10000 ``` -------------------------------- ### Run UDP Echo Server Source: https://github.com/tl-system/ns.py/blob/main/README.md Starts a UDP echo server that listens on a specified port. This is used to test the ns.py UDP proxy. ```shell python examples/real_traffic/udp_echo_server.py 10000 ``` -------------------------------- ### Basic Network Connectivity with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Demonstrates a simple network setup connecting two packet generators to a wire with a propagation delay distribution, and then to a packet sink. It showcases the core components `DistPacketGenerator`, `PacketSink`, and `Wire`. ```Python from ns import DistPacketGenerator, PacketSink, Wire # Example usage (conceptual): # generator1 = DistPacketGenerator(...) # generator2 = DistPacketGenerator(...) # wire = Wire(propagation_delay_distribution=...) # sink = PacketSink() # generator1.connect(wire) # generator2.connect(wire) # wire.connect(sink) ``` -------------------------------- ### Two-Rate Token Bucket Traffic Shaper with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Implements a two-rate, three-color traffic shaper. This example showcases `DistPacketGenerator`, `PacketSink`, and `TwoRateTokenBucketShaper`. ```Python from ns import DistPacketGenerator, PacketSink, TwoRateTokenBucketShaper # Example usage (conceptual): # generator = DistPacketGenerator(...) # shaper = TwoRateTokenBucketShaper(rate1=..., rate2=..., bucket_size1=..., bucket_size2=...) # sink = PacketSink() # generator.connect(shaper) # shaper.connect(sink) ``` -------------------------------- ### Packet Switch Simulation with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Illustrates a scenario with a packet generator connected to a switch port, which is then linked to a packet sink. This example highlights `DistPacketGenerator`, `PacketSink`, and `Port`. ```Python from ns import DistPacketGenerator, PacketSink, Port # Example usage (conceptual): # generator = DistPacketGenerator(...) # switch_port = Port() # sink = PacketSink() # generator.connect(switch_port) # switch_port.connect(sink) ``` -------------------------------- ### Yield on Packet Availability in SimPy Scheduler Source: https://github.com/tl-system/ns.py/blob/main/README.md Ensures that a SimPy process yields control when no packets are available, allowing other processes to execute. This is crucial for infinite loops in network components to prevent blocking. The example uses `yield self.packets_available.get()` which acts like a sleep on a binary semaphore. ```Python yield self.packets_available.get() ``` -------------------------------- ### Weighted Fair Queueing (WFQ) Scheduling with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Demonstrates the Weighted Fair Queueing (WFQ) scheduler and the use of a `ServerMonitor` for finer-grained performance statistics using a sampling distribution. Components: `DistPacketGenerator`, `PacketSink`, `Splitter`, `WFQServer`, `ServerMonitor`. ```Python from ns import DistPacketGenerator, PacketSink, Splitter, WFQServer, ServerMonitor # Example usage (conceptual): # generator = DistPacketGenerator(...) # splitter = Splitter() # wfq_server = WFQServer(weights={...}) # monitor = ServerMonitor(wfq_server, sampling_distribution=...) # sink = PacketSink() # generator.connect(splitter) # splitter.connect(wfq_server) # wfq_server.connect(sink) ``` -------------------------------- ### Run SimPy Environment Source: https://github.com/tl-system/ns.py/blob/main/README.md Illustrates how to execute the SimPy simulation environment until a specified time using env.run(). ```python env.run(until=100) ``` -------------------------------- ### Two-Level Scheduling Topologies with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Illustrates the construction of two-level network topologies using Deficit Round Robin (DRR), Weighted Fair Queueing (WFQ), and Static Priority (SP) servers. It also shows using strings for flow IDs and dictionaries for per-flow weights. ```Python # Conceptual example for two-level DRR: # from ns import DistPacketGenerator, PacketSink, Splitter, DRRServer # # generator = DistPacketGenerator(...) # splitter = Splitter() # drr_level1 = DRRServer(weights={'flowA': 10, 'flowB': 5}) # drr_level2 = DRRServer(weights={'flowA_sub1': 2, 'flowA_sub2': 3}) # sink = PacketSink() # # generator.connect(splitter) # splitter.connect(drr_level1) # drr_level1.connect(drr_level2) # Example of chaining servers # drr_level2.connect(sink) ``` -------------------------------- ### FatTree Topology Simulation with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Shows how to construct and utilize a FatTree topology for network flow simulation. It highlights `DistPacketGenerator`, `PacketSink`, `SimplePacketSwitch`, and `FairPacketSwitch`, and discusses using `FairPacketSwitch` with WFQ, DRR, or Virtual Clock for per-flow fairness. ```Python from ns import DistPacketGenerator, PacketSink, SimplePacketSwitch, FairPacketSwitch # Example usage (conceptual): # generator = DistPacketGenerator(...) # # For a simple FatTree: # switch_core = SimplePacketSwitch(...) # # For per-flow fairness: # switch_fair = FairPacketSwitch(scheduling_discipline='wfq', weights={...}) # sink = PacketSink() # # Connections would depend on the specific FatTree structure... ``` -------------------------------- ### Run ns.py HTTPS Proxy Source: https://github.com/tl-system/ns.py/blob/main/README.md Launches the ns.py proxy to handle HTTPS traffic, redirecting it to a specified host and port where the HTTPS server is running. ```shell python examples/real_traffic/proxy.py 5000 localhost 4443 ``` -------------------------------- ### Virtual Clock Scheduling with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Shows how to use the Virtual Clock scheduler and a `ServerMonitor` for detailed performance statistics with a sampling distribution. Components: `DistPacketGenerator`, `PacketSink`, `Splitter`, `VirtualClockQServer`, `ServerMonitor`. ```Python from ns import DistPacketGenerator, PacketSink, Splitter, VirtualClockQServer, ServerMonitor # Example usage (conceptual): # generator = DistPacketGenerator(...) # splitter = Splitter() # vc_server = VirtualClockQServer(weights={...}) # monitor = ServerMonitor(vc_server, sampling_distribution=...) # sink = PacketSink() # generator.connect(splitter) # splitter.connect(vc_server) # vc_server.connect(sink) ``` -------------------------------- ### RED and WFQ Buffer Combination with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Combines a Random Early Detection (RED) buffer with a WFQ server, demonstrating upstream input buffering and downstream zero-buffer configuration. It handles packet drops when the WFQ server is the bottleneck. Components: `DistPacketGenerator`, `PacketSink`, `Port`, `REDPort`, `WFQServer`, `Splitter`. ```Python from ns import DistPacketGenerator, PacketSink, Port, REDPort, WFQServer, Splitter # Example usage (conceptual): # generator = DistPacketGenerator(...) # red_buffer = REDPort(zero_downstream_buffer=True) # wfq_server = WFQServer(zero_buffer=True, weights={...}) # sink = PacketSink() # generator.connect(red_buffer) # red_buffer.connect(wfq_server) # wfq_server.connect(sink) ``` -------------------------------- ### Run ns.py UDP Proxy Source: https://github.com/tl-system/ns.py/blob/main/README.md Launches the ns.py proxy to handle UDP traffic, redirecting it to a specified host and port where the UDP echo server is running. ```shell python examples/real_traffic/proxy.py 5000 localhost 10000 udp ``` -------------------------------- ### Run ns.py TCP Proxy Source: https://github.com/tl-system/ns.py/blob/main/README.md Launches the ns.py proxy to handle TCP traffic, redirecting it to a specified host and port where the TCP echo server is running. ```shell python examples/real_traffic/proxy.py 5000 localhost 10000 tcp ``` -------------------------------- ### Run UDP Echo Client Source: https://github.com/tl-system/ns.py/blob/main/README.md Connects to the ns.py UDP proxy and sends a message, demonstrating the end-to-end communication flow for UDP. ```shell python examples/real_traffic/udp_echo_client.py localhost 5000 Hello World ``` -------------------------------- ### Static Priority Scheduling with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Constructs a two-layer scheduler using two Static Priority (SP) schedulers. It demonstrates configuring `zero_downstream_buffer` for the upstream scheduler and `zero_buffer` for the downstream one. Components: `DistPacketGenerator`, `PacketSink`, `SPServer`. ```Python from ns import DistPacketGenerator, PacketSink, SPServer # Example usage (conceptual): # generator = DistPacketGenerator(...) # upstream_sp = SPServer(zero_downstream_buffer=True) # downstream_sp = SPServer(zero_buffer=True) # sink = PacketSink() # generator.connect(upstream_sp) # upstream_sp.connect(downstream_sp) # downstream_sp.connect(sink) ``` -------------------------------- ### Run TCP Echo Client Source: https://github.com/tl-system/ns.py/blob/main/README.md Connects to the ns.py TCP proxy and sends a message, demonstrating the end-to-end communication flow. ```shell python examples/real_traffic/tcp_echo_client.py localhost 5000 ``` -------------------------------- ### MM1 Queue Simulation with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Shows how to simulate a network port using the MM1 queue model, featuring exponential packet inter-arrival times and exponentially distributed packet sizes. It utilizes `DistPacketGenerator`, `PacketSink`, `Port`, and `PortMonitor`. ```Python from ns import DistPacketGenerator, PacketSink, Port, PortMonitor # Example usage (conceptual): # generator = DistPacketGenerator(arrival_distribution='exponential', size_distribution='exponential') # port = Port() # sink = PacketSink() # monitor = PortMonitor(port) # generator.connect(port) # port.connect(sink) ``` -------------------------------- ### Connect with curl HTTPS Client Source: https://github.com/tl-system/ns.py/blob/main/README.md Uses curl to connect to the ns.py HTTPS proxy, demonstrating client-side interaction with the proxied HTTPS server. ```shell curl -v https://localhost:5000 --insecure ``` -------------------------------- ### Create and Activate Conda Environment for ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Creates a new conda environment named 'ns.py' with Python 3.9 and activates it. This isolates the simulator's dependencies. ```Shell conda update conda conda create -n ns.py python=3.9 conda activate ns.py ``` -------------------------------- ### Deficit Round Robin (DRR) Scheduling with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Demonstrates the implementation and usage of the Deficit Round Robin (DRR) scheduler. Components used: `DistPacketGenerator`, `PacketSink`, `Splitter`, `DRRServer`. ```Python from ns import DistPacketGenerator, PacketSink, Splitter, DRRServer # Example usage (conceptual): # generator = DistPacketGenerator(...) # splitter = Splitter() # drr_server = DRRServer(weights={...}) # sink = PacketSink() # generator.connect(splitter) # splitter.connect(drr_server) # drr_server.connect(sink) ``` -------------------------------- ### Token Bucket Traffic Shaper with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Creates a traffic shaper where the bucket size equals the packet size, and the bucket rate is half the input packet rate. It uses `DistPacketGenerator`, `PacketSink`, and `TokenBucketShaper`. ```Python from ns import DistPacketGenerator, PacketSink, TokenBucketShaper # Example usage (conceptual): # generator = DistPacketGenerator(...) # shaper = TokenBucketShaper(bucket_size=packet_size, bucket_rate=input_rate / 2) # sink = PacketSink() # generator.connect(shaper) # shaper.connect(sink) ``` -------------------------------- ### Accessing Scheduler Parameters using Flow IDs Source: https://github.com/tl-system/ns.py/blob/main/README.md Demonstrates how flow IDs are used as indices to access scheduler parameters like deficit counters and quantum values in the DRR scheduler. This is a common pattern for managing per-flow data. ```Python self.deficit[flow_id] += self.quantum[flow_id] ``` -------------------------------- ### TCP Network Simulation with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Configures a two-hop network from a sender to a receiver via a switch, including acknowledgment packets. The sender employs a configurable TCP congestion control algorithm (e.g., Reno, CUBIC). Components used: `TCPPacketGenerator`, `CongestionControl`, `TCPSink`, `Wire`, `SimplePacketSwitch`. ```Python from ns import TCPPacketGenerator, CongestionControl, TCPSink, Wire, SimplePacketSwitch # Example usage (conceptual): # sender = TCPPacketGenerator(congestion_control='reno') # switch = SimplePacketSwitch() # receiver = TCPSink() # ack_wire = Wire() # sender.connect(switch) # switch.connect(receiver) # receiver.connect(switch) # for acknowledgments # switch.connect(sender) # for acknowledgments ``` -------------------------------- ### Upgrade Packages with ns.py Source: https://github.com/tl-system/ns.py/blob/main/README.md Upgrades Python packages within the current environment using a provided script. This is a utility script for maintaining project dependencies. ```Shell python upgrade_packages.py ``` -------------------------------- ### Retrieve Packet from SimPy Store Source: https://github.com/tl-system/ns.py/blob/main/README.md Retrieves a packet from a SimPy `Store`, which acts as a FIFO buffer for shared resources. This operation is performed using `yield store.get()`. A new `simpy.Store` is initialized for each flow in the DRR scheduler. ```Python packet = yield store.get() ``` ```Python if not flow_id in self.stores: self.stores[flow_id] = simpy.Store(self.env) ``` -------------------------------- ### Schedule Event with Timeout in SimPy Source: https://github.com/tl-system/ns.py/blob/main/README.md Schedules a SimPy process to resume after a specified timeout. This is achieved using the `yield env.timeout()` call within a generator function, allowing other processes to run concurrently. The timeout duration is calculated based on packet size and transmission rate. ```Python yield self.env.timeout(packet.size * 8.0 / self.rate) ``` -------------------------------- ### Send Packet to Downstream Component in SimPy Source: https://github.com/tl-system/ns.py/blob/main/README.md Sends a packet to a downstream component in the network simulation by calling its `put()` function. This is typically done after a timeout has expired. The `self.out` attribute, representing the downstream component, is set by the main program. ```Python self.out.put(packet) ``` ```Python drr_server.out = ps ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.