use crate::{
packet_route::link::{
InfoData, InfoKind, InfoNetkit, NetkitMode, NetkitPolicy, NetkitScrub,
},
LinkMessageBuilder, LinkUnspec,
};
#[derive(Debug)]
pub struct LinkNetkit;
impl LinkNetkit {
pub fn new(
name: &str,
peer: &str,
mode: NetkitMode,
) -> LinkMessageBuilder<Self> {
LinkMessageBuilder::<LinkNetkit>::new(name, peer, mode)
}
}
impl LinkMessageBuilder<LinkNetkit> {
pub fn new(name: &str, peer: &str, mode: NetkitMode) -> Self {
LinkMessageBuilder::<LinkNetkit>::new_with_info_kind(InfoKind::Netkit)
.name(name.to_string())
.mode(mode)
.peer(peer)
}
pub fn peer(self, peer: &str) -> Self {
let peer_msg = LinkMessageBuilder::<LinkUnspec>::new()
.name(peer.to_string())
.build();
self.append_info_data(InfoNetkit::Peer(peer_msg))
}
pub fn mode(self, mode: NetkitMode) -> Self {
self.append_info_data(InfoNetkit::Mode(mode))
}
pub fn primary(self, primary: bool) -> Self {
self.append_info_data(InfoNetkit::Primary(primary))
}
pub fn policy(self, policy: NetkitPolicy) -> Self {
self.append_info_data(InfoNetkit::Policy(policy))
}
pub fn peer_policy(self, policy: NetkitPolicy) -> Self {
self.append_info_data(InfoNetkit::PeerPolicy(policy))
}
pub fn scrub(self, scrub: NetkitScrub) -> Self {
self.append_info_data(InfoNetkit::Scrub(scrub))
}
pub fn peer_scrub(self, scrub: NetkitScrub) -> Self {
self.append_info_data(InfoNetkit::PeerScrub(scrub))
}
pub fn headroom(self, headroom: u16) -> Self {
self.append_info_data(InfoNetkit::Headroom(headroom))
}
pub fn tailroom(self, tailroom: u16) -> Self {
self.append_info_data(InfoNetkit::Tailroom(tailroom))
}
fn append_info_data(mut self, info: InfoNetkit) -> Self {
if let InfoData::Netkit(ref mut infos) = self
.info_data
.get_or_insert_with(|| InfoData::Netkit(Vec::new()))
{
infos.push(info);
}
self
}
}