شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة ش.ش.و.

Integrated Applications Programming Company

Skip Navigation Links

Public general use code classes and xml files that we've compiled and used over the years:

Signaling Service Processing System (SPS) support class for Huawei's Next Generation Network (NGN) SPS client model.

   1:  using Dart.PowerTCP.Telnet;
   2:  using System;
   3:  using System.Collections.Generic;
   4:  using System.Diagnostics;
   5:   
   6:  namespace Ia.Ngn.Cl.Model.Client.Huawei
   7:  {
   8:      ////////////////////////////////////////////////////////////////////////////
   9:   
  10:      /// <summary publish="true">
  11:      /// Signaling Service Processing System (SPS) support class for Huawei's Next Generation Network (NGN) SPS client model.
  12:      /// </summary>
  13:      /// 
  14:      /// <remarks> 
  15:      /// Copyright © 2018-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  16:      ///
  17:      /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
  18:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  19:      ///
  20:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  21:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  22:      /// 
  23:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  24:      /// 
  25:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  26:      /// </remarks> 
  27:      public class Sps
  28:      {
  29:          private byte[] buffer = new byte[1024];
  30:          internal Telnet telnet;
  31:   
  32:          /// <summary/>
  33:          public static int WaitAfterSendInMillisecond { get { return 4000; } }
  34:   
  35:          /// <summary/>
  36:          public static int WaitAfterSendForCfgCommandInMillisecond { get { return 10000; } }
  37:   
  38:          /// <summary/>
  39:          public string LastSentCommand { get; private set; }
  40:   
  41:          /// <summary/>
  42:          public Queue<string> ReceiveQueue { get; set; }
  43:   
  44:          /// <summary/>
  45:          public Queue<string> SendQueue { get; set; }
  46:   
  47:          ////////////////////////////////////////////////////////////////////////////
  48:   
  49:          /// <summary>
  50:          ///
  51:          /// </summary>
  52:          public enum ResultCode
  53:          {
  54:              /*
  55:               * 9 Collection of Error Codes
  56:               * 9.1 Collection of NP Service Related Error Codes
  57:               * Error Code  Description
  58:               */
  59:   
  60:              OperationIsSuccessful = 0,
  61:              InvalidParameterValue__Xxx__For__Yyy__ = 1004,
  62:              ParameterMissing__Yyy__ = 1009,
  63:              DatabaseOperationFailed = 5000,
  64:              LackingOfCompulsoryParameters = 5004,
  65:              SpecifiedRecordNotFound = 5005,
  66:              UserNumberRepeated = 5526,
  67:              TheMnpRouteNumberBeingUsedByMnpUserCanNotBeRemoved = 5579,
  68:              RoutingNumberTypeDoesNotMatchTheMnpUser = 5591,
  69:              HlrNumberTypeDoesNotMatchTheMnpUser = 5592,
  70:              InvalidRnIndex = 5593,
  71:              AtLeastOneOfTheServicesMustBeRegistered = 5594,
  72:              HlrAddressReferencedByAMnpUserCanNotBeDeleted = 5600,
  73:              InvalidHlrIndex = 5602,
  74:              UserImsiNumberCannotBeSameWithExist = 5855,
  75:              TheNpRoutingIndexGivenDoesNotMatch = 5878,
  76:              SystemError = 6000,
  77:              WhenRouteIndexTypeIsSetToRouteNumberIndex_HlrNumberIndexMustBeSetTo65535 = 6015,
  78:              RnNumberIndexMustBe65535WhenRoutingIndexTypeIsHlrAddressIndex = 6018,
  79:              TheNumberOfTheCurrentSubscribersImsisReachesTheLimit = 6300,
  80:              TheCurrentSubscriberUsesMultipleImsis_IfYouWantToChangeAnImsi_RunRmvSeruattrToDeleteThisImsiAndThenRunAddSeruattrToAddAnImsi = 6301,
  81:              WhenNumberTypeIsSetTo_GsmNumberPortedToCdma_Or_CdmaNumberPortedToGsm__RoutingIndexTypeMustBeSetToAll = 7001,
  82:              WhenNumberTypeIsSetTo_LocalFixedNetwork__RoutingIndexTypeMustBeSetTo_RouteNumberIndex = 7300,
  83:              InvalidRoutingNumber = 7369,
  84:              TheInputParameterNameCanContainOnlyDigits_0_9__LowerCaseLetters_A_z__UpperCaseLetters_A_z__Dot_Hyphens____Underscore____AndSpace___ItCannotBeSetToNull = 40003,
  85:              TheIndexAlreadyExists = 40004,
  86:              AnNpSoftwareParameterDataRecordDoesNotExist_RunSetSesoftcfgToSetNpSoftwareParameters = 40011,
  87:              TheRangeSpecifiedByBeginMsisdnAndEndMsisdnOverlapsWithAnExistingRange = 40022,
  88:              TheEnteredValuesOfBeginMsisdnAndEndMsisdnHaveDifferentLengths = 40023,
  89:              TheEnteredValueOfBeginMsisdnIsNotLessThanThatOfEndMsisdn = 40024,
  90:              ThePossibleCauseMayBeOneOfTheFollowing_TheLinkBetweenTheUscdbAndTheSpsIsFaulty_TheNpRangeSwitchOnTheSpsIsClose = 40025,
  91:              ThePossibleCauseMayBeOneOfTheFollowing_ThePpid180PublicParameterOfTheSpsIsSetToASmallValue_ThePpid180PublicParameterOfTheSpsIsSetToTheMaximumValue = 40026,
  92:              TheNumberOfDataRecordsToBeQueriedExceedsTheLimit = 40027,
  93:              TheDataRecordToBeDeletedDoesNotExist_AsAResult_TheDeletionFails = 40028,
  94:              HlrAddressReferencedByAMnp_RangeCanNotBeDeleted = 40029,
  95:              TheMnpRouteNumberBeingUsedByAMnp_RangeCanNotBeRemoved = 40030,
  96:              TheHlrIndexCannotBeRemovedBecauseItIsUsedByAServiceSubscriberCommandAdapt = 40031,
  97:              TheMnpRouteNumberCannotBeRemovedBecauseItIsUsedByAServiceSubscriberCommandAdapt = 40032,
  98:              LackingOfCompulsoryParameters2 = 45004,
  99:              SpecifiedRecordNotFound2 = 45005,
 100:              DescriptionInformationRepeated = 45138,
 101:              RouteNumberAlreadyExists = 45558,
 102:              InvalidParameterDesc = 40001,
 103:              TheValueIsInvalid = 41007,
 104:              NoMatchingResultIsFound = 43257,
 105:              TheNumberOfNpUserExceedsTheLicensedNumber = 43435,
 106:              TheNumberOfFnrUserExceedsTheLicensedNumber = 43436,
 107:              TheLicenseForNpSubscriberDataStorageOnTheSpsHasExpired_ApplyForANewLicense = 43437,
 108:              TheLicenseForFnrSubscriberDataStorageOnTheSpsHasExpired_ApplyForANewLicense = 43438,
 109:              EnsureThatLinksBetweenTheUscdbAndTheSpsAreAvailable_TheP69SoftwareParameterForTheSpsIsCorrectlyConfigured_AndNpSubscriberDataStorageLicenseIsPurchased = 43439,
 110:              EnsureThatLinksBetweenTheUscdbAndTheSpsAreAvailable_TheP69SoftwareParameterForTheSpsIsCorrectlyConfigured_AndFnrSubscriberDataStorageLicenseIsPurchased = 43440,
 111:              EnsureThatTheNpSubscriberDataStorageLicenseIsPurchased = 43441,
 112:              EnsureThatTheFnrSubscriberDataStorageLicenseIsPurchased = 43442
 113:          }
 114:   
 115:          ////////////////////////////////////////////////////////////////////////////
 116:   
 117:          /// <summary>
 118:          ///
 119:          /// </summary>
 120:          public Sps()
 121:          {
 122:              telnet = new Dart.PowerTCP.Telnet.Telnet();
 123:   
 124:              telnet.ClientOptions.Add(new Dart.PowerTCP.Telnet.Option(Dart.PowerTCP.Telnet.OptionCode.SuppressGoAheads, null, Dart.PowerTCP.Telnet.OptionState.RequestOn));
 125:              //telnet.ClientOptions.Add(new Dart.PowerTCP.Telnet.Option(Dart.PowerTCP.Telnet.OptionCode.TerminalType, new System.Byte[] { ((System.Byte)(0)), ((System.Byte)(116)), ((System.Byte)(116)), ((System.Byte)(121)) }, Dart.PowerTCP.Telnet.OptionState.RequestOn)); // tty
 126:              telnet.ClientOptions.Add(new Dart.PowerTCP.Telnet.Option(Dart.PowerTCP.Telnet.OptionCode.TerminalType, new System.Byte[] { ((System.Byte)(0)), ((System.Byte)(120)), ((System.Byte)(116)), ((System.Byte)(101)), ((System.Byte)(114)), ((System.Byte)(109)) }, Dart.PowerTCP.Telnet.OptionState.RequestOn)); // xterm
 127:   
 128:              telnet.ServerOptions.Add(new Dart.PowerTCP.Telnet.Option(Dart.PowerTCP.Telnet.OptionCode.SuppressGoAheads, null, Dart.PowerTCP.Telnet.OptionState.RequestOn));
 129:              telnet.ServerOptions.Add(new Dart.PowerTCP.Telnet.Option(Dart.PowerTCP.Telnet.OptionCode.Echo, null, Dart.PowerTCP.Telnet.OptionState.RequestOn));
 130:              telnet.ServerOptions.Add(new Dart.PowerTCP.Telnet.Option(Dart.PowerTCP.Telnet.OptionCode.OutputPageSize, null, Dart.PowerTCP.Telnet.OptionState.RequestOn));
 131:   
 132:              //telnet.TerminalType = "tty";
 133:              telnet.TerminalType = "xterm";
 134:   
 135:              telnet.EndReceive += new Dart.PowerTCP.Telnet.SegmentEventHandler(this.Telnet_EndReceive);
 136:              telnet.ConnectedChangedEx += new Dart.PowerTCP.Telnet.EventHandlerEx(this.Telnet_ConnectedChangedEx);
 137:   
 138:              ReceiveQueue = new Queue<string>(100);
 139:              SendQueue = new Queue<string>(100);
 140:   
 141:              IsLoggedIn = false;
 142:          }
 143:   
 144:          ////////////////////////////////////////////////////////////////////////////
 145:   
 146:          /// <summary>
 147:          ///
 148:          /// </summary>
 149:          ~Sps()
 150:          {
 151:              Dispose();
 152:          }
 153:   
 154:          ////////////////////////////////////////////////////////////////////////////
 155:   
 156:          /// <summary>
 157:          ///
 158:          /// </summary>
 159:          public void Connect(out Ia.Cl.Model.Result result)
 160:          {
 161:              result = new Ia.Cl.Model.Result();
 162:   
 163:              try
 164:              {
 165:                  telnet.Connect(Ia.Ngn.Cl.Model.Business.Huawei.Sps.Host, Ia.Ngn.Cl.Model.Business.Huawei.Sps.Port.ToString());
 166:   
 167:                  // receive using asynchronous technique
 168:                  telnet.ReceiveTimeout = 0;
 169:                  telnet.BeginReceive(buffer);
 170:   
 171:                  result.AddSuccess("Connected. ");
 172:              }
 173:              catch (Exception ex)
 174:              {
 175:                  result.AddError("Exception: " + ex.Message);
 176:   
 177:                  telnet.Close();
 178:              }
 179:          }
 180:   
 181:          ////////////////////////////////////////////////////////////////////////////
 182:   
 183:          /// <summary>
 184:          ///
 185:          /// </summary>
 186:          public void Disconnect(out Ia.Cl.Model.Result result)
 187:          {
 188:              result = new Ia.Cl.Model.Result();
 189:   
 190:              try
 191:              {
 192:                  telnet.Close();
 193:   
 194:                  result.AddSuccess("Disconnected. ");
 195:              }
 196:              catch (Exception ex)
 197:              {
 198:                  result.AddError(ex.Message);
 199:              }
 200:          }
 201:   
 202:          ////////////////////////////////////////////////////////////////////////////
 203:   
 204:          /// <summary>
 205:          ///
 206:          /// </summary>
 207:          public bool IsConnected
 208:          {
 209:              get
 210:              {
 211:                  return telnet.Connected;
 212:              }
 213:          }
 214:   
 215:          ////////////////////////////////////////////////////////////////////////////
 216:   
 217:          /// <summary>
 218:          ///
 219:          /// </summary>
 220:          public bool IsLoggedIn { get; set; }
 221:   
 222:          ////////////////////////////////////////////////////////////////////////////
 223:   
 224:          /// <summary>
 225:          ///
 226:          /// </summary>
 227:          public void Dispose()
 228:          {
 229:              telnet.Dispose();
 230:          }
 231:   
 232:          ////////////////////////////////////////////////////////////////////////////
 233:   
 234:          /// <summary>
 235:          ///
 236:          /// </summary>
 237:          public void Login()
 238:          {
 239:              SendQueue.Enqueue(Ia.Ngn.Cl.Model.Business.Huawei.Sps.LoginUser);
 240:          }
 241:   
 242:          ////////////////////////////////////////////////////////////////////////////
 243:   
 244:          /// <summary>
 245:          ///
 246:          /// </summary>
 247:          public void Logout()
 248:          {
 249:              SendQueue.Enqueue(Ia.Ngn.Cl.Model.Business.Huawei.Sps.LogoutUser);
 250:          }
 251:   
 252:          ////////////////////////////////////////////////////////////////////////////
 253:   
 254:          /// <summary>
 255:          ///
 256:          /// </summary>
 257:          public void Send(string text, out Ia.Cl.Model.Result result)
 258:          {
 259:              result = new Ia.Cl.Model.Result();
 260:   
 261:              try
 262:              {
 263:                  if (telnet.Connected)
 264:                  {
 265:                      if (text != null)
 266:                      {
 267:                          LastSentCommand = text;
 268:   
 269:                          telnet.Send(";" + text); // bug: I do not know why I have to do this
 270:   
 271:                          result.AddSuccess("Sent: " + text);
 272:                      }
 273:                      else
 274:                      {
 275:                          result.AddError("No text to send. ");
 276:                      }
 277:                  }
 278:                  else
 279:                  {
 280:                      result.AddError("No established telnet connection. ");
 281:                      //if(processRunning) waitToConnectionCounter = waitToConnectionCounterSeconds;
 282:                  }
 283:              }
 284:              catch (Exception ex)
 285:              {
 286:                  result.AddError(ex.Message);
 287:              }
 288:          }
 289:   
 290:          ////////////////////////////////////////////////////////////////////////////
 291:   
 292:          /// <summary>
 293:          ///
 294:          /// </summary>
 295:          private void Telnet_EndReceive(object sender, Dart.PowerTCP.Telnet.SegmentEventArgs e)
 296:          {
 297:              string receiveString;
 298:   
 299:              Debug.WriteLine(" ");
 300:              Debug.WriteLine("============================================");
 301:   
 302:              try
 303:              {
 304:                  if (e.Exception == null)
 305:                  {
 306:                      Debug.WriteLine("Telnet_EndReceive(): e.Segment: [" + e.Segment.ToString() + "]");
 307:   
 308:                      receiveString = e.Segment.ToString();
 309:   
 310:                      if (!string.IsNullOrEmpty(receiveString))
 311:                      {
 312:                          ReceiveQueue.Enqueue(receiveString);
 313:                      }
 314:                      else
 315:                      {
 316:   
 317:                      }
 318:   
 319:                      telnet.BeginReceive(buffer);
 320:                  }
 321:                  else
 322:                  {
 323:                      throw new Exception("Telnet_EndReceive(): " + e.Exception.Message);
 324:                  }
 325:              }
 326:              catch (System.Net.Sockets.SocketException se)
 327:              {
 328:                  Debug.WriteLine("Telnet_EndReceive(): System.Net.Sockets.SocketException: " + se.ToString());
 329:              }
 330:   
 331:              Debug.WriteLine("============================================");
 332:              Debug.WriteLine(" ");
 333:          }
 334:   
 335:          ////////////////////////////////////////////////////////////////////////////
 336:   
 337:          /// <summary>
 338:          ///
 339:          /// </summary>
 340:          private void Telnet_ConnectedChangedEx(object sender, System.EventArgs e)
 341:          {
 342:   
 343:          }
 344:   
 345:          ////////////////////////////////////////////////////////////////////////////
 346:   
 347:          /// <summary>
 348:          ///
 349:          /// </summary>
 350:          public void Update(string rowData, ref Ia.Ngn.Cl.Model.Client.Huawei.Sps sps, out Ia.Cl.Model.Result result)
 351:          {
 352:              Ia.Ngn.Cl.Model.Data.Huawei.Sps.UpdateDatabaseWithSpsCommandOutput(rowData, ref sps, out result);
 353:          }
 354:   
 355:          ////////////////////////////////////////////////////////////////////////////
 356:          ////////////////////////////////////////////////////////////////////////////
 357:      }
 358:   
 359:      ////////////////////////////////////////////////////////////////////////////
 360:      ////////////////////////////////////////////////////////////////////////////
 361:  }