blob: 1461acb8240bb57c570f9f77d914063c5b3522d7 [file] [log] [blame]
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
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 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
19 * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
20 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
23#ifndef SYNC_SEQ_NO_H
24#define SYNC_SEQ_NO_H
25
26namespace ns3
27{
28
29namespace Sync
30{
31
32/**
33 * @brief Sequence number abstraction
34 *
35 *
36 */
37struct SeqNo
38{
39public:
40 /**
41 * @brief Constructor with just sequence number. Session assumed to be zero
42 * @param seq Sequence number
43 */
44 SeqNo (uint32_t seq)
45 : m_session (0)
46 , m_seq (seq)
47 { }
48
49 /**
50 * @brief Constructor with session and sequence id
51 * @param session Session ID
52 * @param seq Sequence number
53 */
54 SeqNo (uint32_t session, uint32_t seq)
55 : m_session (session)
56 , m_seq (seq)
57 { }
58
59 /**
60 * @brief Session ID (e.g., after crash, application will choose new session ID.
61 *
62 * Note that session IDs for the same name should always increase. So, the good choice
63 * for the session ID is client's timestamp
64 */
65 uint32_t m_session;
66
67 /**
68 * @brief Sequence number
69 *
70 * Sequence number for a session always starts with 0 and goes to max value.
71 *
72 * For now, wrapping sequence number after max to zero is not supported
73 */
74 uint32_t m_seq;
75
76 /**
77 * @brief Compare if one sequence number is lower
78 * @param seq Another sequence number to compare with
79 *
80 * tuple (session1, seq1) is less than (session2, seq2) in two cases:
81 * 1. session1 < session2
82 * 2. session1 == session2 and seq1 < seq2
83 */
84 bool
85 operator < (const SeqNo &seq) const
86 {
87 return m_session < seq.m_session || (m_session == seq.m_session && m_seq < seq.m_seq);
88 }
89
90 /**
91 * @brief Compare if two sequence numbers are equal
92 * @param seq Another sequence number to compare with
93 */
94 bool
95 operator == (const SeqNo &seq) const
96 {
97 return m_session == seq.m_session && m_seq == seq.m_seq;
98 }
99};
100
101} // Sync
102
103} // ns3
104
105#endif // SYNC_SEQ_NO_H