1: using System;
2: using System.Collections.Generic;
3: using System.Globalization;
4: using System.IO;
5: using System.Net;
6: using System.Xml;
7:
8: namespace Ia.Ngn.Cl.Model.Client.Nokia
9: {
10: ////////////////////////////////////////////////////////////////////////////
11:
12: /// <summary publish="true">
13: /// Optical Fiber Network's Operations Support System Management Intranet (OFN OSS) client support class for Nokia's Optical Fiber Network (OFN) client model.
14: /// </summary>
15: ///
16: /// <remarks>
17: /// Copyright © 2018-2022 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
18: ///
19: /// 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
20: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
21: ///
22: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
23: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
24: ///
25: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
26: ///
27: /// Copyright notice: This notice may not be removed or altered from any source distribution.
28: /// </remarks>
29: public class Sdc
30: {
31: ////////////////////////////////////////////////////////////////////////////
32:
33: /// <summary>
34: ///
35: /// </summary>
36: public enum ResultCode
37: {
38: Successful = 0, // added by me
39: Failure = 100001, // added by me
40: DocumentElementIsNull = 100002, // added by me
41: }
42:
43: ////////////////////////////////////////////////////////////////////////////
44:
45: /// <summary>
46: ///
47: /// </summary>
48: public Sdc()
49: {
50: // below: trust all certificates
51: // below: see http://stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel
52:
53: System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
54: //ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
55:
56: System.Net.ServicePointManager.Expect100Continue = true;
57: //System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
58: //System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
59: System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
60: }
61:
62: ////////////////////////////////////////////////////////////////////////////
63:
64: /// <summary>
65: ///
66: /// </summary>
67: public void EnablePerformanceMonitoringDataOverPon(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Pon pon, out Ia.Ngn.Cl.Model.Business.Nokia.Sdc.Response response)
68: {
69: string endPoint;
70: XmlDocument soapEnvelopeXml, soapResponseEnvelopeXmlDocument;
71:
72: endPoint = "PerformanceManagementControlExtns";
73:
74: soapEnvelopeXml = EnablePerformanceMonitoringDataOverPonSoapEnvelopeXml(pon, endPoint);
75:
76: SendSoapRequestAndReadResponse(endPoint, soapEnvelopeXml, out soapResponseEnvelopeXmlDocument);
77:
78: response = ParseSoapResponseXml(soapResponseEnvelopeXmlDocument);
79: }
80:
81: ////////////////////////////////////////////////////////////////////////////
82:
83: /// <summary>
84: ///
85: /// </summary>
86: public void DisablePerformanceMonitoringDataOverPon(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Pon pon, out Ia.Ngn.Cl.Model.Business.Nokia.Sdc.Response response)
87: {
88: string endPoint;
89: XmlDocument soapEnvelopeXml, soapResponseEnvelopeXmlDocument;
90:
91: endPoint = "PerformanceManagementControlExtns";
92:
93: soapEnvelopeXml = DisablePerformanceMonitoringDataOverPonSoapEnvelopeXml(pon, endPoint);
94:
95: SendSoapRequestAndReadResponse(endPoint, soapEnvelopeXml, out soapResponseEnvelopeXmlDocument);
96:
97: response = ParseSoapResponseXml(soapResponseEnvelopeXmlDocument);
98: }
99:
100: ////////////////////////////////////////////////////////////////////////////
101:
102: /// <summary>
103: ///
104: /// </summary>
105: public Ia.Ngn.Cl.Model.Business.Nokia.Sdc.Response GetPerformanceMonitoringDataOverPon(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Pon pon)
106: {
107: string endPoint;
108: XmlDocument soapEnvelopeXml, soapResponseEnvelopeXmlDocument;
109:
110: endPoint = "PerformanceManagementRetrievalExtns";
111:
112: soapEnvelopeXml = GetPerformanceMonitoringDataOverPonSoapEnvelopeXml(pon, endPoint);
113:
114: SendSoapRequestAndReadResponse(endPoint, soapEnvelopeXml, out soapResponseEnvelopeXmlDocument);
115:
116: var response = ParseSoapResponseXml(soapResponseEnvelopeXmlDocument);
117:
118: return response;
119: }
120:
121: ////////////////////////////////////////////////////////////////////////////
122: ////////////////////////////////////////////////////////////////////////////
123:
124:
125:
126:
127:
128:
129:
130:
131: ////////////////////////////////////////////////////////////////////////////
132: ////////////////////////////////////////////////////////////////////////////
133:
134: /// <summary>
135: ///
136: /// </summary>
137: private static XmlDocument EnablePerformanceMonitoringDataOverPonSoapEnvelopeXml(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Pon pon, string endPoint)
138: {
139: string version, author, soapEnvelopeBodyXml;
140: XmlDocument soapEnvelopeXml;
141:
142: version = Ia.Cl.Model.Default.RandomNumber(12);
143: author = Ia.Cl.Model.Default.RandomNumber(12);
144:
145: soapEnvelopeBodyXml = @"
146: <sdc:EnablePerformanceMonitoringDataRequest>
147:
148: <sdc:pmObjectSelect>
149: <tmf:mdNm>AMS</tmf:mdNm>
150: <tmf:meNm>" + pon.PonGroup.Olt.AmsName + @"</tmf:meNm>
151: <tmf:propNm>/type=PON Port/" + pon.RxSxLtxPonx + @"</tmf:propNm>
152: </sdc:pmObjectSelect>
153:
154: <sdc:pmParameterList>
155: <sdc:pmParameter>
156: <sdc:pmParameterName>gponOltSidePonUtilTxPmCurrentIntervalTotalBytes</sdc:pmParameterName>
157: </sdc:pmParameter>
158: </sdc:pmParameterList>
159:
160: </sdc:EnablePerformanceMonitoringDataRequest>";
161:
162: soapEnvelopeXml = SoapEnvelopeXml(endPoint, version, author, soapEnvelopeBodyXml);
163:
164: return soapEnvelopeXml;
165: }
166:
167: ////////////////////////////////////////////////////////////////////////////
168:
169: /// <summary>
170: ///
171: /// </summary>
172: private static XmlDocument DisablePerformanceMonitoringDataOverPonSoapEnvelopeXml(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Pon pon, string endPoint)
173: {
174: string version, author, soapEnvelopeBodyXml;
175: XmlDocument soapEnvelopeXml;
176:
177: version = Ia.Cl.Model.Default.RandomNumber(12);
178: author = Ia.Cl.Model.Default.RandomNumber(12);
179:
180: soapEnvelopeBodyXml = @"
181: <sdc:DisablePerformanceMonitoringDataRequest>
182:
183: <sdc:pmObjectSelect>
184: <tmf:mdNm>AMS</tmf:mdNm>
185: <tmf:meNm>" + pon.PonGroup.Olt.AmsName + @"</tmf:meNm>
186: <tmf:propNm>/type=PON Port/" + pon.RxSxLtxPonx + @"</tmf:propNm>
187: </sdc:pmObjectSelect>
188:
189: <sdc:pmParameterList>
190: <sdc:pmParameter>
191: <sdc:pmParameterName>gponOltSidePonUtilTxPmCurrentIntervalTotalBytes</sdc:pmParameterName>
192: </sdc:pmParameter>
193: </sdc:pmParameterList>
194:
195: </sdc:DisablePerformanceMonitoringDataRequest>";
196:
197: soapEnvelopeXml = SoapEnvelopeXml(endPoint, version, author, soapEnvelopeBodyXml);
198:
199: return soapEnvelopeXml;
200: }
201:
202: ////////////////////////////////////////////////////////////////////////////
203:
204: /// <summary>
205: ///
206: /// </summary>
207: [Obsolete]
208: private static XmlDocument OldGetPerformanceMonitoringDataOverPonSoapEnvelopeXml(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Pon pon, string endPoint)
209: {
210: string version, author, soapEnvelopeBodyXml;
211: XmlDocument soapEnvelopeXml;
212:
213: version = Ia.Cl.Model.Default.RandomNumber(12);
214: author = Ia.Cl.Model.Default.RandomNumber(12);
215:
216: soapEnvelopeBodyXml = @"
217: <sdc:GetPerformanceMonitoringDataRequest>
218:
219: <sdc:pmObjectSelect>
220: <tmf:mdNm>AMS</tmf:mdNm>
221: <tmf:meNm>" + pon.PonGroup.Olt.AmsName + @"</tmf:meNm>
222: <tmf:propNm>/type=PON Port/" + pon.RxSxLtxPonx + @"</tmf:propNm>
223: </sdc:pmObjectSelect>
224:
225: <sdc:pmParameterList>
226: <sdc:pmParameter>
227: <sdc:pmParameterName>gponOltSidePonUtilTxPmCurrentIntervalTotalBytes</sdc:pmParameterName>
228: </sdc:pmParameter>
229: </sdc:pmParameterList>
230:
231: </sdc:GetPerformanceMonitoringDataRequest>";
232:
233: soapEnvelopeXml = SoapEnvelopeXml(endPoint, version, author, soapEnvelopeBodyXml);
234:
235: return soapEnvelopeXml;
236: }
237:
238: ////////////////////////////////////////////////////////////////////////////
239:
240: /// <summary>
241: ///
242: /// </summary>
243: private static XmlDocument GetPerformanceMonitoringDataOverPonSoapEnvelopeXml(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Pon pon, string endPoint)
244: {
245: string version, author, soapEnvelopeBodyXml;
246: XmlDocument soapEnvelopeXml;
247:
248: version = Ia.Cl.Model.Default.RandomNumber(12);
249: author = Ia.Cl.Model.Default.RandomNumber(12);
250:
251: soapEnvelopeBodyXml = @"
252: <sdc:GetPerformanceMonitoringDataRequest>
253: <sdc:pmObjectSelect>
254: <tmf:mdNm>AMS</tmf:mdNm>
255: <tmf:meNm>" + pon.PonGroup.Olt.AmsName + @"</tmf:meNm>
256: <tmf:propNm>/type=PON Port/" + pon.RxSxLtxPonx + @"</tmf:propNm>
257: </sdc:pmObjectSelect>
258:
259: <sdc:pmParameterList>
260: <sdc:pmParameter>
261: <sdc:pmParameterName>gponOltSidePonUtilTxPmIntervalTotalBytes</sdc:pmParameterName>
262: <sdc:pmParemeterMaxIntervals>12</sdc:pmParemeterMaxIntervals>
263: </sdc:pmParameter>
264:
265: <sdc:pmParameter>
266: <sdc:pmParameterName>gponOltSidePonUtilRxPmIntervalTotalBytes</sdc:pmParameterName>
267: <sdc:pmParemeterMaxIntervals>12</sdc:pmParemeterMaxIntervals>
268: </sdc:pmParameter>
269: </sdc:pmParameterList>
270:
271: </sdc:GetPerformanceMonitoringDataRequest>";
272:
273: soapEnvelopeXml = SoapEnvelopeXml(endPoint, version, author, soapEnvelopeBodyXml);
274:
275: return soapEnvelopeXml;
276: }
277:
278: ////////////////////////////////////////////////////////////////////////////
279: ////////////////////////////////////////////////////////////////////////////
280:
281:
282:
283:
284:
285:
286: ////////////////////////////////////////////////////////////////////////////
287: ////////////////////////////////////////////////////////////////////////////
288:
289: /// <summary>
290: ///
291: /// </summary>
292: [Obsolete]
293: private static XmlDocument OldSoapEnvelopeXml(string endPoint, string version, string author, string soapEnvelopeBodyXml)
294: {
295: string s, activityName, destinationUri;
296: XmlDocument soapEnvelopeXml = new XmlDocument();
297:
298: activityName = "activityName";
299: destinationUri = Ia.Ngn.Cl.Model.Business.Nokia.Sdc.BaseAddress + "/" + Ia.Ngn.Cl.Model.Business.Nokia.Sdc.ServiceUrl + "/" + endPoint + "/" + activityName;
300:
301: s = @"<?xml version=""1.0"" encoding=""UTF-8""?>
302: <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:tmf=""tmf854.v1"" xmlns:sdc=""sdcNbi"">
303: <soapenv:Header>
304: <tmf:header extVersion=""" + version + @""" extAuthor=""" + author + @""" tmf854Version=""tmf854.v1"">
305: <tmf:activityName>" + activityName + @"</tmf:activityName>
306: <tmf:msgName>" + activityName + @"</tmf:msgName>
307: <tmf:msgType>REQUEST</tmf:msgType>
308: <tmf:senderURI>http://ofn:8080</tmf:senderURI>
309: <tmf:destinationURI>" + destinationUri + @"</tmf:destinationURI>
310: <tmf:communicationPattern>SimpleResponse</tmf:communicationPattern>
311: <tmf:communicationStyle>RPC</tmf:communicationStyle>
312: </tmf:header>
313: </soapenv:Header>
314: <soapenv:Body>" + soapEnvelopeBodyXml + @"</soapenv:Body>
315: </soapenv:Envelope>";
316:
317: soapEnvelopeXml.LoadXml(s);
318:
319: return soapEnvelopeXml;
320: }
321:
322: ////////////////////////////////////////////////////////////////////////////
323:
324: /// <summary>
325: ///
326: /// </summary>
327: private static XmlDocument SoapEnvelopeXml(string endPoint, string version, string author, string soapEnvelopeBodyXml)
328: {
329: string s, activityName, destinationUri;
330: XmlDocument soapEnvelopeXml = new XmlDocument();
331:
332: activityName = "activityName";
333: destinationUri = Ia.Ngn.Cl.Model.Business.Nokia.Sdc.BaseAddress + "/" + Ia.Ngn.Cl.Model.Business.Nokia.Sdc.ServiceUrl + "/" + endPoint + "/" + activityName;
334:
335: s = @"<?xml version=""1.0"" encoding=""UTF-8""?>
336: <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:tmf=""tmf854.v1"" xmlns:sdc=""sdcNbi"">
337: <soapenv:Header>
338: <tmf:header extVersion=""" + version + @""" extAuthor=""" + author + @""" tmf854Version=""tmf854.v1"">
339: <tmf:msgName>GetPerformanceMonitoringDataRequest</tmf:msgName>
340: <tmf:msgType>REQUEST</tmf:msgType>
341: <tmf:communicationPattern>SimpleResponse</tmf:communicationPattern>
342: <tmf:communicationStyle>RPC</tmf:communicationStyle>
343: </tmf:header>
344: </soapenv:Header>
345: <soapenv:Body>" + soapEnvelopeBodyXml + @"</soapenv:Body>
346: </soapenv:Envelope>";
347:
348: soapEnvelopeXml.LoadXml(s);
349:
350: return soapEnvelopeXml;
351: }
352:
353: ////////////////////////////////////////////////////////////////////////////
354:
355: /// <summary>
356: ///
357: /// </summary>
358: private void SendSoapRequestAndReadResponse(string endPoint, XmlDocument soapEnvelopeXml, out XmlDocument soapResultXmlDocument)
359: {
360: string url;
361: string soapResult;
362: HttpWebRequest request;
363:
364: soapResultXmlDocument = new XmlDocument();
365:
366: url = Ia.Ngn.Cl.Model.Business.Nokia.Sdc.BaseAddress + "/" + Ia.Ngn.Cl.Model.Business.Nokia.Sdc.ServiceUrl + "/" + endPoint;
367:
368: request = CreateWebRequest(url, endPoint);
369:
370: byte[] bytes;
371: bytes = System.Text.Encoding.ASCII.GetBytes(soapEnvelopeXml.OuterXml);
372: request.ContentType = "text/xml; encoding='utf-8'";
373: request.ContentLength = bytes.Length;
374: request.Method = "POST"; // "GET";
375:
376: request.Credentials = new NetworkCredential(Ia.Ngn.Cl.Model.Business.Nokia.Sdc.UserName, Ia.Ngn.Cl.Model.Business.Nokia.Sdc.Password);
377:
378: try
379: {
380: using (Stream stream = request.GetRequestStream())
381: {
382: stream.Write(bytes, 0, bytes.Length);
383: //soapEnvelopeXml.Save(stream);
384: }
385:
386: using (WebResponse response = request.GetResponse())
387: {
388: using (StreamReader rd = new StreamReader(response.GetResponseStream()))
389: {
390: soapResult = rd.ReadToEnd();
391:
392: soapResultXmlDocument.LoadXml(soapResult);
393: }
394: }
395: }
396: catch (Exception)// e)
397: {
398: }
399: }
400:
401: ////////////////////////////////////////////////////////////////////////////
402:
403: /// <summary>
404: ///
405: /// </summary>
406: private Ia.Ngn.Cl.Model.Business.Nokia.Sdc.Response ParseSoapResponseXml(XmlDocument soapResultXmlDocument)
407: {
408: int index;
409: XmlNode headerXmlNode, bodyXmlNode;
410: Dictionary<string, string> parameterDictionary;
411: Ia.Ngn.Cl.Model.Business.Nokia.Sdc.Response response;
412:
413: parameterDictionary = new Dictionary<string, string>();
414: response = new Ia.Ngn.Cl.Model.Business.Nokia.Sdc.Response();
415:
416: if (soapResultXmlDocument.DocumentElement != null)
417: {
418: headerXmlNode = soapResultXmlDocument.DocumentElement.ChildNodes[0].FirstChild;
419:
420: response.Author = headerXmlNode.Attributes["extAuthor"] != null ? headerXmlNode.Attributes["extAuthor"].Value : string.Empty;
421: response.Version = headerXmlNode.Attributes["extVersion"] != null ? headerXmlNode.Attributes["extVersion"].Value : string.Empty;
422: response.Tmf854Version = headerXmlNode.Attributes["tmf854Version"] != null ? headerXmlNode.Attributes["tmf854Version"].Value : string.Empty;
423:
424: foreach (XmlNode c in headerXmlNode.ChildNodes)
425: {
426: if (c.LocalName == "activityName") response.ActivityName = c.InnerText;
427: else if (c.LocalName == "msgName") response.MessageName = c.InnerText;
428: else if (c.LocalName == "msgType") response.MessageType = c.InnerText;
429: else if (c.LocalName == "senderURI") response.SenderUri = c.InnerText;
430: else if (c.LocalName == "destinationURI") response.DestinationUri = c.InnerText;
431: else if (c.LocalName == "communicationPattern") response.CommunicationPattern = c.InnerText;
432: else if (c.LocalName == "communicationStyle") response.CommunicationStyle = c.InnerText;
433: else if (c.LocalName == "activityStatus") response.ActivityStatus = c.InnerText;
434: else if (c.LocalName == "timestamp")
435: {
436: if (DateTime.TryParseExact(c.InnerText, @"yyyyMMddTHHmmss.fffzzz", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dt))
437: {
438: // 20191010T133709.559+0300
439: response.Timestamp = dt;
440: }
441: else
442: {
443: response.Timestamp = DateTime.MinValue;
444:
445: response.BodyText = c.InnerText;
446: }
447: }
448:
449: }
450:
451: response.ReturnCode = response.ActivityStatus == "SUCCESS" ? Ia.Ngn.Cl.Model.Client.Nokia.Sdc.ResultCode.Successful : Ia.Ngn.Cl.Model.Client.Nokia.Sdc.ResultCode.Failure;
452:
453: bodyXmlNode = soapResultXmlDocument.DocumentElement.ChildNodes[1].FirstChild;
454:
455: //response.BodyText = bodyXmlNode.OuterXml;
456:
457: if (response.IsSuccessfull)
458: {
459: index = 0;
460:
461: foreach (XmlNode xn in bodyXmlNode.ChildNodes)
462: {
463: if (xn.HasChildNodes)
464: {
465: foreach (XmlNode xn2 in xn.ChildNodes)
466: {
467: if (xn2.HasChildNodes)
468: {
469: foreach (XmlNode xn3 in xn2.ChildNodes)
470: {
471: if (xn3.HasChildNodes)
472: {
473: foreach (XmlNode xn4 in xn3.ChildNodes)
474: {
475: if (xn4.HasChildNodes)
476: {
477:
478: }
479: else parameterDictionary.Add(xn3.LocalName + index, xn3.InnerText);
480: }
481: }
482: else parameterDictionary.Add(xn2.LocalName, xn2.InnerText);
483: }
484: }
485: else parameterDictionary.Add(xn.LocalName, xn.InnerText);
486:
487: index++;
488: }
489: }
490: else parameterDictionary.Add(xn.LocalName, xn.InnerText);
491: }
492:
493: response.ParameterDictionary = parameterDictionary;
494: }
495: }
496: else
497: {
498: response.ReturnCode = Ia.Ngn.Cl.Model.Client.Nokia.Sdc.ResultCode.DocumentElementIsNull;
499: }
500:
501: return response;
502: }
503:
504: ////////////////////////////////////////////////////////////////////////////
505:
506: /// <summary>
507: /// Create a soap webrequest to [Url]
508: /// </summary>
509: /// <see cref="http://www.roelvanlisdonk.nl/?p=1893"/>
510: /// <returns></returns>
511: private HttpWebRequest CreateWebRequest(string url, string action)
512: {
513: HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
514:
515: webRequest.Headers.Add(@"SOAP:" + action);
516: webRequest.ContentType = "text/xml;charset=\"utf-8\"";
517: webRequest.Accept = "text/xml";
518: webRequest.Method = "POST";
519:
520: return webRequest;
521: }
522:
523: ////////////////////////////////////////////////////////////////////////////
524: ////////////////////////////////////////////////////////////////////////////
525: }
526:
527: ////////////////////////////////////////////////////////////////////////////
528: ////////////////////////////////////////////////////////////////////////////
529: }