Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?


Example: Limiting Egress Traffic on an Interface Using Port Shaping for CoS

This example shows how using port shaping as a form of class of service (CoS) enables you to limit traffic on an interface, so that you can control the amount of traffic passing through the interface.


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.


The purpose of this example is to demonstrate how port shaping enables you to shape the traffic passing through an interface to a rate that is less than the line rate for that interface. When you configure port shaping on an interface, you are essentially specifying a value that indicates the maximum amount of traffic that can pass through the interface. This value must be less than the maximum bandwidth for that interface. When you configure port shaping, you can specify either the maximum rate at which traffic can pass through the interface or as a percentage of the bandwidth of the interface.

In this example the port shaping is done on Device R1. The information required for implementing port shaping on Device R2 is not included in this example. However, you can use the port shaping information in Device R1 (making changes for the interfaces used) and apply it to Device R2 to achieve port shaping on Device R2.


This example uses the topology in Figure 1.

Figure 1: Port Shaping ScenarioPort Shaping Scenario



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 Using Only Class of Service

Device R1 Using Traffic Control Profiles and Class of Service

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 Junos OS CLI User Guide.

You can configure port shaping on network interfaces, aggregated Ethernet interfaces (also known as link aggregation groups (LAGs)), and loopback interfaces.

To configure Device R1:

  1. Configure the device interfaces.

  2. Configure port shaping using only class of service.

  3. Configure port shaping using traffic control profiles and class of service.


    If you configure a fixed shaping rate, you can configure an optional burst size in bytes. If you configure the shaping rate as a percentage, the burst-size option is not allowed.

  4. Configure OSPF.

Step-by-Step Procedure

To configure Device R2:

  1. Configure the device interfaces.

  2. Configure OSPF.


From configuration mode, confirm your configuration by entering the show interfaces , show class-of-service, and show protocols ospf commands. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.

Results for R1

Configuring Port Shaping Using only Class-of-Service

Configuring Port Shaping Using Traffic Control Profiles and Class of Service

If you are done configuring Device R1, enter commit from configuration mode.

Results for R2

If you are done configuring Device R2, enter commit from configuration mode.


Confirm that the configuration is working properly.

Clearing the Counters


Confirm that the interface counters are cleared.


On Device R1, run the clear interfaces statistics ge-2/0/8 command to reset the interface statistics to 0.

Sending TCP Traffic into the Network and Monitoring the Port Shaping


Make sure that the traffic is rate-limited on the output interface (ge-2/0/8) on Device R1 by sending traffic into the network using the host connected to Device R1.


  1. Use a traffic generator to send several continuous streams of TCP packets with a source port of 80.

    The -s flag sets the source port. The -k flag causes the source port to remain steady at 80 instead of incrementing. The -d flag sets the packet size. The -c flag sets the packet count to be sent.

    The destination IP address of represents a user that is downstream of Device R2. The user has requested a webpage from the host (the webserver emulated by the traffic generator), and the packets are sent in response to the request.


    Remember in this example the port shaping has been set to 160 Kbps.

  2. On Device R1, check the interface counters by using the show interfaces extensive ge-2/0/8 command.


In the output you can see that 13470 packets have been dropped. These are the packets that exceeded the 160 Kbps shaping rate configured on ge-2/0/8.