blob: 14485d5a0e8d0aa4cecf783c4c57d90637ef31c0 [file] [log] [blame]
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -07003#include <ns3/core-module.h>
4#include <ns3/network-module.h>
5#include <ns3/NDNabstraction-module.h>
6#include <ns3/point-to-point-module.h>
7
8#include "sync-logic.h"
Alexander Afanasyev09e8d752012-04-10 16:05:55 -07009#include "sync-logic-helper.h"
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080010
11using namespace ns3;
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070012using namespace Sync;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080013
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070014NS_LOG_COMPONENT_DEFINE ("SyncExample");
15
Alexander Afanasyev09e8d752012-04-10 16:05:55 -070016void OnUpdate (const std::string &prefix, const SeqNo &newSeq, const SeqNo &/*oldSeq*/)
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070017{
Alexander Afanasyev09e8d752012-04-10 16:05:55 -070018 NS_LOG_LOGIC (Simulator::Now ().ToDouble (Time::S) <<"s\tNode: " << Simulator::GetContext () << ", prefix: " << prefix << ", seqNo: " << newSeq);
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070019}
20
Alexander Afanasyev09e8d752012-04-10 16:05:55 -070021void OnRemove (const std::string &prefix)
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070022{
Alexander Afanasyev09e8d752012-04-10 16:05:55 -070023 NS_LOG_LOGIC (Simulator::Now ().ToDouble (Time::S) <<"s\tNode: " << Simulator::GetContext () << ", prefix: "<< prefix);
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070024}
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080025
26int
27main (int argc, char *argv[])
28{
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070029 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
30 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
31 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
32
33 Config::SetDefault ("ns3::CcnxFloodingStrategy::SmartFlooding", StringValue ("false"));
34
35 LogComponentEnable ("SyncExample", LOG_ALL);
36
37 Time finishTime = Seconds (3.0);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080038
39 CommandLine cmd;
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070040 cmd.AddValue ("finish", "Finish time", finishTime);
41 cmd.Parse (argc, argv);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080042
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070043 // Creating nodes
44 NodeContainer nodes;
45 nodes.Create (3);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080046
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070047 // Connecting nodes using two links
48 PointToPointHelper p2p;
49 p2p.Install (nodes.Get (0), nodes.Get (1));
50 p2p.Install (nodes.Get (1), nodes.Get (2));
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080051
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070052 Names::Add ("0", nodes.Get (0));
53 Names::Add ("1", nodes.Get (1));
54 Names::Add ("2", nodes.Get (2));
55
56 // Install CCNx stack on all nodes
57 NS_LOG_INFO ("Installing CCNx stack");
58 CcnxStackHelper ccnxHelper;
59 ccnxHelper.SetForwardingStrategy ("ns3::CcnxFloodingStrategy");
60 ccnxHelper.SetDefaultRoutes (false);
61 ccnxHelper.InstallAll ();
62
63 ccnxHelper.AddRoute ("0", "/sync", 0, 0);
64 ccnxHelper.AddRoute ("1", "/sync", 0, 0);
65 ccnxHelper.AddRoute ("1", "/sync", 1, 0);
66 ccnxHelper.AddRoute ("2", "/sync", 0, 0);
67
Alexander Afanasyev09e8d752012-04-10 16:05:55 -070068 SyncLogicHelper logicHelper;
69 logicHelper.SetPrefix ("/sync");
70 logicHelper.SetCallbacks (OnUpdate, OnRemove);
71 ApplicationContainer apps = logicHelper.Install (NodeContainer (nodes.Get (0), nodes.Get (1)));
72
Alexander Afanasyev9cbebab2012-04-09 15:47:19 -070073 // one data
74 Simulator::ScheduleWithContext (0, Seconds (0.5), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (0)), "/0", 1, 1);
75
76 // two producers at the same time
77 Simulator::ScheduleWithContext (0, Seconds (1.001), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (0)), "/0", 1, 2);
78 Simulator::ScheduleWithContext (1, Seconds (1.001), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (1)), "/1", 1, 2);
Alexander Afanasyev09e8d752012-04-10 16:05:55 -070079
80 logicHelper.Install (nodes.Get (2)).
81 Start (Seconds (2.001));
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070082
83 Simulator::Stop (finishTime);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080084 Simulator::Run ();
85 Simulator::Destroy ();
86 return 0;
87}
88
89