26 #include <ns3/csma-net-device.h>
27 #include <ns3/ethernet-header.h>
28 #include <ns3/ethernet-trailer.h>
29 #include <ns3/pointer.h>
30 #include <ns3/virtual-net-device.h>
32 #undef NS_LOG_APPEND_CONTEXT
33 #define NS_LOG_APPEND_CONTEXT \
34 std::clog << "[dp " << m_dpId << " port " << m_portNo << "] ";
47 queueFactory.
SetTypeId(
"ns3::OFSwitch13PriorityQueue");
56 m_openflowDev(nullptr)
74 ofl_structs_free_port(
m_swPort->conf);
87 TypeId(
"ns3::OFSwitch13Port")
89 .SetGroupName(
"OFSwitch13")
93 "The OpenFlow queue to use as the TX queue in this port.",
96 MakePointerChecker<OFSwitch13Queue>())
99 "The object factory for the OpenFlow queue.",
107 "Trace source indicating a packet received at this port.",
109 "ns3::Packet::TracedCallback")
112 "Trace source indicating a packet sent at this port.",
114 "ns3::Packet::TracedCallback");
125 m_openflowDev(openflowDev)
147 "NetDevice must be CsmaNetDevice or VirtualNetDevice.");
150 size_t oflPortSize =
sizeof(
struct ofl_port);
151 size_t oflPortStatsSize =
sizeof(
struct ofl_port_stats);
153 m_swPort->conf = (
struct ofl_port*)xmalloc(oflPortSize);
154 memset(
m_swPort->conf, 0x00, oflPortSize);
156 m_swPort->conf->name = (
char*)xmalloc(OFP_MAX_PORT_NAME_LEN);
159 m_swPort->conf->config = 0x00000000;
160 m_swPort->conf->state = 0x00000000 | OFPPS_LIVE;
170 m_swPort->stats = (
struct ofl_port_stats*)xmalloc(oflPortStatsSize);
171 memset(
m_swPort->stats, 0x00, oflPortStatsSize);
197 struct ofl_msg_port_status msg;
198 msg.header.type = OFPT_PORT_STATUS;
199 msg.reason = OFPPR_ADD;
201 dp_send_message(
m_swPort->dp, (
struct ofl_msg_header*)&msg,
nullptr);
206 csmaDev->SetOpenFlowReceiveCallback(
212 virtDev->SetOpenFlowReceiveCallback(
244 uint32_t orig_state =
m_swPort->conf->state;
247 m_swPort->conf->state &= ~OFPPS_LINK_DOWN;
251 m_swPort->conf->state |= OFPPS_LINK_DOWN;
255 if (orig_state !=
m_swPort->conf->state)
257 NS_LOG_INFO(
"Port status has changed. Notifying the controller.");
258 struct ofl_msg_port_status msg;
259 msg.header.type = OFPT_PORT_STATUS;
260 msg.reason = OFPPR_MODIFY;
262 dp_send_message(
m_swPort->dp, (
struct ofl_msg_header*)&msg,
nullptr);
281 csmaChannel->GetAttribute(
"DataRate", drv);
286 uint32_t feat = 0x00000000;
287 feat |= OFPPF_COPPER;
288 feat |= OFPPF_AUTONEG;
292 feat |= OFPPF_10MB_FD;
296 feat |= OFPPF_100MB_FD;
300 feat |= OFPPF_1GB_FD;
304 feat |= OFPPF_10GB_FD;
308 feat |= OFPPF_40GB_FD;
312 feat |= OFPPF_100GB_FD;
314 else if (dr ==
DataRate(
"1000Gbps"))
316 feat |= OFPPF_1TB_FD;
336 if ((
m_swPort->conf->config & (OFPPC_NO_RECV | OFPPC_PORT_DOWN)) != 0)
338 NS_LOG_WARN(
"This port is down or inoperating. Discarding packet");
370 if (
m_swPort->conf->config & (OFPPC_PORT_DOWN))
372 NS_LOG_WARN(
"This port is down. Discarding packet");
381 <<
" will be sent at this port.");
400 bool status =
m_netDev->SendFrom(packetCopy,
a polymophic address class
A Device for a Csma Network Link.
Class for representing data rates.
AttributeValue implementation for DataRate.
Packet trailer for Ethernet.
PacketType
Packet types are used as they are in Linux.
A OpenFlow switch port, interconnecting the underlying NetDevice to the OpenFlow device through the O...
static TypeId GetTypeId()
Register this type.
uint32_t m_portNo
Port number.
bool Send(Ptr< const Packet > packet, uint32_t queueNo=0, uint64_t tunnelId=0)
Send a packet over this OpenFlow switch port.
struct sw_port * m_swPort
BOFUSS port structure.
TracedCallback< Ptr< const Packet > > m_rxTrace
Trace source fired when a packet arrives at this switch port.
~OFSwitch13Port() override
Dummy destructor, see DoDispose.
Ptr< OFSwitch13Queue > m_portQueue
OpenFlow port Queue.
Ptr< OFSwitch13Device > m_openflowDev
OpenFlow device.
ObjectFactory m_factQueue
Factory for port queue.
void NotifyConstructionCompleted() override
Notifier called once the ObjectBase is fully constructed.
TracedCallback< Ptr< const Packet > > m_txTrace
Trace source fired when a packet will be sent over this switch port.
Ptr< OFSwitch13Device > GetSwitchDevice() const
Get the OFSwitch13Device pointer from this port.
void DoDispose() override
Destructor implementation.
uint32_t GetPortNo() const
Get the OpenFlow port number for this port.
uint64_t m_dpId
OpenFlow datapath ID.
OFSwitch13Port()
Default constructor.
Ptr< OFSwitch13Queue > GetPortQueue() const
Get the OpenFlow queue for this port.
bool PortUpdateState()
Update the port state field based on NetDevice status, and notify the controller when changes occurs.
Ptr< NetDevice > m_netDev
Underlying NetDevice.
uint32_t GetPortFeatures()
Create the bitmaps of OFPPF_* describing port features.
struct sw_port * GetPortStruct()
Get a pointer to the internal BOFUSS port structure.
bool Receive(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Called when a packet is received on this OpenFlow switch port by the underlying NetDevice.
Ptr< NetDevice > GetPortDevice() const
Get the NetDevice pointer from the underlying port.
The OpenFlow 1.3 queue interface.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
AttributeValue implementation for ObjectFactory.
A base class which provides memory management and object aggregation.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
uint32_t RemoveTrailer(Trailer &trailer)
Remove a deserialized trailer from the internal buffer.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Ptr< Packet > Copy() const
performs a COW copy of the packet.
uint64_t GetUid() const
Returns the packet's Uid.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Hold objects of type Ptr<T>.
Smart pointer class similar to boost::intrusive_ptr.
Tag used to hold the queue id before enqueueing a packet into OFSwitch13Queue.
Tag used to hold the tunnel metadata information (tunnel ID) when sending/receiving a packet to/from ...
uint64_t GetTunnelId() const
a unique identifier for an interface.
@ ATTR_GET
The attribute can be read.
@ ATTR_CONSTRUCT
The attribute can be written at construction-time.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
A virtual device, similar to Linux TUN/TAP interfaces.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeChecker > MakeObjectFactoryChecker()
Ptr< const AttributeAccessor > MakeObjectFactoryAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#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_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#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.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
static ObjectFactory GetDefaultQueueFactory()
U * PeekPointer(const Ptr< U > &p)
long long int time_msec(void)
Overriding BOFUSS time_msec weak function from timeval.c.