internet: Add TracedCallback to trace interface set up or down
This commit is contained in:
committed by
Tommaso Pecorella
parent
1f040f783d
commit
aef171c305
@@ -31,16 +31,20 @@ NS_OBJECT_ENSURE_REGISTERED(Ipv4Interface);
|
|||||||
TypeId
|
TypeId
|
||||||
Ipv4Interface::GetTypeId()
|
Ipv4Interface::GetTypeId()
|
||||||
{
|
{
|
||||||
static TypeId tid = TypeId("ns3::Ipv4Interface")
|
static TypeId tid =
|
||||||
.SetParent<Object>()
|
TypeId("ns3::Ipv4Interface")
|
||||||
.SetGroupName("Internet")
|
.SetParent<Object>()
|
||||||
.AddAttribute("ArpCache",
|
.SetGroupName("Internet")
|
||||||
"The arp cache for this ipv4 interface",
|
.AddAttribute(
|
||||||
PointerValue(nullptr),
|
"ArpCache",
|
||||||
MakePointerAccessor(&Ipv4Interface::SetArpCache,
|
"The arp cache for this ipv4 interface",
|
||||||
&Ipv4Interface::GetArpCache),
|
PointerValue(nullptr),
|
||||||
MakePointerChecker<ArpCache>());
|
MakePointerAccessor(&Ipv4Interface::SetArpCache, &Ipv4Interface::GetArpCache),
|
||||||
;
|
MakePointerChecker<ArpCache>())
|
||||||
|
.AddTraceSource("InterfaceStatus",
|
||||||
|
"Interface has been set up or down.",
|
||||||
|
MakeTraceSourceAccessor(&Ipv4Interface::m_interfaceStatus),
|
||||||
|
"ns3::Ipv4Address::TracedCallback");
|
||||||
return tid;
|
return tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +179,11 @@ Ipv4Interface::SetUp()
|
|||||||
{
|
{
|
||||||
NS_LOG_FUNCTION(this);
|
NS_LOG_FUNCTION(this);
|
||||||
m_ifup = true;
|
m_ifup = true;
|
||||||
|
|
||||||
|
Ptr<Ipv4> ip = m_node->GetObject<Ipv4>();
|
||||||
|
NS_ASSERT_MSG(ip, "IPv4 not installed on node.");
|
||||||
|
auto ifIndex = ip->GetInterfaceForDevice(m_device);
|
||||||
|
m_interfaceStatus(m_ifup, ifIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -182,6 +191,11 @@ Ipv4Interface::SetDown()
|
|||||||
{
|
{
|
||||||
NS_LOG_FUNCTION(this);
|
NS_LOG_FUNCTION(this);
|
||||||
m_ifup = false;
|
m_ifup = false;
|
||||||
|
|
||||||
|
Ptr<Ipv4> ip = m_node->GetObject<Ipv4>();
|
||||||
|
NS_ASSERT_MSG(ip, "IPv4 not installed on node.");
|
||||||
|
auto ifIndex = ip->GetInterfaceForDevice(m_device);
|
||||||
|
m_interfaceStatus(m_ifup, ifIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "ns3/object.h"
|
#include "ns3/object.h"
|
||||||
#include "ns3/ptr.h"
|
#include "ns3/ptr.h"
|
||||||
|
#include "ns3/traced-callback.h"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@@ -238,6 +239,12 @@ class Ipv4Interface : public Object
|
|||||||
m_removeAddressCallback; //!< remove address callback
|
m_removeAddressCallback; //!< remove address callback
|
||||||
Callback<void, Ptr<Ipv4Interface>, Ipv4InterfaceAddress>
|
Callback<void, Ptr<Ipv4Interface>, Ipv4InterfaceAddress>
|
||||||
m_addAddressCallback; //!< add address callback
|
m_addAddressCallback; //!< add address callback
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The trace fired when the interface state changes.
|
||||||
|
* Includes state (true if interface is up) and the interface index.
|
||||||
|
*/
|
||||||
|
ns3::TracedCallback<bool, int32_t> m_interfaceStatus;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ns3
|
} // namespace ns3
|
||||||
|
|||||||
@@ -33,7 +33,14 @@ NS_OBJECT_ENSURE_REGISTERED(Ipv6Interface);
|
|||||||
TypeId
|
TypeId
|
||||||
Ipv6Interface::GetTypeId()
|
Ipv6Interface::GetTypeId()
|
||||||
{
|
{
|
||||||
static TypeId tid = TypeId("ns3::Ipv6Interface").SetParent<Object>().SetGroupName("Internet");
|
static TypeId tid =
|
||||||
|
TypeId("ns3::Ipv6Interface")
|
||||||
|
.SetParent<Object>()
|
||||||
|
.SetGroupName("Internet")
|
||||||
|
.AddTraceSource("InterfaceStatus",
|
||||||
|
"Interface has been set up or down.",
|
||||||
|
MakeTraceSourceAccessor(&Ipv6Interface::m_interfaceStatus),
|
||||||
|
"ns3::Ipv6Address::TracedCallback");
|
||||||
return tid;
|
return tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,6 +177,11 @@ Ipv6Interface::SetUp()
|
|||||||
}
|
}
|
||||||
DoSetup();
|
DoSetup();
|
||||||
m_ifup = true;
|
m_ifup = true;
|
||||||
|
|
||||||
|
Ptr<Ipv6> ip = m_node->GetObject<Ipv6>();
|
||||||
|
NS_ASSERT_MSG(ip, "IPv6 not installed on node.");
|
||||||
|
auto ifIndex = ip->GetInterfaceForDevice(m_device);
|
||||||
|
m_interfaceStatus(m_ifup, ifIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -179,6 +191,11 @@ Ipv6Interface::SetDown()
|
|||||||
m_ifup = false;
|
m_ifup = false;
|
||||||
m_addresses.clear();
|
m_addresses.clear();
|
||||||
m_ndCache->Flush();
|
m_ndCache->Flush();
|
||||||
|
|
||||||
|
Ptr<Ipv6> ip = m_node->GetObject<Ipv6>();
|
||||||
|
NS_ASSERT_MSG(ip, "IPv6 not installed on node.");
|
||||||
|
auto ifIndex = ip->GetInterfaceForDevice(m_device);
|
||||||
|
m_interfaceStatus(m_ifup, ifIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "ns3/object.h"
|
#include "ns3/object.h"
|
||||||
#include "ns3/ptr.h"
|
#include "ns3/ptr.h"
|
||||||
|
#include "ns3/traced-callback.h"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@@ -386,6 +387,12 @@ class Ipv6Interface : public Object
|
|||||||
|
|
||||||
Callback<void, Ptr<Ipv6Interface>, Ipv6InterfaceAddress>
|
Callback<void, Ptr<Ipv6Interface>, Ipv6InterfaceAddress>
|
||||||
m_addAddressCallback; //!< add address callback
|
m_addAddressCallback; //!< add address callback
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The trace fired when the interface state changes.
|
||||||
|
* Includes state (true if interface is up) and the interface index.
|
||||||
|
*/
|
||||||
|
ns3::TracedCallback<bool, int32_t> m_interfaceStatus;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace ns3 */
|
} /* namespace ns3 */
|
||||||
|
|||||||
Reference in New Issue
Block a user