Last active
August 23, 2020 14:49
-
-
Save ubaumann/77de4820870274859683de5330217907 to your computer and use it in GitHub Desktop.
Create this table with python: https://www.bytesolutions.com/dscp-tos-cos-presidence-conversion-chart/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import csv | |
| def dscp_class(dec): | |
| if dec == 46: | |
| return "ef" | |
| major_class = dec >> 3 | |
| drop_preference = dec >> 1 & 3 | |
| if drop_preference == 0: | |
| return f"cs{major_class}" | |
| return f"af{major_class}{drop_preference}" | |
| dscp_dec = [0] + list(range(8, 42, 2)) + [46, 48, 56] | |
| tos_string = ( | |
| ["Best Effort"] | |
| + ["Priority"] * 4 | |
| + ["Immediate"] * 4 | |
| + ["Flash"] * 4 | |
| + ["FlashOverride"] * 4 | |
| + ["Critical"] * 2 | |
| + ["Internetworkcontrol", "Networkcontrol"] | |
| ) | |
| with open("dscp.csv", "w") as csvfile: | |
| dscp_writer = csv.writer(csvfile) | |
| dscp_writer.writerow( | |
| [f"DSCP {n}" for n in ["Class", "(bin)", "(hex)", "(dec)"]] | |
| + [ | |
| f"ToS {n}" | |
| for n in [ | |
| "(dec)", | |
| "(hex)", | |
| "(bin)", | |
| "Prec. (bin)", | |
| "Prec. (dec)", | |
| "Delay Flag", | |
| "Throghput Flag", | |
| "Reliability Flag", | |
| "String Format", | |
| ] | |
| ] | |
| ) | |
| for dec, description in zip(dscp_dec, tos_string): | |
| tos_dec = dec * 4 | |
| tos_prec = tos_dec >> 5 | |
| dscp_writer.writerow( | |
| [ | |
| dscp_class(dec), # DSCP Class | |
| f"{dec:06b}", # DSCP (bin) | |
| f"0x{dec:02X}", # DSCP (hex) | |
| dec, # DSCP (dec) | |
| tos_dec, # ToS (dec) | |
| f"0x{tos_dec:02X}", # ToS (hex) | |
| f"{tos_dec:08b}", # ToS (bin) | |
| f"{tos_prec:03b}", # ToS Prec. (bin) | |
| tos_prec, # ToS Prec. (dec) | |
| tos_dec >> 4 & 1, # ToS Delay Flag | |
| tos_dec >> 3 & 1, # ToS Throghput Flag | |
| tos_dec >> 2 & 1, # ToS Reliability Flag | |
| description, # ToS String Format | |
| ] | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment