22 #include "ns3/assert.h" 23 #include "ns3/names.h" 24 #include "ns3/point-to-point-net-device.h" 25 #include "ns3/point-to-point-channel.h" 26 #include "ns3/channel.h" 28 #include "ns3/error-model.h" 29 #include "ns3/string.h" 30 #include "ns3/boolean.h" 31 #include "ns3/double.h" 32 #include "ns3/pointer.h" 40 NS_LOG_COMPONENT_DEFINE(
"ndn.LinkControlHelper");
46 LinkControlHelper::setErrorRate(Ptr<Node> node1, Ptr<Node> node2,
double errorRate)
48 NS_LOG_FUNCTION(node1 << node2 << errorRate);
50 NS_ASSERT(node1 !=
nullptr && node2 !=
nullptr);
51 NS_ASSERT(errorRate <= 1.0);
56 NS_ASSERT(ndn1 !=
nullptr && ndn2 !=
nullptr);
59 for (
const auto&
face : ndn1->getForwarder()->getFaceTable()) {
61 if (linkService ==
nullptr)
64 Ptr<PointToPointNetDevice> nd1 = linkService->GetNetDevice()->GetObject<PointToPointNetDevice>();
68 Ptr<Channel> channel = nd1->GetChannel();
69 if (channel ==
nullptr)
72 Ptr<PointToPointChannel> ppChannel = DynamicCast<PointToPointChannel>(channel);
74 Ptr<NetDevice> nd2 = ppChannel->GetDevice(0);
75 if (nd2->GetNode() == node1)
76 nd2 = ppChannel->GetDevice(1);
78 if (nd2->GetNode() == node2) {
79 ObjectFactory errorFactory(
"ns3::RateErrorModel");
80 errorFactory.Set(
"ErrorUnit", StringValue(
"ERROR_UNIT_PACKET"));
81 errorFactory.Set(
"ErrorRate", DoubleValue(errorRate));
83 errorFactory.Set(
"IsEnabled", BooleanValue(
false));
86 nd1->SetAttribute(
"ReceiveErrorModel", PointerValue(errorFactory.Create<ErrorModel>()));
87 nd2->SetAttribute(
"ReceiveErrorModel", PointerValue(errorFactory.Create<ErrorModel>()));
91 NS_FATAL_ERROR(
"There is no link to fail between the requested nodes");
97 setErrorRate(node1, node2, 1.0);
103 FailLink(Names::Find<Node>(node1), Names::Find<Node>(node2));
109 setErrorRate(node1, node2, -0.1);
115 UpLink(Names::Find<Node>(node1), Names::Find<Node>(node2));
ndn NetDeviceLinkService
Copyright (c) 2011-2015 Regents of the University of California.
Copyright (c) 2011-2015 Regents of the University of California.
static void UpLinkByName(const std::string &node1, const std::string &node2)
Re-enable NDN link between two nodes.
static void UpLink(Ptr< Node > node1, Ptr< Node > node2)
Re-enable NDN link between two nodes.
static void FailLink(Ptr< Node > node1, Ptr< Node > node2)
Fail NDN link between two nodes.
Copyright (c) 2011-2015 Regents of the University of California.
ndn L3Protocol
Copyright (c) 2011-2015 Regents of the University of California.
static void FailLinkByName(const std::string &node1, const std::string &node2)
Fail NDN link between two nodes.