diff options
Diffstat (limited to 'six/participant.go')
-rw-r--r-- | six/participant.go | 224 |
1 files changed, 224 insertions, 0 deletions
diff --git a/six/participant.go b/six/participant.go new file mode 100644 index 0000000..e8150bb --- /dev/null +++ b/six/participant.go | |||
@@ -0,0 +1,224 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0-only | ||
2 | // Copyright (C) 2020 Michael Crute <mike@crute.us>. All rights reserved. | ||
3 | // | ||
4 | // Use of this source code is governed by a license that can be found in the | ||
5 | // LICENSE file. | ||
6 | |||
7 | package six | ||
8 | |||
9 | import ( | ||
10 | "net" | ||
11 | "time" | ||
12 | ) | ||
13 | |||
14 | // IP protocol version number | ||
15 | type IPVersion int | ||
16 | |||
17 | const ( | ||
18 | IPv6 IPVersion = 6 | ||
19 | IPv4 = 4 | ||
20 | ) | ||
21 | |||
22 | // IPv4 and IPv6 union type, contains a full network for IPv4 and IPv6 | ||
23 | // addresses | ||
24 | type Addresses struct { | ||
25 | IPv4 *net.IPNet | ||
26 | IPv6 *net.IPNet | ||
27 | } | ||
28 | |||
29 | // IRR statistical data. Contains the counts of various IRR data for a | ||
30 | // participant. | ||
31 | type IRRData struct { | ||
32 | PrefixCount int | ||
33 | ASNCount int | ||
34 | ASSetCount int | ||
35 | } | ||
36 | |||
37 | // Set of prefixes, optionally with an AS-SET name that a participant has | ||
38 | // registered with the exchange. | ||
39 | type PrefixSet struct { | ||
40 | Timestamp time.Time | ||
41 | ASSet *string | ||
42 | Prefixes []net.IPNet | ||
43 | } | ||
44 | |||
45 | // Set of AS numbers with an AS-SET that the participant has registered with | ||
46 | // the exchange. | ||
47 | type ASSet struct { | ||
48 | Timestamp time.Time | ||
49 | Name string | ||
50 | ASNumbers []int | ||
51 | } | ||
52 | |||
53 | // Set of ROA record summaries that have been parsed from the raw ROA data for | ||
54 | // a participant. | ||
55 | type ROASet struct { | ||
56 | Timestamp time.Time | ||
57 | ROAS []ROA | ||
58 | } | ||
59 | |||
60 | // Individual ROA summary | ||
61 | type ROA struct { | ||
62 | TrustAnchor string | ||
63 | ASN int | ||
64 | MaxLength int | ||
65 | Prefix net.IPNet | ||
66 | } | ||
67 | |||
68 | // A SIX participant is a record of an organization's connection to the Seattle | ||
69 | // Internet Exchange. It contains information about their connect, the prefixes | ||
70 | // and ASes that they have registered with the exchange, and their usage of the | ||
71 | // route server. | ||
72 | // | ||
73 | // Not all data exists for all participants, and the data that does exist isn't | ||
74 | // always in a nice clean format. The parsers attempt to make sense of whatever | ||
75 | // is available but some data may be missing or inconsistent. | ||
76 | // | ||
77 | // The default contains summary data for the participant and more detailed data | ||
78 | // can be fetched with the methods attached to this struct as well as to the | ||
79 | // RouteServer structs, if the participant is using the route server. | ||
80 | type SIXParticipant struct { | ||
81 | Organization string | ||
82 | URL string | ||
83 | ASN int | ||
84 | Speed int // Connection speed in Mbit/s | ||
85 | Switch string // Connected Switch or Location | ||
86 | Contact string // Contact Email | ||
87 | Comment string | ||
88 | IsConnected bool | ||
89 | IsVoter bool | ||
90 | Update *time.Time | ||
91 | Options []string // Currently: IPv6 and MTU9k | ||
92 | PeeringPolicy string | ||
93 | ROACount int | ||
94 | PeeringDBPrefixCountv4 int | ||
95 | PeeringDBPrefixCountv6 int | ||
96 | Addresses Addresses | ||
97 | JumboAddresses *Addresses | ||
98 | IRRv4 IRRData | ||
99 | IRRv6 IRRData | ||
100 | RouteServer2 *RouteServer | ||
101 | RouteServer3 *RouteServer | ||
102 | } | ||
103 | |||
104 | // Get the set of prefixes that the participant has registered. | ||
105 | // | ||
106 | // This does an HTTP fetch to get the detailed file. | ||
107 | func (p *SIXParticipant) GetPrefixes(ip IPVersion) (*PrefixSet, error) { | ||
108 | return fetchParsePrefixList(p.ASN, ip, false) | ||
109 | } | ||
110 | |||
111 | // Get the prefix to AS associations that the participant has registered. | ||
112 | // | ||
113 | // This does an HTTP fetch to get the detailed file. | ||
114 | func (p *SIXParticipant) GetASPrefixes(ip IPVersion) (*PrefixSet, error) { | ||
115 | return fetchParsePrefixList(p.ASN, ip, true) | ||
116 | } | ||
117 | |||
118 | // Get the AS sets that the participant has registered | ||
119 | // | ||
120 | // This does an HTTP fetch to get the detailed file. | ||
121 | func (p *SIXParticipant) GetASSet(ip IPVersion) (*ASSet, error) { | ||
122 | return fetchParseASSet(p.ASN, ip) | ||
123 | } | ||
124 | |||
125 | // Get the ROA set and more detailed records for the ROAs that the participant | ||
126 | // has registered. This does not fetch the raw ROAs, just the summary that the | ||
127 | // exchange has computed. | ||
128 | // | ||
129 | // This does an HTTP fetch to get the detailed file. | ||
130 | func (p *SIXParticipant) GetROASet() (*ROASet, error) { | ||
131 | return fetchParseROAFile(p.ASN) | ||
132 | } | ||
133 | |||
134 | // List of lines from the file containing route data dumped from the route | ||
135 | // server | ||
136 | type RouteFile struct { | ||
137 | Timestamp time.Time | ||
138 | Lines []string | ||
139 | } | ||
140 | |||
141 | // Lists of errors that the route server has exported. These are parsed for | ||
142 | // more details if possible, but if that fails the attached ErrorRecords object | ||
143 | // contains a list of un-parsable lines for consumption. | ||
144 | type Errors struct { | ||
145 | IPv4 *ErrorRecords | ||
146 | IPv6 *ErrorRecords | ||
147 | IPv4Jumbo *ErrorRecords | ||
148 | IPv6Jumbo *ErrorRecords | ||
149 | } | ||
150 | |||
151 | // List of error records for route server errors. Also contains a list of lines | ||
152 | // that could not be parsed by the parser. | ||
153 | type ErrorRecords struct { | ||
154 | Records []ErrorRecord | ||
155 | UnparsableLines []string | ||
156 | } | ||
157 | |||
158 | // Create a new ErrorRecords struct | ||
159 | func NewErrorRecords() *ErrorRecords { | ||
160 | return &ErrorRecords{ | ||
161 | Records: []ErrorRecord{}, | ||
162 | UnparsableLines: []string{}, | ||
163 | } | ||
164 | } | ||
165 | |||
166 | // Contains the parsed data for a route server error. | ||
167 | type ErrorRecord struct { | ||
168 | Timestamp time.Time | ||
169 | ASN int | ||
170 | MTU int | ||
171 | Version IPVersion | ||
172 | NetworkName string | ||
173 | Network net.IPNet | ||
174 | Router net.IP | ||
175 | Path []int | ||
176 | Message string | ||
177 | } | ||
178 | |||
179 | // Data about the participant's connection to a route server. If the | ||
180 | // participant is making use of the route servers this will always contain some | ||
181 | // basic statistics about their connection. More detailed information can be | ||
182 | // obtained by calling the methods attached to this struct. | ||
183 | type RouteServer struct { | ||
184 | Number int | ||
185 | IPv4 RouteServerStats | ||
186 | IPv6 RouteServerStats | ||
187 | IPv4Jumbo RouteServerStats | ||
188 | IPv6Jumbo RouteServerStats | ||
189 | asn int | ||
190 | } | ||
191 | |||
192 | // Route server statistics. Contains the counts of various types of route | ||
193 | // server entries. | ||
194 | type RouteServerStats struct { | ||
195 | Prefixes int | ||
196 | Errors int | ||
197 | TransitErrors int | ||
198 | } | ||
199 | |||
200 | // Gets the list of routes being advertised by the participant. Note that this | ||
201 | // file is the raw lines from the route server and no attempt has been made to | ||
202 | // parse these lines. The lines are in BIRD format. | ||
203 | // | ||
204 | // This does an HTTP fetch to get the detailed file. | ||
205 | func (s *RouteServer) GetRoutes(ip IPVersion, jumbo bool) (*RouteFile, error) { | ||
206 | return fetchParseRoutes(s.Number, s.asn, ip, jumbo) | ||
207 | } | ||
208 | |||
209 | // Gets the errors returned by the route server for all IP protocols and all | ||
210 | // VLANs to which the participant is connected. If the participant is using | ||
211 | // multiple route servers, this data is scoped to the current route server. | ||
212 | // | ||
213 | // This does an HTTP fetch to get the detailed file. | ||
214 | func (s *RouteServer) GetErrors() (*Errors, error) { | ||
215 | return fetchParseRSErrors(s.Number, s.asn, false), nil | ||
216 | } | ||
217 | |||
218 | // Get a list of transit errors from the route server. Otherwise return value | ||
219 | // and behavior is identical to GetErrors. | ||
220 | // | ||
221 | // This does an HTTP fetch to get the detailed file. | ||
222 | func (s *RouteServer) GetTransitErrors() (*Errors, error) { | ||
223 | return fetchParseRSErrors(s.Number, s.asn, true), nil | ||
224 | } | ||