Skip to content

Add an socket option to set type of service to set specific precedence for QoS #13671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 18, 2020

Conversation

balajicyp
Copy link
Contributor

Summary of changes

Add an socket option to set the IP type of service to set specific precedence for Quality of Service.
This change is required to send traffic apart from Best Effort on an Socket.

Impact of changes

Migration actions required

Documentation


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


@mergify mergify bot added the needs: work label Sep 25, 2020
@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Sep 25, 2020
@ciarmcom ciarmcom requested a review from a team September 25, 2020 22:30
@ciarmcom
Copy link
Member

@balajicyp, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.

@0xc0170 0xc0170 requested a review from a team September 29, 2020 12:03
@0xc0170
Copy link
Contributor

0xc0170 commented Sep 29, 2020

@pan- can you review?

0xc0170
0xc0170 previously approved these changes Sep 30, 2020
@mergify mergify bot added needs: CI and removed needs: review labels Sep 30, 2020
@adbridge
Copy link
Contributor

@pan- bump

pan-
pan- previously requested changes Oct 12, 2020
Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the submission @balajicyp.

The current PR is specific to LwIP and relies on internal of LwIP. However type of service is common socket feature.
I'd like to see parameter definitions in nsapi_types.h like it is done with nsapi_ip_mreq_t and the NSAPI_ADD_MEMBERSHIP/NSAPI_DROP_MEMBERSHIP options so it can be used by other stacks.

@@ -664,6 +664,12 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
return err_remap(igmp_err);
}

case NSAPI_IPTOS:
if (optlen != sizeof(int)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need an int ? What are the expected values ?

Copy link
Contributor Author

@balajicyp balajicyp Oct 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pan-

The IPTOS ( is a field an IP header field ) of 8 bits ( with 6 bits (DSCP) + 2 bits (ECN)). The typical values of these used Priority differentiation following the RFC 791 https://tools.ietf.org/html/rfc791

  Bits 0-2:  Precedence.
  Bit    3:  0 = Normal Delay,      1 = Low Delay.
  Bits   4:  0 = Normal Throughput, 1 = High Throughput.
  Bits   5:  0 = Normal Relibility, 1 = High Relibility.
  Bit  6-7:  Reserved for Future Use.

       0     1     2     3     4     5     6     7
  +-----+-----+-----+-----+-----+-----+-----+-----+
  |                 |     |     |     |     |     |
  |   PRECEDENCE    |  D  |  T  |  R  |  0  |  0  |
  |                 |     |     |     |     |     |
  +-----+-----+-----+-----+-----+-----+-----+-----+

This is used to prioritize Traffic class in transmit direction and the following are the values used

uint32_t tos_priority[4] = { 0x00, 0x40, 0xA0, 0xE0 }; // Best Effort, Background, Video, Voice

Regarding add it as nsapi_types.h , please can give more information, I know that NSAPI_ADD_MEMBERSHIP/NSAPI_DROP_MEMBERSHIP is only used for muliticast traffic and how I should add, the following is used for unicast traffic.

Thanks
Balaji.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@balajicyp that doesn't really answer the question of why do we need an int as a single byte is required to code all the values.

For the options what I'd like to see is a list of these flags in NSAPI. Something similar to what is presented in LwIP:

/*
* The Type of Service provides an indication of the abstract
* parameters of the quality of service desired. These parameters are
* to be used to guide the selection of the actual service parameters
* when transmitting a datagram through a particular network. Several
* networks offer service precedence, which somehow treats high
* precedence traffic as more important than other traffic (generally
* by accepting only traffic above a certain precedence at time of high
* load). The major choice is a three way tradeoff between low-delay,
* high-reliability, and high-throughput.
* The use of the Delay, Throughput, and Reliability indications may
* increase the cost (in some sense) of the service. In many networks
* better performance for one of these parameters is coupled with worse
* performance on another. Except for very unusual cases at most two
* of these three indications should be set.
*/
#define IPTOS_TOS_MASK 0x1E
#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
#define IPTOS_LOWDELAY 0x10
#define IPTOS_THROUGHPUT 0x08
#define IPTOS_RELIABILITY 0x04
#define IPTOS_LOWCOST 0x02
#define IPTOS_MINCOST IPTOS_LOWCOST
/*
* The Network Control precedence designation is intended to be used
* within a network only. The actual use and control of that
* designation is up to each network. The Internetwork Control
* designation is intended for use by gateway control originators only.
* If the actual use of these precedence designations is of concern to
* a particular network, it is the responsibility of that network to
* control the access to, and use of, those precedence designations.
*/
#define IPTOS_PREC_MASK 0xe0
#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
#define IPTOS_PREC_NETCONTROL 0xe0
#define IPTOS_PREC_INTERNETCONTROL 0xc0
#define IPTOS_PREC_CRITIC_ECP 0xa0
#define IPTOS_PREC_FLASHOVERRIDE 0x80
#define IPTOS_PREC_FLASH 0x60
#define IPTOS_PREC_IMMEDIATE 0x40
#define IPTOS_PREC_PRIORITY 0x20
#define IPTOS_PREC_ROUTINE 0x00

The goal is to not let the user guess what can be used or hardcode these values. Other stacks may it should be clear what values are expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pan-

I have added the NSAPI type defines for Type of Service similar to mbed-os/connectivity/lwipstack/lwip/src/include/lwip/sockets.h (line 347 to 389).

I have fixed optlen check to u8_t

Please review them

Thanks
Balaji.

@mergify mergify bot added needs: work and removed needs: CI labels Oct 12, 2020
@mergify mergify bot dismissed stale reviews from 0xc0170 and pan- October 12, 2020 20:10

Pull request has been modified.

@mergify mergify bot added needs: CI and removed needs: work labels Nov 6, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented Nov 10, 2020

CI started

@mergify mergify bot added needs: work and removed needs: CI labels Nov 10, 2020
@mbed-ci
Copy link

mbed-ci commented Nov 10, 2020

Jenkins CI Test : ❌ FAILED

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM
jenkins-ci/mbed-os-ci_cmake-example-ARM

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 16, 2020

CI errors unrelated, we are fixing CI targets that started to have issues, will rerun CI once it's all fixed.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 17, 2020

CI restarted

@mbed-ci
Copy link

mbed-ci commented Nov 18, 2020

Jenkins CI Test : ✔️ SUCCESS

Build Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_dynamic-memory-usage ✔️
jenkins-ci/mbed-os-ci_cloud-client-pytest ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️

@0xc0170 0xc0170 merged commit 1bd5ce6 into ARMmbed:master Nov 18, 2020
@mergify mergify bot removed the ready for merge label Nov 18, 2020
@mbedmain mbedmain added release-version: 6.5.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants