void
RoutingExperiment::Rx (std::string context, Ptr <const Packet> packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise){
//context will include info about the source of this event. Use string manipulation if you want to extract info.
//std::cout << BOLD_CODE << context << END_CODE << std::endl;
//Print the info.
// Packet::EnablePrinting();
// Packet::EnableChecking();
// packet->Print(std::cout << "\nTime: " << Simulator::Now().GetSeconds() << "s, Packet Details are: ");
Ipv4Address src_ip = GetSourceAddress(packet);
Ipv4Address des_ip = GetDestAddress(packet); if(packet->GetSize() >= 500){
counterAppRX++; } else {
counterRX++;
} NS_LOG_DEBUG(m_mainAddressW << " W Received Packet from Source Address: " << src_ip << ", With Destination address in Packet: " << des_ip
<< ", \nSize = " << packet->GetSize()
<< " Freq = "<<channelFreqMhz
<< " Mode = " << txVector.GetMode()
<< " ReceptionDataRate = " << txVector.GetMode().GetDataRate(txVector)
<< " RX Counter: " << counterRX << "\t RX APP Counter: " << counterAppRX);
m_rxDataRate = txVector.GetMode().GetDataRate(txVector)/1000000; //insert into table if(src_ip == Ipv4Address("102.102.102.102") || des_ip == Ipv4Address("102.102.102.102"))
{
NS_LOG_DEBUG("This is RTS/CTS/ACK Packet!");
}
else
{
RTableEntry rTableEntryW;
bool permanentTableVerifier = m_rTableW.LookupRoute (src_ip, rTableEntryW); //m_rTableW is the object of rTable class
NS_LOG_DEBUG("Is the route inside the table? " << permanentTableVerifier);
if (permanentTableVerifier == false)
{
NS_LOG_DEBUG ("Received New WRoute!");
RTableEntry newEntry(/*My Address=*/ src_ip, /*destination address=*/ des_ip, /*source address=*/src_ip, /*current location=*/ "L2",
/*previous location=*/ "L1", /*time connected=*/Simulator::Now (), /*time last pakcet received=*/ Simulator::Now (), /*time first packet received*/
Simulator::Now ());
m_rTableW.AddRoute (newEntry);
NS_LOG_DEBUG ("New WRoute added to Wtable!");
}
else
{
rTableEntryW.setMyAddress(m_mainAddressW);
rTableEntryW.setDestAddress(des_ip);
rTableEntryW.setSourceAddress(src_ip);
rTableEntryW.setCurrLocation("L2");
rTableEntryW.setLastLocation("L1");
rTableEntryW.setTimeConnected(Simulator::Now());
rTableEntryW.setTimeLastPktRcvd(Simulator::Now());
rTableEntryW.setTimeFirstPktRcvd(Simulator::Now());
m_rTableW.Update(rTableEntryW);
NS_LOG_DEBUG ("Route Updated in WTable!");
}
} NS_LOG_DEBUG("Values in the rTableW are: ");
if(m_rTableW.RTableSize() > 0)
{
m_rTableW.GetListOfAllRoutes();
}
else
{
NS_LOG_DEBUG("RTableW is Empty!");
} //We can also examine the WifiMacHeader
WifiMacHeader hdr;
if (packet->PeekHeader(hdr))
{
NS_LOG_DEBUG("\tDestination MAC : " << hdr.GetAddr1() << "\tSource MAC : " << hdr.GetAddr2());
}
}
void
RoutingExperiment::Rx (std::string context, Ptr <const Packet> packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise){
//context will include info about the source of this event. Use string manipulation if you want to extract info.
//std::cout << BOLD_CODE << context << END_CODE << std::endl;
//Print the info.
// Packet::EnablePrinting();
// Packet::EnableChecking();
// packet->Print(std::cout << "\nTime: " << Simulator::Now().GetSeconds() << "s, Packet Details are: ");
Ipv4Address src_ip = GetSourceAddress(packet);
Ipv4Address des_ip = GetDestAddress(packet); if(packet->GetSize() >= 500){
counterAppRX++; } else {
counterRX++;
} NS_LOG_DEBUG(m_mainAddressW << " W Received Packet from Source Address: " << src_ip << ", With Destination address in Packet: " << des_ip
<< ", \nSize = " << packet->GetSize()
<< " Freq = "<<channelFreqMhz
<< " Mode = " << txVector.GetMode()
<< " ReceptionDataRate = " << txVector.GetMode().GetDataRate(txVector)
<< " RX Counter: " << counterRX << "\t RX APP Counter: " << counterAppRX);
m_rxDataRate = txVector.GetMode().GetDataRate(txVector)/1000000; //insert into table if(src_ip == Ipv4Address("102.102.102.102") || des_ip == Ipv4Address("102.102.102.102"))
{
NS_LOG_DEBUG("This is RTS/CTS/ACK Packet!");
}
else
{
RTableEntry rTableEntryW;
bool permanentTableVerifier = m_rTableW.LookupRoute (src_ip, rTableEntryW);
NS_LOG_DEBUG("Is the route inside the table? " << permanentTableVerifier);
if (permanentTableVerifier == false)
{
NS_LOG_DEBUG ("Received New WRoute!");
RTableEntry newEntry(/*My Address=*/ src_ip, /*destination address=*/ des_ip, /*source address=*/src_ip, /*current location=*/ "L2",
/*previous location=*/ "L1", /*time connected=*/Simulator::Now (), /*time last pakcet received=*/ Simulator::Now (), /*time first packet received*/
Simulator::Now ());
m_rTableW.AddRoute (newEntry);
NS_LOG_DEBUG ("New WRoute added to Wtable!");
}
else
{
rTableEntryW.setMyAddress(m_mainAddressW);
rTableEntryW.setDestAddress(des_ip);
rTableEntryW.setSourceAddress(src_ip);
rTableEntryW.setCurrLocation("L2");
rTableEntryW.setLastLocation("L1");
rTableEntryW.setTimeConnected(Simulator::Now());
rTableEntryW.setTimeLastPktRcvd(Simulator::Now());
rTableEntryW.setTimeFirstPktRcvd(Simulator::Now());
m_rTableW.Update(rTableEntryW);
NS_LOG_DEBUG ("Route Updated in WTable!");
}
} NS_LOG_DEBUG("Values in the rTableW are: ");
if(m_rTableW.RTableSize() > 0)
{
m_rTableW.GetListOfAllRoutes(); //print the table contents
}
else
{
NS_LOG_DEBUG("RTableW is Empty!");
} //We can also examine the WifiMacHeader
WifiMacHeader hdr;
if (packet->PeekHeader(hdr))
{
NS_LOG_DEBUG("\tDestination MAC : " << hdr.GetAddr1() << "\tSource MAC : " << hdr.GetAddr2());
}
}
static inline std::string
PrintReceivedPacket (Ptr<Socket> socket, Ptr<Packet> packet, Address senderAddress)
{
std::ostringstream oss; // oss << Simulator::Nowdsdv.PrintRoutingTableAllAt (rtt, rtw); ().GetSeconds () << " " << socket->GetNode ()->GetId ();
Ptr<Node> node = socket->GetNode();
Ptr<Ipv4> ip = node->GetObject<Ipv4>();
Ipv4Address address = ip->GetAddress(1,0).GetLocal();
if (InetSocketAddress::IsMatchingType (senderAddress))
{
InetSocketAddress addr = InetSocketAddress::ConvertFrom (senderAddress);
oss << Simulator::Now ().GetSeconds () << " , Node: " << node->GetId() << ", Address: " << address << " received one packet from " << addr.GetIpv4 ();
}
else
{
oss << Simulator::Now ().GetSeconds () << " received one packet!";
}
return oss.str ();
}
Ipv4Address RoutingExperiment::GetSourceAddress(Ptr<const Packet> p){ Ipv4Address src; // To get a header from Ptr<Packet> packet first, copy the packet Ptr<Packet> q = p->Copy(); // Use indicator to search the packet PacketMetadata::ItemIterator metadataIterator = q->BeginItem(); PacketMetadata::Item item; while (metadataIterator.HasNext()) { item = metadataIterator.Next(); NS_LOG_FUNCTION("item name: " << item.tid.GetName()); // If we want to have a dsdv header if(item.tid.GetName() == "ns3::Ipv4Header") { Callback<ObjectBase *> constr = item.tid.GetConstructor(); NS_ASSERT(!constr.IsNull()); // Ptr<> and DynamicCast<> won't work here as all headers are from ObjectBase, not Object ObjectBase *instance = constr(); NS_ASSERT(instance != 0); Ipv4Header* ipv4Header = dynamic_cast<Ipv4Header*>(instance); NS_ASSERT(ipv4Header != 0); ipv4Header->Deserialize(item.current); src = ipv4Header->GetSource(); NS_LOG_DEBUG("Source IP ADDRESS FOUND from IPV4Header: " << src); break; } else if(item.tid.GetName() == "ns3::ArpHeader") { Callback<ObjectBase *> constr = item.tid.GetConstructor(); NS_ASSERT(!constr.IsNull()); // Ptr<> and DynamicCast<> won't work here as all headers are from ObjectBase, not Object ObjectBase *instance = constr(); NS_ASSERT(instance != 0); ArpHeader* arpHeader = dynamic_cast<ArpHeader*>(instance); NS_ASSERT(arpHeader != 0); arpHeader->Deserialize(item.current); src = arpHeader->GetSourceIpv4Address(); NS_LOG_DEBUG("Source IP ADDRESS FOUND from ARPHeader: " << src); break; } else { NS_LOG_DEBUG("NO SOURCE IP ADDRESS FOUND"); //break; } } return src;}
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/0u4a7GQMns0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/b65b55a3-c3b6-402a-9aa9-7d4de21a4ad7%40googlegroups.com.
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/0u4a7GQMns0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/901298fb-6df0-465c-8979-e0de5d75990f%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/CAAk8FH5oS6YCGUd6R4VH-%3DSnZTuF-VyCo7%2Bu0-1O13qO74ng2A%40mail.gmail.com.
To unsubscribe from this group and all its topics, send an email to ns-3-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/901298fb-6df0-465c-8979-e0de5d75990f%40googlegroups.com.
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/0u4a7GQMns0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-...@googlegroups.com.