Supported Platforms
Example: Configuring an Ingress Single-Rate Two-Color Policer
This example shows how to configure an ingress single-rate two-color policer. Policers use a concept know as a token bucket. The policer enforces the QoS strategy for in-contract and out-of-contract traffic. You can apply a single-rate two-color policer to incoming packets, outgoing packets, or both. This example applies the policer as an input (ingress) policer. The goal of this document is to provide you with an introduction to policing by using a example that shows traffic policing in action.
A thorough explanation of the token bucket concept and its underlying algorithms is beyond the scope of this document. For more information about traffic policing, and QoS in general, please refer to the book titled QOS-Enabled Networks—Tools and Foundations by Miguel Barreiros and Peter Lundqvist. This book is available at many online booksellers or via www.juniper.net/books.
Requirements
To verify this procedure, this example uses a traffic generator. The traffic generator can be hardware-based or it can be software running on a server or host machine.
The functionality in this procedure is widely supported on devices that run Junos OS. The example shown here was tested and verified on MX Series routers running Junos OS Release 10.4.
Overview
Single-rate two-color policing enforces a configured rate of traffic flow for a particular service level by applying implicit or configured actions to traffic that does not conform to the limits. When you apply a single-rate two-color policer to the input or output traffic at an interface, the policer meters the traffic flow to the rate limit defined by the following components:
- Bandwidth limit—The average number of bits per second permitted for packets received or transmitted at the interface. You can specify the bandwidth limit as an absolute number of bits per second or as a percentage value from 1 through 100. If a percentage value is specified, the effective bandwidth limit is calculated as a percentage of either the physical interface media rate or the logical interface configured shaping rate.
- Burst-size limit—The maximum size permitted for
bursts of data. Burst sizes are measured in megabytes. We recommend
two formulas for calculating burst size:
Burst size = bandwidth x allowable time for burst traffic / 8
Or
Burst size = interface mtu x 10
For information about configuring the burst size, see Determining Proper Burst Size for Traffic Policers.
Note: There is a finite buffer space for an interface. In general, the estimated total buffer depth for an interface is about 125ms.
For a traffic flow that conforms to the configured limits (categorized as green traffic), packets are implicitly marked with a packet loss priority (PLP) level of low and are allowed to pass through the interface unrestricted.
For a traffic flow that exceeds the configured limits (categorized as red traffic), packets are handled according to the traffic-policing actions configured for the policer. This example discards packets that burst over the 15 KBps limit.
To rate-limit Layer 3 traffic, you can apply a two-color policer in the following ways:
- Directly to a logical interface, at a specific protocol level.
- As the action of a standard stateless firewall filter that is applied to a logical interface, at a specific protocol level. This is the technique used in this example.
To rate-limit Layer 2 traffic, you can apply a two-color policer as a logical interface policer only. You cannot apply a two-color policer to Layer 2 traffic through a firewall filter.
![]() | Caution: You can choose either bandwidth-limit or bandwidth percent within the policer, as they are mutually exclusive. You cannot configure a policer to use bandwidth percentage for aggregate, tunnel, and software interfaces. |
In this example, the host is a traffic generator emulating a web server. Devices R1 and R2 are owned by a service provider. The web server is accessed by users that are behind Device R2. The host will be sending traffic with a source TCP HTTP port of 80 to the users. A single-rate two-color policer is configured and applied to the interface on Device R1 that connects the host to Device R1. The policer enforces the contractual bandwidth availability made between the owner of the web server (in this case emulated by the host) and the service provider that owns Device R1 for the web traffic that flows over the link that connects the host to Device R1.
In accordance with the contractual bandwidth availability made between the owner of the web server and the service provider that owns devices R1 and R2; the policer will limit the HTTP port 80 traffic originating from the host to using 700 mbps (70 percent) of the available bandwidth with an allowable burst rate of 10 x the MTU size of the gigabit Ethernet interface between the host and Device R1.
![]() | Note: In a real-world scenario you would probably also rate limit traffic for a variety of other ports such as: FTP; SFTP; SSH; TELNET; SMTP; IMAP; and POP3 because they are often included as additional services with web hosting services. |
![]() | Note: You need to leave some additional bandwidth available that is not rate limited for network control protocols such as: routing protocols; DNS; and any other protocols required to keep network connectivity operational. This is why the firewall filter has a final accept condition on it. |
Topology
This example uses the topology in Figure 1.
Figure 1: Single-Rate Two - Color Policer Scenario

Figure 2 shows the policing behavior.
Figure 2: Traffic Limiting in a Single-Rate Two - Color Policer Scenario

