Example #1
0
  @Test
  public void testDiameterFactory() throws Throwable {
    // Log.getLog().setDebugEnabled(true);

    TestDiameterHandler serverHandler =
        new TestDiameterHandler() {

          @Override
          public void doHandle(DiameterMessage message) throws Throwable {
            DiameterServletAnswer uda;
            DiameterServletRequest request = (DiameterServletRequest) message;

            assertEquals(true, message.isRequest());
            assertEquals(Sh.UDR, request.getCommand());
            assertEquals(request.getApplicationId(), Sh.SH_APPLICATION_ID.getId());
            assertEquals(request.getDestinationHost(), "server");
            uda = request.createAnswer(Common.DIAMETER_SUCCESS);
            uda.send();
          }
        };
    _server.setHandler(serverHandler);
    _server.start();

    TestDiameterHandler clientHandler =
        new TestDiameterHandler() {

          @Override
          public void doHandle(DiameterMessage message) throws Throwable {
            DiameterServletAnswer uda = (DiameterServletAnswer) message;

            assertFalse(message.isRequest());
            assertEquals(Sh.UDA, uda.getCommand());
            assertEquals(uda.getApplicationId(), Sh.SH_APPLICATION_ID.getId());
          }
        };
    _client.setHandler(clientHandler);
    _client.start();

    waitPeerOpened();

    DiameterFactory clientFactory = createFactory(_client);
    DiameterServletRequest udr =
        clientFactory.createRequest(null, Sh.SH_APPLICATION_ID, Sh.UDR, "server");

    udr.add(Common.DESTINATION_HOST, "server");
    udr.getAVPs().add(Sh.DATA_REFERENCE, DataReference.SCSCFName);
    AVP<AVPList> userIdentity = new AVP<AVPList>(Sh.USER_IDENTITY, new AVPList());
    userIdentity.getValue().add(Cx.PUBLIC_IDENTITY, "sip:[email protected]");
    udr.getAVPs().add(userIdentity);
    udr.getAVPs().add(Common.AUTH_SESSION_STATE, AuthSessionState.NO_STATE_MAINTAINED);
    udr.getSession();
    udr.send();
    serverHandler.assertDone();
    clientHandler.assertDone();
  }
Example #2
0
 private DiameterRequest newUdr() {
   DiameterRequest udr =
       new DiameterRequest(
           _client,
           Sh.UDR,
           Sh.SH_APPLICATION_ID.getId(),
           _client.getSessionManager().newSessionId());
   udr.getAVPs().add(Common.DESTINATION_REALM, "server");
   udr.getAVPs().add(Common.DESTINATION_HOST, "server");
   udr.getAVPs().add(Sh.DATA_REFERENCE, DataReference.SCSCFName);
   AVP<AVPList> userIdentity = new AVP<AVPList>(Sh.USER_IDENTITY, new AVPList());
   userIdentity.getValue().add(Cx.PUBLIC_IDENTITY, "sip:[email protected]");
   udr.getAVPs().add(userIdentity);
   udr.getAVPs().add(Common.AUTH_SESSION_STATE, AuthSessionState.NO_STATE_MAINTAINED);
   udr.getSession();
   return udr;
 }
Example #3
0
  @Test
  public void testSession() throws Throwable {
    // Log.getLog().setDebugEnabled(true);

    TestDiameterHandler serverHandler =
        new TestDiameterHandler() {
          private String _sessionId;
          private DiameterSession _session;

          @Override
          public void doHandle(DiameterMessage message) throws Throwable {
            if (message instanceof DiameterServletAnswer) {
              assertEquals(Sh.PNA, message.getCommand());
              assertEquals(_sessionId, message.getSessionId());
              assertEquals(_session, message.getSession());
            } else {
              DiameterServletAnswer sna;
              DiameterServletRequest request = (DiameterServletRequest) message;

              assertEquals(true, message.isRequest());
              assertEquals(Sh.SNR, request.getCommand());
              assertEquals(request.getApplicationId(), Sh.SH_APPLICATION_ID.getId());
              assertEquals(request.getDestinationHost(), "server");
              sna = request.createAnswer(Common.DIAMETER_SUCCESS);
              _sessionId = request.getSessionId();
              assertNotNull(_sessionId);
              _session = request.getSession();
              assertNotNull(_session);
              sna.send();

              Thread.sleep(50);
              DiameterServletRequest pnr = _session.createRequest(Sh.PNR, true);
              pnr.send();
            }
          }
        };
    _server.setHandler(serverHandler);
    _server.start();

    TestDiameterHandler clientHandler =
        new TestDiameterHandler() {
          private String _sessionId;
          private DiameterSession _session;

          @Override
          public void doHandle(DiameterMessage message) throws Throwable {
            if (message instanceof DiameterServletAnswer) {
              DiameterServletAnswer sna = (DiameterServletAnswer) message;
              assertEquals(Sh.SNA, sna.getCommand());
              assertEquals(sna.getApplicationId(), Sh.SH_APPLICATION_ID.getId());
              _sessionId = sna.getSessionId();
              _session = sna.getSession();
              assertNotNull(_sessionId);
              assertNotNull(_session);
              assertEquals(_sessionId, sna.getRequest().getSessionId());
            } else {
              DiameterServletRequest pnr = (DiameterServletRequest) message;
              assertEquals(Sh.PNR, pnr.getCommand());
              assertEquals(_sessionId, pnr.getSessionId());
              assertEquals(_session, pnr.getSession());
              pnr.createAnswer(Common.DIAMETER_SUCCESS).send();
            }
          }
        };
    _client.setHandler(clientHandler);
    _client.start();

    waitPeerOpened();

    String id = _client.getSessionManager().newSessionId();
    DiameterRequest snr = new DiameterRequest(_client, Sh.SNR, Sh.SH_APPLICATION_ID.getId(), id);
    snr.add(Common.DESTINATION_REALM, "server");
    snr.add(Common.DESTINATION_HOST, "server");
    snr.add(Sh.DATA_REFERENCE, DataReference.SCSCFName);
    AVP<AVPList> userIdentity = new AVP<AVPList>(Sh.USER_IDENTITY, new AVPList());
    userIdentity.getValue().add(Cx.PUBLIC_IDENTITY, "sip:[email protected]");
    snr.getAVPs().add(userIdentity);
    snr.add(Common.AUTH_SESSION_STATE, AuthSessionState.NO_STATE_MAINTAINED);
    snr.getAVPs().add(Sh.SH_APPLICATION_ID.getAVP());

    snr.send();

    serverHandler.assertDone(2);
    clientHandler.assertDone(2);
  }