blob: 3923d37b690c2654700c3932febeaed2edd28e7f [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
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080026#include <boost/cstdint.hpp>
27
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080028namespace ns3
29{
30
31namespace Sync
32{
33
34/**
35 * @brief Sequence number abstraction
36 *
37 *
38 */
39struct SeqNo
40{
41public:
42 /**
43 * @brief Constructor with just sequence number. Session assumed to be zero
44 * @param seq Sequence number
45 */
46 SeqNo (uint32_t seq)
47 : m_session (0)
48 , m_seq (seq)
49 { }
50
51 /**
52 * @brief Constructor with session and sequence id
53 * @param session Session ID
54 * @param seq Sequence number
55 */
56 SeqNo (uint32_t session, uint32_t seq)
57 : m_session (session)
58 , m_seq (seq)
59 { }
60
61 /**
62 * @brief Session ID (e.g., after crash, application will choose new session ID.
63 *
64 * Note that session IDs for the same name should always increase. So, the good choice
65 * for the session ID is client's timestamp
66 */
67 uint32_t m_session;
68
69 /**
70 * @brief Sequence number
71 *
72 * Sequence number for a session always starts with 0 and goes to max value.
73 *
74 * For now, wrapping sequence number after max to zero is not supported
75 */
76 uint32_t m_seq;
77
78 /**
79 * @brief Compare if one sequence number is lower
80 * @param seq Another sequence number to compare with
81 *
82 * tuple (session1, seq1) is less than (session2, seq2) in two cases:
83 * 1. session1 < session2
84 * 2. session1 == session2 and seq1 < seq2
85 */
86 bool
87 operator < (const SeqNo &seq) const
88 {
89 return m_session < seq.m_session || (m_session == seq.m_session && m_seq < seq.m_seq);
90 }
91
92 /**
93 * @brief Compare if two sequence numbers are equal
94 * @param seq Another sequence number to compare with
95 */
96 bool
97 operator == (const SeqNo &seq) const
98 {
99 return m_session == seq.m_session && m_seq == seq.m_seq;
100 }
101};
102
103} // Sync
104
105} // ns3
106
107#endif // SYNC_SEQ_NO_H