src/internet-stack/internet-stack.cc
changeset 4539 df8bf70eb486
parent 4538 3048bd67e5cf
parent 4479 ba809221f9b3
child 4540 e8a12e172432
equal deleted inserted replaced
4538:3048bd67e5cf 4539:df8bf70eb486
     1 // -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
       
     2 //
       
     3 // Copyright (c) 2006 Georgia Tech Research Corporation
       
     4 //
       
     5 // This program is free software; you can redistribute it and/or modify
       
     6 // it under the terms of the GNU General Public License version 2 as
       
     7 // published by the Free Software Foundation;
       
     8 //
       
     9 // This program is distributed in the hope that it will be useful,
       
    10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 // GNU General Public License for more details.
       
    13 //
       
    14 // You should have received a copy of the GNU General Public License
       
    15 // along with this program; if not, write to the Free Software
       
    16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    17 //
       
    18 // Author: George F. Riley<riley@ece.gatech.edu>
       
    19 //
       
    20 
       
    21 #include "ns3/net-device.h"
       
    22 #include "ns3/callback.h"
       
    23 #include "ns3/node.h"
       
    24 #include "ns3/core-config.h"
       
    25 
       
    26 #include "udp-l4-protocol.h"
       
    27 #include "tcp-l4-protocol.h"
       
    28 #include "ipv4-l3-protocol.h"
       
    29 #include "arp-l3-protocol.h"
       
    30 #include "udp-socket-factory-impl.h"
       
    31 #include "tcp-socket-factory-impl.h"
       
    32 #include "ipv4-raw-socket-factory-impl.h"
       
    33 #include "icmpv4-l4-protocol.h"
       
    34 #ifdef NETWORK_SIMULATION_CRADLE
       
    35 #include "nsc-tcp-socket-factory-impl.h"
       
    36 #include "nsc-tcp-l4-protocol.h"
       
    37 #endif
       
    38 
       
    39 namespace ns3 {
       
    40 
       
    41 static void
       
    42 AddArpStack (Ptr<Node> node)
       
    43 {
       
    44   Ptr<ArpL3Protocol> arp = CreateObject<ArpL3Protocol> ();
       
    45   arp->SetNode (node);
       
    46   node->AggregateObject (arp);
       
    47 }
       
    48 
       
    49 static void
       
    50 AddUdpStack(Ptr<Node> node)
       
    51 {
       
    52   Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol> ();
       
    53   Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol> ();
       
    54   udp->SetNode (node);
       
    55   ipv4->Insert (udp);
       
    56   node->AggregateObject (udp);
       
    57 
       
    58   Ptr<UdpSocketFactoryImpl> udpFactory = CreateObject<UdpSocketFactoryImpl> ();
       
    59   udpFactory->SetUdp (udp);
       
    60   node->AggregateObject (udpFactory);
       
    61 }
       
    62 
       
    63 static void
       
    64 AddIcmpStack (Ptr<Node> node)
       
    65 {
       
    66   Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol> ();
       
    67   Ptr<Icmpv4L4Protocol> icmp = CreateObject<Icmpv4L4Protocol> ();
       
    68   icmp->SetNode (node);
       
    69   ipv4->Insert (icmp);
       
    70   node->AggregateObject (icmp);
       
    71 
       
    72   Ptr<Ipv4RawSocketFactoryImpl> rawFactory = CreateObject<Ipv4RawSocketFactoryImpl> ();
       
    73   node->AggregateObject (rawFactory);
       
    74 }
       
    75 
       
    76 static void
       
    77 AddTcpStack(Ptr<Node> node)
       
    78 {
       
    79   Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol> ();
       
    80   Ptr<TcpL4Protocol> tcp = CreateObject<TcpL4Protocol> ();
       
    81   tcp->SetNode (node);
       
    82   ipv4->Insert (tcp);
       
    83   node->AggregateObject (tcp);
       
    84 
       
    85   Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> ();
       
    86   tcpFactory->SetTcp (tcp);
       
    87   node->AggregateObject (tcpFactory);
       
    88 }
       
    89 
       
    90 static void
       
    91 AddIpv4Stack(Ptr<Node> node)
       
    92 {
       
    93   Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
       
    94   ipv4->SetNode (node);
       
    95   node->AggregateObject (ipv4);
       
    96 }
       
    97 
       
    98 void
       
    99 AddInternetStack (Ptr<Node> node)
       
   100 {
       
   101   AddArpStack (node);
       
   102   AddIpv4Stack (node);
       
   103   AddIcmpStack (node);
       
   104   AddUdpStack (node);
       
   105   AddTcpStack (node);
       
   106 }
       
   107 
       
   108 #ifdef NETWORK_SIMULATION_CRADLE
       
   109 static void
       
   110 AddNscStack(Ptr<Node> node, const std::string &soname)
       
   111 {
       
   112   Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol> ();
       
   113   Ptr<NscTcpL4Protocol> tcp = CreateObject<NscTcpL4Protocol> ();
       
   114   tcp->SetNscLibrary(soname);
       
   115   tcp->SetNode (node);
       
   116   ipv4->Insert (tcp);
       
   117   node->AggregateObject (tcp);
       
   118 
       
   119   Ptr<NscTcpSocketFactoryImpl> tcpFactory = CreateObject<NscTcpSocketFactoryImpl> ();
       
   120   tcpFactory->SetTcp (tcp);
       
   121   node->AggregateObject (tcpFactory);
       
   122 }
       
   123 
       
   124 
       
   125 void
       
   126 AddNscInternetStack (Ptr<Node> node, const std::string &soname)
       
   127 {
       
   128   AddArpStack (node);
       
   129   AddIpv4Stack (node);
       
   130   AddIcmpStack (node);
       
   131   AddUdpStack (node);
       
   132   AddNscStack (node, soname);
       
   133 }
       
   134 #else
       
   135 void
       
   136 AddNscInternetStack (Ptr<Node> node, const std::string &soname)
       
   137 {
       
   138   NS_FATAL_ERROR ("NSC Not enabled on this platform.");
       
   139 }
       
   140 #endif
       
   141 }//namespace ns3