示例#1
0
 def StartApplication(self):
     self.soc.Bind(
         network.InetSocketAddress(network.Ipv4Address('0.0.0.0'), 9))
     self.soc.Connect(
         network.InetSocketAddress(network.Ipv4Address(self.add), 9))
     self.soc.SetAllowBroadcast(True)
     if self.nouse:
         core.Simulator.Schedule(core.Seconds(0), self.up)
     else:
         core.Simulator.Schedule(core.Seconds(1.0), self.up2)
     pass
示例#2
0
 def send(self):
     a = network.Packet(1472 - 8 - 4)
     he = app.SeqTsHeader()
     he.SetSeq(self.i)
     a.AddHeader(he)
     self.socket.Send(a)
     core.Simulator.Schedule(core.Seconds(1), self.send)
示例#3
0
 def up2(self):
     self.past = int(core.Simulator.Now().GetSeconds() * 1000)
     num = 0.25 / self.inter.GetSeconds()
     # num *= 0.6
     for i in range(int(num)):
         a = self.packet()
         self.soc.Send(a)
     core.Simulator.Schedule(core.Seconds(0.25), self.up2)
     pass
示例#4
0
    def __simulate(self, simulation_time=None):
        """Simulate the network.

        *Warning:* This method does not catch Keyboard errors.

        Parameters
        ----------
        simulation_time : float
            The simulation timeout in seconds.
            If set to :code:`None` the simulation will continue until being manually aborted.
        """
        if self.started:
            raise Exception('The simulation was already started')
        self.started = True

        self.prepare()

        started = threading.Semaphore(0)

        core.Simulator.Schedule(core.Seconds(0), started.release)

        logger.info('Starting MobilityInputs.')
        for mobility_input in self.scenario.mobility_inputs:
            mobility_input.start()
            defer('stop mobility input', mobility_input.destroy)

        if simulation_time is not None:
            logger.info('Simulating for %.4fs', simulation_time)
        else:
            logger.info('Simulating until process gets stopped')

        def run_simulation():
            if simulation_time is not None:
                core.Simulator.Stop(core.Seconds(simulation_time))
            core.Simulator.Run()
            core.Simulator.Destroy()

        thread = threading.Thread(target=run_simulation)

        try:
            thread.start()
            started.acquire()

            logger.debug('Starting workflows.')
            for task in self.scenario.workflows:
                workflow = Workflow(task)
                self.workflows.append(workflow)
                workflow.start()
            thread.join()
        finally:
            # Stopping the workflows cannot be deferred, because
            # the deferred items won't be cleaned up, until workflows ended.
            self.__stop_workflows()
            core.Simulator.Stop()
示例#5
0
def enq(argv):
    global event_number, n, k, T_in, T_out, time_in, time_out, isjudge, num
    if isjudge:
        event_number += 1
    if event_number <= 100 and isjudge:  #处理100件事件完则停止向调度器增加事件
        if event_number == 100:
            isjudge = False
        now = sim.Now().GetSeconds()
        time_eq = r_eq.GetValue()
        time_in = now + time_eq
        T_in.append(time_in)
        K = 1  #服务忙
        num += 1
        if num > 0:
            n += 1
        print "第%d个事件进入队列的时间是:" % event_number, time_in, "K=", K, "n=", n
        sim.Schedule(core.Seconds(time_eq), enq, now)
        time_deq = r_deq.GetValue()
        time_out = time_in + time_deq
        T_out.append(time_out)
        sim.Schedule(core.Seconds(time_deq), deq, T_in[event_number_out])
示例#6
0
 def __init__(self, soc, inter, size, nouse=True):
     inter = core.Seconds(size * 8 / 1000.0 / 1000.0 / inter)
     self.soc = soc
     self.inter = inter
     self.mtu = size
     self.acc = 0
     self.past = 0
     self.limit = 250
     self.nouse = nouse
     if nouse:
         self.add = "10.1.3.1"
     else:
         self.add = "10.1.3.2"
         print size / inter.GetSeconds() * 8 / 1000000
     super(send, self).__init__()
     pass
