Exemplo n.º 1
0
    def testAttributes(self):
        ##
        ## Yes, I know, the GetAttribute interface for Python is
        ## horrible, we should fix this soon, I hope.
        ##
        queue = ns3.DropTailQueue()

        queue.SetAttribute("MaxPackets", ns3.UintegerValue(123456))

        limit = ns3.UintegerValue()
        queue.GetAttribute("MaxPackets", limit)
        self.assertEqual(limit.Get(), 123456)

        ## -- object pointer values
        mobility = ns3.RandomWaypointMobilityModel()
        ptr = ns3.PointerValue()
        mobility.GetAttribute("PositionAllocator", ptr)
        self.assertEqual(ptr.GetObject(), None)

        pos = ns3.ListPositionAllocator()
        mobility.SetAttribute("PositionAllocator", ns3.PointerValue(pos))

        ptr = ns3.PointerValue()
        mobility.GetAttribute("PositionAllocator", ptr)
        self.assert_(ptr.GetObject() is not None)
Exemplo n.º 2
0
def udp_echo_app(network,
                 client_node,
                 server_node,
                 server_device,
                 start,
                 stop,
                 packets=1,
                 interval=1.0,
                 port=9,
                 packet_size=1024):
    """Set up a UDP echo client/server."""
    server = network.nodes[server_node]
    assert server_device in server.devices, \
        "Device '%s' not found, available: %s" % (server_device, ", ".join(server.devices))
    server_address = server.devices[server_device].interfaces[0].address
    echoServer = ns3.UdpEchoServerHelper(port)
    serverApps = echoServer.Install(server.ns3_node)
    serverApps.Start(ns3.Seconds(start))
    serverApps.Stop(ns3.Seconds(stop))

    client = network.nodes[client_node]
    echoClient = ns3.UdpEchoClientHelper(server_address, 9)
    echoClient.SetAttribute("MaxPackets", ns3.UintegerValue(packets))
    echoClient.SetAttribute("Interval", ns3.TimeValue(ns3.Seconds(interval)))
    echoClient.SetAttribute("PacketSize", ns3.UintegerValue(packet_size))
    clientApps = echoClient.Install(client.ns3_node)
    clientApps.Start(ns3.Seconds(start))
    clientApps.Stop(ns3.Seconds(stop))
Exemplo n.º 3
0
def run_simulation(network):
    #print "distance between CCATCCA and URCOS", distance
    # Applications
    server = network.nodes["CCATCCA"]
    server_address = server.devices["Uuario Final PCMCIA"].interfaces[
        0].address
    echoServer = ns3.UdpEchoServerHelper(9)
    serverApps = echoServer.Install(server.ns3_node)
    serverApps.Start(ns3.Seconds(1.0))
    serverApps.Stop(ns3.Seconds(10.0))

    client = network.nodes["URCOS"]
    echoClient = ns3.UdpEchoClientHelper(server_address, 9)
    echoClient.SetAttribute("MaxPackets", ns3.UintegerValue(1))
    echoClient.SetAttribute("Interval", ns3.TimeValue(ns3.Seconds(1.0)))
    echoClient.SetAttribute("PacketSize", ns3.UintegerValue(1024))
    clientApps = echoClient.Install(client.ns3_node)
    clientApps.Start(ns3.Seconds(2.0))
    clientApps.Stop(ns3.Seconds(10.0))

    # Tracing
    josjo1 = network.nodes["JOSJOJAHUARINA 1"]
    device = josjo1.devices['Josjo 1 Sectorial PC'].ns3_device
    phy = josjo1.devices['Josjo 1 Sectorial PC'].phy_helper
    phy.EnablePcap("udp_echo", device)

    # Run simulation
    ns3.Simulator.Stop(ns3.Seconds(10.0))
    ns3.Simulator.Run()
    ns3.Simulator.Destroy()
