I wrote some methods for my routing protocol like these ones (which I think are the most important) :
Ptr<Ipv4MulticastRoute> RoutingProtocol::LookupStatic(Ipv4Address origin,Ipv4Address group,uint32_t interface, uint8_t ttl) {
Ptr<Ipv4MulticastRoute> mrtentry = 0;
mrtentry = Create<Ipv4MulticastRoute> ();
mrtentry->SetGroup(group);
mrtentry->SetOrigin(origin);
mrtentry->SetParent(iidout);
mrtentry->SetOutputTtl(iidout,ttl);
return mrtentry;
}
bool RoutingProtocol::RouteInput(Ptr<const Packet> p,
const Ipv4Header &header,
Ptr<const NetDevice> idev,
UnicastForwardCallback ucb,
MulticastForwardCallback mcb,
LocalDeliverCallback lcb,
ErrorCallback ecb) {
NS_ASSERT(m_ipv4 != 0); // Check if input device supports IP
NS_ASSERT(m_ipv4->GetInterfaceForDevice(idev) >= 0);
Ipv4Address dst = header.GetDestination ();
Ipv4Address origin = header.GetSource ();
Ipv4Address m_mainAddress = getMainLocalAddr();
uint32_t outif = m_ipv4->GetInterfaceForDevice(idev);
uint8_t outttl = header.GetTtl();
if (origin==m_mainAddress){
return true; // Consume self-originated packets
}
if(outttl<1){
return true;
}
if (dst.IsMulticast()) { // If it is multicast
Ptr<Ipv4MulticastRoute> mrtentry = LookupStatic(origin,dst, outif, outttl);
if (mrtentry){
// checkhash just checks if the packet has been already sent
if(checkhash(p,origin)) {
NS_LOG_INFO("FORWARD from " << mrtentry->GetOrigin() << " to "<< mrtentry->GetGroup()<< " via "<< outif << " TTL:"<< unsigned(outttl)-1);
mcb(mrtentry, p, header);
return true;
}
else{
return false;
}
}
}
return false;
}