M. Lawrence Weikum > BGPmon-core-1 > BGPmon::Translator::XFB2PerlHash

Download:
BGPmon-core-1-092.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  1
View/Report Bugs
Module Version: 1.092   Source  

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 $string = '<BGP_MESSAGE length="00002243" version="0.4" 
xmlns="urn:ietf:params:xml:ns:xfb-0.4" type_value="2" 
type="UPDATE"><BGPMON_SEQ id="0" seq_num="744909286"/><TIME 
timestamp="1336133702" datetime="2012-05-04T12:15:02Z" precision_time="0"/
><PEERING as_num_len="4"><SRC_ADDR><ADDRESS>2600:803::15</ADDRESS><AFI 
value="2">IPV6</AFI></SRC_ADDR><SRC_PORT>179</SRC_PORT><SRC_AS>701</
SRC_AS><DST_ADDR><ADDRESS>127.0.0.1</ADDRESS><AFI value="1">IPV4</AFI></
DST_ADDR><DST_PORT>179</DST_PORT><DST_AS>6447</DST_AS><BGPID>0.0.0.0</BGPID></
PEERING><ASCII_MSG length="110"><MARKER 
length="16">FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF</MARKER><UPDATE withdrawn_len="0" 
path_attr_len="87"><WITHDRAWN count="0"/><PATH_ATTRIBUTES count="5"><ATTRIBUTE 
length="1"><FLAGS transitive="TRUE"/><TYPE value="1">ORIGIN</TYPE><ORIGIN 
value="0">IGP</ORIGIN></ATTRIBUTE><ATTRIBUTE length="26"><FLAGS 
transitive="TRUE"/><TYPE value="2">AS_PATH</TYPE><AS_PATH><AS_SEG 
type="AS_SEQUENCE" length="6"><AS>701</AS><AS>12702</AS><AS>286</AS><AS>3549</
AS><AS>35994</AS><AS>35994</AS></AS_SEG></AS_PATH></ATTRIBUTE><ATTRIBUTE 
length="8"><FLAGS optional="TRUE" transitive="TRUE"/><TYPE 
value="7">AGGREGATOR</TYPE><AGGREGATOR><AS>0</AS><ADDR>192.8.8.2</ADDR></
AGGREGATOR></ATTRIBUTE><ATTRIBUTE length="8"><FLAGS optional="TRUE" 
transitive="TRUE"/><TYPE value="8">COMMUNITIES</
TYPE><COMMUNITIES><COMMUNITY><AS>701</AS><VALUE>333</VALUE></
COMMUNITY><COMMUNITY><AS>701</AS><VALUE>1020</VALUE></COMMUNITY></
COMMUNITIES></ATTRIBUTE><ATTRIBUTE length="28"><FLAGS optional="TRUE" 
extended="TRUE"/><TYPE value="14">MP_REACH_NLRI</TYPE><MP_REACH_NLRI><AFI 
value="2">IPV6</AFI><SAFI value="1">UNICAST</SAFI><NEXT_HOP_LEN>16</
NEXT_HOP_LEN><NEXT_HOP><ADDRESS>2600:803::15</ADDRESS></NEXT_HOP><NLRI 
count="1"><PREFIX label="DANN"><ADDRESS>2001:450:2030::/48</ADDRESS><AFI 
value="2">IPV6</AFI><SAFI value="1">UNICAST</SAFI></PREFIX></NLRI></
MP_REACH_NLRI></ATTRIBUTE></PATH_ATTRIBUTES><NLRI count="0"/></UPDATE></
ASCII_MSG><OCTET_MSG><OCTETS 
length="110">FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF006E02000000574001010040021A02060
00002BD0000319E0000011E00000DDD00008C9A00008C9AC0070800008C9AADDEE9FEC0080802B
D014D02BD03FC900E001C00020110260008030000000000000000000000150030200104502030
</OCTETS></OCTET_MSG></BGP_MESSAGE>';

my %hash = translate_msg($string); #Converts and internally saves the message

print toString(); #pretty-prints the data

my $result = get_content('/BGP_MESSAGE/ASCII_MSG/MARKER/content');

print $$result; #Would print 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'

$result = get_content ('/BGP_MESSAGE/ASCII_MSG/UPDATE/PATH_ATTRIBUTES/ATTRIBUTE/MP_REACH_NLRI/PREFIX');

print $res->{'ADDRESS'}->{'content'} foreach $res (@$result);

$result = get_content('/BGP_MESSAGE/PEERING');

print keys %$result;

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'

AUTHOR ^

Jason Bartlett, <bartletj at cs.colostate.edu>

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: Jason Bartlett, Kaustubh Gadkari, Dan Massey, Cathie Olschanowsky
    Date: 11 July 2012
syntax highlighting: