⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macedon_swp.cc

📁 这是一个著名的应用层组播中间件的源码
💻 CC
📖 第 1 页 / 共 2 页
字号:
//Copyright (c) 2004, Charles Killian, Adolfo Rodriguez, Dejan Kostic, Sooraj Bhat, and Amin Vahdat//All rights reserved.////Redistribution and use in source and binary forms, with or without//modification, are permitted provided that the following conditions are met:////   * Redistributions of source code must retain the above copyright//     notice, this list of conditions and the following disclaimer.//   * Redistributions in binary form must reproduce the above copyright//     notice, this list of conditions and the following disclaimer in//     the documentation and/or other materials provided with the//     distribution.//   * Neither the names of Duke University nor The University of//     California, San Diego, nor the names of its contributors//     may be used to endorse or promote products derived from//     this software without specific prior written permission.////THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"//AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE//IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE//FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL//DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,//OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE//USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE./*      Adolfo Rodriguez    macedon_swp.cc    20010510*/#include "macedon_swp.h"#include "macedon-macros.h"struct macedon_fields *MACEDON_Agent::getmacedonfields(Packet *){}/* macedon_neighbor_entry *MACEDON_Agent::get_neighbor(int dest) *//* { *//*   macedon_neighbor_entry *search; *//*   search = neighbors_; *//*   while (search && search->ne_addr!= dest) *//*     search = search->ne_next_entry; *//*   // if no neighbor entry exists, allocate one *//*   if (!search) *//*   { *//*     search = new macedon_neighbor_entry(dest); *//*     search->ne_next_entry = neighbors_; *//*     neighbors_ = search; *//*     search->ne_num_pkts = 0; *//*     search->ne_num_pkts_not_sent = 0; *//* #ifdef MACEDON_TRACE_RELIAB *//*     debug_macro("Reliab: adding new neighbor %x with data struc %x\n", search->ne_addr, search); *//* #endif *//*     double curtime = Scheduler::instance().clock(); *//*     search->time_added = (int)curtime; *//*     search->remote_time_added = 0; *//*   } *//*   return search; *//* } *//* void MACEDON_Agent::queue_pkt(  macedon_neighbor_entry *neigh,  *//*     macedon_packet_qent *qentry) *//* { *//*   macedon_packet_qent *prev; *//* #ifdef MACEDON_TRACE_RELIAB_DETAIL *//*   debug_macro("Reliab: queueing packet ent %x, packet %x to neighbor %x\n", qentry, qentry->qe_pkt, neigh); *//* #endif *//*   if (neigh->ne_pktq) *//*   { *//*     prev = neigh->ne_pktq; *//*     while (prev->qe_next) *//*       prev = prev->qe_next; *//*     prev->qe_next = qentry; *//*   } *//*   else *//*   { *//*     neigh->ne_pktq = qentry; *//*   } *//*   neigh->ne_num_pkts++;   *//*   neigh->ne_num_pkts_not_sent++; *//* } *//* int MACEDON_Agent::reliab_send(Packet *pkt) *//* { *//*   macedon_neighbor_entry *search; *//*   macedon_packet_qent *qentry; *//*   macedon_packet_qent *prev; *//*   hdr_ip* dest_hdrip     = gethdrip( pkt ); *//*   struct macedon_fields *mf = getmacedonfields(pkt); *//* #ifdef MACEDON_TRACE_RELIAB_DETAIL *//*   debug_macro("Reliab: reliab_send called with pkt %x and hdr %d\n", pkt, pkt->hdrlen_); *//* #endif *//*   // first get the neighbor entry, if it exists *//*   search = get_neighbor(dest_hdrip->dst_.addr_); *//*   // allocate a queue entry and queue the packet to the END of queue *//*   qentry = new macedon_packet_qent(); *//*   qentry->qe_pkt = pkt; *//*   queue_pkt(search, qentry); *//*   //  dest_hdrlift->lh_mf_.mh_send_seqno_ = 0;   // clear seqno field *//*   mf->mh_send_seqno_ = 0;   // clear seqno field *//* #ifdef MACEDON_SANITY_CHECKS *//*   if (search->ne_num_pkts > MACEDON_PACKET_LEAK) *//*   { *//*     debug_macro("Exception: reliab send to neighbor %x with big queue %d\n", search->ne_addr, search->ne_num_pkts ); *//*     exit(42); *//*   } *//* #endif *//*   // send the next pkts in the queue if we can *//*   if ( search->ne_send_seqno <= search->ne_ack_seqno+MACEDON_MAX_RELIAB_WINDOW ) *//*   { *//*     while ( search->ne_send_seqno <= search->ne_ack_seqno+MACEDON_MAX_RELIAB_WINDOW  *//*         && search->ne_pktq) *//*       send_next_in_queue(search); *//*   } *//*   else *//*   { *//* #ifdef MACEDON_TRACE_RELIAB *//*     debug_macro("Reliab: cannot send next in queue just yet.\n"); *//* #endif *//*   } *//*   return 0; *//* } *//* void MACEDON_Agent::send_next_in_queue(class macedon_neighbor_entry *neighbor) *//* { *//*   Packet *send_pkt; *//*   hdr_ip* dest_hdrip; *//*   // hdr_lift* dest_hdrlift; *//*   struct macedon_fields *mf; *//*   macedon_packet_qent *to_send; *//*   macedon_packet_qent *last_sent; *//* #ifdef MACEDON_TRACE_RELIAB_DETAIL *//*   debug_macro("Reliab: checking send queue %x\n", neighbor); *//* #endif *//*   // check if there is nothing to send, leave *//*   if ( neighbor->ne_pktq == 0 ) *//*     return; *//*   dest_hdrip = gethdrip( neighbor->ne_pktq->qe_pkt ); *//*   // dest_hdrlift = gethdrlift( neighbor->ne_pktq->qe_pkt ); *//*   mf = getmacedonfields( neighbor->ne_pktq->qe_pkt ); *//* #ifdef MACEDON_TRACE_RELIAB_DETAIL *//*   debug_macro("Reliab: something to send to %x, %d in queue\n", neighbor->ne_addr, neighbor->ne_num_pkts); *//* #endif *//*   // window is open, can send next packet *//*   // set the seqno and bump for the next to send *//*   // dest_hdrlift->lh_mf_.mh_send_seqno_ = neighbor->ne_send_seqno; *//*   mf->mh_send_seqno_ = neighbor->ne_send_seqno; *//*   neighbor->ne_send_seqno++; *//*   // dequeue the pkt and place it on sent queue *//*   last_sent = neighbor->ne_sent; *//*   if (last_sent) *//*     while (last_sent->qe_next) *//*       last_sent = last_sent->qe_next; *//*   to_send = neighbor->ne_pktq; *//*   if (last_sent) *//*     last_sent->qe_next = to_send; *//*   else *//*     neighbor->ne_sent = to_send;  *//* #ifdef MACEDON_TRACE_RELIAB_DETAIL *//*   debug_macro("Reliab: sending copy of packet ent %x, packet %x, neighbor %x\n", to_send, to_send->qe_pkt, neighbor); *//* #endif *//*   neighbor->ne_pktq = to_send->qe_next; *//*   to_send->qe_next = 0; *//*   neighbor->ne_num_pkts_not_sent--; *//*   // copy the pkt *//*   send_pkt = macedon_pkt_copy(to_send->qe_pkt); *//*   // switch packets now *//*   dest_hdrip = gethdrip(send_pkt); *//*   dest_hdrip->dst_.port_ = 1; *//*   //  dest_hdrlift = gethdrlift(send_pkt); *//*   mf = getmacedonfields(send_pkt); *//* #ifdef MACEDON_TRACE_RELIAB *//*   debug_macro("Reliab: sending message %d of type %d to %x(%x) from %x(%x)\n", mf->mh_send_seqno_, mf->mh_type_, dest_hdrip->dst_.addr_, dest_hdrip->dst_.port_, dest_hdrip->src_.addr_, dest_hdrip->src_.port_); *//* #endif *//*   //  neighbor->ne_last_sent = Scheduler::instance().clock(); *//*   to_send->qe_time_sent =  Scheduler::instance().clock(); *//*   mf->mh_time_added = neighbor->time_added; *//*   // send the copy *//*   packet_count_++; *//*   macedon_send( send_pkt ); *//*   //  #ifdef MACEDON_TRACE_RELIAB *//*   //    debug_macro( "Reliab: sent message %d to %x(%x)\n", dest_hdrlift->lh_mf_.mh_send_seqno_, dest_hdrip->dst_.addr_, dest_hdrip->dst_.port_); *//*   //  #endif *//* } *//* int MACEDON_Agent::macedon_send(Packet *pkt) *//* {  *//*   hdr_ip* dest_hdrip     = gethdrip( pkt ); *//*   struct macedon_fields *dest_mf = getmacedonfields( pkt );  *//* #ifdef MACEDON_SANITY_CHECKS *//*   if (dest_hdrip->dst_.addr_ == 0) *//*   { *//*     debug_macro("Exception: trying to send pkt type %d to 0 address!\n",dest_mf->mh_type_); *//*     exit(48); *//*   } *//*   mem_pkts_sent_++; *//* #endif *//*   dest_mf->mh_dest_addr_ = dest_hdrip->dst_.addr_; *//*   dest_mf->mh_src_addr_ = here_.addr_; *//*   Agent::send(pkt, 0); *//*   return 0; *//* } *//*   int *//* MACEDON_Agent::reliab_recv(Packet *pkt) *//* { *//*   macedon_neighbor_entry *search; *//*   Packet *ack_pkt; *//*   hdr_ip* recv_hdrip     = gethdrip( pkt ); *//*   // hdr_lift* recv_hdrlift = gethdrlift( pkt ); *//*   struct macedon_fields *recv_mf = getmacedonfields( pkt ); *//*   hdr_ip* ack_hdrip; *//*   //hdr_lift* ack_hdrlift; *//*   hdr_cmn* ack_hdrcmn; *//*   struct macedon_fields *ack_mf; *//* #ifdef MACEDON_TRACE_RELIAB *//*   debug_macro( "Reliab: receiving packet from %x\n", recv_hdrip->src_.addr_); *//* #endif *//*   // first get the neighbor entry, if it exists *//*   search = neighbors_; *//*   while (search && search->ne_addr!= recv_hdrip->src_.addr_) *//*     search = search->ne_next_entry; *//*   // if no neighbor entry exists, allocate one *//*   if (!search) *//*   { *//*     search = new macedon_neighbor_entry(recv_hdrip->src_.addr_); *//*     search->ne_num_pkts = 0; *//*     search->ne_num_pkts_not_sent = 0; *//*     search->ne_next_entry = neighbors_; *//*     double curtime = Scheduler::instance().clock(); *//*     search->remote_time_added = 0; *//*     search->time_added = (int)curtime; *//*     neighbors_ = search; *//* #ifdef MACEDON_TRACE_RELIAB *//*     debug_macro("Reliab: adding2 new neighbor %x, %x\n", search->ne_addr, search); *//* #endif *//*   } *//*   // check for a new time_added *//*   if ( search->remote_time_added == 0 ) { *//*     debug_macro("Reliab: setting remote_time_added to %d just added peer %.8x\n",recv_mf->mh_time_added, search->ne_addr); *//*     search->remote_time_added = recv_mf->mh_time_added; *//*   } *//*   else if(search->remote_time_added < recv_mf->mh_time_added) { *//*     debug_macro("INFO: Detected new time added from neighbor, resetting reliab connection\n"); *//*     debug_macro("Reliab: resetting remote_time_added to %d from %d existing peer %.8x\n",recv_mf->mh_time_added, search->remote_time_added, search->ne_addr); *//*     search->ne_send_seqno = 1; *//*     search->ne_ack_seqno = 0; *//*     search->ne_recv_seqno = 1; *//*     macedon_packet_qent *to_retrans = search->ne_sent; *//*     while (to_retrans) *//*     { *//*       macedon_packet_qent *to_free = to_retrans; *//*       Packet *pkt_to_free; *//*       pkt_to_free =  to_free->qe_pkt; *//*       macedon_pkt_free (pkt_to_free); *//*       to_retrans = to_retrans->qe_next; *//*       delete to_free; *//*     } *//*     search->ne_sent = NULL; *//*     search->remote_time_added = recv_mf->mh_time_added; *//*   } *//*   else { *//* //      debug_macro("Reliab: matched remote_time_added %d existing peer %.8x\n",recv_mf->mh_time_added, search->ne_addr); *//*   } *//*   // check to see if we have already seen this packet *//*   if ( recv_mf->mh_send_seqno_ < search->ne_recv_seqno ) *//*   { *//*     // first ack the packet (again) *//*     ack_pkt = macedon_pkt_alloc(); *//*     ack_hdrip = gethdrip( ack_pkt ); *//* #ifndef ALLINONEHDR *//*     ack_pkt->hdrlen_ = sizeof(hdr_cmn) + sizeof(hdr_ip) + sizeof(hdr_basic); *//* #else *//*     ack_pkt->hdrlen_ = sizeof(hdr_cmn) + sizeof(hdr_ip) + sizeof(macedon_fields); *//* #endif *//*     //      ack_hdrlift = gethdrlift( ack_pkt ); *//*     ack_mf = getmacedonfields ( ack_pkt ); *//*     ack_hdrcmn = gethdrcmn( ack_pkt ); *//*     ack_hdrip->fid_ = MH_TYPE_ACK; *//*     ack_mf->mh_type_ = MH_TYPE_ACK; *//*     ack_hdrip->dst_.addr_ = recv_hdrip->src_.addr_; *//*     ack_hdrip->dst_.port_ = 1; *//*     //  ack_hdrip->src_.port_ = 0; *//*     //      ack_hdrlift->lh_mf_.mh_ack_seqno_ =  recv_hdrlift->lh_mf_.mh_send_seqno_; *//*     ack_mf->mh_time_added = search->time_added; *//*     ack_mf->mh_ack_seqno_ =  search->ne_recv_seqno-1; *//*     ack_hdrcmn->size() = 0; *//* #ifdef MACEDON_TRACE_RELIAB *//*     debug_macro( "Reliab: acking message %d again to %x(%x) from my port %x\n", ack_mf->mh_ack_seqno_, ack_hdrip->dst_.addr_, ack_hdrip->dst_.port_, ack_hdrip->src_.port_); *//* #endif *//*     macedon_send( ack_pkt ); *//*     return 1;  // means we should discard the packet *//*   } *//*   // check to see if the packet is invalid *//*   else if ( recv_mf->mh_send_seqno_ > search->ne_recv_seqno ) *//*   { *//*     // first ack the packet (again) *//*     ack_pkt = macedon_pkt_alloc(); *//*     ack_hdrip = gethdrip( ack_pkt ); *//* #ifndef ALLINONEHDR *//*     ack_pkt->hdrlen_ = sizeof(hdr_cmn) + sizeof(hdr_ip) + sizeof(hdr_basic); *//* #else *//*     ack_pkt->hdrlen_ = sizeof(hdr_cmn) + sizeof(hdr_ip) + sizeof(macedon_fields); *//* #endif *//*     //      ack_hdrlift = gethdrlift( ack_pkt ); *//*     ack_mf = getmacedonfields ( ack_pkt ); *//*     ack_hdrcmn = gethdrcmn( ack_pkt ); *//*     ack_hdrip->fid_ = MH_TYPE_ACK; *//*     ack_mf->mh_type_ = MH_TYPE_ACK; *//*     ack_hdrip->dst_.addr_ = recv_hdrip->src_.addr_; *//*     ack_hdrip->dst_.port_ = 1; *//*     //  ack_hdrip->src_.port_ = 0; *//*     //      ack_hdrlift->lh_mf_.mh_ack_seqno_ =  recv_hdrlift->lh_mf_.mh_send_seqno_; *//*     ack_mf->mh_time_added = search->time_added; *//*     ack_mf->mh_ack_seqno_ =  0; *//*     ack_hdrcmn->size() = 0; *//* #ifdef MACEDON_TRACE_RELIAB *//*     debug_macro( "Reliab: Seq no greater than expected from %x.\n",  recv_hdrip->src_.addr_); *//* #endif *//*     macedon_send( ack_pkt ); *//*     return 1; *//*   } *//*   // must be ok to receive *//*   else */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -