• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/tcp/tcp-linux.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1997 The 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 Network Research
00017  *      Group at Lawrence Berkeley National 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  */
00035 
00036 /* 
00037  * TCP-Linux module for NS2 
00038  *
00039  * May 2006
00040  *
00041  * Author: Xiaoliang (David) Wei  (DavidWei@acm.org)
00042  *
00043  * NetLab, the California Institute of Technology 
00044  * http://netlab.caltech.edu
00045  *
00046  * Module: tcp-linux.h
00047  *      This is the header file for TCP-Linux in NS-2.
00048  *
00049  *
00050  * See a mini-tutorial about TCP-Linux at: http://netlab.caltech.edu/projects/ns2tcplinux/
00051  *
00052  */
00053 
00054 
00055 #ifndef ns_tcp_linux_h
00056 #define ns_tcp_linux_h
00057 
00058 #include "tcp.h"
00059 #include "scoreboard1.h"
00060 #include "linux/ns-linux-util.h"
00061 
00062 
00063 #define DEBUG_LEVEL 0
00064 #define DEBUG(level, ...) if (DEBUG_LEVEL>=level) printf(__VA_ARGS__);
00065 
00066 /* A list to store the parameters */
00067 class ParamList {
00068 private:
00069         typedef struct paramNode {
00070                 int* addr;
00071                 int value;
00072                 int default_value;
00073                 struct paramNode* next;
00074         };
00075         struct paramNode* head;
00076 public:
00077         ParamList():head(NULL) {};
00078         ~ParamList();
00080         void set_param(int* address, int value);
00081         bool get_param(int* address, int* valuep);
00082 
00084         void refresh_default();
00085         
00087         void restore_default();
00088         void load_local();
00089 };
00090 
00091 //This class provide C++ interface to access the Linux parameters for specific congestion control algorithm
00092 /* The manager of Linux parameters for each TCP */
00093 class LinuxParamManager {
00094 private:
00095         ParamList localValues;
00096         static struct cc_list* find_cc_by_proto(const char* proto);
00097         static struct cc_param_list* find_param_by_proto_name(const char* proto, const char* name);
00098 public:
00099         LinuxParamManager(){};
00100         static bool set_default_param(const char* proto, const char* param, const int value);
00101         static bool get_default_param(const char* proto, const char* param, int* valuep);
00102         static bool query_param(const char* proto);
00103         bool set_param(const char* proto, const char* param, const int value);
00104         bool get_param(const char* proto, const char* param, int* valuep);
00105         void load_local() {localValues.load_local();};
00106         void restore_default() {localValues.restore_default();};
00107 };
00108 
00109 
00110 /* TCP Linux */
00111 class LinuxTcpAgent : public TcpAgent {
00112 private:        
00113         LinuxParamManager paramManager;
00114 public:
00115         LinuxTcpAgent();
00116         virtual ~LinuxTcpAgent();
00117         virtual void recv(Packet *pkt, Handler*);
00118         virtual void timeout(int tno);
00119         virtual int window();
00120         virtual double windowd();
00121         void oldack (Packet* pkt);
00122         int maxsack (Packet* pkt); 
00123         void plot();
00124         void reset();
00125         virtual void send_much(int force, int reason, int maxburst = 0);
00126         virtual int packets_in_flight();
00127         virtual int command(int argc, const char*const* argv);
00128 
00129 protected:
00130         ScoreBoard1 *scb_;
00131         struct tcp_sock linux_;         // Main data structure of a Linux TCP flow
00132         bool initialized_;              // a flag to record if a congestion control algorithm is initialized or not
00133                                         // ca_ops->init shall be run the first time an acknowledgment is processed (at least one RTT sample recorded).
00134         TracedInt next_pkts_in_flight_; //the # of packets in flight allowed, if we need rate halving
00135 
00136 
00137         virtual bool is_congestion();   // whether the network is congested?
00138 
00139         void rtt_update(double tao, unsigned long pkt_seq_no=0);                //rewrite the tcp.cc functions
00140 
00141         unsigned char ack_processing(Packet* pkt, unsigned char flag);          // process the ack: sequence#
00142         void time_processing(Packet* pkt, unsigned char flag,s32* seq_urtt_p);  // process the ack for timestamp, timer
00143                                                                                 //     these two processing functions replace 
00144                                                                                 // the combination of newack() and oldack()
00145 
00146 
00147 
00148         void touch_cwnd();                              // called whenever cwnd_ is changed, mark linux_.snd_cwnd_stamp
00149 
00150         void enter_loss();
00151 //      void enter_frto();              We don't have FRTO yet
00152 //      void enter_frto_loss();         We don't hvae FRTO yet
00153         void tcp_fastretrans_alert(unsigned char flag);
00154         void tcp_moderate_cwnd();
00155 
00156         void load_to_linux();                           // the variables that shall be loaded to Linux every acks
00157         void load_to_linux_once();                      // the variables that shall be loaded to Linux at boot or reset 
00158 
00159         void save_from_linux();                         // the variables that shall be saved from Linux every ack
00160 
00161         char install_congestion_control(const char* name);
00162         void remove_congestion_control();
00163 
00164         inline void tcp_set_ca_state(const u8 ca_state) {
00165                 if ((linux_.icsk_ca_ops)&&(linux_.icsk_ca_ops->set_state))
00166                         linux_.icsk_ca_ops->set_state(&linux_, ca_state);
00167                 //printf("%lf: %d State: %d->%d cwnd:%d ssthresh:%d\n",Scheduler::instance().clock(), this, linux_.icsk_ca_state, ca_state, linux_.snd_cwnd, linux_.snd_ssthresh);
00168                 linux_.icsk_ca_state = ca_state;
00169 
00170         };
00171         inline void tcp_ca_event(const enum tcp_ca_event event) {
00172                 if ((linux_.icsk_ca_ops)&&(linux_.icsk_ca_ops->cwnd_event))
00173                         linux_.icsk_ca_ops->cwnd_event(&linux_, event);
00174                 //printf("%lf: %d Event: %d\n",Scheduler::instance().clock(), this, event);
00175         };
00176 };
00177 
00178 class CongestionControlManager
00179 {
00180 
00181 public:
00182         CongestionControlManager();
00183 //      int Register(struct tcp_congestion_ops* new_ops);
00184         struct tcp_congestion_ops* get_ops(const char* name);
00185         void dump();
00186         void scan();
00187 private:
00188         int num_;
00189         struct tcp_congestion_ops** ops_list;
00190 };
00191 extern CongestionControlManager cong_ops_manager;
00192 
00193 
00194 
00195 #endif

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1