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

(-)a/myscripts/bug2133/dce-wireless-2.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 = 10;
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-3");
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-3");
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.5154), &AdvancePosition, wifiApNodes.Get (0), -50);
158
  Simulator::Schedule (Seconds (8.5154), &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/bug2133/tcp-client-3.cc (+62 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[500];
27
28
      memset (buf, 0x66, 20);
29
      memset (buf + 20, 0x67, 480);
30
31
      sleep(1);
32
      ssize_t e  = write (sock, &buf, 500);
33
                
34
      std::cout << "write: " << e << std::endl;
35
                
36
      fd_set fds;
37
      FD_ZERO (&fds);
38
      FD_SET (sock, &fds);
39
      
40
      struct timeval timeOut;
41
      timeOut.tv_sec = 5;
42
      timeOut.tv_usec = 0;
43
      
44
      int nfds = select (sock + 1, &fds, NULL, NULL, &timeOut);
45
      ssize_t bytes_read = 0;
46
      
47
      uint8_t bufRead[500];
48
      memset (bufRead, 0, 500);
49
      if (nfds > 0)
50
        bytes_read = read (sock, &bufRead, 500);
51
        
52
      std::cout << "read:" << bytes_read << std::endl;
53
    }
54
  else
55
    {
56
      std::cout << "Connection failed." << std::endl;
57
    }
58
59
  close (sock);
60
61
  return 0;
62
}
(-)a/myscripts/bug2133/tcp-server-3.cc (+72 lines)
Line 0    Link Here 
1
#include <unistd.h>
2
#include <stdlib.h>
3
#include <sys/types.h>
4
#include <sys/socket.h>
5
#include <netdb.h>
6
#include <string.h>
7
#include <iostream>
8
#include <sys/fcntl.h>
9
#include <assert.h>
10
11
#define SERVER_PORT 2000
12
13
int
14
main (int argc, char *argv[])
15
{
16
  int sock;
17
  sock = socket (PF_INET, SOCK_STREAM, 0);
18
19
  struct sockaddr_in addr;
20
  addr.sin_family = AF_INET;
21
  addr.sin_port = htons (SERVER_PORT);
22
  addr.sin_addr.s_addr = INADDR_ANY;
23
24
  fcntl(sock, F_SETFL, O_NONBLOCK);
25
26
  int status;
27
  status = bind (sock, (const struct sockaddr *) &addr, sizeof(addr));
28
  status = listen (sock, 1);
29
  
30
  fd_set fds;
31
  FD_ZERO (&fds);
32
  FD_SET (sock, &fds);
33
  
34
  int nfds = select (sock + 1, &fds, NULL, NULL, NULL);
35
36
  int fd = accept (sock, 0, 0);
37
  /*
38
  * The select should return a socket ready for the accept.
39
  */
40
  if (fd == -1)
41
    {
42
      std::cout << " ACCEPT FAIL: " << fd << std::endl;
43
      exit (1);
44
    }
45
  std::cout << " accept -> " << fd << std::endl;
46
47
  uint8_t buf[500];
48
49
  memset (buf, 0, 500);
50
51
  fd_set rfds;
52
  FD_ZERO (&rfds);
53
  FD_SET (fd, &rfds);
54
55
  struct timeval timeOut;
56
  timeOut.tv_sec = 6;
57
  timeOut.tv_usec = 0;
58
  ssize_t bytes_read = 0;
59
60
  nfds = select (fd + 1, &rfds, NULL, NULL, &timeOut);
61
  if (nfds > 0)
62
    bytes_read = read (fd, &buf, 500);
63
64
  std::cout << "read:" << bytes_read << std::endl;
65
66
  close (fd);
67
  
68
  sleep(100);
69
  close (sock);
70
71
  return 0;
72
}
(-)a/myscripts/bug2133/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-2', needed = ['core', 'network', 'dce', 'wifi', 'point-to-point', 'csma', 'mobility', 'flow-monitor', 'applications'],
11
				  target='bin/dce-wireless-2', 
12
				  source=['dce-wireless-2.cc'],
13
				  )
14
    bld.program(source='tcp-server-3.cc', target='../../bin_dce/tcp-server-3', cxxflags = [ '-fPIC'], linkflags = ['-pie', '-rdynamic'])
15
    bld.program(source='tcp-client-3.cc', target='../../bin_dce/tcp-client-3', cxxflags = [ '-fPIC'], linkflags = ['-pie', '-rdynamic'])

Return to bug 2133