1mod access_line;
45mod accounting;
46mod archival;
47mod arp;
48mod authentication_secret;
49mod auto_sw_sync;
50mod autoinstallation;
51mod backup_router;
52mod commit;
53mod configuration;
54mod configuration_database;
55mod ddos_protection;
56mod demux_options;
57mod dynamic_profile_options;
58mod export_format;
59mod extensions;
60mod fib_streaming;
61mod health_monitor;
62mod icmp;
63mod internet_options;
64mod kernel_replication;
65mod license;
66mod location;
67mod login;
68mod management_traffic;
69mod master_password;
70mod monitor;
71mod name_server;
72mod ntp;
73mod packet_forwarding_options;
74mod password_options;
75mod pixel_tracing;
76mod ports;
77mod processes;
78mod proxy;
79mod radius_options;
80mod radius_server;
81mod resiliency;
82mod root_authentication;
83mod schema;
84mod scripts;
85mod services;
86mod snapshot;
87mod static_host_mapping;
88mod syslog;
89mod tacplus_options;
90mod tacplus_server;
91mod tracing;
92
93pub use access_line::{AccessLine, AccessLineAdjustment};
94pub use accounting::{Accounting, AccountingDestination};
95pub use archival::{Archival, ArchivalConfiguration};
96pub use arp::{Arp, ArpInterface};
97pub use authentication_secret::AuthenticationSecret;
98pub use auto_sw_sync::AutoSwSync;
99pub use autoinstallation::{Autoinstallation, AutoinstallationInterface};
100pub use backup_router::BackupRouter;
101pub use commit::{Commit, CommitPeer, CommitServer};
102pub use configuration::ConfigurationInput;
103pub use configuration_database::{
104 ConfigurationDatabase, DatabaseResize, EphemeralDatabase, EphemeralInstance, VirtualMemoryProcess,
105};
106pub use ddos_protection::{DdosFlowLevels, DdosFpc, DdosGlobal, DdosPacketType, DdosProtection, DdosProtocolGroup};
107pub use demux_options::DemuxOptions;
108pub use dynamic_profile_options::DynamicProfileOptions;
109pub use export_format::ExportFormat;
110pub use extensions::{ExtensionApplication, ExtensionProvider, Extensions, ProviderLicense};
111pub use fib_streaming::{FibStreaming, FibStreamingTable};
112pub use health_monitor::HealthMonitor;
113pub use icmp::Icmp;
114pub use internet_options::{IcmpRateLimit, InternetOptions};
115pub use kernel_replication::KernelReplication;
116pub use license::{License, LicenseAutoupdate, LicenseRenew};
117pub use location::Location;
118pub use login::{Login, LoginClass, LoginPassword, LoginRetryOptions, LoginUser};
119pub use management_traffic::ManagementTrafficProtocol;
120pub use master_password::MasterPassword;
121pub use monitor::{
122 MemoryMonitor, Monitor, ProcessMemoryEvent, ProcessMemoryMonitor, ProcessMemoryThreshold, SystemMemoryEvent,
123 SystemMemoryMonitor,
124};
125pub use name_server::NameServer;
126pub use ntp::{Ntp, NtpAuthenticationKey, NtpBroadcast, NtpHost, NtpHostNts, NtpNts, NtpRestriction, NtpThreshold};
127pub use packet_forwarding_options::{
128 HwMonitorProfile, HwResourceList, HwResourceMonitor, PacketForwardingOptions, PfeFirewall, PfeSystemProfile,
129 RecycleBandwidthProfile,
130};
131pub use password_options::PasswordOptions;
132pub use pixel_tracing::PixelTracing;
133pub use ports::{Auxiliary, Console, Ports};
134pub use processes::{DhcpSessionLog, Process, SnoopingFile};
135pub use proxy::Proxy;
136pub use radius_options::RadiusOptions;
137pub use radius_server::RadiusServer;
138pub use resiliency::{Resiliency, ResiliencyFile, ResiliencyStore};
139pub use root_authentication::RootAuthentication;
140pub use schema::Schema;
141pub use scripts::{ScriptArgument, ScriptDampen, ScriptFile, ScriptKind, ScriptOid, Scripts};
142pub use services::{
143 AaclStatisticsProfile, ConnectionLimits, DhcpActiveLeasequery, DhcpActiveLeasequeryLimits, DhcpAuthentication,
144 DhcpBfd, DhcpBulkLeasequery, DhcpClassificationKey, DhcpDelay, DhcpDualStackGroup, DhcpDynamicProfile,
145 DhcpDynamicServerGroup, DhcpDynamicServerInterface, DhcpFingerprintServer, DhcpFingerprintServerGroup,
146 DhcpGroupInterface, DhcpInterfaceTag, DhcpLeaseTimeValidation, DhcpLivenessDetection, DhcpLocalServer,
147 DhcpLocalServerGroup, DhcpMatch, DhcpOptions, DhcpOverrides, DhcpPool, DhcpReconfigure, DhcpServer,
148 DhcpServerSettings, DhcpShortCycleProtection, DhcpStaticBinding, DhcpUsernameInclude, Dns, DnsCacheEntry,
149 DnsDomain, DnsProxy, DnsView, Dnssec, DynamicDnsClient, ExtensibleSubscriberServices, ExtensionService,
150 ExternalManagement, FlowTapDtcp, FlowTapDtcpSsh, FpcLimit, FtpService, GrpcService, GrpcSsl, GrpcTunnel,
151 GrpcTunnelServer, HttpServer, HttpServerTls, InbandZtp, InlineNaptPool, Jeb, JebTls, JetNotification,
152 JtreeResourceType, LocalPolicyDecisionFunction, Netconf, NetconfClientIdentity, NetconfDefaultClientIdentity,
153 NetconfHelloMessage, NetconfMonitoring, NetconfSsh, NetconfTls, NetconfYangModules, OutboundHttpsAddress,
154 OutboundHttpsClient, OutboundSshClient, OutboundSshServer, OverrideFamily, PicLimit, PortLimit,
155 RedundancyInterface, RemoteDeviceNetconf, ResourceMonitor, Rest, RestHttp, RestHttps, Reverse, ServiceDeployment,
156 ServiceDeploymentServer, ServiceDevice, Services, Shmlog, SshModuli, SshService, StaticSubscriberGroup,
157 StaticSubscriberProfile, StaticSubscriberUsername, StaticSubscribers, SubscriberLimit, SubscriberManagement,
158 SubscriberOverrides, SubscriberRedundancy, TcpForwardingEntry, TelnetService, WebManagement, WebManagementHttp,
159 WebManagementHttps, WebManagementVirtualDomain, Webapi, WebapiHttps, WebapiUser, XnmClearText, XnmSsl,
160};
161pub use snapshot::{Snapshot, SnapshotRecovery};
162pub use static_host_mapping::StaticHostMapping;
163pub use syslog::{
164 GrpcReplay, Syslog, SyslogArchive, SyslogHost, SyslogRule, SyslogStructuredData, SyslogTarget, SyslogTlsDetails,
165};
166pub use tacplus_options::TacplusOptions;
167pub use tacplus_server::TacplusServer;
168pub use tracing::Tracing;
169
170use crate::protocols::traceoptions::{parse_traceoptions, Traceoptions};
171use crate::{
172 active_children, arg_of, args_of, child_block, has_leaf, list_values, split_name, toggle, top_level, unquote,
173};
174use access_line::parse_access_line;
175use accounting::parse_accounting;
176use archival::parse_archival;
177use arp::parse_arp;
178use asterust::config::{Config, ConfigLine};
179use authentication_secret::password_secrets;
180use auto_sw_sync::auto_sw_sync;
181use autoinstallation::parse_autoinstallation;
182use backup_router::parse_backup_router;
183use commit::parse_commit;
184use configuration::parse_configuration;
185use configuration_database::parse_configuration_database;
186use ddos_protection::parse_ddos_protection;
187use demux_options::parse_demux_options;
188use dynamic_profile_options::parse_dynamic_profile_options;
189use export_format::parse_export_format;
190use extensions::parse_extensions;
191use fib_streaming::parse_fib_streaming;
192use health_monitor::parse_health_monitor;
193use icmp::parse_icmp;
194use internet_options::parse_internet_options;
195use kernel_replication::parse_kernel_replication;
196use license::parse_license;
197use location::parse_location;
198use login::parse_login;
199use management_traffic::management_traffic;
200use master_password::parse_master_password;
201use monitor::parse_monitor;
202use name_server::name_servers;
203use ntp::parse_ntp;
204use packet_forwarding_options::parse_packet_forwarding_options;
205use password_options::parse_password_options;
206use pixel_tracing::parse_pixel_tracing;
207use ports::parse_ports;
208use processes::parse_processes;
209use proxy::parse_proxy;
210use radius_options::parse_radius_options;
211use radius_server::radius_servers;
212use resiliency::parse_resiliency;
213use root_authentication::root_authentication;
214use schema::parse_schema;
215use scripts::parse_scripts;
216use services::parse_services;
217use snapshot::parse_snapshot;
218use static_host_mapping::static_host_mappings;
219use syslog::parse_syslog;
220use tacplus_options::parse_tacplus_options;
221use tacplus_server::tacplus_servers;
222use tracing::parse_tracing;
223
224#[derive(Clone, Debug, PartialEq, Eq)]
226#[non_exhaustive]
227pub struct System {
228 pub host_name: Option<String>,
229 pub domain_name: Option<String>,
230 pub time_zone: Option<String>,
232 pub domain_search: Vec<String>,
233 pub static_host_mappings: Vec<StaticHostMapping>,
234 pub backup_router: Option<BackupRouter>,
235 pub inet6_backup_router: Option<BackupRouter>,
236 pub authentication_order: Vec<String>,
238 pub radius_servers: Vec<RadiusServer>,
239 pub tacplus_servers: Vec<TacplusServer>,
240 pub location: Option<Location>,
241 pub ports: Option<Ports>,
242 pub max_configurations_on_flash: Option<String>,
243 pub max_configuration_rollbacks: Option<String>,
244 pub no_redirects: bool,
245 pub default_address_selection: bool,
247 pub internet_options: Option<InternetOptions>,
248 pub commit: Option<Commit>,
249 pub processes: Vec<Process>,
250 pub dynamic_profile_options: Option<DynamicProfileOptions>,
251 pub extensions: Option<Extensions>,
252 pub autoinstallation: Option<Autoinstallation>,
253 pub schema: Option<Schema>,
254 pub pixel_tracing: Option<PixelTracing>,
255 pub scripts: Option<Scripts>,
256 pub no_multicast_echo: bool,
257 pub no_ping_record_route: bool,
258 pub no_ping_time_stamp: bool,
259 pub auto_snapshot: bool,
260 pub compress_configuration_files: bool,
261 pub mirror_flash_on_disk: bool,
262 pub switchover_on_routing_crash: bool,
263 pub use_imported_time_zones: bool,
264 pub archival: Option<Archival>,
265 pub accounting: Option<Accounting>,
266 pub root_authentication: Option<RootAuthentication>,
267 pub master_password: Option<MasterPassword>,
268 pub diag_port_authentication: Vec<String>,
270 pub diag_port_authentication_secrets: Vec<AuthenticationSecret>,
272 pub pic_console_authentication: Vec<String>,
274 pub pic_console_authentication_secrets: Vec<AuthenticationSecret>,
276 pub license: Option<License>,
277 pub name_servers: Vec<NameServer>,
278 pub ntp: Option<Ntp>,
279 pub syslog: Option<Syslog>,
280 pub login: Option<Login>,
281 pub services: Option<Services>,
282 pub arp: Option<Arp>,
283 pub icmp: Option<Icmp>,
284 pub tracing: Option<Tracing>,
285 pub proxy: Option<Proxy>,
286 pub demux_options: Option<DemuxOptions>,
287 pub kernel_replication: Option<KernelReplication>,
288 pub password_options: Option<PasswordOptions>,
289 pub radius_options: Option<RadiusOptions>,
290 pub tacplus_options: Option<TacplusOptions>,
291 pub auto_configuration_traceoptions: Option<Traceoptions>,
293 pub vnf_license_supplements: Vec<String>,
295 pub configuration: Option<ConfigurationInput>,
296 pub configuration_database: Option<ConfigurationDatabase>,
297 pub export_format: Option<ExportFormat>,
298 pub health_monitor: Option<HealthMonitor>,
299 pub monitor: Option<Monitor>,
300 pub resiliency: Option<Resiliency>,
301 pub snapshot: Option<Snapshot>,
302 pub access_line: Option<AccessLine>,
303 pub ddos_protection: Option<DdosProtection>,
304 pub fib_streaming: Option<FibStreaming>,
305 pub packet_forwarding_options: Option<PacketForwardingOptions>,
306 pub management_traffic: Vec<ManagementTrafficProtocol>,
308 pub auto_sw_sync: Vec<AutoSwSync>,
310 pub offline_nodes: Vec<String>,
312 pub boot_loader_authentication: Vec<String>,
314 pub boot_loader_authentication_secrets: Vec<AuthenticationSecret>,
316 pub device_authentication: Vec<String>,
318 pub device_authentication_secrets: Vec<AuthenticationSecret>,
320 pub allow_6pe_traceroute: bool,
321 pub allow_v4mapped_packets: bool,
323 pub arp_enhanced_scale: bool,
324 pub no_redirects_ipv6: bool,
326 pub nd_maxucast_retry: Option<String>,
328 pub allow_l3vpn_traceroute_src_select: bool,
329 pub dual_phase_bootup: bool,
330 pub extended_echo: bool,
331 pub management_instance: bool,
333 pub nd_override_preferred_src: bool,
334 pub no_hidden_commands: bool,
335 pub regex_additive_logic: bool,
336 pub unattended_boot: bool,
337 pub arp_system_cache_limit: Option<String>,
338 pub nd_retransmit_timer: Option<String>,
339 pub nd_system_cache_limit: Option<String>,
340 pub rng: Option<String>,
342 pub saved_core_context: Option<bool>,
344 pub saved_core_files: Option<String>,
345}
346
347pub fn system(config: &Config) -> Option<System> {
360 let system = top_level(config, "system")?;
361 Some(System {
362 host_name: arg_of(system, "host-name").map(str::to_string),
363 domain_name: arg_of(system, "domain-name").map(str::to_string),
364 time_zone: arg_of(system, "time-zone").map(str::to_string),
365 domain_search: args_of(system, "domain-search")
366 .into_iter()
367 .flat_map(list_values)
368 .collect(),
369 static_host_mappings: static_host_mappings(system),
370 backup_router: arg_of(system, "backup-router").map(parse_backup_router),
371 inet6_backup_router: arg_of(system, "inet6-backup-router").map(parse_backup_router),
372 authentication_order: args_of(system, "authentication-order")
373 .into_iter()
374 .flat_map(list_values)
375 .collect(),
376 radius_servers: radius_servers(system, "radius-server"),
377 tacplus_servers: tacplus_servers(system, "tacplus-server"),
378 location: child_block(system, "location").map(parse_location),
379 ports: child_block(system, "ports").map(parse_ports),
380 max_configurations_on_flash: arg_of(system, "max-configurations-on-flash").map(str::to_string),
381 max_configuration_rollbacks: arg_of(system, "max-configuration-rollbacks").map(str::to_string),
382 no_redirects: has_leaf(system, "no-redirects"),
383 default_address_selection: has_leaf(system, "default-address-selection"),
384 internet_options: child_block(system, "internet-options").map(parse_internet_options),
385 commit: child_block(system, "commit").map(parse_commit),
386 processes: child_block(system, "processes")
387 .map(parse_processes)
388 .unwrap_or_default(),
389 dynamic_profile_options: child_block(system, "dynamic-profile-options").map(parse_dynamic_profile_options),
390 extensions: child_block(system, "extensions").map(parse_extensions),
391 autoinstallation: child_block(system, "autoinstallation").map(parse_autoinstallation),
392 schema: child_block(system, "schema").map(parse_schema),
393 pixel_tracing: child_block(system, "pixel-tracing").map(parse_pixel_tracing),
394 scripts: child_block(system, "scripts").map(parse_scripts),
395 no_multicast_echo: has_leaf(system, "no-multicast-echo"),
396 no_ping_record_route: has_leaf(system, "no-ping-record-route"),
397 no_ping_time_stamp: has_leaf(system, "no-ping-time-stamp"),
398 auto_snapshot: has_leaf(system, "auto-snapshot"),
399 compress_configuration_files: has_leaf(system, "compress-configuration-files"),
400 mirror_flash_on_disk: has_leaf(system, "mirror-flash-on-disk"),
401 switchover_on_routing_crash: has_leaf(system, "switchover-on-routing-crash"),
402 use_imported_time_zones: has_leaf(system, "use-imported-time-zones"),
403 archival: child_block(system, "archival").map(parse_archival),
404 accounting: child_block(system, "accounting").map(parse_accounting),
405 root_authentication: root_authentication(system),
406 master_password: child_block(system, "master-password").map(parse_master_password),
407 diag_port_authentication: password_methods(system, "diag-port-authentication"),
408 diag_port_authentication_secrets: password_secrets(system, "diag-port-authentication"),
409 pic_console_authentication: password_methods(system, "pic-console-authentication"),
410 pic_console_authentication_secrets: password_secrets(system, "pic-console-authentication"),
411 license: child_block(system, "license").map(parse_license),
412 name_servers: name_servers(system),
413 ntp: child_block(system, "ntp").map(parse_ntp),
414 syslog: child_block(system, "syslog").map(parse_syslog),
415 login: child_block(system, "login").map(parse_login),
416 services: child_block(system, "services").map(parse_services),
417 arp: child_block(system, "arp").map(parse_arp),
418 icmp: child_block(system, "icmp").map(parse_icmp),
419 tracing: child_block(system, "tracing").map(parse_tracing),
420 proxy: child_block(system, "proxy").map(parse_proxy),
421 demux_options: child_block(system, "demux-options").map(parse_demux_options),
422 kernel_replication: child_block(system, "kernel-replication").map(parse_kernel_replication),
423 password_options: child_block(system, "password-options").map(parse_password_options),
424 radius_options: child_block(system, "radius-options").map(parse_radius_options),
425 tacplus_options: child_block(system, "tacplus-options").map(parse_tacplus_options),
426 auto_configuration_traceoptions: child_block(system, "auto-configuration").and_then(parse_traceoptions),
427 vnf_license_supplements: child_block(system, "vnf-license-supplement")
428 .map(|supplement| active_children(supplement).map(|line| line.text.clone()).collect())
429 .unwrap_or_default(),
430 configuration: child_block(system, "configuration").map(parse_configuration),
431 configuration_database: child_block(system, "configuration-database").map(parse_configuration_database),
432 export_format: child_block(system, "export-format").map(parse_export_format),
433 health_monitor: child_block(system, "health-monitor").map(parse_health_monitor),
434 monitor: child_block(system, "monitor").map(parse_monitor),
435 resiliency: child_block(system, "resiliency").map(parse_resiliency),
436 snapshot: child_block(system, "snapshot").map(parse_snapshot),
437 access_line: child_block(system, "access-line").map(parse_access_line),
438 ddos_protection: child_block(system, "ddos-protection").map(parse_ddos_protection),
439 fib_streaming: child_block(system, "fib-streaming").map(parse_fib_streaming),
440 packet_forwarding_options: child_block(system, "packet-forwarding-options")
441 .map(parse_packet_forwarding_options),
442 management_traffic: management_traffic(system),
443 auto_sw_sync: auto_sw_sync(system),
444 offline_nodes: child_block(system, "node")
445 .map(|node| args_of(node, "offline").into_iter().map(str::to_string).collect())
446 .unwrap_or_default(),
447 boot_loader_authentication: password_methods(system, "boot-loader-authentication"),
448 boot_loader_authentication_secrets: password_secrets(system, "boot-loader-authentication"),
449 device_authentication: password_methods(system, "device-authentication"),
450 device_authentication_secrets: password_secrets(system, "device-authentication"),
451 allow_6pe_traceroute: has_leaf(system, "allow-6pe-traceroute"),
452 allow_v4mapped_packets: has_leaf(system, "allow-v4mapped-packets"),
453 arp_enhanced_scale: has_leaf(system, "arp-enhanced-scale"),
454 no_redirects_ipv6: has_leaf(system, "no-redirects-ipv6"),
455 nd_maxucast_retry: arg_of(system, "nd-maxucast-retry").map(str::to_string),
456 allow_l3vpn_traceroute_src_select: has_leaf(system, "allow-l3vpn-traceroute-src-select"),
457 dual_phase_bootup: has_leaf(system, "dual-phase-bootup"),
458 extended_echo: has_leaf(system, "extended-echo"),
459 management_instance: has_leaf(system, "management-instance"),
460 nd_override_preferred_src: has_leaf(system, "nd-override-preferred-src"),
461 no_hidden_commands: has_leaf(system, "no-hidden-commands"),
462 regex_additive_logic: has_leaf(system, "regex-additive-logic"),
463 unattended_boot: has_leaf(system, "unattended-boot"),
464 arp_system_cache_limit: arg_of(system, "arp-system-cache-limit").map(str::to_string),
465 nd_retransmit_timer: arg_of(system, "nd-retransmit-timer").map(str::to_string),
466 nd_system_cache_limit: arg_of(system, "nd-system-cache-limit").map(str::to_string),
467 rng: arg_of(system, "rng").map(str::to_string),
468 saved_core_context: toggle(system, "saved-core-context"),
469 saved_core_files: arg_of(system, "saved-core-files").map(str::to_string),
470 })
471}
472
473fn servers<'a>(system: &'a ConfigLine, keyword: &str) -> Vec<(&'a str, &'a ConfigLine)> {
476 let mut found = Vec::new();
477 for child in active_children(system) {
478 if child.text == keyword {
479 found.extend(active_children(child).map(|server| (unquote(&server.text), server)));
480 } else if let Some(arg) = child.arg(keyword) {
481 found.push((split_name(arg).0, child));
482 }
483 }
484 found
485}
486
487fn password_methods(system: &ConfigLine, keyword: &str) -> Vec<String> {
490 let mut methods = Vec::new();
491 for child in active_children(system) {
492 if child.text == keyword {
493 methods.extend(authentication_methods(child));
494 } else if let Some(method) = child.arg(keyword).and_then(|arg| arg.split_whitespace().next()) {
495 methods.push(method.to_string());
496 }
497 }
498 methods
499}
500
501fn authentication_methods(auth: &ConfigLine) -> Vec<String> {
504 active_children(auth)
505 .filter_map(|c| c.text.split_whitespace().next())
506 .map(str::to_string)
507 .collect()
508}
509
510#[cfg(test)]
511mod tests {
512 use crate::system::system;
513 use asterust::config::juniper;
514
515 #[test]
517 fn extracts_host_name() {
518 let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
519 assert_eq!(system.host_name.as_deref(), Some("pe1"));
520 }
521
522 #[test]
523 fn host_name_is_optional() {
524 let system = system(&juniper::parse_braces("system {\n domain-name example.net;\n}\n")).unwrap();
525 assert_eq!(system.host_name, None);
526 }
527
528 #[test]
529 fn skips_inactive_host_name() {
530 let system = system(&juniper::parse_braces("system {\n inactive: host-name pe1;\n}\n")).unwrap();
531 assert_eq!(system.host_name, None);
532 }
533
534 #[test]
535 fn extracts_domain_name() {
536 let system = system(&juniper::parse_braces(
537 "system {\n host-name pe1;\n domain-name example.net;\n}\n",
538 ))
539 .unwrap();
540 assert_eq!(system.domain_name.as_deref(), Some("example.net"));
541 }
542
543 #[test]
544 fn domain_name_is_optional() {
545 let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
546 assert_eq!(system.domain_name, None);
547 }
548
549 #[test]
550 fn extracts_time_zone() {
551 let system = system(&juniper::parse_braces("system {\n time-zone America/New_York;\n}\n")).unwrap();
552 assert_eq!(system.time_zone.as_deref(), Some("America/New_York"));
553 }
554
555 #[test]
556 fn time_zone_is_optional() {
557 let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
558 assert_eq!(system.time_zone, None);
559 }
560
561 #[test]
562 fn extracts_configuration_limits_and_no_redirects() {
563 let system = system(&juniper::parse_braces(
564 "system {\n max-configurations-on-flash 5;\n max-configuration-rollbacks 20;\n no-redirects;\n}\n",
565 ))
566 .unwrap();
567 assert_eq!(system.max_configurations_on_flash.as_deref(), Some("5"));
568 assert_eq!(system.max_configuration_rollbacks.as_deref(), Some("20"));
569 assert!(system.no_redirects);
570 }
571
572 #[test]
573 fn configuration_limits_are_optional() {
574 let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
575 assert_eq!(system.max_configurations_on_flash, None);
576 assert_eq!(system.max_configuration_rollbacks, None);
577 assert!(!system.no_redirects);
578 }
579
580 #[test]
581 fn extracts_system_flags() {
582 let system = system(&juniper::parse_braces(
583 "system {\n no-multicast-echo;\n no-ping-record-route;\n no-ping-time-stamp;\n auto-snapshot;\n compress-configuration-files;\n mirror-flash-on-disk;\n switchover-on-routing-crash;\n use-imported-time-zones;\n}\n",
584 ))
585 .unwrap();
586 assert!(system.no_multicast_echo);
587 assert!(system.no_ping_record_route);
588 assert!(system.no_ping_time_stamp);
589 assert!(system.auto_snapshot);
590 assert!(system.compress_configuration_files);
591 assert!(system.mirror_flash_on_disk);
592 assert!(system.switchover_on_routing_crash);
593 assert!(system.use_imported_time_zones);
594 }
595
596 #[test]
597 fn system_flags_default_to_off() {
598 let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
599 assert!(!system.no_multicast_echo);
600 assert!(!system.auto_snapshot);
601 assert!(!system.use_imported_time_zones);
602 }
603
604 #[test]
605 fn no_system_is_none() {
606 assert!(system(&juniper::parse_braces("interfaces {\n lo0;\n}\n")).is_none());
607 }
608
609 #[test]
610 fn diag_port_and_pic_console_report_only_the_method() {
611 let system = system(&juniper::parse_braces(
612 r#"
613system {
614 diag-port-authentication encrypted-password "$6$salt$hash"; ## SECRET-DATA
615 pic-console-authentication {
616 encrypted-password "$6$salt$other"; ## SECRET-DATA
617 }
618}
619"#,
620 ))
621 .unwrap();
622 assert_eq!(system.diag_port_authentication, ["encrypted-password"]);
623 assert_eq!(system.pic_console_authentication, ["encrypted-password"]);
624 let values = |secrets: &[crate::system::AuthenticationSecret]| -> Vec<String> {
625 secrets.iter().map(|s| s.value.expose().to_string()).collect()
626 };
627 let (diag, pic) = if cfg!(feature = "secrets") {
628 (vec!["$6$salt$hash".to_string()], vec!["$6$salt$other".to_string()])
629 } else {
630 (Vec::new(), Vec::new())
631 };
632 assert_eq!(values(&system.diag_port_authentication_secrets), diag);
633 assert_eq!(values(&system.pic_console_authentication_secrets), pic);
634 }
635
636 #[test]
637 fn secret_settings_are_optional() {
638 let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
639 assert!(system.master_password.is_none());
640 assert!(system.diag_port_authentication.is_empty());
641 assert!(system.pic_console_authentication.is_empty());
642 }
643
644 #[test]
645 fn extracts_authentication_order() {
646 let system = system(&juniper::parse_braces(
647 "system {\n authentication-order [ tacplus radius password ];\n}\n",
648 ))
649 .unwrap();
650 assert_eq!(system.authentication_order, ["tacplus", "radius", "password"]);
651 }
652
653 #[test]
654 fn authentication_settings_are_optional() {
655 let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
656 assert!(system.authentication_order.is_empty());
657 assert!(system.radius_servers.is_empty());
658 assert!(system.tacplus_servers.is_empty());
659 }
660
661 #[test]
662 fn extracts_domain_search_list() {
663 let system = system(&juniper::parse_braces(
664 "system {\n domain-search [ example.net lab.example.net ];\n}\n",
665 ))
666 .unwrap();
667 assert_eq!(system.domain_search, ["example.net", "lab.example.net"]);
668 }
669
670 #[test]
671 fn addressing_settings_are_optional() {
672 let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
673 assert!(system.domain_search.is_empty());
674 assert!(system.static_host_mappings.is_empty());
675 assert!(system.backup_router.is_none());
676 assert!(system.inet6_backup_router.is_none());
677 }
678
679 #[test]
680 fn extracts_the_scalar_flags_and_limits() {
681 let system = system(&juniper::parse_braces(
682 r#"
683system {
684 allow-6pe-traceroute;
685 allow-l3vpn-traceroute-src-select;
686 dual-phase-bootup;
687 extended-echo;
688 management-instance;
689 nd-override-preferred-src;
690 no-hidden-commands;
691 regex-additive-logic;
692 unattended-boot;
693 arp-system-cache-limit 50000;
694 nd-retransmit-timer 2000;
695 nd-system-cache-limit 150000;
696 rng fortuna;
697 saved-core-files 3;
698 saved-core-context;
699}
700"#,
701 ))
702 .unwrap();
703 assert!(system.allow_6pe_traceroute);
704 assert!(system.allow_l3vpn_traceroute_src_select);
705 assert!(system.dual_phase_bootup);
706 assert!(system.extended_echo);
707 assert!(system.management_instance);
708 assert!(system.nd_override_preferred_src);
709 assert!(system.no_hidden_commands);
710 assert!(system.regex_additive_logic);
711 assert!(system.unattended_boot);
712 assert_eq!(system.arp_system_cache_limit.as_deref(), Some("50000"));
713 assert_eq!(system.nd_retransmit_timer.as_deref(), Some("2000"));
714 assert_eq!(system.nd_system_cache_limit.as_deref(), Some("150000"));
715 assert_eq!(system.rng.as_deref(), Some("fortuna"));
716 assert_eq!(system.saved_core_files.as_deref(), Some("3"));
717 assert_eq!(system.saved_core_context, Some(true));
718 }
719
720 #[test]
721 fn reads_no_saved_core_context() {
722 let system = system(&juniper::parse_braces("system {\n no-saved-core-context;\n}\n")).unwrap();
723 assert_eq!(system.saved_core_context, Some(false));
724 }
725
726 #[test]
727 fn extracts_the_v4mapped_enhanced_scale_and_nd_retry_statements() {
728 let system = system(&juniper::parse_braces(
729 "system {\n allow-v4mapped-packets;\n arp-enhanced-scale;\n no-redirects-ipv6;\n nd-maxucast-retry 5;\n}\n",
730 ))
731 .unwrap();
732 assert!(system.allow_v4mapped_packets);
733 assert!(system.arp_enhanced_scale);
734 assert!(system.no_redirects_ipv6);
735 assert_eq!(system.nd_maxucast_retry.as_deref(), Some("5"));
736 }
737
738 #[test]
739 fn scalar_flags_and_limits_are_optional() {
740 let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
741 assert!(!system.allow_6pe_traceroute);
742 assert!(!system.management_instance);
743 assert!(!system.unattended_boot);
744 assert_eq!(system.arp_system_cache_limit, None);
745 assert_eq!(system.rng, None);
746 assert_eq!(system.saved_core_context, None);
747 assert!(system.offline_nodes.is_empty());
748 }
749
750 #[test]
751 fn extracts_auto_configuration_traceoptions_and_vnf_license_supplements() {
752 let system = system(&juniper::parse_braces(
753 "system {\n auto-configuration {\n traceoptions {\n file autoconf.log;\n level info;\n }\n }\n vnf-license-supplement {\n gnf1 augmented-ssrn-1;\n }\n}\n",
754 ))
755 .unwrap();
756 assert_eq!(
757 system.auto_configuration_traceoptions.unwrap().level.as_deref(),
758 Some("info")
759 );
760 assert_eq!(system.vnf_license_supplements, ["gnf1 augmented-ssrn-1"]);
761 }
762
763 #[test]
764 fn extracts_offline_nodes() {
765 let system = system(&juniper::parse_braces(
766 "system {\n node {\n offline re1;\n offline fpc3;\n }\n}\n",
767 ))
768 .unwrap();
769 assert_eq!(system.offline_nodes, ["re1", "fpc3"]);
770 }
771
772 #[test]
773 fn boot_loader_and_device_authentication_report_only_the_method() {
774 let system = system(&juniper::parse_braces(
775 r#"
776system {
777 boot-loader-authentication {
778 encrypted-password "$1$salt$hash"; ## SECRET-DATA
779 }
780 device-authentication {
781 encrypted-password "$6$salt$other"; ## SECRET-DATA
782 }
783}
784"#,
785 ))
786 .unwrap();
787 assert_eq!(system.boot_loader_authentication, ["encrypted-password"]);
788 assert_eq!(system.device_authentication, ["encrypted-password"]);
789 let values = |secrets: &[crate::system::AuthenticationSecret]| -> Vec<String> {
790 secrets.iter().map(|s| s.value.expose().to_string()).collect()
791 };
792 let (boot, device) = if cfg!(feature = "secrets") {
793 (vec!["$1$salt$hash".to_string()], vec!["$6$salt$other".to_string()])
794 } else {
795 (Vec::new(), Vec::new())
796 };
797 assert_eq!(values(&system.boot_loader_authentication_secrets), boot);
798 assert_eq!(values(&system.device_authentication_secrets), device);
799 }
800}