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

📄 simparamtcp.java

📁 一个小型网络仿真器的实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
   JaNetSim  ---  Java Network Simulator
   -------------------------------------

   This software was developed at the Network Research Lab, Faculty of
   Computer Science and Information Technology (FCSIT), University of Malaya.
   This software may be used and distributed freely. FCSIT assumes no responsibility
   whatsoever for its use by other parties, and makes no guarantees, expressed or
   implied, about its quality, reliability, or any other characteristic.

   We would appreciate acknowledgement if the software is used.

   FCSIT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
   DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
   FROM THE USE OF THIS SOFTWARE.
*/

package janetsim.component;

import janetsim.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class SimParamTCP extends SimParameter implements ActionListener,
                                          TCPProvider,java.io.Serializable {
  private TCP tcp;
  private double tcp_delay=0;
  private double tcp_delayvar=0;
  private int tcp_maxwin=64000;
  private int tcp_maxseg=536;
  private double rtt_alpha=0.125;
  private double rtt_beta=0.25;
  private double rtt_lbound=1;
  private double rtt_ubound=60;
  private int tcp_cc=2;
  private long log_factor=0;
  private transient JComponent jcomp=null;
  private transient SimDialog ctableDialog=null;
  private transient JTable table=null;

  public SimParamTCP(String aName,SimComponent comp,long creationTick) {
    super(aName,comp,creationTick,false);

    tcp=new TCP(comp,this);
  }

////////////// possible overrides //////////////////////////

  public JComponent getJComponent() {
    if(jcomp==null) {
      jcomp=new JButton("Details...");
      ((JButton)jcomp).setHorizontalAlignment(JButton.LEFT);
      ((JButton)jcomp).addActionListener(this);
    }
    return jcomp;
  }

////////////// services /////////////////////////////////////

  public void reset() {
    tcp.reset();
  }

  public void receive_ip(IPPacket packet,SimComponent fromlink) {
    tcp.receive_ip(packet,fromlink);
  }

  public TCP getTCP() {
    return tcp;
  }


////////////// tcp provider /////////////////////////////////////

  public double getDelay() {
    return tcp_delay;
  }
  public double getDelayVar() {
    return tcp_delayvar;
  }
  public int getMaxWindowSize() {
    return tcp_maxwin;
  }
  public int getMaxSegmentSize() {
    return tcp_maxseg;
  }
  public double getRTT_alpha() {
    return rtt_alpha;
  }
  public double getRTT_beta() {
    return rtt_beta;
  }
  public double getRTT_lbound() {
    return rtt_lbound;
  }
  public double getRTT_ubound() {
    return rtt_ubound;
  }
  public int getTCPCongestionControl() {
    return tcp_cc;
  }
  public long getLogFactor() {
    return log_factor;
  }
  public void sendPacket(IPPacket packet) {
    getOwner().compInfo(SimProvider.CI_TRANSPORT_SEND,null,packet);
  }
  public void statusChanged() {
    //refresh the table if visible
    if(ctableDialog!=null) {
      table.revalidate();
      ctableDialog.repaint();
    }
  }


////////////// private /////////////////////////////////////

  private class PropDialogListener implements ActionListener {
    JDialog dialog=null;
    JTextField txtDelay, txtDelayvar, txtMaxwin, txtMaxseg;
    JTextField txtAlpha, txtBeta, txtLBound, txtUBound, txtLogFac;
    JComboBox cmbTCPCC;
    JButton btnOK, btnCancel;

    public void actionPerformed(ActionEvent e) {
      if(e.getSource()==btnOK) {
        double newdelay=0,newvar=0;
        int newwin=0,newseg=0;
        double newalpha=0,newbeta=0,newlbound=0,newubound=0;
        long newlogfac=0;
        try {
          newdelay=Double.parseDouble(txtDelay.getText().trim());
          if(newdelay<0) throw new NumberFormatException();
        } catch(NumberFormatException ex) {
          JOptionPane.showMessageDialog(theGUI.getMainFrame(),"Delay not valid!",
                                            "Error",JOptionPane.INFORMATION_MESSAGE);
          txtDelay.requestFocus();
          return;
        }
        try {
          newvar=Double.parseDouble(txtDelayvar.getText().trim());
          if(newvar<0) throw new NumberFormatException();
        } catch(NumberFormatException ex) {
          JOptionPane.showMessageDialog(theGUI.getMainFrame(),"Delay variation not valid!",
                                            "Error",JOptionPane.INFORMATION_MESSAGE);
          txtDelayvar.requestFocus();
          return;
        }
        try {
          newwin=Integer.parseInt(txtMaxwin.getText().trim());
          if(newwin<0 || newwin>65535) throw new NumberFormatException();
        } catch(NumberFormatException ex) {
          JOptionPane.showMessageDialog(theGUI.getMainFrame(),"Max window size not valid!",
                                            "Error",JOptionPane.INFORMATION_MESSAGE);
          txtMaxwin.requestFocus();
          return;
        }
        try {
          newseg=Integer.parseInt(txtMaxseg.getText().trim());
          if(newseg<=0) throw new NumberFormatException();
        } catch(NumberFormatException ex) {
          JOptionPane.showMessageDialog(theGUI.getMainFrame(),"Max segment size not valid!",
                                            "Error",JOptionPane.INFORMATION_MESSAGE);
          txtMaxseg.requestFocus();
          return;
        }
        try {
          newalpha=Double.parseDouble(txtAlpha.getText().trim());
          if(newalpha>=1.0 || newalpha<=0) throw new NumberFormatException();
        } catch(NumberFormatException ex) {
          JOptionPane.showMessageDialog(theGUI.getMainFrame(),"RTT alpha not valid!",
                                            "Error",JOptionPane.INFORMATION_MESSAGE);
          txtAlpha.requestFocus();
          return;
        }
        try {
          newbeta=Double.parseDouble(txtBeta.getText().trim());
          if(newbeta>=1.0 || newbeta<=0) throw new NumberFormatException();
        } catch(NumberFormatException ex) {
          JOptionPane.showMessageDialog(theGUI.getMainFrame(),"RTT beta not valid!",
                                            "Error",JOptionPane.INFORMATION_MESSAGE);
          txtBeta.requestFocus();
          return;
        }
        try {
          newlbound=Double.parseDouble(txtLBound.getText().trim());
          if(newlbound<=0) throw new NumberFormatException();
        } catch(NumberFormatException ex) {
          JOptionPane.showMessageDialog(theGUI.getMainFrame(),"RTT lower bound not valid!",
                                            "Error",JOptionPane.INFORMATION_MESSAGE);
          txtLBound.requestFocus();
          return;
        }
        try {
          newubound=Double.parseDouble(txtUBound.getText().trim());
          if(newubound<=0 || newubound<newlbound) throw new NumberFormatException();
        } catch(NumberFormatException ex) {
          JOptionPane.showMessageDialog(theGUI.getMainFrame(),"RTT upper bound not valid!",
                                            "Error",JOptionPane.INFORMATION_MESSAGE);
          txtUBound.requestFocus();
          return;
        }
        try {
          newlogfac=Long.parseLong(txtLogFac.getText().trim());
        } catch(NumberFormatException ex) {
          JOptionPane.showMessageDialog(theGUI.getMainFrame(),"Logging Every value not valid!",
                                            "Error",JOptionPane.INFORMATION_MESSAGE);
          txtLogFac.requestFocus();
          return;
        }
        tcp_delay=newdelay;
        tcp_delayvar=newvar;
        tcp_maxwin=newwin;
        tcp_maxseg=newseg;
        rtt_alpha=newalpha;
        rtt_beta=newbeta;
        rtt_lbound=newlbound;
        rtt_ubound=newubound;
        tcp_cc=cmbTCPCC.getSelectedIndex();
        log_factor=newlogfac;
        dialog.dispose();
      }
      else {
        dialog.dispose();
      }
    }

⌨️ 快捷键说明

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