示例#7
0
 def run_simulation():
     if simulation_time is not None:
         core.Simulator.Stop(core.Seconds(simulation_time))
     core.Simulator.Run()
     core.Simulator.Destroy()
示例#8
0
def main(li):
    p2pNodes = network.NodeContainer()
    p2pNodes.Create(2)

    pointToPoint = point_to_point.PointToPointHelper()
    pointToPoint.SetDeviceAttribute(
        "DataRate",
        core.StringValue(str(int(sum([i[0] for i in li]))) + "Mbps"))
    pointToPoint.SetChannelAttribute("Delay", core.StringValue("20ms"))

    p2pDevices = pointToPoint.Install(p2pNodes)

    csmaNodes = network.NodeContainer()
    csmaNodes.Add(p2pNodes.Get(1))
    csmaNodes.Create(3)

    csma = ccc.CsmaHelper()
    csma.SetChannelAttribute("DataRate", core.StringValue("100Mbps"))
    csma.SetChannelAttribute("Delay", core.TimeValue(core.NanoSeconds(6560)))

    csmaDevices = csma.Install(csmaNodes)

    wifiStaNodes = network.NodeContainer()
    wifiStaNodes.Create(3)
    wifiApNode = p2pNodes.Get(0)

    channel = www.YansWifiChannelHelper.Default()
    phy = www.YansWifiPhyHelper.Default()
    phy.SetChannel(channel.Create())

    wifi = www.WifiHelper()
    # wifi.SetRemoteStationManager("ns3::AarfWifiManager")
    wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",
                                 core.StringValue("OfdmRate54Mbps"))

    mac = www.WifiMacHelper()
    ssid = www.Ssid("ns-3-ssid")

    mac.SetType("ns3::StaWifiMac", "Ssid", www.SsidValue(ssid),
                "ActiveProbing", core.BooleanValue(False))
    staDevices = wifi.Install(phy, mac, wifiStaNodes)

    mac.SetType("ns3::ApWifiMac", "Ssid", www.SsidValue(ssid))
    apDevices = wifi.Install(phy, mac, wifiApNode)

    mobility = mob.MobilityHelper()
    mobility.SetPositionAllocator("ns3::GridPositionAllocator", "MinX",
                                  core.DoubleValue(0.0), "MinY",
                                  core.DoubleValue(0.0), "DeltaX",
                                  core.DoubleValue(5.0), "DeltaY",
                                  core.DoubleValue(10.0), "GridWidth",
                                  core.UintegerValue(3), "LayoutType",
                                  core.StringValue("RowFirst"))
    mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel")
    mobility.Install(wifiApNode)
    mobility.Install(wifiStaNodes)

    stack = internet.InternetStackHelper()
    stack.Install(csmaNodes)
    stack.Install(wifiApNode)
    stack.Install(wifiStaNodes)

    address = internet.Ipv4AddressHelper()
    address.SetBase(network.Ipv4Address("10.1.1.0"),
                    network.Ipv4Mask("255.255.255.0"))
    address.Assign(p2pDevices)

    address.SetBase(network.Ipv4Address("10.1.2.0"),
                    network.Ipv4Mask("255.255.255.0"))
    address.Assign(csmaDevices)

    address.SetBase(network.Ipv4Address("10.1.3.0"),
                    network.Ipv4Mask("255.255.255.0"))
    address.Assign(staDevices)
    address.Assign(apDevices)

    client = csmaNodes.Get(0)
    soc = network.Socket.CreateSocket(client,
                                      internet.UdpSocketFactory.GetTypeId())
    pre = li[0]
    client.AddApplication(send(soc, pre[0], pre[1], False))
    for i in range(1, 4):
        client = csmaNodes.Get(i)
        soc = network.Socket.CreateSocket(
            client, internet.UdpSocketFactory.GetTypeId())
        pre = li[i]
        client.AddApplication(send(soc, pre[0], pre[1]))

    client = wifiStaNodes.Get(0)
    soc = network.Socket.CreateSocket(client,
                                      internet.UdpSocketFactory.GetTypeId())
    client.AddApplication(recv(soc))
    client = wifiStaNodes.Get(1)
    soc = network.Socket.CreateSocket(client,
                                      internet.UdpSocketFactory.GetTypeId())
    client.AddApplication(recv(soc, False))

    internet.Ipv4GlobalRoutingHelper.PopulateRoutingTables()

    core.Simulator.Stop(core.Seconds(3.0))

    # pointToPoint.EnablePcapAll("third")
    # phy.EnablePcapAll("csma")
    # csma.EnablePcapAll("third", True)
    # stack.EnablePcapIpv4All('ics')

    core.Simulator.Run()
    core.Simulator.Destroy()
