netconf_rs/vendor/h3c/
reply.rs1use serde_derive::Deserialize;
2
3#[derive(Debug, Deserialize, PartialEq, Eq)]
4pub struct RpcReply {
5 pub data: Data,
6}
7
8#[derive(Debug, Deserialize, PartialEq, Eq)]
9pub struct Data {
10 pub top: Option<Top>,
11 #[serde(rename = "netconf-state")]
12 pub netconf_state: Option<NetconfState>,
13}
14
15#[derive(Debug, Deserialize, PartialEq, Eq)]
16pub struct Top {
17 #[serde(rename = "Ifmgr")]
18 pub ifmgr: Option<Ifmgr>,
19 #[serde(rename = "MAC")]
20 pub mac: Option<Mac>,
21}
22
23#[derive(Debug, Deserialize, PartialEq, Eq)]
24pub struct Ifmgr {
25 #[serde(rename = "Interfaces")]
26 pub interfaces: Interfaces,
27}
28
29#[derive(Debug, Deserialize, PartialEq, Eq)]
30pub struct Interfaces {
31 #[serde(rename = "Interface")]
32 pub interface: Vec<Interface>,
33}
34
35#[derive(Debug, Deserialize, PartialEq, Eq)]
36pub struct Interface {
37 #[serde(rename = "IfIndex")]
38 pub index: usize,
39 #[serde(rename = "Description")]
40 pub description: Option<String>,
41 #[serde(rename = "PVID")]
42 pub port_vlan_id: Option<usize>,
43 #[serde(rename = "ConfigMTU")]
44 pub mtu: Option<usize>,
45 #[serde(rename = "LinkType")]
48 pub link_type: Option<usize>,
49 #[serde(rename = "PortLayer")]
52 pub port_layer: Option<usize>,
53}
54
55#[derive(Debug, Deserialize, PartialEq, Eq)]
56pub struct NetconfState {
57 pub capabilities: Capabilities,
58 pub schemas: Schemas,
59}
60
61#[derive(Debug, Deserialize, PartialEq, Eq)]
62pub struct Capabilities {
63 pub capability: Vec<String>,
64}
65
66#[derive(Debug, Deserialize, PartialEq, Eq)]
67pub struct Schemas {
68 pub schema: Vec<Schema>,
69}
70
71#[derive(Debug, Deserialize, PartialEq, Eq)]
72pub struct Schema {
73 pub identifier: String,
74 pub version: String,
75 pub format: String,
76 pub namespace: String,
77 pub location: String,
78}
79
80#[derive(Debug, Deserialize, PartialEq, Eq)]
81pub struct Mac {
82 #[serde(rename = "MacUnicastTable")]
83 pub table: MacUnicastTable,
84}
85
86#[derive(Debug, Deserialize, PartialEq, Eq)]
87pub struct MacUnicastTable {
88 #[serde(rename = "Unicast")]
89 pub unicast: Vec<Unicast>,
90}
91
92#[derive(Debug, Deserialize, PartialEq, Eq)]
93pub struct Unicast {
94 #[serde(rename = "VLANID")]
95 pub vlan_id: usize,
96 #[serde(rename = "MacAddress")]
97 pub mac_address: String,
98 #[serde(rename = "PortIndex")]
99 pub port_index: usize,
100 #[serde(rename = "Status")]
101 pub status: usize,
102 #[serde(rename = "Aging")]
103 pub aging: bool,
104}
105
106#[cfg(test)]
107mod tests {
108 use super::*;
109 use serde_xml_rs::from_str;
110
111 #[test]
112 fn parse_mac_table() {
113 let resp = r#"
114<?xml version="1.0" encoding="UTF-8"?>
115<rpc-reply
116 xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="100">
117 <data>
118 <top
119 xmlns="http://www.h3c.com/netconf/data:1.0">
120 <MAC>
121 <MacUnicastTable>
122 <Unicast>
123 <VLANID>1</VLANID>
124 <MacAddress>12-34-56-78-90-AB</MacAddress>
125 <PortIndex>634</PortIndex>
126 <Status>2</Status>
127 <Aging>true</Aging>
128 </Unicast>
129 <Unicast>
130 <VLANID>2</VLANID>
131 <MacAddress>11-11-11-11-11-11</MacAddress>
132 <PortIndex>10</PortIndex>
133 <Status>2</Status>
134 <Aging>true</Aging>
135 </Unicast>
136 </MacUnicastTable>
137 </MAC>
138 </top>
139 </data>
140</rpc-reply>
141 "#;
142
143 let reply: RpcReply = from_str(&resp.trim()).unwrap();
144 assert_eq!(
145 reply,
146 RpcReply {
147 data: Data {
148 top: Some(Top {
149 ifmgr: None,
150 mac: Some(Mac {
151 table: MacUnicastTable {
152 unicast: vec![
153 Unicast {
154 vlan_id: 1,
155 mac_address: String::from("12-34-56-78-90-AB"),
156 port_index: 634,
157 status: 2,
158 aging: true
159 },
160 Unicast {
161 vlan_id: 2,
162 mac_address: String::from("11-11-11-11-11-11"),
163 port_index: 10,
164 status: 2,
165 aging: true
166 }
167 ]
168 }
169 })
170 }),
171 netconf_state: None
172 }
173 }
174 );
175 }
176}