Skip to content

Commit 2cb4a13

Browse files
authored
Merge pull request #12 from lwlee2608/feature/add-dict-ref-to-avp
Add Arc<Dictionary> in Avp struct
2 parents f3c130e + 437ca92 commit 2cb4a13

File tree

8 files changed

+221
-204
lines changed

8 files changed

+221
-204
lines changed

benches/diameter_bench.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#![feature(test)]
22

33
extern crate test;
4-
use diameter::avp;
54
use diameter::avp::flags::M;
6-
use diameter::avp::Avp;
75
use diameter::avp::Enumerated;
86
use diameter::avp::Grouped;
97
use diameter::avp::Identity;
@@ -135,26 +133,22 @@ fn cca_message(dict: Arc<Dictionary>) -> DiameterMessage {
135133
flags::REQUEST | flags::PROXYABLE,
136134
1123158610,
137135
3102381851,
138-
dict,
136+
Arc::clone(&dict),
139137
);
140138

141-
message.add_avp(avp!(264, None, M, Identity::new("host.example.com")));
142-
message.add_avp(avp!(296, None, M, Identity::new("realm.example.com")));
143-
message.add_avp(avp!(263, None, M, UTF8String::new("ses;12345888")));
144-
message.add_avp(avp!(268, None, M, Unsigned32::new(2001)));
145-
message.add_avp(avp!(416, None, M, Enumerated::new(1)));
146-
message.add_avp(avp!(415, None, M, Unsigned32::new(1000)));
147-
message.add_avp(avp!(
148-
873,
149-
Some(10415),
150-
M,
151-
Grouped::new(vec![avp!(
152-
874,
153-
Some(10415),
154-
M,
155-
Grouped::new(vec![avp!(30, None, M, UTF8String::new("10999"))]),
156-
)]),
157-
));
139+
message.add_avp(264, None, M, Identity::new("host.example.com").into());
140+
message.add_avp(296, None, M, Identity::new("realm.example.com").into());
141+
message.add_avp(263, None, M, UTF8String::new("ses;12345888").into());
142+
message.add_avp(268, None, M, Unsigned32::new(2001).into());
143+
message.add_avp(416, None, M, Enumerated::new(1).into());
144+
message.add_avp(415, None, M, Unsigned32::new(1000).into());
145+
146+
let mut ps_information = Grouped::new(vec![], Arc::clone(&dict));
147+
ps_information.add_avp(30, None, M, UTF8String::new("10999").into());
148+
let mut service_information = Grouped::new(vec![], Arc::clone(&dict));
149+
service_information.add_avp(874, Some(10415), M, ps_information.into());
150+
151+
message.add_avp(873, Some(10415), M, service_information.into());
158152
message
159153
}
160154

examples/client.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use diameter::avp;
21
use diameter::avp::address::Value::IPv4;
32
use diameter::avp::flags::M;
43
use diameter::avp::Address;
5-
use diameter::avp::Avp;
64
use diameter::avp::Enumerated;
75
use diameter::avp::Identity;
86
use diameter::avp::UTF8String;
@@ -56,16 +54,16 @@ async fn send_cer(client: &mut DiameterClient, dict: Arc<Dictionary>) {
5654
seq_num,
5755
dict,
5856
);
59-
cer.add_avp(avp!(264, None, M, Identity::new("host.example.com")));
60-
cer.add_avp(avp!(296, None, M, Identity::new("realm.example.com")));
61-
cer.add_avp(avp!(
57+
cer.add_avp(264, None, M, Identity::new("host.example.com").into());
58+
cer.add_avp(296, None, M, Identity::new("realm.example.com").into());
59+
cer.add_avp(
6260
257,
6361
None,
6462
M,
65-
Address::new(IPv4(Ipv4Addr::new(127, 0, 0, 1)))
66-
));
67-
cer.add_avp(avp!(266, None, M, Unsigned32::new(35838)));
68-
cer.add_avp(avp!(269, None, M, UTF8String::new("diameter-rs")));
63+
Address::new(IPv4(Ipv4Addr::new(127, 0, 0, 1))).into(),
64+
);
65+
cer.add_avp(266, None, M, Unsigned32::new(35838).into());
66+
cer.add_avp(269, None, M, UTF8String::new("diameter-rs").into());
6967

