b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt#!/usr/bin/perl
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt#
5d52a1fe1b8ea396fb5ae7f6f1567c8383445113Tinderbox User# Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC")
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# file, You can obtain one at http://mozilla.org/MPL/2.0/.
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt# traffic-xml.pl:
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt# Parses the XML version of the RSSAC002 traffic stats into a
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt# normalized format.
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Huntuse XML::Simple;
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Huntmy $file = $ARGV[0];
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Huntmy $ref = XMLin($file);
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt
10966da999f8f7f364418aa446d8ead9c8a761cfMark Andrewsmy $udp = $ref->{traffic}->{ipv4}->{udp}->{counters};
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Huntforeach $group (@$udp) {
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt my $type = "udp " . $group->{type} . " ";
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt if (exists $group->{counter}->{name}) {
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt print $type . $group->{counter}->{name} . ": " . $group->{counter}->{content} . "\n";
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt } else {
9689922a0d936b04feb418fbaf4c1420f745ea58Mark Andrews foreach $key (keys %{$group->{counter}}) {
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt print $type . $key . ": ". $group->{counter}->{$key}->{content} ."\n";
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt }
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt }
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt}
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt
10966da999f8f7f364418aa446d8ead9c8a761cfMark Andrewsmy $tcp = $ref->{traffic}->{ipv4}->{tcp}->{counters};
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Huntforeach $group (@$tcp) {
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt my $type = "tcp " . $group->{type} . " ";
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt if (exists $group->{counter}->{name}) {
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt print $type . $group->{counter}->{name} . ": " . $group->{counter}->{content} . "\n";
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt } else {
9689922a0d936b04feb418fbaf4c1420f745ea58Mark Andrews foreach $key (keys %{$group->{counter}}) {
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt print $type . $key . ": ". $group->{counter}->{$key}->{content} ."\n";
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt }
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt }
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt}