move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
This commit is contained in:
@@ -31,12 +31,15 @@
|
||||
#include "ns3/serial-channel.h"
|
||||
#include "ns3/serial-net-device.h"
|
||||
#include "ns3/trace-writer.h"
|
||||
#include "ns3/trace-container.h"
|
||||
#include "ns3/drop-tail.h"
|
||||
#include "ns3/arp-ipv4-interface.h"
|
||||
#include "ns3/ipv4.h"
|
||||
#include "ns3/trace-context.h"
|
||||
#include "ns3/udp-socket.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/node-list.h"
|
||||
#include "ns3/trace-root.h"
|
||||
|
||||
#include "ns3/pcap-writer.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
@@ -61,27 +64,74 @@ public:
|
||||
|
||||
~Logger () {}
|
||||
|
||||
void Log (std::string const &name, const Packet &p)
|
||||
void Log (TraceContext const &context, const Packet &p)
|
||||
{
|
||||
NS_DEBUG_UNCOND("**** LogEnque ("<< name << " " << &p << ")");
|
||||
m_filestr << name << " " << &p << std::endl;
|
||||
NodeList::NodeIndex nodeIndex;
|
||||
context.Get (nodeIndex);
|
||||
m_filestr << "node=" << NodeList::GetNode (nodeIndex)->GetId () << " ";
|
||||
Ipv4::InterfaceIndex interfaceIndex;
|
||||
context.Get (interfaceIndex);
|
||||
m_filestr << "interface=" << interfaceIndex << " ";
|
||||
enum Queue::TraceType type;
|
||||
context.Get (type);
|
||||
switch (type)
|
||||
{
|
||||
case Queue::ENQUEUE:
|
||||
m_filestr << "enqueue";
|
||||
break;
|
||||
case Queue::DEQUEUE:
|
||||
m_filestr << "dequeue";
|
||||
break;
|
||||
case Queue::DROP:
|
||||
m_filestr << "drop";
|
||||
break;
|
||||
}
|
||||
m_filestr << " bytes=" << p.GetSize () << std::endl;
|
||||
}
|
||||
|
||||
protected:
|
||||
TraceWriter m_tracer;
|
||||
};
|
||||
|
||||
static void
|
||||
GenerateTraffic (UdpSocket *socket, uint32_t size)
|
||||
{
|
||||
std::cout << "Node: " << socket->GetNode()->GetId ()
|
||||
<< " at=" << Simulator::Now ().GetSeconds () << "s,"
|
||||
<< " tx bytes=" << size << std::endl;
|
||||
socket->SendDummy (size);
|
||||
if (size > 50)
|
||||
{
|
||||
Simulator::Schedule (Seconds (0.5), &GenerateTraffic, socket, size - 50);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
UdpSocketPrinter (UdpSocket *socket, uint32_t size, Ipv4Address from, uint16_t fromPort)
|
||||
{
|
||||
std::cout << "Node: " << socket->GetNode()->GetId ()
|
||||
<< " at=" << Simulator::Now ().GetSeconds () << "s,"
|
||||
<< " rx bytes=" << size << std::endl;
|
||||
}
|
||||
|
||||
static void
|
||||
PrintTraffic (UdpSocket *socket)
|
||||
{
|
||||
socket->SetDummyRxCallback (MakeCallback (&UdpSocketPrinter));
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
NS_DEBUG_UNCOND("Serial Net Device Test");
|
||||
|
||||
TraceContainer traceContainerA;
|
||||
TraceContainer traceContainerB;
|
||||
|
||||
// create two nodes and a simple SerialChannel
|
||||
InternetNode a;
|
||||
InternetNode b;
|
||||
SerialChannel ch;
|
||||
SerialChannel ch = SerialChannel ("Test Channel", 1000, Seconds (0.1));
|
||||
|
||||
NodeList::Add (&a);
|
||||
NodeList::Add (&b);
|
||||
|
||||
// create two NetDevices and assign one to each node
|
||||
// Note: this would normally be done also in conjunction with
|
||||
@@ -94,8 +144,7 @@ int main (int argc, char *argv[])
|
||||
MacAddress addra("00:00:00:00:00:01");
|
||||
SerialNetDevice neta(&a, addra);
|
||||
|
||||
DropTailQueue dtqa ("a");
|
||||
dtqa.RegisterTraces (traceContainerA);
|
||||
DropTailQueue dtqa;
|
||||
|
||||
neta.AddQueue(&dtqa);
|
||||
neta.SetName("a.eth0");
|
||||
@@ -103,16 +152,15 @@ int main (int argc, char *argv[])
|
||||
MacAddress addrb("00:00:00:00:00:02");
|
||||
SerialNetDevice netb(&b, addrb);
|
||||
|
||||
DropTailQueue dtqb ("b");
|
||||
dtqb.RegisterTraces (traceContainerB);
|
||||
DropTailQueue dtqb;
|
||||
|
||||
netb.AddQueue(&dtqb);
|
||||
netb.SetName("b.eth0");
|
||||
|
||||
// bind the two NetDevices together by using a simple Channel
|
||||
// this method changed to do a bidirectional binding
|
||||
ch.Attach(&neta);
|
||||
ch.Attach(&netb);
|
||||
neta.Attach (&ch);
|
||||
netb.Attach (&ch);
|
||||
|
||||
// Some simple prints to see whether it is working
|
||||
NS_DEBUG_UNCOND("neta.GetMtu() <= " << neta.GetMtu());
|
||||
@@ -153,6 +201,9 @@ int main (int argc, char *argv[])
|
||||
NS_DEBUG_UNCOND("Setting ARP interface to UP");
|
||||
arpipv4interfacep->SetUp();
|
||||
|
||||
a.GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1);
|
||||
|
||||
|
||||
NS_DEBUG_UNCOND("Adding ARP Interface to InternetNode b");
|
||||
ArpIpv4Interface* arpipv4interfacepb = new ArpIpv4Interface(&b, &netb);
|
||||
uint32_t indexB = (&b)->GetIpv4 ()->AddInterface (arpipv4interfacepb);
|
||||
@@ -170,20 +221,28 @@ int main (int argc, char *argv[])
|
||||
NS_DEBUG_UNCOND("Setting ARP interface to UP");
|
||||
arpipv4interfacepb->SetUp();
|
||||
|
||||
b.GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.1.1"), 1);
|
||||
|
||||
|
||||
UdpSocket *source = new UdpSocket (&a);
|
||||
UdpSocket *sink = new UdpSocket(&b);
|
||||
sink->Bind (80);
|
||||
source->SetDefaultDestination (Ipv4Address ("10.1.1.2"), 80);
|
||||
|
||||
Logger logger("serial-net-test.log");
|
||||
|
||||
traceContainerA.SetCallback ("Queue::Enque",
|
||||
MakeCallback (&Logger::Log, &logger));
|
||||
TraceRoot::Connect ("/nodes/*/ipv4/interfaces/*/netdevice/queue/*",
|
||||
MakeCallback (&Logger::Log, &logger));
|
||||
|
||||
// create a packet on one node and send it through, reading it
|
||||
// on the other node
|
||||
Packet p;
|
||||
PrintTraffic (sink);
|
||||
GenerateTraffic (source, 100);
|
||||
|
||||
NS_DEBUG_UNCOND("Sending Packet " << &p);
|
||||
arpipv4interfacep->Send(p, Ipv4Address("10.1.1.2"));
|
||||
Simulator::Run ();
|
||||
|
||||
//neta.Send(p, MacAddress()); // Test that all-zero's MacAddress used
|
||||
//netb.Send(p, "00:01:02:03:04:05"); // Dummy function call
|
||||
Simulator::Destroy ();
|
||||
|
||||
delete source;
|
||||
delete sink;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
CallbackTracer<Packet> a;
|
||||
CallbackTraceSourcer<Packet> a;
|
||||
UiVariableTracer<unsigned short> b;
|
||||
StreamTracer c;
|
||||
CallbackTracer<double, int> d;
|
||||
CallbackTraceSourcer<double, int> d;
|
||||
|
||||
void
|
||||
RegisterAllTraceSources (TraceContainer *container)
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
|
||||
#include "ns3/internet-node.h"
|
||||
#include "ns3/serial-channel.h"
|
||||
#include "ns3/serial-net-device.h"
|
||||
#include "ns3/mac-address.h"
|
||||
#include "ns3/ipv4-address.h"
|
||||
#include "ns3/arp-ipv4-interface.h"
|
||||
@@ -60,6 +61,8 @@
|
||||
#include "ns3/arp-header.h"
|
||||
#include "ns3/ipv4-header.h"
|
||||
#include "ns3/udp-header.h"
|
||||
#include "ns3/node-list.h"
|
||||
#include "ns3/trace-root.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
@@ -81,23 +84,37 @@ public:
|
||||
|
||||
~Tracer () {};
|
||||
|
||||
void LogEnqueue (std::string const &name, const Packet &p)
|
||||
void LogNodeInterface (TraceContext const &context)
|
||||
{
|
||||
m_filestr << name << " que ";
|
||||
PrintLlcPacket (p, m_filestr);
|
||||
NodeList::NodeIndex nodeIndex;
|
||||
context.Get (nodeIndex);
|
||||
m_filestr << "node=" << NodeList::GetNode (nodeIndex)->GetId () << " ";
|
||||
Ipv4::InterfaceIndex interfaceIndex;
|
||||
context.Get (interfaceIndex);
|
||||
m_filestr << "interface=" << interfaceIndex << " ";
|
||||
}
|
||||
|
||||
|
||||
void LogEnqueue (TraceContext const &context, const Packet &p)
|
||||
{
|
||||
LogNodeInterface (context);
|
||||
m_filestr << " que p=" << p.GetUid ();
|
||||
//PrintLlcPacket (p, m_filestr);
|
||||
m_filestr << std::endl;
|
||||
}
|
||||
|
||||
void LogDequeue (std::string const &name, const Packet &p)
|
||||
void LogDequeue (TraceContext const &context, const Packet &p)
|
||||
{
|
||||
m_filestr << name << " deq ";
|
||||
PrintLlcPacket (p, m_filestr);
|
||||
LogNodeInterface (context);
|
||||
m_filestr << " deq p=" << p.GetUid ();
|
||||
//PrintLlcPacket (p, m_filestr);
|
||||
m_filestr << std::endl;
|
||||
}
|
||||
void LogDrop (std::string const &name, const Packet &p)
|
||||
void LogDrop (TraceContext const &context, const Packet &p)
|
||||
{
|
||||
m_filestr << name << " dro ";
|
||||
PrintLlcPacket (p, m_filestr);
|
||||
LogNodeInterface (context);
|
||||
m_filestr << " dro p=" << p.GetUid ();
|
||||
//PrintLlcPacket (p, m_filestr);
|
||||
m_filestr << std::endl;
|
||||
}
|
||||
|
||||
@@ -199,7 +216,7 @@ PrintRoutingTable (InternetNode *a, std::string name)
|
||||
|
||||
static SerialChannel *
|
||||
AddDuplexLink(
|
||||
std::string &name,
|
||||
std::string name,
|
||||
uint64_t bps,
|
||||
uint32_t delay,
|
||||
InternetNode* a,
|
||||
@@ -207,12 +224,8 @@ AddDuplexLink(
|
||||
const MacAddress& macaddra,
|
||||
InternetNode* b,
|
||||
const Ipv4Address& addrb,
|
||||
const MacAddress& macaddrb,
|
||||
// const Rate& rate,
|
||||
// const Time& delay,
|
||||
TraceContainer &traceContainer)
|
||||
const MacAddress& macaddrb)
|
||||
{
|
||||
std::string qName;
|
||||
SerialChannel* channel = new SerialChannel(name, bps, MilliSeconds(delay));
|
||||
|
||||
// Duplex link is assumed to be subnetted as a /30
|
||||
@@ -220,30 +233,24 @@ AddDuplexLink(
|
||||
Ipv4Mask netmask("255.255.255.252");
|
||||
assert(netmask.IsMatch(addra,addrb));
|
||||
|
||||
qName = name + "::Queue A";
|
||||
DropTailQueue* dtqa = new DropTailQueue(qName);
|
||||
dtqa->RegisterTraces (traceContainer);
|
||||
DropTailQueue* dtqa = new DropTailQueue();
|
||||
|
||||
SerialNetDevice* neta = new SerialNetDevice(a, macaddra);
|
||||
neta->AddQueue(dtqa);
|
||||
Ipv4Interface *interfA = new ArpIpv4Interface (a, neta);
|
||||
uint32_t indexA = a->GetIpv4 ()->AddInterface (interfA);
|
||||
channel->Attach (neta);
|
||||
neta->Attach (channel);
|
||||
|
||||
interfA->SetAddress (addra);
|
||||
interfA->SetNetworkMask (netmask);
|
||||
interfA->SetUp ();
|
||||
|
||||
qName = name + "::Queue B";
|
||||
DropTailQueue* dtqb = new DropTailQueue(qName);
|
||||
dtqb->RegisterTraces (traceContainer);
|
||||
DropTailQueue* dtqb = new DropTailQueue();
|
||||
|
||||
SerialNetDevice* netb = new SerialNetDevice(b, macaddrb);
|
||||
netb->AddQueue(dtqb);
|
||||
Ipv4Interface *interfB = new ArpIpv4Interface (b, netb);
|
||||
uint32_t indexB = b->GetIpv4 ()->AddInterface (interfB);
|
||||
channel->Attach (netb);
|
||||
netb->Attach (channel);
|
||||
|
||||
interfB->SetAddress (addrb);
|
||||
@@ -262,19 +269,6 @@ AddDuplexLink(
|
||||
return channel;
|
||||
}
|
||||
|
||||
static void
|
||||
SetupTrace (TraceContainer &container, Tracer &tracer)
|
||||
{
|
||||
container.SetCallback ("Queue::Enqueue",
|
||||
MakeCallback (&Tracer::LogEnqueue, &tracer));
|
||||
|
||||
container.SetCallback ("Queue::Dequeue",
|
||||
MakeCallback (&Tracer::LogDequeue, &tracer));
|
||||
|
||||
container.SetCallback ("Queue::Drop",
|
||||
MakeCallback (&Tracer::LogDrop, &tracer));
|
||||
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
@@ -295,37 +289,27 @@ int main (int argc, char *argv[])
|
||||
InternetNode *n2 = new InternetNode();
|
||||
InternetNode *n3 = new InternetNode();
|
||||
|
||||
TraceContainer traceContainer;
|
||||
NodeList::Add (n0);
|
||||
NodeList::Add (n1);
|
||||
NodeList::Add (n2);
|
||||
NodeList::Add (n3);
|
||||
|
||||
n0->SetName(std::string("Node 0"));
|
||||
n1->SetName(std::string("Node 1"));
|
||||
n2->SetName(std::string("Node 2"));
|
||||
n3->SetName(std::string("Node 3"));
|
||||
|
||||
Tracer tracer("serial-net-test.log");
|
||||
|
||||
std::string channelName;
|
||||
|
||||
channelName = "Channel 1";
|
||||
SerialChannel* ch1 = AddDuplexLink (channelName, 5000000, 2,
|
||||
SerialChannel* ch1 = AddDuplexLink ("Channel 1", 5000000, 2,
|
||||
n0, Ipv4Address("10.1.1.1"), MacAddress("00:00:00:00:00:01"),
|
||||
n2, Ipv4Address("10.1.1.2"), MacAddress("00:00:00:00:00:02"),
|
||||
traceContainer);
|
||||
SetupTrace (traceContainer, tracer);
|
||||
|
||||
channelName = "Channel 2";
|
||||
SerialChannel* ch2 = AddDuplexLink (channelName, 5000000, 2,
|
||||
n2, Ipv4Address("10.1.1.2"), MacAddress("00:00:00:00:00:02"));
|
||||
|
||||
SerialChannel* ch2 = AddDuplexLink ("Channel 2", 5000000, 2,
|
||||
n1, Ipv4Address("10.1.2.1"), MacAddress("00:00:00:00:00:03"),
|
||||
n2, Ipv4Address("10.1.2.2"), MacAddress("00:00:00:00:00:04"),
|
||||
traceContainer);
|
||||
SetupTrace (traceContainer, tracer);
|
||||
n2, Ipv4Address("10.1.2.2"), MacAddress("00:00:00:00:00:04"));
|
||||
|
||||
channelName = "Channel 3";
|
||||
SerialChannel* ch3 = AddDuplexLink (channelName, 1500000, 10,
|
||||
SerialChannel* ch3 = AddDuplexLink ("Channel 3", 1500000, 10,
|
||||
n2, Ipv4Address("10.1.3.1"), MacAddress("00:00:00:00:00:05"),
|
||||
n3, Ipv4Address("10.1.3.2"), MacAddress("00:00:00:00:00:06"),
|
||||
traceContainer);
|
||||
SetupTrace (traceContainer, tracer);
|
||||
n3, Ipv4Address("10.1.3.2"), MacAddress("00:00:00:00:00:06"));
|
||||
|
||||
UdpSocket *source0 = new UdpSocket (n0);
|
||||
UdpSocket *source3 = new UdpSocket (n3);
|
||||
@@ -341,6 +325,15 @@ int main (int argc, char *argv[])
|
||||
n0->GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1);
|
||||
n3->GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1);
|
||||
|
||||
Tracer tracer("serial-net-test.log");
|
||||
TraceRoot::Connect ("/nodes/*/ipv4/interfaces/*/netdevice/queue/enqueue",
|
||||
MakeCallback (&Tracer::LogEnqueue, &tracer));
|
||||
TraceRoot::Connect ("/nodes/*/ipv4/interfaces/*/netdevice/queue/dequeue",
|
||||
MakeCallback (&Tracer::LogDequeue, &tracer));
|
||||
TraceRoot::Connect ("/nodes/*/ipv4/interfaces/*/netdevice/queue/drop",
|
||||
MakeCallback (&Tracer::LogDrop, &tracer));
|
||||
|
||||
|
||||
PrintTraffic (sink3);
|
||||
GenerateTraffic (source0, 100);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user