[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] BS broadcasting packets...



Hi!
I'm trying to broadcast packets from one BS to a MH using the following  
code in C++:
void MMPBSAgent :: send_ads(NsObject *target = NULL){
	Tcl&tcl = Tcl:: instance();

	Packet *p = allocpkt();

	hdr_mmp *mmp = (hdr_mmp*)p->access (off_mmp_);
	hdr_ip *iph = (hdr_ip*)p->access (off_ip_);

	mmp->bsaddr_ = Address::instance().get_nodeaddr(addr());
	mmp->core_ = core_;
	mmp->type_ = MMP_ADS;

	iph->ttl() = 1;
	sendOutBCastPkt(p);

	if (target == NULL){
		tcl.evalc("puts stdout target=NULL");
		if (bcast_target_){
			bcast_target_->recv(p, (Handler*) 0);
			tcl.evalc("puts stdout bcast_target_");
		}
		else if (target_){
			target_->recv(p, (Handler*) 0);
			tcl.evalc("puts stdout target_");
		}
		else{
			Packet::free(p);
			tcl.evalc("puts stdout DiscardingPacket");
		}
	}
	else target->recv(p, (Handler*) 0);

}


void MMPBSAgent :: sendOutBCastPkt(Packet *p){
	Tcl&tcl = Tcl:: instance();

	hdr_cmn *hdrc = (hdr_cmn*)p->access (off_cmn_);
	hdr_ip *iph = (hdr_ip*)p->access (off_ip_);

	hdrc->next_hop_ = IP_BROADCAST;
	hdrc->addr_type_ = NS_AF_INET;
	iph-> daddr() = IP_BROADCAST;
	iph->dport() = 0;

	tcl.evalc("puts stdout BCastPacket");
}


//MMP MH node
static class MMPMHAgentClass : public TclClass {
public:
	MMPMHAgentClass() : TclClass ("Agent/MMPMH") {}
	TclObject* create (int, const char*const*){
		return (new MMPMHAgent());
	}
} class_mmpmhagent;

MMPMHAgent :: MMPMHAgent() : Agent(PT_UDP),in_tree(0),BS_now(0){
	bind("off_mmp_", &off_mmp_);
	bind("packetSize_", &size_);
}

void MMPMHAgent :: recv (Packet* p, Handler *){
	Tcl&tcl = Tcl :: instance();

	hdr_mmp *mmp = (hdr_mmp *)p->access(off_mmp_);
	hdr_ip *iph = (hdr_ip *)p->access(off_ip_);

	haddr_ = Address::instance().get_nodeaddr(addr());
	mmp->haddr_ = haddr_;

	switch (mmp->type_){
	case MMP_ADS:
		if (in_tree == 1){//We belong to a tree
			if (BS_now == mmp->bsaddr_){
				tcl.evalc("puts stdout ReceiveSameBS");
				Packet :: free(p);
				break;
				}//We do nothing, the ads are from the same BS
			else{
				tcl.evalc("puts stdout ReceiveBS2");
				BS_now = mmp->bsaddr_;//The BS I'm receiving the adds from
			}
		}
		if (in_tree == 0){//First time we receive ADS from a BS
			tcl.evalc("puts stdout ReceiveBS1");
			BS_now = mmp->bsaddr_;//We take the BS I'm taking the ads
			//from
			mcoa_ = mmp->bsaddr_;//We take the mcoa of the MMPBS
			core_ = mmp->core_;//We take the core of the MMPBS
			mmp->mcoa_ = mcoa_;//We put that mcoa in the mmp packet
			//that will reach the BS
			in_tree = 1;//We now belong to a tree
		}

        //We establish a new link from MH to the BS
		tcl.evalf("%s get-link %d %d", name_, haddr_, mmp->bsaddr_);
		send_packet(p,BS_now, (NsObject*)tcl.lookup(tcl.result()));
		break;

	case MMP_REG_REPLY:

		mmp->type_= MMP_REG_REPLY;//We reply to the MS
		mmp->mcoa_ = mcoa_;//We keep our mcoa
		mmp->core_ = core_;//We keep our core, the first one we got

		iph->daddr() = mmp->bsaddr_;//We send the request to the
		iph->dport() = 0;//station I received the ads from

		send(p,0);
		break;

	default:
		Packet:: free(p);
		break;
	}
}


void MMPMHAgent :: send_packet (Packet *p,int dst,NsObject *target){
	Tcl&tcl = Tcl :: instance();

	hdr_mmp *mmp = (hdr_mmp *)p->access(off_mmp_);
	hdr_ip *iph = (hdr_ip *)p->access(off_ip_);

	mmp->type_= MMP_REG_REQUEST;//We reply to the MS
	iph->daddr() = dst;//We send the request to the
	iph->dport() = 0;//station I received the ads from
	if (target == NULL){
		if(bcast_target_)
			bcast_target_->recv(p, (Handler*) 0);
		else if (target_)
			target_->recv(p, (Handler*) 0);
		else Packet::free(p);
		}
	else target_->recv(p, (Handler*) 0);
	send(p,0);
	tcl.evalc("puts stdout Send:REG_REQUEST");
}


But the MH doesn't receive the packets I'm sending...
Any clue?
Thanks in advance,
Ana





________________________________
Ana Delgado
Centre for Telecommunications Research
King's College London
London England
[email protected]

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com