Question
Flooding: Each node floods a packet to all it neighbor nodes. These packets continue to flood until it reaches it's final destination. Must work as
Flooding:
Each node floods a packet to all it neighbor nodes.
These packets continue to flood until it reaches it's final destination.
Must work as pings and ping replies.
Only use information accessible from the packet and it's headers.
CODE:
Node.nc
#include
#include "includes/command.h"
#include "includes/packet.h"
#include "includes/CommandMsg.h"
#include "includes/sendInfo.h"
#include "includes/channels.h"
module Node{
uses interface Boot;
uses interface SplitControl as AMControl;
uses interface Receive;
uses interface SimpleSend as Sender;
uses interface CommandHandler;
}
implementation{
pack sendPackage;
// Prototypes
void makePack(pack *Package, uint16_t src, uint16_t dest, uint16_t TTL, uint16_t Protocol, uint16_t seq, uint8_t *payload, uint8_t length);
event void Boot.booted(){
call AMControl.start();
dbg(GENERAL_CHANNEL, "Booted ");
}
event void AMControl.startDone(error_t err){
if(err == SUCCESS){
dbg(GENERAL_CHANNEL, "Radio On ");
}else{
//Retry until successful
call AMControl.start();
}
}
event void AMControl.stopDone(error_t err){}
event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len){
dbg(GENERAL_CHANNEL, "Packet Received ");
if(len==sizeof(pack)){
pack* myMsg=(pack*) payload;
dbg(GENERAL_CHANNEL, "Package Payload: %s ", myMsg->payload);
return msg;
}
dbg(GENERAL_CHANNEL, "Unknown Packet Type %d ", len);
return msg;
}
event void CommandHandler.ping(uint16_t destination, uint8_t *payload){
dbg(GENERAL_CHANNEL, "PING EVENT ");
makePack(&sendPackage, TOS_NODE_ID, destination, 0, 0, 0, payload, PACKET_MAX_PAYLOAD_SIZE);
call Sender.send(sendPackage, destination);
}
event void CommandHandler.printNeighbors(){}
event void CommandHandler.printRouteTable(){}
event void CommandHandler.printLinkState(){}
event void CommandHandler.printDistanceVector(){}
event void CommandHandler.setTestServer(){}
event void CommandHandler.setTestClient(){}
event void CommandHandler.setAppServer(){}
event void CommandHandler.setAppClient(){}
void makePack(pack *Package, uint16_t src, uint16_t dest, uint16_t TTL, uint16_t protocol, uint16_t seq, uint8_t* payload, uint8_t length){
Package->src = src;
Package->dest = dest;
Package->TTL = TTL;
Package->seq = seq;
Package->protocol = protocol;
memcpy(Package->payload, payload, length);
}
}
NodeC.nc
#include
#include "includes/CommandMsg.h"
#include "includes/packet.h"
configuration NodeC{
}
implementation {
components MainC;
components Node;
components new AMReceiverC(AM_PACK) as GeneralReceive;
Node -> MainC.Boot;
Node.Receive -> GeneralReceive;
components ActiveMessageC;
Node.AMControl -> ActiveMessageC;
components new SimpleSendC(AM_PACK);
Node.Sender -> SimpleSendC;
components CommandHandlerC;
Node.CommandHandler -> CommandHandlerC;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started