Skip to main content

endhost_api_models/
lib.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//! Endhost API models library.
15
16use std::borrow::Cow;
17
18use sciparse::{identifier::isd_asn::IsdAsn, segment::SegmentsPage};
19
20use crate::underlays::Underlays;
21
22pub mod underlays;
23
24/// Underlay discovery trait.
25pub trait UnderlayDiscovery: Send + Sync {
26    /// List the underlays available to reach the given ISD-AS.
27    fn list_underlays(&self, isd_as: IsdAsn) -> Underlays;
28}
29
30/// Path segment error.
31#[derive(Debug)]
32pub enum SegmentsError {
33    /// Invalid argument.
34    InvalidArgument(Cow<'static, str>),
35    /// Internal error.
36    InternalError(Cow<'static, str>),
37}
38
39/// Segments discovery trait.
40#[async_trait::async_trait]
41pub trait SegmentsDiscovery: Send + Sync {
42    /// List path segments between the given source and destination ISD-ASes.
43    async fn list_segments(
44        &self,
45        src: IsdAsn,
46        dst: IsdAsn,
47        page_size: i32,
48        page_token: String,
49    ) -> Result<SegmentsPage, SegmentsError>;
50}