asterust-junos 0.5.13

Typed Juniper JunOS config views (interfaces, protocols, routing instances and options, policy options, firewall filters, class of service, system, services) extracted from an asterust config tree.
Documentation
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
//! `packet-forwarding-options`
//! `system { packet-forwarding-options { ... } }`.
//!
//! Most of these statements are platform specific and restart the Packet Forwarding Engine.
//!
//! # See also
//!
//! - [eracl-ip6-match](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/eracl-ip6-match-edit-system.html)
//! - [flow-export-timer](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/flow-export-timer-edit-system-packet-fo.html)
//! - [hw-db-profile](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-packet-forwarding-options-hw-db-profile.html)
//! - [mcast stats-enable](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/mcast-stats-enable-edit-system-packet-forwarding-options.html)
//! - [mcast-repl-type ingress-only](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-packet-forwarding-options-mcast-repl-type-ingress-only.html)
//! - [mcast-repl-type ingress-egress-recycle](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-packet-forwarding-options-mcast-repl-type-ingress-egress-recycle.html)
//! - [mef-forwarding-profile](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/mef-forwarding-profile-edit-system-packet-forwarding-options.html)
//! - [mpls (packet-forwarding-options)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-packet-forwarding-options-mpls.html)
//! - [overlay (Packet Forwarding Options)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/overlay-edit-system-packet-forwarding-options.html)
//! - [packet-format-match](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-packet-forwarding-options-packet-format-match.html)
//! - [recycle-bandwidth-profiles](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-packet-forwarding-options-recycle-bandwidth-profiles.html)
//! - [vxlan-extended](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-packet-forwarding-options-system-profile-vxlan-extended.html)
//! - [vxlan-stitching](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/vxlan-stitching-edit-system-packet-forwarding-options-system-profile.html)
//! - [eracl-profile (packet-forwarding-options)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-packet-forwarding-options-firewall-eracl-profile.html)
//! - [ethernet-switching (firewall profiles)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/ethernet-switching-edit-system-packet-forwarding-options-firewall-profiles.html)
//! - [polling-interval (Network Management)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/polling-interval-edit-system-packet-forwarding-options-hw-resource-monitor.html)
//! - [monitor-profile](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/monitor-profile-edit-system-packet-forwarding-options-hw-resource-monitor.html)
//! - [resource-list (Network Management)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/resource-list-edit-system-packet-forwarding-options-hw-resource-monitor.html)
//! - [counter-profiles](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/counter-profiles.html)
//! - [hw-profile](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/hw-profile.html)
//! - [hw-profiles](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/hw-profiles.html)
//! - [internal-forwarding-bandwidth](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/internal-forwarding-bandwidth.html)
//! - [reserve ingress-egress-mcast](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/reserve-ingress-egress-mcast.html)
//! - [ipfix-sw-mode](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/ipfix-sw-mode-system-packet-forwarding-options.html)
//! - [no-ip-tos-rewrite](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/no-ip-tos-rewrite.html)
//! - [multicast-statistics (packet-forwarding-options)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/autogen-system-packet-forwarding-options-multicast-statistics.html)
//! - [force-fbf-terms](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/force-fbf-terms.html)
//! - [egress-l2-extended-match](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/egress-l2-extended-match.html)

use crate::{
    active_children, arg_of, args_of, child_block, has_leaf, list_values, named_children, statements, value_after,
};
use asterust::config::ConfigLine;

/// A `profile <name>` of `recycle-bandwidth-profiles`.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct RecycleBandwidthProfile {
    pub name: String,
    /// `(application, percentage)` pairs such as `("tunnel-services", "20")`.
    pub applications: Vec<(String, String)>,
}

/// An `app <name>` of a custom counter profile.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct CounterProfileApp {
    pub name: String,
    /// Counter engines of each size.
    pub counter_4k: Option<String>,
    pub counter_8k: Option<String>,
    pub counter_16k: Option<String>,
}

/// A `counter-profiles <name>` of `custom-profiles`.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct CounterProfile {
    pub name: String,
    pub apps: Vec<CounterProfileApp>,
}

/// A `hw-profiles <name>` of `custom-profiles`: a grouping of custom profiles.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct HwProfile {
    pub name: String,
    pub counter_profile: Option<String>,
}

/// The `system-profile` block.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct PfeSystemProfile {
    pub vxlan_extended: bool,
    pub vxlan_stitching: bool,
    /// `vxlan-stitching { control-word; }`.
    pub vxlan_stitching_control_word: bool,
}

