-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support hex and hotspot usage reports at filestore and ingestor
- Loading branch information
Showing
12 changed files
with
753 additions
and
93 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
use std::convert::TryFrom; | ||
|
||
use crate::{ | ||
error::DecodeError, | ||
traits::{MsgDecode, MsgTimestamp, TimestampDecode, TimestampEncode}, | ||
Error, Result, | ||
}; | ||
use chrono::{DateTime, Utc}; | ||
use h3o::CellIndex; | ||
use helium_crypto::PublicKeyBinary; | ||
use helium_proto::services::poc_mobile::{ | ||
HexUsageCountsIngestReportV1, HexUsageCountsReqV1, RadioUsageCountsIngestReportV1, | ||
RadioUsageCountsReqV1, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)] | ||
pub struct HexUsageCountsReq { | ||
pub hex: CellIndex, | ||
pub helium_mobile_subscriber_avg_count: u64, | ||
pub helium_mobile_disco_mapping_avg_count: u64, | ||
pub offload_avg_count: u64, | ||
pub tmo_cell_avg_count: u64, | ||
pub timestamp: DateTime<Utc>, | ||
pub carrier_mapping_key: PublicKeyBinary, | ||
} | ||
|
||
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)] | ||
pub struct RadioUsageCountsReq { | ||
pub hotspot_pubkey: PublicKeyBinary, | ||
pub cbsd_id: String, | ||
pub helium_mobile_subscriber_avg_count: u64, | ||
pub helium_mobile_disco_mapping_avg_count: u64, | ||
pub offload_avg_count: u64, | ||
pub timestamp: DateTime<Utc>, | ||
pub carrier_mapping_key: PublicKeyBinary, | ||
} | ||
|
||
impl MsgDecode for HexUsageCountsReq { | ||
type Msg = HexUsageCountsReqV1; | ||
} | ||
|
||
impl MsgDecode for RadioUsageCountsReq { | ||
type Msg = RadioUsageCountsReqV1; | ||
} | ||
|
||
impl MsgTimestamp<Result<DateTime<Utc>>> for HexUsageCountsReqV1 { | ||
fn timestamp(&self) -> Result<DateTime<Utc>> { | ||
self.timestamp.to_timestamp() | ||
} | ||
} | ||
|
||
impl MsgTimestamp<u64> for HexUsageCountsReq { | ||
fn timestamp(&self) -> u64 { | ||
self.timestamp.encode_timestamp() | ||
} | ||
} | ||
|
||
impl MsgTimestamp<Result<DateTime<Utc>>> for RadioUsageCountsReqV1 { | ||
fn timestamp(&self) -> Result<DateTime<Utc>> { | ||
self.timestamp.to_timestamp() | ||
} | ||
} | ||
|
||
impl MsgTimestamp<u64> for RadioUsageCountsReq { | ||
fn timestamp(&self) -> u64 { | ||
self.timestamp.encode_timestamp() | ||
} | ||
} | ||
|
||
impl TryFrom<HexUsageCountsReqV1> for HexUsageCountsReq { | ||
type Error = Error; | ||
fn try_from(v: HexUsageCountsReqV1) -> Result<Self> { | ||
let timestamp = v.timestamp()?; | ||
let hex = CellIndex::try_from(v.hex).map_err(|_| { | ||
DecodeError::FileStreamTryDecode(format!("invalid CellIndex {}", v.hex)) | ||
})?; | ||
Ok(Self { | ||
hex, | ||
helium_mobile_subscriber_avg_count: v.helium_mobile_subscriber_avg_count, | ||
helium_mobile_disco_mapping_avg_count: v.helium_mobile_disco_mapping_avg_count, | ||
offload_avg_count: v.offload_avg_count, | ||
tmo_cell_avg_count: v.tmo_cell_avg_count, | ||
timestamp, | ||
carrier_mapping_key: v.carrier_mapping_key.into(), | ||
}) | ||
} | ||
} | ||
|
||
impl From<HexUsageCountsReq> for HexUsageCountsReqV1 { | ||
fn from(v: HexUsageCountsReq) -> Self { | ||
let timestamp = v.timestamp(); | ||
HexUsageCountsReqV1 { | ||
hex: v.hex.into(), | ||
helium_mobile_subscriber_avg_count: v.helium_mobile_subscriber_avg_count, | ||
helium_mobile_disco_mapping_avg_count: v.helium_mobile_disco_mapping_avg_count, | ||
offload_avg_count: v.offload_avg_count, | ||
tmo_cell_avg_count: v.tmo_cell_avg_count, | ||
timestamp, | ||
carrier_mapping_key: v.carrier_mapping_key.into(), | ||
signature: vec![], | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<RadioUsageCountsReqV1> for RadioUsageCountsReq { | ||
type Error = Error; | ||
fn try_from(v: RadioUsageCountsReqV1) -> Result<Self> { | ||
let timestamp = v.timestamp()?; | ||
Ok(Self { | ||
hotspot_pubkey: v.hotspot_pubkey.into(), | ||
cbsd_id: v.cbsd_id, | ||
helium_mobile_subscriber_avg_count: v.helium_mobile_subscriber_avg_count, | ||
helium_mobile_disco_mapping_avg_count: v.helium_mobile_disco_mapping_avg_count, | ||
offload_avg_count: v.offload_avg_count, | ||
timestamp, | ||
carrier_mapping_key: v.carrier_mapping_key.into(), | ||
}) | ||
} | ||
} | ||
|
||
impl From<RadioUsageCountsReq> for RadioUsageCountsReqV1 { | ||
fn from(v: RadioUsageCountsReq) -> Self { | ||
let timestamp = v.timestamp(); | ||
RadioUsageCountsReqV1 { | ||
hotspot_pubkey: v.hotspot_pubkey.into(), | ||
cbsd_id: v.cbsd_id, | ||
helium_mobile_subscriber_avg_count: v.helium_mobile_subscriber_avg_count, | ||
helium_mobile_disco_mapping_avg_count: v.helium_mobile_disco_mapping_avg_count, | ||
offload_avg_count: v.offload_avg_count, | ||
timestamp, | ||
carrier_mapping_key: v.carrier_mapping_key.into(), | ||
signature: vec![], | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)] | ||
pub struct HexUsageCountsIngestReport { | ||
pub report: HexUsageCountsReq, | ||
pub received_timestamp: DateTime<Utc>, | ||
} | ||
|
||
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)] | ||
pub struct RadioUsageCountsIngestReport { | ||
pub report: RadioUsageCountsReq, | ||
pub received_timestamp: DateTime<Utc>, | ||
} | ||
|
||
impl MsgDecode for HexUsageCountsIngestReport { | ||
type Msg = HexUsageCountsIngestReportV1; | ||
} | ||
|
||
impl MsgDecode for RadioUsageCountsIngestReport { | ||
type Msg = RadioUsageCountsIngestReportV1; | ||
} | ||
|
||
impl MsgTimestamp<Result<DateTime<Utc>>> for HexUsageCountsIngestReportV1 { | ||
fn timestamp(&self) -> Result<DateTime<Utc>> { | ||
self.received_timestamp.to_timestamp() | ||
} | ||
} | ||
|
||
impl MsgTimestamp<u64> for HexUsageCountsIngestReport { | ||
fn timestamp(&self) -> u64 { | ||
self.received_timestamp.encode_timestamp() | ||
} | ||
} | ||
|
||
impl MsgTimestamp<Result<DateTime<Utc>>> for RadioUsageCountsIngestReportV1 { | ||
fn timestamp(&self) -> Result<DateTime<Utc>> { | ||
self.received_timestamp.to_timestamp() | ||
} | ||
} | ||
|
||
impl MsgTimestamp<u64> for RadioUsageCountsIngestReport { | ||
fn timestamp(&self) -> u64 { | ||
self.received_timestamp.encode_timestamp() | ||
} | ||
} | ||
|
||
impl TryFrom<HexUsageCountsIngestReportV1> for HexUsageCountsIngestReport { | ||
type Error = Error; | ||
fn try_from(v: HexUsageCountsIngestReportV1) -> Result<Self> { | ||
Ok(Self { | ||
report: v | ||
.clone() | ||
.report | ||
.ok_or_else(|| Error::not_found("ingest HexUsageCountsIngestReport report"))? | ||
.try_into()?, | ||
received_timestamp: v.timestamp()?, | ||
}) | ||
} | ||
} | ||
|
||
impl From<HexUsageCountsIngestReport> for HexUsageCountsIngestReportV1 { | ||
fn from(v: HexUsageCountsIngestReport) -> Self { | ||
let received_timestamp = v.received_timestamp; | ||
let report: HexUsageCountsReqV1 = v.report.into(); | ||
Self { | ||
report: Some(report), | ||
received_timestamp: received_timestamp.encode_timestamp(), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<RadioUsageCountsIngestReportV1> for RadioUsageCountsIngestReport { | ||
type Error = Error; | ||
fn try_from(v: RadioUsageCountsIngestReportV1) -> Result<Self> { | ||
Ok(Self { | ||
report: v | ||
.clone() | ||
.report | ||
.ok_or_else(|| Error::not_found("ingest RadioUsageCountsIngestReport report"))? | ||
.try_into()?, | ||
received_timestamp: v.timestamp()?, | ||
}) | ||
} | ||
} | ||
|
||
impl From<RadioUsageCountsIngestReport> for RadioUsageCountsIngestReportV1 { | ||
fn from(v: RadioUsageCountsIngestReport) -> Self { | ||
let received_timestamp = v.received_timestamp; | ||
let report: RadioUsageCountsReqV1 = v.report.into(); | ||
Self { | ||
report: Some(report), | ||
received_timestamp: received_timestamp.encode_timestamp(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.