7068
let resp = client.send_message(cer).await.unwrap();
7169
let cea = resp.await.unwrap();
@@ -82,17 +80,17 @@ async fn send_ccr(client: &mut DiameterClient, dict: Arc<Dictionary>) {
8280
seq_num,
8381
dict,
8482
);
85-
ccr.add_avp(avp!(264, None, M, Identity::new("host.example.com")));
86-
ccr.add_avp(avp!(296, None, M, Identity::new("realm.example.com")));
87-
ccr.add_avp(avp!(263, None, M, UTF8String::new("ses;12345888")));
88-
ccr.add_avp(avp!(416, None, M, Enumerated::new(1)));
89-
ccr.add_avp(avp!(415, None, M, Unsigned32::new(1000)));
90-
ccr.add_avp(avp!(
83+
ccr.add_avp(264, None, M, Identity::new("host.example.com").into());
84+
ccr.add_avp(296, None, M, Identity::new("realm.example.com").into());
85+
ccr.add_avp(263, None, M, UTF8String::new("ses;12345888").into());
86+
ccr.add_avp(416, None, M, Enumerated::new(1).into());
87+
ccr.add_avp(415, None, M, Unsigned32::new(1000).into());
88+
ccr.add_avp(
9189
1228,
9290
Some(10415),
9391
M,
94-
Address::new(IPv4(Ipv4Addr::new(127, 0, 0, 1)))
95-
));
92+
Address::new(IPv4(Ipv4Addr::new(127, 0, 0, 1))).into(),
93+
);
9694

9795
let resp = client.send_message(ccr).await.unwrap();
9896
let cca = resp.await.unwrap();

examples/load_generator.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use chrono::Local;
2-
use diameter::avp;
32
use diameter::avp::address::Value::IPv4;
43
use diameter::avp::flags::M;
54
use diameter::avp::Address;
6-
use diameter::avp::Avp;
75
use diameter::avp::Enumerated;
86
use diameter::avp::Identity;
97
use diameter::avp::UTF8String;
@@ -107,16 +105,16 @@ async fn send_cer(client: &mut DiameterClient, dict: Arc<Dictionary>) {
107105
seq_num,
108106
dict,
109107
);
110-
cer.add_avp(avp!(264, None, M, Identity::new("host.example.com")));
111-
cer.add_avp(avp!(296, None, M, Identity::new("realm.example.com")));
112-
cer.add_avp(avp!(
108+
cer.add_avp(264, None, M, Identity::new("host.example.com").into());
109+
cer.add_avp(296, None, M, Identity::new("realm.example.com").into());
110+
cer.add_avp(
113111
257,
114112
None,
115113
M,
116-
Address::new(IPv4(Ipv4Addr::new(127, 0, 0, 1)))
117-
));
118-
cer.add_avp(avp!(266, None, M, Unsigned32::new(35838)));
119-
cer.add_avp(avp!(269, None, M, UTF8String::new("diameter-rs")));
114+
Address::new(IPv4(Ipv4Addr::new(127, 0, 0, 1))).into(),
115+
);
116+
cer.add_avp(266, None, M, Unsigned32::new(35838).into());
117+
cer.add_avp(269, None, M, UTF8String::new("diameter-rs").into());
120118

121119
let response = client.send_message(cer).await.unwrap();
122120
let _cea = response.await.unwrap();
@@ -136,17 +134,17 @@ async fn send_ccr_i(
136134
seq_num,
137135
dict,
138136
);
139-
ccr.add_avp(avp!(264, None, M, Identity::new("host.example.com")));
140-
ccr.add_avp(avp!(296, None, M, Identity::new("realm.example.com")));
141-
ccr.add_avp(avp!(263, None, M, UTF8String::new(&session_id)));
142-
ccr.add_avp(avp!(416, None, M, Enumerated::new(1)));
143-
ccr.add_avp(avp!(415, None, M, Unsigned32::new(1000)));
144-
ccr.add_avp(avp!(
137+
ccr.add_avp(264, None, M, Identity::new("host.example.com").into());
138+
ccr.add_avp(296, None, M, Identity::new("realm.example.com").into());
139+
ccr.add_avp(263, None, M, UTF8String::new(&session_id).into());
140+
ccr.add_avp(416, None, M, Enumerated::new(1).into());
141+
ccr.add_avp(415, None, M, Unsigned32::new(1000).into());
142+
ccr.add_avp(
145143
1228,
146144
Some(10415),
147145
M,
148-
Address::new(IPv4(Ipv4Addr::new(127, 0, 0, 1)))
149-
));
146+
Address::new(IPv4(Ipv4Addr::new(127, 0, 0, 1))).into(),
147+
);
150148

