endhost_api_models/
underlays.rs

1// Copyright 2025 Anapaya Systems
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//   http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//! Network underlay models.
15
16use std::net::SocketAddr;
17
18use scion_proto::address::IsdAsn;
19use serde::{Deserialize, Serialize};
20use url::Url;
21
22/// Network underlays available to the endhost.
23#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
24pub struct Underlays {
25    /// The UDP/IP underlay consisting of the available SCION routers.
26    pub udp_underlay: Vec<ScionRouter>,
27    /// The SNAP underlay.
28    pub snap_underlay: Vec<Snap>,
29}
30
31impl std::fmt::Display for Underlays {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        write!(
34            f,
35            "Underlays[udp: [{}] snap: [{}]]",
36            self.udp_underlay
37                .iter()
38                .map(|r| r.to_string())
39                .collect::<Vec<_>>()
40                .join(", "),
41            self.snap_underlay
42                .iter()
43                .map(|s| s.to_string())
44                .collect::<Vec<_>>()
45                .join(", ")
46        )
47    }
48}
49
50/// SCION router information.
51#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
52pub struct ScionRouter {
53    /// ISD-AS of the SCION router.
54    pub isd_as: IsdAsn,
55    /// The internal interface socket address of the SCION router.
56    pub internal_interface: SocketAddr,
57    /// The list of interfaces available on the SCION router.
58    pub interfaces: Vec<u16>,
59}
60
61impl std::fmt::Display for ScionRouter {
62    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63        write!(
64            f,
65            "ScionRouter[isd_as: {}, internal_interface: {}, interfaces: {:?}]",
66            self.isd_as, self.internal_interface, self.interfaces
67        )
68    }
69}
70
71/// The SNAP underlay consisting of the available SNAP control plane API.
72#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
73pub struct Snap {
74    /// The SNAP control plane API address.
75    pub address: Url,
76    /// The list of ISD-ASes available via this SNAP.
77    pub isd_ases: Vec<IsdAsn>,
78}
79
80impl std::fmt::Display for Snap {
81    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
82        write!(
83            f,
84            "Snap[address: {}, isd_ases: {:?}]",
85            self.address, self.isd_ases
86        )
87    }
88}