Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions activator/src/process/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

let (accesspass_pk_unspecified, _) = get_accesspass_pda(
Expand Down Expand Up @@ -1227,6 +1230,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

let (accesspass_pk_unspecified, _) = get_accesspass_pda(
Expand Down Expand Up @@ -1380,6 +1386,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

client
Expand Down Expand Up @@ -1497,6 +1506,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

client
Expand Down Expand Up @@ -1618,6 +1630,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

client
Expand Down Expand Up @@ -1730,6 +1745,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

let (accesspass_pk_unspecified, _) = get_accesspass_pda(
Expand Down Expand Up @@ -1892,6 +1910,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::new(9, 9, 9, 9),
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

// Expect a reject transaction
Expand Down Expand Up @@ -2010,6 +2031,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

client
Expand Down Expand Up @@ -2109,6 +2133,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

let user2 = user.clone();
Expand Down Expand Up @@ -2286,6 +2313,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

// Deallocate — this should free the IP even though publishers is empty
Expand Down Expand Up @@ -2339,6 +2369,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

deallocate_publisher_dz_ip(&ibrl_user, &mut publisher_dz_ips);
Expand Down Expand Up @@ -2454,6 +2487,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: demanded_endpoint,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

let (accesspass_pk_unspecified, _) = get_accesspass_pda(
Expand Down Expand Up @@ -2608,6 +2644,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::new(9, 9, 9, 9),
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

// Expect a reject transaction, NOT an activate
Expand Down Expand Up @@ -2697,6 +2736,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED, // no demand
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

let (accesspass_pk_unspecified, _) = get_accesspass_pda(
Expand Down Expand Up @@ -2850,6 +2892,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: demanded_endpoint,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

let (accesspass_pk_unspecified, _) = get_accesspass_pda(
Expand Down Expand Up @@ -3004,6 +3049,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::new(9, 9, 9, 9),
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

// Expect a reject transaction
Expand Down Expand Up @@ -3115,6 +3163,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

let (accesspass_pk_unspecified, _) = get_accesspass_pda(
Expand Down Expand Up @@ -3275,6 +3326,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

// SDK's CloseAccountUserCommand fetches the user
Expand Down Expand Up @@ -3395,6 +3449,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

let user2 = user.clone();
Expand Down
3 changes: 3 additions & 0 deletions activator/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
};

let mut users: HashMap<Pubkey, User> = HashMap::new();
Expand Down
3 changes: 3 additions & 0 deletions client/doublezero/src/command/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,9 @@ mod tests {
validator_pubkey: Pubkey::new_unique(),
tunnel_endpoint,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
}
}

Expand Down
3 changes: 3 additions & 0 deletions client/doublezero/src/command/disconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
}
}

Expand Down
3 changes: 3 additions & 0 deletions controlplane/doublezero-admin/src/cli/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ mod tests {
validator_pubkey: Pubkey::default(),
tunnel_endpoint: std::net::Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: Default::default(),
last_bgp_up_at: 0,
last_bgp_reported_at: 0,
}
}

Expand Down
20 changes: 20 additions & 0 deletions sdk/serviceability/python/serviceability/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,16 @@ def __str__(self) -> str:
return _names.get(self.value, "unknown")


class BGPStatus(IntEnum):
UNKNOWN = 0
UP = 1
DOWN = 2

def __str__(self) -> str:
_names = {0: "unknown", 1: "up", 2: "down"}
return _names.get(self.value, "unknown")


class MulticastGroupStatus(IntEnum):
PENDING = 0
ACTIVATED = 1
Expand Down Expand Up @@ -716,6 +726,11 @@ class User:
publishers: list[Pubkey] = field(default_factory=list)
subscribers: list[Pubkey] = field(default_factory=list)
validator_pub_key: Pubkey = Pubkey.default()
tunnel_endpoint: bytes = b"\x00" * 4
tunnel_flags: int = 0
bgp_status: BGPStatus = BGPStatus.UNKNOWN
last_bgp_up_at: int = 0
last_bgp_reported_at: int = 0

@classmethod
def from_bytes(cls, data: bytes) -> User:
Expand All @@ -737,6 +752,11 @@ def from_bytes(cls, data: bytes) -> User:
u.publishers = _read_pubkey_vec(r)
u.subscribers = _read_pubkey_vec(r)
u.validator_pub_key = _read_pubkey(r)
u.tunnel_endpoint = r.read_ipv4()
u.tunnel_flags = r.read_u8()
u.bgp_status = BGPStatus(r.read_u8())
u.last_bgp_up_at = r.read_u64()
u.last_bgp_reported_at = r.read_u64()
return u


Expand Down
15 changes: 15 additions & 0 deletions sdk/serviceability/python/serviceability/tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from serviceability.state import (
AccessPass,
BGPStatus,
Contributor,
Device,
Exchange,
Expand Down Expand Up @@ -226,9 +227,23 @@ def test_deserialize(self):
"TunnelId": u.tunnel_id,
"Status": u.status,
"ValidatorPubkey": u.validator_pub_key,
"TunnelFlags": u.tunnel_flags,
"BgpStatus": u.bgp_status,
"LastBgpUpAt": u.last_bgp_up_at,
"LastBgpReportedAt": u.last_bgp_reported_at,
},
)

def test_backward_compat_old_layout(self):
# Deserializing an account binary that predates bgp_status/last_bgp_up_at/last_bgp_reported_at
# must return zero values for those fields rather than failing.
data, _ = _load_fixture("user")
truncated = data[:-17] # remove bgp_status (1) + last_bgp_up_at (8) + last_bgp_reported_at (8)
u = User.from_bytes(truncated)
assert u.bgp_status == BGPStatus.UNKNOWN
assert u.last_bgp_up_at == 0
assert u.last_bgp_reported_at == 0


class TestFixtureMulticastGroup:
def test_deserialize(self):
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use doublezero_serviceability::state::{
multicastgroup::{MulticastGroup, MulticastGroupStatus},
programconfig::ProgramConfig,
tenant::{Tenant, TenantBillingConfig, TenantPaymentStatus},
user::{User, UserCYOA, UserStatus, UserType},
user::{BGPStatus, User, UserCYOA, UserStatus, UserType},
};
use serde::Serialize;

Expand Down Expand Up @@ -495,6 +495,9 @@ fn generate_user(dir: &Path) {
validator_pubkey,
tunnel_endpoint: Ipv4Addr::UNSPECIFIED,
tunnel_flags: 0,
bgp_status: BGPStatus::Up,
last_bgp_up_at: 1_700_000_000,
last_bgp_reported_at: 1_700_000_100,
};

let data = borsh::to_vec(&val).unwrap();
Expand Down Expand Up @@ -522,6 +525,10 @@ fn generate_user(dir: &Path) {
FieldValue { name: "Subscribers0".into(), value: pubkey_bs58(&subscriber_pk), typ: "pubkey".into() },
FieldValue { name: "ValidatorPubkey".into(), value: pubkey_bs58(&validator_pubkey), typ: "pubkey".into() },
FieldValue { name: "TunnelEndpoint".into(), value: "0.0.0.0".into(), typ: "ipv4".into() },
FieldValue { name: "TunnelFlags".into(), value: "0".into(), typ: "u8".into() },
FieldValue { name: "BgpStatus".into(), value: "1".into(), typ: "u8".into() },
FieldValue { name: "LastBgpUpAt".into(), value: "1700000000".into(), typ: "u64".into() },
FieldValue { name: "LastBgpReportedAt".into(), value: "1700000100".into(), typ: "u64".into() },
],
};

Expand Down
Binary file modified sdk/serviceability/testdata/fixtures/user.bin
Binary file not shown.
22 changes: 21 additions & 1 deletion sdk/serviceability/testdata/fixtures/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@
"name": "TunnelEndpoint",
"value": "0.0.0.0",
"typ": "ipv4"
},
{
"name": "TunnelFlags",
"value": "0",
"typ": "u8"
},
{
"name": "BgpStatus",
"value": "1",
"typ": "u8"
},
{
"name": "LastBgpUpAt",
"value": "1700000000",
"typ": "u64"
},
{
"name": "LastBgpReportedAt",
"value": "1700000100",
"typ": "u64"
}
]
}
}
Loading
Loading