src/devices/csma/csma-ipv4-topology.cc
changeset 1430 25fa26a6533e
parent 1272 67a2ba1143e0
child 1432 3aef7d7a71c2
equal deleted inserted replaced
1429:31cb0668defd 1430:25fa26a6533e
    34 
    34 
    35 namespace ns3 {
    35 namespace ns3 {
    36 
    36 
    37 uint32_t
    37 uint32_t
    38 CsmaIpv4Topology::AddIpv4CsmaNode(Ptr<Node> n1,
    38 CsmaIpv4Topology::AddIpv4CsmaNode(Ptr<Node> n1,
    39                                       Ptr<CsmaChannel> ch,
    39                                   Ptr<CsmaChannel> ch,
    40                                       Eui48Address addr)
    40                                   Eui48Address addr)
    41 {
    41 {
    42   Ptr<Queue> q = Queue::CreateDefault ();
    42   Ptr<Queue> q = Queue::CreateDefault ();
    43 
    43 
    44   // assume full-duplex
    44   // assume full-duplex
    45   Ptr<CsmaNetDevice> nd0 = Create<CsmaNetDevice> (n1, addr, 
    45   Ptr<CsmaNetDevice> nd0 = Create<CsmaNetDevice> (n1, addr, 
    46                                                       ns3::CsmaNetDevice::IP_ARP,
    46                                                   ns3::CsmaNetDevice::IP_ARP,
    47                                                       true, true);
    47                                                   true, true);
    48   nd0->AddQueue(q);
    48   nd0->AddQueue(q);
    49   nd0->Attach (ch);
    49   nd0->Attach (ch);
    50   return nd0->GetIfIndex ();
    50   return nd0->GetIfIndex ();
    51 }
    51 }
    52 
    52 
    53 
    53 
    54 void
    54 void
    55 CsmaIpv4Topology::AddIpv4LlcCsmaNode(Ptr<Node> n1,
    55 CsmaIpv4Topology::AddIpv4LlcCsmaNode(Ptr<Node> n1,
    56                                          Ptr<CsmaChannel> ch,
    56                                      Ptr<CsmaChannel> ch,
    57                                          Eui48Address addr)
    57                                      Eui48Address addr)
    58 {
    58 {
    59   Ptr<Queue> q = Queue::CreateDefault ();
    59   Ptr<Queue> q = Queue::CreateDefault ();
    60 
    60 
    61   Ptr<CsmaNetDevice> nd0 = Create<CsmaNetDevice> (n1, addr,
    61   Ptr<CsmaNetDevice> nd0 = Create<CsmaNetDevice> (n1, addr,
    62                                                       ns3::CsmaNetDevice::LLC,
    62                                                   ns3::CsmaNetDevice::LLC,
    63                                                       true, false);
    63                                                   true, false);
    64   nd0->AddQueue(q);
    64   nd0->AddQueue(q);
    65   nd0->Attach (ch);
    65   nd0->Attach (ch);
    66 
    66 
    67   Ptr<CsmaNetDevice> nd1 = Create<CsmaNetDevice> (n1, addr,
    67   Ptr<CsmaNetDevice> nd1 = Create<CsmaNetDevice> (n1, addr,
    68                                                       ns3::CsmaNetDevice::LLC,
    68                                                   ns3::CsmaNetDevice::LLC,
    69                                                       false, true);
    69                                                   false, true);
    70   nd1->AddQueue(q);
    70   nd1->AddQueue(q);
    71   nd1->Attach (ch);
    71   nd1->Attach (ch);
    72 }
    72 }
    73 
    73 
    74 void
    74 void
    75 CsmaIpv4Topology::AddIpv4RawCsmaNode(Ptr<Node> n1,
    75 CsmaIpv4Topology::AddIpv4RawCsmaNode(Ptr<Node> n1,
    76                                          Ptr<CsmaChannel> ch,
    76                                      Ptr<CsmaChannel> ch,
    77                                          Eui48Address addr)
    77                                      Eui48Address addr)
    78 {
    78 {
    79   Ptr<Queue> q = Queue::CreateDefault ();
    79   Ptr<Queue> q = Queue::CreateDefault ();
    80 
    80 
    81   Ptr<CsmaNetDevice> nd0 = Create<CsmaNetDevice> (n1, addr,
    81   Ptr<CsmaNetDevice> nd0 = Create<CsmaNetDevice> (n1, addr,
    82                                                       ns3::CsmaNetDevice::RAW,
    82                                                   ns3::CsmaNetDevice::RAW,
    83                                                       true, false);
    83                                                   true, false);
    84   nd0->AddQueue(q);
    84   nd0->AddQueue(q);
    85   nd0->Attach (ch);
    85   nd0->Attach (ch);
    86 
    86 
    87   Ptr<CsmaNetDevice> nd1 = Create<CsmaNetDevice> (n1, addr,
    87   Ptr<CsmaNetDevice> nd1 = Create<CsmaNetDevice> (n1, addr,
    88                                                       ns3::CsmaNetDevice::RAW,
    88                                                   ns3::CsmaNetDevice::RAW,
    89                                                       false, true);
    89                                                   false, true);
    90   nd1->AddQueue(q);
    90   nd1->AddQueue(q);
    91   nd1->Attach (ch);
    91   nd1->Attach (ch);
    92 }
    92 }
    93 
    93 
    94 void
    94 void
    95 CsmaIpv4Topology::AddIpv4Address(Ptr<Node> n1,
    95 CsmaIpv4Topology::AddIpv4Address(Ptr<Node> n1,
    96                                        int ndNum,
    96                                  int ndNum,
    97                                        const Ipv4Address& addr1,
    97                                  const Ipv4Address& addr1,
    98                                        const Ipv4Mask& netmask1)
    98                                  const Ipv4Mask& netmask1)
    99 {
    99 {
   100 
       
   101   // Duplex link is assumed to be subnetted as a /30
   100   // Duplex link is assumed to be subnetted as a /30
   102   // May run this unnumbered in the future?
   101   // May run this unnumbered in the future?
   103   Ipv4Mask netmask(netmask1);
   102   Ipv4Mask netmask(netmask1);
   104 
   103 
   105   Ptr<NetDevice> nd1 = n1->GetDevice(ndNum);
   104   Ptr<NetDevice> nd1 = n1->GetDevice(ndNum);
   108   uint32_t index1 = ip1->AddInterface (nd1);
   107   uint32_t index1 = ip1->AddInterface (nd1);
   109 
   108 
   110   ip1->SetAddress (index1, addr1);
   109   ip1->SetAddress (index1, addr1);
   111   ip1->SetNetworkMask (index1, netmask);
   110   ip1->SetNetworkMask (index1, netmask);
   112   ip1->SetUp (index1);
   111   ip1->SetUp (index1);
   113 
       
   114 }
   112 }
   115 
   113 
   116 void
   114 void
   117 CsmaIpv4Topology::AddIpv4Routes (
   115 CsmaIpv4Topology::AddIpv4Routes (
   118   Ptr<NetDevice> nd1, Ptr<NetDevice> nd2)
   116   Ptr<NetDevice> nd1, Ptr<NetDevice> nd2)
   131         {
   129         {
   132           index1 = i;
   130           index1 = i;
   133           found = true;
   131           found = true;
   134         }
   132         }
   135     }
   133     }
   136   NS_ASSERT(found);
   134   NS_ASSERT (found);
   137 
   135 
   138   uint32_t index2 = 0;
   136   uint32_t index2 = 0;
   139   found = false;
   137   found = false;
   140   for (uint32_t i = 0; i < ip2->GetNInterfaces (); i++)
   138   for (uint32_t i = 0; i < ip2->GetNInterfaces (); i++)
   141     {
   139     {
   143         {
   141         {
   144           index2 = i;
   142           index2 = i;
   145           found = true;
   143           found = true;
   146         }
   144         }
   147     }
   145     }
   148   NS_ASSERT(found);
   146   NS_ASSERT (found);
   149 
   147 
   150   ip1->AddHostRouteTo (ip2-> GetAddress (index2), index1);
   148   ip1->AddHostRouteTo (ip2-> GetAddress (index2), index1);
   151   ip2->AddHostRouteTo (ip1-> GetAddress (index1), index2); 
   149   ip2->AddHostRouteTo (ip1-> GetAddress (index1), index2); 
   152 }
   150 }
   153 
   151