Ilya Moiseenko | fa4e263 | 2011-09-01 17:38:31 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 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: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include <ctime> |
| 22 | #include <sstream> |
| 23 | |
| 24 | #include "ns3/core-module.h" |
| 25 | #include "ns3/network-module.h" |
| 26 | #include "ns3/internet-module.h" |
| 27 | #include "ns3/point-to-point-module.h" |
| 28 | #include "ns3/applications-module.h" |
| 29 | #include "ns3/ipv4-static-routing-helper.h" |
| 30 | #include "ns3/ipv4-list-routing-helper.h" |
| 31 | #include "ns3/annotated-topology-reader.h" |
| 32 | #include <list> |
| 33 | //#include "ns3/visualizer-module.h" |
| 34 | #include "ns3/ccnx-consumer-helper.h" |
| 35 | #include "ns3/ccnx-stack-helper.h" |
| 36 | |
| 37 | using namespace ns3; |
| 38 | using namespace std; |
| 39 | |
| 40 | NS_LOG_COMPONENT_DEFINE ("CcnxPcapExample"); |
| 41 | |
| 42 | int main (int argc, char *argv[]) |
| 43 | { |
| 44 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("10Mbps")); |
| 45 | Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("1ms")); |
| 46 | |
| 47 | NodeContainer c; |
| 48 | c.Create (2); |
| 49 | |
| 50 | NodeContainer n1 = NodeContainer (c.Get (0), c.Get (1)); |
| 51 | |
| 52 | PointToPointHelper p2p; |
| 53 | NetDeviceContainer ndc1 = p2p.Install (n1); |
| 54 | |
| 55 | // CcnxStackHelper ccnx; |
| 56 | // Ptr<CcnxFaceContainer> cf = ccnx.Install (c); |
| 57 | |
| 58 | //Ipv4AddressHelper ipv4; |
| 59 | //ipv4.SetBase ("192.168.1.0", "255.255.255.0"); |
| 60 | //Ipv4InterfaceContainer i1 = ipv4.Assign (ndc1); |
| 61 | |
| 62 | CcnxInterestHeader header; |
| 63 | Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> (); |
| 64 | (*testname) ("test") ("test2"); |
| 65 | header.SetName (testname); |
| 66 | header.SetNonce (1); |
| 67 | |
| 68 | Packet packet (0); |
| 69 | packet.AddHeader (header); |
| 70 | |
| 71 | Ptr<Node> nd = c.Get(0); |
| 72 | Ptr<PointToPointNetDevice> device = nd->GetDevice(nd->GetNDevices()-1)->GetObject<PointToPointNetDevice> (); |
| 73 | |
| 74 | |
| 75 | |
| 76 | Ptr<CcnxNameComponents> testname2 = Create<CcnxNameComponents> (); |
| 77 | (*testname2) ("test3") ("test4"); |
| 78 | header.SetName (testname2); |
| 79 | header.SetNonce (2); |
| 80 | Packet packet2 (0); |
| 81 | packet2.AddHeader (header); |
| 82 | |
| 83 | |
| 84 | p2p.EnablePcapAll("pcap-example.pcap"); |
| 85 | |
| 86 | Simulator::Stop (Seconds (20)); |
| 87 | |
| 88 | //NS_LOG_INFO ("Run Simulation."); |
| 89 | NS_LOG_INFO("Size1 = " << packet.GetSize()); |
| 90 | NS_LOG_INFO("Size2 = " << packet2.GetSize()); |
| 91 | device->Send(packet.Copy(),device->GetBroadcast(),0x7777); |
| 92 | NS_LOG_INFO(device->IsLinkUp()); |
| 93 | device->Send(packet2.Copy(),device->GetBroadcast(),0x7777); |
| 94 | NS_LOG_INFO(device->IsLinkUp()); |
| 95 | device->Send(packet2.Copy(),device->GetBroadcast(),0x7777); |
| 96 | NS_LOG_INFO(device->IsLinkUp()); |
| 97 | device->Send(packet2.Copy(),device->GetBroadcast(),0x7777); |
| 98 | device->Send(packet2.Copy(),device->GetBroadcast(),0x7777); |
| 99 | device->Send(packet2.Copy(),device->GetBroadcast(),0x7777); |
| 100 | device->Send(packet2.Copy(),device->GetBroadcast(),0x7777); |
| 101 | device->Send(packet2.Copy(),device->GetBroadcast(),0x7777); |
| 102 | device->Send(packet2.Copy(),device->GetBroadcast(),0x7777); |
| 103 | device->Send(packet2.Copy(),device->GetBroadcast(),0x7777); |
| 104 | device->Send(packet2.Copy(),device->GetBroadcast(),0x7777); |
| 105 | device->Send(packet2.Copy(),device->GetBroadcast(),0x7777); |
| 106 | NS_LOG_INFO ("Run Simulation."); |
| 107 | Simulator::Run (); |
| 108 | Simulator::Destroy (); |
| 109 | NS_LOG_INFO ("Done."); |
| 110 | } |