00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * Copyright (c) 1997 Regents of the University of California. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 3. All advertising materials mentioning features or use of this software 00015 * must display the following acknowledgement: 00016 * This product includes software developed by the Computer Systems 00017 * Engineering Group at Lawrence Berkeley Laboratory. 00018 * 4. Neither the name of the University nor of the Laboratory may be used 00019 * to endorse or promote products derived from this software without 00020 * specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00025 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00028 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00029 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00031 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00032 * SUCH DAMAGE. 00033 */ 00034 /* Ported from CMU/Monarch's code*/ 00035 00036 /* 00037 imep_io.cc 00038 $Id: imep_io.cc,v 1.4 1999/10/13 22:53:06 heideman Exp $ 00039 00040 marshall IMEP packets 00041 */ 00042 00043 #include <random.h> 00044 #include <packet.h> 00045 #include <imep/imep.h> 00046 00047 // ====================================================================== 00048 // ====================================================================== 00049 // Outgoing Packets 00050 00051 void 00052 imepAgent::sendBeacon() 00053 { 00054 Packet *p = Packet::alloc(); 00055 struct hdr_cmn *ch = HDR_CMN(p); 00056 struct hdr_ip *ih = HDR_IP(p); 00057 struct hdr_imep *im = HDR_IMEP(p); 00058 00059 ch->ptype() = PT_IMEP; 00060 ch->size() = BEACON_HDR_LEN; 00061 ch->iface() = -2; 00062 ch->error() = 0; 00063 ch->addr_type() = NS_AF_NONE; 00064 ch->prev_hop_ = ipaddr; 00065 ch->uid() = uidcnt_++; 00066 00067 ih->saddr() = ipaddr; 00068 ih->daddr() = IP_BROADCAST; 00069 ih->sport() = RT_PORT; 00070 ih->dport() = RT_PORT; 00071 ih->ttl_ = 1; 00072 00073 im->imep_version = IMEP_VERSION; 00074 im->imep_block_flags = 0x00; 00075 U_INT16_T(im->imep_length) = sizeof(struct hdr_imep); 00076 00077 imep_output(p); 00078 } 00079 00080 void 00081 imepAgent::sendHello(nsaddr_t index) 00082 { 00083 Packet *p = Packet::alloc(); 00084 struct hdr_cmn *ch = HDR_CMN(p); 00085 struct hdr_ip *ih = HDR_IP(p); 00086 struct hdr_imep *im = HDR_IMEP(p); 00087 struct imep_hello_block *hb = (struct imep_hello_block*) (im + 1); 00088 struct imep_hello *hello = (struct imep_hello*) (hb + 1); 00089 00090 ch->ptype() = PT_IMEP; 00091 ch->size() = HELLO_HDR_LEN; 00092 ch->iface() = -2; 00093 ch->error() = 0; 00094 ch->addr_type() = NS_AF_NONE; 00095 ch->prev_hop_ = ipaddr; 00096 ch->uid() = uidcnt_++; 00097 00098 ih->saddr() = ipaddr; 00099 ih->daddr() = IP_BROADCAST; 00100 ih->sport() = RT_PORT; 00101 ih->dport() = RT_PORT; 00102 ih->ttl_ = 1; 00103 00104 im->imep_version = IMEP_VERSION; 00105 im->imep_block_flags = BLOCK_FLAG_HELLO; 00106 U_INT16_T(im->imep_length) = sizeof(struct hdr_imep) + 00107 sizeof(struct imep_hello_block) + sizeof(struct imep_hello); 00108 00109 hb->hb_num_hellos = 1; 00110 00111 INT32_T(hello->hello_ipaddr) = index; 00112 00113 helloQueue.enque(p); 00114 // aggregate as many control messages as possible before sending 00115 00116 if(controlTimer.busy() == 0) { 00117 controlTimer.start(MIN_TRANSMIT_WAIT_TIME_LOWP 00118 + ((MAX_TRANSMIT_WAIT_TIME_LOWP - MIN_TRANSMIT_WAIT_TIME_LOWP) 00119 * Random::uniform())); 00120 } 00121 00122 } 00123 00124 void 00125 imepAgent::sendAck(nsaddr_t index, u_int32_t seqno) 00126 { 00127 Packet *p = Packet::alloc(); 00128 struct hdr_cmn *ch = HDR_CMN(p); 00129 struct hdr_ip *ih = HDR_IP(p); 00130 struct hdr_imep *im = HDR_IMEP(p); 00131 struct imep_ack_block *ab = (struct imep_ack_block*) (im + 1); 00132 struct imep_ack *ack = (struct imep_ack*) (ab + 1); 00133 00134 ch->ptype() = PT_IMEP; 00135 ch->size() = ACK_HDR_LEN; 00136 ch->iface() = -2; 00137 ch->error() = 0; 00138 ch->addr_type() = NS_AF_NONE; 00139 ch->prev_hop_ = ipaddr; 00140 ch->uid() = uidcnt_++; 00141 00142 ih->saddr() = ipaddr; 00143 ih->daddr() = IP_BROADCAST; 00144 ih->sport() = RT_PORT; 00145 ih->dport() = RT_PORT; 00146 ih->ttl_ = 1; 00147 00148 im->imep_version = IMEP_VERSION; 00149 im->imep_block_flags = BLOCK_FLAG_ACK; 00150 U_INT16_T(im->imep_length) = sizeof(struct hdr_imep) + 00151 sizeof(struct imep_ack_block) + sizeof(struct imep_ack) 00152 ; 00153 ab->ab_num_acks = 1; 00154 ack->ack_seqno = seqno; 00155 INT32_T(ack->ack_ipaddr) = index; 00156 00157 // aggregate as many control messages as possible before sending 00158 ackQueue.enque(p); 00159 if(controlTimer.busy() == 0) { 00160 controlTimer.start(MIN_TRANSMIT_WAIT_TIME_LOWP 00161 + ((MAX_TRANSMIT_WAIT_TIME_LOWP - MIN_TRANSMIT_WAIT_TIME_LOWP) 00162 * Random::uniform())); 00163 } 00164 }
1.3.3