Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 0b1d0ed

Browse files
author
Rain Liu
committed
add ssr
1 parent 7700878 commit 0b1d0ed

File tree

5 files changed

+144
-34
lines changed

5 files changed

+144
-34
lines changed

src/extended_report/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ pub mod dlrr;
55
pub mod prt;
66
pub mod rle;
77
pub mod rrt;
8-
/*pub mod ssr;
9-
pub mod vm;*/
8+
pub mod ssr;
9+
//pub mod vm;
1010
pub mod unknown;
1111

1212
pub use unknown::UnknownReportBlock;

src/extended_report/prt.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22

3-
const PRT_REPORT_BLOCK_MIN_LENGTH: u16 = 9;
3+
const PRT_REPORT_BLOCK_MIN_LENGTH: u16 = 8;
44

55
/// PacketReceiptTimesReportBlock represents a Packet Receipt Times
66
/// report block, as described in RFC 3611 section 4.3.
@@ -24,7 +24,10 @@ const PRT_REPORT_BLOCK_MIN_LENGTH: u16 = 9;
2424
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2525
#[derive(Debug, Default, PartialEq, Clone)]
2626
pub struct PacketReceiptTimesReportBlock {
27+
//not included in marshal/unmarshal
2728
pub t: u8,
29+
30+
//marshal/unmarshal
2831
pub ssrc: u32,
2932
pub begin_seq: u16,
3033
pub end_seq: u16,
@@ -92,7 +95,6 @@ impl Marshal for PacketReceiptTimesReportBlock {
9295
let n = h.marshal_to(buf)?;
9396
buf = &mut buf[n..];
9497

95-
buf.put_u8(self.t);
9698
buf.put_u32(self.ssrc);
9799
buf.put_u16(self.begin_seq);
98100
buf.put_u16(self.end_seq);
@@ -124,7 +126,8 @@ impl Unmarshal for PacketReceiptTimesReportBlock {
124126
return Err(error::Error::PacketTooShort.into());
125127
}
126128

127-
let t = raw_packet.get_u8();
129+
let t = xr_header.type_specific & 0x0F;
130+
128131
let ssrc = raw_packet.get_u32();
129132
let begin_seq = raw_packet.get_u16();
130133
let end_seq = raw_packet.get_u16();
@@ -137,6 +140,7 @@ impl Unmarshal for PacketReceiptTimesReportBlock {
137140

138141
Ok(PacketReceiptTimesReportBlock {
139142
t,
143+
140144
ssrc,
141145
begin_seq,
142146
end_seq,

src/extended_report/rle.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22

3-
const RLE_REPORT_BLOCK_MIN_LENGTH: u16 = 9;
3+
const RLE_REPORT_BLOCK_MIN_LENGTH: u16 = 8;
44

55
/// ChunkType enumerates the three kinds of chunks described in RFC 3611 section 4.1.
66
#[derive(Debug, Copy, Clone, PartialEq)]
@@ -104,8 +104,11 @@ impl Chunk {
104104
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
105105
#[derive(Debug, Default, PartialEq, Clone)]
106106
pub struct RLEReportBlock {
107+
//not included in marshal/unmarshal
107108
pub is_loss_rle: bool,
108109
pub t: u8,
110+
111+
//marshal/unmarshal
109112
pub ssrc: u32,
110113
pub begin_seq: u16,
111114
pub end_seq: u16,
@@ -187,7 +190,6 @@ impl Marshal for RLEReportBlock {
187190
let n = h.marshal_to(buf)?;
188191
buf = &mut buf[n..];
189192

190-
buf.put_u8(self.t);
191193
buf.put_u32(self.ssrc);
192194
buf.put_u16(self.begin_seq);
193195
buf.put_u16(self.end_seq);
@@ -220,7 +222,8 @@ impl Unmarshal for RLEReportBlock {
220222
}
221223

222224
let is_loss_rle = xr_header.block_type == BlockType::LossRLE;
223-
let t = raw_packet.get_u8();
225+
let t = xr_header.type_specific & 0x0F;
226+
224227
let ssrc = raw_packet.get_u32();
225228
let begin_seq = raw_packet.get_u16();
226229
let end_seq = raw_packet.get_u16();

src/extended_report/rrt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22

3-
const RRT_REPORT_BLOCK_MIN_LENGTH: u16 = 8;
3+
const RRT_REPORT_BLOCK_LENGTH: u16 = 8;
44

55
/// ReceiverReferenceTimeReportBlock encodes a Receiver Reference Time
66
/// report block as described in RFC 3611 section 4.4.
@@ -46,7 +46,7 @@ impl Packet for ReceiverReferenceTimeReportBlock {
4646
}
4747

4848
fn raw_size(&self) -> usize {
49-
XR_HEADER_LENGTH + RRT_REPORT_BLOCK_MIN_LENGTH as usize
49+
XR_HEADER_LENGTH + RRT_REPORT_BLOCK_LENGTH as usize
5050
}
5151

5252
fn as_any(&self) -> &(dyn Any + Send + Sync) {
@@ -99,7 +99,7 @@ impl Unmarshal for ReceiverReferenceTimeReportBlock {
9999

100100
let xr_header = XRHeader::unmarshal(raw_packet)?;
101101

102-
if xr_header.block_length != RRT_REPORT_BLOCK_MIN_LENGTH
102+
if xr_header.block_length != RRT_REPORT_BLOCK_LENGTH
103103
|| raw_packet.remaining() < xr_header.block_length as usize
104104
{
105105
return Err(error::Error::PacketTooShort.into());

src/extended_report/ssr.rs

Lines changed: 126 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use super::*;
22

3+
const SSR_REPORT_BLOCK_LENGTH: u16 = 4 + 2 * 2 + 4 * 6 + 4;
4+
35
/// StatisticsSummaryReportBlock encodes a Statistics Summary Report
46
/// Block as described in RFC 3611, section 4.6.
57
///
@@ -28,11 +30,13 @@ use super::*;
2830
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2931
#[derive(Debug, Default, PartialEq, Clone)]
3032
pub struct StatisticsSummaryReportBlock {
31-
pub xr_header: XRHeader,
33+
//not included in marshal/unmarshal
3234
pub loss_reports: bool,
3335
pub duplicate_reports: bool,
3436
pub jitter_reports: bool,
3537
pub ttl_or_hop_limit: TTLorHopLimitType,
38+
39+
//marshal/unmarshal
3640
pub ssrc: u32,
3741
pub begin_seq: u16,
3842
pub end_seq: u16,
@@ -90,49 +94,148 @@ impl fmt::Display for TTLorHopLimitType {
9094
}
9195
}
9296

93-
impl ReportBlock for StatisticsSummaryReportBlock {
94-
/// destination_ssrc returns an array of ssrc values that this report block refers to.
95-
fn destination_ssrc(&self) -> Vec<u32> {
96-
vec![self.ssrc]
97-
}
98-
99-
fn setup_block_header(&mut self) {
100-
self.xr_header.block_type = ReportBlockType::StatisticsSummary;
101-
self.xr_header.type_specific = 0x00;
97+
impl StatisticsSummaryReportBlock {
98+
pub fn xr_header(&self) -> XRHeader {
99+
let mut type_specific = 0x00;
102100
if self.loss_reports {
103-
self.xr_header.type_specific |= 0x80;
101+
type_specific |= 0x80;
104102
}
105103
if self.duplicate_reports {
106-
self.xr_header.type_specific |= 0x40;
104+
type_specific |= 0x40;
107105
}
108106
if self.jitter_reports {
109-
self.xr_header.type_specific |= 0x20;
107+
type_specific |= 0x20;
108+
}
109+
type_specific |= (self.ttl_or_hop_limit as u8 & 0x03) << 3;
110+
111+
XRHeader {
112+
block_type: BlockType::StatisticsSummary,
113+
type_specific,
114+
block_length: (self.raw_size() / 4 - 1) as u16,
110115
}
111-
self.xr_header.type_specific |= (self.ttl_or_hop_limit as u8 & 0x03) << 3;
112-
self.xr_header.block_length = (self.raw_size() / 4 - 1) as u16;
113116
}
117+
}
114118

115-
fn unpack_block_header(&mut self) {
116-
self.loss_reports = self.xr_header.type_specific & 0x80 != 0;
117-
self.duplicate_reports = self.xr_header.type_specific & 0x40 != 0;
118-
self.jitter_reports = self.xr_header.type_specific & 0x20 != 0;
119-
self.ttl_or_hop_limit = ((self.xr_header.type_specific & 0x18) >> 3).into();
119+
impl Packet for StatisticsSummaryReportBlock {
120+
fn header(&self) -> Header {
121+
Header::default()
122+
}
123+
124+
/// destination_ssrc returns an array of ssrc values that this report block refers to.
125+
fn destination_ssrc(&self) -> Vec<u32> {
126+
vec![self.ssrc]
120127
}
121128

122129
fn raw_size(&self) -> usize {
123-
4 + 3 + 1 + 4 + 2 * 2 + 4 * 6 + 4
130+
XR_HEADER_LENGTH + SSR_REPORT_BLOCK_LENGTH as usize
124131
}
125132

126133
fn as_any(&self) -> &(dyn Any + Send + Sync) {
127134
self
128135
}
129-
fn equal(&self, other: &(dyn ReportBlock + Send + Sync)) -> bool {
136+
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
130137
other
131138
.as_any()
132139
.downcast_ref::<StatisticsSummaryReportBlock>()
133140
.map_or(false, |a| self == a)
134141
}
135-
fn cloned(&self) -> Box<dyn ReportBlock + Send + Sync> {
142+
fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
136143
Box::new(self.clone())
137144
}
138145
}
146+
147+
impl MarshalSize for StatisticsSummaryReportBlock {
148+
fn marshal_size(&self) -> usize {
149+
self.raw_size()
150+
}
151+
}
152+
153+
impl Marshal for StatisticsSummaryReportBlock {
154+
/// marshal_to encodes the StatisticsSummaryReportBlock in binary
155+
fn marshal_to(&self, mut buf: &mut [u8]) -> Result<usize> {
156+
if buf.remaining_mut() < self.marshal_size() {
157+
return Err(error::Error::BufferTooShort.into());
158+
}
159+
160+
let h = self.xr_header();
161+
let n = h.marshal_to(buf)?;
162+
buf = &mut buf[n..];
163+
164+
buf.put_u32(self.ssrc);
165+
buf.put_u16(self.begin_seq);
166+
buf.put_u16(self.end_seq);
167+
buf.put_u32(self.lost_packets);
168+
buf.put_u32(self.dup_packets);
169+
buf.put_u32(self.min_jitter);
170+
buf.put_u32(self.max_jitter);
171+
buf.put_u32(self.mean_jitter);
172+
buf.put_u32(self.dev_jitter);
173+
buf.put_u8(self.min_ttl_or_hl);
174+
buf.put_u8(self.max_ttl_or_hl);
175+
buf.put_u8(self.mean_ttl_or_hl);
176+
buf.put_u8(self.dev_ttl_or_hl);
177+
178+
Ok(self.marshal_size())
179+
}
180+
}
181+
182+
impl Unmarshal for StatisticsSummaryReportBlock {
183+
/// Unmarshal decodes the StatisticsSummaryReportBlock from binary
184+
fn unmarshal<B>(raw_packet: &mut B) -> Result<Self>
185+
where
186+
Self: Sized,
187+
B: Buf,
188+
{
189+
if raw_packet.remaining() < XR_HEADER_LENGTH {
190+
return Err(error::Error::PacketTooShort.into());
191+
}
192+
193+
let xr_header = XRHeader::unmarshal(raw_packet)?;
194+
195+
if xr_header.block_length != SSR_REPORT_BLOCK_LENGTH
196+
|| raw_packet.remaining() < xr_header.block_length as usize
197+
{
198+
return Err(error::Error::PacketTooShort.into());
199+
}
200+
201+
let loss_reports = xr_header.type_specific & 0x80 != 0;
202+
let duplicate_reports = xr_header.type_specific & 0x40 != 0;
203+
let jitter_reports = xr_header.type_specific & 0x20 != 0;
204+
let ttl_or_hop_limit: TTLorHopLimitType = ((xr_header.type_specific & 0x18) >> 3).into();
205+
206+
let ssrc = raw_packet.get_u32();
207+
let begin_seq = raw_packet.get_u16();
208+
let end_seq = raw_packet.get_u16();
209+
let lost_packets = raw_packet.get_u32();
210+
let dup_packets = raw_packet.get_u32();
211+
let min_jitter = raw_packet.get_u32();
212+
let max_jitter = raw_packet.get_u32();
213+
let mean_jitter = raw_packet.get_u32();
214+
let dev_jitter = raw_packet.get_u32();
215+
let min_ttl_or_hl = raw_packet.get_u8();
216+
let max_ttl_or_hl = raw_packet.get_u8();
217+
let mean_ttl_or_hl = raw_packet.get_u8();
218+
let dev_ttl_or_hl = raw_packet.get_u8();
219+
220+
Ok(StatisticsSummaryReportBlock {
221+
loss_reports,
222+
duplicate_reports,
223+
jitter_reports,
224+
ttl_or_hop_limit,
225+
226+
ssrc,
227+
begin_seq,
228+
end_seq,
229+
lost_packets,
230+
dup_packets,
231+
min_jitter,
232+
max_jitter,
233+
mean_jitter,
234+
dev_jitter,
235+
min_ttl_or_hl,
236+
max_ttl_or_hl,
237+
mean_ttl_or_hl,
238+
dev_ttl_or_hl,
239+
})
240+
}
241+
}

0 commit comments

Comments
 (0)