Skip to content

Commit a9bc023

Browse files
committed
rm single export cases and ignore it
1 parent d593a9a commit a9bc023

File tree

9 files changed

+53
-121
lines changed

9 files changed

+53
-121
lines changed

route_verification/bgp/src/cmp.rs

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ impl Compare {
6262
/// Check `self` against RPSL policy `query` and generate reports.
6363
/// Depending on which [`Verbosity`] `self.verbosity` is set to,
6464
/// the reports have different levels of details.
65-
/// If `verbosity.stop_at_first`, stops at the first report.
65+
/// - If `verbosity.stop_at_first`, stops at the first report.
66+
/// - Skip generating reports if the AS Path has only one entry.
6667
pub fn check(&self, query: &QueryIr) -> Vec<Report> {
67-
if self.as_path.len() == 1 {
68-
return self.check_last_export(query).into_iter().collect();
68+
if self.as_path.len() <= 1 {
69+
return vec![];
6970
}
7071

7172
let mut reports = Vec::with_capacity(self.as_path.len() << 1);
@@ -91,22 +92,6 @@ impl Compare {
9192
reports
9293
}
9394

94-
pub fn check_last_export(&self, query: &QueryIr) -> Option<Report> {
95-
match self.as_path.last()? {
96-
Seq(from) => match query.aut_nums.get(from) {
97-
Some(from_an) => self.check_export(query, from_an, *from, None, &[]),
98-
None => self.verbosity.show_unrec.then(|| {
99-
let items = aut_num_unrecorded_items(*from);
100-
UnrecSingleExport { from: *from, items }
101-
}),
102-
},
103-
Set(from) => self
104-
.verbosity
105-
.record_set
106-
.then(|| SetSingleExport { from: from.clone() }),
107-
}
108-
}
109-
11095
/// `prev_path` is previous path for `to`.
11196
pub fn check_pair(
11297
&self,
@@ -116,7 +101,7 @@ impl Compare {
116101
prev_path: &[AsPathEntry],
117102
) -> Vec<Report> {
118103
let from_report = match query.aut_nums.get(&from) {
119-
Some(from_an) => self.check_export(query, from_an, from, Some(to), prev_path),
104+
Some(from_an) => self.check_export(query, from_an, from, to, prev_path),
120105
None => self.verbosity.show_unrec.then(|| {
121106
let items = aut_num_unrecorded_items(from);
122107
UnrecExport { from, to, items }
@@ -141,16 +126,13 @@ impl Compare {
141126
query: &QueryIr,
142127
from_an: &AutNum,
143128
from: u32,
144-
to: Option<u32>,
129+
to: u32,
145130
prev_path: &[AsPathEntry],
146131
) -> Option<Report> {
147132
if from_an.exports.is_default() {
148133
return self.verbosity.show_unrec.then(|| {
149134
let items = vec![UnrecExportEmpty];
150-
match to {
151-
Some(to) => UnrecExport { from, to, items },
152-
None => UnrecSingleExport { from, items },
153-
}
135+
UnrecExport { from, to, items }
154136
});
155137
}
156138
let mut report = match (Compliance {
@@ -163,32 +145,26 @@ impl Compare {
163145
})
164146
.check(&from_an.exports)
165147
{
166-
None => {
167-
return self.verbosity.show_success.then_some(match to {
168-
Some(to) => OkExport { from, to },
169-
None => OkSingleExport { from },
170-
})
171-
}
148+
None => return self.verbosity.show_success.then_some(OkExport { from, to }),
172149
Some(report) => report,
173150
};
174151
report.shrink_to_fit();
175152
match report {
176-
SkipAnyReport(items) => self.verbosity.show_skips.then_some(match to {
177-
Some(to) => SkipExport { from, to, items },
178-
None => SkipSingleExport { from, items },
179-
}),
180-
UnrecAnyReport(items) => self.verbosity.show_unrec.then_some(match to {
181-
Some(to) => UnrecExport { from, to, items },
182-
None => UnrecSingleExport { from, items },
183-
}),
184-
MehAnyReport(items) => self.verbosity.show_meh.then_some(match to {
185-
Some(to) => MehExport { from, to, items },
186-
None => MehSingleExport { from, items },
187-
}),
188-
BadAnyReport(items) => Some(match to {
189-
Some(to) => BadExport { from, to, items },
190-
None => BadSingleExport { from, items },
191-
}),
153+
SkipAnyReport(items) => {
154+
self.verbosity
155+
.show_skips
156+
.then_some(SkipExport { from, to, items })
157+
}
158+
UnrecAnyReport(items) => {
159+
self.verbosity
160+
.show_unrec
161+
.then_some(UnrecExport { from, to, items })
162+
}
163+
MehAnyReport(items) => self
164+
.verbosity
165+
.show_meh
166+
.then_some(MehExport { from, to, items }),
167+
BadAnyReport(items) => Some(BadExport { from, to, items }),
192168
}
193169
}
194170

@@ -210,7 +186,7 @@ impl Compare {
210186
let mut report = match (Compliance {
211187
cmp: self,
212188
query,
213-
accept_num: Some(from),
189+
accept_num: from,
214190
self_num: to,
215191
export: false,
216192
prev_path,

route_verification/bgp/src/cmp/compliance.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::*;
33
pub struct Compliance<'a> {
44
pub cmp: &'a Compare,
55
pub query: &'a QueryIr,
6-
pub accept_num: Option<u32>,
6+
pub accept_num: u32,
77
pub self_num: u32,
88
pub export: bool,
99
pub prev_path: &'a [AsPathEntry],
@@ -32,21 +32,18 @@ impl<'a> Compliance<'a> {
3232
}
3333

3434
pub fn check_entry(&self, entry: &Entry) -> AllReport {
35-
let peering_report = match self.accept_num {
36-
Some(accept_num) => CheckPeering {
37-
c: self,
38-
accept_num,
35+
let peering_report = CheckPeering {
36+
c: self,
37+
accept_num: self.accept_num,
38+
}
39+
.check_peering_actions(&entry.mp_peerings)
40+
.to_all()
41+
.map_err(|mut report| {
42+
if self.cmp.verbosity.per_peering_err {
43+
report.push(MatchPeering);
3944
}
40-
.check_peering_actions(&entry.mp_peerings)
41-
.to_all()
42-
.map_err(|mut report| {
43-
if self.cmp.verbosity.per_peering_err {
44-
report.push(MatchPeering);
45-
}
46-
report
47-
})?,
48-
None => OkAllReport,
49-
};
45+
report
46+
})?;
5047
let filter_report = CheckFilter {
5148
cmp: self.cmp,
5249
query: self.query,

route_verification/bgp/src/report.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ pub enum Report {
2525
from: u32,
2626
to: u32,
2727
},
28-
OkSingleExport {
29-
from: u32,
30-
},
3128
SkipImport {
3229
from: u32,
3330
to: u32,
@@ -38,10 +35,6 @@ pub enum Report {
3835
to: u32,
3936
items: ReportItems,
4037
},
41-
SkipSingleExport {
42-
from: u32,
43-
items: ReportItems,
44-
},
4538
UnrecImport {
4639
from: u32,
4740
to: u32,
@@ -52,17 +45,10 @@ pub enum Report {
5245
to: u32,
5346
items: ReportItems,
5447
},
55-
UnrecSingleExport {
56-
from: u32,
57-
items: ReportItems,
58-
},
5948
AsPathPairWithSet {
6049
from: AsPathEntry,
6150
to: AsPathEntry,
6251
},
63-
SetSingleExport {
64-
from: Vec<u32>,
65-
},
6652
MehImport {
6753
from: u32,
6854
to: u32,
@@ -73,10 +59,6 @@ pub enum Report {
7359
to: u32,
7460
items: ReportItems,
7561
},
76-
MehSingleExport {
77-
from: u32,
78-
items: ReportItems,
79-
},
8062
BadImport {
8163
from: u32,
8264
to: u32,
@@ -87,10 +69,6 @@ pub enum Report {
8769
to: u32,
8870
items: ReportItems,
8971
},
90-
BadSingleExport {
91-
from: u32,
92-
items: ReportItems,
93-
},
9472
}
9573

9674
impl Report {
@@ -105,7 +83,7 @@ impl Report {
10583
from: _,
10684
to: _,
10785
items: _
108-
} | MehSingleExport { from: _, items: _ }
86+
}
10987
)
11088
}
11189
}

route_verification/bgp/src/stats/as_.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ use super::{
66
pub fn one(map: &DashMap<u32, RouteStats<u64>>, report: Report) {
77
match report {
88
OkImport { from: _, to } => map.entry(to).or_default().import_ok += 1,
9-
OkExport { from, to: _ } | OkSingleExport { from } => {
10-
map.entry(from).or_default().export_ok += 1
11-
}
9+
OkExport { from, to: _ } => map.entry(from).or_default().export_ok += 1,
1210
SkipImport { from: _, to, items } => {
1311
let mut entry = map.entry(to).or_default();
1412
entry.import_skip += 1;
1513
skip(&mut entry, items);
1614
}
17-
SkipExport { from, to: _, items } | SkipSingleExport { from, items } => {
15+
SkipExport { from, to: _, items } => {
1816
let mut entry = map.entry(from).or_default();
1917
entry.export_skip += 1;
2018
skip(&mut entry, items);
@@ -24,7 +22,7 @@ pub fn one(map: &DashMap<u32, RouteStats<u64>>, report: Report) {
2422
entry.import_unrec += 1;
2523
unrec(&mut entry, items);
2624
}
27-
UnrecExport { from, to: _, items } | UnrecSingleExport { from, items } => {
25+
UnrecExport { from, to: _, items } => {
2826
let mut entry = map.entry(from).or_default();
2927
entry.export_unrec += 1;
3028
unrec(&mut entry, items);
@@ -34,7 +32,7 @@ pub fn one(map: &DashMap<u32, RouteStats<u64>>, report: Report) {
3432
entry.import_err += 1;
3533
bad(&mut entry, items);
3634
}
37-
BadExport { from, to: _, items } | BadSingleExport { from, items } => {
35+
BadExport { from, to: _, items } => {
3836
let mut entry = map.entry(from).or_default();
3937
entry.export_err += 1;
4038
bad(&mut entry, items);
@@ -44,11 +42,11 @@ pub fn one(map: &DashMap<u32, RouteStats<u64>>, report: Report) {
4442
entry.import_meh += 1;
4543
meh(&mut entry, items);
4644
}
47-
MehExport { from, to: _, items } | MehSingleExport { from, items } => {
45+
MehExport { from, to: _, items } => {
4846
let mut entry = map.entry(from).or_default();
4947
entry.export_meh += 1;
5048
meh(&mut entry, items);
5149
}
52-
AsPathPairWithSet { from: _, to: _ } | SetSingleExport { from: _ } => (),
50+
AsPathPairWithSet { from: _, to: _ } => (),
5351
}
5452
}

route_verification/bgp/src/stats/as_pair.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,7 @@ pub fn one(db: &AsRelDb, map: &DashMap<(u32, u32), AsPairStats>, report: Report)
5252
entry.route_stats.export_meh += 1;
5353
meh(&mut entry.route_stats, items)
5454
}
55-
AsPathPairWithSet { from: _, to: _ }
56-
| SetSingleExport { from: _ }
57-
| OkSingleExport { from: _ }
58-
| SkipSingleExport { from: _, items: _ }
59-
| UnrecSingleExport { from: _, items: _ }
60-
| MehSingleExport { from: _, items: _ }
61-
| BadSingleExport { from: _, items: _ } => (),
55+
AsPathPairWithSet { from: _, to: _ } => (),
6256
}
6357
}
6458

route_verification/bgp/src/stats/route.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ReportItem::*;
44
pub fn one(stats: &mut RouteStats<u16>, report: Report) {
55
match report {
66
OkImport { from: _, to: _ } => stats.import_ok.inc(),
7-
OkExport { from: _, to: _ } | OkSingleExport { from: _ } => stats.export_ok.inc(),
7+
OkExport { from: _, to: _ } => stats.export_ok.inc(),
88
SkipImport {
99
from: _,
1010
to: _,
@@ -17,8 +17,7 @@ pub fn one(stats: &mut RouteStats<u16>, report: Report) {
1717
from: _,
1818
to: _,
1919
items,
20-
}
21-
| SkipSingleExport { from: _, items } => {
20+
} => {
2221
stats.export_skip.inc();
2322
skip(stats, items);
2423
}
@@ -34,8 +33,7 @@ pub fn one(stats: &mut RouteStats<u16>, report: Report) {
3433
from: _,
3534
to: _,
3635
items,
37-
}
38-
| UnrecSingleExport { from: _, items } => {
36+
} => {
3937
stats.export_unrec.inc();
4038
unrec(stats, items);
4139
}
@@ -51,8 +49,7 @@ pub fn one(stats: &mut RouteStats<u16>, report: Report) {
5149
from: _,
5250
to: _,
5351
items,
54-
}
55-
| BadSingleExport { from: _, items } => {
52+
} => {
5653
stats.export_err.inc();
5754
bad(stats, items);
5855
}
@@ -68,12 +65,11 @@ pub fn one(stats: &mut RouteStats<u16>, report: Report) {
6865
from: _,
6966
to: _,
7067
items,
71-
}
72-
| MehSingleExport { from: _, items } => {
68+
} => {
7369
stats.export_meh.inc();
7470
meh(stats, items);
7571
}
76-
AsPathPairWithSet { from: _, to: _ } | SetSingleExport { from: _ } => (),
72+
AsPathPairWithSet { from: _, to: _ } => (),
7773
}
7874
}
7975

route_verification/bgp/src/stats/up_down_hill.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub fn one(stats: &mut UpDownHillStats, report: &Report, db: &AsRelDb) {
1414
Some(C2P) => stats.ok_up_export += 1,
1515
None => stats.ok_other_export += 1,
1616
},
17-
OkSingleExport { from: _ } => stats.ok_other_export += 1,
1817
SkipImport { from, to, items: _ } | UnrecImport { from, to, items: _ } => {
1918
match db.get(*from, *to) {
2019
Some(P2C) => stats.skip_down_import += 1,
@@ -31,9 +30,6 @@ pub fn one(stats: &mut UpDownHillStats, report: &Report, db: &AsRelDb) {
3130
None => stats.skip_other_export += 1,
3231
}
3332
}
34-
SkipSingleExport { from: _, items: _ } | UnrecSingleExport { from: _, items: _ } => {
35-
stats.skip_other_export += 1
36-
}
3733
BadImport { from, to, items: _ } | MehImport { from, to, items: _ } => {
3834
match db.get(*from, *to) {
3935
Some(P2C) => stats.bad_down_import += 1,
@@ -50,10 +46,7 @@ pub fn one(stats: &mut UpDownHillStats, report: &Report, db: &AsRelDb) {
5046
None => stats.bad_other_export += 1,
5147
}
5248
}
53-
BadSingleExport { from: _, items: _ } | MehSingleExport { from: _, items: _ } => {
54-
stats.bad_other_export += 1
55-
}
56-
AsPathPairWithSet { from: _, to: _ } | SetSingleExport { from: _ } => (),
49+
AsPathPairWithSet { from: _, to: _ } => (),
5750
}
5851
}
5952

route_verification/src/evcxr_examples/filter_as.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn reports_for_paths_containing_certain_as(
4141
from: _,
4242
to: _,
4343
items: _,
44-
} | Report::SkipSingleExport { from: _, items: _ }
44+
}
4545
)
4646
})
4747
.then(|| line.display_str())

0 commit comments

Comments
 (0)