Exemplo n.º 4
0
def onoff_app(network,
              client_node,
              server_node,
              server_device,
              start,
              stop,
              rate,
              port=9,
              packet_size=1024,
              access_class=None,
              ontime=1,
              offtime=0):
    """Set up a OnOff client + sink server."""
    server = network.nodes[server_node]
    assert server_device in server.devices, \
        "Device '%s' not found, available: %s" % (server_device, ", ".join(server.devices))
    server_address = server.devices[server_device].interfaces[0].address

    local_address = ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), port)
    sink_helper = ns3.PacketSinkHelper("ns3::UdpSocketFactory", local_address)

    server_apps = sink_helper.Install(server.ns3_node)
    server_apps.Start(ns3.Seconds(start))
    server_apps.Stop(ns3.Seconds(stop))

    client = network.nodes[client_node]
    remote_address = ns3.InetSocketAddress(server_address, port)
    onoff_helper = ns3.OnOffHelper("ns3::UdpSocketFactory", ns3.Address())
    onoff_helper.SetAttribute(
        "OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(ontime)))
    onoff_helper.SetAttribute(
        "OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(offtime)))
    onoff_helper.SetAttribute("DataRate",
                              ns3.DataRateValue(ns3.DataRate(rate)))
    onoff_helper.SetAttribute("PacketSize", ns3.UintegerValue(packet_size))
    onoff_helper.SetAttribute("Remote", ns3.AddressValue(remote_address))

    # Set QoS Access Class -> Tid
    # Note that this only works with a patched OnOffApplication with QosTid attribute
    if access_class is not None:
        access_class_to_qos_tid = {
            "ac_vo": 6,  # AC_VO (Tid: 6, 7)
            "ac_vi": 4,  # AC_VI (Tid: 4, 5)
            "ac_be": 0,  # AC_BE (Tid: 0)
            "ac_bk": 1,  # AC_BK (Tid: 1, 2)
            "ac_be_nqos": 3,  # AC_BE_NQOS (Tid: 3)
        }
        qos_tid = access_class_to_qos_tid[access_class.lower()]
        onoff_helper.SetAttribute("QosTid", ns3.UintegerValue(qos_tid))

    client_apps = onoff_helper.Install(client.ns3_node)
    client_apps.Start(ns3.Seconds(start))
    client_apps.Stop(ns3.Seconds(stop))
Exemplo n.º 5
0
def main(argv):
    #
    # Allow the user to override any of the defaults and the above Bind() at
    # run-time, via command-line arguments
    #
    cmd = ns3.CommandLine()
    cmd.Parse(argv)

    #
    # But since this is a realtime script, don't allow the user to mess with
    # that.
    #
    ns3.GlobalValue.Bind("SimulatorImplementationType",
                         ns3.StringValue("ns3::RealtimeSimulatorImpl"))

    #
    # Explicitly create the nodes required by the topology (shown above).
    #
    print "Create nodes."
    n = ns3.NodeContainer()
    n.Create(4)

    internet = ns3.InternetStackHelper()
    internet.Install(n)

    #
    # Explicitly create the channels required by the topology (shown above).
    #
    print("Create channels.")
    csma = ns3.CsmaHelper()
    csma.SetChannelAttribute("DataRate",
                             ns3.DataRateValue(ns3.DataRate(5000000)))
    csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))
    csma.SetDeviceAttribute("Mtu", ns3.UintegerValue(1400))
    d = csma.Install(n)

    #
    # We've got the "hardware" in place.  Now we need to add IP addresses.
    #
    print("Assign IP Addresses.")
    ipv4 = ns3.Ipv4AddressHelper()
    ipv4.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
    i = ipv4.Assign(d)

    print("Create Applications.")

    #
    # Create a UdpEchoServer application on node one.
    #
    port = 9  # well-known echo port number
    server = ns3.UdpEchoServerHelper(port)
    apps = server.Install(n.Get(1))
    apps.Start(ns3.Seconds(1.0))
    apps.Stop(ns3.Seconds(10.0))

    #
    # Create a UdpEchoClient application to send UDP datagrams from node zero to
    # node one.
    #
    packetSize = 1024
    maxPacketCount = 500
    interPacketInterval = ns3.Seconds(0.01)
    client = ns3.UdpEchoClientHelper(i.GetAddress(1), port)
    client.SetAttribute("MaxPackets", ns3.UintegerValue(maxPacketCount))
    client.SetAttribute("Interval", ns3.TimeValue(interPacketInterval))
    client.SetAttribute("PacketSize", ns3.UintegerValue(packetSize))
    apps = client.Install(n.Get(0))
    apps.Start(ns3.Seconds(2.0))
    apps.Stop(ns3.Seconds(10.0))

    ascii = ns3.AsciiTraceHelper()
    csma.EnableAsciiAll(ascii.CreateFileStream("realtime-udp-echo.tr"))
    csma.EnablePcapAll("realtime-udp-echo", False)

    #
    # Now, do the actual simulation.
    #
    print("Run Simulation.")
    ns3.Simulator.Run()
    ns3.Simulator.Destroy()
    print("Done.")
