From 96a92d230e0291cc48cb9d40acf9a4f22662eb05 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 1 Jul 2007 00:21:14 -0700 Subject: [PATCH 1/2] more verbose commenting of the sample --- samples/main-packet-printer.cc | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/samples/main-packet-printer.cc b/samples/main-packet-printer.cc index 5e0612595..fe1fe2bbb 100644 --- a/samples/main-packet-printer.cc +++ b/samples/main-packet-printer.cc @@ -1,4 +1,24 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006,2007 INRIA + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ + #include "ns3/packet.h" #include "ns3/header.h" #include "ns3/packet-printer.h" @@ -7,6 +27,23 @@ using namespace ns3; +// This sample file shows how to use the Packet metadata facility +// +// Packets are stored as ``packed'' data structures, to facilitate +// fragmentation and network emulation. However, when debugging a program, +// or for certain tracing applications, it may be convenient to dump out +// the contents of a packet header in a human-friendly form. +// +// To do this, a few things are needed: +// i) enable the metadata facility (disabled by default, because it causes +// a small performance hit +// ii) decide on whether you want to use a default or customized (you +// provide your own) routine to dump a particular header +// +// This sample steps through two routines; one to use the default +// printing of IPv4 and UDP headers, and one to show a non-default case. +// There is a lot of emphasis in this sample of how this facility +// interacts with packet fragmentation. void DefaultPrint (void) { @@ -23,6 +60,7 @@ void DefaultPrint (void) p.AddHeader (ipv4); std::cout << "full packet size=" << p.GetSize () << std::endl; + // Here, invoke the default Print routine, directed to std out p.Print (std::cout); std::cout << std::endl; @@ -51,6 +89,9 @@ void DefaultPrint (void) std::cout << std::endl; } +// The below functions are used in place of default versions, in the +// non-default case below. For instance, DoPrintIpv4Header will print +// out less IPv4 header information than the default print function void DoPrintDefault (std::ostream &os,uint32_t packetUid, uint32_t size, std::string &name, struct PacketPrinter::FragmentInformation info) @@ -75,6 +116,9 @@ DoPrintIpv4HeaderFragment (std::ostream &os, uint32_t packetUid, uint32_t size, os << "IPV4 fragment"; } +// This function walks through a non-default case. A few features of +// the API (defined in common/packet-printer.h) are shown. +// void NonDefaultPrint (void) { // create an adhoc packet printer. @@ -141,8 +185,10 @@ int main (int argc, char *argv[]) { Packet::EnableMetadata (); + std::cout << "DefaultPrint()" << std::endl; DefaultPrint (); + std::cout << std::endl << "NonDefaultPrint()" << std::endl; NonDefaultPrint (); return 0; From 8b7716b380dd5e0a616c56ad4d3f45a397c1466c Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 1 Jul 2007 00:35:59 -0700 Subject: [PATCH 2/2] Add payload size to UDP --- samples/main-packet-printer.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/main-packet-printer.cc b/samples/main-packet-printer.cc index fe1fe2bbb..771ae83b8 100644 --- a/samples/main-packet-printer.cc +++ b/samples/main-packet-printer.cc @@ -56,6 +56,7 @@ void DefaultPrint (void) ipv4.SetDestination (Ipv4Address ("192.168.0.2")); udp.SetSource (1025); udp.SetDestination (80); + udp.SetPayloadSize (1000); p.AddHeader (udp); p.AddHeader (ipv4); @@ -147,6 +148,7 @@ void NonDefaultPrint (void) ipv4.SetDestination (Ipv4Address ("192.168.0.2")); udp.SetSource (1025); udp.SetDestination (80); + udp.SetPayloadSize (1000); p.AddHeader (udp); p.AddHeader (ipv4);