引用:
現在やろうとしていることは、1ホップ以内にいる全ノードにブロードキャストしたら、今度はそれらのノードが自分の通信範囲内の全ノードに対してブロードキャストを行い、これを繰り返すことでネットワーク全体に対してフラッディングが行われるというものなのですが、こういったことをするにはどうしたら良いのでしょうか?
ブロードキャストパケットならなんでもかんでも全てフラッディングしてしまうようにIPを改造する、という方法ではどうですか?全ノードがそのように動いてしまいますが、以下のようなアプローチで実現できるように思います。
(コードを読んだだけで動かしてはいないので、動くかどうかは分かりませんが。。)
一般に、IPレベルでのブロードキャストパケットの再ブロードキャストというのは、禁止されているはず。
なので、その禁止事項を取っ払えばブロードキャストパケットを再ブロードキャストしてくれるはず。
QualNetでその禁止ルールを適用している箇所は、ip.cppのNetworkIpReceivePacketFromMacLayer()の以下の箇所。(コードは3.9.5のもの)
03621 // IsMyPacket() determines whether the packet should be delivered or
03622 // forwarded. IsMyPacket() checks multicast subscriptions as well
03623 // as the host and broadcast addresses of all local interfaces.
03624
03625 if (IsMyPacket(node, ipHeader->ip_dst))
03626 {
03627 // Deliver IP packet to node.
03628 //
03629 // (We actually deliver a copy of the message instead of the
03630 // original. This is in case the packet is multicast, one copy
03631 // of which is delivered, and the other copy, forwarded.)
03632
03633 // Need to go through the backplane to the processor first before
03634 // deliverying data to higher layers...
03635 NetworkIpSendOnBackplane(node,
03636 MESSAGE_Duplicate(node, msg),
03637 incomingInterface,
03638 CPU_INTERFACE,
03639 previousHopAddress);
03640
03641 //DeliverPacket(node, MESSAGE_Duplicate(node, msg),
03642 // incomingInterface, previousHopAddress);
03643
03644 if (NetworkIpIsMulticastAddress(node, ipHeader->ip_dst))
03645 {
03646 // Destination address is multicast address, so pass packet
03647 // to forwarding process for potential multicast routing.
03648
03649 ForwardPacket(node, msg, incomingInterface, ANY_IP);
03650 }
03651 else
03652 {
03653 // Wasn't a multicast packet, so free message.
03654 //
03655 // [In my tests, the copy and free method happens to be 0.5%
03656 // faster than logic which copies only if necessary. -Jeff]
03657
03658 MESSAGE_Free(node, msg);
03659 }
03660 }
03661 else
03662 {
03663 // Forward packet.
03664 ForwardPacket(node, msg, incomingInterface, previousHopAddress);
03665 }
なので、ここに、「ブロードキャストパケットはフォワードする」というルールを無理やり追加する。
03621 // IsMyPacket() determines whether the packet should be delivered or
03622 // forwarded. IsMyPacket() checks multicast subscriptions as well
03623 // as the host and broadcast addresses of all local interfaces.
03624
03625 if (IsMyPacket(node, ipHeader->ip_dst))
03626 {
03627 // Deliver IP packet to node.
03628 //
03629 // (We actually deliver a copy of the message instead of the
03630 // original. This is in case the packet is multicast, one copy
03631 // of which is delivered, and the other copy, forwarded.)
03632
03633 // Need to go through the backplane to the processor first before
03634 // deliverying data to higher layers...
03635 NetworkIpSendOnBackplane(node,
03636 MESSAGE_Duplicate(node, msg),
03637 incomingInterface,
03638 CPU_INTERFACE,
03639 previousHopAddress);
03640
03641 //DeliverPacket(node, MESSAGE_Duplicate(node, msg),
03642 // incomingInterface, previousHopAddress);
03643
03644 if (NetworkIpIsMulticastAddress(node, ipHeader->ip_dst))
03645 {
03646 // Destination address is multicast address, so pass packet
03647 // to forwarding process for potential multicast routing.
03648
03649 ForwardPacket(node, msg, incomingInterface, ANY_IP);
03650 }
else if (destAddress == ANY_DEST)
{
// Destination address is broadcast address, BUT pass packet
// to forwarding process.
ForwardPacket(node, msg, incomingInterface, ANY_IP);
}
03651 else
03652 {
03653 // Wasn't a multicast packet, so free message.
03654 //
03655 // [In my tests, the copy and free method happens to be 0.5%
03656 // faster than logic which copies only if necessary. -Jeff]
03657
03658 MESSAGE_Free(node, msg);
03659 }
03660 }
03661 else
03662 {
03663 // Forward packet.
03664 ForwardPacket(node, msg, incomingInterface, previousHopAddress);
03665 }