use std::{collections::BTreeMap, time::Duration};
use scion_proto::address::{IsdAsn, ScionAddr};
use serde::{Deserialize, Serialize};
use snap_control::server::state::dto::IoControlPlaneConfigDto;
use snap_dataplane::tunnel_gateway::state::dto::IoDataPlaneConfigDto;
use utoipa::ToSchema;
use crate::{
endhost_api::{EndhostApiId, EndhostApiState},
network::scion::topology::dto::ScionTopologyDto,
state::{
DEFAULT_SNAPTUN_KEEPALIVE_INTERVAL, RouterId,
control_service::ControlServiceState,
endhost_api_discovery::{EndhostApiDiscoveryApiId, EndhostApiDiscoveryStateDto},
external_as::dto::ExternalAsStateDto,
network_forwarder::NetworkForwarderState,
snap::SnapId,
},
};
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
pub struct SystemStateDto {
pub root_secret: Option<String>,
pub snap_token_public_key: String,
#[schema(nullable = false)]
#[serde(skip_serializing_if = "Option::is_none", default)]
pub auth_server_state: Option<AuthServerStateDto>,
#[serde(default = "default_snaptun_keepalive_interval")]
pub snaptun_keepalive_interval: Duration,
pub snaps: BTreeMap<SnapId, SnapStateDto>,
pub routers: BTreeMap<RouterId, RouterStateDto>,
pub endhost_apis: BTreeMap<EndhostApiId, EndhostApiState>,
pub endhost_api_discovery_api: BTreeMap<EndhostApiDiscoveryApiId, EndhostApiDiscoveryStateDto>,
#[schema(nullable = false)]
#[serde(skip_serializing_if = "Option::is_none", default)]
pub topology: Option<ScionTopologyDto>,
pub external_ases: BTreeMap<IsdAsn, ExternalAsStateDto>,
pub control_service_states: BTreeMap<IsdAsn, ControlServiceState>,
pub network_forwarders: BTreeMap<ScionAddr, NetworkForwarderState>,
}
fn default_snaptun_keepalive_interval() -> Duration {
DEFAULT_SNAPTUN_KEEPALIVE_INTERVAL
}
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
pub struct AuthServerStateDto {
pub token_exchanger: TokenExchangerStateDto,
}
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
pub struct TokenExchangerStateDto {
pub config: TokenExchangerConfigDto,
pub id_mapping: BTreeMap<String, String>,
}
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
pub struct TokenExchangerConfigDto {
pub private_key: String,
pub token_lifetime: Duration,
pub fake_idp: FakeIdpDto,
}
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
pub struct FakeIdpDto {
pub(crate) public_key: String,
}
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
pub struct IoConfigDto {
pub auth_server: IoAuthServerConfigDto,
pub snaps: BTreeMap<SnapId, IoSnapConfigDto>,
pub router_sockets: BTreeMap<RouterId, String>,
pub endhost_apis: BTreeMap<EndhostApiId, String>,
pub endhost_discovery_apis: BTreeMap<EndhostApiDiscoveryApiId, String>,
pub external_ases: BTreeMap<(IsdAsn, u16), String>,
pub network_forwarders: BTreeMap<ScionAddr, String>,
}
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
pub struct IoAuthServerConfigDto {
#[schema(nullable = false)]
#[serde(skip_serializing_if = "Option::is_none", default)]
pub(crate) addr: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
pub struct SnapStateDto {
pub isd_as: IsdAsn,
}
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
pub struct IoSnapConfigDto {
pub control_plane: IoControlPlaneConfigDto,
pub data_plane: IoDataPlaneConfigDto,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct RouterStateDto {
pub isd_as: IsdAsn,
pub if_ids: Vec<u16>,
#[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
pub snap_data_plane_interfaces: BTreeMap<String, String>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub snap_data_plane_excludes: Vec<String>,
}