Search in sources :

Example 51 with SipURI

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());
}
Also used : AppServer(org.mobicents.tools.sip.balancer.AppServer) Node(org.mobicents.tools.heartbeat.api.Node) EventListener(org.mobicents.tools.sip.balancer.EventListener) SipURI(javax.sip.address.SipURI) Test(org.junit.Test)

Example 52 with SipURI

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);
}
Also used : AppServer(org.mobicents.tools.sip.balancer.AppServer) EventListener(org.mobicents.tools.sip.balancer.EventListener) SipURI(javax.sip.address.SipURI) Test(org.junit.Test)

Example 53 with SipURI

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();
    }
}
Also used : Response(javax.sip.message.Response) InvalidArgumentException(javax.sip.InvalidArgumentException) ViaHeader(javax.sip.header.ViaHeader) FromHeader(javax.sip.header.FromHeader) ParseException(java.text.ParseException) SipException(javax.sip.SipException) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI)

Example 54 with SipURI

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 ");
    }
}
Also used : MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) Address(javax.sip.address.Address) FromHeader(javax.sip.header.FromHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) ArrayList(java.util.ArrayList) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI) TransactionAlreadyExistsException(javax.sip.TransactionAlreadyExistsException) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) PeerUnavailableException(javax.sip.PeerUnavailableException) SipException(javax.sip.SipException) TransactionUnavailableException(javax.sip.TransactionUnavailableException) CSeqHeader(javax.sip.header.CSeqHeader) CSeqHeader(javax.sip.header.CSeqHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) ContactHeader(javax.sip.header.ContactHeader) ToHeader(javax.sip.header.ToHeader) FromHeader(javax.sip.header.FromHeader) ViaHeader(javax.sip.header.ViaHeader) CallIdHeader(javax.sip.header.CallIdHeader) Header(javax.sip.header.Header) ViaHeader(javax.sip.header.ViaHeader) ToHeader(javax.sip.header.ToHeader) CallIdHeader(javax.sip.header.CallIdHeader)

Example 55 with SipURI

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);
}
Also used : AppServer(org.mobicents.tools.sip.balancer.AppServer) EventListener(org.mobicents.tools.sip.balancer.EventListener) SipURI(javax.sip.address.SipURI) Test(org.junit.Test)

Aggregations

SipURI (javax.sip.address.SipURI)70 ParseException (java.text.ParseException)27 Request (javax.sip.message.Request)24 Address (javax.sip.address.Address)22 InvalidArgumentException (javax.sip.InvalidArgumentException)20 ViaHeader (javax.sip.header.ViaHeader)20 SipException (javax.sip.SipException)19 ToHeader (javax.sip.header.ToHeader)18 ContactHeader (javax.sip.header.ContactHeader)17 FromHeader (javax.sip.header.FromHeader)17 Test (org.junit.Test)17 RouteHeader (javax.sip.header.RouteHeader)16 AppServer (org.mobicents.tools.sip.balancer.AppServer)16 EventListener (org.mobicents.tools.sip.balancer.EventListener)16 CSeqHeader (javax.sip.header.CSeqHeader)13 CallIdHeader (javax.sip.header.CallIdHeader)13 Header (javax.sip.header.Header)13 MaxForwardsHeader (javax.sip.header.MaxForwardsHeader)13 RecordRouteHeader (javax.sip.header.RecordRouteHeader)13 URI (javax.sip.address.URI)11