下面列出了io.netty.channel.sctp.nio.NioSctpChannel#org.mobicents.protocols.api.IpChannelType 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void main(String[] args) {
DiameterFirewallPerformanceTests ec = new DiameterFirewallPerformanceTests();
try {
ec.initSCTP(IpChannelType.SCTP);
ec.start();
while (!ec.finished()) {
try {
Thread.currentThread().sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (Exception ex) {
java.util.logging.Logger.getLogger(DiameterFirewallPerformanceTests.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void setUp(IpChannelType ipChannelType) throws Exception {
this.clientAssocUp = false;
this.serverAssocUp = false;
this.clientAssocDown = false;
this.serverAssocDown = false;
// this.clientMessage = null;
// this.serverMessage = null;
this.management = new ManagementImpl("server-management");
this.management.setSingleThread(true);
this.management.start();
this.management.setConnectDelay(5000);// Try connecting every 5 secs
this.management.removeAllResourses();
this.server = this.management.addServer(SERVER_NAME, SERVER_HOST, SERVER_PORT, ipChannelType, false, 0, null);
this.serverAssociation = this.management.addServerAssociation(CLIENT_HOST, CLIENT_PORT, SERVER_NAME, SERVER_ASSOCIATION_NAME, ipChannelType);
this.clientAssociation = this.management.addAssociation(CLIENT_HOST, CLIENT_PORT, SERVER_HOST, SERVER_PORT, CLIENT_ASSOCIATION_NAME, ipChannelType,
null);
}
public void setUp(IpChannelType ipChannelType) throws Exception {
this.clientMaxInboundStreams = 0;
this.serverMaxOutboundStreams = 0;
this.clientAssocUp = false;
this.serverAssocUp = false;
this.clientAssocDown = false;
this.serverAssocDown = false;
this.clientMessage = null;
this.serverMessage = null;
this.management = new ManagementImpl("server-management");
this.management.setSingleThread(true);
this.management.start();
this.management.setConnectDelay(10000);// Try connecting every 10 secs
this.management.removeAllResourses();
this.server = this.management.addServer(SERVER_NAME, SERVER_HOST, SERVER_PORT, ipChannelType, false, 0, null);
this.serverAssociation = this.management.addServerAssociation(CLIENT_HOST, CLIENT_PORT, SERVER_NAME, SERVER_ASSOCIATION_NAME, ipChannelType);
this.clientAssociation = this.management.addAssociation(CLIENT_HOST, CLIENT_PORT, SERVER_HOST, SERVER_PORT, CLIENT_ASSOCIATION_NAME, ipChannelType,
null);
}
private void initSCTP(IpChannelType ipChannelType) throws Exception {
logger.debug("Initializing SCTP Stack ....");
this.sctpManagement = new ManagementImpl("SctpClientSCTP");
this.sctpManagement.setPersistDir(persistDir);
this.sctpManagement.setSingleThread(false);
this.sctpManagement.start();
this.sctpManagement.setConnectDelay(10000);
this.sctpManagement.setMaxIOErrors(30);
this.sctpManagement.removeAllResourses();
this.sctpManagement.addManagementEventListener(this);
// 1. Create SCTP Association
sctpManagement.addAssociation(CLIENT_IP, CLIENT_PORT, SERVER_IP, /*SERVER_PORT*/3433, CLIENT_ASSOCIATION_NAME,
ipChannelType, null);
logger.debug("Initialized SCTP Stack ....");
}
protected void initializeStack(IpChannelType ipChannelType) throws Exception {
this.initSCTP(ipChannelType);
// Initialize M3UA first
this.initM3UA();
// Initialize SCCP
this.initSCCP();
// Initialize TCAP
this.initTCAP();
// Initialize MAP
this.initMAP();
// FInally start ASP
// Set 5: Finally start ASP
this.serverM3UAMgmt.startAsp("SASP1");
}
private void initSCTP(IpChannelType ipChannelType) throws Exception {
logger.debug("Initializing SCTP Stack ....");
this.sctpManagement = new ManagementImpl("Server");
this.sctpManagement.setSingleThread(true);
this.sctpManagement.start();
this.sctpManagement.setConnectDelay(10000);
this.sctpManagement.removeAllResourses();
//1. Create SCTP Server
sctpManagement.addServer(SERVER_NAME, SERVER_IP,SERVER_PORT, ipChannelType,null);
// 2. Create SCTP Association
sctpManagement.addServerAssociation(CLIENT_IP, CLIENT_PORT, SERVER_NAME,SERVER_ASSOCIATION_NAME,ipChannelType);
//3. Start Sever
sctpManagement.startServer(SERVER_NAME);
logger.debug("Initialized SCTP Stack ....");
}
public void setUp(IpChannelType ipChannelType) throws Exception {
this.clientAssocUp = false;
this.serverAssocUp = false;
this.clientAssocDown = false;
this.serverAssocDown = false;
this.management = new NettySctpManagementImpl("server-management");
// this.management.setSingleThread(true);
this.management.start();
this.management.setConnectDelay(5000);// Try connecting every 5 secs
this.management.removeAllResourses();
this.server = (NettyServerImpl) this.management.addServer(SERVER_NAME, SERVER_HOST, SERVER_PORT, ipChannelType, false,
0, null);
this.serverAssociation = (NettyAssociationImpl) this.management.addServerAssociation(CLIENT_HOST, CLIENT_PORT,
SERVER_NAME, SERVER_ASSOCIATION_NAME, ipChannelType);
this.clientAssociation = (NettyAssociationImpl) this.management.addAssociation(CLIENT_HOST, CLIENT_PORT, SERVER_HOST,
SERVER_PORT, CLIENT_ASSOCIATION_NAME, ipChannelType, null);
}
protected void initializeStack(IpChannelType ipChannelType) throws Exception {
this.initSCTP(ipChannelType);
// Initialize M3UA first
this.initM3UA();
// Initialize SCCP
this.initSCCP();
// Initialize TCAP
this.initTCAP();
// Initialize MAP
this.initMAP();
// FInally start ASP
// Set 5: Finally start ASP
this.serverM3UAMgmt.startAsp("SASP1");
}
public void setUp(IpChannelType ipChannelType) throws Exception {
this.clientAssocUp = false;
this.serverAssocUp = false;
this.clientAssocDown = false;
this.serverAssocDown = false;
this.clientMessage = new FastList<String>();
this.serverMessage = new FastList<String>();
this.management = new NettySctpManagementImpl("server-management");
// this.management.setSingleThread(true);
this.management.start();
this.management.setConnectDelay(10000);// Try connecting every 10 secs
this.management.removeAllResourses();
this.server = (NettyServerImpl) this.management.addServer(SERVER_NAME, SERVER_HOST, SERVER_PORT, ipChannelType, false,
0, new String[] { SERVER_HOST1 });
this.serverAssociation = (NettyAssociationImpl) this.management.addServerAssociation(CLIENT_HOST, CLIENT_PORT,
SERVER_NAME, SERVER_ASSOCIATION_NAME, ipChannelType);
this.clientAssociation = (NettyAssociationImpl) this.management.addAssociation(CLIENT_HOST, CLIENT_PORT, SERVER_HOST,
SERVER_PORT, CLIENT_ASSOCIATION_NAME, ipChannelType, new String[] { CLIENT_HOST1 });
}
private void initSCTP(IpChannelType ipChannelType) throws Exception {
logger.debug("Initializing SCTP Stack ....");
this.sctpManagement = new ManagementImpl("Server");
this.sctpManagement.setSingleThread(true);
this.sctpManagement.start();
this.sctpManagement.setConnectDelay(10000);
this.sctpManagement.removeAllResourses();
//1. Create SCTP Server
sctpManagement.addServer(SERVER_NAME, SERVER_IP,SERVER_PORT, ipChannelType,null);
// 2. Create SCTP Association
sctpManagement.addServerAssociation(CLIENT_IP, CLIENT_PORT, SERVER_NAME,SERVER_ASSOCIATION_NAME,ipChannelType);
//3. Start Sever
sctpManagement.startServer(SERVER_NAME);
logger.debug("Initialized SCTP Stack ....");
}
protected void initializeStack(IpChannelType ipChannelType) throws Exception {
this.initSCTP(ipChannelType);
// Initialize M3UA first
this.initM3UA();
// Initialize SCCP
this.initSCCP();
// Initialize TCAP
this.initTCAP();
// Initialize MAP
this.initMAP();
// FInally start ASP
// Set 5: Finally start ASP
this.serverM3UAMgmt.startAsp("SASP1");
}
public static void main(String args[]) {
System.out.println("*********************************************");
System.out.println("*** IMSI Information - HLR ***");
System.out.println("*********************************************");
IpChannelType ipChannelType = IpChannelType.SCTP;
final SendIMSIResp victim = new SendIMSIResp();
logger.setLevel(org.apache.log4j.Level.DEBUG);
try {
victim.initializeStack(ipChannelType);
// Lets pause for 20 seconds so stacks are initialized properly
Thread.sleep(20000);
} catch (Exception e) {
e.printStackTrace();
}
}
private void initSCTP(IpChannelType ipChannelType) throws Exception {
logger.debug("Initializing SCTP Stack ....");
this.sctpManagement = new ManagementImpl("Server");
this.sctpManagement.setSingleThread(true);
this.sctpManagement.start();
this.sctpManagement.setConnectDelay(10000);
this.sctpManagement.removeAllResourses();
//1. Create SCTP Server
sctpManagement.addServer(SERVER_NAME, SERVER_IP,SERVER_PORT, ipChannelType,null);
// 2. Create SCTP Association
sctpManagement.addServerAssociation(CLIENT_IP, CLIENT_PORT, SERVER_NAME,SERVER_ASSOCIATION_NAME,ipChannelType);
//3. Start Sever
sctpManagement.startServer(SERVER_NAME);
logger.debug("Initialized SCTP Stack ....");
}
private void initSCTP(IpChannelType ipChannelType) throws Exception {
this.sctpManagement = new NettySctpManagementImpl("Server");
// this.sctpManagement.setSingleThread(false);
this.sctpManagement.start();
this.sctpManagement.setConnectDelay(10000);
this.sctpManagement.removeAllResourses();
// 1. Create SCTP Server
sctpManagement.addServer(SERVER_NAME, SERVER_IP, SERVER_PORT, ipChannelType, null);
// 2. Create SCTP Server Association
sctpManagement.addServerAssociation(CLIENT_IP, CLIENT_PORT, SERVER_NAME, SERVER_ASSOCIATION_NAME, ipChannelType);
// 3. Start Server
sctpManagement.startServer(SERVER_NAME);
}
public void setUp(IpChannelType ipChannelType, int serverPort, int clientPort) throws Exception {
this.clientAssocUp = false;
this.serverAssocUp = false;
this.clientAssocDown = false;
this.serverAssocDown = false;
this.clientMessage = null;
this.serverMessage = null;
this.management = new NettySctpManagementImpl("ClientAssociationTest");
this.management.setSingleThread(true);
this.management.start();
this.management.setConnectDelay(1000);
this.management.removeAllResourses();
this.server = (NettyServerImpl) this.management.addServer(SERVER_NAME, SERVER_HOST, serverPort, ipChannelType, false, 0, null);
this.serverAssociation = (NettyAssociationImpl) this.management.addServerAssociation(CLIENT_HOST, clientPort, SERVER_NAME, SERVER_ASSOCIATION_NAME, ipChannelType);
this.clientAssociation = (NettyAssociationImpl) this.management.addAssociation(CLIENT_HOST, clientPort, SERVER_HOST, serverPort, CLIENT_ASSOCIATION_NAME, ipChannelType, null);
}
public void setUp(IpChannelType ipChannelType, int serverPort, int clientPort) throws Exception {
this.clientAssocUp = false;
this.serverAssocUp = false;
this.clientAssocDown = false;
this.serverAssocDown = false;
this.clientMessage = null;
this.serverMessage = null;
this.management = new ManagementImpl("ClientAssociationTest");
this.management.setSingleThread(true);
this.management.start();
this.management.setConnectDelay(1000);
this.management.removeAllResourses();
this.server = this.management.addServer(SERVER_NAME, SERVER_HOST, serverPort, ipChannelType, false, 0, null);
this.serverAssociation = this.management.addServerAssociation(CLIENT_HOST, clientPort, SERVER_NAME, SERVER_ASSOCIATION_NAME, ipChannelType);
this.clientAssociation = this.management.addAssociation(CLIENT_HOST, clientPort, SERVER_HOST, serverPort, CLIENT_ASSOCIATION_NAME, ipChannelType, null);
}
@SuppressWarnings("unchecked")
@Override
public void read(javolution.xml.XMLFormat.InputElement xml, ServerImpl server) throws XMLStreamException {
server.name = xml.getAttribute(NAME, "");
server.started = xml.getAttribute(STARTED, false);
server.hostAddress = xml.getAttribute(HOST_ADDRESS, "");
server.hostport = xml.getAttribute(HOST_PORT, 0);
server.ipChannelType = IpChannelType.getInstance(xml.getAttribute(IPCHANNEL_TYPE,
IpChannelType.SCTP.getCode()));
if (server.ipChannelType == null)
throw new XMLStreamException("Bad value for server.ipChannelType");
server.acceptAnonymousConnections = xml.getAttribute(ACCEPT_ANONYMOUS_CONNECTIONS, false);
server.maxConcurrentConnectionsCount = xml.getAttribute(MAX_CONCURRENT_CONNECTIONS_COUNT, 0);
int extraHostAddressesSize = xml.getAttribute(EXTRA_HOST_ADDRESS_SIZE, 0);
server.extraHostAddresses = new String[extraHostAddressesSize];
for(int i=0;i<extraHostAddressesSize;i++){
server.extraHostAddresses[i] = xml.get(EXTRA_HOST_ADDRESS, String.class);
}
server.associations = xml.get(ASSOCIATIONS, FastList.class);
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("channelActive event: association=%s", this.association));
}
this.ctx = ctx;
this.channel = ctx.channel();
this.association.setChannelHandler(this);
String host = null;
int port = 0;
InetSocketAddress sockAdd = ((InetSocketAddress) channel.remoteAddress());
if (sockAdd != null) {
host = sockAdd.getAddress().getHostAddress();
port = sockAdd.getPort();
}
if (logger.isInfoEnabled()) {
logger.info(String.format("Association=%s connected to host=%s port=%d", association.getName(), host, port));
}
if (association.getIpChannelType() == IpChannelType.TCP) {
this.association.markAssociationUp(1, 1);
}
}
private void testStopAssociationByProtocol(IpChannelType ipChannelType) throws Exception {
ManagementImpl management = new ManagementImpl("ManagementTest");
management.setSingleThread(true);
management.start();
management.setConnectDelay(10000);// Try connecting every 10 secs
management.removeAllResourses();
management.addServer(SERVER_NAME, SERVER_HOST, SERVER_PORT, ipChannelType, false, 0, null);
Association serverAssociation = management.addServerAssociation(CLIENT_HOST, CLIENT_PORT, SERVER_NAME, SERVER_ASSOCIATION_NAME, ipChannelType);
Association clientAssociation = management.addAssociation(CLIENT_HOST, CLIENT_PORT, SERVER_HOST, SERVER_PORT, CLIENT_ASSOCIATION_NAME, ipChannelType, null);
management.startServer(SERVER_NAME);
serverAssociation.setAssociationListener(new ServerAssociationListener());
management.startAssociation(SERVER_ASSOCIATION_NAME);
clientAssociation.setAssociationListener(new ClientAssociationListener());
management.startAssociation(CLIENT_ASSOCIATION_NAME);
for (int i1 = 0; i1 < 40; i1++) {
if (serverAssociation.isConnected())
break;
Thread.sleep(1000 * 5);
}
Thread.sleep(1000 * 1);
assertTrue(serverAssociation.isConnected());
assertTrue(clientAssociation.isConnected());
management.stop();
assertFalse(serverAssociation.isConnected());
assertFalse(clientAssociation.isConnected());
}
public void setUp(IpChannelType ipChannelType) throws Exception {
this.management = new NettySctpManagementImpl("server-management");
// this.management.setSingleThread(true);
this.management.start();
this.management.setConnectDelay(CONNECT_DELAY);// Try connecting every x secs
this.management.removeAllResourses();
this.management2 = new NettySctpManagementImpl("server-management2");
// this.management2.setSingleThread(true);
this.management2.start();
this.management2.setConnectDelay(CONNECT_DELAY);// Try connecting every x secs
this.management2.removeAllResourses();
this.management3 = new NettySctpManagementImpl("server-management3");
// this.management3.setSingleThread(true);
this.management3.start();
this.management3.setConnectDelay(CONNECT_DELAY);// Try connecting every x secs
this.management3.removeAllResourses();
this.server = (NettyServerImpl) this.management.addServer(SERVER_NAME, SERVER_HOST, SERVER_PORT, ipChannelType, true,
2, null);
this.clientAssociation1 = (NettyAssociationImpl) this.management.addAssociation(CLIENT_HOST, CLIENT_PORT1, SERVER_HOST,
SERVER_PORT, CLIENT_ASSOCIATION_NAME1, ipChannelType, null);
this.clientAssociation2 = (NettyAssociationImpl) this.management2.addAssociation(CLIENT_HOST, CLIENT_PORT2,
SERVER_HOST, SERVER_PORT, CLIENT_ASSOCIATION_NAME2, ipChannelType, null);
this.clientAssociation3 = (NettyAssociationImpl) this.management3.addAssociation(CLIENT_HOST, CLIENT_PORT3,
SERVER_HOST, SERVER_PORT, CLIENT_ASSOCIATION_NAME3, ipChannelType, null);
}
/**
* Simple test that creates Client and Server Association, exchanges data
* and brings down association. Finally removes the Associations and Server
*/
@Test(groups = { "functional", "sctp" })
public void testAnonymousSctp() throws Exception {
if (SctpTransferTest.checkSctpEnabled())
this.testAnonymousByProtocol(IpChannelType.SCTP);
}
/**
* Simple test that creates Client and Server Association, exchanges data
* and brings down association. Finally removes the Associations and Server
*/
@Test(groups = { "functional", "tcp" })
public void testDataTransferTcp() throws Exception {
// BasicConfigurator.configure();
// Logger logger = Logger.getLogger(ServerImpl.class.getName());
// logger.setLevel(Level.ALL);
this.testDataTransferByProtocol(IpChannelType.TCP);
}
/**
* Simple test that creates Client and Server Association, exchanges data
* and brings down association. Finally removes the Associations and Server
*/
@Test(groups = { "functional", "tcp" })
public void testAnonymousTcp() throws Exception {
// BasicConfigurator.configure();
// Logger logger = Logger.getLogger(ServerImpl.class.getName());
// logger.setLevel(Level.ALL);
this.testAnonymousByProtocol(IpChannelType.TCP);
}
/**
* Creating a CLIENT Association
*
* @param hostAddress
* @param hostPort
* @param peerAddress
* @param peerPort
* @param assocName
* @param ipChannelType
* @param extraHostAddresses
* @throws IOException
*/
public NettyAssociationImpl(String hostAddress, int hostPort, String peerAddress, int peerPort, String assocName,
IpChannelType ipChannelType, String[] extraHostAddresses) throws IOException {
this();
this.hostAddress = hostAddress;
this.hostPort = hostPort;
this.peerAddress = peerAddress;
this.peerPort = peerPort;
this.name = assocName;
this.ipChannelType = ipChannelType;
this.extraHostAddresses = extraHostAddresses;
this.type = AssociationType.CLIENT;
}
private void initSCTP(IpChannelType ipChannelType) throws Exception {
this.sctpManagement = new NettySctpManagementImpl("Client");
// this.sctpManagement.setSingleThread(false);
this.sctpManagement.start();
this.sctpManagement.setConnectDelay(10000);
this.sctpManagement.removeAllResourses();
// 1. Create SCTP Association
sctpManagement.addAssociation(CLIENT_IP, CLIENT_PORT, SERVER_IP, SERVER_PORT, CLIENT_ASSOCIATION_NAME, ipChannelType,
null);
}
/**
* Test the creation of Server. Stop management and start, and Server should
* be started automatically
*
* @throws Exception
*/
@Test(groups = { "functional", "sctp" })
public void testServerSctp() throws Exception {
if (SctpTransferTest.checkSctpEnabled())
this.testServerByProtocol(IpChannelType.SCTP);
}
public void setUp(IpChannelType ipChannelType) throws Exception {
this.management = new ManagementImpl("server-management");
this.management.setSingleThread(true);
this.management.start();
this.management.setConnectDelay(CONNECT_DELAY);// Try connecting every x secs
this.management.removeAllResourses();
this.management2 = new ManagementImpl("server-management2");
this.management2.setSingleThread(true);
this.management2.start();
this.management2.setConnectDelay(CONNECT_DELAY);// Try connecting every x secs
this.management2.removeAllResourses();
this.management3 = new ManagementImpl("server-management3");
this.management3.setSingleThread(true);
this.management3.start();
this.management3.setConnectDelay(CONNECT_DELAY);// Try connecting every x secs
this.management3.removeAllResourses();
this.server = this.management.addServer(SERVER_NAME, SERVER_HOST, SERVER_PORT, ipChannelType, true, 2, null);
this.clientAssociation1 = this.management.addAssociation(CLIENT_HOST, CLIENT_PORT1, SERVER_HOST, SERVER_PORT, CLIENT_ASSOCIATION_NAME1, ipChannelType,
null);
this.clientAssociation2 = this.management2.addAssociation(CLIENT_HOST, CLIENT_PORT2, SERVER_HOST, SERVER_PORT, CLIENT_ASSOCIATION_NAME2, ipChannelType,
null);
this.clientAssociation3 = this.management3.addAssociation(CLIENT_HOST, CLIENT_PORT3, SERVER_HOST, SERVER_PORT, CLIENT_ASSOCIATION_NAME3, ipChannelType,
null);
}
private void finishConnection(SelectionKey key) throws IOException{
AssociationImpl association = (AssociationImpl) key.attachment();
if (association.getIpChannelType() == IpChannelType.SCTP)
this.finishConnectionSctp(key);
else
this.finishConnectionTcp(key);
}
/**
* Simple test that creates Client and Server Association, exchanges data
* and brings down association. Finally removes the Associations and Server
*/
@Test(groups = { "functional", "sctp" })
public void testDataTransferSctp() throws Exception {
if (SctpTransferTest.checkSctpEnabled())
this.testDataTransferByProtocol(IpChannelType.SCTP);
}
/**
* @param name
* @param ip
* @param port
* @throws IOException
*/
public ServerImpl(String name, String hostAddress, int hostport, IpChannelType ipChannelType, boolean acceptAnonymousConnections,
int maxConcurrentConnectionsCount, String[] extraHostAddresses) throws IOException {
super();
this.name = name;
this.hostAddress = hostAddress;
this.hostport = hostport;
this.ipChannelType = ipChannelType;
this.acceptAnonymousConnections = acceptAnonymousConnections;
this.maxConcurrentConnectionsCount = maxConcurrentConnectionsCount;
this.extraHostAddresses = extraHostAddresses;
}