00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * Protocol Engineering Lab, U of Delaware 00004 * Janardhan Iyengar <iyengar@@cis,udel,edu> 00005 * 00006 * This SCTP test application is a modified version of the telnet code 00007 * developed by the University of California. The original copyright is below. 00008 */ 00009 /* 00010 * Copyright (c) 1997 Regents of the University of California. 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions 00015 * are met: 00016 * 1. Redistributions of source code must retain the above copyright 00017 * notice, this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright 00019 * notice, this list of conditions and the following disclaimer in the 00020 * documentation and/or other materials provided with the distribution. 00021 * 3. All advertising materials mentioning features or use of this software 00022 * must display the following acknowledgement: 00023 * This product includes software developed by the Daedalus Research 00024 * Group at the University of California Berkeley. 00025 * 4. Neither the name of the University nor of the Laboratory may be used 00026 * to endorse or promote products derived from this software without 00027 * specific prior written permission. 00028 * 00029 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00030 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00031 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00032 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00033 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00034 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00035 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00036 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00037 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00038 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00039 * SUCH DAMAGE. 00040 * 00041 * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/apps/sctp_app1.cc,v 1.1 2003/08/21 18:25:59 haldar Exp $ */ 00042 00043 #include "random.h" 00044 #include "sctp.h" 00045 #include "sctp_app1.h" 00046 00047 extern double tcplib_telnet_interarrival(); 00048 00049 AppData_S *data_to_transport = NULL; 00050 00051 static class SctpApp1Class : public TclClass { 00052 public: 00053 SctpApp1Class() : TclClass("Application/SctpApp1") {} 00054 TclObject* create(int, const char*const*) { 00055 return (new SctpApp1); 00056 } 00057 } class_app_sctp; 00058 00059 00060 SctpApp1::SctpApp1() : running_(0), timer_(this) 00061 { 00062 bind("interval_", &interval_); 00063 bind("numUnreliable_", &numUnreliable); 00064 bind("numStreams_", &numStreams); 00065 bind("reliability_", &reliability); 00066 } 00067 00068 00069 void SctpApp1Timer::expire(Event*) 00070 { 00071 t_->timeout(); 00072 } 00073 00074 00075 void SctpApp1::start() 00076 { 00077 running_ = 1; 00078 double t = next(); 00079 timer_.sched(t); 00080 } 00081 00082 void SctpApp1::stop() 00083 { 00084 running_ = 0; 00085 } 00086 00087 void SctpApp1::timeout() 00088 { 00089 if (running_) { 00090 data_to_transport = new AppData_S; 00091 memset(data_to_transport, 0, sizeof(AppData_S)); 00092 data_to_transport->usNumStreams = numStreams; 00093 data_to_transport->usNumUnreliable = numUnreliable; 00094 data_to_transport->usReliability = reliability; 00095 data_to_transport->uiNumBytes = 257; 00096 agent_->sendmsg(agent_->size(), (char*)data_to_transport); 00097 /* reschedule the timer */ 00098 double t = next(); 00099 timer_.resched(t); 00100 } 00101 } 00102 00103 double SctpApp1::next() 00104 { 00105 if (interval_ == 0) 00106 /* use tcplib */ 00107 return tcplib_telnet_interarrival(); 00108 else 00109 return Random::exponential() * interval_; 00110 }
1.4.6