Skip to main content

asterust_junos/protocols/
evpn.rs

1//! `evpn`
2//! `protocols { evpn { ... } }`.
3//!
4//! The `interconnect`, `oism` and `source-packet-routing` blocks are not extracted.
5//!
6//! # See also
7//!
8//! - [evpn](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/evpn-edit-routing-instances-protocols.html)
9//! - [advertise-zero-ethernet-tag](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/advertise-zero-ethernet-tag-edit-protocols-evpn.html)
10//! - [assisted-replication](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/assisted-replication-edit-routing-instances-protocols-evpn.html)
11//! - [leaf (assisted replication)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/leaf-edit-protocols-evpn-assisted-replication.html)
12//! - [replicator](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/replicator-edit-protocols-evpn-assisted-replication.html)
13//! - [colored-tunnel-address](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/colored-tunnel-address-edit-routing-instances-protocols-evpn.html)
14//! - [default-gateway](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/default-gateway.html)
15//! - [duplicate-mac-detection](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/duplicate-mac-detection.html)
16//! - [encapsulation (EVPN)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/enapsulation-vxlan-edit-routing-instances.html)
17//! - [extended-vlan-list](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/extended-vlan-list-edit-routing-instances.html)
18//! - [extended-vni-list](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/extended-vni-list.html)
19//! - [interconnect multihoming peer gateways](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interconnect-multihoming-peer-gateways-protocols-evpn.html)
20//! - [interface (EVPN)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interface-edit-routing-instances-evpn.html)
21//! - [irb-symmetric-routing](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/irb-symmetric-routing-protocols-evpn.html)
22//! - [label-allocation](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/label-allocation-edit-routing-instances-protocols-evpn.html)
23//! - [mac-ip-limit](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/mac-ip-limit-edit-protocols-evpn.html)
24//! - [mac-list](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/mac-list-edit-protocols-evpn.html)
25//! - [multicast-mode](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/multicast-mode-evpn-edit-routing-instances.html)
26//! - [no-default-gateway-ext-comm](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/no-default-gateway-ext-comm-edit-routing-instances.html)
27//! - [pbb-evpn-core](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/pbb-evpn-core-edit-routing-instances.html)
28//! - [remote-ip-host-routes](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/remote-ip-host-routes.html)
29//! - [static-multihoming-peer](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/static-multihoming-peer-edit-protocols-evpn.html)
30//! - [traceoptions (EVPN)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/traceoptions-edit-protocols-evpns.html)
31//! - [Example: Configuring an EVPN-VXLAN Fabric (MX and QFX)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/evpn/topics/example/evpn-vxlan-mx-qfx-configuring.html)
32//! - [EVPN-VXLAN QFX5110 L3 gateway](https://networkingdocs.hpe.com/documentation/us/en/software/junos/evpn/topics/example/evpn-vxlan-qfx5110-l3-vxlan-gateway-collapsed.html)
33//! - [Configuring Loop Detection Settings](https://networkingdocs.hpe.com/documentation/us/en/software/junos/evpn/topics/task/configuring-loop-detection-settings.html)
34//! - [Configuring MAC Mobility Settings](https://networkingdocs.hpe.com/documentation/us/en/software/junos/evpn/topics/task/configuring-mac-mobility-settings.html)
35
36use super::traceoptions::{parse_traceoptions, Traceoptions};
37use crate::{active_children, arg_of, args_of, child_block, has_leaf, list_values, named_children, top_level};
38use asterust::config::{Config, ConfigLine};
39
40/// A MAC limit with its `packet-action`, as in `interface-mac-limit 100 { packet-action drop; }`.
41#[derive(Clone, Debug, PartialEq, Eq)]
42#[non_exhaustive]
43pub struct EvpnMacLimit {
44    pub limit: String,
45    pub packet_action: Option<String>,
46}
47
48/// An `interface <name>` entry of EVPN.
49#[derive(Clone, Debug, PartialEq, Eq)]
50#[non_exhaustive]
51pub struct EvpnInterface {
52    pub name: String,
53    pub ignore_encapsulation_mismatch: bool,
54    pub interface_mac_limit: Option<EvpnMacLimit>,
55    pub mac_pinning: bool,
56    pub no_mac_learning: bool,
57    pub static_macs: Vec<String>,
58}
59
60/// A `vrf-target` statement: a bare community, or a block with `import`, `export` and `auto`.
61#[derive(Clone, Debug, Default, PartialEq, Eq)]
62#[non_exhaustive]
63pub struct EvpnVrfTarget {
64    pub community: Option<String>,
65    pub auto: bool,
66    pub import: Option<String>,
67    pub export: Option<String>,
68}
69
70/// A `vni <number>` entry of `vni-options`.
71#[derive(Clone, Debug, PartialEq, Eq)]
72#[non_exhaustive]
73pub struct EvpnVniOptions {
74    pub vni: String,
75    /// Seconds.
76    pub designated_forwarder_election_hold_time: Option<String>,
77    pub vrf_target: Option<EvpnVrfTarget>,
78}
79
80/// The `duplicate-mac-detection` block.
81#[derive(Clone, Debug, Default, PartialEq, Eq)]
82#[non_exhaustive]
83pub struct EvpnDuplicateMacDetection {
84    /// Minutes.
85    pub auto_recovery_time: Option<String>,
86    pub detection_threshold: Option<String>,
87    /// Seconds.
88    pub detection_window: Option<String>,
89    /// `block` or `shutdown`.
90    pub action: Option<String>,
91    pub include_local_moves: bool,
92}
93
94/// The `assisted-replication` block.
95#[derive(Clone, Debug, Default, PartialEq, Eq)]
96#[non_exhaustive]
97pub struct EvpnAssistedReplication {
98    /// Seconds, from `leaf { replicator-activation-delay ...; }`.
99    pub leaf_replicator_activation_delay: Option<String>,
100    /// From `replicator { inet ...; }`.
101    pub replicator_inet: Option<String>,
102    /// From `replicator { vxlan-encapsulation-source-ip ...; }`.
103    pub replicator_vxlan_encapsulation_source_ip: Option<String>,
104}
105
106/// An entry of `mac-list`.
107#[derive(Clone, Debug, PartialEq, Eq)]
108#[non_exhaustive]
109pub struct EvpnMacList {
110    pub name: String,
111    pub mac_addresses: Vec<String>,
112}
113
114/// The `remote-ip-host-routes` block.
115#[derive(Clone, Debug, Default, PartialEq, Eq)]
116#[non_exhaustive]
117pub struct EvpnRemoteIpHostRoutes {
118    pub import: Vec<String>,
119    pub no_advertise_community: bool,
120}
121
122/// The `protocols evpn` configuration.
123#[derive(Clone, Debug, Default, PartialEq, Eq)]
124#[non_exhaustive]
125pub struct Evpn {
126    pub advertise_zero_ethernet_tag: bool,
127    pub assisted_replication: Option<EvpnAssistedReplication>,
128    /// `inet` and `inet6`, from `colored-tunnel-address`.
129    pub colored_tunnel_addresses: Vec<String>,
130    /// `advertise`, `do-not-advertise` or `no-gateway-community`.
131    pub default_gateway: Option<String>,
132    /// Seconds.
133    pub designated_forwarder_election_hold_time: Option<String>,
134    /// `highest` or `least`, from `designated-forwarder-preference-highest` and `-least`.
135    pub designated_forwarder_preference: Option<String>,
136    pub df_election_ntp: bool,
137    pub duplicate_mac_detection: Option<EvpnDuplicateMacDetection>,
138    /// e.g. `vxlan` or `mpls`.
139    pub encapsulation: Option<String>,
140    pub es_import_oldstyle: bool,
141    pub es_label_oldstyle: bool,
142    pub esi_resolution_per_bridge_domain: bool,
143    pub evpn_etree: bool,
144    pub extended_vlan_list: Vec<String>,
145    /// VNIs, or `all`.
146    pub extended_vni_list: Vec<String>,
147    pub interconnect_multihoming_peer_gateways: Vec<String>,
148    pub interconnected_vlan_list: Vec<String>,
149    pub interconnected_vni_list: Vec<String>,
150    pub interface_mac_limit: Option<EvpnMacLimit>,
151    pub interfaces: Vec<EvpnInterface>,
152    /// The VNI of `irb-symmetric-routing`.
153    pub irb_symmetric_routing_vni: Option<String>,
154    pub label_allocation: Option<String>,
155    pub leave_sync_route_oldstyle: bool,
156    pub mac_ip_limit: Option<String>,
157    pub mac_lists: Vec<EvpnMacList>,
158    /// `mac-mobility { no-sequence-numbers; }`.
159    pub mac_mobility_no_sequence_numbers: bool,
160    pub mac_statistics: bool,
161    pub mac_table_size: Option<EvpnMacLimit>,
162    /// `client` or `ingress-replication`.
163    pub multicast_mode: Option<String>,
164    pub no_core_isolation: bool,
165    pub no_default_gateway_ext_comm: bool,
166    pub no_mac_learning: bool,
167    pub p2mp_bud_support: bool,
168    pub pbb_evpn_core: bool,
169    pub peg_df_election_history: Option<String>,
170    pub pmsi_tunnel_endpoint: Option<String>,
171    pub remote_ip_host_routes: Option<EvpnRemoteIpHostRoutes>,
172    pub smet_etag_carry_vid: bool,
173    pub static_multihoming_peers: Vec<String>,
174    pub suppress_remote_host_routes_on_vlan_down: bool,
175    pub traceoptions: Option<Traceoptions>,
176    pub vni_options: Vec<EvpnVniOptions>,
177}
178
179fn list(line: &ConfigLine, keyword: &str) -> Vec<String> {
180    args_of(line, keyword).into_iter().flat_map(list_values).collect()
181}
182
183fn parse_mac_limit(limit: &str, entry: &ConfigLine) -> EvpnMacLimit {
184    EvpnMacLimit {
185        limit: limit.to_string(),
186        packet_action: arg_of(entry, "packet-action").map(str::to_string),
187    }
188}
189
190fn parse_vrf_target(parent: &ConfigLine) -> Option<EvpnVrfTarget> {
191    let leaf = arg_of(parent, "vrf-target");
192    let block = child_block(parent, "vrf-target");
193    if leaf.is_none() && block.is_none() {
194        return None;
195    }
196    let mut target = EvpnVrfTarget::default();
197    match leaf {
198        Some("auto") => target.auto = true,
199        Some(community) => target.community = Some(community.to_string()),
200        None => {}
201    }
202    if let Some(block) = block {
203        target.auto |= has_leaf(block, "auto");
204        target.import = arg_of(block, "import").map(str::to_string);
205        target.export = arg_of(block, "export").map(str::to_string);
206        target.community = active_children(block)
207            .map(|c| c.text.as_str())
208            .find(|text| *text != "auto" && !text.starts_with("import ") && !text.starts_with("export "))
209            .map(str::to_string);
210    }
211    Some(target)
212}
213
214fn parse_interface(name: &str, interface: &ConfigLine) -> EvpnInterface {
215    EvpnInterface {
216        name: name.to_string(),
217        ignore_encapsulation_mismatch: has_leaf(interface, "ignore-encapsulation-mismatch"),
218        interface_mac_limit: named_children(interface, "interface-mac-limit")
219            .next()
220            .map(|(limit, entry)| parse_mac_limit(limit, entry)),
221        mac_pinning: has_leaf(interface, "mac-pinning"),
222        no_mac_learning: has_leaf(interface, "no-mac-learning"),
223        static_macs: args_of(interface, "static-mac")
224            .into_iter()
225            .map(str::to_string)
226            .collect(),
227    }
228}
229
230/// Returns the `protocols evpn` block, or `None` if EVPN is not configured.
231///
232/// # Examples
233///
234/// ```
235/// use asterust::config::juniper;
236/// use asterust_junos::protocols::evpn::evpn;
237///
238/// let config = juniper::parse_braces("protocols {\n    evpn {\n        encapsulation vxlan;\n        extended-vni-list all;\n    }\n}\n");
239/// let evpn = evpn(&config).unwrap();
240/// assert_eq!(evpn.encapsulation.as_deref(), Some("vxlan"));
241/// assert_eq!(evpn.extended_vni_list, ["all"]);
242/// ```
243pub fn evpn(config: &Config) -> Option<Evpn> {
244    let evpn = child_block(top_level(config, "protocols")?, "evpn")?;
245    let field = |keyword: &str| arg_of(evpn, keyword).map(str::to_string);
246    let flag = |keyword: &str| has_leaf(evpn, keyword);
247    Some(Evpn {
248        advertise_zero_ethernet_tag: flag("advertise-zero-ethernet-tag"),
249        assisted_replication: child_block(evpn, "assisted-replication").map(|block| EvpnAssistedReplication {
250            leaf_replicator_activation_delay: child_block(block, "leaf")
251                .and_then(|leaf| arg_of(leaf, "replicator-activation-delay"))
252                .map(str::to_string),
253            replicator_inet: child_block(block, "replicator")
254                .and_then(|replicator| arg_of(replicator, "inet"))
255                .map(str::to_string),
256            replicator_vxlan_encapsulation_source_ip: child_block(block, "replicator")
257                .and_then(|replicator| arg_of(replicator, "vxlan-encapsulation-source-ip"))
258                .map(str::to_string),
259        }),
260        colored_tunnel_addresses: child_block(evpn, "colored-tunnel-address")
261            .map(|block| active_children(block).map(|c| c.text.clone()).collect())
262            .unwrap_or_default(),
263        default_gateway: field("default-gateway"),
264        designated_forwarder_election_hold_time: field("designated-forwarder-election-hold-time"),
265        designated_forwarder_preference: if flag("designated-forwarder-preference-highest") {
266            Some("highest".to_string())
267        } else if flag("designated-forwarder-preference-least") {
268            Some("least".to_string())
269        } else {
270            None
271        },
272        df_election_ntp: flag("df-election-ntp"),
273        duplicate_mac_detection: child_block(evpn, "duplicate-mac-detection").map(|block| EvpnDuplicateMacDetection {
274            auto_recovery_time: arg_of(block, "auto-recovery-time").map(str::to_string),
275            detection_threshold: arg_of(block, "detection-threshold").map(str::to_string),
276            detection_window: arg_of(block, "detection-window").map(str::to_string),
277            action: arg_of(block, "action").map(str::to_string),
278            include_local_moves: has_leaf(block, "include-local-moves"),
279        }),
280        encapsulation: field("encapsulation"),
281        es_import_oldstyle: flag("es-import-oldstyle"),
282        es_label_oldstyle: flag("es-label-oldstyle"),
283        esi_resolution_per_bridge_domain: flag("esi-resolution-per-bridge-domain"),
284        evpn_etree: flag("evpn-etree"),
285        extended_vlan_list: list(evpn, "extended-vlan-list"),
286        extended_vni_list: list(evpn, "extended-vni-list"),
287        interconnect_multihoming_peer_gateways: list(evpn, "interconnect-multihoming-peer-gateways"),
288        interconnected_vlan_list: list(evpn, "interconnected-vlan-list"),
289        interconnected_vni_list: list(evpn, "interconnected-vni-list"),
290        interface_mac_limit: named_children(evpn, "interface-mac-limit")
291            .next()
292            .map(|(limit, entry)| parse_mac_limit(limit, entry)),
293        interfaces: named_children(evpn, "interface")
294            .map(|(name, interface)| parse_interface(name, interface))
295            .collect(),
296        irb_symmetric_routing_vni: child_block(evpn, "irb-symmetric-routing")
297            .and_then(|block| arg_of(block, "vni"))
298            .map(str::to_string),
299        label_allocation: field("label-allocation"),
300        leave_sync_route_oldstyle: flag("leave-sync-route-oldstyle"),
301        mac_ip_limit: field("mac-ip-limit"),
302        mac_lists: named_children(evpn, "mac-list")
303            .map(|(name, entry)| EvpnMacList {
304                name: name.to_string(),
305                mac_addresses: active_children(entry).map(|c| c.text.clone()).collect(),
306            })
307            .collect(),
308        mac_mobility_no_sequence_numbers: child_block(evpn, "mac-mobility")
309            .is_some_and(|block| has_leaf(block, "no-sequence-numbers")),
310        mac_statistics: flag("mac-statistics"),
311        mac_table_size: named_children(evpn, "mac-table-size")
312            .next()
313            .map(|(limit, entry)| parse_mac_limit(limit, entry)),
314        multicast_mode: field("multicast-mode"),
315        no_core_isolation: flag("no-core-isolation"),
316        no_default_gateway_ext_comm: flag("no-default-gateway-ext-comm"),
317        no_mac_learning: flag("no-mac-learning"),
318        p2mp_bud_support: flag("p2mp-bud-support"),
319        pbb_evpn_core: flag("pbb-evpn-core"),
320        peg_df_election_history: field("peg-df-election-history"),
321        pmsi_tunnel_endpoint: field("pmsi-tunnel-endpoint"),
322        remote_ip_host_routes: child_block(evpn, "remote-ip-host-routes").map(|block| EvpnRemoteIpHostRoutes {
323            import: list(block, "import"),
324            no_advertise_community: has_leaf(block, "no-advertise-community"),
325        }),
326        smet_etag_carry_vid: flag("smet-etag-carry-vid"),
327        static_multihoming_peers: list(evpn, "static-multihoming-peer"),
328        suppress_remote_host_routes_on_vlan_down: flag("suppress-remote-host-routes-on-vlan-down"),
329        traceoptions: parse_traceoptions(evpn),
330        vni_options: child_block(evpn, "vni-options")
331            .map(|options| {
332                named_children(options, "vni")
333                    .map(|(vni, entry)| EvpnVniOptions {
334                        vni: vni.to_string(),
335                        designated_forwarder_election_hold_time: arg_of(
336                            entry,
337                            "designated-forwarder-election-hold-time",
338                        )
339                        .map(str::to_string),
340                        vrf_target: parse_vrf_target(entry),
341                    })
342                    .collect()
343            })
344            .unwrap_or_default(),
345    })
346}
347
348#[cfg(test)]
349mod tests {
350    use super::*;
351    use asterust::config::juniper;
352
353    // The `set protocols evpn` commands of Example: Configuring EVPN-VXLAN ... (MX and QFX, leaf-1), converted to
354    // hierarchy form; see the README "Sources".
355    const DOC_MX_QFX: &str = r#"
356protocols {
357    evpn {
358        encapsulation vxlan;
359        multicast-mode ingress-replication;
360        vni-options {
361            vni 101 {
362                vrf-target target:65000:101;
363            }
364            vni 102 {
365                vrf-target target:65000:102;
366            }
367        }
368        extended-vni-list 101;
369        extended-vni-list 102;
370    }
371}
372"#;
373
374    // The `set protocols evpn` commands of the QFX5110 L3 VXLAN gateway example, converted to hierarchy form.
375    const DOC_QFX5110: &str = r#"
376protocols {
377    evpn {
378        encapsulation vxlan;
379        default-gateway no-gateway-community;
380        multicast-mode ingress-replication;
381        vni-options {
382            vni 101 {
383                vrf-target target:101:1;
384            }
385            vni 102 {
386                vrf-target target:102:1;
387            }
388            vni 103 {
389                vrf-target target:103:1;
390            }
391        }
392        extended-vni-list all;
393    }
394}
395"#;
396
397    // The `duplicate-mac-detection` commands of Configuring Loop Detection Settings (written for a routing instance),
398    // converted to hierarchy form under `protocols evpn`.
399    const DOC_DUPLICATE_MAC: &str = r#"
400protocols {
401    evpn {
402        duplicate-mac-detection {
403            detection-threshold 3;
404            detection-window 5;
405            auto-recovery-time 10;
406            action block;
407            include-local-moves;
408        }
409    }
410}
411"#;
412
413    // Not from documentation: written from the CLI Reference pages of the statements. See the README "Sources".
414    const EXTRA: &str = r#"
415protocols {
416    evpn {
417        advertise-zero-ethernet-tag;
418        colored-tunnel-address {
419            inet;
420            inet6;
421        }
422        designated-forwarder-election-hold-time 30;
423        designated-forwarder-preference-least;
424        df-election-ntp;
425        es-import-oldstyle;
426        es-label-oldstyle;
427        esi-resolution-per-bridge-domain;
428        evpn-etree;
429        leave-sync-route-oldstyle;
430        extended-vlan-list [ 10 20 ];
431        extended-vni-list [ 1010 1020 ];
432        interconnect-multihoming-peer-gateways [ 10.0.0.1 10.0.0.2 ];
433        interconnected-vlan-list 30;
434        interconnected-vni-list all;
435        interface-mac-limit 1000 {
436            packet-action drop;
437        }
438        mac-table-size 2000 {
439            packet-action drop;
440        }
441        irb-symmetric-routing {
442            vni 9000;
443        }
444        label-allocation per-instance;
445        mac-ip-limit 500;
446        mac-mobility {
447            no-sequence-numbers;
448        }
449        mac-statistics;
450        no-core-isolation;
451        no-default-gateway-ext-comm;
452        no-mac-learning;
453        p2mp-bud-support;
454        pbb-evpn-core;
455        peg-df-election-history 5;
456        pmsi-tunnel-endpoint 10.9.9.9;
457        smet-etag-carry-vid;
458        suppress-remote-host-routes-on-vlan-down;
459        static-multihoming-peer [ 10.1.1.1 10.1.1.2 ];
460        default-gateway advertise;
461        multicast-mode client;
462        encapsulation mpls;
463        assisted-replication {
464            leaf {
465                replicator-activation-delay 10;
466            }
467            replicator {
468                inet 10.255.0.1;
469                vxlan-encapsulation-source-ip ingress-replication-ip;
470            }
471        }
472        mac-list BLOCKED {
473            00:11:22:33:44:55;
474            00:11:22:33:44:66;
475        }
476        remote-ip-host-routes {
477            import [ rih1 rih2 ];
478            no-advertise-community;
479        }
480        traceoptions {
481            file evpn.log size 1m;
482            flag all;
483        }
484        interface ge-0/0/0.0 {
485            ignore-encapsulation-mismatch;
486            interface-mac-limit 100 {
487                packet-action drop;
488            }
489            mac-pinning;
490            no-mac-learning;
491            static-mac 00:aa:bb:cc:dd:ee;
492        }
493        vni-options {
494            vni 1010 {
495                designated-forwarder-election-hold-time 20;
496                vrf-target {
497                    target:65000:1010;
498                    auto;
499                    import target:65000:1;
500                    export target:65000:2;
501                }
502            }
503            vni 1020 {
504                vrf-target auto;
505            }
506        }
507    }
508}
509"#;
510
511    fn evpn_of(text: &str) -> Evpn {
512        evpn(&juniper::parse_braces(text)).unwrap()
513    }
514
515    #[test]
516    fn reads_the_guide_mx_qfx_example() {
517        let evpn = evpn_of(DOC_MX_QFX);
518        assert_eq!(evpn.encapsulation.as_deref(), Some("vxlan"));
519        assert_eq!(evpn.multicast_mode.as_deref(), Some("ingress-replication"));
520        assert_eq!(evpn.extended_vni_list, ["101", "102"]);
521        assert_eq!(evpn.vni_options.len(), 2);
522        assert_eq!(evpn.vni_options[0].vni, "101");
523        let target = evpn.vni_options[0].vrf_target.as_ref().unwrap();
524        assert_eq!(target.community.as_deref(), Some("target:65000:101"));
525        assert!(!target.auto);
526        assert_eq!(
527            evpn.vni_options[1].vrf_target.as_ref().unwrap().community.as_deref(),
528            Some("target:65000:102")
529        );
530    }
531
532    #[test]
533    fn reads_the_guide_qfx5110_example() {
534        let evpn = evpn_of(DOC_QFX5110);
535        assert_eq!(evpn.default_gateway.as_deref(), Some("no-gateway-community"));
536        assert_eq!(evpn.extended_vni_list, ["all"]);
537        assert_eq!(evpn.vni_options.len(), 3);
538        assert_eq!(
539            evpn.vni_options[2].vrf_target.as_ref().unwrap().community.as_deref(),
540            Some("target:103:1")
541        );
542    }
543
544    #[test]
545    fn reads_the_guide_duplicate_mac_detection() {
546        let detection = evpn_of(DOC_DUPLICATE_MAC).duplicate_mac_detection.unwrap();
547        assert_eq!(detection.detection_threshold.as_deref(), Some("3"));
548        assert_eq!(detection.detection_window.as_deref(), Some("5"));
549        assert_eq!(detection.auto_recovery_time.as_deref(), Some("10"));
550        assert_eq!(detection.action.as_deref(), Some("block"));
551        assert!(detection.include_local_moves);
552    }
553
554    #[test]
555    fn reads_the_flags_and_simple_options() {
556        let evpn = evpn_of(EXTRA);
557        assert!(evpn.advertise_zero_ethernet_tag);
558        assert_eq!(evpn.colored_tunnel_addresses, ["inet", "inet6"]);
559        assert_eq!(evpn.designated_forwarder_election_hold_time.as_deref(), Some("30"));
560        assert_eq!(evpn.designated_forwarder_preference.as_deref(), Some("least"));
561        assert!(evpn.df_election_ntp);
562        assert!(evpn.es_import_oldstyle);
563        assert!(evpn.es_label_oldstyle);
564        assert!(evpn.esi_resolution_per_bridge_domain);
565        assert!(evpn.evpn_etree);
566        assert!(evpn.leave_sync_route_oldstyle);
567        assert_eq!(evpn.default_gateway.as_deref(), Some("advertise"));
568        assert_eq!(evpn.multicast_mode.as_deref(), Some("client"));
569        assert_eq!(evpn.encapsulation.as_deref(), Some("mpls"));
570        assert_eq!(evpn.label_allocation.as_deref(), Some("per-instance"));
571        assert_eq!(evpn.mac_ip_limit.as_deref(), Some("500"));
572        assert!(evpn.mac_mobility_no_sequence_numbers);
573        assert!(evpn.mac_statistics);
574        assert!(evpn.no_core_isolation);
575        assert!(evpn.no_default_gateway_ext_comm);
576        assert!(evpn.no_mac_learning);
577        assert!(evpn.p2mp_bud_support);
578        assert!(evpn.pbb_evpn_core);
579        assert_eq!(evpn.peg_df_election_history.as_deref(), Some("5"));
580        assert_eq!(evpn.pmsi_tunnel_endpoint.as_deref(), Some("10.9.9.9"));
581        assert!(evpn.smet_etag_carry_vid);
582        assert!(evpn.suppress_remote_host_routes_on_vlan_down);
583        assert_eq!(evpn.irb_symmetric_routing_vni.as_deref(), Some("9000"));
584    }
585
586    #[test]
587    fn reads_the_lists_and_limits() {
588        let evpn = evpn_of(EXTRA);
589        assert_eq!(evpn.extended_vlan_list, ["10", "20"]);
590        assert_eq!(evpn.extended_vni_list, ["1010", "1020"]);
591        assert_eq!(evpn.interconnect_multihoming_peer_gateways, ["10.0.0.1", "10.0.0.2"]);
592        assert_eq!(evpn.interconnected_vlan_list, ["30"]);
593        assert_eq!(evpn.interconnected_vni_list, ["all"]);
594        assert_eq!(evpn.static_multihoming_peers, ["10.1.1.1", "10.1.1.2"]);
595        let limit = evpn.interface_mac_limit.unwrap();
596        assert_eq!(limit.limit, "1000");
597        assert_eq!(limit.packet_action.as_deref(), Some("drop"));
598        assert_eq!(evpn.mac_table_size.unwrap().limit, "2000");
599    }
600
601    #[test]
602    fn reads_the_blocks() {
603        let evpn = evpn_of(EXTRA);
604        let replication = evpn.assisted_replication.unwrap();
605        assert_eq!(replication.leaf_replicator_activation_delay.as_deref(), Some("10"));
606        assert_eq!(replication.replicator_inet.as_deref(), Some("10.255.0.1"));
607        assert_eq!(
608            replication.replicator_vxlan_encapsulation_source_ip.as_deref(),
609            Some("ingress-replication-ip")
610        );
611        assert_eq!(evpn.mac_lists.len(), 1);
612        assert_eq!(evpn.mac_lists[0].name, "BLOCKED");
613        assert_eq!(
614            evpn.mac_lists[0].mac_addresses,
615            ["00:11:22:33:44:55", "00:11:22:33:44:66"]
616        );
617        let routes = evpn.remote_ip_host_routes.unwrap();
618        assert_eq!(routes.import, ["rih1", "rih2"]);
619        assert!(routes.no_advertise_community);
620        let trace = evpn.traceoptions.unwrap();
621        assert_eq!(trace.file.as_deref(), Some("evpn.log"));
622        assert_eq!(trace.flags[0].name, "all");
623    }
624
625    #[test]
626    fn reads_the_interface_options() {
627        let evpn = evpn_of(EXTRA);
628        let interface = &evpn.interfaces[0];
629        assert_eq!(interface.name, "ge-0/0/0.0");
630        assert!(interface.ignore_encapsulation_mismatch);
631        assert_eq!(interface.interface_mac_limit.as_ref().unwrap().limit, "100");
632        assert!(interface.mac_pinning);
633        assert!(interface.no_mac_learning);
634        assert_eq!(interface.static_macs, ["00:aa:bb:cc:dd:ee"]);
635    }
636
637    #[test]
638    fn reads_the_vni_options_forms() {
639        let evpn = evpn_of(EXTRA);
640        let first = &evpn.vni_options[0];
641        assert_eq!(first.designated_forwarder_election_hold_time.as_deref(), Some("20"));
642        let target = first.vrf_target.as_ref().unwrap();
643        assert_eq!(target.community.as_deref(), Some("target:65000:1010"));
644        assert!(target.auto);
645        assert_eq!(target.import.as_deref(), Some("target:65000:1"));
646        assert_eq!(target.export.as_deref(), Some("target:65000:2"));
647
648        let auto_only = evpn.vni_options[1].vrf_target.as_ref().unwrap();
649        assert!(auto_only.auto);
650        assert_eq!(auto_only.community, None);
651    }
652
653    #[test]
654    fn a_bare_evpn_block_has_nothing_set() {
655        assert_eq!(evpn_of("protocols {\n    evpn;\n}\n"), Evpn::default());
656    }
657
658    #[test]
659    fn no_evpn_is_none() {
660        let config = juniper::parse_braces("protocols {\n    ospf {\n        area 0.0.0.0;\n    }\n}\n");
661        assert_eq!(evpn(&config), None);
662    }
663}