openthread/ot/types/
external_route_config.rs1use crate::prelude_internal::*;
6
7use core::fmt::{Debug, Formatter};
8
9#[derive(Default, Clone, Copy)]
12#[repr(transparent)]
13pub struct ExternalRouteConfig(pub otExternalRouteConfig);
14
15impl_ot_castable!(ExternalRouteConfig, otExternalRouteConfig);
16
17impl Debug for ExternalRouteConfig {
18 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
19 self.prefix().fmt(f)?;
20 if self.is_stable() {
21 write!(f, " STABLE")?;
22 }
23 if self.is_next_hop_this_device() {
24 write!(f, " NEXT_HOP_IS_THIS_DEVICE")?;
25 }
26 Ok(())
27 }
28}
29
30impl std::fmt::Display for ExternalRouteConfig {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
32 std::fmt::Debug::fmt(self, f)
33 }
34}
35
36impl ExternalRouteConfig {
37 pub fn from_prefix<T: Into<otIp6Prefix>>(prefix: T) -> ExternalRouteConfig {
39 let mut ret = ExternalRouteConfig(otExternalRouteConfig {
40 mPrefix: prefix.into(),
41 mRloc16: 0,
42 ..otExternalRouteConfig::default()
43 });
44 ret.set_stable(true);
45 ret
46 }
47
48 pub fn prefix(&self) -> &Ip6Prefix {
50 (&self.0.mPrefix).into()
51 }
52
53 pub fn rloc16(&self) -> u16 {
55 self.0.mRloc16
56 }
57
58 pub fn route_preference(&self) -> RoutePreference {
63 RoutePreference::from_i32((self.0.mPreference() << 30) >> 30)
64 .expect("Invalid route preference")
65 }
66
67 pub fn set_route_preference(&mut self, pref: RoutePreference) {
69 self.0.set_mPreference(pref as i32);
70 }
71
72 pub fn is_stable(&self) -> bool {
74 self.0.mStable()
75 }
76
77 pub fn set_stable(&mut self, x: bool) {
79 self.0.set_mStable(x)
80 }
81
82 pub fn is_next_hop_this_device(&self) -> bool {
84 self.0.mNextHopIsThisDevice()
85 }
86
87 pub fn is_nat64(&self) -> bool {
89 self.0.mNat64()
90 }
91
92 pub fn is_adv_pio(&self) -> bool {
94 self.0.mAdvPio()
95 }
96}