?? rdt.cc
字號(hào):
#include "rdt.h"#include "rtp.h"#include "random.h"#include <string.h>int hdr_rdt::offset_;// rdt Header Class static class rdtHeaderClass : public PacketHeaderClass {public: rdtHeaderClass() : PacketHeaderClass("PacketHeader/rdt", sizeof(hdr_rdt)) { bind_offset(&hdr_rdt::offset_); }} class_rdthdr;// rdtAgent OTcl linkage classstatic class rdtAgentClass : public TclClass {public: rdtAgentClass() : TclClass("Agent/UDP/rdt") {} TclObject* create(int, const char*const*) { return (new rdtAgent()); }} class_rdt_agent;// Constructor (with no arg)rdtAgent::rdtAgent() : UdpAgent(){ support_mm_ = 0; asm_info.seq = -1;}rdtAgent::rdtAgent(packet_t type) : UdpAgent(type){ support_mm_ = 0; asm_info.seq = -1;}// Add Support of rdt Application to UdpAgent::sendmsgvoid rdtAgent::sendmsg(int nbytes, const char* flags){ Packet *p; int n, remain; if (size_) { n = (nbytes/size_ + (nbytes%size_ ? 1 : 0)); remain = nbytes%size_; } else printf("Error: rdt size = 0\n"); if (nbytes == -1) { printf("Error: sendmsg() for rdt should not be -1\n"); return; } double local_time =Scheduler::instance().clock(); while (n-- > 0) { p = allocpkt(); if(n==0 && remain>0) hdr_cmn::access(p)->size() = remain; else hdr_cmn::access(p)->size() = size_; hdr_rtp* rh = hdr_rtp::access(p); rh->flags() = 0; rh->seqno() = ++seqno_; hdr_cmn::access(p)->timestamp() = (u_int32_t)(SAMPLERATE*local_time); // to eliminate recv to use MM fields for non MM packets hdr_rdt* mh = hdr_rdt::access(p); mh->ack = 0; mh->rej = 0; mh->seq = 0; mh->nbytes = 0; mh->time = 0; mh->scale = 0; // rdt udp packets are distinguished by setting the ip // priority bit to 15 (Max Priority). if(support_mm_) { hdr_ip* ih = hdr_ip::access(p); ih->prio_ = 15; if(flags) // MM Seq Num is passed as flags memcpy(mh, flags, sizeof(hdr_rdt)); } // add "beginning of talkspurt" labels (tcl/ex/test-rcvr.tcl) if (flags && (0 ==strcmp(flags, "NEW_BURST"))) rh->flags() |= RTP_M; target_->recv(p); } idle();}// Support Packet Re-Assembly and rdt Applicationvoid rdtAgent::recv(Packet* p, Handler*){ hdr_ip* ih = hdr_ip::access(p); int bytes_to_deliver = hdr_cmn::access(p)->size(); // if it is a MM packet (data or ack) if(ih->prio_ == 15) { if(app_) { // if MM Application exists // re-assemble MM Application packet if segmented hdr_rdt* mh = hdr_rdt::access(p); if(mh->seq == asm_info.seq) asm_info.rbytes += hdr_cmn::access(p)->size(); else { asm_info.seq = mh->seq; asm_info.tbytes = mh->nbytes; asm_info.rbytes = hdr_cmn::access(p)->size(); } // if fully reassembled, pass the packet to application if(asm_info.tbytes == asm_info.rbytes) { hdr_rdt mh_buf; memcpy(&mh_buf, mh, sizeof(hdr_rdt)); app_->recv_msg(mh_buf.nbytes, (char*) &mh_buf); } } Packet::free(p); } // if it is a normal data packet (not MM data or ack packet) else { if (app_) app_->recv(bytes_to_deliver); Packet::free(p); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -