Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | |
2 /* | |
3 * Copyright (c) 2009 University of Pennsylvania | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License version 2 as | |
7 * published by the Free Software Foundation; | |
8 * | |
9 * This program is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with this program; if not, write to the Free Software | |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 */ | |
18 | |
19 #ifndef CHORD_MESSAGE_H | |
20 #define CHORD_MESSAGE_H | |
21 | |
22 #include <vector> | |
23 #include "ns3/header.h" | |
24 #include "ns3/ipv4-address.h" | |
25 #include "ns3/nstime.h" | |
26 #include "ns3/assert.h" | |
27 #include "chord-identifier.h" | |
28 #include "chord-node.h" | |
29 | |
30 namespace ns3 { | |
31 | |
32 /**·· | |
33 * \ingroup chordipv4 | |
34 * \class ChordMessage | |
35 * \brief Chord Protocol Messages | |
36 */ | |
37 class ChordMessage : public Header | |
38 { | |
39 public: | |
40 enum MessageType { | |
41 JOIN_REQ = 1, | |
42 JOIN_RSP = 2, | |
43 STABILIZE_REQ = 3, | |
44 STABILIZE_RSP = 4, | |
45 FINGER_REQ = 5, | |
46 FINGER_RSP = 6, | |
47 HEARTBEAT_REQ = 7, | |
48 HEARTBEAT_RSP = 8, | |
49 LOOKUP_REQ = 9, | |
50 LOOKUP_RSP = 10, | |
51 LEAVE_REQ = 11, | |
52 LEAVE_RSP = 12, | |
53 TRACE_RING = 20, | |
54 }; | |
55 | |
56 ChordMessage (); | |
57 virtual ~ChordMessage (); | |
58 | |
59 /** | |
60 * \brief Sets message type | |
61 * \param messageType message type | |
62 */ | |
63 void SetMessageType (MessageType messageType) | |
Mathieu Lacage
2010/01/13 12:51:12
no code in headers unless for performance reasons
taher007saeed
2010/01/24 20:47:01
Done.
| |
64 { | |
65 m_messageType = messageType; | |
66 } | |
67 /** | |
68 * \brief Sets transaction Id | |
69 * \param transactionId transaction Id of request | |
70 */ | |
71 | |
72 void SetTransactionId (uint32_t transactionId) | |
73 { | |
74 m_transactionId = transactionId; | |
75 } | |
76 /** | |
77 * \brief Sets TTL | |
78 * \param ttl time to live before request is dropped | |
79 * Coming Soon! | |
80 */ | |
81 void SetTTL(uint8_t ttl) | |
82 { | |
83 m_ttl = ttl; | |
84 }· | |
85 /** | |
86 * \returns message type | |
87 */ | |
88 | |
89 MessageType GetMessageType () const | |
90 { | |
91 return m_messageType; | |
92 } | |
93 | |
94 /** | |
95 * \returns transaction Id | |
96 */ | |
97 uint32_t GetTransactionId (void) | |
98 { | |
99 return m_transactionId; | |
100 } | |
101 ···· | |
102 /** | |
103 * \brief Sets requestor node in message | |
104 * \param chordNode Ptr of requesting ChordNode | |
105 */ | |
106 void SetRequestorNode (Ptr<ChordNode> chordNode) | |
107 { | |
108 m_chordNode = chordNode; | |
109 } | |
110 /** | |
111 * \returns Ptr to requestor ChordNode | |
112 */ | |
113 Ptr<ChordNode> GetRequestorNode () | |
114 { | |
115 return m_chordNode; | |
116 } | |
117 /** | |
118 * \returns ttl of request | |
119 */ | |
120 uint8_t GetTTL() | |
121 { | |
122 return m_ttl; | |
123 }· | |
124 | |
125 private: | |
126 /** | |
127 * \cond | |
128 */ | |
129 MessageType m_messageType; | |
130 uint32_t m_transactionId; | |
131 Ptr<ChordNode> m_chordNode; | |
132 uint8_t m_ttl ; | |
133 /** | |
134 * \endcond | |
135 */ | |
136 | |
137 public: | |
138 static TypeId GetTypeId (void); | |
139 TypeId GetInstanceTypeId (void) const; | |
140 /** | |
141 * \brief Prints ChordMessage | |
142 * \param os Output Stream | |
143 */ | |
144 void Print (std::ostream &os) const; | |
145 /** | |
146 * \returns Size in bytes of packed ChordMessage | |
147 */ | |
148 uint32_t GetSerializedSize (void) const; | |
149 /** | |
150 * \brief Packs ChordMessage | |
151 * \param start Buffer::Iterator | |
152 * | |
153 * \verbatim | |
154 Packed Structure: | |
155 ····· | |
156 ChordMessage Header: | |
157 ····· | |
158 0 1 2 3 4 5 6 7 8· | |
159 +-+-+-+-+-+-+-+-+ | |
160 | messageType | | |
161 +-+-+-+-+-+-+-+-+ | |
162 | ttl | | |
163 +-+-+-+-+-+-+-+-+ | |
164 | | | |
165 | | | |
166 | transactionId | | |
167 | | | |
168 +-+-+-+-+-+-+-+-+ | |
169 | | | |
170 : requestorNode : | |
171 | | | |
172 +-+-+-+-+-+-+-+-+ | |
173 | |· | |
174 : Payload : | |
175 | | | |
176 +-+-+-+-+-+-+-+-+ | |
177 ····· | |
178 JOIN_REQ Payload: | |
179 None | |
180 ······ | |
181 JOIN_RSP Payload: | |
182 0 1 2 3 4 5 6 7 8· | |
183 +-+-+-+-+-+-+-+-+ | |
184 | | | |
185 : successorNode : | |
186 | | | |
187 +-+-+-+-+-+-+-+-+ | |
188 ······ | |
189 LEAVE_REQ Payload: | |
190 0 1 2 3 4 5 6 7 8· | |
191 +-+-+-+-+-+-+-+-+ | |
192 | | | |
193 : successorNode : | |
194 | | | |
195 +-+-+-+-+-+-+-+-+ | |
196 | | | |
197 :predecessorNode: | |
198 | | | |
199 +-+-+-+-+-+-+-+-+ | |
200 ····· | |
201 LEAVE_RSP Payload: | |
202 0 1 2 3 4 5 6 7 8· | |
203 +-+-+-+-+-+-+-+-+ | |
204 | | | |
205 : successorNode : | |
206 | | | |
207 +-+-+-+-+-+-+-+-+ | |
208 | | | |
209 :predecessorNode: | |
210 | | | |
211 +-+-+-+-+-+-+-+-+ | |
212 ······ | |
213 STABILIZE_REQ Payload: | |
214 0 1 2 3 4 5 6 7 8· | |
215 +-+-+-+-+-+-+-+-+ | |
216 | | | |
217 : successor- : | |
218 | Identifier | | |
219 +-+-+-+-+-+-+-+-+ | |
220 ······ | |
221 STABILIZE_RSP Payload: | |
222 0 1 2 3 4 5 6 7 8· | |
223 +-+-+-+-+-+-+-+-+ | |
224 | | | |
225 :predecessorNode: | |
226 | | | |
227 +-+-+-+-+-+-+-+-+ | |
228 | | | |
229 : successorNode : | |
230 | List | | |
231 +-+-+-+-+-+-+-+-+ | |
232 ······· | |
233 FINGER_REQ Payload: | |
234 0 1 2 3 4 5 6 7 8· | |
235 +-+-+-+-+-+-+-+-+ | |
236 | | | |
237 : requested- : | |
238 | Identifier | | |
239 +-+-+-+-+-+-+-+-+ | |
240 ······ | |
241 FINGER_RSP Payload: | |
242 0 1 2 3 4 5 6 7 8· | |
243 +-+-+-+-+-+-+-+-+ | |
244 | | | |
245 : requested- : | |
246 | Identifier | | |
247 +-+-+-+-+-+-+-+-+ | |
248 | | | |
249 : fingerNode : | |
250 | | | |
251 +-+-+-+-+-+-+-+-+ | |
252 ······ | |
253 HEARTBEAT_REQ Payload: | |
254 0 1 2 3 4 5 6 7 8· | |
255 +-+-+-+-+-+-+-+-+ | |
256 | | | |
257 : predecessor- : | |
258 | Identifier | | |
259 +-+-+-+-+-+-+-+-+ | |
260 ······ | |
261 HEARTBEAT_RSP Payload: | |
262 0 1 2 3 4 5 6 7 8· | |
263 +-+-+-+-+-+-+-+-+ | |
264 | | | |
265 : successorNode : | |
266 | | | |
267 +-+-+-+-+-+-+-+-+ | |
268 | | | |
269 :predecessorNode: | |
270 | List | | |
271 +-+-+-+-+-+-+-+-+ | |
272 ····· | |
273 LOOKUP_REQ Payload: | |
274 0 1 2 3 4 5 6 7 8· | |
275 +-+-+-+-+-+-+-+-+ | |
276 | | | |
277 : requestor- : | |
278 | Identifier | | |
279 +-+-+-+-+-+-+-+-+ | |
280 ····· | |
281 LOOKUP_RSP Payload: | |
282 0 1 2 3 4 5 6 7 8· | |
283 +-+-+-+-+-+-+-+-+ | |
284 | | | |
285 : resolvedNode : | |
286 | | | |
287 +-+-+-+-+-+-+-+-+ | |
288 ····· | |
289 TRACE_RING Payload: | |
290 0 1 2 3 4 5 6 7 8· | |
291 +-+-+-+-+-+-+-+-+ | |
292 | | | |
293 : successor- : | |
294 | Identifier | | |
295 +-+-+-+-+-+-+-+-+ | |
296 ······ | |
297 \endverbatim | |
298 */ | |
299 void Serialize (Buffer::Iterator start) const; | |
300 /** | |
301 * \brief Unpacks ChordMessage | |
302 * \param start Buffer::Iterator· | |
303 */ | |
304 uint32_t Deserialize (Buffer::Iterator start); | |
305 | |
306 struct JoinReq | |
307 { | |
308 void Print (std::ostream &os) const;· | |
309 uint32_t GetSerializedSize (void) const; | |
310 void Serialize (Buffer::Iterator &start) const; | |
311 uint32_t Deserialize (Buffer::Iterator &start); | |
312 }; | |
313 | |
314 struct JoinRsp | |
315 { | |
316 Ptr<ChordNode> successorNode; | |
317 void Print (std::ostream &os) const;· | |
318 uint32_t GetSerializedSize (void) const; | |
319 void Serialize (Buffer::Iterator &start) const; | |
320 uint32_t Deserialize (Buffer::Iterator &start); | |
321 }; | |
322 | |
323 struct StabilizeReq | |
324 { | |
325 Ptr<ChordIdentifier> successorIdentifier; | |
326 void Print (std::ostream &os) const;· | |
327 uint32_t GetSerializedSize (void) const; | |
328 void Serialize (Buffer::Iterator &start) const; | |
329 uint32_t Deserialize (Buffer::Iterator &start); | |
330 }; | |
331 | |
332 struct StabilizeRsp | |
333 { | |
334 Ptr<ChordNode> predecessorNode; | |
335 uint8_t successorListSize; | |
336 std::vector<Ptr<ChordNode> > successorList; | |
337 void Print (std::ostream &os) const;· | |
338 uint32_t GetSerializedSize (void) const; | |
339 void Serialize (Buffer::Iterator &start) const; | |
340 uint32_t Deserialize (Buffer::Iterator &start); | |
341 }; | |
342 | |
343 struct FingerReq | |
344 { | |
345 Ptr<ChordIdentifier> requestedIdentifier; | |
346 void Print (std::ostream &os) const;· | |
347 uint32_t GetSerializedSize (void) const; | |
348 void Serialize (Buffer::Iterator &start) const; | |
349 uint32_t Deserialize (Buffer::Iterator &start); | |
350 }; | |
351 | |
352 struct FingerRsp | |
353 { | |
354 Ptr<ChordIdentifier> requestedIdentifier; | |
355 Ptr<ChordNode> fingerNode; | |
356 void Print (std::ostream &os) const;· | |
357 uint32_t GetSerializedSize (void) const; | |
358 void Serialize (Buffer::Iterator &start) const; | |
359 uint32_t Deserialize (Buffer::Iterator &start); | |
360 }; | |
361 | |
362 struct HeartbeatReq | |
363 { | |
364 Ptr<ChordIdentifier> predecessorIdentifier; | |
365 void Print (std::ostream &os) const;· | |
366 uint32_t GetSerializedSize (void) const; | |
367 void Serialize (Buffer::Iterator &start) const; | |
368 uint32_t Deserialize (Buffer::Iterator &start); | |
369 }; | |
370 | |
371 struct HeartbeatRsp | |
372 { | |
373 Ptr<ChordNode> successorNode; | |
374 uint8_t predecessorListSize; | |
375 std::vector<Ptr<ChordNode> > predecessorList; | |
376 void Print (std::ostream &os) const;· | |
377 uint32_t GetSerializedSize (void) const; | |
378 void Serialize (Buffer::Iterator &start) const; | |
379 uint32_t Deserialize (Buffer::Iterator &start); | |
380 }; | |
381 | |
382 struct LookupReq | |
383 { | |
384 Ptr<ChordIdentifier> requestedIdentifier; | |
385 void Print (std::ostream &os) const;· | |
386 uint32_t GetSerializedSize (void) const; | |
387 void Serialize (Buffer::Iterator &start) const; | |
388 uint32_t Deserialize (Buffer::Iterator &start); | |
389 }; | |
390 | |
391 struct LookupRsp | |
392 { | |
393 Ptr<ChordNode> resolvedNode; | |
394 void Print (std::ostream &os) const;· | |
395 uint32_t GetSerializedSize (void) const; | |
396 void Serialize (Buffer::Iterator &start) const; | |
397 uint32_t Deserialize (Buffer::Iterator &start); | |
398 }; | |
399 · | |
400 struct LeaveReq | |
401 { | |
402 Ptr<ChordNode> successorNode; | |
403 Ptr<ChordNode> predecessorNode; | |
404 void Print (std::ostream &os) const;· | |
405 uint32_t GetSerializedSize (void) const; | |
406 void Serialize (Buffer::Iterator &start) const; | |
407 uint32_t Deserialize (Buffer::Iterator &start); | |
408 }; | |
409 | |
410 struct LeaveRsp | |
411 { | |
412 Ptr<ChordNode> successorNode; | |
413 Ptr<ChordNode> predecessorNode; | |
414 void Print (std::ostream &os) const; | |
415 uint32_t GetSerializedSize (void) const; | |
416 void Serialize (Buffer::Iterator &start) const; | |
417 uint32_t Deserialize (Buffer::Iterator &start); | |
418 }; | |
419 ··· | |
420 struct TraceRing | |
421 { | |
422 Ptr<ChordIdentifier> successorIdentifier; | |
423 void Print (std::ostream &os) const;· | |
424 uint32_t GetSerializedSize (void) const; | |
425 void Serialize (Buffer::Iterator &start) const; | |
426 uint32_t Deserialize (Buffer::Iterator &start); | |
427 }; | |
428 | |
429 private: | |
430 /** | |
431 * \cond | |
432 */ | |
433 struct | |
434 { | |
435 JoinReq joinReq; | |
436 JoinRsp joinRsp; | |
437 LeaveReq leaveReq; | |
438 LeaveRsp leaveRsp; | |
439 StabilizeReq stabilizeReq; | |
440 StabilizeRsp stabilizeRsp; | |
441 FingerReq fingerReq; | |
442 FingerRsp fingerRsp; | |
443 HeartbeatReq heartbeatReq; | |
444 HeartbeatRsp heartbeatRsp; | |
445 LookupReq lookupReq; | |
446 LookupRsp lookupRsp; | |
447 TraceRing traceRing; | |
448 } m_message; | |
449 /** | |
450 * \endcond | |
451 */ | |
452 public: | |
453 | |
454 /** | |
455 * \returns JoinReq structure | |
456 */···· | |
457 JoinReq& GetJoinReq () | |
Mathieu Lacage
2010/01/13 12:51:12
same comments as in DHashMessage
taher007saeed
2010/01/24 20:47:01
Done.
| |
458 { | |
459 if (m_messageType == 0) | |
460 { | |
461 m_messageType = JOIN_REQ; | |
462 } | |
463 else | |
464 { | |
465 NS_ASSERT (m_messageType == JOIN_REQ); | |
466 } | |
467 return m_message.joinReq; | |
468 }···· | |
469 | |
470 /** | |
471 * \returns JoinRsp structure | |
472 */···· | |
473 JoinRsp& GetJoinRsp () | |
474 { | |
475 if (m_messageType == 0) | |
476 { | |
477 m_messageType = JOIN_RSP; | |
478 } | |
479 else | |
480 { | |
481 NS_ASSERT (m_messageType == JOIN_RSP); | |
482 } | |
483 return m_message.joinRsp; | |
484 }···· | |
485 | |
486 /** | |
487 * \returns LeaveReq structure | |
488 */···· | |
489 LeaveReq& GetLeaveReq () | |
490 { | |
491 if (m_messageType == 0) | |
492 { | |
493 m_messageType = LEAVE_REQ; | |
494 } | |
495 else | |
496 { | |
497 NS_ASSERT (m_messageType == LEAVE_REQ); | |
498 } | |
499 return m_message.leaveReq; | |
500 }···· | |
501 | |
502 /** | |
503 * \returns LeaveRsp structure | |
504 */···· | |
505 LeaveRsp& GetLeaveRsp () | |
506 { | |
507 if (m_messageType == 0) | |
508 { | |
509 m_messageType = LEAVE_RSP; | |
510 } | |
511 else | |
512 { | |
513 NS_ASSERT (m_messageType == LEAVE_RSP); | |
514 } | |
515 return m_message.leaveRsp; | |
516 }···· | |
517 ··· | |
518 | |
519 /** | |
520 * \returns StabilizeReq structure | |
521 */···· | |
522 StabilizeReq& GetStabilizeReq () | |
523 { | |
524 if (m_messageType == 0) | |
525 { | |
526 m_messageType = STABILIZE_REQ; | |
527 } | |
528 else | |
529 { | |
530 NS_ASSERT (m_messageType == STABILIZE_REQ); | |
531 } | |
532 return m_message.stabilizeReq; | |
533 } | |
534 | |
535 /** | |
536 * \returns StabilizeRsp structure | |
537 */···· | |
538 StabilizeRsp& GetStabilizeRsp () | |
539 { | |
540 if (m_messageType == 0) | |
541 { | |
542 m_messageType = STABILIZE_RSP; | |
543 } | |
544 else | |
545 { | |
546 NS_ASSERT (m_messageType == STABILIZE_RSP); | |
547 } | |
548 return m_message.stabilizeRsp; | |
549 } | |
550 | |
551 /** | |
552 * \returns FingerReq structure | |
553 */···· | |
554 FingerReq& GetFingerReq () | |
555 { | |
556 if (m_messageType == 0) | |
557 { | |
558 m_messageType = FINGER_REQ; | |
559 } | |
560 else | |
561 { | |
562 NS_ASSERT (m_messageType == FINGER_REQ); | |
563 } | |
564 return m_message.fingerReq; | |
565 }···· | |
566 | |
567 /** | |
568 * \returns FingerRsp structure | |
569 */···· | |
570 FingerRsp& GetFingerRsp () | |
571 { | |
572 if (m_messageType == 0) | |
573 { | |
574 m_messageType = FINGER_RSP; | |
575 } | |
576 else | |
577 { | |
578 NS_ASSERT (m_messageType == FINGER_RSP); | |
579 } | |
580 return m_message.fingerRsp; | |
581 } | |
582 | |
583 /** | |
584 * \returns HeartbeatReq structure | |
585 */···· | |
586 HeartbeatReq& GetHeartbeatReq () | |
587 { | |
588 if (m_messageType == 0) | |
589 { | |
590 m_messageType = HEARTBEAT_REQ; | |
591 } | |
592 else | |
593 { | |
594 NS_ASSERT (m_messageType == HEARTBEAT_REQ); | |
595 } | |
596 return m_message.heartbeatReq; | |
597 } | |
598 | |
599 /** | |
600 * \returns HeartbeatRsp structure | |
601 */···· | |
602 HeartbeatRsp& GetHeartbeatRsp () | |
603 { | |
604 if (m_messageType == 0) | |
605 { | |
606 m_messageType = HEARTBEAT_RSP; | |
607 } | |
608 else | |
609 { | |
610 NS_ASSERT (m_messageType == HEARTBEAT_RSP); | |
611 } | |
612 return m_message.heartbeatRsp; | |
613 } | |
614 | |
615 /** | |
616 * \returns LookupReq structure | |
617 */···· | |
618 LookupReq& GetLookupReq () | |
619 { | |
620 if (m_messageType == 0) | |
621 { | |
622 m_messageType = LOOKUP_REQ; | |
623 } | |
624 else | |
625 { | |
626 NS_ASSERT (m_messageType == LOOKUP_REQ); | |
627 } | |
628 return m_message.lookupReq; | |
629 } | |
630 | |
631 /** | |
632 * \returns LookupRsp structure | |
633 */···· | |
634 LookupRsp& GetLookupRsp () | |
635 { | |
636 if (m_messageType == 0) | |
637 { | |
638 m_messageType = LOOKUP_RSP; | |
639 } | |
640 else | |
641 { | |
642 NS_ASSERT (m_messageType == LOOKUP_RSP); | |
643 } | |
644 return m_message.lookupRsp; | |
645 }· | |
646 | |
647 /** | |
648 * \returns TraceRing structure | |
649 */···· | |
650 TraceRing& GetTraceRing () | |
651 { | |
652 if (m_messageType == 0) | |
653 { | |
654 m_messageType = TRACE_RING; | |
655 } | |
656 else | |
657 { | |
658 NS_ASSERT (m_messageType == TRACE_RING); | |
659 } | |
660 return m_message.traceRing; | |
661 }···· | |
662 ·· | |
663 }; //class ChordMessage | |
664 | |
665 static inline std::ostream& operator<< (std::ostream& os, const ChordMessage & m essage) | |
666 { | |
667 message.Print (os); | |
668 return os; | |
669 } | |
670 | |
671 | |
672 } //namespace ns3 | |
673 | |
674 #endif //CHORD_MESSAGE_H | |
OLD | NEW |