Fix Python coding style.
authorSebastien Vincent <vincent@clarinet.u-strasbg.fr>
Fri Sep 04 17:27:33 2009 +0200 (5 months ago)
changeset 475477c878bc3e84
parent 4753 81146e4a3993
child 4755 04a9a7e9a624
Fix Python coding style.
examples/csma-bridge.py
examples/mixed-wireless.py
examples/simple-routing-ping6.py
examples/wifi-ap.py
     1.1 --- a/examples/csma-bridge.py	Fri Sep 04 16:25:55 2009 +0200
     1.2 +++ b/examples/csma-bridge.py	Fri Sep 04 17:27:33 2009 +0200
     1.3 @@ -104,7 +104,7 @@
     1.4      sink = ns3.PacketSinkHelper("ns3::UdpSocketFactory",
     1.5                                  ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), port)))
     1.6      app = sink.Install(ns3.NodeContainer(terminals.Get(1)))
     1.7 -    app.Start (ns3.Seconds (0.0))
     1.8 +    app.Start(ns3.Seconds(0.0))
     1.9  
    1.10      # 
    1.11      # Create a similar flow from n3 to n0, starting at time 1.1 seconds
    1.12 @@ -116,7 +116,7 @@
    1.13      app.Stop(ns3.Seconds(10.0))
    1.14  
    1.15      app = sink.Install(ns3.NodeContainer(terminals.Get(0)))
    1.16 -    app.Start (ns3.Seconds (0.0))
    1.17 +    app.Start(ns3.Seconds(0.0))
    1.18  
    1.19      #
    1.20      # Configure tracing of all enqueue, dequeue, and NetDevice receive events.
     2.1 --- a/examples/mixed-wireless.py	Fri Sep 04 16:25:55 2009 +0200
     2.2 +++ b/examples/mixed-wireless.py	Fri Sep 04 17:27:33 2009 +0200
     2.3 @@ -114,13 +114,13 @@
     2.4      #  our container
     2.5      # 
     2.6      wifi = ns3.WifiHelper()
     2.7 -    mac = ns3.NqosWifiMacHelper.Default ()
     2.8 -    mac.SetType ("ns3::AdhocWifiMac")
     2.9 -    wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
    2.10 -                                  "DataMode", ns3.StringValue ("wifia-54mbs"))
    2.11 -    wifiPhy = ns3.YansWifiPhyHelper.Default ()
    2.12 -    wifiChannel = ns3.YansWifiChannelHelper.Default ()
    2.13 -    wifiPhy.SetChannel (wifiChannel.Create ())
    2.14 +    mac = ns3.NqosWifiMacHelper.Default()
    2.15 +    mac.SetType("ns3::AdhocWifiMac")
    2.16 +    wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
    2.17 +                                  "DataMode", ns3.StringValue("wifia-54mbs"))
    2.18 +    wifiPhy = ns3.YansWifiPhyHelper.Default()
    2.19 +    wifiChannel = ns3.YansWifiChannelHelper.Default()
    2.20 +    wifiPhy.SetChannel(wifiChannel.Create())
    2.21      backboneDevices = wifi.Install(wifiPhy, mac, backbone)
    2.22      # 
    2.23      #  Add the IPv4 protocol stack to the nodes in our container
    2.24 @@ -128,8 +128,8 @@
    2.25      print "Enabling OLSR routing on all backbone nodes"
    2.26      internet = ns3.InternetStackHelper()
    2.27      olsr = ns3.OlsrHelper()
    2.28 -    internet.SetRoutingHelper (olsr);
    2.29 -    internet.Install (backbone);
    2.30 +    internet.SetRoutingHelper(olsr);
    2.31 +    internet.Install(backbone);
    2.32      # 
    2.33      #  Assign IPv4 addresses to the device drivers(actually to the associated
    2.34      #  IPv4 interfaces) we just created.
    2.35 @@ -223,24 +223,24 @@
    2.36          # 
    2.37          #  Create another ad hoc network and devices
    2.38          # 
    2.39 -        ssid = ns3.Ssid ('wifi-infra' + str(i))
    2.40 -        wifiInfra = ns3.WifiHelper.Default ()
    2.41 -        wifiPhy.SetChannel (wifiChannel.Create ())
    2.42 -        wifiInfra.SetRemoteStationManager ('ns3::ArfWifiManager')
    2.43 -        macInfra = ns3.NqosWifiMacHelper.Default ();
    2.44 -        macInfra.SetType ("ns3::NqstaWifiMac",
    2.45 -                          "Ssid", ns3.SsidValue (ssid),
    2.46 -                          "ActiveProbing", ns3.BooleanValue (False))
    2.47 +        ssid = ns3.Ssid('wifi-infra' + str(i))
    2.48 +        wifiInfra = ns3.WifiHelper.Default()
    2.49 +        wifiPhy.SetChannel(wifiChannel.Create())
    2.50 +        wifiInfra.SetRemoteStationManager('ns3::ArfWifiManager')
    2.51 +        macInfra = ns3.NqosWifiMacHelper.Default();
    2.52 +        macInfra.SetType("ns3::NqstaWifiMac",
    2.53 +                          "Ssid", ns3.SsidValue(ssid),
    2.54 +                          "ActiveProbing", ns3.BooleanValue(False))
    2.55  
    2.56          # setup stas
    2.57 -        staDevices = wifiInfra.Install (wifiPhy, macInfra, stas)
    2.58 +        staDevices = wifiInfra.Install(wifiPhy, macInfra, stas)
    2.59          # setup ap.
    2.60 -        macInfra.SetType ("ns3::NqapWifiMac", "Ssid", ns3.SsidValue (ssid),
    2.61 -                          "BeaconGeneration", ns3.BooleanValue (True),
    2.62 -                          "BeaconInterval", ns3.TimeValue (ns3.Seconds (2.5)))
    2.63 -        apDevices = wifiInfra.Install (wifiPhy, macInfra, backbone.Get (i))
    2.64 +        macInfra.SetType("ns3::NqapWifiMac", "Ssid", ns3.SsidValue(ssid),
    2.65 +                          "BeaconGeneration", ns3.BooleanValue(True),
    2.66 +                          "BeaconInterval", ns3.TimeValue(ns3.Seconds(2.5)))
    2.67 +        apDevices = wifiInfra.Install(wifiPhy, macInfra, backbone.Get(i))
    2.68          # Collect all of these new devices
    2.69 -        infraDevices = ns3.NetDeviceContainer (apDevices, staDevices)
    2.70 +        infraDevices = ns3.NetDeviceContainer(apDevices, staDevices)
    2.71  
    2.72          #  Add the IPv4 protocol stack to the nodes in our container
    2.73          # 
    2.74 @@ -284,7 +284,7 @@
    2.75  
    2.76      #  Let's make sure that the user does not define too few LAN nodes
    2.77      #  to make this example work.  We need lanNodes >= 5
    2.78 -    assert (lanNodes >= 5)
    2.79 +    assert(lanNodes >= 5)
    2.80      appSource = ns3.NodeList.GetNode(11)
    2.81      appSink = ns3.NodeList.GetNode(13)
    2.82      remoteAddr = ns3.Ipv4Address("172.16.0.5")
     3.1 --- a/examples/simple-routing-ping6.py	Fri Sep 04 16:25:55 2009 +0200
     3.2 +++ b/examples/simple-routing-ping6.py	Fri Sep 04 17:27:33 2009 +0200
     3.3 @@ -31,74 +31,74 @@
     3.4  
     3.5  def main(argv):
     3.6  
     3.7 -  cmd = ns3.CommandLine ();
     3.8 +    cmd = ns3.CommandLine();
     3.9  
    3.10 -  cmd.Parse (argv);
    3.11 +    cmd.Parse(argv);
    3.12  
    3.13 -  # Create nodes
    3.14 -  print "Create nodes"
    3.15 -  n0 = ns3.Node ();
    3.16 -  r = ns3.Node ();
    3.17 -  n1 = ns3.Node ();
    3.18 +    # Create nodes
    3.19 +    print "Create nodes"
    3.20 +    n0 = ns3.Node();
    3.21 +    r = ns3.Node();
    3.22 +    n1 = ns3.Node();
    3.23  
    3.24 -  net1 = ns3.NodeContainer ();
    3.25 -  net1.Add (n0);
    3.26 -  net1.Add (r);
    3.27 -  net2 = ns3.NodeContainer ();
    3.28 -  net2.Add (r);
    3.29 -  net2.Add (n1);
    3.30 -  all = ns3.NodeContainer ();
    3.31 -  all.Add (n0);
    3.32 -  all.Add (r);
    3.33 -  all.Add (n1);
    3.34 +    net1 = ns3.NodeContainer();
    3.35 +    net1.Add(n0);
    3.36 +    net1.Add(r);
    3.37 +    net2 = ns3.NodeContainer();
    3.38 +    net2.Add(r);
    3.39 +    net2.Add(n1);
    3.40 +    all = ns3.NodeContainer();
    3.41 +    all.Add(n0);
    3.42 +    all.Add(r);
    3.43 +    all.Add(n1);
    3.44  
    3.45 -  # Create IPv6 Internet Stack
    3.46 -  internetv6 = ns3.InternetStackHelper ();
    3.47 -  internetv6.Install (all);
    3.48 +    # Create IPv6 Internet Stack
    3.49 +    internetv6 = ns3.InternetStackHelper();
    3.50 +    internetv6.Install(all);
    3.51  
    3.52 -  # Create channels
    3.53 -  csma = ns3.CsmaHelper ();
    3.54 -  csma.SetChannelAttribute ("DataRate", ns3.DataRateValue (ns3.DataRate (5000000)));
    3.55 -  csma.SetChannelAttribute ("Delay", ns3.TimeValue (ns3.MilliSeconds (2)));
    3.56 -  d1 = csma.Install (net1);
    3.57 -  d2 = csma.Install (net2);
    3.58 +    # Create channels
    3.59 +    csma = ns3.CsmaHelper();
    3.60 +    csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)));
    3.61 +    csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)));
    3.62 +    d1 = csma.Install(net1);
    3.63 +    d2 = csma.Install(net2);
    3.64  
    3.65 -  # Create networks and assign IPv6 Addresses
    3.66 -  print "Addressing"
    3.67 -  ipv6 = ns3.Ipv6AddressHelper ();
    3.68 -  ipv6.NewNetwork (ns3.Ipv6Address ("2001:1::"), ns3.Ipv6Prefix (64));
    3.69 -  i1 = ipv6.Assign (d1);
    3.70 -  i1.SetRouter (1, True);
    3.71 -  ipv6.NewNetwork (ns3.Ipv6Address ("2001:2::"), ns3.Ipv6Prefix (64));
    3.72 -  i2 = ipv6.Assign (d2);
    3.73 -  i2.SetRouter (0, True);
    3.74 +    # Create networks and assign IPv6 Addresses
    3.75 +    print "Addressing"
    3.76 +    ipv6 = ns3.Ipv6AddressHelper();
    3.77 +    ipv6.NewNetwork(ns3.Ipv6Address("2001:1::"), ns3.Ipv6Prefix(64));
    3.78 +    i1 = ipv6.Assign(d1);
    3.79 +    i1.SetRouter(1, True);
    3.80 +    ipv6.NewNetwork(ns3.Ipv6Address("2001:2::"), ns3.Ipv6Prefix(64));
    3.81 +    i2 = ipv6.Assign(d2);
    3.82 +    i2.SetRouter(0, True);
    3.83  
    3.84 -  # Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r 
    3.85 -  print "Application"
    3.86 -  packetSize = 1024;
    3.87 -  maxPacketCount = 5;
    3.88 -  interPacketInterval = ns3.Seconds (1.);
    3.89 -  ping6 = ns3.Ping6Helper ();
    3.90 +    # Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r 
    3.91 +    print "Application"
    3.92 +    packetSize = 1024;
    3.93 +    maxPacketCount = 5;
    3.94 +    interPacketInterval = ns3.Seconds(1.);
    3.95 +    ping6 = ns3.Ping6Helper();
    3.96  
    3.97 -  ping6.SetLocal (i1.GetAddress (0, 1));
    3.98 -  ping6.SetRemote (i2.GetAddress (1, 1)); 
    3.99 +    ping6.SetLocal(i1.GetAddress(0, 1));
   3.100 +    ping6.SetRemote(i2.GetAddress(1, 1)); 
   3.101  
   3.102 -  ping6.SetAttribute ("MaxPackets", ns3.UintegerValue (maxPacketCount));
   3.103 -  ping6.SetAttribute ("Interval", ns3.TimeValue (interPacketInterval));
   3.104 -  ping6.SetAttribute ("PacketSize", ns3.UintegerValue (packetSize));
   3.105 +    ping6.SetAttribute("MaxPackets", ns3.UintegerValue(maxPacketCount));
   3.106 +    ping6.SetAttribute("Interval", ns3.TimeValue(interPacketInterval));
   3.107 +    ping6.SetAttribute("PacketSize", ns3.UintegerValue(packetSize));
   3.108  
   3.109 -  apps = ping6.Install (ns3.NodeContainer (net1.Get (0)));
   3.110 -  apps.Start (ns3.Seconds (2.0));
   3.111 -  apps.Stop (ns3.Seconds (20.0));
   3.112 +    apps = ping6.Install(ns3.NodeContainer(net1.Get(0)));
   3.113 +    apps.Start(ns3.Seconds(2.0));
   3.114 +    apps.Stop(ns3.Seconds(20.0));
   3.115  
   3.116 -  print "Tracing"
   3.117 -  ascii = ns3.ofstream ("simple-routing-ping6.tr");
   3.118 -  ns3.CsmaHelper.EnableAsciiAll (ascii);
   3.119 -  ns3.CsmaHelper.EnablePcapAll ("simple-routing-ping6", True);
   3.120 +    print "Tracing"
   3.121 +    ascii = ns3.ofstream("simple-routing-ping6.tr");
   3.122 +    ns3.CsmaHelper.EnableAsciiAll(ascii);
   3.123 +    ns3.CsmaHelper.EnablePcapAll("simple-routing-ping6", True);
   3.124  
   3.125 -  # Run Simulation   
   3.126 -  ns3.Simulator.Run ();
   3.127 -  ns3.Simulator.Destroy ();
   3.128 +    # Run Simulation     
   3.129 +    ns3.Simulator.Run();
   3.130 +    ns3.Simulator.Destroy();
   3.131  
   3.132  if __name__ == '__main__':
   3.133      import sys
     4.1 --- a/examples/wifi-ap.py	Fri Sep 04 16:25:55 2009 +0200
     4.2 +++ b/examples/wifi-ap.py	Fri Sep 04 17:27:33 2009 +0200
     4.3 @@ -29,30 +29,30 @@
     4.4  #   std::cout << " TX to=" << address << " p: " << *p << std::endl;
     4.5  # }
     4.6  # void
     4.7 -# DevRxTrace (std::string context, Ptr<const Packet> p, Mac48Address address)
     4.8 +# DevRxTrace(std::string context, Ptr<const Packet> p, Mac48Address address)
     4.9  # {
    4.10  #   std::cout << " RX from=" << address << " p: " << *p << std::endl;
    4.11  # }
    4.12  # void
    4.13 -# PhyRxOkTrace (std::string context, Ptr<const Packet> packet, double snr, WifiMode mode, enum WifiPreamble preamble)
    4.14 +# PhyRxOkTrace(std::string context, Ptr<const Packet> packet, double snr, WifiMode mode, enum WifiPreamble preamble)
    4.15  # {
    4.16  #   std::cout << "PHYRXOK mode=" << mode << " snr=" << snr << " " << *packet << std::endl;
    4.17  # }
    4.18  # void
    4.19 -# PhyRxErrorTrace (std::string context, Ptr<const Packet> packet, double snr)
    4.20 +# PhyRxErrorTrace(std::string context, Ptr<const Packet> packet, double snr)
    4.21  # {
    4.22  #   std::cout << "PHYRXERROR snr=" << snr << " " << *packet << std::endl;
    4.23  # }
    4.24  # void
    4.25 -# PhyTxTrace (std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
    4.26 +# PhyTxTrace(std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
    4.27  # {
    4.28  #   std::cout << "PHYTX mode=" << mode << " " << *packet << std::endl;
    4.29  # }
    4.30  # void
    4.31 -# PhyStateTrace (std::string context, Time start, Time duration, enum WifiPhy::State state)
    4.32 +# PhyStateTrace(std::string context, Time start, Time duration, enum WifiPhy::State state)
    4.33  # {
    4.34  #   std::cout << " state=";
    4.35 -#   switch (state) {
    4.36 +#   switch(state) {
    4.37  #   case WifiPhy::TX:
    4.38  #     std::cout << "tx      ";
    4.39  #     break;
    4.40 @@ -79,7 +79,7 @@
    4.41      return mobility.GetPosition()
    4.42  
    4.43  def AdvancePosition(node):
    4.44 -    pos = GetPosition (node);
    4.45 +    pos = GetPosition(node);
    4.46      pos.x += 5.0
    4.47      if pos.x >= 210.0:
    4.48        return
    4.49 @@ -88,12 +88,12 @@
    4.50  
    4.51  
    4.52  def main(argv):
    4.53 -    ns3.Packet.EnablePrinting ();
    4.54 +    ns3.Packet.EnablePrinting();
    4.55  
    4.56      # enable rts cts all the time.
    4.57      ns3.Config.SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", ns3.StringValue("0"))
    4.58      # disable fragmentation
    4.59 -    ns3.Config.SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", ns3.StringValue ("2200"))
    4.60 +    ns3.Config.SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", ns3.StringValue("2200"))
    4.61  
    4.62      wifi = ns3.WifiHelper.Default()
    4.63      mobility = ns3.MobilityHelper()
    4.64 @@ -115,7 +115,7 @@
    4.65  
    4.66      ssid = ns3.Ssid("wifi-default")
    4.67      wifi.SetRemoteStationManager("ns3::ArfWifiManager")
    4.68 -    wifiMac = ns3.NqosWifiMacHelper.Default ()
    4.69 +    wifiMac = ns3.NqosWifiMacHelper.Default()
    4.70  
    4.71      # setup stas.
    4.72      wifiMac.SetType("ns3::NqstaWifiMac", 
    4.73 @@ -149,12 +149,12 @@
    4.74  
    4.75      ns3.Simulator.Stop(ns3.Seconds(44.0))
    4.76  
    4.77 -  #   Config::Connect ("/NodeList/*/DeviceList/*/Tx", MakeCallback (&DevTxTrace));
    4.78 -  #   Config::Connect ("/NodeList/*/DeviceList/*/Rx", MakeCallback (&DevRxTrace));
    4.79 -  #   Config::Connect ("/NodeList/*/DeviceList/*/Phy/RxOk", MakeCallback (&PhyRxOkTrace));
    4.80 -  #   Config::Connect ("/NodeList/*/DeviceList/*/Phy/RxError", MakeCallback (&PhyRxErrorTrace));
    4.81 -  #   Config::Connect ("/NodeList/*/DeviceList/*/Phy/Tx", MakeCallback (&PhyTxTrace));
    4.82 -  #   Config::Connect ("/NodeList/*/DeviceList/*/Phy/State", MakeCallback (&PhyStateTrace));
    4.83 +  #   Config::Connect("/NodeList/*/DeviceList/*/Tx", MakeCallback(&DevTxTrace));
    4.84 +  #   Config::Connect("/NodeList/*/DeviceList/*/Rx", MakeCallback(&DevRxTrace));
    4.85 +  #   Config::Connect("/NodeList/*/DeviceList/*/Phy/RxOk", MakeCallback(&PhyRxOkTrace));
    4.86 +  #   Config::Connect("/NodeList/*/DeviceList/*/Phy/RxError", MakeCallback(&PhyRxErrorTrace));
    4.87 +  #   Config::Connect("/NodeList/*/DeviceList/*/Phy/Tx", MakeCallback(&PhyTxTrace));
    4.88 +  #   Config::Connect("/NodeList/*/DeviceList/*/Phy/State", MakeCallback(&PhyStateTrace));
    4.89  
    4.90      ascii = ns3.ofstream("wifi-ap.tr")
    4.91      ns3.YansWifiPhyHelper.EnableAsciiAll(ascii)