diff -r 61b2ef996f45 src/mesh/doc/mesh.h --- a/src/mesh/doc/mesh.h Mon Mar 12 16:45:30 2012 +0100 +++ b/src/mesh/doc/mesh.h Thu Mar 15 16:43:04 2012 +0400 @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Authors: Kirill Andreev + * Authors: Kirill Andreev * Aleksander Safonov * Pavel Boyko * diff -r 61b2ef996f45 src/mesh/examples/mesh.cc --- a/src/mesh/examples/mesh.cc Mon Mar 12 16:45:30 2012 +0100 +++ b/src/mesh/examples/mesh.cc Thu Mar 15 16:43:04 2012 +0400 @@ -52,6 +52,7 @@ #include "ns3/mesh-module.h" #include "ns3/mobility-module.h" #include "ns3/mesh-helper.h" +#include "ns3/trace-helper.h" #include #include @@ -90,6 +91,8 @@ Ipv4InterfaceContainer interfaces; // MeshHelper. Report is not static methods MeshHelper mesh; + + AsciiTraceHelper ascii; private: /// Create nodes and setup their mobility void CreateNodes (); @@ -106,7 +109,7 @@ m_step (100.0), m_randomStart (0.1), m_totalTime (100.0), - m_packetInterval (0.1), + m_packetInterval (1), m_packetSize (1024), m_nIfaces (1), m_chan (true), @@ -146,6 +149,7 @@ /* * Create m_ySize*m_xSize stations to form a grid topology */ + ns3::PacketMetadata::Enable (); nodes.Create (m_ySize*m_xSize); // Configure YansWifiChannel YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); @@ -193,6 +197,9 @@ mobility.Install (nodes); if (m_pcap) wifiPhy.EnablePcapAll (std::string ("mp-")); + + wifiPhy.EnableAsciiAll (ascii.CreateFileStream ("test.tr")); + } void MeshTest::InstallInternetStack () diff -r 61b2ef996f45 src/mesh/model/dot11s/peer-link-frame.cc --- a/src/mesh/model/dot11s/peer-link-frame.cc Mon Mar 12 16:45:30 2012 +0100 +++ b/src/mesh/model/dot11s/peer-link-frame.cc Thu Mar 15 16:43:04 2012 +0400 @@ -26,6 +26,274 @@ namespace ns3 { namespace dot11s { + +NS_OBJECT_ENSURE_REGISTERED (PeerLinkOpenFrame); + +PeerLinkOpenFrame::PeerLinkOpenFrame () : + m_protocolVersion (IePeeringProtocol ()), + m_capability (0), + m_supportedRates (SupportedRates ()), + m_meshId (IeMeshId ()), + m_config (IeConfiguration ()) +{} + +PeerLinkOpenFrame::PeerLinkOpenFrame (const IePeeringProtocol & protocol, + uint16_t capability, + const SupportedRates & supportedRates, + const IeMeshId & meshId, + const IeConfiguration & config) : + m_protocolVersion (protocol), + m_capability (capability), + m_supportedRates (supportedRates), + m_meshId (meshId), + m_config (config) +{} + +TypeId PeerLinkOpenFrame::GetTypeId () +{ + static TypeId tid = TypeId ("ns3::dot11s::PeerLinkOpenFrame") + .SetParent
() + .AddConstructor (); + return tid; +} + +TypeId +PeerLinkOpenFrame::GetInstanceTypeId () const +{ + return GetTypeId (); +} +void +PeerLinkOpenFrame::Print (std::ostream &os) const +{ + +} + +uint32_t +PeerLinkOpenFrame::GetSerializedSize () const +{ + return m_protocolVersion.GetSerializedSize () + + 2 // capability + + m_supportedRates.GetSerializedSize () + + m_supportedRates.extended.GetSerializedSize () + + +m_meshId.GetSerializedSize () + + m_config.GetSerializedSize (); +} + +void +PeerLinkOpenFrame::Serialize (Buffer::Iterator start) const +{ + Buffer::Iterator i = start; + i = m_protocolVersion.Serialize (i); + i.WriteHtolsbU16 (m_capability); + i = m_supportedRates.Serialize (i); + i = m_supportedRates.extended.Serialize (i); + i = m_meshId.Serialize (i); + i = m_config.Serialize (i); +} + +uint32_t +PeerLinkOpenFrame::Deserialize (Buffer::Iterator start) +{ + Buffer::Iterator i = start; + //1. Read protocol: + uint8_t id = i.ReadU8 (); + uint8_t length = i.ReadU8 (); + m_protocolVersion.DeserializeInformationField (i, length); + i.Next (m_protocolVersion.GetInformationFieldSize ()); + // 2. Read capability: + m_capability = i.ReadLsbtohU16 (); + // 3. read supported rates: + i = m_supportedRates.Deserialize (i); + i = m_supportedRates.extended.DeserializeIfPresent (i); + // 4. read MESH ID + id = i.ReadU8 (); + length = i.ReadU8 (); + m_meshId.DeserializeInformationField (i, length); + i.Next (m_meshId.GetInformationFieldSize ()); + // 5. Read Configuration: + id = i.ReadU8 (); + length = i.ReadU8 (); + m_config.DeserializeInformationField (i, length); + i.Next (m_config.GetInformationFieldSize ()); + return i.GetDistanceFrom (start); +} + +NS_OBJECT_ENSURE_REGISTERED (PeerLinkConfirmFrame); + +PeerLinkConfirmFrame::PeerLinkConfirmFrame () : + m_protocolVersion (IePeeringProtocol ()), + m_capability (0), + m_aid (0), + m_supportedRates (SupportedRates ()), + m_config (IeConfiguration ()) +{} + +PeerLinkConfirmFrame::PeerLinkConfirmFrame (const IePeeringProtocol & protocol, + uint16_t capability, + uint16_t assocId, + const SupportedRates & supportedRates, + const IeConfiguration & config) : + m_protocolVersion (protocol), + m_capability (capability), + m_aid (assocId), + m_supportedRates (supportedRates), + m_config (config) +{} + +TypeId PeerLinkConfirmFrame::GetTypeId () +{ + static TypeId tid = TypeId ("ns3::dot11s::PeerLinkConfirmFrame") + .SetParent
() + .AddConstructor (); + return tid; +} + +TypeId +PeerLinkConfirmFrame::GetInstanceTypeId () const +{ + return GetTypeId (); +} +void +PeerLinkConfirmFrame::Print (std::ostream &os) const +{ + +} + +uint32_t +PeerLinkConfirmFrame::GetSerializedSize () const +{ + return m_protocolVersion.GetSerializedSize () + + 2 // capability + + 2 // aid + + m_supportedRates.GetSerializedSize () + + m_supportedRates.extended.GetSerializedSize () + + +m_config.GetSerializedSize (); +} + +void +PeerLinkConfirmFrame::Serialize (Buffer::Iterator start) const +{ + Buffer::Iterator i = start; + i = m_protocolVersion.Serialize (i); + i.WriteHtolsbU16 (m_capability); + i.WriteHtolsbU16 (m_aid); + i = m_supportedRates.Serialize (i); + i = m_supportedRates.extended.Serialize (i); + i = m_config.Serialize (i); +} + +uint32_t +PeerLinkConfirmFrame::Deserialize (Buffer::Iterator start) +{ + Buffer::Iterator i = start; + //1. Read protocol: + uint8_t id = i.ReadU8 (); + uint8_t length = i.ReadU8 (); + m_protocolVersion.DeserializeInformationField (i, length); + i.Next (m_protocolVersion.GetInformationFieldSize ()); + // 2. Read capability: + m_capability = i.ReadLsbtohU16 (); + // 3. Read AID + m_aid = i.ReadLsbtohU16 (); + // 4. read supported rates: + i = m_supportedRates.Deserialize (i); + i = m_supportedRates.extended.DeserializeIfPresent (i); + // 5. Read Configuration: + id = i.ReadU8 (); + length = i.ReadU8 (); + m_config.DeserializeInformationField (i, length); + i.Next (m_config.GetInformationFieldSize ()); + return i.GetDistanceFrom (start); +} + + +PeerLinkCloseFrame::PeerLinkCloseFrame () : + m_protocolVersion (IePeeringProtocol ()), + m_meshId (IeMeshId ()), + m_reasonCode (0) +{} +PeerLinkCloseFrame::PeerLinkCloseFrame (const IePeeringProtocol & protocol, + const IeMeshId & meshId, + uint16_t reason) : + m_protocolVersion (protocol), + m_meshId (meshId), + m_reasonCode (reason) +{} + +TypeId +PeerLinkCloseFrame::GetTypeId () +{ + static TypeId tid = TypeId ("ns3::dot11s::PeerLinkCloseFrame") + .SetParent
() + .AddConstructor (); + return tid; +} + +TypeId +PeerLinkCloseFrame::GetInstanceTypeId () const +{ + return GetTypeId (); +} + +void +PeerLinkCloseFrame::Print (std::ostream &os) const +{ +} + +uint32_t +PeerLinkCloseFrame::GetSerializedSize () const +{ + return m_protocolVersion.GetSerializedSize () + + m_meshId.GetSerializedSize () + + 2; +} + +void +PeerLinkCloseFrame::Serialize (Buffer::Iterator start) const +{ + Buffer::Iterator i = start; + i = m_protocolVersion.Serialize (i); + i = m_meshId.Serialize (i); + i.WriteHtolsbU16 (m_reasonCode); +} + +uint32_t +PeerLinkCloseFrame::Deserialize (Buffer::Iterator start) +{ + Buffer::Iterator i = start; + //1. Read protocol: + uint8_t id = i.ReadU8 (); + uint8_t length = i.ReadU8 (); + m_protocolVersion.DeserializeInformationField (i, length); + // 2. read MESH ID + id = i.ReadU8 (); + length = i.ReadU8 (); + m_meshId.DeserializeInformationField (i, length); + m_reasonCode = i.ReadLsbtohU16 (); + return i.GetDistanceFrom (start); +} + + + + + + + + + + + + + + + + + + + + + + NS_OBJECT_ENSURE_REGISTERED (PeerLinkFrameStart); PeerLinkFrameStart::PeerLinkFrameStart () : @@ -82,6 +350,7 @@ retval.reasonCode = m_reasonCode; return retval; } + TypeId PeerLinkFrameStart::GetTypeId () { @@ -172,6 +441,7 @@ PeerLinkFrameStart::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; + std::cout << "m_subtype = " << (uint32_t)m_subtype << std::endl; NS_ASSERT (m_subtype < 3); { uint8_t id = i.ReadU8 (); diff -r 61b2ef996f45 src/mesh/model/dot11s/peer-link-frame.h --- a/src/mesh/model/dot11s/peer-link-frame.h Mon Mar 12 16:45:30 2012 +0100 +++ b/src/mesh/model/dot11s/peer-link-frame.h Thu Mar 15 16:43:04 2012 +0400 @@ -42,6 +42,88 @@ * - Supported rates * - Mesh ID of mesh */ + +class PeerLinkOpenFrame : public Header +{ +public: + PeerLinkOpenFrame (); + PeerLinkOpenFrame (const IePeeringProtocol & protocol, + uint16_t capability, + const SupportedRates & supportedRates, + const IeMeshId & meshId, + const IeConfiguration & config); + ///\name Inherited from header: + ///\{ + static TypeId GetTypeId (); + TypeId GetInstanceTypeId () const; + void Print (std::ostream &os) const; + uint32_t GetSerializedSize () const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); + ///\} +private: + /// 3 octets protocol version + IePeeringProtocol m_protocolVersion; + /// capability fiels + uint16_t m_capability; + /// Supported rates: + SupportedRates m_supportedRates; + /// Mesh network identificator + IeMeshId m_meshId; + /// Mesh configuration: + IeConfiguration m_config; //open and confirm +}; + +class PeerLinkConfirmFrame : public Header +{ +public: + PeerLinkConfirmFrame (); + PeerLinkConfirmFrame (const IePeeringProtocol & protocol, + uint16_t capability, + uint16_t assocId, + const SupportedRates & supportedRates, + const IeConfiguration & config); + ///\name Inherited from header: + ///\{ + static TypeId GetTypeId (); + TypeId GetInstanceTypeId () const; + void Print (std::ostream &os) const; + uint32_t GetSerializedSize () const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); + ///\} +private: + /// 3 octets protocol version + IePeeringProtocol m_protocolVersion; + /// capability fiels + uint16_t m_capability; + uint16_t m_aid; + SupportedRates m_supportedRates; + IeConfiguration m_config; +}; + +class PeerLinkCloseFrame : public Header +{ +public: + PeerLinkCloseFrame (); + PeerLinkCloseFrame (const IePeeringProtocol & protocol, + const IeMeshId & meshId, + uint16_t reason); + ///\name Inherited from header: + ///\{ + static TypeId GetTypeId (); + TypeId GetInstanceTypeId () const; + void Print (std::ostream &os) const; + uint32_t GetSerializedSize () const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); + ///\} +private: + IePeeringProtocol m_protocolVersion; + IeMeshId m_meshId; + uint16_t m_reasonCode; +}; + class PeerLinkFrameStart : public Header { public: @@ -64,8 +146,8 @@ void SetPlinkFrameStart (PlinkFrameStartFields); PlinkFrameStartFields GetFields () const; /** \name Inherited from header: - * \{ - */ + * \{ + */ static TypeId GetTypeId (); virtual TypeId GetInstanceTypeId () const; virtual void Print (std::ostream &os) const; diff -r 61b2ef996f45 src/mesh/model/dot11s/peer-management-protocol-mac.cc --- a/src/mesh/model/dot11s/peer-management-protocol-mac.cc Mon Mar 12 16:45:30 2012 +0100 +++ b/src/mesh/model/dot11s/peer-management-protocol-mac.cc Thu Mar 15 16:43:04 2012 +0400 @@ -167,18 +167,12 @@ { return true; } - else + if (m_protocol->IsActiveLink (m_ifIndex, header.GetAddr1 ())) { - if (m_protocol->IsActiveLink (m_ifIndex, header.GetAddr1 ())) - { - return true; - } - else - { - m_stats.dropped++; - return false; - } + return true; } + m_stats.dropped++; + return false; } void PeerManagementProtocolMac::UpdateBeacon (MeshWifiBeacon & beacon) const @@ -202,12 +196,6 @@ MeshInformationElementVector elements; elements.AddInformationElement (Ptr (&peerElement)); packet->AddHeader (elements); - PeerLinkFrameStart::PlinkFrameStartFields fields; - fields.rates = m_parent->GetSupportedRates (); - fields.capability = 0; - fields.meshId = *(m_protocol->GetMeshId ()); - fields.config = meshConfig; - PeerLinkFrameStart plinkFrame; //Create an 802.11 frame header: //Send management frame to MAC: WifiActionHeader actionHdr; @@ -216,36 +204,42 @@ m_stats.txOpen++; WifiActionHeader::ActionValue action; action.peerLink = WifiActionHeader::PEER_LINK_OPEN; - fields.subtype = WifiActionHeader::PEER_LINK_OPEN; actionHdr.SetAction (WifiActionHeader::MESH_PEERING_MGT, action); + packet->AddHeader (PeerLinkOpenFrame (IePeeringProtocol (), 0, m_parent->GetSupportedRates (), *(m_protocol->GetMeshId ()), meshConfig)); } - if (peerElement.SubtypeIsConfirm ()) + else if (peerElement.SubtypeIsConfirm ()) { m_stats.txConfirm++; WifiActionHeader::ActionValue action; action.peerLink = WifiActionHeader::PEER_LINK_CONFIRM; - fields.aid = aid; - fields.subtype = WifiActionHeader::PEER_LINK_CONFIRM; actionHdr.SetAction (WifiActionHeader::MESH_PEERING_MGT, action); + packet->AddHeader (PeerLinkConfirmFrame (IePeeringProtocol (), 0, aid, m_parent->GetSupportedRates (), meshConfig)); } - if (peerElement.SubtypeIsClose ()) + else if (peerElement.SubtypeIsClose ()) { m_stats.txClose++; WifiActionHeader::ActionValue action; action.peerLink = WifiActionHeader::PEER_LINK_CLOSE; - fields.subtype = WifiActionHeader::PEER_LINK_CLOSE; - fields.reasonCode = peerElement.GetReasonCode (); actionHdr.SetAction (WifiActionHeader::MESH_PEERING_MGT, action); + packet->AddHeader (PeerLinkCloseFrame (IePeeringProtocol (), *(m_protocol->GetMeshId ()), peerElement.GetReasonCode ())); } - plinkFrame.SetPlinkFrameStart (fields); - packet->AddHeader (plinkFrame); + else + { + NS_FATAL_ERROR ("Can not determine the type of peering frame"); + } packet->AddHeader (actionHdr); + SendManagementFrame (packet, peerAddress); +} + +void +PeerManagementProtocolMac::SendManagementFrame (Ptr packet, Mac48Address to) +{ m_stats.txMgt++; m_stats.txMgtBytes += packet->GetSize (); // Wifi Mac header: WifiMacHeader hdr; hdr.SetAction (); - hdr.SetAddr1 (peerAddress); + hdr.SetAddr1 (to); hdr.SetAddr2 (m_parent->GetAddress ()); //Addr is not used here, we use it as our MP address hdr.SetAddr3 (m_protocol->GetAddress ()); diff -r 61b2ef996f45 src/mesh/model/dot11s/peer-management-protocol-mac.h --- a/src/mesh/model/dot11s/peer-management-protocol-mac.h Mon Mar 12 16:45:30 2012 +0100 +++ b/src/mesh/model/dot11s/peer-management-protocol-mac.h Thu Mar 15 16:43:04 2012 +0400 @@ -95,6 +95,8 @@ IePeerManagement peerElement, IeConfiguration meshConfig ); + /// Construct 802.11 header and pass a packet to MAC + void SendManagementFrame (Ptr packet, Mac48Address to); ///\brief debug only, used to print established links Mac48Address GetAddress () const; ///\name Statistics diff -r 61b2ef996f45 src/mesh/model/mesh-information-element-vector.cc --- a/src/mesh/model/mesh-information-element-vector.cc Mon Mar 12 16:45:30 2012 +0100 +++ b/src/mesh/model/mesh-information-element-vector.cc Thu Mar 15 16:43:04 2012 +0400 @@ -36,6 +36,28 @@ namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (MeshInformationElementVector); + +MeshInformationElementVector::MeshInformationElementVector () : + WifiInformationElementVector () +{} + +TypeId +MeshInformationElementVector::GetTypeId () +{ + static TypeId tid = TypeId ("ns3::MeshInformationElementVector") + .SetParent () + .AddConstructor (); + return tid; +} + +TypeId +MeshInformationElementVector::GetInstanceTypeId () const +{ + return GetTypeId (); +} + uint32_t MeshInformationElementVector::DeserializeSingleIe (Buffer::Iterator start) { diff -r 61b2ef996f45 src/mesh/model/mesh-information-element-vector.h --- a/src/mesh/model/mesh-information-element-vector.h Mon Mar 12 16:45:30 2012 +0100 +++ b/src/mesh/model/mesh-information-element-vector.h Thu Mar 15 16:43:04 2012 +0400 @@ -30,6 +30,9 @@ class MeshInformationElementVector : public WifiInformationElementVector { public: + static TypeId GetTypeId (); + TypeId GetInstanceTypeId () const; + MeshInformationElementVector (); virtual uint32_t DeserializeSingleIe (Buffer::Iterator start); }; diff -r 61b2ef996f45 src/mesh/model/mesh-wifi-beacon.h --- a/src/mesh/model/mesh-wifi-beacon.h Mon Mar 12 16:45:30 2012 +0100 +++ b/src/mesh/model/mesh-wifi-beacon.h Thu Mar 15 16:43:04 2012 +0400 @@ -67,7 +67,7 @@ /// Beacon header MgtBeaconHeader m_header; /// List of information elements added - WifiInformationElementVector m_elements; + MeshInformationElementVector m_elements; }; }