OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2013 Dalian University of Technology |
| 4 * This program is free software; you can redistribute it and/or modify |
| 5 * it under the terms of the GNU General Public License version 2 as |
| 6 * published by the Free Software Foundation; |
| 7 * |
| 8 * This program is distributed in the hope that it will be useful, |
| 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 * GNU General Public License for more details. |
| 12 * |
| 13 * You should have received a copy of the GNU General Public License |
| 14 * along with this program; if not, write to the Free Software |
| 15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 * |
| 17 * Author: Junling Bu <linlinjavaer@gmail.com> |
| 18 */ |
| 19 #include "ns3/log.h" |
| 20 #include "ns3/string.h" |
| 21 #include "ns3/command-line.h" |
| 22 #include "ns3/mobility-model.h" |
| 23 #include "ns3/yans-wifi-helper.h" |
| 24 #include "ns3/position-allocator.h" |
| 25 #include "ns3/mobility-helper.h" |
| 26 #include "ns3/wifi-net-device.h" |
| 27 #include <iostream> |
| 28 |
| 29 #include "ns3/ocb-wifi-mac.h" |
| 30 #include "ns3/wifi-80211p-helper.h" |
| 31 #include "ns3/wave-mac-helper.h" |
| 32 |
| 33 NS_LOG_COMPONENT_DEFINE ("WaveVsaExample"); |
| 34 |
| 35 using namespace ns3; |
| 36 |
| 37 /* |
| 38 * Normally the higher layer can send packets in different protocols |
| 39 * via 802.11 data frame, like ipv4 and ipv6. |
| 40 * However, actually wifi know nothing about these differences, |
| 41 * because this work has been done with LlcSnapHeader with protocol field. |
| 42 * So if higher layer wants to send different management informations |
| 43 * over 802.11 management frame (of course nobody can prevent someone just |
| 44 * wants to send management information over 802.11 data frame), how can we do? |
| 45 * The 802.11 and 802.11p can allow the higher layer send different information
s |
| 46 * over Vendor Specific Action management frame by using different |
| 47 * OrganizationIdentifier fields to identify differences. |
| 48 * Usage: |
| 49 * 1. define an OrganizationIdentifier |
| 50 * uint8_t oi_bytes[5] = {0x00, 0x50, 0xC2, 0x4A, 0x40}; |
| 51 * OrganizationIdentifier oi(oi_bytes,5); |
| 52 * 2. define a Callback for the defined OrganizationIdentifier |
| 53 * VscCallback vsccall = MakeCallback (&VsaExample::GetWsaAndOi, this); |
| 54 * 3. OcbWifiMac registers this identifier and function |
| 55 * Ptr<WifiNetDevice> device1 = DynamicCast<WifiNetDevice>(nodes.Get (i)->Ge
tDevice (0)); |
| 56 * Ptr<OcbWifiMac> ocb1 = DynamicCast<OcbWifiMac>(device->GetMac ()); |
| 57 * ocb1->AddReceiveVscCallback (oi, vsccall); |
| 58 * 4. now you can send management packet over VSA frame |
| 59 * Ptr<Packet> vsc = Create<Packet> (); |
| 60 * ocb2->SendVsc (vsc, Mac48Address::GetBroadcast (), m_16093oi); |
| 61 * 5. then registed callback in other devices will be called. |
| 62 */ |
| 63 class VsaExample |
| 64 { |
| 65 public: |
| 66 VsaExample (); |
| 67 virtual ~VsaExample (); |
| 68 void DoRun (void); |
| 69 private: |
| 70 void SendWsa (Ptr<OcbWifiMac>); |
| 71 void SendAuthen (Ptr<OcbWifiMac>); |
| 72 bool GetWsaAndOi (const OrganizationIdentifier &,Ptr<const Packet>,const Addre
ss &); |
| 73 bool GetAuthenAndOi (const OrganizationIdentifier &,Ptr<const Packet>,const Ad
dress &); |
| 74 |
| 75 OrganizationIdentifier m_16093oi; |
| 76 OrganizationIdentifier m_authenoi; |
| 77 }; |
| 78 |
| 79 VsaExample::VsaExample () |
| 80 { |
| 81 // define two OrganizationIdentifier |
| 82 // 00-50-C2-4A-4y is used in WAVE |
| 83 // 00-0F-AC is used in authentication services, see 802.11-2010 chapter 4.10 |
| 84 uint8_t oi_bytes_16093[5] = {0x00, 0x50, 0xC2, 0x4A, 0x40}; |
| 85 OrganizationIdentifier oi_16093 (oi_bytes_16093,5); |
| 86 m_16093oi = oi_16093; |
| 87 |
| 88 uint8_t oi_bytes_authen[5] = {0x00, 0x0F, 0xAC}; |
| 89 OrganizationIdentifier oi_authen (oi_bytes_authen,3); |
| 90 m_authenoi = oi_authen; |
| 91 } |
| 92 |
| 93 |
| 94 VsaExample::~VsaExample () |
| 95 { |
| 96 } |
| 97 |
| 98 bool |
| 99 VsaExample::GetWsaAndOi (const OrganizationIdentifier & oi,Ptr<const Packet> wsa
, const Address & peer) |
| 100 { |
| 101 std::cout << "receive wsa packet" << std::endl; |
| 102 return true; |
| 103 } |
| 104 |
| 105 bool |
| 106 VsaExample::GetAuthenAndOi (const OrganizationIdentifier & oi,Ptr<const Packet>
auth,const Address & peer) |
| 107 { |
| 108 std::cout << "receive authen packet" << std::endl; |
| 109 return true; |
| 110 } |
| 111 |
| 112 void |
| 113 VsaExample::SendWsa (Ptr<OcbWifiMac> ocb) |
| 114 { |
| 115 Ptr<Packet> vsc = Create<Packet> (); |
| 116 VendorSpecificActionHeader vsa; |
| 117 ocb->SendVsc (vsc, Mac48Address::GetBroadcast (), m_16093oi); |
| 118 } |
| 119 |
| 120 void |
| 121 VsaExample::SendAuthen (Ptr<OcbWifiMac> ocb) |
| 122 { |
| 123 Ptr<Packet> auth = Create<Packet> (); |
| 124 VendorSpecificActionHeader vsa; |
| 125 ocb->SendVsc (auth, Mac48Address::GetBroadcast (),m_authenoi); |
| 126 } |
| 127 |
| 128 |
| 129 void |
| 130 VsaExample::DoRun (void) |
| 131 { |
| 132 VscCallback vsccall = MakeCallback (&VsaExample::GetWsaAndOi, this); |
| 133 VscCallback authencall = MakeCallback (&VsaExample::GetAuthenAndOi, this); |
| 134 |
| 135 NodeContainer nodes; |
| 136 nodes.Create (2); |
| 137 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
| 138 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); |
| 139 wifiPhy.SetChannel (wifiChannel.Create ()); |
| 140 NqosWaveMacHelper wifi80211pMac = NqosWaveMacHelper::Default (); |
| 141 |
| 142 Wifi80211pHelper wifi80211p = Wifi80211pHelper::Default (); |
| 143 wifi80211p.SetRemoteStationManager ("ns3::ConstantRateWifiManager", |
| 144 "DataMode", StringValue ("OfdmRate6MbpsBW1
0MHz"), |
| 145 "ControlMode",StringValue ("OfdmRate6MbpsB
W10MHz")); |
| 146 wifi80211p.Install (wifiPhy, wifi80211pMac, nodes); |
| 147 |
| 148 MobilityHelper mobility; |
| 149 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>
(); |
| 150 positionAlloc->Add (Vector (0.0, 0.0, 0.0)); |
| 151 positionAlloc->Add (Vector (5.0, 0.0, 0.0)); |
| 152 mobility.SetPositionAllocator (positionAlloc); |
| 153 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
| 154 mobility.Install (nodes); |
| 155 |
| 156 for (uint32_t i = 0; i < nodes.GetN (); i++) |
| 157 { |
| 158 Ptr<WifiNetDevice> device = DynamicCast<WifiNetDevice> (nodes.Get (i)->Get
Device (0)); |
| 159 Ptr<OcbWifiMac> ocb = DynamicCast<OcbWifiMac> (device->GetMac ()); |
| 160 ocb->AddReceiveVscCallback (m_16093oi, vsccall); |
| 161 ocb->AddReceiveVscCallback (m_authenoi, authencall); |
| 162 Simulator::Schedule (Seconds (i), &VsaExample::SendWsa, this, ocb); |
| 163 Simulator::Schedule (Seconds (i + 0.5), &VsaExample::SendAuthen, this, ocb
); |
| 164 } |
| 165 Simulator::Run (); |
| 166 Simulator::Destroy (); |
| 167 } |
| 168 |
| 169 int main (int argc, char *argv[]) |
| 170 { |
| 171 VsaExample vsa; |
| 172 vsa.DoRun (); |
| 173 return 0; |
| 174 } |
OLD | NEW |