use crate::error::PfcpError;
use crate::ie::{Ie, IeType};
use crate::message::{header::Header, Message, MsgType};
use crate::types::{Seid, SequenceNumber};
#[derive(Debug, PartialEq)]
pub struct SessionDeletionResponse {
pub header: Header,
pub cause: Ie, pub offending_ie: Option<Ie>, pub load_control_information: Option<Ie>, pub overload_control_information: Option<Ie>, pub usage_reports: Vec<Ie>, pub additional_usage_reports_information: Option<Ie>, pub packet_rate_status_reports: Vec<Ie>, pub mbs_session_n4_information: Vec<Ie>, pub pfcpsdrsp_flags: Option<Ie>, pub tl_container: Vec<Ie>, pub ies: Vec<Ie>, }
impl Message for SessionDeletionResponse {
fn marshal(&self) -> Vec<u8> {
let mut buf = Vec::with_capacity(self.marshaled_size());
self.marshal_into(&mut buf);
buf
}
fn marshal_into(&self, buf: &mut Vec<u8>) {
buf.reserve(self.marshaled_size());
self.header.marshal_into(buf);
self.cause.marshal_into(buf);
if let Some(ref ie) = self.offending_ie {
ie.marshal_into(buf);
}
if let Some(ref ie) = self.load_control_information {
ie.marshal_into(buf);
}
if let Some(ref ie) = self.overload_control_information {
ie.marshal_into(buf);
}
for ie in &self.usage_reports {
ie.marshal_into(buf);
}
if let Some(ref ie) = self.additional_usage_reports_information {
ie.marshal_into(buf);
}
for ie in &self.packet_rate_status_reports {
ie.marshal_into(buf);
}
for ie in &self.mbs_session_n4_information {
ie.marshal_into(buf);
}
if let Some(ref ie) = self.pfcpsdrsp_flags {
ie.marshal_into(buf);
}
for ie in &self.tl_container {
ie.marshal_into(buf);
}
for ie in &self.ies {
ie.marshal_into(buf);
}
}
fn marshaled_size(&self) -> usize {
let mut size = self.header.len() as usize;
size += self.cause.len() as usize;
if let Some(ref ie) = self.offending_ie {
size += ie.len() as usize;
}
if let Some(ref ie) = self.load_control_information {
size += ie.len() as usize;
}
if let Some(ref ie) = self.overload_control_information {
size += ie.len() as usize;
}
for ie in &self.usage_reports {
size += ie.len() as usize;
}
if let Some(ref ie) = self.additional_usage_reports_information {
size += ie.len() as usize;
}
for ie in &self.packet_rate_status_reports {
size += ie.len() as usize;
}
for ie in &self.mbs_session_n4_information {
size += ie.len() as usize;
}
if let Some(ref ie) = self.pfcpsdrsp_flags {
size += ie.len() as usize;
}
for ie in &self.tl_container {
size += ie.len() as usize;
}
for ie in &self.ies {
size += ie.len() as usize;
}
size
}
fn unmarshal(data: &[u8]) -> Result<Self, PfcpError> {
let header = Header::unmarshal(data)?;
let mut cursor = header.len() as usize;
let mut cause = None;
let mut offending_ie = None;
let mut load_control_information = None;
let mut overload_control_information = None;
let mut usage_reports = Vec::new();
let mut additional_usage_reports_information = None;
let mut packet_rate_status_reports = Vec::new();
let mut mbs_session_n4_information = Vec::new();
let mut pfcpsdrsp_flags = None;
let mut tl_container = Vec::new();
let mut ies = Vec::new();
while cursor < data.len() {
let ie = Ie::unmarshal(&data[cursor..])?;
let ie_len = ie.len() as usize;
match ie.ie_type {
IeType::Cause => cause = Some(ie),
IeType::OffendingIe => offending_ie = Some(ie),
IeType::LoadControlInformation => load_control_information = Some(ie),
IeType::OverloadControlInformation => overload_control_information = Some(ie),
IeType::UsageReportWithinSessionDeletionResponse => usage_reports.push(ie),
IeType::AdditionalUsageReportsInformation => {
additional_usage_reports_information = Some(ie)
}
IeType::PacketRateStatusReport => packet_rate_status_reports.push(ie),
IeType::MbsSessionN4Information => mbs_session_n4_information.push(ie),
IeType::TlContainer => tl_container.push(ie),
IeType::PfcpsdrspFlags => pfcpsdrsp_flags = Some(ie),
_ => ies.push(ie),
}
cursor += ie_len;
}
Ok(SessionDeletionResponse {
header,
cause: cause.ok_or(PfcpError::MissingMandatoryIe {
ie_type: IeType::Cause,
message_type: Some(MsgType::SessionDeletionResponse),
parent_ie: None,
})?,
offending_ie,
load_control_information,
overload_control_information,
usage_reports,
additional_usage_reports_information,
packet_rate_status_reports,
mbs_session_n4_information,
pfcpsdrsp_flags,
tl_container,
ies,
})
}
fn msg_type(&self) -> MsgType {
MsgType::SessionDeletionResponse
}
fn seid(&self) -> Option<Seid> {
if self.header.has_seid {
Some(self.header.seid)
} else {
None
}
}
fn sequence(&self) -> SequenceNumber {
self.header.sequence_number
}
fn set_sequence(&mut self, seq: SequenceNumber) {
self.header.sequence_number = seq;
}
fn ies(&self, ie_type: IeType) -> crate::message::IeIter<'_> {
use crate::message::IeIter;
match ie_type {
IeType::Cause => IeIter::single(Some(&self.cause), ie_type),
IeType::OffendingIe => IeIter::single(self.offending_ie.as_ref(), ie_type),
IeType::LoadControlInformation => {
IeIter::single(self.load_control_information.as_ref(), ie_type)
}
IeType::OverloadControlInformation => {
IeIter::single(self.overload_control_information.as_ref(), ie_type)
}
IeType::UsageReportWithinSessionDeletionResponse => {
IeIter::multiple(&self.usage_reports, ie_type)
}
IeType::AdditionalUsageReportsInformation => {
IeIter::single(self.additional_usage_reports_information.as_ref(), ie_type)
}
IeType::PacketRateStatusReport => {
IeIter::multiple(&self.packet_rate_status_reports, ie_type)
}
IeType::MbsSessionN4Information => {
IeIter::multiple(&self.mbs_session_n4_information, ie_type)
}
IeType::PfcpsdrspFlags => IeIter::single(self.pfcpsdrsp_flags.as_ref(), ie_type),
IeType::TlContainer => IeIter::multiple(&self.tl_container, ie_type),
_ => IeIter::generic(&self.ies, ie_type),
}
}
fn all_ies(&self) -> Vec<&Ie> {
let mut result = vec![&self.cause];
if let Some(ref ie) = self.offending_ie {
result.push(ie);
}
if let Some(ref ie) = self.load_control_information {
result.push(ie);
}
if let Some(ref ie) = self.overload_control_information {
result.push(ie);
}
result.extend(self.usage_reports.iter());
if let Some(ref ie) = self.additional_usage_reports_information {
result.push(ie);
}
result.extend(self.packet_rate_status_reports.iter());
result.extend(self.mbs_session_n4_information.iter());
if let Some(ref ie) = self.pfcpsdrsp_flags {
result.push(ie);
}
result.extend(self.tl_container.iter());
result.extend(self.ies.iter());
result
}
}
impl SessionDeletionResponse {
#[allow(clippy::too_many_arguments)]
pub fn new(
seid: impl Into<Seid>,
seq: impl Into<SequenceNumber>,
cause_ie: Ie,
offending_ie: Option<Ie>,
load_control_information: Option<Ie>,
overload_control_information: Option<Ie>,
usage_reports: Vec<Ie>,
additional_usage_reports_information: Option<Ie>,
packet_rate_status_reports: Vec<Ie>,
mbs_session_n4_information: Vec<Ie>,
pfcpsdrsp_flags: Option<Ie>,
tl_container: Vec<Ie>,
ies: Vec<Ie>,
) -> Self {
let mut header = Header::new(MsgType::SessionDeletionResponse, true, seid, seq);
let mut payload_len = cause_ie.len();
if let Some(ie) = &offending_ie {
payload_len += ie.len();
}
if let Some(ie) = &load_control_information {
payload_len += ie.len();
}
if let Some(ie) = &overload_control_information {
payload_len += ie.len();
}
for ie in &usage_reports {
payload_len += ie.len();
}
if let Some(ie) = &additional_usage_reports_information {
payload_len += ie.len();
}
for ie in &packet_rate_status_reports {
payload_len += ie.len();
}
for ie in &mbs_session_n4_information {
payload_len += ie.len();
}
if let Some(ie) = &pfcpsdrsp_flags {
payload_len += ie.len();
}
for ie in &tl_container {
payload_len += ie.len();
}
for ie in &ies {
payload_len += ie.len();
}
header.length = payload_len + header.len() - 4;
SessionDeletionResponse {
header,
cause: cause_ie,
offending_ie,
load_control_information,
overload_control_information,
usage_reports,
additional_usage_reports_information,
packet_rate_status_reports,
mbs_session_n4_information,
pfcpsdrsp_flags,
tl_container,
ies,
}
}
}
#[derive(Debug, Default)]
pub struct SessionDeletionResponseBuilder {
seid: Seid,
sequence: SequenceNumber,
cause: Option<Ie>,
offending_ie: Option<Ie>,
load_control_information: Option<Ie>,
overload_control_information: Option<Ie>,
usage_reports: Vec<Ie>,
additional_usage_reports_information: Option<Ie>,
packet_rate_status_reports: Vec<Ie>,
mbs_session_n4_information: Vec<Ie>,
pfcpsdrsp_flags: Option<Ie>,
tl_container: Vec<Ie>,
ies: Vec<Ie>,
}
impl SessionDeletionResponseBuilder {
pub fn accepted(seid: impl Into<Seid>, sequence: impl Into<SequenceNumber>) -> Self {
Self::new(seid, sequence).cause_accepted()
}
pub fn new(seid: impl Into<Seid>, sequence: impl Into<SequenceNumber>) -> Self {
Self {
seid: seid.into(),
sequence: sequence.into(),
cause: None,
offending_ie: None,
load_control_information: None,
overload_control_information: None,
usage_reports: Vec::new(),
additional_usage_reports_information: None,
packet_rate_status_reports: Vec::new(),
mbs_session_n4_information: Vec::new(),
pfcpsdrsp_flags: None,
tl_container: Vec::new(),
ies: Vec::new(),
}
}
pub fn cause(mut self, cause_value: crate::ie::cause::CauseValue) -> Self {
use crate::ie::cause::Cause;
use crate::ie::{Ie, IeType};
let cause = Cause::new(cause_value);
self.cause = Some(Ie::new(IeType::Cause, cause.marshal().to_vec()));
self
}
pub fn cause_accepted(self) -> Self {
self.cause(crate::ie::cause::CauseValue::RequestAccepted)
}
pub fn cause_rejected(self) -> Self {
self.cause(crate::ie::cause::CauseValue::RequestRejected)
}
pub fn cause_ie(mut self, cause: Ie) -> Self {
self.cause = Some(cause);
self
}
pub fn offending_ie(mut self, offending_ie: Ie) -> Self {
self.offending_ie = Some(offending_ie);
self
}
pub fn load_control_information(mut self, load_control_information: Ie) -> Self {
self.load_control_information = Some(load_control_information);
self
}
pub fn overload_control_information(mut self, overload_control_information: Ie) -> Self {
self.overload_control_information = Some(overload_control_information);
self
}
pub fn usage_reports(mut self, mut usage_reports: Vec<Ie>) -> Self {
self.usage_reports.append(&mut usage_reports);
self
}
pub fn usage_report(mut self, usage_report: Ie) -> Self {
self.usage_reports.push(usage_report);
self
}
pub fn additional_usage_reports_information(
mut self,
additional_usage_reports_information: Ie,
) -> Self {
self.additional_usage_reports_information = Some(additional_usage_reports_information);
self
}
pub fn packet_rate_status_report(mut self, packet_rate_status_report: Ie) -> Self {
self.packet_rate_status_reports
.push(packet_rate_status_report);
self
}
pub fn packet_rate_status_reports(mut self, mut packet_rate_status_reports: Vec<Ie>) -> Self {
self.packet_rate_status_reports
.append(&mut packet_rate_status_reports);
self
}
pub fn mbs_session_n4_information(mut self, mbs_session_n4_information: Ie) -> Self {
self.mbs_session_n4_information
.push(mbs_session_n4_information);
self
}
pub fn mbs_session_n4_informations(mut self, mut mbs_session_n4_information: Vec<Ie>) -> Self {
self.mbs_session_n4_information
.append(&mut mbs_session_n4_information);
self
}
pub fn pfcpsdrsp_flags(mut self, pfcpsdrsp_flags: Ie) -> Self {
self.pfcpsdrsp_flags = Some(pfcpsdrsp_flags);
self
}
pub fn tl_container(mut self, tl_container: Ie) -> Self {
self.tl_container.push(tl_container);
self
}
pub fn tl_containers(mut self, mut tl_containers: Vec<Ie>) -> Self {
self.tl_container.append(&mut tl_containers);
self
}
pub fn ie(mut self, ie: Ie) -> Self {
self.ies.push(ie);
self
}
pub fn ies(mut self, mut ies: Vec<Ie>) -> Self {
self.ies.append(&mut ies);
self
}
pub fn build(self) -> SessionDeletionResponse {
let cause = self
.cause
.expect("Cause IE is required for SessionDeletionResponse");
SessionDeletionResponse::new(
self.seid,
self.sequence,
cause,
self.offending_ie,
self.load_control_information,
self.overload_control_information,
self.usage_reports,
self.additional_usage_reports_information,
self.packet_rate_status_reports,
self.mbs_session_n4_information,
self.pfcpsdrsp_flags,
self.tl_container,
self.ies,
)
}
pub fn try_build(self) -> Result<SessionDeletionResponse, &'static str> {
let cause = self
.cause
.ok_or("Cause IE is required for SessionDeletionResponse")?;
Ok(SessionDeletionResponse::new(
self.seid,
self.sequence,
cause,
self.offending_ie,
self.load_control_information,
self.overload_control_information,
self.usage_reports,
self.additional_usage_reports_information,
self.packet_rate_status_reports,
self.mbs_session_n4_information,
self.pfcpsdrsp_flags,
self.tl_container,
self.ies,
))
}
pub fn marshal(self) -> Vec<u8> {
self.build().marshal()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::ie::cause::*;
use crate::ie::sequence_number::SequenceNumber;
use crate::ie::urr_id::UrrId;
use crate::ie::usage_report::UsageReportBuilder;
use crate::ie::usage_report_sdr::UsageReportSdr;
#[test]
fn test_session_deletion_response_builder_minimal() {
let cause = Cause::new(CauseValue::RequestAccepted);
let cause_ie = Ie::new(IeType::Cause, cause.marshal().to_vec());
let response = SessionDeletionResponseBuilder::new(12345, 67890)
.cause_ie(cause_ie.clone())
.build();
assert_eq!(*response.sequence(), 67890);
assert_eq!(response.seid(), Some(Seid(12345)));
assert_eq!(response.msg_type(), MsgType::SessionDeletionResponse);
assert_eq!(response.cause, cause_ie);
assert!(response.offending_ie.is_none());
assert!(response.ies.is_empty());
}
#[test]
fn test_session_deletion_response_builder_with_offending_ie() {
let cause = Cause::new(CauseValue::MandatoryIeMissing);
let cause_ie = Ie::new(IeType::Cause, cause.marshal().to_vec());
let offending_ie = Ie::new(IeType::OffendingIe, vec![0x00, 0x01]);
let response = SessionDeletionResponseBuilder::new(11111, 22222)
.cause_ie(cause_ie.clone())
.offending_ie(offending_ie.clone())
.build();
assert_eq!(*response.sequence(), 22222);
assert_eq!(response.seid(), Some(Seid(11111)));
assert_eq!(response.cause, cause_ie);
assert_eq!(response.offending_ie, Some(offending_ie));
assert!(response.ies.is_empty());
}
#[test]
fn test_session_deletion_response_builder_with_additional_ies() {
let cause = Cause::new(CauseValue::RequestAccepted);
let cause_ie = Ie::new(IeType::Cause, cause.marshal().to_vec());
let ie1 = Ie::new(IeType::Unknown, vec![0xAA, 0xBB]);
let ie2 = Ie::new(IeType::Unknown, vec![0xCC, 0xDD]);
let ie3 = Ie::new(IeType::Unknown, vec![0xEE, 0xFF]);
let response = SessionDeletionResponseBuilder::new(33333, 44444)
.cause_ie(cause_ie.clone())
.ie(ie1.clone())
.ies(vec![ie2.clone(), ie3.clone()])
.build();
assert_eq!(*response.sequence(), 44444);
assert_eq!(response.seid(), Some(Seid(33333)));
assert_eq!(response.cause, cause_ie);
assert_eq!(response.ies.len(), 3);
assert_eq!(response.ies[0], ie1);
assert_eq!(response.ies[1], ie2);
assert_eq!(response.ies[2], ie3);
}
#[test]
fn test_session_deletion_response_builder_full() {
let cause = Cause::new(CauseValue::SessionContextNotFound);
let cause_ie = Ie::new(IeType::Cause, cause.marshal().to_vec());
let offending_ie = Ie::new(IeType::OffendingIe, vec![0xFF, 0xFE]);
let additional_ie = Ie::new(IeType::Unknown, vec![0xAB, 0xCD, 0xEF]);
let response = SessionDeletionResponseBuilder::new(55555, 66666)
.cause_ie(cause_ie.clone())
.offending_ie(offending_ie.clone())
.ie(additional_ie.clone())
.build();
assert_eq!(*response.sequence(), 66666);
assert_eq!(response.seid(), Some(Seid(55555)));
assert_eq!(response.cause, cause_ie);
assert_eq!(response.offending_ie, Some(offending_ie));
assert_eq!(response.ies.len(), 1);
assert_eq!(response.ies[0], additional_ie);
}
#[test]
fn test_session_deletion_response_builder_try_build_success() {
let cause = Cause::new(CauseValue::RequestAccepted);
let cause_ie = Ie::new(IeType::Cause, cause.marshal().to_vec());
let result = SessionDeletionResponseBuilder::new(12345, 67890)
.cause_ie(cause_ie.clone())
.try_build();
assert!(result.is_ok());
let response = result.unwrap();
assert_eq!(*response.sequence(), 67890);
assert_eq!(response.seid(), Some(Seid(12345)));
assert_eq!(response.cause, cause_ie);
}
#[test]
fn test_session_deletion_response_builder_try_build_missing_cause() {
let result = SessionDeletionResponseBuilder::new(12345, 67890).try_build();
assert!(result.is_err());
assert_eq!(
result.unwrap_err(),
"Cause IE is required for SessionDeletionResponse"
);
}
#[test]
#[should_panic(expected = "Cause IE is required for SessionDeletionResponse")]
fn test_session_deletion_response_builder_build_panic() {
SessionDeletionResponseBuilder::new(12345, 67890).build();
}
#[test]
fn test_session_deletion_response_builder_roundtrip() {
let cause = Cause::new(CauseValue::RuleCreationModificationFailure);
let cause_ie = Ie::new(IeType::Cause, cause.marshal().to_vec());
let offending_ie = Ie::new(IeType::OffendingIe, vec![0x12, 0x34]);
let original = SessionDeletionResponseBuilder::new(98765, 54321)
.cause_ie(cause_ie)
.offending_ie(offending_ie)
.build();
let marshaled = original.marshal();
let unmarshaled = SessionDeletionResponse::unmarshal(&marshaled).unwrap();
assert_eq!(original, unmarshaled);
}
#[test]
fn test_session_deletion_response_with_usage_reports() {
let usage_report =
UsageReportBuilder::stop_of_traffic_report(UrrId::new(1), SequenceNumber::new(100))
.with_volume_data(10000000, 6000000, 4000000)
.with_duration(7200)
.build()
.unwrap();
let usage_report_sdr = UsageReportSdr::new(usage_report);
let usage_report_ie = usage_report_sdr.to_ie();
assert_eq!(
usage_report_ie.ie_type,
IeType::UsageReportWithinSessionDeletionResponse
);
let response = SessionDeletionResponseBuilder::new(12345, 67890)
.cause_accepted()
.usage_report(usage_report_ie.clone())
.build();
assert_eq!(response.usage_reports.len(), 1);
assert_eq!(response.usage_reports[0], usage_report_ie);
assert_eq!(
response
.ies(IeType::UsageReportWithinSessionDeletionResponse)
.next(),
Some(&usage_report_ie)
);
let marshaled = response.marshal();
let unmarshaled = SessionDeletionResponse::unmarshal(&marshaled).unwrap();
assert_eq!(response, unmarshaled);
assert_eq!(unmarshaled.usage_reports.len(), 1);
}
#[test]
fn test_session_deletion_response_with_additional_usage_reports_information() {
let auri_ie = Ie::new(
IeType::AdditionalUsageReportsInformation,
vec![0x01], );
let response = SessionDeletionResponseBuilder::new(12345, 67890)
.cause_accepted()
.additional_usage_reports_information(auri_ie.clone())
.build();
assert_eq!(
response.additional_usage_reports_information,
Some(auri_ie.clone())
);
assert_eq!(
response
.ies(IeType::AdditionalUsageReportsInformation)
.next(),
Some(&auri_ie)
);
let marshaled = response.marshal();
let unmarshaled = SessionDeletionResponse::unmarshal(&marshaled).unwrap();
assert_eq!(response, unmarshaled);
assert_eq!(
unmarshaled.additional_usage_reports_information,
Some(auri_ie)
);
}
#[test]
fn test_session_deletion_response_with_packet_rate_status_reports() {
let prsr_ie1 = Ie::new(IeType::PacketRateStatusReport, vec![0x01, 0x02, 0x03]);
let prsr_ie2 = Ie::new(IeType::PacketRateStatusReport, vec![0x04, 0x05, 0x06]);
let response = SessionDeletionResponseBuilder::new(12345, 67890)
.cause_accepted()
.packet_rate_status_report(prsr_ie1.clone())
.packet_rate_status_reports(vec![prsr_ie2.clone()])
.build();
assert_eq!(response.packet_rate_status_reports.len(), 2);
assert_eq!(response.packet_rate_status_reports[0], prsr_ie1);
assert_eq!(response.packet_rate_status_reports[1], prsr_ie2);
assert_eq!(
response.ies(IeType::PacketRateStatusReport).next(),
Some(&prsr_ie1)
);
let marshaled = response.marshal();
let unmarshaled = SessionDeletionResponse::unmarshal(&marshaled).unwrap();
assert_eq!(response, unmarshaled);
assert_eq!(unmarshaled.packet_rate_status_reports.len(), 2);
}
#[test]
fn test_session_deletion_response_with_mbs_session_n4_information() {
let mbs_ie1 = Ie::new(IeType::MbsSessionN4Information, vec![0x10, 0x20]);
let mbs_ie2 = Ie::new(IeType::MbsSessionN4Information, vec![0x30, 0x40]);
let response = SessionDeletionResponseBuilder::new(12345, 67890)
.cause_accepted()
.mbs_session_n4_information(mbs_ie1.clone())
.mbs_session_n4_informations(vec![mbs_ie2.clone()])
.build();
assert_eq!(response.mbs_session_n4_information.len(), 2);
assert_eq!(response.mbs_session_n4_information[0], mbs_ie1);
assert_eq!(response.mbs_session_n4_information[1], mbs_ie2);
let marshaled = response.marshal();
let unmarshaled = SessionDeletionResponse::unmarshal(&marshaled).unwrap();
assert_eq!(response, unmarshaled);
assert_eq!(unmarshaled.mbs_session_n4_information.len(), 2);
}
#[test]
fn test_session_deletion_response_with_pfcpsdrsp_flags() {
let flags_ie = Ie::new(IeType::PfcpsdrspFlags, vec![0x01]);
let response = SessionDeletionResponseBuilder::new(12345, 67890)
.cause_accepted()
.pfcpsdrsp_flags(flags_ie.clone())
.build();
assert_eq!(response.pfcpsdrsp_flags, Some(flags_ie.clone()));
let marshaled = response.marshal();
let unmarshaled = SessionDeletionResponse::unmarshal(&marshaled).unwrap();
assert_eq!(response, unmarshaled);
assert_eq!(unmarshaled.pfcpsdrsp_flags, Some(flags_ie));
}
#[test]
fn test_session_deletion_response_with_tl_container() {
let tl_ie1 = Ie::new(IeType::TlContainer, vec![0x50, 0x60, 0x70]);
let tl_ie2 = Ie::new(IeType::TlContainer, vec![0x80, 0x90, 0xA0]);
let response = SessionDeletionResponseBuilder::new(12345, 67890)
.cause_accepted()
.tl_container(tl_ie1.clone())
.tl_containers(vec![tl_ie2.clone()])
.build();
assert_eq!(response.tl_container.len(), 2);
assert_eq!(response.tl_container[0], tl_ie1);
assert_eq!(response.tl_container[1], tl_ie2);
let marshaled = response.marshal();
let unmarshaled = SessionDeletionResponse::unmarshal(&marshaled).unwrap();
assert_eq!(response, unmarshaled);
assert_eq!(unmarshaled.tl_container.len(), 2);
}
#[test]
fn test_session_deletion_response_all_new_ies_combined() {
let auri_ie = Ie::new(IeType::AdditionalUsageReportsInformation, vec![0x01]);
let prsr_ie = Ie::new(IeType::PacketRateStatusReport, vec![0x01, 0x02]);
let mbs_ie = Ie::new(IeType::MbsSessionN4Information, vec![0x10, 0x20]);
let flags_ie = Ie::new(IeType::PfcpsdrspFlags, vec![0x01]);
let tl_ie = Ie::new(IeType::TlContainer, vec![0x50, 0x60]);
let response = SessionDeletionResponseBuilder::new(12345, 67890)
.cause_accepted()
.additional_usage_reports_information(auri_ie.clone())
.packet_rate_status_report(prsr_ie.clone())
.mbs_session_n4_information(mbs_ie.clone())
.pfcpsdrsp_flags(flags_ie.clone())
.tl_container(tl_ie.clone())
.build();
assert_eq!(
response.additional_usage_reports_information,
Some(auri_ie.clone())
);
assert_eq!(response.packet_rate_status_reports.len(), 1);
assert_eq!(response.mbs_session_n4_information.len(), 1);
assert_eq!(response.pfcpsdrsp_flags, Some(flags_ie.clone()));
assert_eq!(response.tl_container.len(), 1);
let all_ies = response.all_ies();
assert!(all_ies.contains(&&auri_ie));
assert!(all_ies.contains(&&prsr_ie));
assert!(all_ies.contains(&&mbs_ie));
assert!(all_ies.contains(&&flags_ie));
assert!(all_ies.contains(&&tl_ie));
let marshaled = response.marshal();
let unmarshaled = SessionDeletionResponse::unmarshal(&marshaled).unwrap();
assert_eq!(response, unmarshaled);
}
}