author | Craig Dowell <craigdo@ee.washington.edu> |
Mon, 02 Feb 2009 11:43:10 -0800 | |
changeset 4178 | bd8625e5913a |
parent 4173 | a7983f5acf98 |
child 4180 | 1ec09ce94019 |
permissions | -rw-r--r-- |
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* Copyright (c) 2009 University of Washington |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
*/ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
19 |
#include "tap-bridge.h" |
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
20 |
#include "tap-encode-decode.h" |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
21 |
|
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
22 |
#include "ns3/node.h" |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
23 |
#include "ns3/channel.h" |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
#include "ns3/packet.h" |
4165 | 25 |
#include "ns3/ethernet-header.h" |
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
26 |
#include "ns3/llc-snap-header.h" |
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
#include "ns3/log.h" |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
#include "ns3/boolean.h" |
4165 | 29 |
#include "ns3/string.h" |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
30 |
#include "ns3/ipv4.h" |
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
#include "ns3/simulator.h" |
4165 | 32 |
#include "ns3/realtime-simulator-impl.h" |
33 |
#include "ns3/system-thread.h" |
|
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
|
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
35 |
#include <sys/wait.h> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
36 |
#include <sys/stat.h> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
37 |
#include <sys/socket.h> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
38 |
#include <sys/un.h> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
39 |
#include <sys/ioctl.h> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
40 |
#include <net/ethernet.h> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
41 |
#include <net/if.h> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
42 |
#include <netinet/in.h> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
43 |
#include <netpacket/packet.h> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
44 |
#include <arpa/inet.h> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
45 |
#include <errno.h> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
46 |
#include <limits> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
47 |
#include <stdlib.h> |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
48 |
|
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
NS_LOG_COMPONENT_DEFINE ("TapBridge"); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
namespace ns3 { |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
|
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
53 |
#define TAP_MAGIC 95549 |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
54 |
|
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
55 |
NS_OBJECT_ENSURE_REGISTERED (TapBridge); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
56 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
TypeId |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
58 |
TapBridge::GetTypeId (void) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
60 |
static TypeId tid = TypeId ("ns3::TapBridge") |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
61 |
.SetParent<NetDevice> () |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
62 |
.AddConstructor<TapBridge> () |
4165 | 63 |
.AddAttribute ("DeviceName", |
64 |
"The name of the tap device to create.", |
|
65 |
StringValue (""), |
|
66 |
MakeStringAccessor (&TapBridge::m_tapDeviceName), |
|
67 |
MakeStringChecker ()) |
|
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
68 |
.AddAttribute ("Gateway", |
4165 | 69 |
"The IP address of the default gateway to assign to the tap device.", |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
70 |
Ipv4AddressValue ("255.255.255.255"), |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
71 |
MakeIpv4AddressAccessor (&TapBridge::m_tapGateway), |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
72 |
MakeIpv4AddressChecker ()) |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
73 |
.AddAttribute ("IpAddress", |
4165 | 74 |
"The IP address to assign to the tap device.", |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
75 |
Ipv4AddressValue ("255.255.255.255"), |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
76 |
MakeIpv4AddressAccessor (&TapBridge::m_tapIp), |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
77 |
MakeIpv4AddressChecker ()) |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
78 |
.AddAttribute ("MacAddress", |
4165 | 79 |
"The MAC address to assign to the tap device.", |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
80 |
Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")), |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
81 |
MakeMac48AddressAccessor (&TapBridge::m_tapMac), |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
82 |
MakeMac48AddressChecker ()) |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
83 |
.AddAttribute ("Netmask", |
4165 | 84 |
"The network mask to assign to the tap device.", |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
85 |
Ipv4MaskValue ("255.255.255.255"), |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
86 |
MakeIpv4MaskAccessor (&TapBridge::m_tapNetmask), |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
87 |
MakeIpv4MaskChecker ()) |
4165 | 88 |
.AddAttribute ("Start", |
89 |
"The simulation time at which to spin up the tap device read thread.", |
|
90 |
TimeValue (Seconds (0.)), |
|
91 |
MakeTimeAccessor (&TapBridge::m_tStart), |
|
92 |
MakeTimeChecker ()) |
|
93 |
.AddAttribute ("Stop", |
|
94 |
"The simulation time at which to tear down the tap device read thread.", |
|
95 |
TimeValue (Seconds (0.)), |
|
96 |
MakeTimeAccessor (&TapBridge::m_tStop), |
|
97 |
MakeTimeChecker ()) |
|
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
return tid; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
100 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
102 |
TapBridge::TapBridge () |
4165 | 103 |
: m_node (0), |
104 |
m_ifIndex (0), |
|
105 |
m_mtu (0), |
|
106 |
m_sock (-1), |
|
107 |
m_startEvent (), |
|
108 |
m_stopEvent (), |
|
109 |
m_readThread (0) |
|
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
110 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
NS_LOG_FUNCTION_NOARGS (); |
4165 | 112 |
Start (m_tStart); |
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
TapBridge::~TapBridge() |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
117 |
NS_LOG_FUNCTION_NOARGS (); |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
118 |
m_bridgedDevice = 0; |
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
119 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
121 |
void |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
122 |
TapBridge::DoDispose () |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
123 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
124 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
125 |
NetDevice::DoDispose (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
126 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
127 |
|
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
128 |
void |
4165 | 129 |
TapBridge::Start (Time tStart) |
130 |
{ |
|
131 |
NS_LOG_FUNCTION (tStart); |
|
132 |
||
133 |
// |
|
134 |
// Cancel any pending start event and schedule a new one at some relative time in the future. |
|
135 |
// |
|
136 |
Simulator::Cancel (m_startEvent); |
|
137 |
m_startEvent = Simulator::Schedule (tStart, &TapBridge::StartTapDevice, this); |
|
138 |
} |
|
139 |
||
140 |
void |
|
141 |
TapBridge::Stop (Time tStop) |
|
142 |
{ |
|
143 |
NS_LOG_FUNCTION (tStop); |
|
144 |
// |
|
145 |
// Cancel any pending stop event and schedule a new one at some relative time in the future. |
|
146 |
// |
|
147 |
Simulator::Cancel (m_stopEvent); |
|
148 |
m_startEvent = Simulator::Schedule (tStop, &TapBridge::StopTapDevice, this); |
|
149 |
} |
|
150 |
||
151 |
void |
|
152 |
TapBridge::StartTapDevice (void) |
|
153 |
{ |
|
154 |
NS_LOG_FUNCTION_NOARGS (); |
|
155 |
||
156 |
// |
|
157 |
// Spin up the tap bridge and start receiving packets. |
|
158 |
// |
|
159 |
if (m_sock != -1) |
|
160 |
{ |
|
161 |
NS_FATAL_ERROR ("TapBridge::StartTapDevice(): Tap is already started"); |
|
162 |
} |
|
163 |
||
164 |
NS_LOG_LOGIC ("Creating tap device"); |
|
165 |
||
166 |
// |
|
167 |
// Call out to a separate process running as suid root in order to get the |
|
168 |
// tap device allocated and set up. We do this to avoid having the entire |
|
169 |
// simulation running as root. If this method returns, we'll have a socket |
|
170 |
// waiting for us in m_sock that we can use to talk to the newly created |
|
171 |
// tap device. |
|
172 |
// |
|
173 |
CreateTap (); |
|
174 |
||
175 |
// |
|
176 |
// Now spin up a read thread to read packets from the tap device. |
|
177 |
// |
|
178 |
if (m_readThread != 0) |
|
179 |
{ |
|
180 |
NS_FATAL_ERROR ("TapBridge::StartTapDevice(): Receive thread is already running"); |
|
181 |
} |
|
182 |
||
183 |
NS_LOG_LOGIC ("Spinning up read thread"); |
|
184 |
||
185 |
m_readThread = Create<SystemThread> (MakeCallback (&TapBridge::ReadThread, this)); |
|
186 |
m_readThread->Start (); |
|
187 |
} |
|
188 |
||
189 |
void |
|
190 |
TapBridge::StopTapDevice (void) |
|
191 |
{ |
|
192 |
NS_LOG_FUNCTION_NOARGS (); |
|
193 |
||
194 |
close (m_sock); |
|
195 |
m_sock = -1; |
|
196 |
||
197 |
NS_ASSERT_MSG (m_readThread != 0, "TapBridge::StopTapDevice(): Receive thread is not running"); |
|
198 |
||
199 |
NS_LOG_LOGIC ("Joining read thread"); |
|
200 |
m_readThread->Join (); |
|
201 |
m_readThread = 0; |
|
202 |
} |
|
203 |
||
204 |
void |
|
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
205 |
TapBridge::CreateTap (void) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
206 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
207 |
NS_LOG_FUNCTION_NOARGS (); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
208 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
209 |
// We want to create a tap device on the host. Unfortunately for us |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
210 |
// you have to have root privileges to do that. Instead of running the |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
211 |
// entire simulation as root, we decided to make a small program who's whole |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
212 |
// reason for being is to run as suid root and do what it takes to create the |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
213 |
// tap. We're going to fork and exec that program soon, but we need to have |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
214 |
// a socket to talk to it with. So we create a local interprocess (Unix) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
215 |
// socket for that purpose. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
216 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
217 |
int sock = socket (PF_UNIX, SOCK_DGRAM, 0); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
218 |
if (sock == -1) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
219 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
220 |
NS_FATAL_ERROR ("TapBridge::CreateTap(): Unix socket creation error, errno = " << strerror (errno)); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
221 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
222 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
223 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
224 |
// Bind to that socket and let the kernel allocate an endpoint |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
225 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
226 |
struct sockaddr_un un; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
227 |
memset (&un, 0, sizeof (un)); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
228 |
un.sun_family = AF_UNIX; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
229 |
int status = bind (sock, (struct sockaddr*)&un, sizeof (sa_family_t)); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
230 |
if (status == -1) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
231 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
232 |
NS_FATAL_ERROR ("TapBridge::CreateTap(): Could not bind(): errno = " << strerror (errno)); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
233 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
234 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
235 |
NS_LOG_INFO ("Created Unix socket"); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
236 |
NS_LOG_INFO ("sun_family = " << un.sun_family); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
237 |
NS_LOG_INFO ("sun_path = " << un.sun_path); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
238 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
239 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
240 |
// We have a socket here, but we want to get it there -- to the program we're |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
241 |
// going to exec. What we'll do is to do a getsockname and then encode the |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
242 |
// resulting address information as a string, and then send the string to the |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
243 |
// program as an argument. So we need to get the sock name. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
244 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
245 |
socklen_t len = sizeof (un); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
246 |
status = getsockname (sock, (struct sockaddr*)&un, &len); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
247 |
if (status == -1) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
248 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
249 |
NS_FATAL_ERROR ("TapBridge::CreateTap(): Could not getsockname(): errno = " << strerror (errno)); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
250 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
251 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
252 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
253 |
// Now encode that socket name (family and path) as a string of hex digits |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
254 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
255 |
std::string path = TapBufferToString((uint8_t *)&un, len); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
256 |
NS_LOG_INFO ("Encoded Unix socket as \"" << path << "\""); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
257 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
258 |
// Fork and exec the process to create our socket. If we're us (the parent) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
259 |
// we wait for the child (the creator) to complete and read the socket it created using the ancillary data mechanism. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
260 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
261 |
pid_t pid = ::fork (); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
262 |
if (pid == 0) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
263 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
264 |
NS_LOG_DEBUG ("Child process"); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
265 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
266 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
267 |
// build a command line argument from the encoded endpoint string that |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
268 |
// the socket creation process will use to figure out how to respond to |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
269 |
// the (now) parent process. We're going to have to give this program |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
270 |
// quite a bit of information. |
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
271 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
272 |
// -d<device-name> The name of the tap device we want to create; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
273 |
// -g<gateway-address> The IP address to use as the default gateway; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
274 |
// -i<IP-address> The IP address to assign to the new tap device; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
275 |
// -m<MAC-address> The MAC-48 address to assign to the new tap device; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
276 |
// -n<network-mask> The network mask to assign to the new tap device; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
277 |
// -p<path> the path to the unix socket described above. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
278 |
// |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
279 |
// Example tap-creator -dnewdev -g1.2.3.2 -i1.2.3.1 -m08:00:2e:00:01:23 -n255.255.255.0 -pblah |
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
280 |
// |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
281 |
// We want to get as much of this stuff automagically as possible. |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
282 |
// |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
283 |
// <IP-address> is the IP address we are going to set in the newly |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
284 |
// created Tap device on the Linux host. At the point in the simulation |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
285 |
// where devices are coming up, we should have all of our IP addresses |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
286 |
// assigned. That means that we can find the IP address to assign to |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
287 |
// the new Tap device from the IP address associated with the bridged |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
288 |
// net device. |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
289 |
// |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
290 |
Ptr<NetDevice> nd = GetBridgedNetDevice (); |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
291 |
Ptr<Node> n = nd->GetNode (); |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
292 |
Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> (); |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
293 |
uint32_t index = ipv4->FindInterfaceForDevice (nd); |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
294 |
Ipv4Address ipv4Address = ipv4->GetAddress (index); |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
295 |
|
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
296 |
// |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
297 |
// The net mask is sitting right there next to the ipv4 address. |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
298 |
// |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
299 |
Ipv4Mask ipv4Mask = ipv4->GetNetworkMask (index); |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
300 |
|
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
301 |
// |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
302 |
// The MAC address should also already be assigned and waiting for us in |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
303 |
// the bridged net device. |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
304 |
// |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
305 |
Address address = nd->GetAddress (); |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
306 |
Mac48Address mac48Address = Mac48Address::ConvertFrom (address); |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
307 |
|
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
308 |
// |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
309 |
// The device-name is something we may want the system to make up in |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
310 |
// every case. We also rely on it being configured via an Attribute |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
311 |
// through the helper. By default, it is set to the empty string |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
312 |
// which tells the system to make up a device name such as "tap123". |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
313 |
// |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
314 |
std::ostringstream ossDeviceName; |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
315 |
ossDeviceName << "-d" << m_tapDeviceName; |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
316 |
|
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
317 |
// |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
318 |
// The gateway-address is something we can't derive, so we rely on it |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
319 |
// being configured via an Attribute through the helper. |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
320 |
// |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
321 |
std::ostringstream ossGateway; |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
322 |
ossGateway << "-g" << m_tapGateway; |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
323 |
|
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
324 |
// |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
325 |
// For flexibility, we do allow a client to override any of the values |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
326 |
// above via attributes, so only use our found values if the Attribute |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
327 |
// is not equal to its default value (empty string or broadcast address). |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
328 |
// |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
329 |
std::ostringstream ossIp; |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
330 |
if (m_tapIp.IsBroadcast ()) |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
331 |
{ |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
332 |
ossIp << "-i" << ipv4Address; |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
333 |
} |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
334 |
else |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
335 |
{ |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
336 |
ossIp << "-i" << m_tapIp; |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
337 |
} |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
338 |
|
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
339 |
std::ostringstream ossMac; |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
340 |
if (m_tapMac.IsBroadcast ()) |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
341 |
{ |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
342 |
ossMac << "-m" << mac48Address; |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
343 |
} |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
344 |
else |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
345 |
{ |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
346 |
ossMac << "-m" << m_tapMac; |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
347 |
} |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
348 |
|
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
349 |
std::ostringstream ossNetmask; |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
350 |
if (m_tapNetmask.IsEqual (Ipv4Mask::GetOnes ())) |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
351 |
{ |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
352 |
ossNetmask << "-n" << ipv4Mask; |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
353 |
} |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
354 |
else |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
355 |
{ |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
356 |
ossNetmask << "-n" << m_tapNetmask; |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
357 |
} |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
358 |
|
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
359 |
std::ostringstream ossPath; |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
360 |
ossPath << "-p" << path; |
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
361 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
362 |
// Execute the socket creation process image. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
363 |
// |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
364 |
status = ::execl (FindCreator ("tap-creator").c_str (), |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
365 |
FindCreator ("tap-creator").c_str (), // argv[0] (filename) |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
366 |
ossDeviceName.str ().c_str (), // argv[1] (-d<device name>) |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
367 |
ossGateway.str ().c_str (), // argv[2] (-g<gateway>) |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
368 |
ossIp.str ().c_str (), // argv[3] (-i<IP address>) |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
369 |
ossMac.str ().c_str (), // argv[4] (-m<MAC address>) |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
370 |
ossNetmask.str ().c_str (), // argv[5] (-n<net mask>) |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
371 |
ossPath.str ().c_str (), // argv[6] (-p<path>) |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
372 |
(char *)NULL); |
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
373 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
374 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
375 |
// If the execl successfully completes, it never returns. If it returns it failed or the OS is |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
376 |
// broken. In either case, we bail. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
377 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
378 |
NS_FATAL_ERROR ("TapBridge::CreateTap(): Back from execl(), errno = " << ::strerror (errno)); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
379 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
380 |
else |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
381 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
382 |
NS_LOG_DEBUG ("Parent process"); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
383 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
384 |
// We're the process running the emu net device. We need to wait for the |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
385 |
// socket creator process to finish its job. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
386 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
387 |
int st; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
388 |
pid_t waited = waitpid (pid, &st, 0); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
389 |
if (waited == -1) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
390 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
391 |
NS_FATAL_ERROR ("TapBridge::CreateTap(): waitpid() fails, errno = " << strerror (errno)); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
392 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
393 |
NS_ASSERT_MSG (pid == waited, "TapBridge::CreateTap(): pid mismatch"); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
394 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
395 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
396 |
// Check to see if the socket creator exited normally and then take a |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
397 |
// look at the exit code. If it bailed, so should we. If it didn't |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
398 |
// even exit normally, we bail too. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
399 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
400 |
if (WIFEXITED (st)) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
401 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
402 |
int exitStatus = WEXITSTATUS (st); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
403 |
if (exitStatus != 0) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
404 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
405 |
NS_FATAL_ERROR ("TapBridge::CreateTap(): socket creator exited normally with status " << exitStatus); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
406 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
407 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
408 |
else |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
409 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
410 |
NS_FATAL_ERROR ("TapBridge::CreateTap(): socket creator exited abnormally"); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
411 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
412 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
413 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
414 |
// At this point, the socket creator has run successfully and should |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
415 |
// have created our tap device, initialized it with the information we |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
416 |
// passed and sent it back to the socket address we provided. A socket |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
417 |
// (fd) we can use to talk to this tap device should be waiting on the |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
418 |
// Unix socket we set up to receive information back from the creator |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
419 |
// program. We've got to do a bunch of grunt work to get at it, though. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
420 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
421 |
// The struct iovec below is part of a scatter-gather list. It describes a |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
422 |
// buffer. In this case, it describes a buffer (an integer) that will |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
423 |
// get the data that comes back from the socket creator process. It will |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
424 |
// be a magic number that we use as a consistency/sanity check. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
425 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
426 |
struct iovec iov; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
427 |
uint32_t magic; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
428 |
iov.iov_base = &magic; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
429 |
iov.iov_len = sizeof(magic); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
430 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
431 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
432 |
// The CMSG macros you'll see below are used to create and access control |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
433 |
// messages (which is another name for ancillary data). The ancillary |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
434 |
// data is made up of pairs of struct cmsghdr structures and associated |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
435 |
// data arrays. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
436 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
437 |
// First, we're going to allocate a buffer on the stack to receive our |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
438 |
// data array (that contains the socket). Sometimes you'll see this called |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
439 |
// an "ancillary element" but the msghdr uses the control message termimology |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
440 |
// so we call it "control." |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
441 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
442 |
size_t msg_size = sizeof(int); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
443 |
char control[CMSG_SPACE(msg_size)]; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
444 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
445 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
446 |
// There is a msghdr that is used to minimize the number of parameters |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
447 |
// passed to recvmsg (which we will use to receive our ancillary data). |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
448 |
// This structure uses terminology corresponding to control messages, so |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
449 |
// you'll see msg_control, which is the pointer to the ancillary data and |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
450 |
// controllen which is the size of the ancillary data array. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
451 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
452 |
// So, initialize the message header that describes the ancillary/control |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
453 |
// data we expect to receive and point it to buffer. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
454 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
455 |
struct msghdr msg; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
456 |
msg.msg_name = 0; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
457 |
msg.msg_namelen = 0; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
458 |
msg.msg_iov = &iov; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
459 |
msg.msg_iovlen = 1; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
460 |
msg.msg_control = control; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
461 |
msg.msg_controllen = sizeof (control); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
462 |
msg.msg_flags = 0; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
463 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
464 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
465 |
// Now we can actually receive the interesting bits from the tap |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
466 |
// creator process. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
467 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
468 |
ssize_t bytesRead = recvmsg (sock, &msg, 0); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
469 |
if (bytesRead != sizeof(int)) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
470 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
471 |
NS_FATAL_ERROR ("TapBridge::CreateTap(): Wrong byte count from socket creator"); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
472 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
473 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
474 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
475 |
// There may be a number of message headers/ancillary data arrays coming in. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
476 |
// Let's look for the one with a type SCM_RIGHTS which indicates it' the |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
477 |
// one we're interested in. |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
478 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
479 |
struct cmsghdr *cmsg; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
480 |
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
481 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
482 |
if (cmsg->cmsg_level == SOL_SOCKET && |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
483 |
cmsg->cmsg_type == SCM_RIGHTS) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
484 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
485 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
486 |
// This is the type of message we want. Check to see if the magic |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
487 |
// number is correct and then pull out the socket we care about if |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
488 |
// it matches |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
489 |
// |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
490 |
if (magic == TAP_MAGIC) |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
491 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
492 |
NS_LOG_INFO ("Got SCM_RIGHTS with correct magic " << magic); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
493 |
int *rawSocket = (int*)CMSG_DATA (cmsg); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
494 |
NS_LOG_INFO ("Got the socket from the socket creator = " << *rawSocket); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
495 |
m_sock = *rawSocket; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
496 |
return; |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
497 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
498 |
else |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
499 |
{ |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
500 |
NS_LOG_INFO ("Got SCM_RIGHTS, but with bad magic " << magic); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
501 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
502 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
503 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
504 |
NS_FATAL_ERROR ("Did not get the raw socket from the socket creator"); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
505 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
506 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
507 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
508 |
std::string |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
509 |
TapBridge::FindCreator (std::string creatorName) |
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
510 |
{ |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
511 |
NS_LOG_FUNCTION (creatorName); |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
512 |
|
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
513 |
std::list<std::string> locations; |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
514 |
|
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
515 |
// in repo |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
516 |
locations.push_back ("./build/optimized/src/devices/tap-bridge/"); |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
517 |
locations.push_back ("./build/debug/src/devices/tap-bridge/"); |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
518 |
|
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
519 |
// in src |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
520 |
locations.push_back ("../build/optimized/src/devices/tap-bridge/"); |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
521 |
locations.push_back ("../build/debug/src/devices/tap-bridge/"); |
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
522 |
|
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
523 |
// in src/devices |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
524 |
locations.push_back ("../../build/optimized/src/devices/tap-bridge/"); |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
525 |
locations.push_back ("../../build/debug/src/devices/tap-bridge/"); |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
526 |
|
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
527 |
// in src/devices/tap-bridge |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
528 |
locations.push_back ("../../../build/optimized/src/devices/tap-bridge/"); |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
529 |
locations.push_back ("../../../build/debug/src/devices/tap-bridge/"); |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
530 |
|
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
531 |
for (std::list<std::string>::const_iterator i = locations.begin (); i != locations.end (); ++i) |
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
532 |
{ |
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
533 |
struct stat st; |
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
534 |
|
4168
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
535 |
if (::stat ((*i + creatorName).c_str (), &st) == 0) |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
536 |
{ |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
537 |
NS_LOG_INFO ("Found Creator " << *i + creatorName); |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
538 |
return *i + creatorName; |
3d8f0d101f79
last connections on tap-bridge, start flowing packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4167
diff
changeset
|
539 |
} |
4164
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
540 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
541 |
|
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
542 |
NS_FATAL_ERROR ("TapBridge::FindCreator(): Couldn't find creator"); |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
543 |
return ""; // quiet compiler |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
544 |
} |
1f6ae48061a9
checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4163
diff
changeset
|
545 |
|
4165 | 546 |
void |
547 |
TapBridge::ReadThread (void) |
|
548 |
{ |
|
549 |
NS_LOG_FUNCTION_NOARGS (); |
|
550 |
||
551 |
// |
|
552 |
// It's important to remember that we're in a completely different thread than the simulator is running in. We |
|
553 |
// need to synchronize with that other thread to get the packet up into ns-3. What we will need to do is to schedule |
|
554 |
// a method to deal with the packet using the multithreaded simulator we are most certainly running. However, I just |
|
555 |
// said it -- we are talking about two threads here, so it is very, very dangerous to do any kind of reference couning |
|
556 |
// on a shared object. Just don't do it. So what we're going to do is to allocate a buffer on the heap and pass that |
|
557 |
// buffer into the ns-3 context thread where it will create the packet. |
|
558 |
// |
|
559 |
int32_t len = -1; |
|
560 |
||
561 |
for (;;) |
|
562 |
{ |
|
563 |
uint32_t bufferSize = 65536; |
|
564 |
uint8_t *buf = (uint8_t *)malloc (bufferSize); |
|
565 |
if (buf == 0) |
|
566 |
{ |
|
567 |
NS_FATAL_ERROR ("TapBridge::ReadThread(): malloc packet buffer failed"); |
|
568 |
} |
|
569 |
||
570 |
NS_LOG_LOGIC ("Calling read on tap device socket fd"); |
|
571 |
len = read (m_sock, buf, bufferSize); |
|
572 |
||
573 |
if (len == -1) |
|
574 |
{ |
|
575 |
free (buf); |
|
576 |
buf = 0; |
|
577 |
return; |
|
578 |
} |
|
579 |
||
580 |
NS_LOG_INFO ("TapBridge::ReadThread(): Received packet"); |
|
581 |
NS_LOG_INFO ("TapBridge::ReadThread(): Scheduling handler"); |
|
582 |
DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ())->ScheduleRealtimeNow ( |
|
583 |
MakeEvent (&TapBridge::ForwardToBridgedDevice, this, buf, len)); |
|
584 |
buf = 0; |
|
585 |
} |
|
586 |
} |
|
587 |
||
588 |
void |
|
589 |
TapBridge::ForwardToBridgedDevice (uint8_t *buf, uint32_t len) |
|
590 |
{ |
|
591 |
NS_LOG_FUNCTION (buf << len); |
|
592 |
||
593 |
// |
|
594 |
// Create a packet out of the buffer we received and free that buffer. |
|
595 |
// |
|
596 |
Ptr<Packet> packet = Create<Packet> (reinterpret_cast<const uint8_t *> (buf), len); |
|
597 |
free (buf); |
|
598 |
buf = 0; |
|
599 |
||
600 |
// |
|
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
601 |
// Make sure the packet we received is reasonable enough for the rest of the |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
602 |
// system to handle and get it ready to be injected directly into an ns-3 |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
603 |
// device. What should come back is a packet with the Ethernet header |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
604 |
// (and possibly an LLC header as well) stripped off. |
4165 | 605 |
// |
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
606 |
Address src, dst; |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
607 |
uint16_t type; |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
608 |
|
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
609 |
NS_LOG_LOGIC ("Received packet from tap device"); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
610 |
|
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
611 |
Ptr<Packet> p = Filter (packet, &src, &dst, &type); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
612 |
if (p == 0) |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
613 |
{ |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
614 |
NS_LOG_LOGIC ("Discarding packet as unfit for ns-3 consumption"); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
615 |
return; |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
616 |
} |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
617 |
|
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
618 |
NS_LOG_LOGIC ("Pkt source is " << src); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
619 |
NS_LOG_LOGIC ("Pkt destination is " << dst); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
620 |
NS_LOG_LOGIC ("Pkt LengthType is " << type); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
621 |
|
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
622 |
NS_LOG_LOGIC ("Forwarding packet"); |
4178
bd8625e5913a
no need to do SendFrom in tap-bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4173
diff
changeset
|
623 |
#if 0 |
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
624 |
m_bridgedDevice->SendFrom (packet, src, dst, type); |
4178
bd8625e5913a
no need to do SendFrom in tap-bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4173
diff
changeset
|
625 |
#else |
bd8625e5913a
no need to do SendFrom in tap-bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4173
diff
changeset
|
626 |
m_bridgedDevice->Send (packet, dst, type); |
bd8625e5913a
no need to do SendFrom in tap-bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
4173
diff
changeset
|
627 |
#endif |
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
628 |
} |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
629 |
|
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
630 |
Ptr<Packet> |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
631 |
TapBridge::Filter (Ptr<Packet> p, Address *src, Address *dst, uint16_t *type) |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
632 |
{ |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
633 |
NS_LOG_FUNCTION (p); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
634 |
uint32_t pktSize; |
4165 | 635 |
|
636 |
// |
|
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
637 |
// We have a candidate packet for injection into ns-3. We expect that since |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
638 |
// it came over a socket that provides Ethernet packets, it sould be big |
4170
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
639 |
// enough to hold an EthernetHeader. If it can't, we signify the packet |
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
640 |
// should be filtered out by returning 0. |
4165 | 641 |
// |
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
642 |
pktSize = p->GetSize (); |
4165 | 643 |
EthernetHeader header (false); |
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
644 |
if (pktSize < header.GetSerializedSize ()) |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
645 |
{ |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
646 |
return 0; |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
647 |
} |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
648 |
|
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
649 |
p->RemoveHeader (header); |
4165 | 650 |
|
651 |
NS_LOG_LOGIC ("Pkt source is " << header.GetSource ()); |
|
652 |
NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ()); |
|
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
653 |
NS_LOG_LOGIC ("Pkt LengthType is " << header.GetLengthType ()); |
4165 | 654 |
|
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
655 |
// |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
656 |
// If the length/type is less than 1500, it corresponds to a length |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
657 |
// interpretation packet. In this case, it is an 802.3 packet and |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
658 |
// will also have an 802.2 LLC header. If greater than 1500, we |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
659 |
// find the protocol number (Ethernet type) directly. |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
660 |
// |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
661 |
if (header.GetLengthType () <= 1500) |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
662 |
{ |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
663 |
*src = header.GetSource (); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
664 |
*dst = header.GetDestination (); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
665 |
|
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
666 |
pktSize = p->GetSize (); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
667 |
LlcSnapHeader llc; |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
668 |
if (pktSize < llc.GetSerializedSize ()) |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
669 |
{ |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
670 |
return 0; |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
671 |
} |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
672 |
|
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
673 |
p->RemoveHeader (llc); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
674 |
*type = llc.GetType (); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
675 |
} |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
676 |
else |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
677 |
{ |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
678 |
*src = header.GetSource (); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
679 |
*dst = header.GetDestination (); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
680 |
*type = header.GetLengthType (); |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
681 |
} |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
682 |
|
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
683 |
// |
4170
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
684 |
// What we give back is a packet without the Ethernet header (nor the |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
685 |
// possible llc/snap header) on it. We think it is ready to send on |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
686 |
// out the bridged net device. |
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
687 |
// |
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
688 |
return p; |
4165 | 689 |
} |
690 |
||
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
691 |
Ptr<NetDevice> |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
692 |
TapBridge::GetBridgedNetDevice (void) |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
693 |
{ |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
694 |
NS_LOG_FUNCTION_NOARGS (); |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
695 |
return m_bridgedDevice; |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
696 |
} |
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
697 |
|
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
698 |
void |
4167
7e444dc749ee
wire needed values into tap-bridge Attribute system, but figure out as many as possible in the default case
Craig Dowell <craigdo@ee.washington.edu>
parents:
4166
diff
changeset
|
699 |
TapBridge::SetBridgedNetDevice (Ptr<NetDevice> bridgedDevice) |
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
700 |
{ |
4169
d966e2ded46d
checkpoint tap progress
Craig Dowell <craigdo@ee.washington.edu>
parents:
4168
diff
changeset
|
701 |
NS_LOG_FUNCTION (bridgedDevice); |
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
702 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
703 |
NS_ASSERT_MSG (m_node != 0, "TapBridge::SetBridgedDevice: Bridge not installed in a node"); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
704 |
NS_ASSERT_MSG (bridgedDevice != this, "TapBridge::SetBridgedDevice: Cannot bridge to self"); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
705 |
NS_ASSERT_MSG (m_bridgedDevice == 0, "TapBridge::SetBridgedDevice: Already bridged"); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
706 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
707 |
if (!Mac48Address::IsMatchingType (bridgedDevice->GetAddress ())) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
708 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
709 |
NS_FATAL_ERROR ("TapBridge::SetBridgedDevice: Device does not support eui 48 addresses: cannot be added to bridge."); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
710 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
711 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
712 |
if (!bridgedDevice->SupportsSendFrom ()) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
713 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
714 |
NS_FATAL_ERROR ("TapBridge::SetBridgedDevice: Device does not support SendFrom: cannot be added to bridge."); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
715 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
716 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
717 |
// |
4170
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
718 |
// Tell the bridged device to forward its received packets here. We use the |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
719 |
// promiscuous mode hook to get both the source and destination addresses. |
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
720 |
// |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
721 |
m_node->RegisterProtocolHandler (MakeCallback (&TapBridge::ReceiveFromBridgedDevice, this), 0, bridgedDevice, true); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
722 |
m_bridgedDevice = bridgedDevice; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
723 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
724 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
725 |
void |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
726 |
TapBridge::ReceiveFromBridgedDevice ( |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
727 |
Ptr<NetDevice> device, |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
728 |
Ptr<const Packet> packet, |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
729 |
uint16_t protocol, |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
730 |
Address const &src, |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
731 |
Address const &dst, |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
732 |
PacketType packetType) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
733 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
734 |
NS_LOG_FUNCTION (device << packet << protocol << src << dst << packetType); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
735 |
NS_ASSERT_MSG (device == m_bridgedDevice, "TapBridge::SetBridgedDevice: Received packet from unexpected device"); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
736 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
737 |
NS_LOG_DEBUG ("Packet UID is " << packet->GetUid ()); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
738 |
|
4165 | 739 |
Mac48Address from = Mac48Address::ConvertFrom (src); |
740 |
Mac48Address to = Mac48Address::ConvertFrom (dst); |
|
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
741 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
742 |
// |
4170
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
743 |
// We hooked the promiscuous mode protocol handler so we could get the |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
744 |
// destination address of the actual packet. This means we will be getting |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
745 |
// PACKET_OTHERHOST packets (not broadcast, not multicast, not unicast to |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
746 |
// this device, but to some other address). We don't want to forward those |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
747 |
// PACKET_OTHERHOST packets so just ignore them |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
748 |
// |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
749 |
if (packetType == PACKET_OTHERHOST) |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
750 |
{ |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
751 |
return; |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
752 |
} |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
753 |
|
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
754 |
// |
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
755 |
// We have received a packet from the ns-3 net device that has been associated |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
756 |
// with this bridge. We want to take these bits and send them off to the |
4165 | 757 |
// Tap device on the Linux host. Once we do this, the bits in the packet will |
758 |
// percolate up through the stack on the Linux host. |
|
759 |
// |
|
760 |
// The ns-3 net device that is the source of these bits has removed the MAC |
|
761 |
// header, so we have to put one back on. |
|
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
762 |
// |
4165 | 763 |
Ptr<Packet> p = packet->Copy (); |
4170
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
764 |
|
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
765 |
|
4165 | 766 |
EthernetHeader header = EthernetHeader (false); |
767 |
header.SetSource (from); |
|
768 |
header.SetDestination (to); |
|
4170
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
769 |
header.SetLengthType (protocol); |
4165 | 770 |
p->AddHeader (header); |
771 |
||
4170
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
772 |
NS_LOG_LOGIC ("Writing packet to Linux host"); |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
773 |
NS_LOG_LOGIC ("Pkt source is " << header.GetSource ()); |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
774 |
NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ()); |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
775 |
NS_LOG_LOGIC ("Pkt LengthType is " << header.GetLengthType ()); |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
776 |
NS_LOG_LOGIC ("Pkt size is " << p->GetSize ()); |
8e5bdeb6a71b
turn on checksums in example csma-tap-bridge and tweaks to make ping demo work
Craig Dowell <craigdo@ee.washington.edu>
parents:
4169
diff
changeset
|
777 |
|
4165 | 778 |
write (m_sock, p->PeekData (), p->GetSize ()); |
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
779 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
780 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
781 |
void |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
782 |
TapBridge::SetName(const std::string name) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
783 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
784 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
785 |
m_name = name; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
786 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
787 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
788 |
std::string |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
789 |
TapBridge::GetName(void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
790 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
791 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
792 |
return m_name; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
793 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
794 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
795 |
void |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
796 |
TapBridge::SetIfIndex(const uint32_t index) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
797 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
798 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
799 |
m_ifIndex = index; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
800 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
801 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
802 |
uint32_t |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
803 |
TapBridge::GetIfIndex(void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
804 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
805 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
806 |
return m_ifIndex; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
807 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
808 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
809 |
Ptr<Channel> |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
810 |
TapBridge::GetChannel (void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
811 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
812 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
813 |
return 0; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
814 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
815 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
816 |
Address |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
817 |
TapBridge::GetAddress (void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
818 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
819 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
820 |
return m_address; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
821 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
822 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
823 |
bool |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
824 |
TapBridge::SetMtu (const uint16_t mtu) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
825 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
826 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
827 |
m_mtu = mtu; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
828 |
return true; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
829 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
830 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
831 |
uint16_t |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
832 |
TapBridge::GetMtu (void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
833 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
834 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
835 |
return m_mtu; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
836 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
837 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
838 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
839 |
bool |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
840 |
TapBridge::IsLinkUp (void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
841 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
842 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
843 |
return true; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
844 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
845 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
846 |
void |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
847 |
TapBridge::SetLinkChangeCallback (Callback<void> callback) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
848 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
849 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
850 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
851 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
852 |
bool |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
853 |
TapBridge::IsBroadcast (void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
854 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
855 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
856 |
return true; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
857 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
858 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
859 |
Address |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
860 |
TapBridge::GetBroadcast (void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
861 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
862 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
863 |
return Mac48Address ("ff:ff:ff:ff:ff:ff"); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
864 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
865 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
866 |
bool |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
867 |
TapBridge::IsMulticast (void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
868 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
869 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
870 |
return true; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
871 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
872 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
873 |
Address |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
874 |
TapBridge::GetMulticast (Ipv4Address multicastGroup) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
875 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
876 |
NS_LOG_FUNCTION (this << multicastGroup); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
877 |
Mac48Address multicast = Mac48Address::GetMulticast (multicastGroup); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
878 |
return multicast; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
879 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
880 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
881 |
bool |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
882 |
TapBridge::IsPointToPoint (void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
883 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
884 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
885 |
return false; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
886 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
887 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
888 |
bool |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
889 |
TapBridge::IsBridge (void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
890 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
891 |
NS_LOG_FUNCTION_NOARGS (); |
4173
a7983f5acf98
add a more complicated tap example that uses routing.
Craig Dowell <craigdo@ee.washington.edu>
parents:
4170
diff
changeset
|
892 |
// |
a7983f5acf98
add a more complicated tap example that uses routing.
Craig Dowell <craigdo@ee.washington.edu>
parents:
4170
diff
changeset
|
893 |
// Returning false from IsBridge in a device called TapBridge may seem odd |
a7983f5acf98
add a more complicated tap example that uses routing.
Craig Dowell <craigdo@ee.washington.edu>
parents:
4170
diff
changeset
|
894 |
// at first glance, but this test is for a device that bridges ns-3 devices |
a7983f5acf98
add a more complicated tap example that uses routing.
Craig Dowell <craigdo@ee.washington.edu>
parents:
4170
diff
changeset
|
895 |
// together. The Tap bridge doesn't do that -- it bridges an ns-3 device to |
a7983f5acf98
add a more complicated tap example that uses routing.
Craig Dowell <craigdo@ee.washington.edu>
parents:
4170
diff
changeset
|
896 |
// a Linux device. This is a completely different story. |
a7983f5acf98
add a more complicated tap example that uses routing.
Craig Dowell <craigdo@ee.washington.edu>
parents:
4170
diff
changeset
|
897 |
// |
a7983f5acf98
add a more complicated tap example that uses routing.
Craig Dowell <craigdo@ee.washington.edu>
parents:
4170
diff
changeset
|
898 |
return false; |
4163
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
899 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
900 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
901 |
bool |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
902 |
TapBridge::Send (Ptr<Packet> packet, const Address& dst, uint16_t protocol) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
903 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
904 |
NS_LOG_FUNCTION (packet << dst << protocol); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
905 |
NS_FATAL_ERROR ("TapBridge::Send: You may not call Send on a TapBridge directly"); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
906 |
return false; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
907 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
908 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
909 |
bool |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
910 |
TapBridge::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dst, uint16_t protocol) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
911 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
912 |
NS_LOG_FUNCTION (packet << src << dst << protocol); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
913 |
NS_FATAL_ERROR ("TapBridge::Send: You may not call SendFrom on a TapBridge directly"); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
914 |
return false; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
915 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
916 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
917 |
Ptr<Node> |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
918 |
TapBridge::GetNode (void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
919 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
920 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
921 |
return m_node; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
922 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
923 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
924 |
void |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
925 |
TapBridge::SetNode (Ptr<Node> node) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
926 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
927 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
928 |
m_node = node; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
929 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
930 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
931 |
bool |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
932 |
TapBridge::NeedsArp (void) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
933 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
934 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
935 |
return true; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
936 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
937 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
938 |
void |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
939 |
TapBridge::SetReceiveCallback (NetDevice::ReceiveCallback cb) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
940 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
941 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
942 |
m_rxCallback = cb; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
943 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
944 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
945 |
void |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
946 |
TapBridge::SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb) |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
947 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
948 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
949 |
m_promiscRxCallback = cb; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
950 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
951 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
952 |
bool |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
953 |
TapBridge::SupportsSendFrom () const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
954 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
955 |
NS_LOG_FUNCTION_NOARGS (); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
956 |
return true; |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
957 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
958 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
959 |
Address TapBridge::GetMulticast (Ipv6Address addr) const |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
960 |
{ |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
961 |
NS_LOG_FUNCTION (this << addr); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
962 |
return Mac48Address::GetMulticast (addr); |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
963 |
} |
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
964 |
|
8c48682b3d42
checkpoint tap development
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
965 |
} // namespace ns3 |