OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * 2016 National Institute of Standards and Technology (NIST) |
| 4 * |
| 5 * This program is free software; you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 2 as |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 * |
| 18 * Author: Wesley Garey <wesley.garey@nist.gov> |
| 19 */ |
| 20 |
| 21 #include <stdint.h> |
| 22 #include <string> |
| 23 |
| 24 #include <ns3/address.h> |
| 25 #include <ns3/data-rate.h> |
| 26 #include <ns3/double.h> |
| 27 #include <ns3/names.h> |
| 28 #include <ns3/nist-mcptt-floor-machine.h> |
| 29 #include <ns3/nist-mcptt-floor-msg-parser.h> |
| 30 #include <ns3/nist-mcptt-ptt-app.h> |
| 31 #include <ns3/nist-mcptt-pusher.h> |
| 32 #include <ns3/nist-mcptt-send-requester.h> |
| 33 #include <ns3/packet-socket-address.h> |
| 34 #include <ns3/pointer.h> |
| 35 #include <ns3/ptr.h> |
| 36 #include <ns3/string.h> |
| 37 #include <ns3/udp-socket-factory.h> |
| 38 #include <ns3/uinteger.h> |
| 39 |
| 40 #include "nist-mcptt-helper.h" |
| 41 |
| 42 |
| 43 namespace ns3 { |
| 44 |
| 45 NistMcpttHelper::NistMcpttHelper () |
| 46 : m_appFac (ObjectFactory ()), |
| 47 m_floorFac (ObjectFactory ()), |
| 48 m_msgParserFac (ObjectFactory ()), |
| 49 m_nextUserId (1), |
| 50 m_requesterFac (ObjectFactory ()), |
| 51 m_pusherFac (ObjectFactory ()) |
| 52 {· |
| 53 this->SetAppTid (NistMcpttPttApp::GetTypeId ()); |
| 54 this->SetFloorMachineTid (NistMcpttFloorMachine::GetTypeId ()); |
| 55 this->SetMsgParserTid (NistMcpttMsgParser::GetTypeId ()); |
| 56 this->SetPusherTid (NistMcpttPusher::GetTypeId ()); |
| 57 this->SetRequesterTid (NistMcpttSendRequester::GetTypeId ()); |
| 58 |
| 59 this->SetAppAttribute ("LocalPort", UintegerValue (49153)); |
| 60 this->SetAppAttribute ("PeerAddress", AddressValue (Ipv4Address ("255.255.255.
255"))); |
| 61 this->SetAppAttribute ("PeerPort", UintegerValue (49153)); |
| 62 this->SetAppAttribute ("SocketFactoryTid", TypeIdValue (UdpSocketFactory::GetT
ypeId ())); |
| 63 this->SetRequesterAttribute ("Bytes", UintegerValue (1)); |
| 64 this->SetRequesterAttribute ("DataRate", DataRateValue (DataRate ("8b/s"))); |
| 65 this->SetPusherAttribute ("Rnd", PointerValue (CreateObjectWithAttributes<Norm
alRandomVariable> ("Mean", DoubleValue(5.0), "Variance", DoubleValue (2.0)))); |
| 66 |
| 67 } |
| 68 |
| 69 NistMcpttHelper::NistMcpttHelper (const Address& peerAddress, const uint16_t& pe
erPort) |
| 70 : m_appFac (ObjectFactory ()), |
| 71 m_floorFac (ObjectFactory ()), |
| 72 m_msgParserFac (ObjectFactory ()), |
| 73 m_nextUserId (1), |
| 74 m_requesterFac (ObjectFactory ()), |
| 75 m_pusherFac (ObjectFactory ()) |
| 76 {· |
| 77 this->SetAppTid (NistMcpttPttApp::GetTypeId ()); |
| 78 this->SetFloorMachineTid (NistMcpttFloorMachine::GetTypeId ()); |
| 79 this->SetMsgParserTid (NistMcpttMsgParser::GetTypeId ()); |
| 80 this->SetPusherTid (NistMcpttPusher::GetTypeId ()); |
| 81 this->SetRequesterTid (NistMcpttSendRequester::GetTypeId ()); |
| 82 |
| 83 this->SetAppAttribute ("LocalPort", UintegerValue (49153)); |
| 84 this->SetAppAttribute ("PeerAddress", AddressValue (peerAddress)); |
| 85 this->SetAppAttribute ("PeerPort", UintegerValue (peerPort)); |
| 86 this->SetAppAttribute ("SocketFactoryTid", TypeIdValue (UdpSocketFactory::GetT
ypeId ())); |
| 87 this->SetRequesterAttribute ("Bytes", UintegerValue (1)); |
| 88 this->SetRequesterAttribute ("DataRate", DataRateValue (DataRate ("8b/s"))); |
| 89 this->SetPusherAttribute ("Rnd", PointerValue (CreateObjectWithAttributes<Norm
alRandomVariable> ("Mean", DoubleValue(5.0), "Variance", DoubleValue (2.0)))); |
| 90 } |
| 91 |
| 92 NistMcpttHelper::~NistMcpttHelper () |
| 93 { } |
| 94 |
| 95 ApplicationContainer |
| 96 NistMcpttHelper::Install (const Ptr<Node>& node) |
| 97 { |
| 98 return ApplicationContainer (this->InstallPriv (node)); |
| 99 } |
| 100 |
| 101 ApplicationContainer |
| 102 NistMcpttHelper::Install (const std::string& nodeName) |
| 103 { |
| 104 Ptr<Node> node = Names::Find<Node> (nodeName); |
| 105 ·· |
| 106 return ApplicationContainer (this->InstallPriv (node)); |
| 107 } |
| 108 |
| 109 ApplicationContainer |
| 110 NistMcpttHelper::Install (const NodeContainer& c) |
| 111 { |
| 112 ApplicationContainer apps; |
| 113 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 114 { |
| 115 apps.Add (this->InstallPriv (*i)); |
| 116 } |
| 117 |
| 118 return apps; |
| 119 } |
| 120 |
| 121 void |
| 122 NistMcpttHelper::SetAppAttribute (const std::string& name, const AttributeValue&
value) |
| 123 { |
| 124 this->m_appFac.Set (name, value); |
| 125 } |
| 126 |
| 127 void |
| 128 NistMcpttHelper::SetAppTid (const TypeId& appTid) |
| 129 { |
| 130 TypeId pttAppTid = NistMcpttPttApp::GetTypeId (); |
| 131 |
| 132 NS_ASSERT_MSG ((appTid == pttAppTid || appTid.IsChildOf (pttAppTid)), "The giv
en type ID is not that of a " << pttAppTid.GetName () << "."); |
| 133 |
| 134 this->m_appFac.SetTypeId (appTid); |
| 135 } |
| 136 |
| 137 void |
| 138 NistMcpttHelper::SetFloorMachineAttribute (const std::string& name, const Attrib
uteValue& value) |
| 139 { |
| 140 this->m_floorFac.Set (name, value); |
| 141 } |
| 142 |
| 143 void |
| 144 NistMcpttHelper::SetFloorMachineTid (const TypeId& floorTid) |
| 145 { |
| 146 TypeId floorMachineTid = NistMcpttFloorMachine::GetTypeId (); |
| 147 |
| 148 NS_ASSERT_MSG ((floorTid == floorMachineTid || floorTid.IsChildOf (floorMachin
eTid)), "The given type ID is not that of a " << floorMachineTid.GetName () << "
."); |
| 149 |
| 150 this->m_floorFac.SetTypeId (floorTid); |
| 151 } |
| 152 |
| 153 void |
| 154 NistMcpttHelper::SetMsgParserAttribute (const std::string& name, const Attribute
Value& value) |
| 155 { |
| 156 this->m_msgParserFac.Set (name, value); |
| 157 } |
| 158 |
| 159 void |
| 160 NistMcpttHelper::SetMsgParserTid (const TypeId& parserTid) |
| 161 { |
| 162 TypeId mcpttParserTid = NistMcpttMsgParser::GetTypeId (); |
| 163 |
| 164 NS_ASSERT_MSG ((parserTid == mcpttParserTid || parserTid.IsChildOf (mcpttParse
rTid)), "The given type ID is not that of a " << mcpttParserTid.GetName () << ".
"); |
| 165 |
| 166 this->m_msgParserFac.SetTypeId (parserTid); |
| 167 } |
| 168 |
| 169 void |
| 170 NistMcpttHelper::SetPusherAttribute (const std::string& name, const AttributeVal
ue& value) |
| 171 { |
| 172 this->m_pusherFac.Set (name, value); |
| 173 } |
| 174 |
| 175 void |
| 176 NistMcpttHelper::SetPusherTid (const TypeId& pusherTid) |
| 177 { |
| 178 TypeId mcpttPusherTid = NistMcpttPusher::GetTypeId (); |
| 179 |
| 180 NS_ASSERT_MSG ((pusherTid == mcpttPusherTid || pusherTid.IsChildOf (mcpttPushe
rTid)), "The given type ID is not that of a " << mcpttPusherTid.GetName () << ".
"); |
| 181 |
| 182 this->m_pusherFac.SetTypeId (pusherTid); |
| 183 } |
| 184 |
| 185 void |
| 186 NistMcpttHelper::SetRequesterAttribute (const std::string& name, const Attribute
Value& value) |
| 187 { |
| 188 this->m_requesterFac.Set (name, value); |
| 189 } |
| 190 |
| 191 void |
| 192 NistMcpttHelper::SetRequesterTid (const TypeId& requesterTid) |
| 193 { |
| 194 TypeId mcpttRequesterTid = NistMcpttSendRequester::GetTypeId (); |
| 195 |
| 196 NS_ASSERT_MSG ((mcpttRequesterTid == requesterTid || requesterTid.IsChildOf (m
cpttRequesterTid)), "The given type ID is not that of a " << mcpttRequesterTid.G
etName () << "."); |
| 197 |
| 198 this->m_requesterFac.SetTypeId (requesterTid); |
| 199 } |
| 200 |
| 201 Ptr<Application> |
| 202 NistMcpttHelper::InstallPriv (const Ptr<Node>& node) |
| 203 { |
| 204 uint32_t userId = this->NextUserId (); |
| 205 |
| 206 Ptr<NistMcpttPttApp> app = this->m_appFac.Create<NistMcpttPttApp> (); |
| 207 Ptr<NistMcpttFloorMachine> floorMachine = this->m_floorFac.Create<NistMcpttFlo
orMachine> (); |
| 208 Ptr<NistMcpttMsgParser> msgParser = this->m_msgParserFac.Create<NistMcpttMsgPa
rser> (); |
| 209 Ptr<NistMcpttSendRequester> requester = this->m_requesterFac.Create<NistMcpttS
endRequester> (); |
| 210 Ptr<NistMcpttPusher> pusher = this->m_pusherFac.Create<NistMcpttPusher> (); |
| 211 |
| 212 app->SetUserId (userId); |
| 213 app->SetDataSrc (requester); |
| 214 app->SetFloorMachine (floorMachine); |
| 215 app->SetMsgParser (msgParser); |
| 216 app->SetPusher (pusher); |
| 217 |
| 218 node->AddApplication (app); |
| 219 |
| 220 return app; |
| 221 } |
| 222 |
| 223 uint32_t |
| 224 NistMcpttHelper::NextUserId (void) |
| 225 { |
| 226 uint32_t current = this->GetNextUserId (); |
| 227 uint32_t next = current + 1; |
| 228 |
| 229 this->SetNextUserId (next); |
| 230 |
| 231 return current; |
| 232 } |
| 233 |
| 234 uint32_t |
| 235 NistMcpttHelper::GetNextUserId (void) const |
| 236 { |
| 237 return this->m_nextUserId; |
| 238 } |
| 239 |
| 240 void |
| 241 NistMcpttHelper::SetNextUserId (const uint32_t& nextUserId) |
| 242 { |
| 243 this->m_nextUserId = nextUserId; |
| 244 } |
| 245 |
| 246 } // namespace ns3 |
| 247 |
OLD | NEW |