Skip to content

Commit

Permalink
Merge pull request #973 from ostelco/feature/proxy-ccr-t
Browse files Browse the repository at this point in the history
Use local data source for CCR-T
  • Loading branch information
mpeterss authored Dec 4, 2019
2 parents f3a351a + 8c35821 commit 4f6b35b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class ProtobufDataSource {
if (ccrContext != null) {
ccrContext.logLatency()
logger.debug("Found Context for answer msisdn {} requestId [{}] request number {}", ccrContext.creditControlRequest.msisdn, ccrContext.sessionId, ccrContext.creditControlRequest.ccRequestNumber?.integer32)
val session = OcsServer.stack?.getSession(ccrContext.sessionId, ServerCCASession::class.java)
if (session != null && session.isValid) {
removeFromSessionMap(ccrContext)
updateBlockedList(answer, ccrContext.creditControlRequest)
if (!ccrContext.skipAnswer) {
removeFromSessionMap(ccrContext)
updateBlockedList(answer, ccrContext.creditControlRequest)
if (!ccrContext.skipAnswer) {
val session = OcsServer.stack?.getSession(ccrContext.sessionId, ServerCCASession::class.java)
if (session != null && session.isValid) {
val cca = createCreditControlAnswer(answer)
try {
session.sendCreditControlAnswer(ccrContext.createCCA(cca))
Expand All @@ -63,9 +63,9 @@ class ProtobufDataSource {
} catch (e: OverloadException) {
logger.error("Failed to send Credit-Control-Answer msisdn {} requestId {}", answer.msisdn, answer.requestId, e)
}
} else {
logger.warn("No session found for [{}] [{}] [{}]", answer.msisdn, answer.requestId, answer.requestNumber)
}
} else {
logger.warn("No session found for [{}] [{}] [{}]", answer.msisdn, answer.requestId, answer.requestNumber)
}
} else {
logger.warn("Missing CreditControlContext for [{}] [{}] [{}]", answer.msisdn, answer.requestId, answer.requestNumber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.ostelco.ocsgw.datasource.local.LocalDataSource;
import org.ostelco.diameter.CreditControlContext;
import org.ostelco.ocs.api.CreditControlRequestType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Proxy DataSource is a combination of the Local DataSource and any other
Expand All @@ -22,6 +24,8 @@ public class ProxyDataSource implements DataSource {

private final DataSource secondary;

private static final Logger LOG = LoggerFactory.getLogger(ProxyDataSource.class);

public ProxyDataSource(DataSource dataSource) {
secondary = dataSource;
}
Expand All @@ -33,23 +37,36 @@ public void init() {

@Override
public void handleRequest(CreditControlContext context) {
// CCR-I and CCR-T will always be handled by the secondary DataSource
if (context.getOriginalCreditControlRequest().getRequestTypeAVPValue()
!= CreditControlRequestType.UPDATE_REQUEST.getNumber()) {
secondary.handleRequest(context);
} else {
// For CCR-U we will send all requests to both Local and Secondary until the secondary has blocked the msisdn
if (!secondary.isBlocked(context.getCreditControlRequest().getMsisdn())) {
local.handleRequest(context);
// When local datasource will be responding with Answer, Secondary datasource should skip to send Answer to P-GW.
context.setSkipAnswer(true);
secondary.handleRequest(context);
} else {

switch (context.getOriginalCreditControlRequest().getRequestTypeAVPValue()) {
case CreditControlRequestType.INITIAL_REQUEST_VALUE:
secondary.handleRequest(context);
}
break;
case CreditControlRequestType.UPDATE_REQUEST_VALUE:
if (!secondary.isBlocked(context.getCreditControlRequest().getMsisdn())) {
proxyAnswer(context);
} else {
secondary.handleRequest(context);
}
break;
case CreditControlRequestType.TERMINATION_REQUEST_VALUE:
proxyAnswer(context);
break;
default:
LOG.warn("Unknown request type : {}", context.getOriginalCreditControlRequest().getRequestTypeAVPValue());
}
}

/**
* Use the local data source to send an answer directly to P-GW.
* Use secondary to report the usage to OCS.
*/
private void proxyAnswer(CreditControlContext context) {
local.handleRequest(context);
context.setSkipAnswer(true);
secondary.handleRequest(context);
}

@Override
public boolean isBlocked(final String msisdn) {
return secondary.isBlocked(msisdn);
Expand Down

0 comments on commit 4f6b35b

Please sign in to comment.