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

📄 genericbte.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 java.awt.*;
import java.io.Serializable;

public class GenericBTE extends SimComponent implements Serializable {

  private class Queue implements Serializable {
    SimParamInt iq=null;
    SimParamInt dq=null;
    java.util.List ptr=null;
  }

  private class Port implements Serializable {
    SimComponent to_link=null;
    boolean link_busy=false;
    Queue vbr=null;
    Queue abr=null;
    java.util.List sigQueue=null;
    SimParamNSAP nsap=null;
    AAL5 aal=null; //AAL for the UNI signaling channel (0/5)
  }

  private class CallRecordKey implements Serializable {
    short vpi,vci;

    CallRecordKey(int vpi,int vci) {
      this.vpi=(short)vpi;
      this.vci=(short)vci;
    }
    public boolean equals(Object o) {
      if(!(o instanceof CallRecordKey)) return false;
      CallRecordKey k=(CallRecordKey)o;
      if(vpi==k.vpi && vci==k.vci) return true;
      return false;
    }
    public int hashCode() {
      return ((vpi<<16)|vci);
    }
  }

  private class CallRecord implements Serializable {
    CallRecordKey key;
    SimComponent appcomp; //the source/dest application
    int callref;
    int contype;
  }

/* Note about calls:
    Calls from this bte are mapped in ftable and records,
    while calls from other btes are mapped in r_records and r_ftable,
    in order to avoid duplicate of call reference or callrecordkey.

    Another note: callref assigned by the source application will
                  ALWAYS be its app_port to ensure uniqueness.
*/

  private SimParamInt b_oqsize;
  private SimParamInt b_cc;
  private SimParamInt b_log_factor;
  private int b_cell_count;

  private Port voport=null; //now, the only port...
  private java.util.Map records,r_records;
  private java.util.Map ftable,r_ftable;

  private java.util.Map app_ports;

//compInfo IDs:
  public static final int GET_PORT = SimProvider.CI_PRIVATE + 1;
                                        //Ask for a port number
                                        //Returns an integer as
                                        //  the port number
  public static final int REMOVE_PORT = SimProvider.CI_PRIVATE + 2;
                                        //Release a port number
                                        // parameter: the port number
  public static final int GET_ALL_NSAP = SimProvider.CI_PRIVATE + 3;
                                        //get all nsap as array of string
  public static final int GET_ALL_PORT = SimProvider.CI_PRIVATE + 4;
                                        //get all app. ports as array of Integer
                                        //can supply a component type as the
                                        // argument to limit the results

//the constructor
  public GenericBTE(String name,String aClass,Sim aSim,int locx,int locy) {
    super(name,aClass,aSim,locx,locy);

    b_create();
  }

  public boolean isConnectable(SimComponent comp) {
    if(!super.isConnectable(comp)) return false;

    if(comp.getCompClass().equals("Application")) return true;
    if(comp.getCompClass().equals("Link") && voport==null)
      return true;
    return false;
  }

  protected void neighborAdded(SimComponent comp) {
    if(comp.getCompClass().equals("Link")) {
      voport=new Port();
      voport.to_link=comp;
      voport.link_busy=false;
      voport.vbr=new Queue();
      voport.vbr.ptr=new java.util.LinkedList();
      voport.vbr.iq=new SimParamInt("Cells in VBR Q to "+comp.getName(),this,
                                     theSim.now(),true,false,0);
      voport.vbr.iq.update(theSim.now());
      voport.vbr.dq=new SimParamInt("Cells dropped in VBR Q to "+comp.getName(),this,
                                     theSim.now(),true,false,0);
      voport.vbr.dq.update(theSim.now());
      voport.abr=new Queue();
      voport.abr.ptr=new java.util.LinkedList();
      voport.abr.iq=new SimParamInt("Cells in ABR Q to "+comp.getName(),this,
                                     theSim.now(),true,false,0);
      voport.abr.iq.update(theSim.now());
      voport.abr.dq=new SimParamInt("Cells dropped in ABR Q to "+comp.getName(),this,
                                     theSim.now(),true,false,0);
      voport.abr.dq.update(theSim.now());
      voport.sigQueue=new java.util.LinkedList();
      voport.nsap=new SimParamNSAP("NSAP for interface to "+comp.getName(),this,
                                    theSim.now(),false,true,"0");
      voport.aal=new AAL5();

      addParameter(voport.nsap);
      addParameter(voport.vbr.iq);
      addParameter(voport.vbr.dq);
      addParameter(voport.abr.iq);
      addParameter(voport.abr.dq);
    }
  }

  protected void neighborRemoved(SimComponent comp) {
    if(voport==null || voport.to_link!=comp) return;

    removeParameter(voport.nsap);
    removeParameter(voport.vbr.iq);
    removeParameter(voport.vbr.dq);
    removeParameter(voport.abr.iq);
    removeParameter(voport.abr.dq);

    voport=null;
  }

  public void copy(SimComponent comp) {
    if(comp instanceof GenericBTE) {
      GenericBTE theComp=(GenericBTE)comp;
      b_oqsize.setValue(theComp.b_oqsize.getValue());
      b_log_factor.setValue(theComp.b_log_factor.getValue());
    }
  }

  public Image getImage(Component refcomp) {
    if(image==null) {
      image=Toolkit.getDefaultToolkit().getImage(
              "images"+System.getProperty("file.separator")+"bte.gif");
    }
    return image;
  }

  public void reset() {
    b_cell_count=0;
    b_cc.setValue(0);
    b_cc.update(theSim.now());

    records.clear();
    r_records.clear();
    ftable.clear();
    r_ftable.clear();

    if(voport!=null) {
      voport.link_busy=false;
      voport.vbr.ptr.clear();
      voport.vbr.iq.setValue(0);
      voport.vbr.iq.update(theSim.now());
      voport.vbr.dq.setValue(0);
      voport.vbr.dq.update(theSim.now());
      voport.abr.ptr.clear();
      voport.abr.iq.setValue(0);
      voport.abr.iq.update(theSim.now());
      voport.abr.dq.setValue(0);
      voport.abr.dq.update(theSim.now());
      voport.sigQueue.clear();
      voport.aal.reset();
    }
  }

  public void start() {
  }

  public void action(SimEvent e) {
    switch(e.getType()) {
      case SimProvider.EV_RECEIVE:
        b_receive(e);
        break;
      case SimProvider.EV_READY:
        b_ready(e);
        break;
      case SimProvider.EV_RECEIVE_UNI:
        b_receive_uni(e);
        break;
    }
  }

////compInfo of GenericBTE:
////(refer constant definitions near the beginning of the class declaration)
  public Object compInfo(int infoid,SimComponent src,Object paramlist) {
    int i,j;
    switch(infoid) {
      case GET_PORT:
        Integer [] curports=(Integer [])app_ports.keySet().toArray(new Integer[0]);
        outer: for(i=1;;i++) {
          for(j=0;j<curports.length;j++) {
            if(i==curports[j].intValue()) continue outer;
          }
          break;
        }
        Object o=new Integer(i);
        app_ports.put(o,src);
        return o;
      case REMOVE_PORT:
        app_ports.remove((Integer)paramlist);
        return null;
      case GET_ALL_NSAP:
        if(voport==null) return null;
        String [] str=new String[1];
        str[0]=voport.nsap.getValue();
        return str;
      case GET_ALL_PORT:
        if(app_ports.isEmpty()) return null;
        Integer [] intports=(Integer [])app_ports.keySet().toArray(new Integer[0]);
        if(paramlist==null) {
          return intports;
        }

⌨️ 快捷键说明

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