PageRenderTime 80ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/servers/diameter/testsuite/slee/sbb/src/main/java/org/mobicents/slee/tests/diameter/DiameterTestsSbb.java

http://mobicents.googlecode.com/
Java | 658 lines | 484 code | 127 blank | 47 comment | 30 complexity | 3168fb3051d03a1b1ccf6791cab0b94a MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. package org.mobicents.slee.tests.diameter;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import javax.naming.Context;
  6. import javax.naming.InitialContext;
  7. import javax.slee.ActivityContextInterface;
  8. import javax.slee.RolledBackContext;
  9. import javax.slee.SbbContext;
  10. import javax.slee.facilities.TimerEvent;
  11. import javax.slee.facilities.TimerFacility;
  12. import javax.slee.serviceactivity.ServiceActivity;
  13. import javax.slee.serviceactivity.ServiceActivityFactory;
  14. import net.java.slee.resource.diameter.base.DiameterAvpFactory;
  15. import net.java.slee.resource.diameter.base.DiameterMessageFactory;
  16. import net.java.slee.resource.diameter.base.DiameterProvider;
  17. import net.java.slee.resource.diameter.base.events.AccountingAnswer;
  18. import net.java.slee.resource.diameter.base.events.DiameterMessage;
  19. import net.java.slee.resource.diameter.base.events.avp.DiameterAvp;
  20. import net.java.slee.resource.diameter.base.events.avp.GroupedAvp;
  21. import org.apache.log4j.Logger;
  22. import org.jdiameter.api.Avp;
  23. import org.jdiameter.api.ResultCode;
  24. import org.mobicents.slee.resource.diameter.base.AccountingServerSessionActivityImpl;
  25. /**
  26. *
  27. * DiameterExampleSbb.java
  28. *
  29. * <br>Super project: mobicents
  30. * <br>11:34:16 PM May 26, 2008
  31. * <br>
  32. * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
  33. * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a>
  34. * @author Erick Svenson
  35. */
  36. public abstract class DiameterTestsSbb implements javax.slee.Sbb {
  37. private static Logger logger = Logger.getLogger( DiameterTestsSbb.class );
  38. private SbbContext sbbContext = null; // This SBB's context
  39. private Context myEnv = null; // This SBB's environment
  40. private DiameterProvider provider = null;
  41. private DiameterMessageFactory messageFactory = null;
  42. private DiameterAvpFactory avpFactory = null;
  43. private TimerFacility timerFacility = null;
  44. private static class DiameterUser
  45. {
  46. String msisdn;
  47. String name;
  48. String imsi;
  49. Double balance;
  50. Double reserved;
  51. public DiameterUser( String msisdn, String name, String imsi, Double balance, Double reserved )
  52. {
  53. this.msisdn = msisdn;
  54. this.name = name;
  55. this.msisdn = msisdn;
  56. this.balance = balance;
  57. this.reserved = reserved;
  58. }
  59. }
  60. private static HashMap<String, DiameterUser> users = new HashMap();
  61. static {
  62. users.put( "00001000", new DiameterUser("00001000", "Alexandre Mendonca", "00001000", 1000.0, 0.0) );
  63. users.put( "00001001", new DiameterUser("00001001", "Bartosz Baranowski", "00001001", 100.0, 0.0) );
  64. users.put( "00001002", new DiameterUser("00001002", "Erick Svensson", "00001002", 0.0, 0.0) );
  65. }
  66. public void setSbbContext( SbbContext context )
  67. {
  68. logger.info( "sbbRolledBack invoked." );
  69. this.sbbContext = context;
  70. try
  71. {
  72. myEnv = (Context) new InitialContext().lookup( "java:comp/env" );
  73. provider = (DiameterProvider) myEnv.lookup("slee/resources/diameter-base-ra/provider");
  74. //acif = (DiameterActivityContextInterfaceFactory) myEnv.lookup("slee/resources/diameter-base-ra/acif");
  75. logger.info( "Got Provider:" + provider );
  76. messageFactory = provider.getDiameterMessageFactory();
  77. logger.info( "Got Message Factory:" + provider );
  78. avpFactory = provider.getDiameterAvpFactory();
  79. logger.info( "Got AVP Factory:" + provider );
  80. // Get the timer facility
  81. timerFacility = (TimerFacility) myEnv.lookup("slee/facilities/timer");
  82. }
  83. catch ( Exception e )
  84. {
  85. logger.error( "Unable to set sbb context.", e );
  86. }
  87. }
  88. public void unsetSbbContext()
  89. {
  90. logger.info( "unsetSbbContext invoked." );
  91. this.sbbContext = null;
  92. }
  93. public void sbbCreate() throws javax.slee.CreateException
  94. {
  95. logger.info( "sbbCreate invoked." );
  96. }
  97. public void sbbPostCreate() throws javax.slee.CreateException
  98. {
  99. logger.info( "sbbPostCreate invoked." );
  100. }
  101. public void sbbActivate()
  102. {
  103. logger.info( "sbbActivate invoked." );
  104. }
  105. public void sbbPassivate()
  106. {
  107. logger.info( "sbbPassivate invoked." );
  108. }
  109. public void sbbRemove()
  110. {
  111. logger.info( "sbbRemove invoked." );
  112. }
  113. public void sbbLoad()
  114. {
  115. logger.info( "sbbLoad invoked." );
  116. }
  117. public void sbbStore()
  118. {
  119. logger.info( "sbbStore invoked." );
  120. }
  121. public void sbbExceptionThrown( Exception exception, Object event, ActivityContextInterface activity )
  122. {
  123. logger.info( "sbbRolledBack invoked." );
  124. }
  125. public void sbbRolledBack( RolledBackContext context )
  126. {
  127. logger.info( "sbbRolledBack invoked." );
  128. }
  129. protected SbbContext getSbbContext()
  130. {
  131. logger.info( "getSbbContext invoked." );
  132. return sbbContext;
  133. }
  134. // ##########################################################################
  135. // ## EVENT HANDLERS ##
  136. // ##########################################################################
  137. public void onServiceStartedEvent( javax.slee.serviceactivity.ServiceStartedEvent event, ActivityContextInterface aci )
  138. {
  139. logger.info( "onServiceStartedEvent invoked." );
  140. try
  141. {
  142. // check if it's my service that is starting
  143. ServiceActivity sa = ( (ServiceActivityFactory) myEnv.lookup( "slee/serviceactivity/factory" ) ).getActivity();
  144. if( sa.equals( aci.getActivity() ) )
  145. {
  146. logger.info( "################################################################################" );
  147. logger.info( "## D I A M E T E R T E S T A P P L I C A T I O N S B B E N G A G E D ##" );
  148. logger.info( "################################################################################" );
  149. messageFactory = provider.getDiameterMessageFactory();
  150. avpFactory = provider.getDiameterAvpFactory();
  151. logger.info( "Performing sanity check..." );
  152. logger.info( "Provider [" + provider + "]" );
  153. logger.info( "Message Factory [" + messageFactory + "]" );
  154. logger.info( "AVP Factory [" + avpFactory + "]" );
  155. //logger.info( "# Check completed. Result: " + ((provider != null ? 1 : 0) + (messageFactory != null ? 1 : 0) + (avpFactory != null ? 1 : 0)) + "/3" );
  156. logger.info( "Connected to " + provider.getPeerCount() + " peers." );
  157. }
  158. }
  159. catch ( Exception e )
  160. {
  161. logger.error( "Unable to handle service started event...", e );
  162. }
  163. }
  164. public void onTimerEvent(TimerEvent event, ActivityContextInterface aci)
  165. {
  166. sendAccountingRequest();
  167. }
  168. public void onAbortSessionRequest(net.java.slee.resource.diameter.base.events.AbortSessionRequest asr, ActivityContextInterface aci)
  169. {
  170. logger.info( "Abort-Session-Request received." );
  171. }
  172. public void onAbortSessionAnswer(net.java.slee.resource.diameter.base.events.AbortSessionAnswer asa, ActivityContextInterface aci)
  173. {
  174. logger.info( "Abort-Session-Answer received." );
  175. }
  176. public void onAccountingRequest(net.java.slee.resource.diameter.base.events.AccountingRequest acr, ActivityContextInterface aci)
  177. {
  178. long start = System.currentTimeMillis();
  179. logger.info( "Accounting-Request received. [" + acr + "]" );
  180. boolean actAsProxy = false;
  181. try
  182. {
  183. // Are we gonna act as a proxy?
  184. if(actAsProxy)
  185. {
  186. // In here we act as a "proxy". Just for testing we take the original message,
  187. // replace the Origin/Destination Host/Realm AVPs and send it to the emulator.
  188. boolean hasDestinationHost = false;
  189. boolean hasDestinationRealm = false;
  190. List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
  191. for(DiameterAvp avp : acr.getAvps())
  192. {
  193. switch(avp.getCode())
  194. {
  195. case Avp.ORIGIN_HOST:
  196. avps.add(avpFactory.createAvp(Avp.ORIGIN_HOST, "aaa://127.0.0.1:3868".getBytes() ));
  197. break;
  198. case Avp.ORIGIN_REALM:
  199. avps.add(avpFactory.createAvp(Avp.ORIGIN_REALM, "mobicents.org".getBytes() ));
  200. break;
  201. case Avp.DESTINATION_HOST:
  202. avps.add(avpFactory.createAvp(Avp.DESTINATION_HOST, "aaa://127.0.0.1:13868".getBytes() ));
  203. hasDestinationHost = true;
  204. break;
  205. case Avp.DESTINATION_REALM:
  206. avps.add(avpFactory.createAvp(Avp.DESTINATION_REALM, "mobicents.org".getBytes() ));
  207. hasDestinationRealm = true;
  208. break;
  209. default:
  210. avps.add(avp);
  211. }
  212. }
  213. if(!hasDestinationHost)
  214. avps.add(avpFactory.createAvp(Avp.DESTINATION_HOST, "127.0.0.1".getBytes() ));
  215. if(!hasDestinationRealm)
  216. avps.add(avpFactory.createAvp(Avp.DESTINATION_REALM, "mobicents.org".getBytes() ));
  217. logger.info( "AVPs ==> " + avps );
  218. DiameterAvp[] avpArray = new DiameterAvp[avps.size()];
  219. avpArray = avps.toArray(avpArray);
  220. logger.info( "Creating Custom Message..." );
  221. DiameterMessage ms = messageFactory.createAccountingRequest(avpArray);
  222. logger.info( "Created Custom Message[" + ms + "]" );
  223. logger.info( "Sending Custom Message..." );
  224. provider.createActivity().sendMessage( ms );
  225. logger.info( "Sent Custom Message[" + ms + "]" );
  226. }
  227. else
  228. {
  229. // In here we act as a server...
  230. int subscriptionIdType = -1;
  231. String subscriptionIdData = "";
  232. int unitType = -1;
  233. long valueDigits = -1;
  234. int exponent = 0;
  235. int requestedAction = -1;
  236. int serviceParameterType;
  237. int serviceParameterValue;
  238. int serviceParameterInfo;
  239. DiameterAvp subscriptionIdAvp = null;
  240. DiameterAvp requestedActionAvp = null;
  241. if(aci.getActivity() instanceof AccountingServerSessionActivityImpl)
  242. {
  243. for(DiameterAvp avp : acr.getAvps())
  244. {
  245. switch ( avp.getCode() )
  246. {
  247. case SUBSCRIPTION_ID:
  248. {
  249. // This should contain a SUBSCRIPTION_ID_TYPE and a SUBSCRIPTION_ID_DATA
  250. if(avp instanceof GroupedAvp)
  251. {
  252. GroupedAvp gAvp = (GroupedAvp)avp;
  253. for(DiameterAvp subAvp : gAvp.getExtensionAvps())
  254. {
  255. switch(subAvp.getCode())
  256. {
  257. case SUBSCRIPTION_ID_TYPE:
  258. subscriptionIdType = subAvp.intValue();
  259. break;
  260. case SUBSCRIPTION_ID_DATA:
  261. subscriptionIdData = subAvp.stringValue();
  262. break;
  263. }
  264. }
  265. }
  266. }
  267. break;
  268. case REQUESTED_SERVICE_UNIT:
  269. {
  270. // This should contain a UNIT_TYPE and a UNIT_VALUE
  271. if(avp instanceof GroupedAvp)
  272. {
  273. GroupedAvp gAvp = (GroupedAvp)avp;
  274. for(DiameterAvp subAvp : gAvp.getExtensionAvps())
  275. {
  276. switch(subAvp.getCode())
  277. {
  278. case UNIT_TYPE:
  279. unitType = subAvp.intValue();
  280. break;
  281. case UNIT_VALUE:
  282. {
  283. // This should contain a VALUE_DIGITS
  284. if(subAvp instanceof GroupedAvp)
  285. {
  286. GroupedAvp gSubAvp = (GroupedAvp)subAvp;
  287. for(DiameterAvp subSubAvp : gSubAvp.getExtensionAvps())
  288. {
  289. switch(subSubAvp.getCode())
  290. {
  291. case VALUE_DIGITS:
  292. valueDigits = subSubAvp.longValue();
  293. break;
  294. case EXPONENT:
  295. exponent = subSubAvp.intValue();
  296. break;
  297. }
  298. }
  299. }
  300. break;
  301. }
  302. }
  303. }
  304. }
  305. }
  306. break;
  307. case REQUESTED_ACTION:
  308. requestedAction = avp.intValue();
  309. requestedActionAvp = avp;
  310. break;
  311. case SERVICE_PARAMETER_TYPE:
  312. // We can discard this...
  313. case SERVICE_PARAMETER_VALUE:
  314. // We can discard this...
  315. case SERVICE_PARAMETER_INFO:
  316. // We can discard this...
  317. default:
  318. }
  319. }
  320. logger.info( "Subscription-Id-Type: " + subscriptionIdType );
  321. logger.info( "Subscription-Id-Data: " + subscriptionIdData );
  322. logger.info( "Unit-Type: " + unitType );
  323. logger.info( "Value-Digits: " + valueDigits );
  324. logger.info( "Exponent: " + exponent );
  325. logger.info( "Requested-Action: " + requestedAction );
  326. AccountingServerSessionActivityImpl assa = (AccountingServerSessionActivityImpl)aci.getActivity();
  327. // Aditional AVPs container
  328. List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
  329. // By default, let's consider it's OK and create answer with 2001
  330. AccountingAnswer ans = assa.createAccountAnswer( acr, ResultCode.SUCCESS );
  331. double chargingValue = valueDigits * Math.pow( 10, exponent );
  332. if(subscriptionIdType == 0 || subscriptionIdType == 1)
  333. {
  334. DiameterUser user = null;
  335. if( (user = users.get( subscriptionIdData )) == null )
  336. {
  337. // Not a valid user. Reject it with DIAMETER_END_USER_NOT_FOUND.
  338. ans = assa.createAccountAnswer( acr, 5241 );
  339. // Subscription ID
  340. DiameterAvp subscriptionIdTypeAvp = avpFactory.createAvp( 193, 555, subscriptionIdType );
  341. DiameterAvp subscriptionIdDataAvp = avpFactory.createAvp( 193, 554, subscriptionIdData );
  342. avps.add( avpFactory.createAvp( 193, 553, new DiameterAvp[]{subscriptionIdTypeAvp, subscriptionIdDataAvp} ) );
  343. }
  344. else if(requestedAction == 0 && user.balance < chargingValue)
  345. {
  346. logger.info( "Received Direct Debit Request:" );
  347. logger.info( "User ID " + subscriptionIdData + " (" + user.name + ")" );
  348. logger.info( "Current Balance: " + user.balance );
  349. logger.info( "Charging Value: " + chargingValue );
  350. // Not able to provide the service. not enough balance.
  351. ans = assa.createAccountAnswer( acr, 4241 );
  352. // Subscription ID
  353. DiameterAvp subscriptionIdTypeAvp = avpFactory.createAvp( 193, 555, subscriptionIdType );
  354. DiameterAvp subscriptionIdDataAvp = avpFactory.createAvp( 193, 554, subscriptionIdData );
  355. avps.add( avpFactory.createAvp( 193, 553, new DiameterAvp[]{subscriptionIdTypeAvp, subscriptionIdDataAvp} ) );
  356. }
  357. else
  358. {
  359. boolean isError = false;
  360. // Refund Account?
  361. if(requestedAction == 1)
  362. {
  363. logger.info( "Received Refund Account Request:" );
  364. logger.info( "User ID " + subscriptionIdData + " (" + user.name + ")" );
  365. logger.info( "Old Balance: " + user.balance );
  366. user.balance += chargingValue;
  367. logger.info( "New Balance: " + user.balance );
  368. }
  369. else if(requestedAction == 0)
  370. {
  371. logger.info( "Received Direct Debit Request:" );
  372. logger.info( "User ID " + subscriptionIdData + " (" + user.name + ")" );
  373. logger.info( "Old Balance: " + user.balance );
  374. user.balance -= chargingValue;
  375. logger.info( "New Balance: " + user.balance );
  376. }
  377. else
  378. {
  379. logger.warn( "Unknown requested action (" + requestedAction + ")" );
  380. DiameterAvp failedAvp = avpFactory.createAvp( 0, 279, new DiameterAvp[]{requestedActionAvp} );
  381. ans = assa.createAccountAnswer( acr, ResultCode.INVALID_AVP_VALUE);
  382. avps.add( failedAvp );
  383. isError = true;
  384. }
  385. if(!isError)
  386. {
  387. // Subscription ID
  388. DiameterAvp subscriptionIdTypeAvp = avpFactory.createAvp( 193, 555, subscriptionIdType );
  389. DiameterAvp subscriptionIdDataAvp = avpFactory.createAvp( 193, 554, subscriptionIdData );
  390. avps.add( avpFactory.createAvp( 193, 553, new DiameterAvp[]{subscriptionIdTypeAvp, subscriptionIdDataAvp} ) );
  391. // Granted Service Unit
  392. DiameterAvp unitTypeAvp = avpFactory.createAvp( 193, 611, unitType );
  393. DiameterAvp valueDigitsAvp = avpFactory.createAvp( 193, 617, valueDigits );
  394. DiameterAvp unitValueAvp = avpFactory.createAvp( 193, 612, new DiameterAvp[]{valueDigitsAvp} );
  395. avps.add( avpFactory.createAvp( 193, 602, new DiameterAvp[]{unitTypeAvp, unitValueAvp} ) );
  396. // Cost Information
  397. DiameterAvp costAvp = avpFactory.createAvp( 193, 603, chargingValue );
  398. DiameterAvp currencyCodeAvp = avpFactory.createAvp( 193, 544, 978 );
  399. avps.add( avpFactory.createAvp( 193, 604, new DiameterAvp[]{costAvp, currencyCodeAvp} ) );
  400. }
  401. }
  402. }
  403. DiameterAvp[] avpArray = new DiameterAvp[avps.size()];
  404. avpArray = avps.toArray(avpArray);
  405. ans.setExtensionAvps( avpArray );
  406. logger.info( "Sending Accounting-Answer [" + ans + "]" );
  407. assa.sendAccountingAnswer( ans );
  408. logger.info( "Accounting-Answer sent." );
  409. }
  410. }
  411. }
  412. catch (Exception e)
  413. {
  414. logger.error( "", e );
  415. }
  416. long end = System.currentTimeMillis();
  417. logger.info( "Accounting-Request proccessed. [" + (end-start) + "ms]" );
  418. }
  419. public void onAccountingAnswer(net.java.slee.resource.diameter.base.events.AccountingAnswer aca, ActivityContextInterface aci)
  420. {
  421. logger.info( "Accounting-Answer received." );
  422. }
  423. public void onCapabilitiesExchangeRequest(net.java.slee.resource.diameter.base.events.CapabilitiesExchangeRequest cer, ActivityContextInterface aci)
  424. {
  425. logger.info( "Capabilities-Exchange-Request received." );
  426. }
  427. public void onCapabilitiesExchangeAnswer(net.java.slee.resource.diameter.base.events.CapabilitiesExchangeAnswer cea, ActivityContextInterface aci)
  428. {
  429. logger.info( "Capabilities-Exchange-Answer received." );
  430. }
  431. public void onDeviceWatchdogRequest(net.java.slee.resource.diameter.base.events.DeviceWatchdogRequest dwr, ActivityContextInterface aci)
  432. {
  433. logger.info( "Device-Watchdog-Request received." );
  434. }
  435. public void onDeviceWatchdogAnswer(net.java.slee.resource.diameter.base.events.DeviceWatchdogAnswer dwa, ActivityContextInterface aci)
  436. {
  437. logger.info( "Device-Watchdog-Answer received." );
  438. }
  439. public void onDisconnectPeerRequest(net.java.slee.resource.diameter.base.events.DisconnectPeerRequest dpr, ActivityContextInterface aci)
  440. {
  441. logger.info( "Disconnect-Peer-Request received." );
  442. }
  443. public void onDisconnectPeerAnswer(net.java.slee.resource.diameter.base.events.DisconnectPeerAnswer dpa, ActivityContextInterface aci)
  444. {
  445. logger.info( "Disconnect-Peer-Answer received." );
  446. }
  447. public void onReAuthRequest(net.java.slee.resource.diameter.base.events.ReAuthRequest rar, ActivityContextInterface aci)
  448. {
  449. logger.info( "Re-Auth-Request received." );
  450. }
  451. public void onReAuthAnswer(net.java.slee.resource.diameter.base.events.ReAuthAnswer raa, ActivityContextInterface aci)
  452. {
  453. logger.info( "Re-Auth-Answer received." );
  454. }
  455. public void onSessionTerminationRequest(net.java.slee.resource.diameter.base.events.SessionTerminationRequest rar, ActivityContextInterface aci)
  456. {
  457. logger.info( "Session-Termination-Request received." );
  458. }
  459. public void onSessionTerminationAnswer(net.java.slee.resource.diameter.base.events.SessionTerminationAnswer raa, ActivityContextInterface aci)
  460. {
  461. logger.info( "Session-Termination-Answer received." );
  462. }
  463. public void onErrorAnswer(net.java.slee.resource.diameter.base.events.ErrorAnswer era, ActivityContextInterface aci)
  464. {
  465. logger.info( "Error-Answer received." );
  466. }
  467. // ##########################################################################
  468. // ## PRIVATE METHODS ##
  469. // ##########################################################################
  470. private final static int SUBSCRIPTION_ID_TYPE = 555;
  471. private final static int SUBSCRIPTION_ID_DATA = 554;
  472. private final static int SUBSCRIPTION_ID = 553;
  473. private final static int UNIT_TYPE = 611;
  474. private final static int VALUE_DIGITS = 617;
  475. private final static int UNIT_VALUE = 612;
  476. private final static int EXPONENT = 616;
  477. private final static int REQUESTED_SERVICE_UNIT = 606;
  478. private final static int REQUESTED_ACTION = 615; // 0 = Direct Debit, 1 = Refund Account
  479. private final static int SERVICE_PARAMETER_TYPE = 608;
  480. private final static int SERVICE_PARAMETER_VALUE = 609;
  481. private final static int SERVICE_PARAMETER_INFO = 607;
  482. private void sendAccountingRequest()
  483. {
  484. try
  485. {
  486. List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
  487. avps.add(avpFactory.createAvp(Avp.SESSION_ID, "12345".getBytes() ));
  488. DiameterAvp avpVendorId = avpFactory.createAvp( Avp.VENDOR_ID, 193 );
  489. DiameterAvp avpAcctApplicationId = avpFactory.createAvp( Avp.ACCT_APPLICATION_ID, 193 );
  490. avps.add( avpFactory.createAvp( Avp.VENDOR_SPECIFIC_APPLICATION_ID, new DiameterAvp[]{avpVendorId, avpAcctApplicationId} ) );
  491. avps.add(avpFactory.createAvp(Avp.ORIGIN_HOST, "aaa://127.0.0.1:3868".getBytes() ));
  492. avps.add(avpFactory.createAvp(Avp.ORIGIN_REALM, "mobicents.org".getBytes() ));
  493. avps.add(avpFactory.createAvp(Avp.DESTINATION_HOST, "aaa://127.0.0.1:13868".getBytes() ));
  494. avps.add(avpFactory.createAvp(Avp.DESTINATION_REALM, "mobicents.org".getBytes() ));
  495. // Subscription ID
  496. DiameterAvp subscriptionIdType = avpFactory.createAvp( 193, 555, 0 );
  497. DiameterAvp subscriptionIdData = avpFactory.createAvp( 193, 554, "00001000" );
  498. avps.add( avpFactory.createAvp( 193, 553, new DiameterAvp[]{subscriptionIdType, subscriptionIdData} ) );
  499. // Requested Service Unit
  500. DiameterAvp unitType = avpFactory.createAvp( 193, 611, 2 );
  501. DiameterAvp valueDigits = avpFactory.createAvp( 193, 617, 10L );
  502. DiameterAvp unitValue = avpFactory.createAvp( 193, 612, new DiameterAvp[]{valueDigits} );
  503. avps.add( avpFactory.createAvp( 193, 606, new DiameterAvp[]{unitType, unitValue} ) );
  504. // Record Number and Type
  505. avps.add(avpFactory.createAvp(Avp.ACC_RECORD_NUMBER, 0 ));
  506. avps.add(avpFactory.createAvp(Avp.ACC_RECORD_TYPE, 1 ));
  507. // Requested action
  508. avps.add( avpFactory.createAvp( 193, 615, 0 ) );
  509. // Service Parameter Type
  510. DiameterAvp serviceParameterType = avpFactory.createAvp( 193, 608, 0 );
  511. DiameterAvp serviceParameterValue = avpFactory.createAvp( 193, 609, "510" );
  512. avps.add( avpFactory.createAvp( 193, 607, new DiameterAvp[]{serviceParameterType, serviceParameterValue} ) );
  513. // Service Parameter Type
  514. DiameterAvp serviceParameterType2 = avpFactory.createAvp( 193, 608, 14 );
  515. DiameterAvp serviceParameterValue2 = avpFactory.createAvp( 193, 609, "20" );
  516. avps.add( avpFactory.createAvp( 193, 607, new DiameterAvp[]{serviceParameterType2, serviceParameterValue2} ) );
  517. DiameterAvp[] avpArray = new DiameterAvp[avps.size()];
  518. avpArray = avps.toArray(avpArray);
  519. logger.info( "Creating Custom Message..." );
  520. DiameterMessage ms = messageFactory.createAccountingRequest(avpArray);
  521. logger.info( "Created Custom Message[" + ms + "]" );
  522. logger.info( "Sending Custom Message..." );
  523. provider.createActivity().sendMessage( ms );
  524. logger.info( "Sent Custom Message[" + ms + "]" );
  525. }
  526. catch (Exception e)
  527. {
  528. logger.error( "", e );
  529. }
  530. }
  531. }