A Discrete-Event Network Simulator
API
ofswitch13-device.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 University of Campinas (Unicamp)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Luciano Jerez Chaves <ljerezchaves@gmail.com>
18  */
19 
20 #ifndef OFSWITCH13_DEVICE_H
21 #define OFSWITCH13_DEVICE_H
22 
23 #include "ofswitch13-interface.h"
25 
26 #include <ns3/inet-socket-address.h>
27 #include <ns3/socket.h>
28 #include <ns3/string.h>
29 #include <ns3/tcp-header.h>
30 #include <ns3/traced-value.h>
31 #include <ns3/uinteger.h>
32 
33 namespace ns3
34 {
35 
36 class OFSwitch13Port;
37 
53 class OFSwitch13Device : public Object
54 {
55  private:
61  class RemoteController : public SimpleRefCount<RemoteController>
62  {
63  friend class OFSwitch13Device;
64 
65  public:
68 
69  private:
73  struct remote* m_remote;
74  }; // Class RemoteController
75 
86  {
87  public:
90 
96  void SetPacket(uint64_t id, Ptr<Packet> packet);
97 
99  Ptr<Packet> GetPacket() const;
100 
102  void Invalidate();
103 
108  bool IsValid() const;
109 
114  void NewCopy(uint64_t id);
115 
121  bool DelCopy(uint64_t id);
122 
128  bool HasId(uint64_t id);
129 
130  private:
131  bool m_valid;
133  std::list<uint64_t> m_ids;
134  }; // Struct PipelinePacket
135 
136  public:
137  OFSwitch13Device();
138  ~OFSwitch13Device() override;
139 
144  static TypeId GetTypeId();
145 
150  uint64_t GetDatapathId() const;
151 
156  uint64_t GetDpId() const;
157 
162  //\{
163  uint64_t GetFlowModCounter() const;
164  uint64_t GetGroupModCounter() const;
165  uint64_t GetMeterModCounter() const;
166  uint64_t GetPacketInCounter() const;
167  uint64_t GetPacketOutCounter() const;
168  //\}
169 
175  //\{
176  uint32_t GetBufferEntries() const;
177  uint32_t GetBufferSize() const;
178  double GetBufferUsage() const;
179  DataRate GetCpuCapacity() const;
180  DataRate GetCpuLoad() const;
181  double GetCpuUsage() const;
182  Time GetDatapathTimeout() const;
183  uint32_t GetDftFlowTableSize() const;
184  uint32_t GetFlowTableEntries(uint8_t tableId) const;
185  uint32_t GetFlowTableSize(uint8_t tableId) const;
186  double GetFlowTableUsage(uint8_t tableId) const;
187  uint32_t GetGroupTableEntries() const;
188  uint32_t GetGroupTableSize() const;
189  double GetGroupTableUsage() const;
190  uint32_t GetMeterTableEntries() const;
191  uint32_t GetMeterTableSize() const;
192  double GetMeterTableUsage() const;
193  uint32_t GetNControllers() const;
194  uint32_t GetNPipelineTables() const;
195  uint32_t GetNSwitchPorts() const;
196  Time GetPipelineDelay() const;
197  uint32_t GetSumFlowEntries() const;
198  //\}
199 
204  struct datapath* GetDatapathStruct();
205 
217 
223  Ptr<OFSwitch13Port> GetSwitchPort(uint32_t no) const;
224 
232  uint32_t portNo,
233  uint64_t tunnelId = 0);
234 
240  void StartControllerConnection(Address ctrlAddr);
241 
254  static void SendPacketToController(struct pipeline* pl,
255  struct packet* pkt,
256  uint8_t tableId,
257  uint8_t reason);
258 
270  static int SendOpenflowBufferToRemote(struct ofpbuf* buffer,
271  struct remote* remote);
272 
288  static void DpActionsOutputPort(struct packet* pkt,
289  uint32_t outPort,
290  uint32_t outQueue,
291  uint16_t maxLength,
292  uint64_t cookie);
293 
298  static void MeterCreatedCallback(struct meter_entry* entry);
299 
305  static void MeterDropCallback(struct packet* pkt,
306  struct meter_entry* entry);
307 
313  static void TableDropCallback(struct packet* pkt, struct flow_table* table);
314 
320  static void PacketCloneCallback(struct packet* pkt, struct packet* clone);
321 
326  static void PacketDestroyCallback(struct packet* pkt);
327 
333  static void BufferSaveCallback(struct packet* pkt, time_t timeout);
334 
339  static void BufferRetrieveCallback(struct packet* pkt);
340 
346  static Ptr<OFSwitch13Device> GetDevice(uint64_t id);
347 
354  uint32_t meterId);
355 
363  uint8_t tableId);
364 
370 
371  protected:
372  // Inherited from Object
373  void DoDispose() override;
374 
375  // Inherited from ObjectBase.
376  void NotifyConstructionCompleted() override;
377 
378  private:
384  struct datapath* DatapathNew();
385 
391  //\{
392  void SetFlowTableSize(uint8_t tableId, uint32_t value);
393  void SetDftFlowTableSize(uint32_t value);
394  void SetGroupTableSize(uint32_t value);
395  void SetMeterTableSize(uint32_t value);
396  //\}
397 
405  void DatapathTimeout(struct datapath* dp);
406 
417  int SendPacketInMessage(struct packet* pkt,
418  uint8_t tableId,
419  uint8_t reason,
420  uint16_t maxLength,
421  uint64_t cookie = 0);
422 
432  bool SendToSwitchPort(struct packet* pkt,
433  uint32_t portNo,
434  uint32_t queueNo = 0);
435 
442  void SendToPipeline(Ptr<Packet> packet,
443  uint32_t portNo,
444  uint64_t tunnelId = 0);
445 
456  int SendToController(Ptr<Packet> packet,
458 
465  void ReceiveFromController(Ptr<Packet> packet, Address from);
466 
476  int ReplyWithErrorMessage(ofl_err error,
477  struct ofpbuf* buffer,
478  struct sender* senderCtrl);
479 
484  void SocketCtrlSucceeded(Ptr<Socket> socket);
485 
490  void SocketCtrlFailed(Ptr<Socket> socket);
491 
499  void NotifyMeterEntryCreated(struct meter_entry* entry);
500 
506  void NotifyPacketCloned(struct packet* pkt, struct packet* clone);
507 
512  void NotifyPacketDestroyed(struct packet* pkt);
513 
519  void NotifyPacketDroppedByMeter(struct packet* pkt,
520  struct meter_entry* entry);
521 
528  void NotifyPacketDroppedByTable(struct packet* pkt,
529  struct flow_table* table);
530 
536  void BufferPacketSave(uint64_t packetId, time_t timeout);
537 
543  void BufferPacketRetrieve(uint64_t packetId);
544 
549  void BufferPacketDelete(uint64_t packetId);
550 
557  Ptr<Socket> socket);
558 
565  Address address);
566 
573  struct remote* remote);
574 
582  static uint64_t GetNewPacketId();
583 
592  static bool CopyTags(Ptr<const Packet> srcPkt, Ptr<const Packet> dstPkt);
593 
599  static void RegisterDatapath(uint64_t id, Ptr<OFSwitch13Device> dev);
600 
605  static void UnregisterDatapath(uint64_t id);
606 
608  typedef std::vector<Ptr<OFSwitch13Port>> PortList_t;
609 
611  typedef std::vector<Ptr<OFSwitch13Device::RemoteController>> CtrlList_t;
612 
614  typedef std::map<uint64_t, Ptr<OFSwitch13Device>> DpIdDevMap_t;
615 
617  typedef std::map<uint64_t, Ptr<Packet>> IdPacketMap_t;
618 
621 
624 
627 
630 
633 
636 
639 
642 
645 
648 
651 
654 
657 
658  uint64_t m_dpId;
662  std::string m_libLog;
663  struct datapath* m_datapath;
666  uint32_t m_flowTabSize;
667  uint32_t m_groupTabSize;
668  uint32_t m_meterTabSize;
669  uint32_t m_numPipeTabs;
671  uint32_t m_bufferSize;
674  uint64_t m_cpuConsumed;
675  uint64_t m_cpuTokens;
676  uint64_t m_cFlowMod;
677  uint64_t m_cGroupMod;
678  uint64_t m_cMeterMod;
679  uint64_t m_cPacketIn;
680  uint64_t m_cPacketOut;
681 
682  static uint64_t m_globalDpId;
683  static uint64_t m_globalPktId;
684 
694 
695 }; // Class OFSwitch13Device
696 
697 } // namespace ns3
698 #endif /* OFSWITCH13_DEVICE_H */
a polymophic address class
Definition: address.h:100
Class for representing data rates.
Definition: data-rate.h:90
Inner class to save information of a remote active controller connected to this OpenFlow switch.
RemoteController()
Default (empty) constructor.
struct remote * m_remote
Library remote struct.
Ptr< OFSwitch13SocketHandler > m_handler
Socket handler.
Address m_address
Controller address.
Ptr< Socket > m_socket
TCP socket to controller.
An OpenFlow 1.3 device that switches multiple CSMA segments via OpenFlow protocol.
CtrlList_t m_controllers
Collection of active controllers.
struct datapath * GetDatapathStruct()
Get a pointer to the internal BOFUSS datapath structure.
Ptr< OFSwitch13Port > GetSwitchPort(uint32_t no) const
Get the OFSwitch13Port pointer from its number.
std::vector< Ptr< OFSwitch13Port > > PortList_t
Structure to save the list of ports in this datapath.
static void BufferSaveCallback(struct packet *pkt, time_t timeout)
Callback fired when a packet is saved into buffer.
void SocketCtrlFailed(Ptr< Socket > socket)
Socket callback fired when a TCP connection to controller fail.
double GetCpuUsage() const
TracedCallback signature for packets dropped by meter bands.
std::string m_libLog
The BOFUSS library log level.
uint32_t GetBufferEntries() const
TracedCallback signature for packets dropped by meter bands.
uint32_t m_numPipeTabs
Number of pipeline flow tables.
uint64_t m_cpuConsumed
CPU processing tokens consumed.
uint32_t GetGroupTableSize() const
TracedCallback signature for packets dropped by meter bands.
IdPacketMap_t m_bufferPkts
Packets saved in switch buffer.
TracedCallback< Ptr< const Packet > > m_pipePacketTrace
Trace source fired when a packet is sent to pipeline.
uint32_t GetFlowTableEntries(uint8_t tableId) const
TracedCallback signature for packets dropped by meter bands.
TracedValue< DataRate > m_cpuLoad
Average CPU processing load.
uint32_t GetMeterTableSize() const
TracedCallback signature for packets dropped by meter bands.
void SetFlowTableSize(uint8_t tableId, uint32_t value)
Structure to save the list of ports in this datapath.
void DoDispose() override
TracedCallback signature for packets dropped by meter bands.
uint32_t GetNSwitchPorts() const
TracedCallback signature for packets dropped by meter bands.
static void PacketDestroyCallback(struct packet *pkt)
Callback fired when a packet is destroyed.
double GetBufferUsage() const
TracedCallback signature for packets dropped by meter bands.
PipelinePacket m_pipePkt
Packet under switch pipeline.
Ptr< OFSwitch13Device::RemoteController > GetRemoteController(Ptr< Socket > socket)
Get the remote controller for this socket.
void SendToPipeline(Ptr< Packet > packet, uint32_t portNo, uint64_t tunnelId=0)
Send the packet to the OpenFlow BOFUSS pipeline.
void NotifyPacketDroppedByMeter(struct packet *pkt, struct meter_entry *entry)
Notify this device of a packet dropped by OpenFlow meter band.
double GetFlowTableUsage(uint8_t tableId) const
TracedCallback signature for packets dropped by meter bands.
void DatapathTimeout(struct datapath *dp)
Check if any flow in any table is timed out and update port status.
void SocketCtrlSucceeded(Ptr< Socket > socket)
Socket callback fired when a TCP connection to controller succeed.
uint64_t GetFlowModCounter() const
TracedCallback< Ptr< const OFSwitch13Device > > m_datapathTimeoutTrace
Trace source fired when the datapath timeout operation is completed.
Time GetDatapathTimeout() const
TracedCallback signature for packets dropped by meter bands.
void ReceiveFromSwitchPort(Ptr< Packet > packet, uint32_t portNo, uint64_t tunnelId=0)
Called when a packet is received on one of the switch's ports.
void ReceiveFromController(Ptr< Packet > packet, Address from)
Receive an OpenFlow packet from controller.
uint32_t GetNControllers() const
TracedCallback signature for packets dropped by meter bands.
static Ptr< OFSwitch13Device > GetDevice(uint64_t id)
Retrieve and existing OpenFlow device object by its datapath ID.
TracedCallback< Ptr< const Packet >, uint8_t > m_tableDropTrace
Trace source fired when an unmatched packet is dropped by flow table.
static void MeterCreatedCallback(struct meter_entry *entry)
Callback fired when a new meter entry is created at meter table.
OFSwitch13Device()
Default constructor.
double GetMeterTableUsage() const
TracedCallback signature for packets dropped by meter bands.
PortList_t m_ports
List of switch ports.
double GetGroupTableUsage() const
TracedCallback signature for packets dropped by meter bands.
void BufferPacketSave(uint64_t packetId, time_t timeout)
Notify this device of a packet saved into buffer.
void NotifyMeterEntryCreated(struct meter_entry *entry)
Notify this device of a new meter entry created at meter table.
void NotifyPacketCloned(struct packet *pkt, struct packet *clone)
Notify this device of a packet cloned by the OpenFlow pipeline.
static void RegisterDatapath(uint64_t id, Ptr< OFSwitch13Device > dev)
Insert a new OpenFlow device in global map.
uint32_t GetGroupTableEntries() const
TracedCallback signature for packets dropped by meter bands.
Time m_timeout
Datapath timeout interval.
static uint64_t m_globalDpId
Global counter for datapath IDs.
DataRate GetCpuLoad() const
TracedCallback signature for packets dropped by meter bands.
TracedValue< uint32_t > m_groupEntries
Number of entries in group table.
TracedCallback< Ptr< const Packet > > m_bufferSaveTrace
Trace source fired when a packet is saved into buffer.
void StartControllerConnection(Address ctrlAddr)
Starts the TCP connection between this switch and the target controller indicated by the address para...
void NotifyPacketDestroyed(struct packet *pkt)
Notify this device of a packet destroyed by the OpenFlow pipeline.
TracedCallback< Ptr< const Packet > > m_loadDropTrace
Trace source fired when a packet is dropped due to overloaded switch.
void BufferPacketRetrieve(uint64_t packetId)
Notify this device of a packet retrieved from buffer.
Ptr< OFSwitch13Port > AddSwitchPort(Ptr< NetDevice > portDevice)
Add a 'port' to the switch device.
uint64_t m_cGroupMod
Pipeline group mod counter.
static uint64_t m_globalPktId
Global counter for packets IDs.
uint64_t m_cPacketIn
Pipeline packet in counter.
DataRate GetCpuCapacity() const
TracedCallback signature for packets dropped by meter bands.
Time m_tcamDelay
Flow Table TCAM lookup delay.
uint32_t m_meterTabSize
Meter table maximum entries.
int SendPacketInMessage(struct packet *pkt, uint8_t tableId, uint8_t reason, uint16_t maxLength, uint64_t cookie=0)
Create an OpenFlow packet in message and send the packet to all controllers with open connections.
void SetGroupTableSize(uint32_t value)
Structure to save the list of ports in this datapath.
static void BufferRetrieveCallback(struct packet *pkt)
Callback fired when a packet is retrieved from buffer.
TracedValue< uint32_t > m_sumFlowEntries
Sum of entries in all flow tables.
uint32_t GetMeterTableEntries() const
TracedCallback signature for packets dropped by meter bands.
void(* DeviceTracedCallback)(Ptr< const OFSwitch13Device > dev)
TracedCallback signature for OpenFlow switch device.
void NotifyPacketDroppedByTable(struct packet *pkt, struct flow_table *table)
Notify this device of an unmatched packet dropped by OpenFlow flow table without a table-miss entry.
struct datapath * DatapathNew()
Creates a new datapath.
static void MeterDropCallback(struct packet *pkt, struct meter_entry *entry)
Callback fired when a packet is dropped by meter band.
static void UnregisterDatapath(uint64_t id)
Remove an existing OpenFlow device from global map.
static void TableDropCallback(struct packet *pkt, struct flow_table *table)
Callback fired when an unmatched packet is dropped by a flow table without a table-miss entry.
struct datapath * m_datapath
BOFUSS datapath structure.
uint64_t m_cMeterMod
Pipeline meter mod counter.
static uint64_t GetNewPacketId()
Increase the global packet ID counter and return a new packet ID.
~OFSwitch13Device() override
Dummy destructor, see DoDispose.
uint64_t GetPacketInCounter() const
TracedValue< Time > m_pipeDelay
Average delay for pipeline packet processing.
uint64_t GetDatapathId() const
Get the OpenFlow datapath ID.
void NotifyConstructionCompleted() override
TracedCallback signature for packets dropped by meter bands.
uint64_t m_cFlowMod
Pipeline flow mod counter.
int ReplyWithErrorMessage(ofl_err error, struct ofpbuf *buffer, struct sender *senderCtrl)
Create an OpenFlow error message and send it back to the sender controller.
uint32_t m_flowTabSize
Flow table maximum entries.
uint64_t GetPacketOutCounter() const
uint32_t m_groupTabSize
Group table maximum entries.
static bool CopyTags(Ptr< const Packet > srcPkt, Ptr< const Packet > dstPkt)
Copy all tags (packet and byte) from srcPkt packet to dstPkt packet.
static void DpActionsOutputPort(struct packet *pkt, uint32_t outPort, uint32_t outQueue, uint16_t maxLength, uint64_t cookie)
Overriding BOFUSS dp_actions_output_port weak function from udatapath/dp_actions.c.
static int SendOpenflowBufferToRemote(struct ofpbuf *buffer, struct remote *remote)
Overriding BOFUSS send_openflow_buffer_to_remote weak function from udatapath/datapath....
std::map< uint64_t, Ptr< OFSwitch13Device > > DpIdDevMap_t
Structure to map datapath id to OpenFlow device.
std::vector< Ptr< OFSwitch13Device::RemoteController > > CtrlList_t
Structure to save the list of active controllers.
uint32_t m_bufferSize
Buffer size in terms of packets.
static TypeId GetTypeId()
Register this type.
void(* TableDropTracedCallback)(Ptr< const Packet > packet, uint8_t tableId)
TracedCallback signature for unmatched packets dropped by flow tables without table-miss entries.
void BufferPacketDelete(uint64_t packetId)
Delete the ns-3 packet from buffer map.
uint64_t m_cPacketOut
Pipeline packet out counter.
void SetMeterTableSize(uint32_t value)
Structure to save the list of ports in this datapath.
uint64_t GetDpId() const
Alias for the GetDatapathId () method.
uint64_t m_cpuTokens
CPU processing tokens available.
std::map< uint64_t, Ptr< Packet > > IdPacketMap_t
Structure to save packets, indexed by its id.
int SendToController(Ptr< Packet > packet, Ptr< OFSwitch13Device::RemoteController > remoteCtrl)
Send a packet to the controller node.
Time m_lastTimeout
Datapath last timeout.
bool SendToSwitchPort(struct packet *pkt, uint32_t portNo, uint32_t queueNo=0)
Send a message over a specific switch port.
TracedCallback< Ptr< const Packet > > m_bufferRetrieveTrace
Trace source fired when a packet is retrieved from buffer.
uint64_t GetGroupModCounter() const
TracedCallback< Ptr< const Packet > > m_bufferExpireTrace
Trace source fired when a packet in buffer expires.
static void SendPacketToController(struct pipeline *pl, struct packet *pkt, uint8_t tableId, uint8_t reason)
Overriding BOFUSS send_packet_to_controller weak function from udatapath/pipeline....
uint32_t GetNPipelineTables() const
TracedCallback signature for packets dropped by meter bands.
uint32_t GetSumFlowEntries() const
TracedCallback signature for packets dropped by meter bands.
static DpIdDevMap_t m_globalSwitchMap
As the integration of BOFUSS and ns-3 involve overriding some C functions, we are using a global map ...
TracedCallback< Ptr< const Packet >, uint32_t > m_meterDropTrace
Trace source fired when a packet is dropped by a meter band.
uint64_t m_dpId
This datapath id.
uint32_t GetDftFlowTableSize() const
TracedCallback signature for packets dropped by meter bands.
static void PacketCloneCallback(struct packet *pkt, struct packet *clone)
Callback fired when a packet is cloned.
uint32_t GetBufferSize() const
TracedCallback signature for packets dropped by meter bands.
TracedValue< uint32_t > m_meterEntries
Number of entries in meter table.
uint64_t GetMeterModCounter() const
uint32_t GetFlowTableSize(uint8_t tableId) const
TracedCallback signature for packets dropped by meter bands.
Time GetPipelineDelay() const
TracedCallback signature for packets dropped by meter bands.
void SetDftFlowTableSize(uint32_t value)
Structure to save the list of ports in this datapath.
DataRate m_cpuCapacity
CPU processing capacity.
void(* MeterDropTracedCallback)(Ptr< const Packet > packet, uint32_t meterId)
TracedCallback signature for packets dropped by meter bands.
A base class which provides memory management and object aggregation.
Definition: object.h:89
A template-based reference counting class.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:60
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
value
Definition: second.py:41
ns3::Time timeout
Structure to save packet metadata while it is under OpenFlow pipeline.
void SetPacket(uint64_t id, Ptr< Packet > packet)
Save packet metadata.
bool DelCopy(uint64_t id)
Delete an existing copy for this packet.
Ptr< Packet > m_packet
Packet pointer.
PipelinePacket()
Default (empty) constructor.
bool HasId(uint64_t id)
Check for packet id in the internal list of IDs for this packet.
void Invalidate()
Invalidate packet metatada.
bool IsValid() const
Check for valid packet metadata.
void NewCopy(uint64_t id)
Notify a new copy for this packet, with a new unique ID.
std::list< uint64_t > m_ids
Internal list of IDs for this packet.