1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

use std::error::Error;
use std::str::FromStr;
use crate::{IpAddr, Ipv4Addr, Ipv6Addr,SocketAddrScion, SocketAddrV6, SocketAddrV4, Parser};
use crate::scion_parse_utils::{ make_ia ,as_to_dotted_hex, as_from_ia, isd_from_ia};

#[derive(Copy, Clone, PartialEq, Eq, Hash,Ord,PartialOrd,Debug)]

pub struct ScionAddr {
  pub  ia: u64,
    pub host: IpAddr,
}

impl Default for ScionAddr{
    fn default() -> Self {
        Self{ia: 0, host: IpAddr::default()}
    }
}

impl ScionAddr
{
    pub fn new( _ia: u64, _host: IpAddr)->ScionAddr
    {
        Self{ia:_ia, host: _host }
    }

    pub fn new1( _isd: u16, _as: u64, _host: IpAddr ) -> ScionAddr
    {
        Self{ ia: make_ia(_isd,_as), host: _host }
    }
    pub fn set_ia(&mut self, ia_: u64) 
    {
        self.ia  = ia_;
    }

    pub const fn get_ia(&self) -> u64
    {
        self.ia
    }

    pub fn set_isd(&mut self,isd_: u16)
    {
        self.set_ia( make_ia(isd_, self.get_as()) );
    }

    pub fn get_isd(&self) -> u16
    {
        isd_from_ia(self.get_ia())
    }

    pub fn get_as(&self) ->u64
    {
        as_from_ia( self.get_ia() )
    }

    pub fn set_as( &mut self, as_: u64)
    {
        self.set_ia(make_ia(self.get_isd(), as_));
    }

    pub fn get_host(&self)-> &IpAddr
    { & self.host }

    pub fn set_host(&mut self, h: IpAddr)
    {
        self.host=h;
    }
}


impl std::fmt::Display for ScionAddr {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.pad( & format!("{}-{},{}", self.get_isd()
        , as_to_dotted_hex(self.get_as() ), & self.host.to_string() ) )
    }
}