26 #include <ns3/ofswitch13-port.h>
35 Ipv4AddressHelper(
"10.100.0.0",
"255.255.255.0");
37 class OFSwitch13Controller;
45 m_devFactory.SetTypeId(
"ns3::OFSwitch13Device");
48 OFSwitch13Helper::~OFSwitch13Helper()
54 OFSwitch13Helper::GetTypeId()
57 TypeId(
"ns3::OFSwitch13Helper")
59 .SetGroupName(
"OFSwitch13")
62 "The data rate to be used for the OpenFlow channel.",
64 MakeDataRateAccessor(&OFSwitch13Helper::SetChannelDataRate),
65 MakeDataRateChecker())
68 "The configuration used to create the OpenFlow channel",
69 TypeId::ATTR_GET | TypeId::ATTR_CONSTRUCT,
70 EnumValue(OFSwitch13Helper::SINGLECSMA),
74 OFSwitch13Helper::DEDICATEDCSMA,
76 OFSwitch13Helper::DEDICATEDP2P,
82 OFSwitch13Helper::SetDeviceAttribute(std::string n1,
const AttributeValue& v1)
86 m_devFactory.Set(n1, v1);
90 OFSwitch13Helper::SetChannelType(ChannelType
type)
99 OFSwitch13Helper::SetChannelDataRate(
DataRate rate)
103 m_channelDataRate = rate;
107 OFSwitch13Helper::EnableOpenFlowPcap(std::string prefix,
bool promiscuous)
112 switch (m_channelType)
114 case OFSwitch13Helper::SINGLECSMA:
115 case OFSwitch13Helper::DEDICATEDCSMA: {
116 m_csmaHelper.EnablePcap(prefix, m_controlDevs, promiscuous);
119 case OFSwitch13Helper::DEDICATEDP2P: {
120 m_p2pHelper.EnablePcap(prefix, m_controlDevs, promiscuous);
130 OFSwitch13Helper::EnableOpenFlowAscii(std::string prefix)
135 AsciiTraceHelper ascii;
136 switch (m_channelType)
138 case OFSwitch13Helper::SINGLECSMA:
139 case OFSwitch13Helper::DEDICATEDCSMA: {
140 m_csmaHelper.EnableAsciiAll(ascii.CreateFileStream(prefix +
".txt"));
143 case OFSwitch13Helper::DEDICATEDP2P: {
144 m_p2pHelper.EnableAsciiAll(ascii.CreateFileStream(prefix +
".txt"));
154 OFSwitch13Helper::EnableDatapathStats(std::string prefix,
bool useNodeNames)
160 if (prefix.back() !=
'-')
165 ObjectFactory statsFactory(
"ns3::OFSwitch13StatsCalculator");
166 Ptr<OFSwitch13StatsCalculator> statsCalculator;
167 const std::string extension =
".log";
171 OFSwitch13DeviceContainer::Iterator it;
172 for (it = m_openFlowDevs.Begin(); it != m_openFlowDevs.End(); it++)
174 Ptr<OFSwitch13Device> dev = *it;
175 std::string filename = prefix;
176 std::string nodename;
180 Ptr<Node> node = dev->GetObject<Node>();
181 nodename = Names::FindName(node);
185 filename += nodename;
189 filename += std::to_string(dev->GetDatapathId());
191 filename += extension;
193 statsFactory.Set(
"OutputFilename", StringValue(filename));
194 statsCalculator = statsFactory.Create<OFSwitch13StatsCalculator>();
195 statsCalculator->AggregateObject(dev);
196 statsCalculator->HookSinks(dev);
200 Ptr<OFSwitch13Device>
201 OFSwitch13Helper::InstallSwitch(Ptr<Node> swNode, NetDeviceContainer& swPorts)
206 Ptr<OFSwitch13Device> openFlowDev = InstallSwitch(swNode);
209 NetDeviceContainer::Iterator it;
210 for (it = swPorts.Begin(); it != swPorts.End(); it++)
213 openFlowDev->AddSwitchPort(*it);
219 Ptr<OFSwitch13Device>
220 OFSwitch13Helper::InstallSwitch(Ptr<Node> swNode)
224 NS_LOG_INFO(
"Installing OpenFlow device on node " << swNode->GetId());
228 if (!swNode->GetObject<Ipv4>())
230 m_internet.Install(swNode);
234 Ptr<OFSwitch13Device> openFlowDev = m_devFactory.Create<OFSwitch13Device>();
235 swNode->AggregateObject(openFlowDev);
236 m_openFlowDevs.Add(openFlowDev);
237 m_switchNodes.Add(swNode);
242 OFSwitch13DeviceContainer
243 OFSwitch13Helper::InstallSwitch(NodeContainer& swNodes)
248 OFSwitch13DeviceContainer openFlowDevices;
249 NodeContainer::Iterator it;
250 for (it = swNodes.Begin(); it != swNodes.End(); it++)
252 openFlowDevices.Add(InstallSwitch(*it));
255 return openFlowDevices;
259 OFSwitch13Helper::SetAddressBase(Ipv4Address network,
265 m_ipv4helper.SetBase(network, mask, base);
269 OFSwitch13Helper::EnableDatapathLogs(std::string prefix,
bool explicitFilename)
278 OFSwitch13Helper::DoDispose()
AttributeValue implementation for DataRate.
static Ipv4AddressHelper m_ipv4helper
Helper for IP address.
OFSwitch13Helper()
Default constructor.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
void EnableBofussLog(bool printToFile, std::string prefix, bool explicitFilename, std::string customLevels)
Enable the logging system of the BOFUSS library.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.