Search in sources :

Example 16 with AppServer

use of org.mobicents.tools.sip.balancer.AppServer in project load-balancer by RestComm.

the class RegisterWithNexmoPropertyTest method setUp.

@Before
public void setUp() throws Exception {
    shootist = new Shootist(ListeningPoint.TCP, 5060);
    balancer = new BalancerRunner();
    LoadBalancerConfiguration lbConfig = new LoadBalancerConfiguration();
    lbConfig.getSipConfiguration().getInternalLegConfiguration().setTcpPort(5065);
    lbConfig.getSipConfiguration().getExternalLegConfiguration().setTcpPort(5060);
    lbConfig.getSipConfiguration().getAlgorithmConfiguration().setAlgorithmClass(UserBasedAlgorithm.class.getCanonicalName());
    lbConfig.getSipConfiguration().getAlgorithmConfiguration().setSipHeaderAffinityKey("From");
    lbConfig.getSipConfiguration().setIsUseWithNexmo(true);
    lbConfig.getSipConfiguration().setSendTrying(false);
    balancer.start(lbConfig);
    for (int q = 0; q < servers.length; q++) {
        servers[q] = new AppServer("node" + q, 4060 + q, "127.0.0.1", 2000, 5060, 5065, "0", ListeningPoint.TCP, 2222 + q);
        servers[q].start();
    }
    Thread.sleep(3000);
}
Also used : AppServer(org.mobicents.tools.sip.balancer.AppServer) BalancerRunner(org.mobicents.tools.sip.balancer.BalancerRunner) LoadBalancerConfiguration(org.mobicents.tools.configuration.LoadBalancerConfiguration) UserBasedAlgorithm(org.mobicents.tools.sip.balancer.UserBasedAlgorithm) Shootist(org.mobicents.tools.sip.balancer.operation.Shootist) ListeningPoint(javax.sip.ListeningPoint) Before(org.junit.Before)

Example 17 with AppServer

use of org.mobicents.tools.sip.balancer.AppServer in project load-balancer by RestComm.

the class RollingUpgradeTest method testCallDoesntGoBackToOriginalButUpgradedNode.

