From 6043c3e8ba4e20f6292d3b2d5d1b471a375ec8ba Mon Sep 17 00:00:00 2001 From: Fernando Mendioroz Date: Mon, 13 Jun 2016 21:53:02 -0300 Subject: [PATCH] Added SLg and SLh AVP codes. Issue #37 and Issue #38 Update Avp.java There was a problem introduced by automatic checkstyle formatting in Eclipse in line 31 (it added one more line and thus made it appear with so many changes/deletions). Also, made more human readable the comments of reused AVPs either for SLh or SLg. Added SLh and SLg (ELP) AVPs into dictionary, including all applications/commands and AVP's elements definitions according to 3GPP TS 29.172/173. Issue #37 and issue #38 SLh and SLg interfaces implementation initial work after correspondent AVP definition/configuration previous commit. Some few error corrections and TODOs pending. Issues #37 and #38 PR #48 Fixed all compilations errors from previous commits. Added jdiameter-ha classes for both interfaces. Issues #37 and #38. PR #48 Worked on conflicts. Issues #37 and #38. PR #48 Modifications for consistency with latest changes for declaration of attributes in Avp.java class. Issues #37 and #38. PR #48 Started testsuite work. Issues #37 and #38. PR #48 A couple of fixes from previous commit and SLh abstract client and server classes for testsuite implementation start. Issues #37 and #38. PR #48 Attempt to resolve conflicts in Avp.java. Issues #37 and #38. PR #48 Rollback to original Avp.java. Issues #37 and #38. PR #48 Rollback to original Avp.java. fixing 2 spaces instead of 4. Issues #37 and #38. PR #48 Rollback to original Avp.java. fixing 2 spaces instead of 4, 2nd attempt. Issues #37 and #38. PR #48 --- .../ClientSLgSessionDataReplicatedImpl.java | 64 ++ .../ClientSLhSessionDataReplicatedImpl.java | 63 ++ .../slg/SLgReplicatedSessionDataFactory.java | 71 +++ .../slg/SLgSessionDataReplicatedImpl.java | 152 +++++ .../slh/SLhReplicatedSessionDataFactory.java | 71 +++ .../slh/SLhSessionDataReplicatedImpl.java | 152 +++++ .../ha/data/ReplicatedSessionDatasource.java | 8 +- .../ServerSLgSessionDataReplicatedImpl.java | 63 ++ .../ServerSLhSessionDataReplicatedImpl.java | 63 ++ .../jdiameter/api/slg/ClientSLgSession.java | 64 ++ .../api/slg/ClientSLgSessionListener.java | 52 ++ .../jdiameter/api/slg/ServerSLgSession.java | 64 ++ .../api/slg/ServerSLgSessionListener.java | 49 ++ .../api/slg/events/LocationReportAnswer.java | 48 ++ .../api/slg/events/LocationReportRequest.java | 48 ++ .../api/slg/events/ProvideLocationAnswer.java | 51 ++ .../slg/events/ProvideLocationRequest.java | 51 ++ .../jdiameter/api/slh/ClientSLhSession.java | 52 ++ .../api/slh/ClientSLhSessionListener.java | 48 ++ .../jdiameter/api/slh/ServerSLhSession.java | 51 ++ .../api/slh/ServerSLhSessionListener.java | 46 ++ .../api/slh/events/LCSRoutingInfoAnswer.java | 46 ++ .../api/slh/events/LCSRoutingInfoRequest.java | 45 ++ .../slg/ClientSLgSessionDataLocalImpl.java | 34 ++ .../jdiameter/client/impl/app/slg/Event.java | 86 +++ .../impl/app/slg/IClientSLgSessionData.java | 33 + .../impl/app/slg/SLgClientSessionImpl.java | 341 +++++++++++ .../slh/ClientSLhSessionDataLocalImpl.java | 34 ++ .../jdiameter/client/impl/app/slh/Event.java | 86 +++ .../impl/app/slh/IClientSLhSessionData.java | 33 + .../impl/app/slh/SLhClientSessionImpl.java | 316 ++++++++++ .../api/app/slg/ISLgMessageFactory.java | 52 ++ .../common/api/app/slg/ISLgSessionData.java | 48 ++ .../api/app/slg/ISLgSessionFactory.java | 88 +++ .../common/api/app/slg/SLgSessionState.java | 33 + .../api/app/slh/ISLhMessageFactory.java | 47 ++ .../common/api/app/slh/ISLhSessionData.java | 48 ++ .../api/app/slh/ISLhSessionFactory.java | 90 +++ .../common/api/app/slh/SLhSessionState.java | 33 + .../app/slg/LocationReportAnswerImpl.java | 53 ++ .../app/slg/LocationReportRequestImpl.java | 50 ++ .../app/slg/ProvideLocationAnswerImpl.java | 54 ++ .../app/slg/ProvideLocationRequestImpl.java | 49 ++ .../app/slg/SLgLocalSessionDataFactory.java | 52 ++ .../impl/app/slg/SLgLocalSessionDataImpl.java | 65 ++ .../common/impl/app/slg/SLgSession.java | 134 ++++ .../impl/app/slg/SLgSessionFactoryImpl.java | 291 +++++++++ .../app/slh/LCSRoutingInfoAnswerImpl.java | 55 ++ .../app/slh/LCSRoutingInfoRequestImpl.java | 48 ++ .../app/slh/SLhLocalSessionDataFactory.java | 52 ++ .../impl/app/slh/SLhLocalSessionDataImpl.java | 65 ++ .../common/impl/app/slh/SLhSession.java | 134 ++++ .../impl/app/slh/SLhSessionFactoryImpl.java | 269 +++++++++ .../common/impl/data/LocalDataSource.java | 6 + .../jdiameter/server/impl/app/slg/Event.java | 86 +++ .../impl/app/slg/IServerSLgSessionData.java | 33 + .../impl/app/slg/SLgServerSessionImpl.java | 306 ++++++++++ .../slg/ServerSLgSessionDataLocalImpl.java | 34 ++ .../jdiameter/server/impl/app/slh/Event.java | 86 +++ .../impl/app/slh/IServerSLhSessionData.java | 33 + .../impl/app/slh/SLhServerSessionImpl.java | 290 +++++++++ .../slh/ServerSLhSessionDataLocalImpl.java | 34 ++ core/mux/common/config/dictionary.xml | 570 +++++++++++++++++ .../stack/functional/slg/AbstractClient.java | 319 ++++++++++ .../stack/functional/slg/AbstractServer.java | 254 ++++++++ .../stack/functional/slh/AbstractClient.java | 197 ++++++ .../stack/functional/slh/AbstractServer.java | 199 ++++++ .../functional-slg/config-client.xml | 0 .../functional-slg/config-server-node1.xml | 0 .../functional-slg/config-server-node2.xml | 0 .../replicated-config-client.xml | 0 .../replicated-config-server-node1.xml | 0 .../replicated-config-server-node2.xml | 0 .../functional-slh/config-client.xml | 0 .../functional-slh/config-server-node1.xml | 0 .../functional-slh/config-server-node2.xml | 0 .../replicated-config-client.xml | 0 .../replicated-config-server-node1.xml | 0 .../replicated-config-server-node2.xml | 0 .../tests/src/test/resources/dictionary.xml | 571 ++++++++++++++++++ 80 files changed, 7212 insertions(+), 1 deletion(-) create mode 100644 core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/client/slg/ClientSLgSessionDataReplicatedImpl.java create mode 100644 core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/client/slh/ClientSLhSessionDataReplicatedImpl.java create mode 100644 core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slg/SLgReplicatedSessionDataFactory.java create mode 100644 core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slg/SLgSessionDataReplicatedImpl.java create mode 100644 core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slh/SLhReplicatedSessionDataFactory.java create mode 100644 core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slh/SLhSessionDataReplicatedImpl.java create mode 100644 core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/server/slg/ServerSLgSessionDataReplicatedImpl.java create mode 100644 core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/server/slh/ServerSLhSessionDataReplicatedImpl.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ClientSLgSession.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ClientSLgSessionListener.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ServerSLgSession.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ServerSLgSessionListener.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/LocationReportAnswer.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/LocationReportRequest.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/ProvideLocationAnswer.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/ProvideLocationRequest.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ClientSLhSession.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ClientSLhSessionListener.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ServerSLhSession.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ServerSLhSessionListener.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slh/events/LCSRoutingInfoAnswer.java create mode 100644 core/jdiameter/api/src/main/java/org/jdiameter/api/slh/events/LCSRoutingInfoRequest.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/ClientSLgSessionDataLocalImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/Event.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/IClientSLgSessionData.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/SLgClientSessionImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/ClientSLhSessionDataLocalImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/Event.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/IClientSLhSessionData.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/SLhClientSessionImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/ISLgMessageFactory.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/ISLgSessionData.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/ISLgSessionFactory.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/SLgSessionState.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/ISLhMessageFactory.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/ISLhSessionData.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/ISLhSessionFactory.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/SLhSessionState.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/LocationReportAnswerImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/LocationReportRequestImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/ProvideLocationAnswerImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/ProvideLocationRequestImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgLocalSessionDataFactory.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgLocalSessionDataImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgSession.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgSessionFactoryImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/LCSRoutingInfoAnswerImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/LCSRoutingInfoRequestImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhLocalSessionDataFactory.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhLocalSessionDataImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhSession.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhSessionFactoryImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/Event.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/IServerSLgSessionData.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/SLgServerSessionImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/ServerSLgSessionDataLocalImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/Event.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/IServerSLhSessionData.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/SLhServerSessionImpl.java create mode 100644 core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/ServerSLhSessionDataLocalImpl.java create mode 100644 testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slg/AbstractClient.java create mode 100644 testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slg/AbstractServer.java create mode 100644 testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slh/AbstractClient.java create mode 100644 testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slh/AbstractServer.java create mode 100644 testsuite/tests/src/test/resources/configurations/functional-slg/config-client.xml create mode 100644 testsuite/tests/src/test/resources/configurations/functional-slg/config-server-node1.xml create mode 100644 testsuite/tests/src/test/resources/configurations/functional-slg/config-server-node2.xml create mode 100644 testsuite/tests/src/test/resources/configurations/functional-slg/replicated-config-client.xml create mode 100644 testsuite/tests/src/test/resources/configurations/functional-slg/replicated-config-server-node1.xml create mode 100644 testsuite/tests/src/test/resources/configurations/functional-slg/replicated-config-server-node2.xml create mode 100644 testsuite/tests/src/test/resources/configurations/functional-slh/config-client.xml create mode 100644 testsuite/tests/src/test/resources/configurations/functional-slh/config-server-node1.xml create mode 100644 testsuite/tests/src/test/resources/configurations/functional-slh/config-server-node2.xml create mode 100644 testsuite/tests/src/test/resources/configurations/functional-slh/replicated-config-client.xml create mode 100644 testsuite/tests/src/test/resources/configurations/functional-slh/replicated-config-server-node1.xml create mode 100644 testsuite/tests/src/test/resources/configurations/functional-slh/replicated-config-server-node2.xml diff --git a/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/client/slg/ClientSLgSessionDataReplicatedImpl.java b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/client/slg/ClientSLgSessionDataReplicatedImpl.java new file mode 100644 index 000000000..7a9c159ee --- /dev/null +++ b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/client/slg/ClientSLgSessionDataReplicatedImpl.java @@ -0,0 +1,64 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ + +package org.mobicents.diameter.impl.ha.client.slg; + +import org.jboss.cache.Fqn; +import org.jdiameter.api.slg.ClientSLgSession; +import org.jdiameter.client.api.IContainer; +import org.jdiameter.client.impl.app.slg.IClientSLgSessionData; +import org.jdiameter.common.api.app.slg.SLgSessionState; +import org.mobicents.cluster.MobicentsCluster; +import org.mobicents.diameter.impl.ha.common.slg.SLgSessionDataReplicatedImpl; +import org.mobicents.diameter.impl.ha.data.ReplicatedSessionDatasource; + +/** + * + * @author Fernando Mendioroz (fernando.mendioroz@telestax.com) + * + */ +public class ClientSLgSessionDataReplicatedImpl extends SLgSessionDataReplicatedImpl implements IClientSLgSessionData { + + /** + * @param nodeFqn + * @param mobicentsCluster + * @param iface + */ + public ClientSLgSessionDataReplicatedImpl(Fqn nodeFqn, MobicentsCluster mobicentsCluster, IContainer container) { + super(nodeFqn, mobicentsCluster, container); + + if (super.create()) { + setAppSessionIface(this, ClientSLgSession.class); + setSLgSessionState(SLgSessionState.IDLE); + } + } + + /** + * @param sessionId + * @param mobicentsCluster + * @param iface + */ + public ClientSLgSessionDataReplicatedImpl(String sessionId, MobicentsCluster mobicentsCluster, IContainer container) { + this(Fqn.fromRelativeElements(ReplicatedSessionDatasource.SESSIONS_FQN, sessionId), mobicentsCluster, container); + } + +} + diff --git a/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/client/slh/ClientSLhSessionDataReplicatedImpl.java b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/client/slh/ClientSLhSessionDataReplicatedImpl.java new file mode 100644 index 000000000..08e905069 --- /dev/null +++ b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/client/slh/ClientSLhSessionDataReplicatedImpl.java @@ -0,0 +1,63 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ + +package org.mobicents.diameter.impl.ha.client.slh; + +import org.jboss.cache.Fqn; +import org.jdiameter.api.slh.ClientSLhSession; +import org.jdiameter.client.api.IContainer; +import org.jdiameter.client.impl.app.slh.IClientSLhSessionData; +import org.jdiameter.common.api.app.slh.SLhSessionState; +import org.mobicents.cluster.MobicentsCluster; +import org.mobicents.diameter.impl.ha.common.slh.SLhSessionDataReplicatedImpl; +import org.mobicents.diameter.impl.ha.data.ReplicatedSessionDatasource; + +/** + * + * @author Fernando Mendioroz (fernando.mendioroz@telestax.com) + * + */ +public class ClientSLhSessionDataReplicatedImpl extends SLhSessionDataReplicatedImpl implements IClientSLhSessionData { + + /** + * @param nodeFqn + * @param mobicentsCluster + * @param iface + */ + public ClientSLhSessionDataReplicatedImpl(Fqn nodeFqn, MobicentsCluster mobicentsCluster, IContainer container) { + super(nodeFqn, mobicentsCluster, container); + + if (super.create()) { + setAppSessionIface(this, ClientSLhSession.class); + setSLhSessionState(SLhSessionState.IDLE); + } + } + + /** + * @param sessionId + * @param mobicentsCluster + * @param iface + */ + public ClientSLhSessionDataReplicatedImpl(String sessionId, MobicentsCluster mobicentsCluster, IContainer container) { + this(Fqn.fromRelativeElements(ReplicatedSessionDatasource.SESSIONS_FQN, sessionId), mobicentsCluster, container); + } + +} diff --git a/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slg/SLgReplicatedSessionDataFactory.java b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slg/SLgReplicatedSessionDataFactory.java new file mode 100644 index 000000000..325eb5752 --- /dev/null +++ b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slg/SLgReplicatedSessionDataFactory.java @@ -0,0 +1,71 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ + +package org.mobicents.diameter.impl.ha.common.slg; + +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.slg.ClientSLgSession; +import org.jdiameter.api.slg.ServerSLgSession; +import org.jdiameter.common.api.app.IAppSessionDataFactory; +import org.jdiameter.common.api.app.slg.ISLgSessionData; +import org.jdiameter.common.api.data.ISessionDatasource; +import org.mobicents.cluster.MobicentsCluster; +import org.mobicents.diameter.impl.ha.client.slg.ClientSLgSessionDataReplicatedImpl; +import org.mobicents.diameter.impl.ha.data.ReplicatedSessionDatasource; +import org.mobicents.diameter.impl.ha.server.slg.ServerSLgSessionDataReplicatedImpl; + +/** + * + * @author Fernando Mendioroz (fernando.mendioroz@telestax.com) + * + */ +public class SLgReplicatedSessionDataFactory implements IAppSessionDataFactory { + + private ReplicatedSessionDatasource replicatedSessionDataSource; + private MobicentsCluster mobicentsCluster; + + /** + * @param replicatedSessionDataSource + */ + public SLgReplicatedSessionDataFactory(ISessionDatasource replicatedSessionDataSource) { // Is this ok? + super(); + this.replicatedSessionDataSource = (ReplicatedSessionDatasource) replicatedSessionDataSource; + this.mobicentsCluster = this.replicatedSessionDataSource.getMobicentsCluster(); + } + + /* + * (non-Javadoc) + * + * @see org.jdiameter.common.api.app.IAppSessionDataFactory#getAppSessionData(java.lang.Class, java.lang.String) + */ + public ISLgSessionData getAppSessionData(Class clazz, String sessionId) { + if (clazz.equals(ClientSLgSession.class)) { + ClientSLgSessionDataReplicatedImpl data = new ClientSLgSessionDataReplicatedImpl(sessionId, this.mobicentsCluster, this.replicatedSessionDataSource.getContainer()); + return data; + } + else if (clazz.equals(ServerSLgSession.class)) { + ServerSLgSessionDataReplicatedImpl data = new ServerSLgSessionDataReplicatedImpl(sessionId, this.mobicentsCluster, this.replicatedSessionDataSource.getContainer()); + return data; + } + throw new IllegalArgumentException(); + } + +} diff --git a/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slg/SLgSessionDataReplicatedImpl.java b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slg/SLgSessionDataReplicatedImpl.java new file mode 100644 index 000000000..cb4af62d8 --- /dev/null +++ b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slg/SLgSessionDataReplicatedImpl.java @@ -0,0 +1,152 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ + +package org.mobicents.diameter.impl.ha.common.slg; + +import java.io.Serializable; +import java.nio.ByteBuffer; + +import org.jboss.cache.Fqn; +import org.jdiameter.api.AvpDataException; +import org.jdiameter.api.Request; +import org.jdiameter.client.api.IContainer; +import org.jdiameter.client.api.IMessage; +import org.jdiameter.client.api.parser.IMessageParser; +import org.jdiameter.client.api.parser.ParseException; +import org.jdiameter.common.api.app.slg.SLgSessionState; +import org.jdiameter.common.api.app.slg.ISLgSessionData; +import org.mobicents.cluster.MobicentsCluster; +import org.mobicents.diameter.impl.ha.common.AppSessionDataReplicatedImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Fernando Mendioroz (fernando.mendioroz@telestax.com) + * + */ +public abstract class SLgSessionDataReplicatedImpl extends AppSessionDataReplicatedImpl implements ISLgSessionData { + + private static final Logger logger = LoggerFactory.getLogger(SLgSessionDataReplicatedImpl.class); + + private static final String STATE = "STATE"; + private static final String BUFFER = "BUFFER"; + private static final String TS_TIMERID = "TS_TIMERID"; + + private IMessageParser messageParser; + + /** + * @param nodeFqn + * @param mobicentsCluster + * @param iface + */ + public SLgSessionDataReplicatedImpl(Fqn nodeFqn, MobicentsCluster mobicentsCluster, IContainer container) { + super(nodeFqn, mobicentsCluster); + this.messageParser = container.getAssemblerFacility().getComponentInstance(IMessageParser.class); + } + + /* + * (non-Javadoc) + * + * @see org.jdiameter.common.api.app.slg.ISLgSessionData#setSLgSessionState(org.jdiameter.common.api.app.slg.SLgSessionState) + */ + public void setSLgSessionState(SLgSessionState state) { + if (exists()) { + getNode().put(STATE, state); + } + else { + throw new IllegalStateException(); + } + } + + /* + * (non-Javadoc) + * + * @see org.jdiameter.common.api.app.slg.ISLgSessionData#getSLgSessionState() + */ + public SLgSessionState getSLgSessionState() { + if (exists()) { + return (SLgSessionState) getNode().get(STATE); + } + else { + throw new IllegalStateException(); + } + } + + /* + * (non-Javadoc) + * + * @see org.jdiameter.common.api.app.slg.ISLgSessionData#getTsTimerId() + */ + public Serializable getTsTimerId() { + if (exists()) { + return (Serializable) getNode().get(TS_TIMERID); + } + else { + throw new IllegalStateException(); + } + } + + /* + * (non-Javadoc) + * + * @see org.jdiameter.common.api.app.slg.ISLgSessionData#setTsTimerId(java.io.Serializable) + */ + public void setTsTimerId(Serializable tid) { + if (exists()) { + getNode().put(TS_TIMERID, tid); + } + else { + throw new IllegalStateException(); + } + } + + public Request getBuffer() { + byte[] data = (byte[]) getNode().get(BUFFER); + if (data != null) { + try { + return (Request) this.messageParser.createMessage(ByteBuffer.wrap(data)); + } + catch (AvpDataException e) { + logger.error("Unable to recreate message from buffer."); + return null; + } + } + else { + return null; + } + } + + public void setBuffer(Request buffer) { + if (buffer != null) { + try { + byte[] data = this.messageParser.encodeMessage((IMessage) buffer).array(); + getNode().put(BUFFER, data); + } + catch (ParseException e) { + logger.error("Unable to encode message to buffer."); + } + } + else { + getNode().remove(BUFFER); + } + } +} diff --git a/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slh/SLhReplicatedSessionDataFactory.java b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slh/SLhReplicatedSessionDataFactory.java new file mode 100644 index 000000000..58c5bdd62 --- /dev/null +++ b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slh/SLhReplicatedSessionDataFactory.java @@ -0,0 +1,71 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ + +package org.mobicents.diameter.impl.ha.common.slh; + +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.slh.ClientSLhSession; +import org.jdiameter.api.slh.ServerSLhSession; +import org.jdiameter.common.api.app.IAppSessionDataFactory; +import org.jdiameter.common.api.app.slh.ISLhSessionData; +import org.jdiameter.common.api.data.ISessionDatasource; +import org.mobicents.cluster.MobicentsCluster; +import org.mobicents.diameter.impl.ha.client.slh.ClientSLhSessionDataReplicatedImpl; +import org.mobicents.diameter.impl.ha.data.ReplicatedSessionDatasource; +import org.mobicents.diameter.impl.ha.server.slh.ServerSLhSessionDataReplicatedImpl; + +/** + * + * @author Fernando Mendioroz (fernando.mendioroz@telestax.com) + * + */ +public class SLhReplicatedSessionDataFactory implements IAppSessionDataFactory { + + private ReplicatedSessionDatasource replicatedSessionDataSource; + private MobicentsCluster mobicentsCluster; + + /** + * @param replicatedSessionDataSource + */ + public SLhReplicatedSessionDataFactory(ISessionDatasource replicatedSessionDataSource) { // Is this ok? + super(); + this.replicatedSessionDataSource = (ReplicatedSessionDatasource) replicatedSessionDataSource; + this.mobicentsCluster = this.replicatedSessionDataSource.getMobicentsCluster(); + } + + /* + * (non-Javadoc) + * + * @see org.jdiameter.common.api.app.IAppSessionDataFactory#getAppSessionData(java.lang.Class, java.lang.String) + */ + public ISLhSessionData getAppSessionData(Class clazz, String sessionId) { + if (clazz.equals(ClientSLhSession.class)) { + ClientSLhSessionDataReplicatedImpl data = new ClientSLhSessionDataReplicatedImpl(sessionId, this.mobicentsCluster, this.replicatedSessionDataSource.getContainer()); + return data; + } + else if (clazz.equals(ServerSLhSession.class)) { + ServerSLhSessionDataReplicatedImpl data = new ServerSLhSessionDataReplicatedImpl(sessionId, this.mobicentsCluster, this.replicatedSessionDataSource.getContainer()); + return data; + } + throw new IllegalArgumentException(); + } + +} diff --git a/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slh/SLhSessionDataReplicatedImpl.java b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slh/SLhSessionDataReplicatedImpl.java new file mode 100644 index 000000000..57bee93f8 --- /dev/null +++ b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/common/slh/SLhSessionDataReplicatedImpl.java @@ -0,0 +1,152 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ + +package org.mobicents.diameter.impl.ha.common.slh; + +import java.io.Serializable; +import java.nio.ByteBuffer; + +import org.jboss.cache.Fqn; +import org.jdiameter.api.AvpDataException; +import org.jdiameter.api.Request; +import org.jdiameter.client.api.IContainer; +import org.jdiameter.client.api.IMessage; +import org.jdiameter.client.api.parser.IMessageParser; +import org.jdiameter.client.api.parser.ParseException; +import org.jdiameter.common.api.app.slh.SLhSessionState; +import org.jdiameter.common.api.app.slh.ISLhSessionData; +import org.mobicents.cluster.MobicentsCluster; +import org.mobicents.diameter.impl.ha.common.AppSessionDataReplicatedImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Fernando Mendioroz (fernando.mendioroz@telestax.com) + * + */ +public abstract class SLhSessionDataReplicatedImpl extends AppSessionDataReplicatedImpl implements ISLhSessionData { + + private static final Logger logger = LoggerFactory.getLogger(SLhSessionDataReplicatedImpl.class); + + private static final String STATE = "STATE"; + private static final String BUFFER = "BUFFER"; + private static final String TS_TIMERID = "TS_TIMERID"; + + private IMessageParser messageParser; + + /** + * @param nodeFqn + * @param mobicentsCluster + * @param iface + */ + public SLhSessionDataReplicatedImpl(Fqn nodeFqn, MobicentsCluster mobicentsCluster, IContainer container) { + super(nodeFqn, mobicentsCluster); + this.messageParser = container.getAssemblerFacility().getComponentInstance(IMessageParser.class); + } + + /* + * (non-Javadoc) + * + * @see org.jdiameter.common.api.app.slh.ISLhSessionData#setSLhSessionState(org.jdiameter.common.api.app.slh.SLhSessionState) + */ + public void setSLhSessionState(SLhSessionState state) { + if (exists()) { + getNode().put(STATE, state); + } + else { + throw new IllegalStateException(); + } + } + + /* + * (non-Javadoc) + * + * @see org.jdiameter.common.api.app.slh.ISLhSessionData#getSLhSessionState() + */ + public SLhSessionState getSLhSessionState() { + if (exists()) { + return (SLhSessionState) getNode().get(STATE); + } + else { + throw new IllegalStateException(); + } + } + + /* + * (non-Javadoc) + * + * @see org.jdiameter.common.api.app.slh.ISLhSessionData#getTsTimerId() + */ + public Serializable getTsTimerId() { + if (exists()) { + return (Serializable) getNode().get(TS_TIMERID); + } + else { + throw new IllegalStateException(); + } + } + + /* + * (non-Javadoc) + * + * @see org.jdiameter.common.api.app.slh.ISLhSessionData#setTsTimerId(java.io.Serializable) + */ + public void setTsTimerId(Serializable tid) { + if (exists()) { + getNode().put(TS_TIMERID, tid); + } + else { + throw new IllegalStateException(); + } + } + + public Request getBuffer() { + byte[] data = (byte[]) getNode().get(BUFFER); + if (data != null) { + try { + return (Request) this.messageParser.createMessage(ByteBuffer.wrap(data)); + } + catch (AvpDataException e) { + logger.error("Unable to recreate message from buffer."); + return null; + } + } + else { + return null; + } + } + + public void setBuffer(Request buffer) { + if (buffer != null) { + try { + byte[] data = this.messageParser.encodeMessage((IMessage) buffer).array(); + getNode().put(BUFFER, data); + } + catch (ParseException e) { + logger.error("Unable to encode message to buffer."); + } + } + else { + getNode().remove(BUFFER); + } + } +} diff --git a/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/data/ReplicatedSessionDatasource.java b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/data/ReplicatedSessionDatasource.java index 6958f457d..3c6874d5d 100644 --- a/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/data/ReplicatedSessionDatasource.java +++ b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/data/ReplicatedSessionDatasource.java @@ -66,6 +66,8 @@ import org.jdiameter.common.api.app.rx.IRxSessionData; import org.jdiameter.common.api.app.s13.IS13SessionData; import org.jdiameter.common.api.app.sh.IShSessionData; +import org.jdiameter.common.api.app.slh.ISLhSessionData; +import org.jdiameter.common.api.app.slg.ISLgSessionData; import org.jdiameter.common.api.data.ISessionDatasource; import org.jdiameter.common.impl.data.LocalDataSource; import org.mobicents.cache.MobicentsCache; @@ -84,6 +86,8 @@ import org.mobicents.diameter.impl.ha.common.rx.RxReplicatedSessionDataFactory; import org.mobicents.diameter.impl.ha.common.s13.S13ReplicatedSessionDataFactory; import org.mobicents.diameter.impl.ha.common.sh.ShReplicatedSessionDataFactory; +import org.mobicents.diameter.impl.ha.common.slh.SLhReplicatedSessionDataFactory; +import org.mobicents.diameter.impl.ha.common.slg.SLgReplicatedSessionDataFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -138,7 +142,7 @@ public ReplicatedSessionDatasource(IContainer container, ISessionDatasource loca this.mobicentsCluster.startCluster(); this.container = container; - // this is coded, its tied to specific impl of SessionDatasource + // this is coded, it's tied to specific impl of SessionDatasource appSessionDataFactories.put(IAuthSessionData.class, new AuthReplicatedSessionDataFactory(this)); appSessionDataFactories.put(IAccSessionData.class, new AccReplicatedSessionDataFactory(this)); appSessionDataFactories.put(ICCASessionData.class, new CCAReplicatedSessionDataFactory(this)); @@ -149,6 +153,8 @@ public ReplicatedSessionDatasource(IContainer container, ISessionDatasource loca appSessionDataFactories.put(IGxSessionData.class, new GxReplicatedSessionDataFactory(this)); appSessionDataFactories.put(IRxSessionData.class, new RxReplicatedSessionDataFactory(this)); appSessionDataFactories.put(IS13SessionData.class, new S13ReplicatedSessionDataFactory(this)); + appSessionDataFactories.put(ISLhSessionData.class, new SLhReplicatedSessionDataFactory(this)); + appSessionDataFactories.put(ISLgSessionData.class, new SLgReplicatedSessionDataFactory(this)); } diff --git a/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/server/slg/ServerSLgSessionDataReplicatedImpl.java b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/server/slg/ServerSLgSessionDataReplicatedImpl.java new file mode 100644 index 000000000..67ecf6bfd --- /dev/null +++ b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/server/slg/ServerSLgSessionDataReplicatedImpl.java @@ -0,0 +1,63 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ + +package org.mobicents.diameter.impl.ha.server.slg; + +import org.jboss.cache.Fqn; +import org.jdiameter.api.slg.ServerSLgSession; +import org.jdiameter.client.api.IContainer; +import org.jdiameter.common.api.app.slg.SLgSessionState; +import org.jdiameter.server.impl.app.slg.IServerSLgSessionData; +import org.mobicents.cluster.MobicentsCluster; +import org.mobicents.diameter.impl.ha.common.slg.SLgSessionDataReplicatedImpl; +import org.mobicents.diameter.impl.ha.data.ReplicatedSessionDatasource; + +/** + * + * @author Fernando Mendioroz (fernando.mendioroz@telestax.com) + * + */ +public class ServerSLgSessionDataReplicatedImpl extends SLgSessionDataReplicatedImpl implements IServerSLgSessionData { + + /** + * @param nodeFqn + * @param mobicentsCluster + * @param iface + */ + public ServerSLgSessionDataReplicatedImpl(Fqn nodeFqn, MobicentsCluster mobicentsCluster, IContainer container) { + super(nodeFqn, mobicentsCluster, container); + + if (super.create()) { + setAppSessionIface(this, ServerSLgSession.class); + setSLgSessionState(SLgSessionState.IDLE); + } + } + + /** + * @param sessionId + * @param mobicentsCluster + * @param iface + */ + public ServerSLgSessionDataReplicatedImpl(String sessionId, MobicentsCluster mobicentsCluster, IContainer container) { + this(Fqn.fromRelativeElements(ReplicatedSessionDatasource.SESSIONS_FQN, sessionId), mobicentsCluster, container); + } + +} diff --git a/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/server/slh/ServerSLhSessionDataReplicatedImpl.java b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/server/slh/ServerSLhSessionDataReplicatedImpl.java new file mode 100644 index 000000000..3548061e5 --- /dev/null +++ b/core/jdiameter-ha/impl/src/main/java/org/mobicents/diameter/impl/ha/server/slh/ServerSLhSessionDataReplicatedImpl.java @@ -0,0 +1,63 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ + +package org.mobicents.diameter.impl.ha.server.slh; + +import org.jboss.cache.Fqn; +import org.jdiameter.api.slh.ServerSLhSession; +import org.jdiameter.client.api.IContainer; +import org.jdiameter.common.api.app.slh.SLhSessionState; +import org.jdiameter.server.impl.app.slh.IServerSLhSessionData; +import org.mobicents.cluster.MobicentsCluster; +import org.mobicents.diameter.impl.ha.common.slh.SLhSessionDataReplicatedImpl; +import org.mobicents.diameter.impl.ha.data.ReplicatedSessionDatasource; + +/** + * + * @author Fernando Mendioroz (fernando.mendioroz@telestax.com) + * + */ +public class ServerSLhSessionDataReplicatedImpl extends SLhSessionDataReplicatedImpl implements IServerSLhSessionData { + + /** + * @param nodeFqn + * @param mobicentsCluster + * @param iface + */ + public ServerSLhSessionDataReplicatedImpl(Fqn nodeFqn, MobicentsCluster mobicentsCluster, IContainer container) { + super(nodeFqn, mobicentsCluster, container); + + if (super.create()) { + setAppSessionIface(this, ServerSLhSession.class); + setSLhSessionState(SLhSessionState.IDLE); + } + } + + /** + * @param sessionId + * @param mobicentsCluster + * @param iface + */ + public ServerSLhSessionDataReplicatedImpl(String sessionId, MobicentsCluster mobicentsCluster, IContainer container) { + this(Fqn.fromRelativeElements(ReplicatedSessionDatasource.SESSIONS_FQN, sessionId), mobicentsCluster, container); + } + +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ClientSLgSession.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ClientSLgSession.java new file mode 100644 index 000000000..0a7a53949 --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ClientSLgSession.java @@ -0,0 +1,64 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slg; + +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.app.StateMachine; +import org.jdiameter.api.slg.events.LocationReportRequest; +import org.jdiameter.api.slg.events.ProvideLocationRequest; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ClientSLgSession extends AppSession, StateMachine { + + /** + * Send Provide-Location-Request to server + * + * @param request Provide-Location-Request event instance + * @throws InternalException The InternalException signals that internal error is occurred. + * @throws IllegalDiameterStateException The IllegalStateException signals that session has incorrect state (invalid). + * @throws RouteException The NoRouteException signals that no route exist for a given realm. + * @throws OverloadException The OverloadException signals that destination host is overloaded. + */ + void sendProvideLocationRequest(ProvideLocationRequest request) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + + /** + * Send Location-Report-Request to server + * + * @param request Location-Report-Request event instance + * @throws InternalException The InternalException signals that internal error is occurred. + * @throws IllegalDiameterStateException The IllegalStateException signals that session has incorrect state (invalid). + * @throws RouteException The NoRouteException signals that no route exist for a given realm. + * @throws OverloadException The OverloadException signals that destination host is overloaded. + */ + void sendLocationReportRequest(LocationReportRequest request) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ClientSLgSessionListener.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ClientSLgSessionListener.java new file mode 100644 index 000000000..e95c6e5ac --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ClientSLgSessionListener.java @@ -0,0 +1,52 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slg; + +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppAnswerEvent; +import org.jdiameter.api.app.AppRequestEvent; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.slg.events.ProvideLocationRequest; +import org.jdiameter.api.slg.events.ProvideLocationAnswer; +import org.jdiameter.api.slg.events.LocationReportAnswer; +import org.jdiameter.api.slg.events.LocationReportRequest; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ClientSLgSessionListener { + + void doOtherEvent(AppSession session, AppRequestEvent request, AppAnswerEvent answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + + void doProvideLocationAnswerEvent(ClientSLgSession session, ProvideLocationRequest request, ProvideLocationAnswer answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + + void doLocationReportAnswerEvent(ClientSLgSession session, LocationReportRequest request, LocationReportAnswer answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ServerSLgSession.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ServerSLgSession.java new file mode 100644 index 000000000..f2eea0b64 --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ServerSLgSession.java @@ -0,0 +1,64 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slg; + +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.app.StateMachine; +import org.jdiameter.api.slg.events.LocationReportAnswer; +import org.jdiameter.api.slg.events.ProvideLocationAnswer; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ServerSLgSession extends AppSession, StateMachine { + + /** + * Send Provide-Location-Answer to client + * + * @param answer Provide-Location-Answer event instance + * @throws InternalException The InternalException signals that internal error is occurred. + * @throws IllegalDiameterStateException The IllegalStateException signals that session has incorrect state (invalid). + * @throws RouteException The NoRouteException signals that no route exist for a given realm. + * @throws OverloadException The OverloadException signals that destination host is overloaded. + */ + void sendProvideLocationAnswer(ProvideLocationAnswer answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + + /** + * Send Location-Report-Answer to client + * + * @param answer Location-Report-Answer event instance + * @throws InternalException The InternalException signals that internal error is occurred. + * @throws IllegalDiameterStateException The IllegalStateException signals that session has incorrect state (invalid). + * @throws RouteException The NoRouteException signals that no route exist for a given realm. + * @throws OverloadException The OverloadException signals that destination host is overloaded. + */ + void sendLocationReportAnswer(LocationReportAnswer answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ServerSLgSessionListener.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ServerSLgSessionListener.java new file mode 100644 index 000000000..651fd21f1 --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/ServerSLgSessionListener.java @@ -0,0 +1,49 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slg; + +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppAnswerEvent; +import org.jdiameter.api.app.AppRequestEvent; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.slg.events.LocationReportRequest; +import org.jdiameter.api.slg.events.ProvideLocationRequest; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ServerSLgSessionListener { + + void doOtherEvent(AppSession session, AppRequestEvent request, AppAnswerEvent answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + + void doProvideLocationRequestEvent(ServerSLgSession session, ProvideLocationRequest request) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + + void doLocationReportRequestEvent(ServerSLgSession session, LocationReportRequest request) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/LocationReportAnswer.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/LocationReportAnswer.java new file mode 100644 index 000000000..90ee35978 --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/LocationReportAnswer.java @@ -0,0 +1,48 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slg.events; + +import org.jdiameter.api.app.AppAnswerEvent; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +/* + * As for 3GPP TS 29.172 v13.0.0, Subscriber Location Report operation is used by an MME or SGSN to provide the location of a + * target UE to a GMLC, when a request for location has been implicitly issued or when a Delayed Location Reporting is triggered + * after receipt of a request for location for a UE transiently not reachable. + * + * The Location-Report-Answer (LRA) command, indicated by the Command-Code field set to 8388621 and the �R� bit cleared in the + * Command Flags field, is sent by the GMLC to the MME or SGSN in response to the Location-Report-Request command (Subscriber + * Location Report operation answer) + */ + +public interface LocationReportAnswer extends AppAnswerEvent{ + + public static final String _SHORT_NAME = "LRA"; + public static final String _LONG_NAME = "Location-Report-Answer"; + + public static final int code = 8388621; + +} \ No newline at end of file diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/LocationReportRequest.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/LocationReportRequest.java new file mode 100644 index 000000000..abff7bf6a --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/LocationReportRequest.java @@ -0,0 +1,48 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slg.events; + +import org.jdiameter.api.app.AppRequestEvent; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +/* + * As for 3GPP TS 29.172 v13.0.0, Subscriber Location Report operation is used by an MME or SGSN to provide the location of a + * target UE to a GMLC, when a request for location has been implicitly issued or when a Delayed Location Reporting is triggered + * after receipt of a request for location for a UE transiently not reachable. + * + * The Location-Report-Request (LRR) command, indicated by the Command-Code field set to 8388621 and the ‘R’ bit set in the + * Command Flags field, is sent by the MME or SGSN in order to provide subscriber location data to the GMLC (Subscriber Location + * Report operation request) + */ + +public interface LocationReportRequest extends AppRequestEvent { + + public static final String _SHORT_NAME = "LRR"; + public static final String _LONG_NAME = "Location-Report-Request"; + + public static final int code = 8388621; + +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/ProvideLocationAnswer.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/ProvideLocationAnswer.java new file mode 100644 index 000000000..197787bd4 --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/ProvideLocationAnswer.java @@ -0,0 +1,51 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slg.events; + +import org.jdiameter.api.app.AppAnswerEvent; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +/* + * As for 3GPP TS 29.172 v13.0.0, the Provide Subscriber Location operation is used by a GMLC to request the location of a + * target UE from the MME or SGSN at any time, as part of EPC-MT-LR (Evolved Packet Core Mobile Terminated Location Request) or + * PS-MT-LR (Packet Switched Mobile Terminated Location Request) positioning procedures. The response contains a location + * estimate of the target UE and other additional information. This operation is also used by a GMLC to request the location of + * the target UE from the SGSN at any time, as part of deferred MT-LR procedure. The response contains the acknowledgment of the + * receipt of the request and other additional information. + * + * The Provide-Location-Answer (PLA) command, indicated by the Command-Code field set to 8388620 and the �R� bit cleared in the + * Command Flags field, is sent by the MME or SGSN to the GMLC in response to the Provide-Location-Request command (Provide + * Subscriber Location operation answer) + */ + +public interface ProvideLocationAnswer extends AppAnswerEvent{ + + public static final String _SHORT_NAME = "PLA"; + public static final String _LONG_NAME = "Provide-Location-Answer"; + + public static final int code = 8388620; + +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/ProvideLocationRequest.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/ProvideLocationRequest.java new file mode 100644 index 000000000..5ce03a72c --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slg/events/ProvideLocationRequest.java @@ -0,0 +1,51 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slg.events; + +import org.jdiameter.api.app.AppRequestEvent; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +/* + * As for 3GPP TS 29.172 v13.0.0, the Provide Subscriber Location operation is used by a GMLC to request the location of a + * target UE from the MME or SGSN at any time, as part of EPC-MT-LR (Evolved Packet Core Mobile Terminated Location Request) or + * PS-MT-LR (Packet Switched Mobile Terminated Location Request) positioning procedures. The response contains a location + * estimate of the target UE and other additional information. This operation is also used by a GMLC to request the location of + * the target UE from the SGSN at any time, as part of deferred MT-LR procedure. The response contains the acknowledgment of the + * receipt of the request and other additional information. + * + * The Provide-Location-Request (PLR) command, indicated by the Command-Code field set to 8388620 and the ‘R’ bit set in the + * Command Flags field, is sent by the GMLC in order to request subscriber location to the MME or SGSN (Provide Subscriber + * Location operation request) + */ + +public interface ProvideLocationRequest extends AppRequestEvent { + + public static final String _SHORT_NAME = "PLR"; + public static final String _LONG_NAME = "Provide-Location-Request"; + + public static final int code = 8388620; + +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ClientSLhSession.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ClientSLhSession.java new file mode 100644 index 000000000..ab394a06f --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ClientSLhSession.java @@ -0,0 +1,52 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slh; + +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.app.StateMachine; +import org.jdiameter.api.slh.events.LCSRoutingInfoRequest; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ClientSLhSession extends AppSession, StateMachine { + + /** + * Send LCS-Routing-Info-Request to server + * + * @param request LCS-Routing-Info-Request event instance + * @throws InternalException The InternalException signals that internal error is occurred. + * @throws IllegalDiameterStateException The IllegalStateException signals that session has incorrect state (invalid). + * @throws RouteException The NoRouteException signals that no route exist for a given realm. + * @throws OverloadException The OverloadException signals that destination host is overloaded. + */ + + void sendLCSRoutingInfoRequest(LCSRoutingInfoRequest request) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ClientSLhSessionListener.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ClientSLhSessionListener.java new file mode 100644 index 000000000..4e3330d60 --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ClientSLhSessionListener.java @@ -0,0 +1,48 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slh; + +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppAnswerEvent; +import org.jdiameter.api.app.AppRequestEvent; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.slh.events.LCSRoutingInfoAnswer; +import org.jdiameter.api.slh.events.LCSRoutingInfoRequest; + + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ClientSLhSessionListener { + + void doOtherEvent(AppSession session, AppRequestEvent request, AppAnswerEvent answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + + void doLCSRoutingInfoAnswerEvent(ClientSLhSession session, LCSRoutingInfoRequest request, LCSRoutingInfoAnswer answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ServerSLhSession.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ServerSLhSession.java new file mode 100644 index 000000000..8e5bc76fd --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ServerSLhSession.java @@ -0,0 +1,51 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slh; + +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.app.StateMachine; +import org.jdiameter.api.slh.events.LCSRoutingInfoAnswer; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ServerSLhSession extends AppSession, StateMachine { + + /** + * Send LCS-Routing-Info-Answer to client + * + * @param answer LCS-Routing-Info-Answer event instance + * @throws InternalException The InternalException signals that internal error is occurred. + * @throws IllegalDiameterStateException The IllegalStateException signals that session has incorrect state (invalid). + * @throws RouteException The NoRouteException signals that no route exist for a given realm. + * @throws OverloadException The OverloadException signals that destination host is overloaded. + */ + void sendLCSRoutingInfoAnswer(LCSRoutingInfoAnswer answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ServerSLhSessionListener.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ServerSLhSessionListener.java new file mode 100644 index 000000000..23203d588 --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/ServerSLhSessionListener.java @@ -0,0 +1,46 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slh; + +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppAnswerEvent; +import org.jdiameter.api.app.AppRequestEvent; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.slh.events.LCSRoutingInfoRequest; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ServerSLhSessionListener { + + void doOtherEvent(AppSession session, AppRequestEvent request, AppAnswerEvent answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + + void doLCSRoutingInfoRequestEvent(ServerSLhSession session, LCSRoutingInfoRequest request) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException; + +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/events/LCSRoutingInfoAnswer.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/events/LCSRoutingInfoAnswer.java new file mode 100644 index 000000000..abae89135 --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/events/LCSRoutingInfoAnswer.java @@ -0,0 +1,46 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slh.events; + +import org.jdiameter.api.app.AppAnswerEvent; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +/* + * As for 3GPP TS 29.173 v13.0.0, the LCS-Routing-Info-Answer (RIA) command, indicated by the Command-Code field set to 8388622 + * and the "R" bit cleared in the Command Flags field, is sent from HSS to GMLC. The procedure invoked by the GMLC is used for + * retrieving routing information for LCS (Location Services) for a specified user from the HSS via a LCS-Routing-Info-Request + * (RIR) command. + * + */ + +public interface LCSRoutingInfoAnswer extends AppAnswerEvent { + + public static final String _SHORT_NAME = "RIA"; + public static final String _LONG_NAME = "LCS-Routing-Info-Answer"; + + public static final int code = 8388622; + +} diff --git a/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/events/LCSRoutingInfoRequest.java b/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/events/LCSRoutingInfoRequest.java new file mode 100644 index 000000000..86b4a39d3 --- /dev/null +++ b/core/jdiameter/api/src/main/java/org/jdiameter/api/slh/events/LCSRoutingInfoRequest.java @@ -0,0 +1,45 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.api.slh.events; + +import org.jdiameter.api.app.AppRequestEvent; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +/* + * As for 3GPP TS 29.173 v13.0.0, the LCS-Routing-Info-Request (RIR) command, indicated by the Command-Code field set to 8388622 + * and the "R" bit set in the Command Flags field, is sent from GMLC to HSS. The procedure invoked by the GMLC is used for + * retrieving routing information for LCS (Location Services) for a specified user from the HSS. + * + */ + +public interface LCSRoutingInfoRequest extends AppRequestEvent { + + public static final String _SHORT_NAME = "RIR"; + public static final String _LONG_NAME = "LCS-Routing-Info-Request"; + + public static final int code = 8388622; + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/ClientSLgSessionDataLocalImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/ClientSLgSessionDataLocalImpl.java new file mode 100644 index 000000000..682247061 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/ClientSLgSessionDataLocalImpl.java @@ -0,0 +1,34 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.client.impl.app.slg; + +import org.jdiameter.common.impl.app.slg.SLgLocalSessionDataImpl; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class ClientSLgSessionDataLocalImpl extends SLgLocalSessionDataImpl implements IClientSLgSessionData { + public ClientSLgSessionDataLocalImpl() { + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/Event.java b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/Event.java new file mode 100644 index 000000000..9112ecbb2 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/Event.java @@ -0,0 +1,86 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.client.impl.app.slg; + +import org.jdiameter.api.InternalException; +import org.jdiameter.api.app.AppEvent; +import org.jdiameter.api.app.StateEvent; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class Event implements StateEvent { + + enum Type { + SEND_MESSAGE, TIMEOUT_EXPIRES, RECEIVE_PLA, RECEIVE_LRA; + } + + AppEvent request; + AppEvent answer; + Type type; + + Event(Type type, AppEvent request, AppEvent answer) { + this.type = type; + this.answer = answer; + this.request = request; + } + + @SuppressWarnings("unchecked") + public E encodeType(Class eClass) { + return eClass == Type.class ? (E) type : null; + } + + @SuppressWarnings("rawtypes") + public Enum getType() { + return type; + } + + public AppEvent getRequest() { + return request; + } + + public AppEvent getAnswer() { + return answer; + } + + public int compareTo(Object o) { + return 0; + } + + public Object getData() { + return request != null ? request : answer; + } + + public void setData(Object data) { + try { + if (((AppEvent) data).getMessage().isRequest()) { + request = (AppEvent) data; + } else { + answer = (AppEvent) data; + } + } catch (InternalException e) { + throw new IllegalArgumentException(e); + } + } +} \ No newline at end of file diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/IClientSLgSessionData.java b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/IClientSLgSessionData.java new file mode 100644 index 000000000..618c51d53 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/IClientSLgSessionData.java @@ -0,0 +1,33 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.client.impl.app.slg; + +import org.jdiameter.common.api.app.slg.ISLgSessionData; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface IClientSLgSessionData extends ISLgSessionData { + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/SLgClientSessionImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/SLgClientSessionImpl.java new file mode 100644 index 000000000..35ebd5c69 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slg/SLgClientSessionImpl.java @@ -0,0 +1,341 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.client.impl.app.slg; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +import org.jdiameter.api.Answer; +import org.jdiameter.api.EventListener; +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.NetworkReqListener; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.Request; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppEvent; +import org.jdiameter.api.app.StateChangeListener; +import org.jdiameter.api.app.StateEvent; +import org.jdiameter.api.slg.ClientSLgSession; +import org.jdiameter.api.slg.ClientSLgSessionListener; +import org.jdiameter.api.slg.events.LocationReportAnswer; +import org.jdiameter.api.slg.events.LocationReportRequest; +import org.jdiameter.api.slg.events.ProvideLocationAnswer; +import org.jdiameter.api.slg.events.ProvideLocationRequest; +import org.jdiameter.client.api.ISessionFactory; +import org.jdiameter.client.impl.app.slg.Event.Type; +import org.jdiameter.common.api.app.slg.ISLgMessageFactory; +import org.jdiameter.common.api.app.slg.SLgSessionState; +import org.jdiameter.common.impl.app.AppAnswerEventImpl; +import org.jdiameter.common.impl.app.AppRequestEventImpl; +import org.jdiameter.common.impl.app.slg.SLgSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class SLgClientSessionImpl extends SLgSession + implements ClientSLgSession, EventListener, NetworkReqListener { + + private static final Logger logger = LoggerFactory.getLogger(SLgClientSessionImpl.class); + + private transient ClientSLgSessionListener listener; + + protected long appId = -1; + protected IClientSLgSessionData sessionData; + + public SLgClientSessionImpl(IClientSLgSessionData sessionData, ISLgMessageFactory fct, ISessionFactory sf, + ClientSLgSessionListener lst) { + super(sf, sessionData); + if (lst == null) { + throw new IllegalArgumentException("Listener can not be null"); + } + if (fct.getApplicationId() < 0) { + throw new IllegalArgumentException("ApplicationId can not be less than zero"); + } + + this.appId = fct.getApplicationId(); + this.listener = lst; + super.messageFactory = fct; + this.sessionData = sessionData; + } + + @SuppressWarnings("unchecked") + public E getState(Class stateType) { + return stateType == SLgSessionState.class ? (E) this.sessionData.getSLgSessionState() : null; + } + + public Answer processRequest(Request request) { + RequestDelivery rd = new RequestDelivery(); + rd.session = this; + rd.request = request; + super.scheduler.execute(rd); + return null; + } + + public void sendProvideLocationRequest(ProvideLocationRequest request) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + send(Event.Type.SEND_MESSAGE, request, null); + } + + public void sendLocationReportRequest(LocationReportRequest request) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + send(Event.Type.SEND_MESSAGE, request, null); + } + + public void receivedSuccessMessage(Request request, Answer answer) { + AnswerDelivery rd = new AnswerDelivery(); + rd.session = this; + rd.request = request; + rd.answer = answer; + super.scheduler.execute(rd); + } + + public void timeoutExpired(Request request) { + try { + handleEvent(new Event(Event.Type.TIMEOUT_EXPIRES, new AppRequestEventImpl(request), null)); + } catch (Exception e) { + logger.debug("Failed to process timeout message", e); + } + } + + protected void send(Event.Type type, AppEvent request, AppEvent answer) throws InternalException { + try { + if (type != null) { + handleEvent(new Event(type, request, answer)); + } + } catch (Exception e) { + throw new InternalException(e); + } + } + + public boolean handleEvent(StateEvent event) throws InternalException, OverloadException { + try { + sendAndStateLock.lock(); + if (!super.session.isValid()) { + // FIXME: throw new InternalException("Generic session is not valid."); + return false; + } + final SLgSessionState state = this.sessionData.getSLgSessionState(); + SLgSessionState newState = null; + Event localEvent = (Event) event; + Event.Type eventType = (Type) event.getType(); + switch (state) { + + case IDLE: + switch (eventType) { + + case SEND_MESSAGE: + newState = SLgSessionState.MESSAGE_SENT_RECEIVED; + super.session.send(((AppEvent) event.getData()).getMessage(), this); + setState(newState); // FIXME: is this ok to be here? + break; + + default: + logger.error("Invalid Event Type {} for SLg Client Session at state {}.", eventType, + sessionData.getSLgSessionState()); + break; + } + break; + + case MESSAGE_SENT_RECEIVED: + switch (eventType) { + case TIMEOUT_EXPIRES: + newState = SLgSessionState.TIMEDOUT; + setState(newState); + break; + + case SEND_MESSAGE: + try { + super.session.send(((AppEvent) event.getData()).getMessage(), this); + } finally { + newState = SLgSessionState.TERMINATED; + setState(newState); + } + break; + + case RECEIVE_PLA: + newState = SLgSessionState.TERMINATED; + setState(newState); + super.cancelMsgTimer(); + listener.doProvideLocationAnswerEvent(this, (ProvideLocationRequest) localEvent.getRequest(), + (ProvideLocationAnswer) localEvent.getAnswer()); + break; + + case RECEIVE_LRA: + newState = SLgSessionState.TERMINATED; + setState(newState); + super.cancelMsgTimer(); + listener.doLocationReportAnswerEvent(this, (LocationReportRequest) localEvent.getRequest(), + (LocationReportAnswer) localEvent.getAnswer()); + break; + + default: + throw new InternalException("Unexpected/Unknown message received: " + event.getData()); + } + break; + + case TERMINATED: + throw new InternalException("Cant receive message in state TERMINATED. Command: " + event.getData()); + + case TIMEDOUT: + throw new InternalException("Cant receive message in state TIMEDOUT. Command: " + event.getData()); + + default: + logger.error("SLg Client FSM in wrong state: {}", state); + break; + } + } catch (Exception e) { + throw new InternalException(e); + } finally { + sendAndStateLock.unlock(); + } + return true; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected void setState(SLgSessionState newState) { + SLgSessionState oldState = this.sessionData.getSLgSessionState(); + this.sessionData.setSLgSessionState(newState); + + for (StateChangeListener i : stateListeners) { + i.stateChanged(this, (Enum) oldState, (Enum) newState); + } + if (newState == SLgSessionState.TERMINATED || newState == SLgSessionState.TIMEDOUT) { + super.cancelMsgTimer(); + this.release(); + } + } + + public void onTimer(String timerName) { + if (timerName.equals(SLgSession.TIMER_NAME_MSG_TIMEOUT)) { + try { + sendAndStateLock.lock(); + try { + handleEvent( + new Event(Event.Type.TIMEOUT_EXPIRES, new AppRequestEventImpl(this.sessionData.getBuffer()), null)); + } catch (Exception e) { + logger.debug("Failure handling Timeout event."); + } + this.sessionData.setBuffer(null); + this.sessionData.setTsTimerId(null); + } finally { + sendAndStateLock.unlock(); + } + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (int) (appId ^ (appId >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + SLgClientSessionImpl other = (SLgClientSessionImpl) obj; + if (appId != other.appId) { + return false; + } + return true; + } + + @Override + public void release() { + if (isValid()) { + try { + sendAndStateLock.lock(); + super.release(); + } catch (Exception e) { + logger.debug("Failed to release session", e); + } finally { + sendAndStateLock.unlock(); + } + } else { + logger.debug("Trying to release an already invalid session, with Session ID '{}'", getSessionId()); + } + } + + private class RequestDelivery implements Runnable { + ClientSLgSession session; + Request request; + + public void run() { + try { + switch (request.getCommandCode()) { + + default: + listener.doOtherEvent(session, new AppRequestEventImpl(request), null); + break; + } + } catch (Exception e) { + logger.debug("Failed to process request message", e); + } + } + } + + private class AnswerDelivery implements Runnable { + ClientSLgSession session; + Answer answer; + Request request; + + public void run() { + try { + switch (answer.getCommandCode()) { + + case ProvideLocationAnswer.code: + handleEvent(new Event(Event.Type.RECEIVE_PLA, messageFactory.createProvideLocationRequest(request), + messageFactory.createProvideLocationAnswer(answer))); + break; + + case LocationReportAnswer.code: + handleEvent(new Event(Event.Type.RECEIVE_LRA, messageFactory.createLocationReportRequest(request), + messageFactory.createLocationReportAnswer(answer))); + break; + + default: + listener.doOtherEvent(session, new AppRequestEventImpl(request), new AppAnswerEventImpl(answer)); + break; + } + } catch (Exception e) { + logger.debug("Failed to process success message", e); + } + } + } +} \ No newline at end of file diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/ClientSLhSessionDataLocalImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/ClientSLhSessionDataLocalImpl.java new file mode 100644 index 000000000..6029910f8 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/ClientSLhSessionDataLocalImpl.java @@ -0,0 +1,34 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.client.impl.app.slh; + +import org.jdiameter.common.impl.app.slh.SLhLocalSessionDataImpl; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class ClientSLhSessionDataLocalImpl extends SLhLocalSessionDataImpl implements IClientSLhSessionData { + public ClientSLhSessionDataLocalImpl() { + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/Event.java b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/Event.java new file mode 100644 index 000000000..c91422011 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/Event.java @@ -0,0 +1,86 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.client.impl.app.slh; + +import org.jdiameter.api.InternalException; +import org.jdiameter.api.app.AppEvent; +import org.jdiameter.api.app.StateEvent; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class Event implements StateEvent { + + enum Type { + SEND_MESSAGE, TIMEOUT_EXPIRES, RECEIVE_RIA; + } + + AppEvent request; + AppEvent answer; + Type type; + + Event(Type type, AppEvent request, AppEvent answer) { + this.type = type; + this.answer = answer; + this.request = request; + } + + @SuppressWarnings("unchecked") + public E encodeType(Class eClass) { + return eClass == Type.class ? (E) type : null; + } + + @SuppressWarnings("rawtypes") + public Enum getType() { + return type; + } + + public AppEvent getRequest() { + return request; + } + + public AppEvent getAnswer() { + return answer; + } + + public int compareTo(Object o) { + return 0; + } + + public Object getData() { + return request != null ? request : answer; + } + + public void setData(Object data) { + try { + if (((AppEvent) data).getMessage().isRequest()) { + request = (AppEvent) data; + } else { + answer = (AppEvent) data; + } + } catch (InternalException e) { + throw new IllegalArgumentException(e); + } + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/IClientSLhSessionData.java b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/IClientSLhSessionData.java new file mode 100644 index 000000000..59868fae1 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/IClientSLhSessionData.java @@ -0,0 +1,33 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.client.impl.app.slh; + +import org.jdiameter.common.api.app.slh.ISLhSessionData; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface IClientSLhSessionData extends ISLhSessionData { + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/SLhClientSessionImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/SLhClientSessionImpl.java new file mode 100644 index 000000000..4891a9ff2 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/slh/SLhClientSessionImpl.java @@ -0,0 +1,316 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.client.impl.app.slh; + +import org.jdiameter.api.Answer; +import org.jdiameter.api.EventListener; +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.NetworkReqListener; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.Request; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppEvent; +import org.jdiameter.api.app.StateChangeListener; +import org.jdiameter.api.app.StateEvent; +import org.jdiameter.api.slh.ClientSLhSession; +import org.jdiameter.api.slh.ClientSLhSessionListener; +import org.jdiameter.api.slh.events.LCSRoutingInfoRequest; +import org.jdiameter.api.slh.events.LCSRoutingInfoAnswer; +import org.jdiameter.client.api.ISessionFactory; +import org.jdiameter.client.impl.app.slh.Event.Type; +import org.jdiameter.common.api.app.slh.ISLhMessageFactory; +import org.jdiameter.common.api.app.slh.SLhSessionState; +import org.jdiameter.common.impl.app.AppAnswerEventImpl; +import org.jdiameter.common.impl.app.AppRequestEventImpl; +import org.jdiameter.common.impl.app.slh.SLhSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class SLhClientSessionImpl extends SLhSession + implements ClientSLhSession, EventListener, NetworkReqListener { + + private static final Logger logger = LoggerFactory.getLogger(SLhClientSessionImpl.class); + + private transient ClientSLhSessionListener listener; + + protected long appId = -1; + protected IClientSLhSessionData sessionData; + + public SLhClientSessionImpl(IClientSLhSessionData sessionData, ISLhMessageFactory fct, ISessionFactory sf, + ClientSLhSessionListener lst) { + super(sf, sessionData); + if (lst == null) { + throw new IllegalArgumentException("Listener can not be null"); + } + if (fct.getApplicationId() < 0) { + throw new IllegalArgumentException("ApplicationId can not be less than zero"); + } + + this.appId = fct.getApplicationId(); + this.listener = lst; + super.messageFactory = fct; + this.sessionData = sessionData; + } + + @SuppressWarnings("unchecked") + public E getState(Class stateType) { + return stateType == SLhSessionState.class ? (E) this.sessionData.getSLhSessionState() : null; + } + + public Answer processRequest(Request request) { + RequestDelivery rd = new RequestDelivery(); + rd.session = this; + rd.request = request; + super.scheduler.execute(rd); + return null; + } + + public void sendLCSRoutingInfoRequest(LCSRoutingInfoRequest request) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + send(Event.Type.SEND_MESSAGE, request, null); + } + + public void receivedSuccessMessage(Request request, Answer answer) { + AnswerDelivery rd = new AnswerDelivery(); + rd.session = this; + rd.request = request; + rd.answer = answer; + super.scheduler.execute(rd); + } + + public void timeoutExpired(Request request) { + try { + handleEvent(new Event(Event.Type.TIMEOUT_EXPIRES, new AppRequestEventImpl(request), null)); + } catch (Exception e) { + logger.debug("Failed to process timeout message", e); + } + } + + protected void send(Event.Type type, AppEvent request, AppEvent answer) throws InternalException { + try { + if (type != null) { + handleEvent(new Event(type, request, answer)); + } + } catch (Exception e) { + throw new InternalException(e); + } + } + + public boolean handleEvent(StateEvent event) throws InternalException, OverloadException { + try { + sendAndStateLock.lock(); + if (!super.session.isValid()) { + // FIXME: throw new InternalException("Generic session is not valid."); + return false; + } + final SLhSessionState state = this.sessionData.getSLhSessionState(); + SLhSessionState newState = null; + Event localEvent = (Event) event; + Event.Type eventType = (Type) event.getType(); + switch (state) { + + case IDLE: + switch (eventType) { + + case SEND_MESSAGE: + newState = SLhSessionState.MESSAGE_SENT_RECEIVED; + super.session.send(((AppEvent) event.getData()).getMessage(), this); + setState(newState); // FIXME: is this ok to be here? + break; + + default: + logger.error("Invalid Event Type {} for SLh Client Session at state {}.", eventType, + sessionData.getSLhSessionState()); + break; + } + break; + + case MESSAGE_SENT_RECEIVED: + switch (eventType) { + case TIMEOUT_EXPIRES: + newState = SLhSessionState.TIMEDOUT; + setState(newState); + break; + + case SEND_MESSAGE: + try { + super.session.send(((AppEvent) event.getData()).getMessage(), this); + } finally { + newState = SLhSessionState.TERMINATED; + setState(newState); + } + break; + + case RECEIVE_RIA: + newState = SLhSessionState.TERMINATED; + setState(newState); + super.cancelMsgTimer(); + listener.doLCSRoutingInfoAnswerEvent(this, (LCSRoutingInfoRequest) localEvent.getRequest(), + (LCSRoutingInfoAnswer) localEvent.getAnswer()); + break; + + default: + throw new InternalException("Unexpected/Unknown message received: " + event.getData()); + } + break; + + case TERMINATED: + throw new InternalException("Cant receive message in state TERMINATED. Command: " + event.getData()); + + case TIMEDOUT: + throw new InternalException("Cant receive message in state TIMEDOUT. Command: " + event.getData()); + + default: + logger.error("SLh Client FSM in wrong state: {}", state); + break; + } + } catch (Exception e) { + throw new InternalException(e); + } finally { + sendAndStateLock.unlock(); + } + return true; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected void setState(SLhSessionState newState) { + SLhSessionState oldState = this.sessionData.getSLhSessionState(); + this.sessionData.setSLhSessionState(newState); + + for (StateChangeListener i : stateListeners) { + i.stateChanged(this, (Enum) oldState, (Enum) newState); + } + if (newState == SLhSessionState.TERMINATED || newState == SLhSessionState.TIMEDOUT) { + super.cancelMsgTimer(); + this.release(); + } + } + + public void onTimer(String timerName) { + if (timerName.equals(SLhSession.TIMER_NAME_MSG_TIMEOUT)) { + try { + sendAndStateLock.lock(); + try { + handleEvent( + new Event(Event.Type.TIMEOUT_EXPIRES, new AppRequestEventImpl(this.sessionData.getBuffer()), null)); + } catch (Exception e) { + logger.debug("Failure handling Timeout event."); + } + this.sessionData.setBuffer(null); + this.sessionData.setTsTimerId(null); + } finally { + sendAndStateLock.unlock(); + } + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (int) (appId ^ (appId >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + SLhClientSessionImpl other = (SLhClientSessionImpl) obj; + if (appId != other.appId) { + return false; + } + return true; + } + + @Override + public void release() { + if (isValid()) { + try { + sendAndStateLock.lock(); + super.release(); + } catch (Exception e) { + logger.debug("Failed to release session", e); + } finally { + sendAndStateLock.unlock(); + } + } else { + logger.debug("Trying to release an already invalid session, with Session ID '{}'", getSessionId()); + } + } + + private class RequestDelivery implements Runnable { + ClientSLhSession session; + Request request; + + public void run() { + try { + switch (request.getCommandCode()) { + + default: + listener.doOtherEvent(session, new AppRequestEventImpl(request), null); + break; + } + } catch (Exception e) { + logger.debug("Failed to process request message", e); + } + } + } + + private class AnswerDelivery implements Runnable { + ClientSLhSession session; + Answer answer; + Request request; + + public void run() { + try { + switch (answer.getCommandCode()) { + + case LCSRoutingInfoAnswer.code: + handleEvent(new Event(Event.Type.RECEIVE_RIA, messageFactory.createLCSRoutingInfoRequest(request), + messageFactory.createLCSRoutingInfoAnswer(answer))); + break; + + default: + listener.doOtherEvent(session, new AppRequestEventImpl(request), new AppAnswerEventImpl(answer)); + break; + } + } catch (Exception e) { + logger.debug("Failed to process success message", e); + } + } + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/ISLgMessageFactory.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/ISLgMessageFactory.java new file mode 100644 index 000000000..bec720448 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/ISLgMessageFactory.java @@ -0,0 +1,52 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.api.app.slg; + +import org.jdiameter.api.Answer; +import org.jdiameter.api.Request; +import org.jdiameter.api.slg.events.LocationReportAnswer; +import org.jdiameter.api.slg.events.LocationReportRequest; +import org.jdiameter.api.slg.events.ProvideLocationAnswer; +import org.jdiameter.api.slg.events.ProvideLocationRequest; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ISLgMessageFactory { + + ProvideLocationRequest createProvideLocationRequest(Request request); + + ProvideLocationAnswer createProvideLocationAnswer(Answer answer); + + LocationReportRequest createLocationReportRequest(Request request); + + LocationReportAnswer createLocationReportAnswer(Answer answer); + + /** + * Returns the Application-Id that this message factory is related to + * + * @return the Application-Id value + */ + long getApplicationId(); +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/ISLgSessionData.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/ISLgSessionData.java new file mode 100644 index 000000000..e45d48369 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/ISLgSessionData.java @@ -0,0 +1,48 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.api.app.slg; + +import java.io.Serializable; + +import org.jdiameter.api.Request; +import org.jdiameter.common.api.app.IAppSessionData; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ISLgSessionData extends IAppSessionData { + + public void setSLgSessionState(SLgSessionState state); + + public SLgSessionState getSLgSessionState(); + + public Serializable getTsTimerId(); + + public void setTsTimerId(Serializable tid); + + public void setBuffer(Request buffer); + + public Request getBuffer(); + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/ISLgSessionFactory.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/ISLgSessionFactory.java new file mode 100644 index 000000000..82680f0a6 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/ISLgSessionFactory.java @@ -0,0 +1,88 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.api.app.slg; + +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.app.StateChangeListener; +import org.jdiameter.api.slg.ClientSLgSessionListener; +import org.jdiameter.api.slg.ServerSLgSessionListener; +import org.jdiameter.common.api.app.slg.ISLgMessageFactory; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ISLgSessionFactory { + + /** + * Get stack wide listener for sessions. In local mode it has similar effect as setting this directly in app session. + * However clustered session use this value when recreated! + * + * @return the serverSessionListener + */ + public ServerSLgSessionListener getServerSessionListener(); + + /** + * Set stack wide listener for sessions. In local mode it has similar effect as setting this directly in app session. + * However clustered session use this value when recreated! + * + * @param serverSessionListener the serverSessionListener to set + */ + public void setServerSessionListener(ServerSLgSessionListener serverSessionListener); + + /** + * Get stack wide listener for sessions. In local mode it has similar effect as setting this directly in app session. + * However clustered session use this value when recreated! + * + * @return the clientSessionListener + */ + public ClientSLgSessionListener getClientSessionListener(); + + /** + * Set stack wide listener for sessions. In local mode it has similar effect as setting this directly in app session. + * However clustered session use this value when recreated! + * + * @param clientSessionListener the clientSessionListener to set + */ + public void setClientSessionListener(ClientSLgSessionListener clientSessionListener); + + /** + * @return the messageFactory + */ + public ISLgMessageFactory getMessageFactory(); + + /** + * @param messageFactory the messageFactory to set + */ + public void setMessageFactory(ISLgMessageFactory messageFactory); + + /** + * @return the stateListener + */ + public StateChangeListener getStateListener(); + + /** + * @param stateListener the stateListener to set + */ + public void setStateListener(StateChangeListener stateListener); +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/SLgSessionState.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/SLgSessionState.java new file mode 100644 index 000000000..67ac8d337 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slg/SLgSessionState.java @@ -0,0 +1,33 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.api.app.slg; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public enum SLgSessionState { + + IDLE, MESSAGE_SENT_RECEIVED, TERMINATED, TIMEDOUT; + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/ISLhMessageFactory.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/ISLhMessageFactory.java new file mode 100644 index 000000000..cde960644 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/ISLhMessageFactory.java @@ -0,0 +1,47 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.api.app.slh; + +import org.jdiameter.api.Answer; +import org.jdiameter.api.Request; +import org.jdiameter.api.slh.events.LCSRoutingInfoAnswer; +import org.jdiameter.api.slh.events.LCSRoutingInfoRequest; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ISLhMessageFactory { + + LCSRoutingInfoRequest createLCSRoutingInfoRequest(Request request); + + LCSRoutingInfoAnswer createLCSRoutingInfoAnswer(Answer answer); + + /** + * Returns the Application-Id that this message factory is related to + * + * @return the Application-Id value + */ + long getApplicationId(); + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/ISLhSessionData.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/ISLhSessionData.java new file mode 100644 index 000000000..1345d9a7a --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/ISLhSessionData.java @@ -0,0 +1,48 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.api.app.slh; + +import java.io.Serializable; + +import org.jdiameter.api.Request; +import org.jdiameter.common.api.app.IAppSessionData; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ISLhSessionData extends IAppSessionData { + + public void setSLhSessionState(SLhSessionState state); + + public SLhSessionState getSLhSessionState(); + + public Serializable getTsTimerId(); + + public void setTsTimerId(Serializable tid); + + public void setBuffer(Request buffer); + + public Request getBuffer(); + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/ISLhSessionFactory.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/ISLhSessionFactory.java new file mode 100644 index 000000000..e663e8461 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/ISLhSessionFactory.java @@ -0,0 +1,90 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.api.app.slh; + +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.app.StateChangeListener; +import org.jdiameter.api.slh.ClientSLhSessionListener; +import org.jdiameter.api.slh.ServerSLhSessionListener; +import org.jdiameter.common.api.app.IAppSessionFactory; +import org.jdiameter.common.api.app.slh.ISLhMessageFactory; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface ISLhSessionFactory extends IAppSessionFactory { + + /** + * Get stack wide listener for sessions. In local mode it has similar effect + * as setting this directly in app session. However clustered session use this value when recreated! + * + * @return the serverSessionListener + */ + public ServerSLhSessionListener getServerSessionListener(); + + /** + * Set stack wide listener for sessions. In local mode it has similar effect + * as setting this directly in app session. However clustered session use this value when recreated! + * + * @param serverSessionListener the serverSessionListener to set + */ + public void setServerSessionListener(ServerSLhSessionListener serverSessionListener); + + /** + * Get stack wide listener for sessions. In local mode it has similar effect + * as setting this directly in app session. However clustered session use this value when recreated! + * + * @return the clientSessionListener + */ + public ClientSLhSessionListener getClientSessionListener(); + + /** + * Set stack wide listener for sessions. In local mode it has similar effect + * as setting this directly in app session. However clustered session use this value when recreated! + * + * @param clientSessionListener the clientSessionListener to set + */ + public void setClientSessionListener(ClientSLhSessionListener clientSessionListener); + + /** + * @return the messageFactory + */ + public ISLhMessageFactory getMessageFactory(); + + /** + * @param messageFactory the messageFactory to set + */ + public void setMessageFactory(ISLhMessageFactory messageFactory); + + /** + * @return the stateListener + */ + public StateChangeListener getStateListener(); + + /** + * @param stateListener the stateListener to set + */ + public void setStateListener(StateChangeListener stateListener); + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/SLhSessionState.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/SLhSessionState.java new file mode 100644 index 000000000..a72573b77 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/api/app/slh/SLhSessionState.java @@ -0,0 +1,33 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.api.app.slh; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public enum SLhSessionState { + + IDLE, MESSAGE_SENT_RECEIVED, TERMINATED, TIMEDOUT; + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/LocationReportAnswerImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/LocationReportAnswerImpl.java new file mode 100644 index 000000000..f64f4af2b --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/LocationReportAnswerImpl.java @@ -0,0 +1,53 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slg; + +import org.jdiameter.api.Avp; +import org.jdiameter.api.AvpDataException; +import org.jdiameter.api.Message; +import org.jdiameter.api.slg.events.LocationReportAnswer; +import org.jdiameter.common.impl.app.AppRequestEventImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class LocationReportAnswerImpl extends AppRequestEventImpl implements LocationReportAnswer { + + private static final long serialVersionUID = 1L; + + protected final static Logger logger = LoggerFactory.getLogger(LocationReportAnswerImpl.class); + + public LocationReportAnswerImpl(Message message) { + super(message); + message.setRequest(true); + } + + public Avp getResultCodeAvp() throws AvpDataException { + return null; + } + + /*** TODO ***/ +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/LocationReportRequestImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/LocationReportRequestImpl.java new file mode 100644 index 000000000..90fc76d04 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/LocationReportRequestImpl.java @@ -0,0 +1,50 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slg; + +import org.jdiameter.api.Avp; +import org.jdiameter.api.AvpDataException; +import org.jdiameter.api.Message; +import org.jdiameter.api.slg.events.LocationReportRequest; +import org.jdiameter.common.impl.app.AppRequestEventImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class LocationReportRequestImpl extends AppRequestEventImpl implements LocationReportRequest { + + private static final long serialVersionUID = 1L; + + protected final static Logger logger = LoggerFactory.getLogger(LocationReportRequestImpl.class); + + public LocationReportRequestImpl(Message message) { + super(message); + message.setRequest(true); + } + + /*** TODO ***/ + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/ProvideLocationAnswerImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/ProvideLocationAnswerImpl.java new file mode 100644 index 000000000..ebbcac433 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/ProvideLocationAnswerImpl.java @@ -0,0 +1,54 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slg; + +import org.jdiameter.api.Avp; +import org.jdiameter.api.AvpDataException; +import org.jdiameter.api.Message; +import org.jdiameter.api.slg.events.ProvideLocationAnswer; +import org.jdiameter.common.impl.app.AppRequestEventImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class ProvideLocationAnswerImpl extends AppRequestEventImpl implements ProvideLocationAnswer { + + private static final long serialVersionUID = 1L; + + protected final static Logger logger = LoggerFactory.getLogger(ProvideLocationRequestImpl.class); + + public ProvideLocationAnswerImpl(Message message) { + super(message); + message.setRequest(true); + } + + public Avp getResultCodeAvp() throws AvpDataException { + return null; + } + + /*** TODO ***/ + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/ProvideLocationRequestImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/ProvideLocationRequestImpl.java new file mode 100644 index 000000000..51988fb80 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/ProvideLocationRequestImpl.java @@ -0,0 +1,49 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slg; + +import org.jdiameter.api.Avp; +import org.jdiameter.api.AvpDataException; +import org.jdiameter.api.Message; +import org.jdiameter.api.slg.events.ProvideLocationRequest; +import org.jdiameter.common.impl.app.AppRequestEventImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class ProvideLocationRequestImpl extends AppRequestEventImpl implements ProvideLocationRequest { + + private static final long serialVersionUID = 1L; + + protected final static Logger logger = LoggerFactory.getLogger(ProvideLocationRequestImpl.class); + + public ProvideLocationRequestImpl(Message message) { + super(message); + message.setRequest(true); + } + + /*** TODO ***/ +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgLocalSessionDataFactory.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgLocalSessionDataFactory.java new file mode 100644 index 000000000..68faaf562 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgLocalSessionDataFactory.java @@ -0,0 +1,52 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slg; + +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.slg.ClientSLgSession; +import org.jdiameter.api.slg.ServerSLgSession; +import org.jdiameter.client.impl.app.slg.ClientSLgSessionDataLocalImpl; +import org.jdiameter.common.api.app.IAppSessionDataFactory; +import org.jdiameter.common.api.app.slg.ISLgSessionData; +import org.jdiameter.server.impl.app.slg.ServerSLgSessionDataLocalImpl; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class SLgLocalSessionDataFactory implements IAppSessionDataFactory { + + public ISLgSessionData getAppSessionData(Class clazz, String sessionId) { + if (clazz.equals(ClientSLgSession.class)) { + ClientSLgSessionDataLocalImpl data = new ClientSLgSessionDataLocalImpl(); + data.setSessionId(sessionId); + return data; + } else if (clazz.equals(ServerSLgSession.class)) { + ServerSLgSessionDataLocalImpl data = new ServerSLgSessionDataLocalImpl(); + data.setSessionId(sessionId); + return data; + } else { + throw new IllegalArgumentException("Invalid Session Class: " + clazz.toString()); + } + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgLocalSessionDataImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgLocalSessionDataImpl.java new file mode 100644 index 000000000..d2cdc7d55 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgLocalSessionDataImpl.java @@ -0,0 +1,65 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slg; + +import java.io.Serializable; + +import org.jdiameter.api.Request; +import org.jdiameter.common.api.app.AppSessionDataLocalImpl; +import org.jdiameter.common.api.app.slg.ISLgSessionData; +import org.jdiameter.common.api.app.slg.SLgSessionState; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class SLgLocalSessionDataImpl extends AppSessionDataLocalImpl implements ISLgSessionData { + + protected SLgSessionState state = SLgSessionState.IDLE; + protected Request buffer; + protected Serializable tsTimerId; + + public void setSLgSessionState(SLgSessionState state) { + this.state = state; + } + + public SLgSessionState getSLgSessionState() { + return this.state; + } + + public Serializable getTsTimerId() { + return this.tsTimerId; + } + + public void setTsTimerId(Serializable tid) { + this.tsTimerId = tid; + } + + public void setBuffer(Request buffer) { + this.buffer = buffer; + } + + public Request getBuffer() { + return this.buffer; + } +} \ No newline at end of file diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgSession.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgSession.java new file mode 100644 index 000000000..9db0b5baa --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgSession.java @@ -0,0 +1,134 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slg; + +import java.io.Serializable; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import org.jdiameter.api.NetworkReqListener; +import org.jdiameter.api.app.StateChangeListener; +import org.jdiameter.api.app.StateMachine; +import org.jdiameter.client.api.ISessionFactory; +import org.jdiameter.common.impl.app.AppSessionImpl; +import org.jdiameter.common.api.app.slg.ISLgMessageFactory; +import org.jdiameter.common.api.app.slg.ISLgSessionData; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public abstract class SLgSession extends AppSessionImpl implements NetworkReqListener, StateMachine { + + public static final int _TX_TIMEOUT = 30 * 1000; + + protected Lock sendAndStateLock = new ReentrantLock(); + + @SuppressWarnings("rawtypes") + protected transient List stateListeners = new CopyOnWriteArrayList(); + protected transient ISLgMessageFactory messageFactory; + + protected static final String TIMER_NAME_MSG_TIMEOUT = "MSG_TIMEOUT"; + protected ISLgSessionData sessionData; + + public SLgSession(ISessionFactory sf, ISLgSessionData sessionData) { + super(sf, sessionData); + this.sessionData = sessionData; + } + + @SuppressWarnings("rawtypes") + public void addStateChangeNotification(StateChangeListener listener) { + if (!stateListeners.contains(listener)) { + stateListeners.add(listener); + } + } + + @SuppressWarnings("rawtypes") + public void removeStateChangeNotification(StateChangeListener listener) { + stateListeners.remove(listener); + } + + public boolean isStateless() { + return true; + } + + @Override + public boolean isReplicable() { + return false; + } + + protected void startMsgTimer() { + try { + sendAndStateLock.lock(); + sessionData.setTsTimerId(super.timerFacility.schedule(getSessionId(), TIMER_NAME_MSG_TIMEOUT, _TX_TIMEOUT)); + } finally { + sendAndStateLock.unlock(); + } + } + + protected void cancelMsgTimer() { + try { + sendAndStateLock.lock(); + final Serializable timerId = this.sessionData.getTsTimerId(); + if (timerId == null) { + return; + } + super.timerFacility.cancel(timerId); + this.sessionData.setTsTimerId(null); + } finally { + sendAndStateLock.unlock(); + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((sessionData == null) ? 0 : sessionData.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + SLgSession other = (SLgSession) obj; + if (sessionData == null) { + if (other.sessionData != null) { + return false; + } + } else if (!sessionData.equals(other.sessionData)) { + return false; + } + return true; + } +} \ No newline at end of file diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgSessionFactoryImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgSessionFactoryImpl.java new file mode 100644 index 000000000..a051fe125 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slg/SLgSessionFactoryImpl.java @@ -0,0 +1,291 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slg; + +import org.jdiameter.api.Answer; +import org.jdiameter.api.ApplicationId; +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.Request; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.SessionFactory; +import org.jdiameter.api.app.AppAnswerEvent; +import org.jdiameter.api.app.AppRequestEvent; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.app.StateChangeListener; +import org.jdiameter.api.slg.ClientSLgSession; +import org.jdiameter.api.slg.ClientSLgSessionListener; +import org.jdiameter.api.slg.ServerSLgSession; +import org.jdiameter.api.slg.ServerSLgSessionListener; +import org.jdiameter.api.slg.events.ProvideLocationRequest; +import org.jdiameter.api.slg.events.LocationReportAnswer; +import org.jdiameter.api.slg.events.LocationReportRequest; +import org.jdiameter.api.slg.events.ProvideLocationAnswer; +import org.jdiameter.client.api.ISessionFactory; +import org.jdiameter.client.impl.app.slg.IClientSLgSessionData; +import org.jdiameter.client.impl.app.slg.SLgClientSessionImpl; +import org.jdiameter.common.api.app.IAppSessionDataFactory; +import org.jdiameter.common.api.app.slg.ISLgMessageFactory; +import org.jdiameter.common.api.app.slg.ISLgSessionData; +import org.jdiameter.common.api.app.slg.ISLgSessionFactory; +import org.jdiameter.common.api.data.ISessionDatasource; +import org.jdiameter.server.impl.app.slg.IServerSLgSessionData; +import org.jdiameter.server.impl.app.slg.SLgServerSessionImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class SLgSessionFactoryImpl implements ISLgSessionFactory, ServerSLgSessionListener, ClientSLgSessionListener, + ISLgMessageFactory, StateChangeListener { + + private static final Logger logger = LoggerFactory.getLogger(SLgSessionFactoryImpl.class); + + protected ISessionFactory sessionFactory; + + protected ServerSLgSessionListener serverSessionListener; + protected ClientSLgSessionListener clientSessionListener; + + protected ISLgMessageFactory messageFactory; + protected StateChangeListener stateListener; + protected ISessionDatasource iss; + protected IAppSessionDataFactory sessionDataFactory; + + public SLgSessionFactoryImpl() { + }; + + public SLgSessionFactoryImpl(SessionFactory sessionFactory) { + super(); + init(sessionFactory); + } + + public void init(SessionFactory sessionFactory) { + this.sessionFactory = (ISessionFactory) sessionFactory; + this.iss = this.sessionFactory.getContainer().getAssemblerFacility().getComponentInstance(ISessionDatasource.class); + this.sessionDataFactory = (IAppSessionDataFactory) this.iss.getDataFactory(ISLgSessionData.class); + } + + /** + * @return the serverSessionListener + */ + public ServerSLgSessionListener getServerSessionListener() { + return serverSessionListener != null ? serverSessionListener : this; + } + + /** + * @param serverSessionListener the serverSessionListener to set + */ + public void setServerSessionListener(ServerSLgSessionListener serverSessionListener) { + this.serverSessionListener = serverSessionListener; + } + + /** + * @return the serverSessionListener + */ + public ClientSLgSessionListener getClientSessionListener() { + return clientSessionListener != null ? clientSessionListener : this; + } + + /** + * @param serverSessionListener the serverSessionListener to set + */ + public void setClientSessionListener(ClientSLgSessionListener clientSessionListener) { + this.clientSessionListener = clientSessionListener; + } + + /** + * @return the messageFactory + */ + public ISLgMessageFactory getMessageFactory() { + return messageFactory != null ? messageFactory : this; + } + + /** + * @param messageFactory the messageFactory to set + */ + public void setMessageFactory(ISLgMessageFactory messageFactory) { + this.messageFactory = messageFactory; + } + + /** + * @return the stateListener + */ + public StateChangeListener getStateListener() { + return stateListener != null ? stateListener : this; + } + + /** + * @param stateListener the stateListener to set + */ + public void setStateListener(StateChangeListener stateListener) { + this.stateListener = stateListener; + } + + public AppSession getSession(String sessionId, Class aClass) { + if (sessionId == null) { + throw new IllegalArgumentException("SessionId must not be null"); + } + if (!this.iss.exists(sessionId)) { + return null; + } + AppSession appSession = null; + try { + if (aClass == ServerSLgSession.class) { + IServerSLgSessionData sessionData = (IServerSLgSessionData) this.sessionDataFactory + .getAppSessionData(ServerSLgSession.class, sessionId); + SLgServerSessionImpl serverSession = new SLgServerSessionImpl(sessionData, getMessageFactory(), sessionFactory, + this.getServerSessionListener()); + serverSession.getSessions().get(0).setRequestListener(serverSession); + appSession = serverSession; + } else if (aClass == ClientSLgSession.class) { + IClientSLgSessionData sessionData = (IClientSLgSessionData) this.sessionDataFactory + .getAppSessionData(ClientSLgSession.class, sessionId); + SLgClientSessionImpl clientSession = new SLgClientSessionImpl(sessionData, getMessageFactory(), sessionFactory, + this.getClientSessionListener()); + clientSession.getSessions().get(0).setRequestListener(clientSession); + appSession = clientSession; + } else { + throw new IllegalArgumentException( + "Wrong session class: " + aClass + ". Supported[" + ServerSLgSession.class + "]"); + } + } catch (Exception e) { + logger.error("Failure to obtain new SLg Session.", e); + } + return appSession; + } + + public AppSession getNewSession(String sessionId, Class aClass, ApplicationId applicationId, + Object[] args) { + AppSession appSession = null; + + try { + if (aClass == ServerSLgSession.class) { + if (sessionId == null) { + if (args != null && args.length > 0 && args[0] instanceof Request) { + Request request = (Request) args[0]; + sessionId = request.getSessionId(); + } else { + sessionId = this.sessionFactory.getSessionId(); + } + } + IServerSLgSessionData sessionData = (IServerSLgSessionData) this.sessionDataFactory + .getAppSessionData(ServerSLgSession.class, sessionId); + sessionData.setApplicationId(applicationId); + SLgServerSessionImpl serverSession = new SLgServerSessionImpl(sessionData, getMessageFactory(), sessionFactory, + this.getServerSessionListener()); + + iss.addSession(serverSession); + serverSession.getSessions().get(0).setRequestListener(serverSession); + appSession = serverSession; + } else if (aClass == ClientSLgSession.class) { + if (sessionId == null) { + if (args != null && args.length > 0 && args[0] instanceof Request) { + Request request = (Request) args[0]; + sessionId = request.getSessionId(); + } else { + sessionId = this.sessionFactory.getSessionId(); + } + } + IClientSLgSessionData sessionData = (IClientSLgSessionData) this.sessionDataFactory + .getAppSessionData(ClientSLgSession.class, sessionId); + sessionData.setApplicationId(applicationId); + SLgClientSessionImpl clientSession = new SLgClientSessionImpl(sessionData, getMessageFactory(), sessionFactory, + this.getClientSessionListener()); + + iss.addSession(clientSession); + clientSession.getSessions().get(0).setRequestListener(clientSession); + appSession = clientSession; + } else { + throw new IllegalArgumentException( + "Wrong session class: " + aClass + ". Supported[" + ServerSLgSession.class + "]"); + } + } catch (Exception e) { + logger.error("Failure to obtain new SLg Session.", e); + } + return appSession; + } + + public void stateChanged(Enum oldState, Enum newState) { + logger.info("Diameter SLg Session Factory :: stateChanged :: oldState[{}], newState[{}]", oldState, newState); + } + + public long getApplicationId() { + return 16777255; + } + + public void stateChanged(AppSession source, Enum oldState, Enum newState) { + logger.info("Diameter SLg Session Factory :: stateChanged :: Session, [{}], oldState[{}], newState[{}]", + new Object[] { source, oldState, newState }); + } + + public ProvideLocationRequest createProvideLocationRequest(Request request) { + return new ProvideLocationRequestImpl(request); + } + + public ProvideLocationAnswer createProvideLocationAnswer(Answer answer) { + return new ProvideLocationAnswerImpl(answer); + } + + public void doProvideLocationRequestEvent(ServerSLgSession appSession, ProvideLocationRequest request) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + logger.info("Diameter SLg Session Factory :: doProvideLocationRequestEvent :: appSession[{}], Request[{}]", appSession, + request); + } + + public void doProvideLocationAnswerEvent(ClientSLgSession appSession, ProvideLocationRequest request, + ProvideLocationAnswer answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + logger.info("Diameter SLg Session Factory :: doProvideLocationAnswerEvent :: appSession[{}], Request[{}], Answer[{}]", + new Object[] { appSession, request, answer }); + } + + public LocationReportRequest createLocationReportRequest(Request request) { + return new LocationReportRequestImpl(request); + } + + public LocationReportAnswer createLocationReportAnswer(Answer answer) { + return new LocationReportAnswerImpl(answer); + } + + public void doLocationReportRequestEvent(ServerSLgSession appSession, LocationReportRequest request) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + logger.info("Diameter SLg Session Factory :: doLocationReportRequestEvent :: appSession[{}], Request[{}]", appSession, + request); + } + + public void doLocationReportAnswerEvent(ClientSLgSession appSession, LocationReportRequest request, + LocationReportAnswer answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + logger.info("Diameter SLg Session Factory :: doLocationReportAnswerEvent :: appSession[{}], Request[{}], Answer[{}]", + new Object[] { appSession, request, answer }); + } + + public void doOtherEvent(AppSession appSession, AppRequestEvent request, AppAnswerEvent answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + logger.info("Diameter SLg Session Factory :: doOtherEvent :: appSession[{}], Request[{}], Answer[{}]", + new Object[] { appSession, request, answer }); + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/LCSRoutingInfoAnswerImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/LCSRoutingInfoAnswerImpl.java new file mode 100644 index 000000000..955f42abc --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/LCSRoutingInfoAnswerImpl.java @@ -0,0 +1,55 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slh; + +import org.jdiameter.api.Avp; +import org.jdiameter.api.AvpDataException; +import org.jdiameter.api.slh.events.LCSRoutingInfoAnswer; +import org.jdiameter.api.slh.events.LCSRoutingInfoRequest; +import org.jdiameter.common.impl.app.AppRequestEventImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.jdiameter.api.Message; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class LCSRoutingInfoAnswerImpl extends AppRequestEventImpl implements LCSRoutingInfoAnswer { + + private static final long serialVersionUID = 1L; + + protected final static Logger logger = LoggerFactory.getLogger(LCSRoutingInfoAnswer.class); + + public LCSRoutingInfoAnswerImpl(Message message) { + super(message); + message.setRequest(true); + } + + public Avp getResultCodeAvp() throws AvpDataException { + return null; + } + + /*** TODO ***/ + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/LCSRoutingInfoRequestImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/LCSRoutingInfoRequestImpl.java new file mode 100644 index 000000000..303fe53af --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/LCSRoutingInfoRequestImpl.java @@ -0,0 +1,48 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slh; + +import org.jdiameter.api.slh.events.LCSRoutingInfoRequest; +import org.jdiameter.common.impl.app.AppRequestEventImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.jdiameter.api.Message; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class LCSRoutingInfoRequestImpl extends AppRequestEventImpl implements LCSRoutingInfoRequest { + + private static final long serialVersionUID = 1L; + + protected final static Logger logger = LoggerFactory.getLogger(LCSRoutingInfoRequestImpl.class); + + public LCSRoutingInfoRequestImpl(Message message) { + super(message); + message.setRequest(true); + } + + /*** TODO ***/ + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhLocalSessionDataFactory.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhLocalSessionDataFactory.java new file mode 100644 index 000000000..cb4d67ebe --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhLocalSessionDataFactory.java @@ -0,0 +1,52 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slh; + +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.slh.ClientSLhSession; +import org.jdiameter.api.slh.ServerSLhSession; +import org.jdiameter.client.impl.app.slh.ClientSLhSessionDataLocalImpl; +import org.jdiameter.common.api.app.IAppSessionDataFactory; +import org.jdiameter.common.api.app.slh.ISLhSessionData; +import org.jdiameter.server.impl.app.slh.ServerSLhSessionDataLocalImpl; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class SLhLocalSessionDataFactory implements IAppSessionDataFactory { + + public ISLhSessionData getAppSessionData(Class clazz, String sessionId) { + if (clazz.equals(ClientSLhSession.class)) { + ClientSLhSessionDataLocalImpl data = new ClientSLhSessionDataLocalImpl(); + data.setSessionId(sessionId); + return data; + } else if (clazz.equals(ServerSLhSession.class)) { + ServerSLhSessionDataLocalImpl data = new ServerSLhSessionDataLocalImpl(); + data.setSessionId(sessionId); + return data; + } else { + throw new IllegalArgumentException("Invalid Session Class: " + clazz.toString()); + } + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhLocalSessionDataImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhLocalSessionDataImpl.java new file mode 100644 index 000000000..cd5e2107f --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhLocalSessionDataImpl.java @@ -0,0 +1,65 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slh; + +import java.io.Serializable; + +import org.jdiameter.api.Request; +import org.jdiameter.common.api.app.AppSessionDataLocalImpl; +import org.jdiameter.common.api.app.slh.ISLhSessionData; +import org.jdiameter.common.api.app.slh.SLhSessionState; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class SLhLocalSessionDataImpl extends AppSessionDataLocalImpl implements ISLhSessionData { + + protected SLhSessionState state = SLhSessionState.IDLE; + protected Request buffer; + protected Serializable tsTimerId; + + public void setSLhSessionState(SLhSessionState state) { + this.state = state; + } + + public SLhSessionState getSLhSessionState() { + return this.state; + } + + public Serializable getTsTimerId() { + return this.tsTimerId; + } + + public void setTsTimerId(Serializable tid) { + this.tsTimerId = tid; + } + + public void setBuffer(Request buffer) { + this.buffer = buffer; + } + + public Request getBuffer() { + return this.buffer; + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhSession.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhSession.java new file mode 100644 index 000000000..5665b7676 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhSession.java @@ -0,0 +1,134 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slh; + +import java.io.Serializable; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import org.jdiameter.api.NetworkReqListener; +import org.jdiameter.api.app.StateChangeListener; +import org.jdiameter.api.app.StateMachine; +import org.jdiameter.client.api.ISessionFactory; +import org.jdiameter.common.impl.app.AppSessionImpl; +import org.jdiameter.common.api.app.slh.ISLhMessageFactory; +import org.jdiameter.common.api.app.slh.ISLhSessionData; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public abstract class SLhSession extends AppSessionImpl implements NetworkReqListener, StateMachine { + + public static final int _TX_TIMEOUT = 30 * 1000; + + protected Lock sendAndStateLock = new ReentrantLock(); + + @SuppressWarnings("rawtypes") + protected transient List stateListeners = new CopyOnWriteArrayList(); + protected transient ISLhMessageFactory messageFactory; + + protected static final String TIMER_NAME_MSG_TIMEOUT = "MSG_TIMEOUT"; + protected ISLhSessionData sessionData; + + public SLhSession(ISessionFactory sf, ISLhSessionData sessionData) { + super(sf, sessionData); + this.sessionData = sessionData; + } + + @SuppressWarnings("rawtypes") + public void addStateChangeNotification(StateChangeListener listener) { + if (!stateListeners.contains(listener)) { + stateListeners.add(listener); + } + } + + @SuppressWarnings("rawtypes") + public void removeStateChangeNotification(StateChangeListener listener) { + stateListeners.remove(listener); + } + + public boolean isStateless() { + return true; + } + + @Override + public boolean isReplicable() { + return false; + } + + protected void startMsgTimer() { + try { + sendAndStateLock.lock(); + sessionData.setTsTimerId(super.timerFacility.schedule(getSessionId(), TIMER_NAME_MSG_TIMEOUT, _TX_TIMEOUT)); + } finally { + sendAndStateLock.unlock(); + } + } + + protected void cancelMsgTimer() { + try { + sendAndStateLock.lock(); + final Serializable timerId = this.sessionData.getTsTimerId(); + if (timerId == null) { + return; + } + super.timerFacility.cancel(timerId); + this.sessionData.setTsTimerId(null); + } finally { + sendAndStateLock.unlock(); + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((sessionData == null) ? 0 : sessionData.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + SLhSession other = (SLhSession) obj; + if (sessionData == null) { + if (other.sessionData != null) { + return false; + } + } else if (!sessionData.equals(other.sessionData)) { + return false; + } + return true; + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhSessionFactoryImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhSessionFactoryImpl.java new file mode 100644 index 000000000..de7929602 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/slh/SLhSessionFactoryImpl.java @@ -0,0 +1,269 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.common.impl.app.slh; + +import org.jdiameter.api.Answer; +import org.jdiameter.api.ApplicationId; +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.Request; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.SessionFactory; +import org.jdiameter.api.app.AppAnswerEvent; +import org.jdiameter.api.app.AppRequestEvent; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.app.StateChangeListener; +import org.jdiameter.api.slh.ClientSLhSession; +import org.jdiameter.api.slh.ClientSLhSessionListener; +import org.jdiameter.api.slh.ServerSLhSession; +import org.jdiameter.api.slh.ServerSLhSessionListener; +import org.jdiameter.api.slh.events.LCSRoutingInfoRequest; +import org.jdiameter.api.slh.events.LCSRoutingInfoAnswer; +import org.jdiameter.client.api.ISessionFactory; +import org.jdiameter.client.impl.app.slh.IClientSLhSessionData; +import org.jdiameter.client.impl.app.slh.SLhClientSessionImpl; +import org.jdiameter.common.api.app.IAppSessionDataFactory; +import org.jdiameter.common.api.app.slh.ISLhMessageFactory; +import org.jdiameter.common.api.app.slh.ISLhSessionData; +import org.jdiameter.common.api.app.slh.ISLhSessionFactory; +import org.jdiameter.common.api.data.ISessionDatasource; +import org.jdiameter.server.impl.app.slh.IServerSLhSessionData; +import org.jdiameter.server.impl.app.slh.SLhServerSessionImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class SLhSessionFactoryImpl implements ISLhSessionFactory, ServerSLhSessionListener, ClientSLhSessionListener, + ISLhMessageFactory, StateChangeListener { + + private static final Logger logger = LoggerFactory.getLogger(SLhSessionFactoryImpl.class); + + protected ISessionFactory sessionFactory; + + protected ServerSLhSessionListener serverSessionListener; + protected ClientSLhSessionListener clientSessionListener; + + protected ISLhMessageFactory messageFactory; + protected StateChangeListener stateListener; + protected ISessionDatasource iss; + protected IAppSessionDataFactory sessionDataFactory; + + public SLhSessionFactoryImpl() { + }; + + public SLhSessionFactoryImpl(SessionFactory sessionFactory) { + super(); + init(sessionFactory); + } + + public void init(SessionFactory sessionFactory) { + this.sessionFactory = (ISessionFactory) sessionFactory; + this.iss = this.sessionFactory.getContainer().getAssemblerFacility().getComponentInstance(ISessionDatasource.class); + this.sessionDataFactory = (IAppSessionDataFactory) this.iss.getDataFactory(ISLhSessionData.class); + } + + /** + * @return the serverSessionListener + */ + public ServerSLhSessionListener getServerSessionListener() { + return serverSessionListener != null ? serverSessionListener : this; + } + + /** + * @param serverSessionListener the serverSessionListener to set + */ + public void setServerSessionListener(ServerSLhSessionListener serverSessionListener) { + this.serverSessionListener = serverSessionListener; + } + + /** + * @return the serverSessionListener + */ + public ClientSLhSessionListener getClientSessionListener() { + return clientSessionListener != null ? clientSessionListener : this; + } + + /** + * @param serverSessionListener the serverSessionListener to set + */ + public void setClientSessionListener(ClientSLhSessionListener clientSessionListener) { + this.clientSessionListener = clientSessionListener; + } + + /** + * @return the messageFactory + */ + public ISLhMessageFactory getMessageFactory() { + return messageFactory != null ? messageFactory : this; + } + + /** + * @param messageFactory the messageFactory to set + */ + public void setMessageFactory(ISLhMessageFactory messageFactory) { + this.messageFactory = messageFactory; + } + + /** + * @return the stateListener + */ + public StateChangeListener getStateListener() { + return stateListener != null ? stateListener : this; + } + + /** + * @param stateListener the stateListener to set + */ + public void setStateListener(StateChangeListener stateListener) { + this.stateListener = stateListener; + } + + public AppSession getSession(String sessionId, Class aClass) { + if (sessionId == null) { + throw new IllegalArgumentException("SessionId must not be null"); + } + if (!this.iss.exists(sessionId)) { + return null; + } + AppSession appSession = null; + try { + if (aClass == ServerSLhSession.class) { + IServerSLhSessionData sessionData = (IServerSLhSessionData) this.sessionDataFactory + .getAppSessionData(ServerSLhSession.class, sessionId); + SLhServerSessionImpl serverSession = new SLhServerSessionImpl(sessionData, getMessageFactory(), sessionFactory, + this.getServerSessionListener()); + serverSession.getSessions().get(0).setRequestListener(serverSession); + appSession = serverSession; + } else if (aClass == ClientSLhSession.class) { + IClientSLhSessionData sessionData = (IClientSLhSessionData) this.sessionDataFactory + .getAppSessionData(ClientSLhSession.class, sessionId); + SLhClientSessionImpl clientSession = new SLhClientSessionImpl(sessionData, getMessageFactory(), sessionFactory, + this.getClientSessionListener()); + clientSession.getSessions().get(0).setRequestListener(clientSession); + appSession = clientSession; + } else { + throw new IllegalArgumentException( + "Wrong session class: " + aClass + ". Supported[" + ServerSLhSession.class + "]"); + } + } catch (Exception e) { + logger.error("Failure to obtain new SLh Session.", e); + } + return appSession; + } + + public AppSession getNewSession(String sessionId, Class aClass, ApplicationId applicationId, + Object[] args) { + AppSession appSession = null; + + try { + if (aClass == ServerSLhSession.class) { + if (sessionId == null) { + if (args != null && args.length > 0 && args[0] instanceof Request) { + Request request = (Request) args[0]; + sessionId = request.getSessionId(); + } else { + sessionId = this.sessionFactory.getSessionId(); + } + } + IServerSLhSessionData sessionData = (IServerSLhSessionData) this.sessionDataFactory + .getAppSessionData(ServerSLhSession.class, sessionId); + sessionData.setApplicationId(applicationId); + SLhServerSessionImpl serverSession = new SLhServerSessionImpl(sessionData, getMessageFactory(), sessionFactory, + this.getServerSessionListener()); + + iss.addSession(serverSession); + serverSession.getSessions().get(0).setRequestListener(serverSession); + appSession = serverSession; + } else if (aClass == ClientSLhSession.class) { + if (sessionId == null) { + if (args != null && args.length > 0 && args[0] instanceof Request) { + Request request = (Request) args[0]; + sessionId = request.getSessionId(); + } else { + sessionId = this.sessionFactory.getSessionId(); + } + } + IClientSLhSessionData sessionData = (IClientSLhSessionData) this.sessionDataFactory + .getAppSessionData(ClientSLhSession.class, sessionId); + sessionData.setApplicationId(applicationId); + SLhClientSessionImpl clientSession = new SLhClientSessionImpl(sessionData, getMessageFactory(), sessionFactory, + this.getClientSessionListener()); + + iss.addSession(clientSession); + clientSession.getSessions().get(0).setRequestListener(clientSession); + appSession = clientSession; + } else { + throw new IllegalArgumentException( + "Wrong session class: " + aClass + ". Supported[" + ServerSLhSession.class + "]"); + } + } catch (Exception e) { + logger.error("Failure to obtain new SLh Session.", e); + } + return appSession; + } + + public void stateChanged(Enum oldState, Enum newState) { + logger.info("Diameter SLh Session Factory :: stateChanged :: oldState[{}], newState[{}]", oldState, newState); + } + + public long getApplicationId() { + return 16777291; + } + + public void stateChanged(AppSession source, Enum oldState, Enum newState) { + logger.info("Diameter SLh Session Factory :: stateChanged :: Session, [{}], oldState[{}], newState[{}]", + new Object[] { source, oldState, newState }); + } + + public LCSRoutingInfoAnswer createLCSRoutingInfoAnswer(Answer answer) { + return new LCSRoutingInfoAnswerImpl(answer); + } + + public LCSRoutingInfoRequest createLCSRoutingInfoRequest(Request request) { + return new LCSRoutingInfoRequestImpl(request); + } + + public void doLCSRoutingInfoRequestEvent(ServerSLhSession appSession, LCSRoutingInfoRequest request) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + logger.info("Diameter SLh Session Factory :: doLCSRoutingInfoRequestEvent :: appSession[{}], Request[{}]", + appSession, request); + } + + public void doOtherEvent(AppSession appSession, AppRequestEvent request, AppAnswerEvent answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + logger.info("Diameter SLh Session Factory :: doOtherEvent :: appSession[{}], Request[{}], Answer[{}]", + new Object[] { appSession, request, answer }); + } + + public void doLCSRoutingInfoAnswerEvent(ClientSLhSession appSession, LCSRoutingInfoRequest request, + LCSRoutingInfoAnswer answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + logger.info( + "Diameter SLh Session Factory :: doLCSRoutingInfoAnswerEvent :: appSession[{}], Request[{}], Answer[{}]", + new Object[] { appSession, request, answer }); + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/data/LocalDataSource.java b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/data/LocalDataSource.java index d066798e6..7b5bcd85e 100644 --- a/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/data/LocalDataSource.java +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/data/LocalDataSource.java @@ -62,6 +62,8 @@ import org.jdiameter.common.api.app.s13.IS13SessionData; import org.jdiameter.common.api.app.s6a.IS6aSessionData; import org.jdiameter.common.api.app.sh.IShSessionData; +import org.jdiameter.common.api.app.slg.ISLgSessionData; +import org.jdiameter.common.api.app.slh.ISLhSessionData; import org.jdiameter.common.api.data.ISessionDatasource; import org.jdiameter.common.impl.app.acc.AccLocalSessionDataFactory; import org.jdiameter.common.impl.app.auth.AuthLocalSessionDataFactory; @@ -74,6 +76,8 @@ import org.jdiameter.common.impl.app.s13.S13LocalSessionDataFactory; import org.jdiameter.common.impl.app.s6a.S6aLocalSessionDataFactory; import org.jdiameter.common.impl.app.sh.ShLocalSessionDataFactory; +import org.jdiameter.common.impl.app.slg.SLgLocalSessionDataFactory; +import org.jdiameter.common.impl.app.slh.SLhLocalSessionDataFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -105,6 +109,8 @@ public LocalDataSource() { appSessionDataFactories.put(IRxSessionData.class, new RxLocalSessionDataFactory()); appSessionDataFactories.put(IS6aSessionData.class, new S6aLocalSessionDataFactory()); appSessionDataFactories.put(IS13SessionData.class, new S13LocalSessionDataFactory()); + appSessionDataFactories.put(ISLhSessionData.class, new SLhLocalSessionDataFactory()); + appSessionDataFactories.put(ISLgSessionData.class, new SLgLocalSessionDataFactory()); } public LocalDataSource(IContainer container) { diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/Event.java b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/Event.java new file mode 100644 index 000000000..475f2b9f6 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/Event.java @@ -0,0 +1,86 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.server.impl.app.slg; + +import org.jdiameter.api.InternalException; +import org.jdiameter.api.app.AppEvent; +import org.jdiameter.api.app.StateEvent; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class Event implements StateEvent { + + enum Type { + SEND_MESSAGE, TIMEOUT_EXPIRES, RECEIVE_PLR, RECEIVE_LRR + } + + AppEvent request; + AppEvent answer; + Type type; + + Event(Type type, AppEvent request, AppEvent answer) { + this.type = type; + this.answer = answer; + this.request = request; + } + + @SuppressWarnings("unchecked") + public E encodeType(Class eClass) { + return eClass == Type.class ? (E) type : null; + } + + @SuppressWarnings("rawtypes") + public Enum getType() { + return type; + } + + public AppEvent getRequest() { + return request; + } + + public AppEvent getAnswer() { + return answer; + } + + public int compareTo(Object o) { + return 0; + } + + public Object getData() { + return request != null ? request : answer; + } + + public void setData(Object data) { + try { + if (((AppEvent) data).getMessage().isRequest()) { + request = (AppEvent) data; + } else { + answer = (AppEvent) data; + } + } catch (InternalException e) { + throw new IllegalArgumentException(e); + } + } +} \ No newline at end of file diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/IServerSLgSessionData.java b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/IServerSLgSessionData.java new file mode 100644 index 000000000..31df642d3 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/IServerSLgSessionData.java @@ -0,0 +1,33 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.server.impl.app.slg; + +import org.jdiameter.common.api.app.slg.ISLgSessionData; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface IServerSLgSessionData extends ISLgSessionData { + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/SLgServerSessionImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/SLgServerSessionImpl.java new file mode 100644 index 000000000..a11f4dad6 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/SLgServerSessionImpl.java @@ -0,0 +1,306 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.server.impl.app.slg; + +import org.jdiameter.api.Answer; +import org.jdiameter.api.EventListener; +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.NetworkReqListener; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.Request; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppEvent; +import org.jdiameter.api.app.StateChangeListener; +import org.jdiameter.api.app.StateEvent; +import org.jdiameter.api.slg.ServerSLgSession; +import org.jdiameter.api.slg.ServerSLgSessionListener; +import org.jdiameter.api.slg.events.LocationReportAnswer; +import org.jdiameter.api.slg.events.LocationReportRequest; +import org.jdiameter.api.slg.events.ProvideLocationAnswer; +import org.jdiameter.api.slg.events.ProvideLocationRequest; +import org.jdiameter.client.api.ISessionFactory; +import org.jdiameter.common.api.app.slg.ISLgMessageFactory; +import org.jdiameter.common.api.app.slg.SLgSessionState; +import org.jdiameter.common.impl.app.AppAnswerEventImpl; +import org.jdiameter.common.impl.app.AppRequestEventImpl; +import org.jdiameter.common.impl.app.slg.SLgSession; +import org.jdiameter.server.impl.app.slg.Event.Type; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class SLgServerSessionImpl extends SLgSession + implements ServerSLgSession, EventListener, NetworkReqListener { + + private static final Logger logger = LoggerFactory.getLogger(SLgServerSessionImpl.class); + + // Factories and Listeners + // -------------------------------------------------- + private transient ServerSLgSessionListener listener; + protected long appId = -1; + protected IServerSLgSessionData sessionData; + + public SLgServerSessionImpl(IServerSLgSessionData sessionData, ISLgMessageFactory fct, ISessionFactory sf, + ServerSLgSessionListener lst) { + super(sf, sessionData); + if (lst == null) { + throw new IllegalArgumentException("Listener can not be null"); + } + if ((this.appId = fct.getApplicationId()) < 0) { + throw new IllegalArgumentException("ApplicationId can not be less than zero"); + } + + this.listener = lst; + super.messageFactory = fct; + this.sessionData = sessionData; + } + + public void sendProvideLocationAnswer(ProvideLocationAnswer answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + send(Event.Type.SEND_MESSAGE, null, answer); + } + + public void sendLocationReportAnswer(LocationReportAnswer answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + send(Event.Type.SEND_MESSAGE, null, answer); + } + + @SuppressWarnings("unchecked") + public E getState(Class stateType) { + return stateType == SLgSessionState.class ? (E) this.sessionData.getSLgSessionState() : null; + } + + @SuppressWarnings("unused") + public boolean handleEvent(StateEvent event) throws InternalException, OverloadException { + try { + sendAndStateLock.lock(); + if (!super.session.isValid()) { + // FIXME: throw new InternalException("Generic session is not valid."); + return false; + } + final SLgSessionState state = this.sessionData.getSLgSessionState(); + SLgSessionState newState = null; + Event localEvent = (Event) event; + Event.Type eventType = (Type) event.getType(); + + switch (state) { + + case IDLE: + switch (eventType) { + + case RECEIVE_PLR: + this.sessionData.setBuffer((Request) ((AppEvent) event.getData()).getMessage()); + super.cancelMsgTimer(); + super.startMsgTimer(); + newState = SLgSessionState.MESSAGE_SENT_RECEIVED; + setState(newState); + listener.doProvideLocationRequestEvent(this, (ProvideLocationRequest) event.getData()); + break; + + case RECEIVE_LRR: + this.sessionData.setBuffer((Request) ((AppEvent) event.getData()).getMessage()); + super.cancelMsgTimer(); + super.startMsgTimer(); + newState = SLgSessionState.MESSAGE_SENT_RECEIVED; + setState(newState); + listener.doLocationReportRequestEvent(this, (LocationReportRequest) event.getData()); + break; + + case SEND_MESSAGE: + super.session.send(((AppEvent) event.getData()).getMessage(), this); + newState = SLgSessionState.MESSAGE_SENT_RECEIVED; + setState(newState); + break; + + default: + logger.error("Wrong action in SLg Server FSM. State: IDLE, Event Type: {}", eventType); + break; + } + break; + + case MESSAGE_SENT_RECEIVED: + switch (eventType) { + case TIMEOUT_EXPIRES: + newState = SLgSessionState.TIMEDOUT; + setState(newState); + break; + + case SEND_MESSAGE: + try { + super.session.send(((AppEvent) event.getData()).getMessage(), this); + } finally { + newState = SLgSessionState.TERMINATED; + setState(newState); + } + break; + + default: + throw new InternalException( + "Should not receive more messages after initial. Command: " + event.getData()); + } + break; + + case TERMINATED: + throw new InternalException("Cant receive message in state TERMINATED. Command: " + event.getData()); + + case TIMEDOUT: + throw new InternalException("Cant receive message in state TIMEDOUT. Command: " + event.getData()); + + default: + logger.error("SLg Server FSM in wrong state: {}", state); + break; + } + } catch (Exception e) { + throw new InternalException(e); + } finally { + sendAndStateLock.unlock(); + } + return true; + } + + public void receivedSuccessMessage(Request request, Answer answer) { + AnswerDelivery rd = new AnswerDelivery(); + rd.session = this; + rd.request = request; + rd.answer = answer; + super.scheduler.execute(rd); + } + + public void timeoutExpired(Request request) { + try { + handleEvent(new Event(Event.Type.TIMEOUT_EXPIRES, new AppRequestEventImpl(request), null)); + } catch (Exception e) { + logger.debug("Failed to process timeout message", e); + } + } + + public Answer processRequest(Request request) { + RequestDelivery rd = new RequestDelivery(); + rd.session = this; + rd.request = request; + super.scheduler.execute(rd); + return null; + } + + protected void send(Event.Type type, AppEvent request, AppEvent answer) throws InternalException { + try { + if (type != null) { + handleEvent(new Event(type, request, answer)); + } + } catch (Exception e) { + throw new InternalException(e); + } + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected void setState(SLgSessionState newState) { + SLgSessionState oldState = this.sessionData.getSLgSessionState(); + this.sessionData.setSLgSessionState(newState); + + for (StateChangeListener i : stateListeners) { + i.stateChanged(this, (Enum) oldState, (Enum) newState); + } + if (newState == SLgSessionState.TERMINATED || newState == SLgSessionState.TIMEDOUT) { + super.cancelMsgTimer(); + this.release(); + } + } + + @Override + public void onTimer(String timerName) { + if (timerName.equals(SLgSession.TIMER_NAME_MSG_TIMEOUT)) { + try { + sendAndStateLock.lock(); + try { + handleEvent( + new Event(Event.Type.TIMEOUT_EXPIRES, new AppRequestEventImpl(this.sessionData.getBuffer()), null)); + } catch (Exception e) { + logger.debug("Failure handling Timeout event."); + } + this.sessionData.setBuffer(null); + this.sessionData.setTsTimerId(null); + } finally { + sendAndStateLock.unlock(); + } + } + } + + public void release() { + if (isValid()) { + try { + sendAndStateLock.lock(); + super.release(); + } catch (Exception e) { + logger.debug("Failed to release session", e); + } finally { + sendAndStateLock.unlock(); + } + } else { + logger.debug("Trying to release an already invalid session, with Session ID '{}'", getSessionId()); + } + } + + private class RequestDelivery implements Runnable { + ServerSLgSession session; + Request request; + + public void run() { + try { + switch (request.getCommandCode()) { + case ProvideLocationRequest.code: + handleEvent( + new Event(Event.Type.RECEIVE_PLR, messageFactory.createProvideLocationRequest(request), null)); + break; + + default: + listener.doOtherEvent(session, new AppRequestEventImpl(request), null); + break; + } + } catch (Exception e) { + logger.debug("Failed to process request message", e); + } + } + } + + private class AnswerDelivery implements Runnable { + ServerSLgSession session; + Answer answer; + Request request; + + public void run() { + try { + switch (answer.getCommandCode()) { + default: + listener.doOtherEvent(session, new AppRequestEventImpl(request), new AppAnswerEventImpl(answer)); + break; + } + } catch (Exception e) { + logger.debug("Failed to process success message", e); + } + } + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/ServerSLgSessionDataLocalImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/ServerSLgSessionDataLocalImpl.java new file mode 100644 index 000000000..ef345f9c2 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slg/ServerSLgSessionDataLocalImpl.java @@ -0,0 +1,34 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.server.impl.app.slg; + +import org.jdiameter.common.impl.app.slg.SLgLocalSessionDataImpl; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class ServerSLgSessionDataLocalImpl extends SLgLocalSessionDataImpl implements IServerSLgSessionData { + public ServerSLgSessionDataLocalImpl() { + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/Event.java b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/Event.java new file mode 100644 index 000000000..d9b786d57 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/Event.java @@ -0,0 +1,86 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.server.impl.app.slh; + +import org.jdiameter.api.InternalException; +import org.jdiameter.api.app.AppEvent; +import org.jdiameter.api.app.StateEvent; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class Event implements StateEvent { + + enum Type { + SEND_MESSAGE, TIMEOUT_EXPIRES, RECEIVE_RIR; + } + + AppEvent request; + AppEvent answer; + Type type; + + Event(Type type, AppEvent request, AppEvent answer) { + this.type = type; + this.answer = answer; + this.request = request; + } + + @SuppressWarnings("unchecked") + public E encodeType(Class eClass) { + return eClass == Type.class ? (E) type : null; + } + + @SuppressWarnings("rawtypes") + public Enum getType() { + return type; + } + + public AppEvent getRequest() { + return request; + } + + public AppEvent getAnswer() { + return answer; + } + + public int compareTo(Object o) { + return 0; + } + + public Object getData() { + return request != null ? request : answer; + } + + public void setData(Object data) { + try { + if (((AppEvent) data).getMessage().isRequest()) { + request = (AppEvent) data; + } else { + answer = (AppEvent) data; + } + } catch (InternalException e) { + throw new IllegalArgumentException(e); + } + } +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/IServerSLhSessionData.java b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/IServerSLhSessionData.java new file mode 100644 index 000000000..5f1c50b1f --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/IServerSLhSessionData.java @@ -0,0 +1,33 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.server.impl.app.slh; + +import org.jdiameter.common.api.app.slh.ISLhSessionData; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public interface IServerSLhSessionData extends ISLhSessionData { + +} diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/SLhServerSessionImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/SLhServerSessionImpl.java new file mode 100644 index 000000000..4812dcebb --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/SLhServerSessionImpl.java @@ -0,0 +1,290 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.server.impl.app.slh; + +import org.jdiameter.api.Answer; +import org.jdiameter.api.EventListener; +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.NetworkReqListener; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.Request; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppEvent; +import org.jdiameter.api.app.StateChangeListener; +import org.jdiameter.api.app.StateEvent; +import org.jdiameter.api.slh.ServerSLhSession; +import org.jdiameter.api.slh.ServerSLhSessionListener; +import org.jdiameter.api.slh.events.LCSRoutingInfoRequest; +import org.jdiameter.api.slh.events.LCSRoutingInfoAnswer; +import org.jdiameter.client.api.ISessionFactory; +import org.jdiameter.common.api.app.slh.ISLhMessageFactory; +import org.jdiameter.common.api.app.slh.SLhSessionState; +import org.jdiameter.common.impl.app.AppAnswerEventImpl; +import org.jdiameter.common.impl.app.AppRequestEventImpl; +import org.jdiameter.common.impl.app.slh.SLhSession; +import org.jdiameter.server.impl.app.slh.Event.Type; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class SLhServerSessionImpl extends SLhSession + implements ServerSLhSession, EventListener, NetworkReqListener { + + private static final Logger logger = LoggerFactory.getLogger(SLhServerSessionImpl.class); + + // Factories and Listeners + // -------------------------------------------------- + private transient ServerSLhSessionListener listener; + protected long appId = -1; + protected IServerSLhSessionData sessionData; + + public SLhServerSessionImpl(IServerSLhSessionData sessionData, ISLhMessageFactory fct, ISessionFactory sf, + ServerSLhSessionListener lst) { + super(sf, sessionData); + if (lst == null) { + throw new IllegalArgumentException("Listener can not be null"); + } + if ((this.appId = fct.getApplicationId()) < 0) { + throw new IllegalArgumentException("ApplicationId can not be less than zero"); + } + + this.listener = lst; + super.messageFactory = fct; + this.sessionData = sessionData; + } + + public void sendLCSRoutingInfoAnswer(LCSRoutingInfoAnswer answer) + throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + send(Event.Type.SEND_MESSAGE, null, answer); + } + + @SuppressWarnings("unchecked") + public E getState(Class stateType) { + return stateType == SLhSessionState.class ? (E) this.sessionData.getSLhSessionState() : null; + } + + @SuppressWarnings("unused") + public boolean handleEvent(StateEvent event) throws InternalException, OverloadException { + try { + sendAndStateLock.lock(); + if (!super.session.isValid()) { + // FIXME: throw new InternalException("Generic session is not valid."); + return false; + } + final SLhSessionState state = this.sessionData.getSLhSessionState(); + SLhSessionState newState = null; + Event localEvent = (Event) event; + Event.Type eventType = (Type) event.getType(); + + switch (state) { + + case IDLE: + switch (eventType) { + + case RECEIVE_RIR: + this.sessionData.setBuffer((Request) ((AppEvent) event.getData()).getMessage()); + super.cancelMsgTimer(); + super.startMsgTimer(); + newState = SLhSessionState.MESSAGE_SENT_RECEIVED; + setState(newState); + listener.doLCSRoutingInfoRequestEvent(this, (LCSRoutingInfoRequest) event.getData()); + break; + + case SEND_MESSAGE: + super.session.send(((AppEvent) event.getData()).getMessage(), this); + newState = SLhSessionState.MESSAGE_SENT_RECEIVED; + setState(newState); + break; + + default: + logger.error("Wrong action in SLh Server FSM. State: IDLE, Event Type: {}", eventType); + break; + } + break; + + case MESSAGE_SENT_RECEIVED: + switch (eventType) { + case TIMEOUT_EXPIRES: + newState = SLhSessionState.TIMEDOUT; + setState(newState); + break; + + case SEND_MESSAGE: + try { + super.session.send(((AppEvent) event.getData()).getMessage(), this); + } finally { + newState = SLhSessionState.TERMINATED; + setState(newState); + } + break; + + default: + throw new InternalException( + "Should not receive more messages after initial. Command: " + event.getData()); + } + break; + + case TERMINATED: + throw new InternalException("Cant receive message in state TERMINATED. Command: " + event.getData()); + + case TIMEDOUT: + throw new InternalException("Cant receive message in state TIMEDOUT. Command: " + event.getData()); + + default: + logger.error("SLh Server FSM in wrong state: {}", state); + break; + } + } catch (Exception e) { + throw new InternalException(e); + } finally { + sendAndStateLock.unlock(); + } + return true; + } + + public void receivedSuccessMessage(Request request, Answer answer) { + AnswerDelivery rd = new AnswerDelivery(); + rd.session = this; + rd.request = request; + rd.answer = answer; + super.scheduler.execute(rd); + } + + public void timeoutExpired(Request request) { + try { + handleEvent(new Event(Event.Type.TIMEOUT_EXPIRES, new AppRequestEventImpl(request), null)); + } catch (Exception e) { + logger.debug("Failed to process timeout message", e); + } + } + + public Answer processRequest(Request request) { + RequestDelivery rd = new RequestDelivery(); + rd.session = this; + rd.request = request; + super.scheduler.execute(rd); + return null; + } + + protected void send(Event.Type type, AppEvent request, AppEvent answer) throws InternalException { + try { + if (type != null) { + handleEvent(new Event(type, request, answer)); + } + } catch (Exception e) { + throw new InternalException(e); + } + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected void setState(SLhSessionState newState) { + SLhSessionState oldState = this.sessionData.getSLhSessionState(); + this.sessionData.setSLhSessionState(newState); + + for (StateChangeListener i : stateListeners) { + i.stateChanged(this, (Enum) oldState, (Enum) newState); + } + if (newState == SLhSessionState.TERMINATED || newState == SLhSessionState.TIMEDOUT) { + super.cancelMsgTimer(); + this.release(); + } + } + + @Override + public void onTimer(String timerName) { + if (timerName.equals(SLhSession.TIMER_NAME_MSG_TIMEOUT)) { + try { + sendAndStateLock.lock(); + try { + handleEvent( + new Event(Event.Type.TIMEOUT_EXPIRES, new AppRequestEventImpl(this.sessionData.getBuffer()), null)); + } catch (Exception e) { + logger.debug("Failure handling Timeout event."); + } + this.sessionData.setBuffer(null); + this.sessionData.setTsTimerId(null); + } finally { + sendAndStateLock.unlock(); + } + } + } + + public void release() { + if (isValid()) { + try { + sendAndStateLock.lock(); + super.release(); + } catch (Exception e) { + logger.debug("Failed to release session", e); + } finally { + sendAndStateLock.unlock(); + } + } else { + logger.debug("Trying to release an already invalid session, with Session ID '{}'", getSessionId()); + } + } + + private class RequestDelivery implements Runnable { + ServerSLhSession session; + Request request; + + public void run() { + try { + switch (request.getCommandCode()) { + case LCSRoutingInfoRequest.code: + handleEvent( + new Event(Event.Type.RECEIVE_RIR, messageFactory.createLCSRoutingInfoRequest(request), null)); + break; + + default: + listener.doOtherEvent(session, new AppRequestEventImpl(request), null); + break; + } + } catch (Exception e) { + logger.debug("Failed to process request message", e); + } + } + } + + private class AnswerDelivery implements Runnable { + ServerSLhSession session; + Answer answer; + Request request; + + public void run() { + try { + switch (answer.getCommandCode()) { + default: + listener.doOtherEvent(session, new AppRequestEventImpl(request), new AppAnswerEventImpl(answer)); + break; + } + } catch (Exception e) { + logger.debug("Failed to process success message", e); + } + } + } +} \ No newline at end of file diff --git a/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/ServerSLhSessionDataLocalImpl.java b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/ServerSLhSessionDataLocalImpl.java new file mode 100644 index 000000000..fd97ce925 --- /dev/null +++ b/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/app/slh/ServerSLhSessionDataLocalImpl.java @@ -0,0 +1,34 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, Telestax Inc and individual contributors + * by the @authors tag. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jdiameter.server.impl.app.slh; + +import org.jdiameter.common.impl.app.slh.SLhLocalSessionDataImpl; + +/** + * @author fernando.mendioroz@telestax.com (Fernando Mendioroz) + * + */ + +public class ServerSLhSessionDataLocalImpl extends SLhLocalSessionDataImpl implements IServerSLhSessionData { + public ServerSLhSessionDataLocalImpl() { + } +} diff --git a/core/mux/common/config/dictionary.xml b/core/mux/common/config/dictionary.xml index 91bf1acf5..ac6b5b072 100644 --- a/core/mux/common/config/dictionary.xml +++ b/core/mux/common/config/dictionary.xml @@ -7616,4 +7616,574 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slg/AbstractClient.java b/testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slg/AbstractClient.java new file mode 100644 index 000000000..5f6d32b4d --- /dev/null +++ b/testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slg/AbstractClient.java @@ -0,0 +1,319 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, TeleStax Inc. and individual contributors + * by the @authors tag. + * + * This program is free software: you can redistribute it and/or modify + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * JBoss, Home of Professional Open Source + * Copyright 2007-2011, Red Hat, Inc. and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.mobicents.diameter.stack.functional.slg; + +import java.io.InputStream; +import java.util.concurrent.TimeUnit; + +import org.jdiameter.api.ApplicationId; +import org.jdiameter.api.Avp; +import org.jdiameter.api.AvpSet; +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.Mode; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppAnswerEvent; +import org.jdiameter.api.app.AppRequestEvent; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.slg.ClientSLgSession; +import org.jdiameter.api.slg.ClientSLgSessionListener; +import org.jdiameter.api.slg.ServerSLgSession; +import org.jdiameter.api.slg.events.ProvideLocationRequest; +import org.jdiameter.api.slg.events.ProvideLocationAnswer; +import org.jdiameter.api.slg.events.LocationReportRequest; +import org.jdiameter.api.slg.events.LocationReportAnswer; +import org.jdiameter.client.api.ISessionFactory; +import org.jdiameter.common.impl.app.slg.ProvideLocationRequestImpl; +import org.jdiameter.common.impl.app.slg.LocationReportRequestImpl; +import org.jdiameter.common.impl.app.slg.SLgSessionFactoryImpl; +import org.mobicents.diameter.stack.functional.TBase; + +/** + * + * @author Fernando Mendioroz (fernando.mendioroz@telestax.com) + * + */ +public abstract class AbstractClient extends TBase implements ClientSLgSessionListener { + + // NOTE: implementing NetworkReqListener since its required for stack to + // know we support it... ech. + + protected ClientSLgSession clientSLgSession; + + public void init(InputStream configStream, String clientID) throws Exception { + try { + super.init(configStream, clientID, ApplicationId.createByAuthAppId(10415, 16777255)); + SLgSessionFactoryImpl sLgSessionFactory = new SLgSessionFactoryImpl(this.sessionFactory); + ((ISessionFactory) sessionFactory).registerAppFacory(ServerSLgSession.class, sLgSessionFactory); + ((ISessionFactory) sessionFactory).registerAppFacory(ClientSLgSession.class, sLgSessionFactory); + + sLgSessionFactory .setClientSessionListener(this); + + this.clientSLgSession = ((ISessionFactory) this.sessionFactory).getNewAppSession(this.sessionFactory.getSessionId("xx-SLg-TESTxx"), getApplicationId(), ClientSLgSession.class, null); + } + finally { + try { + configStream.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + } + + // ----------- delegate methods so + + public void start() throws IllegalDiameterStateException, InternalException { + stack.start(); + } + + public void start(Mode mode, long timeOut, TimeUnit timeUnit) throws IllegalDiameterStateException, InternalException { + stack.start(mode, timeOut, timeUnit); + } + + public void stop(long timeOut, TimeUnit timeUnit, int disconnectCause) throws IllegalDiameterStateException, InternalException { + stack.stop(timeOut, timeUnit, disconnectCause); + } + + public void stop(int disconnectCause) { + stack.stop(disconnectCause); + } + + // ------- def methods, to fail :) + + public void doOtherEvent(AppSession session, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + fail("Received \"Other\" event, request[" + request + "], answer[" + answer + "], on session[" + session + "]", null); + } + + public void doProvideLocationAnswerEvent(ClientSLgSession session, ProvideLocationRequest request, ProvideLocationAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + fail("Received \"PLA\" event, request[" + request + "], answer[" + answer + "], on session[" + session + "]", null); + } + + public void doLocationReportAnswerEvent(ClientSLgSession session, LocationReportRequest request, LocationReportAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + fail("Received \"LRA\" event, request[" + request + "], answer[" + answer + "], on session[" + session + "]", null); + } + + // ----------- conf parts + + public String getSessionId() { + return this.clientSLgSession.getSessionId(); + } + + public ClientSLgSession getSession() { + return this.clientSLgSession; + } + + // missing protected abstract attributes TODO + + // ----------- helper + + protected ProvideLocationRequest createPLR(ClientSLgSession slgSession) throws Exception { + /* + < Provide-Location-Request> ::= < Diameter Header: 8388620, REQ, PXY, 16777255 > + < Session-Id > + [ Vendor-Specific-Application-Id ] + { Auth-Session-State } + { Origin-Host } + { Origin-Realm } + { Destination-Host } + { Destination-Realm } + { SLg-Location-Type } + [ User-Name ] + [ MSISDN ] + [ IMEI ] + { LCS-EPS-Client-Name } + { LCS-Client-Type } + [ LCS-Requestor-Name ] + [ LCS-Priority ] + [ LCS-QoS ] + [ Velocity-Requested ] + [ LCS-Supported-GAD-Shapes ] + [ LCS-Service-Type-ID ] + [ LCS-Codeword ] + [ LCS-Privacy-Check-Non-Session ] + [ LCS-Privacy-Check-Session ] + [ Service-Selection ] + [ Deferred-Location-Type ] + [ PLR-Flags ] + *[ Supported-Features ] + *[ AVP ] + *[ Proxy-Info ] + *[ Route-Record ] + */ + // Create ProvideLocationRequest + ProvideLocationRequest plr = new ProvideLocationRequestImpl(slgSession.getSessions().get(0).createRequest(ProvideLocationRequest.code, getApplicationId(), getServerRealmName())); + // < Provide-Location-Request> ::= < Diameter Header: 8388620, REQ, PXY, 16777255 > + + AvpSet reqSet = plr.getMessage().getAvps(); + + if (reqSet.getAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID) == null) { + AvpSet vendorSpecificApplicationId = reqSet.addGroupedAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID, 0, false, false); + // 1* [ Vendor-Id ] + vendorSpecificApplicationId.addAvp(Avp.VENDOR_ID, getApplicationId().getVendorId(), true); + // 0*1{ Auth-Application-Id } + vendorSpecificApplicationId.addAvp(Avp.AUTH_APPLICATION_ID, getApplicationId().getAuthAppId(), true); + } + + // { Auth-Session-State } + if (reqSet.getAvp(Avp.AUTH_SESSION_STATE) == null) { + reqSet.addAvp(Avp.AUTH_SESSION_STATE, 1); + } + + // { Origin-Host } + reqSet.removeAvp(Avp.ORIGIN_HOST); + reqSet.addAvp(Avp.ORIGIN_HOST, getClientURI(), true); + + // PENDING - TODO + if (reqSet.getAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID) == null) { + AvpSet vendorSpecificApplicationId = reqSet.addGroupedAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID, 0, false, false); + // 1* [ Vendor-Id ] + vendorSpecificApplicationId.addAvp(Avp.VENDOR_ID, getApplicationId().getVendorId(), true); + // 0*1{ Auth-Application-Id } + vendorSpecificApplicationId.addAvp(Avp.AUTH_APPLICATION_ID, getApplicationId().getAuthAppId(), true); + } + + // { Auth-Session-State } + if (reqSet.getAvp(Avp.AUTH_SESSION_STATE) == null) { + reqSet.addAvp(Avp.AUTH_SESSION_STATE, 1); + } + + // { Origin-Host } + reqSet.removeAvp(Avp.ORIGIN_HOST); + reqSet.addAvp(Avp.ORIGIN_HOST, getClientURI(), true); + + // PENDING - TODO + return plr; + } + + protected LocationReportRequest createLRR(ClientSLgSession slgSession) throws Exception { + /* + < Location-Report-Request> ::= < Diameter Header: 8388621, REQ, PXY, 16777255 > + < Session-Id > + [ Vendor-Specific-Application-Id ] + { Auth-Session-State } + { Origin-Host } + { Origin-Realm } + { Destination-Host } + { Destination-Realm } + { Location-Event } + [ LCS-EPS-Client-Name ] + [ User-Name ] + [ MSISDN] + [ IMEI ] + [ Location-Estimate ] + [ Accuracy-Fulfilment-Indicator ] + [ Age-Of-Location-Estimate ] + [ Velocity-Estimate ] + [ EUTRAN-Positioning-Data ] + [ ECGI ] + [ GERAN-Positioning-Info ] + [ Cell-Global-Identity ] + [ UTRAN-Positioning-Info ] + [ Service-Area-Identity ] + [ LCS-Service-Type-ID ] + [ Pseudonym-Indicator ] + [ LCS-QoS-Class ] + [ Serving-Node ] + [ LRR-Flags ] + [ LCS-Reference-Number ] + [ Deferred-MT-LR-Data] + [ GMLC-Address ] + [ Reporting-Amount ] + [ Periodic-LDR-Information ] + [ ESMLC-Cell-Info ] + [ 1xRTT-RCID ] ] + [ Civic-Address ] + [ Barometric-Pressure ] + *[ Supported-Features ] + *[ AVP ] + *[ Proxy-Info ] + *[ Route-Record ] + + */ + // Create ProvideLocationRequest + ProvideLocationRequest lrr = new LocationReportRequestImpl(slgSession.getSessions().get(0).createRequest(LocationReportRequest.code, getApplicationId(), getServerRealmName())); + // < Location-Report-Request> ::= < Diameter Header: 8388621, REQ, PXY, 16777255 > + + AvpSet reqSet = lrr.getMessage().getAvps(); + + if (reqSet.getAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID) == null) { + AvpSet vendorSpecificApplicationId = reqSet.addGroupedAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID, 0, false, false); + // 1* [ Vendor-Id ] + vendorSpecificApplicationId.addAvp(Avp.VENDOR_ID, getApplicationId().getVendorId(), true); + // 0*1{ Auth-Application-Id } + vendorSpecificApplicationId.addAvp(Avp.AUTH_APPLICATION_ID, getApplicationId().getAuthAppId(), true); + } + + // { Auth-Session-State } + if (reqSet.getAvp(Avp.AUTH_SESSION_STATE) == null) { + reqSet.addAvp(Avp.AUTH_SESSION_STATE, 1); + } + + // { Origin-Host } + reqSet.removeAvp(Avp.ORIGIN_HOST); + reqSet.addAvp(Avp.ORIGIN_HOST, getClientURI(), true); + + // PENDING - TODO + if (reqSet.getAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID) == null) { + AvpSet vendorSpecificApplicationId = reqSet.addGroupedAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID, 0, false, false); + // 1* [ Vendor-Id ] + vendorSpecificApplicationId.addAvp(Avp.VENDOR_ID, getApplicationId().getVendorId(), true); + // 0*1{ Auth-Application-Id } + vendorSpecificApplicationId.addAvp(Avp.AUTH_APPLICATION_ID, getApplicationId().getAuthAppId(), true); + } + + // { Auth-Session-State } + if (reqSet.getAvp(Avp.AUTH_SESSION_STATE) == null) { + reqSet.addAvp(Avp.AUTH_SESSION_STATE, 1); + } + + // { Origin-Host } + reqSet.removeAvp(Avp.ORIGIN_HOST); + reqSet.addAvp(Avp.ORIGIN_HOST, getClientURI(), true); + + // PENDING - TODO + return plr; + } +} \ No newline at end of file diff --git a/testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slg/AbstractServer.java b/testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slg/AbstractServer.java new file mode 100644 index 000000000..4d0dfd83b --- /dev/null +++ b/testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slg/AbstractServer.java @@ -0,0 +1,254 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, TeleStax Inc. and individual contributors + * by the @authors tag. + * + * This program is free software: you can redistribute it and/or modify + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * JBoss, Home of Professional Open Source + * Copyright 2007-2011, Red Hat, Inc. and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.mobicents.diameter.stack.functional.slg; + +import java.io.InputStream; +import java.util.concurrent.TimeUnit; + +import org.jdiameter.api.ApplicationId; +import org.jdiameter.api.Avp; +import org.jdiameter.api.AvpSet; +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.Mode; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppAnswerEvent; +import org.jdiameter.api.app.AppRequestEvent; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.slg.ClientSLgSession; +import org.jdiameter.api.slg.ClientSLgSessionListener; +import org.jdiameter.api.slg.ServerSLgSession; +import org.jdiameter.api.slg.events.ProvideLocationAnswer; +import org.jdiameter.api.slg.events.ProvideLocationRequest; +import org.jdiameter.client.api.ISessionFactory; +import org.jdiameter.common.impl.app.slg.ProvideLocationAnswerImpl; +import org.jdiameter.common.impl.app.slg.LocationReportAnswerImpl; +import org.jdiameter.common.impl.app.slg.SLgSessionFactoryImpl; +import org.mobicents.diameter.stack.functional.TBase; + +/** + * + * @author Fernando Mendioroz (fernando.mendioroz@telestax.com) + * + */ +public abstract class AbstractServer extends TBase implements ServerSLgSessionListener { + + // NOTE: implementing NetworkReqListener since its required for stack to + // know we support it... ech. + + protected ServerSLgSession serverSLgSession; + + public void init(InputStream configStream, String clientID) throws Exception { + try { + super.init(configStream, clientID, ApplicationId.createByAuthAppId(10415, 16777255)); + SLgSessionFactoryImpl slgSessionFactory = new SLgSessionFactoryImpl(this.sessionFactory); + ((ISessionFactory) sessionFactory).registerAppFacory(ServerSLgSession.class, slgSessionFactory); + ((ISessionFactory) sessionFactory).registerAppFacory(ClientSLgSession.class, slgSessionFactory); + slgSessionFactory.setServerSessionListener(this); + } finally { + try { + configStream.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + } + + // ----------- delegate methods so + + public void start() throws IllegalDiameterStateException, InternalException { + stack.start(); + } + + public void start(Mode mode, long timeOut, TimeUnit timeUnit) throws IllegalDiameterStateException, InternalException { + stack.start(mode, timeOut, timeUnit); + } + + public void stop(long timeOut, TimeUnit timeUnit, int disconnectCause) throws IllegalDiameterStateException, InternalException { + stack.stop(timeOut, timeUnit, disconnectCause); + } + + public void stop(int disconnectCause) { + stack.stop(disconnectCause); + } + + public void doOtherEvent(AppSession session, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, + OverloadException { + fail("Received \"Other\" event, request[" + request + "], answer[" + answer + "], on session[" + session + "]", null); + } + + public void doProvideLocationRequestEvent(ServerSLgSession session, ProvideLocationRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + fail("Received \"PLR\" event, request[" + request + "], on session[" + session + "]", null); + } + + public void doLocationReportRequestEvent(ServerSLgSession session, ProvideLocationRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + fail("Received \"LRR\" event, request[" + request + "], on session[" + session + "]", null); + } + // -------- conf + + public String getSessionId() { + return this.serverSLgSession.getSessionId(); + } + + public void fetchSession(String sessionId) throws InternalException { + this.serverSLgSession = stack.getSession(sessionId, ServerSLgSession.class); + } + + public ServerSLgSession getSession() { + return this.serverSLgSession; + } + + // protected abstract int TODO PENDING attributes + + // ----------- helper + + public ProvideLocationAnswer createPLA(ProvideLocationRequest plr, long resultCode) throws Exception { + /* + < Provide-Location-Answer > ::= < Diameter Header: 8388620, PXY, 16777255 > + < Session-Id > + [ Vendor-Specific-Application-Id ] + [ Result-Code ] + [ Experimental-Result ] + { Auth-Session-State } + { Origin-Host } + { Origin-Realm } + [ Location-Estimate ] + [ Accuracy-Fulfilment-Indicator ] + [ Age-Of-Location-Estimate] + [ Velocity-Estimate ] + [ EUTRAN-Positioning-Data] + [ ECGI ] + [ GERAN-Positioning-Info ] + [ Cell-Global-Identity ] + [ UTRAN-Positioning-Info ] + [ Service-Area-Identity ] + [ Serving-Node ] + [ PLA-Flags ] + [ ESMLC-Cell-Info ] + [ Civic-Address ] + [ Barometric-Pressure ] + *[ Supported-Features ] + *[ AVP ] + *[ Failed-AVP ] + *[ Proxy-Info ] + *[ Route-Record ] + + */ + ProvideLocationAnswer pla = new ProvideLocationAnswerImpl((Request) plr.getMessage(), resultCode); + + AvpSet reqSet = plr.getMessage().getAvps(); + AvpSet set = pla.getMessage().getAvps(); + set.removeAvp(Avp.DESTINATION_HOST); + set.removeAvp(Avp.DESTINATION_REALM); + set.addAvp(reqSet.getAvp(Avp.AUTH_APPLICATION_ID)); + + // { Vendor-Specific-Application-Id } + if (set.getAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID) == null) { + AvpSet vendorSpecificApplicationId = set.addGroupedAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID, 0, false, false); + // 1* [ Vendor-Id ] + vendorSpecificApplicationId.addAvp(Avp.VENDOR_ID, getApplicationId().getVendorId(), true); + // 0*1{ Auth-Application-Id } + vendorSpecificApplicationId.addAvp(Avp.AUTH_APPLICATION_ID, getApplicationId().getAuthAppId(), true); + } + // [ Result-Code ] + // [ Experimental-Result ] + // { Auth-Session-State } + if (set.getAvp(Avp.AUTH_SESSION_STATE) == null) { + set.addAvp(Avp.AUTH_SESSION_STATE, 1); + } + + // TODO - PENDING + return pla; + } + + + public LocationReportAnswer createLRA(LocationReportRequest lrr, long resultCode) throws Exception { + /* + < Location-Report-Answer > ::= < Diameter Header: 8388621, PXY, 16777255> + < Session-Id > + [ Vendor-Specific-Application-Id ] + [ Result-Code ] + [ Experimental-Result ] + { Auth-Session-State } + { Origin-Host } + { Origin-Realm } + [ GMLC-Address ] + [ LRA-Flags ] + [ Reporting-PLMN-List ] + [ LCS-Reference-Number ] + *[ Supported-Features ] + *[ AVP ] + *[ Failed-AVP ] + *[ Proxy-Info ] + *[ Route-Record ] + + */ + ProvideLocationAnswer lra = new ProvideLocationAnswerImpl((Request) lrr.getMessage(), resultCode); + + AvpSet reqSet = lrr.getMessage().getAvps(); + AvpSet set = lra.getMessage().getAvps(); + set.removeAvp(Avp.DESTINATION_HOST); + set.removeAvp(Avp.DESTINATION_REALM); + set.addAvp(reqSet.getAvp(Avp.AUTH_APPLICATION_ID)); + + // { Vendor-Specific-Application-Id } + if (set.getAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID) == null) { + AvpSet vendorSpecificApplicationId = set.addGroupedAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID, 0, false, false); + // 1* [ Vendor-Id ] + vendorSpecificApplicationId.addAvp(Avp.VENDOR_ID, getApplicationId().getVendorId(), true); + // 0*1{ Auth-Application-Id } + vendorSpecificApplicationId.addAvp(Avp.AUTH_APPLICATION_ID, getApplicationId().getAuthAppId(), true); + } + // [ Result-Code ] + // [ Experimental-Result ] + // { Auth-Session-State } + if (set.getAvp(Avp.AUTH_SESSION_STATE) == null) { + set.addAvp(Avp.AUTH_SESSION_STATE, 1); + } + + // TODO - PENDING + return lra; + } +} \ No newline at end of file diff --git a/testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slh/AbstractClient.java b/testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slh/AbstractClient.java new file mode 100644 index 000000000..cc3a7dea6 --- /dev/null +++ b/testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slh/AbstractClient.java @@ -0,0 +1,197 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, TeleStax Inc. and individual contributors + * by the @authors tag. + * + * This program is free software: you can redistribute it and/or modify + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * JBoss, Home of Professional Open Source + * Copyright 2007-2011, Red Hat, Inc. and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.mobicents.diameter.stack.functional.slh; + +import java.io.InputStream; +import java.util.concurrent.TimeUnit; + +import org.jdiameter.api.ApplicationId; +import org.jdiameter.api.Avp; +import org.jdiameter.api.AvpSet; +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.Mode; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppAnswerEvent; +import org.jdiameter.api.app.AppRequestEvent; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.slh.ClientSLhSession; +import org.jdiameter.api.slh.ClientSLhSessionListener; +import org.jdiameter.api.slh.ServerSLhSession; +import org.jdiameter.api.slh.events.LCSRoutingInfoRequest; +import org.jdiameter.api.slh.events.LCSRoutingInfoAnswer; +import org.jdiameter.client.api.ISessionFactory; +import org.jdiameter.common.impl.app.slh.LCSRoutingInfoRequestImpl; +import org.jdiameter.common.impl.app.slh.SLgSessionFactoryImpl; +import org.mobicents.diameter.stack.functional.TBase; + +/** + * + * @author Fernando Mendioroz (fernando.mendioroz@telestax.com) + * + */ +public abstract class AbstractClient extends TBase implements ClientSLhSessionListener { + + // NOTE: implementing NetworkReqListener since its required for stack to + // know we support it... ech. + + protected ClientSLhSession clientSLhSession; + + public void init(InputStream configStream, String clientID) throws Exception { + try { + super.init(configStream, clientID, ApplicationId.createByAuthAppId(10415, 16777255)); + SLhSessionFactoryImpl slhSessionFactory = new SLhSessionFactoryImpl(this.sessionFactory); + ((ISessionFactory) sessionFactory).registerAppFacory(ServerSLhSession.class, slhSessionFactory); + ((ISessionFactory) sessionFactory).registerAppFacory(ClientSLhSession.class, slhSessionFactory); + + slhSessionFactory.setClientSessionListener(this); + + this.clientSLhSession = ((ISessionFactory) this.sessionFactory).getNewAppSession(this.sessionFactory.getSessionId("xx-SLh-TESTxx"), getApplicationId(), ClientSLhSession.class, null); + } + finally { + try { + configStream.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + } + + // ----------- delegate methods so + + public void start() throws IllegalDiameterStateException, InternalException { + stack.start(); + } + + public void start(Mode mode, long timeOut, TimeUnit timeUnit) throws IllegalDiameterStateException, InternalException { + stack.start(mode, timeOut, timeUnit); + } + + public void stop(long timeOut, TimeUnit timeUnit, int disconnectCause) throws IllegalDiameterStateException, InternalException { + stack.stop(timeOut, timeUnit, disconnectCause); + } + + public void stop(int disconnectCause) { + stack.stop(disconnectCause); + } + + // ------- def methods, to fail :) + + public void doOtherEvent(AppSession session, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + fail("Received \"Other\" event, request[" + request + "], answer[" + answer + "], on session[" + session + "]", null); + } + + public void doProvideLocationAnswerEvent(ClientSLhSession session, ProvideLocationRequest request, ProvideLocationAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + fail("Received \"PLA\" event, request[" + request + "], answer[" + answer + "], on session[" + session + "]", null); + } + + // ----------- conf parts + + public String getSessionId() { + return this.clientSLhSession.getSessionId(); + } + + public ClientSLhSession getSession() { + return this.clientSLhSession; + } + + //protected abstract String PENDING attributes + + // ----------- helper + + protected LCSRoutingInfoRequest createRIR(ClientSLhSession slhSession) throws Exception { + /* + < LCS-Routing-Info-Request> ::= < Diameter Header: 8388622, REQ, PXY, 16777291 > + < Session-Id > + [ Vendor-Specific-Application-Id ] + { Auth-Session-State } + { Origin-Host } + { Origin-Realm } + [ Destination-Host ] + { Destination-Realm } + [ User-Name ] + [ MSISDN ] + [ GMLC-Number ] + *[ Supported-Features ] + *[ Proxy-Info ] + *[ Route-Record ] + *[ AVP ] + + */ + // Create LCSRoutingInfoRequest + LCSRoutingInfoRequest rir = new LCSRoutingInfoRequestImpl(slhSession.getSessions().get(0).createRequest(LCSRoutingInfoRequest.code, getApplicationId(), getServerRealmName())); + // < LCS-Routing-Info-Request> ::= < Diameter Header: 8388622, REQ, PXY, 16777291 > + + AvpSet reqSet = rir.getMessage().getAvps(); + + if (reqSet.getAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID) == null) { + AvpSet vendorSpecificApplicationId = reqSet.addGroupedAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID, 0, false, false); + // 1* [ Vendor-Id ] + vendorSpecificApplicationId.addAvp(Avp.VENDOR_ID, getApplicationId().getVendorId(), true); + // 0*1{ Auth-Application-Id } + vendorSpecificApplicationId.addAvp(Avp.AUTH_APPLICATION_ID, getApplicationId().getAuthAppId(), true); + } + + // { Auth-Session-State } + if (reqSet.getAvp(Avp.AUTH_SESSION_STATE) == null) { + reqSet.addAvp(Avp.AUTH_SESSION_STATE, 1); + } + + // { Origin-Host } + reqSet.removeAvp(Avp.ORIGIN_HOST); + reqSet.addAvp(Avp.ORIGIN_HOST, getClientURI(), true); + + //TODO PENDING + } + + //[ User-Name ] + String userName = getUserName(); + if (userName != null) { + reqSet.addAvp(Avp.USER_NAME, userName, false); + } + return rir; +} +} \ No newline at end of file diff --git a/testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slh/AbstractServer.java b/testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slh/AbstractServer.java new file mode 100644 index 000000000..c381730e8 --- /dev/null +++ b/testsuite/tests/src/test/java/org/mobicents/diameter/stack/functional/slh/AbstractServer.java @@ -0,0 +1,199 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2016, TeleStax Inc. and individual contributors + * by the @authors tag. + * + * This program is free software: you can redistribute it and/or modify + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * JBoss, Home of Professional Open Source + * Copyright 2007-2011, Red Hat, Inc. and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.mobicents.diameter.stack.functional.slh; + +import java.io.InputStream; +import java.util.concurrent.TimeUnit; + +import org.jdiameter.api.ApplicationId; +import org.jdiameter.api.Avp; +import org.jdiameter.api.AvpSet; +import org.jdiameter.api.IllegalDiameterStateException; +import org.jdiameter.api.InternalException; +import org.jdiameter.api.Mode; +import org.jdiameter.api.OverloadException; +import org.jdiameter.api.Request; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.app.AppAnswerEvent; +import org.jdiameter.api.app.AppRequestEvent; +import org.jdiameter.api.app.AppSession; +import org.jdiameter.api.slh.ClientSLgSession; +import org.jdiameter.api.slh.ServerSLgSession; +import org.jdiameter.api.slh.ServerSLgSessionListener; +import org.jdiameter.api.slh.events.LCSRoutingInfoRequest; +import org.jdiameter.api.slh.events.LCSRoutingInfoAnswer; +import org.jdiameter.client.api.ISessionFactory; +import org.jdiameter.common.impl.app.slh.LCSRoutingInfoAnswerImpl; +import org.jdiameter.common.impl.app.slh.SLhSessionFactoryImpl; +import org.mobicents.diameter.stack.functional.TBase + +/** + * + * @author Fernando Mendioroz (fernando.mendioroz@telestax.com) + * + */ +public abstract class AbstractServer extends TBase implements ServerSLhSessionListener { + + // NOTE: implementing NetworkReqListener since its required for stack to + // know we support it... ech. + + protected ServerSLhSession serverSLhSession; + + public void init(InputStream configStream, String clientID) throws Exception { + try { + super.init(configStream, clientID, ApplicationId.createByAuthAppId(10415, 16777291)); + SLhSessionFactoryImpl slhSessionFactory = new SLhSessionFactoryImpl(this.sessionFactory); + ((ISessionFactory) sessionFactory).registerAppFacory(ServerSLhSession.class, slhSessionFactory); + ((ISessionFactory) sessionFactory).registerAppFacory(ClientSLhSession.class, slhSessionFactory); + slhSessionFactory.setServerSessionListener(this); + } + finally { + try { + configStream.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + } + + // ----------- delegate methods so + + public void start() throws IllegalDiameterStateException, InternalException { + stack.start(); + } + + public void start(Mode mode, long timeOut, TimeUnit timeUnit) throws IllegalDiameterStateException, InternalException { + stack.start(mode, timeOut, timeUnit); + } + + public void stop(long timeOut, TimeUnit timeUnit, int disconnectCause) throws IllegalDiameterStateException, InternalException { + stack.stop(timeOut, timeUnit, disconnectCause); + } + + public void stop(int disconnectCause) { + stack.stop(disconnectCause); + } + + public void doOtherEvent(AppSession session, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, + OverloadException { + fail("Received \"Other\" event, request[" + request + "], answer[" + answer + "], on session[" + session + "]", null); + } + + public void doLCSRoutingInfoRequestEvent(ServerSLhSession session, LCSRoutingInfoRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { + fail("Received \"RIR\" event, request[" + request + "], on session[" + session + "]", null); + } + + // -------- conf + + public String getSessionId() { + return this.serverSLhSession.getSessionId(); + } + + public void fetchSession(String sessionId) throws InternalException { + this.serverSLhSession = stack.getSession(sessionId, ServerSLhSession.class); + } + + + public ServerSLhSession getSession() { + return this.serverSLhSession; + } + + // protected abstract PENDING attributes + + // ----------- helper + + public LCSRoutingInfoAnswer createLIA(LCSRoutingInfoRequest rir, long resultCode) throws Exception { + /* + < LCS-Routing-Info-Answer> ::= < Diameter Header: 8388622, PXY, 16777291 > + < Session-Id > + [ Vendor-Specific-Application-Id ] + [ Result-Code ] + [ Experimental-Result ] + { Auth-Session-State } + { Origin-Host } + { Origin-Realm } + *[ Supported-Features ] + [ User-Name ] + [ MSISDN ] + [ LMSI ] + [ Serving-Node ] + *[ Additional-Serving-Node ] + [ GMLC-Address ] + [ PPR-Address ] + [ RIA-Flags ] + *[ AVP ] + *[ Failed-AVP ] + *[ Proxy-Info ] + *[ Route-Record ] + + */ + LCSRoutingInfoAnswer ria = new ProvideLocationAnswerImpl((Request) rir.getMessage(), resultCode); + + AvpSet reqSet = rir.getMessage().getAvps(); + AvpSet set = ria.getMessage().getAvps(); + set.removeAvp(Avp.DESTINATION_HOST); + set.removeAvp(Avp.DESTINATION_REALM); + set.addAvp(reqSet.getAvp(Avp.AUTH_APPLICATION_ID)); + + // { Vendor-Specific-Application-Id } + if (set.getAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID) == null) { + AvpSet vendorSpecificApplicationId = set.addGroupedAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID, 0, false, false); + // 1* [ Vendor-Id ] + vendorSpecificApplicationId.addAvp(Avp.VENDOR_ID, getApplicationId().getVendorId(), true); + // 0*1{ Auth-Application-Id } + vendorSpecificApplicationId.addAvp(Avp.AUTH_APPLICATION_ID, getApplicationId().getAuthAppId(), true); + } + // [ Result-Code ] + // [ Experimental-Result ] + // { Auth-Session-State } + if (set.getAvp(Avp.AUTH_SESSION_STATE) == null) { + set.addAvp(Avp.AUTH_SESSION_STATE, 1); + } + + // TODO - PENDING + } + return ria; +} +} \ No newline at end of file diff --git a/testsuite/tests/src/test/resources/configurations/functional-slg/config-client.xml b/testsuite/tests/src/test/resources/configurations/functional-slg/config-client.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/src/test/resources/configurations/functional-slg/config-server-node1.xml b/testsuite/tests/src/test/resources/configurations/functional-slg/config-server-node1.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/src/test/resources/configurations/functional-slg/config-server-node2.xml b/testsuite/tests/src/test/resources/configurations/functional-slg/config-server-node2.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/src/test/resources/configurations/functional-slg/replicated-config-client.xml b/testsuite/tests/src/test/resources/configurations/functional-slg/replicated-config-client.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/src/test/resources/configurations/functional-slg/replicated-config-server-node1.xml b/testsuite/tests/src/test/resources/configurations/functional-slg/replicated-config-server-node1.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/src/test/resources/configurations/functional-slg/replicated-config-server-node2.xml b/testsuite/tests/src/test/resources/configurations/functional-slg/replicated-config-server-node2.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/src/test/resources/configurations/functional-slh/config-client.xml b/testsuite/tests/src/test/resources/configurations/functional-slh/config-client.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/src/test/resources/configurations/functional-slh/config-server-node1.xml b/testsuite/tests/src/test/resources/configurations/functional-slh/config-server-node1.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/src/test/resources/configurations/functional-slh/config-server-node2.xml b/testsuite/tests/src/test/resources/configurations/functional-slh/config-server-node2.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/src/test/resources/configurations/functional-slh/replicated-config-client.xml b/testsuite/tests/src/test/resources/configurations/functional-slh/replicated-config-client.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/src/test/resources/configurations/functional-slh/replicated-config-server-node1.xml b/testsuite/tests/src/test/resources/configurations/functional-slh/replicated-config-server-node1.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/src/test/resources/configurations/functional-slh/replicated-config-server-node2.xml b/testsuite/tests/src/test/resources/configurations/functional-slh/replicated-config-server-node2.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/src/test/resources/dictionary.xml b/testsuite/tests/src/test/resources/dictionary.xml index 91bf1acf5..75b91b3ae 100644 --- a/testsuite/tests/src/test/resources/dictionary.xml +++ b/testsuite/tests/src/test/resources/dictionary.xml @@ -7616,4 +7616,575 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file