-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
391 lines (273 loc) · 10.5 KB
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
--
-- PostgreSQL database dump
--
-- Dumped from database version 15.5 (Debian 15.5-0+deb12u1)
-- Dumped by pg_dump version 15.5 (Debian 15.5-0+deb12u1)
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: btree_gist; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;
--
-- Name: EXTENSION btree_gist; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION btree_gist IS 'support for indexing common datatypes in GiST';
--
-- Name: split_cidr(cidr, integer); Type: FUNCTION; Schema: public; Owner: apnic
--
CREATE FUNCTION public.split_cidr(net cidr, exc integer) RETURNS SETOF cidr
LANGUAGE plpgsql
AS $$
DECLARE
r cidr;
lower cidr;
upper cidr;
BEGIN
IF masklen(net) > 24 AND family(net) = 4 THEN RETURN; END IF;
IF masklen(net) > 48 AND family(net) = 6 THEN RETURN; END IF;
IF masklen(net) > exc THEN RETURN; END IF;
lower = set_masklen(net, masklen(net)+1);
upper = set_masklen( (lower | ~ netmask(lower)) + 1, masklen(lower));
RETURN NEXT net;
FOR r IN SELECT * from split_cidr(upper, exc)
LOOP RETURN NEXT r;
END LOOP;
FOR r IN SELECT * from split_cidr(lower, exc)
LOOP RETURN NEXT r;
END LOOP;
RETURN;
END $$;
ALTER FUNCTION public.split_cidr(net cidr, exc integer) OWNER TO apnic;
--
-- Name: split_cidr_count(cidr, integer); Type: FUNCTION; Schema: public; Owner: apnic
--
CREATE FUNCTION public.split_cidr_count(net cidr, exc integer) RETURNS bigint
LANGUAGE plpgsql
AS $$
DECLARE
l integer;
ml integer;
BEGIN
ml = masklen(net);
IF family(net) = 4 THEN
if exc > 24 THEN
l = 24 - ml;
ELSE
l = exc - ml;
END IF;
END IF;
IF family(net) = 6 THEN
if exc > 48 THEN
l = 48 - ml;
ELSE
l = exc - ml;
END IF;
END IF;
RETURN (2^(l+1))-1;
END $$;
ALTER FUNCTION public.split_cidr_count(net cidr, exc integer) OWNER TO apnic;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: _geocode_rir_economy; Type: TABLE; Schema: public; Owner: apnic
--
CREATE TABLE public._geocode_rir_economy (
rir text,
economy_iso character varying(2)
);
ALTER TABLE public._geocode_rir_economy OWNER TO apnic;
--
-- Name: _geocode_subnet_data; Type: TABLE; Schema: public; Owner: apnic
--
CREATE TABLE public._geocode_subnet_data (
rir text,
economy_iso character varying(2),
prefix cidr
);
ALTER TABLE public._geocode_subnet_data OWNER TO apnic;
--
-- Name: _route_rpki_subnet_counts; Type: TABLE; Schema: public; Owner: apnic
--
CREATE TABLE public._route_rpki_subnet_counts (
subnet cidr,
maxlen integer,
expanded_count bigint,
routed_count bigint,
rir text,
economy_iso character varying(2)
);
ALTER TABLE public._route_rpki_subnet_counts OWNER TO apnic;
--
-- Name: rpki_signed_routes; Type: TABLE; Schema: public; Owner: apnic
--
CREATE TABLE public.rpki_signed_routes (
"ASN" text,
"IP Prefix" cidr,
"Max Length" integer,
"Trust Anchor" text,
"Expires" bigint
);
ALTER TABLE public.rpki_signed_routes OWNER TO apnic;
--
-- Name: overlapping_signed_routes; Type: MATERIALIZED VIEW; Schema: public; Owner: apnic
--
CREATE MATERIALIZED VIEW public.overlapping_signed_routes AS
SELECT array_agg(DISTINCT a."ASN") AS asns_subnet,
array_agg(DISTINCT b."ASN") AS asns_supernet,
a."IP Prefix" AS subnet,
a."Max Length" AS subnet_maxlen,
b."IP Prefix" AS supernet,
b."Max Length" AS supernet_maxlen
FROM (public.rpki_signed_routes a
JOIN public.rpki_signed_routes b ON ((((a."IP Prefix")::inet << (b."IP Prefix")::inet) AND (masklen((a."IP Prefix")::inet) <= b."Max Length"))))
GROUP BY a."IP Prefix", a."Max Length", b."IP Prefix", b."Max Length"
WITH NO DATA;
ALTER TABLE public.overlapping_signed_routes OWNER TO apnic;
--
-- Name: report_bcp185_by_iso; Type: VIEW; Schema: public; Owner: apnic
--
CREATE VIEW public.report_bcp185_by_iso AS
SELECT _route_rpki_subnet_counts.economy_iso,
sum(_route_rpki_subnet_counts.expanded_count) AS "ROA Coverage",
sum(_route_rpki_subnet_counts.routed_count) AS "Global Routes",
to_char((((100)::double precision * (sum(_route_rpki_subnet_counts.routed_count))::double precision) / (sum(_route_rpki_subnet_counts.expanded_count))::double precision), 'fm000D00%'::text) AS "BCP185 Compliance"
FROM public._route_rpki_subnet_counts
WHERE (_route_rpki_subnet_counts.rir IS NOT NULL)
GROUP BY _route_rpki_subnet_counts.economy_iso
UNION
SELECT 'Global'::character varying AS economy_iso,
sum(_route_rpki_subnet_counts.expanded_count) AS "ROA Coverage",
sum(_route_rpki_subnet_counts.routed_count) AS "Global Routes",
to_char((((100)::double precision * (sum(_route_rpki_subnet_counts.routed_count))::double precision) / (sum(_route_rpki_subnet_counts.expanded_count))::double precision), 'fm000D00%'::text) AS "BCP185 Compliance"
FROM public._route_rpki_subnet_counts;
ALTER TABLE public.report_bcp185_by_iso OWNER TO apnic;
--
-- Name: report_bcp185_by_rir; Type: VIEW; Schema: public; Owner: apnic
--
CREATE VIEW public.report_bcp185_by_rir AS
SELECT _route_rpki_subnet_counts.rir,
sum(_route_rpki_subnet_counts.expanded_count) AS "ROA Coverage",
sum(_route_rpki_subnet_counts.routed_count) AS "Global Routes",
to_char((((100)::double precision * (sum(_route_rpki_subnet_counts.routed_count))::double precision) / (sum(_route_rpki_subnet_counts.expanded_count))::double precision), 'fm00D00%'::text) AS "BCP185 Compliance"
FROM public._route_rpki_subnet_counts
WHERE (_route_rpki_subnet_counts.rir IS NOT NULL)
GROUP BY _route_rpki_subnet_counts.rir
UNION
SELECT 'Global'::text AS rir,
sum(_route_rpki_subnet_counts.expanded_count) AS "ROA Coverage",
sum(_route_rpki_subnet_counts.routed_count) AS "Global Routes",
to_char((((100)::double precision * (sum(_route_rpki_subnet_counts.routed_count))::double precision) / (sum(_route_rpki_subnet_counts.expanded_count))::double precision), 'fm00D00%'::text) AS "BCP185 Compliance"
FROM public._route_rpki_subnet_counts;
ALTER TABLE public.report_bcp185_by_rir OWNER TO apnic;
--
-- Name: report_bcp185_combined; Type: VIEW; Schema: public; Owner: apnic
--
CREATE VIEW public.report_bcp185_combined AS
SELECT _route_rpki_subnet_counts.rir,
_route_rpki_subnet_counts.economy_iso,
sum(_route_rpki_subnet_counts.expanded_count) AS "ROA Coverage",
sum(_route_rpki_subnet_counts.routed_count) AS "Global Routes",
to_char((((100)::double precision * (sum(_route_rpki_subnet_counts.routed_count))::double precision) / (sum(_route_rpki_subnet_counts.expanded_count))::double precision), 'fm000D00%'::text) AS "BCP185 Compliance"
FROM public._route_rpki_subnet_counts
GROUP BY _route_rpki_subnet_counts.rir, _route_rpki_subnet_counts.economy_iso;
ALTER TABLE public.report_bcp185_combined OWNER TO apnic;
--
-- Name: rir_allocations; Type: TABLE; Schema: public; Owner: apnic
--
CREATE TABLE public.rir_allocations (
rir text,
economy_iso character varying(2),
family character varying(4),
prefix inet,
size integer,
allocation_date text,
allocation_status text,
extended text
);
ALTER TABLE public.rir_allocations OWNER TO apnic;
--
-- Name: routes; Type: TABLE; Schema: public; Owner: apnic
--
CREATE TABLE public.routes (
dumptype text,
exported text,
protocol character(1),
nexthop inet,
asn bigint,
prefix cidr,
aspath text,
origin text
);
ALTER TABLE public.routes OWNER TO apnic;
--
-- Name: _geocode_subnet_data_economy_iso_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX _geocode_subnet_data_economy_iso_idx ON public._geocode_subnet_data USING btree (economy_iso);
--
-- Name: _geocode_subnet_data_prefix_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX _geocode_subnet_data_prefix_idx ON public._geocode_subnet_data USING gist (prefix inet_ops);
--
-- Name: _geocode_subnet_data_rir_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX _geocode_subnet_data_rir_idx ON public._geocode_subnet_data USING btree (rir);
--
-- Name: _route_rpki_subnet_counts_economy_iso_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX _route_rpki_subnet_counts_economy_iso_idx ON public._route_rpki_subnet_counts USING btree (economy_iso);
--
-- Name: _route_rpki_subnet_counts_rir_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX _route_rpki_subnet_counts_rir_idx ON public._route_rpki_subnet_counts USING btree (rir);
--
-- Name: _route_rpki_subnet_counts_subnet_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX _route_rpki_subnet_counts_subnet_idx ON public._route_rpki_subnet_counts USING gist (subnet inet_ops);
--
-- Name: allocated_economy_iso_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX allocated_economy_iso_idx ON public.rir_allocations USING btree (economy_iso);
--
-- Name: allocated_prefix_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX allocated_prefix_idx ON public.rir_allocations USING gist (prefix inet_ops);
--
-- Name: allocated_rir_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX allocated_rir_idx ON public.rir_allocations USING btree (rir);
--
-- Name: overlapping_signed_routres_supernet_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX overlapping_signed_routres_supernet_idx ON public.overlapping_signed_routes USING gist (supernet inet_ops);
--
-- Name: routes_prefix_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX routes_prefix_idx ON public.routes USING gist (prefix inet_ops);
--
-- Name: rpki_signed_routes_ASN_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX "rpki_signed_routes_ASN_idx" ON public.rpki_signed_routes USING btree ("ASN");
--
-- Name: rpki_signed_routes_IP Prefix_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX "rpki_signed_routes_IP Prefix_idx" ON public.rpki_signed_routes USING gist ("IP Prefix" inet_ops);
--
-- Name: rpki_signed_routes_Trust Anchor_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX "rpki_signed_routes_Trust Anchor_idx" ON public.rpki_signed_routes USING btree ("Trust Anchor");
--
-- Name: rpki_signed_routes_masklen_idx; Type: INDEX; Schema: public; Owner: apnic
--
CREATE INDEX rpki_signed_routes_masklen_idx ON public.rpki_signed_routes USING btree (masklen(("IP Prefix")::inet));
--
-- PostgreSQL database dump complete
--