39 NS_LOG_COMPONENT_DEFINE ("WifiHelper"); |
39 NS_LOG_COMPONENT_DEFINE ("WifiHelper"); |
40 |
40 |
41 namespace ns3 { |
41 namespace ns3 { |
42 |
42 |
43 static void PcapPhyTxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet, |
43 static void PcapPhyTxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet, |
44 WifiMode mode, WifiPreamble preamble, |
44 WifiMode mode, WifiPreamble preamble, |
45 uint8_t txLevel) |
45 uint8_t txLevel) |
46 { |
46 { |
47 writer->WritePacket (packet); |
47 writer->WritePacket (packet); |
48 } |
48 } |
49 |
49 |
50 static void PcapPhyRxEvent (Ptr<PcapWriter> writer, |
50 static void PcapPhyRxEvent (Ptr<PcapWriter> writer, |
51 Ptr<const Packet> packet, double snr, WifiMode mode, |
51 Ptr<const Packet> packet, double snr, WifiMode mode, |
52 enum WifiPreamble preamble) |
52 enum WifiPreamble preamble) |
53 { |
53 { |
54 writer->WritePacket (packet); |
54 writer->WritePacket (packet); |
55 } |
55 } |
56 |
56 |
57 static void AsciiPhyTxEvent (std::ostream *os, std::string context, |
57 static void AsciiPhyTxEvent (std::ostream *os, std::string context, |
58 Ptr<const Packet> packet, |
58 Ptr<const Packet> packet, |
59 WifiMode mode, WifiPreamble preamble, |
59 WifiMode mode, WifiPreamble preamble, |
60 uint8_t txLevel) |
60 uint8_t txLevel) |
61 { |
61 { |
62 *os << "+ " << Simulator::Now () << " " << context << " " << *packet << std::endl; |
62 *os << "+ " << Simulator::Now () << " " << context << " " << *packet << std::endl; |
63 } |
63 } |
64 |
64 |
65 static void AsciiPhyRxOkEvent (std::ostream *os, std::string context, |
65 static void AsciiPhyRxOkEvent (std::ostream *os, std::string context, |
66 Ptr<const Packet> packet, double snr, WifiMode mode, |
66 Ptr<const Packet> packet, double snr, WifiMode mode, |
67 enum WifiPreamble preamble) |
67 enum WifiPreamble preamble) |
68 { |
68 { |
69 *os << "r " << Simulator::Now () << " " << context << " " << *packet << std::endl; |
69 *os << "r " << Simulator::Now () << " " << context << " " << *packet << std::endl; |
70 } |
70 } |
71 |
71 |
72 |
72 |
76 m_mac.SetTypeId ("ns3::AdhocWifiMac"); |
76 m_mac.SetTypeId ("ns3::AdhocWifiMac"); |
77 } |
77 } |
78 |
78 |
79 void |
79 void |
80 WifiHelper::SetRemoteStationManager (std::string type, |
80 WifiHelper::SetRemoteStationManager (std::string type, |
81 std::string n0, const AttributeValue &v0, |
81 std::string n0, const AttributeValue &v0, |
82 std::string n1, const AttributeValue &v1, |
82 std::string n1, const AttributeValue &v1, |
83 std::string n2, const AttributeValue &v2, |
83 std::string n2, const AttributeValue &v2, |
84 std::string n3, const AttributeValue &v3, |
84 std::string n3, const AttributeValue &v3, |
85 std::string n4, const AttributeValue &v4, |
85 std::string n4, const AttributeValue &v4, |
86 std::string n5, const AttributeValue &v5, |
86 std::string n5, const AttributeValue &v5, |
87 std::string n6, const AttributeValue &v6, |
87 std::string n6, const AttributeValue &v6, |
88 std::string n7, const AttributeValue &v7) |
88 std::string n7, const AttributeValue &v7) |
89 { |
89 { |
90 m_stationManager = ObjectFactory (); |
90 m_stationManager = ObjectFactory (); |
91 m_stationManager.SetTypeId (type); |
91 m_stationManager.SetTypeId (type); |
92 m_stationManager.Set (n0, v0); |
92 m_stationManager.Set (n0, v0); |
93 m_stationManager.Set (n1, v1); |
93 m_stationManager.Set (n1, v1); |
99 m_stationManager.Set (n7, v7); |
99 m_stationManager.Set (n7, v7); |
100 } |
100 } |
101 |
101 |
102 void |
102 void |
103 WifiHelper::SetMac (std::string type, |
103 WifiHelper::SetMac (std::string type, |
104 std::string n0, const AttributeValue &v0, |
104 std::string n0, const AttributeValue &v0, |
105 std::string n1, const AttributeValue &v1, |
105 std::string n1, const AttributeValue &v1, |
106 std::string n2, const AttributeValue &v2, |
106 std::string n2, const AttributeValue &v2, |
107 std::string n3, const AttributeValue &v3, |
107 std::string n3, const AttributeValue &v3, |
108 std::string n4, const AttributeValue &v4, |
108 std::string n4, const AttributeValue &v4, |
109 std::string n5, const AttributeValue &v5, |
109 std::string n5, const AttributeValue &v5, |
110 std::string n6, const AttributeValue &v6, |
110 std::string n6, const AttributeValue &v6, |
111 std::string n7, const AttributeValue &v7) |
111 std::string n7, const AttributeValue &v7) |
112 { |
112 { |
113 m_mac = ObjectFactory (); |
113 m_mac = ObjectFactory (); |
114 m_mac.SetTypeId (type); |
114 m_mac.SetTypeId (type); |
115 m_mac.Set (n0, v0); |
115 m_mac.Set (n0, v0); |
116 m_mac.Set (n1, v1); |
116 m_mac.Set (n1, v1); |
130 |
130 |
131 void |
131 void |
132 WifiHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid) |
132 WifiHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid) |
133 { |
133 { |
134 std::ostringstream oss; |
134 std::ostringstream oss; |
|
135 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/"; |
|
136 Config::MatchContainer matches = Config::LookupMatches (oss.str ()); |
|
137 if (matches.GetN () == 0) |
|
138 { |
|
139 return; |
|
140 } |
|
141 oss.str (""); |
135 oss << filename << "-" << nodeid << "-" << deviceid << ".pcap"; |
142 oss << filename << "-" << nodeid << "-" << deviceid << ".pcap"; |
136 Ptr<PcapWriter> pcap = Create<PcapWriter> (); |
143 Ptr<PcapWriter> pcap = Create<PcapWriter> (); |
137 pcap->Open (oss.str ()); |
144 pcap->Open (oss.str ()); |
138 pcap->WriteWifiHeader (); |
145 pcap->WriteWifiHeader (); |
139 oss.str (""); |
146 oss.str (""); |
158 NetDeviceContainer devs; |
165 NetDeviceContainer devs; |
159 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
166 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
160 { |
167 { |
161 Ptr<Node> node = *i; |
168 Ptr<Node> node = *i; |
162 for (uint32_t j = 0; j < node->GetNDevices (); ++j) |
169 for (uint32_t j = 0; j < node->GetNDevices (); ++j) |
163 { |
170 { |
164 devs.Add (node->GetDevice (j)); |
171 devs.Add (node->GetDevice (j)); |
165 } |
172 } |
166 } |
173 } |
167 EnablePcap (filename, devs); |
174 EnablePcap (filename, devs); |
168 } |
175 } |
169 |
176 |
170 void |
177 void |
174 } |
181 } |
175 |
182 |
176 void |
183 void |
177 WifiHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid) |
184 WifiHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid) |
178 { |
185 { |
179 Packet::EnableMetadata (); |
186 Packet::EnablePrinting (); |
180 std::ostringstream oss; |
187 std::ostringstream oss; |
181 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk"; |
188 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk"; |
182 Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyRxOkEvent, &os)); |
189 Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyRxOkEvent, &os)); |
183 oss.str (""); |
190 oss.str (""); |
184 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx"; |
191 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx"; |
199 NetDeviceContainer devs; |
206 NetDeviceContainer devs; |
200 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
207 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
201 { |
208 { |
202 Ptr<Node> node = *i; |
209 Ptr<Node> node = *i; |
203 for (uint32_t j = 0; j < node->GetNDevices (); ++j) |
210 for (uint32_t j = 0; j < node->GetNDevices (); ++j) |
204 { |
211 { |
205 devs.Add (node->GetDevice (j)); |
212 devs.Add (node->GetDevice (j)); |
206 } |
213 } |
207 } |
214 } |
208 EnableAscii (os, devs); |
215 EnableAscii (os, devs); |
209 } |
216 } |
210 |
217 |
211 void |
218 void |