Refactor for AVP

This commit is contained in:
moznion
2020-12-02 02:32:35 +09:00
parent f27b0d85fb
commit b82d400aae
6 changed files with 258 additions and 258 deletions

View File

@@ -263,15 +263,15 @@ fn generate_string_attribute_code(
) {
let code = format!(
"pub fn add_{method_identifier}(packet: &mut Packet, value: &str) {{
packet.add(AVP::encode_string({type_identifier}, value));
packet.add(AVP::from_string({type_identifier}, value));
}}
pub fn lookup_{method_identifier}(packet: &Packet) -> Option<Result<String, AVPError>> {{
packet.lookup({type_identifier}).map(|v| v.decode_string())
packet.lookup({type_identifier}).map(|v| v.encode_string())
}}
pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result<Vec<String>, AVPError> {{
let mut vec = Vec::new();
for avp in packet.lookup_all({type_identifier}) {{
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}}
Ok(vec)
}}
@@ -289,15 +289,15 @@ fn generate_tagged_string_attribute_code(
) {
let code = format!(
"pub fn add_{method_identifier}(packet: &mut Packet, tag: Option<&Tag>, value: &str) {{
packet.add(AVP::encode_tagged_string({type_identifier}, tag, value));
packet.add(AVP::from_tagged_string({type_identifier}, tag, value));
}}
pub fn lookup_{method_identifier}(packet: &Packet) -> Option<Result<(String, Option<Tag>), AVPError>> {{
packet.lookup({type_identifier}).map(|v| v.decode_tagged_string())
packet.lookup({type_identifier}).map(|v| v.encode_tagged_string())
}}
pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result<Vec<(String, Option<Tag>)>, AVPError> {{
let mut vec = Vec::new();
for avp in packet.lookup_all({type_identifier}) {{
vec.push(avp.decode_tagged_string()?)
vec.push(avp.encode_tagged_string()?)
}}
Ok(vec)
}}
@@ -315,16 +315,16 @@ fn generate_user_password_attribute_code(
) {
let code = format!(
"pub fn add_{method_identifier}(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> {{
packet.add(AVP::encode_user_password({type_identifier}, value, packet.get_secret(), packet.get_authenticator())?);
packet.add(AVP::from_user_password({type_identifier}, value, packet.get_secret(), packet.get_authenticator())?);
Ok(())
}}
pub fn lookup_{method_identifier}(packet: &Packet) -> Option<Result<Vec<u8>, AVPError>> {{
packet.lookup({type_identifier}).map(|v| v.decode_user_password(packet.get_secret(), packet.get_authenticator()))
packet.lookup({type_identifier}).map(|v| v.encode_user_password(packet.get_secret(), packet.get_authenticator()))
}}
pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result<Vec<Vec<u8>>, AVPError> {{
let mut vec = Vec::new();
for avp in packet.lookup_all({type_identifier}) {{
vec.push(avp.decode_user_password(packet.get_secret(), packet.get_authenticator())?)
vec.push(avp.encode_user_password(packet.get_secret(), packet.get_authenticator())?)
}}
Ok(vec)
}}
@@ -342,16 +342,16 @@ fn generate_tunnel_password_attribute_code(
) {
let code = format!(
"pub fn add_{method_identifier}(packet: &mut Packet, tag: Option<&Tag>, value: &[u8]) -> Result<(), AVPError> {{
packet.add(AVP::encode_tunnel_password({type_identifier}, tag, value, packet.get_secret(), packet.get_authenticator())?);
packet.add(AVP::from_tunnel_password({type_identifier}, tag, value, packet.get_secret(), packet.get_authenticator())?);
Ok(())
}}
pub fn lookup_{method_identifier}(packet: &Packet) -> Option<Result<(Vec<u8>, Tag), AVPError>> {{
packet.lookup({type_identifier}).map(|v| v.decode_tunnel_password(packet.get_secret(), packet.get_authenticator()))
packet.lookup({type_identifier}).map(|v| v.encode_tunnel_password(packet.get_secret(), packet.get_authenticator()))
}}
pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result<Vec<(Vec<u8>, Tag)>, AVPError> {{
let mut vec = Vec::new();
for avp in packet.lookup_all({type_identifier}) {{
vec.push(avp.decode_tunnel_password(packet.get_secret(), packet.get_authenticator())?)
vec.push(avp.encode_tunnel_password(packet.get_secret(), packet.get_authenticator())?)
}}
Ok(vec)
}}
@@ -369,15 +369,15 @@ fn generate_octets_attribute_code(
) {
let code = format!(
"pub fn add_{method_identifier}(packet: &mut Packet, value: &[u8]) {{
packet.add(AVP::encode_bytes({type_identifier}, value));
packet.add(AVP::from_bytes({type_identifier}, value));
}}
pub fn lookup_{method_identifier}(packet: &Packet) -> Option<Vec<u8>> {{
packet.lookup({type_identifier}).map(|v| v.decode_bytes())
packet.lookup({type_identifier}).map(|v| v.encode_bytes())
}}
pub fn lookup_all_{method_identifier}(packet: &Packet) -> Vec<Vec<u8>> {{
let mut vec = Vec::new();
for avp in packet.lookup_all({type_identifier}) {{
vec.push(avp.decode_bytes())
vec.push(avp.encode_bytes())
}}
vec
}}
@@ -395,15 +395,15 @@ fn generate_ipaddr_attribute_code(
) {
let code = format!(
"pub fn add_{method_identifier}(packet: &mut Packet, value: &Ipv4Addr) {{
packet.add(AVP::encode_ipv4({type_identifier}, value));
packet.add(AVP::from_ipv4({type_identifier}, value));
}}
pub fn lookup_{method_identifier}(packet: &Packet) -> Option<Result<Ipv4Addr, AVPError>> {{
packet.lookup({type_identifier}).map(|v| v.decode_ipv4())
packet.lookup({type_identifier}).map(|v| v.encode_ipv4())
}}
pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result<Vec<Ipv4Addr>, AVPError> {{
let mut vec = Vec::new();
for avp in packet.lookup_all({type_identifier}) {{
vec.push(avp.decode_ipv4()?)
vec.push(avp.encode_ipv4()?)
}}
Ok(vec)
}}
@@ -421,15 +421,15 @@ fn generate_integer_attribute_code(
) {
let code = format!(
"pub fn add_{method_identifier}(packet: &mut Packet, value: u32) {{
packet.add(AVP::encode_u32({type_identifier}, value));
packet.add(AVP::from_u32({type_identifier}, value));
}}
pub fn lookup_{method_identifier}(packet: &Packet) -> Option<Result<u32, AVPError>> {{
packet.lookup({type_identifier}).map(|v| v.decode_u32())
packet.lookup({type_identifier}).map(|v| v.encode_u32())
}}
pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result<Vec<u32>, AVPError> {{
let mut vec = Vec::new();
for avp in packet.lookup_all({type_identifier}) {{
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}}
Ok(vec)
}}
@@ -447,15 +447,15 @@ fn generate_tagged_integer_attribute_code(
) {
let code = format!(
"pub fn add_{method_identifier}(packet: &mut Packet, tag: Option<&Tag>, value: u32) {{
packet.add(AVP::encode_tagged_u32({type_identifier}, tag, value));
packet.add(AVP::from_tagged_u32({type_identifier}, tag, value));
}}
pub fn lookup_{method_identifier}(packet: &Packet) -> Option<Result<(u32, Tag), AVPError>> {{
packet.lookup({type_identifier}).map(|v| v.decode_tagged_u32())
packet.lookup({type_identifier}).map(|v| v.encode_tagged_u32())
}}
pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result<Vec<(u32, Tag)>, AVPError> {{
let mut vec = Vec::new();
for avp in packet.lookup_all({type_identifier}) {{
vec.push(avp.decode_tagged_u32()?)
vec.push(avp.encode_tagged_u32()?)
}}
Ok(vec)
}}
@@ -474,15 +474,15 @@ fn generate_value_defined_integer_attribute_code(
) {
let code = format!(
"pub fn add_{method_identifier}(packet: &mut Packet, value: {value_type}) {{
packet.add(AVP::encode_u32({type_identifier}, value as u32));
packet.add(AVP::from_u32({type_identifier}, value as u32));
}}
pub fn lookup_{method_identifier}(packet: &Packet) -> Option<Result<{value_type}, AVPError>> {{
packet.lookup({type_identifier}).map(|v| Ok(v.decode_u32()? as {value_type}))
packet.lookup({type_identifier}).map(|v| Ok(v.encode_u32()? as {value_type}))
}}
pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result<Vec<{value_type}>, AVPError> {{
let mut vec = Vec::new();
for avp in packet.lookup_all({type_identifier}) {{
vec.push(avp.decode_u32()? as {value_type})
vec.push(avp.encode_u32()? as {value_type})
}}
Ok(vec)
}}
@@ -502,18 +502,18 @@ fn generate_value_tagged_defined_integer_attribute_code(
) {
let code = format!(
"pub fn add_{method_identifier}(packet: &mut Packet, tag: Option<&Tag>, value: {value_type}) {{
packet.add(AVP::encode_tagged_u32({type_identifier}, tag, value as u32));
packet.add(AVP::from_tagged_u32({type_identifier}, tag, value as u32));
}}
pub fn lookup_{method_identifier}(packet: &Packet) -> Option<Result<({value_type}, Tag), AVPError>> {{
packet.lookup({type_identifier}).map(|v| {{
let (v, t) = v.decode_tagged_u32()?;
let (v, t) = v.encode_tagged_u32()?;
Ok((v as {value_type}, t))
}})
}}
pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result<Vec<({value_type}, Tag)>, AVPError> {{
let mut vec = Vec::new();
for avp in packet.lookup_all({type_identifier}) {{
let (v, t) = avp.decode_tagged_u32()?;
let (v, t) = avp.encode_tagged_u32()?;
vec.push((v as {value_type}, t))
}}
Ok(vec)

View File

@@ -41,14 +41,14 @@ pub struct AVP {
}
impl AVP {
pub fn encode_u32(typ: AVPType, value: u32) -> Self {
pub fn from_u32(typ: AVPType, value: u32) -> Self {
AVP {
typ,
value: u32::to_be_bytes(value).to_vec(),
}
}
pub fn encode_tagged_u32(typ: AVPType, tag: Option<&Tag>, value: u32) -> Self {
pub fn from_tagged_u32(typ: AVPType, tag: Option<&Tag>, value: u32) -> Self {
let tag = match tag {
None => &Tag {
value: UNUSED_TAG_VALUE,
@@ -62,14 +62,14 @@ impl AVP {
}
}
pub fn encode_string(typ: AVPType, value: &str) -> Self {
pub fn from_string(typ: AVPType, value: &str) -> Self {
AVP {
typ,
value: value.as_bytes().to_vec(),
}
}
pub fn encode_tagged_string(typ: AVPType, tag: Option<&Tag>, value: &str) -> Self {
pub fn from_tagged_string(typ: AVPType, tag: Option<&Tag>, value: &str) -> Self {
match tag {
None => AVP {
typ,
@@ -82,28 +82,28 @@ impl AVP {
}
}
pub fn encode_bytes(typ: AVPType, value: &[u8]) -> Self {
pub fn from_bytes(typ: AVPType, value: &[u8]) -> Self {
AVP {
typ,
value: value.to_vec(),
}
}
pub fn encode_ipv4(typ: AVPType, value: &Ipv4Addr) -> Self {
pub fn from_ipv4(typ: AVPType, value: &Ipv4Addr) -> Self {
AVP {
typ,
value: value.octets().to_vec(),
}
}
pub fn encode_ipv6(typ: AVPType, value: &Ipv6Addr) -> Self {
pub fn from_ipv6(typ: AVPType, value: &Ipv6Addr) -> Self {
AVP {
typ,
value: value.octets().to_vec(),
}
}
pub fn encode_user_password(
pub fn from_user_password(
typ: AVPType,
plain_text: &[u8],
secret: &[u8],
@@ -166,14 +166,14 @@ impl AVP {
Ok(AVP { typ, value: enc })
}
pub fn encode_date(typ: AVPType, dt: &DateTime<Utc>) -> Self {
pub fn from_date(typ: AVPType, dt: &DateTime<Utc>) -> Self {
AVP {
typ,
value: u32::to_be_bytes(dt.timestamp() as u32).to_vec(),
}
}
pub fn encode_tunnel_password(
pub fn from_tunnel_password(
typ: AVPType,
tag: Option<&Tag>,
plain_text: &[u8],
@@ -262,7 +262,7 @@ impl AVP {
Ok(AVP { typ, value: enc })
}
pub fn decode_u32(&self) -> Result<u32, AVPError> {
pub fn encode_u32(&self) -> Result<u32, AVPError> {
const U32_SIZE: usize = std::mem::size_of::<u32>();
if self.value.len() != U32_SIZE {
return Err(AVPError::InvalidAttributeLengthError(self.value.len()));
@@ -275,7 +275,7 @@ impl AVP {
}
}
pub fn decode_tagged_u32(&self) -> Result<(u32, Tag), AVPError> {
pub fn encode_tagged_u32(&self) -> Result<(u32, Tag), AVPError> {
if self.value.is_empty() {
return Err(AVPError::InvalidAttributeLengthError(self.value.len()));
}
@@ -302,14 +302,14 @@ impl AVP {
}
}
pub fn decode_string(&self) -> Result<String, AVPError> {
pub fn encode_string(&self) -> Result<String, AVPError> {
match String::from_utf8(self.value.to_vec()) {
Ok(str) => Ok(str),
Err(e) => Err(AVPError::UnexpectedDecodingError(e.to_string())),
}
}
pub fn decode_tagged_string(&self) -> Result<(String, Option<Tag>), AVPError> {
pub fn encode_tagged_string(&self) -> Result<(String, Option<Tag>), AVPError> {
let string_vec = self.value.to_vec();
if string_vec.is_empty() {
return Err(AVPError::InvalidAttributeLengthError(string_vec.len()));
@@ -344,11 +344,11 @@ impl AVP {
}
}
pub fn decode_bytes(&self) -> Vec<u8> {
pub fn encode_bytes(&self) -> Vec<u8> {
self.value.to_vec()
}
pub fn decode_ipv4(&self) -> Result<Ipv4Addr, AVPError> {
pub fn encode_ipv4(&self) -> Result<Ipv4Addr, AVPError> {
const IPV4_SIZE: usize = std::mem::size_of::<Ipv4Addr>();
if self.value.len() != IPV4_SIZE {
return Err(AVPError::InvalidAttributeLengthError(self.value.len()));
@@ -361,7 +361,7 @@ impl AVP {
}
}
pub fn decode_ipv6(&self) -> Result<Ipv6Addr, AVPError> {
pub fn encode_ipv6(&self) -> Result<Ipv6Addr, AVPError> {
const IPV6_SIZE: usize = std::mem::size_of::<Ipv6Addr>();
if self.value.len() != IPV6_SIZE {
return Err(AVPError::InvalidAttributeLengthError(self.value.len()));
@@ -374,7 +374,7 @@ impl AVP {
}
}
pub fn decode_user_password(
pub fn encode_user_password(
&self,
secret: &[u8],
request_authenticator: &[u8],
@@ -417,7 +417,7 @@ impl AVP {
}
}
pub fn decode_date(&self) -> Result<DateTime<Utc>, AVPError> {
pub fn encode_date(&self) -> Result<DateTime<Utc>, AVPError> {
const U32_SIZE: usize = std::mem::size_of::<u32>();
if self.value.len() != U32_SIZE {
return Err(AVPError::InvalidAttributeLengthError(self.value.len()));
@@ -433,7 +433,7 @@ impl AVP {
}
}
pub fn decode_tunnel_password(
pub fn encode_tunnel_password(
&self,
secret: &[u8],
request_authenticator: &[u8],
@@ -498,31 +498,31 @@ mod tests {
#[test]
fn it_should_convert_attribute_to_integer32() -> Result<(), AVPError> {
let given_u32 = 16909060;
let avp = AVP::encode_u32(1, given_u32);
assert_eq!(avp.decode_u32()?, given_u32);
let avp = AVP::from_u32(1, given_u32);
assert_eq!(avp.encode_u32()?, given_u32);
Ok(())
}
#[test]
fn it_should_convert_attribute_to_string() -> Result<(), AVPError> {
let given_str = "Hello, World";
let avp = AVP::encode_string(1, given_str);
assert_eq!(avp.decode_string()?, given_str);
let avp = AVP::from_string(1, given_str);
assert_eq!(avp.encode_string()?, given_str);
Ok(())
}
#[test]
fn it_should_convert_attribute_to_byte() {
let given_bytes = b"Hello, World";
let avp = AVP::encode_bytes(1, given_bytes);
assert_eq!(avp.decode_bytes(), given_bytes);
let avp = AVP::from_bytes(1, given_bytes);
assert_eq!(avp.encode_bytes(), given_bytes);
}
#[test]
fn it_should_convert_ipv4() -> Result<(), AVPError> {
let given_ipv4 = Ipv4Addr::new(192, 0, 2, 1);
let avp = AVP::encode_ipv4(1, &given_ipv4);
assert_eq!(avp.decode_ipv4()?, given_ipv4);
let avp = AVP::from_ipv4(1, &given_ipv4);
assert_eq!(avp.encode_ipv4()?, given_ipv4);
Ok(())
}
@@ -531,8 +531,8 @@ mod tests {
let given_ipv6 = Ipv6Addr::new(
0x2001, 0x0db8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001,
);
let avp = AVP::encode_ipv6(1, &given_ipv6);
assert_eq!(avp.decode_ipv6()?, given_ipv6);
let avp = AVP::from_ipv6(1, &given_ipv6);
assert_eq!(avp.encode_ipv6()?, given_ipv6);
Ok(())
}
@@ -574,7 +574,7 @@ mod tests {
];
for test_case in test_cases {
let user_password_avp_result = AVP::encode_user_password(
let user_password_avp_result = AVP::from_user_password(
1,
test_case.plain_text.as_bytes(),
&secret,
@@ -584,7 +584,7 @@ mod tests {
assert_eq!(avp.value.len(), test_case.expected_encoded_len);
let decoded_password = avp
.decode_user_password(&secret, &request_authenticator)
.encode_user_password(&secret, &request_authenticator)
.unwrap();
assert_eq!(
String::from_utf8(decoded_password).unwrap(),
@@ -596,8 +596,8 @@ mod tests {
#[test]
fn it_should_convert_date() -> Result<(), AVPError> {
let now = Utc::now();
let avp = AVP::encode_date(1, &now);
assert_eq!(avp.decode_date()?.timestamp(), now.timestamp(),);
let avp = AVP::from_date(1, &now);
assert_eq!(avp.encode_date()?.timestamp(), now.timestamp(),);
Ok(())
}
@@ -640,7 +640,7 @@ mod tests {
];
for test_case in test_cases {
let user_password_avp_result = AVP::encode_tunnel_password(
let user_password_avp_result = AVP::from_tunnel_password(
1,
Some(&tag),
test_case.plain_text.as_bytes(),
@@ -651,7 +651,7 @@ mod tests {
assert_eq!(avp.value.len(), test_case.expected_encoded_len);
let (decoded_password, got_tag) = avp
.decode_tunnel_password(&secret, &request_authenticator)
.encode_tunnel_password(&secret, &request_authenticator)
.unwrap();
assert_eq!(got_tag, tag);
assert_eq!(

View File

@@ -84,15 +84,15 @@ pub fn delete_user_name(packet: &mut Packet) {
packet.delete(USER_NAME_TYPE);
}
pub fn add_user_name(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(USER_NAME_TYPE, value));
packet.add(AVP::from_string(USER_NAME_TYPE, value));
}
pub fn lookup_user_name(packet: &Packet) -> Option<Result<String, AVPError>> {
packet.lookup(USER_NAME_TYPE).map(|v| v.decode_string())
packet.lookup(USER_NAME_TYPE).map(|v| v.encode_string())
}
pub fn lookup_all_user_name(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(USER_NAME_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -102,7 +102,7 @@ pub fn delete_user_password(packet: &mut Packet) {
packet.delete(USER_PASSWORD_TYPE);
}
pub fn add_user_password(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> {
packet.add(AVP::encode_user_password(
packet.add(AVP::from_user_password(
USER_PASSWORD_TYPE,
value,
packet.get_secret(),
@@ -113,12 +113,12 @@ pub fn add_user_password(packet: &mut Packet, value: &[u8]) -> Result<(), AVPErr
pub fn lookup_user_password(packet: &Packet) -> Option<Result<Vec<u8>, AVPError>> {
packet
.lookup(USER_PASSWORD_TYPE)
.map(|v| v.decode_user_password(packet.get_secret(), packet.get_authenticator()))
.map(|v| v.encode_user_password(packet.get_secret(), packet.get_authenticator()))
}
pub fn lookup_all_user_password(packet: &Packet) -> Result<Vec<Vec<u8>>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(USER_PASSWORD_TYPE) {
vec.push(avp.decode_user_password(packet.get_secret(), packet.get_authenticator())?)
vec.push(avp.encode_user_password(packet.get_secret(), packet.get_authenticator())?)
}
Ok(vec)
}
@@ -128,15 +128,15 @@ pub fn delete_chap_password(packet: &mut Packet) {
packet.delete(CHAP_PASSWORD_TYPE);
}
pub fn add_chap_password(packet: &mut Packet, value: &[u8]) {
packet.add(AVP::encode_bytes(CHAP_PASSWORD_TYPE, value));
packet.add(AVP::from_bytes(CHAP_PASSWORD_TYPE, value));
}
pub fn lookup_chap_password(packet: &Packet) -> Option<Vec<u8>> {
packet.lookup(CHAP_PASSWORD_TYPE).map(|v| v.decode_bytes())
packet.lookup(CHAP_PASSWORD_TYPE).map(|v| v.encode_bytes())
}
pub fn lookup_all_chap_password(packet: &Packet) -> Vec<Vec<u8>> {
let mut vec = Vec::new();
for avp in packet.lookup_all(CHAP_PASSWORD_TYPE) {
vec.push(avp.decode_bytes())
vec.push(avp.encode_bytes())
}
vec
}
@@ -146,15 +146,15 @@ pub fn delete_nas_ip_address(packet: &mut Packet) {
packet.delete(NAS_IP_ADDRESS_TYPE);
}
pub fn add_nas_ip_address(packet: &mut Packet, value: &Ipv4Addr) {
packet.add(AVP::encode_ipv4(NAS_IP_ADDRESS_TYPE, value));
packet.add(AVP::from_ipv4(NAS_IP_ADDRESS_TYPE, value));
}
pub fn lookup_nas_ip_address(packet: &Packet) -> Option<Result<Ipv4Addr, AVPError>> {
packet.lookup(NAS_IP_ADDRESS_TYPE).map(|v| v.decode_ipv4())
packet.lookup(NAS_IP_ADDRESS_TYPE).map(|v| v.encode_ipv4())
}
pub fn lookup_all_nas_ip_address(packet: &Packet) -> Result<Vec<Ipv4Addr>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(NAS_IP_ADDRESS_TYPE) {
vec.push(avp.decode_ipv4()?)
vec.push(avp.encode_ipv4()?)
}
Ok(vec)
}
@@ -164,15 +164,15 @@ pub fn delete_nas_port(packet: &mut Packet) {
packet.delete(NAS_PORT_TYPE);
}
pub fn add_nas_port(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(NAS_PORT_TYPE, value));
packet.add(AVP::from_u32(NAS_PORT_TYPE, value));
}
pub fn lookup_nas_port(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet.lookup(NAS_PORT_TYPE).map(|v| v.decode_u32())
packet.lookup(NAS_PORT_TYPE).map(|v| v.encode_u32())
}
pub fn lookup_all_nas_port(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(NAS_PORT_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -182,17 +182,17 @@ pub fn delete_service_type(packet: &mut Packet) {
packet.delete(SERVICE_TYPE_TYPE);
}
pub fn add_service_type(packet: &mut Packet, value: ServiceType) {
packet.add(AVP::encode_u32(SERVICE_TYPE_TYPE, value as u32));
packet.add(AVP::from_u32(SERVICE_TYPE_TYPE, value as u32));
}
pub fn lookup_service_type(packet: &Packet) -> Option<Result<ServiceType, AVPError>> {
packet
.lookup(SERVICE_TYPE_TYPE)
.map(|v| Ok(v.decode_u32()? as ServiceType))
.map(|v| Ok(v.encode_u32()? as ServiceType))
}
pub fn lookup_all_service_type(packet: &Packet) -> Result<Vec<ServiceType>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(SERVICE_TYPE_TYPE) {
vec.push(avp.decode_u32()? as ServiceType)
vec.push(avp.encode_u32()? as ServiceType)
}
Ok(vec)
}
@@ -202,17 +202,17 @@ pub fn delete_framed_protocol(packet: &mut Packet) {
packet.delete(FRAMED_PROTOCOL_TYPE);
}
pub fn add_framed_protocol(packet: &mut Packet, value: FramedProtocol) {
packet.add(AVP::encode_u32(FRAMED_PROTOCOL_TYPE, value as u32));
packet.add(AVP::from_u32(FRAMED_PROTOCOL_TYPE, value as u32));
}
pub fn lookup_framed_protocol(packet: &Packet) -> Option<Result<FramedProtocol, AVPError>> {
packet
.lookup(FRAMED_PROTOCOL_TYPE)
.map(|v| Ok(v.decode_u32()? as FramedProtocol))
.map(|v| Ok(v.encode_u32()? as FramedProtocol))
}
pub fn lookup_all_framed_protocol(packet: &Packet) -> Result<Vec<FramedProtocol>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(FRAMED_PROTOCOL_TYPE) {
vec.push(avp.decode_u32()? as FramedProtocol)
vec.push(avp.encode_u32()? as FramedProtocol)
}
Ok(vec)
}
@@ -222,17 +222,17 @@ pub fn delete_framed_ip_address(packet: &mut Packet) {
packet.delete(FRAMED_IP_ADDRESS_TYPE);
}
pub fn add_framed_ip_address(packet: &mut Packet, value: &Ipv4Addr) {
packet.add(AVP::encode_ipv4(FRAMED_IP_ADDRESS_TYPE, value));
packet.add(AVP::from_ipv4(FRAMED_IP_ADDRESS_TYPE, value));
}
pub fn lookup_framed_ip_address(packet: &Packet) -> Option<Result<Ipv4Addr, AVPError>> {
packet
.lookup(FRAMED_IP_ADDRESS_TYPE)
.map(|v| v.decode_ipv4())
.map(|v| v.encode_ipv4())
}
pub fn lookup_all_framed_ip_address(packet: &Packet) -> Result<Vec<Ipv4Addr>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(FRAMED_IP_ADDRESS_TYPE) {
vec.push(avp.decode_ipv4()?)
vec.push(avp.encode_ipv4()?)
}
Ok(vec)
}
@@ -242,17 +242,17 @@ pub fn delete_framed_ip_netmask(packet: &mut Packet) {
packet.delete(FRAMED_IP_NETMASK_TYPE);
}
pub fn add_framed_ip_netmask(packet: &mut Packet, value: &Ipv4Addr) {
packet.add(AVP::encode_ipv4(FRAMED_IP_NETMASK_TYPE, value));
packet.add(AVP::from_ipv4(FRAMED_IP_NETMASK_TYPE, value));
}
pub fn lookup_framed_ip_netmask(packet: &Packet) -> Option<Result<Ipv4Addr, AVPError>> {
packet
.lookup(FRAMED_IP_NETMASK_TYPE)
.map(|v| v.decode_ipv4())
.map(|v| v.encode_ipv4())
}
pub fn lookup_all_framed_ip_netmask(packet: &Packet) -> Result<Vec<Ipv4Addr>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(FRAMED_IP_NETMASK_TYPE) {
vec.push(avp.decode_ipv4()?)
vec.push(avp.encode_ipv4()?)
}
Ok(vec)
}
@@ -262,17 +262,17 @@ pub fn delete_framed_routing(packet: &mut Packet) {
packet.delete(FRAMED_ROUTING_TYPE);
}
pub fn add_framed_routing(packet: &mut Packet, value: FramedRouting) {
packet.add(AVP::encode_u32(FRAMED_ROUTING_TYPE, value as u32));
packet.add(AVP::from_u32(FRAMED_ROUTING_TYPE, value as u32));
}
pub fn lookup_framed_routing(packet: &Packet) -> Option<Result<FramedRouting, AVPError>> {
packet
.lookup(FRAMED_ROUTING_TYPE)
.map(|v| Ok(v.decode_u32()? as FramedRouting))
.map(|v| Ok(v.encode_u32()? as FramedRouting))
}
pub fn lookup_all_framed_routing(packet: &Packet) -> Result<Vec<FramedRouting>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(FRAMED_ROUTING_TYPE) {
vec.push(avp.decode_u32()? as FramedRouting)
vec.push(avp.encode_u32()? as FramedRouting)
}
Ok(vec)
}
@@ -282,15 +282,15 @@ pub fn delete_filter_id(packet: &mut Packet) {
packet.delete(FILTER_ID_TYPE);
}
pub fn add_filter_id(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(FILTER_ID_TYPE, value));
packet.add(AVP::from_string(FILTER_ID_TYPE, value));
}
pub fn lookup_filter_id(packet: &Packet) -> Option<Result<String, AVPError>> {
packet.lookup(FILTER_ID_TYPE).map(|v| v.decode_string())
packet.lookup(FILTER_ID_TYPE).map(|v| v.encode_string())
}
pub fn lookup_all_filter_id(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(FILTER_ID_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -300,15 +300,15 @@ pub fn delete_framed_mtu(packet: &mut Packet) {
packet.delete(FRAMED_MTU_TYPE);
}
pub fn add_framed_mtu(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(FRAMED_MTU_TYPE, value));
packet.add(AVP::from_u32(FRAMED_MTU_TYPE, value));
}
pub fn lookup_framed_mtu(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet.lookup(FRAMED_MTU_TYPE).map(|v| v.decode_u32())
packet.lookup(FRAMED_MTU_TYPE).map(|v| v.encode_u32())
}
pub fn lookup_all_framed_mtu(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(FRAMED_MTU_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -318,17 +318,17 @@ pub fn delete_framed_compression(packet: &mut Packet) {
packet.delete(FRAMED_COMPRESSION_TYPE);
}
pub fn add_framed_compression(packet: &mut Packet, value: FramedCompression) {
packet.add(AVP::encode_u32(FRAMED_COMPRESSION_TYPE, value as u32));
packet.add(AVP::from_u32(FRAMED_COMPRESSION_TYPE, value as u32));
}
pub fn lookup_framed_compression(packet: &Packet) -> Option<Result<FramedCompression, AVPError>> {
packet
.lookup(FRAMED_COMPRESSION_TYPE)
.map(|v| Ok(v.decode_u32()? as FramedCompression))
.map(|v| Ok(v.encode_u32()? as FramedCompression))
}
pub fn lookup_all_framed_compression(packet: &Packet) -> Result<Vec<FramedCompression>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(FRAMED_COMPRESSION_TYPE) {
vec.push(avp.decode_u32()? as FramedCompression)
vec.push(avp.encode_u32()? as FramedCompression)
}
Ok(vec)
}
@@ -338,15 +338,15 @@ pub fn delete_login_ip_host(packet: &mut Packet) {
packet.delete(LOGIN_IP_HOST_TYPE);
}
pub fn add_login_ip_host(packet: &mut Packet, value: &Ipv4Addr) {
packet.add(AVP::encode_ipv4(LOGIN_IP_HOST_TYPE, value));
packet.add(AVP::from_ipv4(LOGIN_IP_HOST_TYPE, value));
}
pub fn lookup_login_ip_host(packet: &Packet) -> Option<Result<Ipv4Addr, AVPError>> {
packet.lookup(LOGIN_IP_HOST_TYPE).map(|v| v.decode_ipv4())
packet.lookup(LOGIN_IP_HOST_TYPE).map(|v| v.encode_ipv4())
}
pub fn lookup_all_login_ip_host(packet: &Packet) -> Result<Vec<Ipv4Addr>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(LOGIN_IP_HOST_TYPE) {
vec.push(avp.decode_ipv4()?)
vec.push(avp.encode_ipv4()?)
}
Ok(vec)
}
@@ -356,17 +356,17 @@ pub fn delete_login_service(packet: &mut Packet) {
packet.delete(LOGIN_SERVICE_TYPE);
}
pub fn add_login_service(packet: &mut Packet, value: LoginService) {
packet.add(AVP::encode_u32(LOGIN_SERVICE_TYPE, value as u32));
packet.add(AVP::from_u32(LOGIN_SERVICE_TYPE, value as u32));
}
pub fn lookup_login_service(packet: &Packet) -> Option<Result<LoginService, AVPError>> {
packet
.lookup(LOGIN_SERVICE_TYPE)
.map(|v| Ok(v.decode_u32()? as LoginService))
.map(|v| Ok(v.encode_u32()? as LoginService))
}
pub fn lookup_all_login_service(packet: &Packet) -> Result<Vec<LoginService>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(LOGIN_SERVICE_TYPE) {
vec.push(avp.decode_u32()? as LoginService)
vec.push(avp.encode_u32()? as LoginService)
}
Ok(vec)
}
@@ -376,17 +376,17 @@ pub fn delete_login_tcp_port(packet: &mut Packet) {
packet.delete(LOGIN_TCP_PORT_TYPE);
}
pub fn add_login_tcp_port(packet: &mut Packet, value: LoginTCPPort) {
packet.add(AVP::encode_u32(LOGIN_TCP_PORT_TYPE, value as u32));
packet.add(AVP::from_u32(LOGIN_TCP_PORT_TYPE, value as u32));
}
pub fn lookup_login_tcp_port(packet: &Packet) -> Option<Result<LoginTCPPort, AVPError>> {
packet
.lookup(LOGIN_TCP_PORT_TYPE)
.map(|v| Ok(v.decode_u32()? as LoginTCPPort))
.map(|v| Ok(v.encode_u32()? as LoginTCPPort))
}
pub fn lookup_all_login_tcp_port(packet: &Packet) -> Result<Vec<LoginTCPPort>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(LOGIN_TCP_PORT_TYPE) {
vec.push(avp.decode_u32()? as LoginTCPPort)
vec.push(avp.encode_u32()? as LoginTCPPort)
}
Ok(vec)
}
@@ -396,15 +396,15 @@ pub fn delete_reply_message(packet: &mut Packet) {
packet.delete(REPLY_MESSAGE_TYPE);
}
pub fn add_reply_message(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(REPLY_MESSAGE_TYPE, value));
packet.add(AVP::from_string(REPLY_MESSAGE_TYPE, value));
}
pub fn lookup_reply_message(packet: &Packet) -> Option<Result<String, AVPError>> {
packet.lookup(REPLY_MESSAGE_TYPE).map(|v| v.decode_string())
packet.lookup(REPLY_MESSAGE_TYPE).map(|v| v.encode_string())
}
pub fn lookup_all_reply_message(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(REPLY_MESSAGE_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -414,17 +414,17 @@ pub fn delete_callback_number(packet: &mut Packet) {
packet.delete(CALLBACK_NUMBER_TYPE);
}
pub fn add_callback_number(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(CALLBACK_NUMBER_TYPE, value));
packet.add(AVP::from_string(CALLBACK_NUMBER_TYPE, value));
}
pub fn lookup_callback_number(packet: &Packet) -> Option<Result<String, AVPError>> {
packet
.lookup(CALLBACK_NUMBER_TYPE)
.map(|v| v.decode_string())
.map(|v| v.encode_string())
}
pub fn lookup_all_callback_number(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(CALLBACK_NUMBER_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -434,15 +434,15 @@ pub fn delete_callback_id(packet: &mut Packet) {
packet.delete(CALLBACK_ID_TYPE);
}
pub fn add_callback_id(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(CALLBACK_ID_TYPE, value));
packet.add(AVP::from_string(CALLBACK_ID_TYPE, value));
}
pub fn lookup_callback_id(packet: &Packet) -> Option<Result<String, AVPError>> {
packet.lookup(CALLBACK_ID_TYPE).map(|v| v.decode_string())
packet.lookup(CALLBACK_ID_TYPE).map(|v| v.encode_string())
}
pub fn lookup_all_callback_id(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(CALLBACK_ID_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -452,15 +452,15 @@ pub fn delete_framed_route(packet: &mut Packet) {
packet.delete(FRAMED_ROUTE_TYPE);
}
pub fn add_framed_route(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(FRAMED_ROUTE_TYPE, value));
packet.add(AVP::from_string(FRAMED_ROUTE_TYPE, value));
}
pub fn lookup_framed_route(packet: &Packet) -> Option<Result<String, AVPError>> {
packet.lookup(FRAMED_ROUTE_TYPE).map(|v| v.decode_string())
packet.lookup(FRAMED_ROUTE_TYPE).map(|v| v.encode_string())
}
pub fn lookup_all_framed_route(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(FRAMED_ROUTE_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -470,17 +470,17 @@ pub fn delete_framed_ipx_network(packet: &mut Packet) {
packet.delete(FRAMED_IPX_NETWORK_TYPE);
}
pub fn add_framed_ipx_network(packet: &mut Packet, value: &Ipv4Addr) {
packet.add(AVP::encode_ipv4(FRAMED_IPX_NETWORK_TYPE, value));
packet.add(AVP::from_ipv4(FRAMED_IPX_NETWORK_TYPE, value));
}
pub fn lookup_framed_ipx_network(packet: &Packet) -> Option<Result<Ipv4Addr, AVPError>> {
packet
.lookup(FRAMED_IPX_NETWORK_TYPE)
.map(|v| v.decode_ipv4())
.map(|v| v.encode_ipv4())
}
pub fn lookup_all_framed_ipx_network(packet: &Packet) -> Result<Vec<Ipv4Addr>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(FRAMED_IPX_NETWORK_TYPE) {
vec.push(avp.decode_ipv4()?)
vec.push(avp.encode_ipv4()?)
}
Ok(vec)
}
@@ -490,15 +490,15 @@ pub fn delete_state(packet: &mut Packet) {
packet.delete(STATE_TYPE);
}
pub fn add_state(packet: &mut Packet, value: &[u8]) {
packet.add(AVP::encode_bytes(STATE_TYPE, value));
packet.add(AVP::from_bytes(STATE_TYPE, value));
}
pub fn lookup_state(packet: &Packet) -> Option<Vec<u8>> {
packet.lookup(STATE_TYPE).map(|v| v.decode_bytes())
packet.lookup(STATE_TYPE).map(|v| v.encode_bytes())
}
pub fn lookup_all_state(packet: &Packet) -> Vec<Vec<u8>> {
let mut vec = Vec::new();
for avp in packet.lookup_all(STATE_TYPE) {
vec.push(avp.decode_bytes())
vec.push(avp.encode_bytes())
}
vec
}
@@ -508,15 +508,15 @@ pub fn delete_class(packet: &mut Packet) {
packet.delete(CLASS_TYPE);
}
pub fn add_class(packet: &mut Packet, value: &[u8]) {
packet.add(AVP::encode_bytes(CLASS_TYPE, value));
packet.add(AVP::from_bytes(CLASS_TYPE, value));
}
pub fn lookup_class(packet: &Packet) -> Option<Vec<u8>> {
packet.lookup(CLASS_TYPE).map(|v| v.decode_bytes())
packet.lookup(CLASS_TYPE).map(|v| v.encode_bytes())
}
pub fn lookup_all_class(packet: &Packet) -> Vec<Vec<u8>> {
let mut vec = Vec::new();
for avp in packet.lookup_all(CLASS_TYPE) {
vec.push(avp.decode_bytes())
vec.push(avp.encode_bytes())
}
vec
}
@@ -531,15 +531,15 @@ pub fn delete_session_timeout(packet: &mut Packet) {
packet.delete(SESSION_TIMEOUT_TYPE);
}
pub fn add_session_timeout(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(SESSION_TIMEOUT_TYPE, value));
packet.add(AVP::from_u32(SESSION_TIMEOUT_TYPE, value));
}
pub fn lookup_session_timeout(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet.lookup(SESSION_TIMEOUT_TYPE).map(|v| v.decode_u32())
packet.lookup(SESSION_TIMEOUT_TYPE).map(|v| v.encode_u32())
}
pub fn lookup_all_session_timeout(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(SESSION_TIMEOUT_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -549,15 +549,15 @@ pub fn delete_idle_timeout(packet: &mut Packet) {
packet.delete(IDLE_TIMEOUT_TYPE);
}
pub fn add_idle_timeout(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(IDLE_TIMEOUT_TYPE, value));
packet.add(AVP::from_u32(IDLE_TIMEOUT_TYPE, value));
}
pub fn lookup_idle_timeout(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet.lookup(IDLE_TIMEOUT_TYPE).map(|v| v.decode_u32())
packet.lookup(IDLE_TIMEOUT_TYPE).map(|v| v.encode_u32())
}
pub fn lookup_all_idle_timeout(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(IDLE_TIMEOUT_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -567,17 +567,17 @@ pub fn delete_termination_action(packet: &mut Packet) {
packet.delete(TERMINATION_ACTION_TYPE);
}
pub fn add_termination_action(packet: &mut Packet, value: TerminationAction) {
packet.add(AVP::encode_u32(TERMINATION_ACTION_TYPE, value as u32));
packet.add(AVP::from_u32(TERMINATION_ACTION_TYPE, value as u32));
}
pub fn lookup_termination_action(packet: &Packet) -> Option<Result<TerminationAction, AVPError>> {
packet
.lookup(TERMINATION_ACTION_TYPE)
.map(|v| Ok(v.decode_u32()? as TerminationAction))
.map(|v| Ok(v.encode_u32()? as TerminationAction))
}
pub fn lookup_all_termination_action(packet: &Packet) -> Result<Vec<TerminationAction>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(TERMINATION_ACTION_TYPE) {
vec.push(avp.decode_u32()? as TerminationAction)
vec.push(avp.encode_u32()? as TerminationAction)
}
Ok(vec)
}
@@ -587,17 +587,17 @@ pub fn delete_called_station_id(packet: &mut Packet) {
packet.delete(CALLED_STATION_ID_TYPE);
}
pub fn add_called_station_id(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(CALLED_STATION_ID_TYPE, value));
packet.add(AVP::from_string(CALLED_STATION_ID_TYPE, value));
}
pub fn lookup_called_station_id(packet: &Packet) -> Option<Result<String, AVPError>> {
packet
.lookup(CALLED_STATION_ID_TYPE)
.map(|v| v.decode_string())
.map(|v| v.encode_string())
}
pub fn lookup_all_called_station_id(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(CALLED_STATION_ID_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -607,17 +607,17 @@ pub fn delete_calling_station_id(packet: &mut Packet) {
packet.delete(CALLING_STATION_ID_TYPE);
}
pub fn add_calling_station_id(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(CALLING_STATION_ID_TYPE, value));
packet.add(AVP::from_string(CALLING_STATION_ID_TYPE, value));
}
pub fn lookup_calling_station_id(packet: &Packet) -> Option<Result<String, AVPError>> {
packet
.lookup(CALLING_STATION_ID_TYPE)
.map(|v| v.decode_string())
.map(|v| v.encode_string())
}
pub fn lookup_all_calling_station_id(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(CALLING_STATION_ID_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -627,17 +627,17 @@ pub fn delete_nas_identifier(packet: &mut Packet) {
packet.delete(NAS_IDENTIFIER_TYPE);
}
pub fn add_nas_identifier(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(NAS_IDENTIFIER_TYPE, value));
packet.add(AVP::from_string(NAS_IDENTIFIER_TYPE, value));
}
pub fn lookup_nas_identifier(packet: &Packet) -> Option<Result<String, AVPError>> {
packet
.lookup(NAS_IDENTIFIER_TYPE)
.map(|v| v.decode_string())
.map(|v| v.encode_string())
}
pub fn lookup_all_nas_identifier(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(NAS_IDENTIFIER_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -647,15 +647,15 @@ pub fn delete_proxy_state(packet: &mut Packet) {
packet.delete(PROXY_STATE_TYPE);
}
pub fn add_proxy_state(packet: &mut Packet, value: &[u8]) {
packet.add(AVP::encode_bytes(PROXY_STATE_TYPE, value));
packet.add(AVP::from_bytes(PROXY_STATE_TYPE, value));
}
pub fn lookup_proxy_state(packet: &Packet) -> Option<Vec<u8>> {
packet.lookup(PROXY_STATE_TYPE).map(|v| v.decode_bytes())
packet.lookup(PROXY_STATE_TYPE).map(|v| v.encode_bytes())
}
pub fn lookup_all_proxy_state(packet: &Packet) -> Vec<Vec<u8>> {
let mut vec = Vec::new();
for avp in packet.lookup_all(PROXY_STATE_TYPE) {
vec.push(avp.decode_bytes())
vec.push(avp.encode_bytes())
}
vec
}
@@ -665,17 +665,17 @@ pub fn delete_login_lat_service(packet: &mut Packet) {
packet.delete(LOGIN_LAT_SERVICE_TYPE);
}
pub fn add_login_lat_service(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(LOGIN_LAT_SERVICE_TYPE, value));
packet.add(AVP::from_string(LOGIN_LAT_SERVICE_TYPE, value));
}
pub fn lookup_login_lat_service(packet: &Packet) -> Option<Result<String, AVPError>> {
packet
.lookup(LOGIN_LAT_SERVICE_TYPE)
.map(|v| v.decode_string())
.map(|v| v.encode_string())
}
pub fn lookup_all_login_lat_service(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(LOGIN_LAT_SERVICE_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -685,17 +685,17 @@ pub fn delete_login_lat_node(packet: &mut Packet) {
packet.delete(LOGIN_LAT_NODE_TYPE);
}
pub fn add_login_lat_node(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(LOGIN_LAT_NODE_TYPE, value));
packet.add(AVP::from_string(LOGIN_LAT_NODE_TYPE, value));
}
pub fn lookup_login_lat_node(packet: &Packet) -> Option<Result<String, AVPError>> {
packet
.lookup(LOGIN_LAT_NODE_TYPE)
.map(|v| v.decode_string())
.map(|v| v.encode_string())
}
pub fn lookup_all_login_lat_node(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(LOGIN_LAT_NODE_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -705,17 +705,17 @@ pub fn delete_login_lat_group(packet: &mut Packet) {
packet.delete(LOGIN_LAT_GROUP_TYPE);
}
pub fn add_login_lat_group(packet: &mut Packet, value: &[u8]) {
packet.add(AVP::encode_bytes(LOGIN_LAT_GROUP_TYPE, value));
packet.add(AVP::from_bytes(LOGIN_LAT_GROUP_TYPE, value));
}
pub fn lookup_login_lat_group(packet: &Packet) -> Option<Vec<u8>> {
packet
.lookup(LOGIN_LAT_GROUP_TYPE)
.map(|v| v.decode_bytes())
.map(|v| v.encode_bytes())
}
pub fn lookup_all_login_lat_group(packet: &Packet) -> Vec<Vec<u8>> {
let mut vec = Vec::new();
for avp in packet.lookup_all(LOGIN_LAT_GROUP_TYPE) {
vec.push(avp.decode_bytes())
vec.push(avp.encode_bytes())
}
vec
}
@@ -725,17 +725,17 @@ pub fn delete_framed_apple_talk_link(packet: &mut Packet) {
packet.delete(FRAMED_APPLE_TALK_LINK_TYPE);
}
pub fn add_framed_apple_talk_link(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(FRAMED_APPLE_TALK_LINK_TYPE, value));
packet.add(AVP::from_u32(FRAMED_APPLE_TALK_LINK_TYPE, value));
}
pub fn lookup_framed_apple_talk_link(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet
.lookup(FRAMED_APPLE_TALK_LINK_TYPE)
.map(|v| v.decode_u32())
.map(|v| v.encode_u32())
}
pub fn lookup_all_framed_apple_talk_link(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(FRAMED_APPLE_TALK_LINK_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -745,17 +745,17 @@ pub fn delete_framed_apple_talk_network(packet: &mut Packet) {
packet.delete(FRAMED_APPLE_TALK_NETWORK_TYPE);
}
pub fn add_framed_apple_talk_network(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(FRAMED_APPLE_TALK_NETWORK_TYPE, value));
packet.add(AVP::from_u32(FRAMED_APPLE_TALK_NETWORK_TYPE, value));
}
pub fn lookup_framed_apple_talk_network(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet
.lookup(FRAMED_APPLE_TALK_NETWORK_TYPE)
.map(|v| v.decode_u32())
.map(|v| v.encode_u32())
}
pub fn lookup_all_framed_apple_talk_network(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(FRAMED_APPLE_TALK_NETWORK_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -765,17 +765,17 @@ pub fn delete_framed_apple_talk_zone(packet: &mut Packet) {
packet.delete(FRAMED_APPLE_TALK_ZONE_TYPE);
}
pub fn add_framed_apple_talk_zone(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(FRAMED_APPLE_TALK_ZONE_TYPE, value));
packet.add(AVP::from_string(FRAMED_APPLE_TALK_ZONE_TYPE, value));
}
pub fn lookup_framed_apple_talk_zone(packet: &Packet) -> Option<Result<String, AVPError>> {
packet
.lookup(FRAMED_APPLE_TALK_ZONE_TYPE)
.map(|v| v.decode_string())
.map(|v| v.encode_string())
}
pub fn lookup_all_framed_apple_talk_zone(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(FRAMED_APPLE_TALK_ZONE_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -785,15 +785,15 @@ pub fn delete_chap_challenge(packet: &mut Packet) {
packet.delete(CHAP_CHALLENGE_TYPE);
}
pub fn add_chap_challenge(packet: &mut Packet, value: &[u8]) {
packet.add(AVP::encode_bytes(CHAP_CHALLENGE_TYPE, value));
packet.add(AVP::from_bytes(CHAP_CHALLENGE_TYPE, value));
}
pub fn lookup_chap_challenge(packet: &Packet) -> Option<Vec<u8>> {
packet.lookup(CHAP_CHALLENGE_TYPE).map(|v| v.decode_bytes())
packet.lookup(CHAP_CHALLENGE_TYPE).map(|v| v.encode_bytes())
}
pub fn lookup_all_chap_challenge(packet: &Packet) -> Vec<Vec<u8>> {
let mut vec = Vec::new();
for avp in packet.lookup_all(CHAP_CHALLENGE_TYPE) {
vec.push(avp.decode_bytes())
vec.push(avp.encode_bytes())
}
vec
}
@@ -803,17 +803,17 @@ pub fn delete_nas_port_type(packet: &mut Packet) {
packet.delete(NAS_PORT_TYPE_TYPE);
}
pub fn add_nas_port_type(packet: &mut Packet, value: NasPortType) {
packet.add(AVP::encode_u32(NAS_PORT_TYPE_TYPE, value as u32));
packet.add(AVP::from_u32(NAS_PORT_TYPE_TYPE, value as u32));
}
pub fn lookup_nas_port_type(packet: &Packet) -> Option<Result<NasPortType, AVPError>> {
packet
.lookup(NAS_PORT_TYPE_TYPE)
.map(|v| Ok(v.decode_u32()? as NasPortType))
.map(|v| Ok(v.encode_u32()? as NasPortType))
}
pub fn lookup_all_nas_port_type(packet: &Packet) -> Result<Vec<NasPortType>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(NAS_PORT_TYPE_TYPE) {
vec.push(avp.decode_u32()? as NasPortType)
vec.push(avp.encode_u32()? as NasPortType)
}
Ok(vec)
}
@@ -823,15 +823,15 @@ pub fn delete_port_limit(packet: &mut Packet) {
packet.delete(PORT_LIMIT_TYPE);
}
pub fn add_port_limit(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(PORT_LIMIT_TYPE, value));
packet.add(AVP::from_u32(PORT_LIMIT_TYPE, value));
}
pub fn lookup_port_limit(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet.lookup(PORT_LIMIT_TYPE).map(|v| v.decode_u32())
packet.lookup(PORT_LIMIT_TYPE).map(|v| v.encode_u32())
}
pub fn lookup_all_port_limit(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(PORT_LIMIT_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -841,17 +841,17 @@ pub fn delete_login_lat_port(packet: &mut Packet) {
packet.delete(LOGIN_LAT_PORT_TYPE);
}
pub fn add_login_lat_port(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(LOGIN_LAT_PORT_TYPE, value));
packet.add(AVP::from_string(LOGIN_LAT_PORT_TYPE, value));
}
pub fn lookup_login_lat_port(packet: &Packet) -> Option<Result<String, AVPError>> {
packet
.lookup(LOGIN_LAT_PORT_TYPE)
.map(|v| v.decode_string())
.map(|v| v.encode_string())
}
pub fn lookup_all_login_lat_port(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(LOGIN_LAT_PORT_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}

View File

@@ -43,17 +43,17 @@ pub fn delete_acct_status_type(packet: &mut Packet) {
packet.delete(ACCT_STATUS_TYPE_TYPE);
}
pub fn add_acct_status_type(packet: &mut Packet, value: AcctStatusType) {
packet.add(AVP::encode_u32(ACCT_STATUS_TYPE_TYPE, value as u32));
packet.add(AVP::from_u32(ACCT_STATUS_TYPE_TYPE, value as u32));
}
pub fn lookup_acct_status_type(packet: &Packet) -> Option<Result<AcctStatusType, AVPError>> {
packet
.lookup(ACCT_STATUS_TYPE_TYPE)
.map(|v| Ok(v.decode_u32()? as AcctStatusType))
.map(|v| Ok(v.encode_u32()? as AcctStatusType))
}
pub fn lookup_all_acct_status_type(packet: &Packet) -> Result<Vec<AcctStatusType>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_STATUS_TYPE_TYPE) {
vec.push(avp.decode_u32()? as AcctStatusType)
vec.push(avp.encode_u32()? as AcctStatusType)
}
Ok(vec)
}
@@ -63,15 +63,15 @@ pub fn delete_acct_delay_time(packet: &mut Packet) {
packet.delete(ACCT_DELAY_TIME_TYPE);
}
pub fn add_acct_delay_time(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(ACCT_DELAY_TIME_TYPE, value));
packet.add(AVP::from_u32(ACCT_DELAY_TIME_TYPE, value));
}
pub fn lookup_acct_delay_time(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet.lookup(ACCT_DELAY_TIME_TYPE).map(|v| v.decode_u32())
packet.lookup(ACCT_DELAY_TIME_TYPE).map(|v| v.encode_u32())
}
pub fn lookup_all_acct_delay_time(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_DELAY_TIME_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -81,17 +81,17 @@ pub fn delete_acct_input_octets(packet: &mut Packet) {
packet.delete(ACCT_INPUT_OCTETS_TYPE);
}
pub fn add_acct_input_octets(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(ACCT_INPUT_OCTETS_TYPE, value));
packet.add(AVP::from_u32(ACCT_INPUT_OCTETS_TYPE, value));
}
pub fn lookup_acct_input_octets(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet
.lookup(ACCT_INPUT_OCTETS_TYPE)
.map(|v| v.decode_u32())
.map(|v| v.encode_u32())
}
pub fn lookup_all_acct_input_octets(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_INPUT_OCTETS_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -101,17 +101,17 @@ pub fn delete_acct_output_octets(packet: &mut Packet) {
packet.delete(ACCT_OUTPUT_OCTETS_TYPE);
}
pub fn add_acct_output_octets(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(ACCT_OUTPUT_OCTETS_TYPE, value));
packet.add(AVP::from_u32(ACCT_OUTPUT_OCTETS_TYPE, value));
}
pub fn lookup_acct_output_octets(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet
.lookup(ACCT_OUTPUT_OCTETS_TYPE)
.map(|v| v.decode_u32())
.map(|v| v.encode_u32())
}
pub fn lookup_all_acct_output_octets(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_OUTPUT_OCTETS_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -121,17 +121,17 @@ pub fn delete_acct_session_id(packet: &mut Packet) {
packet.delete(ACCT_SESSION_ID_TYPE);
}
pub fn add_acct_session_id(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(ACCT_SESSION_ID_TYPE, value));
packet.add(AVP::from_string(ACCT_SESSION_ID_TYPE, value));
}
pub fn lookup_acct_session_id(packet: &Packet) -> Option<Result<String, AVPError>> {
packet
.lookup(ACCT_SESSION_ID_TYPE)
.map(|v| v.decode_string())
.map(|v| v.encode_string())
}
pub fn lookup_all_acct_session_id(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_SESSION_ID_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -141,17 +141,17 @@ pub fn delete_acct_authentic(packet: &mut Packet) {
packet.delete(ACCT_AUTHENTIC_TYPE);
}
pub fn add_acct_authentic(packet: &mut Packet, value: AcctAuthentic) {
packet.add(AVP::encode_u32(ACCT_AUTHENTIC_TYPE, value as u32));
packet.add(AVP::from_u32(ACCT_AUTHENTIC_TYPE, value as u32));
}
pub fn lookup_acct_authentic(packet: &Packet) -> Option<Result<AcctAuthentic, AVPError>> {
packet
.lookup(ACCT_AUTHENTIC_TYPE)
.map(|v| Ok(v.decode_u32()? as AcctAuthentic))
.map(|v| Ok(v.encode_u32()? as AcctAuthentic))
}
pub fn lookup_all_acct_authentic(packet: &Packet) -> Result<Vec<AcctAuthentic>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_AUTHENTIC_TYPE) {
vec.push(avp.decode_u32()? as AcctAuthentic)
vec.push(avp.encode_u32()? as AcctAuthentic)
}
Ok(vec)
}
@@ -161,17 +161,17 @@ pub fn delete_acct_session_time(packet: &mut Packet) {
packet.delete(ACCT_SESSION_TIME_TYPE);
}
pub fn add_acct_session_time(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(ACCT_SESSION_TIME_TYPE, value));
packet.add(AVP::from_u32(ACCT_SESSION_TIME_TYPE, value));
}
pub fn lookup_acct_session_time(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet
.lookup(ACCT_SESSION_TIME_TYPE)
.map(|v| v.decode_u32())
.map(|v| v.encode_u32())
}
pub fn lookup_all_acct_session_time(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_SESSION_TIME_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -181,17 +181,17 @@ pub fn delete_acct_input_packets(packet: &mut Packet) {
packet.delete(ACCT_INPUT_PACKETS_TYPE);
}
pub fn add_acct_input_packets(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(ACCT_INPUT_PACKETS_TYPE, value));
packet.add(AVP::from_u32(ACCT_INPUT_PACKETS_TYPE, value));
}
pub fn lookup_acct_input_packets(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet
.lookup(ACCT_INPUT_PACKETS_TYPE)
.map(|v| v.decode_u32())
.map(|v| v.encode_u32())
}
pub fn lookup_all_acct_input_packets(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_INPUT_PACKETS_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -201,17 +201,17 @@ pub fn delete_acct_output_packets(packet: &mut Packet) {
packet.delete(ACCT_OUTPUT_PACKETS_TYPE);
}
pub fn add_acct_output_packets(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(ACCT_OUTPUT_PACKETS_TYPE, value));
packet.add(AVP::from_u32(ACCT_OUTPUT_PACKETS_TYPE, value));
}
pub fn lookup_acct_output_packets(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet
.lookup(ACCT_OUTPUT_PACKETS_TYPE)
.map(|v| v.decode_u32())
.map(|v| v.encode_u32())
}
pub fn lookup_all_acct_output_packets(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_OUTPUT_PACKETS_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}
@@ -221,21 +221,21 @@ pub fn delete_acct_terminate_cause(packet: &mut Packet) {
packet.delete(ACCT_TERMINATE_CAUSE_TYPE);
}
pub fn add_acct_terminate_cause(packet: &mut Packet, value: AcctTerminateCause) {
packet.add(AVP::encode_u32(ACCT_TERMINATE_CAUSE_TYPE, value as u32));
packet.add(AVP::from_u32(ACCT_TERMINATE_CAUSE_TYPE, value as u32));
}
pub fn lookup_acct_terminate_cause(
packet: &Packet,
) -> Option<Result<AcctTerminateCause, AVPError>> {
packet
.lookup(ACCT_TERMINATE_CAUSE_TYPE)
.map(|v| Ok(v.decode_u32()? as AcctTerminateCause))
.map(|v| Ok(v.encode_u32()? as AcctTerminateCause))
}
pub fn lookup_all_acct_terminate_cause(
packet: &Packet,
) -> Result<Vec<AcctTerminateCause>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_TERMINATE_CAUSE_TYPE) {
vec.push(avp.decode_u32()? as AcctTerminateCause)
vec.push(avp.encode_u32()? as AcctTerminateCause)
}
Ok(vec)
}
@@ -245,17 +245,17 @@ pub fn delete_acct_multi_session_id(packet: &mut Packet) {
packet.delete(ACCT_MULTI_SESSION_ID_TYPE);
}
pub fn add_acct_multi_session_id(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(ACCT_MULTI_SESSION_ID_TYPE, value));
packet.add(AVP::from_string(ACCT_MULTI_SESSION_ID_TYPE, value));
}
pub fn lookup_acct_multi_session_id(packet: &Packet) -> Option<Result<String, AVPError>> {
packet
.lookup(ACCT_MULTI_SESSION_ID_TYPE)
.map(|v| v.decode_string())
.map(|v| v.encode_string())
}
pub fn lookup_all_acct_multi_session_id(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_MULTI_SESSION_ID_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -265,15 +265,15 @@ pub fn delete_acct_link_count(packet: &mut Packet) {
packet.delete(ACCT_LINK_COUNT_TYPE);
}
pub fn add_acct_link_count(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(ACCT_LINK_COUNT_TYPE, value));
packet.add(AVP::from_u32(ACCT_LINK_COUNT_TYPE, value));
}
pub fn lookup_acct_link_count(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet.lookup(ACCT_LINK_COUNT_TYPE).map(|v| v.decode_u32())
packet.lookup(ACCT_LINK_COUNT_TYPE).map(|v| v.encode_u32())
}
pub fn lookup_all_acct_link_count(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_LINK_COUNT_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}

View File

@@ -16,17 +16,17 @@ pub fn delete_acct_tunnel_connection(packet: &mut Packet) {
packet.delete(ACCT_TUNNEL_CONNECTION_TYPE);
}
pub fn add_acct_tunnel_connection(packet: &mut Packet, value: &str) {
packet.add(AVP::encode_string(ACCT_TUNNEL_CONNECTION_TYPE, value));
packet.add(AVP::from_string(ACCT_TUNNEL_CONNECTION_TYPE, value));
}
pub fn lookup_acct_tunnel_connection(packet: &Packet) -> Option<Result<String, AVPError>> {
packet
.lookup(ACCT_TUNNEL_CONNECTION_TYPE)
.map(|v| v.decode_string())
.map(|v| v.encode_string())
}
pub fn lookup_all_acct_tunnel_connection(packet: &Packet) -> Result<Vec<String>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_TUNNEL_CONNECTION_TYPE) {
vec.push(avp.decode_string()?)
vec.push(avp.encode_string()?)
}
Ok(vec)
}
@@ -36,17 +36,17 @@ pub fn delete_acct_tunnel_packets_lost(packet: &mut Packet) {
packet.delete(ACCT_TUNNEL_PACKETS_LOST_TYPE);
}
pub fn add_acct_tunnel_packets_lost(packet: &mut Packet, value: u32) {
packet.add(AVP::encode_u32(ACCT_TUNNEL_PACKETS_LOST_TYPE, value));
packet.add(AVP::from_u32(ACCT_TUNNEL_PACKETS_LOST_TYPE, value));
}
pub fn lookup_acct_tunnel_packets_lost(packet: &Packet) -> Option<Result<u32, AVPError>> {
packet
.lookup(ACCT_TUNNEL_PACKETS_LOST_TYPE)
.map(|v| v.decode_u32())
.map(|v| v.encode_u32())
}
pub fn lookup_all_acct_tunnel_packets_lost(packet: &Packet) -> Result<Vec<u32>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(ACCT_TUNNEL_PACKETS_LOST_TYPE) {
vec.push(avp.decode_u32()?)
vec.push(avp.encode_u32()?)
}
Ok(vec)
}

View File

@@ -41,18 +41,18 @@ pub fn delete_tunnel_type(packet: &mut Packet) {
packet.delete(TUNNEL_TYPE_TYPE);
}
pub fn add_tunnel_type(packet: &mut Packet, tag: Option<&Tag>, value: TunnelType) {
packet.add(AVP::encode_tagged_u32(TUNNEL_TYPE_TYPE, tag, value as u32));
packet.add(AVP::from_tagged_u32(TUNNEL_TYPE_TYPE, tag, value as u32));
}
pub fn lookup_tunnel_type(packet: &Packet) -> Option<Result<(TunnelType, Tag), AVPError>> {
packet.lookup(TUNNEL_TYPE_TYPE).map(|v| {
let (v, t) = v.decode_tagged_u32()?;
let (v, t) = v.encode_tagged_u32()?;
Ok((v as TunnelType, t))
})
}
pub fn lookup_all_tunnel_type(packet: &Packet) -> Result<Vec<(TunnelType, Tag)>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(TUNNEL_TYPE_TYPE) {
let (v, t) = avp.decode_tagged_u32()?;
let (v, t) = avp.encode_tagged_u32()?;
vec.push((v as TunnelType, t))
}
Ok(vec)
@@ -63,7 +63,7 @@ pub fn delete_tunnel_medium_type(packet: &mut Packet) {
packet.delete(TUNNEL_MEDIUM_TYPE_TYPE);
}
pub fn add_tunnel_medium_type(packet: &mut Packet, tag: Option<&Tag>, value: TunnelMediumType) {
packet.add(AVP::encode_tagged_u32(
packet.add(AVP::from_tagged_u32(
TUNNEL_MEDIUM_TYPE_TYPE,
tag,
value as u32,
@@ -73,7 +73,7 @@ pub fn lookup_tunnel_medium_type(
packet: &Packet,
) -> Option<Result<(TunnelMediumType, Tag), AVPError>> {
packet.lookup(TUNNEL_MEDIUM_TYPE_TYPE).map(|v| {
let (v, t) = v.decode_tagged_u32()?;
let (v, t) = v.encode_tagged_u32()?;
Ok((v as TunnelMediumType, t))
})
}
@@ -82,7 +82,7 @@ pub fn lookup_all_tunnel_medium_type(
) -> Result<Vec<(TunnelMediumType, Tag)>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(TUNNEL_MEDIUM_TYPE_TYPE) {
let (v, t) = avp.decode_tagged_u32()?;
let (v, t) = avp.encode_tagged_u32()?;
vec.push((v as TunnelMediumType, t))
}
Ok(vec)
@@ -93,7 +93,7 @@ pub fn delete_tunnel_client_endpoint(packet: &mut Packet) {
packet.delete(TUNNEL_CLIENT_ENDPOINT_TYPE);
}
pub fn add_tunnel_client_endpoint(packet: &mut Packet, tag: Option<&Tag>, value: &str) {
packet.add(AVP::encode_tagged_string(
packet.add(AVP::from_tagged_string(
TUNNEL_CLIENT_ENDPOINT_TYPE,
tag,
value,
@@ -104,14 +104,14 @@ pub fn lookup_tunnel_client_endpoint(
) -> Option<Result<(String, Option<Tag>), AVPError>> {
packet
.lookup(TUNNEL_CLIENT_ENDPOINT_TYPE)
.map(|v| v.decode_tagged_string())
.map(|v| v.encode_tagged_string())
}
pub fn lookup_all_tunnel_client_endpoint(
packet: &Packet,
) -> Result<Vec<(String, Option<Tag>)>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(TUNNEL_CLIENT_ENDPOINT_TYPE) {
vec.push(avp.decode_tagged_string()?)
vec.push(avp.encode_tagged_string()?)
}
Ok(vec)
}
@@ -121,7 +121,7 @@ pub fn delete_tunnel_server_endpoint(packet: &mut Packet) {
packet.delete(TUNNEL_SERVER_ENDPOINT_TYPE);
}
pub fn add_tunnel_server_endpoint(packet: &mut Packet, tag: Option<&Tag>, value: &str) {
packet.add(AVP::encode_tagged_string(
packet.add(AVP::from_tagged_string(
TUNNEL_SERVER_ENDPOINT_TYPE,
tag,
value,
@@ -132,14 +132,14 @@ pub fn lookup_tunnel_server_endpoint(
) -> Option<Result<(String, Option<Tag>), AVPError>> {
packet
.lookup(TUNNEL_SERVER_ENDPOINT_TYPE)
.map(|v| v.decode_tagged_string())
.map(|v| v.encode_tagged_string())
}
pub fn lookup_all_tunnel_server_endpoint(
packet: &Packet,
) -> Result<Vec<(String, Option<Tag>)>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(TUNNEL_SERVER_ENDPOINT_TYPE) {
vec.push(avp.decode_tagged_string()?)
vec.push(avp.encode_tagged_string()?)
}
Ok(vec)
}
@@ -153,7 +153,7 @@ pub fn add_tunnel_password(
tag: Option<&Tag>,
value: &[u8],
) -> Result<(), AVPError> {
packet.add(AVP::encode_tunnel_password(
packet.add(AVP::from_tunnel_password(
TUNNEL_PASSWORD_TYPE,
tag,
value,
@@ -165,12 +165,12 @@ pub fn add_tunnel_password(
pub fn lookup_tunnel_password(packet: &Packet) -> Option<Result<(Vec<u8>, Tag), AVPError>> {
packet
.lookup(TUNNEL_PASSWORD_TYPE)
.map(|v| v.decode_tunnel_password(packet.get_secret(), packet.get_authenticator()))
.map(|v| v.encode_tunnel_password(packet.get_secret(), packet.get_authenticator()))
}
pub fn lookup_all_tunnel_password(packet: &Packet) -> Result<Vec<(Vec<u8>, Tag)>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(TUNNEL_PASSWORD_TYPE) {
vec.push(avp.decode_tunnel_password(packet.get_secret(), packet.get_authenticator())?)
vec.push(avp.encode_tunnel_password(packet.get_secret(), packet.get_authenticator())?)
}
Ok(vec)
}
@@ -180,7 +180,7 @@ pub fn delete_tunnel_private_group_id(packet: &mut Packet) {
packet.delete(TUNNEL_PRIVATE_GROUP_ID_TYPE);
}
pub fn add_tunnel_private_group_id(packet: &mut Packet, tag: Option<&Tag>, value: &str) {
packet.add(AVP::encode_tagged_string(
packet.add(AVP::from_tagged_string(
TUNNEL_PRIVATE_GROUP_ID_TYPE,
tag,
value,
@@ -191,14 +191,14 @@ pub fn lookup_tunnel_private_group_id(
) -> Option<Result<(String, Option<Tag>), AVPError>> {
packet
.lookup(TUNNEL_PRIVATE_GROUP_ID_TYPE)
.map(|v| v.decode_tagged_string())
.map(|v| v.encode_tagged_string())
}
pub fn lookup_all_tunnel_private_group_id(
packet: &Packet,
) -> Result<Vec<(String, Option<Tag>)>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(TUNNEL_PRIVATE_GROUP_ID_TYPE) {
vec.push(avp.decode_tagged_string()?)
vec.push(avp.encode_tagged_string()?)
}
Ok(vec)
}
@@ -208,7 +208,7 @@ pub fn delete_tunnel_assignment_id(packet: &mut Packet) {
packet.delete(TUNNEL_ASSIGNMENT_ID_TYPE);
}
pub fn add_tunnel_assignment_id(packet: &mut Packet, tag: Option<&Tag>, value: &str) {
packet.add(AVP::encode_tagged_string(
packet.add(AVP::from_tagged_string(
TUNNEL_ASSIGNMENT_ID_TYPE,
tag,
value,
@@ -219,14 +219,14 @@ pub fn lookup_tunnel_assignment_id(
) -> Option<Result<(String, Option<Tag>), AVPError>> {
packet
.lookup(TUNNEL_ASSIGNMENT_ID_TYPE)
.map(|v| v.decode_tagged_string())
.map(|v| v.encode_tagged_string())
}
pub fn lookup_all_tunnel_assignment_id(
packet: &Packet,
) -> Result<Vec<(String, Option<Tag>)>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(TUNNEL_ASSIGNMENT_ID_TYPE) {
vec.push(avp.decode_tagged_string()?)
vec.push(avp.encode_tagged_string()?)
}
Ok(vec)
}
@@ -236,17 +236,17 @@ pub fn delete_tunnel_preference(packet: &mut Packet) {
packet.delete(TUNNEL_PREFERENCE_TYPE);
}
pub fn add_tunnel_preference(packet: &mut Packet, tag: Option<&Tag>, value: u32) {
packet.add(AVP::encode_tagged_u32(TUNNEL_PREFERENCE_TYPE, tag, value));
packet.add(AVP::from_tagged_u32(TUNNEL_PREFERENCE_TYPE, tag, value));
}
pub fn lookup_tunnel_preference(packet: &Packet) -> Option<Result<(u32, Tag), AVPError>> {
packet
.lookup(TUNNEL_PREFERENCE_TYPE)
.map(|v| v.decode_tagged_u32())
.map(|v| v.encode_tagged_u32())
}
pub fn lookup_all_tunnel_preference(packet: &Packet) -> Result<Vec<(u32, Tag)>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(TUNNEL_PREFERENCE_TYPE) {
vec.push(avp.decode_tagged_u32()?)
vec.push(avp.encode_tagged_u32()?)
}
Ok(vec)
}
@@ -256,7 +256,7 @@ pub fn delete_tunnel_client_auth_id(packet: &mut Packet) {
packet.delete(TUNNEL_CLIENT_AUTH_ID_TYPE);
}
pub fn add_tunnel_client_auth_id(packet: &mut Packet, tag: Option<&Tag>, value: &str) {
packet.add(AVP::encode_tagged_string(
packet.add(AVP::from_tagged_string(
TUNNEL_CLIENT_AUTH_ID_TYPE,
tag,
value,
@@ -267,14 +267,14 @@ pub fn lookup_tunnel_client_auth_id(
) -> Option<Result<(String, Option<Tag>), AVPError>> {
packet
.lookup(TUNNEL_CLIENT_AUTH_ID_TYPE)
.map(|v| v.decode_tagged_string())
.map(|v| v.encode_tagged_string())
}
pub fn lookup_all_tunnel_client_auth_id(
packet: &Packet,
) -> Result<Vec<(String, Option<Tag>)>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(TUNNEL_CLIENT_AUTH_ID_TYPE) {
vec.push(avp.decode_tagged_string()?)
vec.push(avp.encode_tagged_string()?)
}
Ok(vec)
}
@@ -284,7 +284,7 @@ pub fn delete_tunnel_server_auth_id(packet: &mut Packet) {
packet.delete(TUNNEL_SERVER_AUTH_ID_TYPE);
}
pub fn add_tunnel_server_auth_id(packet: &mut Packet, tag: Option<&Tag>, value: &str) {
packet.add(AVP::encode_tagged_string(
packet.add(AVP::from_tagged_string(
TUNNEL_SERVER_AUTH_ID_TYPE,
tag,
value,
@@ -295,14 +295,14 @@ pub fn lookup_tunnel_server_auth_id(
) -> Option<Result<(String, Option<Tag>), AVPError>> {
packet
.lookup(TUNNEL_SERVER_AUTH_ID_TYPE)
.map(|v| v.decode_tagged_string())
.map(|v| v.encode_tagged_string())
}
pub fn lookup_all_tunnel_server_auth_id(
packet: &Packet,
) -> Result<Vec<(String, Option<Tag>)>, AVPError> {
let mut vec = Vec::new();
for avp in packet.lookup_all(TUNNEL_SERVER_AUTH_ID_TYPE) {
vec.push(avp.decode_tagged_string()?)
vec.push(avp.encode_tagged_string()?)
}
Ok(vec)
}