void DsrRreqHeaderTest::DoRun () { dsr::DsrOptionRreqHeader h; std::vector<Ipv4Address> nodeList; nodeList.push_back (Ipv4Address ("1.1.1.0")); nodeList.push_back (Ipv4Address ("1.1.1.1")); nodeList.push_back (Ipv4Address ("1.1.1.2")); h.SetTarget (Ipv4Address ("1.1.1.3")); NS_TEST_EXPECT_MSG_EQ (h.GetTarget (), Ipv4Address ("1.1.1.3"), "trivial"); h.SetNodesAddress (nodeList); NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (0), Ipv4Address ("1.1.1.0"), "trivial"); NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (1), Ipv4Address ("1.1.1.1"), "trivial"); NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (2), Ipv4Address ("1.1.1.2"), "trivial"); h.SetId (1); NS_TEST_EXPECT_MSG_EQ (h.GetId (), 1, "trivial"); Ptr<Packet> p = Create<Packet> (); dsr::DsrRoutingHeader header; header.AddDsrOption (h); p->AddHeader (header); p->RemoveAtStart (8); dsr::DsrOptionRreqHeader h2; h2.SetNumberAddress (3); uint32_t bytes = p->RemoveHeader (h2); NS_TEST_EXPECT_MSG_EQ (bytes, 20, "Total RREP is 20 bytes long"); }
IpcsClassifierRecord::IpcsClassifierRecord (void) { m_priority = 255; m_priority = 0; m_index = 0; m_tosLow = 0; m_tosHigh = 0; m_tosMask = 0; m_cid = 0; m_protocol.push_back (6); // tcp m_protocol.push_back (17); // udp AddSrcAddr (Ipv4Address ("0.0.0.0"), Ipv4Mask ("0.0.0.0")); AddDstAddr (Ipv4Address ("0.0.0.0"), Ipv4Mask ("0.0.0.0")); AddSrcPortRange (0, 65535); AddDstPortRange (0, 65535); }
Ipv4Address Ipv4AddressHelper::NewNetwork (void) { NS_LOG_FUNCTION_NOARGS (); ++m_network; m_address = m_base; return Ipv4Address (m_network << m_shift); }
std::pair<Ipv4Address, uint16_t> TcpConnection::getPeerAddressAndPort() { sockaddr_in address; int size = sizeof(address); if (getpeername(connection, reinterpret_cast<sockaddr*>(&address), &size) != 0) { throw std::runtime_error("TcpConnection::getPeerAddress, getpeername failed, result=" + std::to_string(WSAGetLastError())); } assert(size == sizeof(sockaddr_in)); return std::make_pair(Ipv4Address(htonl(address.sin_addr.S_un.S_addr)), htons(address.sin_port)); }
std::pair<Ipv4Address, uint16_t> TcpConnection::getPeerAddressAndPort() const { sockaddr_in addr; socklen_t size = sizeof(addr); if (getpeername(connection, reinterpret_cast<sockaddr*>(&addr), &size) != 0) { throw std::runtime_error("TcpConnection::getPeerAddress, getpeername failed, " + lastErrorMessage()); } assert(size == sizeof(sockaddr_in)); return std::make_pair(Ipv4Address(htonl(addr.sin_addr.s_addr)), htons(addr.sin_port)); }
void DsrAckHeaderTest::DoRun () { dsr::DsrOptionAckHeader h; h.SetRealSrc (Ipv4Address ("1.1.1.0")); NS_TEST_EXPECT_MSG_EQ (h.GetRealSrc (), Ipv4Address ("1.1.1.0"), "trivial"); h.SetRealDst (Ipv4Address ("1.1.1.1")); NS_TEST_EXPECT_MSG_EQ (h.GetRealDst (), Ipv4Address ("1.1.1.1"), "trivial"); h.SetAckId (1); NS_TEST_EXPECT_MSG_EQ (h.GetAckId (), 1, "trivial"); Ptr<Packet> p = Create<Packet> (); dsr::DsrRoutingHeader header; header.AddDsrOption (h); p->AddHeader (header); p->RemoveAtStart (8); p->AddHeader (header); dsr::DsrOptionAckHeader h2; p->RemoveAtStart (8); uint32_t bytes = p->RemoveHeader (h2); NS_TEST_EXPECT_MSG_EQ (bytes, 12, "Total RREP is 12 bytes long"); }
P2pNode::P2pNode(const P2pNodeConfig& cfg, Dispatcher& dispatcher, Logging::ILogger& log, const Crypto::Hash& genesisHash, PeerIdType peerId) : logger(log, "P2pNode:" + std::to_string(cfg.getBindPort())), m_stopRequested(false), m_cfg(cfg), m_myPeerId(peerId), m_genesisHash(genesisHash), m_genesisPayload(CORE_SYNC_DATA{ 1, genesisHash }), m_dispatcher(dispatcher), workingContextGroup(dispatcher), m_connectorTimer(dispatcher), m_queueEvent(dispatcher) { m_peerlist.init(cfg.getAllowLocalIp()); m_listener = TcpListener(m_dispatcher, Ipv4Address(m_cfg.getBindIp()), m_cfg.getBindPort()); for (auto& peer : cfg.getPeers()) { m_peerlist.append_with_peer_white(peer); } }
P2pNode::ContextPtr P2pNode::tryToConnectPeer(const NetworkAddress& address) { try { TcpConnector connector(m_dispatcher); TcpConnection tcpConnection; doWithTimeoutAndThrow(m_dispatcher, m_cfg.getConnectTimeout(), [&] { tcpConnection = connector.connect( Ipv4Address(Common::ipAddressToString(address.ip)), static_cast<uint16_t>(address.port)); }); logger(DEBUGGING) << "connection established to " << address; return ContextPtr(new P2pContext(m_dispatcher, std::move(tcpConnection), false, address, m_cfg.getTimedSyncInterval(), getGenesisPayload())); } catch (std::exception& e) { logger(DEBUGGING) << "Connection to " << address << " failed: " << e.what(); } return ContextPtr(); }
void P2pNode::tryPing(P2pContext& ctx) { if (ctx.getPeerId() == m_myPeerId || !m_peerlist.is_ip_allowed(ctx.getRemoteAddress().ip) || ctx.getPeerPort() == 0) { return; } NetworkAddress peerAddress; peerAddress.ip = ctx.getRemoteAddress().ip; peerAddress.port = ctx.getPeerPort(); try { TcpConnector connector(m_dispatcher); TcpConnection connection; doWithTimeoutAndThrow(m_dispatcher, m_cfg.getConnectTimeout(), [&] { connection = connector.connect(Ipv4Address(Common::ipAddressToString(peerAddress.ip)), static_cast<uint16_t>(peerAddress.port)); }); doWithTimeoutAndThrow(m_dispatcher, m_cfg.getHandshakeTimeout(), [&] { LevinProtocol proto(connection); COMMAND_PING::request request; COMMAND_PING::response response; proto.invoke(COMMAND_PING::ID, request, response); if (response.status == PING_OK_RESPONSE_STATUS_TEXT && response.peer_id == ctx.getPeerId()) { PeerlistEntry entry; entry.adr = peerAddress; entry.id = ctx.getPeerId(); entry.last_seen = time(nullptr); m_peerlist.append_with_peer_white(entry); } else { logger(Logging::DEBUGGING) << ctx << "back ping invoke wrong response \"" << response.status << "\" from" << peerAddress << ", expected peerId=" << ctx.getPeerId() << ", got " << response.peer_id; } }); } catch (std::exception& e) { logger(DEBUGGING) << "Ping to " << peerAddress << " failed: " << e.what(); } }
void DsrRerrHeaderTest::DoRun () { dsr::DsrOptionRerrUnreachHeader h; h.SetErrorSrc (Ipv4Address ("1.1.1.0")); NS_TEST_EXPECT_MSG_EQ (h.GetErrorSrc (), Ipv4Address ("1.1.1.0"), "trivial"); h.SetErrorDst (Ipv4Address ("1.1.1.1")); NS_TEST_EXPECT_MSG_EQ (h.GetErrorDst (), Ipv4Address ("1.1.1.1"), "trivial"); h.SetSalvage (1); NS_TEST_EXPECT_MSG_EQ (h.GetSalvage (), 1, "trivial"); h.SetUnreachNode (Ipv4Address ("1.1.1.2")); NS_TEST_EXPECT_MSG_EQ (h.GetUnreachNode (), Ipv4Address ("1.1.1.2"), "trivial"); Ptr<Packet> p = Create<Packet> (); dsr::DsrRoutingHeader header; header.AddDsrOption (h); p->AddHeader (header); p->RemoveAtStart (8); dsr::DsrOptionRerrUnreachHeader h2; uint32_t bytes = p->RemoveHeader (h2); NS_TEST_EXPECT_MSG_EQ (bytes, 20, "Total RREP is 20 bytes long"); }
void DsrSendBuffTest::DoRun () { q.SetMaxQueueLen (32); NS_TEST_EXPECT_MSG_EQ (q.GetMaxQueueLen (), 32, "trivial"); q.SetSendBufferTimeout (Seconds (10)); NS_TEST_EXPECT_MSG_EQ (q.GetSendBufferTimeout (), Seconds (10), "trivial"); Ptr<const Packet> packet = Create<Packet> (); Ipv4Address dst1 = Ipv4Address ("0.0.0.1"); dsr::SendBuffEntry e1 (packet, dst1, Seconds (1)); q.Enqueue (e1); q.Enqueue (e1); q.Enqueue (e1); NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("0.0.0.1")), true, "trivial"); NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("1.1.1.1")), false, "trivial"); NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 1, "trivial"); q.DropPacketWithDst (Ipv4Address ("0.0.0.1")); NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("0.0.0.1")), false, "trivial"); NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0, "trivial"); Ipv4Address dst2 = Ipv4Address ("0.0.0.2"); dsr::SendBuffEntry e2 (packet, dst2, Seconds (1)); q.Enqueue (e1); q.Enqueue (e2); Ptr<Packet> packet2 = Create<Packet> (); dsr::SendBuffEntry e3 (packet2, dst2, Seconds (1)); NS_TEST_EXPECT_MSG_EQ (q.Dequeue (Ipv4Address ("0.0.0.3"), e3), false, "trivial"); NS_TEST_EXPECT_MSG_EQ (q.Dequeue (Ipv4Address ("0.0.0.2"), e3), true, "trivial"); NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("0.0.0.2")), false, "trivial"); q.Enqueue (e2); q.Enqueue (e3); NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "trivial"); Ptr<Packet> packet4 = Create<Packet> (); Ipv4Address dst4 = Ipv4Address ("0.0.0.4"); dsr::SendBuffEntry e4 (packet4, dst4, Seconds (20)); q.Enqueue (e4); NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 3, "trivial"); q.DropPacketWithDst (Ipv4Address ("0.0.0.4")); NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "trivial"); CheckSizeLimit (); Simulator::Schedule (q.GetSendBufferTimeout () + Seconds (1), &DsrSendBuffTest::CheckTimeout, this); Simulator::Run (); Simulator::Destroy (); }
void DsrCacheEntryTest::DoRun () { Ptr<dsr::RouteCache> rcache = CreateObject<dsr::RouteCache> (); std::vector<Ipv4Address> ip; ip.push_back (Ipv4Address ("0.0.0.0")); ip.push_back (Ipv4Address ("0.0.0.1")); Ipv4Address dst = Ipv4Address ("0.0.0.1"); dsr::RouteCacheEntry entry (ip, dst, Seconds (1)); NS_TEST_EXPECT_MSG_EQ (entry.GetVector ().size (), 2, "trivial"); NS_TEST_EXPECT_MSG_EQ (entry.GetDestination (), Ipv4Address ("0.0.0.1"), "trivial"); NS_TEST_EXPECT_MSG_EQ (entry.GetExpireTime (), Seconds (1), "trivial"); entry.SetExpireTime (Seconds (3)); NS_TEST_EXPECT_MSG_EQ (entry.GetExpireTime (), Seconds (3), "trivial"); entry.SetDestination (Ipv4Address ("1.1.1.1")); NS_TEST_EXPECT_MSG_EQ (entry.GetDestination (), Ipv4Address ("1.1.1.1"), "trivial"); ip.push_back (Ipv4Address ("0.0.0.2")); entry.SetVector (ip); NS_TEST_EXPECT_MSG_EQ (entry.GetVector ().size (), 3, "trivial"); NS_TEST_EXPECT_MSG_EQ (rcache->AddRoute (entry), true, "trivial"); std::vector<Ipv4Address> ip2; ip2.push_back (Ipv4Address ("1.1.1.0")); ip2.push_back (Ipv4Address ("1.1.1.1")); Ipv4Address dst2 = Ipv4Address ("1.1.1.1"); dsr::RouteCacheEntry entry2 (ip2, dst2, Seconds (2)); dsr::RouteCacheEntry newEntry; NS_TEST_EXPECT_MSG_EQ (rcache->AddRoute (entry2), true, "trivial"); NS_TEST_EXPECT_MSG_EQ (rcache->LookupRoute (dst2, newEntry), true, "trivial"); NS_TEST_EXPECT_MSG_EQ (rcache->DeleteRoute (Ipv4Address ("2.2.2.2")), false, "trivial"); NS_TEST_EXPECT_MSG_EQ (rcache->DeleteRoute (Ipv4Address ("1.1.1.1")), true, "trivial"); NS_TEST_EXPECT_MSG_EQ (rcache->DeleteRoute (Ipv4Address ("1.1.1.1")), false, "trivial"); }
void LenaPssFfMacSchedulerTestCase2::DoRun (void) { if (!m_errorModelEnabled) { Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false)); Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false)); } Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true)); Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> (); lteHelper->SetEpcHelper (epcHelper); Ptr<Node> pgw = epcHelper->GetPgwNode (); // Create a single RemoteHost NodeContainer remoteHostContainer; remoteHostContainer.Create (1); Ptr<Node> remoteHost = remoteHostContainer.Get (0); InternetStackHelper internet; internet.Install (remoteHostContainer); // Create the Internet PointToPointHelper p2ph; p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s"))); p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500)); p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.001))); NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost); Ipv4AddressHelper ipv4h; ipv4h.SetBase ("1.0.0.0", "255.0.0.0"); Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices); // interface 0 is localhost, 1 is the p2p device Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1); Ipv4StaticRoutingHelper ipv4RoutingHelper; Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ()); remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1); // LogComponentDisableAll (LOG_LEVEL_ALL); //LogComponentEnable ("LenaTestPssFfMacCheduler", LOG_LEVEL_ALL); lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel")); // Create Nodes: eNodeB and UE NodeContainer enbNodes; NodeContainer ueNodes; enbNodes.Create (1); ueNodes.Create (m_nUser); // Install Mobility Model MobilityHelper mobility; mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (enbNodes); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (ueNodes); // Create Devices and install them in the Nodes (eNB and UE) NetDeviceContainer enbDevs; NetDeviceContainer ueDevs; lteHelper->SetSchedulerType ("ns3::PssFfMacScheduler"); enbDevs = lteHelper->InstallEnbDevice (enbNodes); ueDevs = lteHelper->InstallUeDevice (ueNodes); Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> (); Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy (); enbPhy->SetAttribute ("TxPower", DoubleValue (30.0)); enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0)); // Set UEs' position and power for (int i = 0; i < m_nUser; i++) { Ptr<ConstantPositionMobilityModel> mm = ueNodes.Get (i)->GetObject<ConstantPositionMobilityModel> (); mm->SetPosition (Vector (m_dist.at (i), 0.0, 0.0)); Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> (); Ptr<LteUePhy> uePhy = lteUeDev->GetPhy (); uePhy->SetAttribute ("TxPower", DoubleValue (23.0)); uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0)); } // Install the IP stack on the UEs internet.Install (ueNodes); Ipv4InterfaceContainer ueIpIface; ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs)); // Assign IP address to UEs for (uint32_t u = 0; u < ueNodes.GetN (); ++u) { Ptr<Node> ueNode = ueNodes.Get (u); // Set the default gateway for the UE Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ()); ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1); } // Attach a UE to a eNB lteHelper->Attach (ueDevs, enbDevs.Get (0)); // Activate an EPS bearer on all UEs for (uint32_t u = 0; u < ueNodes.GetN (); ++u) { Ptr<NetDevice> ueDevice = ueDevs.Get (u); GbrQosInformation qos; qos.gbrDl = (m_packetSize.at (u) + 32) * (1000 / m_interval) * 8; // bit/s, considering IP, UDP, RLC, PDCP header size qos.gbrUl = (m_packetSize.at (u) + 32) * (1000 / m_interval) * 8; qos.mbrDl = qos.gbrDl; qos.mbrUl = qos.gbrUl; enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; EpsBearer bearer (q, qos); lteHelper->ActivateDedicatedEpsBearer (ueDevice, bearer, EpcTft::Default ()); } // Install downlind and uplink applications uint16_t dlPort = 1234; uint16_t ulPort = 2000; PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort)); PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort)); ApplicationContainer clientApps; ApplicationContainer serverApps; for (uint32_t u = 0; u < ueNodes.GetN (); ++u) { ++ulPort; serverApps.Add (dlPacketSinkHelper.Install (ueNodes.Get (u))); // receive packets from remotehost serverApps.Add (ulPacketSinkHelper.Install (remoteHost)); // receive packets from UEs UdpClientHelper dlClient (ueIpIface.GetAddress (u), dlPort); // uplink packets generator dlClient.SetAttribute ("Interval", TimeValue (MilliSeconds (m_interval))); dlClient.SetAttribute ("MaxPackets", UintegerValue (1000000)); dlClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize.at (u))); UdpClientHelper ulClient (remoteHostAddr, ulPort); // downlink packets generator ulClient.SetAttribute ("Interval", TimeValue (MilliSeconds (m_interval))); ulClient.SetAttribute ("MaxPackets", UintegerValue (1000000)); ulClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize.at (u))); clientApps.Add (dlClient.Install (remoteHost)); clientApps.Add (ulClient.Install (ueNodes.Get (u))); } serverApps.Start (Seconds (0.030)); clientApps.Start (Seconds (0.030)); double statsStartTime = 0.04; // need to allow for RRC connection establishment + SRS double statsDuration = 0.5; double tolerance = 0.1; Simulator::Stop (Seconds (statsStartTime + statsDuration - 0.0001)); lteHelper->EnableRlcTraces (); Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats (); rlcStats->SetAttribute ("StartTime", TimeValue (Seconds (statsStartTime))); rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (statsDuration))); Simulator::Run (); /** * Check that the downlink assignation is done in a "token bank fair queue" manner */ NS_LOG_INFO ("DL - Test with " << m_nUser << " user(s)"); std::vector <uint64_t> dlDataRxed; for (int i = 0; i < m_nUser; i++) { // get the imsi uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi (); // get the lcId uint8_t lcId = 4; dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId)); NS_LOG_INFO ("\tUser " << i << " dist " << m_dist.at (i) << " imsi " << imsi << " bytes rxed " << (double)dlDataRxed.at (i) << " thr " << (double)dlDataRxed.at (i) / statsDuration << " ref " << m_estThrPssDl.at (i)); } for (int i = 0; i < m_nUser; i++) { NS_TEST_ASSERT_MSG_EQ_TOL ((double)dlDataRxed.at (i) / statsDuration, m_estThrPssDl.at (i), m_estThrPssDl.at (i) * tolerance, " Unfair Throughput!"); } Simulator::Destroy (); }
void EpcS1uDlTestCase::DoRun () { Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> (); Ptr<Node> pgw = epcHelper->GetPgwNode (); // allow jumbo packets Config::SetDefault ("ns3::CsmaNetDevice::Mtu", UintegerValue (30000)); Config::SetDefault ("ns3::PointToPointNetDevice::Mtu", UintegerValue (30000)); epcHelper->SetAttribute ("S1uLinkMtu", UintegerValue (30000)); // Create a single RemoteHost NodeContainer remoteHostContainer; remoteHostContainer.Create (1); Ptr<Node> remoteHost = remoteHostContainer.Get (0); InternetStackHelper internet; internet.Install (remoteHostContainer); // Create the internet PointToPointHelper p2ph; p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s"))); NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost); Ipv4AddressHelper ipv4h; ipv4h.SetBase ("1.0.0.0", "255.0.0.0"); ipv4h.Assign (internetDevices); // setup default gateway for the remote hosts Ipv4StaticRoutingHelper ipv4RoutingHelper; Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ()); // hardcoded UE addresses for now remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.255.255.0"), 1); NodeContainer enbs; uint16_t cellIdCounter = 0; for (std::vector<EnbDlTestData>::iterator enbit = m_enbDlTestData.begin (); enbit < m_enbDlTestData.end (); ++enbit) { Ptr<Node> enb = CreateObject<Node> (); enbs.Add (enb); // we test EPC without LTE, hence we use: // 1) a CSMA network to simulate the cell // 2) a raw socket opened on the CSMA device to simulate the LTE socket uint16_t cellId = ++cellIdCounter; NodeContainer ues; ues.Create (enbit->ues.size ()); NodeContainer cell; cell.Add (ues); cell.Add (enb); CsmaHelper csmaCell; NetDeviceContainer cellDevices = csmaCell.Install (cell); // the eNB's CSMA NetDevice acting as an LTE NetDevice. Ptr<NetDevice> enbDevice = cellDevices.Get (cellDevices.GetN () - 1); // Note that the EpcEnbApplication won't care of the actual NetDevice type epcHelper->AddEnb (enb, enbDevice, cellId); // Plug test RRC entity Ptr<EpcEnbApplication> enbApp = enb->GetApplication (0)->GetObject<EpcEnbApplication> (); NS_ASSERT_MSG (enbApp != 0, "cannot retrieve EpcEnbApplication"); Ptr<EpcTestRrc> rrc = CreateObject<EpcTestRrc> (); rrc->SetS1SapProvider (enbApp->GetS1SapProvider ()); enbApp->SetS1SapUser (rrc->GetS1SapUser ()); // we install the IP stack on UEs only InternetStackHelper internet; internet.Install (ues); // assign IP address to UEs, and install applications for (uint32_t u = 0; u < ues.GetN (); ++u) { Ptr<NetDevice> ueLteDevice = cellDevices.Get (u); Ipv4InterfaceContainer ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevice)); Ptr<Node> ue = ues.Get (u); // disable IP Forwarding on the UE. This is because we use // CSMA broadcast MAC addresses for this test. The problem // won't happen with a LteUeNetDevice. ue->GetObject<Ipv4> ()->SetAttribute ("IpForward", BooleanValue (false)); uint16_t port = 1234; PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port)); ApplicationContainer apps = packetSinkHelper.Install (ue); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); enbit->ues[u].serverApp = apps.Get (0)->GetObject<PacketSink> (); Time interPacketInterval = Seconds (0.01); UdpEchoClientHelper client (ueIpIface.GetAddress (0), port); client.SetAttribute ("MaxPackets", UintegerValue (enbit->ues[u].numPkts)); client.SetAttribute ("Interval", TimeValue (interPacketInterval)); client.SetAttribute ("PacketSize", UintegerValue (enbit->ues[u].pktSize)); apps = client.Install (remoteHost); apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); enbit->ues[u].clientApp = apps.Get (0); uint64_t imsi = u+1; epcHelper->AddUe (ueLteDevice, imsi); epcHelper->ActivateEpsBearer (ueLteDevice, imsi, EpcTft::Default (), EpsBearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT)); enbApp->GetS1SapProvider ()->InitialUeMessage (imsi, (uint16_t) imsi); } } Simulator::Run (); for (std::vector<EnbDlTestData>::iterator enbit = m_enbDlTestData.begin (); enbit < m_enbDlTestData.end (); ++enbit) { for (std::vector<UeDlTestData>::iterator ueit = enbit->ues.begin (); ueit < enbit->ues.end (); ++ueit) { NS_TEST_ASSERT_MSG_EQ (ueit->serverApp->GetTotalRx (), (ueit->numPkts) * (ueit->pktSize), "wrong total received bytes"); } } Simulator::Destroy (); }