use std::net::{Ipv4Addr, Ipv6Addr};
use crate::{
packet_route::link::{GeneveDf, InfoData, InfoGeneve, InfoKind},
LinkMessageBuilder,
};
#[derive(Default, Debug)]
pub struct LinkGeneve;
impl LinkGeneve {
pub fn new(name: &str, vni: u32) -> LinkMessageBuilder<Self> {
LinkMessageBuilder::<LinkGeneve>::new(name).id(vni)
}
}
impl LinkMessageBuilder<LinkGeneve> {
pub fn new(name: &str) -> Self {
LinkMessageBuilder::<LinkGeneve>::new_with_info_kind(InfoKind::Geneve)
.name(name.to_string())
}
pub fn append_info_data(self, info: InfoGeneve) -> Self {
let mut ret = self;
if let InfoData::Geneve(infos) = ret
.info_data
.get_or_insert_with(|| InfoData::Geneve(Vec::new()))
{
infos.push(info);
}
ret
}
pub fn id(self, id: u32) -> Self {
self.append_info_data(InfoGeneve::Id(id))
}
pub fn remote(self, addr: Ipv4Addr) -> Self {
self.append_info_data(InfoGeneve::Remote(addr))
}
pub fn remote6(self, addr: Ipv6Addr) -> Self {
self.append_info_data(InfoGeneve::Remote6(addr))
}
pub fn local(self, addr: Ipv4Addr) -> Self {
self.append_info_data(InfoGeneve::Local(addr))
}
pub fn local6(self, addr: Ipv6Addr) -> Self {
self.append_info_data(InfoGeneve::Local6(addr))
}
pub fn ttl(self, ttl: u8) -> Self {
self.append_info_data(InfoGeneve::Ttl(ttl))
}
pub fn tos(self, tos: u8) -> Self {
self.append_info_data(InfoGeneve::Tos(tos))
}
pub fn port(self, port: u16) -> Self {
self.append_info_data(InfoGeneve::Port(port))
}
pub fn collect_metadata(self) -> Self {
self.append_info_data(InfoGeneve::CollectMetadata)
}
pub fn udp_csum(self, enable: bool) -> Self {
self.append_info_data(InfoGeneve::UdpCsum(enable))
}
pub fn udp_zero_csum6_tx(self, enable: bool) -> Self {
self.append_info_data(InfoGeneve::UdpZeroCsum6Tx(enable))
}
pub fn udp_zero_csum6_rx(self, enable: bool) -> Self {
self.append_info_data(InfoGeneve::UdpZeroCsum6Rx(enable))
}
pub fn label(self, label: u32) -> Self {
self.append_info_data(InfoGeneve::Label(label))
}
pub fn ttl_inherit(self, enable: bool) -> Self {
self.append_info_data(InfoGeneve::TtlInherit(enable))
}
pub fn df(self, df: GeneveDf) -> Self {
self.append_info_data(InfoGeneve::Df(df))
}
pub fn inner_proto_inherit(self) -> Self {
self.append_info_data(InfoGeneve::InnerProtoInherit)
}
}