- 1.Create and send a requestMessage: http://blog.csdn.net/minico/article/details/5723503
1) When a request message is generated, the following rules must be observed:
- Set the command code of the header;
- Set the 'R' bit in the header;
- Set the end-to-end of the header to a unique local value;
- Origin-host and origin-realm avps must be carried to identify the source address of the message;
- Destination-host and destination-realm avps should be set according to the following rules;
A) messages that cannot be sent by the proxy must not contain destination-realm and destination-host avps;
B) if the message is sent to a realm instead of a specific host, it will only carry destination-realm AVP;
C) if the message is sent to a specific host, it must carry destination-realm and destination-host avps at the same time;
- If a message may be forwarded, one of the following AVP must be included in the message: An Acct-Application-id avp, an auth-Application-id avp or a vendor-specific-Application-id avp;
2) When sending a request message, whether sent by the source host or forwarded by the agent, you must perform the following operations:
A) set the hop-by-hop in the header to a unique local value;
B) put the message into the pending request message queue;
- 2.Receive requestMessage:
1) when a diameter node receives a request message, there are four possible processing methods:
A) if the following conditions are met, the local processing will be performed:
- Destination-host AVP contains the ID of the local host, or
- Destination-host AVP does not exist. Destination-realm AVP is configured as local processing after being queried in the routing table, or
- Destination-host and destination-realm do not exist;
B) If destination-host AVP exists in the local peer table, execute request forwarding:
C) Request Forwarding is not performed without local processing, search for the realm routing table based on destination-realm AVP, Auth-Application-ID, ACCT-Application-ID, or vendor-specific-Application-ID, and execute Request Routing;
D) The error diameter_unable_to_deliver is returned;
Note:Request forwarding and request routing are distinguished here. The "forwarding" mentioned elsewhere in this article generally refers to the situation where messages are not processed locally;
2) When a request message is relay or proxy, relay agent and proxy agent need to do the following:
A) insert route-record AVP into the forwarded request message, which contains the host ID for sending the request message;
B) Save the protocol, IP address, port, and hop-by-hop identifiers related to the request message; the information is saved to receive the answer message corresponding to the reqeuest message, and then the answer message can be correctly forwarded;
- 3.CreateAnswer message:
After a request message is locally processed, an answer message must be created and sent according to the following rules:
- Copy hop-by-hop from the request message and fill in the answer message;
- Use the local host ID as the origin-host AVP;
- Destination-host and destination-realm avps cannot appear in answer messages;
- Add result-code AVP to indicate whether the operation is successful or not.
- If the reqeust message contains the session-ID, the answer message should also contain this value;
- Any proxy-Info avps in the request message should be copied to the answer message intact;
- The 'P' bit must be consistent with the request message;
- End-to-end must be consistent with the request message;
- YesAnswer message:
To receive an answer message, perform the following operations:
- Check its hop-by-hop, find the consistent reqeust message from the pending request queue, and delete the reqeust message from the pending request queue;
- If an answer message is received by the agent, the agent must replace hop-by-hop with the hop-by-hop in the reqeust saved earlier, and then forward the answer message;
The diameter node abc.example.com sends a request message to xyz.example.net through the relay agent and receives the answer message. This figure mainly describes the functions of the two identifiers hop-by-hop and end-to-end:
Http://hi.csdn.net/attachment/201007/10/0_1278740717r5ai.gif