From fbba64b5a4e0d288f8d664bb6abfde925ca4b33a Mon Sep 17 00:00:00 2001 From: Alexander Afanasyev Date: Thu, 19 Jan 2012 14:51:49 -0800 Subject: [PATCH] network+all: !!! Modification of PacketTag API !!! Not compatible with previous versions. On MacOS all modules that are supported can be compiled. Other modules may require minor changes. --- examples/routing/manet-routing-compare.cc | 22 +- src/aodv/model/aodv-routing-protocol.cc | 15 +- src/applications/model/radvd.cc | 4 +- src/dsdv/model/dsdv-routing-protocol.cc | 14 +- src/flow-monitor/model/ipv4-flow-probe.cc | 20 +- src/internet/model/icmpv6-l4-protocol.cc | 8 +- src/internet/model/ipv4-l3-protocol.cc | 7 +- src/internet/model/ipv4-raw-socket-impl.cc | 7 +- src/internet/model/ipv6-l3-protocol.cc | 7 +- src/internet/model/ipv6-raw-socket-impl.cc | 6 +- src/internet/model/tcp-socket-base.cc | 143 +++++------ src/internet/model/udp-socket-impl.cc | 137 ++++++----- src/mesh/model/dot11s/hwmp-protocol-mac.cc | 19 +- src/mesh/model/dot11s/hwmp-protocol.cc | 50 ++-- src/mesh/model/dot11s/hwmp-tag.cc | 8 +- src/mesh/model/dot11s/hwmp-tag.h | 8 +- src/mesh/model/flame/flame-protocol-mac.cc | 18 +- src/mesh/model/flame/flame-protocol.cc | 34 +-- src/mesh/model/mesh-wifi-interface-mac.cc | 10 +- src/network/examples/main-packet-tag.cc | 9 +- src/network/model/packet-tag-list.cc | 248 ++++++++++---------- src/network/model/packet-tag-list.h | 137 ++++------- src/network/model/packet.cc | 162 +++++++------ src/network/model/packet.h | 173 ++++++++------ src/network/model/tag.h | 11 +- src/network/utils/packet-socket.cc | 26 +- .../examples/virtual-net-device.cc | 9 +- src/wifi/model/mac-low.cc | 18 +- src/wifi/model/qos-utils.cc | 8 +- src/wifi/model/wifi-remote-station-manager.cc | 24 +- utils/bench-packets.cc | 12 +- 31 files changed, 689 insertions(+), 685 deletions(-) diff --git a/examples/routing/manet-routing-compare.cc b/examples/routing/manet-routing-compare.cc index 14c6ff2..c7736d5 100644 --- a/examples/routing/manet-routing-compare.cc +++ b/examples/routing/manet-routing-compare.cc @@ -120,24 +120,22 @@ RoutingExperiment::RoutingExperiment () std::string PrintReceivedPacket (Ptr socket, Ptr packet) { - SocketAddressTag tag; - bool found; - found = packet->PeekPacketTag (tag); + Ptr tag = packet->PeekPacketTag (); std::ostringstream oss; oss << Simulator::Now ().GetSeconds () << " " << socket->GetNode ()->GetId (); - if (found) - { - InetSocketAddress addr = InetSocketAddress::ConvertFrom (tag.GetAddress ()); + if (tag != 0) + { + InetSocketAddress addr = InetSocketAddress::ConvertFrom (tag->GetAddress ()); oss << " received one packet from " << addr.GetIpv4 (); - } - else - { + } + else + { oss << " received one packet!"; - } + } return oss.str (); -} + } void RoutingExperiment::ReceivePacket (Ptr socket) @@ -148,7 +146,7 @@ RoutingExperiment::ReceivePacket (Ptr socket) bytesTotal += packet->GetSize (); packetsReceived += 1; NS_LOG_UNCOND (PrintReceivedPacket (socket, packet)); - } +} } void diff --git a/src/aodv/model/aodv-routing-protocol.cc b/src/aodv/model/aodv-routing-protocol.cc index c6f3622..89e88f1 100644 --- a/src/aodv/model/aodv-routing-protocol.cc +++ b/src/aodv/model/aodv-routing-protocol.cc @@ -332,9 +332,9 @@ RoutingProtocol::RouteOutput (Ptr p, const Ipv4Header &header, // Actual route request will be deferred until packet will be fully formed, // routed to loopback, received from loopback and passed to RouteInput (see below) uint32_t iif = (oif ? m_ipv4->GetInterfaceForDevice (oif) : -1); - DeferredRouteOutputTag tag (iif); - if (!p->PeekPacketTag (tag)) + if (p->PeekPacketTag () == 0) { + Ptr tag = CreateObject (iif); p->AddPacketTag (tag); } return LoopbackRoute (header, oif); @@ -385,8 +385,7 @@ RoutingProtocol::RouteInput (Ptr p, const Ipv4Header &header, // Deferred route request if (idev == m_lo) { - DeferredRouteOutputTag tag; - if (p->PeekPacketTag (tag)) + if (p->PeekPacketTag () != 0) { DeferredRouteOutput (p, header, ucb, ecb); return true; @@ -1574,11 +1573,11 @@ RoutingProtocol::SendPacketFromQueue (Ipv4Address dst, Ptr route) QueueEntry queueEntry; while (m_queue.Dequeue (dst, queueEntry)) { - DeferredRouteOutputTag tag; Ptr p = ConstCast (queueEntry.GetPacket ()); - if (p->RemovePacketTag (tag) && - tag.oif != -1 && - tag.oif != m_ipv4->GetInterfaceForDevice (route->GetOutputDevice ())) + Ptr tag = p->RemovePacketTag (); + if (tag != 0 && + tag->oif != -1 && + tag->oif != m_ipv4->GetInterfaceForDevice (route->GetOutputDevice ())) { NS_LOG_DEBUG ("Output device doesn't match. Dropped."); return; diff --git a/src/applications/model/radvd.cc b/src/applications/model/radvd.cc index 841ca41..14f361b 100644 --- a/src/applications/model/radvd.cc +++ b/src/applications/model/radvd.cc @@ -211,8 +211,8 @@ void Radvd::Send (Ptr config, Ipv6Address dst, bool reschedule) /* Router advertisements MUST always have a ttl of 255 * The ttl value should be set as a socket option, but this is not yet implemented */ - SocketIpTtlTag ttl; - ttl.SetTtl (255); + Ptr ttl = CreateObject (); + ttl->SetTtl (255); p->AddPacketTag (ttl); /* send RA */ diff --git a/src/dsdv/model/dsdv-routing-protocol.cc b/src/dsdv/model/dsdv-routing-protocol.cc index 94e722e..1de06a0 100644 --- a/src/dsdv/model/dsdv-routing-protocol.cc +++ b/src/dsdv/model/dsdv-routing-protocol.cc @@ -317,10 +317,9 @@ RoutingProtocol::RouteOutput (Ptr p, if (EnableBuffering) { uint32_t iif = (oif ? m_ipv4->GetInterfaceForDevice (oif) : -1); - DeferredRouteOutputTag tag (iif); - if (!p->PeekPacketTag (tag)) + if (p->PeekPacketTag () == 0) { - p->AddPacketTag (tag); + p->AddPacketTag (CreateObject (iif)); } } return LoopbackRoute (header,oif); @@ -377,8 +376,7 @@ RoutingProtocol::RouteInput (Ptr p, // Deferred route request if (EnableBuffering == true && idev == m_lo) { - DeferredRouteOutputTag tag; - if (p->PeekPacketTag (tag)) + if (p->PeekPacketTag () != 0) { DeferredRouteOutput (p,header,ucb,ecb); return true; @@ -1121,11 +1119,11 @@ RoutingProtocol::SendPacketFromQueue (Ipv4Address dst, QueueEntry queueEntry; if (m_queue.Dequeue (dst,queueEntry)) { - DeferredRouteOutputTag tag; Ptr p = ConstCast (queueEntry.GetPacket ()); - if (p->RemovePacketTag (tag)) + Ptr tag = p->RemovePacketTag (); + if (tag != 0) { - if (tag.oif != -1 && tag.oif != m_ipv4->GetInterfaceForDevice (route->GetOutputDevice ())) + if (tag->oif != -1 && tag->oif != m_ipv4->GetInterfaceForDevice (route->GetOutputDevice ())) { NS_LOG_DEBUG ("Output device doesn't match. Dropped."); return; diff --git a/src/flow-monitor/model/ipv4-flow-probe.cc b/src/flow-monitor/model/ipv4-flow-probe.cc index 42cb8f7..3b90cdb 100644 --- a/src/flow-monitor/model/ipv4-flow-probe.cc +++ b/src/flow-monitor/model/ipv4-flow-probe.cc @@ -204,8 +204,8 @@ Ipv4FlowProbe::SendOutgoingLogger (const Ipv4Header &ipHeader, Ptr // tag the packet with the flow id and packet id, so that the packet can be identified even // when Ipv4Header is not accessible at some non-IPv4 protocol layer - Ipv4FlowProbeTag fTag (flowId, packetId, size); - ipPayload->AddPacketTag (fTag); + Ptr fTag = CreateObject (flowId, packetId, size); + ConstCast (ipPayload)->AddPacketTag (fTag); } } @@ -233,10 +233,9 @@ Ipv4FlowProbe::ForwardUpLogger (const Ipv4Header &ipHeader, Ptr ip if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId)) { // remove the tags that are added by Ipv4FlowProbe::SendOutgoingLogger () - Ipv4FlowProbeTag fTag; // ConstCast: see http://www.nsnam.org/bugzilla/show_bug.cgi?id=904 - ConstCast (ipPayload)->RemovePacketTag (fTag); + ConstCast (ipPayload)->RemovePacketTag (); uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ()); NS_LOG_DEBUG ("ReportLastRx ("< ipPaylo if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId)) { // remove the tags that are added by Ipv4FlowProbe::SendOutgoingLogger () - Ipv4FlowProbeTag fTag; // ConstCast: see http://www.nsnam.org/bugzilla/show_bug.cgi?id=904 - ConstCast (ipPayload)->RemovePacketTag (fTag); + ConstCast (ipPayload)->RemovePacketTag (); uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ()); NS_LOG_DEBUG ("Drop ("< ipPayload) { // remove the tags that are added by Ipv4FlowProbe::SendOutgoingLogger () - Ipv4FlowProbeTag fTag; // ConstCast: see http://www.nsnam.org/bugzilla/show_bug.cgi?id=904 - bool tagFound; - tagFound = ConstCast (ipPayload)->RemovePacketTag (fTag); + Ptr fTag = ConstCast (ipPayload)->RemovePacketTag (); if (!tagFound) { return; } - FlowId flowId = fTag.GetFlowId (); - FlowPacketId packetId = fTag.GetPacketId (); - uint32_t size = fTag.GetPacketSize (); + FlowId flowId = fTag->GetFlowId (); + FlowPacketId packetId = fTag->GetPacketId (); + uint32_t size = fTag->GetPacketSize (); NS_LOG_DEBUG ("Drop ("< packet, Ipv6Address src, Ipv6Add { NS_LOG_FUNCTION (this << packet << src << dst << (uint32_t)ttl); Ptr ipv6 = m_node->GetObject (); - SocketIpTtlTag tag; NS_ASSERT (ipv6 != 0); - tag.SetTtl (ttl); + Ptr tag = CreateObject (); + tag->SetTtl (ttl); packet->AddPacketTag (tag); m_downTarget (packet, src, dst, PROT_NUMBER, 0); } @@ -768,7 +768,6 @@ void Icmpv6L4Protocol::SendMessage (Ptr packet, Ipv6Address dst, Icmpv6H Ptr ipv6 = m_node->GetObject (); NS_ASSERT (ipv6 != 0 && ipv6->GetRoutingProtocol () != 0); Ipv6Header header; - SocketIpTtlTag tag; Socket::SocketErrno err; Ptr route; Ptr oif (0); //specify non-zero if bound to a source address @@ -779,7 +778,8 @@ void Icmpv6L4Protocol::SendMessage (Ptr packet, Ipv6Address dst, Icmpv6H if (route != 0) { NS_LOG_LOGIC ("Route exists"); - tag.SetTtl (ttl); + Ptr tag = CreateObject (); + tag->SetTtl (ttl); packet->AddPacketTag (tag); Ipv6Address src = route->GetSource (); diff --git a/src/internet/model/ipv4-l3-protocol.cc b/src/internet/model/ipv4-l3-protocol.cc index 929ba65..a0104d6 100644 --- a/src/internet/model/ipv4-l3-protocol.cc +++ b/src/internet/model/ipv4-l3-protocol.cc @@ -547,11 +547,10 @@ Ipv4L3Protocol::Send (Ptr packet, Ipv4Header ipHeader; bool mayFragment = true; uint8_t ttl = m_defaultTtl; - SocketIpTtlTag tag; - bool found = packet->RemovePacketTag (tag); - if (found) + Ptr tag = packet->RemovePacketTag (); + if (tag != 0) { - ttl = tag.GetTtl (); + ttl = tag->GetTtl (); } // Handle a few cases: diff --git a/src/internet/model/ipv4-raw-socket-impl.cc b/src/internet/model/ipv4-raw-socket-impl.cc index 53f4c1f..c8df351 100644 --- a/src/internet/model/ipv4-raw-socket-impl.cc +++ b/src/internet/model/ipv4-raw-socket-impl.cc @@ -320,9 +320,10 @@ Ipv4RawSocketImpl::ForwardUp (Ptr p, Ipv4Header ipHeader, PtrRemovePacketTag (tag); - tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ()); + Ptr origTag = copy->RemovePacketTag (); + NS_ASSERT (origTag != 0); + Ptr tag = CreateObject (*origTag); + tag->SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ()); copy->AddPacketTag (tag); } if (m_protocol == 1) diff --git a/src/internet/model/ipv6-l3-protocol.cc b/src/internet/model/ipv6-l3-protocol.cc index 134e07c..72cb1d6 100644 --- a/src/internet/model/ipv6-l3-protocol.cc +++ b/src/internet/model/ipv6-l3-protocol.cc @@ -593,12 +593,11 @@ void Ipv6L3Protocol::Send (Ptr packet, Ipv6Address source, Ipv6Address d NS_LOG_FUNCTION (this << packet << source << destination << (uint32_t)protocol << route); Ipv6Header hdr; uint8_t ttl = m_defaultTtl; - SocketIpTtlTag tag; - bool found = packet->RemovePacketTag (tag); + Ptr tag = packet->RemovePacketTag (); - if (found) + if (tag != 0) { - ttl = tag.GetTtl (); + ttl = tag->GetTtl (); } /* Handle 3 cases: diff --git a/src/internet/model/ipv6-raw-socket-impl.cc b/src/internet/model/ipv6-raw-socket-impl.cc index 51d556b..ab8353c 100644 --- a/src/internet/model/ipv6-raw-socket-impl.cc +++ b/src/internet/model/ipv6-raw-socket-impl.cc @@ -340,9 +340,9 @@ bool Ipv6RawSocketImpl::ForwardUp (Ptr p, Ipv6Header hdr, PtrRemovePacketTag (tag); - tag.SetRecvIf (device->GetIfIndex ()); + Ptr origTag = copy->RemovePacketTag (); + Ptr tag = CreateObject (*origTag); + tag->SetRecvIf (device->GetIfIndex ()); copy->AddPacketTag (tag); } diff --git a/src/internet/model/tcp-socket-base.cc b/src/internet/model/tcp-socket-base.cc index e468282..1ee8190 100644 --- a/src/internet/model/tcp-socket-base.cc +++ b/src/internet/model/tcp-socket-base.cc @@ -271,30 +271,30 @@ TcpSocketBase::Bind (const Address &address) NS_LOG_FUNCTION (this << address); if (InetSocketAddress::IsMatchingType (address)) { - InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); - Ipv4Address ipv4 = transport.GetIpv4 (); - uint16_t port = transport.GetPort (); - if (ipv4 == Ipv4Address::GetAny () && port == 0) - { - m_endPoint = m_tcp->Allocate (); - } - else if (ipv4 == Ipv4Address::GetAny () && port != 0) - { - m_endPoint = m_tcp->Allocate (port); - } - else if (ipv4 != Ipv4Address::GetAny () && port == 0) - { - m_endPoint = m_tcp->Allocate (ipv4); - } - else if (ipv4 != Ipv4Address::GetAny () && port != 0) - { - m_endPoint = m_tcp->Allocate (ipv4, port); - } - if (0 == m_endPoint) - { - m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL; - return -1; - } + InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); + Ipv4Address ipv4 = transport.GetIpv4 (); + uint16_t port = transport.GetPort (); + if (ipv4 == Ipv4Address::GetAny () && port == 0) + { + m_endPoint = m_tcp->Allocate (); + } + else if (ipv4 == Ipv4Address::GetAny () && port != 0) + { + m_endPoint = m_tcp->Allocate (port); + } + else if (ipv4 != Ipv4Address::GetAny () && port == 0) + { + m_endPoint = m_tcp->Allocate (ipv4); + } + else if (ipv4 != Ipv4Address::GetAny () && port != 0) + { + m_endPoint = m_tcp->Allocate (ipv4, port); + } + if (0 == m_endPoint) + { + m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL; + return -1; + } } else if (Inet6SocketAddress::IsMatchingType (address)) { @@ -343,24 +343,24 @@ TcpSocketBase::Connect (const Address & address) // If haven't do so, Bind() this socket first if (InetSocketAddress::IsMatchingType (address)) { - if (m_endPoint == 0) + if (m_endPoint == 0) + { + if (Bind () == -1) { - if (Bind () == -1) - { - NS_ASSERT (m_endPoint == 0); - return -1; // Bind() failed - } - NS_ASSERT (m_endPoint != 0); + NS_ASSERT (m_endPoint == 0); + return -1; // Bind() failed } - InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); - m_endPoint->SetPeer (transport.GetIpv4 (), transport.GetPort ()); + NS_ASSERT (m_endPoint != 0); + } + InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); + m_endPoint->SetPeer (transport.GetIpv4 (), transport.GetPort ()); m_endPoint6 = 0; - // Get the appropriate local address and port number from the routing protocol and set up endpoint - if (SetupEndpoint () != 0) - { // Route to destination does not exist - return -1; - } + // Get the appropriate local address and port number from the routing protocol and set up endpoint + if (SetupEndpoint () != 0) + { // Route to destination does not exist + return -1; + } } else if (Inet6SocketAddress::IsMatchingType (address) ) { @@ -516,15 +516,16 @@ TcpSocketBase::Recv (uint32_t maxSize, uint32_t flags) Ptr outPacket = m_rxBuffer.Extract (maxSize); if (outPacket != 0 && outPacket->GetSize () != 0) { - SocketAddressTag tag; + Ptr tag = CreateObject (); if (m_endPoint != 0) { - tag.SetAddress (InetSocketAddress (m_endPoint->GetPeerAddress (), m_endPoint->GetPeerPort ())); + tag->SetAddress (InetSocketAddress (m_endPoint->GetPeerAddress (), m_endPoint->GetPeerPort ())); } else if (m_endPoint6 != 0) { - tag.SetAddress (Inet6SocketAddress (m_endPoint6->GetPeerAddress (), m_endPoint6->GetPeerPort ())); + tag->SetAddress (Inet6SocketAddress (m_endPoint6->GetPeerAddress (), m_endPoint6->GetPeerPort ())); } + outPacket->AddPacketTag (tag); } return outPacket; @@ -611,7 +612,7 @@ TcpSocketBase::BindToNetDevice (Ptr netdevice) if (m_endPoint != 0) { - m_endPoint->BindToNetDevice (netdevice); + m_endPoint->BindToNetDevice (netdevice); } // No BindToNetDevice() for Ipv6EndPoint return; @@ -629,8 +630,8 @@ TcpSocketBase::SetupCallback (void) } if (m_endPoint != 0) { - m_endPoint->SetRxCallback (MakeCallback (&TcpSocketBase::ForwardUp, Ptr (this))); - m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketBase::Destroy, Ptr (this))); + m_endPoint->SetRxCallback (MakeCallback (&TcpSocketBase::ForwardUp, Ptr (this))); + m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketBase::Destroy, Ptr (this))); } if (m_endPoint6 != 0) { @@ -1139,8 +1140,8 @@ TcpSocketBase::ProcessSynRcvd (Ptr packet, const TcpHeader& tcpHeader, m_txBuffer.SetHeadSequence (m_nextTxSequence); if (m_endPoint) { - m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (), - InetSocketAddress::ConvertFrom (fromAddress).GetPort ()); + m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (), + InetSocketAddress::ConvertFrom (fromAddress).GetPort ()); } else if (m_endPoint6) { @@ -1173,8 +1174,8 @@ TcpSocketBase::ProcessSynRcvd (Ptr packet, const TcpHeader& tcpHeader, m_txBuffer.SetHeadSequence (m_nextTxSequence); if (m_endPoint) { - m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (), - InetSocketAddress::ConvertFrom (fromAddress).GetPort ()); + m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (), + InetSocketAddress::ConvertFrom (fromAddress).GetPort ()); } else if (m_endPoint6) { @@ -1191,8 +1192,8 @@ TcpSocketBase::ProcessSynRcvd (Ptr packet, const TcpHeader& tcpHeader, NS_LOG_LOGIC ("Illegal flag " << tcpflags << " received. Reset packet is sent."); if (m_endPoint) { - m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (), - InetSocketAddress::ConvertFrom (fromAddress).GetPort ()); + m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (), + InetSocketAddress::ConvertFrom (fromAddress).GetPort ()); } else if (m_endPoint6) { @@ -1425,12 +1426,12 @@ TcpSocketBase::Destroy (void) m_endPoint = 0; if (m_tcp != 0) { - std::vector >::iterator it - = std::find (m_tcp->m_sockets.begin (), m_tcp->m_sockets.end (), this); - if (it != m_tcp->m_sockets.end ()) - { - m_tcp->m_sockets.erase (it); - } + std::vector >::iterator it + = std::find (m_tcp->m_sockets.begin (), m_tcp->m_sockets.end (), this); + if (it != m_tcp->m_sockets.end ()) + { + m_tcp->m_sockets.erase (it); + } } NS_LOG_LOGIC (this << " Cancelled ReTxTimeout event which was set to expire at " << (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ()); @@ -1486,8 +1487,8 @@ TcpSocketBase::SendEmptyPacket (uint8_t flags) header.SetAckNumber (m_rxBuffer.NextRxSequence ()); if (m_endPoint != 0) { - header.SetSourcePort (m_endPoint->GetLocalPort ()); - header.SetDestinationPort (m_endPoint->GetPeerPort ()); + header.SetSourcePort (m_endPoint->GetLocalPort ()); + header.SetDestinationPort (m_endPoint->GetPeerPort ()); } else { @@ -1576,7 +1577,7 @@ TcpSocketBase::DeallocateEndPoint (void) if (it != m_tcp->m_sockets.end ()) { m_tcp->m_sockets.erase (it); - } +} CancelAllTimers (); } } @@ -1652,10 +1653,10 @@ TcpSocketBase::CompleteFork (Ptr p, const TcpHeader& h, // Get port and address from peer (connecting host) if (InetSocketAddress::IsMatchingType (toAddress)) { - m_endPoint = m_tcp->Allocate (InetSocketAddress::ConvertFrom (toAddress).GetIpv4 (), - InetSocketAddress::ConvertFrom (toAddress).GetPort (), - InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (), - InetSocketAddress::ConvertFrom (fromAddress).GetPort ()); + m_endPoint = m_tcp->Allocate (InetSocketAddress::ConvertFrom (toAddress).GetIpv4 (), + InetSocketAddress::ConvertFrom (toAddress).GetPort (), + InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (), + InetSocketAddress::ConvertFrom (fromAddress).GetPort ()); m_endPoint6 = 0; } else if (Inet6SocketAddress::IsMatchingType (toAddress)) @@ -1723,8 +1724,8 @@ TcpSocketBase::SendDataPacket (SequenceNumber32 seq, uint32_t maxSize, bool with header.SetAckNumber (m_rxBuffer.NextRxSequence ()); if (m_endPoint) { - header.SetSourcePort (m_endPoint->GetLocalPort ()); - header.SetDestinationPort (m_endPoint->GetPeerPort ()); + header.SetSourcePort (m_endPoint->GetLocalPort ()); + header.SetDestinationPort (m_endPoint->GetPeerPort ()); } else { @@ -1744,8 +1745,8 @@ TcpSocketBase::SendDataPacket (SequenceNumber32 seq, uint32_t maxSize, bool with NS_LOG_LOGIC ("Send packet via TcpL4Protocol with flags 0x" << std::hex << static_cast (flags) << std::dec); if (m_endPoint) { - m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (), - m_endPoint->GetPeerAddress (), m_boundnetdevice); + m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (), + m_endPoint->GetPeerAddress (), m_boundnetdevice); } else { @@ -2024,8 +2025,8 @@ TcpSocketBase::PersistTimeout () tcpHeader.SetWindowSize (AdvertisedWindowSize ()); if (m_endPoint != 0) { - tcpHeader.SetSourcePort (m_endPoint->GetLocalPort ()); - tcpHeader.SetDestinationPort (m_endPoint->GetPeerPort ()); + tcpHeader.SetSourcePort (m_endPoint->GetLocalPort ()); + tcpHeader.SetDestinationPort (m_endPoint->GetPeerPort ()); } else { @@ -2036,8 +2037,8 @@ TcpSocketBase::PersistTimeout () if (m_endPoint != 0) { - m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (), - m_endPoint->GetPeerAddress (), m_boundnetdevice); + m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (), + m_endPoint->GetPeerAddress (), m_boundnetdevice); } else { diff --git a/src/internet/model/udp-socket-impl.cc b/src/internet/model/udp-socket-impl.cc index acd93b6..10a5ef6 100644 --- a/src/internet/model/udp-socket-impl.cc +++ b/src/internet/model/udp-socket-impl.cc @@ -180,9 +180,9 @@ UdpSocketImpl::FinishBind (void) bool done = false; if (m_endPoint != 0) { - m_endPoint->SetRxCallback (MakeCallback (&UdpSocketImpl::ForwardUp, Ptr (this))); - m_endPoint->SetIcmpCallback (MakeCallback (&UdpSocketImpl::ForwardIcmp, Ptr (this))); - m_endPoint->SetDestroyCallback (MakeCallback (&UdpSocketImpl::Destroy, Ptr (this))); + m_endPoint->SetRxCallback (MakeCallback (&UdpSocketImpl::ForwardUp, Ptr (this))); + m_endPoint->SetIcmpCallback (MakeCallback (&UdpSocketImpl::ForwardIcmp, Ptr (this))); + m_endPoint->SetDestroyCallback (MakeCallback (&UdpSocketImpl::Destroy, Ptr (this))); done = true; } if (m_endPoint6 != 0) @@ -194,8 +194,8 @@ UdpSocketImpl::FinishBind (void) } if (done) { - return 0; - } + return 0; +} return -1; } @@ -207,7 +207,7 @@ UdpSocketImpl::Bind (void) return FinishBind (); } -int +int UdpSocketImpl::Bind6 (void) { NS_LOG_FUNCTION_NOARGS (); @@ -222,25 +222,25 @@ UdpSocketImpl::Bind (const Address &address) if (InetSocketAddress::IsMatchingType (address)) { - InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); - Ipv4Address ipv4 = transport.GetIpv4 (); - uint16_t port = transport.GetPort (); - if (ipv4 == Ipv4Address::GetAny () && port == 0) - { - m_endPoint = m_udp->Allocate (); - } - else if (ipv4 == Ipv4Address::GetAny () && port != 0) - { - m_endPoint = m_udp->Allocate (port); - } - else if (ipv4 != Ipv4Address::GetAny () && port == 0) - { - m_endPoint = m_udp->Allocate (ipv4); - } - else if (ipv4 != Ipv4Address::GetAny () && port != 0) - { - m_endPoint = m_udp->Allocate (ipv4, port); - } + InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); + Ipv4Address ipv4 = transport.GetIpv4 (); + uint16_t port = transport.GetPort (); + if (ipv4 == Ipv4Address::GetAny () && port == 0) + { + m_endPoint = m_udp->Allocate (); + } + else if (ipv4 == Ipv4Address::GetAny () && port != 0) + { + m_endPoint = m_udp->Allocate (port); + } + else if (ipv4 != Ipv4Address::GetAny () && port == 0) + { + m_endPoint = m_udp->Allocate (ipv4); + } + else if (ipv4 != Ipv4Address::GetAny () && port != 0) + { + m_endPoint = m_udp->Allocate (ipv4, port); + } } else if (Inet6SocketAddress::IsMatchingType (address)) { @@ -310,11 +310,11 @@ UdpSocketImpl::Connect (const Address & address) NS_LOG_FUNCTION (this << address); if (InetSocketAddress::IsMatchingType(address) == true) { - InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); + InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); m_defaultAddress = Address(transport.GetIpv4 ()); - m_defaultPort = transport.GetPort (); - m_connected = true; - NotifyConnectionSucceeded (); + m_defaultPort = transport.GetPort (); + m_connected = true; + NotifyConnectionSucceeded (); } else if (Inet6SocketAddress::IsMatchingType(address) == true) { @@ -393,11 +393,11 @@ UdpSocketImpl::DoSendTo (Ptr p, const Address &address) NS_LOG_LOGIC ("Not connected"); if (InetSocketAddress::IsMatchingType(address) == true) { - InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); - Ipv4Address ipv4 = transport.GetIpv4 (); - uint16_t port = transport.GetPort (); - return DoSendTo (p, ipv4, port); - } + InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); + Ipv4Address ipv4 = transport.GetIpv4 (); + uint16_t port = transport.GetPort (); + return DoSendTo (p, ipv4, port); + } else if (Inet6SocketAddress::IsMatchingType(address) == true) { Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address); @@ -405,8 +405,8 @@ UdpSocketImpl::DoSendTo (Ptr p, const Address &address) uint16_t port = transport.GetPort (); return DoSendTo (p, ipv6, port); } - else - { + else + { return -1; } } @@ -417,11 +417,11 @@ UdpSocketImpl::DoSendTo (Ptr p, const Address &address) if (Ipv4Address::IsMatchingType(m_defaultAddress)) { return DoSendTo (p, Ipv4Address::ConvertFrom(m_defaultAddress), m_defaultPort); - } + } else if (Ipv6Address::IsMatchingType(m_defaultAddress)) { return DoSendTo (p, Ipv6Address::ConvertFrom(m_defaultAddress), m_defaultPort); - } +} } m_errno = ERROR_AFNOSUPPORT; return(-1); @@ -468,28 +468,29 @@ UdpSocketImpl::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) // the same as a unicast, but it will be fixed further down the stack if (m_ipMulticastTtl != 0 && dest.IsMulticast ()) { - SocketIpTtlTag tag; - tag.SetTtl (m_ipMulticastTtl); + Ptr tag = CreateObject (); + tag->SetTtl (m_ipMulticastTtl); p->AddPacketTag (tag); } else if (m_ipTtl != 0 && !dest.IsMulticast () && !dest.IsBroadcast ()) { - SocketIpTtlTag tag; - tag.SetTtl (m_ipTtl); + Ptr tag = CreateObject (); + tag->SetTtl (m_ipTtl); p->AddPacketTag (tag); } { - SocketSetDontFragmentTag tag; - bool found = p->RemovePacketTag (tag); - if (!found) + + // !!! Previously, header was removed, checked, but never added back. Guess, this was wrong + if (p->PeekPacketTag () == 0) { + Ptr tag = CreateObject (); if (m_mtuDiscover) { - tag.Enable (); + tag->Enable (); } else { - tag.Disable (); + tag->Disable (); } p->AddPacketTag (tag); } @@ -656,14 +657,14 @@ UdpSocketImpl::DoSendTo (Ptr p, Ipv6Address dest, uint16_t port) // the same as a unicast, but it will be fixed further down the stack if (m_ipMulticastTtl != 0 && dest.IsMulticast ()) { - SocketIpTtlTag tag; - tag.SetTtl (m_ipMulticastTtl); + Ptr tag = CreateObject (); + tag->SetTtl (m_ipMulticastTtl); p->AddPacketTag (tag); } else if (m_ipTtl != 0 && !dest.IsMulticast ()) { - SocketIpTtlTag tag; - tag.SetTtl (m_ipTtl); + Ptr tag = CreateObject (); + tag->SetTtl (m_ipTtl); p->AddPacketTag (tag); } // There is no analgous to an IPv4 broadcast address in IPv6. @@ -734,11 +735,11 @@ UdpSocketImpl::SendTo (Ptr p, uint32_t flags, const Address &address) NS_LOG_FUNCTION (this << p << flags << address); if (InetSocketAddress::IsMatchingType (address)) { - InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); - Ipv4Address ipv4 = transport.GetIpv4 (); - uint16_t port = transport.GetPort (); - return DoSendTo (p, ipv4, port); - } + InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); + Ipv4Address ipv4 = transport.GetIpv4 (); + uint16_t port = transport.GetPort (); + return DoSendTo (p, ipv4, port); +} else if (Inet6SocketAddress::IsMatchingType (address)) { Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address); @@ -788,11 +789,9 @@ UdpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, Ptr packet = Recv (maxSize, flags); if (packet != 0) { - SocketAddressTag tag; - bool found; - found = packet->PeekPacketTag (tag); - NS_ASSERT (found); - fromAddress = tag.GetAddress (); + Ptr tag = packet->PeekPacketTag (); + NS_ASSERT (tag != 0); + fromAddress = tag->GetAddress (); } return packet; } @@ -874,17 +873,17 @@ UdpSocketImpl::ForwardUp (Ptr packet, Ipv4Header header, uint16_t port, // Should check via getsockopt ().. if (IsRecvPktInfo ()) { - Ipv4PacketInfoTag tag; - packet->RemovePacketTag (tag); - tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ()); + Ptr origTag = packet->RemovePacketTag (); + Ptr tag = CreateObject (*origTag); + tag->SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ()); packet->AddPacketTag (tag); } if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize) { Address address = InetSocketAddress (header.GetSource (), port); - SocketAddressTag tag; - tag.SetAddress (address); + Ptr tag = CreateObject (); + tag->SetAddress (address); packet->AddPacketTag (tag); m_deliveryQueue.push (packet); m_rxAvailable += packet->GetSize (); @@ -902,7 +901,7 @@ UdpSocketImpl::ForwardUp (Ptr packet, Ipv4Header header, uint16_t port, } } -void +void UdpSocketImpl::ForwardUp6 (Ptr packet, Ipv6Address saddr, Ipv6Address daddr, uint16_t port) { NS_LOG_FUNCTION (this << packet << saddr << port); @@ -915,8 +914,8 @@ UdpSocketImpl::ForwardUp6 (Ptr packet, Ipv6Address saddr, Ipv6Address da if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize) { Address address = Inet6SocketAddress (saddr, port); - SocketAddressTag tag; - tag.SetAddress (address); + Ptr tag = CreateObject (); + tag->SetAddress (address); packet->AddPacketTag (tag); m_deliveryQueue.push (packet); m_rxAvailable += packet->GetSize (); diff --git a/src/mesh/model/dot11s/hwmp-protocol-mac.cc b/src/mesh/model/dot11s/hwmp-protocol-mac.cc index a4d140d..49f30c6 100644 --- a/src/mesh/model/dot11s/hwmp-protocol-mac.cc +++ b/src/mesh/model/dot11s/hwmp-protocol-mac.cc @@ -55,8 +55,7 @@ HwmpProtocolMac::ReceiveData (Ptr packet, const WifiMacHeader & header) NS_ASSERT (header.IsData ()); MeshHeader meshHdr; - HwmpTag tag; - if (packet->PeekPacketTag (tag)) + if (packet->PeekPacketTag () != 0) { NS_FATAL_ERROR ("HWMP tag is not supposed to be received by network"); } @@ -78,8 +77,9 @@ HwmpProtocolMac::ReceiveData (Ptr packet, const WifiMacHeader & header) NS_FATAL_ERROR ( "6-address scheme is not yet supported and 4-address extension is not supposed to be used for data frames."); } - tag.SetSeqno (meshHdr.GetMeshSeqno ()); - tag.SetTtl (meshHdr.GetMeshTtl ()); + Ptr tag = CreateObject (); + tag->SetSeqno (meshHdr.GetMeshSeqno ()); + tag->SetTtl (meshHdr.GetMeshTtl ()); packet->AddPacketTag (tag); if ((destination == Mac48Address::GetBroadcast ()) && (m_protocol->DropDataFrame (meshHdr.GetMeshSeqno (), @@ -188,19 +188,18 @@ HwmpProtocolMac::UpdateOutcomingFrame (Ptr packet, WifiMacHeader & heade { return true; } - HwmpTag tag; - bool tagExists = packet->RemovePacketTag (tag); - if (!tagExists) + Ptr tag = packet->RemovePacketTag (); + if (tag == 0) { NS_FATAL_ERROR ("HWMP tag must exist at this point"); } m_stats.txData++; m_stats.txDataBytes += packet->GetSize (); MeshHeader meshHdr; - meshHdr.SetMeshSeqno (tag.GetSeqno ()); - meshHdr.SetMeshTtl (tag.GetTtl ()); + meshHdr.SetMeshSeqno (tag->GetSeqno ()); + meshHdr.SetMeshTtl (tag->GetTtl ()); packet->AddHeader (meshHdr); - header.SetAddr1 (tag.GetAddress ()); + header.SetAddr1 (tag->GetAddress ()); return true; } WifiActionHeader diff --git a/src/mesh/model/dot11s/hwmp-protocol.cc b/src/mesh/model/dot11s/hwmp-protocol.cc index c0973ab..ff5d89d 100644 --- a/src/mesh/model/dot11s/hwmp-protocol.cc +++ b/src/mesh/model/dot11s/hwmp-protocol.cc @@ -233,29 +233,32 @@ HwmpProtocol::RequestRoute ( ) { Ptr packet = constPacket->Copy (); - HwmpTag tag; + Ptr tag = 0; if (sourceIface == GetMeshPoint ()->GetIfIndex ()) { // packet from level 3 - if (packet->PeekPacketTag (tag)) + if (packet->PeekPacketTag () != 0) { NS_FATAL_ERROR ("HWMP tag has come with a packet from upper layer. This must not occur..."); } + tag = CreateObject (); //Filling TAG: if (destination == Mac48Address::GetBroadcast ()) { - tag.SetSeqno (m_dataSeqno++); + tag->SetSeqno (m_dataSeqno++); } - tag.SetTtl (m_maxTtl); + tag->SetTtl (m_maxTtl); } else { - if (!packet->RemovePacketTag (tag)) + Ptr origTag = packet->RemovePacketTag (); + if (!packet->RemovePacketTag ()) { NS_FATAL_ERROR ("HWMP tag is supposed to be here at this point."); } - tag.DecrementTtl (); - if (tag.GetTtl () == 0) + tag = CreateObject (*origTag); + tag->DecrementTtl (); + if (tag->GetTtl () == 0) { m_stats.droppedTtl++; return false; @@ -287,11 +290,11 @@ HwmpProtocol::RequestRoute ( { Ptr packetCopy = packet->Copy (); // - // 64-bit Intel valgrind complains about tag.SetAddress (*i). It + // 64-bit Intel valgrind complains about tag->SetAddress (*i). It // likes this just fine. // Mac48Address address = *i; - tag.SetAddress (address); + tag->SetAddress (address); packetCopy->AddPacketTag (tag); routeReply (true, packetCopy, source, destination, protocolType, plugin->first); } @@ -299,7 +302,7 @@ HwmpProtocol::RequestRoute ( } else { - return ForwardUnicast (sourceIface, source, destination, packet, protocolType, routeReply, tag.GetTtl ()); + return ForwardUnicast (sourceIface, source, destination, packet, protocolType, routeReply, tag->GetTtl ()); } return true; } @@ -307,8 +310,8 @@ bool HwmpProtocol::RemoveRoutingStuff (uint32_t fromIface, const Mac48Address source, const Mac48Address destination, Ptr packet, uint16_t& protocolType) { - HwmpTag tag; - if (!packet->RemovePacketTag (tag)) + Ptr tag = packet->RemovePacketTag (); + if (tag == 0) { NS_FATAL_ERROR ("HWMP tag must exist when packet received from the network"); } @@ -325,9 +328,9 @@ HwmpProtocol::ForwardUnicast (uint32_t sourceIface, const Mac48Address source, { result = m_rtable->LookupProactive (); } - HwmpTag tag; - tag.SetAddress (result.retransmitter); - tag.SetTtl (ttl); + Ptr tag = CreateObject (); + tag->SetAddress (result.retransmitter); + tag->SetTtl (ttl); //seqno and metric is not used; packet->AddPacketTag (tag); if (result.retransmitter != Mac48Address::GetBroadcast ()) @@ -921,9 +924,13 @@ HwmpProtocol::ReactivePathResolved (Mac48Address dst) while (packet.pkt != 0) { //set RA tag for retransmitter: - HwmpTag tag; - packet.pkt->RemovePacketTag (tag); - tag.SetAddress (result.retransmitter); + Ptr origTag = packet.pkt->RemovePacketTag (); + if (origTag == 0) + { + NS_FATAL_ERROR ("HWMP tag must be present at this point"); + } + Ptr tag = CreateObject (*origTag); + tag->SetAddress (result.retransmitter); packet.pkt->AddPacketTag (tag); m_stats.txUnicast++; m_stats.txBytes += packet.pkt->GetSize (); @@ -942,12 +949,13 @@ HwmpProtocol::ProactivePathResolved () while (packet.pkt != 0) { //set RA tag for retransmitter: - HwmpTag tag; - if (!packet.pkt->RemovePacketTag (tag)) + Ptr origTag = packet.pkt->RemovePacketTag (); + if (origTag == 0) { NS_FATAL_ERROR ("HWMP tag must be present at this point"); } - tag.SetAddress (result.retransmitter); + Ptr tag = CreateObject (*origTag); + tag->SetAddress (result.retransmitter); packet.pkt->AddPacketTag (tag); m_stats.txUnicast++; m_stats.txBytes += packet.pkt->GetSize (); diff --git a/src/mesh/model/dot11s/hwmp-tag.cc b/src/mesh/model/dot11s/hwmp-tag.cc index 88fe7fd..32a0579 100644 --- a/src/mesh/model/dot11s/hwmp-tag.cc +++ b/src/mesh/model/dot11s/hwmp-tag.cc @@ -41,7 +41,7 @@ HwmpTag::SetAddress (Mac48Address retransmitter) } Mac48Address -HwmpTag::GetAddress () +HwmpTag::GetAddress () const { return m_address; } @@ -53,7 +53,7 @@ HwmpTag::SetTtl (uint8_t ttl) } uint8_t -HwmpTag::GetTtl () +HwmpTag::GetTtl () const { return m_ttl; } @@ -65,7 +65,7 @@ HwmpTag::SetMetric (uint32_t metric) } uint32_t -HwmpTag::GetMetric () +HwmpTag::GetMetric () const { return m_metric; } @@ -77,7 +77,7 @@ HwmpTag::SetSeqno (uint32_t seqno) } uint32_t -HwmpTag::GetSeqno () +HwmpTag::GetSeqno () const { return m_seqno; } diff --git a/src/mesh/model/dot11s/hwmp-tag.h b/src/mesh/model/dot11s/hwmp-tag.h index 127d0f2..0f282e0 100644 --- a/src/mesh/model/dot11s/hwmp-tag.h +++ b/src/mesh/model/dot11s/hwmp-tag.h @@ -51,13 +51,13 @@ public: HwmpTag (); ~HwmpTag (); void SetAddress (Mac48Address retransmitter); - Mac48Address GetAddress (); + Mac48Address GetAddress () const; void SetTtl (uint8_t ttl); - uint8_t GetTtl (); + uint8_t GetTtl () const; void SetMetric (uint32_t metric); - uint32_t GetMetric (); + uint32_t GetMetric () const; void SetSeqno (uint32_t seqno); - uint32_t GetSeqno (); + uint32_t GetSeqno () const; void DecrementTtl (); static TypeId GetTypeId (); diff --git a/src/mesh/model/flame/flame-protocol-mac.cc b/src/mesh/model/flame/flame-protocol-mac.cc index 8106610..9517498 100644 --- a/src/mesh/model/flame/flame-protocol-mac.cc +++ b/src/mesh/model/flame/flame-protocol-mac.cc @@ -47,14 +47,14 @@ FlameProtocolMac::Receive (Ptr packet, const WifiMacHeader & header) { return true; } - FlameTag tag; - if (packet->PeekPacketTag (tag)) + if (packet->PeekPacketTag () != 0) { NS_FATAL_ERROR ("FLAME tag is not supposed to be received by network"); } - tag.receiver = header.GetAddr1 (); - tag.transmitter = header.GetAddr2 (); - if (tag.receiver == Mac48Address::GetBroadcast ()) + Ptr tag = CreateObject (); + tag->receiver = header.GetAddr1 (); + tag->transmitter = header.GetAddr2 (); + if (tag->receiver == Mac48Address::GetBroadcast ()) { m_stats.rxBroadcast++; } @@ -74,13 +74,13 @@ FlameProtocolMac::UpdateOutcomingFrame (Ptr packet, WifiMacHeader & head { return true; } - FlameTag tag; - if (!packet->RemovePacketTag (tag)) + Ptr tag = packet->RemovePacketTag (); + if (tag == 0) { NS_FATAL_ERROR ("FLAME tag must exist here"); } - header.SetAddr1 (tag.receiver); - if (tag.receiver == Mac48Address::GetBroadcast ()) + header.SetAddr1 (tag->receiver); + if (tag->receiver == Mac48Address::GetBroadcast ()) { m_stats.txBroadcast++; } diff --git a/src/mesh/model/flame/flame-protocol.cc b/src/mesh/model/flame/flame-protocol.cc index e900a19..49baf38 100644 --- a/src/mesh/model/flame/flame-protocol.cc +++ b/src/mesh/model/flame/flame-protocol.cc @@ -150,8 +150,7 @@ FlameProtocol::RequestRoute (uint32_t sourceIface, const Mac48Address source, co if (sourceIface == m_mp->GetIfIndex ()) { //Packet from upper layer! - FlameTag tag; - if (packet->PeekPacketTag (tag)) + if (packet->PeekPacketTag () != 0) { NS_FATAL_ERROR ("FLAME tag is not supposed to be received from upper layers"); } @@ -174,7 +173,8 @@ FlameProtocol::RequestRoute (uint32_t sourceIface, const Mac48Address source, co flameHdr.SetOrigSrc (source); m_stats.txBytes += packet->GetSize (); packet->AddHeader (flameHdr); - tag.receiver = result.retransmitter; + Ptr tag = CreateObject (); + tag->receiver = result.retransmitter; if (result.retransmitter == Mac48Address::GetBroadcast ()) { m_stats.txBroadcast++; @@ -183,7 +183,7 @@ FlameProtocol::RequestRoute (uint32_t sourceIface, const Mac48Address source, co { m_stats.txUnicast++; } - NS_LOG_DEBUG ("Source: send packet with RA = " << tag.receiver); + NS_LOG_DEBUG ("Source: send packet with RA = " << tag->receiver); packet->AddPacketTag (tag); routeReply (true, packet, source, destination, FLAME_PROTOCOL, result.ifIndex); } @@ -191,17 +191,18 @@ FlameProtocol::RequestRoute (uint32_t sourceIface, const Mac48Address source, co { FlameHeader flameHdr; packet->RemoveHeader (flameHdr); - FlameTag tag; - if (!packet->RemovePacketTag (tag)) + Ptr origTag = packet->RemovePacketTag (); + if (origTag == 0) { NS_FATAL_ERROR ("FLAME tag must exist here"); } + if (destination == Mac48Address::GetBroadcast ()) { //Broadcast always is forwarded as broadcast! - NS_ASSERT (HandleDataFrame (flameHdr.GetSeqno (), source, flameHdr, tag.transmitter, sourceIface)); - FlameTag tag (Mac48Address::GetBroadcast ()); + NS_ASSERT (HandleDataFrame (flameHdr.GetSeqno (), source, flameHdr, origTag->transmitter, sourceIface)); + Ptr tag = CreateObject (Mac48Address::GetBroadcast ()); flameHdr.AddCost (1); m_stats.txBytes += packet->GetSize (); packet->AddHeader (flameHdr); @@ -212,27 +213,28 @@ FlameProtocol::RequestRoute (uint32_t sourceIface, const Mac48Address source, co } else { + Ptr tag = CreateObject (*origTag); // We check sequence only when forward unicast, because broadcast-checks were done // inside remove routing stuff. - if (HandleDataFrame (flameHdr.GetSeqno (), source, flameHdr, tag.transmitter, sourceIface)) + if (HandleDataFrame (flameHdr.GetSeqno (), source, flameHdr, tag->transmitter, sourceIface)) { return false; } FlameRtable::LookupResult result = m_rtable->Lookup (destination); - if (tag.receiver != Mac48Address::GetBroadcast ()) + if (origTag->receiver != Mac48Address::GetBroadcast ()) { if (result.retransmitter == Mac48Address::GetBroadcast ()) { NS_LOG_DEBUG ("unicast packet dropped, because no route! I am " << GetAddress () - << ", RA = " << tag.receiver << ", TA = " << tag.transmitter); + << ", RA = " << origTag->receiver << ", TA = " << origTag->transmitter); m_stats.totalDropped++; return false; } - tag.receiver = result.retransmitter; + tag->receiver = result.retransmitter; } else { - tag.receiver = Mac48Address::GetBroadcast (); + tag->receiver = Mac48Address::GetBroadcast (); } if (result.retransmitter == Mac48Address::GetBroadcast ()) { @@ -263,14 +265,14 @@ FlameProtocol::RemoveRoutingStuff (uint32_t fromIface, const Mac48Address source NS_LOG_DEBUG ("Dropped my own frame!"); return false; } - FlameTag tag; - if (!packet->RemovePacketTag (tag)) + Ptr tag = packet->RemovePacketTag (); + if (tag == 0) { NS_FATAL_ERROR ("FLAME tag must exist when packet is coming to protocol"); } FlameHeader flameHdr; packet->RemoveHeader (flameHdr); - if (HandleDataFrame (flameHdr.GetSeqno (), source, flameHdr, tag.transmitter, fromIface)) + if (HandleDataFrame (flameHdr.GetSeqno (), source, flameHdr, tag->transmitter, fromIface)) { return false; } diff --git a/src/mesh/model/mesh-wifi-interface-mac.cc b/src/mesh/model/mesh-wifi-interface-mac.cc index 1f46d3e..950f9bd 100644 --- a/src/mesh/model/mesh-wifi-interface-mac.cc +++ b/src/mesh/model/mesh-wifi-interface-mac.cc @@ -222,15 +222,15 @@ MeshWifiInterfaceMac::ForwardDown (Ptr const_packet, Mac48Address //Classify: application sets a tag, which is removed here // Get Qos tag: AcIndex ac = AC_BE; - QosTag tag; - if (packet->RemovePacketTag (tag)) + Ptr tag = packet->RemovePacketTag (); + if (tag != 0) { hdr.SetType (WIFI_MAC_QOSDATA); - hdr.SetQosTid (tag.GetTid ()); + hdr.SetQosTid (tag->GetTid ()); //Aftre setting type DsFrom and DsTo fields are reset. hdr.SetDsFrom (); hdr.SetDsTo (); - ac = QosUtilsMapTidToAc (tag.GetTid ()); + ac = QosUtilsMapTidToAc (tag->GetTid ()); } m_stats.sentFrames++; m_stats.sentBytes += packet->GetSize (); @@ -446,7 +446,7 @@ MeshWifiInterfaceMac::Receive (Ptr packet, WifiMacHeader const *hdr) // Check if QoS tag exists and add it: if (hdr->IsQosData ()) { - packet->AddPacketTag (QosTag (hdr->GetQosTid ())); + packet->AddPacketTag (CreateObject (hdr->GetQosTid ())); } // Forward data up if (hdr->IsData ()) diff --git a/src/network/examples/main-packet-tag.cc b/src/network/examples/main-packet-tag.cc index b0598bf..37c9115 100644 --- a/src/network/examples/main-packet-tag.cc +++ b/src/network/examples/main-packet-tag.cc @@ -96,8 +96,8 @@ MyTag::GetSimpleValue (void) const int main (int argc, char *argv[]) { // create a tag. - MyTag tag; - tag.SetSimpleValue (0x56); + Ptr tag = CreateObject (); + tag->SetSimpleValue (0x56); // store the tag in a packet. Ptr p = Create (100); @@ -107,11 +107,10 @@ int main (int argc, char *argv[]) Ptr aCopy = p->Copy (); // read the tag from the packet copy - MyTag tagCopy; - p->PeekPacketTag (tagCopy); + Ptr tagCopy = p->PeekPacketTag (); // the copy and the original are the same ! - NS_ASSERT (tagCopy.GetSimpleValue () == tag.GetSimpleValue ()); + NS_ASSERT (tagCopy->GetSimpleValue () == tag->GetSimpleValue ()); aCopy->PrintPacketTags (std::cout); std::cout << std::endl; diff --git a/src/network/model/packet-tag-list.cc b/src/network/model/packet-tag-list.cc index c311a0f..a758b29 100644 --- a/src/network/model/packet-tag-list.cc +++ b/src/network/model/packet-tag-list.cc @@ -28,150 +28,146 @@ NS_LOG_COMPONENT_DEFINE ("PacketTagList"); namespace ns3 { -#ifdef USE_FREE_LIST - -struct PacketTagList::TagData *PacketTagList::g_free = 0; -uint32_t PacketTagList::g_nfree = 0; - -struct PacketTagList::TagData * -PacketTagList::AllocData (void) const -{ - NS_LOG_FUNCTION (g_nfree); - struct PacketTagList::TagData *retval; - if (g_free != 0) - { - retval = g_free; - g_free = g_free->m_next; - g_nfree--; - } - else - { - retval = new struct PacketTagList::TagData (); - } - return retval; -} - void -PacketTagList::FreeData (struct TagData *data) const -{ - NS_LOG_FUNCTION (g_nfree << data); - if (g_nfree > 1000) - { - delete data; - return; - } - g_nfree++; - data->next = g_free; - data->tid = TypeId (); - g_free = data; -} -#else -struct PacketTagList::TagData * -PacketTagList::AllocData (void) const +PacketTagList::Add (Ptr tag) { - NS_LOG_FUNCTION_NOARGS (); - struct PacketTagList::TagData *retval; - retval = new struct PacketTagList::TagData (); - return retval; -} + NS_LOG_FUNCTION (this << tag->GetInstanceTypeId ()); -void -PacketTagList::FreeData (struct TagData *data) const -{ - NS_LOG_FUNCTION (data); - delete data; + NS_ASSERT_MSG (Peek (tag->GetInstanceTypeId ()) == 0, + "Only one tag type per packet is allowed"); + + push_back (tag); } -#endif -bool -PacketTagList::Remove (Tag &tag) +Ptr +PacketTagList::Remove (TypeId tagType) { - NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ()); - TypeId tid = tag.GetInstanceTypeId (); - bool found = false; - for (struct TagData *cur = m_next; cur != 0; cur = cur->next) - { - if (cur->tid == tid) - { - found = true; - tag.Deserialize (TagBuffer (cur->data, cur->data+PACKET_TAG_MAX_SIZE)); - } - } - if (!found) + NS_LOG_FUNCTION (this << tagType); + + for (iterator tag = begin (); tag != end (); tag++) { - return false; - } - struct TagData *start = 0; - struct TagData **prevNext = &start; - for (struct TagData *cur = m_next; cur != 0; cur = cur->next) - { - if (cur->tid == tid) + if ((*tag)->GetInstanceTypeId () == tagType) { - /** - * XXX - * Note: I believe that we could optimize this to - * avoid copying each TagData located after the target id - * and just link the already-copied list to the next tag. - */ - continue; + Ptr retval = *tag; + erase (tag); + return retval; } - struct TagData *copy = AllocData (); - copy->tid = cur->tid; - copy->count = 1; - copy->next = 0; - memcpy (copy->data, cur->data, PACKET_TAG_MAX_SIZE); - *prevNext = copy; - prevNext = ©->next; } - *prevNext = 0; - RemoveAll (); - m_next = start; - return true; -} -void -PacketTagList::Add (const Tag &tag) const -{ - NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ()); - // ensure this id was not yet added - for (struct TagData *cur = m_next; cur != 0; cur = cur->next) - { - NS_ASSERT (cur->tid != tag.GetInstanceTypeId ()); - } - struct TagData *head = AllocData (); - head->count = 1; - head->next = 0; - head->tid = tag.GetInstanceTypeId (); - head->next = m_next; - NS_ASSERT (tag.GetSerializedSize () <= PACKET_TAG_MAX_SIZE); - tag.Serialize (TagBuffer (head->data, head->data+tag.GetSerializedSize ())); - - const_cast (this)->m_next = head; + return 0; } -bool -PacketTagList::Peek (Tag &tag) const +Ptr +PacketTagList::Peek (TypeId tagType) const { - NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ()); - TypeId tid = tag.GetInstanceTypeId (); - for (struct TagData *cur = m_next; cur != 0; cur = cur->next) + NS_LOG_FUNCTION (this << tagType); + for (const_iterator tag = begin (); tag != end (); tag++) { - if (cur->tid == tid) - { - /* found tag */ - tag.Deserialize (TagBuffer (cur->data, cur->data+PACKET_TAG_MAX_SIZE)); - return true; - } + if ((*tag)->GetInstanceTypeId () == tagType) + return *tag; } - /* no tag found */ - return false; -} -const struct PacketTagList::TagData * -PacketTagList::Head (void) const -{ - return m_next; + return 0; } + +// bool +// PacketTagList::Remove (Tag &tag) +// { +// NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ()); + +// return false; + +// // TypeId tid = tag.GetInstanceTypeId (); +// // bool found = false; +// // for (struct TagData *cur = m_next; cur != 0; cur = cur->next) +// // { +// // if (cur->tid == tid) +// // { +// // found = true; +// // tag.Deserialize (TagBuffer (cur->data, cur->data+PACKET_TAG_MAX_SIZE)); +// // } +// // } +// // if (!found) +// // { +// // return false; +// // } +// // struct TagData *start = 0; +// // struct TagData **prevNext = &start; +// // for (struct TagData *cur = m_next; cur != 0; cur = cur->next) +// // { +// // if (cur->tid == tid) +// // { +// // /** +// // * XXX +// // * Note: I believe that we could optimize this to +// // * avoid copying each TagData located after the target id +// // * and just link the already-copied list to the next tag. +// // */ +// // continue; +// // } +// // struct TagData *copy = AllocData (); +// // copy->tid = cur->tid; +// // copy->count = 1; +// // copy->next = 0; +// // memcpy (copy->data, cur->data, PACKET_TAG_MAX_SIZE); +// // *prevNext = copy; +// // prevNext = ©->next; +// // } +// // *prevNext = 0; +// // RemoveAll (); +// // m_next = start; +// // return true; +// } + +// void +// PacketTagList::Add (const Tag &tag) const +// { +// NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ()); +// // ensure this id was not yet added + +// // for (struct TagData *cur = m_next; cur != 0; cur = cur->next) +// // { +// // NS_ASSERT (cur->tid != tag.GetInstanceTypeId ()); +// // } + +// // struct TagData *head = AllocData (); +// // head->count = 1; +// // head->next = 0; +// // head->tid = tag.GetInstanceTypeId (); +// // head->next = m_next; +// // NS_ASSERT (tag.GetSerializedSize () <= PACKET_TAG_MAX_SIZE); +// // tag.Serialize (TagBuffer (head->data, head->data+tag.GetSerializedSize ())); + +// // const_cast (this)->m_next = head; + +// // m_tags. +// } + +// bool +// PacketTagList::Peek (Tag &tag) const +// { +// NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ()); +// // TypeId tid = tag.GetInstanceTypeId (); +// // for (struct TagData *cur = m_next; cur != 0; cur = cur->next) +// // { +// // if (cur->tid == tid) +// // { +// // /* found tag */ +// // tag.Deserialize (TagBuffer (cur->data, cur->data+PACKET_TAG_MAX_SIZE)); +// // return true; +// // } +// // } + +// /* no tag found */ +// return false; +// } + +// // const struct PacketTagList::TagData * +// // PacketTagList::Head (void) const +// // { +// // return m_next; +// // } + } // namespace ns3 diff --git a/src/network/model/packet-tag-list.h b/src/network/model/packet-tag-list.h index 838e847..270ddff 100644 --- a/src/network/model/packet-tag-list.h +++ b/src/network/model/packet-tag-list.h @@ -21,7 +21,7 @@ #define PACKET_TAG_LIST_H #include -#include +#include #include "ns3/type-id.h" namespace ns3 { @@ -34,40 +34,30 @@ class Tag; * The maximum size (in bytes) of a Tag is stored * in this constant. */ -#define PACKET_TAG_MAX_SIZE 20 +// #define PACKET_TAG_MAX_SIZE 20 -class PacketTagList +class PacketTagList : public std::list > { public: - struct TagData { - uint8_t data[PACKET_TAG_MAX_SIZE]; - struct TagData *next; - TypeId tid; - uint32_t count; - }; + // struct TagData { + // std::vector data; + // TypeId tid; + // uint32_t count; + // }; - inline PacketTagList (); - inline PacketTagList (PacketTagList const &o); - inline PacketTagList &operator = (PacketTagList const &o); - inline ~PacketTagList (); + // inline PacketTagList (); + // inline PacketTagList (PacketTagList const &o); + // inline PacketTagList &operator = (PacketTagList const &o); + // inline ~PacketTagList (); - void Add (Tag const&tag) const; - bool Remove (Tag &tag); - bool Peek (Tag &tag) const; - inline void RemoveAll (void); + void + Add (Ptr tag); - const struct PacketTagList::TagData *Head (void) const; + Ptr + Remove (TypeId tagType); -private: - - bool Remove (TypeId tid); - struct PacketTagList::TagData *AllocData (void) const; - void FreeData (struct TagData *data) const; - - static struct PacketTagList::TagData *g_free; - static uint32_t g_nfree; - - struct TagData *m_next; + Ptr + Peek (TypeId tagType) const; }; } // namespace ns3 @@ -78,65 +68,38 @@ private: namespace ns3 { -PacketTagList::PacketTagList () - : m_next () -{ -} - -PacketTagList::PacketTagList (PacketTagList const &o) - : m_next (o.m_next) -{ - if (m_next != 0) - { - m_next->count++; - } -} - -PacketTagList & -PacketTagList::operator = (PacketTagList const &o) -{ - // self assignment - if (m_next == o.m_next) - { - return *this; - } - RemoveAll (); - m_next = o.m_next; - if (m_next != 0) - { - m_next->count++; - } - return *this; -} - -PacketTagList::~PacketTagList () -{ - RemoveAll (); -} - -void -PacketTagList::RemoveAll (void) -{ - struct TagData *prev = 0; - for (struct TagData *cur = m_next; cur != 0; cur = cur->next) - { - cur->count--; - if (cur->count > 0) - { - break; - } - if (prev != 0) - { - FreeData (prev); - } - prev = cur; - } - if (prev != 0) - { - FreeData (prev); - } - m_next = 0; -} +// PacketTagList::PacketTagList () +// { +// } + +// PacketTagList::PacketTagList (PacketTagList const &o) +// : m_tags (o.m_tags) +// { +// } + +// PacketTagList & +// PacketTagList::operator = (PacketTagList const &o) +// { +// // self assignment +// if (&o == this) +// { +// return *this; +// } +// // RemoveAll (); // ??? +// m_tags = o.m_tags; +// return *this; +// } + +// PacketTagList::~PacketTagList () +// { +// RemoveAll (); +// } + +// void +// PacketTagList::RemoveAll (void) +// { +// m_tags.clear (); +// } } // namespace ns3 diff --git a/src/network/model/packet.cc b/src/network/model/packet.cc index 72ccc94..62aba0f 100644 --- a/src/network/model/packet.cc +++ b/src/network/model/packet.cc @@ -81,39 +81,39 @@ ByteTagIterator::ByteTagIterator (ByteTagList::Iterator i) } -PacketTagIterator::PacketTagIterator (const struct PacketTagList::TagData *head) - : m_current (head) -{ -} -bool -PacketTagIterator::HasNext (void) const -{ - return m_current != 0; -} -PacketTagIterator::Item -PacketTagIterator::Next (void) -{ - NS_ASSERT (HasNext ()); - const struct PacketTagList::TagData *prev = m_current; - m_current = m_current->next; - return PacketTagIterator::Item (prev); -} - -PacketTagIterator::Item::Item (const struct PacketTagList::TagData *data) - : m_data (data) -{ -} -TypeId -PacketTagIterator::Item::GetTypeId (void) const -{ - return m_data->tid; -} -void -PacketTagIterator::Item::GetTag (Tag &tag) const -{ - NS_ASSERT (tag.GetInstanceTypeId () == m_data->tid); - tag.Deserialize (TagBuffer ((uint8_t*)m_data->data, (uint8_t*)m_data->data+PACKET_TAG_MAX_SIZE)); -} +// PacketTagIterator::PacketTagIterator (const struct PacketTagList::TagData *head) +// : m_current (head) +// { +// } +// bool +// PacketTagIterator::HasNext (void) const +// { +// return m_current != 0; +// } +// PacketTagIterator::Item +// PacketTagIterator::Next (void) +// { +// NS_ASSERT (HasNext ()); +// const struct PacketTagList::TagData *prev = m_current; +// m_current = m_current->next; +// return PacketTagIterator::Item (prev); +// } + +// PacketTagIterator::Item::Item (const struct PacketTagList::TagData *data) +// : m_data (data) +// { +// } +// TypeId +// PacketTagIterator::Item::GetTypeId (void) const +// { +// return m_data->tid; +// } +// void +// PacketTagIterator::Item::GetTag (Tag &tag) const +// { +// NS_ASSERT (tag.GetInstanceTypeId () == m_data->tid); +// tag.Deserialize (TagBuffer ((uint8_t*)m_data->data, (uint8_t*)m_data->data+PACKET_TAG_MAX_SIZE)); +// } Ptr @@ -835,60 +835,90 @@ Packet::FindFirstMatchingByteTag (Tag &tag) const return false; } -void -Packet::AddPacketTag (const Tag &tag) const +// void +// Packet::AddPacketTag (const Tag &tag) const +// { +// NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ()); +// m_packetTagList.Add (tag); +// } +// bool +// Packet::RemovePacketTag (Tag &tag) +// { +// NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ()); +// bool found = m_packetTagList.Remove (tag); +// return found; +// } +// bool +// Packet::PeekPacketTag (Tag &tag) const +// { +// bool found = m_packetTagList.Peek (tag); +// return found; +// } + +void +Packet::AddPacketTag (Ptr tag) { - NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ()); m_packetTagList.Add (tag); } -bool -Packet::RemovePacketTag (Tag &tag) + +Ptr +Packet::RemovePacketTag (TypeId tagType) { - NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ()); - bool found = m_packetTagList.Remove (tag); - return found; + return m_packetTagList.Remove (tagType); } -bool -Packet::PeekPacketTag (Tag &tag) const + +Ptr +Packet::PeekPacketTag (TypeId tagType) const { - bool found = m_packetTagList.Peek (tag); - return found; + return m_packetTagList.Peek (tagType); } + void Packet::RemoveAllPacketTags (void) { NS_LOG_FUNCTION (this); - m_packetTagList.RemoveAll (); + m_packetTagList.clear (); } void Packet::PrintPacketTags (std::ostream &os) const { - PacketTagIterator i = GetPacketTagIterator (); - while (i.HasNext ()) + for (PacketTagList::const_iterator tag = m_packetTagList.begin (); + tag != m_packetTagList.end (); + tag++) { - PacketTagIterator::Item item = i.Next (); - NS_ASSERT (item.GetTypeId ().HasConstructor ()); - Callback constructor = item.GetTypeId ().GetConstructor (); - NS_ASSERT (!constructor.IsNull ()); - ObjectBase *instance = constructor (); - Tag *tag = dynamic_cast (instance); - NS_ASSERT (tag != 0); - item.GetTag (*tag); - tag->Print (os); - delete tag; - if (i.HasNext ()) + if (tag != m_packetTagList.begin ()) { os << " "; } - } -} -PacketTagIterator -Packet::GetPacketTagIterator (void) const -{ - return PacketTagIterator (m_packetTagList.Head ()); -} + (*tag)->Print (os); + } + // PacketTagIterator i = GetPacketTagIterator (); + // while (i.HasNext ()) + // { + // PacketTagIterator::Item item = i.Next (); + // NS_ASSERT (item.GetTypeId ().HasConstructor ()); + // Callback constructor = item.GetTypeId ().GetConstructor (); + // NS_ASSERT (!constructor.IsNull ()); + // ObjectBase *instance = constructor (); + // Tag *tag = dynamic_cast (instance); + // NS_ASSERT (tag != 0); + // item.GetTag (*tag); + // tag->Print (os); + // delete tag; + // if (i.HasNext ()) + // { + // os << " "; + // } + // } +} + +// PacketTagIterator +// Packet::GetPacketTagIterator (void) const +// { +// return PacketTagIterator (m_packetTagList.Head ()); +// } std::ostream& operator<< (std::ostream& os, const Packet &packet) { diff --git a/src/network/model/packet.h b/src/network/model/packet.h index 539dac5..57b52bf 100644 --- a/src/network/model/packet.h +++ b/src/network/model/packet.h @@ -104,52 +104,52 @@ private: ByteTagList::Iterator m_current; }; -/** - * \ingroup packet - * \brief Iterator over the set of 'packet' tags in a packet - * - * This is a java-style iterator. - */ -class PacketTagIterator -{ -public: - /** - * Identifies a tag within a packet. - */ - class Item - { -public: - /** - * \returns the ns3::TypeId associated to this tag. - */ - TypeId GetTypeId (void) const; - /** - * \param tag the user tag to which the data should be copied. - * - * Read the requested tag and store it in the user-provided - * tag instance. This method will crash if the type of the - * tag provided by the user does not match the type of - * the underlying tag. - */ - void GetTag (Tag &tag) const; -private: - friend class PacketTagIterator; - Item (const struct PacketTagList::TagData *data); - const struct PacketTagList::TagData *m_data; - }; - /** - * \returns true if calling Next is safe, false otherwise. - */ - bool HasNext (void) const; - /** - * \returns the next item found and prepare for the next one. - */ - Item Next (void); -private: - friend class Packet; - PacketTagIterator (const struct PacketTagList::TagData *head); - const struct PacketTagList::TagData *m_current; -}; +// /** +// * \ingroup packet +// * \brief Iterator over the set of 'packet' tags in a packet +// * +// * This is a java-style iterator. +// */ +// class PacketTagIterator +// { +// public: +// /** +// * Identifies a tag within a packet. +// */ +// class Item +// { +// public: +// /** +// * \returns the ns3::TypeId associated to this tag. +// */ +// TypeId GetTypeId (void) const; +// /** +// * \param tag the user tag to which the data should be copied. +// * +// * Read the requested tag and store it in the user-provided +// * tag instance. This method will crash if the type of the +// * tag provided by the user does not match the type of +// * the underlying tag. +// */ +// void GetTag (Tag &tag) const; +// private: +// friend class PacketTagIterator; +// Item (const struct PacketTagList::TagData *data); +// const struct PacketTagList::TagData *m_data; +// }; +// /** +// * \returns true if calling Next is safe, false otherwise. +// */ +// bool HasNext (void) const; +// /** +// * \returns the next item found and prepare for the next one. +// */ +// Item Next (void); +// private: +// friend class Packet; +// PacketTagIterator (const struct PacketTagList::TagData *head); +// const struct PacketTagList::TagData *m_current; +// }; /** * \ingroup packet @@ -495,34 +495,57 @@ public: */ void PrintByteTags (std::ostream &os) const; - /** - * \param tag the tag to store in this packet - * - * Add a tag to this packet. This method calls the - * Tag::GetSerializedSize and, then, Tag::Serialize. - * - * Note that this method is const, that is, it does not - * modify the state of this packet, which is fairly - * un-intuitive. - */ - void AddPacketTag (const Tag &tag) const; - /** - * \param tag the tag to remove from this packet - * \returns true if the requested tag is found, false - * otherwise. - * - * Remove a tag from this packet. This method calls - * Tag::Deserialize if the tag is found. - */ - bool RemovePacketTag (Tag &tag); - /** - * \param tag the tag to search in this packet - * \returns true if the requested tag is found, false - * otherwise. - * - * Search a matching tag and call Tag::Deserialize if it is found. - */ - bool PeekPacketTag (Tag &tag) const; + void + AddPacketTag (Ptr tag); + + Ptr + RemovePacketTag (TypeId tagType); + + template + Ptr + RemovePacketTag () + { + return DynamicCast (RemovePacketTag (T::GetTypeId ())); + } + + Ptr + PeekPacketTag (TypeId tagType) const; + + template + Ptr + PeekPacketTag () const + { + return DynamicCast (PeekPacketTag (T::GetTypeId ())); + } + + // /** + // * \param tag the tag to store in this packet + // * + // * Add a tag to this packet. This method calls the + // * Tag::GetSerializedSize and, then, Tag::Serialize. + // * + // * Note that this method is const, that is, it does not + // * modify the state of this packet, which is fairly + // * un-intuitive. + // */ + // void AddPacketTag (const Tag &tag) const; + // /** + // * \param tag the tag to remove from this packet + // * \returns true if the requested tag is found, false + // * otherwise. + // * + // * Remove a tag from this packet. This method calls + // * Tag::Deserialize if the tag is found. + // */ + // bool RemovePacketTag (Tag &tag); + // /** + // * \param tag the tag to search in this packet + // * \returns true if the requested tag is found, false + // * otherwise. + // * + // * Search a matching tag and call Tag::Deserialize if it is found. + // */ + // bool PeekPacketTag (Tag &tag) const; /** * Remove all packet tags. */ @@ -542,7 +565,7 @@ public: * \returns an object which can be used to iterate over the list of * packet tags. */ - PacketTagIterator GetPacketTagIterator (void) const; + // PacketTagIterator GetPacketTagIterator (void) const; /* Note: These functions support a temporary solution * to a specific problem in this generic class, i.e. diff --git a/src/network/model/tag.h b/src/network/model/tag.h index f25cecf..7a97306 100644 --- a/src/network/model/tag.h +++ b/src/network/model/tag.h @@ -20,7 +20,7 @@ #ifndef TAG_H #define TAG_H -#include "ns3/object-base.h" +#include "ns3/object.h" #include "tag-buffer.h" #include @@ -33,7 +33,7 @@ namespace ns3 { * * New kinds of tags can be created by subclassing this base class. */ -class Tag : public ObjectBase +class Tag : public Object { public: static TypeId GetTypeId (void); @@ -71,6 +71,13 @@ public: virtual void Print (std::ostream &os) const = 0; }; +inline std::ostream & +operator << (std::ostream &os, const Tag &tag) +{ + tag.Print (os); + return os; +} + } // namespace ns3 #endif /* TAG_H */ diff --git a/src/network/utils/packet-socket.cc b/src/network/utils/packet-socket.cc index 295dd4a..4ab3043 100644 --- a/src/network/utils/packet-socket.cc +++ b/src/network/utils/packet-socket.cc @@ -385,13 +385,13 @@ PacketSocket::ForwardUp (Ptr device, Ptr packet, if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize) { Ptr copy = packet->Copy (); - DeviceNameTag dnt; - dnt.SetDeviceName (device->GetTypeId ().GetName ()); - PacketSocketTag pst; - pst.SetPacketType (packetType); - pst.SetDestAddress (to); - SocketAddressTag tag; - tag.SetAddress (address); + Ptr dnt = CreateObject (); + dnt->SetDeviceName (device->GetTypeId ().GetName ()); + Ptr pst = CreateObject (); + pst->SetPacketType (packetType); + pst->SetDestAddress (to); + Ptr tag = CreateObject (); + tag->SetAddress (address); copy->AddPacketTag (tag); // Attach From Physical Address copy->AddPacketTag (pst); // Attach Packet Type and Dest Address copy->AddPacketTag (dnt); // Attach device source name @@ -449,11 +449,9 @@ PacketSocket::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress) Ptr packet = Recv (maxSize, flags); if (packet != 0) { - SocketAddressTag tag; - bool found; - found = packet->PeekPacketTag (tag); - NS_ASSERT (found); - fromAddress = tag.GetAddress (); + Ptr tag = packet->PeekPacketTag (); + NS_ASSERT (tag != 0); + fromAddress = tag->GetAddress (); } return packet; } @@ -611,7 +609,7 @@ uint32_t DeviceNameTag::GetSerializedSize (void) const { uint32_t s = 1 + m_deviceName.size(); - return ( s >= PACKET_TAG_MAX_SIZE)?PACKET_TAG_MAX_SIZE:s; + return s; } void DeviceNameTag::Serialize (TagBuffer i) const @@ -619,8 +617,6 @@ DeviceNameTag::Serialize (TagBuffer i) const const char *n = m_deviceName.c_str(); uint8_t l = (uint8_t) strlen (n); - if ( ( 1 + l ) > PACKET_TAG_MAX_SIZE ) l = PACKET_TAG_MAX_SIZE - 1; - i.WriteU8 (l); i.Write ( (uint8_t*) n , (uint32_t) l ); } diff --git a/src/virtual-net-device/examples/virtual-net-device.cc b/src/virtual-net-device/examples/virtual-net-device.cc index 73456d3..e786216 100644 --- a/src/virtual-net-device/examples/virtual-net-device.cc +++ b/src/virtual-net-device/examples/virtual-net-device.cc @@ -113,8 +113,7 @@ class Tunnel { Ptr packet = socket->Recv (65535, 0); NS_LOG_DEBUG ("N3SocketRecv: " << *packet); - SocketAddressTag socketAddressTag; - packet->RemovePacketTag (socketAddressTag); + packet->RemovePacketTag (); m_n3Tap->Receive (packet, 0x0800, m_n3Tap->GetAddress (), m_n3Tap->GetAddress (), NetDevice::PACKET_HOST); } @@ -122,8 +121,7 @@ class Tunnel { Ptr packet = socket->Recv (65535, 0); NS_LOG_DEBUG ("N0SocketRecv: " << *packet); - SocketAddressTag socketAddressTag; - packet->RemovePacketTag (socketAddressTag); + packet->RemovePacketTag (); m_n0Tap->Receive (packet, 0x0800, m_n0Tap->GetAddress (), m_n0Tap->GetAddress (), NetDevice::PACKET_HOST); } @@ -131,8 +129,7 @@ class Tunnel { Ptr packet = socket->Recv (65535, 0); NS_LOG_DEBUG ("N1SocketRecv: " << *packet); - SocketAddressTag socketAddressTag; - packet->RemovePacketTag (socketAddressTag); + packet->RemovePacketTag (); m_n1Tap->Receive (packet, 0x0800, m_n1Tap->GetAddress (), m_n1Tap->GetAddress (), NetDevice::PACKET_HOST); } diff --git a/src/wifi/model/mac-low.cc b/src/wifi/model/mac-low.cc index a8e09b1..c0c5c35 100644 --- a/src/wifi/model/mac-low.cc +++ b/src/wifi/model/mac-low.cc @@ -709,12 +709,11 @@ MacLow::ReceiveOk (Ptr packet, double rxSnr, WifiMode txMode, WifiPreamb && m_currentPacket != 0) { NS_LOG_DEBUG ("receive cts from=" << m_currentHdr.GetAddr1 ()); - SnrTag tag; - packet->RemovePacketTag (tag); + Ptr tag = packet->RemovePacketTag (); m_stationManager->ReportRxOk (m_currentHdr.GetAddr1 (), &m_currentHdr, rxSnr, txMode); m_stationManager->ReportRtsOk (m_currentHdr.GetAddr1 (), &m_currentHdr, - rxSnr, txMode, tag.Get ()); + rxSnr, txMode, tag->Get ()); m_ctsTimeoutEvent.Cancel (); NotifyCtsTimeoutResetNow (); @@ -734,12 +733,11 @@ MacLow::ReceiveOk (Ptr packet, double rxSnr, WifiMode txMode, WifiPreamb && m_txParams.MustWaitAck ()) { NS_LOG_DEBUG ("receive ack from=" << m_currentHdr.GetAddr1 ()); - SnrTag tag; - packet->RemovePacketTag (tag); + Ptr tag = packet->RemovePacketTag (); m_stationManager->ReportRxOk (m_currentHdr.GetAddr1 (), &m_currentHdr, rxSnr, txMode); m_stationManager->ReportDataOk (m_currentHdr.GetAddr1 (), &m_currentHdr, - rxSnr, txMode, tag.Get ()); + rxSnr, txMode, tag->Get ()); bool gotAck = false; if (m_txParams.MustWaitNormalAck () && m_normalAckTimeoutEvent.IsRunning ()) @@ -1446,8 +1444,8 @@ MacLow::SendCtsAfterRts (Mac48Address source, Time duration, WifiMode rtsTxMode, WifiMacTrailer fcs; packet->AddTrailer (fcs); - SnrTag tag; - tag.Set (rtsSnr); + Ptr tag = CreateObject (); + tag->Set (rtsSnr); packet->AddPacketTag (tag); ForwardDown (packet, &cts, ctsTxMode); @@ -1525,8 +1523,8 @@ MacLow::SendAckAfterData (Mac48Address source, Time duration, WifiMode dataTxMod WifiMacTrailer fcs; packet->AddTrailer (fcs); - SnrTag tag; - tag.Set (dataSnr); + Ptr tag = CreateObject (); + tag->Set (dataSnr); packet->AddPacketTag (tag); ForwardDown (packet, &ack, ackTxMode); diff --git a/src/wifi/model/qos-utils.cc b/src/wifi/model/qos-utils.cc index b444f11..1ff464e 100644 --- a/src/wifi/model/qos-utils.cc +++ b/src/wifi/model/qos-utils.cc @@ -59,13 +59,13 @@ QosUtilsMapTidToAc (uint8_t tid) uint8_t QosUtilsGetTidForPacket (Ptr packet) { - QosTag qos; + Ptr qos = packet->PeekPacketTag (); uint8_t tid = 8; - if (packet->PeekPacketTag (qos)) + if (qos != 0) { - if (qos.GetTid () < 8) + if (qos->GetTid () < 8) { - tid = qos.GetTid (); + tid = qos->GetTid (); } } return tid; diff --git a/src/wifi/model/wifi-remote-station-manager.cc b/src/wifi/model/wifi-remote-station-manager.cc index d2c9261..854291f 100644 --- a/src/wifi/model/wifi-remote-station-manager.cc +++ b/src/wifi/model/wifi-remote-station-manager.cc @@ -347,12 +347,12 @@ WifiRemoteStationManager::PrepareForQueue (Mac48Address address, const WifiMacHe WifiRemoteStation *station = Lookup (address, header); WifiMode rts = DoGetRtsMode (station); WifiMode data = DoGetDataMode (station, fullPacketSize); - TxModeTag tag; + // first, make sure that the tag is not here anymore. - ConstCast (packet)->RemovePacketTag (tag); - tag = TxModeTag (rts, data); + ConstCast (packet)->RemovePacketTag (); + Ptr tag = CreateObject (rts, data); // and then, add it back - packet->AddPacketTag (tag); + ConstCast (packet)->AddPacketTag (tag); } WifiMode WifiRemoteStationManager::GetDataMode (Mac48Address address, const WifiMacHeader *header, @@ -364,11 +364,9 @@ WifiRemoteStationManager::GetDataMode (Mac48Address address, const WifiMacHeader } if (!IsLowLatency ()) { - TxModeTag tag; - bool found; - found = ConstCast (packet)->PeekPacketTag (tag); - NS_ASSERT (found); - return tag.GetDataMode (); + Ptr tag = packet->PeekPacketTag (); + NS_ASSERT (tag != 0); + return tag->GetDataMode (); } return DoGetDataMode (Lookup (address, header), fullPacketSize); } @@ -379,11 +377,9 @@ WifiRemoteStationManager::GetRtsMode (Mac48Address address, const WifiMacHeader NS_ASSERT (!address.IsGroup ()); if (!IsLowLatency ()) { - TxModeTag tag; - bool found; - found = ConstCast (packet)->PeekPacketTag (tag); - NS_ASSERT (found); - return tag.GetRtsMode (); + Ptr tag = packet->PeekPacketTag (); + NS_ASSERT (tag != 0); + return tag->GetRtsMode (); } return DoGetRtsMode (Lookup (address, header)); } diff --git a/utils/bench-packets.cc b/utils/bench-packets.cc index ad95107..632b509 100644 --- a/utils/bench-packets.cc +++ b/utils/bench-packets.cc @@ -163,19 +163,19 @@ benchD (uint32_t n) { BenchHeader<25> ipv4; BenchHeader<8> udp; - BenchTag<16> tag1; - BenchTag<17> tag2; for (uint32_t i = 0; i < n; i++) { Ptr p = Create (2000); - p->AddPacketTag (tag1); + p->AddPacketTag (CreateObject > ()); p->AddHeader (udp); - p->RemovePacketTag (tag1); - p->AddPacketTag (tag2); + p->RemovePacketTag (BenchTag<16>::GetTypeId ()); + + p->AddPacketTag (CreateObject > ()); p->AddHeader (ipv4); + Ptr o = p->Copy (); o->RemoveHeader (ipv4); - p->RemovePacketTag (tag2); + p->RemovePacketTag (BenchTag<17>::GetTypeId ()); o->RemoveHeader (udp); } } -- 1.7.9.2