oltcore/vendors/huawei/ma5680t/
mod.rs1use crate::error::Result;
2use crate::olt::Olt;
3use crate::session::Session;
4use crate::types::{
5 AlarmDetail, AlarmListEntry, Fsp, LineProfile, LineProfileDetail, OntAddRequest, OntInfo,
6 OntInfoByDesc, OntOpticalInfo, OntPortNativeVlanRequest, OntSummaryPort, OntSummaryScope,
7 ServicePort, ServicePortAddRequest, ServicePortDetail, SrvProfile, UnprovisionedOnt, Vlan,
8 VlanDetail, VlanType,
9};
10
11pub struct Ma5680T {
12 session: Session,
13}
14
15impl Ma5680T {
16 const NEWLINE: &str = "\n";
17}
18
19impl Olt for Ma5680T {
20 fn connect(host: &str, port: i32, user: &str, pass: &str) -> Result<Self> {
21 let session = Session::connect(host, port, user, pass)?;
22 Ok(Self { session })
23 }
24
25 fn list_unprovisioned_onts(&mut self) -> Result<Vec<UnprovisionedOnt>> {
26 let cmd = format!("display ont autofind all{}", Self::NEWLINE);
27 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
28 super::commands::parse_unprovisioned_onts(&output)
29 }
30
31 fn find_onts_by_description(&mut self, description: &str) -> Result<Vec<OntInfoByDesc>> {
32 let cmd = format!(
33 "display ont info by-desc \"{description}\"{}",
34 Self::NEWLINE
35 );
36 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
37 Ok(super::commands::parse_ont_info_by_desc(&output))
38 }
39
40 fn get_ont_by_sn(&mut self, serial_number: &str) -> Result<OntInfo> {
41 let cmd = format!("display ont info by-sn {serial_number}{}", Self::NEWLINE);
42 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
43 super::commands::parse_ont_info_by_sn(&output)
44 }
45
46 fn get_ont_summary(&mut self, scope: &OntSummaryScope) -> Result<Vec<OntSummaryPort>> {
47 let cmd = format!("display ont info summary {scope}{}", Self::NEWLINE);
48 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
49 Ok(super::commands::parse_ont_info_summary(&output))
50 }
51
52 fn list_line_profiles(&mut self) -> Result<Vec<LineProfile>> {
53 let cmd = format!("display ont-lineprofile gpon all{}", Self::NEWLINE);
54 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
55 Ok(super::commands::parse_line_profiles(&output))
56 }
57
58 fn get_line_profile(&mut self, id: u32) -> Result<LineProfileDetail> {
59 let cmd = format!(
60 "display ont-lineprofile gpon profile-id {id}{}",
61 Self::NEWLINE
62 );
63 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
64 super::commands::parse_line_profile_detail(&output)
65 }
66
67 fn list_service_profiles(&mut self) -> Result<Vec<SrvProfile>> {
68 let cmd = format!("display ont-srvprofile gpon all{}", Self::NEWLINE);
69 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
70 Ok(super::commands::parse_service_profiles(&output))
71 }
72
73 fn get_ont_optical_info(&mut self, fsp: &Fsp, ont_id: u32) -> Result<OntOpticalInfo> {
74 super::get_ont_optical_info(&mut self.session, fsp, ont_id, Self::NEWLINE)
75 }
76
77 fn ont_add(&mut self, request: &OntAddRequest) -> Result<u32> {
78 super::ont_add(&mut self.session, request, Self::NEWLINE)
79 }
80
81 fn ont_delete_all(&mut self, fsp: &Fsp) -> Result<()> {
82 super::ont_delete_all(&mut self.session, fsp, Self::NEWLINE)
83 }
84
85 fn ont_port_native_vlan(&mut self, request: &OntPortNativeVlanRequest) -> Result<()> {
86 super::ont_port_native_vlan(&mut self.session, request, Self::NEWLINE)
87 }
88
89 fn list_alarms_detail(&mut self) -> Result<Vec<AlarmDetail>> {
90 let cmd = format!("display alarm active all detail{}", Self::NEWLINE);
91 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
92 Ok(super::commands::parse_alarm_detail(&output))
93 }
94
95 fn list_alarms(&mut self) -> Result<Vec<AlarmListEntry>> {
96 let cmd = format!("display alarm active all list{}", Self::NEWLINE);
97 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
98 Ok(super::commands::parse_alarm_list(&output))
99 }
100
101 fn list_service_ports(&mut self) -> Result<Vec<ServicePort>> {
102 let cmd = format!("display service-port all{}", Self::NEWLINE);
103 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
104 super::commands::parse_service_port_table(&output)
105 }
106
107 fn get_service_port(&mut self, id: u32) -> Result<ServicePortDetail> {
108 let cmd = format!("display service-port {id}{}", Self::NEWLINE);
109 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
110 super::commands::parse_service_port_detail(&output)
111 }
112
113 fn list_service_ports_by_port(&mut self, fsp: &Fsp) -> Result<Vec<ServicePort>> {
114 let cmd = format!("display service-port port {fsp}{}", Self::NEWLINE);
115 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
116 super::commands::parse_service_port_table(&output)
117 }
118
119 fn list_service_ports_by_ont(&mut self, fsp: &Fsp, ont_id: u32) -> Result<Vec<ServicePort>> {
120 let cmd = format!(
121 "display service-port port {fsp} ont {ont_id}{}",
122 Self::NEWLINE
123 );
124 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
125 super::commands::parse_service_port_table(&output)
126 }
127
128 fn service_port_add(&mut self, request: &ServicePortAddRequest) -> Result<()> {
129 super::service_port_add(&mut self.session, request, Self::NEWLINE)
130 }
131
132 fn service_port_undo(&mut self, id: u32) -> Result<()> {
133 super::service_port_undo(&mut self.session, id, Self::NEWLINE)
134 }
135
136 fn list_vlans(&mut self) -> Result<Vec<Vlan>> {
137 let cmd = format!("display vlan all{}", Self::NEWLINE);
138 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
139 Ok(super::commands::parse_vlans(&output))
140 }
141
142 fn get_vlan(&mut self, id: u32) -> Result<VlanDetail> {
143 let cmd = format!("display vlan {id}{}", Self::NEWLINE);
144 let output = self.session.execute_command(&cmd, super::CONFIG_PROMPT)?;
145 super::commands::parse_vlan_detail(&output)
146 }
147
148 fn create_vlan(&mut self, id: u32, vlan_type: VlanType) -> Result<()> {
149 super::create_vlan(&mut self.session, id, vlan_type, Self::NEWLINE)
150 }
151
152 fn delete_vlan(&mut self, id: u32) -> Result<()> {
153 super::delete_vlan(&mut self.session, id, Self::NEWLINE)
154 }
155
156 fn ping(&mut self) -> Result<()> {
157 self.session.ping()
158 }
159
160 fn quit(&mut self) -> Result<()> {
161 self.session.quit()
162 }
163}