1 package evel_javalibrary.att.com;
\r
3 /**************************************************************************//**
\r
5 * Evel SIP Signalling class
\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
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
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
26 import java.text.MessageFormat;
\r
27 import java.util.ArrayList;
\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
34 import org.apache.log4j.Logger;
\r
35 import org.slf4j.helpers.MessageFormatter;
\r
38 public class EvelSipSignaling extends EvelHeader {
\r
40 int major_version = 2;
\r
41 int minor_version = 1;
\r
43 /**************************************************************************//**
\r
44 * Vendor VNF Name fields.
\r
45 * JSON equivalent field: vendorVnfNameFields
\r
46 *****************************************************************************/
\r
47 public class VENDOR_VNFNAME_FIELD {
\r
49 EvelOptionString vfmodule;
\r
50 EvelOptionString vnfname;
\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
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
71 /***************************************************************************/
\r
72 /* Optional fields */
\r
73 /***************************************************************************/
\r
75 private static final Logger LOGGER = Logger.getLogger( EvelSipSignaling.class.getName() );
\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
86 *****************************************************************************/
\r
87 public EvelSipSignaling(String evname,String evid,
\r
90 String locip_address,
\r
92 String remip_address,
\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
107 assert(remip_address != null);
\r
108 assert(rem_port != null);
\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
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
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
126 /***************************************************************************/
\r
127 /* Optional fields. */
\r
128 /***************************************************************************/
\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
135 additional_info = null;
\r
136 compressed_sip = new EvelOptionString();
\r
137 summary_sip = new EvelOptionString();
\r
142 /**************************************************************************//**
\r
143 * Set the Event Type property of the SIP signaling.
\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
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
152 *****************************************************************************/
\r
153 public void evel_signaling_type_set(String typ)
\r
156 assert(typ != null);
\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
167 /**************************************************************************//**
\r
168 * Set the Local Ip Address property of the Signaling event.
\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
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
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
191 local_ip_address = loc_ip_address;
\r
197 /**************************************************************************//**
\r
198 * Set the Local Port property of the Signaling event.
\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
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
208 *****************************************************************************/
\r
209 public void evel_signaling_local_port_set(String loc_port)
\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
220 local_port = loc_port;
\r
225 /**************************************************************************//**
\r
226 * Set the Remote Ip Address property of the Signaling event.
\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
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
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
249 remote_ip_address = remip_address;
\r
254 /**************************************************************************//**
\r
255 * Set the Remote Port property of the Signaling event.
\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
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
265 *****************************************************************************/
\r
266 public void evel_signaling_remote_port_set(String rem_port)
\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
277 remote_port = rem_port;
\r
282 /**************************************************************************//**
\r
283 * Set the Vendor module property of the Signaling event.
\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
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
293 *****************************************************************************/
\r
294 public void evel_signaling_vnfmodule_name_set(String module_name)
\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
305 vnfname_field.vfmodule.SetValue(module_name);
\r
310 /**************************************************************************//**
\r
311 * Set the Vendor module property of the Signaling event.
\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
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
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
333 vnfname_field.vnfname.SetValue(vnfname);
\r
338 /**************************************************************************//**
\r
339 * Set the Compressed SIP property of the Signaling event.
\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
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
350 *****************************************************************************/
\r
351 public void evel_signaling_compressed_sip_set(String compr_sip)
\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
362 compressed_sip.SetValue(compr_sip);
\r
367 /**************************************************************************//**
\r
368 * Set the Summary SIP property of the Signaling event.
\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
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
378 *****************************************************************************/
\r
379 public void evel_signaling_summary_sip_set(String summ_sip)
\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
390 summary_sip.SetValue(summ_sip);
\r
395 /**************************************************************************//**
\r
396 * Set the Correlator property of the Signaling event.
\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
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
406 *****************************************************************************/
\r
407 public void evel_signaling_correlator_set(String corlator)
\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
418 correlator = corlator;
\r
423 /**************************************************************************//**
\r
424 * Add an additional value name/value pair to the Signaling.
\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
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
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
436 *****************************************************************************/
\r
437 public void evel_signaling_addl_info_add(String name, String value)
\r
439 String[] addl_info = null;
\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
449 if( additional_info == null )
\r
451 additional_info = new ArrayList<String[]>();
\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
460 additional_info.add(addl_info);
\r
466 /**************************************************************************//**
\r
467 * Encode SIP Signaling Object according to VES schema
\r
469 * @retval JSON Object of SIP event
\r
470 *****************************************************************************/
\r
471 JsonObjectBuilder evelSipSignalingObject()
\r
474 double version = major_version+(double)minor_version/10;
\r
478 /***************************************************************************/
\r
479 /* Check preconditions. */
\r
480 /***************************************************************************/
\r
481 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_SIPSIGNALING);
\r
483 /***************************************************************************/
\r
484 /* Mandatory fields. */
\r
485 /***************************************************************************/
\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
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
501 /***************************************************************************/
\r
502 /* Optional fields. */
\r
503 /***************************************************************************/
\r
504 compressed_sip.encJsonValue(evelsip, "compressedSip");
\r
505 summary_sip.encJsonValue(evelsip, "summarySip");
\r
508 // additional fields
\r
509 if( additional_info != null )
\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
519 evelsip.add("additionalFields", builder);
\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
534 /**************************************************************************//**
\r
535 * Encode the event as a JSON event object according to AT&T's schema.
\r
537 * retval : String of JSON event message
\r
538 *****************************************************************************/
\r
539 String evel_json_encode_event()
\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
553 return obj.toString();
\r