NAME
BGPmon::Translator::XFB2PerlHash - convert an XFB message into a Perl hash
This module converts an XML message to a nested hash data structure and provides an interface to get a stringified representation of the data structure as well as the ability to extract individual subtrees from the nested structure.
SYNOPSIS
use BGPmon::Translator::XFB2PerlHash;
my $xml_string = '...
#Convering and soring the xml message
my %hash = translate_msg($xml_string);
#printing the data in an easier-to-read way
print toString();
#printing the port number of the peer that passed us this message
my $result = get_content('/BGP_MONITOR_MESSAGE/SOURCE/PORT/content');
print $result;
#Printing all the prefixes found in the NLRI section
$result = get_content('/BGP_MONITOR_MESSAGE/bgp:UPDATE/bgp:NLRI/');
print $_->{'ADDRESS'}->{'content'} foreach (@$result);
#Resetting the module
reset();
EXPORT
translate_msg toString get_content reset get_error_code get_error_msg get_error_message
SUBROUTINES/METHODS
translate_msg
Converts an XML message into a Perl hash structure while maintaining the structure of the message itself.
Input: The XML string to be parsed
Output: A perl hash structure that contains the converted string or an empty hash if there is no string provided or the XML parser fails
toString
Returns a printable version of the most recent XML message that was parsed with translate_msg. If there is no such message, returns the empty string.
get_content
Returns a reference to an element or attribute of the most recent XML message translated via translate_msg.
Input: A slash-delimited string which gives the path through the message tree structure, i.e. "/ROOT_TAG/NEXT_TAG/attribute_name" NOTE: To get the text contents of an element, specify "/content" as the final "node" in the target string.
Output: A reference to the appropriate content if found. undef if no such information is found
reset
Resets the module's state variables
get_error_code
Get the error code for some function
Input : the name of the function whose error code we should report
Output: the function's error code or UNDEFINED_ARGUMENT if the user did not supply a function or INVALID_FUNCTION_SPECIFIED if the user provided an invalid function name
get_error_message
Get the error message for some function
Input : the name of the function whose error message we should report
Output: the function's error message or UNDEFINED_ARGUMENT if the user did not supply a function or INVALID_FUNCTION_SPECIFIED if the user provided an invalid function name
get_error_msg
Get the error message
This function is identical to get_error_message
ERROR CODES AND MESSAGES
The following error codes and messages are defined:
0: No Error
'No Error. Life is good.'
601: There has been no XML message passed through translate_msg
'No XML message provided'
602: No argument was passed to a function expecting one
'Undefined argument'
603: An invalid function name was passed to get_error_[code/message/msg]
'Invalid Function Name Specified'
604: The XML parser failed
'XML Parser Error'
605: There was no information found at the location passed to
get_content
'No such element/attribute exists'
BUGS
Please report any bugs or feature requests to bgpmon at netsec.colostate.edu
, or through the web interface at http://bgpmon.netsec.colostate.edu.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc BGPmon::Translator::XFB2PerlHash
LICENSE AND COPYRIGHT
Copyright (c) 2012 Colorado State University
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.\
File: XFB2PerlHash.pm
Authors: M. Lawrence Weikum, Jason Bartlett, Kaustubh Gadkari, Dan Massey, Cathie Olschanowsky
Date: 13 October 2013