151149
let response = client.send_message(ccr).await.unwrap();
152150
log::info!(
@@ -184,17 +182,17 @@ async fn send_ccr_t(
184182
seq_num,
185183
dict,
186184
);
187-
ccr.add_avp(avp!(264, None, M, Identity::new("host.example.com")));
188-
ccr.add_avp(avp!(296, None, M, Identity::new("realm.example.com")));
189-
ccr.add_avp(avp!(263, None, M, UTF8String::new(session_id)));
190-
ccr.add_avp(avp!(416, None, M, Enumerated::new(3)));
191-
ccr.add_avp(avp!(415, None, M, Unsigned32::new(1000)));
192-
ccr.add_avp(avp!(
185+
ccr.add_avp(264, None, M, Identity::new("host.example.com").into());
186+
ccr.add_avp(296, None, M, Identity::new("realm.example.com").into());
187+
ccr.add_avp(263, None, M, UTF8String::new(session_id).into());
188+
ccr.add_avp(416, None, M, Enumerated::new(3).into());
189+
ccr.add_avp(415, None, M, Unsigned32::new(1000).into());
190+
ccr.add_avp(
193191
1228,
194192
Some(10415),
195193
M,
196-
Address::new(IPv4(Ipv4Addr::new(127, 0, 0, 1)))
197-
));
194+
Address::new(IPv4(Ipv4Addr::new(127, 0, 0, 1))).into(),
195+
);
198196

199197
let response = client.send_message(ccr).await.unwrap();
200198
log::info!(

examples/server.rs

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use chrono::Local;
2-
use diameter::avp;
32
use diameter::avp::flags::M;
4-
use diameter::avp::Avp;
53
use diameter::avp::Enumerated;
64
use diameter::avp::Grouped;
75
use diameter::avp::Identity;
@@ -70,48 +68,37 @@ async fn main() {
7068
req.get_flags() ^ flags::REQUEST,
7169
req.get_hop_by_hop_id(),
7270
req.get_end_to_end_id(),
73-
dict_ref2,
71+
Arc::clone(&dict_ref2),
7472
);
7573

7674
match req.get_command_code() {
7775
CommandCode::CapabilitiesExchange => {
78-
res.add_avp(avp!(264, None, M, Identity::new("host.example.com")));
79-
res.add_avp(avp!(296, None, M, Identity::new("realm.example.com")));
80-
res.add_avp(avp!(266, None, M, Unsigned32::new(35838)));
81-
res.add_avp(avp!(269, None, M, UTF8String::new("diameter-rs")));
82-
res.add_avp(avp!(258, None, M, Unsigned32::new(4)));
83-
res.add_avp(avp!(268, None, M, Unsigned32::new(2001)));
76+
res.add_avp(264, None, M, Identity::new("host.example.com").into());
77+
res.add_avp(296, None, M, Identity::new("realm.example.com").into());
78+
res.add_avp(266, None, M, Unsigned32::new(35838).into());
79+
res.add_avp(269, None, M, UTF8String::new("diameter-rs").into());
80+
res.add_avp(258, None, M, Unsigned32::new(4).into());
81+
res.add_avp(268, None, M, Unsigned32::new(2001).into());
8482
}
8583
_ => {
86-
res.add_avp(avp!(264, None, M, Identity::new("host.example.com")));
87-
res.add_avp(avp!(296, None, M, Identity::new("realm.example.com")));
88-
res.add_avp(avp!(263, None, M, UTF8String::new("ses;123458890")));
89-
res.add_avp(avp!(416, None, M, Enumerated::new(1)));
90-
res.add_avp(avp!(415, None, M, Unsigned32::new(1000)));
91-
res.add_avp(avp!(268, None, M, Unsigned32::new(2001)));
92-
res.add_avp(avp!(
93-
456,
94-
None,
95-
M,
96-
Grouped::new(vec![
97-
avp!(439, None, M, Unsigned32::new(7786)),
98-
avp!(432, None, M, Unsigned32::new(7786)),
99-
avp!(268, None, M, Unsigned32::new(2001)),
100-
])
101-
));
102-
res.add_avp(avp!(
103-
873,
104-
Some(10415),
105-
M,
106-
Grouped::new(vec![avp!(
107-
874,
108-
Some(10415),
109-
M,
110-
Grouped::new(
111-
vec![avp!(30, None, M, UTF8String::new("10099")),]
112-
)
113-
),])
114-
));
84+
res.add_avp(264, None, M, Identity::new("host.example.com").into());
85+
res.add_avp(296, None, M, Identity::new("realm.example.com").into());
86+
res.add_avp(263, None, M, UTF8String::new("ses;123458890").into());
87+
res.add_avp(416, None, M, Enumerated::new(1).into());
88+
res.add_avp(415, None, M, Unsigned32::new(1000).into());
89+
res.add_avp(268, None, M, Unsigned32::new(2001).into());
90+
91+
let mut mscc = Grouped::new(vec![], Arc::clone(&dict_ref2));
92+
mscc.add_avp(439, None, M, Unsigned32::new(7786).into());
93+
mscc.add_avp(432, None, M, Unsigned32::new(7786).into());
94+
mscc.add_avp(268, None, M, Unsigned32::new(2001).into());
95+
res.add_avp(456, None, M, mscc.into());
96+
97+
let mut ps_info = Grouped::new(vec![], Arc::clone(&dict_ref2));
98+
ps_info.add_avp(30, None, M, UTF8String::new("10999").into());
99+
let mut service_info = Grouped::new(vec![], Arc::clone(&dict_ref2));
100+
service_info.add_avp(874, Some(10415), M, ps_info.into());
101+
res.add_avp(873, Some(10415), M, service_info.into());
115102
}
116103
}
117104

0 commit comments

Comments
 (0)