Update License text
[vnfsdk/compliance.git] / veslibrary / ves_javalibrary / evel_javalib2 / src / evel_javalibrary / att / com / EvelSipSignaling.java
1 package evel_javalibrary.att.com;\r
2 \r
3 /**************************************************************************//**\r
4  * @file\r
5  * Evel SIP Signalling class\r
6  *\r
7   * This file implements the Evel SIP Signaling Event class which is intended to provide a\r
8  * simple wrapper around the complexity of AT&T's Vendor Event Listener API so\r
9  * that VNFs can use it to send SIP events.\r
10  *\r
11  * License\r
12  * -------\r
13  * Unless otherwise specified, all software contained herein is\r
14  * Licensed under the Apache License, Version 2.0 (the "License");\r
15  * you may not use this file except in compliance with the License.\r
16  * You may obtain a copy of the License at\r
17  *        http://www.apache.org/licenses/LICENSE-2.0\r
18  *\r
19  * Unless required by applicable law or agreed to in writing, software\r
20  * distributed under the License is distributed on an "AS IS" BASIS,\r
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
22  * See the License for the specific language governing permissions and\r
23  * limitations under the License.\r
24  *****************************************************************************/\r
25 \r
26 import java.text.MessageFormat;\r
27 import java.util.ArrayList;\r
28 \r
29 import javax.json.Json;\r
30 import javax.json.JsonArrayBuilder;\r
31 import javax.json.JsonObject;\r
32 import javax.json.JsonObjectBuilder;\r
33 \r
34 import org.apache.log4j.Logger;\r
35 import org.slf4j.helpers.MessageFormatter;\r
36 \r
37 \r
38 public class EvelSipSignaling extends EvelHeader {\r
39         \r
40         int major_version = 2;\r
41         int minor_version = 1;\r
42         \r
43         /**************************************************************************//**\r
44          * Vendor VNF Name fields.\r
45          * JSON equivalent field: vendorVnfNameFields\r
46          *****************************************************************************/\r
47         public class VENDOR_VNFNAME_FIELD {\r
48           String vendorname;\r
49           EvelOptionString vfmodule;\r
50           EvelOptionString vnfname;\r
51         }\r
52         \r
53         /***************************************************************************/\r
54         /* Mandatory fields                                                        */\r
55         /***************************************************************************/\r
56           VENDOR_VNFNAME_FIELD vnfname_field;\r
57           String correlator;                         /* JSON: correlator */\r
58           String local_ip_address;               /* JSON: localIpAddress */\r
59           String local_port;                          /* JSON: localPort */\r
60           String remote_ip_address;             /* JSON: remoteIpAddress */\r
61           String remote_port;                        /* JSON: remotePort */\r
62                   \r
63           /***************************************************************************/\r
64           /* Optional fields                                                         */\r
65           /***************************************************************************/\r
66           ArrayList<String[]> additional_info;\r
67           EvelOptionString compressed_sip;                  /* JSON: compressedSip */\r
68           EvelOptionString summary_sip;                        /* JSON: summarySip */\r
69 \r
70 \r
71         /***************************************************************************/\r
72         /* Optional fields                                                         */\r
73         /***************************************************************************/\r
74 \r
75           private static final Logger LOGGER = Logger.getLogger( EvelSipSignaling.class.getName() );\r
76 \r
77 \r
78           /**************************************************************************//**\r
79            * Create a new SIP Signaling event.\r
80            * @param corlator  Correlator value\r
81            * @param locip_address  Local IP address\r
82            * @param loc_port       Local Port\r
83            * @param remip_address   Remote IP address\r
84            * @param rem_port        Remote Port\r
85            *\r
86            *****************************************************************************/\r
87           public EvelSipSignaling(String evname,String evid,\r
88                           String vendr_name,\r
89               String corlator,\r
90               String locip_address,\r
91               String loc_port,\r
92               String remip_address,\r
93               String rem_port)\r
94           {//Init header\r
95         super(evname,evid);\r
96 \r
97             EVEL_ENTER();\r
98 \r
99             /***************************************************************************/\r
100             /* Check preconditions.                                                    */\r
101             /***************************************************************************/\r
102             assert(vendr_name != null);\r
103             assert(corlator != null);\r
104             assert(locip_address != null);\r
105             assert(loc_port != null);\r
106             \r
107             assert(remip_address != null);\r
108             assert(rem_port != null);\r
109 \r
110             LOGGER.debug("New SipSignaling vendor "+vendr_name+" correlator"+corlator+"local_ip_address"+locip_address+"local port"+loc_port+"remote ip address"+remip_address+"remote port"+rem_port);\r
111 \r
112             /***************************************************************************/\r
113             /* Initialize the header & the Domain                        */\r
114             /***************************************************************************/\r
115             event_domain = EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING;\r
116             /***************************************************************************/\r
117             /* Initialize mandatory fields                       */\r
118             /***************************************************************************/\r
119             \r
120             correlator = corlator;\r
121                 local_ip_address = locip_address;\r
122                 local_port = loc_port;\r
123                 remote_ip_address = remip_address;\r
124                 remote_port = rem_port;\r
125                 \r
126             /***************************************************************************/\r
127             /* Optional fields.                                                    */\r
128             /***************************************************************************/\r
129                 \r
130                 vnfname_field = new VENDOR_VNFNAME_FIELD();\r
131                 vnfname_field.vendorname = vendr_name;\r
132                 vnfname_field.vfmodule = new EvelOptionString();\r
133                 vnfname_field.vnfname = new EvelOptionString();\r
134 \r
135             additional_info = null;\r
136             compressed_sip = new EvelOptionString();\r
137             summary_sip = new EvelOptionString();\r
138 \r
139             EVEL_EXIT();\r
140           }\r
141 \r
142           /**************************************************************************//**\r
143            * Set the Event Type property of the SIP signaling.\r
144            *\r
145            * @note  The property is treated as immutable: it is only valid to call\r
146            *        the setter once.  However, we don't assert if the caller tries to\r
147            *        overwrite, just ignoring the update instead.\r
148            *\r
149        * @param type        The Event Type to be set. ASCIIZ string. The caller\r
150            *                    does not need to preserve the value once the function\r
151            *                    returns.\r
152            *****************************************************************************/\r
153            public void evel_signaling_type_set(String typ)\r
154           {\r
155             EVEL_ENTER();\r
156             assert(typ != null);\r
157 \r
158             /***************************************************************************/\r
159             /* Check preconditions and call evel_header_type_set.                      */\r
160             /***************************************************************************/\r
161             assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
162             evel_header_type_set(typ);\r
163 \r
164             EVEL_EXIT();\r
165           }\r
166 \r
167           /**************************************************************************//**\r
168            * Set the Local Ip Address property of the Signaling event.\r
169            *\r
170            * @note  The property is treated as immutable: it is only valid to call\r
171            *        the setter once.  However, we don't assert if the caller tries to\r
172            *        overwrite, just ignoring the update instead.\r
173            *\r
174            * @param local_ip_address\r
175            *                      The Local Ip Address to be set. ASCIIZ string. The\r
176            *                      caller does not need to preserve the value once the\r
177            *                      function returns.\r
178            *****************************************************************************/\r
179           public  void evel_signaling_local_ip_address_set(\r
180                                                    String loc_ip_address)\r
181           {\r
182             EVEL_ENTER();\r
183 \r
184             /***************************************************************************/\r
185             /* Check preconditions.                                                    */\r
186             /***************************************************************************/\r
187             assert(loc_ip_address != null);\r
188             assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
189             LOGGER.debug("Setting SipSignaling Local IP "+loc_ip_address);\r
190 \r
191             local_ip_address = loc_ip_address;\r
192 \r
193 \r
194             EVEL_EXIT();\r
195           }\r
196 \r
197           /**************************************************************************//**\r
198            * Set the Local Port property of the Signaling event.\r
199            *\r
200            * @note  The property is treated as immutable: it is only valid to call\r
201            *        the setter once.  However, we don't assert if the caller tries to\r
202            *        overwrite, just ignoring the update instead.\r
203            *\r
204            * \r
205            * @param local_port    The Local Port to be set. ASCIIZ string. The caller\r
206            *                      does not need to preserve the value once the function\r
207            *                      returns.\r
208            *****************************************************************************/\r
209           public  void evel_signaling_local_port_set(String loc_port)\r
210           {\r
211             EVEL_ENTER();\r
212 \r
213             /***************************************************************************/\r
214             /* Check preconditions.                                                    */\r
215             /***************************************************************************/\r
216             assert(loc_port != null);\r
217             assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
218             LOGGER.debug("Setting SipSignaling Local Port "+loc_port);\r
219 \r
220             local_port = loc_port;\r
221 \r
222             EVEL_EXIT();\r
223           }\r
224 \r
225           /**************************************************************************//**\r
226            * Set the Remote Ip Address property of the Signaling event.\r
227            *\r
228            * @note  The property is treated as immutable: it is only valid to call\r
229            *        the setter once.  However, we don't assert if the caller tries to\r
230            *        overwrite, just ignoring the update instead.\r
231            *\r
232            * \r
233            * @param remote_ip_address\r
234            *                      The Remote Ip Address to be set. ASCIIZ string. The\r
235            *                      caller does not need to preserve the value once the\r
236            *                      function returns.\r
237            *****************************************************************************/\r
238           public  void evel_signaling_remote_ip_address_set(String remip_address)\r
239           {\r
240             EVEL_ENTER();\r
241 \r
242             /***************************************************************************/\r
243             /* Check preconditions.                                                    */\r
244             /***************************************************************************/\r
245             assert(remip_address != null);\r
246             assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
247             LOGGER.debug("Setting SipSignaling Remote IP Address "+remip_address);\r
248 \r
249             remote_ip_address = remip_address;\r
250             \r
251             EVEL_EXIT();\r
252           }\r
253 \r
254           /**************************************************************************//**\r
255            * Set the Remote Port property of the Signaling event.\r
256            *\r
257            * @note  The property is treated as immutable: it is only valid to call\r
258            *        the setter once.  However, we don't assert if the caller tries to\r
259            *        overwrite, just ignoring the update instead.\r
260            *\r
261            * \r
262            * @param remote_port   The Remote Port to be set. ASCIIZ string. The caller\r
263            *                      does not need to preserve the value once the function\r
264            *                      returns.\r
265            *****************************************************************************/\r
266           public  void evel_signaling_remote_port_set(String rem_port)\r
267           {\r
268             EVEL_ENTER();\r
269 \r
270             /***************************************************************************/\r
271             /* Check preconditions.                                                    */\r
272             /***************************************************************************/\r
273             assert(rem_port != null);\r
274             assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
275             LOGGER.debug("Setting SipSignaling Remote Port "+rem_port);\r
276 \r
277             remote_port = rem_port;\r
278             \r
279             EVEL_EXIT();\r
280           }\r
281 \r
282           /**************************************************************************//**\r
283            * Set the Vendor module property of the Signaling event.\r
284            *\r
285            * @note  The property is treated as immutable: it is only valid to call\r
286            *        the setter once.  However, we don't assert if the caller tries to\r
287            *        overwrite, just ignoring the update instead.\r
288            *\r
289            * \r
290            * @param modulename    The module name to be set. ASCIIZ string. The caller\r
291            *                      does not need to preserve the value once the function\r
292            *                      returns.\r
293            *****************************************************************************/\r
294           public  void evel_signaling_vnfmodule_name_set(String module_name)\r
295           {\r
296             EVEL_ENTER();\r
297 \r
298             /***************************************************************************/\r
299             /* Check preconditions.                                                    */\r
300             /***************************************************************************/\r
301             assert(module_name != null);\r
302             assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
303             LOGGER.debug("Setting SipSignaling Module Name "+module_name);\r
304             \r
305             vnfname_field.vfmodule.SetValue(module_name);\r
306             \r
307             EVEL_EXIT();\r
308           }\r
309 \r
310           /**************************************************************************//**\r
311            * Set the Vendor module property of the Signaling event.\r
312            *\r
313            * @note  The property is treated as immutable: it is only valid to call\r
314            *        the setter once.  However, we don't assert if the caller tries to\r
315            *        overwrite, just ignoring the update instead.\r
316            *\r
317            * \r
318            * @param vnfname       The Virtual Network function to be set. ASCIIZ string.\r
319            *                      The caller does not need to preserve the value once\r
320            *                    the function returns.\r
321            *****************************************************************************/\r
322           public void evel_signaling_vnfname_set(String vnfname)\r
323           {\r
324             EVEL_ENTER();\r
325 \r
326             /***************************************************************************/\r
327             /* Check preconditions.                                                    */\r
328             /***************************************************************************/\r
329             assert(vnfname != null);\r
330             assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
331             LOGGER.debug("Setting SipSignaling VNF Name "+vnfname);\r
332             \r
333             vnfname_field.vnfname.SetValue(vnfname);\r
334 \r
335             EVEL_EXIT();\r
336           }\r
337 \r
338           /**************************************************************************//**\r
339            * Set the Compressed SIP property of the Signaling event.\r
340            *\r
341            * @note  The property is treated as immutable: it is only valid to call\r
342            *        the setter once.  However, we don't assert if the caller tries to\r
343            *        overwrite, just ignoring the update instead.\r
344            *\r
345            * \r
346            * @param compressed_sip\r
347            *                      The Compressed SIP to be set. ASCIIZ string. The caller\r
348            *                      does not need to preserve the value once the function\r
349            *                      returns.\r
350            *****************************************************************************/\r
351           public  void evel_signaling_compressed_sip_set(String compr_sip)\r
352           {\r
353             EVEL_ENTER();\r
354 \r
355             /***************************************************************************/\r
356             /* Check preconditions.                                                    */\r
357             /***************************************************************************/\r
358             assert(compr_sip != null);\r
359             assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
360             LOGGER.debug("Setting SipSignaling Compressed SIP "+compr_sip);\r
361             \r
362             compressed_sip.SetValue(compr_sip);\r
363 \r
364             EVEL_EXIT();\r
365           }\r
366 \r
367           /**************************************************************************//**\r
368            * Set the Summary SIP property of the Signaling event.\r
369            *\r
370            * @note  The property is treated as immutable: it is only valid to call\r
371            *        the setter once.  However, we don't assert if the caller tries to\r
372            *        overwrite, just ignoring the update instead.\r
373            *\r
374            * \r
375            * @param summary_sip   The Summary SIP to be set. ASCIIZ string. The caller\r
376            *                      does not need to preserve the value once the function\r
377            *                      returns.\r
378            *****************************************************************************/\r
379           public void evel_signaling_summary_sip_set(String summ_sip)\r
380           {\r
381             EVEL_ENTER();\r
382 \r
383             /***************************************************************************/\r
384             /* Check preconditions.                                                    */\r
385             /***************************************************************************/\r
386             assert(summ_sip != null);\r
387             assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
388             LOGGER.debug("Setting SipSignaling Summary SIP "+summ_sip);\r
389             \r
390             summary_sip.SetValue(summ_sip);\r
391 \r
392             EVEL_EXIT();\r
393           }\r
394 \r
395           /**************************************************************************//**\r
396            * Set the Correlator property of the Signaling event.\r
397            *\r
398            * @note  The property is treated as immutable: it is only valid to call\r
399            *        the setter once.  However, we don't assert if the caller tries to\r
400            *        overwrite, just ignoring the update instead.\r
401            *\r
402            * \r
403            * @param correlator    The correlator to be set. ASCIIZ string. The caller\r
404            *                      does not need to preserve the value once the function\r
405            *                      returns.\r
406            *****************************************************************************/\r
407           public void evel_signaling_correlator_set(String corlator)\r
408           {\r
409             EVEL_ENTER();\r
410 \r
411             /***************************************************************************/\r
412             /* Check preconditions and call evel_header_type_set.                      */\r
413             /***************************************************************************/\r
414             assert(corlator != null);\r
415             assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
416             LOGGER.debug("Setting Correlator "+corlator);\r
417             \r
418             correlator = corlator;\r
419             \r
420             EVEL_EXIT();\r
421           }\r
422           \r
423           /**************************************************************************//**\r
424            * Add an additional value name/value pair to the Signaling.\r
425            *\r
426            * The name and value are null delimited ASCII strings.  The library takes\r
427            * a copy so the caller does not have to preserve values after the function\r
428            * returns.\r
429            *\r
430            * @param name      ASCIIZ string with the attribute's name.  The caller\r
431            *                  does not need to preserve the value once the function\r
432            *                  returns.\r
433            * @param value     ASCIIZ string with the attribute's value.  The caller\r
434            *                  does not need to preserve the value once the function\r
435            *                  returns.\r
436            *****************************************************************************/\r
437           public void evel_signaling_addl_info_add(String name, String value)\r
438                 {\r
439                   String[] addl_info = null;\r
440                   EVEL_ENTER();\r
441 \r
442                   /***************************************************************************/\r
443                   /* Check preconditions.                                                    */\r
444                   /***************************************************************************/\r
445                   assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
446                   assert(name != null);\r
447                   assert(value != null);\r
448                   \r
449                   if( additional_info == null )\r
450                   {\r
451                           additional_info = new ArrayList<String[]>();\r
452                   }\r
453 \r
454                   LOGGER.debug(MessageFormat.format("Adding name={0} value={1}", name, value));\r
455                   addl_info = new String[2];\r
456                   assert(addl_info != null);\r
457                   addl_info[0] = name;\r
458                   addl_info[1] = value;\r
459 \r
460                   additional_info.add(addl_info);\r
461 \r
462                   EVEL_EXIT();\r
463                 }\r
464 \r
465 \r
466           /**************************************************************************//**\r
467            * Encode SIP Signaling Object according to VES schema\r
468            *\r
469            * @retval JSON Object of SIP event\r
470            *****************************************************************************/\r
471           JsonObjectBuilder evelSipSignalingObject()\r
472           {\r
473 \r
474             double version = major_version+(double)minor_version/10;\r
475 \r
476             EVEL_ENTER();\r
477 \r
478             /***************************************************************************/\r
479             /* Check preconditions.                                                    */\r
480             /***************************************************************************/\r
481             assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
482 \r
483             /***************************************************************************/\r
484             /* Mandatory fields.                                                       */\r
485             /***************************************************************************/\r
486             \r
487         JsonObjectBuilder vnfnamedobj =  Json.createObjectBuilder()\r
488                 .add( "vendorName",vnfname_field.vendorname);\r
489             vnfname_field.vfmodule.encJsonValue(vnfnamedobj,"vfModuleName");\r
490             vnfname_field.vfmodule.encJsonValue(vnfnamedobj,"vnfName");\r
491             \r
492             JsonObjectBuilder evelsip = Json.createObjectBuilder()\r
493                                           .add("correlator", correlator)\r
494                                           .add("localIpAddress", local_ip_address)\r
495                                           .add("localPort", local_port)\r
496                                   .add("remoteIpAddress", remote_ip_address)\r
497                                   .add("remotePort", remote_port)\r
498                                   .add("vendorVnfNamedFields", vnfnamedobj);\r
499                              \r
500             \r
501             /***************************************************************************/\r
502             /* Optional fields.                                                        */\r
503             /***************************************************************************/\r
504             compressed_sip.encJsonValue(evelsip, "compressedSip");\r
505             summary_sip.encJsonValue(evelsip, "summarySip");\r
506             \r
507             \r
508             // additional fields\r
509                   if( additional_info != null )\r
510                   {\r
511                     JsonArrayBuilder builder = Json.createArrayBuilder();\r
512                     for(int i=0;i<additional_info.size();i++) {\r
513                           String[] addl_info = additional_info.get(i);\r
514                           JsonObject obj = Json.createObjectBuilder()\r
515                                      .add("name", addl_info[0])\r
516                                      .add("value", addl_info[1]).build();\r
517                           builder.add(obj);\r
518                     }\r
519                         evelsip.add("additionalFields", builder);\r
520                   }\r
521             \r
522 \r
523             /***************************************************************************/\r
524             /* Although optional, we always generate the version.  Note that this      */\r
525             /* closes the object, too.                                                 */\r
526             /***************************************************************************/\r
527             evelsip.add("signalingFieldsVersion", version);\r
528 \r
529             EVEL_EXIT();\r
530             \r
531             return evelsip;\r
532           }\r
533           \r
534           /**************************************************************************//**\r
535            * Encode the event as a JSON event object according to AT&T's schema.\r
536            *\r
537            * retval : String of JSON event message\r
538            *****************************************************************************/\r
539           String evel_json_encode_event()\r
540           {\r
541                 EVEL_ENTER();\r
542                 \r
543                 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);\r
544             //encode commonheader and sip signaling body fields    \r
545             JsonObject obj = Json.createObjectBuilder()\r
546                      .add("event", Json.createObjectBuilder()\r
547                                  .add( "commonEventHeader",eventHeaderObject() )\r
548                                  .add( "signalingFields",evelSipSignalingObject() )\r
549                                  ).build();\r
550 \r
551             EVEL_EXIT();\r
552             \r
553             return obj.toString();\r
554 \r
555           }\r
556 \r
557 \r
558 }\r