@Test
public void testCallDoesntGoBackToOriginalButUpgradedNode() {
    EventListener failureEventListener = new EventListener() {

        @Override
        public void uasAfterResponse(int statusCode, AppServer source) {
        }

        @Override
        public void uasAfterRequestReceived(String method, AppServer source) {
            if (method.equals("INVITE")) {
                inviteServer = source;
            } else if (method.equals("ACK")) {
                ackServer = source;
                ackServer.stop();
                ackServer.version = "2";
                ackServer.start();
                boolean keepOneOldVersionAlive = true;
                for (AppServer srv : servers) {
                    if (srv != ackServer) {
                        if (keepOneOldVersionAlive && !srv.getNode().getProperties().get("udpPort").toString().endsWith("0")) {
                            // make sure it is not the first one to avoid some errors
                            keepOneOldVersionAlive = false;
                            oldVersionServer = srv;
                            System.out.println("We kept alive " + oldVersionServer);
                        } else {
                            // everyone else move to new version
                            srv.stop();
                            srv.version = "2";
                            srv.start();
                        }
                    }
                }
            } else {
                byeServer = source;
            }
        }

        @Override
        public void uacAfterRequestSent(String method, AppServer source) {
        // TODO Auto-generated method stub
        }

        @Override
        public void uacAfterResponse(int statusCode, AppServer source) {
        }
    };
    for (AppServer as : servers) as.setEventListener(failureEventListener);
    for (BalancerRunner balancer : balancers) {
        balancer.setNodeExpiration(15000);
    }
    shootist.peerHostPort = "127.0.0.1:9988";
    shootist.callerSendsBye = true;
    shootist.sendInitialInvite();
    // servers[0].sendHeartbeat = false;
    Helper.sleep(20000);
    try {
        shootist.sendBye();
    } catch (SipException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Helper.sleep(2000);
    assertEquals(3, externalIpLoadBalancer.sipMessageWithoutRetrans.size());
    assertNotSame(inviteServer, byeServer);
    assertSame(inviteServer, ackServer);
    assertSame(byeServer, oldVersionServer);
    // not same because invite server was upgraded before bye
    assertNotSame(byeServer.version, inviteServer.version);
    // same because not upgraded before ack
    assertEquals(ackServer.version, inviteServer.version);
    assertNotNull(byeServer);
    assertNotNull(ackServer);
}
Also used : AppServer(org.mobicents.tools.sip.balancer.AppServer) BalancerRunner(org.mobicents.tools.sip.balancer.BalancerRunner) EventListener(org.mobicents.tools.sip.balancer.EventListener) SipException(javax.sip.SipException) Test(org.junit.Test)

Example 18 with AppServer

use of org.mobicents.tools.sip.balancer.AppServer in project load-balancer by RestComm.

the class SprayTwoPureConsistentHashTest method testSprayingRoundRobinSIPLBsUASCallConsistentHash.

@Test
public void testSprayingRoundRobinSIPLBsUASCallConsistentHash() throws Exception {
    EventListener failureEventListener = new EventListener() {

        @Override
        public void uasAfterResponse(int statusCode, AppServer source) {
        }

        @Override
        public void uasAfterRequestReceived(String method, AppServer source) {
            if (method.equals("INVITE")) {
                inviteServer = source;
            } else if (method.equals("ACK")) {
                ackServer = source;
            } else {
                byeServer = source;
            }
        }

        @Override
        public void uacAfterRequestSent(String method, AppServer source) {
        // TODO Auto-generated method stub
        }

        @Override
        public void uacAfterResponse(int statusCode, AppServer source) {
        }
    };
    for (AppServer as : servers) as.setEventListener(failureEventListener);
    for (BalancerRunner balancer : balancers) {
        balancer.setNodeExpiration(15000);
    }
    Thread.sleep(1000);
    shootist.peerHostPort = "127.0.0.1:9988";
    shootist.callerSendsBye = true;
    shootist.sendInitialInvite();
    // servers[0].sendHeartbeat = false;
    Thread.sleep(15000);
    shootist.sendBye();
    Thread.sleep(2000);
    assertEquals(3, externalIpLoadBalancer.sipMessageWithoutRetrans.size());
    assertSame(inviteServer, byeServer);
    assertSame(inviteServer, ackServer);
    assertNotNull(byeServer);
    assertNotNull(ackServer);
}
Also used : AppServer(org.mobicents.tools.sip.balancer.AppServer) BalancerRunner(org.mobicents.tools.sip.balancer.BalancerRunner) EventListener(org.mobicents.tools.sip.balancer.EventListener) Test(org.junit.Test)

Example 19 with AppServer

use of org.mobicents.tools.sip.balancer.AppServer in project load-balancer by RestComm.

the class SprayTwoPureConsistentHashTest method setUp.

@Before
public void setUp() throws Exception {
    shootist = new Shootist();
    String externalIpLBString = "";
    String internalIpLBString = "";
    for (int q = 0; q < numBalancers; q++) {
        balancers[q] = prepBalancer(q);
        externalIpLBString += "127.0.0.1:" + 5 + q + "60,";
        internalIpLBString += "127.0.0.1:" + 5 + q + "65,";
    }
    for (int q = 0; q < servers.length; q++) {
        servers[q] = new AppServer("node" + q, 4060 + q, "127.0.0.1", 2000, 5060, 5065, "0", ListeningPoint.UDP, 2222 + q);
        servers[q].setBalancers(loadbalancers);
        servers[q].start();
    }
    externalIpLoadBalancer = new UDPPacketForwarder(9988, externalIpLBString, "127.0.0.1");
    externalIpLoadBalancer.start();
    internalIpLoadBalancer = new UDPPacketForwarder(9922, internalIpLBString, "127.0.0.1");
    internalIpLoadBalancer.start();
    Thread.sleep(5000);
}
Also used : AppServer(org.mobicents.tools.sip.balancer.AppServer) UDPPacketForwarder(org.mobicents.tools.sip.balancer.UDPPacketForwarder) Shootist(org.mobicents.tools.sip.balancer.operation.Shootist) ListeningPoint(javax.sip.ListeningPoint) Before(org.junit.Before)

Example 20 with AppServer

use of org.mobicents.tools.sip.balancer.AppServer in project load-balancer by RestComm.

the class SprayingLoadBalancersWithNoInternalPortTest method testSprayingRoundRobinSIPLBsUASCallConsistentHash.

@Test
public void testSprayingRoundRobinSIPLBsUASCallConsistentHash() {
    EventListener failureEventListener = new EventListener() {

        @Override
        public void uasAfterResponse(int statusCode, AppServer source) {
        }

        @Override
        public void uasAfterRequestReceived(String method, AppServer source) {
            if (method.equals("INVITE")) {
                inviteServer = source;
            } else if (method.equals("ACK")) {
                ackServer = source;
            } else {
                byeServer = source;
            }
        }

        @Override
        public void uacAfterRequestSent(String method, AppServer source) {
        // TODO Auto-generated method stub
        }

        @Override
        public void uacAfterResponse(int statusCode, AppServer source) {
        }
    };
    for (AppServer as : servers) as.setEventListener(failureEventListener);
    shootist.peerHostPort = "127.0.0.1:9988";
    shootist.callerSendsBye = true;
    shootist.sendInitialInvite();
    // servers[0].sendHeartbeat = false;
    Helper.sleep(10000);
    try {
        shootist.sendBye();
    } catch (SipException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Helper.sleep(2200);
    assertEquals(3, externalIpLoadBalancer.sipMessageWithoutRetrans.size());
    assertSame(inviteServer, byeServer);
    assertSame(inviteServer, ackServer);
    assertNotNull(byeServer);
    assertNotNull(ackServer);
}
Also used : AppServer(org.mobicents.tools.sip.balancer.AppServer) EventListener(org.mobicents.tools.sip.balancer.EventListener) SipException(javax.sip.SipException) Test(org.junit.Test)

Aggregations

AppServer (org.mobicents.tools.sip.balancer.AppServer)72 Test (org.junit.Test)41 EventListener (org.mobicents.tools.sip.balancer.EventListener)37 ListeningPoint (javax.sip.ListeningPoint)27 Before (org.junit.Before)26 BalancerRunner (org.mobicents.tools.sip.balancer.BalancerRunner)26 Shootist (org.mobicents.tools.sip.balancer.operation.Shootist)26 LoadBalancerConfiguration (org.mobicents.tools.configuration.LoadBalancerConfiguration)24 SipURI (javax.sip.address.SipURI)16 SinglePointTest (org.mobicents.tools.sip.balancer.SinglePointTest)11 WorstCaseUdpTestAffinityAlgorithm (org.mobicents.tools.sip.balancer.WorstCaseUdpTestAffinityAlgorithm)7 UDPPacketForwarder (org.mobicents.tools.sip.balancer.UDPPacketForwarder)5 UserBasedAlgorithm (org.mobicents.tools.sip.balancer.UserBasedAlgorithm)5 ArrayList (java.util.ArrayList)2 SipException (javax.sip.SipException)2 Response (javax.sip.message.Response)2 CongestionControlMessageValve (org.mobicents.ext.javax.sip.congestion.CongestionControlMessageValve)1 Node (org.mobicents.tools.heartbeat.api.Node)1 ActiveStandbyAlgorithm (org.mobicents.tools.sip.balancer.ActiveStandbyAlgorithm)1 HeaderConsistentHashBalancerAlgorithm (org.mobicents.tools.sip.balancer.HeaderConsistentHashBalancerAlgorithm)1