CLI Quick Configuration shows the configuration for all of the Juniper Networks devices in Figure 1.
The section Step-by-Step Procedure describes the individual configuration steps on Device R1 and Device R2.
Configuration
CLI Quick Configuration
To quickly configure this example, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, and then copy and paste the commands into the CLI at the [edit] hierarchy level.
Device R1
Device R2
Step-by-Step Procedure
The following example requires you to navigate various levels in the configuration hierarchy. For instructions on how to do that, see Using the CLI Editor in Configuration Mode in the CLI User Guide.
To configure Device R1:
- Add a description to the interfaces.user@R1# set interfaces ge-2/0/5 description to-hostuser@R1# set interfaces ge-2/0/8 description to-R2
- Configure the IP addresses on the interfacesuser@R1# set interfaces ge-2/0/5 unit 0 family inet address 172.16.70.2/30user@R1# set interfaces ge-2/0/8 unit 0 family inet address 10.50.0.1/30
- Apply the firewall filter to the input of the logical
interface.[edit interfaces ge-2/0/5 unit 0 family inet]user@R1# set filter input srtcp-http-in
- Configure the policer to rate-limit to a bandwidth of
700 mbps and a burst size of 15000 KBps for HTTP traffic
(TCP port 80).[edit firewall policer srtcp-http-discard]user@R1# set if-exceeding bandwidth-limit 700muser@R1# set if-exceeding burst-size-limit 15k
- Configure the policer to discard packets in the red traffic
flow.[edit firewall policer srtcp-http-discard]user@R1# set then discard
- Configure the first two conditions of the firewall to
accept all TCP traffic to port HTTP (port 80). [edit firewall family inet filter srtcp-http-in]user@R1# set term t1 from protocol tcpuser@R1# set term t1 from port http
- Configure the third condition to rate-limit HTTP TCP traffic
using the policer.user@R1# set term t1 then policer srtcp-http-discard
- At the end of the firewall filter, you can configure a
default condition that accepts all other traffic. Otherwise, all traffic
that arrives on the interface and is not explicitly accepted by the
firewall is discarded.user@R1# set term t2 then accept
Step-by-Step Procedure
To configure device R2
- Add a description to the interfaces.set interfaces ge-2/0/8 description to-R1set interfaces ge-2/0/7 description to-users
- Configure the IP address on the interfaces.user@R2# set interfaces ge-2/0/8 unit 0 family inet address 10.50.0.2/30user@R2# set interfaces ge-2/0/7 unit 0 family inet address 172.16.80.2
Results
From configuration mode, confirm your configuration by entering the show interfaces, and show firewall commands. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.
If you are done configuring Device R1, enter commit from configuration mode.
If you are done configuring Device R2, enter commit from configuration mode.
Verification
Confirm that the configuration is working properly.
Clearing the Counters
Purpose
Confirm that the firewall and interface counters are cleared.
Action
- On Device R1, run the clear firewall all command
to reset the firewall counters to 0.
user@R1> clear firewall all
- On Device R1, run the clear interface statistics ge-2/0/5 command to reset the interface counters to 0.
user@R1> clear interface statistics ge-2/0/5
Sending TCP Traffic into the Network and Monitoring the Discards
Purpose
Make sure that the traffic of interest that is sent is rate-limited on the input interface (ge-2/0/5).
Action
- Use a traffic generator to send ten TCP packets with a
source port of 80. The -c flag sets the number of packets to 10. The
-k flag causes the source port to remain steady at 80 instead of incrementing.
The -d flag sets the packet size.
The destination IP address of 172.16.80.1 represents a user that is downstream of Device R2. The user has requested a web page from the host (the web server emulated by the traffic generator), and the packets are sent in response to the request.
Note: In this example the policer numbers are reduced to a bandwidth limit of 8 kbps and a burst size limit of 1500 KBps to ensure that some packets are dropped.
[root@host]# hping 172.16.80.1 -c 10 -s 80 -k -d 300
[root@host# hping 172.16.80.1 -c 10 -s 80 -k -d 300 HPING 172.16.80.1 (eth1 172.16.80.1): NO FLAGS are set, 40 headers + 300 data bytes . . . --- 172.16.80.1 hping statistic --- 10 packets transmitted, 7 packets received, 30% packet loss round-trip min/avg/max = 0.4/4572.7/8001.8 ms
- On Device R1, check the firewall counters using the show firewall command.
user@R1> show firewall
Filter: srtcp-http-in Policers: Name Bytes Packets srtcp-http-discard-t1 1020 3
Meaning
In Steps 1 and 2 the output from both devices shows that 3 packets were discarded This means that there was at least 8 kbps of green (in-contract HTTP port 80) traffic and the 1500 KBps burst option for red out-of-contract HTTP port 80 traffic was exceeded.