Exemplo n.º 6
0
def main(argv):

    cmd = ns3.CommandLine()

    cmd.Parse(argv)

    # Create nodes
    print "Create nodes"
    n0 = ns3.Node()
    r = ns3.Node()
    n1 = ns3.Node()

    net1 = ns3.NodeContainer()
    net1.Add(n0)
    net1.Add(r)
    net2 = ns3.NodeContainer()
    net2.Add(r)
    net2.Add(n1)
    all = ns3.NodeContainer()
    all.Add(n0)
    all.Add(r)
    all.Add(n1)

    # Create IPv6 Internet Stack
    internetv6 = ns3.InternetStackHelper()
    internetv6.Install(all)

    # Create channels
    csma = ns3.CsmaHelper()
    csma.SetChannelAttribute("DataRate",
                             ns3.DataRateValue(ns3.DataRate(5000000)))
    csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))
    d1 = csma.Install(net1)
    d2 = csma.Install(net2)

    # Create networks and assign IPv6 Addresses
    print "Addressing"
    ipv6 = ns3.Ipv6AddressHelper()
    ipv6.NewNetwork(ns3.Ipv6Address("2001:1::"), ns3.Ipv6Prefix(64))
    i1 = ipv6.Assign(d1)
    i1.SetRouter(1, True)
    ipv6.NewNetwork(ns3.Ipv6Address("2001:2::"), ns3.Ipv6Prefix(64))
    i2 = ipv6.Assign(d2)
    i2.SetRouter(0, True)

    # Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r
    print "Application"
    packetSize = 1024
    maxPacketCount = 5
    interPacketInterval = ns3.Seconds(1.)
    ping6 = ns3.Ping6Helper()

    ping6.SetLocal(i1.GetAddress(0, 1))
    ping6.SetRemote(i2.GetAddress(1, 1))

    ping6.SetAttribute("MaxPackets", ns3.UintegerValue(maxPacketCount))
    ping6.SetAttribute("Interval", ns3.TimeValue(interPacketInterval))
    ping6.SetAttribute("PacketSize", ns3.UintegerValue(packetSize))

    apps = ping6.Install(ns3.NodeContainer(net1.Get(0)))
    apps.Start(ns3.Seconds(2.0))
    apps.Stop(ns3.Seconds(20.0))

    print "Tracing"
    ascii = ns3.ofstream("simple-routing-ping6.tr")
    ns3.CsmaHelper.EnableAsciiAll(ascii)
    ns3.CsmaHelper.EnablePcapAll("simple-routing-ping6", True)

    # Run Simulation
    ns3.Simulator.Run()
    ns3.Simulator.Destroy()
Exemplo n.º 7
0
 def testConfig(self):
     ns3.Config.SetDefault("ns3::OnOffApplication::PacketSize",
                           ns3.UintegerValue(123))
Exemplo n.º 8
0
pointToPoint.SetDeviceAttribute("DataRate", ns3.StringValue("5Mbps"))
pointToPoint.SetChannelAttribute("Delay", ns3.StringValue("2ms"))

devices = pointToPoint.Install(nodes)

stack = ns3.InternetStackHelper()
stack.Install(nodes)

address = ns3.Ipv4AddressHelper()
address.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))

interfaces = address.Assign(devices)

echoServer = ns3.UdpEchoServerHelper(9)

serverApps = echoServer.Install(nodes.Get(1))
serverApps.Start(ns3.Seconds(1.0))
serverApps.Stop(ns3.Seconds(10.0))

echoClient = ns3.UdpEchoClientHelper(interfaces.GetAddress(1), 9)
echoClient.SetAttribute("MaxPackets", ns3.UintegerValue(1))
echoClient.SetAttribute("Interval", ns3.TimeValue(ns3.Seconds(1.0)))
echoClient.SetAttribute("PacketSize", ns3.UintegerValue(1024))

clientApps = echoClient.Install(nodes.Get(0))
clientApps.Start(ns3.Seconds(2.0))
clientApps.Stop(ns3.Seconds(10.0))

ns3.Simulator.Run()
ns3.Simulator.Destroy()