diff --git a/model/quic-bbr.cc b/model/quic-bbr.cc index e673dbc..4cff7ef 100644 --- a/model/quic-bbr.cc +++ b/model/quic-bbr.cc @@ -161,7 +161,7 @@ void QuicBbr::EnterStartup () { NS_LOG_FUNCTION (this); - SetBbrState (BbrMode_t::BBR_STARTUP); + SetBbrState (Mode::STARTUP); m_pacingGain = m_highGain; m_cWndGain = m_highGain; } @@ -173,7 +173,7 @@ QuicBbr::HandleRestartFromIdle (Ptr tcb, const RateSample * rs) if (tcb->m_bytesInFlight.Get () == 0U && rs->m_isAppLimited) { m_idleRestart = true; - if (m_state.Get () == BbrMode_t::BBR_PROBE_BW) + if (m_state.Get () == Mode::PROBE_BW) { SetPacingRate (tcb, 1); } @@ -237,7 +237,7 @@ void QuicBbr::CheckCyclePhase (Ptr tcb, const struct RateSample * rs) { NS_LOG_FUNCTION (this << tcb << rs); - if (m_state.Get () == BbrMode_t::BBR_PROBE_BW && IsNextCyclePhase (tcb, rs)) + if (m_state.Get () == Mode::PROBE_BW && IsNextCyclePhase (tcb, rs)) { AdvanceCyclePhase (); } @@ -272,7 +272,7 @@ void QuicBbr::EnterDrain () { NS_LOG_FUNCTION (this); - SetBbrState (BbrMode_t::BBR_DRAIN); + SetBbrState (Mode::DRAIN); m_pacingGain = 1.0 / m_highGain; m_cWndGain = m_highGain; } @@ -281,7 +281,7 @@ void QuicBbr::EnterProbeBW () { NS_LOG_FUNCTION (this); - SetBbrState (BbrMode_t::BBR_PROBE_BW); + SetBbrState (Mode::PROBE_BW); m_pacingGain = 1; m_cWndGain = 2; m_cycleIndex = GAIN_CYCLE_LENGTH - 1 - (int) m_uv->GetValue (0, 8); @@ -292,12 +292,12 @@ void QuicBbr::CheckDrain (Ptr tcb) { NS_LOG_FUNCTION (this << tcb); - if (m_state.Get () == BbrMode_t::BBR_STARTUP && m_isPipeFilled) + if (m_state.Get () == Mode::STARTUP && m_isPipeFilled) { EnterDrain (); } - if (m_state.Get () == BbrMode_t::BBR_DRAIN && tcb->m_bytesInFlight <= InFlight (tcb, 1)) + if (m_state.Get () == Mode::DRAIN && tcb->m_bytesInFlight <= InFlight (tcb, 1)) { EnterProbeBW (); } @@ -319,7 +319,7 @@ void QuicBbr::EnterProbeRTT () { NS_LOG_FUNCTION (this); - SetBbrState (BbrMode_t::BBR_PROBE_RTT); + SetBbrState (Mode::PROBE_RTT); m_pacingGain = 1; m_cWndGain = 1; } @@ -328,7 +328,7 @@ void QuicBbr::SaveCwnd (Ptr tcb) { NS_LOG_FUNCTION (this << tcb); - if (tcb->m_congState != TcpSocketState::CA_RECOVERY && m_state.Get () != BbrMode_t::BBR_PROBE_RTT) + if (tcb->m_congState != TcpSocketState::CA_RECOVERY && m_state.Get () != Mode::PROBE_RTT) { m_priorCwnd = tcb->m_cWnd; } @@ -391,17 +391,17 @@ void QuicBbr::CheckProbeRTT (Ptr tcb) { NS_LOG_FUNCTION (this << tcb); - NS_LOG_DEBUG (Simulator::Now () << "WhichState " << WhichState (m_state.Get ()) + NS_LOG_DEBUG (Simulator::Now () << "WhichState " << m_state.Get () << " m_rtPropExpired " << m_rtPropExpired << " !m_idleRestart " << !m_idleRestart); - if (m_state.Get () != BbrMode_t::BBR_PROBE_RTT && m_rtPropExpired && !m_idleRestart) + if (m_state.Get () != Mode::PROBE_RTT && m_rtPropExpired && !m_idleRestart) { EnterProbeRTT (); SaveCwnd (tcb); m_probeRttDoneStamp = Seconds (0); } - if (m_state.Get () == BbrMode_t::BBR_PROBE_RTT) + if (m_state.Get () == Mode::PROBE_RTT) { HandleProbeRTT (tcb); } @@ -456,7 +456,7 @@ void QuicBbr::ModulateCwndForProbeRTT (Ptr tcb) { NS_LOG_FUNCTION (this << tcb); - if (m_state.Get () == BbrMode_t::BBR_PROBE_RTT) + if (m_state.Get () == Mode::PROBE_RTT) { tcb->m_cWnd = std::min (tcb->m_cWnd.Get (), m_minPipeCwnd); } @@ -548,34 +548,15 @@ QuicBbr::UpdateControlParameters (Ptr tcb, const struct RateSam SetCwnd (tcb, rs); } -std::string -QuicBbr::WhichState (BbrMode_t mode) const -{ - switch (mode) - { - case 0: - return "BBR_STARTUP"; - case 1: - return "BBR_DRAIN"; - case 2: - return "BBR_PROBE_BW"; - case 3: - return "BBR_PROBE_RTT"; - default: - NS_ABORT_MSG ("Invalid BBR state"); - return ""; - } -} - void -QuicBbr::SetBbrState (BbrMode_t mode) +QuicBbr::SetBbrState (Mode mode) { NS_LOG_FUNCTION (this << mode); - NS_LOG_DEBUG (Simulator::Now () << " Changing from " << WhichState (m_state) << " to " << WhichState (mode)); + NS_LOG_DEBUG (Simulator::Now () << " Changing from " << m_state << " to " << mode); m_state = mode; } -uint32_t +QuicBbr::Mode QuicBbr::GetBbrState () { NS_LOG_FUNCTION (this); @@ -680,7 +661,7 @@ QuicBbr::CwndEvent (Ptr tcb, if (tcbd->m_bytesInFlight.Get () == 0 && tcbd->m_appLimitedUntil > tcbd->m_delivered) { m_idleRestart = true; - if (m_state.Get () == BbrMode_t::BBR_PROBE_BW && tcbd->m_appLimitedUntil > tcbd->m_delivered) + if (m_state.Get () == Mode::PROBE_BW && tcbd->m_appLimitedUntil > tcbd->m_delivered) { SetPacingRate (tcbd, 1); } @@ -818,4 +799,22 @@ QuicBbr::Fork (void) return CopyObject (this); } +std::ostream& +operator<<(std::ostream& os, QuicBbr::Mode mode) +{ + switch (mode) + { + case QuicBbr::Mode::STARTUP: + return os << "STARTUP"; + case QuicBbr::Mode::DRAIN: + return os << "DRAIN"; + case QuicBbr::Mode::PROBE_BW: + return os << "PROBE_BW"; + case QuicBbr::Mode::PROBE_RTT: + return os << "PROBE_RTT"; + }; + NS_ABORT_MSG ("Invalid BBR state"); + return os << "UNKNOWN(" << static_cast(mode) << ")"; +} + } // namespace ns3 diff --git a/model/quic-bbr.h b/model/quic-bbr.h index e755507..d819f1a 100644 --- a/model/quic-bbr.h +++ b/model/quic-bbr.h @@ -66,13 +66,13 @@ class QuicBbr : public QuicCongestionOps QuicBbr (const QuicBbr &sock); /* BBR has the following modes for deciding how fast to send: */ - typedef enum + enum class Mode { - BBR_STARTUP, /* ramp up sending rate rapidly to fill pipe */ - BBR_DRAIN, /* drain any queue created during startup */ - BBR_PROBE_BW, /* discover, share bw: pace around estimated bw */ - BBR_PROBE_RTT, /* cut inflight to min to probe min_rtt */ - } BbrMode_t; + STARTUP, /* ramp up sending rate rapidly to fill pipe */ + DRAIN, /* drain any queue created during startup */ + PROBE_BW, /* discover, share bw: pace around estimated bw */ + PROBE_RTT, /* cut inflight to min to probe min_rtt */ + }; typedef WindowedFilter, @@ -137,12 +137,12 @@ class QuicBbr : public QuicCongestionOps friend class QuicBbrCheckGainValuesTest; /** - * \brief Advances pacing gain using cycle gain algorithm, while in BBR_PROBE_BW state + * \brief Advances pacing gain using cycle gain algorithm, while in Mode::PROBE_BW state */ void AdvanceCyclePhase (); /** - * \brief Checks whether to advance pacing gain in BBR_PROBE_BW state, + * \brief Checks whether to advance pacing gain in Mode::PROBE_BW state, * and if allowed calls AdvanceCyclePhase () * \param tcb the socket state. * \param rs rate sample @@ -150,7 +150,7 @@ class QuicBbr : public QuicCongestionOps void CheckCyclePhase (Ptr tcb, const struct RateSample * rs); /** - * \brief Checks whether its time to enter BBR_DRAIN or BBR_PROBE_BW state + * \brief Checks whether its time to enter Mode::DRAIN or Mode::PROBE_BW state * \param tcb the socket state. */ void CheckDrain (Ptr tcb); @@ -168,27 +168,27 @@ class QuicBbr : public QuicCongestionOps void CheckProbeRTT (Ptr tcb); /** - * \brief Updates variables specific to BBR_DRAIN state + * \brief Updates variables specific to Mode::DRAIN state */ void EnterDrain (); /** - * \brief Updates variables specific to BBR_PROBE_BW state + * \brief Updates variables specific to Mode::PROBE_BW state */ void EnterProbeBW (); /** - * \brief Updates variables specific to BBR_PROBE_RTT state + * \brief Updates variables specific to Mode::PROBE_RTT state */ void EnterProbeRTT (); /** - * \brief Updates variables specific to BBR_STARTUP state + * \brief Updates variables specific to Mode::STARTUP state */ void EnterStartup (); /** - * \brief Called on exiting from BBR_PROBE_RTT state, it eithers invoke EnterProbeBW () or EnterStartup () + * \brief Called on exiting from Mode::PROBE_RTT state, it eithers invoke EnterProbeBW () or EnterStartup () */ void ExitProbeRTT (); @@ -196,7 +196,7 @@ class QuicBbr : public QuicCongestionOps * \brief Gets BBR state. * \return returns BBR state. */ - uint32_t GetBbrState (); + Mode GetBbrState(); /** * \brief Gets current pacing gain. @@ -211,7 +211,7 @@ class QuicBbr : public QuicCongestionOps double GetCwndGain (); /** - * \brief Handles the steps for BBR_PROBE_RTT state. + * \brief Handles the steps for Mode::PROBE_RTT state. * \param tcb the socket state. */ void HandleProbeRTT (Ptr tcb); @@ -247,7 +247,7 @@ class QuicBbr : public QuicCongestionOps void InitRoundCounting (); /** - * \brief Checks whether to move to next value of pacing gain while in BBR_PROBE_BW. + * \brief Checks whether to move to next value of pacing gain while in Mode::PROBE_BW. * \param tcb the socket state. * \param rs rate sample * \returns true if want to move to next value otherwise false. @@ -255,7 +255,7 @@ class QuicBbr : public QuicCongestionOps bool IsNextCyclePhase (Ptr tcb, const struct RateSample * rs); /** - * \brief Modulates congestion window in BBR_PROBE_RTT. + * \brief Modulates congestion window in Mode::PROBE_RTT. * \param tcb the socket state */ void ModulateCwndForProbeRTT (Ptr tcb); @@ -344,16 +344,16 @@ class QuicBbr : public QuicCongestionOps * \brief Sets BBR state. * \param state BBR state. */ - void SetBbrState (BbrMode_t state); + void SetBbrState (Mode state); /** * \brief Maps mode into string. * \return string translation of mode value. */ - std::string WhichState (BbrMode_t state) const; + std::string WhichState (Mode state) const; private: - TracedValue m_state {BbrMode_t::BBR_STARTUP}; //!< Current state of BBR state machine + TracedValue m_state {Mode::STARTUP}; //!< Current state of BBR state machine MaxBandwidthFilter_t m_maxBwFilter; //!< Maximum bandwidth filter uint32_t m_bandwidthWindowLength {0}; //!< A constant specifying the length of the BBR.BtlBw max filter window, default 10 packet-timed round trips. double m_pacingGain {0}; //!< The dynamic pacing gain factor @@ -366,8 +366,8 @@ class QuicBbr : public QuicCongestionOps uint32_t m_nextRoundDelivered {0}; //!< Denotes the end of a packet-timed round trip Time m_probeRttDuration {MilliSeconds (200)};//!< A constant specifying the minimum duration for which ProbeRTT state, default 200 millisecs Time m_probeRtPropStamp {Seconds (0)}; //!< The wall clock time at which the current BBR.RTProp sample was obtained. - Time m_probeRttDoneStamp {Seconds (0)}; //!< Time to exit from BBR_PROBE_RTT state - bool m_probeRttRoundDone {false}; //!< True when it is time to exit BBR_PROBE_RTT + Time m_probeRttDoneStamp {Seconds (0)}; //!< Time to exit from Mode::PROBE_RTT state + bool m_probeRttRoundDone {false}; //!< True when it is time to exit Mode::PROBE_RTT bool m_packetConservation {false}; //!< uint32_t m_priorCwnd {0}; //!< The last-known good congestion window bool m_idleRestart {false}; //!< When restarting from idle, set it true @@ -392,7 +392,9 @@ class QuicBbr : public QuicCongestionOps * \param [in] oldValue original value of the traced variable * \param [in] newValue new value of the traced variable */ -typedef void (*BbrStatesTracedValueCallback) (const QuicBbr::BbrMode_t oldValue, - const QuicBbr::BbrMode_t newValue); +typedef void (*BbrStatesTracedValueCallback) (const QuicBbr::Mode oldValue, + const QuicBbr::Mode newValue); + +std::ostream& operator<<(std::ostream& os, QuicBbr::Mode mode); } // namespace ns3 diff --git a/model/quic-header.cc b/model/quic-header.cc index 42b7d97..2619df0 100644 --- a/model/quic-header.cc +++ b/model/quic-header.cc @@ -36,9 +36,9 @@ NS_LOG_COMPONENT_DEFINE ("QuicHeader"); NS_OBJECT_ENSURE_REGISTERED (QuicHeader); QuicHeader::QuicHeader () - : m_form (SHORT), + : m_form (Format::SHORT), m_c (false), - m_k (PHASE_ZERO), + m_k (KeyPhase::ZERO), m_type (0), m_connectionId (0), m_packetNumber (0), @@ -101,7 +101,7 @@ QuicHeader::GetInstanceTypeId (void) const uint32_t QuicHeader::GetSerializedSize (void) const { - NS_ASSERT (m_type != NONE or m_form == SHORT); + NS_ASSERT (m_type != NONE or m_form == Format::SHORT); uint32_t serializesSize = CalculateHeaderLength (); NS_LOG_INFO ("Serialized Size " << serializesSize); @@ -161,14 +161,14 @@ void QuicHeader::Serialize (Buffer::Iterator start) const { NS_LOG_FUNCTION (this); - NS_ASSERT (m_type != NONE or m_form == SHORT); + NS_ASSERT (m_type != NONE or m_form == Format::SHORT); NS_LOG_INFO ("Serialize::Serialized Size " << CalculateHeaderLength ()); Buffer::Iterator i = start; - uint8_t t = m_type + (m_form << 7); + uint8_t t = m_type + (static_cast(m_form) << 7); - if (m_form) + if (m_form == Format::LONG) { i.WriteU8 (t); i.WriteHtonU64 (m_connectionId); @@ -180,7 +180,7 @@ QuicHeader::Serialize (Buffer::Iterator start) const } else { - t += (m_c << 6) + (m_k << 5); + t += (m_c << 6) + (static_cast(m_k) << 5); i.WriteU8 (t); if (m_c) @@ -212,19 +212,19 @@ QuicHeader::Deserialize (Buffer::Iterator start) uint8_t t = i.ReadU8 (); - m_form = (t & 0x80) >> 7; + m_form = static_cast((t & 0x80) >> 7); if (IsShort ()) { m_c = (t & 0x40) >> 6; - m_k = (t & 0x20) >> 5; + m_k = static_cast((t & 0x20) >> 5); SetTypeByte (t & 0x1F); } else { SetTypeByte (t & 0x7F); } - NS_ASSERT (m_type != NONE or m_form == SHORT); + NS_ASSERT (m_type != NONE or m_form == Format::SHORT); if (HasConnectionId ()) { @@ -263,7 +263,7 @@ QuicHeader::Deserialize (Buffer::Iterator start) void QuicHeader::Print (std::ostream &os) const { - NS_ASSERT (m_type != NONE or m_form == SHORT); + NS_ASSERT (m_type != NONE or m_form == Format::SHORT); os << "|" << m_form << "|"; @@ -296,7 +296,7 @@ QuicHeader::CreateInitial (uint64_t connectionId, uint32_t version, SequenceNumb NS_LOG_INFO ("Create Initial Helper called"); QuicHeader head; - head.SetFormat (QuicHeader::LONG); + head.SetFormat (QuicHeader::Format::LONG); head.SetTypeByte (QuicHeader::INITIAL); head.SetConnectionID (connectionId); head.SetVersion (version); @@ -312,7 +312,7 @@ QuicHeader::CreateRetry (uint64_t connectionId, uint32_t version, SequenceNumber NS_LOG_INFO ("Create Retry Helper called"); QuicHeader head; - head.SetFormat (QuicHeader::LONG); + head.SetFormat (QuicHeader::Format::LONG); head.SetTypeByte (QuicHeader::RETRY); head.SetConnectionID (connectionId); head.SetVersion (version); @@ -327,7 +327,7 @@ QuicHeader::CreateHandshake (uint64_t connectionId, uint32_t version, SequenceNu NS_LOG_INFO ("Create Handshake Helper called "); QuicHeader head; - head.SetFormat (QuicHeader::LONG); + head.SetFormat (QuicHeader::Format::LONG); head.SetTypeByte (QuicHeader::HANDSHAKE); head.SetConnectionID (connectionId); head.SetVersion (version); @@ -342,7 +342,7 @@ QuicHeader::Create0RTT (uint64_t connectionId, uint32_t version, SequenceNumber3 NS_LOG_INFO ("Create 0RTT Helper called"); QuicHeader head; - head.SetFormat (QuicHeader::LONG); + head.SetFormat (QuicHeader::Format::LONG); head.SetTypeByte (QuicHeader::ZRTT_PROTECTED); head.SetConnectionID (connectionId); head.SetVersion (version); @@ -352,12 +352,12 @@ QuicHeader::Create0RTT (uint64_t connectionId, uint32_t version, SequenceNumber3 } QuicHeader -QuicHeader::CreateShort (uint64_t connectionId, SequenceNumber32 packetNumber, bool connectionIdFlag, bool keyPhaseBit) +QuicHeader::CreateShort (uint64_t connectionId, SequenceNumber32 packetNumber, bool connectionIdFlag, KeyPhase keyPhaseBit) { NS_LOG_INFO ("Create Short Helper called"); QuicHeader head; - head.SetFormat (QuicHeader::SHORT); + head.SetFormat (QuicHeader::Format::SHORT); head.SetKeyPhaseBit (keyPhaseBit); head.SetPacketNumber (packetNumber); @@ -375,7 +375,7 @@ QuicHeader::CreateVersionNegotiation (uint64_t connectionId, uint32_t version, s NS_LOG_INFO ("Create Version Negotiation Helper called"); QuicHeader head; - head.SetFormat (QuicHeader::LONG); + head.SetFormat (QuicHeader::Format::LONG); head.SetTypeByte (QuicHeader::VERSION_NEGOTIATION); head.SetConnectionID (connectionId); head.SetVersion (version); @@ -411,14 +411,14 @@ QuicHeader::SetTypeByte (uint8_t typeByte) m_type = typeByte; } -uint8_t +QuicHeader::Format QuicHeader::GetFormat () const { return m_form; } void -QuicHeader::SetFormat (bool form) +QuicHeader::SetFormat (Format form) { m_form = form; } @@ -482,7 +482,7 @@ QuicHeader::SetVersion (uint32_t version) m_version = version; } -bool +QuicHeader::KeyPhase QuicHeader::GetKeyPhaseBit () const { NS_ASSERT (IsShort ()); @@ -490,7 +490,7 @@ QuicHeader::GetKeyPhaseBit () const } void -QuicHeader::SetKeyPhaseBit (bool keyPhaseBit) +QuicHeader::SetKeyPhaseBit (QuicHeader::KeyPhase keyPhaseBit) { NS_ASSERT (IsShort ()); m_k = keyPhaseBit; @@ -498,7 +498,7 @@ QuicHeader::SetKeyPhaseBit (bool keyPhaseBit) bool QuicHeader::IsShort () const { - return m_form == SHORT; + return m_form == Format::SHORT; } bool @@ -562,5 +562,31 @@ operator<< (std::ostream& os, QuicHeader& tc) return os; } +std::ostream& +operator<<(std::ostream& os, QuicHeader::Format format) +{ + switch (format) + { + case QuicHeader::Format::SHORT: + return os << "SHORT"; + case QuicHeader::Format::LONG: + return os << "LONG"; + }; + return os << "UNKNOWN(" << static_cast(format) << ")"; +} + +std::ostream& +operator<<(std::ostream& os, QuicHeader::KeyPhase phase) +{ + switch (phase) + { + case QuicHeader::KeyPhase::ZERO: + return os << "ZERO"; + case QuicHeader::KeyPhase::ONE: + return os << "ONE"; + }; + return os << "UNKNOWN(" << static_cast(phase) << ")"; +} + } // namespace ns3 diff --git a/model/quic-header.h b/model/quic-header.h index e0a851d..eab49df 100644 --- a/model/quic-header.h +++ b/model/quic-header.h @@ -48,11 +48,11 @@ class QuicHeader : public Header /** * \brief Quic header form bit values */ - typedef enum + enum class Format { SHORT = 0, //!< Short header LONG = 1 //!< Long header - } TypeFormat_t; + }; /** * \brief Quic long header type byte values @@ -70,11 +70,11 @@ class QuicHeader : public Header /** * \brief Quic header key phase bit values */ - typedef enum + enum class KeyPhase { - PHASE_ZERO = 0, //!< Phase 0 - PHASE_ONE = 1 //!< Phase 1 - } KeyPhase_t; + ZERO = 0, //!< Phase 0 + ONE = 1 //!< Phase 1 + }; /** * \brief Quic packet number encodings for headers @@ -172,7 +172,7 @@ class QuicHeader : public Header * \param keyPhaseBit the key phase, which allows a recipient of a packet to identify the packet protection keys that are used to protect the packet. * \return the generated QuicHeader */ - static QuicHeader CreateShort (uint64_t connectionId, SequenceNumber32 packetNumber, bool connectionIdFlag = true, bool keyPhaseBit = QuicHeader::PHASE_ZERO); + static QuicHeader CreateShort (uint64_t connectionId, SequenceNumber32 packetNumber, bool connectionIdFlag = true, KeyPhase keyPhaseBit = KeyPhase::ZERO); // Getters, Setters and Controls @@ -238,25 +238,25 @@ class QuicHeader : public Header * \brief Get the key phase bit * \return The key phase bit for this QuicHeader */ - bool GetKeyPhaseBit () const; + KeyPhase GetKeyPhaseBit() const; /** * \brief Set the key phase bit * \param keyPhaseBit the key phase bit for this QuicHeader */ - void SetKeyPhaseBit (bool keyPhaseBit); + void SetKeyPhaseBit (KeyPhase keyPhaseBit); /** * \brief Get the form bit * \return The form bit for this QuicHeader */ - uint8_t GetFormat () const; + Format GetFormat() const; /** * \brief Set the form bit * \param form the form bit for this QuicHeader */ - void SetFormat (bool form); + void SetFormat (Format form); /** * \brief Check if the header is Short @@ -334,15 +334,19 @@ class QuicHeader : public Header */ uint32_t CalculateHeaderLength () const; - bool m_form; //!< Form bit + Format m_form; //!< Form bit bool m_c; //!< Connection id flag - bool m_k; //!< Key phase bit + KeyPhase m_k; //!< Key phase bit uint8_t m_type; //!< Type byte uint64_t m_connectionId; //!< Connection Id SequenceNumber32 m_packetNumber; //!< Packet number uint32_t m_version; //!< Version }; +std::ostream& operator<<(std::ostream& os, QuicHeader::Format format); + +std::ostream& operator<<(std::ostream& os, QuicHeader::KeyPhase phase); + } // namespace ns3 #endif /* QUIC_HEADER_H_ */ diff --git a/model/quic-l5-protocol.cc b/model/quic-l5-protocol.cc index f1cd10c..f82d744 100644 --- a/model/quic-l5-protocol.cc +++ b/model/quic-l5-protocol.cc @@ -91,7 +91,7 @@ QuicL5Protocol::~QuicL5Protocol () void QuicL5Protocol::CreateStream ( - const QuicStreamBase::QuicStreamDirectionTypes_t streamDirectionType) + const QuicStreamBase::Direction streamDirectionType) { NS_LOG_FUNCTION (this); NS_LOG_INFO ("Create the stream with ID " << m_streams.size ()); @@ -106,11 +106,11 @@ QuicL5Protocol::CreateStream ( stream->SetStreamId ((uint64_t) m_streams.size ()); uint64_t mask = 0x00000003; - if ((m_streams.size () & mask) == QuicStream::CLIENT_INITIATED_BIDIRECTIONAL - or (m_streams.size () & mask) - == QuicStream::SERVER_INITIATED_BIDIRECTIONAL) + if (static_cast(m_streams.size () & mask) == QuicStream::Type::CLIENT_INITIATED_BIDIRECTIONAL + or static_cast(m_streams.size () & mask) + == QuicStream::Type::SERVER_INITIATED_BIDIRECTIONAL) { - stream->SetStreamDirectionType (QuicStream::BIDIRECTIONAL); + stream->SetStreamDirectionType (QuicStream::Direction::BIDIRECTIONAL); } else @@ -133,7 +133,7 @@ QuicL5Protocol::CreateStream ( void QuicL5Protocol::CreateStream ( - const QuicStream::QuicStreamDirectionTypes_t streamDirectionType, + const QuicStream::Direction streamDirectionType, uint64_t streamNum) { @@ -176,7 +176,7 @@ QuicL5Protocol::DispatchSend (Ptr data) if (m_streams.size () != m_socket->GetMaxStreamId ()) { NS_LOG_INFO ("Create the missing streams"); - CreateStream (QuicStream::SENDER, m_socket->GetMaxStreamId ()); // TODO open up to max_stream_uni and max_stream_bidi + CreateStream (QuicStream::Direction::SENDER, m_socket->GetMaxStreamId ()); // TODO open up to max_stream_uni and max_stream_bidi } std::vector > disgregated = DisgregateSend (data); @@ -191,10 +191,10 @@ QuicL5Protocol::DispatchSend (Ptr data) jt = m_streams.begin () + 1; } NS_LOG_LOGIC ( - this << " " << (uint64_t)(*jt)->GetStreamDirectionType () << (uint64_t) QuicStream::SENDER << (uint64_t) QuicStream::BIDIRECTIONAL); + this << " " << (uint64_t)(*jt)->GetStreamDirectionType () << (uint64_t) QuicStream::Direction::SENDER << (uint64_t) QuicStream::Direction::BIDIRECTIONAL); - if ((*jt)->GetStreamDirectionType () == QuicStream::SENDER - or (*jt)->GetStreamDirectionType () == QuicStream::BIDIRECTIONAL) + if ((*jt)->GetStreamDirectionType () == QuicStream::Direction::SENDER + or (*jt)->GetStreamDirectionType () == QuicStream::Direction::BIDIRECTIONAL) { NS_LOG_INFO ( "Sending data on stream " << (*jt)->GetStreamId ()); @@ -221,14 +221,14 @@ QuicL5Protocol::DispatchSend (Ptr data, uint64_t streamId) if (!stream) { - CreateStream (QuicStream::SENDER, streamId); + CreateStream (QuicStream::Direction::SENDER, streamId); } stream = SearchStream (streamId); int sentData = 0; - if (stream->GetStreamDirectionType () == QuicStream::SENDER - or stream->GetStreamDirectionType () == QuicStream::BIDIRECTIONAL) + if (stream->GetStreamDirectionType () == QuicStream::Direction::SENDER + or stream->GetStreamDirectionType () == QuicStream::Direction::BIDIRECTIONAL) { sentData = stream->Send (data); } @@ -270,7 +270,7 @@ QuicL5Protocol::DispatchRecv (Ptr data, Address &address) } } - CreateStream (QuicStream::RECEIVER, currStreamNum); + CreateStream (QuicStream::Direction::RECEIVER, currStreamNum); for (auto it = disgregated.begin (); it != disgregated.end (); ++it) { @@ -283,9 +283,9 @@ QuicL5Protocol::DispatchRecv (Ptr data, Address &address) Ptr stream = SearchStream (sub.GetStreamId ()); if (stream - and (stream->GetStreamDirectionType () == QuicStream::RECEIVER + and (stream->GetStreamDirectionType () == QuicStream::Direction::RECEIVER or stream->GetStreamDirectionType () - == QuicStream::BIDIRECTIONAL)) + == QuicStream::Direction::BIDIRECTIONAL)) { NS_LOG_INFO ( "Receiving frame on stream " << stream->GetStreamId () << diff --git a/model/quic-l5-protocol.h b/model/quic-l5-protocol.h index 9ee811a..70e43e7 100644 --- a/model/quic-l5-protocol.h +++ b/model/quic-l5-protocol.h @@ -174,7 +174,7 @@ class QuicL5Protocol : public Object * * \param streamDirectionType the stream direction */ - void CreateStream (const QuicStream::QuicStreamDirectionTypes_t streamDirectionType); + void CreateStream (const QuicStream::Direction streamDirectionType); /** * \brief create streamNum streams to be associated to this L5 object @@ -183,7 +183,7 @@ class QuicL5Protocol : public Object * i.e., unidirectional or bidirectional * \param the number of streams to be created */ - void CreateStream (const QuicStream::QuicStreamDirectionTypes_t streamDirectionType, uint64_t streamNum); + void CreateStream (const QuicStream::Direction streamDirectionType, uint64_t streamNum); /** * \brief Get the maximum packet size from the underlying socket diff --git a/model/quic-socket-base.cc b/model/quic-socket-base.cc index 575d3d5..d34553d 100644 --- a/model/quic-socket-base.cc +++ b/model/quic-socket-base.cc @@ -441,7 +441,7 @@ QuicSocketBase::QuicSocketBase (void) m_quicl4 (0), m_quicl5 (0), m_socketState ( - IDLE), + State::IDLE), m_transportErrorCode ( QuicSubheader::TransportErrorCodes_t::NO_ERROR), m_serverBusy (false), @@ -451,7 +451,7 @@ QuicSocketBase::QuicSocketBase (void) m_connectionId (0), m_vers ( QUIC_VERSION_NS3_IMPL), - m_keyPhase (QuicHeader::PHASE_ZERO), + m_keyPhase (QuicHeader::KeyPhase::ZERO), m_lastReceived (Seconds (0.0)), m_initial_max_stream_data ( 0), @@ -541,14 +541,14 @@ QuicSocketBase::QuicSocketBase (const QuicSocketBase& sock) // Copy constructo m_node (sock.m_node), m_quicl4 (sock.m_quicl4), m_quicl5 (0), - m_socketState (LISTENING), + m_socketState (State::LISTENING), m_transportErrorCode (sock.m_transportErrorCode), m_serverBusy (sock.m_serverBusy), m_errno (sock.m_errno), m_connected (sock.m_connected), m_connectionId (0), m_vers (sock.m_vers), - m_keyPhase (QuicHeader::PHASE_ZERO), + m_keyPhase (QuicHeader::KeyPhase::ZERO), m_lastReceived (sock.m_lastReceived), m_initial_max_stream_data (sock.m_initial_max_stream_data), m_max_data (sock.m_max_data), @@ -750,12 +750,12 @@ int QuicSocketBase::Listen (void) { NS_LOG_FUNCTION (this); - if (m_socketType == NONE) + if (m_socketType == Type::NONE) { - m_socketType = SERVER; + m_socketType = Type::SERVER; } - if (m_socketState != IDLE and m_socketState != QuicSocket::CONNECTING_SVR) + if (m_socketState != State::IDLE and m_socketState != QuicSocket::State::CONNECTING_SVR) { //m_errno = ERROR_INVAL; return -1; @@ -764,7 +764,7 @@ QuicSocketBase::Listen (void) bool res = m_quicl4->SetListener (this); NS_ASSERT (res); - SetState (LISTENING); + SetState (State::LISTENING); return 0; } @@ -835,15 +835,15 @@ QuicSocketBase::Connect (const Address & address) } - if (m_socketType == NONE) + if (m_socketType == Type::NONE) { - m_socketType = CLIENT; + m_socketType = Type::CLIENT; } if (!m_quicl5) { m_quicl5 = CreateStreamController (); - m_quicl5->CreateStream (QuicStream::BIDIRECTIONAL, 0); // Create Stream 0 (necessary) + m_quicl5->CreateStream (QuicStream::Direction::BIDIRECTIONAL, 0); // Create Stream 0 (necessary) } // check if the address is in a list of known and authenticated addresses @@ -916,7 +916,7 @@ QuicSocketBase::AppendingTx (Ptr frame) { NS_LOG_FUNCTION (this); - if (m_socketState != IDLE) + if (m_socketState != State::IDLE) { bool done = m_txBuffer->Add (frame); if (!done) @@ -929,11 +929,11 @@ QuicSocketBase::AppendingTx (Ptr frame) uint32_t win = AvailableWindow (); NS_LOG_DEBUG ( "Added packet to the buffer - txBufSize = " << m_txBuffer->AppSize () - << " AvailableWindow = " << win << " state " << QuicStateName[m_socketState]); + << " AvailableWindow = " << win << " state " << m_socketState); } - if (m_socketState != IDLE) + if (m_socketState != State::IDLE) { if (!m_sendPendingDataEvent.IsRunning ()) { @@ -951,7 +951,7 @@ QuicSocketBase::AppendingTx (Ptr frame) else { - NS_ABORT_MSG ("Sending in state" << QuicStateName[m_socketState]); + NS_ABORT_MSG ("Sending in state" << m_socketState); return -1; } } @@ -1042,7 +1042,7 @@ QuicSocketBase::SendPendingData (bool withAck) } // check the state of the socket! - if (m_socketState == CONNECTING_CLT || m_socketState == CONNECTING_SVR) + if (m_socketState == State::CONNECTING_CLT || m_socketState == State::CONNECTING_SVR) { NS_LOG_INFO ("CONNECTING_CLT and CONNECTING_SVR state; no data to transmit"); break; @@ -1110,7 +1110,7 @@ void QuicSocketBase::SetSegSize (uint32_t size) { NS_LOG_FUNCTION (this << size); - NS_ABORT_MSG_UNLESS (m_socketState == IDLE || m_tcb->m_segmentSize == size, + NS_ABORT_MSG_UNLESS (m_socketState == State::IDLE || m_tcb->m_segmentSize == size, "Cannot change segment size dynamically."); m_tcb->m_segmentSize = size; @@ -1243,10 +1243,10 @@ QuicSocketBase::SendAck () // head = QuicHeader::Create0RTT (m_connectionId, m_vers, // packetNumber); // m_connected = true; - // m_keyPhase == QuicHeader::PHASE_ONE ? m_keyPhase = - // QuicHeader::PHASE_ZERO : + // m_keyPhase == QuicHeader::KeyPhase::ONE ? m_keyPhase = + // QuicHeader::KeyPhase::ZERO : // m_keyPhase = - // QuicHeader::PHASE_ONE; + // QuicHeader::KeyPhase::ONE; // } // else // { @@ -1338,17 +1338,17 @@ QuicSocketBase::SendDataPacket (SequenceNumber32 packetNumber, QuicHeader head; - if (m_socketState == CONNECTING_SVR) + if (m_socketState == State::CONNECTING_SVR) { m_connected = true; head = QuicHeader::CreateHandshake (m_connectionId, m_vers, packetNumber); } - else if (m_socketState == CONNECTING_CLT) + else if (m_socketState == State::CONNECTING_CLT) { head = QuicHeader::CreateInitial (m_connectionId, m_vers, packetNumber); } - else if (m_socketState == OPEN) + else if (m_socketState == State::OPEN) { if (!m_connected and !m_quicl4->Is0RTTHandshakeAllowed ()) { @@ -1361,10 +1361,10 @@ QuicSocketBase::SendDataPacket (SequenceNumber32 packetNumber, head = QuicHeader::Create0RTT (m_connectionId, m_vers, packetNumber); m_connected = true; - m_keyPhase == QuicHeader::PHASE_ONE ? m_keyPhase = - QuicHeader::PHASE_ZERO : + m_keyPhase == QuicHeader::KeyPhase::ONE ? m_keyPhase = + QuicHeader::KeyPhase::ZERO : m_keyPhase = - QuicHeader::PHASE_ONE; + QuicHeader::KeyPhase::ONE; } else { @@ -1419,7 +1419,7 @@ QuicSocketBase::SetReTxTimeout () Time alarmDuration; // Handshake packets are outstanding - if (m_socketState == CONNECTING_CLT || m_socketState == CONNECTING_SVR) + if (m_socketState == State::CONNECTING_CLT || m_socketState == State::CONNECTING_SVR) { NS_LOG_INFO ("Connecting, set alarm"); // Handshake retransmission alarm. @@ -1503,7 +1503,7 @@ QuicSocketBase::ReTxTimeout () NS_LOG_FUNCTION (this); NS_LOG_INFO ("ReTxTimeout Expired at time " << Simulator::Now ().GetSeconds ()); // Handshake packets are outstanding) - if (m_tcb->m_alarmType == 0 && (m_socketState == CONNECTING_CLT || m_socketState == CONNECTING_SVR)) + if (m_tcb->m_alarmType == 0 && (m_socketState == State::CONNECTING_CLT || m_socketState == State::CONNECTING_SVR)) { // Handshake retransmission alarm. //TODO retransmit handshake packets @@ -1644,7 +1644,7 @@ QuicSocketBase::Recv (uint32_t maxSize, uint32_t flags) NS_ABORT_MSG_IF (flags, "use of flags is not supported in QuicSocketBase::Recv()"); - if (m_rxBuffer->Size () == 0 && m_socketState == CLOSING) + if (m_rxBuffer->Size () == 0 && m_socketState == State::CLOSING) { return Create (); } @@ -1698,10 +1698,10 @@ QuicSocketBase::Close (void) m_receivedTransportParameters = false; - if (m_idleTimeoutEvent.IsRunning () and m_socketState != IDLE - and m_socketState != CLOSING) //Connection Close from application signal + if (m_idleTimeoutEvent.IsRunning () and m_socketState != State::IDLE + and m_socketState != State::CLOSING) //Connection Close from application signal { - SetState (CLOSING); + SetState (State::CLOSING); if (m_flushOnClose) { m_closeOnEmpty = true; @@ -1711,10 +1711,10 @@ QuicSocketBase::Close (void) ScheduleCloseAndSendConnectionClosePacket (); } } - else if (m_idleTimeoutEvent.IsExpired () and m_socketState != CLOSING - and m_socketState != IDLE and m_socketState != LISTENING) //Connection Close due to Idle Period termination + else if (m_idleTimeoutEvent.IsExpired () and m_socketState != State::CLOSING + and m_socketState != State::IDLE and m_socketState != State::LISTENING) //Connection Close due to Idle Period termination { - SetState (CLOSING); + SetState (State::CLOSING); m_drainingPeriodEvent.Cancel (); NS_LOG_LOGIC ( this << " Close Schedule DoClose at time " << Simulator::Now ().GetSeconds () << " to expire at time " << (Simulator::Now () + m_drainingPeriodTimeout.Get ()).GetSeconds ()); @@ -1723,14 +1723,14 @@ QuicSocketBase::Close (void) this); } else if (m_idleTimeoutEvent.IsExpired () - and m_drainingPeriodEvent.IsExpired () and m_socketState != CLOSING - and m_socketState != IDLE) //close last listening sockets + and m_drainingPeriodEvent.IsExpired () and m_socketState != State::CLOSING + and m_socketState != State::IDLE) //close last listening sockets { NS_LOG_LOGIC (this << " Closing listening socket"); DoClose (); } else if (m_idleTimeoutEvent.IsExpired () - and m_drainingPeriodEvent.IsExpired () and m_socketState == IDLE) + and m_drainingPeriodEvent.IsExpired () and m_socketState == State::IDLE) { NS_LOG_LOGIC (this << " Has already been closed"); } @@ -2047,7 +2047,7 @@ QuicSocketBase::SendInitialHandshake (uint8_t type, { NS_LOG_INFO ("Create HANDSHAKE"); Ptr p = Create (); - if (m_socketState == CONNECTING_SVR) + if (m_socketState == State::CONNECTING_SVR) { p->AddHeader (OnSendingTransportParameters ()); } @@ -2440,24 +2440,24 @@ QuicSocketBase::OnReceivedTransportParameters ( uint32_t mask = transportParameters.GetInitialMaxStreamIdBidi () & 0x00000003; - if ((mask == 0) && m_socketState != CONNECTING_CLT) + if ((mask == 0) && m_socketState != State::CONNECTING_CLT) { // TODO AbortConnection(QuicSubheader::TransportErrorCodes_t::TRANSPORT_PARAMETER_ERROR, "Invalid Initial Max Stream Id Bidi value provided from Server"); return; } - else if ((mask == 1) && m_socketState != CONNECTING_SVR) + else if ((mask == 1) && m_socketState != State::CONNECTING_SVR) { // TODO AbortConnection(QuicSubheader::TransportErrorCodes_t::TRANSPORT_PARAMETER_ERROR, "Invalid Initial Max Stream Id Bidi value provided from Client"); return; } mask = transportParameters.GetInitialMaxStreamIdUni () & 0x00000003; - if ((mask == 2) && m_socketState != CONNECTING_CLT) + if ((mask == 2) && m_socketState != State::CONNECTING_CLT) { // TODO AbortConnection(QuicSubheader::TransportErrorCodes_t::TRANSPORT_PARAMETER_ERROR, "Invalid Initial Max Stream Id Uni value provided from Server"); return; } - else if ((mask == 3) && m_socketState != CONNECTING_SVR) + else if ((mask == 3) && m_socketState != State::CONNECTING_SVR) { // TODO AbortConnection(QuicSubheader::TransportErrorCodes_t::TRANSPORT_PARAMETER_ERROR, "Invalid Initial Max Stream Id Uni value provided from Client"); return; @@ -2524,19 +2524,19 @@ QuicSocketBase::DoConnect (void) { NS_LOG_FUNCTION (this); - if (m_socketState != IDLE and m_socketState != QuicSocket::LISTENING) + if (m_socketState != State::IDLE and m_socketState != State::LISTENING) { //m_errno = ERROR_INVAL; return -1; } - if (m_socketState == LISTENING) + if (m_socketState == State::LISTENING) { - SetState (CONNECTING_SVR); + SetState (State::CONNECTING_SVR); } - else if (m_socketState == IDLE) + else if (m_socketState == State::IDLE) { - SetState (CONNECTING_CLT); + SetState (State::CONNECTING_CLT); QuicHeader q; SendInitialHandshake (QuicHeader::INITIAL, q, 0); } @@ -2550,15 +2550,15 @@ QuicSocketBase::DoFastConnect (void) NS_ABORT_MSG_IF (!IsVersionSupported (m_vers), "0RTT Handshake requested with wrong Initial Version"); - if (m_socketState != IDLE) + if (m_socketState != State::IDLE) { //m_errno = ERROR_INVAL; return -1; } - else if (m_socketState == IDLE) + else if (m_socketState == State::IDLE) { - SetState (OPEN); + SetState (State::OPEN); Simulator::ScheduleNow (&QuicSocketBase::ConnectionSucceeded, this); m_congestionControl->CongestionStateSet (m_tcb, TcpSocketState::CA_OPEN); @@ -2588,9 +2588,9 @@ QuicSocketBase::DoClose (void) NS_LOG_FUNCTION (this); NS_LOG_INFO (this << " DoClose at time " << Simulator::Now ().GetSeconds ()); - if (m_socketState != IDLE) + if (m_socketState != State::IDLE) { - SetState (IDLE); + SetState (State::IDLE); } SetRecvCallback (MakeNullCallback > ()); @@ -2624,7 +2624,7 @@ QuicSocketBase::ReceivedData (Ptr p, const QuicHeader& quicHeader, int onlyAckFrames = 0; bool unsupportedVersion = false; - if (quicHeader.IsORTT () and m_socketState == LISTENING) + if (quicHeader.IsORTT () and m_socketState == State::LISTENING) { if (m_serverBusy) @@ -2640,18 +2640,18 @@ QuicSocketBase::ReceivedData (Ptr p, const QuicHeader& quicHeader, m_receivedPacketNumbers.push_back (quicHeader.GetPacketNumber ()); m_connected = true; - m_keyPhase == QuicHeader::PHASE_ONE ? m_keyPhase = - QuicHeader::PHASE_ZERO : + m_keyPhase == QuicHeader::KeyPhase::ONE ? m_keyPhase = + QuicHeader::KeyPhase::ZERO : m_keyPhase = - QuicHeader::PHASE_ONE; - SetState (OPEN); + QuicHeader::KeyPhase::ONE; + SetState (State::OPEN); Simulator::ScheduleNow (&QuicSocketBase::ConnectionSucceeded, this); m_congestionControl->CongestionStateSet (m_tcb, TcpSocketState::CA_OPEN); m_couldContainTransportParameters = false; } - else if (quicHeader.IsInitial () and m_socketState == CONNECTING_SVR) + else if (quicHeader.IsInitial () and m_socketState == State::CONNECTING_SVR) { NS_LOG_INFO ("Server receives INITIAL"); if (m_serverBusy) @@ -2689,14 +2689,14 @@ QuicSocketBase::ReceivedData (Ptr p, const QuicHeader& quicHeader, } return; } - else if (quicHeader.IsHandshake () and m_socketState == CONNECTING_CLT) // Undefined compiler behaviour if i try to receive transport parameters + else if (quicHeader.IsHandshake () and m_socketState == State::CONNECTING_CLT) // Undefined compiler behaviour if i try to receive transport parameters { NS_LOG_INFO ("Client receives HANDSHAKE"); onlyAckFrames = m_quicl5->DispatchRecv (p, address); m_receivedPacketNumbers.push_back (quicHeader.GetPacketNumber ()); - SetState (OPEN); + SetState (State::OPEN); Simulator::ScheduleNow (&QuicSocketBase::ConnectionSucceeded, this); m_congestionControl->CongestionStateSet (m_tcb, TcpSocketState::CA_OPEN); @@ -2705,14 +2705,14 @@ QuicSocketBase::ReceivedData (Ptr p, const QuicHeader& quicHeader, SendInitialHandshake (QuicHeader::HANDSHAKE, quicHeader, p); return; } - else if (quicHeader.IsHandshake () and m_socketState == CONNECTING_SVR) + else if (quicHeader.IsHandshake () and m_socketState == State::CONNECTING_SVR) { NS_LOG_INFO ("Server receives HANDSHAKE"); onlyAckFrames = m_quicl5->DispatchRecv (p, address); m_receivedPacketNumbers.push_back (quicHeader.GetPacketNumber ()); - SetState (OPEN); + SetState (State::OPEN); Simulator::ScheduleNow (&QuicSocketBase::ConnectionSucceeded, this); m_congestionControl->CongestionStateSet (m_tcb, TcpSocketState::CA_OPEN); @@ -2720,7 +2720,7 @@ QuicSocketBase::ReceivedData (Ptr p, const QuicHeader& quicHeader, return; } else if (quicHeader.IsVersionNegotiation () - and m_socketState == CONNECTING_CLT) + and m_socketState == State::CONNECTING_CLT) { NS_LOG_INFO ("Client receives VERSION_NEGOTIATION"); @@ -2769,7 +2769,7 @@ QuicSocketBase::ReceivedData (Ptr p, const QuicHeader& quicHeader, } return; } - else if (quicHeader.IsShort () and m_socketState == OPEN) + else if (quicHeader.IsShort () and m_socketState == State::OPEN) { // TODOACK here? // we need to check if the packet contains only an ACK frame @@ -2779,7 +2779,7 @@ QuicSocketBase::ReceivedData (Ptr p, const QuicHeader& quicHeader, onlyAckFrames = m_quicl5->DispatchRecv (p, address); } - else if (m_socketState == CLOSING) + else if (m_socketState == State::CLOSING) { AbortConnection (m_transportErrorCode, @@ -2821,26 +2821,26 @@ QuicSocketBase::SetConnectionMaxData (uint32_t maxData) m_max_data = maxData; } -QuicSocket::QuicStates_t +QuicSocket::State QuicSocketBase::GetSocketState () const { return m_socketState; } void -QuicSocketBase::SetState (TracedValue newstate) +QuicSocketBase::SetState (TracedValue newstate) { NS_LOG_FUNCTION (this); if (m_quicl4->IsServer ()) { NS_LOG_INFO ( - "Server " << QuicStateName[m_socketState] << " -> " << QuicStateName[newstate] << ""); + "Server " << m_socketState << " -> " << newstate << ""); } else { NS_LOG_INFO ( - "Client " << QuicStateName[m_socketState] << " -> " << QuicStateName[newstate] << ""); + "Client " << m_socketState << " -> " << newstate << ""); } m_socketState = newstate; @@ -2889,15 +2889,15 @@ QuicSocketBase::AbortConnection (uint16_t transportErrorCode, QuicHeader quicHeader; switch (m_socketState) { - case CONNECTING_CLT: + case State::CONNECTING_CLT: quicHeader = QuicHeader::CreateInitial (m_connectionId, m_vers, m_tcb->m_nextTxSequence++); break; - case CONNECTING_SVR: + case State::CONNECTING_SVR: quicHeader = QuicHeader::CreateHandshake (m_connectionId, m_vers, m_tcb->m_nextTxSequence++); break; - case OPEN: + case State::OPEN: quicHeader = !m_connected ? QuicHeader::CreateHandshake (m_connectionId, m_vers, @@ -2906,7 +2906,7 @@ QuicSocketBase::AbortConnection (uint16_t transportErrorCode, m_tcb->m_nextTxSequence++, !m_omit_connection_id, m_keyPhase); break; - case CLOSING: + case State::CLOSING: quicHeader = QuicHeader::CreateShort (m_connectionId, m_tcb->m_nextTxSequence++, !m_omit_connection_id, @@ -3067,7 +3067,7 @@ QuicSocketBase::UpdateHighTxMark (SequenceNumber32 oldValue, SequenceNumber32 ne void QuicSocketBase::SetInitialSSThresh (uint32_t threshold) { - NS_ABORT_MSG_UNLESS ( (m_socketState == IDLE) || threshold == m_tcb->m_initialSsThresh, + NS_ABORT_MSG_UNLESS ( (m_socketState == State::IDLE) || threshold == m_tcb->m_initialSsThresh, "QuicSocketBase::SetSSThresh() cannot change initial ssThresh after connection started."); m_tcb->m_initialSsThresh = threshold; diff --git a/model/quic-socket-base.h b/model/quic-socket-base.h index f999fec..3248423 100644 --- a/model/quic-socket-base.h +++ b/model/quic-socket-base.h @@ -359,7 +359,7 @@ class QuicSocketBase : public QuicSocket * * \return the state in the Congestion state machine */ - QuicSocket::QuicStates_t GetSocketState () const; + QuicSocket::State GetSocketState () const; /** * \brief abort the connection due to an error @@ -700,7 +700,7 @@ class QuicSocketBase : public QuicSocket * * \param the new state */ - void SetState (TracedValue state); + void SetState (TracedValue state); /** * \brief Check if a version is supported by the QuicSocket @@ -753,14 +753,14 @@ class QuicSocketBase : public QuicSocket Time m_defaultLatency; //!< The default latency bound (only used by the EDF scheduler) // State-related attributes - TracedValue m_socketState; //!< State in the Congestion state machine + TracedValue m_socketState; //!< State in the Congestion state machine uint16_t m_transportErrorCode; //!< Quic transport error code bool m_serverBusy; //!< If true, server too busy to accept new connections mutable enum SocketErrno m_errno; //!< Socket error code bool m_connected; //!< Check if connection is established uint64_t m_connectionId; //!< Connection id uint32_t m_vers; //!< Quic protocol version - QuicHeader::KeyPhase_t m_keyPhase; //!< Key phase + QuicHeader::KeyPhase m_keyPhase; //!< Key phase Time m_lastReceived; //!< Time of last received packet // Transport Parameters values diff --git a/model/quic-socket.cc b/model/quic-socket.cc index 79627c5..aea231f 100644 --- a/model/quic-socket.cc +++ b/model/quic-socket.cc @@ -39,12 +39,6 @@ NS_LOG_COMPONENT_DEFINE ("QuicSocket"); NS_OBJECT_ENSURE_REGISTERED (QuicSocket); -const char* const -QuicSocket::QuicStateName[QuicSocket::LAST_STATE] = { - "IDLE", "LISTENING", "CONNECTING_SVR", - "CONNECTING_CLT", "OPEN", "CLOSING" -}; - TypeId QuicSocket::GetTypeId (void) { @@ -57,7 +51,7 @@ QuicSocket::GetTypeId (void) QuicSocket::QuicSocket () : Socket (), - m_socketType (NONE) + m_socketType (Type::NONE) { NS_LOG_FUNCTION_NOARGS (); } @@ -74,14 +68,14 @@ QuicSocket::~QuicSocket () NS_LOG_FUNCTION_NOARGS (); } -QuicSocket::QuicSocketTypes_t +QuicSocket::Type QuicSocket::GetQuicSocketType () const { return m_socketType; } void -QuicSocket::SetQuicSocketType (QuicSocketTypes_t m_socketType) +QuicSocket::SetQuicSocketType (Type m_socketType) { QuicSocket::m_socketType = m_socketType; } @@ -103,4 +97,25 @@ QuicSocket::CheckVersionNegotiation (uint32_t version) } } +std::ostream& +operator<<(std::ostream& os, QuicSocket::State state) +{ + switch (state) + { + case QuicSocket::State::IDLE: + return os << "IDLE"; + case QuicSocket::State::LISTENING: + return os << "LISTENING"; + case QuicSocket::State::CONNECTING_SVR: + return os << "CONNECTING_SVR"; + case QuicSocket::State::CONNECTING_CLT: + return os << "CONNECTING_CLT"; + case QuicSocket::State::OPEN: + return os << "OPEN"; + case QuicSocket::State::CLOSING: + return os << "CLOSING"; + }; + return os << "UNKNOWN(" << static_cast(state) << ")"; +} + } // namespace ns3 diff --git a/model/quic-socket.h b/model/quic-socket.h index c93dbd3..b99a266 100644 --- a/model/quic-socket.h +++ b/model/quic-socket.h @@ -79,17 +79,17 @@ class QuicSocket : public Socket /** * \brief Quic Socket types */ - typedef enum + enum class Type { CLIENT = 0, //!< Client Socket SERVER, //!< Server Socket NONE //!< Unknown Socket - } QuicSocketTypes_t; + }; /** * \brief Quic Socket states */ - typedef enum + enum class State { IDLE = 0, //!< Idle (no state yet) LISTENING, //!< Waiting for connection incoming @@ -97,28 +97,21 @@ class QuicSocket : public Socket CONNECTING_CLT, //!< Connection being set-up, client side OPEN, //!< Connection open CLOSING, //!< Termination of the connection - LAST_STATE, //!< Last State for debug - } QuicStates_t; - - - /** - * \brief Literal names of QUIC Socket states for use in log messages - */ - static const char* const QuicStateName[QuicSocket::LAST_STATE]; + }; /** * Get the socket type * - * \return a QuicSocketTypes_t with the socket type + * \return socket type */ - QuicSocketTypes_t GetQuicSocketType () const; + Type GetQuicSocketType () const; /** * Set the socket type * - * \param socketType a QuicSocketTypes_t with the socket type + * \param socketType the socket type */ - void SetQuicSocketType (QuicSocketTypes_t socketType); + void SetQuicSocketType (Type socketType); /** * Check if the Quic version indicates a Version Negotiation request @@ -129,7 +122,7 @@ class QuicSocket : public Socket bool CheckVersionNegotiation (uint32_t version); protected: - QuicSocketTypes_t m_socketType; //!< Quic Socket type + Type m_socketType; //!< Quic Socket type private: // Indirect the attribute setting and getting through private virtual methods @@ -163,6 +156,8 @@ class QuicSocket : public Socket }; +std::ostream& operator<<(std::ostream& os, QuicSocket::State state); + } // namespace ns3 #endif /* QUIC_SOCKET_H */ diff --git a/model/quic-stream-base.cc b/model/quic-stream-base.cc index d85ac4d..25abfc9 100644 --- a/model/quic-stream-base.cc +++ b/model/quic-stream-base.cc @@ -23,7 +23,7 @@ */ /* #define NS_LOG_APPEND_CONTEXT \ - if (m_node and m_connectionId and (m_streamId >= 0)) { std::clog << " [node " << m_node->GetId () << " socket " << m_connectionId << " stream " << m_streamId << " " << StreamDirectionTypeToString () << "] "; } + if (m_node and m_connectionId and (m_streamId >= 0)) { std::clog << " [node " << m_node->GetId () << " socket " << m_connectionId << " stream " << m_streamId << " " << m_streamDirectionType << "] "; } */ #include "ns3/abort.h" @@ -81,10 +81,10 @@ QuicStreamBase::GetInstanceTypeId () const QuicStreamBase::QuicStreamBase (void) : QuicStream (), - m_streamType (NONE), - m_streamDirectionType (UNKNOWN), - m_streamStateSend (IDLE), - m_streamStateRecv (IDLE), + m_streamType (Type::NONE), + m_streamDirectionType (Direction::UNKNOWN), + m_streamStateSend (State::IDLE), + m_streamStateRecv (State::IDLE), m_node (0), m_connectionId (0), m_streamId (0), @@ -120,16 +120,16 @@ QuicStreamBase::Send (Ptr frame) { NS_LOG_FUNCTION (this); - SetStreamStateSendIf (m_streamStateSend == IDLE and (m_streamDirectionType == SENDER or m_streamDirectionType == BIDIRECTIONAL), OPEN); + SetStreamStateSendIf (m_streamStateSend == State::IDLE and (m_streamDirectionType == Direction::SENDER or m_streamDirectionType == Direction::BIDIRECTIONAL), State::OPEN); - if (m_streamStateSend == OPEN or m_streamStateSend == SEND) + if (m_streamStateSend == State::OPEN or m_streamStateSend == State::SEND) { int sent = AppendingTx (frame); - NS_LOG_LOGIC ("Sending packets in stream. TxBufSize = " << m_txBuffer->AppSize () << " AvailableWindow = " << AvailableWindow () << " state " << QuicStreamStateName[m_streamStateSend]); + NS_LOG_LOGIC ("Sending packets in stream. TxBufSize = " << m_txBuffer->AppSize () << " AvailableWindow = " << AvailableWindow () << " state " << m_streamStateSend); - if ((m_streamStateSend == OPEN or m_streamStateSend == SEND) and AvailableWindow () > 0) + if ((m_streamStateSend == State::OPEN or m_streamStateSend == State::SEND) and AvailableWindow () > 0) { if (!m_streamSendPendingDataEvent.IsRunning ()) { @@ -140,7 +140,7 @@ QuicStreamBase::Send (Ptr frame) } else { - NS_ABORT_MSG ("Sending in state" << QuicStreamStateName[m_streamStateSend]); + NS_ABORT_MSG ("Sending in state" << m_streamStateSend); //m_errno = ERROR_NOTCONN; return -1; } @@ -249,9 +249,9 @@ QuicStreamBase::SendDataFrame (SequenceNumber32 seq, uint32_t maxSize) { NS_LOG_FUNCTION (this); - if (m_streamStateSend == OPEN and (m_streamDirectionType == SENDER or m_streamDirectionType == BIDIRECTIONAL)) + if (m_streamStateSend == State::OPEN and (m_streamDirectionType == Direction::SENDER or m_streamDirectionType == Direction::BIDIRECTIONAL)) { - SetStreamStateSend (SEND); + SetStreamStateSend (State::SEND); } Ptr frame = m_txBuffer->NextSequence (maxSize, seq); @@ -270,9 +270,9 @@ QuicStreamBase::SendDataFrame (SequenceNumber32 seq, uint32_t maxSize) NS_LOG_WARN ("Sending error - could not append packet to socket buffer. Putting packet back in stream buffer"); m_sentSize -= frame->GetSize (); } - else if (m_streamStateSend == SEND and m_fin and (m_streamDirectionType == SENDER or m_streamDirectionType == BIDIRECTIONAL)) + else if (m_streamStateSend == State::SEND and m_fin and (m_streamDirectionType == Direction::SENDER or m_streamDirectionType == Direction::BIDIRECTIONAL)) { - SetStreamStateSend (DATA_SENT); + SetStreamStateSend (State::DATA_SENT); } return size; @@ -314,14 +314,14 @@ QuicStreamBase::Recv (Ptr frame, const QuicSubheader& sub, Address &addr return -1; } - if (!(m_streamDirectionType == RECEIVER or m_streamDirectionType == BIDIRECTIONAL)) + if (!(m_streamDirectionType == Direction::RECEIVER or m_streamDirectionType == Direction::BIDIRECTIONAL)) { m_quicl5->SignalAbortConnection (QuicSubheader::TransportErrorCodes_t::PROTOCOL_VIOLATION, "Received RST_STREAM in send-only Stream"); return -1; } - if ((m_streamStateRecv == DATA_READ or m_streamStateRecv == RESET_READ)) + if ((m_streamStateRecv == State::DATA_READ or m_streamStateRecv == State::RESET_READ)) { m_quicl5->SignalAbortConnection (QuicSubheader::TransportErrorCodes_t::PROTOCOL_VIOLATION, "Receiving RST_STREAM Frames in DATA_READ or RESET_READ Stream State"); @@ -335,12 +335,12 @@ QuicStreamBase::Recv (Ptr frame, const QuicSubheader& sub, Address &addr return -1; } - SetStreamStateRecvIf (m_streamStateRecv == RECV or m_streamStateSend == SIZE_KNOWN or m_streamStateSend == DATA_RECVD, RESET_RECVD); + SetStreamStateRecvIf (m_streamStateRecv == State::RECV or m_streamStateSend == State::SIZE_KNOWN or m_streamStateSend == State::DATA_RECVD, State::RESET_RECVD); break; case QuicSubheader::MAX_STREAM_DATA: - if (!(m_streamDirectionType == SENDER or m_streamDirectionType == BIDIRECTIONAL)) + if (!(m_streamDirectionType == Direction::SENDER or m_streamDirectionType == Direction::BIDIRECTIONAL)) { m_quicl5->SignalAbortConnection (QuicSubheader::TransportErrorCodes_t::PROTOCOL_VIOLATION, "Received MAX_STREAM_DATA in receive-only Stream"); @@ -356,7 +356,7 @@ QuicStreamBase::Recv (Ptr frame, const QuicSubheader& sub, Address &addr case QuicSubheader::STREAM_BLOCKED: // TODO block the stream - if (!(m_streamDirectionType == RECEIVER or m_streamDirectionType == BIDIRECTIONAL)) + if (!(m_streamDirectionType == Direction::RECEIVER or m_streamDirectionType == Direction::BIDIRECTIONAL)) { m_quicl5->SignalAbortConnection (QuicSubheader::TransportErrorCodes_t::PROTOCOL_VIOLATION, "Received STREAM_BLOCKED in send-only Stream"); @@ -367,7 +367,7 @@ QuicStreamBase::Recv (Ptr frame, const QuicSubheader& sub, Address &addr case QuicSubheader::STOP_SENDING: // TODO implement a mechanism to stop sending data - if (!(m_streamDirectionType == SENDER or m_streamDirectionType == BIDIRECTIONAL)) + if (!(m_streamDirectionType == Direction::SENDER or m_streamDirectionType == Direction::BIDIRECTIONAL)) { m_quicl5->SignalAbortConnection (QuicSubheader::TransportErrorCodes_t::PROTOCOL_VIOLATION, "Received STOP_SENDING in receive-only Stream"); @@ -386,14 +386,14 @@ QuicStreamBase::Recv (Ptr frame, const QuicSubheader& sub, Address &addr case QuicSubheader::STREAM111: - if (!(m_streamDirectionType == RECEIVER or m_streamDirectionType == BIDIRECTIONAL)) + if (!(m_streamDirectionType == Direction::RECEIVER or m_streamDirectionType == Direction::BIDIRECTIONAL)) { m_quicl5->SignalAbortConnection (QuicSubheader::TransportErrorCodes_t::PROTOCOL_VIOLATION, "Received STREAM in send-only Stream"); return -1; } - if (!(m_streamStateRecv == IDLE or m_streamStateRecv == RECV or m_streamStateRecv == SIZE_KNOWN)) + if (!(m_streamStateRecv == State::IDLE or m_streamStateRecv == State::RECV or m_streamStateRecv == State::SIZE_KNOWN)) { m_quicl5->SignalAbortConnection (QuicSubheader::TransportErrorCodes_t::PROTOCOL_VIOLATION, "Received STREAM in State unequal to IDLE, RECV, SIZE_KNOWN"); @@ -407,7 +407,7 @@ QuicStreamBase::Recv (Ptr frame, const QuicSubheader& sub, Address &addr return -1; } - SetStreamStateRecvIf (m_streamStateRecv == IDLE, RECV); + SetStreamStateRecvIf (m_streamStateRecv == State::IDLE, State::RECV); if (m_quicl5->ContainsTransportParameters () and m_streamId == 0) { @@ -432,7 +432,7 @@ QuicStreamBase::Recv (Ptr frame, const QuicSubheader& sub, Address &addr return -1; } - SetStreamStateRecvIf (m_streamStateRecv == RECV and m_fin, SIZE_KNOWN); + SetStreamStateRecvIf (m_streamStateRecv == State::RECV and m_fin, State::SIZE_KNOWN); if (m_recvSize == sub.GetOffset ()) { @@ -462,7 +462,7 @@ QuicStreamBase::Recv (Ptr frame, const QuicSubheader& sub, Address &addr } NS_LOG_LOGIC ("Flushed RxBuffer - new offset " << m_recvSize << ", " << m_rxBuffer->Available () << "bytes available"); - SetStreamStateRecvIf (m_streamStateRecv == SIZE_KNOWN and m_rxBuffer->Size () == 0, DATA_RECVD); + SetStreamStateRecvIf (m_streamStateRecv == State::SIZE_KNOWN and m_rxBuffer->Size () == 0, State::DATA_RECVD); if (m_streamId != 0 ) { @@ -478,7 +478,7 @@ QuicStreamBase::Recv (Ptr frame, const QuicSubheader& sub, Address &addr NS_LOG_INFO ("Received handshake Message in Stream 0"); } - SetStreamStateRecvIf (m_streamStateRecv == DATA_RECVD, DATA_READ); + SetStreamStateRecvIf (m_streamStateRecv == State::DATA_RECVD, State::DATA_READ); } else @@ -522,7 +522,7 @@ QuicStreamBase::Recv (Ptr frame, const QuicSubheader& sub, Address &addr // case QuicSubheader::RST_STREAM: // // TODO // NS_ABORT_MSG_IF (!(m_streamDirectionType == SENDER or m_streamDirectionType == BIDIRECTIONAL), " Sending RstStream Frames in Receiver Stream"); -// NS_ABORT_MSG_IF ((m_streamStateRecv == DATA_READ or m_streamStateRecv == RESET_READ or m_streamStateRecv == RESET_SENT), " Sending RstStream Frames in " << QuicStreamStateName[m_streamStateRecv] << " State"); +// NS_ABORT_MSG_IF ((m_streamStateRecv == DATA_READ or m_streamStateRecv == RESET_READ or m_streamStateRecv == RESET_SENT), " Sending RstStream Frames in " << m_streamStateRecv << " State"); // SetStreamStateSendIf (m_streamStateSend == OPEN or m_streamStateSend == SEND or m_streamStateSend == DATA_SENT, RESET_SENT); // // if((m_streamStateSend = OPEN or m_streamStateSend == SEND or m_streamStateSend == DATA_SENT)){SetStreamStateSend(RESET_SENT);} @@ -576,40 +576,40 @@ QuicStreamBase::GetMaxStreamData () const } void -QuicStreamBase::SetStreamDirectionType (const QuicStreamDirectionTypes_t& streamDirectionType) +QuicStreamBase::SetStreamDirectionType (const Direction& streamDirectionType) { NS_LOG_FUNCTION (this); m_streamDirectionType = streamDirectionType; } -QuicStream::QuicStreamDirectionTypes_t +QuicStream::Direction QuicStreamBase::GetStreamDirectionType () { return m_streamDirectionType; } void -QuicStreamBase::SetStreamType (const QuicStreamTypes_t& streamType) +QuicStreamBase::SetStreamType (const Type& streamType) { NS_LOG_FUNCTION (this); m_streamType = streamType; } void -QuicStreamBase::SetStreamStateSend (const QuicStreamStates_t& streamState) +QuicStreamBase::SetStreamStateSend (const State& streamState) { NS_LOG_FUNCTION (this); - if (m_streamType == SERVER_INITIATED_BIDIRECTIONAL or m_streamType == SERVER_INITIATED_UNIDIRECTIONAL) + if (m_streamType == Type::SERVER_INITIATED_BIDIRECTIONAL or m_streamType == Type::SERVER_INITIATED_UNIDIRECTIONAL) { - NS_LOG_INFO ("Server Stream " << QuicStreamStateName[m_streamStateSend] << " -> " << QuicStreamStateName[streamState] << ""); + NS_LOG_INFO ("Server Stream " << m_streamStateSend << " -> " << streamState << ""); } else { - NS_LOG_INFO ("Client Stream " << QuicStreamStateName[m_streamStateSend] << " -> " << QuicStreamStateName[streamState] << ""); + NS_LOG_INFO ("Client Stream " << m_streamStateSend << " -> " << streamState << ""); } @@ -617,7 +617,7 @@ QuicStreamBase::SetStreamStateSend (const QuicStreamStates_t& streamState) } void -QuicStreamBase::SetStreamStateSendIf (bool condition, const QuicStreamStates_t& streamState) +QuicStreamBase::SetStreamStateSendIf (bool condition, const State& streamState) { NS_LOG_FUNCTION (this); if (condition) @@ -628,20 +628,20 @@ QuicStreamBase::SetStreamStateSendIf (bool condition, const QuicStreamStates_t& void -QuicStreamBase::SetStreamStateRecv (const QuicStreamStates_t& streamState) +QuicStreamBase::SetStreamStateRecv (const State& streamState) { NS_LOG_FUNCTION (this); - if (m_streamType == SERVER_INITIATED_BIDIRECTIONAL or m_streamType == SERVER_INITIATED_UNIDIRECTIONAL) + if (m_streamType == Type::SERVER_INITIATED_BIDIRECTIONAL or m_streamType == Type::SERVER_INITIATED_UNIDIRECTIONAL) { - NS_LOG_INFO ("Server Stream " << QuicStreamStateName[m_streamStateRecv] << " -> " << QuicStreamStateName[streamState] << ""); + NS_LOG_INFO ("Server Stream " << m_streamStateRecv << " -> " << streamState << ""); } else { - NS_LOG_INFO ("Client Stream " << QuicStreamStateName[m_streamStateRecv] << " -> " << QuicStreamStateName[streamState] << ""); + NS_LOG_INFO ("Client Stream " << m_streamStateRecv << " -> " << streamState << ""); } @@ -649,7 +649,7 @@ QuicStreamBase::SetStreamStateRecv (const QuicStreamStates_t& streamState) } void -QuicStreamBase::SetStreamStateRecvIf (bool condition, const QuicStreamStates_t& streamState) +QuicStreamBase::SetStreamStateRecvIf (bool condition, const State& streamState) { NS_LOG_FUNCTION (this); if (condition) @@ -677,16 +677,16 @@ QuicStreamBase::SetStreamId (uint64_t streamId) { case 0: - SetStreamType (QuicStream::CLIENT_INITIATED_BIDIRECTIONAL); + SetStreamType (QuicStream::Type::CLIENT_INITIATED_BIDIRECTIONAL); break; case 1: - SetStreamType (QuicStream::SERVER_INITIATED_BIDIRECTIONAL); + SetStreamType (QuicStream::Type::SERVER_INITIATED_BIDIRECTIONAL); break; case 2: - SetStreamType (QuicStream::CLIENT_INITIATED_UNIDIRECTIONAL); + SetStreamType (QuicStream::Type::CLIENT_INITIATED_UNIDIRECTIONAL); break; case 3: - SetStreamType (QuicStream::SERVER_INITIATED_UNIDIRECTIONAL); + SetStreamType (QuicStream::Type::SERVER_INITIATED_UNIDIRECTIONAL); break; } @@ -705,23 +705,6 @@ QuicStreamBase::SetConnectionId (uint64_t connId) m_connectionId = connId; } -std::string -QuicStreamBase::StreamDirectionTypeToString () const -{ - static const char* StreamDirectionTypeNames[6] = { - "SENDER", - "RECEIVER", - "BIDIRECTIONAL", - "UNKNOWN" - }; - - std::string typeDescription = ""; - - typeDescription.append (StreamDirectionTypeNames[m_streamDirectionType]); - - return typeDescription; -} - void QuicStreamBase::SetStreamSndBufSize (uint32_t size) { diff --git a/model/quic-stream-base.h b/model/quic-stream-base.h index 6d0e4ef..cdecfc6 100644 --- a/model/quic-stream-base.h +++ b/model/quic-stream-base.h @@ -182,14 +182,13 @@ class QuicStreamBase : public QuicStream uint32_t GetStreamRcvBufSize (void) const; // Implementation of QuicStream virtuals - std::string StreamDirectionTypeToString () const; - void SetStreamDirectionType (const QuicStreamDirectionTypes_t& streamDirectionType); - QuicStreamDirectionTypes_t GetStreamDirectionType (); - void SetStreamType (const QuicStreamTypes_t& streamType); - void SetStreamStateSendIf (bool condition, const QuicStreamStates_t& streamState); - void SetStreamStateSend (const QuicStreamStates_t& streamState); - void SetStreamStateRecv (const QuicStreamStates_t& streamState); - void SetStreamStateRecvIf (bool condition, const QuicStreamStates_t& streamState); + void SetStreamDirectionType (const Direction& streamDirectionType); + Direction GetStreamDirectionType (); + void SetStreamType (const Type& streamType); + void SetStreamStateSendIf (bool condition, const State& streamState); + void SetStreamStateSend (const State& streamState); + void SetStreamStateRecv (const State& streamState); + void SetStreamStateRecvIf (bool condition, const State& streamState); void SetNode (Ptr node); void SetConnectionId (uint64_t connId); void SetStreamId (uint64_t streamId); @@ -197,10 +196,10 @@ class QuicStreamBase : public QuicStream uint32_t GetStreamTxAvailable (void) const; protected: - QuicStreamTypes_t m_streamType; //!< The stream type - QuicStreamDirectionTypes_t m_streamDirectionType; //!< The stream direction - QuicStreamStates_t m_streamStateSend; //!< The state of the send stream - QuicStreamStates_t m_streamStateRecv; //!< The state of the receive stream + Type m_streamType; //!< The stream type + Direction m_streamDirectionType; //!< The stream direction + State m_streamStateSend; //!< The state of the send stream + State m_streamStateRecv; //!< The state of the receive stream Ptr m_node; //!< The node this stream is associated with uint64_t m_connectionId; //!< The connection ID uint64_t m_streamId; //!< The stream ID diff --git a/model/quic-stream.cc b/model/quic-stream.cc index 050a226..2fb1c1c 100644 --- a/model/quic-stream.cc +++ b/model/quic-stream.cc @@ -40,9 +40,6 @@ NS_LOG_COMPONENT_DEFINE ("QuicStream"); NS_OBJECT_ENSURE_REGISTERED (QuicStream); -const char* const -QuicStream::QuicStreamStateName[QuicStream::LAST_STATE] = {"IDLE", "OPEN", "SEND", "RECV", "SIZE_KNOWN", "DATA_SENT", "DATA_RECVD", "DATA_READ", "RESET_SENT", "RESET_RECVD", "RESET_READ"}; - TypeId QuicStream::GetTypeId (void) { @@ -64,4 +61,52 @@ QuicStream::~QuicStream () NS_LOG_FUNCTION_NOARGS (); } +std::ostream& +operator<<(std::ostream& os, QuicStream::Direction direction) +{ + switch (direction) + { + case QuicStream::Direction::SENDER: + return os << "SENDER"; + case QuicStream::Direction::RECEIVER: + return os << "RECEIVER"; + case QuicStream::Direction::BIDIRECTIONAL: + return os << "BIDIRECTIONAL"; + case QuicStream::Direction::UNKNOWN: + return os << "UNKNOWN"; + }; + return os << "UNKNOWN(" << static_cast(direction) << ")"; +} + +std::ostream& +operator<<(std::ostream& os, QuicStream::State state) +{ + switch (state) + { + case QuicStream::State::IDLE: + return os << "IDLE"; + case QuicStream::State::OPEN: + return os << "OPEN"; + case QuicStream::State::SEND: + return os << "SEND"; + case QuicStream::State::RECV: + return os << "RECV"; + case QuicStream::State::SIZE_KNOWN: + return os << "SIZE_KNOWN"; + case QuicStream::State::DATA_SENT: + return os << "DATA_SENT"; + case QuicStream::State::DATA_RECVD: + return os << "DATA_RECVD"; + case QuicStream::State::DATA_READ: + return os << "DATA_READ"; + case QuicStream::State::RESET_SENT: + return os << "RESET_SENT"; + case QuicStream::State::RESET_RECVD: + return os << "RESET_RECVD"; + case QuicStream::State::RESET_READ: + return os << "RESET_READ"; + }; + return os << "UNKNOWN(" << static_cast(state) << ")"; +} + } // namespace ns3 diff --git a/model/quic-stream.h b/model/quic-stream.h index 9d14334..c89b3b2 100644 --- a/model/quic-stream.h +++ b/model/quic-stream.h @@ -56,30 +56,30 @@ class QuicStream : public Object /** * \brief Quic Stream types, which are represented by the 2 lsb of stream Id */ - typedef enum + enum class Type { CLIENT_INITIATED_BIDIRECTIONAL = 0, //!< Client Initiated Bidirectional Stream SERVER_INITIATED_BIDIRECTIONAL, //!< Server Initiated Bidirectional Stream CLIENT_INITIATED_UNIDIRECTIONAL, //!< Client Initiated Unidirectional Stream SERVER_INITIATED_UNIDIRECTIONAL, //!< Server Initiated Unidirectional Stream NONE //!< Unknown Stream types - } QuicStreamTypes_t; + }; /** * \brief Quic Stream direction types */ - typedef enum + enum class Direction { SENDER = 0, //!< Sender Stream RECEIVER, //!< Receiver Stream BIDIRECTIONAL, //!< Bidirectional Stream UNKNOWN //!< Unknown direction type - } QuicStreamDirectionTypes_t; + }; /** * \brief Quic Stream states */ - typedef enum + enum class State { IDLE = 0, //!< Idle (no state yet) OPEN, //!< Initial state for a Sender Stream [Sender] @@ -92,41 +92,28 @@ class QuicStream : public Object RESET_SENT, //!< Abandon transmission of stream data [Sender] RESET_RECVD, //!< Packet containing a RST_STREAM has been acknowledged [Sender] / delivery of stream data to the application to be interrupted [Receiver] RESET_READ, //!< Application has been delivered the signal indicating that the Receiver stream has been reset [Receiver] - LAST_STATE //!< Last State for debug - } QuicStreamStates_t; - - /** - * \brief return a string with the QuicStreamDirectionTypes_t - * - * \return a string with the QuicStreamDirectionTypes_t - */ - virtual std::string StreamDirectionTypeToString () const = 0; - - /** - * \brief Literal names of Quic Stream states for use in log messages - */ - static const char* const QuicStreamStateName[QuicStream::LAST_STATE]; + }; /** * Set the stream direction * * \param streamDirectionType a QuicStreamDirectionTypes_t with the stream direction */ - virtual void SetStreamDirectionType (const QuicStreamDirectionTypes_t& streamDirectionType) = 0; + virtual void SetStreamDirectionType (const Direction& streamDirectionType) = 0; /** * Get the stream direction * * \return a QuicStreamDirectionTypes_t with the stream direction */ - virtual QuicStreamDirectionTypes_t GetStreamDirectionType () = 0; + virtual Direction GetStreamDirectionType () = 0; /** * \brief Set the stream type * * \param streamType the stream type */ - virtual void SetStreamType (const QuicStreamTypes_t& streamType) = 0; + virtual void SetStreamType (const Type& streamType) = 0; /** * \brief check the input condition, and, if true, set the input stream state for the send stream @@ -134,21 +121,21 @@ class QuicStream : public Object * \param condition a boolean condition * \param streamState the new QuicStreamStates_t to be applied if the condition holds */ - virtual void SetStreamStateSendIf (bool condition, const QuicStreamStates_t& streamState) = 0; + virtual void SetStreamStateSendIf (bool condition, const State& streamState) = 0; /** * \brief set the input stream state for the send stream * * \param streamState the new QuicStreamStates_t to be applied */ - virtual void SetStreamStateSend (const QuicStreamStates_t& streamState) = 0; + virtual void SetStreamStateSend (const State& streamState) = 0; /** * \brief set the input stream state for the rx stream * * \param streamState the new QuicStreamStates_t to be applied */ - virtual void SetStreamStateRecv (const QuicStreamStates_t& streamState) = 0; + virtual void SetStreamStateRecv (const State& streamState) = 0; /** * \brief check the input condition, and, if true, set the input stream state for the rx stream @@ -156,7 +143,7 @@ class QuicStream : public Object * \param condition a boolean condition * \param streamState the new QuicStreamStates_t to be applied if the condition holds */ - virtual void SetStreamStateRecvIf (bool condition, const QuicStreamStates_t& streamState) = 0; + virtual void SetStreamStateRecvIf (bool condition, const State& streamState) = 0; /** * Set the node of this stream @@ -195,6 +182,10 @@ class QuicStream : public Object }; +std::ostream& operator<<(std::ostream& os, QuicStream::Direction direction); + +std::ostream& operator<<(std::ostream& os, QuicStream::State state); + } // namespace ns3 #endif /* QUIC_STREAM_H */ diff --git a/test/quic-header-test.cc b/test/quic-header-test.cc index 3b46478..d9c63c8 100644 --- a/test/quic-header-test.cc +++ b/test/quic-header-test.cc @@ -155,7 +155,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () buffer.AddAtStart (head.GetSerializedSize ()); head.Serialize (buffer.Begin ()); - NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::LONG, + NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::Format::LONG, "Different format found"); NS_TEST_ASSERT_MSG_EQ (head.GetTypeByte (), QuicHeader::VERSION_NEGOTIATION, "Different type byte found"); @@ -168,7 +168,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () copyHead.Deserialize (buffer.Begin ()); - NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::LONG, + NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::Format::LONG, "Different format found in deserialized header"); NS_TEST_ASSERT_MSG_EQ (head.GetTypeByte (), QuicHeader::VERSION_NEGOTIATION, "Different type byte found in deserialized header"); @@ -188,7 +188,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () buffer.AddAtStart (head.GetSerializedSize ()); head.Serialize (buffer.Begin ()); - NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::LONG, + NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::Format::LONG, "Different format found"); NS_TEST_ASSERT_MSG_EQ (head.GetTypeByte (), QuicHeader::INITIAL, "Different type byte found"); @@ -203,7 +203,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () copyHead.Deserialize (buffer.Begin ()); - NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::LONG, + NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::Format::LONG, "Different format found in deserialized header"); NS_TEST_ASSERT_MSG_EQ (head.GetTypeByte (), QuicHeader::INITIAL, "Different type byte found in deserialized header"); @@ -225,7 +225,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () buffer.AddAtStart (head.GetSerializedSize ()); head.Serialize (buffer.Begin ()); - NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::LONG, + NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::Format::LONG, "Different format found"); NS_TEST_ASSERT_MSG_EQ (head.GetTypeByte (), QuicHeader::RETRY, "Different type byte found"); @@ -240,7 +240,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () copyHead.Deserialize (buffer.Begin ()); - NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::LONG, + NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::Format::LONG, "Different format found in deserialized header"); NS_TEST_ASSERT_MSG_EQ (head.GetTypeByte (), QuicHeader::RETRY, "Different type byte found in deserialized header"); @@ -262,7 +262,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () buffer.AddAtStart (head.GetSerializedSize ()); head.Serialize (buffer.Begin ()); - NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::LONG, + NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::Format::LONG, "Different format found"); NS_TEST_ASSERT_MSG_EQ (head.GetTypeByte (), QuicHeader::HANDSHAKE, "Different type byte found"); @@ -277,7 +277,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () copyHead.Deserialize (buffer.Begin ()); - NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::LONG, + NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::Format::LONG, "Different format found in deserialized header"); NS_TEST_ASSERT_MSG_EQ (head.GetTypeByte (), QuicHeader::HANDSHAKE, "Different type byte found in deserialized header"); @@ -299,7 +299,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () buffer.AddAtStart (head.GetSerializedSize ()); head.Serialize (buffer.Begin ()); - NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::LONG, + NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::Format::LONG, "Different format found"); NS_TEST_ASSERT_MSG_EQ (head.GetTypeByte (), QuicHeader::ZRTT_PROTECTED, "Different type byte found"); @@ -314,7 +314,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () copyHead.Deserialize (buffer.Begin ()); - NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::LONG, + NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::Format::LONG, "Different format found in deserialized header"); NS_TEST_ASSERT_MSG_EQ (head.GetTypeByte (), QuicHeader::ZRTT_PROTECTED, "Different type byte found in deserialized header"); @@ -333,7 +333,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () } bool connectionIdFlag = (i % 2 == 0) ? true : false; - bool keyPhaseBit = (i % 2 == 0) ? QuicHeader::PHASE_ZERO : QuicHeader::PHASE_ONE; + QuicHeader::KeyPhase keyPhaseBit = (i % 2 == 0) ? QuicHeader::KeyPhase::ZERO : QuicHeader::KeyPhase::ONE; head = QuicHeader::CreateShort (connectionId, packetNumber, connectionIdFlag, keyPhaseBit); @@ -343,7 +343,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () buffer.AddAtStart (head.GetSerializedSize ()); head.Serialize (buffer.Begin ()); - NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::SHORT, + NS_TEST_ASSERT_MSG_EQ (head.GetFormat (), QuicHeader::Format::SHORT, "Different format found"); NS_TEST_ASSERT_MSG_EQ (head.GetKeyPhaseBit (), keyPhaseBit, "Different key phase bit found"); @@ -358,7 +358,7 @@ QuicHeaderTestCase::TestQuicHeaderSerializeDeserialize () copyHead.Deserialize (buffer.Begin ()); - NS_TEST_ASSERT_MSG_EQ (copyHead.GetFormat (), QuicHeader::SHORT, + NS_TEST_ASSERT_MSG_EQ (copyHead.GetFormat (), QuicHeader::Format::SHORT, "Different format found"); NS_TEST_ASSERT_MSG_EQ (copyHead.GetKeyPhaseBit (), keyPhaseBit, "Different key phase bit found");