示例#9
0
        time_eq = r_eq.GetValue()
        time_in = now + time_eq
        T_in.append(time_in)
        K = 1  #服务忙
        num += 1
        if num > 0:
            n += 1
        print "第%d个事件进入队列的时间是:" % event_number, time_in, "K=", K, "n=", n
        sim.Schedule(core.Seconds(time_eq), enq, now)
        time_deq = r_deq.GetValue()
        time_out = time_in + time_deq
        T_out.append(time_out)
        sim.Schedule(core.Seconds(time_deq), deq, T_in[event_number_out])


def deq(argv):
    global K, n, event_number_out, num
    event_number_out += 1
    num -= 1
    len_out = len(T_in)
    if len_out == event_number_out: K = 0
    if n != 0:
        n -= 1
    print "第%d个事件离开队列的时间是:" % event_number_out, T_out[(
        event_number_out - 1)], "K=", K, "n=", n, len_out, event_number_out


sim.Schedule(core.Seconds(0), enq, sim.Now().GetSeconds())
sim.Run()
sim.Destroy()
示例#10
0
def main():
    # core.LogComponentEnable("UdpEchoClientApplication", core.LOG_LEVEL_INFO)

    wifihelper = wifi.WifiHelper.Default()
    wifihelper.SetStandard(wifi.WIFI_PHY_STANDARD_80211a)

    wifiphy = wifi.YansWifiPhyHelper.Default()
    wifichannel = wifi.YansWifiChannelHelper.Default()
    wifiphy.SetChannel(wifichannel.Create())

    wifimac = wifi.WifiMacHelper()
    wifimac.SetType("ns3::AdhocWifiMac")
    wifihelper.SetRemoteStationManager("ns3::ConstantRateWifiManager",
                                       "DataMode",
                                       core.StringValue("OfdmRate54Mbps"))

    p2pmac = p2p.PointToPointHelper()
    p2pmac.SetChannelAttribute("Delay", core.TimeValue(core.NanoSeconds(6560)))
    p2pmac.SetDeviceAttribute("DataRate", core.StringValue("2Mbps"))

    stas = network.NodeContainer()
    stas.Create(3)

    p2ps = network.NodeContainer()
    p2ps.Create(1)

    mob = mobility.MobilityHelper()
    mob.Install(stas)

    stack = internet.InternetStackHelper()
    stack.Install(stas)
    stack.Install(p2ps)

    dev = wifihelper.Install(wifiphy, wifimac, stas)
    p2ps.Add(stas.Get(0))
    dev2 = p2pmac.Install(p2ps)

    ip = internet.Ipv4AddressHelper()
    ip.SetBase(network.Ipv4Address('192.168.0.0'),
               network.Ipv4Mask('255.255.255.0'))
    ip.Assign(dev)
    ip.SetBase(network.Ipv4Address('192.168.1.0'),
               network.Ipv4Mask('255.255.255.0'))
    ip.Assign(dev2)

    client = p2ps.Get(0)
    client.AddApplication(
        aaa(
            network.Socket.CreateSocket(client,
                                        internet.UdpSocketFactory.GetTypeId()),
            0))
    for i in range(3):
        client = stas.Get(i)
        client.AddApplication(
            aaa(
                network.Socket.CreateSocket(
                    client, internet.UdpSocketFactory.GetTypeId()), i))

    internet.Ipv4GlobalRoutingHelper.PopulateRoutingTables()

    core.Simulator.Stop(core.Seconds(10.0))

    wifiphy.EnablePcapAll('adhoc', True)
    stack.EnablePcapIpv4All('ipv4')
    core.Simulator.Run()
    core.Simulator.Destroy()

    sys.exit(0)