use of javax.sip.address.SipURI in project load-balancer by RestComm.
the class CustomHeartbeatTest method testCustomHeartbeat.
@Test
public void testCustomHeartbeat() throws Exception {
EventListener failureEventListener = new EventListener() {
@Override
public void uasAfterResponse(int statusCode, AppServer source) {
}
@Override
public void uasAfterRequestReceived(String method, AppServer source) {
// TODO Auto-generated method stub
}
@Override
public void uacAfterRequestSent(String method, AppServer source) {
// TODO Auto-generated method stub
}
@Override
public void uacAfterResponse(int statusCode, AppServer source) {
if (statusCode == 180) {
ringingAppServer = source;
} else {
okAppServer = source;
}
}
};
for (AppServer as : servers) as.setEventListener(failureEventListener);
shootist.callerSendsBye = true;
String fromName = "sender";
String fromHost = "sip-servlets.com";
SipURI fromAddress = servers[0].protocolObjects.addressFactory.createSipURI(fromName, fromHost);
String toUser = "replaces";
String toHost = "sip-servlets.com";
SipURI toAddress = servers[0].protocolObjects.addressFactory.createSipURI(toUser, toHost);
SipURI ruri = servers[0].protocolObjects.addressFactory.createSipURI("usera", "127.0.0.1:5033");
ruri.setLrParam();
SipURI route = servers[0].protocolObjects.addressFactory.createSipURI("lbaddress_InternalPort", "127.0.0.1:5065");
route.setParameter("node_host", "127.0.0.1");
route.setParameter("node_port", "4060");
route.setLrParam();
shootist.start();
// servers[0].sipListener.sendSipRequest("INVITE", fromAddress, toAddress, null, null, false);
// servers[0].sendHeartbeat = false;
// servers[1].sendHeartbeat = false;
servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
Thread.sleep(4000);
servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
Thread.sleep(4000);
servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
Thread.sleep(4000);
servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
Thread.sleep(4000);
servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
List<Node> list = balancer.getNodes();
Node node = list.get(0);
assertEquals(node.getHostName(), "sipHeartbeat");
assertEquals(1, list.size());
}
use of javax.sip.address.SipURI in project load-balancer by RestComm.
the class IncorrectAddRecivedInResponseTest method testOKRingingLandOnDifferentNodes.
@Test
public void testOKRingingLandOnDifferentNodes() throws Exception {
EventListener failureEventListener = new EventListener() {
@Override
public void uasAfterResponse(int statusCode, AppServer source) {
}
@Override
public void uasAfterRequestReceived(String method, AppServer source) {
}
@Override
public void uacAfterRequestSent(String method, AppServer source) {
}
@Override
public void uacAfterResponse(int statusCode, AppServer source) {
if (statusCode == 180) {
ringingAppServer = source;
} else if (statusCode == 200) {
okAppServer = source;
}
}
};
for (AppServer as : servers) as.setEventListener(failureEventListener);
shootist.callerSendsBye = true;
String fromName = "senderToNexmo";
String fromHost = "sip-servlets.com";
SipURI fromAddress = servers[0].protocolObjects.addressFactory.createSipURI(fromName, fromHost);
String toUser = "replaces";
String toHost = "sip-servlets.com";
SipURI toAddress = servers[0].protocolObjects.addressFactory.createSipURI(toUser, toHost);
SipURI ruri = servers[0].protocolObjects.addressFactory.createSipURI("usera", "127.0.0.1:5033");
ruri.setLrParam();
SipURI route = servers[0].protocolObjects.addressFactory.createSipURI("lbint", "127.0.0.1:5065");
route.setParameter("node_host", "127.0.0.1");
route.setParameter("node_port", "4060");
route.setTransportParam(ListeningPoint.TCP);
route.setLrParam();
shootist.start();
servers[0].sipListener.sendSipRequest(SIPRequest.INVITE, fromAddress, toAddress, null, route, false, null, null, ruri);
Thread.sleep(16000);
assertTrue(shootist.inviteRequest.getHeader(RecordRouteHeader.NAME).toString().contains("node_host"));
assertSame(servers[0], ringingAppServer);
assertSame(ringingAppServer, okAppServer);
assertNotNull(ringingAppServer);
assertNotNull(okAppServer);
}
use of javax.sip.address.SipURI in project load-balancer by RestComm.
the class Shootist method processInvite.
public void processInvite(Request request, ServerTransaction stx) {
try {
inviteRequest = request;
Response response = messageFactory.createResponse(180, request);
contactHeader = headerFactory.createContactHeader(addressFactory.createAddress("sip:here@" + localIPAddress + ":" + localPort));
response.addHeader(contactHeader);
dialog = stx.getDialog();
// check removing incorrect patching last via https://github.com/RestComm/load-balancer/issues/97
FromHeader fromHeader = (FromHeader) response.getHeader(From.NAME);
URI currUri = fromHeader.getAddress().getURI();
String fromUser = null;
if (currUri.isSipURI()) {
fromUser = ((SipURI) currUri).getUser();
if (fromUser.equals("senderToNexmo")) {
ViaHeader lastViaHeader = null;
ListIterator<ViaHeader> it = response.getHeaders(ViaHeader.NAME);
while (it.hasNext()) lastViaHeader = it.next();
lastViaHeader.setReceived("127.0.0.2");
lastViaHeader.setParameter("rport", "1111");
}
}
stx.sendResponse(response);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response = messageFactory.createResponse(200, request);
contactHeader = headerFactory.createContactHeader(addressFactory.createAddress("sip:here@" + localIPAddress + ":" + localPort));
response.addHeader(contactHeader);
dialog = stx.getDialog();
stx.sendResponse(response);
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of javax.sip.address.SipURI in project load-balancer by RestComm.
the class Shootist method sendInitialInvite.
public void sendInitialInvite() {
try {
if (!started)
start();
String fromName = "BigGuy";
String fromSipAddress = "here.com";
String fromDisplayName = "The Master Blaster";
String toSipAddress = "there.com";
String toUser = "LittleGuy";
String toDisplayName = "The Little Blister";
// create >From Header
SipURI fromAddress = addressFactory.createSipURI(fromName, fromSipAddress);
Address fromNameAddress = addressFactory.createAddress(fromAddress);
fromNameAddress.setDisplayName(fromDisplayName);
FromHeader fromHeader = headerFactory.createFromHeader(fromNameAddress, "12345");
// create To Header
SipURI toAddress = addressFactory.createSipURI(toUser, toSipAddress);
Address toNameAddress = addressFactory.createAddress(toAddress);
toNameAddress.setDisplayName(toDisplayName);
ToHeader toHeader = headerFactory.createToHeader(toNameAddress, null);
// create Request URI
SipURI requestURI = addressFactory.createSipURI(toUser, peerHostPort);
// Create ViaHeaders
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
String ipAddress = udpListeningPoint.getIPAddress();
ViaHeader viaHeader = headerFactory.createViaHeader(ipAddress, sipProvider.getListeningPoint(transport).getPort(), transport, null);
// add via headers
viaHeaders.add(viaHeader);
// Create ContentTypeHeader
ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "sdp");
// Create a new CallId header
CallIdHeader callIdHeader = sipProvider.getNewCallId();
// Create a new Cseq header
CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(1L, Request.INVITE);
// Create a new MaxForwardsHeader
MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70);
// Create the request.
Request request = messageFactory.createRequest(requestURI, Request.INVITE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
// Create contact headers
String host = "127.0.0.1";
SipURI contactUrl = addressFactory.createSipURI(fromName, host);
contactUrl.setPort(udpListeningPoint.getPort());
contactUrl.setLrParam();
// Create the contact name address.
SipURI contactURI = addressFactory.createSipURI(fromName, host);
contactURI.setPort(sipProvider.getListeningPoint(transport).getPort());
Address contactAddress = addressFactory.createAddress(contactURI);
// Add the contact address.
contactAddress.setDisplayName(fromName);
contactHeader = headerFactory.createContactHeader(contactAddress);
request.addHeader(contactHeader);
// You can add extension headers of your own making
// to the outgoing SIP request.
// Add the extension header.
Header extensionHeader = headerFactory.createHeader("My-Header", "my header value");
request.addHeader(extensionHeader);
String sdpData = "v=0\r\n" + "o=4855 13760799956958020 13760799956958020" + " IN IP4 129.6.55.78\r\n" + "s=mysession session\r\n" + "p=+46 8 52018010\r\n" + "c=IN IP4 129.6.55.78\r\n" + "t=0 0\r\n" + "m=audio 6022 RTP/AVP 0 4 18\r\n" + "a=rtpmap:0 PCMU/8000\r\n" + "a=rtpmap:4 G723/8000\r\n" + "a=rtpmap:18 G729A/8000\r\n" + "a=ptime:20\r\n";
byte[] contents = sdpData.getBytes();
request.setContent(contents, contentTypeHeader);
// You can add as many extension headers as you
// want.
extensionHeader = headerFactory.createHeader("My-Other-Header", "my new header value ");
request.addHeader(extensionHeader);
Header callInfoHeader = headerFactory.createHeader("Call-Info", "<http://www.antd.nist.gov>");
request.addHeader(callInfoHeader);
// Create the client transaction.
inviteTid = sipProvider.getNewClientTransaction(request);
// send the request out.
inviteTid.sendRequest();
dialog = inviteTid.getDialog();
} catch (Exception ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
fail("Unxpected exception ");
}
}
use of javax.sip.address.SipURI in project load-balancer by RestComm.
the class SprayingLoadBalancersWithIPLBAddressInViaHeader method testASactingAsUAC.
@Test
public void testASactingAsUAC() throws Exception {
EventListener failureEventListener = new EventListener() {
@Override
public void uasAfterResponse(int statusCode, AppServer source) {
}
@Override
public void uasAfterRequestReceived(String method, AppServer source) {
// TODO Auto-generated method stub
}
@Override
public void uacAfterRequestSent(String method, AppServer source) {
// TODO Auto-generated method stub
}
@Override
public void uacAfterResponse(int statusCode, AppServer source) {
if (statusCode == 180) {
ringingAppServer = source;
// i guess should send stop
// source.sendCleanShutdownToBalancers();
source.stop();
} else if (statusCode == 200) {
okAppServer = source;
}
}
};
for (AppServer as : servers) as.setEventListener(failureEventListener);
shootist.callerSendsBye = true;
String fromName = "sender";
String fromHost = "sip-servlets.com";
SipURI fromAddress = servers[0].protocolObjects.addressFactory.createSipURI(fromName, fromHost);
String toUser = "replaces";
String toHost = "sip-servlets.com";
SipURI toAddress = servers[0].protocolObjects.addressFactory.createSipURI(toUser, toHost);
SipURI ruri = servers[0].protocolObjects.addressFactory.createSipURI("usera", "127.0.0.1:5033");
ruri.setLrParam();
SipURI route = servers[0].protocolObjects.addressFactory.createSipURI("lbaddress_noInternalPort", "127.0.0.1:5065");
route.setParameter("node_host", "127.0.0.1");
route.setParameter("node_port", "4060");
route.setLrParam();
shootist.start();
// servers[0].sipListener.sendSipRequest("INVITE", fromAddress, toAddress, null, null, false);
servers[0].sipListener.sendSipRequest("INVITE", fromAddress, toAddress, null, route, false, null, null, ruri);
Thread.sleep(16000);
assertTrue(shootist.inviteRequest.getHeader(RecordRouteHeader.NAME).toString().contains("node_host"));
assertNotSame(ringingAppServer, okAppServer);
assertNotNull(ringingAppServer);
assertNotNull(okAppServer);
}
Aggregations