/// The `firewall` block of `packet-forwarding-options`.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct PfeFirewall {
    /// `eracl-profile { eracl-scale; }`: egress firewall filters in scaled mode.
    pub eracl_scale: bool,
    pub force_fbf_terms: bool,
    /// The profiles of `profiles ethernet-switching`, e.g. `profile1`, `udf-profile1`.
    pub ethernet_switching_profiles: Vec<String>,
    /// The profiles of `profiles ethernet-switching egress`.
    pub ethernet_switching_egress_profiles: Vec<String>,
}

/// A `monitor-profile <name>` of `hw-resource-monitor`.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct HwMonitorProfile {
    pub name: String,
    pub lower_threshold: Option<String>,
    /// `alarm`, `none` or `syslog`.
    pub notification_type: Option<String>,
    pub upper_threshold: Option<String>,
}

/// A `resource-list <name>` of `hw-resource-monitor`.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct HwResourceList {
    pub name: String,
    /// The `resource-names`, e.g. `lpm-ipv4`.
    pub resource_names: Vec<String>,
}

/// The `hw-resource-monitor` block.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct HwResourceMonitor {
    /// Milliseconds.
    pub polling_interval: Option<String>,
    pub monitor_profiles: Vec<HwMonitorProfile>,
    pub resource_lists: Vec<HwResourceList>,
}

/// The `system packet-forwarding-options` settings.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct PacketForwardingOptions {
    /// `srcip6-and-destip6` or `srcip6-only`.
    pub eracl_ip6_match: Option<String>,
    /// Seconds.
    pub flow_export_timer: Option<String>,
    /// e.g. `lean-edge`, `bng`, `carrier-ethernet` or `cloud-metro`.
    pub hw_db_profile: Option<String>,
    /// `mcast { stats-enable; }`.
    pub mcast_stats_enable: bool,
    /// `ingress-only` or `ingress-egress-recycle`.
    pub mcast_repl_type: Option<String>,
    pub mef_forwarding_profile: bool,
    pub mpls_lsp_ingress_stats_enable: bool,
    pub mpls_lsp_transit_stats_enable: bool,
    /// From `overlay { interface-num }`.
    pub overlay_interface_num: Option<String>,
    /// From `overlay { next-hop }`.
    pub overlay_next_hop: Option<String>,
    /// e.g. `mpls-packet-format-1`.
    pub packet_format_match: Option<String>,
    pub recycle_bandwidth_profiles: Vec<RecycleBandwidthProfile>,
    pub system_profile: Option<PfeSystemProfile>,
    pub firewall: Option<PfeFirewall>,
    pub hw_resource_monitor: Option<HwResourceMonitor>,
    pub counter_profiles: Vec<CounterProfile>,
    pub hw_profiles: Vec<HwProfile>,
    /// The custom hardware profile made active with `hw-profile <name>`.
    pub hw_profile: Option<String>,
    /// From `internal-forwarding-bandwidth <value>`.
    pub internal_forwarding_bandwidth: Option<String>,
    /// Percentage, from `internal-forwarding-bandwidth { reserve ingress-egress-mcast }`.
    pub internal_forwarding_reserve_ingress_egress_mcast: Option<String>,
    pub ipfix_sw_mode: bool,
    pub no_ip_tos_rewrite: bool,
    pub multicast_statistics: bool,
    /// From `firewall-profile { egress-l2-extended-match; }`.
    pub egress_l2_extended_match: bool,
}

fn parse_firewall(firewall: &ConfigLine) -> PfeFirewall {
    let switching = child_block(firewall, "profiles").and_then(|profiles| child_block(profiles, "ethernet-switching"));
    PfeFirewall {
        eracl_scale: child_block(firewall, "eracl-profile").is_some_and(|profile| has_leaf(profile, "eracl-scale")),
        force_fbf_terms: has_leaf(firewall, "force-fbf-terms"),
        ethernet_switching_profiles: switching
            .map(|s| {
                active_children(s)
                    .filter(|c| c.text != "egress")
                    .map(|c| c.text.clone())
                    .collect()
            })
            .unwrap_or_default(),
        ethernet_switching_egress_profiles: switching
            .and_then(|s| child_block(s, "egress"))
            .map(|egress| active_children(egress).map(|c| c.text.clone()).collect())
            .unwrap_or_default(),
    }
}

