📄 genericbte.java
字号:
else {
String comptype=(String)paramlist;
java.util.List targets=new java.util.ArrayList();
for(i=0;i<intports.length;i++) {
SimComponent thecomp=(SimComponent)app_ports.get(intports[i]);
if(thecomp.getClass().getName().equals(comptype)) targets.add(intports[i]);
}
return (Integer [])targets.toArray(new Integer[0]);
}
}
return null;
}
///////////////////// private methods ////////////////////////////////
private void b_create() {
b_cell_count=0;
records=new java.util.HashMap();
r_records=new java.util.HashMap();
ftable=new java.util.HashMap();
r_ftable=new java.util.HashMap();
//Initialize the parameters
long ctick=theSim.now();
b_oqsize=new SimParamInt("Max Output Queue Size (-1=inf)",this,ctick,false,true,-1);
b_log_factor=new SimParamInt("Logging every (ticks) (e.g. 1, 100)",this,ctick,false,true,0);
b_cc=new SimParamInt("Cells Received",this,ctick,true,false,0);
addParameter(b_oqsize);
addParameter(b_log_factor);
addParameter(b_cc);
app_ports=new java.util.HashMap();
}
private void b_ready(SimEvent e) {
if(voport!=null && voport.to_link==e.getSource()) {
voport.link_busy=false;
b_schedule_output();
}
}
private void b_schedule_output() {
Cell icell=null;
if(voport.link_busy) return;
if(!voport.sigQueue.isEmpty()) {
icell=(Cell)voport.sigQueue.remove(0);
}
else if(!voport.vbr.ptr.isEmpty()) {
icell=(Cell)voport.vbr.ptr.remove(0);
voport.vbr.iq.setValue(voport.vbr.ptr.size(),theSim.now(),b_log_factor.getValue());
}
else if(!voport.abr.ptr.isEmpty()) {
icell=(Cell)voport.abr.ptr.remove(0);
voport.abr.iq.setValue(voport.abr.ptr.size(),theSim.now(),b_log_factor.getValue());
}
if(icell!=null) {
theSim.enqueue(new SimEvent(SimProvider.EV_RECEIVE,this,voport.to_link,theSim.now(),icell));
voport.link_busy=true;
}
}
//helper function, check whether an NSAP is a local interface
private boolean targetMe(String calledNSAP) {
if(voport==null) return false;
if(calledNSAP.equals(voport.nsap.getValue())) return true;
return false;
}
private void b_receive_uni(SimEvent e) {
UNIInfo uni=(UNIInfo)e.getParams();
//note: this can only be received from Application!
switch(uni.msgtype) {
case UNIInfo.UNI_SETUP:
//first, check whether it's a local call...
if(targetMe(uni.calledNSAP)) {
//don't allow that, so send release_complete
UNIInfo newuni=new UNIInfo();
newuni.callref=uni.callref+65535; //reverse direction must set "flag"...
newuni.msgtype=UNIInfo.UNI_RELEASE_COMPLETE;
theSim.enqueue(new SimEvent(SimProvider.EV_RECEIVE_UNI,this,
e.getSource(),theSim.now(),newuni));
return;
}
//else, add a new record
CallRecord newrec=new CallRecord();
newrec.key=null; //not assigned yet...
newrec.appcomp=(SimComponent)e.getSource();
newrec.callref=uni.callref; //this IS the app_port !
newrec.contype=uni.contype;
records.put(new Integer(newrec.callref),newrec);
//must send out the only link...
if(voport!=null) { //safety check
voport.sigQueue.addAll(voport.aal.sendData(uni,120,0,5));
b_schedule_output();
}
break;
case UNIInfo.UNI_RELEASE:
//got the RELEASE message, so delete the call record
//right now, assume ALWAYS release by source...
//(although the GenericATMSwitch allows release by any party, but...)
CallRecord rec=(CallRecord)records.remove(new Integer(uni.callref));
ftable.remove(rec.key);
if(voport!=null) {//safety check
voport.sigQueue.addAll(voport.aal.sendData(uni,20,0,5));
b_schedule_output();
}
break;
}
}
private void b_receive(SimEvent e) {
Cell cell=(Cell)e.getParams();
CallRecord rec;
SimComponent src=(SimComponent)e.getSource();
SimComponent dest;
//update total received cell, including those from local applications
b_cell_count++;
b_cc.setValue(b_cell_count,theSim.now(),b_log_factor.getValue());
if(src.getCompClass().equals("Application")) {
//look up first...
rec=(CallRecord)ftable.get(new CallRecordKey(cell.vpi,cell.vci));
if(rec==null) return; //no record!! Can't be....
if(voport!=null) {
if(rec.contype==UNIInfo.CON_ABR || rec.contype==UNIInfo.CON_UBR) {
if((voport.abr.ptr.size()<b_oqsize.getValue()) || (b_oqsize.getValue()==-1)) {
voport.abr.ptr.add(cell);
voport.abr.iq.setValue(voport.abr.ptr.size(),theSim.now(),b_log_factor.getValue());
b_schedule_output();
}
else //drop it if queue full
voport.abr.dq.setValue(voport.abr.dq.getValue()+1,theSim.now(),b_log_factor.getValue());
}
else {
if((voport.vbr.ptr.size()<b_oqsize.getValue()) || (b_oqsize.getValue()==-1)) {
voport.vbr.ptr.add(cell);
voport.vbr.iq.setValue(voport.vbr.ptr.size(),theSim.now(),b_log_factor.getValue());
b_schedule_output();
}
else //drop it if queue full
voport.vbr.dq.setValue(voport.vbr.dq.getValue()+1,theSim.now(),b_log_factor.getValue());
}
}
}
else if(src.getCompClass().equals("Link")) {
rec=(CallRecord)r_ftable.get(new CallRecordKey(cell.vpi,cell.vci));
if(rec==null) { //no record...
//check for signaling cells
if(cell.vpi==0 && cell.vci==5) {
if(voport.aal.receiveCell(cell)==1) {
UNIInfo uni=(UNIInfo)cell.payload;
switch(uni.msgtype) {
case UNIInfo.UNI_SETUP:
//call request from others
dest=(SimComponent)app_ports.get(new Integer(uni.calledport));
if(dest==null) { //oops, port doesn't exist...
//send RELEASE COMPLETE
UNIInfo newuni=new UNIInfo();
newuni.callref=uni.callref+65535; //reverse direction must set "flag"...
newuni.msgtype=UNIInfo.UNI_RELEASE_COMPLETE;
voport.sigQueue.addAll(voport.aal.sendData(newuni,20,0,5));
b_schedule_output();
return;
}
//should add record
CallRecord newrec=new CallRecord();
newrec.key=new CallRecordKey(uni.newvpi,uni.newvci);
newrec.appcomp=dest;
newrec.callref=uni.callref;
newrec.contype=uni.contype;
r_ftable.put(newrec.key,newrec);
r_records.put(new Integer(newrec.callref),newrec);
//and send back CONNECT (just accept all calls)
UNIInfo newuni=new UNIInfo();
newuni.callref=uni.callref+65535;
newuni.msgtype=UNIInfo.UNI_CONNECT;
voport.sigQueue.addAll(voport.aal.sendData(newuni,20,0,5));
b_schedule_output();
//pass through to the app
theSim.enqueue(new SimEvent(SimProvider.EV_RECEIVE_UNI,this,dest,theSim.now(),uni));
break;
case UNIInfo.UNI_CALL_PROCEEDING:
//call_proceeding for call setup from this bte,
//now grab the vpi/vci
rec=(CallRecord)records.get(new Integer(uni.callref-65535));
rec.key=new CallRecordKey(uni.newvpi,uni.newvci);
ftable.put(rec.key,rec);
//pass through to the app
theSim.enqueue(new SimEvent(SimProvider.EV_RECEIVE_UNI,this,rec.appcomp,theSim.now(),uni));
break;
case UNIInfo.UNI_RELEASE_COMPLETE:
//must be call reject for call setup from this bte,
//must delete the record
rec=(CallRecord)records.get(new Integer(uni.callref-65535));
ftable.remove(rec.key);
records.remove(new Integer(rec.callref));
//pass through to the app
theSim.enqueue(new SimEvent(SimProvider.EV_RECEIVE_UNI,this,rec.appcomp,theSim.now(),uni));
break;
case UNIInfo.UNI_RELEASE:
//release from others
//(again, assume release ONLY from source...)
//must delete the record
rec=(CallRecord)r_records.get(new Integer(uni.callref));
r_ftable.remove(rec.key);
r_records.remove(new Integer(rec.callref));
//pass through to the app
theSim.enqueue(new SimEvent(SimProvider.EV_RECEIVE_UNI,this,rec.appcomp,theSim.now(),uni));
break;
case UNIInfo.UNI_CONNECT:
//call accepted, just pass through to the app
rec=(CallRecord)records.get(new Integer(uni.callref-65535));
theSim.enqueue(new SimEvent(SimProvider.EV_RECEIVE_UNI,this,rec.appcomp,theSim.now(),uni));
break;
}
}
}
//else, drop it (just ignore...)
return;
}
theSim.enqueue(new SimEvent(SimProvider.EV_RECEIVE,this,rec.appcomp,theSim.now(),cell));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -