View | Details | Raw Unified | Return to bug 2092
Collapse All | Expand All

(-)a/myscripts/bug2092/dce-wireless.cc (+166 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2015 Universidad de la República - Uruguay
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Matias Richart <mrichart@fing.edu.uy>
19
 */
20
21
#include <sstream>
22
#include <fstream>
23
24
#include "ns3/core-module.h"
25
#include "ns3/network-module.h"
26
#include "ns3/dce-module.h"
27
#include "ns3/internet-module.h"
28
#include "ns3/mobility-module.h"
29
#include "ns3/wifi-module.h"
30
31
using namespace ns3;
32
using namespace std;
33
34
NS_LOG_COMPONENT_DEFINE ("DceWireless");
35
36
static void
37
SetPosition (Ptr<Node> node, Vector position)
38
{
39
  Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
40
  mobility->SetPosition (position);
41
}
42
43
static Vector
44
GetPosition (Ptr<Node> node)
45
{
46
  Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
47
  return mobility->GetPosition ();
48
}
49
50
static void
51
AdvancePosition (Ptr<Node> node, int stepsSize)
52
{
53
  Vector pos = GetPosition (node);
54
  pos.x += stepsSize;
55
  SetPosition (node, pos);
56
  NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () << " sec; setting new position to " << pos);
57
}
58
59
int main (int argc, char *argv[])
60
{
61
  uint32_t rtsThreshold = 2346;
62
  int ap1_x = 0;
63
  int ap1_y = 0;
64
  int sta1_x = 30;
65
  int sta1_y = 0;
66
  uint32_t simuTime = 300;
67
68
  CommandLine cmd;
69
  cmd.AddValue ("simuTime", "Total simulation time (sec)", simuTime);
70
  cmd.AddValue ("AP1_x", "Position of AP1 in x coordinate", ap1_x);
71
  cmd.AddValue ("AP1_y", "Position of AP1 in y coordinate", ap1_y);
72
  cmd.AddValue ("STA1_x", "Position of STA1 in x coordinate", sta1_x);
73
  cmd.AddValue ("STA1_y", "Position of STA1 in y coordinate", sta1_y);
74
  cmd.Parse (argc, argv);
75
76
  // Define the AP
77
  NodeContainer wifiApNodes;
78
  wifiApNodes.Create (1);
79
80
  //Define the STA
81
  NodeContainer wifiStaNodes;
82
  wifiStaNodes.Create (1);
83
84
  WifiHelper wifi = WifiHelper::Default ();
85
  wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
86
  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
87
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
88
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
89
90
  wifiPhy.SetChannel (wifiChannel.Create ());
91
92
  NetDeviceContainer wifiApDevices;
93
  NetDeviceContainer wifiStaDevices;
94
  NetDeviceContainer wifiDevices;
95
96
  //Configure the STA node
97
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate6Mbps"), "ControlMode", StringValue ("ErpOfdmRate6Mbps"));
98
99
  Ssid ssid = Ssid ("AP0");
100
  wifiMac.SetType ("ns3::StaWifiMac",
101
                   "Ssid", SsidValue (ssid),
102
                   "ActiveProbing", BooleanValue (false),
103
                   "MaxMissedBeacons", UintegerValue (1000));
104
  wifiStaDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiStaNodes.Get (0)));
105
106
  //Configure the AP node
107
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate54Mbps"),"ControlMode", StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (rtsThreshold));
108
  
109
  ssid = Ssid ("AP0");
110
  wifiMac.SetType ("ns3::ApWifiMac",
111
                   "Ssid", SsidValue (ssid));
112
  wifiApDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiApNodes.Get (0)));
113
114
  wifiDevices.Add (wifiStaDevices);
115
  wifiDevices.Add (wifiApDevices);
116
117
  // Configure the mobility.
118
  MobilityHelper mobility;
119
  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
120
  positionAlloc->Add (Vector (ap1_x, ap1_y, 0.0));
121
  positionAlloc->Add (Vector (sta1_x, sta1_y, 0.0));
122
  mobility.SetPositionAllocator (positionAlloc);
123
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
124
  mobility.Install (wifiApNodes.Get (0));
125
  mobility.Install (wifiStaNodes.Get (0));
126
127
128
  //Configure the IP stack
129
  InternetStackHelper stack;
130
  stack.Install (wifiApNodes);
131
  stack.Install (wifiStaNodes);
132
  Ipv4AddressHelper address;
133
  address.SetBase ("10.1.1.0", "255.255.255.0");
134
  Ipv4InterfaceContainer i = address.Assign (wifiDevices);
135
  Ipv4Address sinkAddress = i.GetAddress (0);
136
  uint16_t port = 9; 
137
138
  DceManagerHelper dceManager;
139
  dceManager.Install (wifiApNodes);
140
  dceManager.Install (wifiStaNodes);
141
142
  DceApplicationHelper dce;
143
  ApplicationContainer apps;
144
  
145
  dce.SetBinary ("tcp-server-2");
146
  dce.ResetArguments ();
147
  dce.SetStackSize (1 << 16);
148
  apps = dce.Install (wifiStaNodes.Get (0));
149
  apps.Start (Seconds (2.0));
150
151
  dce.SetBinary ("tcp-client-2");
152
  dce.ResetArguments ();
153
  dce.ParseArguments ("10.1.1.1");
154
  apps = dce.Install (wifiApNodes.Get (0));
155
  apps.Start (Seconds (2.5));
156
157
  Simulator::Schedule (Seconds (2.51), &AdvancePosition, wifiApNodes.Get (0), -50);