fn parse_hw_resource_monitor(monitor: &ConfigLine) -> HwResourceMonitor {
    HwResourceMonitor {
        polling_interval: arg_of(monitor, "polling-interval").map(str::to_string),
        monitor_profiles: named_children(monitor, "monitor-profile")
            .map(|(name, profile)| HwMonitorProfile {
                name: name.to_string(),
                lower_threshold: arg_of(profile, "lower-threshold").map(str::to_string),
                notification_type: arg_of(profile, "notification-type").map(str::to_string),
                upper_threshold: arg_of(profile, "upper-threshold").map(str::to_string),
            })
            .collect(),
        resource_lists: named_children(monitor, "resource-list")
            .map(|(name, list)| HwResourceList {
                name: name.to_string(),
                resource_names: args_of(list, "resource-names")
                    .into_iter()
                    .flat_map(list_values)
                    .collect(),
            })
            .collect(),
    }
}

/// The words of an entry written as `<name> <options...>` or `<name> { <options>; }`.
fn entry_words(entry: &ConfigLine) -> Vec<&str> {
    entry
        .text
        .split_whitespace()
        .chain(active_children(entry).flat_map(|c| c.text.split_whitespace()))
        .collect()
}

pub(super) fn parse_packet_forwarding_options(options: &ConfigLine) -> PacketForwardingOptions {
    let overlay = child_block(options, "overlay");
    let mpls = child_block(options, "mpls");
    let profile = child_block(options, "system-profile");
    let custom = child_block(options, "custom-profiles");
    let bandwidth = child_block(options, "internal-forwarding-bandwidth");
    PacketForwardingOptions {
        eracl_ip6_match: statements(options, "eracl-ip6-match").first().map(|s| s.to_string()),
        flow_export_timer: arg_of(options, "flow-export-timer").map(str::to_string),
        hw_db_profile: statements(options, "hw-db-profile").first().map(|s| s.to_string()),
        mcast_stats_enable: child_block(options, "mcast").is_some_and(|mcast| has_leaf(mcast, "stats-enable")),
        mcast_repl_type: statements(options, "mcast-repl-type").first().map(|s| s.to_string()),
        mef_forwarding_profile: has_leaf(options, "mef-forwarding-profile"),
        mpls_lsp_ingress_stats_enable: mpls.is_some_and(|m| has_leaf(m, "lsp-ingress-stats-enable")),
        mpls_lsp_transit_stats_enable: mpls.is_some_and(|m| has_leaf(m, "lsp-transit-stats-enable")),
        overlay_interface_num: overlay.and_then(|o| arg_of(o, "interface-num")).map(str::to_string),
        overlay_next_hop: overlay.and_then(|o| arg_of(o, "next-hop")).map(str::to_string),
        packet_format_match: statements(options, "packet-format-match")
            .first()
            .map(|s| s.to_string()),
        recycle_bandwidth_profiles: named_children(options, "recycle-bandwidth-profiles")
            .map(|(name, profile)| RecycleBandwidthProfile {
                name: name.to_string(),
                applications: active_children(profile)
                    .filter_map(|c| {
                        let (application, percentage) = c.text.split_once(char::is_whitespace)?;
                        Some((application.to_string(), percentage.trim().to_string()))
                    })
                    .collect(),
            })
            .collect(),
        system_profile: profile.map(|profile| PfeSystemProfile {
            vxlan_extended: has_leaf(profile, "vxlan-extended"),
            vxlan_stitching: child_block(profile, "vxlan-stitching").is_some(),
            vxlan_stitching_control_word: child_block(profile, "vxlan-stitching")
                .is_some_and(|stitching| has_leaf(stitching, "control-word")),
        }),
        firewall: child_block(options, "firewall").map(parse_firewall),
        hw_resource_monitor: child_block(options, "hw-resource-monitor").map(parse_hw_resource_monitor),
        counter_profiles: custom
            .map(|custom| {
                named_children(custom, "counter-profiles")
                    .map(|(name, profile)| CounterProfile {
                        name: name.to_string(),
                        apps: child_block(profile, "app")
                            .map(|app| {
                                active_children(app)
                                    .map(|entry| {
                                        let words = entry_words(entry);
                                        CounterProfileApp {
                                            name: words.first().unwrap_or(&"").to_string(),
                                            counter_4k: value_after(&words, "counter-4k"),
                                            counter_8k: value_after(&words, "counter-8k"),
                                            counter_16k: value_after(&words, "counter-16k"),
                                        }
                                    })
                                    .collect()
                            })
                            .unwrap_or_default(),
                    })
                    .collect()
            })
            .unwrap_or_default(),
        hw_profiles: custom
            .map(|custom| {
                named_children(custom, "hw-profiles")
                    .map(|(name, profile)| HwProfile {
                        name: name.to_string(),
                        counter_profile: arg_of(profile, "counter-profile").map(str::to_string),
                    })
                    .collect()
            })
            .unwrap_or_default(),
        hw_profile: arg_of(options, "hw-profile").map(str::to_string),
        internal_forwarding_bandwidth: arg_of(options, "internal-forwarding-bandwidth").map(str::to_string),
        internal_forwarding_reserve_ingress_egress_mcast: bandwidth
            .and_then(|b| arg_of(b, "reserve"))
            .and_then(|reserve| value_after(&reserve.split_whitespace().collect::<Vec<_>>(), "ingress-egress-mcast")),
        ipfix_sw_mode: has_leaf(options, "ipfix-sw-mode"),
        no_ip_tos_rewrite: has_leaf(options, "no-ip-tos-rewrite"),
        multicast_statistics: has_leaf(options, "multicast-statistics"),
        egress_l2_extended_match: child_block(options, "firewall-profile")
            .is_some_and(|profile| has_leaf(profile, "egress-l2-extended-match")),
    }
}

