Needed to push const changes

This commit is contained in:
Emmanuelle Laprise
2007-07-03 22:28:45 -05:00

View File

@@ -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 <mathieu.lacage@sophia.inria.fr>
*/
#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)
{
@@ -19,10 +56,12 @@ 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);
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 +90,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 +117,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.
@@ -103,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);
@@ -141,8 +187,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;