snap_control/model.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//! SNAP control plane models.
15
16use std::net::SocketAddr;
17
18#[cfg(test)]
19use mockall::{automock, predicate::*};
20use scion_proto::address::IsdAsn;
21use snap_dataplane::session::{manager::SessionTokenError, state::SessionOpenError};
22use snap_tokens::snap_token::SnapTokenClaims;
23use thiserror::Error;
24
25use crate::crpc_api::api_service::model::SessionGrant;
26
27/// List the available data planes.
28#[cfg_attr(test, automock)]
29pub trait DataPlaneDiscovery: Send + Sync {
30 /// List all SNAP data planes.
31 fn list_snap_data_planes(&self) -> Vec<SnapDataPlane>;
32 /// List all UDP data planes.
33 fn list_udp_data_planes(&self) -> Vec<UdpDataPlane>;
34}
35
36/// Data plane session granter.
37#[cfg_attr(test, automock)]
38pub trait SessionGranter: Send + Sync {
39 /// Create a SNAP data plane session for the given address and SNAP token.
40 fn create_session(
41 &self,
42 addr: SocketAddr,
43 snap_token: SnapTokenClaims,
44 ) -> Result<SessionGrant, CreateSessionError>;
45}
46
47/// Session creation error.
48#[derive(Debug, Error)]
49pub enum CreateSessionError {
50 /// Data plane not found.
51 #[error("no data plane with matching address exists")]
52 DataPlaneNotFound,
53 /// Failed to open session.
54 #[error("open session error: {0}")]
55 OpenSession(#[from] SessionOpenError),
56 /// Failed to issue session token.
57 #[error("failed to issue session token: {0}")]
58 IssueSessionToken(#[from] SessionTokenError),
59}
60
61/// SNAP data plane information.
62pub struct SnapDataPlane {
63 /// The listener address of the data plane.
64 pub address: SocketAddr,
65 /// The ISD-ASes of the data plane.
66 pub isd_ases: Vec<IsdAsn>,
67}
68
69/// UDP data plane information.
70pub struct UdpDataPlane {
71 /// The UDP socket address of the data plane.
72 pub endpoint: SocketAddr,
73 /// The ISD-ASes and their associated interfaces for this UDP data plane.
74 pub isd_ases: Vec<IsdAsInterfaces>,
75}
76
77/// The interface IDs for an ISD-AS.
78pub struct IsdAsInterfaces {
79 /// The ISD-AS identifier
80 pub isd_as: IsdAsn,
81 /// The interface IDs for this ISD-AS
82 pub interfaces: Vec<u32>,
83}