1: using Microsoft.EntityFrameworkCore;
2: using System;
3: using System.Collections.Generic;
4: using System.Configuration;
5: using System.Data;
6: using System.Linq;
7:
8: namespace Ia.Ngn.Cl.Model.Business.Nokia
9: {
10: ////////////////////////////////////////////////////////////////////////////
11:
12: /// <summary publish="true">
13: /// Optical Fiber Network's Operations Support System Management Intranet (OFN OSS) support class for Nokia's Optical Fiber Network (OFN) business model.
14: /// </summary>
15: ///
16: /// <value>
17: /// <appSettings>
18: /// <add key="imsServerHost" value="https://*" />
19: /// <add key="imsServerPort" value="*" />
20: /// <add key="imsServerServiceUrl" value="*" />
21: /// <add key="imsServerUser" value="*" />
22: /// <add key="imsServerUserPassword" value="*" />
23: /// </appSettings>
24: /// </value>
25: ///
26: /// <remarks>
27: /// Copyright © 2014-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
28: ///
29: /// 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
30: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
31: ///
32: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
33: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
34: ///
35: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
36: ///
37: /// Copyright notice: This notice may not be removed or altered from any source distribution.
38: /// </remarks>
39: public class Ims
40: {
41: // below: this is the almost official GwId range used
42:
43: private const int gwIdFirst = 2048;
44: private const int gwIdLast = 65535;
45:
46: private const int primaryPUIDCPEProfileNumberForSip = 10;
47: private const int primaryPUIDCPEProfileNumberForH248 = 35;
48:
49: private const string sipSubscriberRegistrationPassword = "1234"; // as per Nokia spec
50:
51: private static List<int> allPossibleGwIdList = new List<int>();
52: private static List<int> allPossibleServiceNumberList = new List<int>();
53: private static Queue<string> agcfEndpointPrividUserQueue = new Queue<string>();
54:
55: private static Ia.Ngn.Cl.Model.Business.Procedure procedureNokiaImsSubscriberToBeUpdatedFromH248ToSipList = new Ia.Ngn.Cl.Model.Business.Procedure(Ia.Ngn.Cl.Model.Business.Provision.NokiaImsSubscriberToBeUpdatedFromH248ToSipList);
56:
57: /// <summary/>
58: public class ImsBasicService
59: {
60: public string MgcIp;
61: public string MgcSecondaryIp;
62: public string MgcSubnetMask;
63: public int Service;
64: public string Fsdb;
65: public string PrimarySwitch;
66: }
67:
68: /// <summary/>
69: public static ImsBasicService[] ImsBasicServiceList =
70: {
71: new ImsBasicService { MgcIp="10.16.1.31", MgcSecondaryIp="10.16.5.31", MgcSubnetMask="255.255.224.0",Service=0,Fsdb="fsdb0",PrimarySwitch=TEC },
72: new ImsBasicService { MgcIp="10.16.1.32", MgcSecondaryIp="10.16.5.32", MgcSubnetMask="255.255.224.0",Service=1,Fsdb="fsdb1",PrimarySwitch=TEC },
73: new ImsBasicService { MgcIp="10.16.1.33", MgcSecondaryIp="10.16.5.33", MgcSubnetMask="255.255.224.0",Service=2,Fsdb="fsdb1",PrimarySwitch=TEC },
74: new ImsBasicService { MgcIp="10.16.1.34", MgcSecondaryIp="10.16.5.34", MgcSubnetMask="255.255.224.0",Service=3,Fsdb="fsdb1",PrimarySwitch=TEC },
75: new ImsBasicService { MgcIp="10.16.1.35", MgcSecondaryIp="10.16.5.35", MgcSubnetMask="255.255.224.0",Service=4,Fsdb="fsdb2",PrimarySwitch=TEC },
76: new ImsBasicService { MgcIp="10.16.1.36", MgcSecondaryIp="10.16.5.36", MgcSubnetMask="255.255.224.0",Service=5,Fsdb="fsdb2",PrimarySwitch=TEC },
77: new ImsBasicService { MgcIp="10.16.1.37", MgcSecondaryIp="10.16.5.37", MgcSubnetMask="255.255.224.0",Service=6,Fsdb="fsdb2",PrimarySwitch=TEC },
78: new ImsBasicService { MgcIp="10.16.1.38", MgcSecondaryIp="10.16.5.38", MgcSubnetMask="255.255.224.0",Service=7,Fsdb="fsdb3",PrimarySwitch=TEC },
79: new ImsBasicService { MgcIp="10.16.1.39", MgcSecondaryIp="10.16.5.39", MgcSubnetMask="255.255.224.0",Service=8,Fsdb="fsdb3",PrimarySwitch=TEC },
80: new ImsBasicService { MgcIp="10.16.1.40", MgcSecondaryIp="10.16.5.40", MgcSubnetMask="255.255.224.0",Service=9,Fsdb="fsdb3",PrimarySwitch=TEC },
81:
82: new ImsBasicService { MgcIp="10.16.5.31", MgcSecondaryIp="10.16.1.31", MgcSubnetMask="255.255.224.0",Service=0,Fsdb="fsdb0",PrimarySwitch=SKB },
83: new ImsBasicService { MgcIp="10.16.5.32", MgcSecondaryIp="10.16.1.32", MgcSubnetMask="255.255.224.0",Service=1,Fsdb="fsdb1",PrimarySwitch=SKB },
84: new ImsBasicService { MgcIp="10.16.5.33", MgcSecondaryIp="10.16.1.33", MgcSubnetMask="255.255.224.0",Service=2,Fsdb="fsdb1",PrimarySwitch=SKB },
85: new ImsBasicService { MgcIp="10.16.5.34", MgcSecondaryIp="10.16.1.34", MgcSubnetMask="255.255.224.0",Service=3,Fsdb="fsdb1",PrimarySwitch=SKB },
86: new ImsBasicService { MgcIp="10.16.5.35", MgcSecondaryIp="10.16.1.35", MgcSubnetMask="255.255.224.0",Service=4,Fsdb="fsdb2",PrimarySwitch=SKB },
87: new ImsBasicService { MgcIp="10.16.5.36", MgcSecondaryIp="10.16.1.36", MgcSubnetMask="255.255.224.0",Service=5,Fsdb="fsdb2",PrimarySwitch=SKB },
88: new ImsBasicService { MgcIp="10.16.5.37", MgcSecondaryIp="10.16.1.37", MgcSubnetMask="255.255.224.0",Service=6,Fsdb="fsdb2",PrimarySwitch=SKB },
89: new ImsBasicService { MgcIp="10.16.5.38", MgcSecondaryIp="10.16.1.38", MgcSubnetMask="255.255.224.0",Service=7,Fsdb="fsdb3",PrimarySwitch=SKB },
90: new ImsBasicService { MgcIp="10.16.5.39", MgcSecondaryIp="10.16.1.39", MgcSubnetMask="255.255.224.0",Service=8,Fsdb="fsdb3",PrimarySwitch=SKB },
91: new ImsBasicService { MgcIp="10.16.5.40", MgcSecondaryIp="10.16.1.40", MgcSubnetMask="255.255.224.0",Service=9,Fsdb="fsdb3",PrimarySwitch=SKB },
92: };
93:
94: /// <summary/>
95: public static int FirstGatewayId { get { return gwIdFirst; } }
96:
97: /// <summary/>
98: public static int LastGatewayId { get { return gwIdLast; } }
99:
100: /// <summary/>
101: public static string BaseAddress { get { return ConfigurationManager.AppSettings["imsServerHost"].ToString() + ":" + ConfigurationManager.AppSettings["imsServerPort"].ToString(); } }
102:
103: /// <summary/>
104: public static string ServiceUrl { get { return ConfigurationManager.AppSettings["imsServerServiceUrl"].ToString(); } }
105:
106: /// <summary/>
107: public static string UserName { get { return ConfigurationManager.AppSettings["imsServerUser"].ToString(); } }
108:
109: /// <summary/>
110: public static string Password { get { return ConfigurationManager.AppSettings["imsServerUserPassword"].ToString(); } }
111:
112: /// <summary/>
113: public static string AnyPrimarySwitch { get { return TEC; } }
114:
115: /// <summary/>
116: public static string TEC { get { return "TECICS01"; } }
117:
118: /// <summary/>
119: public static string SKB { get { return "SKBICS02"; } }
120:
121:
122: /// <summary/>
123: public const int MaximumCombinedNumberOfAgcfGatewayRecordsInAnyMgcIpAndMgcSecondaryIpPair = 4800; // limit defind by Nokia
124:
125: /// <summary/>
126: public static int PrimaryPUIDCPEProfileNumberForSip { get { return primaryPUIDCPEProfileNumberForSip; } }
127:
128: /// <summary/>
129: public static int PrimaryPUIDCPEProfileNumberForH248 { get { return primaryPUIDCPEProfileNumberForH248; } }
130:
131: /// <summary/>
132: public static string SipSubscriberRegistrationPassword { get { return sipSubscriberRegistrationPassword; } }
133:
134: /// <summary/>
135: public static List<string> FsdbList = new List<string> { "fsdb0", "fsdb1", "fsdb2", "fsdb3" };
136:
137: /// <summary/>
138: public static List<int> NokiaImsPrefixesAsPerNokia2021 = new List<int> { 1810407, 1830011, 22239, 2323, 2324, 2360, 2363, 2364, 2365, 2366, 2367, 2368, 2369, 2374, 2380, 2435, 2436, 2438, 2453, 2454, 2460, 2461, 2464, 2465, 2466, 2468, 2469, 24780, 24781, 24782, 2490, 2493, 24973, 24974, 24975, 24976, 24977, 24978, 24979, 2520, 2521, 2522, 2523, 2524, 2529, };
139:
140: ////////////////////////////////////////////////////////////////////////////
141:
142: /// <summary>
143: /// Response of IMS
144: /// </summary>
145: public class Response
146: {
147: /// <summary/>
148: public int Service { get; set; }
149:
150: /// <summary/>
151: public bool IsSuccess { get { return ResultCode == Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode.Successful; } }
152:
153: /// <summary/>
154: public bool IsProvisioned { get; set; }
155:
156: /// <summary/>
157: public Ia.Ngn.Cl.Model.Client.Nokia.Ims.ResultCode ResultCode { get; set; }
158:
159: /// <summary/>
160: //public string Ctag { get; set; } // no need because the commad string is included in response body
161:
162: /// <summary/>
163: public DateTime DateTime { get; set; }
164:
165: /// <summary/>
166: public string CommandString { get; set; }
167:
168: /// <summary/>
169: public string FailureReason { get; set; }
170:
171: /// <summary/>
172: public string FailureCode { get; set; }
173:
174: /// <summary/>
175: //public Dictionary<string, string> ParameterDictionary { get; set; }
176:
177: /// <summary/>
178: public List<Dictionary<string, string>> ParameterDictionaryList { get; set; }
179:
180: /// <summary/>
181: public Response() { }
182: }
183:
184: ////////////////////////////////////////////////////////////////////////////
185:
186: /// <summary>
187: ///
188: /// </summary>
189: public Ims()
190: {
191: }
192:
193: ////////////////////////////////////////////////////////////////////////////
194:
195: /// <summary>
196: ///
197: /// </summary>
198: public static List<string> NumberOfNokiaH248SubsribersPerFsdb()
199: {
200: string imsFsdb;
201: Dictionary<string, string> ontListNokiaIpToPrimarySwitchImsFsdbDictionary;
202: List<string> list;
203:
204: var dictionary = new Dictionary<string, int>();
205:
206: ontListNokiaIpToPrimarySwitchImsFsdbDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOntIpToPrimarySwitchImsFsdbDictionary;
207:
208: using (var db = new Ia.Ngn.Cl.Model.Ngn())
209: {
210: list = (from e in db.AgcfEndpoints
211: join gr in db.AgcfGatewayRecords on e.AgcfGatewayRecord.Id equals gr.Id
212: select gr.IP1).AsNoTracking().ToList();
213: }
214:
215: foreach (string ip in list)
216: {
217: if (ontListNokiaIpToPrimarySwitchImsFsdbDictionary.ContainsKey(ip))
218: {
219: imsFsdb = ontListNokiaIpToPrimarySwitchImsFsdbDictionary[ip];
220:
221: if (dictionary.ContainsKey(imsFsdb)) dictionary[imsFsdb]++;
222: else dictionary[imsFsdb] = 1;
223: }
224: }
225:
226: list.Clear();
227:
228: foreach (KeyValuePair<string, int> kvp in dictionary)
229: {
230: list.Add(kvp.Key + ": " + kvp.Value);
231: }
232:
233: return list;
234: }
235:
236: ////////////////////////////////////////////////////////////////////////////
237:
238: /// <summary>
239: ///
240: /// </summary>
241: public static List<string> NumberOfNokiaSipSubsribersPerFsdb()
242: {
243: string imsFsdb;
244: Dictionary<string, string> ontListNokiaIpToPrimarySwitchImsFsdbDictionary;
245:
246: var list = new List<string>();
247:
248: var dictionary = new Dictionary<string, int>();
249:
250: ontListNokiaIpToPrimarySwitchImsFsdbDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntIpToPrimarySwitchImsFsdbDictionary;
251:
252: using (var db = new Ia.Ngn.Cl.Model.Ngn())
253: {
254: var list0 = (from s in db.Subscribers
255: join sp in db.SubParties on s.SubParty.Id equals sp.Id
256: join eosi in db.EmsOntSipInfoes on s.PartyId equals eosi.SIPUSERNAME
257: join eo in db.EmsOnts on eosi.EmsOnt.Id equals eo.Id
258: select eo.Id).AsNoTracking().ToList();
259:
260: var list1 = (from s in db.Subscribers
261: join sp in db.SubParties on s.SubParty.Id equals sp.Id
262: join evpu in db.EmsVoipPstnUsers on s.PartyId equals "+" + evpu.DN
263: join eo in db.EmsOnts on evpu.EmsOnt.Id equals eo.Id
264: select eo.Id).AsNoTracking().ToList();
265:
266: var list3 = list0.Concat(list1).ToList();
267:
268: var ontIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntIdToOntDictionary;
269:
270: foreach (var id in list3)
271: {
272: if (ontIdToOntDictionary.ContainsKey(id))
273: {
274: list.Add(ontIdToOntDictionary[id].Ip);
275: }
276: }
277: }
278:
279: foreach (string ip in list)
280: {
281: if (ontListNokiaIpToPrimarySwitchImsFsdbDictionary.ContainsKey(ip))
282: {
283: imsFsdb = ontListNokiaIpToPrimarySwitchImsFsdbDictionary[ip];
284:
285: if (dictionary.ContainsKey(imsFsdb)) dictionary[imsFsdb]++;
286: else dictionary[imsFsdb] = 1;
287: }
288: }
289:
290: list.Clear();
291:
292: foreach (KeyValuePair<string, int> kvp in dictionary)
293: {
294: list.Add(kvp.Key + ": " + kvp.Value);
295: }
296:
297: return list;
298: }
299:
300: ////////////////////////////////////////////////////////////////////////////
301:
302: /// <summary>
303: ///
304: /// </summary>
305: public static int NextVacantFlatTermIdFromAgcfEndpointUsingGwId(Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType familyType, int gwId)
306: {
307: int ft;
308: List<int> list;
309:
310: list = Ia.Ngn.Cl.Model.Data.Nokia.AgcfEndpoint.UsedFlatTermIdListForGatewayId(gwId);
311:
312: if (list.Count == 0) ft = 1; // this means agcfEndpoint does not exist for any number and the box is empty, and we should create agcfEndpoint at 1
313: else
314: {
315: // change this later to accommodate the Huawei ONT type
316: list = Ia.Cl.Model.Default.ExcludedNumberListFromNumberListWithinRange(list, Ia.Ngn.Cl.Model.Business.Nokia.Ont.PossibleNumberOfTdForOntFamilyType(familyType));
317:
318: if (list.Count > 0) ft = list[0];
319: else ft = 0; // something went wrong
320: }
321:
322: return ft;
323: }
324:
325: ////////////////////////////////////////////////////////////////////////////
326:
327: /// <summary>
328: /// Check the number of combined AGCF gateway records for this MGC IP and its secondary MGC IP if they exceed the MaximumCombinedNumberOfAgcfGatewayRecordsInAnyMgcIpAndMgcSecondaryIpPair
329: /// </summary>
330: public static bool MaximumCombinedNumberOfAgcfGatewayRecordsInAnyMgcIpAndMgcSecondaryIpPairIsExceeded(string mgcIp)
331: {
332: bool isExceeded;
333: int count;
334: ImsBasicService imsBasicServiceItem;
335:
336: imsBasicServiceItem = ImsBasicServiceItem(mgcIp);
337:
338: if (imsBasicServiceItem != null)
339: {
340: using (var db = new Ia.Ngn.Cl.Model.Ngn())
341: {
342: count = (from gr in db.AgcfGatewayRecords
343: where gr.MateExternalIPAddr == imsBasicServiceItem.MgcIp || gr.MateExternalIPAddr == imsBasicServiceItem.MgcSecondaryIp
344: select gr.Id).Count();
345:
346: isExceeded = (count > MaximumCombinedNumberOfAgcfGatewayRecordsInAnyMgcIpAndMgcSecondaryIpPair);
347: }
348: }
349: else throw new System.ArgumentException("imsBasicServiceItem cannot be null", "imsBasicServiceItem");
350:
351: return isExceeded;
352: }
353:
354: ////////////////////////////////////////////////////////////////////////////
355:
356: /// <summary>
357: /// Statistics dictionary of the current AGCF Gateway Record by MGC gateway IP
358: /// </summary>
359: public static Dictionary<string, int> NumberOfAgcfGatewayRecordInGroupOfMgcIpDictionary
360: {
361: get
362: {
363: Dictionary<string, int> dictionary;
364:
365: using (var db = new Ia.Ngn.Cl.Model.Ngn())
366: {
367: dictionary = (from gr in db.AgcfGatewayRecords
368: group gr.MateExternalIPAddr by gr.MateExternalIPAddr into g
369: select new { MateExternalIPAddr = g.Key, Count = g.Count() }).AsNoTracking().ToDictionary(t => t.MateExternalIPAddr, t => t.Count);
370: }
371:
372: return dictionary;
373: }
374: }
375:
376: ////////////////////////////////////////////////////////////////////////////
377:
378: /// <summary>
379: /// Statistics dictionary of the current AGCF gateway records with corresponding AGCF endpoints by MGC gateway IP
380: /// </summary>
381: public static Dictionary<string, int> NumberOfAgcfGatewayRecordWithCorrespondingAgcfEndpointInGroupOfMgcIpDictionary
382: {
383: get
384: {
385: Dictionary<string, int> dictionary;
386:
387: using (var db = new Ia.Ngn.Cl.Model.Ngn())
388: {
389: dictionary = (from gr in db.AgcfGatewayRecords
390: join ep in db.AgcfEndpoints on new { gr.Id } equals new { ep.AgcfGatewayRecord.Id }
391: group gr.MateExternalIPAddr by gr.MateExternalIPAddr into g
392: select new { MateExternalIPAddr = g.Key, Count = g.Count() }).ToDictionary(t => t.MateExternalIPAddr, t => t.Count);
393: }
394:
395: return dictionary;
396: }
397: }
398:
399: ////////////////////////////////////////////////////////////////////////////
400:
401: /// <summary>
402: /// Calculate a pseudo random MGC IP from imsBasicServiceList for this ONT IP
403: /// </summary>
404: public static string PseudoRandomMgcIp(string ontIp)
405: {
406: uint ui, randomIndex;
407: string mgcIp;
408:
409: if (!string.IsNullOrEmpty(ontIp))
410: {
411: ui = Ia.Cl.Model.Default.IpToUint(ontIp);
412:
413: // important: any change to imsBasicServiceList length will cause the pseudo random function to produce different values for IPs
414: randomIndex = ui % (uint)ImsBasicServiceList.Count();
415:
416: mgcIp = ImsBasicServiceList[randomIndex].MgcIp;
417: }
418: else mgcIp = string.Empty;
419:
420: return mgcIp;
421: }
422:
423: ////////////////////////////////////////////////////////////////////////////
424:
425: /// <summary>
426: /// Return the IMS basic service for given MGC IP
427: /// </summary>
428: public static ImsBasicService ImsBasicServiceItem(string mgcIp)
429: {
430: ImsBasicService imsBasicService;
431:
432: imsBasicService = (from ibs in ImsBasicServiceList where ibs.MgcIp == mgcIp select ibs).SingleOrDefault();
433:
434: return imsBasicService;
435: }
436:
437: ////////////////////////////////////////////////////////////////////////////
438:
439: /// <summary>
440: ///
441: /// </summary>
442: public static string ImsFsdb(int imsService, string primarySwitch)
443: {
444: string fsdb;
445: ImsBasicService imsBasicService;
446:
447: if (imsService >= 0)
448: {
449: imsBasicService = (from ibs in ImsBasicServiceList where ibs.Service == imsService && ibs.PrimarySwitch == primarySwitch select ibs).SingleOrDefault();
450:
451: fsdb = (imsBasicService != null) ? imsBasicService.Fsdb : string.Empty;
452: }
453: else fsdb = string.Empty;
454:
455: return fsdb;
456: }
457:
458: ////////////////////////////////////////////////////////////////////////////
459:
460: /// <summary>
461: ///
462: /// </summary>
463: public static string AgcfSipIaPort(int imsService)
464: {
465: // see ImsServiceFromAgcfSipIaPort()
466: string agcfSipIaPort;
467:
468: switch (imsService)
469: {
470: case 0: agcfSipIaPort = "agcf-stdn.imsgroup0-00" + imsService; break;
471: case 1:
472: case 2:
473: case 3: agcfSipIaPort = "agcf-stdo.imsgroup0-00" + imsService; break;
474: case 4:
475: case 5:
476: case 6: agcfSipIaPort = "agcf-stdp.imsgroup0-00" + imsService; break;
477: case 7:
478: case 8:
479: case 9: agcfSipIaPort = "agcf-stdq.imsgroup0-00" + imsService; break;
480: default: agcfSipIaPort = null; break;
481: }
482:
483: return agcfSipIaPort;
484: }
485:
486: ////////////////////////////////////////////////////////////////////////////
487:
488: /// <summary>
489: ///
490: /// </summary>
491: public static int ImsServiceFromAgcfSipIaPort(string agcfSipIaPort)
492: {
493: // see AgcfSipIaPort()
494: int imsService;
495:
496: switch (agcfSipIaPort)
497: {
498: case "agcf-stdn.imsgroup0-000": imsService = 0; break;
499: case "agcf-stdo.imsgroup0-001": imsService = 1; break;
500: case "agcf-stdo.imsgroup0-002": imsService = 2; break;
501: case "agcf-stdo.imsgroup0-003": imsService = 3; break;
502: case "agcf-stdp.imsgroup0-004": imsService = 4; break;
503: case "agcf-stdp.imsgroup0-005": imsService = 5; break;
504: case "agcf-stdp.imsgroup0-006": imsService = 6; break;
505: case "agcf-stdq.imsgroup0-007": imsService = 7; break;
506: case "agcf-stdq.imsgroup0-008": imsService = 8; break;
507: case "agcf-stdq.imsgroup0-009": imsService = 9; break;
508: default: imsService = -1; break;
509: }
510:
511: return imsService;
512: }
513:
514: ////////////////////////////////////////////////////////////////////////////
515:
516: /// <summary>
517: ///
518: /// </summary>
519: public static string AlternateFsdbFqdn(string primarySwitch, string fsdb)
520: {
521: string alternateFsdbFqdn;
522:
523: if (primarySwitch == TEC)
524: {
525: switch (fsdb)
526: {
527: case "fsdb0": alternateFsdbFqdn = "10.16.0.88"; break;
528: case "fsdb1": alternateFsdbFqdn = "10.16.0.89"; break;
529: case "fsdb2": alternateFsdbFqdn = "10.16.0.90"; break;
530: case "fsdb3": alternateFsdbFqdn = "10.16.0.91"; break;
531: default: alternateFsdbFqdn = string.Empty; break;
532: }
533: }
534: else if (primarySwitch == SKB)
535: {
536: switch (fsdb)
537: {
538: case "fsdb0": alternateFsdbFqdn = "10.16.0.9"; break;
539: case "fsdb1": alternateFsdbFqdn = "10.16.0.10"; break;
540: case "fsdb2": alternateFsdbFqdn = "10.16.0.11"; break;
541: case "fsdb3": alternateFsdbFqdn = "10.16.0.12"; break;
542: default: alternateFsdbFqdn = string.Empty; break;
543: }
544: }
545: else throw new Exception("Unknown primarySwitch") { };
546:
547: return alternateFsdbFqdn;
548: }
549:
550: ////////////////////////////////////////////////////////////////////////////
551:
552: /// <summary>
553: ///
554: /// </summary>
555: public static void AssocAndAlternateOtasRealm(string primarySwitch, string fsdb, out int applicationServerId, out string assocOtasRealm, out string alternateOtasRealm)
556: {
557: bool randomState;
558:
559: randomState = Ia.Cl.Model.Default.RandomBool;
560:
561: switch (fsdb)
562: {
563: case "fsdb0": applicationServerId = 0; break;
564: case "fsdb1": applicationServerId = randomState ? 1 : 2; break;
565: case "fsdb2": applicationServerId = randomState ? 3 : 4; break;
566: case "fsdb3": applicationServerId = randomState ? 5 : 6; break;
567: default: throw new Exception("Unknown fsdb") { };
568: }
569:
570: if (primarySwitch == TEC)
571: {
572: assocOtasRealm = "stas-stdn.fsimsgroup0-00" + applicationServerId + @".tecics01.ims.moc1.kw";
573: }
574: else if (primarySwitch == SKB)
575: {
576: assocOtasRealm = "stas-stdn.fsimsgroup0-00" + applicationServerId + @".skbics01.ims.moc1.kw";
577: }
578: else throw new Exception("Unknown primarySwitch") { };
579:
580: //
581: if (assocOtasRealm.Contains("skbics01"))
582: {
583: alternateOtasRealm = assocOtasRealm.Replace("skbics01", "tecics01");
584: }
585: else if (assocOtasRealm.Contains("tecics01"))
586: {
587: alternateOtasRealm = assocOtasRealm.Replace("tecics01", "skbics01");
588: }
589: else throw new Exception("Unknown primarySwitch") { };
590: }
591:
592: ////////////////////////////////////////////////////////////////////////////
593:
594: /// <summary>
595: ///
596: /// </summary>
597: public static string AssigneCorrectMateExternalIPAddrForIsPrimary(bool isPrimary, string mateExternalIPAddr)
598: {
599: string mate;
600:
601: if (isPrimary)
602: {
603: mate = mateExternalIPAddr;
604: }
605: else
606: {
607: switch (mateExternalIPAddr)
608: {
609: case "10.16.1.31": mate = "10.16.5.31"; break;
610: case "10.16.1.32": mate = "10.16.5.32"; break;
611: case "10.16.1.33": mate = "10.16.5.33"; break;
612: case "10.16.1.34": mate = "10.16.5.34"; break;
613: case "10.16.1.35": mate = "10.16.5.35"; break;
614: case "10.16.1.36": mate = "10.16.5.36"; break;
615: case "10.16.1.37": mate = "10.16.5.37"; break;
616: case "10.16.1.38": mate = "10.16.5.38"; break;
617: case "10.16.1.39": mate = "10.16.5.39"; break;
618: case "10.16.1.40": mate = "10.16.5.40"; break;
619:
620: case "10.16.5.31": mate = "10.16.1.31"; break;
621: case "10.16.5.32": mate = "10.16.1.32"; break;
622: case "10.16.5.33": mate = "10.16.1.33"; break;
623: case "10.16.5.34": mate = "10.16.1.34"; break;
624: case "10.16.5.35": mate = "10.16.1.35"; break;
625: case "10.16.5.36": mate = "10.16.1.36"; break;
626: case "10.16.5.37": mate = "10.16.1.37"; break;
627: case "10.16.5.38": mate = "10.16.1.38"; break;
628: case "10.16.5.39": mate = "10.16.1.39"; break;
629: case "10.16.5.40": mate = "10.16.1.40"; break;
630:
631: default: mate = null; break;
632: }
633: }
634:
635: return mate;
636: }
637:
638: ////////////////////////////////////////////////////////////////////////////
639:
640: /// <summary>
641: ///
642: /// </summary>
643: public static string PrimarySwitchFromAgcfGatewayRecord(bool isPrimary)
644: {
645: string primarySwitch;
646:
647: if (isPrimary) primarySwitch = Ia.Ngn.Cl.Model.Business.Nokia.Ims.AnyPrimarySwitch;
648: else primarySwitch = Ia.Ngn.Cl.Model.Business.Nokia.Ims.SKB;
649:
650: return primarySwitch;
651: }
652:
653: ////////////////////////////////////////////////////////////////////////////
654:
655: /// <summary>
656: ///
657: /// </summary>
658: public static string SecondarySwitchFromAgcfGatewayRecord(bool isPrimary)
659: {
660: string secondarySwitch;
661:
662: if (!isPrimary) secondarySwitch = Ia.Ngn.Cl.Model.Business.Nokia.Ims.AnyPrimarySwitch;
663: else secondarySwitch = Ia.Ngn.Cl.Model.Business.Nokia.Ims.SKB;
664:
665: return secondarySwitch;
666: }
667:
668: ////////////////////////////////////////////////////////////////////////////
669:
670: /// <summary>
671: ///
672: /// </summary>
673: public static int ServiceProfileNumber(int applicationServerId)
674: {
675: int serviceProfileNumber;
676:
677: switch (applicationServerId)
678: {
679: case 0: serviceProfileNumber = 2; break;
680: case 1: serviceProfileNumber = 10; break;
681: case 2: serviceProfileNumber = 18; break;
682: case 3: serviceProfileNumber = 26; break;
683: case 4: serviceProfileNumber = 34; break;
684: case 5: serviceProfileNumber = 42; break;
685: case 6: serviceProfileNumber = 50; break;
686: default: throw new Exception("Unknown primarySwitch") { };
687: }
688:
689: return serviceProfileNumber;
690: }
691:
692: ////////////////////////////////////////////////////////////////////////////
693:
694: /// <summary>
695: ///
696: /// </summary>
697: public static int ServiceProfileNumberAgcfGatewayRecord(int imsService)
698: {
699: bool randomState;
700: int serviceProfileNumber;
701:
702: randomState = Ia.Cl.Model.Default.RandomBool;
703:
704: switch (imsService)
705: {
706: case 0: serviceProfileNumber = 2; break;
707: case 1:
708: case 2:
709: case 3: serviceProfileNumber = randomState ? 10 : 18; break;
710: case 4:
711: case 5:
712: case 6: serviceProfileNumber = randomState ? 26 : 34; break;
713: case 7:
714: case 8:
715: case 9: serviceProfileNumber = randomState ? 42 : 50; break;
716: default: throw new Exception("Unknown primarySwitch") { };
717: }
718:
719: return serviceProfileNumber;
720: }
721:
722: ////////////////////////////////////////////////////////////////////////////
723:
724: /// <summary>
725: ///
726: /// </summary>
727: public static int GwIdToReadAgcfGatewayRecordData(ref int referenceIndex, out int itemIndex, out int listCount)
728: {
729: if (allPossibleGwIdList.JustStartedOrRolledOver())
730: {
731: allPossibleGwIdList = Ia.Ngn.Cl.Model.Data.Nokia.Ims.AllPossibleGatewayIdList;
732: }
733:
734: var number = allPossibleGwIdList.Next(ref referenceIndex, out itemIndex, out listCount);
735:
736: return number;
737: }
738:
739: ////////////////////////////////////////////////////////////////////////////
740:
741: /// <summary>
742: ///
743: /// </summary>
744: public static string ServiceToReadServiceData(ref int referenceIndex, out int itemIndex, out int listCount)
745: {
746: if (allPossibleServiceNumberList.JustStartedOrRolledOver())
747: {
748: allPossibleServiceNumberList = Ia.Ngn.Cl.Model.Data.Service.AllPossibleServiceNumberListWithinNokiaSwitch;
749: }
750:
751: var service = allPossibleServiceNumberList.Next(ref referenceIndex, out itemIndex, out listCount);
752:
753: return service.ToString();
754: }
755:
756: ////////////////////////////////////////////////////////////////////////////
757:
758: /// <summary>
759: ///
760: /// </summary>
761: public static string SequentialPrividUserFromAgcfEndpointToReadSubPartyAndSubscriberData
762: {
763: get
764: {
765: string prividUser;
766:
767: if (agcfEndpointPrividUserQueue.Count == 0)
768: {
769: agcfEndpointPrividUserQueue = new Queue<string>(Ia.Ngn.Cl.Model.Data.Nokia.AgcfEndpoint.ReadPrividUserList);
770: }
771:
772: prividUser = agcfEndpointPrividUserQueue.Dequeue();
773:
774: return prividUser;
775: }
776: }
777:
778: ////////////////////////////////////////////////////////////////////////////
779: ////////////////////////////////////////////////////////////////////////////
780:
781: /// <summary>
782: ///
783: /// </summary>
784: public static Ia.Cl.Model.Result CreateMissingAgcfGatewayRecordForNokiaSwitchOntInNonSipOlt(Ia.Ngn.Cl.Model.Client.Nokia.Ims nokiaIms)
785: {
786: string r1;
787:
788: var result = new Ia.Cl.Model.Result();
789:
790: var nddOnt = Ia.Ngn.Cl.Model.Data.Provision.NddNokiaSwitchOntInNonSipOltWithAccessButNoAgcfGatewayRecord(out string r0);
791:
792: if (nddOnt != null)
793: {
794: var gwId = Ia.Ngn.Cl.Model.Business.Nokia.AgcfGatewayRecord.RandomUnusedGwId();
795:
796: Ia.Ngn.Cl.Model.Data.Nokia.Ims.CreateAgcfGatewayRecordForGwId(nokiaIms, gwId, nddOnt, out string createResult);
797:
798: Ia.Ngn.Cl.Model.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(nokiaIms, gwId, out string readResult);
799:
800: r1 = r0 + " " + nddOnt.Access.Name + ", gwId: " + gwId + ", createResult: " + createResult + ", readResult: " + readResult;
801: }
802: else
803: {
804: r1 = "There are no Nokia switch non SIP OLT NDD ONTs with access and without an AgcfGatewayRecord. ";
805: }
806:
807: result.AddSuccess(r1);
808:
809: return result;
810: }
811:
812: ////////////////////////////////////////////////////////////////////////////
813:
814: /// <summary>
815: ///
816: /// </summary>
817: public static Ia.Cl.Model.Result DeleteAgcfGatewayRecordWithNoNddNokiaSwitchOntInNonSipOltAndNullOrEmptyAgcfEndpoint(Ia.Ngn.Cl.Model.Client.Nokia.Ims nokiaIms)
818: {
819: var r0 = string.Empty;
820: var result = new Ia.Cl.Model.Result();
821:
822: var agcfGatewayRecord = Ia.Ngn.Cl.Model.Data.Provision.AgcfGatewayRecordWithNoNddNokiaSwitchOntInNonSipOltAndNullOrEmptyAgcfEndpoint(out string r1);
823:
824: try
825: {
826: if (agcfGatewayRecord != null)
827: {
828: Ia.Ngn.Cl.Model.Data.Nokia.Ims.DeleteAgcfGatewayRecordForGwId(nokiaIms, agcfGatewayRecord, out string deleteResult);
829:
830: Ia.Ngn.Cl.Model.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(nokiaIms/*, null*/, agcfGatewayRecord.GwId, out string readResult);
831:
832: r0 = "GwId: " + agcfGatewayRecord.GwId + ", deleteResult: " + deleteResult + ", readResult: " + readResult;
833: }
834: else
835: {
836: r0 = "There are no AgcfGatewayRecords with no Nokia switch, non SIP OLT NDD ONTs and with null or empty AgcfEndpoint. ";
837: }
838: }
839: catch (Exception)
840: {
841: r0 = "Exception: " + r0;
842: }
843:
844: r0 = r1 + " " + r0;
845: result.AddSuccess(r0);
846:
847: return result;
848: }
849:
850: ////////////////////////////////////////////////////////////////////////////
851:
852: /// <summary>
853: ///
854: /// </summary>
855: private void ManageNokiaUpdateAgcfGatewayRecord(Ia.Ngn.Cl.Model.Client.Nokia.Ims nokiaIms, out string result)
856: {
857: string r1;
858: int gwId;
859: Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
860: Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
861:
862: r1 = string.Empty;
863: result = string.Empty;
864:
865: agcfGatewayRecord = Ia.Ngn.Cl.Model.Data.Nokia.AgcfGatewayRecord.ListByMateExternalIPAddr("10.16.1.36").PickRandom();
866:
867: try
868: {
869: if (agcfGatewayRecord != null)
870: {
871: gwId = agcfGatewayRecord.GwId;
872: nddOnt = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntByIp(agcfGatewayRecord.IP1);
873: //nddOnt = (from no in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where no.Ip == agcfGatewayRecord.IP1 select no).SingleOrDefault();
874:
875: if (nddOnt != null)
876: {
877: nokiaIms.EdNgfsAgcfGatewayRecordV2_MateExternalIPAddr(gwId, "10.16.5.36", nddOnt, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response);
878:
879: Ia.Ngn.Cl.Model.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(nokiaIms, gwId, out result);
880:
881: result = nddOnt.Access.Name + ", gwId: " + gwId + ", ResultCode: " + response.ResultCode.ToString() + ", result: " + result.ToString();
882: }
883: else
884: {
885: result = "nddOnt null. ";
886: }
887: }
888: else
889: {
890: result = "agcfGatewayRecord is null. ";
891: }
892: }
893: catch (Exception)
894: {
895: result = "Exception: " + result;
896: }
897:
898: result = "Updated: " + r1 + " " + result;
899: }
900:
901: ////////////////////////////////////////////////////////////////////////////
902:
903: /// <summary>
904: ///
905: /// </summary>
906: private void DeleteAgcfGatewayRecordList(Ia.Ngn.Cl.Model.Client.Nokia.Ims nokiaIms, List<int> list, out string result)
907: {
908: string primarySwitch;
909: //Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
910:
911: result = string.Empty;
912:
913: try
914: {
915: foreach (int gwId in list)
916: {
917: //agcfGatewayRecord = Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord.ReadByGwId(0);
918:
919: //if (agcfGatewayRecord != null)
920: //{
921: primarySwitch = Ia.Ngn.Cl.Model.Business.Nokia.Ims.SKB;// Ia.Ngn.Cl.Model.Business.Nokia.Ims.PrimarySwitchFromAgcfGatewayRecord(agcfGatewayRecord.IsPrimary);
922:
923: nokiaIms.DltNgfsAgcfGwCombinedRecV2(gwId, primarySwitch, out Ia.Ngn.Cl.Model.Business.Nokia.Ims.Response response);
924:
925: Ia.Ngn.Cl.Model.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(nokiaIms/*, null*/, gwId, out result);
926:
927: result = "GwId: " + gwId + ", dltResultCode: " + response.ResultCode.ToString() + ", result: " + result.ToString();
928: //}
929: //else
930: //{
931: // result = "agcfGatewayRecord is null. ";
932: //}
933: }
934: }
935: catch (Exception)
936: {
937: result = "Exception: " + result;
938: }
939:
940: result = "Delete AgcfGatewayRecord list: " + result;
941: }
942:
943: ////////////////////////////////////////////////////////////////////////////
944: ////////////////////////////////////////////////////////////////////////////
945:
946: /// <summary>
947: ///
948: /// </summary>
949: public static void ManageModifyNokiaSwitchSubscriberH248ToSip(Ia.Ngn.Cl.Model.Client.Nokia.Ims ims, out Ia.Cl.Model.Result result)
950: {
951: string r;
952: Ia.Ngn.Cl.Model.Business.Procedure.Process process;
953:
954: result = new Ia.Cl.Model.Result();
955:
956: process = procedureNokiaImsSubscriberToBeUpdatedFromH248ToSipList.NextProcess();
957:
958: if (process.Type != Ia.Ngn.Cl.Model.Business.Procedure.ProcessType.None)
959: {
960: if (process.Type == Ia.Ngn.Cl.Model.Business.Procedure.ProcessType.DeleteRead)
961: {
962: result.AddSuccess("delete-read H.248: " + process.Ont.Access.Name + " " + procedureNokiaImsSubscriberToBeUpdatedFromH248ToSipList.ProgressCounterString);
963:
964: Ia.Ngn.Cl.Model.Business.Provision.DeleteReadNokiaSwitchSubscriber(ims, process.Ont.Access.Name, process.Service, process.Protocol, false, out r);
965:
966: result.AddSuccess(r);
967: }
968: else if (process.Type == Ia.Ngn.Cl.Model.Business.Procedure.ProcessType.CreateRead)
969: {
970: result.AddSuccess("create-read SIP: " + process.Ont.Access.Name + " " + procedureNokiaImsSubscriberToBeUpdatedFromH248ToSipList.ProgressCounterString);
971:
972: Ia.Ngn.Cl.Model.Business.Provision.CreateReadNokiaSwitchSubscriber(ims, process.Ont.Access.Name, process.Service, Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown, process.Protocol, false, out r);
973:
974: result.AddSuccess(r);
975: }
976: else result.AddSuccess("delete-read, create-read: undefined procedure. ");
977: }
978: else result.AddSuccess("delete-read, create-read: nothing to update");
979: }
980:
981: ////////////////////////////////////////////////////////////////////////////
982: ////////////////////////////////////////////////////////////////////////////
983:
984: /// <summary>
985: ///
986: /// </summary>
987: public static bool TemporaryProcedureToDetectASessionInvalidAndStopProcessing(Ia.Cl.Model.Result result)
988: {
989: bool b;
990:
991: b = result.Message.Contains("SessionInvalid") || result.Message.Contains("Session");
992:
993: return b;
994: }
995:
996: ////////////////////////////////////////////////////////////////////////////
997: ////////////////////////////////////////////////////////////////////////////
998: }
999:
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
}