OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2014 Universita' di Firenze |
| 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: Tommaso Pecorella <tommaso.pecorella@unifi.it> |
| 19 */ |
| 20 |
| 21 // Network topology |
| 22 // |
| 23 // n0 n1 |
| 24 // | | |
| 25 // ================= |
| 26 // SimpleChannel |
| 27 // |
| 28 // - Packets flows from n0 to n1 |
| 29 // |
| 30 // This example shows how to use the SimpleServer and SimpleClient |
| 31 // to send non-IP packets over a SimpleNetDevice |
| 32 |
| 33 #include "ns3/core-module.h" |
| 34 #include "ns3/network-module.h" |
| 35 |
| 36 using namespace ns3; |
| 37 |
| 38 |
| 39 int main (int argc, char *argv[]) |
| 40 { |
| 41 bool verbose = false; |
| 42 |
| 43 CommandLine cmd; |
| 44 cmd.AddValue ("verbose", "turn on log components", verbose); |
| 45 cmd.Parse(argc, argv); |
| 46 |
| 47 if (verbose) |
| 48 { |
| 49 LogComponentEnable ("PacketSocketServer", LOG_LEVEL_ALL); |
| 50 LogComponentEnable ("PacketSocketClient", LOG_LEVEL_ALL); |
| 51 LogComponentEnable ("SimpleNetDevice", LOG_LEVEL_ALL); |
| 52 } |
| 53 |
| 54 NodeContainer nodes; |
| 55 nodes.Create (2); |
| 56 |
| 57 ns3::PacketMetadata::Enable(); |
| 58 |
| 59 PacketSocketHelper packetSocket; |
| 60 |
| 61 // give packet socket powers to nodes. |
| 62 packetSocket.Install (nodes); |
| 63 |
| 64 Ptr<SimpleNetDevice> txDev; |
| 65 txDev = CreateObject<SimpleNetDevice> (); |
| 66 nodes.Get (0)->AddDevice (txDev); |
| 67 |
| 68 Ptr<SimpleNetDevice> rxDev; |
| 69 rxDev = CreateObject<SimpleNetDevice> (); |
| 70 nodes.Get (1)->AddDevice (rxDev); |
| 71 |
| 72 Ptr<SimpleChannel> channel = CreateObject<SimpleChannel> (); |
| 73 txDev->SetChannel (channel); |
| 74 rxDev->SetChannel (channel); |
| 75 txDev->SetNode (nodes.Get (0)); |
| 76 rxDev->SetNode (nodes.Get (1)); |
| 77 |
| 78 |
| 79 PacketSocketAddress socketAddr; |
| 80 socketAddr.SetSingleDevice (txDev->GetIfIndex ()); |
| 81 socketAddr.SetPhysicalAddress (rxDev->GetAddress ()); |
| 82 // Arbitrary protocol type. |
| 83 // Note: PacketSocket doesn't have any L4 multiplexing or demultiplexing |
| 84 // The only mux/demux is based on the protocol field |
| 85 socketAddr.SetProtocol (1); |
| 86 |
| 87 Ptr<PacketSocketClient> client = CreateObject<PacketSocketClient> (); |
| 88 client->SetRemote (socketAddr); |
| 89 nodes.Get (0)->AddApplication (client); |
| 90 |
| 91 Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> (); |
| 92 server->SetLocal (socketAddr); |
| 93 nodes.Get (1)->AddApplication (server); |
| 94 |
| 95 Simulator::Run (); |
| 96 Simulator::Destroy (); |
| 97 return 0; |
| 98 } |
OLD | NEW |