asterust 0.1.1__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {asterust-0.1.1 → asterust-0.2.0}/CHANGELOG.md +7 -0
- {asterust-0.1.1 → asterust-0.2.0}/Cargo.lock +4 -4
- {asterust-0.1.1 → asterust-0.2.0}/Cargo.toml +1 -1
- {asterust-0.1.1 → asterust-0.2.0}/PKG-INFO +12 -1
- {asterust-0.1.1/crates/asterust-py → asterust-0.2.0/crates/asterust-iosxe}/CHANGELOG.md +2 -2
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxe/Cargo.toml +1 -1
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxe/README.md +5 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxe/src/device.rs +10 -1
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxe/src/lib.rs +1 -0
- asterust-0.2.0/crates/asterust-iosxe/src/vrf.rs +170 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxr/CHANGELOG.md +6 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxr/Cargo.toml +1 -1
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxr/README.md +2 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxr/src/device.rs +11 -1
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxr/src/lib.rs +1 -0
- asterust-0.2.0/crates/asterust-iosxr/src/vrf.rs +150 -0
- asterust-0.2.0/crates/asterust-py/CHANGELOG.md +24 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-py/Cargo.toml +1 -1
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-py/README.md +11 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-py/src/iosxe.rs +54 -2
- asterust-0.2.0/crates/asterust-py/src/iosxr.rs +406 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-py/src/lib.rs +11 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-py/tests/test_iosxe.py +34 -0
- asterust-0.2.0/crates/asterust-py/tests/test_iosxr.py +198 -0
- {asterust-0.1.1 → asterust-0.2.0}/python/asterust/iosxe.py +5 -1
- asterust-0.2.0/python/asterust/iosxr.py +39 -0
- {asterust-0.1.1 → asterust-0.2.0}/release-plz.toml +0 -1
- asterust-0.1.1/crates/asterust-py/src/iosxr.rs +0 -183
- asterust-0.1.1/crates/asterust-py/tests/test_iosxr.py +0 -88
- asterust-0.1.1/python/asterust/iosxr.py +0 -21
- {asterust-0.1.1 → asterust-0.2.0}/.github/workflows/ci.yml +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/.github/workflows/publish-pypi.yml +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/.github/workflows/release-plz.yml +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/.gitignore +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/AGENTS.md +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/LICENSE-APACHE +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/LICENSE-MIT +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/Makefile +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/README.md +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxe/LICENSE-APACHE +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxe/LICENSE-MIT +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxe/src/bgp.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxe/src/interface.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxe/src/isis.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxe/src/ospf.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxe/tests/full_config.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxr/LICENSE-APACHE +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxr/LICENSE-MIT +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxr/src/bgp.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxr/src/interface.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxr/src/isis.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxr/src/ospf.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-iosxr/tests/full_config.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-py/src/config.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-py/src/repr.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/crates/asterust-py/tests/test_config.py +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/pyproject.toml +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/python/asterust/__init__.py +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/rustfmt.toml +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/src/config/cisco.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/src/config/juniper.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/src/config/mod.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/src/device.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/src/lib.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/tests/config_cisco.rs +0 -0
- {asterust-0.1.1 → asterust-0.2.0}/tests/config_juniper.rs +0 -0
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.2](https://github.com/asterust/asterust/compare/asterust-v0.2.1...asterust-v0.2.2) - 2026-11-26
|
|
11
|
+
|
|
12
|
+
### Other
|
|
13
|
+
|
|
14
|
+
- use the default asterust-py-v tag and release names for the Python package
|
|
15
|
+
- name the asterust-py GitHub Release after its py-v tag
|
|
16
|
+
|
|
10
17
|
## [0.2.1](https://github.com/asterust/asterust/compare/asterust-v0.2.0...asterust-v0.2.1) - 2026-11-26
|
|
11
18
|
|
|
12
19
|
### Added
|
|
@@ -13,28 +13,28 @@ dependencies = [
|
|
|
13
13
|
|
|
14
14
|
[[package]]
|
|
15
15
|
name = "asterust"
|
|
16
|
-
version = "0.2.
|
|
16
|
+
version = "0.2.2"
|
|
17
17
|
dependencies = [
|
|
18
18
|
"regex",
|
|
19
19
|
]
|
|
20
20
|
|
|
21
21
|
[[package]]
|
|
22
22
|
name = "asterust-iosxe"
|
|
23
|
-
version = "0.1.
|
|
23
|
+
version = "0.1.1"
|
|
24
24
|
dependencies = [
|
|
25
25
|
"asterust",
|
|
26
26
|
]
|
|
27
27
|
|
|
28
28
|
[[package]]
|
|
29
29
|
name = "asterust-iosxr"
|
|
30
|
-
version = "0.2.
|
|
30
|
+
version = "0.2.1"
|
|
31
31
|
dependencies = [
|
|
32
32
|
"asterust",
|
|
33
33
|
]
|
|
34
34
|
|
|
35
35
|
[[package]]
|
|
36
36
|
name = "asterust-py"
|
|
37
|
-
version = "0.
|
|
37
|
+
version = "0.2.0"
|
|
38
38
|
dependencies = [
|
|
39
39
|
"asterust",
|
|
40
40
|
"asterust-iosxe",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: asterust
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Requires-Dist: pytest ; extra == 'test'
|
|
5
5
|
Provides-Extra: test
|
|
6
6
|
Summary: Hierarchical network device config parsing with typed platform views (IOS XR).
|
|
@@ -25,6 +25,16 @@ for iface in device.interfaces:
|
|
|
25
25
|
device.ospf # list of OspfProcess
|
|
26
26
|
device.bgp # list of BgpProcess
|
|
27
27
|
device.isis # list of IsisInstance
|
|
28
|
+
device.vrfs # list of Vrf (route-targets, route-policies, maximum prefix)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
BGP exposes templates and VRFs as well as neighbors:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
bgp = device.bgp[0]
|
|
35
|
+
bgp.neighbors[0].use_neighbor_group # template inheritance
|
|
36
|
+
bgp.neighbor_groups, bgp.session_groups, bgp.af_groups
|
|
37
|
+
bgp.vrfs[0].neighbors[0].address_families[0].route_policy_in
|
|
28
38
|
```
|
|
29
39
|
|
|
30
40
|
IOS XE works the same way from `asterust.iosxe`:
|
|
@@ -35,6 +45,7 @@ from asterust.iosxe import IosXeDevice
|
|
|
35
45
|
device = IosXeDevice(running_config_text)
|
|
36
46
|
device.interfaces # includes ospf_area / isis_tag set per interface
|
|
37
47
|
device.bgp # neighbors assembled from `neighbor <addr> ...` lines
|
|
48
|
+
device.vrfs # `vrf definition` and legacy `ip vrf`
|
|
38
49
|
```
|
|
39
50
|
|
|
40
51
|
The generic tree is available for any platform:
|
|
@@ -7,8 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
## [0.1.1](https://github.com/asterust/asterust/compare/
|
|
10
|
+
## [0.1.1](https://github.com/asterust/asterust/compare/asterust-iosxe-v0.1.0...asterust-iosxe-v0.1.1) - 2026-11-26
|
|
11
11
|
|
|
12
12
|
### Added
|
|
13
13
|
|
|
14
|
-
- add
|
|
14
|
+
- *(iosxr,iosxe)* add VRF definition views
|
|
@@ -9,6 +9,7 @@ tree parsed by [asterust](https://github.com/asterust/asterust).
|
|
|
9
9
|
| `ospf` | `router ospf <id> [vrf <name>]` | router-id, `network` statements, passive interfaces |
|
|
10
10
|
| `bgp` | `router bgp <asn>` | router-id, address-families, neighbors (remote-as, description, peer-group) |
|
|
11
11
|
| `isis` | `router isis [tag]` | net |
|
|
12
|
+
| `vrf` | `vrf definition <name>`, `ip vrf <name>` | description, rd, per-address-family route-targets and import/export maps |
|
|
12
13
|
|
|
13
14
|
```rust
|
|
14
15
|
use asterust_iosxe::IosXeDevice;
|
|
@@ -21,3 +22,7 @@ for iface in device.interfaces() {
|
|
|
21
22
|
|
|
22
23
|
The per-module functions (e.g. `interface::interfaces(&config)`) work on any
|
|
23
24
|
`asterust::config::Config` if you already have one parsed.
|
|
25
|
+
|
|
26
|
+
## Sources
|
|
27
|
+
|
|
28
|
+
Unlike `asterust-iosxr`, these views are not yet grounded in a Cisco guide: the test fixtures are written from the IOS XE command syntax and have not been checked against a Cisco guide or a real device. Treat the `vrf` fixtures in particular as unverified.
|
|
@@ -4,6 +4,7 @@ use crate::bgp::{bgp_processes, BgpProcess};
|
|
|
4
4
|
use crate::interface::{interfaces, Interface};
|
|
5
5
|
use crate::isis::{isis_instances, IsisInstance};
|
|
6
6
|
use crate::ospf::{ospf_processes, OspfProcess};
|
|
7
|
+
use crate::vrf::{vrfs, Vrf};
|
|
7
8
|
use asterust::config::{cisco, Config};
|
|
8
9
|
|
|
9
10
|
/// A parsed IOS XE running config.
|
|
@@ -40,6 +41,10 @@ impl IosXeDevice {
|
|
|
40
41
|
bgp_processes(&self.config)
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
pub fn vrfs(&self) -> Vec<Vrf> {
|
|
45
|
+
vrfs(&self.config)
|
|
46
|
+
}
|
|
47
|
+
|
|
43
48
|
pub fn isis(&self) -> Vec<IsisInstance> {
|
|
44
49
|
isis_instances(&self.config)
|
|
45
50
|
}
|
|
@@ -65,12 +70,16 @@ router ospf 1
|
|
|
65
70
|
router bgp 65000
|
|
66
71
|
neighbor 10.255.0.2 remote-as 65000
|
|
67
72
|
!
|
|
73
|
+
vrf definition CUSTOMER-A
|
|
74
|
+
rd 65000:1
|
|
75
|
+
!
|
|
68
76
|
",
|
|
69
77
|
);
|
|
70
78
|
assert_eq!(device.interfaces()[0].name, "Loopback0");
|
|
71
79
|
assert_eq!(device.isis()[0].tag.as_deref(), Some("CORE"));
|
|
80
|
+
assert_eq!(device.vrfs()[0].rd.as_deref(), Some("65000:1"));
|
|
72
81
|
assert_eq!(device.ospf()[0].process_id, "1");
|
|
73
82
|
assert_eq!(device.bgp()[0].neighbors[0].address, "10.255.0.2");
|
|
74
|
-
assert_eq!(device.config().get_block_count(),
|
|
83
|
+
assert_eq!(device.config().get_block_count(), 5);
|
|
75
84
|
}
|
|
76
85
|
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
//! `vrf definition <name>` and legacy `ip vrf <name>` blocks.
|
|
2
|
+
|
|
3
|
+
use crate::{child_arg, child_args, line_arg};
|
|
4
|
+
use asterust::config::{Config, ConfigBlock, ConfigLine};
|
|
5
|
+
|
|
6
|
+
/// Route targets and maps for one address family of a VRF.
|
|
7
|
+
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
8
|
+
#[non_exhaustive]
|
|
9
|
+
pub struct VrfAddressFamily {
|
|
10
|
+
/// e.g. `"ipv4"` or `"ipv6"`.
|
|
11
|
+
pub name: String,
|
|
12
|
+
/// `route-target both` entries appear in both lists.
|
|
13
|
+
pub import_route_targets: Vec<String>,
|
|
14
|
+
pub export_route_targets: Vec<String>,
|
|
15
|
+
pub import_map: Option<String>,
|
|
16
|
+
pub export_map: Option<String>,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// An IOS XE VRF. The legacy `ip vrf` form has no address-family sections; its route targets and
|
|
20
|
+
/// maps are reported as a single `"ipv4"` address family.
|
|
21
|
+
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
22
|
+
#[non_exhaustive]
|
|
23
|
+
pub struct Vrf {
|
|
24
|
+
pub name: String,
|
|
25
|
+
pub description: Option<String>,
|
|
26
|
+
pub rd: Option<String>,
|
|
27
|
+
pub address_families: Vec<VrfAddressFamily>,
|
|
28
|
+
/// `true` for `ip vrf <name>`, `false` for `vrf definition <name>`.
|
|
29
|
+
pub legacy: bool,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
impl Vrf {
|
|
33
|
+
/// Build from a top-level `vrf definition <name>` or `ip vrf <name>` block, or `None` for any other block.
|
|
34
|
+
pub fn from_block(block: &ConfigBlock) -> Option<Self> {
|
|
35
|
+
let root = block.get_root_line();
|
|
36
|
+
let (name, legacy) = match line_arg(&root.text, "vrf definition") {
|
|
37
|
+
Some(name) => (name, false),
|
|
38
|
+
None => (line_arg(&root.text, "ip vrf")?, true),
|
|
39
|
+
};
|
|
40
|
+
if name.is_empty() {
|
|
41
|
+
return None;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let mut address_families: Vec<_> = root
|
|
45
|
+
.children
|
|
46
|
+
.iter()
|
|
47
|
+
.filter_map(|c| Some(parse_address_family(c, line_arg(&c.text, "address-family")?)))
|
|
48
|
+
.collect();
|
|
49
|
+
if legacy {
|
|
50
|
+
address_families.push(parse_address_family(root, "ipv4"));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Some(Self {
|
|
54
|
+
name: name.to_string(),
|
|
55
|
+
description: child_arg(root, "description").map(str::to_string),
|
|
56
|
+
rd: child_arg(root, "rd").map(str::to_string),
|
|
57
|
+
address_families,
|
|
58
|
+
legacy,
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// Every `vrf definition` and legacy `ip vrf` block in `config`.
|
|
64
|
+
pub fn vrfs(config: &Config) -> Vec<Vrf> {
|
|
65
|
+
config.blocks.iter().filter_map(Vrf::from_block).collect()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fn parse_address_family(line: &ConfigLine, name: &str) -> VrfAddressFamily {
|
|
69
|
+
let mut af = VrfAddressFamily {
|
|
70
|
+
name: name.to_string(),
|
|
71
|
+
import_route_targets: Vec::new(),
|
|
72
|
+
export_route_targets: Vec::new(),
|
|
73
|
+
import_map: child_arg(line, "import map").map(str::to_string),
|
|
74
|
+
export_map: child_arg(line, "export map").map(str::to_string),
|
|
75
|
+
};
|
|
76
|
+
for arg in child_args(line, "route-target") {
|
|
77
|
+
let mut words = arg.split_whitespace();
|
|
78
|
+
let (Some(direction), Some(target)) = (words.next(), words.next()) else {
|
|
79
|
+
continue;
|
|
80
|
+
};
|
|
81
|
+
if matches!(direction, "import" | "both") {
|
|
82
|
+
af.import_route_targets.push(target.to_string());
|
|
83
|
+
}
|
|
84
|
+
if matches!(direction, "export" | "both") {
|
|
85
|
+
af.export_route_targets.push(target.to_string());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
af
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
#[cfg(test)]
|
|
92
|
+
mod tests {
|
|
93
|
+
use super::*;
|
|
94
|
+
use asterust::config::cisco;
|
|
95
|
+
|
|
96
|
+
// Written from the IOS XE `vrf definition` / `ip vrf` command syntax. Not checked against a Cisco
|
|
97
|
+
// guide or a real device yet; see the README "Sources".
|
|
98
|
+
const CONFIG: &str = "
|
|
99
|
+
vrf definition CUSTOMER-A
|
|
100
|
+
description Customer A
|
|
101
|
+
rd 65000:1
|
|
102
|
+
!
|
|
103
|
+
address-family ipv4
|
|
104
|
+
route-target export 65000:1
|
|
105
|
+
route-target import 65000:1
|
|
106
|
+
route-target both 65000:100
|
|
107
|
+
import map FROM-CORE
|
|
108
|
+
export map TO-CORE
|
|
109
|
+
exit-address-family
|
|
110
|
+
!
|
|
111
|
+
address-family ipv6
|
|
112
|
+
route-target both 65000:6
|
|
113
|
+
exit-address-family
|
|
114
|
+
!
|
|
115
|
+
ip vrf LEGACY
|
|
116
|
+
rd 65000:9
|
|
117
|
+
route-target export 65000:9
|
|
118
|
+
route-target import 65000:9
|
|
119
|
+
import map LEGACY-IN
|
|
120
|
+
!
|
|
121
|
+
interface Loopback0
|
|
122
|
+
ip vrf forwarding LEGACY
|
|
123
|
+
!
|
|
124
|
+
";
|
|
125
|
+
|
|
126
|
+
#[test]
|
|
127
|
+
fn vrf_definition_with_address_families() {
|
|
128
|
+
let vrfs = vrfs(&cisco::parse(CONFIG));
|
|
129
|
+
assert_eq!(vrfs.len(), 2);
|
|
130
|
+
|
|
131
|
+
let vrf = &vrfs[0];
|
|
132
|
+
assert_eq!(vrf.name, "CUSTOMER-A");
|
|
133
|
+
assert_eq!(vrf.description.as_deref(), Some("Customer A"));
|
|
134
|
+
assert_eq!(vrf.rd.as_deref(), Some("65000:1"));
|
|
135
|
+
assert!(!vrf.legacy);
|
|
136
|
+
|
|
137
|
+
let names: Vec<_> = vrf.address_families.iter().map(|a| a.name.as_str()).collect();
|
|
138
|
+
assert_eq!(names, ["ipv4", "ipv6"]);
|
|
139
|
+
let ipv4 = &vrf.address_families[0];
|
|
140
|
+
assert_eq!(ipv4.import_route_targets, ["65000:1", "65000:100"]);
|
|
141
|
+
assert_eq!(ipv4.export_route_targets, ["65000:1", "65000:100"]);
|
|
142
|
+
assert_eq!(ipv4.import_map.as_deref(), Some("FROM-CORE"));
|
|
143
|
+
assert_eq!(ipv4.export_map.as_deref(), Some("TO-CORE"));
|
|
144
|
+
|
|
145
|
+
let ipv6 = &vrf.address_families[1];
|
|
146
|
+
assert_eq!(ipv6.import_route_targets, ["65000:6"]);
|
|
147
|
+
assert_eq!(ipv6.export_route_targets, ["65000:6"]);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
#[test]
|
|
151
|
+
fn legacy_ip_vrf_is_reported_as_one_ipv4_family() {
|
|
152
|
+
let vrfs = vrfs(&cisco::parse(CONFIG));
|
|
153
|
+
let legacy = &vrfs[1];
|
|
154
|
+
assert_eq!(legacy.name, "LEGACY");
|
|
155
|
+
assert!(legacy.legacy);
|
|
156
|
+
assert_eq!(legacy.rd.as_deref(), Some("65000:9"));
|
|
157
|
+
assert_eq!(legacy.address_families.len(), 1);
|
|
158
|
+
let af = &legacy.address_families[0];
|
|
159
|
+
assert_eq!(af.name, "ipv4");
|
|
160
|
+
assert_eq!(af.import_route_targets, ["65000:9"]);
|
|
161
|
+
assert_eq!(af.export_route_targets, ["65000:9"]);
|
|
162
|
+
assert_eq!(af.import_map.as_deref(), Some("LEGACY-IN"));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
#[test]
|
|
166
|
+
fn interface_vrf_forwarding_is_not_a_vrf_block() {
|
|
167
|
+
let config = cisco::parse(CONFIG);
|
|
168
|
+
assert!(Vrf::from_block(&config.blocks[2]).is_none());
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.1](https://github.com/asterust/asterust/compare/asterust-iosxr-v0.2.0...asterust-iosxr-v0.2.1) - 2026-11-26
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- *(iosxr,iosxe)* add VRF definition views
|
|
15
|
+
|
|
10
16
|
## [0.2.0](https://github.com/asterust/asterust/compare/asterust-iosxr-v0.1.0...asterust-iosxr-v0.2.0) - 2026-11-26
|
|
11
17
|
|
|
12
18
|
### Added
|
|
@@ -12,6 +12,7 @@ tree parsed by [asterust](https://github.com/asterust/asterust).
|
|
|
12
12
|
| `ospf` | `router ospf <id>` | router-id, areas and their interfaces |
|
|
13
13
|
| `bgp` | `router bgp <asn>` | router-id, timers, confederation, route-reflector cluster-id, address-families (networks, aggregates, redistribution), neighbors, neighbor/session/af-group templates, VRFs |
|
|
14
14
|
| `isis` | `router isis <tag>` | net, interfaces |
|
|
15
|
+
| `vrf` | `vrf <name>` | description, address-families (maximum prefix, import/export route-policy and route-targets) |
|
|
15
16
|
|
|
16
17
|
```rust
|
|
17
18
|
use asterust_iosxr::IosXrDevice;
|
|
@@ -37,6 +38,7 @@ The BGP model and its test fixtures follow Cisco's
|
|
|
37
38
|
| `TEMPLATES` | BGP Configuration: "Viewing Inherited Configurations" sample configuration |
|
|
38
39
|
| `ROUTE_REFLECTOR` | "Configuring a Route Reflector for BGP" and "Adjusting BGP Timers" |
|
|
39
40
|
| `PE_CE` | "Configuring BGP as a PE-CE Protocol" |
|
|
41
|
+
| `GUIDE_VRF` (`src/vrf.rs`) | "Defining the Virtual Routing and Forwarding Tables in Provider Edge Routers" (the guide's `123;234` route-target is a typo and is written `123:234`) |
|
|
40
42
|
|
|
41
43
|
The fixtures are adapted, not copied verbatim: the guide mostly shows interactive CLI sessions, so
|
|
42
44
|
they are reindented into running-config form and shortened. Release 4.1 is old; the neighbor,
|
|
@@ -4,6 +4,7 @@ use crate::bgp::{bgp_processes, BgpProcess};
|
|
|
4
4
|
use crate::interface::{interfaces, Interface};
|
|
5
5
|
use crate::isis::{isis_instances, IsisInstance};
|
|
6
6
|
use crate::ospf::{ospf_processes, OspfProcess};
|
|
7
|
+
use crate::vrf::{vrfs, Vrf};
|
|
7
8
|
use asterust::config::{cisco, Config};
|
|
8
9
|
|
|
9
10
|
/// A parsed IOS XR running config.
|
|
@@ -40,6 +41,10 @@ impl IosXrDevice {
|
|
|
40
41
|
bgp_processes(&self.config)
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
pub fn vrfs(&self) -> Vec<Vrf> {
|
|
45
|
+
vrfs(&self.config)
|
|
46
|
+
}
|
|
47
|
+
|
|
43
48
|
pub fn isis(&self) -> Vec<IsisInstance> {
|
|
44
49
|
isis_instances(&self.config)
|
|
45
50
|
}
|
|
@@ -67,12 +72,17 @@ router bgp 65000
|
|
|
67
72
|
remote-as 65000
|
|
68
73
|
!
|
|
69
74
|
!
|
|
75
|
+
vrf CUSTOMER-A
|
|
76
|
+
address-family ipv4 unicast
|
|
77
|
+
!
|
|
78
|
+
!
|
|
70
79
|
",
|
|
71
80
|
);
|
|
72
81
|
assert_eq!(device.interfaces()[0].name, "Loopback0");
|
|
73
82
|
assert_eq!(device.isis()[0].tag, "CORE");
|
|
83
|
+
assert_eq!(device.vrfs()[0].name, "CUSTOMER-A");
|
|
74
84
|
assert_eq!(device.ospf()[0].process_id, "1");
|
|
75
85
|
assert_eq!(device.bgp()[0].neighbors[0].address, "10.255.0.2");
|
|
76
|
-
assert_eq!(device.config().get_block_count(),
|
|
86
|
+
assert_eq!(device.config().get_block_count(), 5);
|
|
77
87
|
}
|
|
78
88
|
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
//! `vrf <name>` definitions. The `vrf` sections under `router bgp` are modelled by [`crate::bgp::BgpVrf`].
|
|
2
|
+
|
|
3
|
+
use crate::{child_arg, line_arg};
|
|
4
|
+
use asterust::config::{Config, ConfigBlock, ConfigLine};
|
|
5
|
+
|
|
6
|
+
/// An `address-family <afi> <safi>` section of a VRF definition.
|
|
7
|
+
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
8
|
+
#[non_exhaustive]
|
|
9
|
+
pub struct VrfAddressFamily {
|
|
10
|
+
/// e.g. `"ipv4 unicast"`.
|
|
11
|
+
pub name: String,
|
|
12
|
+
pub maximum_prefix: Option<u32>,
|
|
13
|
+
pub import_route_policy: Option<String>,
|
|
14
|
+
pub export_route_policy: Option<String>,
|
|
15
|
+
pub import_route_targets: Vec<String>,
|
|
16
|
+
pub export_route_targets: Vec<String>,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// An IOS XR VRF definition.
|
|
20
|
+
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
21
|
+
#[non_exhaustive]
|
|
22
|
+
pub struct Vrf {
|
|
23
|
+
pub name: String,
|
|
24
|
+
pub description: Option<String>,
|
|
25
|
+
pub address_families: Vec<VrfAddressFamily>,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
impl Vrf {
|
|
29
|
+
/// Build from a top-level `vrf <name>` block, or `None` for any other block.
|
|
30
|
+
pub fn from_block(block: &ConfigBlock) -> Option<Self> {
|
|
31
|
+
let root = block.get_root_line();
|
|
32
|
+
let name = line_arg(&root.text, "vrf").filter(|n| !n.is_empty())?;
|
|
33
|
+
Some(Self {
|
|
34
|
+
name: name.to_string(),
|
|
35
|
+
description: child_arg(root, "description").map(str::to_string),
|
|
36
|
+
address_families: root
|
|
37
|
+
.children
|
|
38
|
+
.iter()
|
|
39
|
+
.filter_map(|c| Some(parse_address_family(c, line_arg(&c.text, "address-family")?)))
|
|
40
|
+
.collect(),
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// Every top-level `vrf` definition in `config`.
|
|
46
|
+
pub fn vrfs(config: &Config) -> Vec<Vrf> {
|
|
47
|
+
config.blocks.iter().filter_map(Vrf::from_block).collect()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fn parse_address_family(line: &ConfigLine, name: &str) -> VrfAddressFamily {
|
|
51
|
+
VrfAddressFamily {
|
|
52
|
+
name: name.to_string(),
|
|
53
|
+
maximum_prefix: child_arg(line, "maximum prefix").and_then(|a| a.split_whitespace().next()?.parse().ok()),
|
|
54
|
+
import_route_policy: child_arg(line, "import route-policy").map(str::to_string),
|
|
55
|
+
export_route_policy: child_arg(line, "export route-policy").map(str::to_string),
|
|
56
|
+
import_route_targets: route_targets(line, "import"),
|
|
57
|
+
export_route_targets: route_targets(line, "export"),
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// Route targets listed as a block under `<direction> route-target` or inline after it.
|
|
62
|
+
fn route_targets(line: &ConfigLine, direction: &str) -> Vec<String> {
|
|
63
|
+
let keyword = format!("{direction} route-target");
|
|
64
|
+
let mut targets = Vec::new();
|
|
65
|
+
for c in &line.children {
|
|
66
|
+
if c.text == keyword {
|
|
67
|
+
targets.extend(c.children.iter().map(|t| t.text.clone()));
|
|
68
|
+
} else if let Some(target) = line_arg(&c.text, &keyword) {
|
|
69
|
+
targets.push(target.to_string());
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
targets
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#[cfg(test)]
|
|
76
|
+
mod tests {
|
|
77
|
+
use super::*;
|
|
78
|
+
use asterust::config::cisco;
|
|
79
|
+
|
|
80
|
+
// Adapted from Cisco's "Implementing BGP on Cisco IOS XR Software" (XR 12000, R4.1), section
|
|
81
|
+
// "Defining the Virtual Routing and Forwarding Tables in Provider Edge Routers"; the guide's
|
|
82
|
+
// export route-target `123;234` is a typo and is written `123:234` here. See the README "Sources".
|
|
83
|
+
const GUIDE_VRF: &str = "
|
|
84
|
+
vrf vrf_pe
|
|
85
|
+
address-family ipv4 unicast
|
|
86
|
+
maximum prefix 2300
|
|
87
|
+
import route-policy policy_a
|
|
88
|
+
import route-target
|
|
89
|
+
234:222
|
|
90
|
+
!
|
|
91
|
+
export route-policy policy_b
|
|
92
|
+
export route-target
|
|
93
|
+
123:234
|
|
94
|
+
!
|
|
95
|
+
!
|
|
96
|
+
!
|
|
97
|
+
";
|
|
98
|
+
|
|
99
|
+
#[test]
|
|
100
|
+
fn guide_vrf_definition() {
|
|
101
|
+
let vrfs = vrfs(&cisco::parse(GUIDE_VRF));
|
|
102
|
+
assert_eq!(vrfs.len(), 1);
|
|
103
|
+
|
|
104
|
+
let vrf = &vrfs[0];
|
|
105
|
+
assert_eq!(vrf.name, "vrf_pe");
|
|
106
|
+
let af = &vrf.address_families[0];
|
|
107
|
+
assert_eq!(af.name, "ipv4 unicast");
|
|
108
|
+
assert_eq!(af.maximum_prefix, Some(2300));
|
|
109
|
+
assert_eq!(af.import_route_policy.as_deref(), Some("policy_a"));
|
|
110
|
+
assert_eq!(af.export_route_policy.as_deref(), Some("policy_b"));
|
|
111
|
+
assert_eq!(af.import_route_targets, ["234:222"]);
|
|
112
|
+
assert_eq!(af.export_route_targets, ["123:234"]);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Not from the guide: description, a second address family and inline route-targets.
|
|
116
|
+
#[test]
|
|
117
|
+
fn description_second_family_and_inline_route_targets() {
|
|
118
|
+
let config = cisco::parse(
|
|
119
|
+
"
|
|
120
|
+
vrf CUSTOMER-A
|
|
121
|
+
description Customer A
|
|
122
|
+
address-family ipv4 unicast
|
|
123
|
+
import route-target 65000:1
|
|
124
|
+
export route-target 65000:1
|
|
125
|
+
!
|
|
126
|
+
address-family ipv6 unicast
|
|
127
|
+
import route-target
|
|
128
|
+
65000:6
|
|
129
|
+
65000:7
|
|
130
|
+
!
|
|
131
|
+
!
|
|
132
|
+
!
|
|
133
|
+
",
|
|
134
|
+
);
|
|
135
|
+
let vrf = Vrf::from_block(&config.blocks[0]).unwrap();
|
|
136
|
+
assert_eq!(vrf.description.as_deref(), Some("Customer A"));
|
|
137
|
+
let names: Vec<_> = vrf.address_families.iter().map(|a| a.name.as_str()).collect();
|
|
138
|
+
assert_eq!(names, ["ipv4 unicast", "ipv6 unicast"]);
|
|
139
|
+
assert_eq!(vrf.address_families[0].import_route_targets, ["65000:1"]);
|
|
140
|
+
assert_eq!(vrf.address_families[0].export_route_targets, ["65000:1"]);
|
|
141
|
+
assert_eq!(vrf.address_families[1].import_route_targets, ["65000:6", "65000:7"]);
|
|
142
|
+
assert!(vrf.address_families[1].export_route_targets.is_empty());
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#[test]
|
|
146
|
+
fn non_vrf_block_is_none() {
|
|
147
|
+
let config = cisco::parse("router bgp 65000\n bgp router-id 1.1.1.1\n");
|
|
148
|
+
assert!(Vrf::from_block(&config.blocks[0]).is_none());
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.2.0](https://github.com/asterust/asterust/compare/asterust-py-v0.1.1...asterust-py-v0.2.0) - 2026-11-26
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- *(py)* [**breaking**] expose IOS XR BGP templates and VRFs, and IOS XE/XR vrfs()
|
|
15
|
+
|
|
16
|
+
### Other
|
|
17
|
+
|
|
18
|
+
- point the asterust-py changelog compare link at the asterust-py-v tags
|
|
19
|
+
|
|
20
|
+
## [0.1.1](https://github.com/asterust/asterust/compare/asterust-py-v0.1.0...asterust-py-v0.1.1) - 2026-11-26
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- add asterust.iosxe Python module
|
|
@@ -15,6 +15,16 @@ for iface in device.interfaces:
|
|
|
15
15
|
device.ospf # list of OspfProcess
|
|
16
16
|
device.bgp # list of BgpProcess
|
|
17
17
|
device.isis # list of IsisInstance
|
|
18
|
+
device.vrfs # list of Vrf (route-targets, route-policies, maximum prefix)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
BGP exposes templates and VRFs as well as neighbors:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
bgp = device.bgp[0]
|
|
25
|
+
bgp.neighbors[0].use_neighbor_group # template inheritance
|
|
26
|
+
bgp.neighbor_groups, bgp.session_groups, bgp.af_groups
|
|
27
|
+
bgp.vrfs[0].neighbors[0].address_families[0].route_policy_in
|
|
18
28
|
```
|
|
19
29
|
|
|
20
30
|
IOS XE works the same way from `asterust.iosxe`:
|
|
@@ -25,6 +35,7 @@ from asterust.iosxe import IosXeDevice
|
|
|
25
35
|
device = IosXeDevice(running_config_text)
|
|
26
36
|
device.interfaces # includes ospf_area / isis_tag set per interface
|
|
27
37
|
device.bgp # neighbors assembled from `neighbor <addr> ...` lines
|
|
38
|
+
device.vrfs # `vrf definition` and legacy `ip vrf`
|
|
28
39
|
```
|
|
29
40
|
|
|
30
41
|
The generic tree is available for any platform:
|