1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Utilities for managing and monitoring Retina cores.

pub(crate) mod monitor;
// pub(crate) mod ring;
pub(crate) mod rx_core;

use crate::dpdk;

use std::fmt;

use serde::{Deserialize, Serialize};

#[derive(Debug, Copy, Clone, Hash, Ord, Eq, PartialEq, PartialOrd)]
pub(crate) struct SocketId(pub(crate) u32);

impl SocketId {
    // For DPDK functions
    pub(crate) fn raw(&self) -> u32 {
        self.0
    }
}

impl fmt::Display for SocketId {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.0)
    }
}

/* --------------------------------------------------------------------------------- */

/// An identifier for a core running Retina (sink, monitoring, or RX).
#[derive(Debug, Copy, Clone, Hash, Ord, Eq, PartialEq, PartialOrd, Deserialize, Serialize)]
pub struct CoreId(pub u32);

impl CoreId {
    pub(crate) fn socket_id(&self) -> SocketId {
        unsafe { SocketId(dpdk::rte_lcore_to_socket_id(self.0)) }
    }

    /// The core ID as u32, primarily for DPDK functions
    pub fn raw(&self) -> u32 {
        self.0
    }
}

impl fmt::Display for CoreId {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.0)
    }
}