tap-bridge: (merges !114) Add verbose attribute to call tap creator with -v

* add Verbose attribute to TapBridge to call tap creator with the -v option
* adds "this" to NS_FUNCTION_LOG calls in TapBridge
* add branch on tap creator call to check if call exited with a signal
This commit is contained in:
Jared Dulmage
2019-10-09 12:36:52 -06:00
committed by Tom Henderson
parent 7f9fe95dd5
commit 564a98a7ec
2 changed files with 77 additions and 42 deletions

View File

@@ -52,7 +52,7 @@ NS_LOG_COMPONENT_DEFINE ("TapBridge");
FdReader::Data TapBridgeFdReader::DoRead (void) FdReader::Data TapBridgeFdReader::DoRead (void)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
uint32_t bufferSize = 65536; uint32_t bufferSize = 65536;
uint8_t *buf = (uint8_t *)std::malloc (bufferSize); uint8_t *buf = (uint8_t *)std::malloc (bufferSize);
@@ -132,6 +132,11 @@ TapBridge::GetTypeId (void)
MakeEnumChecker (CONFIGURE_LOCAL, "ConfigureLocal", MakeEnumChecker (CONFIGURE_LOCAL, "ConfigureLocal",
USE_LOCAL, "UseLocal", USE_LOCAL, "UseLocal",
USE_BRIDGE, "UseBridge")) USE_BRIDGE, "UseBridge"))
.AddAttribute ("Verbose",
"Enable verbose output from tap-creator child process",
BooleanValue (false),
MakeBooleanAccessor (&TapBridge::m_verbose),
MakeBooleanChecker ())
; ;
return tid; return tid;
} }
@@ -145,14 +150,14 @@ TapBridge::TapBridge ()
m_fdReader (0), m_fdReader (0),
m_ns3AddressRewritten (false) m_ns3AddressRewritten (false)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
m_packetBuffer = new uint8_t[65536]; m_packetBuffer = new uint8_t[65536];
Start (m_tStart); Start (m_tStart);
} }
TapBridge::~TapBridge() TapBridge::~TapBridge()
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
StopTapDevice (); StopTapDevice ();
@@ -165,14 +170,14 @@ TapBridge::~TapBridge()
void void
TapBridge::DoDispose () TapBridge::DoDispose ()
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
NetDevice::DoDispose (); NetDevice::DoDispose ();
} }
void void
TapBridge::Start (Time tStart) TapBridge::Start (Time tStart)
{ {
NS_LOG_FUNCTION (tStart); NS_LOG_FUNCTION (this << tStart);
// //
// Cancel any pending start event and schedule a new one at some relative time in the future. // Cancel any pending start event and schedule a new one at some relative time in the future.
@@ -184,7 +189,7 @@ TapBridge::Start (Time tStart)
void void
TapBridge::Stop (Time tStop) TapBridge::Stop (Time tStop)
{ {
NS_LOG_FUNCTION (tStop); NS_LOG_FUNCTION (this << tStop);
// //
// Cancel any pending stop event and schedule a new one at some relative time in the future. // Cancel any pending stop event and schedule a new one at some relative time in the future.
// //
@@ -195,7 +200,7 @@ TapBridge::Stop (Time tStop)
void void
TapBridge::StartTapDevice (void) TapBridge::StartTapDevice (void)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
NS_ABORT_MSG_IF (m_sock != -1, "TapBridge::StartTapDevice(): Tap is already started"); NS_ABORT_MSG_IF (m_sock != -1, "TapBridge::StartTapDevice(): Tap is already started");
@@ -237,7 +242,7 @@ TapBridge::StartTapDevice (void)
void void
TapBridge::StopTapDevice (void) TapBridge::StopTapDevice (void)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
if (m_fdReader != 0) if (m_fdReader != 0)
{ {
@@ -255,7 +260,7 @@ TapBridge::StopTapDevice (void)
void void
TapBridge::CreateTap (void) TapBridge::CreateTap (void)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
// //
// The TapBridge has three distinct operating modes. At this point, the // The TapBridge has three distinct operating modes. At this point, the
@@ -488,13 +493,31 @@ TapBridge::CreateTap (void)
ossMode << "3"; ossMode << "3";
} }
std::ostringstream ossVerbose;
if (m_verbose)
{
ossVerbose << "-v";
}
std::ostringstream ossPath; std::ostringstream ossPath;
ossPath << "-p" << path; ossPath << "-p" << path;
NS_LOG_DEBUG ("Executing: " << TAP_CREATOR <<
" " << ossDeviceName.str () <<
" " << ossGateway.str () <<
" " << ossIp.str () <<
" " << ossMac.str () <<
" " << ossNetmask.str () <<
" " << ossMode.str () <<
" " << ossPath.str () <<
" " << ossVerbose.str ()
);
// //
// Execute the socket creation process image. // Execute the socket creation process image.
// //
status = ::execlp (TAP_CREATOR, status = ::execlp (TAP_CREATOR,
TAP_CREATOR, // argv[0] (filename) TAP_CREATOR, // argv[0] (filename)
ossDeviceName.str ().c_str (), // argv[1] (-d<device name>) ossDeviceName.str ().c_str (), // argv[1] (-d<device name>)
ossGateway.str ().c_str (), // argv[2] (-g<gateway>) ossGateway.str ().c_str (), // argv[2] (-g<gateway>)
ossIp.str ().c_str (), // argv[3] (-i<IP address>) ossIp.str ().c_str (), // argv[3] (-i<IP address>)
@@ -502,6 +525,7 @@ TapBridge::CreateTap (void)
ossNetmask.str ().c_str (), // argv[5] (-n<net mask>) ossNetmask.str ().c_str (), // argv[5] (-n<net mask>)
ossMode.str ().c_str (), // argv[6] (-o<operating mode>) ossMode.str ().c_str (), // argv[6] (-o<operating mode>)
ossPath.str ().c_str (), // argv[7] (-p<path>) ossPath.str ().c_str (), // argv[7] (-p<path>)
ossVerbose.str ().c_str (), // argv[8] (-v)
(char *)NULL); (char *)NULL);
// //
@@ -534,6 +558,10 @@ TapBridge::CreateTap (void)
NS_ABORT_MSG_IF (exitStatus != 0, NS_ABORT_MSG_IF (exitStatus != 0,
"TapBridge::CreateTap(): socket creator exited normally with status " << exitStatus); "TapBridge::CreateTap(): socket creator exited normally with status " << exitStatus);
} }
else if (WIFSIGNALED (st))
{
NS_FATAL_ERROR ("TapBridge::CreateTap(): socket creator exited with signal " << WTERMSIG (st));
}
else else
{ {
NS_FATAL_ERROR ("TapBridge::CreateTap(): socket creator exited abnormally"); NS_FATAL_ERROR ("TapBridge::CreateTap(): socket creator exited abnormally");
@@ -667,7 +695,7 @@ TapBridge::CreateTap (void)
void void
TapBridge::ReadCallback (uint8_t *buf, ssize_t len) TapBridge::ReadCallback (uint8_t *buf, ssize_t len)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this << buf << len);
NS_ASSERT_MSG (buf != 0, "invalid buf argument"); NS_ASSERT_MSG (buf != 0, "invalid buf argument");
NS_ASSERT_MSG (len > 0, "invalid len argument"); NS_ASSERT_MSG (len > 0, "invalid len argument");
@@ -692,7 +720,7 @@ TapBridge::ReadCallback (uint8_t *buf, ssize_t len)
void void
TapBridge::ForwardToBridgedDevice (uint8_t *buf, ssize_t len) TapBridge::ForwardToBridgedDevice (uint8_t *buf, ssize_t len)
{ {
NS_LOG_FUNCTION (buf << len); NS_LOG_FUNCTION (this << buf << len);
// //
// There are three operating modes for the TapBridge // There are three operating modes for the TapBridge
@@ -819,7 +847,7 @@ TapBridge::ForwardToBridgedDevice (uint8_t *buf, ssize_t len)
Ptr<Packet> Ptr<Packet>
TapBridge::Filter (Ptr<Packet> p, Address *src, Address *dst, uint16_t *type) TapBridge::Filter (Ptr<Packet> p, Address *src, Address *dst, uint16_t *type)
{ {
NS_LOG_FUNCTION (p); NS_LOG_FUNCTION (this << p);
uint32_t pktSize; uint32_t pktSize;
// //
@@ -881,14 +909,14 @@ TapBridge::Filter (Ptr<Packet> p, Address *src, Address *dst, uint16_t *type)
Ptr<NetDevice> Ptr<NetDevice>
TapBridge::GetBridgedNetDevice (void) TapBridge::GetBridgedNetDevice (void)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return m_bridgedDevice; return m_bridgedDevice;
} }
void void
TapBridge::SetBridgedNetDevice (Ptr<NetDevice> bridgedDevice) TapBridge::SetBridgedNetDevice (Ptr<NetDevice> bridgedDevice)
{ {
NS_LOG_FUNCTION (bridgedDevice); NS_LOG_FUNCTION (this << bridgedDevice);
NS_ASSERT_MSG (m_node != 0, "TapBridge::SetBridgedDevice: Bridge not installed in a node"); NS_ASSERT_MSG (m_node != 0, "TapBridge::SetBridgedDevice: Bridge not installed in a node");
NS_ASSERT_MSG (bridgedDevice != this, "TapBridge::SetBridgedDevice: Cannot bridge to self"); NS_ASSERT_MSG (bridgedDevice != this, "TapBridge::SetBridgedDevice: Cannot bridge to self");
@@ -921,7 +949,7 @@ TapBridge::SetBridgedNetDevice (Ptr<NetDevice> bridgedDevice)
bool bool
TapBridge::DiscardFromBridgedDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol, const Address &src) TapBridge::DiscardFromBridgedDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol, const Address &src)
{ {
NS_LOG_FUNCTION (device << packet << protocol << src); NS_LOG_FUNCTION (this << device << packet << protocol << src);
NS_LOG_LOGIC ("Discarding packet stolen from bridged device " << device); NS_LOG_LOGIC ("Discarding packet stolen from bridged device " << device);
return true; return true;
} }
@@ -935,7 +963,7 @@ TapBridge::ReceiveFromBridgedDevice (
const Address &dst, const Address &dst,
PacketType packetType) PacketType packetType)
{ {
NS_LOG_FUNCTION (device << packet << protocol << src << dst << packetType); NS_LOG_FUNCTION (this << device << packet << protocol << src << dst << packetType);
NS_ASSERT_MSG (device == m_bridgedDevice, "TapBridge::SetBridgedDevice: Received packet from unexpected device"); NS_ASSERT_MSG (device == m_bridgedDevice, "TapBridge::SetBridgedDevice: Received packet from unexpected device");
NS_LOG_DEBUG ("Packet UID is " << packet->GetUid ()); NS_LOG_DEBUG ("Packet UID is " << packet->GetUid ());
@@ -1001,56 +1029,56 @@ TapBridge::ReceiveFromBridgedDevice (
void void
TapBridge::SetIfIndex (const uint32_t index) TapBridge::SetIfIndex (const uint32_t index)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this << index);
m_ifIndex = index; m_ifIndex = index;
} }
uint32_t uint32_t
TapBridge::GetIfIndex (void) const TapBridge::GetIfIndex (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return m_ifIndex; return m_ifIndex;
} }
Ptr<Channel> Ptr<Channel>
TapBridge::GetChannel (void) const TapBridge::GetChannel (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return 0; return 0;
} }
void void
TapBridge::SetAddress (Address address) TapBridge::SetAddress (Address address)
{ {
NS_LOG_FUNCTION (address); NS_LOG_FUNCTION (this << address);
m_address = Mac48Address::ConvertFrom (address); m_address = Mac48Address::ConvertFrom (address);
} }
Address Address
TapBridge::GetAddress (void) const TapBridge::GetAddress (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return m_address; return m_address;
} }
void void
TapBridge::SetMode (enum Mode mode) TapBridge::SetMode (enum Mode mode)
{ {
NS_LOG_FUNCTION (mode); NS_LOG_FUNCTION (this << mode);
m_mode = mode; m_mode = mode;
} }
TapBridge::Mode TapBridge::Mode
TapBridge::GetMode (void) TapBridge::GetMode (void)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return m_mode; return m_mode;
} }
bool bool
TapBridge::SetMtu (const uint16_t mtu) TapBridge::SetMtu (const uint16_t mtu)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this << mtu);
m_mtu = mtu; m_mtu = mtu;
return true; return true;
} }
@@ -1058,14 +1086,14 @@ TapBridge::SetMtu (const uint16_t mtu)
uint16_t uint16_t
TapBridge::GetMtu (void) const TapBridge::GetMtu (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return m_mtu; return m_mtu;
} }
void void
TapBridge::NotifyLinkUp (void) TapBridge::NotifyLinkUp (void)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
if (!m_linkUp) if (!m_linkUp)
{ {
m_linkUp = true; m_linkUp = true;
@@ -1076,35 +1104,35 @@ TapBridge::NotifyLinkUp (void)
bool bool
TapBridge::IsLinkUp (void) const TapBridge::IsLinkUp (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return m_linkUp; return m_linkUp;
} }
void void
TapBridge::AddLinkChangeCallback (Callback<void> callback) TapBridge::AddLinkChangeCallback (Callback<void> callback)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
m_linkChangeCallbacks.ConnectWithoutContext (callback); m_linkChangeCallbacks.ConnectWithoutContext (callback);
} }
bool bool
TapBridge::IsBroadcast (void) const TapBridge::IsBroadcast (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return true; return true;
} }
Address Address
TapBridge::GetBroadcast (void) const TapBridge::GetBroadcast (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return Mac48Address ("ff:ff:ff:ff:ff:ff"); return Mac48Address ("ff:ff:ff:ff:ff:ff");
} }
bool bool
TapBridge::IsMulticast (void) const TapBridge::IsMulticast (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return true; return true;
} }
@@ -1119,14 +1147,14 @@ TapBridge::GetMulticast (Ipv4Address multicastGroup) const
bool bool
TapBridge::IsPointToPoint (void) const TapBridge::IsPointToPoint (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return false; return false;
} }
bool bool
TapBridge::IsBridge (void) const TapBridge::IsBridge (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
// //
// Returning false from IsBridge in a device called TapBridge may seem odd // Returning false from IsBridge in a device called TapBridge may seem odd
// at first glance, but this test is for a device that bridges ns-3 devices // at first glance, but this test is for a device that bridges ns-3 devices
@@ -1139,7 +1167,7 @@ TapBridge::IsBridge (void) const
bool bool
TapBridge::Send (Ptr<Packet> packet, const Address& dst, uint16_t protocol) TapBridge::Send (Ptr<Packet> packet, const Address& dst, uint16_t protocol)
{ {
NS_LOG_FUNCTION (packet << dst << protocol); NS_LOG_FUNCTION (this << packet << dst << protocol);
NS_FATAL_ERROR ("TapBridge::Send: You may not call Send on a TapBridge directly"); NS_FATAL_ERROR ("TapBridge::Send: You may not call Send on a TapBridge directly");
return false; return false;
} }
@@ -1147,7 +1175,7 @@ TapBridge::Send (Ptr<Packet> packet, const Address& dst, uint16_t protocol)
bool bool
TapBridge::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dst, uint16_t protocol) TapBridge::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dst, uint16_t protocol)
{ {
NS_LOG_FUNCTION (packet << src << dst << protocol); NS_LOG_FUNCTION (this << packet << src << dst << protocol);
NS_FATAL_ERROR ("TapBridge::Send: You may not call SendFrom on a TapBridge directly"); NS_FATAL_ERROR ("TapBridge::Send: You may not call SendFrom on a TapBridge directly");
return false; return false;
} }
@@ -1155,42 +1183,42 @@ TapBridge::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dst,
Ptr<Node> Ptr<Node>
TapBridge::GetNode (void) const TapBridge::GetNode (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return m_node; return m_node;
} }
void void
TapBridge::SetNode (Ptr<Node> node) TapBridge::SetNode (Ptr<Node> node)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
m_node = node; m_node = node;
} }
bool bool
TapBridge::NeedsArp (void) const TapBridge::NeedsArp (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return true; return true;
} }
void void
TapBridge::SetReceiveCallback (NetDevice::ReceiveCallback cb) TapBridge::SetReceiveCallback (NetDevice::ReceiveCallback cb)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
m_rxCallback = cb; m_rxCallback = cb;
} }
void void
TapBridge::SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb) TapBridge::SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb)
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
m_promiscRxCallback = cb; m_promiscRxCallback = cb;
} }
bool bool
TapBridge::SupportsSendFrom () const TapBridge::SupportsSendFrom () const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION (this);
return true; return true;
} }

View File

@@ -450,6 +450,13 @@ private:
*/ */
bool m_linkUp; bool m_linkUp;
/**
* Flag indicating whether or not the link is up. In this case,
* whether or not ns-3 is connected to the underlying TAP device
* with a file descriptor.
*/
bool m_verbose;
/** /**
* Callbacks to fire if the link changes state (up or down). * Callbacks to fire if the link changes state (up or down).
*/ */