#[cfg(test)]
mod tests {
    use crate::system::system;
    use asterust::config::juniper;

    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
    #[test]
    fn extracts_the_packet_forwarding_options() {
        let options = system(&juniper::parse_braces(
            r#"
system {
    packet-forwarding-options {
        eracl-ip6-match {
            srcip6-only;
        }
        flow-export-timer 30;
        hw-db-profile {
            cloud-metro;
        }
        mcast {
            stats-enable;
        }
        mcast-repl-type {
            ingress-only;
        }
        mef-forwarding-profile;
        mpls {
            lsp-ingress-stats-enable;
        }
        overlay {
            interface-num 2048;
            next-hop 8192;
        }
        packet-format-match {
            mpls-packet-format-3;
        }
        recycle-bandwidth-profiles lab {
            tunnel-services 20;
            srv6 30;
        }
        system-profile {
            vxlan-extended;
            vxlan-stitching {
                control-word;
            }
        }
        firewall {
            eracl-profile {
                eracl-scale;
            }
            profiles {
                ethernet-switching {
                    profile1;
                    udf-profile1;
                    egress {
                        profile1;
                    }
                }
            }
        }
        hw-resource-monitor {
            polling-interval 5000;
            monitor-profile alarms {
                lower-threshold 60;
                notification-type syslog;
                upper-threshold 90;
            }
            resource-list lpm {
                resource-names [ lpm-ipv4 lpm-ipv6-64 ];
            }
        }
    }
}
"#,
        ))
        .unwrap()
        .packet_forwarding_options
        .unwrap();
        assert_eq!(options.eracl_ip6_match.as_deref(), Some("srcip6-only"));
        assert_eq!(options.flow_export_timer.as_deref(), Some("30"));
        assert_eq!(options.hw_db_profile.as_deref(), Some("cloud-metro"));
        assert!(options.mcast_stats_enable);
        assert_eq!(options.mcast_repl_type.as_deref(), Some("ingress-only"));
        assert!(options.mef_forwarding_profile);
        assert!(options.mpls_lsp_ingress_stats_enable);
        assert!(!options.mpls_lsp_transit_stats_enable);
        assert_eq!(options.overlay_interface_num.as_deref(), Some("2048"));
        assert_eq!(options.overlay_next_hop.as_deref(), Some("8192"));
        assert_eq!(options.packet_format_match.as_deref(), Some("mpls-packet-format-3"));
        assert_eq!(options.recycle_bandwidth_profiles[0].name, "lab");
        assert_eq!(
            options.recycle_bandwidth_profiles[0].applications,
            [
                ("tunnel-services".to_string(), "20".to_string()),
                ("srv6".to_string(), "30".to_string())
            ]
        );
        let profile = options.system_profile.unwrap();
        assert!(profile.vxlan_extended);
        assert!(profile.vxlan_stitching);
        assert!(profile.vxlan_stitching_control_word);

        let firewall = options.firewall.unwrap();
        assert!(firewall.eracl_scale);
        assert_eq!(firewall.ethernet_switching_profiles, ["profile1", "udf-profile1"]);
        assert_eq!(firewall.ethernet_switching_egress_profiles, ["profile1"]);

        let monitor = options.hw_resource_monitor.unwrap();
        assert_eq!(monitor.polling_interval.as_deref(), Some("5000"));
        assert_eq!(monitor.monitor_profiles[0].name, "alarms");
        assert_eq!(monitor.monitor_profiles[0].lower_threshold.as_deref(), Some("60"));
        assert_eq!(monitor.monitor_profiles[0].notification_type.as_deref(), Some("syslog"));
        assert_eq!(monitor.monitor_profiles[0].upper_threshold.as_deref(), Some("90"));
        assert_eq!(monitor.resource_lists[0].name, "lpm");
        assert_eq!(monitor.resource_lists[0].resource_names, ["lpm-ipv4", "lpm-ipv6-64"]);
    }

