In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
How to configure the weak network environment test program? In view of this problem, today the editor summarizes this article on the configuration of weak network environment, which can be used as a reference for interested friends. I hope it will be helpful to you.
When doing audio and video development, you often need to simulate the weak network environment and observe the performance of app under the weak network, such as packet loss, delay, jitter, limited bandwidth conditions, and so on. Mac system has a weak network tool APP, called "Network Link Conditioner", which supports visual completion of weak network simulation and configuration. It is very easy to use. It is highly recommended that you use this tool to complete weak network simulation.
But if you expect to use the command line or script to implement the configuration of the weak network environment, you have to study the principle behind it. This article introduces the system-related commands and services used behind Network Link Conditioner, and teaches you how to use the command line to complete the configuration of the weak network environment.
After Mac OS X 10.10, the system mainly uses `PF (Packet Filter, the BSD firewall) `and `dummynet (the BSD traffic shaper)` to simulate various weak network environments.
Dummynet
DUMMYNET (4) BSD Kernel Interfaces Manual DUMMYNET (4) NAME dummynet-traffic shaper, bandwidth manager and delay emulatorDESCRIPTION dummynet is a system facility that permits the control of traffic going through the various network interfaces, by applying bandwidth and queue size limitations, implementing different scheduling and queue management policies, and emulating delays and losses. The user interface for dummynet is implemented by the dnctl program, so the reader is referred to the dnctl (8) manpage for a complete description of the capabilities of dummynet and on how to use it.SEE ALSO dnctl (8), setsockopt (2), bridge (4), ip (4), sysctl (8) HISTORY dummynet was initially implemented as a testing tool for TCP congestion control by Luigi Rizzo, as described on ACM Computer Communication Review, Jan.97 issue. Later it has been then modified to work at the ip and bridging level, integrated with the IPFW packet fil- ter, and extended to support multiple queueing and scheduling policies.
To put it simply, `dummynet` is a traffic / bandwidth / delay control tool, and users can use the `dnctl` command to configure and interact with it.
Dnctl
Online documentation: http://www.manpagez.com/man/8/dnctl/
DNCTL (8) BSD System Manager's Manual DNCTL (8) NAME dnctl-- Traffic shaper control programSYNOPSIS dnctl [- anqs] {list | show} dnctl [- f |-Q] flush dnctl [- Q] {delete} [number.] Dnctl {pipe | queue} number config config-options dnctl [- s [field]] {pipe | queue} {delete | list | show} [number.] Dnctl [- nq] [- p preproc [preproc-flags]] pathnameDESCRIPTION The dnctl utility is the user interface for controlling the dummynet (4) traffic shaper. Dummynet operates by first using a packet filter to classify packets and divide them into flows, using any match pattern that can be used in dnctl rules. Depending on local policies, a flow can contain packets for a single TCP connection, or from/to a given host, or entire subnet, or a protocol type, etc.
To put it simply, `dummynet` is a command line tool used to configure the `dummynet` service.
$dnctl {pipe | queue} number config config-options
`dnctl` provides two traffic control mechanisms, one is pipe and the other is queue. The former is mainly used for weak network simulation under fixed bandwidth conditions, while the latter can experiment with different pipe to preempt and share available bandwidth. Usually we choose the former to simply simulate the weak network.
There are many types of `options`, and the configuration of weak network conditions is basically here:
The following parameters can be configured for a pipe:bw bandwidth Bandwidth, measured in [K | M] {bit/s | Byte/s}. A value of 0 (default) means unlimited bandwidth.delay ms-delay Propagation delay, measured in milliseconds.plr packet-loss-rate a floating-point number between 0 and 1, with 0 meaning no loss, 1 meaning 100% loss.queue {slots | sizeKbytes} Queue size, in slots or KBytes. Default value is 50 slots, which is the typical queue size for Ethernet devices.
To sum up, let's define a weak network environment in which the pipe number id is 1 and the bandwidth is limited to 100Kbit.
/ / create a configuration and display $sudo dnctl pipe 1 config bw 100Kbit/s delay 100 plr 0.5$ sudo dnctl show00001: 100.000 Kbit/s 100 ms 50 sl.plr 0.500000 0 queues (1 buckets) droptail mask: 0x00 0x00000000/0x0000-> 0x00000000/0x0000// clear the configuration and display $sudo dnctl-Q flush$ sudo dnctl show
Pf
Let's take a look at another tool: `pf`, which is the firewall tool of the Mac system, which we use to transfer the traffic passing through the system to our weak network environment for filter processing.
`pf` mainly uses configuration files to save firewall rules. The syntax is more stringent, cat / etc/pf.conf. You can see the following:
# This file contains the main ruleset, which gets automatically loaded# at startup. PF will not be automatically enabled, however. Instead,# each component which utilizes PF is responsible for enabling and disabling# PF via-E and-X as documented in pfctl (8). That will ensure that PF# is disabled only when the last enable reference is released.## Care must be taken to ensure that the main ruleset does not get flushed,# as the nested anchors rely on the anchor point defined here. In addition,# to the anchors loaded by this file, some system services would dynamically# insert anchors into the main ruleset. These anchors will be added only when# the system service is used and would removed on termination of the service.## See pf.conf (5) for syntax.## com.apple anchor point#scrub-anchor "com.apple/*" nat-anchor "com.apple/*" rdr-anchor "com.apple/*" dummynet-anchor "com.apple/*" anchor "com.apple/*" load anchor "com.apple" from "/ etc/pf.anchors/com.apple"
Next, we need to write our own rules.
1. Create a new pf.conf file
$touch pf.conf
two。 Add routing rules
Rule document: https://www.openbsd.org/faq/pf/filter.html
Action [direction] [log] [quick] [on interface] [af] [proto protocol] [from src_addr [port src_port]] [to dst_addr [port dst_port]] [flags tcp_flags] [state]
For more information on the parameters, please see the documentation. Here are several key configurations:
[direction]: direction of traffic, uplink: out, downlink: in [proto protocol]: protocol, tcp/udp/icmp, etc. [from src_addr [port src_port]]: source ip and port, default can use any [to dst_addr [port dst_port]]: destination ip and port, default can use any
Here we mainly show how to add rules to dummynet pipe 1 that we created above
$vi pf.conf# the "uplink + downlink" of this example is configured with weak network, and you can also configure one-way test change # test tcp, such as: curl www.baidu.comdummynet in proto tcp from any to any pipe 1 dummynet out proto tcp from any to any pipe conversation test udp, such as audio / video call dummynet in proto udp from any to any pipe 1 dummynet out proto udp from any to any pipe connection test ping For example: ping baidu.comdummynet in proto icmp from any to any pipe 1dummynet out proto icmp from any to any pipe 1
3. Start and load the `PF` configuration
To operate the `PF` service, you need to use the `PF` command.
# Mac system disables the `PF` service by default. Start the `PF` service $sudo pfctl-e# load the custom firewall rule $sudo pfctl-f pf.conf# to restore the original firewall rule $sudo pfctl-f / etc/pf.conf # Note: the following warning often appears when using the pfctl command, so just ignore it. "No ALTQ support in kernel"
On the Mac configuration weak network environment to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you like this article, you might as well share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.