Skip to content

Commit

Permalink
showcases: released 'Combining Time-Aware and Credit-Based Shaping' s…
Browse files Browse the repository at this point in the history
…howcase.
  • Loading branch information
adamgeorge309 committed Jul 7, 2023
1 parent 2db3d28 commit 0ed1641
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 39 deletions.
67 changes: 47 additions & 20 deletions showcases/tsn/trafficshaping/cbsandtas/CbsAndTasShowcase.anf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
<input pattern="/inet/showcases/tsn/trafficshaping/cbsandtas/results/General-*.sca"/>
</inputs>
<charts>
<chart createdWith="OMNeT++ 7.0.0.qualifier" icon="icons/full/obj/linechart.png" id="366351528" name="data rate" resultTypes="vector" template="linechart_mpl" type="MATPLOTLIB">
<chart createdWith="OMNeT++ 7.0.0.qualifier" icon="icons/full/obj/linechart.png" id="398527638" name="data rate" resultTypes="vector" template="linechart_mpl" type="MATPLOTLIB">
<script><![CDATA[import math
from omnetpp.scave import results, chart, utils
import os
import sys
# TODO workaround when using omnetpp 6.0 that doesn't yet contain the python path feature
sys.path.append(os.path.join(os.getcwd(), "../../../../python"))
import matplotlib.pyplot as plt
import inet.scave.plot
default_colors = inet.scave.plot.default_colors
# get chart properties
props = chart.get_properties()
Expand All @@ -27,14 +34,34 @@ except results.ResultQueryError as e:
if df.empty:
raise chart.ChartScriptError("The result filter returned no data.")
print(df)
style_tuple_list = [('name', 'incoming.*', {'linestyle': '--'}),
('name', 'outgoing.*', {'linestyle': '-'}),
('module', '.*(app\[0\]|queue\[0\]).*', {'color': default_colors[0]}),
('module', '.*(app\[1\]|queue\[1\]).*', {'color': default_colors[1]})]
# apply vector operations
df = utils.perform_vector_ops(df, props["vector_operations"])
inet.scave.plot.add_to_dataframe(df, style_tuple_list)
# plot
utils.plot_vectors(df, props)
inet.scave.plot_vectors(df, props, global_style={'linewidth': 1})
utils.postconfigure_plot(props)
legend_style = [('shaper incoming', {'linestyle': 'dashed', 'color': 'black'}),
('shaper outgoing', {'linestyle': 'solid', 'color': 'black'}),
('best effort', {'marker': 's', 'linestyle': '', 'color': default_colors[0]}),
('video', {'marker': 's', 'linestyle': '', 'color': default_colors[1]}),
('committed information rate', {'linestyle': 'dashdot', 'color': 'grey'})]
handles, labels = inet.scave.plot.create_custom_legend(props, legend_style, ncols=3)
plt.axhline(y=20.94, color='grey', linestyle='dashdot')
plt.axhline(y=41.84, color='grey', linestyle='dashdot')
utils.export_image_if_needed(props)
utils.export_data_if_needed(df, props)
]]></script>
Expand Down Expand Up @@ -599,23 +626,23 @@ utils.export_data_if_needed(df, props)
<property name="linecolor" value=""/>
<property name="matplotlibrc.figure.facecolor" value=""/>
<property name="legend_prefer_result_titles" value="true"/>
<property name="legend_manual" value=""/>
<property name="yaxis_title" value=""/>
<property name="legend_manual" value="false"/>
<property name="yaxis_title" value="Data rate [Mbps]"/>
<property name="legend_replacements" value=""/>
<property name="title" value="data rate"/>
<property name="title" value="Traffic Shaper Incoming and Outgoing Data Rate"/>
<property name="legend_automatic" value="true"/>
<property name="vector_operations" value=""/>
<property name="vector_operations" value="apply: divide_by(1000000)"/>
<property name="cycle_seed" value="0"/>
<property name="yaxis_log" value="false"/>
<property name="image_export_height" value="4"/>
<property name="image_export_height" value="6"/>
<property name="xaxis_log" value="false"/>
<property name="legend_placement" value="upper right"/>
<property name="data_export_filename" value=""/>
<property name="xaxis_title" value=""/>
<property name="xaxis_title" value="Simulation time [s]"/>
<property name="grid_density" value="Major"/>
<property name="yaxis_min" value=""/>
<property name="image_export_filename" value=""/>
<property name="xaxis_min" value=""/>
<property name="yaxis_min" value="0"/>
<property name="image_export_filename" value="shaper_both"/>
<property name="xaxis_min" value="0"/>
<property name="matplotlibrc.axes.facecolor" value=""/>
<property name="linewidth" value="1.5"/>
<property name="legend_format" value=""/>
Expand All @@ -628,14 +655,14 @@ utils.export_data_if_needed(df, props)
<property name="plt.style" value="default"/>
<property name="legend_show" value="true"/>
<property name="matplotlibrc.legend.shadow" value="false"/>
<property name="simplify" value=""/>
<property name="yaxis_max" value=""/>
<property name="xaxis_max" value=""/>
<property name="image_export_width" value="6"/>
<property name="matplotlibrc" value=""/>
<property name="simplify" value="false"/>
<property name="yaxis_max" value="55"/>
<property name="xaxis_max" value="10"/>
<property name="image_export_width" value="9"/>
<property name="matplotlibrc" value="figure.autolayout : True&#10;savefig.transparent : True"/>
<property name="include_fields" value="false"/>
</chart>
<chart createdWith="OMNeT++ 7.0.0.qualifier" icon="icons/full/obj/linechart.png" id="105148588" name="gate state" resultTypes="vector" template="linechart_separate_mpl" type="MATPLOTLIB">
<chart createdWith="OMNeT++ 7.0.0.qualifier" icon="icons/full/obj/linechart.png" id="790042139" name="gate state" resultTypes="vector" template="linechart_separate_mpl" type="MATPLOTLIB">
<script><![CDATA[import math
import matplotlib.pyplot as plt
from omnetpp.scave import results, chart, utils
Expand Down Expand Up @@ -1269,7 +1296,7 @@ utils.export_data_if_needed(df, props)]]></script>
<property name="matplotlibrc" value=""/>
<property name="include_fields" value="false"/>
</chart>
<chart createdWith="OMNeT++ 7.0.0.qualifier" icon="icons/full/obj/linechart.png" id="740596314" name="number of credits" resultTypes="vector" template="linechart_mpl" type="MATPLOTLIB">
<chart createdWith="OMNeT++ 7.0.0.qualifier" icon="icons/full/obj/linechart.png" id="1934124261" name="number of credits" resultTypes="vector" template="linechart_mpl" type="MATPLOTLIB">
<script><![CDATA[import math
from omnetpp.scave import results, chart, utils
Expand Down Expand Up @@ -1899,7 +1926,7 @@ utils.export_data_if_needed(df, props)
<property name="matplotlibrc" value=""/>
<property name="include_fields" value="false"/>
</chart>
<chart createdWith="OMNeT++ 7.0.0.qualifier" icon="icons/full/obj/linechart.png" id="1028820947" name="queue length" resultTypes="vector" template="linechart_mpl" type="MATPLOTLIB">
<chart createdWith="OMNeT++ 7.0.0.qualifier" icon="icons/full/obj/linechart.png" id="1521539721" name="queue length" resultTypes="vector" template="linechart_mpl" type="MATPLOTLIB">
<script><![CDATA[import math
from omnetpp.scave import results, chart, utils
Expand Down Expand Up @@ -2529,7 +2556,7 @@ utils.export_data_if_needed(df, props)
<property name="matplotlibrc" value=""/>
<property name="include_fields" value="false"/>
</chart>
<chart createdWith="OMNeT++ 7.0.0.qualifier" icon="icons/full/obj/linechart.png" id="21669326" name="combined" resultTypes="vector" template="linechart_separate_mpl" type="MATPLOTLIB">
<chart createdWith="OMNeT++ 7.0.0.qualifier" icon="icons/full/obj/linechart.png" id="1478979375" name="combined" resultTypes="vector" template="linechart_separate_mpl" type="MATPLOTLIB">
<script><![CDATA[import math
import matplotlib.pyplot as plt
from omnetpp.scave import results, chart, utils
Expand Down
103 changes: 90 additions & 13 deletions showcases/tsn/trafficshaping/cbsandtas/doc/index.rst
Original file line number Diff line number Diff line change
@@ -1,40 +1,117 @@
Credit-based Shaper and Time-aware Shaper
=========================================
Combining Time-Aware and Credit-Based Shaping
=============================================

Goals
-----

TODO
INET allows multiple traffic shapers to be used in the same traffic stream. This showcase
demonstrates this option by showing a simple network where credit-based and time-aware shaping
are combined.

.. note:: You might be interested in looking at another showcase, in which multiple traffic shapers are used in different traffic streams: :doc:`/showcases/tsn/trafficshaping/cbsandats/doc/index`.

| INET version: ``4.4``
| Source files location: `inet/showcases/tsn/trafficshaping/cbsandtas <https://github.com/inet-framework/inet/tree/master/showcases/tsn/trafficshaping/cbsandtas>`__
The Model
---------

Here is the network:
Time-aware shapers (TAS) and credit-based shapers (CBS) can be combined by
inserting an :ned:`Ieee8021qTimeAwareShaper` module into an interface, and
setting the queue type to :ned:`Ieee8021qCreditBasedShaper`. The number of
credits in the CBS only changes when the corresponding gate of the TAS
is open.

The Network
+++++++++++

In this demonstration, similarly to the :doc:`/showcases/tsn/trafficshaping/creditbasedshaper/doc/index` showcase, we employ a
:ned:`Ieee8021qTimeAwareShaper` module with two traffic classes. The two traffic classes
are shaped with both CBS and TAS.

.. .. figure:: media/Network.png
There are three network nodes in the network. The client and the server are
:ned:`TsnDevice` modules, and the switch is a :ned:`TsnSwitch` module. The links between them
use 100 Mbps Ethernet links. The client generates two traffic streams,
and transmits them to the switch. In the switch, these streams undergo traffic
shaping, and are transmitted to the server. In the results section, we plot the
traffic in the switch before and after shapers, to see the effects of traffic
shaping.

.. figure:: media/Network.png
:align: center
:width: 100%

Here is the configuration:
Traffic
+++++++

.. Similarly to the other traffic shaping showcases, we want to observe how the
.. shapers change the traffic. When generating packets, we make sure that traffic
.. is only changed significantly in the shapers (i.e. other parts of the network
.. have no significant shaping effects).
We create two sinusoidally changing traffic streams (called ``best effort`` and
``video``) in the ``client``, with an average data rate of 40 and 20 Mbps. The
two streams are terminated in two packet sinks in the ``server``:

.. literalinclude:: ../omnetpp.ini
:start-at: client applications
:end-before: outgoing streams
:language: ini

Stream Identification and Encoding
++++++++++++++++++++++++++++++++++

The two streams have two different traffic classes: best effort and video. The
bridging layer in the client identifies the outgoing packets by their UDP destination port.
The client encodes and the switch decodes the streams using the IEEE 802.1Q PCP
field.

.. literalinclude:: ../omnetpp.ini
:start-at: outgoing streams
:end-before: egress traffic shaping
:language: ini

Traffic Shaping
+++++++++++++++

The traffic shaping takes place in the outgoing network interface of the switch
where both streams pass through. We configure the CBS to limit the data rate of
the best effort stream to ~40 Mbps, and the video stream to ~20 Mbps.
In the time-aware shaper, we configure the gates to be open for 4ms for best effort, and 2ms for video.

Here is the egress traffic shaping configuration:

.. literalinclude:: ../omnetpp.ini
:start-at: egress traffic shaping
:language: ini

Note that the actual committed information rate for CBS is 1/3 and 2/3 of the idle slope values set
here, because the corresponding gates are open for 1/3 and 2/3 of the time.

Packets that are held up by the shapers are stored in the MAC layer subqueues of
the corresponding traffic class.

Results
-------

The following video shows the behavior in Qtenv:
The following chart displays the incoming and outgoing data rate in the
credit-based shapers:

.. video:: media/behavior.mp4
.. figure:: media/shaper_both.png
:align: center
:width: 90%
:width: 100%

Data rate measurement produces a data point after every 100 packet
transmissions, i.e. ~10 ms of continuous transmission. This is the same as the
cycle time of the time-aware shaping (including the periods when the gate is
closed), so ~2.5 open-gate periods for best effort, ~5 for video. Thus, the
fluctuation depends on how many idle periods are counted in a measurement
interval (so the data rate seems to fluctuate between two distinct values).

Here are the simulation results:
The following sequence chart displays packet transmissions for both traffic
categories (blue for best effort, orange for video). We can observe the
time-aware shaping gate schedules:

.. .. figure:: media/results.png
.. figure:: media/seqchart2.png
:align: center
:width: 100%

Expand All @@ -44,5 +121,5 @@ Sources: :download:`omnetpp.ini <../omnetpp.ini>`
Discussion
----------

Use `this <https://github.com/inet-framework/inet/discussions/TODO>`__ page in the GitHub issue tracker for commenting on this showcase.
Use `this <https://github.com/inet-framework/inet/discussions/900>`__ page in the GitHub issue tracker for commenting on this showcase.

31 changes: 25 additions & 6 deletions showcases/tsn/trafficshaping/cbsandtas/omnetpp.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
[General]
network = inet.networks.tsn.TsnLinearNetwork
sim-time-limit = 1s
sim-time-limit = 10s
description = "Traffic shaping using mixed asynchronous and credit-based shapers"

####################
# Flow Configuration
#
# Traffic class Packet interval CBS data rate Channel data rate Priority Shaping
# Best Effort 200us ~41.84Mbps ~42.64Mbps 0 CBS
# Video 400us ~20.92Mbps ~21.32Mbps 4 CBS
#
# Applicaion packet length: 1000B
# Credit based shaper packet lengt: 1046B = 1000B + 8B (UDP) + 20B (IP) + 14B (ETH MAC) + 4B (ETH FCS)
# Credit based shaper data rate: 1046B * 8 / Packet interval
# Channel packet length: 1054B = 1000B (APP) + 8B (UDP) + 20B (IP) + 14B (ETH MAC) + 4B (ETH FCS) + 8B (ETH PHY)
# Channel data rate = (1054B + 12B (IFG)) * 8 / Packet interval
####################

**.displayGateSchedules = true
**.gateFilter = "**.eth[1].**.transmissionGate*"
**.gateScheduleVisualizer.height = 16
**.gateScheduleVisualizer.placementHint = "top"

# client applications
*.client.numApps = 2
*.client.app[*].typename = "UdpSourceApp"
Expand All @@ -11,9 +30,9 @@ description = "Traffic shaping using mixed asynchronous and credit-based shapers
*.client.app[*].io.destAddress = "server"
*.client.app[0].io.destPort = 1000
*.client.app[1].io.destPort = 1001
*.client.app[*].source.packetLength = 1000B - 54B # 42B = 8B (UDP) + 20B (IP) + 14B (ETH MAC) + 4B (ETH FCS) + 8B (ETH PHY)
*.client.app[0].source.productionInterval = exponential(200us) # ~40Mbps
*.client.app[1].source.productionInterval = exponential(400us) # ~20Mbps
*.client.app[*].source.packetLength = 1000B # 42B = 8B (UDP) + 20B (IP) + 14B (ETH MAC) + 4B (ETH FCS) + 8B (ETH PHY)
*.client.app[0].source.productionInterval = replaceUnit(1 / (sin(dropUnit(simTime()) * 3) + 4.5), "ms")
*.client.app[1].source.productionInterval = replaceUnit(1 / (sin(dropUnit(simTime() * 1)) + sin(dropUnit(simTime() * 8)) + 2), "ms")

# server applications
*.server.numApps = 2
Expand Down Expand Up @@ -49,9 +68,9 @@ description = "Traffic shaping using mixed asynchronous and credit-based shapers
*.switch.eth[*].macLayer.queue.*[0].display-name = "best effort"
*.switch.eth[*].macLayer.queue.*[1].display-name = "video"
*.switch.eth[*].macLayer.queue.transmissionSelectionAlgorithm[0].typename = "Ieee8021qCreditBasedShaper"
*.switch.eth[*].macLayer.queue.transmissionSelectionAlgorithm[0].idleSlope = 60Mbps
*.switch.eth[*].macLayer.queue.transmissionSelectionAlgorithm[0].idleSlope = 63.96Mbps # channel data rate * 2/3
*.switch.eth[*].macLayer.queue.transmissionSelectionAlgorithm[1].typename = "Ieee8021qCreditBasedShaper"
*.switch.eth[*].macLayer.queue.transmissionSelectionAlgorithm[1].idleSlope = 60Mbps
*.switch.eth[*].macLayer.queue.transmissionSelectionAlgorithm[1].idleSlope = 63.96Mbps # channel data rate * 1/3
*.switch.eth[*].macLayer.queue.transmissionGate[0].initiallyOpen = true
*.switch.eth[*].macLayer.queue.transmissionGate[1].initiallyOpen = false
*.switch.eth[*].macLayer.queue.transmissionGate[*].durations = [4ms, 2ms]
1 change: 1 addition & 0 deletions showcases/tsn/trafficshaping/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The following showcases demonstrate scheduling and traffic shaping:
creditbasedshaper/doc/index
asynchronousshaper/doc/index
cbsandats/doc/index
cbsandtas/doc/index
underthehood/doc/index

.. cbsandtas/doc/index
Expand Down

0 comments on commit 0ed1641

Please sign in to comment.