    #[test]
    fn extracts_the_custom_profiles_and_other_statements() {
        let options = system(&juniper::parse_braces(
            r#"
system {
    packet-forwarding-options {
        custom-profiles {
            counter-profiles flows {
                app {
                    acl {
                        counter-4k 2;
                        counter-8k 1;
                    }
                    telemetry {
                        counter-16k 4;
                    }
                }
            }
            hw-profiles edge {
                counter-profile flows;
            }
        }
        hw-profile edge;
        internal-forwarding-bandwidth {
            reserve ingress-egress-mcast 40;
        }
        ipfix-sw-mode;
        no-ip-tos-rewrite;
        multicast-statistics;
        firewall {
            force-fbf-terms;
        }
        firewall-profile {
            egress-l2-extended-match;
        }
    }
}
"#,
        ))
        .unwrap()
        .packet_forwarding_options
        .unwrap();
        assert_eq!(options.counter_profiles[0].name, "flows");
        let acl = &options.counter_profiles[0].apps[0];
        assert_eq!(acl.name, "acl");
        assert_eq!(acl.counter_4k.as_deref(), Some("2"));
        assert_eq!(acl.counter_8k.as_deref(), Some("1"));
        assert_eq!(acl.counter_16k, None);
        assert_eq!(options.counter_profiles[0].apps[1].counter_16k.as_deref(), Some("4"));
        assert_eq!(options.hw_profiles[0].name, "edge");
        assert_eq!(options.hw_profiles[0].counter_profile.as_deref(), Some("flows"));
        assert_eq!(options.hw_profile.as_deref(), Some("edge"));
        assert_eq!(options.internal_forwarding_bandwidth, None);
        assert_eq!(
            options.internal_forwarding_reserve_ingress_egress_mcast.as_deref(),
            Some("40")
        );
        assert!(options.ipfix_sw_mode);
        assert!(options.no_ip_tos_rewrite);
        assert!(options.multicast_statistics);
        assert!(options.firewall.unwrap().force_fbf_terms);
        assert!(options.egress_l2_extended_match);
    }

    #[test]
    fn reads_the_inline_internal_forwarding_bandwidth() {
        let options = system(&juniper::parse_braces(
            "system {\n    packet-forwarding-options {\n        internal-forwarding-bandwidth 50g;\n    }\n}\n",
        ))
        .unwrap()
        .packet_forwarding_options
        .unwrap();
        assert_eq!(options.internal_forwarding_bandwidth.as_deref(), Some("50g"));
        assert_eq!(options.internal_forwarding_reserve_ingress_egress_mcast, None);
        assert!(options.counter_profiles.is_empty());
    }

    #[test]
    fn accepts_the_inline_forms() {
        let options = system(&juniper::parse_braces(
            "system {\n    packet-forwarding-options {\n        hw-db-profile bng;\n        mcast-repl-type ingress-egress-recycle;\n        mcast {\n            stats-enable;\n        }\n    }\n}\n",
        ))
        .unwrap()
        .packet_forwarding_options
        .unwrap();
        assert_eq!(options.hw_db_profile.as_deref(), Some("bng"));
        assert_eq!(options.mcast_repl_type.as_deref(), Some("ingress-egress-recycle"));
        assert!(options.system_profile.is_none());
        assert!(options.firewall.is_none());
    }

    #[test]
    fn no_packet_forwarding_options_is_none() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert!(system.packet_forwarding_options.is_none());
    }
}