Skip to content

Commit

Permalink
deal with TODOs:
Browse files Browse the repository at this point in the history
1. implement is_owner() method.
2. add skew time to VrrpInstance state
3. Implement send advert with priority 0
    when shutdown functionality is being carried out
  • Loading branch information
Paul-weqe committed Dec 9, 2024
1 parent 491f785 commit 7d1b424
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
27 changes: 25 additions & 2 deletions holo-vrrp/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,22 @@ impl Instance {
}

pub(crate) fn shutdown(&mut self, interface: &InterfaceView) {
if self.state.state == fsm::State::Master {
if self.state.state == fsm::State::Master
&& let Some(src_ip) = interface.system.addresses.first()
&& let Some(net) = &self.net
{
// Send an advertisement with Priority = 0.
// TODO
let mut pkt = self.generate_vrrp_packet();
pkt.priority = 0;
pkt.generate_checksum();

let packet = VrrpPacket {
ip: self.generate_ipv4_packet(src_ip.ip()),
vrrp: pkt,
};

let msg = NetTxPacketMsg::Vrrp { packet };
let _ = net.net_tx_packetp.send(msg);
}

// Transition to the Initialize state.
Expand Down Expand Up @@ -410,6 +423,16 @@ impl Instance {
let _ = net.net_tx_packetp.send(msg);
}
}

pub(crate) fn is_owner(&self, interface_sys: &InterfaceSys) -> bool {
let iter = self.config.virtual_addresses.iter();
for addr in iter {
if interface_sys.addresses.contains(addr) {
return true;
}
}
false
}
}

impl Drop for Instance {
Expand Down
11 changes: 5 additions & 6 deletions holo-vrrp/src/northbound/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,17 @@ fn load_callbacks() -> Callbacks<Interface> {
let iter = interface.instances.iter().map(|(vrid, instance)| ListEntry::Instance(*vrid, instance));
Some(Box::new(iter))
})
.get_object(|_interface, args| {
.get_object(|interface, args| {
use interfaces::interface::ipv4::vrrp::vrrp_instance::VrrpInstance;
let (vrid, instance) = args.list_entry.as_instance().unwrap();
Box::new(VrrpInstance {
vrid: *vrid,
state: Some(instance.state.state.to_yang()),
// TODO
is_owner: None,
is_owner: Some(instance.is_owner(&interface.system)),
last_adv_source: instance.state.last_adv_src.map(std::convert::Into::into).map(Cow::Owned).ignore_in_testing(),
up_datetime: instance.state.up_time.as_ref().map(Cow::Borrowed).ignore_in_testing(),
master_down_interval: instance.state.timer.as_master_down_timer().map(|task| task.remaining().as_millis() as u32 / 10).ignore_in_testing(),
// TODO
skew_time: None,
skew_time: Some(instance.config.skew_time() as u32),
last_event: Some(instance.state.last_event.to_yang()).ignore_in_testing(),
new_master_reason: Some(instance.state.new_master_reason.to_yang()),
})
Expand Down Expand Up @@ -81,7 +79,8 @@ fn load_callbacks() -> Callbacks<Interface> {

impl Provider for Interface {
// TODO
const STATE_PATH: &'static str = "";
const STATE_PATH: &'static str =
"/ietf-interfaces:interfaces/interface[type=holo-vrrp:vrrp][name='main']/ietf-vrrp:vrrp";

type ListEntry<'a> = ListEntry<'a>;

Expand Down

0 comments on commit 7d1b424

Please sign in to comment.