158
  Simulator::Schedule (Seconds (200), &AdvancePosition, wifiApNodes.Get (0), 50);
159
  
160
  Simulator::Stop (Seconds (simuTime));
161
  Simulator::Run ();
162
163
  Simulator::Destroy ();
164
165
  return 0;
166
}
(-)a/myscripts/bug2092/tcp-client-2.cc (+65 lines)
Line 0    Link Here 
1
#include <unistd.h>
2
#include <sys/types.h>
3
#include <sys/socket.h>
4
#include <netdb.h>
5
#include <string.h>
6
#include <iostream>
7
8
9
int main (int argc, char *argv[])
10
{
11
  int sock;
12
  sock = socket (PF_INET, SOCK_STREAM, 0);
13
14
  struct sockaddr_in addr;
15
  addr.sin_family = AF_INET;
16
  addr.sin_port = htons (2000);
17
18
  struct hostent *host = gethostbyname (argv[1]);
19
  memcpy (&addr.sin_addr.s_addr, host->h_addr_list[0], host->h_length);
20
21
  int result;
22
  result = connect (sock, (const struct sockaddr *) &addr, sizeof (addr));
23
  
24
  if (result != -1)
25
    {
26
      uint8_t buf[1024];
27
28
      memset (buf, 0x66, 20);
29
      memset (buf + 20, 0x67, 1004);
30
      ssize_t tot = 0;
31
32
      for (uint32_t i = 0; i < 1000; i++)
33
        {
34
          ssize_t n = 1024;
35
          while (n > 0)
36
            {
37
              ssize_t e  = write (sock, &(buf[1024 - n]), n);
38
              if (e < 0)
39
                {
40
                  break;
41
                }
42
              if (e < n)
43
                {
44
                  sleep (1);
45
                  std::cout << "e < n : " << e << "<" << n << std::endl;
46
                }
47
              n -= e;
48
              tot += e;
49
            }
50
51
          std::cout << "write: " << tot << std::endl;
52
           sleep (1);
53
        }
54
55
      std::cout << "did write all buffers total:" << tot << std::endl;
56
    }
57
  else
58
    {
59
      std::cout << "Connection failed." << std::endl;
60
    }
61
62
  close (sock);
63
64
  return 0;
65
}
(-)a/myscripts/bug2092/tcp-server-2.cc (+77 lines)
Line 0    Link Here 
1
#include <unistd.h>
2
#include <sys/types.h>
3
#include <sys/socket.h>
4
#include <netdb.h>
5
#include <string.h>
6
#include <iostream>
7
#include <sys/fcntl.h>
8
#include <assert.h>
9
10
#define SERVER_PORT 2000
11
12
int
13
main (int argc, char *argv[])
14
{
15
  int sock;
16
  sock = socket (PF_INET, SOCK_STREAM, 0);
17
18
  struct sockaddr_in addr;
19
  addr.sin_family = AF_INET;
20
  addr.sin_port = htons (SERVER_PORT);
21
  addr.sin_addr.s_addr = INADDR_ANY;
22
23
  fcntl(sock, F_SETFL, O_NONBLOCK);
24
25
  int status;
26
  status = bind (sock, (const struct sockaddr *) &addr, sizeof(addr));
27
  status = listen (sock, 1);
28
  
29
  fd_set fds;
30
  FD_ZERO (&fds);
31
  FD_SET (sock, &fds);
32
  
33
  int nfds = select (sock + 1, &fds, NULL, NULL, NULL);
34
35
  int fd = accept (sock, 0, 0);
36
  /*
37
  * The select should return a socket ready for the accept.
38
  */
39
  assert(fd != -1);
40
  std::cout << " accept -> " << fd << std::endl;
41
42
  uint8_t buf[10240];
43
44
  memset (buf, 0, 10240);
45
  ssize_t tot = 0;
46
47
  for (uint32_t i = 0; i < 100; i++)
48
    {
49
      ssize_t n = 10240;
50
      while (n > 0)
51
        {
52
          ssize_t bytes_read = read (fd, &buf[10240 - n], n);
53
54
          if (bytes_read > 0)
55
            {
56
              n -= bytes_read;
57
58
              std::cout << "read:" << bytes_read << " n:" << n << std::endl;
59
60
              tot += bytes_read;
61
            }
62
          else
63
            {
64
              break;
65
            }
66
67
        }
68
         sleep (1);
69
    }
70
71
  std::cout << "did read all buffers tot:" << tot << std::endl;
72
73
  close (sock);
74
  close (fd);
75
76
  return 0;
77
}
(-)a/myscripts/bug2092/wscript (+15 lines)
Line 0    Link Here 
1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3
import ns3waf
4
import os
5
6
def configure(conf):
7
    ns3waf.check_modules(conf, ['core', 'network', 'dce', 'wifi', 'point-to-point', 'csma', 'mobility'], mandatory = True)
8
9
def build(bld):
10
    bld.build_a_script('dce-wireless', needed = ['core', 'network', 'dce', 'wifi', 'point-to-point', 'csma', 'mobility', 'flow-monitor', 'applications'],
11
				  target='bin/dce-wireless', 
12
				  source=['dce-wireless.cc'],
13
				  )
14
    bld.program(source='tcp-server-2.cc', target='../../bin_dce/tcp-server-2', cxxflags = [ '-fPIC'], linkflags = ['-pie', '-rdynamic'])
15
    bld.program(source='tcp-client-2.cc', target='../../bin_dce/tcp-client-2', cxxflags = [ '-fPIC'], linkflags = ['-pie', '-rdynamic'])

Return to bug 2092