Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dpdk-sysroot-helper = { path = "./dpdk-sysroot-helper", package = "dataplane-dpd
dplane-rpc = { git = "https://github.com/githedgehog/dplane-rpc.git", rev = "e8fc33db10e1d00785f2a2b90cbadcad7900f200", features = [] }
errno = { path = "./errno", package = "dataplane-errno", features = [] }
flow-info = { path = "./flow-info", package = "dataplane-flow-info", features = [] }
gateway_config = { git = "https://github.com/githedgehog/gateway-proto", tag = "v0.19.0", features = [] }
gateway_config = { git = "https://github.com/githedgehog/gateway-proto", tag = "v0.20.0", features = [] }
gwname = { path = "./gwname", package = "dataplane-gwname", features = [] }
hardware = { path = "./hardware", package = "dataplane-hardware", features = [] }
id = { path = "./id", package = "dataplane-id", features = [] }
Expand Down
40 changes: 4 additions & 36 deletions config/src/converters/grpc/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,14 @@
use ::gateway_config::config as gateway_config;
use gateway_config::TracingConfig as ApiTracingConfig;

use crate::internal::device::{
DeviceConfig,
settings::{DeviceSettings, DpdkPortConfig, KernelPacketConfig, PacketDriver},
tracecfg::TracingConfig,
};
use crate::internal::device::{DeviceConfig, tracecfg::TracingConfig};

impl TryFrom<&gateway_config::Device> for DeviceConfig {
type Error = String;

fn try_from(device: &gateway_config::Device) -> Result<Self, Self::Error> {
// Convert driver enum
let driver = match ::gateway_config::PacketDriver::try_from(device.driver) {
Ok(::gateway_config::PacketDriver::Kernel) => {
PacketDriver::Kernel(KernelPacketConfig {})
}
Ok(::gateway_config::PacketDriver::Dpdk) => PacketDriver::DPDK(DpdkPortConfig {}),
Err(_) => return Err(format!("Invalid driver value: {}", device.driver)),
};

// Create device settings
let mut device_settings = DeviceSettings::new(&device.hostname);
device_settings = device_settings.set_packet_driver(driver);

// Create DeviceConfig with these settings
// Note: PortConfig is not yet implemented, so we don't add any ports
let mut device_config = DeviceConfig::new(device_settings);

// Create DeviceConfig
let mut device_config = DeviceConfig::new();
if let Some(tracing) = &device.tracing {
device_config.set_tracing(TracingConfig::try_from(tracing)?);
}
Expand All @@ -42,21 +23,8 @@ impl TryFrom<&DeviceConfig> for gateway_config::Device {
type Error = String;

fn try_from(device: &DeviceConfig) -> Result<Self, Self::Error> {
let driver = match device.settings.driver {
PacketDriver::Kernel(_) => ::gateway_config::PacketDriver::Kernel,
PacketDriver::DPDK(_) => ::gateway_config::PacketDriver::Dpdk,
};

// Convert ports if available
let ports = Vec::new(); // TODO: Implement port conversion when needed
let tracing = device.tracing.as_ref().map(ApiTracingConfig::from);

Ok(gateway_config::Device {
driver: driver.into(),
hostname: device.settings.hostname.clone(),
eal: None, // TODO: Handle EAL configuration when needed
ports,
tracing,
})
Ok(gateway_config::Device { tracing })
}
}
4 changes: 2 additions & 2 deletions config/src/converters/grpc/gateway_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::external::communities::PriorityCommunityTable;
use crate::external::gwgroup::{GwGroup, GwGroupTable};
use crate::external::overlay::Overlay;
use crate::external::underlay::Underlay;
use crate::internal::device::{DeviceConfig, settings::DeviceSettings};
use crate::internal::device::DeviceConfig;
use crate::{ExternalConfig, GwConfig};
use gateway_config::config::GatewayGroup;

Expand All @@ -29,7 +29,7 @@ pub fn convert_gateway_config_from_grpc_with_defaults(
DeviceConfig::try_from(device)?
} else {
warn!("Missing device configuration!");
DeviceConfig::new(DeviceSettings::new("Unset"))
DeviceConfig::new()
};

// convert underlay or provide a default (empty)
Expand Down
11 changes: 0 additions & 11 deletions config/src/converters/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ mod test {
fn create_test_gateway_config() -> GatewayConfig {
// Create device
let device = gateway_config::Device {
driver: 0, // Kernel
hostname: "test-gateway".to_string(),
ports: Vec::new(),
eal: None,
tracing: Some(create_tracing_config()),
};

Expand Down Expand Up @@ -388,10 +384,6 @@ mod test {

// Create test data with specific components
let device = gateway_config::Device {
driver: 0, // Kernel
hostname: "test-device".to_string(),
ports: Vec::new(),
eal: None,
tracing: Some(tracing.clone()),
};

Expand All @@ -415,14 +407,11 @@ mod test {
"TryFrom for DeviceConfig failed"
);
let device_config = device_config_result.unwrap();
assert_eq!(device_config.settings.hostname, "test-device");

// Back to gRPC
let device_back_result = gateway_config::Device::try_from(&device_config);
assert!(device_back_result.is_ok(), "TryFrom back to Device failed");
let device_back = device_back_result.unwrap();
assert_eq!(device_back.hostname, device.hostname);
assert_eq!(device_back.driver, device.driver);
assert_eq!(device_back.tracing.as_ref().unwrap(), &tracing);

// InterfaceConfig TryFrom
Expand Down
19 changes: 1 addition & 18 deletions config/src/converters/k8s/config/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,13 @@ use k8s_intf::gateway_agent_crd::GatewayAgent;

use crate::converters::k8s::FromK8sConversionError;
use crate::internal::device::DeviceConfig;
use crate::internal::device::settings::{DeviceSettings, KernelPacketConfig, PacketDriver};
use crate::internal::device::tracecfg::TracingConfig;

impl TryFrom<&GatewayAgent> for DeviceConfig {
type Error = FromK8sConversionError;

fn try_from(ga: &GatewayAgent) -> Result<Self, Self::Error> {
// We don't really use this, we take the actual value from the CLI
let driver = PacketDriver::Kernel(KernelPacketConfig {});

// Create device settings
let mut device_settings = DeviceSettings::new(ga.metadata.name.as_ref().ok_or(
FromK8sConversionError::MissingData("metadata.name is required".to_string()),
)?);
device_settings = device_settings.set_packet_driver(driver);

// Create DeviceConfig with these settings
// Note: PortConfig is not yet implemented, so we don't add any ports
let mut device_config = DeviceConfig::new(device_settings);
let mut device_config = DeviceConfig::new();

if let Some(logs) = &ga
.spec
Expand Down Expand Up @@ -53,11 +41,6 @@ mod test {
.for_each(|ga| {
let ga = ga.as_ref();
let dev = DeviceConfig::try_from(ga).unwrap();
assert_eq!(&dev.settings.hostname, ga.metadata.name.as_ref().unwrap());
assert!(matches!(
&dev.settings.driver,
&PacketDriver::Kernel(KernelPacketConfig {})
));
// Make sure we set tracing, the conversion is tested as part of the `TraceConfig` conversion
assert_eq!(
ga.spec.gateway.as_ref().unwrap().logs.is_some(),
Expand Down
3 changes: 1 addition & 2 deletions config/src/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub mod overlay;
pub mod underlay;

use crate::internal::device::DeviceConfig;
use crate::internal::device::settings::DeviceSettings;
use crate::{ConfigError, ConfigResult};
use communities::PriorityCommunityTable;
use derive_builder::Builder;
Expand Down Expand Up @@ -40,7 +39,7 @@ impl ExternalConfig {
pub fn new() -> Self {
Self {
genid: Self::BLANK_GENID,
device: DeviceConfig::new(DeviceSettings::new("Unset")),
device: DeviceConfig::new(),
underlay: Underlay::default(),
overlay: Overlay::default(),
gwgroups: GwGroupTable::new(),
Expand Down
16 changes: 3 additions & 13 deletions config/src/internal/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,21 @@

//! Dataplane configuration model: device

pub mod ports;
pub mod settings;
pub mod tracecfg;

use ports::PortConfig;
use settings::DeviceSettings;
use tracecfg::TracingConfig;
use tracing::{debug, error};

use crate::{ConfigError, ConfigResult};

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct DeviceConfig {
pub settings: DeviceSettings,
pub ports: Vec<PortConfig>,
pub tracing: Option<TracingConfig>,
}
impl DeviceConfig {
#[must_use]
pub fn new(settings: DeviceSettings) -> Self {
Self {
settings,
ports: vec![],
tracing: None,
}
pub fn new() -> Self {
Self { tracing: None }
}
pub fn set_tracing(&mut self, tracing: TracingConfig) {
self.tracing = Some(tracing);
Expand Down
9 changes: 0 additions & 9 deletions config/src/internal/device/ports.rs

This file was deleted.

39 changes: 0 additions & 39 deletions config/src/internal/device/settings.rs

This file was deleted.

7 changes: 3 additions & 4 deletions config/src/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::internal::routing::frr::Frr;
use crate::internal::routing::prefixlist::{PrefixList, PrefixListTable};
use crate::internal::routing::routemap::{RouteMap, RouteMapTable};
use crate::internal::routing::vrf::{VrfConfig, VrfConfigTable};
use gwname::get_gw_name;

#[derive(Clone, Debug)]
/* Main internal GW configuration */
Expand All @@ -39,11 +40,9 @@ pub struct InternalConfig {
impl InternalConfig {
#[must_use]
pub fn new(dev_cfg: DeviceConfig) -> Self {
let hostname = get_gw_name().unwrap_or_else(|| unreachable!());
// Frr profile is not configurable for the time being
let frr = Frr::new(
routing::frr::FrrProfile::Datacenter,
&dev_cfg.settings.hostname,
);
let frr = Frr::new(routing::frr::FrrProfile::Datacenter, hostname);
Self {
dev_cfg,
frr,
Expand Down
10 changes: 1 addition & 9 deletions mgmt/src/tests/mgmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ pub mod test {
use config::external::underlay::Underlay;

use config::internal::device::DeviceConfig;
use config::internal::device::settings::DeviceSettings;
use config::internal::device::settings::KernelPacketConfig;
use config::internal::device::settings::PacketDriver;
use config::internal::interfaces::interface::{
IfEthConfig, IfVtepConfig, InterfaceConfig, InterfaceType,
};
Expand Down Expand Up @@ -154,12 +151,7 @@ pub mod test {

/* DEVICE configuration */
fn sample_device_config() -> DeviceConfig {
/* device settings */
let settings = DeviceSettings::new("GW1")
.set_packet_driver(PacketDriver::Kernel(KernelPacketConfig {}));

/* device config */
DeviceConfig::new(settings)
DeviceConfig::new()
}

/* UNDERLAY, default VRF BGP AF configs */
Expand Down
3 changes: 1 addition & 2 deletions nat/src/stateful/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ mod tests {
use config::external::underlay::Underlay;
use config::internal::device::DeviceConfig;

use config::internal::device::settings::DeviceSettings;
use config::internal::interfaces::interface::{IfVtepConfig, InterfaceConfig, InterfaceType};
use config::internal::routing::bgp::BgpConfig;
use config::internal::routing::vrf::VrfConfig;
Expand Down Expand Up @@ -65,7 +64,7 @@ mod tests {
// Use a default configuration to build a valid GwConfig, the details are not really relevant to
// our tests
fn build_sample_config(overlay: Overlay) -> GwConfig {
let device_config = DeviceConfig::new(DeviceSettings::new("sample"));
let device_config = DeviceConfig::new();

let vtep = InterfaceConfig::new(
"vtep",
Expand Down
5 changes: 1 addition & 4 deletions nat/src/stateless/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ mod tests {
};
use config::external::underlay::Underlay;
use config::internal::device::DeviceConfig;
use config::internal::device::settings::DeviceSettings;
use config::internal::interfaces::interface::InterfaceConfig;
use config::internal::interfaces::interface::{IfVtepConfig, InterfaceType};
use config::internal::routing::bgp::BgpConfig;
Expand Down Expand Up @@ -487,8 +486,6 @@ mod tests {
// Now comes some default configuration to build a valid GwConfig, not really relevant to
// our tests

let device_config = DeviceConfig::new(DeviceSettings::new("sample"));

let vtep = InterfaceConfig::new(
"vtep",
InterfaceType::Vtep(IfVtepConfig {
Expand All @@ -510,7 +507,7 @@ mod tests {

let mut external_builder = ExternalConfigBuilder::default();
external_builder.genid(1);
external_builder.device(device_config);
external_builder.device(DeviceConfig::new());
external_builder.underlay(underlay);
external_builder.overlay(overlay);
external_builder.gwgroups(GwGroupTable::new());
Expand Down
Loading