Skip to content

Commit

Permalink
Implemented MBMS Session Start Request
Browse files Browse the repository at this point in the history
  • Loading branch information
ErvinsK committed May 30, 2024
1 parent bf7831f commit 662a87e
Show file tree
Hide file tree
Showing 6 changed files with 549 additions and 35 deletions.
8 changes: 4 additions & 4 deletions src/gtpv2/messages/ies/ie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ pub enum InformationElement {
NodeType(NodeType),
Fqdn(Fqdn),
TransactionIdentifier(TransactionIdentifier),
MbmsSa(MbmsSa),
MbmsSd(MbmsSd),
MbmsSa(MbmsServiceArea),
MbmsSd(MbmsSessionDuration),
MbmsSessionId(MbmsSessionId),
MbmsFlowId(MbmsFlowId),
MbmsIpMulticastDistribution(MbmsIpMulticastDistribution),
Expand Down Expand Up @@ -922,14 +922,14 @@ impl InformationElement {
}
Err(j) => return Err(j),
},
138 => match MbmsSd::unmarshal(&buffer[cursor..]) {
138 => match MbmsSessionDuration::unmarshal(&buffer[cursor..]) {
Ok(i) => {
cursor += i.len();
ies.push(InformationElement::MbmsSd(i));
}
Err(j) => return Err(j),
},
139 => match MbmsSa::unmarshal(&buffer[cursor..]) {
139 => match MbmsServiceArea::unmarshal(&buffer[cursor..]) {
Ok(i) => {
cursor += i.len();
ies.push(InformationElement::MbmsSa(i));
Expand Down
28 changes: 14 additions & 14 deletions src/gtpv2/messages/ies/mbmssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ pub const MBMSSA: u8 = 139;
// MBMS Service Area IE implementation

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MbmsSa {
pub struct MbmsServiceArea {
pub t: u8,
pub length: u16,
pub ins: u8,
pub mbms_sa: Vec<u16>,
}

impl Default for MbmsSa {
fn default() -> MbmsSa {
MbmsSa {
impl Default for MbmsServiceArea {
fn default() -> MbmsServiceArea {
MbmsServiceArea {
t: MBMSSA,
length: 0,
ins: 0,
Expand All @@ -31,13 +31,13 @@ impl Default for MbmsSa {
}
}

impl From<MbmsSa> for InformationElement {
fn from(i: MbmsSa) -> Self {
impl From<MbmsServiceArea> for InformationElement {
fn from(i: MbmsServiceArea) -> Self {
InformationElement::MbmsSa(i)
}
}

impl IEs for MbmsSa {
impl IEs for MbmsServiceArea {
fn marshal(&self, buffer: &mut Vec<u8>) {
let mut buffer_ie: Vec<u8> = vec![];
buffer_ie.push(MBMSSA);
Expand All @@ -58,12 +58,12 @@ impl IEs for MbmsSa {
buffer.append(&mut buffer_ie);
}

fn unmarshal(buffer: &[u8]) -> Result<MbmsSa, GTPV2Error> {
fn unmarshal(buffer: &[u8]) -> Result<MbmsServiceArea, GTPV2Error> {
if buffer.len() >= MIN_IE_SIZE {
let mut data = MbmsSa {
let mut data = MbmsServiceArea {
length: u16::from_be_bytes([buffer[1], buffer[2]]),
ins: buffer[3] & 0x0f,
..MbmsSa::default()
..MbmsServiceArea::default()
};
if check_tliv_ie_buffer(data.length, buffer) {
if buffer.len() >= 5 + (buffer[4] as usize + 1) * 2 {
Expand Down Expand Up @@ -101,20 +101,20 @@ impl IEs for MbmsSa {
#[test]
fn mbmssa_ie_unmarshal_test() {
let encoded_ie: [u8; 9] = [0x8b, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0xff, 0xff];
let test_struct = MbmsSa {
let test_struct = MbmsServiceArea {
t: MBMSSA,
length: 5,
ins: 0,
mbms_sa: vec![0, 0xffff],
};
let i = MbmsSa::unmarshal(&encoded_ie);
let i = MbmsServiceArea::unmarshal(&encoded_ie);
assert_eq!(i.unwrap(), test_struct);
}

#[test]
fn mbmssa_ie_marshal_test() {
let encoded_ie: [u8; 9] = [0x8b, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0xff, 0xff];
let test_struct = MbmsSa {
let test_struct = MbmsServiceArea {
t: MBMSSA,
length: 5,
ins: 0,
Expand All @@ -128,6 +128,6 @@ fn mbmssa_ie_marshal_test() {
#[test]
fn mbmssa_ie_wrong_msmssa_length() {
let encoded_ie: [u8; 6] = [0x8b, 0x00, 0x03, 0x00, 0x00, 0x00];
let i = MbmsSa::unmarshal(&encoded_ie);
let i = MbmsServiceArea::unmarshal(&encoded_ie);
assert_eq!(i, Err(GTPV2Error::IEInvalidLength(MBMSSA)));
}
24 changes: 12 additions & 12 deletions src/gtpv2/messages/ies/mbmssd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ pub const MBMSSD_LENGTH: usize = 3;
// MBMS Session Duration IE implementation

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MbmsSd {
pub struct MbmsSessionDuration {
pub t: u8,
pub length: u16,
pub ins: u8,
pub seconds: u32,
pub days: u8,
}

impl Default for MbmsSd {
fn default() -> MbmsSd {
MbmsSd {
impl Default for MbmsSessionDuration {
fn default() -> MbmsSessionDuration {
MbmsSessionDuration {
t: MBMSSD,
length: MBMSSD_LENGTH as u16,
ins: 0,
Expand All @@ -34,13 +34,13 @@ impl Default for MbmsSd {
}
}

impl From<MbmsSd> for InformationElement {
fn from(i: MbmsSd) -> Self {
impl From<MbmsSessionDuration> for InformationElement {
fn from(i: MbmsSessionDuration) -> Self {
InformationElement::MbmsSd(i)
}
}

impl IEs for MbmsSd {
impl IEs for MbmsSessionDuration {
fn marshal(&self, buffer: &mut Vec<u8>) {
let mut buffer_ie: Vec<u8> = vec![];
buffer_ie.push(MBMSSD);
Expand All @@ -54,12 +54,12 @@ impl IEs for MbmsSd {

fn unmarshal(buffer: &[u8]) -> Result<Self, GTPV2Error> {
if buffer.len() >= MBMSSD_LENGTH + MIN_IE_SIZE {
let data = MbmsSd {
let data = MbmsSessionDuration {
length: u16::from_be_bytes([buffer[1], buffer[2]]),
ins: buffer[3] & 0x0f,
seconds: (u32::from_be_bytes([0x00, buffer[4], buffer[5], buffer[6]])) >> 7,
days: buffer[6] & 0x7f,
..MbmsSd::default()
..MbmsSessionDuration::default()
};
Ok(data)
} else {
Expand All @@ -85,21 +85,21 @@ impl IEs for MbmsSd {
#[test]
fn mbms_sd_ie_unmarshal_test() {
let encoded_ie: [u8; 7] = [0x8a, 0x00, 0x03, 0x00, 0x00, 0xc8, 0x0a];
let test_struct = MbmsSd {
let test_struct = MbmsSessionDuration {
t: MBMSSD,
length: MBMSSD_LENGTH as u16,
ins: 0,
seconds: 400,
days: 10,
};
let i = MbmsSd::unmarshal(&encoded_ie);
let i = MbmsSessionDuration::unmarshal(&encoded_ie);
assert_eq!(i.unwrap(), test_struct);
}

#[test]
fn mbms_sd_ie_marshal_test() {
let encoded_ie: [u8; 7] = [0x8a, 0x00, 0x03, 0x00, 0x00, 0xc8, 0x0a];
let test_struct = MbmsSd {
let test_struct = MbmsSessionDuration {
t: MBMSSD,
length: MBMSSD_LENGTH as u16,
ins: 0,
Expand Down
4 changes: 2 additions & 2 deletions src/gtpv2/messages/ies/tmgi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn tmgi_ie_marshal_test() {
let encoded: [u8; 10] = [0x9E, 0x00, 0x06, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05];
let decoded = Tmgi {
tmgi: [0x00, 0x01, 0x02, 0x03, 0x04, 0x05],
..Default::default()
..Tmgi::default()
};
let mut buffer: Vec<u8> = vec![];
decoded.marshal(&mut buffer);
Expand All @@ -99,7 +99,7 @@ fn tmgi_ie_unmarshal_test() {
let encoded: [u8; 10] = [0x9E, 0x00, 0x06, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05];
let decoded = Tmgi {
tmgi: [0x00, 0x01, 0x02, 0x03, 0x04, 0x05],
..Default::default()
..Tmgi::default()
};
assert_eq!(Tmgi::unmarshal(&encoded).unwrap(), decoded);
}
Loading

0 comments on commit 662a87e

Please sign in to comment.