| Crates.io | diameter-interface |
| lib.rs | diameter-interface |
| version | 0.1.3 |
| created_at | 2025-07-12 19:18:04.242874+00 |
| updated_at | 2025-07-12 21:56:43.407032+00 |
| description | Rust Implementation of the Diameter Protocol. |
| homepage | |
| repository | https://github.com/AhmedMehanna1/diameter-protocol |
| max_upload_size | |
| id | 1749605 |
| size | 114,313 |
Rust Implementation of the Diameter Protocol.
This library provides a Rust implementation of the Diameter protocol, as defined by RFC 6733. Currently, the library supports only Diameter Client without TLS.
Add this crate to your Rust project by adding the following to your Cargo.toml:
[dependencies]
diameter-interface = "^0.1"
Or use cargo command
cargo add diameter-interface
Below is an example of creating a Diameter client that sends a Credit-Control-Request (CCR) message to a server and waits for a response.
use diameter_interface::errors::DiameterResult;
use diameter_interface::modeling::avp::avp::{Avp, AvpValue};
use diameter_interface::modeling::avp::avp::AvpFlags::M;
use diameter_interface::modeling::avp::enumerated::Enumerated;
use diameter_interface::modeling::avp::unsigned32::Unsigned32;
use diameter_interface::modeling::avp::utf8_string::{Identity, UTF8String};
use diameter_interface::modeling::diameter::DiameterMessage;
use diameter_interface::modeling::message::application_id::ApplicationId;
use diameter_interface::modeling::message::command_code::CommandCode;
use diameter_interface::modeling::message::command_flags::CommandFlag;
use diameter_interface::modeling::message::dictionary;
use diameter_interface::modeling::message::dictionary::Dictionary;
use diameter_interface::transport::client::DiameterClient;
use std::sync::Arc;
use diameter_interface::errors::Error::ClientError;
fn main() -> DiameterResult<()> {
let dict = Arc::new(Dictionary::new(&[&dictionary::DEFAULT_DICT_XML]));
let mut ccr: DiameterMessage = DiameterMessage::new(
CommandFlag::Request,
CommandCode::CreditControl,
ApplicationId::Gx,
1123158611,
3102381851,
);
ccr.add(Avp::new(263, M, None, UTF8String::from_str("a")));
ccr.add_avp(264, M, None, Identity::from_str("host.example.com"));
ccr.add(Avp::new(
296,
M,
None,
Identity::from_str("realm.example.com"),
));
ccr.add(Avp::new(263, M, None, UTF8String::from_str("ses;12345888")));
ccr.add(Avp::new(416, M, None, Enumerated::new(1)));
ccr.add(Avp::new(415, M, None, Unsigned32::new(1000)));
ccr.add(Avp::new(
264,
M,
None,
Identity::from_str("host.example.com"),
));
ccr.add(Avp::new(
296,
M,
None,
Identity::from_str("realm.example.com"),
));
ccr.add(Avp::new(416, M, None, Enumerated::new(1)));
ccr.add(Avp::new(415, M, None, Unsigned32::new(1000)));
let mut client = DiameterClient::new("127.0.0.1:3868");
client.connect()?;
let cca: DiameterMessage = client.send_message(&mut ccr, dict)?;
let avp = match cca.get_avp(268) {
Some(avp) => {
match avp.get_value() {
AvpValue::Unsigned32(value) => {
if *value.value() != 2001 {
println!("invalid response status");
} else {
println!("success response status {}", value.value());
}
},
_ => {
}
}
},
None => Err(ClientError("avp 268 not found"))?
};
client.close()?;
println!("{:?}", cca);
Ok(())
}