numinnex commented on code in PR #2769:
URL: https://github.com/apache/iggy/pull/2769#discussion_r2833257252


##########
core/simulator/src/network.rs:
##########
@@ -0,0 +1,150 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Network abstraction layer for the cluster simulator.
+//!
+//! **Note:** Currently a thin passthrough over `PacketSimulator`. Once the
+//! Cluster and MessageBus layers are built, this will own
+//! process-to-bus routing, and node enable/disable logic.
+
+use crate::packet::{
+    ALLOW_ALL, BLOCK_ALL, LinkFilter, Packet, PacketSimulator, 
PacketSimulatorOptions, ProcessId,
+};
+use iggy_common::{header::GenericHeader, message::Message};
+
+/// Network layer for the cluster simulation.
+///
+/// This provides an interface over the `PacketSimulator` for the
+/// `Cluster` orchestrator to use. It handles:
+/// - Submitting packets into the network
+/// - Stepping the network to deliver ready packets
+/// - Managing network partitions and link states
+#[derive(Debug)]
+pub struct Network {
+    simulator: PacketSimulator,
+}
+
+impl Network {
+    /// Create a new network.
+    pub fn new(options: PacketSimulatorOptions) -> Self {
+        Self {
+            simulator: PacketSimulator::new(options),
+        }
+    }
+
+    /// Submit a message into the network.
+    ///
+    /// The message will be queued with a simulated delay and may be:
+    /// - Delivered normally after the delay
+    /// - Dropped (based on packet_loss_probability)
+    /// - Replayed/duplicated (based on replay_probability)
+    pub fn submit(&mut self, from: ProcessId, to: ProcessId, message: 
Message<GenericHeader>) {
+        self.simulator.submit(from, to, message);
+    }
+
+    /// Deliver all ready packets.
+    ///
+    /// The returned `Vec` is taken from an internal buffer. Pass it back via
+    /// [`recycle_buffer`](Self::recycle_buffer) after processing to reuse the
+    /// allocation on the next call.
+    pub fn step(&mut self) -> Vec<Packet> {
+        self.simulator.step()
+    }
+
+    /// Return a previously taken buffer for reuse. See 
[`PacketSimulator::recycle_buffer`].
+    pub fn recycle_buffer(&mut self, buf: Vec<Packet>) {
+        self.simulator.recycle_buffer(buf);
+    }
+
+    /// Advance network time by one tick.
+    ///
+    /// This should be called once per simulation tick, after all ready
+    /// packets have been delivered. Handles automatic partition lifecycle
+    /// and random path clogging.
+    pub fn tick(&mut self) {

Review Comment:
   Just leaving this comment in there for an reference point of how this will 
get integrated later on with the simulated server. 



##########
core/simulator/src/network.rs:
##########
@@ -0,0 +1,150 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Network abstraction layer for the cluster simulator.
+//!
+//! **Note:** Currently a thin passthrough over `PacketSimulator`. Once the
+//! Cluster and MessageBus layers are built, this will own
+//! process-to-bus routing, and node enable/disable logic.
+
+use crate::packet::{
+    ALLOW_ALL, BLOCK_ALL, LinkFilter, Packet, PacketSimulator, 
PacketSimulatorOptions, ProcessId,
+};
+use iggy_common::{header::GenericHeader, message::Message};
+
+/// Network layer for the cluster simulation.
+///
+/// This provides an interface over the `PacketSimulator` for the
+/// `Cluster` orchestrator to use. It handles:
+/// - Submitting packets into the network
+/// - Stepping the network to deliver ready packets
+/// - Managing network partitions and link states
+#[derive(Debug)]
+pub struct Network {
+    simulator: PacketSimulator,
+}
+
+impl Network {
+    /// Create a new network.
+    pub fn new(options: PacketSimulatorOptions) -> Self {
+        Self {
+            simulator: PacketSimulator::new(options),
+        }
+    }
+
+    /// Submit a message into the network.
+    ///
+    /// The message will be queued with a simulated delay and may be:
+    /// - Delivered normally after the delay
+    /// - Dropped (based on packet_loss_probability)
+    /// - Replayed/duplicated (based on replay_probability)
+    pub fn submit(&mut self, from: ProcessId, to: ProcessId, message: 
Message<GenericHeader>) {
+        self.simulator.submit(from, to, message);
+    }
+
+    /// Deliver all ready packets.
+    ///
+    /// The returned `Vec` is taken from an internal buffer. Pass it back via
+    /// [`recycle_buffer`](Self::recycle_buffer) after processing to reuse the
+    /// allocation on the next call.
+    pub fn step(&mut self) -> Vec<Packet> {
+        self.simulator.step()
+    }
+
+    /// Return a previously taken buffer for reuse. See 
[`PacketSimulator::recycle_buffer`].
+    pub fn recycle_buffer(&mut self, buf: Vec<Packet>) {
+        self.simulator.recycle_buffer(buf);
+    }
+
+    /// Advance network time by one tick.
+    ///
+    /// This should be called once per simulation tick, after all ready
+    /// packets have been delivered. Handles automatic partition lifecycle
+    /// and random path clogging.
+    pub fn tick(&mut self) {

Review Comment:
   I've recon in our case the `tick` method will be probably replaced by an 
async function that will Poll an `step` Future and update the state of the 
network simulator and return an `Message` back.
   
   So for example we would have our tcp listener, which on accepted connection 
returns an `Sender`, which has async method `recv_message`, that Sender in 
simulation would be replaced with something that on `recv_message().await` 
would use the network simulator to receive it's message, by `ticking` the 
network simulator.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to