1use crate::{
4 packet_route::link::{
5 InfoData, InfoKind, InfoNetkit, NetkitMode, NetkitPolicy, NetkitScrub,
6 },
7 LinkMessageBuilder, LinkUnspec,
8};
9
10#[derive(Debug)]
11pub struct LinkNetkit;
33
34impl LinkNetkit {
35 pub fn new(
37 name: &str,
38 peer: &str,
39 mode: NetkitMode,
40 ) -> LinkMessageBuilder<Self> {
41 LinkMessageBuilder::<LinkNetkit>::new(name, peer, mode)
42 }
43}
44
45impl LinkMessageBuilder<LinkNetkit> {
46 pub fn new(name: &str, peer: &str, mode: NetkitMode) -> Self {
48 LinkMessageBuilder::<LinkNetkit>::new_with_info_kind(InfoKind::Netkit)
49 .name(name.to_string())
50 .mode(mode)
51 .peer(peer)
52 }
53
54 pub fn peer(self, peer: &str) -> Self {
56 let peer_msg = LinkMessageBuilder::<LinkUnspec>::new()
57 .name(peer.to_string())
58 .build();
59
60 self.append_info_data(InfoNetkit::Peer(peer_msg))
61 }
62
63 pub fn mode(self, mode: NetkitMode) -> Self {
65 self.append_info_data(InfoNetkit::Mode(mode))
66 }
67
68 pub fn primary(self, primary: bool) -> Self {
70 self.append_info_data(InfoNetkit::Primary(primary))
71 }
72
73 pub fn policy(self, policy: NetkitPolicy) -> Self {
75 self.append_info_data(InfoNetkit::Policy(policy))
76 }
77
78 pub fn peer_policy(self, policy: NetkitPolicy) -> Self {
80 self.append_info_data(InfoNetkit::PeerPolicy(policy))
81 }
82
83 pub fn scrub(self, scrub: NetkitScrub) -> Self {
85 self.append_info_data(InfoNetkit::Scrub(scrub))
86 }
87
88 pub fn peer_scrub(self, scrub: NetkitScrub) -> Self {
90 self.append_info_data(InfoNetkit::PeerScrub(scrub))
91 }
92
93 pub fn headroom(self, headroom: u16) -> Self {
95 self.append_info_data(InfoNetkit::Headroom(headroom))
96 }
97
98 pub fn tailroom(self, tailroom: u16) -> Self {
100 self.append_info_data(InfoNetkit::Tailroom(tailroom))
101 }
102
103 fn append_info_data(mut self, info: InfoNetkit) -> Self {
105 if let InfoData::Netkit(ref mut infos) = self
106 .info_data
107 .get_or_insert_with(|| InfoData::Netkit(Vec::new()))
108 {
109 infos.push(info);
110 }
111 self
112 }
113}