Translated for portuguese by the students of the inter-institutional doctorate program of IME-USP/UTFPR-CM.
Traduzido para o portugu<67>s pelos alunos do programa de doutorado inter institucional do Instituto de Matem<65>tica e Estat<61>stica da Universidade de S<>o Paulo --- IME-USP em parceria com a Universidade Tecnol<6F>gica Federal do Paran<61> - Campus Campo Mour<75>o --- UTFPR-CM:
* Frank Helbert (frank@ime.usp.br);
* Luiz Arthur Feitosa dos Santos (luizsan@ime.usp.br);
The first thing we need to do before actually starting to look at or write
|ns3| code is to explain a few core concepts and abstractions in the
system. Much of this may appear transparently obvious to some, but we
recommend taking the time to read through this section just to ensure you
are starting on a firm foundation.
Antes de escrever c<>digos no |ns3| <20> extremamente importante entender um pouco dos conceitos e abstra<72><61>es do sistema. Muitos conceitos poder<65>o parecer <20>bvios, mas a recomenda<64><61>o geral <20> que esta se<73><65>o seja lida por completo para assegurar que o leitor inicie com uma base s<>lida.
.. Key Abstractions
Principais Abstra<72><61>es
*********************
..
In this section, we'll review some terms that are commonly used in
networking, but have a specific meaning in |ns3|.
Nesta se<73><65>o, s<>o revistos alguns termos que s<>o comumente usados por profissionais de redes de computadores, mas que tem um significado espec<65>fico no |ns3|.
N<EFBFBD> (`Node`)
+++++++++++
..
In Internet jargon, a computing device that connects to a network is called
a *host* or sometimes an *end system*. Because |ns3| is a
*network* simulator, not specifically an *Internet* simulator, we
intentionally do not use the term host since it is closely associated with
the Internet and its protocols. Instead, we use a more generic term also
used by other simulators that originates in Graph Theory --- the *node*.
No jarg<72>o da Internet, um dispositivo computacional que conecta-se a uma rede <20> chamado de *host* ou em alguns casos de *terminal*. Devido ao fato do |ns3| ser um simulador de *rede*, e n<>o um simulador da *Internet*, o termo `host`<20> intencionalmente n<>o utilizado, pois est<73> intimamente associado com a Internet e seus protocolos. Ao inv<6E>s disso, <20> utilizado o termo *node* --- em portugu<67>s, *n<>* --- que <20> um termo mais gen<65>rico e tamb<6D>m usado por outros simuladores que tem suas origens na Teoria dos Grafos.
..
In |ns3| the basic computing device abstraction is called the
node. This abstraction is represented in C++ by the class ``Node``. The
``Node`` class provides methods for managing the representations of
computing devices in simulations.
A abstra<72><61>o de um dispositivo computacional b<>sico <20> chamado ent<6E>o de n<>. Essa abstra<72><61>o <20> representada em C++ pela classe ``Node``. Esta classe fornece m<>todos para gerenciar as representa<74><61>es de dispositivos computacionais nas simula<6C><61>es.
..
You should think of a ``Node`` as a computer to which you will add
functionality. One adds things like applications, protocol stacks and
peripheral cards with their associated drivers to enable the computer to do
useful work. We use the same basic model in |ns3|.
O n<> deve ser pensado como um computador no qual se adicionam funcionalidades, tal como aplicativos, pilhas de protocolos e perif<69>ricos com seus `drivers` associados que permitem ao computador executar tarefas <20>teis. No |ns3| <20> utilizado este mesmo conceito b<>sico.
.. Application
Aplica<EFBFBD><EFBFBD>es (`Application`)
++++++++++++++++++++++++++
..
Typically, computer software is divided into two broad classes. *System
Software* organizes various computer resources such as memory, processor
cycles, disk, network, etc., according to some computing model. System
software usually does not use those resources to complete tasks that directly
benefit a user. A user would typically run an *application* that acquires
and uses the resources controlled by the system software to accomplish some
goal.
Normalmente, programas de computador s<>o divididos em duas classes. *Programas de sistema* organizam recursos do computador, tais como: mem<65>ria, processador, disco, rede, etc., de acordo com algum modelo computacional. Tais programas normalmente n<>o s<>o utilizados diretamente pelos usu<73>rios. Na maioria das vezes, os usu<73>rios fazem uso de *aplica<63><61>es*, que usam os recursos controlados pelos programas de sistema para atingir seus objetivos.
..
Often, the line of separation between system and application software is made
at the privilege level change that happens in operating system traps.
In |ns3| there is no real concept of operating system and especially
no concept of privilege levels or system calls. We do, however, have the
idea of an application. Just as software applications run on computers to
perform tasks in the "real world," |ns3| applications run on
|ns3| ``Nodes`` to drive simulations in the simulated world.
Geralmente, a separa<72><61>o entre programas de sistema e aplica<63><61>es de usu<73>rios <20> feita pela mudan<61>a no n<>vel de privil<69>gios que acontece na troca de contexto feita pelo sistema operacional. No |ns3|, n<>o existe um conceito de sistema operacional real, n<>o h<> o conceito de n<>veis de privil<69>gios nem chamadas de sistema. H<> apenas aplica<63><61>es que s<>o executadas nos n<>s para uma determinada simula<6C><61>o.
..
In |ns3| the basic abstraction for a user program that generates some
activity to be simulated is the application. This abstraction is represented
in C++ by the class ``Application``. The ``Application`` class provides
methods for managing the representations of our version of user-level
applications in simulations. Developers are expected to specialize the
``Application`` class in the object-oriented programming sense to create new
applications. In this tutorial, we will use specializations of class
``Application`` called ``UdpEchoClientApplication`` and
``UdpEchoServerApplication``. As you might expect, these applications
compose a client/server application set used to generate and echo simulated
network packets
No |ns3|, a abstra<72><61>o b<>sica para um programa de usu<73>rio que gera alguma atividade a ser simulada <20> a aplica<63><61>o. Esta abstra<72><61>o <20> representada em C++ pela classe ``Application``, que fornece m<>todos para gerenciar a representa<74><61>o de suas vers<72>es de aplica<63><61>es a serem simuladas. Os desenvolvedores devem especializar a classe ``Application`` para criar novas aplica<63><61>es. Neste tutorial ser<65>o utilizadas duas especializa<7A><61>es da classe ``Application``, chamadas ``UdpEchoClientApplication`` e ``UdpEchoServerApplication``. Estas aplica<63><61>es comp<6D>em um modelo cliente/servidor usado para gerar pacotes simulados de eco na rede.
.. Channel
Canal de Comunica<63><61>o (`Channel`)
++++++++++++++++++++++++++++++++
..
In the real world, one can connect a computer to a network. Often the media
over which data flows in these networks are called *channels*. When
you connect your Ethernet cable to the plug in the wall, you are connecting
your computer to an Ethernet communication channel. In the simulated world
of |ns3|, one connects a ``Node`` to an object representing a
communication channel. Here the basic communication subnetwork abstraction
is called the channel and is represented in C++ by the class ``Channel``.
No mundo real, computadores est<73>o conectados em uma rede. Normalmente, o meio sobre o qual os dados trafegam <20> chamada de canal (*channel*). Quando um cabo Ethernet <20> ligado ao conector na parede, na verdade est<73> se conectando a um canal de comunica<63><61>o Ethernet. No mundo simulado do |ns3|, um n<><20> conectado a um objeto que representa um canal de comunica<63><61>o. A abstra<72><61>o de canal de comunica<63><61>o <20> representada em C++ pela classe ``Channel``.
..
The ``Channel`` class provides methods for managing communication
subnetwork objects and connecting nodes to them. ``Channels`` may also be
specialized by developers in the object oriented programming sense. A
``Channel`` specialization may model something as simple as a wire. The
specialized ``Channel`` can also model things as complicated as a large
Ethernet switch, or three-dimensional space full of obstructions in the case
of wireless networks.
A classe ``Channel`` fornece m<>todos para gerenciar objetos de comunica<63><61>o de sub-redes e n<>s conectados a eles. Os ``Channels`` tamb<6D>m podem ser especializados por desenvolvedores (no sentido de programa<6D><61>o orientada a objetos). Uma especializa<7A><61>o de ``Channel`` pode ser algo como um simples fio. Pode tamb<6D>m ser algo mais complexo, como um comutador Ethernet ou ainda ser uma rede sem fio (`wireless`) em um espa<70>o tridimensional com obst<73>culos.
..
We will use specialized versions of the ``Channel`` called
``CsmaChannel``, ``PointToPointChannel`` and ``WifiChannel`` in this
tutorial. The ``CsmaChannel``, for example, models a version of a
communication subnetwork that implements a *carrier sense multiple
access* communication medium. This gives us Ethernet-like functionality.
Neste tutorial, s<>o utilizadas vers<72>es especializadas de ``Channel`` chamadas ``CsmaChannel``, ``PointToPointChannel`` e ``WifiChannel``. O ``CsmaChannel``, por exemplo, <20> uma vers<72>o do modelo de rede que implementa controle de acesso ao meio CSMA (*Carrier Sense Multiple Access*). Ele fornece uma funcionalidade similar a uma rede Ethernet.
.. Net Device
Dispositivos de Rede (`Net Device`)
+++++++++++++++++++++++++++++++++++
..
It used to be the case that if you wanted to connect a computers to a network,
you had to buy a specific kind of network cable and a hardware device called
(in PC terminology) a *peripheral card* that needed to be installed in
your computer. If the peripheral card implemented some networking function,
they were called Network Interface Cards, or *NICs*. Today most
computers come with the network interface hardware built in and users don't
see these building blocks.
No passado, para conectar computadores em uma rede, era necess<73>rio comprar o cabo espec<65>fico e um dispositivo chamado (na terminologia dos PCs) de *perif<69>rico*, que precisava ser instalado no computador. Se a placa implementava fun<75><6E>es de rede, era chamada de interface de rede (`Network Interface Card` - NIC). Atualmente, a maioria dos computadores v<>m com a placa de rede integrada <20> placa m<>e (`on-board`) e os usu<73>rios n<>o v<>em o computador como uma jun<75><6E>o de partes.
..
A NIC will not work without a software driver to control the hardware. In
Unix (or Linux), a piece of peripheral hardware is classified as a
*device*. Devices are controlled using *device drivers*, and network
devices (NICs) are controlled using *network device drivers*
collectively known as *net devices*. In Unix and Linux you refer
to these net devices by names such as *eth0*.
Uma placa de rede n<>o funciona sem o `driver` que a controle. No Unix (ou Linux), um perif<69>rico (como a placa de rede) <20> classificado como um dispositivo (*device*). Dispositivos s<>o controlados usando drivers de dispositivo (*device drivers*) e as placas de rede s<>o controladas atrav<61>s de drivers de dispositivo de rede (*network device drivers*), tamb<6D>m chamadas de dispositivos de rede (*net devices*). No Unix e Linux estes dispositivos de rede levam nomes como *eth0*.
..
In |ns3| the *net device* abstraction covers both the software
driver and the simulated hardware. A net device is "installed" in a
``Node`` in order to enable the ``Node`` to communicate with other
``Nodes`` in the simulation via ``Channels``. Just as in a real
computer, a ``Node`` may be connected to more than one ``Channel`` via
multiple ``NetDevices``.
No |ns3| a abstra<72><61>o do *dispositivo de rede* cobre tanto o hardware quanto o software (`drive`). Um dispositivo de rede <20> "instalado" em um n<> para permitir que este se comunique com outros na simula<6C><61>o, usando os canais de comunica<63><61>o (`channels`). Assim como em um computador real, um n<> pode ser conectado a mais que um canal via m<>ltiplos dispositivos de rede.
..
The net device abstraction is represented in C++ by the class ``NetDevice``.
The ``NetDevice`` class provides methods for managing connections to
``Node`` and ``Channel`` objects; and may be specialized by developers
in the object-oriented programming sense. We will use the several specialized
versions of the ``NetDevice`` called ``CsmaNetDevice``,
``PointToPointNetDevice``, and ``WifiNetDevice`` in this tutorial.
Just as an Ethernet NIC is designed to work with an Ethernet network, the
``CsmaNetDevice`` is designed to work with a ``CsmaChannel``; the
``PointToPointNetDevice`` is designed to work with a
``PointToPointChannel`` and a ``WifiNetNevice`` is designed to work with
a ``WifiChannel``.
A abstra<72><61>o do dispositivo de rede <20> representado em C++ pela classe ``NetDevice``, que fornece m<>todos para gerenciar conex<65>es para objetos ``Node`` e ``Channel``. Os dispositivos, assim como os canais e as aplica<63><61>es, tamb<6D>m podem ser especializados. V<>rias vers<72>es do ``NetDevice`` s<>o utilizadas neste tutorial, tais como: ``CsmaNetDevice``, ``PointToPointNetDevice`` e ``WifiNetDevice``. Assim como uma placa de rede Ethernet <20> projetada para trabalhar em uma rede Ethernet, um ``CsmaNetDevice``<20> projetado para trabalhar com um ``CsmaChannel``. O ``PointToPointNetDevice`` deve trabalhar com um ``PointToPointChannel`` e o ``WifiNetNevice`` com um ``WifiChannel``.
.. Topology Helpers
Assistentes de Topologia (`Topology Helpers`)
+++++++++++++++++++++++++++++++++++++++++++++
..
In a real network, you will find host computers with added (or built-in)
NICs. In |ns3| we would say that you will find ``Nodes`` with
attached ``NetDevices``. In a large simulated network you will need to
arrange many connections between ``Nodes``, ``NetDevices`` and
``Channels``.
Em redes reais, os computadores possuem placas de rede, sejam elas integradas ou n<>o. No |ns3|, teremos n<>s com dispositivos de rede. Em grandes simula<6C><61>es, ser<65> necess<73>rio arranjar muitas conex<65>es entre n<>s, dispositivos e canais de comunica<63><61>o.
..
Since connecting ``NetDevices`` to ``Nodes``, ``NetDevices``
to ``Channels``, assigning IP addresses, etc., are such common tasks
in |ns3|, we provide what we call *topology helpers* to make
this as easy as possible. For example, it may take many distinct
|ns3| core operations to create a NetDevice, add a MAC address,
install that net device on a ``Node``, configure the node's protocol stack,
and then connect the ``NetDevice`` to a ``Channel``. Even more
operations would be required to connect multiple devices onto multipoint
channels and then to connect individual networks together into internetworks.
We provide topology helper objects that combine those many distinct operations
into an easy to use model for your convenience.
Visto que conectar dispositivos a n<>s e a canais, atribuir endere<72>os IP, etc., s<>o todas tarefas rotineiras no |ns3|, s<>o fornecidos os Assistentes de Topologia (*topology helpers*). Por exemplo, podem ser necess<73>rias muitas opera<72><61>es distintas para criar um dispositivo, atribuir um endere<72>o MAC a ele, instalar o dispositivo em um n<>, configurar a pilha de protocolos no n<> em quest<73>o e por fim, conectar o dispositivo ao canal. Ainda mais opera<72><61>es podem ser necess<73>rias para conectar m<>ltiplos dispositivos em canais multiponto e ent<6E>o fazer a interconex<65>o das v<>rias redes. Para facilitar o trabalho, s<>o disponibilizados objetos que s<>o Assistentes de Topologia, que combinam estas opera<72><61>es distintas em um modelo f<>cil e conveniente.
.. A First ns-3 Script
O primeiro c<>digo no ns-3
*************************
..
If you downloaded the system as was suggested above, you will have a release
of |ns3| in a directory called ``repos`` under your home
directory. Change into that release directory, and you should find a
directory structure something like the following:
Se o sistema foi baixado como sugerido, uma vers<72>o do |ns3| estar<61> em um diret<65>rio chamado ``repos`` dentro do diret<65>rio `home`. Entrando no diret<65>rio dessa vers<72>o, dever<65> haver uma estrutura parecida com a seguinte:
::
AUTHORS examples scratch utils waf.bat*
bindings LICENSE src utils.py waf-tools
build ns3 test.py* utils.pyc wscript
CHANGES.html README testpy-output VERSION wutils.py
doc RELEASE_NOTES testpy.supp waf* wutils.pyc
..
Change into the ``examples/tutorial`` directory. You should see a file named
``first.cc`` located there. This is a script that will create a simple
point-to-point link between two nodes and echo a single packet between the
nodes. Let's take a look at that script line by line, so go ahead and open
``first.cc`` in your favorite editor.
Entrando no diret<65>rio ``examples/tutorial``, vai haver um arquivo chamado ``first.cc``. Este <20> um c<>digo que criar<61> uma conex<65>o ponto-a-ponto entre dois n<>s e enviar<61> um pacote de eco entre eles. O arquivo ser<65> analisado linha a linha, para isto, o leitor pode abri-lo em seu editor de textos favorito.
..
Boilerplate
Padroniza<EFBFBD><EFBFBD>o
++++++++++++
..
The first line in the file is an emacs mode line. This tells emacs about the
formatting conventions (coding style) we use in our source code.
A primeira linha do arquivo <20> uma linha de modo emacs, que informa sobre a conven<65><6E>o de formata<74><61>o (estilo de codifica<63><61>o) que ser<65> usada no c<>digo fonte.
Este <20> sempre um assunto um tanto quanto controverso. O projeto |ns3|, tal como a maioria dos projetos de grande porte, adotou um estilo de codifica<63><61>o, para o qual todo o c<>digo deve conformar. Se o leitor quiser contribuir com o projeto, dever<65> estar em conformidade com a codifica<63><61>o que est<73> descrita no arquivo ``doc/codingstd.txt`` ou no `s<>tio <http://www.nsnam.org/developers/contributing-code/coding-style/>`_.
We recommend that you, well, just get used to the look and feel of |ns3|
code and adopt this standard whenever you are working with our code. All of
the development team and contributors have done so with various amounts of
grumbling. The emacs mode line above makes it easier to get the formatting
correct if you use the emacs editor.
A equipe do |ns3| recomenda aos novos usu<73>rios que adotem o padr<64>o quando estiverem tralhando com o c<>digo. Tanto eles, quanto todos os que contribuem, tiveram que fazer isto em algum momento. Para aqueles que utilizam o editor Emacs, a linha de modo torna mais facil seguir o padr<64>o corretamente.
..
The |ns3| simulator is licensed using the GNU General Public
License. You will see the appropriate GNU legalese at the head of every file
in the |ns3| distribution. Often you will see a copyright notice for
one of the institutions involved in the |ns3| project above the GPL
text and an author listed below.
O |ns3| <20> licenciado usando a `GNU General Public License` - GPL. No cabe<62>alho de todo aquivo da distribui<75><69>o h<> as quest<73>es legais associadas <20> licen<65>a. Frequentemente, haver<65> tamb<6D>m informa<6D><61>es sobre os direitos de c<>pia de uma das institui<75><69>es envolvidas no projeto e o autor do arquivo.
::
/*
* 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
*/
.. Module Includes
Inclus<EFBFBD>o de M<>dulos
+++++++++++++++++++
..
The code proper starts with a number of include statements.
O c<>digo realmente come<6D>a pelo carregamento de m<>dulos atrav<61>s da inclus<75>o dos arquivos:
::
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
..
To help our high-level script users deal with the large number of include
files present in the system, we group includes according to relatively large
modules. We provide a single include file that will recursively load all of
the include files used in each module. Rather than having to look up exactly
what header you need, and possibly have to get a number of dependencies right,
we give you the ability to load a group of files at a large granularity. This
is not the most efficient approach but it certainly makes writing scripts much
easier.
Os arquivos a serem inclu<6C>dos s<>o agrupados em m<>dulos relativamente grandes, de forma a ajudar os usu<73>rios. Tamb<6D>m <20> poss<73>vel fazer refer<65>ncia a um <20>nico arquivo que ir<69> recursivamente carregar todas as bibliotecas de cada m<>dulo. Ao inv<6E>s de procurar pelo arquivo exato, e provavelmente, ter que resolver depend<6E>ncias, <20> poss<73>vel carregar um grupo de arquivos de uma vez. Esta com certeza n<>o <20> a abordagem mais eficiente, mas permite escrever c<>digos de forma bem mais f<>cil.
..
Each of the |ns3| include files is placed in a directory called
``ns3`` (under the build directory) during the build process to help avoid
include file name collisions. The ``ns3/core-module.h`` file corresponds
to the ns-3 module you will find in the directory ``src/core`` in your
downloaded release distribution. If you list this directory you will find a
large number of header files. When you do a build, Waf will place public
header files in an ``ns3`` directory under the appropriate
``build/debug`` or ``build/optimized`` directory depending on your
configuration. Waf will also automatically generate a module include file to
load all of the public header files.
Durante a constru<72><75>o, cada um dos arquivos inclu<6C>dos <20> copiado para o diret<65>rio chamado ``ns3`` (dentro do diret<65>rio ``build``), o que ajuda a evitar conflito entre os nomes dos arquivos de bibliotecas. O arquivo ``ns3/core-module.h``, por exemplo, corresponde ao m<>dulo que est<73> no diret<65>rio ``src/core``. H<> um grande n<>mero de arquivos neste diret<65>rio. No momento em que o Waf est<73> construindo o projeto, copia os arquivos para o diret<65>rio ``ns3``, no subdiret<65>rio apropriado --- ``build/debug`` ou ``build/optimized`` --- dependendo da configura<72><61>o utilizada.
..
Since you are, of course, following this tutorial religiously, you will
already have done a
Considerando que o leitor esteja seguindo este tutorial, j<> ter<65> feito:
in order to configure the project to perform debug builds that include
examples and tests. You will also have done a
Tamb<EFBFBD>m j<> ter<65> feito
::
./waf
..
to build the project. So now if you look in the directory
``../../build/debug/ns3`` you will find the four module include files shown
above. You can take a look at the contents of these files and find that they
do include all of the public include files in their respective modules.
para construir o projeto. Ent<6E>o, no diret<65>rio ``../../build/debug/ns3`` dever<65> haver os quatro m<>dulos inclu<6C>dos anteriormente. Olhando para o conte<74>do destes arquivos, <20> poss<73>vel observar que eles incluem todos os arquivos p<>blicos dos seus respectivos m<>dulos.
Ns3 `Namespace`
+++++++++++++++
..
The next line in the ``first.cc`` script is a namespace declaration.
A pr<70>xima linha no c<>digo ``first.cc``<20> a declara<72><61>o do `namespace`.
::
using namespace ns3;
..
The |ns3| project is implemented in a C++ namespace called
``ns3``. This groups all |ns3|-related declarations in a scope
outside the global namespace, which we hope will help with integration with
other code. The C++ ``using`` statement introduces the |ns3|
namespace into the current (global) declarative region. This is a fancy way
of saying that after this declaration, you will not have to type ``ns3::``
scope resolution operator before all of the |ns3| code in order to use
it. If you are unfamiliar with namespaces, please consult almost any C++
tutorial and compare the ``ns3`` namespace and usage here with instances of
the ``std`` namespace and the ``using namespace std;`` statements you
will often find in discussions of ``cout`` and streams.
O projeto |ns3| <20> implementado em um `namespace` chamado `ns3`. Isto agrupa todas as declara<72><61>es relacionadas ao projeto em um escopo fora do global, que ajuda na integra<72><61>o com outros c<>digos. A declara<72><61>o ``using`` do C++ insere o `namespace` |ns3| no escopo global, evitando que se tenha que ficar digitando ``ns3::`` antes dos c<>digos |ns3|. Se o leitor n<>o esta familiarizado com `namesapaces`, consulte algum tutorial de C++ e compare o `namespace```ns3`` e o `namespace```std``, usado com frequ<71>ncia em C++, principalmente com ``cout`` e ``streams``.
.. Logging
Registro (`Logging`)
++++++++++++++++++++
..
The next line of the script is the following,
A pr<70>xima linha do c<>digo <20> o seguinte,
::
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
..
We will use this statement as a convenient place to talk about our Doxygen
documentation system. If you look at the project web site,
`ns-3 project
<http://www.nsnam.org>`_, you will find a link to "Documentation" in the navigation bar. If you select this link, you will be
taken to our documentation page. There
is a link to "Latest Release" that will take you to the documentation
for the latest stable release of |ns3|.
If you select the "API Documentation" link, you will be
taken to the |ns3| API documentation page.
N<EFBFBD>s iremos utilizar esta declara<72><61>o em um lugar conveniente para conversar com o sistema de documenta<74><61>o Doxygen. Se voc<6F> procurar no `web site` do `projeto ns-3 <http://www.nsnam.org>`_, voc<6F> encontrar<61> um `link` para a documenta<74><61>o (`Documentation`) na barra de navega<67><61>o. Se selecionarmos este `link`, veremos a p<>gina de documenta<74><61>o. L<> tem um `link` para as <20>ltimas `releases` (`Latest Release`) que ir<69>o apresentar a documenta<74><61>o da <20>ltima `release` do |ns3|. Se voc<6F> tamb<6D>m pode selecionar o `link` para a documenta<74><61>o das APIs (`API Documentation`).
..
Along the left side, you will find a graphical representation of the structure
of the documentation. A good place to start is the ``NS-3 Modules``
"book" in the |ns3| navigation tree. If you expand ``Modules``
you will see a list of |ns3| module documentation. The concept of
module here ties directly into the module include files discussed above. The |ns3| logging subsystem is discussed in the ``C++ Constructs Used by All Modules``
section, so go ahead and expand that documentation node. Now, expand the
``Debugging`` book and then select the ``Logging`` page.
Do lado esquerdo, voc<6F> achar<61> uma representa<74><61>o gr<67>fica da estrutura da documenta<74><61>o. Um bom lugar para come<6D>ar <20> com o livro de m<>dulos do NS-3 (``NS-3 Modules``) na <20>rvore de navega<67><61>o, voc<6F> pode expandir para ver a lista de documenta<74><61>o de m<>dulos do |ns3|. O conceito de m<>dulo aqui est<73> diretamente ligado com a inclus<75>o de bibliotecas apresentadas anteriormente. O sistema de registro (`logging`) <20> discutido na se<73><65>o ``C++ Constructs Used by All Modules``, v<> em frente e expanda a documenta<74><61>o. Agora expanda o livro da depura<72><61>o (``Debugging``) e selecione a p<>gina de ``Logging``.
..
You should now be looking at the Doxygen documentation for the Logging module.
In the list of ``#define``s at the top of the page you will see the entry
for ``NS_LOG_COMPONENT_DEFINE``. Before jumping in, it would probably be
good to look for the "Detailed Description" of the logging module to get a
feel for the overall operation. You can either scroll down or select the
"More..." link under the collaboration diagram to do this.
Agora voc<6F> deve procurar na documenta<74><61>o Doxygen pelo m<>dulo de ``Logging``. Na lista de ``#define`` bem no topo da p<>gina voc<6F> ver<65> uma entrada para ``NS_LOG_COMPONENT_DEFINE``. Antes de ir para l<>, d<> uma boa olhada na descri<72><69>o detalhada (`Detailed Description`) do m<>dulo de `logging`.
..
Once you have a general idea of what is going on, go ahead and take a look at
the specific ``NS_LOG_COMPONENT_DEFINE`` documentation. I won't duplicate
the documentation here, but to summarize, this line declares a logging
component called ``FirstScriptExample`` that allows you to enable and
disable console message logging by reference to the name.
Uma vez que voc<6F> tem uma ideia geral, prossiga e olhe a documenta<74><61>o de ``NS_LOG_COMPONENT_DEFINE``. N<>o esperamos duplicar a documenta<74><61>o, mas para resumir esta linha declara o componente de `logging` chamado ``FirstScriptExample`` que permite habilitar e desabilitar mensagens de `logging` referenciando pelo nome.
.. Main Function
Fun<EFBFBD><EFBFBD>o Principal
++++++++++++++++
..
The next lines of the script you will find are,
As pr<70>ximas linhas do c<>digo s<>o,
::
int
main (int argc, char *argv[])
{
..
This is just the declaration of the main function of your program (script).
Just as in any C++ program, you need to define a main function that will be
the first function run. There is nothing at all special here. Your
|ns3| script is just a C++ program.
Esta <20> a declara<72><61>o da fun<75><6E>o principal (``main``) do programa. Assim como em qualquer programa em C++, voc<6F> precisa definir uma fun<75><6E>o principal que <20> a primeira fun<75><6E>o que ser<65> executada no programa. N<>o h<> nada de especial e seu c<>digo |ns3| <20> apenas um programa C++.
..
The next two lines of the script are used to enable two logging components that
are built into the Echo Client and Echo Server applications:
As pr<70>ximas duas linhas do c<>digo s<>o usadas para habilitar dois componentes de registro que s<>o constru<72>dos com as aplica<63><61>es de `Echo Client` e `Echo Server`:
If you have read over the Logging component documentation you will have seen
that there are a number of levels of logging verbosity/detail that you can
enable on each component. These two lines of code enable debug logging at the
INFO level for echo clients and servers. This will result in the application
printing out messages as packets are sent and received during the simulation.
Se voc<6F> leu a documenta<74><61>o do componente de `logging` voc<6F> viu que existem v<>rios n<>veis de detalhamento de `logging` e que voc<6F> pode habilit<69>-los para cada componente. Essas duas linhas de c<>digo habilitam a depura<72><61>o de `logging` com o n<>vel ``INFO`` para o cliente e servidor. Isto ira fazer com que as aplica<63><61>es mostrem as mensagens dos pacotes sendo enviados e recebidos durante a simula<6C><61>o.
..
Now we will get directly to the business of creating a topology and running
a simulation. We use the topology helper objects to make this job as
easy as possible.
Agora n<>s iremos direto ao ponto, criando uma topologia e executando uma simula<6C><61>o. N<>s usaremos o Assistente de Topologia para fazer isto da forma mais simples poss<73>vel.
.. Topology Helpers
Assistentes de Topologia
++++++++++++++++++++++++
.. NodeContainer
Cont<EFBFBD>ineres de n<>s (`NodeContainer`)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
..
The next two lines of code in our script will actually create the
|ns3| ``Node`` objects that will represent the computers in the
simulation.
As pr<70>ximas duas linhas de c<>digo cria os objetos do tipo ``Node`` que representar<61>o os computadores na simula<6C><61>o.
::
NodeContainer nodes;
nodes.Create (2);
..
Let's find the documentation for the ``NodeContainer`` class before we
continue. Another way to get into the documentation for a given class is via
the ``Classes`` tab in the Doxygen pages. If you still have the Doxygen
handy, just scroll up to the top of the page and select the ``Classes``
tab. You should see a new set of tabs appear, one of which is
``Class List``. Under that tab you will see a list of all of the
|ns3| classes. Scroll down, looking for ``ns3::NodeContainer``.
When you find the class, go ahead and select it to go to the documentation for
the class.
Antes de continuar vamos pesquisar a documenta<74><61>o da classe ``NodeContainer``. Outra forma de obter a documenta<74><61>o <20> atrav<61>s aba ``Classes`` na p<>gina do Doxygen. No Doxygen, v<> at<61> o topo da p<>gina e selecione ``Classes``. Ent<6E>o, voc<6F> ver<65> um novo conjunto de op<6F><70>es aparecendo, uma delas ser<65> a sub-aba ``Class List``. Dentro desta op<6F><70>o voc<6F> ver<65> uma lista com todas as classes do |ns3|. Agora procure por ``ns3::NodeContainer``. Quando voc<6F> achar a classe, selecione e veja a documenta<74><61>o da classe.
..
You may recall that one of our key abstractions is the ``Node``. This
represents a computer to which we are going to add things like protocol stacks,
applications and peripheral cards. The ``NodeContainer`` topology helper
provides a convenient way to create, manage and access any ``Node`` objects
that we create in order to run a simulation. The first line above just
declares a NodeContainer which we call ``nodes``. The second line calls the
``Create`` method on the ``nodes`` object and asks the container to
create two nodes. As described in the Doxygen, the container calls down into
the |ns3| system proper to create two ``Node`` objects and stores
pointers to those objects internally.
Lembre-se que uma de nossas abstra<72><61>es <20> o n<>. Este representa um computador, ao qual iremos adicionar coisas, como protocolos, aplica<63><61>es e perif<69>ricos. O assistente ``NodeContainer`` fornece uma forma conveniente de criar, gerenciar e acessar qualquer objeto ``Node`` que criamos para executar a simula<6C><61>o. A primeira linha declara um ``NodeContainer`` que chamamos de ``nodes``. A segunda linha chama o m<>todo ``Create`` sobre o objeto ``nodes`` e pede para criar dois n<>s.
..
The nodes as they stand in the script do nothing. The next step in
constructing a topology is to connect our nodes together into a network.
The simplest form of network we support is a single point-to-point link
between two nodes. We'll construct one of those links here.
Os n<>s, como est<73>o no c<>digo, n<>o fazem nada. O pr<70>ximo passo <20> montar uma topologia para conect<63>-los em uma rede. Uma forma simples de conectar dois computadores em uma rede <20> com um enlace ponto-a-ponto.
PointToPointHelper
~~~~~~~~~~~~~~~~~~
..
We are constructing a point to point link, and, in a pattern which will become
quite familiar to you, we use a topology helper object to do the low-level
work required to put the link together. Recall that two of our key
abstractions are the ``NetDevice`` and the ``Channel``. In the real
world, these terms correspond roughly to peripheral cards and network cables.
Typically these two things are intimately tied together and one cannot expect
to interchange, for example, Ethernet devices and wireless channels. Our
Topology Helpers follow this intimate coupling and therefore you will use a
single ``PointToPointHelper`` to configure and connect |ns3|
``PointToPointNetDevice`` and ``PointToPointChannel`` objects in this
script.
Construiremos um enlace ponto-a-ponto e para isto usaremos um assistente para configurar o n<>vel mais baixo da rede. Lembre-se que duas abstra<72><61>es b<>sicas s<>o ``NetDevice`` e ``Channel``. No mundo real, estes termos correspondem, a grosso modo, <20> placa de rede e ao cabo. Normalmente, estes dois est<73>o intimamente ligados e n<>o <20> normal ficar trocando. Por exemplo, n<>o <20> comum placas Ethernet conectadas em canais sem fio. O assistente de topologia acopla estes dois conceitos em um simples ``PointToPointHelper`` para configurar e conectar objetos ``PointToPointNetDevice`` e ``PointToPointChannel`` em nosso c<>digo.
tells the ``PointToPointHelper`` object to use the value "5Mbps"
(five megabits per second) as the "DataRate" when it creates a
``PointToPointNetDevice`` object.
diz ao objeto ``PointToPointHelper`` para usar o valor de "5Mbps" (cinco `megabits` por segundo) como "DataRate" (taxa de transfer<65>ncia) quando criarmos um objeto ``PointToPointNetDevice``.
..
From a more detailed perspective, the string "DataRate" corresponds
to what we call an ``Attribute`` of the ``PointToPointNetDevice``.
If you look at the Doxygen for class ``ns3::PointToPointNetDevice`` and
find the documentation for the ``GetTypeId`` method, you will find a list
of ``Attributes`` defined for the device. Among these is the "DataRate"
``Attribute``. Most user-visible |ns3| objects have similar lists of
``Attributes``. We use this mechanism to easily configure simulations without
recompiling as you will see in a following section.
De uma perspectiva mais detalhada, a palavra "DataRate" corresponde ao que n<>s chamamos de atributo (``Attribute``) do ``PointToPointNetDevice``. Se voc<6F> olhar no Doxygen na classe ``ns3::PointToPointNetDevice`` e procurar a documenta<74><61>o para o m<>todo ``GetTypeId``, voc<6F> achar<61> uma lista de atributos definidos por dispositivos. Dentro desses est<73> o atributo "DataRate". A maioria dos objetos do |ns3| tem uma lista similar de atributos. N<>s usamos este mecanismo para facilitar a configura<72><61>o das simula<6C><61>es sem precisar recompilar, veremos isto na se<73><65>o seguinte.
..
Similar to the "DataRate" on the ``PointToPointNetDevice`` you will find a
"Delay" ``Attribute`` associated with the ``PointToPointChannel``. The
final line,
Parecido com o "DataRate" no ``PointToPointNetDevice`` voc<6F> achar<61> o atributo "Delay" (atraso) associado com o ``PointToPointChannel``. O final da linha,
tells the ``PointToPointHelper`` to use the value "2ms" (two milliseconds)
as the value of the transmission delay of every point to point channel it
subsequently creates.
diz ao ``PointToPointHelper`` para usar o valor de "2ms" (dois milissegundos) como valor de atraso de transmiss<73>o para o canal ponto-a-ponto criado.
NetDeviceContainer
~~~~~~~~~~~~~~~~~~
..
At this point in the script, we have a ``NodeContainer`` that contains
two nodes. We have a ``PointToPointHelper`` that is primed and ready to
make ``PointToPointNetDevices`` and wire ``PointToPointChannel`` objects
between them. Just as we used the ``NodeContainer`` topology helper object
to create the ``Nodes`` for our simulation, we will ask the
``PointToPointHelper`` to do the work involved in creating, configuring and
installing our devices for us. We will need to have a list of all of the
NetDevice objects that are created, so we use a NetDeviceContainer to hold
them just as we used a NodeContainer to hold the nodes we created. The
following two lines of code,
At<EFBFBD> agora no c<>digo, temos um ``NodeContainer`` que cont<6E>m dois n<>s. Tamb<6D>m temos ``PointToPointHelper`` que carrega e prepara os objetos ``PointToPointNetDevices`` e ``PointToPointChannel``. Depois, usamos o assistente ``NodeContainer`` para criar os n<>s para a simula<6C><61>o. Iremos pedir ao ``PointToPointHelper`` para criar, configurar e instalar nossos dispositivos. Iremos necessitar de uma lista de todos os objetos `NetDevice` que s<>o criados, ent<6E>o n<>s usamos um `NetDeviceContainer` para agrupar os objetos criados, tal como usamos o `NodeContainer` para agrupar os n<>s que criamos. Nas duas linhas de c<>digo seguintes,
::
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes);
..
will finish configuring the devices and channel. The first line declares the
device container mentioned above and the second does the heavy lifting. The
``Install`` method of the ``PointToPointHelper`` takes a
``NodeContainer`` as a parameter. Internally, a ``NetDeviceContainer``
is created. For each node in the ``NodeContainer`` (there must be exactly
two for a point-to-point link) a ``PointToPointNetDevice`` is created and
saved in the device container. A ``PointToPointChannel`` is created and
the two ``PointToPointNetDevices`` are attached. When objects are created
by the ``PointToPointHelper``, the ``Attributes`` previously set in the
helper are used to initialize the corresponding ``Attributes`` in the
created objects.
vamos terminar configurando os dispositivos e o canal. A primeira linha declara o cont<6E>iner de dispositivos mencionado anteriormente e o segundo faz o trabalho pesado. O m<>todo ``Install`` do ``PointToPointHelper`` utiliza um ``NodeContainer`` como par<61>metro. Internamente, um ``NetDeviceContainer``<20> criado. Para cada n<> no ``NodeContainer`` (devem existir dois para um enlace ponto-a-ponto) um ``PointToPointNetDevice``<20> criado e salvo no cont<6E>iner do dispositivo. Um ``PointToPointChannel``<20> criado e dois ``PointToPointNetDevices`` s<>o conectados. Quando os objetos s<>o criados pelo ``PointToPointHelper``, os atributos, passados anteriormente, s<>o configurados pelo assistente (`Helper`).
..
After executing the ``pointToPoint.Install (nodes)`` call we will have
two nodes, each with an installed point-to-point net device and a single
point-to-point channel between them. Both devices will be configured to
transmit data at five megabits per second over the channel which has a two
millisecond transmission delay.
Depois de executar a chamada ``pointToPoint.Install (nodes)`` iremos ter dois n<>s, cada qual instalado na rede ponto-a-ponto e um <20>nico canal ponto-a-ponto ligando os dois. Ambos os dispositivos ser<65>o configurados para ter uma taxa de transfer<65>ncia de dados de cinco megabits por segundo, que por sua vez tem um atraso de transmiss<73>o de dois milissegundos.
InternetStackHelper
~~~~~~~~~~~~~~~~~~~
..
We now have nodes and devices configured, but we don't have any protocol stacks
installed on our nodes. The next two lines of code will take care of that.
Agora temos os n<>s e dispositivos configurados, mas n<>o temos qualquer pilha de protocolos instalada em nossos n<>s. As pr<70>ximas duas linhas de c<>digo ir<69>o cuidar disso.
::
InternetStackHelper stack;
stack.Install (nodes);
..
The ``InternetStackHelper`` is a topology helper that is to internet stacks
what the ``PointToPointHelper`` is to point-to-point net devices. The
``Install`` method takes a ``NodeContainer`` as a parameter. When it is
executed, it will install an Internet Stack (TCP, UDP, IP, etc.) on each of
the nodes in the node container.
O ``InternetStackHelper``<20> um assistente de topologia inter-rede. O m<>todo ``Install`` utiliza um ``NodeContainer`` como par<61>metro. Quando isto <20> executado, ele ir<69> instalar a pilha de protocolos da Internet (TCP, UDP, IP, etc) em cada n<> do cont<6E>iner.
Ipv4AddressHelper
~~~~~~~~~~~~~~~~~
..
Next we need to associate the devices on our nodes with IP addresses. We
provide a topology helper to manage the allocation of IP addresses. The only
user-visible API is to set the base IP address and network mask to use when
performing the actual address allocation (which is done at a lower level
inside the helper).
Agora precisamos associar os dispositivos dos n<>s a endere<72>os IP. N<>s fornecemos um assistente de topologia para gerenciar a aloca<63><61>o de endere<72>os IP's. A <20>nica API de usu<73>rio vis<69>vel serve para configurar o endere<72>o IP base e a m<>scara de rede, usado para aloca<63><61>o de endere<72>os.
..
The next two lines of code in our example script, ``first.cc``,
As pr<70>ximas duas linhas de c<>digo,
::
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
..
declare an address helper object and tell it that it should begin allocating IP
addresses from the network 10.1.1.0 using the mask 255.255.255.0 to define
the allocatable bits. By default the addresses allocated will start at one
and increase monotonically, so the first address allocated from this base will
be 10.1.1.1, followed by 10.1.1.2, etc. The low level |ns3| system
actually remembers all of the IP addresses allocated and will generate a
fatal error if you accidentally cause the same address to be generated twice
(which is a very hard to debug error, by the way).
declara um assistente de endere<72>amento e diz para ele iniciar a aloca<63><61>o de IP's na rede 10.1.1.0 usando a m<>scara 255.255.255.0. Por padr<64>o, os endere<72>os alocados ir<69>o iniciar do primeiro endere<72>o IP dispon<6F>vel e ser<65>o incrementados um a um. Ent<6E>o, o primeiro endere<72>o IP alocado ser<65> o 10.1.1.1, seguido pelo 10.1.1.2, etc. Em um n<>vel mais baixo, o |ns3| mant<6E>m todos os endere<72>os IP's alocados e gera um erro fatal se voc<6F> acidentalmente usar o mesmo endere<72>o duas vezes (esse <20> um erro muito dif<69>cil de depurar).
performs the actual address assignment. In |ns3| we make the
association between an IP address and a device using an ``Ipv4Interface``
object. Just as we sometimes need a list of net devices created by a helper
for future reference we sometimes need a list of ``Ipv4Interface`` objects.
The ``Ipv4InterfaceContainer`` provides this functionality.
realiza efetivamente o endere<72>amento. No |ns3| n<>s fazemos a associa<69><61>o entre endere<72>os IP e dispositivos usando um objeto ``Ipv4Interface``. As vezes precisamos de uma lista dos dispositivos de rede criados pelo assistente de topologia para consultas futuras. O ``Ipv4InterfaceContainer`` fornece esta funcionalidade.
..
Now we have a point-to-point network built, with stacks installed and IP
addresses assigned. What we need at this point are applications to generate
traffic.
Agora que n<>s temos uma rede ponto-a-ponto funcionando, com pilhas de protocolos instaladas e endere<72>os IP's configurados. O que n<>s precisamos s<>o aplica<63><61>es para gerar o tr<74>fego de rede.
..
Applications
Aplica<EFBFBD><EFBFBD>es
++++++++++
..
Another one of the core abstractions of the ns-3 system is the
``Application``. In this script we use two specializations of the core
|ns3| class ``Application`` called ``UdpEchoServerApplication``
and ``UdpEchoClientApplication``. Just as we have in our previous
explanations, we use helper objects to help configure and manage the
underlying objects. Here, we use ``UdpEchoServerHelper`` and
``UdpEchoClientHelper`` objects to make our lives easier.
Outra abstra<72><61>o do n<>cleo do |ns3| s<>o as aplica<63><61>es (``Application``). Neste c<>digo s<>o utilizadas duas especializa<7A><61>es da classe ``Application`` chamadas ``UdpEchoServerApplication`` e ``UdpEchoClientApplication``. Assim como nas explica<63><61>es anteriores que n<>s utilizamos assistentes para configurar e gerenciar outros objetos, n<>s usaremos os objetos ``UdpEchoServerHelper`` e ``UdpEchoClientHelper`` para deixar a nossa vida mais f<>cil.
UdpEchoServerHelper
~~~~~~~~~~~~~~~~~~~
..
The following lines of code in our example script, ``first.cc``, are used
to set up a UDP echo server application on one of the nodes we have previously
created.
As linhas seguintes do c<>digo do exemplo ``first.cc``, s<>o usadas para configurar uma aplica<63><61>o de eco (`echo`) UDP em um dos n<>s criados anteriormente.
The first line of code in the above snippet declares the
``UdpEchoServerHelper``. As usual, this isn't the application itself, it
is an object used to help us create the actual applications. One of our
conventions is to place *required*``Attributes`` in the helper constructor.
In this case, the helper can't do anything useful unless it is provided with
a port number that the client also knows about. Rather than just picking one
and hoping it all works out, we require the port number as a parameter to the
constructor. The constructor, in turn, simply does a ``SetAttribute``
with the passed value. If you want, you can set the "Port" ``Attribute``
to another value later using ``SetAttribute``.
Um fragmento da primeira linha do c<>digo declara o ``UdpEchoServerHelper``. Esta n<>o <20> a pr<70>pria aplica<63><61>o, <20> o objeto usado para ajudar na cria<69><61>o da aplica<63><61>o. Uma de nossas conven<65><6E>es <20> colocar os atributos *obrigat<61>rios* no construtor do assistente de topologia. Neste caso, o assistente n<>o pode fazer nada se n<>o colocarmos um n<>mero de porta que o cliente conhece. O construtor, por sua vez, configura o atributo "Port" usando ``SetAttribute``.
..
Similar to many other helper objects, the ``UdpEchoServerHelper`` object
has an ``Install`` method. It is the execution of this method that actually
causes the underlying echo server application to be instantiated and attached
to a node. Interestingly, the ``Install`` method takes a
``NodeContainter`` as a parameter just as the other ``Install`` methods
we have seen. This is actually what is passed to the method even though it
doesn't look so in this case. There is a C++ *implicit conversion* at
work here that takes the result of ``nodes.Get (1)`` (which returns a smart
pointer to a node object --- ``Ptr<Node>``) and uses that in a constructor
for an unnamed ``NodeContainer`` that is then passed to ``Install``.
If you are ever at a loss to find a particular method signature in C++ code
that compiles and runs just fine, look for these kinds of implicit conversions.
De forma semelhante aos outros assistentes, o ``UdpEchoServerHelper`` tem o m<>todo ``Install``. <20> este m<>todo que instancia a aplica<63><61>o de servidor de eco (``echo server``) e a associa ao n<>. O m<>todo ``Install`` tem como par<61>metro um ``NodeContainter``, assim como o outro m<>todo ``Install`` visto. Isto <20> o que <20> passado para o m<>todo, mesmo que n<>o seja vis<69>vel. H<> uma *convers<72>o impl<70>cita* em C++, que pega o resultado de ``nodes.Get (1)`` (o qual retorna um ponteiro para o objeto `node` --- ``Ptr<Node>``) e o usa em um construtor de um ``NodeContainer`` sem nome, que ent<6E>o <20> passado para o m<>todo ``Install``.
..
We now see that ``echoServer.Install`` is going to install a
``UdpEchoServerApplication`` on the node found at index number one of the
``NodeContainer`` we used to manage our nodes. ``Install`` will return
a container that holds pointers to all of the applications (one in this case
since we passed a ``NodeContainer`` containing one node) created by the
helper.
Agora vemos que o ``echoServer.Install`` instala um ``UdpEchoServerApplication`` no primeiro n<> do ``NodeContainer``. O ``Install`` ir<69> retornar um cont<6E>iner que armazena os ponteiros de todas as aplica<63><61>es (neste caso passamos um ``NodeContainer`` contendo um n<>) criadas pelo assistente de topologia.
..
Applications require a time to "start" generating traffic and may take an
optional time to "stop". We provide both. These times are set using the
``ApplicationContainer`` methods ``Start`` and ``Stop``. These
methods take ``Time`` parameters. In this case, we use an *explicit*
C++ conversion sequence to take the C++ double 1.0 and convert it to an
|ns3| ``Time`` object using a ``Seconds`` cast. Be aware that
the conversion rules may be controlled by the model author, and C++ has its
own rules, so you can't always just assume that parameters will be happily
converted for you. The two lines,
As aplica<63><61>es requerem um tempo para "iniciar" a gera<72><61>o de tr<74>fego de rede e podem ser opcionalmente "desligadas". Estes tempos podem ser configurados usando o ``ApplicationContainer`` com os m<>todos ``Start`` e ``Stop``, respectivamente. Esses m<>todos possuem o par<61>metro ``Time``. Em nosso exemplo, n<>s usamos uma conven<65><6E>o explicita do C++ para passar 1.0 e converter em um objeto ``Time`` usando segundos. Esteja ciente que as regras de convers<72>o podem ser controladas pelo autor do modelo e o C++ tem suas pr<70>prias regras, desta forma, voc<6F> n<>o pode assumir que o par<61>metro sempre vai ser convertido para voc<6F>. As duas linhas,
::
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
..
will cause the echo server application to ``Start`` (enable itself) at one
second into the simulation and to ``Stop`` (disable itself) at ten seconds
into the simulation. By virtue of the fact that we have declared a simulation
event (the application stop event) to be executed at ten seconds, the simulation
will last *at least* ten seconds.
ir<EFBFBD>o iniciar (``Start``) a aplica<63><61>o de servidor de eco um segundo ap<61>s o in<69>cio da simula<6C><61>o e depois desligar (``Stop``) em dez segundos. Em virtude de termos declarado que um evento de simula<6C><61>o (o evento de desligamento da aplica<63><61>o) deve ser executado por dez segundos, a simula<6C><61>o vai durar pelo menos dez segundos.
UdpEchoClientHelper
~~~~~~~~~~~~~~~~~~~
..
The echo client application is set up in a method substantially similar to
that for the server. There is an underlying ``UdpEchoClientApplication``
that is managed by an ``UdpEchoClientHelper``.
A aplica<63><61>o cliente de eco <20> configurada de forma muito similar ao servidor. H<> o ``UdpEchoClientApplication`` que <20> gerenciado por um ``UdpEchoClientHelper``.
For the echo client, however, we need to set five different ``Attributes``.
The first two ``Attributes`` are set during construction of the
``UdpEchoClientHelper``. We pass parameters that are used (internally to
the helper) to set the "RemoteAddress" and "RemotePort" ``Attributes``
in accordance with our convention to make required ``Attributes`` parameters
in the helper constructors.
Para o cliente de eco, precisamos configurar cinco diferentes atributos. Os dois primeiros s<>o configurados durante a constru<72><75>o do ``UdpEchoClientHelper``. Passamos os par<61>metros que s<>o usados (internamente pelo Assistente) para configurar os atributos "RemoteAddress" (endere<72>o remoto) e "RemotePort" (porta remota).
..
Recall that we used an ``Ipv4InterfaceContainer`` to keep track of the IP
addresses we assigned to our devices. The zeroth interface in the
``interfaces`` container is going to correspond to the IP address of the
zeroth node in the ``nodes`` container. The first interface in the
``interfaces`` container corresponds to the IP address of the first node
in the ``nodes`` container. So, in the first line of code (from above), we
are creating the helper and telling it so set the remote address of the client
to be the IP address assigned to the node on which the server resides. We
also tell it to arrange to send packets to port nine.
Lembre-se que usamos um ``Ipv4InterfaceContainer`` para configurar o endere<72>o IP em nossos dispositivos. A interface zero (primeira) no cont<6E>iner corresponde ao endere<72>o IP do n<> zero no cont<6E>iner de n<>s. A primeira interface corresponde ao endere<72>o IP do primeiro n<>. Ent<6E>o, na primeira linha do c<>digo anterior, n<>s criamos um assistente e dizemos ao n<> para configurar o endere<72>o remoto do cliente conforme o IP do servidor. N<>s dizemos tamb<6D>m para enviar pacotes para a porta nove.
..
The "MaxPackets" ``Attribute`` tells the client the maximum number of
packets we allow it to send during the simulation. The "Interval"
``Attribute`` tells the client how long to wait between packets, and the
"PacketSize" ``Attribute`` tells the client how large its packet payloads
should be. With this particular combination of ``Attributes``, we are
telling the client to send one 1024-byte packet.
O atributo "MaxPackets" diz ao cliente o n<>mero m<>ximo de pacotes que s<>o permitidos para envio durante a simula<6C><61>o. O atributo "Interval" diz ao cliente quanto tempo esperar entre os pacotes e o "PacketSize" informa ao cliente qual <20> o tamanho da <20>rea de dados do pacote. Com esta combina<6E><61>o de atributos que n<>s fizemos teremos clientes enviando pacotes de 1024 bytes.
..
Just as in the case of the echo server, we tell the echo client to ``Start``
and ``Stop``, but here we start the client one second after the server is
enabled (at two seconds into the simulation).
Assim como no caso do servidor de eco, n<>s dizemos para o cliente de eco iniciar e parar, mas aqui n<>s iniciamos o cliente um segundo depois que o servidor estiver funcionando (com dois segundos de simula<6C><61>o).
.. Simulator
Simulador (`Simulator`)
+++++++++++++++++++++++
..
What we need to do at this point is to actually run the simulation. This is
done using the global function ``Simulator::Run``.
O que n<>s precisamos agora <20> executar o simulador. Isto <20> feito usando a fun<75><6E>o global ``Simulator::Run``.
::
Simulator::Run ();
..
When we previously called the methods,
Quando n<>s chamamos os m<>todos
::
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
...
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
..
we actually scheduled events in the simulator at 1.0 seconds, 2.0 seconds and
two events at 10.0 seconds. When ``Simulator::Run`` is called, the system
will begin looking through the list of scheduled events and executing them.
First it will run the event at 1.0 seconds, which will enable the echo server
application (this event may, in turn, schedule many other events). Then it
will run the event scheduled for t=2.0 seconds which will start the echo client
application. Again, this event may schedule many more events. The start event
implementation in the echo client application will begin the data transfer phase
of the simulation by sending a packet to the server.
agendamos os eventos no simulador em 1 segundo, 2 segundos e dois eventos em 10 segundos. Quando chamamos ``Simulator::Run``, o sistema verificar<61> a lista de eventos agendados e os executar<61> no momento apropriado. Primeiramente, ele vai executar o evento de 1 segundo que inicia a aplica<63><61>o de servidor de eco. Depois executa o evento agendado com dois segundos (t=2,0) que iniciar<61> a aplica<63><61>o do cliente de eco. Estes eventos podem agendar muitos outros eventos. O evento `start` do cliente ir<69> iniciar a fase de transfer<65>ncia de dados na simula<6C><61>o enviando pacotes ao servidor.
..
The act of sending the packet to the server will trigger a chain of events
that will be automatically scheduled behind the scenes and which will perform
the mechanics of the packet echo according to the various timing parameters
that we have set in the script.
O ato de enviar pacotes para o servidor vai disparar uma cadeia de eventos que ser<65>o automaticamente escalonados e executar<61>o a mec<65>nica do envio de pacotes de eco de acordo com os v<>rios par<61>metros de tempo que configuramos no c<>digo.
..
Eventually, since we only send one packet (recall the ``MaxPackets``
``Attribute`` was set to one), the chain of events triggered by
that single client echo request will taper off and the simulation will go
idle. Once this happens, the remaining events will be the ``Stop`` events
for the server and the client. When these events are executed, there are
no further events to process and ``Simulator::Run`` returns. The simulation
is then complete.
Considerando que enviamos somente um pacote (lembre-se que o atributo ``MaxPackets`` foi definido com um), uma cadeia de eventos ser<65> disparada por este <20>nico pedido de eco do cliente at<61> cessar e o simulador ficar<61> ocioso. Uma vez que isto ocorra, os eventos restantes ser<65>o o ``Stop`` do servidor e do cliente. Quando estes eventos forem executados, n<>o havendo mais eventos para processar, o ``Simulator::Run`` retorna. A simula<6C><61>o est<73> completa.
..
All that remains is to clean up. This is done by calling the global function
``Simulator::Destroy``. As the helper functions (or low level
|ns3| code) executed, they arranged it so that hooks were inserted in
the simulator to destroy all of the objects that were created. You did not
have to keep track of any of these objects yourself --- all you had to do
was to call ``Simulator::Destroy`` and exit. The |ns3| system
took care of the hard part for you. The remaining lines of our first
|ns3| script, ``first.cc``, do just that:
Tudo que resta <20> limpar. Isto <20> feito chamando uma fun<75><6E>o global chamada ``Simulator::Destroy``. Uma das fun<75><6E>es dos assistentes (ou do c<>digo de baixo n<>vel do |ns3|) <20> agrupar todos os objetos que foram criados e destru<72>-los. Voc<6F> n<>o precisa tratar estes objetos --- tudo que precisa fazer <20> chamar ``Simulator::Destroy`` e sair. O |ns3| cuidar<61> desta dif<69>cil tarefa para voc<6F>. As linhas restantes do c<>digo fazem isto:
::
Simulator::Destroy ();
return 0;
}
.. Building Your Script
Construindo o c<>digo
++++++++++++++++++++
..
We have made it trivial to build your simple scripts. All you have to do is
to drop your script into the scratch directory and it will automatically be
built if you run Waf. Let's try it. Copy ``examples/tutorial/first.cc`` into
the ``scratch`` directory after changing back into the top level directory.
<EFBFBD> trivial construir (criar os bin<69>rios de) seu c<>digo. Tudo que tem a fazer <20> copiar seu c<>digo para dentro do diret<65>rio ``scratch`` e ele ser<65> constru<72>do automaticamente quando executar o Waf. Copie ``examples/tutorial/first.cc`` para o diret<65>rio ``scratch`` e depois volte ao diret<65>rio principal.
::
cd ../..
cp examples/tutorial/first.cc scratch/myfirst.cc
..
Now build your first example script using waf:
Agora construa seu primeiro exemplo usando o Waf:
::
./waf
..
You should see messages reporting that your ``myfirst`` example was built
successfully.
Voc<EFBFBD> deve ver mensagens reportando que o seu exemplo ``myfirst`` foi constru<72>do com sucesso.
You can now run the example (note that if you build your program in the scratch
directory you must run it out of the scratch directory):
Voc<EFBFBD> agora pode executar o exemplo (note que se voc<6F> construiu seu programa no diret<65>rio ``scratch``, ent<6E>o deve executar o comando fora deste diret<65>rio):
Here you see that the build system checks to make sure that the file has been
build and then runs it. You see the logging component on the echo client
indicate that it has sent one 1024 byte packet to the Echo Server on
10.1.1.2. You also see the logging component on the echo server say that
it has received the 1024 bytes from 10.1.1.1. The echo server silently
echoes the packet and you see the echo client log that it has received its
packet back from the server.
O sistema verifica se os arquivos foram constru<72>dos e ent<6E>o executa-os. Atrav<61>s do componente de registro vemos que o cliente enviou 1024 bytes para o servidor atrav<61>s do IP 10.1.1.2. Tamb<6D>m podemos ver que o servidor diz ter recebido 1024 bytes do IP 10.1.1.1 e ecoa o pacote para o cliente, que registra o seu recebimento.
.. Ns-3 Source Code
C<EFBFBD>digo fonte do Ns-3
********************
..
Now that you have used some of the |ns3| helpers you may want to
have a look at some of the source code that implements that functionality.
The most recent code can be browsed on our web server at the following link:
http://code.nsnam.org/ns-3-dev. There, you will see the Mercurial
summary page for our |ns3| development tree.
Agora que voc<6F> j<> utilizou alguns assistentes do |ns3|, podemos dar uma olhada no c<>digo fonte que implementa estas funcionalidades. Pode-se navegar o c<>digo mais recente no seguinte endere<72>o: http://code.nsnam.org/ns-3-dev. L<> voc<6F> ver<65> a p<>gina de sum<75>rio do Mercurial para a <20>rvore de desenvolvimento do |ns3|.
..
At the top of the page, you will see a number of links,
No in<69>cio da p<>gina, voc<6F> ver<65> v<>rios `links`,
Our example scripts are in the ``examples`` directory. If you click on ``examples``
you will see a list of subdirectories. One of the files in ``tutorial`` subdirectory is ``first.cc``. If
you click on ``first.cc`` you will find the code you just walked through.
Os c<>digos exemplo est<73>o no diret<65>rio ``examples``. Se voc<6F> clicar ver<65> uma lista de subdiret<65>rios. Um dos arquivos no subdiret<65>rio ``tutorial``<20> o ``first.cc``. Clicando nele voc<6F> encontrar<61> o c<>digo que acabamos de analisar.
..
The source code is mainly in the ``src`` directory. You can view source
code either by clicking on the directory name or by clicking on the ``files``
link to the right of the directory name. If you click on the ``src``
directory, you will be taken to the listing of the ``src`` subdirectories. If you
then click on ``core`` subdirectory, you will find a list of files. The first file
you will find (as of this writing) is ``abort.h``. If you click on the
``abort.h`` link, you will be sent to the source file for ``abort.h`` which
contains useful macros for exiting scripts if abnormal conditions are detected.
O c<>digo fonte <20> mantido no diret<65>rio ``src``. Voc<6F> pode v<>-lo clicando sobre o nome do diret<65>rio ou clicando no item ``files`` a direita do nome. Clicando no diret<65>rio ``src``, obter<65> uma lista de subdiret<65>rios. Clicando no subdiret<65>rio ``core``, encontrar<61> um lista de arquivos. O primeiro arquivo <20> o ``abort.h``, que cont<6E>m macros caso condi<64><69>es anormais sejam encontradas.
..
The source code for the helpers we have used in this chapter can be found in the
``src/applications/helper`` directory. Feel free to poke around in the directory tree to
get a feel for what is there and the style of |ns3| programs.
O c<>digo fonte para os assistentes utilizados neste cap<61>tulo podem ser encontrados no diret<65>rio ``src/applications/helper``. Sinta-se <20> vontade para explorar a <20>rvore de diret<65>rios e ver o estilo de c<>digo do |ns3|.