# HG changeset patch # User Hajime Tazaki # Date 1262721186 28800 # Node ID 4af39a3f472bb2b94ebc90ee29578ad0c0b039e9 # Parent 2654e75513dc8bf0ec3dfbd844a0468bdc650ca2 (Bug 671) Add RecvIfIndex tag to sockets diff -r 2654e75513dc -r 4af39a3f472b examples/tunneling/virtual-net-device.cc --- a/examples/tunneling/virtual-net-device.cc Thu Dec 31 10:20:06 2009 -0800 +++ b/examples/tunneling/virtual-net-device.cc Tue Jan 05 11:53:06 2010 -0800 @@ -115,6 +115,8 @@ NS_LOG_DEBUG ("N3SocketRecv: " << *packet); SocketAddressTag socketAddressTag; packet->RemovePacketTag (socketAddressTag); + SocketRecvIfTag recvIfTag; + packet->RemovePacketTag (recvIfTag); m_n3Tap->Receive (packet, 0x0800, m_n3Tap->GetAddress (), m_n3Tap->GetAddress (), NetDevice::PACKET_HOST); } @@ -124,6 +126,8 @@ NS_LOG_DEBUG ("N0SocketRecv: " << *packet); SocketAddressTag socketAddressTag; packet->RemovePacketTag (socketAddressTag); + SocketRecvIfTag recvIfTag; + packet->RemovePacketTag (recvIfTag); m_n0Tap->Receive (packet, 0x0800, m_n0Tap->GetAddress (), m_n0Tap->GetAddress (), NetDevice::PACKET_HOST); } @@ -133,6 +137,8 @@ NS_LOG_DEBUG ("N1SocketRecv: " << *packet); SocketAddressTag socketAddressTag; packet->RemovePacketTag (socketAddressTag); + SocketRecvIfTag recvIfTag; + packet->RemovePacketTag (recvIfTag); m_n1Tap->Receive (packet, 0x0800, m_n1Tap->GetAddress (), m_n1Tap->GetAddress (), NetDevice::PACKET_HOST); } diff -r 2654e75513dc -r 4af39a3f472b src/common/packet-tag-list.cc --- a/src/common/packet-tag-list.cc Thu Dec 31 10:20:06 2009 -0800 +++ b/src/common/packet-tag-list.cc Tue Jan 05 11:53:06 2010 -0800 @@ -136,7 +136,7 @@ // ensure this id was not yet added for (struct TagData *cur = m_next; cur != 0; cur = cur->next) { - NS_ASSERT (cur->tid != tag.GetInstanceTypeId ()); + NS_ASSERT_MSG (cur->tid != tag.GetInstanceTypeId (), "Assert: trying to add a Packet tag type that is already added"); } struct TagData *head = AllocData (); head->count = 1; diff -r 2654e75513dc -r 4af39a3f472b src/internet-stack/ipv4-l3-protocol.cc --- a/src/internet-stack/ipv4-l3-protocol.cc Thu Dec 31 10:20:06 2009 -0800 +++ b/src/internet-stack/ipv4-l3-protocol.cc Tue Jan 05 11:53:06 2010 -0800 @@ -780,6 +780,10 @@ m_localDeliverTrace (ip, packet, iif); + SocketRecvIfTag tag; + tag.SetRecvIf (iif); + p->AddPacketTag (tag); + Ptr protocol = GetProtocol (ip.GetProtocol ()); if (protocol != 0) { diff -r 2654e75513dc -r 4af39a3f472b src/internet-stack/ipv6-l3-protocol.cc --- a/src/internet-stack/ipv6-l3-protocol.cc Thu Dec 31 10:20:06 2009 -0800 +++ b/src/internet-stack/ipv6-l3-protocol.cc Tue Jan 05 11:53:06 2010 -0800 @@ -665,6 +665,7 @@ { NS_LOG_FUNCTION (this << device << p << protocol << from << to << packetType); NS_LOG_LOGIC ("Packet from " << from << " received on node " << m_node->GetId ()); + uint32_t interface = 0; Ptr packet = p->Copy (); Ptr ipv6Interface = 0; @@ -933,6 +934,11 @@ { NS_LOG_FUNCTION (this << packet << ip << iif); Ptr p = packet->Copy (); + + SocketRecvIfTag tag; + tag.SetRecvIf (iif); + p->AddPacketTag (tag); + Ptr protocol = 0; Ptr ipv6ExtensionDemux = m_node->GetObject(); Ptr ipv6Extension = 0; diff -r 2654e75513dc -r 4af39a3f472b src/node/socket.cc --- a/src/node/socket.cc Thu Dec 31 10:20:06 2009 -0800 +++ b/src/node/socket.cc Tue Jan 05 11:53:06 2010 -0800 @@ -487,4 +487,58 @@ os << (m_dontFragment?"true":"false"); } + +SocketRecvIfTag::SocketRecvIfTag () +{ +} + +void +SocketRecvIfTag::SetRecvIf (uint32_t ifindex) +{ + m_ifindex = ifindex; +} + +uint32_t +SocketRecvIfTag::GetRecvIf (void) const +{ + return m_ifindex; +} + + +TypeId +SocketRecvIfTag::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::SocketRecvIfTag") + .SetParent () + .AddConstructor () + ; + return tid; +} +TypeId +SocketRecvIfTag::GetInstanceTypeId (void) const +{ + return GetTypeId (); +} + +uint32_t +SocketRecvIfTag::GetSerializedSize (void) const +{ + return sizeof(uint32_t); +} +void +SocketRecvIfTag::Serialize (TagBuffer i) const +{ + i.WriteU32 (m_ifindex); +} +void +SocketRecvIfTag::Deserialize (TagBuffer i) +{ + m_ifindex = i.ReadU32 (); +} +void +SocketRecvIfTag::Print (std::ostream &os) const +{ + os << "RecvIf=" << (uint32_t) m_ifindex; +} + }//namespace ns3 diff -r 2654e75513dc -r 4af39a3f472b src/node/socket.h --- a/src/node/socket.h Thu Dec 31 10:20:06 2009 -0800 +++ b/src/node/socket.h Tue Jan 05 11:53:06 2010 -0800 @@ -80,6 +80,8 @@ ERROR_INVAL, ERROR_BADF, ERROR_NOROUTETOHOST, + ERROR_NODEV, + ERROR_ADDRNOTAVAIL, SOCKET_ERRNO_LAST }; @@ -637,6 +639,29 @@ bool m_dontFragment; }; +/** + * \brief This class implements a tag that carries the information of + * received interface of a packet to the socket layer + */ +class SocketRecvIfTag : public Tag +{ +public: + SocketRecvIfTag (); + void SetRecvIf (uint32_t ifindex); + uint32_t GetRecvIf (void) const; + + static TypeId GetTypeId (void); + virtual TypeId GetInstanceTypeId (void) const; + virtual uint32_t GetSerializedSize (void) const; + virtual void Serialize (TagBuffer i) const; + virtual void Deserialize (TagBuffer i); + virtual void Print (std::ostream &os) const; + +private: + uint8_t m_ifindex; +}; + + } //namespace ns3 #endif /* SOCKET_H */