Created
June 8, 2018 03:05
-
-
Save dario-javier-rick/d2b0fa66a9f8ea2efb5f86e432d3da8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sistemas Operativos y Redes 2 | |
// TCP/IP: Dumbell topology | |
// Alumnos: Nicolas Cabral, Dar�o Rick | |
// Profesor: Alexis Tcach | |
// | |
// | |
// e1 - - r1 | |
// | | | |
// e2 ------- n0 ------ n1 -------- r2 | |
// | | | |
// e3 - - r3 | |
// | |
// | |
// - 1. Dise�ar un escenario con 3 emisores on/off application, 3 receptores | |
// y dos nodo intermedios. O sea se conectar�n los 3 emisores | |
// a un nodo, luego �ste a otro y finalmente �ste a los 3 destinos | |
// finales. Esto es normalmente llamado Dumbell topology. En el | |
// sistema deber� tener uno de los emisores UDP y los otros 2 TCP. | |
// Hacer pruebas s�lo con los 2 emisores TCP. Hacer que sature el | |
// canal. Medir esa velocidad de transferencia (la cantidad de paquetes | |
// que llegan a destino). Mostrar mediante gr�ficos, tama�o | |
// de colas de recepci�n, ventana de TCP y cualquier mecanismo | |
// que muestre lo que sucede. Explicar en el gr�fico las distintas | |
// etapas del protocolo TCP. Usar siempre conexiones cableadas. | |
// - 2. Calcular el ancho de banda del canal. Explicar qu� sucede. �Ve | |
// alguna anomal�a? Explicarla. | |
// - 3. Posteriormente, con esa misma configuraci�n, pero ahora tambi�n | |
// emitiendo el nodo UDP. Explicar qu� sucede con el ancho | |
// de banda utilizado por cada uno. | |
// - 4. Mostrar en los paquetes TCP d�nde se ven las distintas acciones | |
// del protocolo. | |
#include <string> | |
#include <fstream> | |
#include "ns3/core-module.h" | |
#include "ns3/point-to-point-module.h" | |
#include "ns3/internet-module.h" | |
#include "ns3/applications-module.h" | |
#include "ns3/network-module.h" | |
#include "ns3/packet-sink.h" | |
#include "ns3/netanim-module.h" | |
using namespace ns3; | |
NS_LOG_COMPONENT_DEFINE ("dumbell-topology"); | |
int | |
main (int argc, char *argv[]) | |
{ | |
bool tracing = false; | |
uint32_t maxBytes = 0; | |
// | |
// Flags para logs y tama�o de paquete | |
// | |
CommandLine cmd; | |
cmd.AddValue ("tracing", "Flag de logeo", tracing); | |
cmd.AddValue ("maxBytes", "Cantidad de bytes de la prueba", maxBytes); | |
cmd.Parse (argc, argv); | |
// | |
// Se crean los nodos seg�n la documentaci�n detallada al principio | |
// | |
NS_LOG_INFO ("Creando nodos."); | |
// NodeContainer nodos; | |
// NodeContainer emisores; | |
// NodeContainer receptores; | |
// nodos.Create(2); | |
// emisores.Create(3); | |
// receptores.Create(3); | |
NodeContainer n0n1; | |
n0n1.Create (2); | |
NodeContainer n1n2; | |
n1n2.Add (n0n1.Get (1)); | |
n1n2.Create (1); | |
NodeContainer n2n3; | |
n2n3.Add (n1n2.Get (1)); | |
n2n3.Create (1); | |
NodeContainer s0s1; | |
s0s1.Add(n2n3.Get (0)); | |
s0s1.Create (1); | |
NodeContainer u2n2; | |
u2n2.Add (n2n3.Get (0)); | |
u2n2.Create (1); | |
NodeContainer u1n0; | |
u1n0.Add (n0n1.Get (1)); | |
u1n0.Create (1); | |
NodeContainer s2s3; | |
s2s3.Add (n0n1.Get (1)); | |
s2s3.Create (1); | |
Names::Add ("Sender1", n0n1.Get (0)); | |
Names::Add ("Sender2", s2s3.Get (1)); | |
Names::Add ("Sender3", u1n0.Get (1)); | |
Names::Add ("Router1", n0n1.Get (1)); | |
Names::Add ("Router2", n1n2.Get (1)); | |
Names::Add ("Receiver1", n2n3.Get (1)); | |
Names::Add ("Receiver2", s0s1.Get (1)); | |
Names::Add ("Receiver3", u2n2.Get (1)); | |
// | |
// Se crean enlaces entre los nodos | |
// | |
NS_LOG_INFO ("Creando canales."); | |
// PointToPointHelper p2pIntermedio, p2p_1, p2p_2, p2p_3, p2p_4, p2p_5, p2p_6; | |
// NetDeviceContainer ndIntermedios = p2pIntermedio.Install(nodos); | |
// NetDeviceContainer ndEmisores, ndReceptores; | |
// PointToPointHelper pointToPoint; | |
// pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("500Kbps")); | |
// pointToPoint.SetChannelAttribute ("Delay", StringValue ("5ms")); | |
// NetDeviceContainer devices; | |
// devices = pointToPoint.Install (nodos); | |
PointToPointHelper p2p; | |
p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (10000000))); | |
p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10))); | |
PointToPointHelper s2s; | |
s2s.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (10000000))); | |
s2s.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10))); | |
NetDeviceContainer dev0 = p2p.Install (n0n1); | |
NetDeviceContainer dev1 = p2p.Install (n1n2); | |
NetDeviceContainer dev2 = p2p.Install (n2n3); | |
NetDeviceContainer Udpdev1 = s2s.Install (u1n0); | |
NetDeviceContainer Udpdev2 = s2s.Install (u2n2); | |
NetDeviceContainer sev0 = s2s.Install (s0s1); | |
NetDeviceContainer sev2 = s2s.Install (s2s3); | |
// | |
// Le doy el stack de internet a todos los nodos | |
// | |
InternetStackHelper internet; | |
internet.InstallAll (); | |
// internet.Install(nodos); | |
// internet.Install(emisores); | |
// internet.Install(receptores); | |
//Asigno Ips | |
// NS_LOG_INFO ("Asignando IPs."); | |
// Ipv4AddressHelper routerIp = Ipv4AddressHelper("10.3.0.0","255.255.255.0"); | |
// Ipv4InterfaceContainer routerIFC; | |
// routerIFC = routerIp.Assign(ndIntermedios); | |
/* | |
Ipv4AddressHelper ipv4; | |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); | |
Ipv4InterfaceContainer i = ipv4.Assign (devices); | |
*/ | |
Ipv4AddressHelper ipv4; | |
ipv4.SetBase ("10.1.3.0", "255.255.255.0"); | |
ipv4.Assign (dev0); | |
ipv4.SetBase ("10.1.2.0", "255.255.255.0"); | |
ipv4.Assign (dev1); | |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); | |
Ipv4InterfaceContainer ipInterfs = ipv4.Assign (dev2); | |
Ipv4AddressHelper isv4; | |
isv4.SetBase ("10.2.3.0", "255.255.255.0"); | |
isv4.Assign (sev0); | |
isv4.SetBase ("10.2.1.0", "255.255.255.0"); | |
Ipv4InterfaceContainer isInterfs = isv4.Assign (sev2); | |
Ipv4AddressHelper Udpipv4; | |
Udpipv4.SetBase ("10.3.1.0", "255.255.255.0"); | |
Udpipv4.Assign (Udpdev1); | |
Udpipv4.SetBase ("10.3.2.0", "255.255.255.0"); | |
Ipv4InterfaceContainer interfacesUdp = Udpipv4.Assign (Udpdev2); | |
// and setup ip routing tables to get total ip-level connectivity. | |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); | |
// | |
// Create a BulkSendApplication and install it on node 0 | |
// | |
uint16_t port = 9; // well-known echo port number | |
BulkSendHelper source ("ns3::TcpSocketFactory", | |
InetSocketAddress (Ipv4Address::GetAny (), port)); | |
// Set the amount of data to send in bytes. Zero is unlimited. | |
source.SetAttribute ("MaxBytes", UintegerValue (maxBytes)); | |
ApplicationContainer sourceApps = source.Install (n2n3.Get (0)); | |
sourceApps.Start (Seconds (0.0)); | |
sourceApps.Stop (Seconds (10.0)); | |
// | |
// Create a PacketSinkApplication and install it on node 1 | |
// | |
PacketSinkHelper sink ("ns3::TcpSocketFactory", | |
InetSocketAddress (Ipv4Address::GetAny (), port)); | |
ApplicationContainer sinkApps = sink.Install (n2n3.Get (1)); | |
sinkApps.Start (Seconds (0.0)); | |
sinkApps.Stop (Seconds (10.0)); | |
//uint16_t servPort = 50000; | |
uint16_t servSort = 40000; | |
PacketSinkHelper sins ("ns3::TcpSocketFactory", | |
InetSocketAddress (Ipv4Address::GetAny (), servSort)); | |
ApplicationContainer asps = sins.Install (s2s3.Get (1)); | |
asps.Start (Seconds (0.0)); | |
asps.Stop (Seconds (3.0)); | |
// | |
// Set up tracing if enabled | |
// | |
if (tracing) | |
{ | |
AsciiTraceHelper ascii; | |
//pointToPoint.EnableAsciiAll (ascii.CreateFileStream ("tcp-bulk-send.tr")); | |
// pointToPoint.EnablePcapAll ("tcp-bulk-send", false); | |
} | |
//Envio de paquetes | |
// Create and bind the socket... | |
Ptr<Socket> localSocket = | |
Socket::CreateSocket (n0n1.Get (0), TcpSocketFactory::GetTypeId ()); | |
localSocket->Bind (); | |
Ptr<Socket> socalSocket = | |
Socket::CreateSocket (s0s1.Get (1), TcpSocketFactory::GetTypeId ()); | |
socalSocket->Bind (); | |
// | |
// Ejecucion de simulacion. | |
// | |
AnimationInterface anim ("prueba_tp2.xml"); | |
NS_LOG_INFO ("Ejecutando simulacion."); | |
Simulator::Stop (Seconds (10.0)); | |
Simulator::Run (); | |
Simulator::Destroy (); | |
NS_LOG_INFO ("Listo."); | |
Ptr<PacketSink> sink1 = DynamicCast<PacketSink> (sinkApps.Get (0)); | |
// std::cout << "Total Bytes Received: " << sink1->GetTotalRx () << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment