📄 tcp.h
字号:
/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
/*
* Copyright (c) 1991-1997 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/tcp.h,v 1.82 2000/09/01 03:04:08 haoboy Exp $ (LBL)
*/
#ifndef ns_tcp_h
#define ns_tcp_h
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "agent.h"
#include "packet.h"
//added by xiaoqiao
#define VALID_TIMESPAN 2 //2 seconds,used in RecentMeanandVariation()
#define SMOOTH_FACTOR 0.7 //0.7*currentvalue + (1-0.7)*lastvalue
#define IDD_THRESHOLD_WHETHERCONGESTION_THRESHOLDMETHOD 2
#define THRU_THRESHOLD_WHETHERCONGESTION_THRESHOLDMETHOD 2
#define WEIGHT_COEFFICIENT_IDD 10 //relative weight of each metric
#define WEIGHT_COEFFICIENT_THRU 1
#define WEIGHT_COEFFICIENT_PO 10
#define WEIGHT_COEFFICIENT_LOS 10
struct MetricVector_ {
double dIDD;
double dTHRU;
double dPO;
double dLOS;
};
struct Value_t {
double dvalue;
double dtime;
};
struct Params_ {
double dIDDHistory_Mean;
double dIDDHistory_Deviation;
double dTHRUHistory_Mean;
double dTHRUHistory_Deviation;
double dPOHistory_Mean;
double dPOHistory_Deviation;
double dLOSHistory_Mean;
double dLOSHistory_Deviation;
};
#define LDA_Con_NonCon_MAXSAMPLENUMBER 100
#define LDA_Con_NonCon_MINSAMPLENUMBER 3
//---------------------------------------------------
struct hdr_tcp {
#define NSA 3
double ts_; /* time packet generated (at source) */
double ts_echo_; /* the echoed timestamp (originally sent by
the peer) */
int seqno_; /* sequence number */
int reason_; /* reason for a retransmit */
int sack_area_[NSA+1][2]; /* sack blocks: start, end of block */
int sa_length_; /* Indicate the number of SACKs in this *
* packet. Adds 2+sack_length*8 bytes */
int ackno_; /* ACK number for FullTcp */
int hlen_; /* header len (bytes) for FullTcp */
int tcp_flags_; /* TCP flags for FullTcp */
static int offset_; // offset for this header
inline static int& offset() { return offset_; }
inline static hdr_tcp* access(Packet* p) {
return (hdr_tcp*) p->access(offset_);
}
/* per-field member functions */
double& ts() { return (ts_); }
double& ts_echo() { return (ts_echo_); }
int& seqno() { return (seqno_); }
int& reason() { return (reason_); }
int& sa_left(int n) { return (sack_area_[n][0]); }
int& sa_right(int n) { return (sack_area_[n][1]); }
int& sa_length() { return (sa_length_); }
int& hlen() { return (hlen_); }
int& ackno() { return (ackno_); }
int& flags() { return (tcp_flags_); }
};
/* these are used to mark packets as to why we xmitted them */
#define TCP_REASON_TIMEOUT 0x01
#define TCP_REASON_DUPACK 0x02
#define TCP_REASON_RBP 0x03 // used only in tcp-rbp.cc
#define TCP_REASON_ELFN 0x04 // used for elfn
/* these are reasons we adjusted our congestion window */
#define CWND_ACTION_DUPACK 1 // dup acks/fast retransmit
#define CWND_ACTION_TIMEOUT 2 // retransmission timeout
#define CWND_ACTION_ECN 3 // ECN bit [src quench if supported]
/* these are bits for how to change the cwnd and ssthresh values */
#define CLOSE_SSTHRESH_HALF 0x00000001
#define CLOSE_CWND_HALF 0x00000002
#define CLOSE_CWND_RESTART 0x00000004
#define CLOSE_CWND_INIT 0x00000008
#define CLOSE_CWND_ONE 0x00000010
#define CLOSE_SSTHRESH_HALVE 0x00000020
#define CLOSE_CWND_HALVE 0x00000040
#define THREE_QUARTER_SSTHRESH 0x00000080
#define CLOSE_CWND_HALF_WAY 0x00000100
#define CWND_HALF_WITH_MIN 0x00000200
// virtual monitor, added by Zhenghua
#define F_LINK 0x00001000
#define F_MOBI 0x00002000
#define F_ERR 0x00004000
#define F_PO 0x00008000
#define F_CONG 0x00010000
#define ALPHA 0.125
#define BETA 4
#define STARTUP_PKTS 1
#define MAX_NODES 200
#define STATE_HOLDING_TIME 1 // in seconds
#define MAX_INTERVALS 500
#define LOWEST_VAL 0
#define HIGHEST_VAL 20.0
#define INTERVAL 0.05
#define MAX_PKTNO 200000
#define MAX_PKTS 50000
#define MAX_PACKET_PER_SECOND 50
#define PC_WEIGHT_LINEAR ALPHA
#define PC_WEIGHT_EXP 1.3
#define IAD_WEIGHT ALPHA
#define MAX_HIST_TABLE 128
#define IAD_INTERVAL 0.01
#define MAX_TS 1.0
#define MINIMUM_SAMPLES 100
#define NOCONGEST_THRESHOLD 0.75
#define NOCONGEST_THRESHOLD_EXP 0.85
#define NOCONGEST_THRESHOLD_LIN 0.65
#define TOTAL_SAMPLES 500
/*
* tcp_tick_:
* default 0.1,
* 0.3 for 4.3 BSD,
* 0.01 for new window algorithms,
*/
#define NUMDUPACKS 3 /* This is no longer used. The variable */
/* numdupacks_ is used instead. */
#define TCP_MAXSEQ 1073741824 /* Number that curseq_ is set to for */
/* "infinite send" (2^30) */
#define TCP_TIMER_RTX 0
#define TCP_TIMER_DELSND 1
#define TCP_TIMER_BURSTSND 2
#define TCP_TIMER_DELACK 3
#define TCP_TIMER_Q 4
#define TCP_TIMER_RESET 5
#define TCP_TIMER_PACE 6
class TcpAgent;
class RtxTimer : public TimerHandler {
public:
RtxTimer(TcpAgent *a) : TimerHandler() { a_ = a; }
protected:
virtual void expire(Event *e);
TcpAgent *a_;
};
class PaceTimer: public TimerHandler {
public:
PaceTimer(TcpAgent *a) : TimerHandler() {a_ = a;}
protected:
virtual void expire(Event *e);
TcpAgent *a_;
};
class DelSndTimer : public TimerHandler {
public:
DelSndTimer(TcpAgent *a) : TimerHandler() { a_ = a; }
protected:
virtual void expire(Event *e);
TcpAgent *a_;
};
class BurstSndTimer : public TimerHandler {
public:
BurstSndTimer(TcpAgent *a) : TimerHandler() { a_ = a; }
protected:
virtual void expire(Event *e);
TcpAgent *a_;
};
class TcpAgent : public Agent {
public:
TcpAgent();
virtual void recv(Packet*, Handler*);
virtual void timeout(int tno);
virtual void timeout_nonrtx(int tno);
int command(int argc, const char*const* argv);
virtual void sendmsg(int nbytes, const char *flags = 0);
void trace(TracedVar* v);
virtual void advanceby(int delta);
protected:
virtual int window();
virtual double windowd();
void print_if_needed(double memb_time);
void traceAll();
virtual void traceVar(TracedVar* v);
virtual void delay_bind_init_all();
virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
/*
* State encompassing the round-trip-time estimate.
* srtt and rttvar are stored as fixed point;
* srtt has 3 bits to the right of the binary point, rttvar has 2.
*/
TracedInt t_seqno_; /* sequence number */
#define T_RTT_BITS 0
TracedInt t_rtt_; /* round trip time */
int T_SRTT_BITS; /* exponent of weight for updating t_srtt_ */
TracedInt t_srtt_; /* smoothed round-trip time */
int srtt_init_; /* initial value for computing t_srtt_ */
int T_RTTVAR_BITS; /* exponent of weight for updating t_rttvar_ */
int rttvar_exp_; /* exponent of multiple for t_rtxcur_ */
TracedInt t_rttvar_; /* variance in round-trip time */
int rttvar_init_; /* initial value for computing t_rttvar_ */
double t_rtxcur_; /* current retransmit value */
double rtxcur_init_; /* initial value for t_rtxcur_ */
TracedInt t_backoff_; /* current multiplier, 1 if not backed off */
virtual void rtt_init();
virtual double rtt_timeout(); /* provide RTO based on RTT estimates */
virtual void rtt_update(double tao); /* update RTT estimate */
virtual void rtt_backoff(); /* double multiplier */
double ts_peer_; /* the most recent timestamp the peer sent */
/* connection and packet dynamics */
virtual void output(int seqno, int reason = 0);
virtual void send_much(int force, int reason, int maxburst = 0);
virtual void newtimer(Packet*);
virtual void dupack_action(); /* do this on dupacks */
virtual void send_one(); /* do this on 1-2 dupacks */
void opencwnd();
void slowdown(int how); /* reduce cwnd/ssthresh */
void ecn(int seqno); /* react to quench */
virtual void set_initial_window(); /* set IW */
double initial_window(); /* what is IW? */
void reset();
void newack(Packet*);
void tcp_eln(Packet *pkt); /* reaction to ELN (usually wireless) */
void finish(); /* called when the connection is terminated */
void reset_qoption(); /* for QOption with EnblRTTCtr_ */
void rtt_counting(); /* for QOption with EnblRTTCtr_ */
int network_limited(); /* Sending limited by network? */
/* Helper functions. Currently used by tcp-asym */
virtual void output_helper(Packet*) { return; }
virtual void send_helper(int) { return; }
virtual void send_idle_helper() { return; }
virtual void recv_helper(Packet*) { return; }
virtual void recv_newack_helper(Packet*);
virtual void partialnewack_helper(Packet*) {};
/* Timers */
RtxTimer rtx_timer_;
PaceTimer pace_timer_;
DelSndTimer delsnd_timer_;
BurstSndTimer burstsnd_timer_;
virtual void cancel_timers() {
rtx_timer_.force_cancel();
burstsnd_timer_.force_cancel();
delsnd_timer_.force_cancel();
}
virtual void cancel_rtx_timer() {
rtx_timer_.force_cancel();
}
virtual void set_rtx_timer();
virtual void set_pace_timer();
void reset_rtx_timer(int mild, int backoff = 1);
double boot_time_; /* where between 'ticks' this sytem came up */
double overhead_;
double wnd_;
double wnd_const_;
double wnd_th_; /* window "threshold" */
double wnd_init_;
double wnd_restart_;
double tcp_tick_; /* clock granularity */
int wnd_option_;
int wnd_init_option_; /* 1 for using wnd_init_ */
/* 2 for using large initial windows */
double decrease_num_; /* factor for multiplicative decrease */
double increase_num_; /* factor for additive increase */
double k_parameter_; /* k parameter in binomial controls */
double l_parameter_; /* l parameter in binomial controls */
int precision_reduce_; /* non-integer reduction of cwnd */
int syn_; /* 1 for modeling SYN/ACK exchange */
int delay_growth_; /* delay opening cwnd until 1st data recv'd */
int tcpip_base_hdr_size_; /* size of base TCP/IP header */
int bug_fix_; /* 1 for multiple-fast-retransmit fix */
int ts_option_; /* use RFC1323-like timestamps? */
int maxburst_; /* max # packets can send back-2-back */
int maxcwnd_; /* max # cwnd can ever be */
int numdupacks_; /* dup ACKs before fast retransmit */
double maxrto_; /* max value of an RTO */
int old_ecn_; /* For backwards compatibility with the
* old ECN implementation, which never
* reduced the congestion window below
* one packet. */
FILE *plotfile_;
/*
* Dynamic state.
*/
TracedInt dupacks_; /* number of duplicate acks */
TracedInt curseq_; /* highest seqno "produced by app" */
int last_ack_; /* largest consecutive ACK, frozen during
* Fast Recovery */
TracedInt highest_ack_; /* not frozen during Fast Recovery */
int recover_; /* highest pkt sent before dup acks, */
/* timeout, or source quench/ecn */
int last_cwnd_action_; /* CWND_ACTION_{TIMEOUT,DUPACK,ECN} */
TracedDouble cwnd_; /* current window */
double base_cwnd_; /* base window (for experimental purposes) */
double awnd_; /* averaged window */
TracedInt ssthresh_; /* slow start threshold */
int count_; /* used in window increment algorithms */
double fcnt_; /* used in window increment algorithms */
int rtt_active_; /* 1 if a rtt sample is pending */
int rtt_seq_; /* seq # of timed seg if rtt_active_ is 1 */
double rtt_ts_; /* time at which rtt_seq_ was sent */
TracedInt maxseq_; /* used for Karn algorithm */
/* highest seqno sent so far */
int ecn_; /* Explicit Congestion Notification */
int cong_action_; /* Congestion Action. True to indicate
that the sender responded to congestion. */
int ecn_burst_; /* True when the previous ACK packet
* carried ECN-Echo. */
int ecn_backoff_; /* True when retransmit timer should begin
to be backed off. */
int ect_; /* turn on ect bit now? */
int eln_; /* Explicit Loss Notification (wireless) */
int eln_rxmit_thresh_; /* Threshold for ELN-triggered rxmissions */
int eln_last_rxmit_; /* Last packet rxmitted due to ELN info */
double firstsent_; /* When first packet was sent --Allman */
int slow_start_restart_; /* boolean: re-init cwnd after connection
goes idle. On by default. */
int restart_bugfix_; /* ssthresh is cut down because of
timeouts during a connection's idle period.
Setting this boolean fixes this problem.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -