106 } |
106 } |
107 } |
107 } |
108 } |
108 } |
109 } |
109 } |
110 |
110 |
|
111 void |
|
112 V4Ping::Write32 (uint8_t *buffer, uint32_t data) |
|
113 { |
|
114 buffer[0] = (data >> 0) & 0xff; |
|
115 buffer[1] = (data >> 8) & 0xff; |
|
116 buffer[2] = (data >> 16) & 0xff; |
|
117 buffer[3] = (data >> 24) & 0xff; |
|
118 } |
|
119 |
111 void |
120 void |
112 V4Ping::StartApplication (void) |
121 V4Ping::StartApplication (void) |
113 { |
122 { |
114 NS_LOG_FUNCTION (this); |
123 NS_LOG_FUNCTION (this); |
115 m_socket = Socket::CreateSocket (GetNode (), TypeId::LookupByName ("ns3::Ipv4RawSocketFactory")); |
124 m_socket = Socket::CreateSocket (GetNode (), TypeId::LookupByName ("ns3::Ipv4RawSocketFactory")); |
126 Ptr<Packet> p = Create<Packet> (); |
135 Ptr<Packet> p = Create<Packet> (); |
127 Icmpv4Echo echo; |
136 Icmpv4Echo echo; |
128 echo.SetSequenceNumber (m_seq); |
137 echo.SetSequenceNumber (m_seq); |
129 m_seq++; |
138 m_seq++; |
130 echo.SetIdentifier (0); |
139 echo.SetIdentifier (0); |
131 uint32_t data[4]; |
140 |
132 data[0] = GetNode ()->GetId (); |
141 // |
133 data[1] = GetApplicationId (); |
142 // We must write quantities out in some form of network order. Since there |
|
143 // isn't an htonl to work with we just follow the convention in pcap traces |
|
144 // (where any difference would show up anyway) and borrow that code. Don't |
|
145 // be too surprised when you see that this is a little endian convention. |
|
146 // |
|
147 uint8_t data[4 * sizeof(uint32_t)]; |
|
148 uint32_t tmp = GetNode ()->GetId (); |
|
149 Write32 (&data[0 * sizeof(uint32_t)], tmp); |
|
150 |
|
151 tmp = GetApplicationId (); |
|
152 Write32 (&data[1 * sizeof(uint32_t)], tmp); |
|
153 |
134 int64_t now = Simulator::Now ().GetTimeStep (); |
154 int64_t now = Simulator::Now ().GetTimeStep (); |
135 data[2] = now & 0xffffffff; |
155 tmp = now & 0xffffffff; |
|
156 Write32 (&data[2 * sizeof(uint32_t)], tmp); |
|
157 |
136 now >>= 32; |
158 now >>= 32; |
137 data[3] = now & 0xffffffff; |
159 tmp = now & 0xffffffff; |
|
160 Write32 (&data[3 * sizeof(uint32_t)], tmp); |
|
161 |
138 Ptr<Packet> dataPacket = Create<Packet> ((uint8_t *) &data, 16); |
162 Ptr<Packet> dataPacket = Create<Packet> ((uint8_t *) &data, 16); |
139 echo.SetData (dataPacket); |
163 echo.SetData (dataPacket); |
140 p->AddHeader (echo); |
164 p->AddHeader (echo); |
141 Icmpv4Header header; |
165 Icmpv4Header header; |
142 header.SetType (Icmpv4Header::ECHO); |
166 header.SetType (Icmpv4Header::ECHO); |