//----------------------------------------------------------------------------------------------------------------------------------------------------- VOID FrameBuffer::Attach( DWORD Buffer, Ptr<RenderBuffer> pRenderBuffer ) { pRenderBuffer->Bind(); m_pContext->glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, Buffer, GL_RENDERBUFFER_EXT, pRenderBuffer->Id() ); GLenum status = m_pContext->glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT ); }
void MyApp::StartApplication (void) { m_running = true; m_packetsSent = 0; m_socket->Bind (); m_socket->Connect (m_peer); SendPacket (); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- VOID Context::SetTexture( UINT TextureUnit, Ptr<Texture> pTexture ) { if (m_pCurrentTexture[TextureUnit] == pTexture) return; m_pCurrentTexture[TextureUnit] = pTexture; //glActiveTextureARB(GL_TEXTURE0_ARB); pTexture->Bind(); }
void Ipv6FragmentationTest::StartServer (Ptr<Node> ServerNode) { if (m_socketServer == 0) { TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); m_socketServer = Socket::CreateSocket (ServerNode, tid); Inet6SocketAddress local = Inet6SocketAddress (Ipv6Address ("2001::1"), 9); m_socketServer->Bind (local); Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socketServer); } m_socketServer->SetRecvCallback (MakeCallback (&Ipv6FragmentationTest::HandleReadServer, this)); }
void Ipv6FragmentationTest::StartClient (Ptr<Node> ClientNode) { if (m_socketClient == 0) { TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); m_socketClient = Socket::CreateSocket (ClientNode, tid); m_socketClient->Bind (Inet6SocketAddress (Ipv6Address::GetAny (), 9)); m_socketClient->Connect (Inet6SocketAddress (Ipv6Address ("2001::1"), 9)); CallbackValue cbValue = MakeCallback (&Ipv6FragmentationTest::HandleReadIcmpClient, this); m_socketClient->SetAttribute ("IcmpCallback6", cbValue); } m_socketClient->SetRecvCallback (MakeCallback (&Ipv6FragmentationTest::HandleReadClient, this)); }
int main (int argc, char *argv[]) { std::string phyMode ("DsssRate1Mbps"); double rss = -80; // -dBm uint32_t packetSize = 1000; // bytes uint32_t numPackets = 1; double interval = 1.0; // seconds bool verbose = false; CommandLine cmd; cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode); cmd.AddValue ("rss", "received signal strength", rss); cmd.AddValue ("packetSize", "size of application packet sent", packetSize); cmd.AddValue ("numPackets", "number of packets generated", numPackets); cmd.AddValue ("interval", "interval (seconds) between packets", interval); cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose); cmd.Parse (argc, argv); // Convert to time object Time interPacketInterval = Seconds (interval); // disable fragmentation for frames below 2200 bytes Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); // turn off RTS/CTS for frames below 2200 bytes Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); // Fix non-unicast data rate to be the same as that of unicast Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (phyMode)); NodeContainer c; c.Create (2); // The below set of helpers will help us to put together the wifi NICs we want WifiHelper wifi; if (verbose) { wifi.EnableLogComponents (); // Turn on all Wifi logging } wifi.SetStandard (WIFI_PHY_STANDARD_80211b); YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); // This is one parameter that matters when using FixedRssLossModel // set it to zero; otherwise, gain will be added wifiPhy.Set ("RxGain", DoubleValue (0) ); // ns-3 supports RadioTap and Prism tracing extensions for 802.11b wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); YansWifiChannelHelper wifiChannel; wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); // The below FixedRssLossModel will cause the rss to be fixed regardless // of the distance between the two stations, and the transmit power wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (rss)); wifiPhy.SetChannel (wifiChannel.Create ()); // Add a non-QoS upper mac, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",StringValue (phyMode), "ControlMode",StringValue (phyMode)); // Set it to adhoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); // Note that with FixedRssLossModel, the positions below are not // used for received signal strength. MobilityHelper mobility; Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); positionAlloc->Add (Vector (0.0, 0.0, 0.0)); positionAlloc->Add (Vector (5.0, 0.0, 0.0)); mobility.SetPositionAllocator (positionAlloc); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (c); InternetStackHelper internet; internet.Install (c); Ipv4AddressHelper ipv4; NS_LOG_INFO ("Assign IP Addresses."); ipv4.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer i = ipv4.Assign (devices); TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid); InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80); recvSink->Bind (local); recvSink->SetRecvCallback (MakeCallback (&ReceivePacket)); Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid); InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80); source->SetAllowBroadcast (true); source->Connect (remote); // Tracing wifiPhy.EnablePcap ("wifi-simple-adhoc", devices); // Output what we are doing NS_LOG_UNCOND ("Testing " << numPackets << " packets sent with receiver rss " << rss ); Simulator::ScheduleWithContext (source->GetNode ()->GetId (), Seconds (1.0), &GenerateTraffic, source, packetSize, numPackets, interPacketInterval); Simulator::Run (); Simulator::Destroy (); return 0; }
//----------------------------------------------------------------------------------------------------------------------------------------------------- VOID FrameBuffer::Attach( DWORD Buffer, Ptr<Texture> pTexture ) { pTexture->Bind(); m_pContext->glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, Buffer, GL_TEXTURE_2D, pTexture->Id(), 0 ); }
int main (int argc, char *argv[]) { uint32_t packetSize = 1000; // Application bytes per packet double interval = 1.0; // Time between events uint32_t generationSize = 3; // RLNC generation size double errorRateEncoderRecoder = 0.4; // Error rate for encoder-recoder link double errorRateRecoderDecoder = 0.2; // Error rate for recoder-decoder link bool recodingFlag = true; // Flag to control recoding Time interPacketInterval = Seconds (interval); CommandLine cmd; cmd.AddValue ("packetSize", "Size of application packet sent", packetSize); cmd.AddValue ("interval", "Interval (seconds) between packets", interval); cmd.AddValue ("generationSize", "Set the generation size to use", generationSize); cmd.AddValue ("errorRateEncoderRecoder", "Packet erasure rate for the encoder-recoder link", errorRateEncoderRecoder); cmd.AddValue ("errorRateRecoderDecoder", "Packet erasure rate for the recoder-decoder link", errorRateRecoderDecoder); cmd.AddValue ("recodingFlag", "Enable packet recoding", recodingFlag); cmd.Parse (argc, argv); Time::SetResolution (Time::NS); // Set the basic helper for a single link PointToPointHelper pointToPoint; // Create node containers NodeContainer nodes; nodes.Create (3); NodeContainer encoderRecoder = NodeContainer (nodes.Get (0), nodes.Get (1)); NodeContainer recoderDecoder = NodeContainer (nodes.Get (1), nodes.Get (2)); // Internet stack for the nodes InternetStackHelper internet; internet.Install (nodes); // Create net device containers NetDeviceContainer encoderRecoderDevs = pointToPoint.Install (encoderRecoder); NetDeviceContainer recoderDecoderDevs = pointToPoint.Install (recoderDecoder); NetDeviceContainer devices = NetDeviceContainer (encoderRecoderDevs, recoderDecoderDevs); // Set IP addresses Ipv4AddressHelper ipv4("10.1.1.0", "255.255.255.0"); ipv4.Assign (devices); // Turn on global static routing so we can actually be routed across the hops Ipv4GlobalRoutingHelper::PopulateRoutingTables (); // Do pcap tracing on all point-to-point devices on all nodes. File naming // convention is: multihop-[NODE_NUMBER]-[DEVICE_NUMBER].pcap pointToPoint.EnablePcapAll ("multihop"); // Set error model for the net devices Config::SetDefault ("ns3::RateErrorModel::ErrorUnit", StringValue ("ERROR_UNIT_PACKET")); Ptr<RateErrorModel> errorEncoderRecoder = CreateObject<RateErrorModel> (); errorEncoderRecoder->SetAttribute ("ErrorRate", DoubleValue (errorRateEncoderRecoder)); devices.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (errorEncoderRecoder)); Ptr<RateErrorModel> errorRecoderDecoder = CreateObject<RateErrorModel> (); errorRecoderDecoder->SetAttribute ("ErrorRate", DoubleValue (errorRateRecoderDecoder)); devices.Get (3)->SetAttribute ("ReceiveErrorModel", PointerValue (errorRecoderDecoder)); errorEncoderRecoder->Enable (); errorRecoderDecoder->Enable (); // Creation of RLNC encoder and decoder objects rlnc_encoder::factory encoder_factory(generationSize, packetSize); rlnc_decoder::factory decoder_factory(generationSize, packetSize); // The member build function creates differents instances of each object KodoSimulation kodoSimulator(encoder_factory.build(), decoder_factory.build(), decoder_factory.build(), recodingFlag); // Setting up application sockets for recoder and decoder uint16_t port = 80; TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); // Get node Ipv4 addresses Ipv4Address recoderAddress = nodes.Get (1)->GetObject<Ipv4>()-> GetAddress(1,0).GetLocal(); Ipv4Address decoderAddress = nodes.Get (2)->GetObject<Ipv4>()-> GetAddress(1,0).GetLocal(); // Socket connection addresses InetSocketAddress recoderSocketAddress = InetSocketAddress (recoderAddress, port); InetSocketAddress decoderSocketAddress = InetSocketAddress (decoderAddress, port); // Socket bind address InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny(), port); // Encoder Ptr<Socket> encoderSocket = Socket::CreateSocket (nodes.Get (0), tid); encoderSocket->Connect (recoderSocketAddress); // Recoder Ptr<Socket> recoderSocket = Socket::CreateSocket (nodes.Get (1), tid); recoderSocket->Bind(local); recoderSocket->Connect (decoderSocketAddress); recoderSocket-> SetRecvCallback (MakeCallback (&KodoSimulation::ReceivePacketRecoder, &kodoSimulator)); // Decoder Ptr<Socket> decoderSocket = Socket::CreateSocket (nodes.Get (2), tid); decoderSocket->Bind(local); decoderSocket-> SetRecvCallback (MakeCallback (&KodoSimulation::ReceivePacketDecoder, &kodoSimulator)); // Simulation setup // Schedule encoding process Simulator::ScheduleWithContext (encoderSocket->GetNode ()->GetId (), Seconds (1.0), &KodoSimulation::SendPacketEncoder, &kodoSimulator, encoderSocket, interPacketInterval); Simulator::ScheduleWithContext (recoderSocket->GetNode ()->GetId (), Seconds (1.5), &KodoSimulation::SendPacketRecoder, &kodoSimulator, recoderSocket, interPacketInterval); Simulator::Run (); Simulator::Destroy (); return 0; }
void SixlowpanHc1ImplTest::DoRun (void) { // Create topology // Receiver Node Ptr<Node> rxNode = CreateObject<Node> (); AddInternetStack6 (rxNode); Ptr<SimpleNetDevice> rxDev; { // first interface rxDev = CreateObject<SimpleNetDevice> (); rxDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ())); rxNode->AddDevice (rxDev); Ptr<SixLowPanNetDevice> rxSix = CreateObject<SixLowPanNetDevice> (); rxSix->SetAttribute ("ForceEtherType", BooleanValue (true) ); rxSix->SetAttribute ("Rfc6282", BooleanValue (false) ); rxNode->AddDevice (rxSix); rxSix->SetNetDevice (rxDev); Ptr<Ipv6> ipv6 = rxNode->GetObject<Ipv6> (); ipv6->AddInterface (rxDev); uint32_t netdev_idx = ipv6->AddInterface (rxSix); Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100::1"), Ipv6Prefix (64)); ipv6->AddAddress (netdev_idx, ipv6Addr); ipv6->SetUp (netdev_idx); } // Sender Node Ptr<Node> txNode = CreateObject<Node> (); AddInternetStack6 (txNode); Ptr<SimpleNetDevice> txDev; { txDev = CreateObject<SimpleNetDevice> (); txDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ())); txNode->AddDevice (txDev); Ptr<SixLowPanNetDevice> txSix = CreateObject<SixLowPanNetDevice> (); txSix->SetAttribute ("ForceEtherType", BooleanValue (true) ); txSix->SetAttribute ("Rfc6282", BooleanValue (false) ); txNode->AddDevice (txSix); txSix->SetNetDevice (txDev); Ptr<Ipv6> ipv6 = txNode->GetObject<Ipv6> (); ipv6->AddInterface (txDev); uint32_t netdev_idx = ipv6->AddInterface (txSix); Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100::2"), Ipv6Prefix (64)); ipv6->AddAddress (netdev_idx, ipv6Addr); ipv6->SetUp (netdev_idx); } // link the two nodes Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> (); rxDev->SetChannel (channel1); txDev->SetChannel (channel1); // Create the UDP sockets Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> (); Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket (); NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (Inet6SocketAddress (Ipv6Address ("2001:0100::1"), 1234)), 0, "trivial"); rxSocket->SetRecvCallback (MakeCallback (&SixlowpanHc1ImplTest::ReceivePkt, this)); Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> (); Ptr<Socket> txSocket = txSocketFactory->CreateSocket (); txSocket->SetAllowBroadcast (true); // ------ Now the tests ------------ // Unicast test SendData (txSocket, "2001:0100::1"); NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 180, "trivial"); uint8_t rxBuffer [180]; uint8_t txBuffer [180] = "\"Can you tell me where my country lies?\" \\ said the unifaun to his true love's eyes. \\ \"It lies with me!\" cried the Queen of Maybe \\ - for her merchandise, he traded in his prize."; m_receivedPacket->CopyData (rxBuffer, 180); NS_TEST_EXPECT_MSG_EQ (memcmp (rxBuffer, txBuffer, 180), 0, "trivial"); m_receivedPacket->RemoveAllByteTags (); Simulator::Destroy (); }
int main (int argc, char *argv[]) { std::string phyMode ("DsssRate1Mbps"); double distance = 500; // m uint32_t packetSize = 1000; // bytes uint32_t numPackets = 1; uint32_t numNodes = 25; // by default, 5x5 uint32_t sinkNode = 0; uint32_t sourceNode = 24; double interval = 1.0; // seconds bool verbose = false; bool tracing = false; CommandLine cmd; cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode); cmd.AddValue ("distance", "distance (m)", distance); cmd.AddValue ("packetSize", "size of application packet sent", packetSize); cmd.AddValue ("numPackets", "number of packets generated", numPackets); cmd.AddValue ("interval", "interval (seconds) between packets", interval); cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose); cmd.AddValue ("tracing", "turn on ascii and pcap tracing", tracing); cmd.AddValue ("numNodes", "number of nodes", numNodes); cmd.AddValue ("sinkNode", "Receiver node number", sinkNode); cmd.AddValue ("sourceNode", "Sender node number", sourceNode); cmd.Parse (argc, argv); // Convert to time object Time interPacketInterval = Seconds (interval); // disable fragmentation for frames below 2200 bytes Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); // turn off RTS/CTS for frames below 2200 bytes Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); // Fix non-unicast data rate to be the same as that of unicast Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (phyMode)); NodeContainer c; c.Create (numNodes); // The below set of helpers will help us to put together the wifi NICs we want WifiHelper wifi; if (verbose) { wifi.EnableLogComponents (); // Turn on all Wifi logging } YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); // set it to zero; otherwise, gain will be added wifiPhy.Set ("RxGain", DoubleValue (-10) ); // ns-3 supports RadioTap and Prism tracing extensions for 802.11b wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); YansWifiChannelHelper wifiChannel; wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel"); wifiPhy.SetChannel (wifiChannel.Create ()); // Add a non-QoS upper mac, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetStandard (WIFI_PHY_STANDARD_80211b); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",StringValue (phyMode), "ControlMode",StringValue (phyMode)); // Set it to adhoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); MobilityHelper mobility; mobility.SetPositionAllocator ("ns3::GridPositionAllocator", "MinX", DoubleValue (0.0), "MinY", DoubleValue (0.0), "DeltaX", DoubleValue (distance), "DeltaY", DoubleValue (distance), "GridWidth", UintegerValue (5), "LayoutType", StringValue ("RowFirst")); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (c); // Enable OLSR OlsrHelper olsr; Ipv4StaticRoutingHelper staticRouting; Ipv4ListRoutingHelper list; list.Add (staticRouting, 0); list.Add (olsr, 10); InternetStackHelper internet; internet.SetRoutingHelper (list); // has effect on the next Install () internet.Install (c); Ipv4AddressHelper ipv4; NS_LOG_INFO ("Assign IP Addresses."); ipv4.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer i = ipv4.Assign (devices); TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (sinkNode), tid); InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80); recvSink->Bind (local); recvSink->SetRecvCallback (MakeCallback (&ReceivePacket)); Ptr<Socket> source = Socket::CreateSocket (c.Get (sourceNode), tid); InetSocketAddress remote = InetSocketAddress (i.GetAddress (sinkNode, 0), 80); source->Connect (remote); if (tracing == true) { AsciiTraceHelper ascii; wifiPhy.EnableAsciiAll (ascii.CreateFileStream ("wifi-simple-adhoc-grid.tr")); wifiPhy.EnablePcap ("wifi-simple-adhoc-grid", devices); // Trace routing tables Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("wifi-simple-adhoc-grid.routes", std::ios::out); olsr.PrintRoutingTableAllEvery (Seconds (2), routingStream); // To do-- enable an IP-level trace that shows forwarding events only } // Give OLSR time to converge-- 30 seconds perhaps Simulator::Schedule (Seconds (30.0), &GenerateTraffic, source, packetSize, numPackets, interPacketInterval); // Output what we are doing NS_LOG_UNCOND ("Testing from node " << sourceNode << " to " << sinkNode << " with grid distance " << distance); Simulator::Stop (Seconds (32.0)); Simulator::Run (); Simulator::Destroy (); return 0; }