mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
writing test: face&linkservice
This commit is contained in:
1 parent
d141ca0e92
commit
6dfd17cc8e
4 files changed
+187
-20
No files matched your search
@@ -1,9 +1,6 @@
|
||||
package logicface;
|
||||
|
||||
import component.ComponentException;
|
||||
import component.LpPacketFragmentId;
|
||||
import component.LpPacketFragmentNum;
|
||||
import component.LpPacketFragmentSeq;
|
||||
import component.*;
|
||||
import encoding.*;
|
||||
import mgmt.MgmtException;
|
||||
import packet.*;
|
||||
@@ -17,6 +14,9 @@ import util.ByteHelper;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class LinkService {
|
||||
// 常量
|
||||
private final int LpPacketHeaderMaxSize = 1000; // 默认最长头部长度
|
||||
|
||||
public ITransport transport; // 传输通道
|
||||
public LogicFace logicFace=new LogicFace();// LinkService关联的logicFace
|
||||
public int mtu; // MTU大小
|
||||
@@ -36,7 +36,7 @@ public class LinkService {
|
||||
byte[] buf=new byte[Encoder.MaxPacketSize];
|
||||
lpPacket.setValue(buf);
|
||||
Encoder encoder=new Encoder();
|
||||
if(!encoder.encoderReset(new SizeT(Encoder.MaxPacketSize+1000),new SizeT(0))){
|
||||
if(!encoder.encoderReset(new SizeT(Encoder.MaxPacketSize+this.LpPacketHeaderMaxSize),new SizeT(0))){
|
||||
throw new LogicFaceException("LinkService.calculateLpPacketHeadSize: encoderReset error");
|
||||
}
|
||||
this.lpPacketHeadSize = lpPacket.wireEncode(encoder);
|
||||
@@ -222,4 +222,13 @@ public class LinkService {
|
||||
throw new LogicFaceException("LinkService.sendMINPacket: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印自己的状态,测试使用。
|
||||
*/
|
||||
public void printSelf(){
|
||||
System.out.println("lpPacketHeadSize: "+this.lpPacketHeadSize);
|
||||
System.out.println("mtu: "+this.mtu);
|
||||
System.out.println("lpPacketId: "+this.lpPacketId);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
package logicface;
|
||||
|
||||
import common.LoggerHelper;
|
||||
import component.ComponentException;
|
||||
import component.Identifier;
|
||||
import component.IdentifierWrapper;
|
||||
import encoding.TLV;
|
||||
import encoding.VlIntException;
|
||||
import jnr.unixsocket.UnixSocketAddress;
|
||||
@@ -25,6 +22,9 @@ import java.nio.channels.SocketChannel;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class LogicFace {
|
||||
// 定量区
|
||||
public final int DefaultMtuSize = 9000; // 缺省MTU为 9000 字节, 初始化face时会用到
|
||||
|
||||
// LogicFaceType区:LogicFace的类型
|
||||
public static final int LogicFaceTypeTCP = 0;
|
||||
public static final int LogicFaceTypeUDP = 1;
|
||||
@@ -47,18 +47,24 @@ public class LogicFace {
|
||||
* @param port MIR的TCP端口号,如 13899
|
||||
* @return
|
||||
*/
|
||||
public boolean initWithTcp(String ip,String port) throws LogicFaceException {
|
||||
public boolean initWithTcp(String ip,Integer port) throws LogicFaceException {
|
||||
try {
|
||||
// Transport
|
||||
SocketChannel channel=SocketChannel.open();
|
||||
channel.connect(new InetSocketAddress(ip, Integer.parseInt(port)));
|
||||
this.linkService=new LinkService();
|
||||
channel.connect(new InetSocketAddress(ip, port));
|
||||
TcpTransport tcpTransport=new TcpTransport();
|
||||
tcpTransport.init(channel);
|
||||
this.linkService.init(9000); // 设置MTU为 9000 字节
|
||||
|
||||
// LinkService
|
||||
this.linkService=new LinkService();
|
||||
this.linkService.init(DefaultMtuSize);
|
||||
this.linkService.logicFace=this;
|
||||
this.linkService.transport=tcpTransport;
|
||||
|
||||
tcpTransport.linkService=this.linkService;
|
||||
this.transport=tcpTransport;
|
||||
|
||||
// Others
|
||||
this.logicFaceType=LogicFaceTypeTCP;
|
||||
this.keyChain=null;
|
||||
this.state=true;
|
||||
@@ -74,18 +80,24 @@ public class LogicFace {
|
||||
* @param port MIR的TCP端口号,如 13899
|
||||
* @return
|
||||
*/
|
||||
public boolean initWithUdp(String ip,String port) throws LogicFaceException {
|
||||
public boolean initWithUdp(String ip,Integer port) throws LogicFaceException {
|
||||
try {
|
||||
// Transport
|
||||
DatagramChannel channel=DatagramChannel.open();
|
||||
channel.connect(new InetSocketAddress(ip, Integer.parseInt(port)));
|
||||
this.linkService=new LinkService();
|
||||
channel.connect(new InetSocketAddress(ip, port));
|
||||
UdpTransport udpTransport=new UdpTransport();
|
||||
udpTransport.init(channel,new InetSocketAddress(ip, Integer.parseInt(port)));
|
||||
this.linkService.init(9000); // 设置MTU为 9000 字节
|
||||
udpTransport.init(channel,new InetSocketAddress(ip, port));
|
||||
|
||||
// LinkService
|
||||
this.linkService=new LinkService();
|
||||
this.linkService.init(DefaultMtuSize);
|
||||
this.linkService.logicFace=this;
|
||||
this.linkService.transport=udpTransport;
|
||||
|
||||
udpTransport.linkService=this.linkService;
|
||||
this.transport=udpTransport;
|
||||
|
||||
// Others
|
||||
this.keyChain=null;
|
||||
this.logicFaceType=LogicFaceTypeUDP;
|
||||
this.state=true;
|
||||
@@ -97,23 +109,27 @@ public class LogicFace {
|
||||
|
||||
/**
|
||||
* 通过unixSocket连接MIR
|
||||
* 暂时不测
|
||||
* @param path MIR的unix socket地址,默认是 "/tmp/mir-sock"
|
||||
* @return
|
||||
*/
|
||||
public boolean initWithUnixSocket(String path) throws LogicFaceException {
|
||||
private boolean initWithUnixSocket(String path) throws LogicFaceException {
|
||||
try {
|
||||
// 建立 Unix Socket 连接
|
||||
File unixFile = new File(path);
|
||||
UnixSocketChannel channel=UnixSocketChannel.open();
|
||||
channel.connect(new UnixSocketAddress(unixFile));
|
||||
this.linkService=new LinkService();
|
||||
UnixStreamTransport unixStreamTransport=new UnixStreamTransport();
|
||||
unixStreamTransport.init(channel);
|
||||
this.linkService.init(9000); // 设置MTU为 9000 字节
|
||||
|
||||
this.linkService=new LinkService();
|
||||
this.linkService.init(DefaultMtuSize);
|
||||
this.linkService.logicFace=this;
|
||||
this.linkService.transport=unixStreamTransport;
|
||||
|
||||
unixStreamTransport.linkService=this.linkService;
|
||||
this.transport=unixStreamTransport;
|
||||
|
||||
this.keyChain=null;
|
||||
this.logicFaceType=LogicFaceTypeUnix;
|
||||
this.state=true;
|
||||
|
||||
Reference in new issue
Block a user