diff --git a/examples/traffic-control/queue-discs-benchmark.cc b/examples/traffic-control/queue-discs-benchmark.cc index ef1e03856..42e1ba932 100644 --- a/examples/traffic-control/queue-discs-benchmark.cc +++ b/examples/traffic-control/queue-discs-benchmark.cc @@ -170,11 +170,9 @@ int main (int argc, char *argv[]) } else if (queueDiscType.compare ("FqCoDel") == 0) { - uint32_t handle = tchBottleneck.SetRootQueueDisc ("ns3::FqCoDelQueueDisc"); + tchBottleneck.SetRootQueueDisc ("ns3::FqCoDelQueueDisc"); Config::SetDefault ("ns3::FqCoDelQueueDisc::MaxSize", QueueSizeValue (QueueSize (QueueSizeUnit::PACKETS, queueDiscSize))); - tchBottleneck.AddPacketFilter (handle, "ns3::FqCoDelIpv4PacketFilter"); - tchBottleneck.AddPacketFilter (handle, "ns3::FqCoDelIpv6PacketFilter"); } else if (queueDiscType.compare ("PIE") == 0) { diff --git a/src/internet/model/ipv4-packet-filter.cc b/src/internet/model/ipv4-packet-filter.cc index a01ac4105..ef9b1e747 100644 --- a/src/internet/model/ipv4-packet-filter.cc +++ b/src/internet/model/ipv4-packet-filter.cc @@ -64,88 +64,5 @@ Ipv4PacketFilter::CheckProtocol (Ptr item) const // ------------------------------------------------------------------------- // -NS_OBJECT_ENSURE_REGISTERED (FqCoDelIpv4PacketFilter); - -TypeId -FqCoDelIpv4PacketFilter::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::FqCoDelIpv4PacketFilter") - .SetParent () - .SetGroupName ("Internet") - .AddConstructor () - .AddAttribute ("Perturbation", - "The salt used as an additional input to the hash function of this filter", - UintegerValue (0), - MakeUintegerAccessor (&FqCoDelIpv4PacketFilter::m_perturbation), - MakeUintegerChecker ()) - ; - return tid; -} - -FqCoDelIpv4PacketFilter::FqCoDelIpv4PacketFilter () -{ - NS_LOG_FUNCTION (this); -} - -FqCoDelIpv4PacketFilter::~FqCoDelIpv4PacketFilter () -{ - NS_LOG_FUNCTION (this); -} - -int32_t -FqCoDelIpv4PacketFilter::DoClassify (Ptr item) const -{ - NS_LOG_FUNCTION (this << item); - Ptr ipv4Item = DynamicCast (item); - - NS_ASSERT (ipv4Item != 0); - - Ipv4Header hdr = ipv4Item->GetHeader (); - Ipv4Address src = hdr.GetSource (); - Ipv4Address dest = hdr.GetDestination (); - uint8_t prot = hdr.GetProtocol (); - uint16_t fragOffset = hdr.GetFragmentOffset (); - - TcpHeader tcpHdr; - UdpHeader udpHdr; - uint16_t srcPort = 0; - uint16_t destPort = 0; - - Ptr pkt = ipv4Item->GetPacket (); - - if (prot == 6 && fragOffset == 0) // TCP - { - pkt->PeekHeader (tcpHdr); - srcPort = tcpHdr.GetSourcePort (); - destPort = tcpHdr.GetDestinationPort (); - } - else if (prot == 17 && fragOffset == 0) // UDP - { - pkt->PeekHeader (udpHdr); - srcPort = udpHdr.GetSourcePort (); - destPort = udpHdr.GetDestinationPort (); - } - - /* serialize the 5-tuple and the perturbation in buf */ - uint8_t buf[17]; - src.Serialize (buf); - dest.Serialize (buf + 4); - buf[8] = prot; - buf[9] = (srcPort >> 8) & 0xff; - buf[10] = srcPort & 0xff; - buf[11] = (destPort >> 8) & 0xff; - buf[12] = destPort & 0xff; - buf[13] = (m_perturbation >> 24) & 0xff; - buf[14] = (m_perturbation >> 16) & 0xff; - buf[15] = (m_perturbation >> 8) & 0xff; - buf[16] = m_perturbation & 0xff; - - /* Linux calculates the jhash2 (jenkins hash), we calculate the murmur3 */ - uint32_t hash = Hash32 ((char*) buf, 17); - - NS_LOG_DEBUG ("Found Ipv4 packet; hash value " << hash); - - return hash; -} } // namespace ns3 diff --git a/src/internet/model/ipv4-packet-filter.h b/src/internet/model/ipv4-packet-filter.h index 3e9af1a57..190f51d90 100644 --- a/src/internet/model/ipv4-packet-filter.h +++ b/src/internet/model/ipv4-packet-filter.h @@ -51,31 +51,6 @@ private: virtual int32_t DoClassify (Ptr item) const = 0; }; - -/** - * \ingroup internet - * - * FqCoDelIpv4PacketFilter is the filter to be added to the FQCoDel - * queue disc to simulate the behavior of the fq-codel Linux queue disc. - * - */ -class FqCoDelIpv4PacketFilter : public Ipv4PacketFilter { -public: - /** - * \brief Get the type ID. - * \return the object TypeId - */ - static TypeId GetTypeId (void); - - FqCoDelIpv4PacketFilter (); - virtual ~FqCoDelIpv4PacketFilter (); - -private: - virtual int32_t DoClassify (Ptr item) const; - - uint32_t m_perturbation; //!< hash perturbation value -}; - } // namespace ns3 #endif /* IPV4_PACKET_FILTER */ diff --git a/src/internet/model/ipv6-packet-filter.cc b/src/internet/model/ipv6-packet-filter.cc index 7b2433368..c9413bc6b 100644 --- a/src/internet/model/ipv6-packet-filter.cc +++ b/src/internet/model/ipv6-packet-filter.cc @@ -64,87 +64,5 @@ Ipv6PacketFilter::CheckProtocol (Ptr item) const // ------------------------------------------------------------------------- // -NS_OBJECT_ENSURE_REGISTERED (FqCoDelIpv6PacketFilter); - -TypeId -FqCoDelIpv6PacketFilter::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::FqCoDelIpv6PacketFilter") - .SetParent () - .SetGroupName ("Internet") - .AddConstructor () - .AddAttribute ("Perturbation", - "The salt used as an additional input to the hash function of this filter", - UintegerValue (0), - MakeUintegerAccessor (&FqCoDelIpv6PacketFilter::m_perturbation), - MakeUintegerChecker ()) - ; - return tid; -} - -FqCoDelIpv6PacketFilter::FqCoDelIpv6PacketFilter () -{ - NS_LOG_FUNCTION (this); -} - -FqCoDelIpv6PacketFilter::~FqCoDelIpv6PacketFilter () -{ - NS_LOG_FUNCTION (this); -} - -int32_t -FqCoDelIpv6PacketFilter::DoClassify (Ptr< QueueDiscItem > item) const -{ - NS_LOG_FUNCTION (this << item); - Ptr ipv6Item = DynamicCast (item); - - NS_ASSERT (ipv6Item != 0); - - Ipv6Header hdr = ipv6Item->GetHeader (); - Ipv6Address src = hdr.GetSourceAddress (); - Ipv6Address dest = hdr.GetDestinationAddress (); - uint8_t prot = hdr.GetNextHeader (); - - TcpHeader tcpHdr; - UdpHeader udpHdr; - uint16_t srcPort = 0; - uint16_t destPort = 0; - - Ptr pkt = ipv6Item->GetPacket (); - - if (prot == 6) // TCP - { - pkt->PeekHeader (tcpHdr); - srcPort = tcpHdr.GetSourcePort (); - destPort = tcpHdr.GetDestinationPort (); - } - else if (prot == 17) // UDP - { - pkt->PeekHeader (udpHdr); - srcPort = udpHdr.GetSourcePort (); - destPort = udpHdr.GetDestinationPort (); - } - - /* serialize the 5-tuple and the perturbation in buf */ - uint8_t buf[41]; - src.Serialize (buf); - dest.Serialize (buf + 16); - buf[32] = prot; - buf[33] = (srcPort >> 8) & 0xff; - buf[34] = srcPort & 0xff; - buf[35] = (destPort >> 8) & 0xff; - buf[36] = destPort & 0xff; - buf[37] = (m_perturbation >> 24) & 0xff; - buf[38] = (m_perturbation >> 16) & 0xff; - buf[39] = (m_perturbation >> 8) & 0xff; - buf[40] = m_perturbation & 0xff; - - /* Linux calculates the jhash2 (jenkins hash), we calculate the murmur3 */ - uint32_t hash = Hash32 ((char*) buf, 41); - - NS_LOG_DEBUG ("Found Ipv6 packet; hash of the five tuple " << hash); - - return hash; -} } // namespace ns3 diff --git a/src/internet/model/ipv6-packet-filter.h b/src/internet/model/ipv6-packet-filter.h index 97b72e04e..07a35eb9e 100644 --- a/src/internet/model/ipv6-packet-filter.h +++ b/src/internet/model/ipv6-packet-filter.h @@ -51,31 +51,6 @@ private: virtual int32_t DoClassify (Ptr item) const = 0; }; - -/** - * \ingroup internet - * - * FqCoDelIpv6PacketFilter is the filter to be added to the FQCoDel - * queue disc to simulate the behavior of the fq-codel Linux queue disc. - * - */ -class FqCoDelIpv6PacketFilter : public Ipv6PacketFilter { -public: - /** - * \brief Get the type ID. - * \return the object TypeId - */ - static TypeId GetTypeId (void); - - FqCoDelIpv6PacketFilter (); - virtual ~FqCoDelIpv6PacketFilter (); - -private: - virtual int32_t DoClassify (Ptr item) const; - - uint32_t m_perturbation; //!< hash perturbation value -}; - } // namespace ns3 #endif /* IPV6_PACKET_FILTER */ diff --git a/src/test/ns3tc/fq-codel-queue-disc-test-suite.cc b/src/test/ns3tc/fq-codel-queue-disc-test-suite.cc index 9f6a7a143..ad76568b7 100644 --- a/src/test/ns3tc/fq-codel-queue-disc-test-suite.cc +++ b/src/test/ns3tc/fq-codel-queue-disc-test-suite.cc @@ -36,6 +36,50 @@ using namespace ns3; +/** + * Simple test packet filter able to classify IPv4 packets + * + */ +class Ipv4TestPacketFilter : public Ipv4PacketFilter { +public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ + static TypeId GetTypeId (void); + + Ipv4TestPacketFilter (); + virtual ~Ipv4TestPacketFilter (); + +private: + virtual int32_t DoClassify (Ptr item) const; +}; + +TypeId +Ipv4TestPacketFilter::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::Ipv4TestPacketFilter") + .SetParent () + .SetGroupName ("Internet") + .AddConstructor () + ; + return tid; +} + +Ipv4TestPacketFilter::Ipv4TestPacketFilter () +{ +} + +Ipv4TestPacketFilter::~Ipv4TestPacketFilter () +{ +} + +int32_t +Ipv4TestPacketFilter::DoClassify (Ptr item) const +{ + return 0; +} + /** * This class tests packets for which there is no suitable filter */ @@ -63,7 +107,7 @@ FqCoDelQueueDiscNoSuitableFilter::DoRun (void) { // Packets that cannot be classified by the available filters should be dropped Ptr queueDisc = CreateObjectWithAttributes ("MaxSize", StringValue ("4p")); - Ptr filter = CreateObject (); + Ptr filter = CreateObject (); queueDisc->AddPacketFilter (filter); queueDisc->SetQuantum (1500); @@ -122,10 +166,6 @@ void FqCoDelQueueDiscIPFlowsSeparationAndPacketLimit::DoRun (void) { Ptr queueDisc = CreateObjectWithAttributes ("MaxSize", StringValue ("4p")); - Ptr ipv6Filter = CreateObject (); - Ptr ipv4Filter = CreateObject (); - queueDisc->AddPacketFilter (ipv6Filter); - queueDisc->AddPacketFilter (ipv4Filter); queueDisc->SetQuantum (1500); queueDisc->Initialize (); @@ -195,10 +235,6 @@ void FqCoDelQueueDiscDeficit::DoRun (void) { Ptr queueDisc = CreateObjectWithAttributes (); - Ptr ipv6Filter = CreateObject (); - Ptr ipv4Filter = CreateObject (); - queueDisc->AddPacketFilter (ipv6Filter); - queueDisc->AddPacketFilter (ipv4Filter); queueDisc->SetQuantum (90); queueDisc->Initialize (); @@ -342,10 +378,6 @@ void FqCoDelQueueDiscTCPFlowsSeparation::DoRun (void) { Ptr queueDisc = CreateObjectWithAttributes ("MaxSize", StringValue ("10p")); - Ptr ipv6Filter = CreateObject (); - Ptr ipv4Filter = CreateObject (); - queueDisc->AddPacketFilter (ipv6Filter); - queueDisc->AddPacketFilter (ipv4Filter); queueDisc->SetQuantum (1500); queueDisc->Initialize (); @@ -432,10 +464,6 @@ void FqCoDelQueueDiscUDPFlowsSeparation::DoRun (void) { Ptr queueDisc = CreateObjectWithAttributes ("MaxSize", StringValue ("10p")); - Ptr ipv6Filter = CreateObject (); - Ptr ipv4Filter = CreateObject (); - queueDisc->AddPacketFilter (ipv6Filter); - queueDisc->AddPacketFilter (ipv4Filter); queueDisc->SetQuantum (1500); queueDisc->Initialize (); diff --git a/src/traffic-control/doc/mq.rst b/src/traffic-control/doc/mq.rst index 6b973a91d..52587ab17 100644 --- a/src/traffic-control/doc/mq.rst +++ b/src/traffic-control/doc/mq.rst @@ -46,11 +46,7 @@ discs: TrafficControlHelper tch; uint16_t handle = tch.SetRootQueueDisc ("ns3::MqQueueDisc"); TrafficControlHelper::ClassIdList cls = tch.AddQueueDiscClasses (handle, numTxQueues, "ns3::QueueDiscClass"); - TrafficControlHelper::HandleList hdl = tch.AddChildQueueDiscs (handle, cls, "ns3::FqCoDelQueueDisc"); - for (auto h : hdl) - { - tch.AddPacketFilter (h, "ns3::FqCoDelIpv4PacketFilter"); - } + tch.AddChildQueueDiscs (handle, cls, "ns3::FqCoDelQueueDisc"); QueueDiscContainer qdiscs = tch.Install (devices); Note that the child queue discs attached to the classes do not necessarily have to be of the same type.