📄 aal5.java
字号:
/*
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.*;
/* A generic class to handle AAL5 */
public class AAL5 implements java.io.Serializable {
private static int easy_crc=1;
private java.util.List cell_queue;
public AAL5() {
cell_queue=new java.util.ArrayList();
}
public void reset() {
cell_queue.clear();
}
public java.util.List sendData(Object pdu,int length,int vpi,int vci) {
length+=8; //aal5 trailer size
int pad=length%48;
if(pad>0) pad=48-pad;
int num_cells=(length+pad)/48;
int crc=easy_crc++;
java.util.List q=new java.util.ArrayList();
for(int i=1;i<num_cells;i++) { //send all but the last cell
Cell cell=new Cell();
cell.vpi=vpi;
cell.vci=vci;
cell.pti=0;
cell.crc=crc;
q.add(cell);
}
//the last cell
Cell cell=new Cell();
cell.vpi=vpi;
cell.vci=vci;
cell.pti=0x01;
cell.payload=pdu;
cell.len=num_cells;
cell.crc=crc;
q.add(cell);
return q;
}
//return 1: pdu ready (caller get payload)
// 0: pdu not ready
// -1: crc error
public int receiveCell(Cell cell) {
cell_queue.add(cell);
//check pti
if((cell.pti & 0x01) == 0x01) { //the last cell
if((cell_queue.size() != cell.len) ||
(((Cell)cell_queue.get(0)).crc != cell.crc)) {
cell_queue.clear();
return -1; //bad crc
}
cell_queue.clear();
return 1; //good & ready
}
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -