Skip to content

Commit 61de1b6

Browse files
Make protocol number import dynamic update via flatbot (#494)
1 parent 99315cb commit 61de1b6

File tree

5 files changed

+397
-131
lines changed

5 files changed

+397
-131
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
name: "Protocol-Number-Updates"
3+
4+
on: # yamllint disable-line rule:truthy
5+
schedule:
6+
- cron: "0 2 1 * *"
7+
8+
jobs:
9+
data_gathering:
10+
runs-on: "ubuntu-latest"
11+
env:
12+
BRANCH_NAME: "PROTO_NUM_Updates"
13+
steps:
14+
# Checkout repo
15+
- name: "Check out code"
16+
uses: "actions/checkout@v2"
17+
with:
18+
ref: "develop"
19+
# Delete old branch if it exists
20+
- name: "Delete existing branch"
21+
run: "git branch -D $BRANCH_NAME || true"
22+
# Create branch for Flatbot
23+
- name: "Create Flatbot branch"
24+
run: "git checkout -b $BRANCH_NAME"
25+
# Push new branch so Flatbot can make its commit
26+
- name: "Push Flatbot branch"
27+
run: "git push -f --set-upstream origin $BRANCH_NAME"
28+
# Install Black
29+
- name: "Install Python Black"
30+
run: "pip install black"
31+
# This step installs Deno, which is a new Javascript runtime that improves on Node. Can be used for an optional postprocessing step
32+
- name: "Setup deno"
33+
uses: "denoland/setup-deno@main"
34+
with:
35+
deno-version: "v1.10.x"
36+
# The Flat Action step. We fetch the data in the http_url and save it as downloaded_filename
37+
- name: "Fetch data"
38+
uses: "githubocto/flat@v3"
39+
with:
40+
http_url: "https://www.iana.org/assignments/protocol-numbers/protocol-numbers-1.csv"
41+
downloaded_filename: "./netutils/data_files/protocol_number_mappings.py"
42+
postprocess: "./flat_postprocess/protocol_number_postprocess.ts"
43+
pr_creation:
44+
runs-on: "ubuntu-latest"
45+
needs: "data_gathering"
46+
steps:
47+
# Checkout repo
48+
- name: "Check out code"
49+
uses: "actions/checkout@v2"
50+
with:
51+
ref: "PROTO_NUM_Updates"
52+
# Create PR from branch created above into develop
53+
- name: "Create a Pull Request"
54+
run: "gh pr create -B develop -H PROTO_NUM_Updates --title 'Flatbot PROTOCOL Number File Updates' --body 'Created by Flatbot action'"
55+
env:
56+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Python code used to postprocess Flat github action data related to Protocol mappings."""
2+
import csv
3+
import os
4+
import sys
5+
from urllib.request import urlopen
6+
7+
8+
if __name__ == "__main__":
9+
if len(sys.argv) == 2:
10+
URL = "https://www.iana.org/assignments/protocol-numbers/protocol-numbers-1.csv"
11+
oui_textfile = urlopen(URL).read().decode("utf-8") # nosec: pylint: disable=consider-using-with
12+
with open(sys.argv[1], "w", encoding="utf-8") as proto_mappings:
13+
proto_mappings.write(oui_textfile)
14+
15+
protocol_mapping = {}
16+
reverse_mapping = {}
17+
with open(sys.argv[1], encoding="utf-8") as file:
18+
next(file)
19+
reader = csv.reader(file)
20+
for row in reader:
21+
number = row[0]
22+
name = row[1]
23+
if not number.isnumeric():
24+
continue
25+
if not name:
26+
continue
27+
name = name.replace(" (deprecated)", "")
28+
protocol_mapping[name] = int(number)
29+
reverse_mapping[int(number)] = name
30+
31+
with open(sys.argv[1], "w", encoding="utf-8") as proto_mappings:
32+
proto_mappings.write('"""Dictionary object to store Protocol Number."""\n')
33+
proto_mappings.write("from typing import Dict\n")
34+
proto_mappings.write(f"PROTO_NAME_TO_NUM: Dict[str, int] = {protocol_mapping}")
35+
proto_mappings.write("\n")
36+
proto_mappings.write(f"PROTO_NUM_TO_NAME: Dict[int, str] = {reverse_mapping}")
37+
38+
os.system(f"black {sys.argv[1]}") # nosec
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Forwards the execution to the python script
2+
const py_run = Deno.run({
3+
// Run `python ./flat_postprocess/protocol_number_postprocess.py netutils/data_files/protocol_number_mappings.py` to test locally.
4+
cmd: ["python", "./flat_postprocess/protocol_number_postprocess.py"].concat(Deno.args),
5+
});
6+
7+
await py_run.status();
Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
"""Dictionary object to store Protocol Number."""
2+
from typing import Dict
3+
4+
PROTO_NAME_TO_NUM: Dict[str, int] = {
5+
"HOPOPT": 0,
6+
"ICMP": 1,
7+
"IGMP": 2,
8+
"GGP": 3,
9+
"IPv4": 4,
10+
"ST": 5,
11+
"TCP": 6,
12+
"CBT": 7,
13+
"EGP": 8,
14+
"IGP": 9,
15+
"BBN-RCC-MON": 10,
16+
"NVP-II": 11,
17+
"PUP": 12,
18+
"ARGUS": 13,
19+
"EMCON": 14,
20+
"XNET": 15,
21+
"CHAOS": 16,
22+
"UDP": 17,
23+
"MUX": 18,
24+
"DCN-MEAS": 19,
25+
"HMP": 20,
26+
"PRM": 21,
27+
"XNS-IDP": 22,
28+
"TRUNK-1": 23,
29+
"TRUNK-2": 24,
30+
"LEAF-1": 25,
31+
"LEAF-2": 26,
32+
"RDP": 27,
33+
"IRTP": 28,
34+
"ISO-TP4": 29,
35+
"NETBLT": 30,
36+
"MFE-NSP": 31,
37+
"MERIT-INP": 32,
38+
"DCCP": 33,
39+
"3PC": 34,
40+
"IDPR": 35,
41+
"XTP": 36,
42+
"DDP": 37,
43+
"IDPR-CMTP": 38,
44+
"TP++": 39,
45+
"IL": 40,
46+
"IPv6": 41,
47+
"SDRP": 42,
48+
"IPv6-Route": 43,
49+
"IPv6-Frag": 44,
50+
"IDRP": 45,
51+
"RSVP": 46,
52+
"GRE": 47,
53+
"DSR": 48,
54+
"BNA": 49,
55+
"ESP": 50,
56+
"AH": 51,
57+
"I-NLSP": 52,
58+
"SWIPE": 53,
59+
"NARP": 54,
60+
"Min-IPv4": 55,
61+
"TLSP": 56,
62+
"SKIP": 57,
63+
"IPv6-ICMP": 58,
64+
"IPv6-NoNxt": 59,
65+
"IPv6-Opts": 60,
66+
"CFTP": 62,
67+
"SAT-EXPAK": 64,
68+
"KRYPTOLAN": 65,
69+
"RVD": 66,
70+
"IPPC": 67,
71+
"SAT-MON": 69,
72+
"VISA": 70,
73+
"IPCV": 71,
74+
"CPNX": 72,
75+
"CPHB": 73,
76+
"WSN": 74,
77+
"PVP": 75,
78+
"BR-SAT-MON": 76,
79+
"SUN-ND": 77,
80+
"WB-MON": 78,
81+
"WB-EXPAK": 79,
82+
"ISO-IP": 80,
83+
"VMTP": 81,
84+
"SECURE-VMTP": 82,
85+
"VINES": 83,
86+
"IPTM": 84,
87+
"NSFNET-IGP": 85,
88+
"DGP": 86,
89+
"TCF": 87,
90+
"EIGRP": 88,
91+
"OSPFIGP": 89,
92+
"Sprite-RPC": 90,
93+
"LARP": 91,
94+
"MTP": 92,
95+
"AX.25": 93,
96+
"IPIP": 94,
97+
"MICP": 95,
98+
"SCC-SP": 96,
99+
"ETHERIP": 97,
100+
"ENCAP": 98,
101+
"GMTP": 100,
102+
"IFMP": 101,
103+
"PNNI": 102,
104+
"PIM": 103,
105+
"ARIS": 104,
106+
"SCPS": 105,
107+
"QNX": 106,
108+
"A/N": 107,
109+
"IPComp": 108,
110+
"SNP": 109,
111+
"Compaq-Peer": 110,
112+
"IPX-in-IP": 111,
113+
"VRRP": 112,
114+
"PGM": 113,
115+
"L2TP": 115,
116+
"DDX": 116,
117+
"IATP": 117,
118+
"STP": 118,
119+
"SRP": 119,
120+
"UTI": 120,
121+
"SMP": 121,
122+
"SM": 122,
123+
"PTP": 123,
124+
"ISIS over IPv4": 124,
125+
"FIRE": 125,
126+
"CRTP": 126,
127+
"CRUDP": 127,
128+
"SSCOPMCE": 128,
129+
"IPLT": 129,
130+
"SPS": 130,
131+
"PIPE": 131,
132+
"SCTP": 132,
133+
"FC": 133,
134+
"RSVP-E2E-IGNORE": 134,
135+
"Mobility Header": 135,
136+
"UDPLite": 136,
137+
"MPLS-in-IP": 137,
138+
"manet": 138,
139+
"HIP": 139,
140+
"Shim6": 140,
141+
"WESP": 141,
142+
"ROHC": 142,
143+
"Ethernet": 143,
144+
"AGGFRAG": 144,
145+
"NSH": 145,
146+
"Reserved": 255,
147+
}
148+
149+
PROTO_NUM_TO_NAME: Dict[int, str] = {
150+
0: "HOPOPT",
151+
1: "ICMP",
152+
2: "IGMP",
153+
3: "GGP",
154+
4: "IPv4",
155+
5: "ST",
156+
6: "TCP",
157+
7: "CBT",
158+
8: "EGP",
159+
9: "IGP",
160+
10: "BBN-RCC-MON",
161+
11: "NVP-II",
162+
12: "PUP",
163+
13: "ARGUS",
164+
14: "EMCON",
165+
15: "XNET",
166+
16: "CHAOS",
167+
17: "UDP",
168+
18: "MUX",
169+
19: "DCN-MEAS",
170+
20: "HMP",
171+
21: "PRM",
172+
22: "XNS-IDP",
173+
23: "TRUNK-1",
174+
24: "TRUNK-2",
175+
25: "LEAF-1",
176+
26: "LEAF-2",
177+
27: "RDP",
178+
28: "IRTP",
179+
29: "ISO-TP4",
180+
30: "NETBLT",
181+
31: "MFE-NSP",
182+
32: "MERIT-INP",
183+
33: "DCCP",
184+
34: "3PC",
185+
35: "IDPR",
186+
36: "XTP",
187+
37: "DDP",
188+
38: "IDPR-CMTP",
189+
39: "TP++",
190+
40: "IL",
191+
41: "IPv6",
192+
42: "SDRP",
193+
43: "IPv6-Route",
194+
44: "IPv6-Frag",
195+
45: "IDRP",
196+
46: "RSVP",
197+
47: "GRE",
198+
48: "DSR",
199+
49: "BNA",
200+
50: "ESP",
201+
51: "AH",
202+
52: "I-NLSP",
203+
53: "SWIPE",
204+
54: "NARP",
205+
55: "Min-IPv4",
206+
56: "TLSP",
207+
57: "SKIP",
208+
58: "IPv6-ICMP",
209+
59: "IPv6-NoNxt",
210+
60: "IPv6-Opts",
211+
62: "CFTP",
212+
64: "SAT-EXPAK",
213+
65: "KRYPTOLAN",
214+
66: "RVD",
215+
67: "IPPC",
216+
69: "SAT-MON",
217+
70: "VISA",
218+
71: "IPCV",
219+
72: "CPNX",
220+
73: "CPHB",
221+
74: "WSN",
222+
75: "PVP",
223+
76: "BR-SAT-MON",
224+
77: "SUN-ND",
225+
78: "WB-MON",
226+
79: "WB-EXPAK",
227+
80: "ISO-IP",
228+
81: "VMTP",
229+
82: "SECURE-VMTP",
230+
83: "VINES",
231+
84: "IPTM",
232+
85: "NSFNET-IGP",
233+
86: "DGP",
234+
87: "TCF",
235+
88: "EIGRP",
236+
89: "OSPFIGP",
237+
90: "Sprite-RPC",
238+
91: "LARP",
239+
92: "MTP",
240+
93: "AX.25",
241+
94: "IPIP",
242+
95: "MICP",
243+
96: "SCC-SP",
244+
97: "ETHERIP",
245+
98: "ENCAP",
246+
100: "GMTP",
247+
101: "IFMP",
248+
102: "PNNI",
249+
103: "PIM",
250+
104: "ARIS",
251+
105: "SCPS",
252+
106: "QNX",
253+
107: "A/N",
254+
108: "IPComp",
255+
109: "SNP",
256+
110: "Compaq-Peer",
257+
111: "IPX-in-IP",
258+
112: "VRRP",
259+
113: "PGM",
260+
115: "L2TP",
261+
116: "DDX",
262+
117: "IATP",
263+
118: "STP",
264+
119: "SRP",
265+
120: "UTI",
266+
121: "SMP",
267+
122: "SM",
268+
123: "PTP",
269+
124: "ISIS over IPv4",
270+
125: "FIRE",
271+
126: "CRTP",
272+
127: "CRUDP",
273+
128: "SSCOPMCE",
274+
129: "IPLT",
275+
130: "SPS",
276+
131: "PIPE",
277+
132: "SCTP",
278+
133: "FC",
279+
134: "RSVP-E2E-IGNORE",
280+
135: "Mobility Header",
281+
136: "UDPLite",
282+
137: "MPLS-in-IP",
283+
138: "manet",
284+
139: "HIP",
285+
140: "Shim6",
286+
141: "WESP",
287+
142: "ROHC",
288+
143: "Ethernet",
289+
144: "AGGFRAG",
290+
145: "NSH",
291+
255: "Reserved",
292+
}

0 commit comments

Comments
 (0)