A Discrete-Event Network Simulator
API
openflow-switch-net-device.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Author: Blake Hurd <naimorai@gmail.com>
17  */
18 
24 #ifndef OPENFLOW_SWITCH_NET_DEVICE_H
25 #define OPENFLOW_SWITCH_NET_DEVICE_H
26 
27 #include "ns3/simulator.h"
28 #include "ns3/log.h"
29 #include "ns3/mac48-address.h"
30 
31 #include "ns3/ethernet-header.h"
32 #include "ns3/arp-header.h"
33 #include "ns3/tcp-header.h"
34 #include "ns3/udp-header.h"
35 
36 #include "ns3/ipv4-l3-protocol.h"
37 #include "ns3/arp-l3-protocol.h"
38 
39 #include "ns3/bridge-channel.h"
40 #include "ns3/node.h"
41 #include "ns3/enum.h"
42 #include "ns3/string.h"
43 #include "ns3/integer.h"
44 #include "ns3/uinteger.h"
45 
46 #include <map>
47 #include <set>
48 
49 #include "openflow-interface.h"
50 
51 namespace ns3 {
52 
87 {
88 public:
93  static TypeId GetTypeId (void);
94 
109  static const char * GetManufacturerDescription ();
110  static const char * GetHardwareDescription ();
111  static const char * GetSoftwareDescription ();
112  static const char * GetSerialNumber ();
117 
124 
141  int AddSwitchPort (Ptr<NetDevice> switchPort);
142 
156  int AddVPort (const ofp_vport_mod *ovpm);
157 
167 
176 
186  void DoOutput (uint32_t packet_uid, int in_port, size_t max_len, int out_port, bool ignore_no_fwd);
187 
195  int ForwardControlInput (const void *msg, size_t length);
196 
200  sw_chain* GetChain ();
201 
205  uint32_t GetNSwitchPorts (void) const;
206 
212 
217  ofi::Port GetSwitchPort (uint32_t n) const;
218 
222  vport_table_t GetVPortTable ();
223 
224  // From NetDevice
225  virtual void SetIfIndex (const uint32_t index);
226  virtual uint32_t GetIfIndex (void) const;
227  virtual Ptr<Channel> GetChannel (void) const;
228  virtual void SetAddress (Address address);
229  virtual Address GetAddress (void) const;
230  virtual bool SetMtu (const uint16_t mtu);
231  virtual uint16_t GetMtu (void) const;
232  virtual bool IsLinkUp (void) const;
233  virtual void AddLinkChangeCallback (Callback<void> callback);
234  virtual bool IsBroadcast (void) const;
235  virtual Address GetBroadcast (void) const;
236  virtual bool IsMulticast (void) const;
237  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
238  virtual bool IsPointToPoint (void) const;
239  virtual bool IsBridge (void) const;
240  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
241  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
242  virtual Ptr<Node> GetNode (void) const;
243  virtual void SetNode (Ptr<Node> node);
244  virtual bool NeedsArp (void) const;
247  virtual bool SupportsSendFrom () const;
248  virtual Address GetMulticast (Ipv6Address addr) const;
249 
250 protected:
251  virtual void DoDispose (void);
252 
263  void ReceiveFromDevice (Ptr<NetDevice> netdev, Ptr<const Packet> packet, uint16_t protocol, const Address& src, const Address& dst, PacketType packetType);
264 
275  ofpbuf * BufferFromPacket (Ptr<const Packet> packet, Address src, Address dst, int mtu, uint16_t protocol);
276 
277 private:
286  int AddFlow (const ofp_flow_mod *ofm);
287 
294  int ModFlow (const ofp_flow_mod *ofm);
295 
304  int OutputAll (uint32_t packet_uid, int in_port, bool flood);
305 
311  void OutputPacket (uint32_t packet_uid, int out_port);
312 
324  void OutputPort (uint32_t packet_uid, int in_port, int out_port, bool ignore_no_fwd);
325 
336  void OutputControl (uint32_t packet_uid, int in_port, size_t max_len, int reason);
337 
346  void SendErrorMsg (uint16_t type, uint16_t code, const void *data, size_t len);
347 
370 
377  void SendFlowExpired (sw_flow *flow, enum ofp_flow_expired_reason reason);
378 
385  void SendPortStatus (ofi::Port p, uint8_t status);
386 
391 
401  int SendOpenflowBuffer (ofpbuf *buffer);
402 
411  void RunThroughFlowTable (uint32_t packet_uid, int port, bool send_to_controller = true);
412 
422  int RunThroughVPortTable (uint32_t packet_uid, int port, uint32_t vport);
423 
434  void FlowTableLookup (sw_flow_key key, ofpbuf* buffer, uint32_t packet_uid, int port, bool send_to_controller);
435 
444 
451  void FillPortDesc (ofi::Port p, ofp_phy_port *desc);
452 
461  void* MakeOpenflowReply (size_t openflow_len, uint8_t type, ofpbuf **bufferp);
462 
474  int ReceiveFeaturesRequest (const void *msg);
475  int ReceiveGetConfigRequest (const void *msg);
476  int ReceiveSetConfig (const void *msg);
477  int ReceivePacketOut (const void *msg);
478  int ReceiveFlow (const void *msg);
479  int ReceivePortMod (const void *msg);
480  int ReceiveStatsRequest (const void *oh);
481  int ReceiveEchoRequest (const void *oh);
482  int ReceiveEchoReply (const void *oh);
483  int ReceiveVPortMod (const void *msg);
484  int ReceiveVPortTableFeaturesRequest (const void *msg);
490 
494  uint32_t m_ifIndex;
495  uint16_t m_mtu;
496 
497  typedef std::map<uint32_t,ofi::SwitchPacketMetadata> PacketData_t;
499 
500  typedef std::vector<ofi::Port> Ports_t;
502 
504 
505  uint64_t m_id;
507 
509  uint16_t m_flags;
510  uint16_t m_missSendLen;
511 
512  sw_chain *m_chain;
513  vport_table_t m_vportTable;
514 };
515 
516 } // namespace ns3
517 
518 #endif /* OPENFLOW_SWITCH_NET_DEVICE_H */
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::OpenFlowSwitchNetDevice::GetBroadcast
virtual Address GetBroadcast(void) const
ns3::OpenFlowSwitchNetDevice::GetMulticast
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
ns3::OpenFlowSwitchNetDevice::GetChannel
virtual Ptr< Channel > GetChannel(void) const
ns3::OpenFlowSwitchNetDevice::m_flags
uint16_t m_flags
Flags; configurable by the controller.
Definition: openflow-switch-net-device.h:509
ns3::OpenFlowSwitchNetDevice::m_address
Mac48Address m_address
Address of this device.
Definition: openflow-switch-net-device.h:491
ns3::OpenFlowSwitchNetDevice::SendPortStatus
void SendPortStatus(ofi::Port p, uint8_t status)
Send a reply about a Port's status to the controller.
ns3::Callback< void >
ns3::OpenFlowSwitchNetDevice::IsPointToPoint
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::OpenFlowSwitchNetDevice::AddVPort
int AddVPort(const ofp_vport_mod *ovpm)
Add a virtual port to a switch device.
ns3::OpenFlowSwitchNetDevice::m_lastExecute
Time m_lastExecute
Last time the periodic execution occurred.
Definition: openflow-switch-net-device.h:508
ns3::OpenFlowSwitchNetDevice::GetHardwareDescription
static const char * GetHardwareDescription()
ns3::OpenFlowSwitchNetDevice::GetNode
virtual Ptr< Node > GetNode(void) const
ns3::OpenFlowSwitchNetDevice::SendErrorMsg
void SendErrorMsg(uint16_t type, uint16_t code, const void *data, size_t len)
If an error message happened during the controller's request, send it to the controller.
ns3::OpenFlowSwitchNetDevice
A net device that switches multiple LAN segments via an OpenFlow-compatible flow table.
Definition: openflow-switch-net-device.h:87
ns3::OpenFlowSwitchNetDevice::SetNode
virtual void SetNode(Ptr< Node > node)
ns3::OpenFlowSwitchNetDevice::m_channel
Ptr< BridgeChannel > m_channel
Collection of port channels into the Switch Channel.
Definition: openflow-switch-net-device.h:493
ns3::OpenFlowSwitchNetDevice::SendFeaturesReply
void SendFeaturesReply()
Send a reply about this OpenFlow switch's features to the controller.
ns3::OpenFlowSwitchNetDevice::SendFlowExpired
void SendFlowExpired(sw_flow *flow, enum ofp_flow_expired_reason reason)
Send a reply to the controller that a specific flow has expired.
ns3::OpenFlowSwitchNetDevice::GetSwitchPortIndex
int GetSwitchPortIndex(ofi::Port p)
ns3::OpenFlowSwitchNetDevice::SupportsSendFrom
virtual bool SupportsSendFrom() const
ns3::OpenFlowSwitchNetDevice::~OpenFlowSwitchNetDevice
virtual ~OpenFlowSwitchNetDevice()
ns3::OpenFlowSwitchNetDevice::Send
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
openflow-interface.h
ns3::OpenFlowSwitchNetDevice::m_vportTable
vport_table_t m_vportTable
Virtual Port Table.
Definition: openflow-switch-net-device.h:513
ns3::OpenFlowSwitchNetDevice::m_node
Ptr< Node > m_node
Node this device is installed on.
Definition: openflow-switch-net-device.h:492
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::OpenFlowSwitchNetDevice::GetSoftwareDescription
static const char * GetSoftwareDescription()
ns3::Ipv6Address
Describes an IPv6 address.
Definition: ipv6-address.h:50
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
ns3::OpenFlowSwitchNetDevice::MakeOpenflowReply
void * MakeOpenflowReply(size_t openflow_len, uint8_t type, ofpbuf **bufferp)
Generates an OpenFlow reply message based on the type.
ns3::OpenFlowSwitchNetDevice::ModFlow
int ModFlow(const ofp_flow_mod *ofm)
Modify a flow.
ns3::OpenFlowSwitchNetDevice::ReceiveFromDevice
void ReceiveFromDevice(Ptr< NetDevice > netdev, Ptr< const Packet > packet, uint16_t protocol, const Address &src, const Address &dst, PacketType packetType)
Called when a packet is received on one of the switch's ports.
ns3::OpenFlowSwitchNetDevice::NeedsArp
virtual bool NeedsArp(void) const
ns3::OpenFlowSwitchNetDevice::GetVPortTable
vport_table_t GetVPortTable()
ns3::OpenFlowSwitchNetDevice::m_lookupDelay
Time m_lookupDelay
Flow Table Lookup Delay [overhead].
Definition: openflow-switch-net-device.h:506
ns3::OpenFlowSwitchNetDevice::DoOutput
void DoOutput(uint32_t packet_uid, int in_port, size_t max_len, int out_port, bool ignore_no_fwd)
Called from the OpenFlow Interface to output the Packet on either a Port or the Controller.
ns3::OpenFlowSwitchNetDevice::ReceiveFeaturesRequest
int ReceiveFeaturesRequest(const void *msg)
ns3::OpenFlowSwitchNetDevice::GetNSwitchPorts
uint32_t GetNSwitchPorts(void) const
ns3::OpenFlowSwitchNetDevice::SetReceiveCallback
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
ns3::OpenFlowSwitchNetDevice::OutputAll
int OutputAll(uint32_t packet_uid, int in_port, bool flood)
Send packets out all the ports except the originating one.
ns3::OpenFlowSwitchNetDevice::OutputPacket
void OutputPacket(uint32_t packet_uid, int out_port)
Sends a copy of the Packet over the provided output port.
ns3::OpenFlowSwitchNetDevice::DoDispose
virtual void DoDispose(void)
Destructor implementation.
ns3::OpenFlowSwitchNetDevice::m_mtu
uint16_t m_mtu
Maximum Transmission Unit.
Definition: openflow-switch-net-device.h:495
ns3::OpenFlowSwitchNetDevice::ReceiveStatsRequest
int ReceiveStatsRequest(const void *oh)
ns3::OpenFlowSwitchNetDevice::m_rxCallback
NetDevice::ReceiveCallback m_rxCallback
Callbacks.
Definition: openflow-switch-net-device.h:488
ns3::OpenFlowSwitchNetDevice::GetSwitchPort
ofi::Port GetSwitchPort(uint32_t n) const
ns3::OpenFlowSwitchNetDevice::SetMtu
virtual bool SetMtu(const uint16_t mtu)
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::OpenFlowSwitchNetDevice::UpdatePortStatus
int UpdatePortStatus(ofi::Port &p)
Update the port status field of the switch port.
ns3::OpenFlowSwitchNetDevice::SetIfIndex
virtual void SetIfIndex(const uint32_t index)
ns3::OpenFlowSwitchNetDevice::RunThroughVPortTable
int RunThroughVPortTable(uint32_t packet_uid, int port, uint32_t vport)
Run the packet through the vport table.
ns3::ofi::Port
Port and its metadata.
Definition: openflow-interface.h:122
ns3::OpenFlowSwitchNetDevice::FillPortDesc
void FillPortDesc(ofi::Port p, ofp_phy_port *desc)
Fill out a description of the switch port.
ns3::OpenFlowSwitchNetDevice::StatsDone
void StatsDone(ofi::StatsDumpCallback *cb_)
Stats callback is done.
ns3::OpenFlowSwitchNetDevice::IsBridge
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::OpenFlowSwitchNetDevice::RunThroughFlowTable
void RunThroughFlowTable(uint32_t packet_uid, int port, bool send_to_controller=true)
Run the packet through the flow table.
data
uint8_t data[writeSize]
Definition: socket-bound-tcp-static-routing.cc:53
ns3::OpenFlowSwitchNetDevice::m_id
uint64_t m_id
Unique identifier for this switch, needed for OpenFlow.
Definition: openflow-switch-net-device.h:505
ns3::OpenFlowSwitchNetDevice::SetAddress
virtual void SetAddress(Address address)
Set the address of this interface.
ns3::OpenFlowSwitchNetDevice::OpenFlowSwitchNetDevice
OpenFlowSwitchNetDevice()
ns3::OpenFlowSwitchNetDevice::m_chain
sw_chain * m_chain
Flow Table; forwarding rules.
Definition: openflow-switch-net-device.h:512
first.address
address
Definition: first.py:44
ns3::OpenFlowSwitchNetDevice::GetIfIndex
virtual uint32_t GetIfIndex(void) const
ns3::OpenFlowSwitchNetDevice::BufferFromPacket
ofpbuf * BufferFromPacket(Ptr< const Packet > packet, Address src, Address dst, int mtu, uint16_t protocol)
Takes a packet and generates an OpenFlow buffer from it, loading the packet data as well as its heade...
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::OpenFlowSwitchNetDevice::GetTypeId
static TypeId GetTypeId(void)
Register this type.
ns3::OpenFlowSwitchNetDevice::AddFlow
int AddFlow(const ofp_flow_mod *ofm)
Add a flow.
ns3::OpenFlowSwitchNetDevice::ForwardControlInput
int ForwardControlInput(const void *msg, size_t length)
The registered controller calls this method when sending a message to the switch.
ns3::OpenFlowSwitchNetDevice::GetMulticast
virtual Address GetMulticast(Ipv6Address addr) const
Get the MAC multicast address corresponding to the IPv6 address provided.
ns3::OpenFlowSwitchNetDevice::ReceivePacketOut
int ReceivePacketOut(const void *msg)
ns3::OpenFlowSwitchNetDevice::ReceiveSetConfig
int ReceiveSetConfig(const void *msg)
ns3::OpenFlowSwitchNetDevice::m_packetData
PacketData_t m_packetData
Packet data.
Definition: openflow-switch-net-device.h:498
ns3::OpenFlowSwitchNetDevice::m_controller
Ptr< ofi::Controller > m_controller
Connection to controller.
Definition: openflow-switch-net-device.h:503
ns3::OpenFlowSwitchNetDevice::GetManufacturerDescription
static const char * GetManufacturerDescription()
ns3::OpenFlowSwitchNetDevice::IsMulticast
virtual bool IsMulticast(void) const
ns3::OpenFlowSwitchNetDevice::m_promiscRxCallback
NetDevice::PromiscReceiveCallback m_promiscRxCallback
Definition: openflow-switch-net-device.h:489
ns3::OpenFlowSwitchNetDevice::ReceiveVPortTableFeaturesRequest
int ReceiveVPortTableFeaturesRequest(const void *msg)
ns3::OpenFlowSwitchNetDevice::SendFrom
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
ns3::OpenFlowSwitchNetDevice::SetController
void SetController(Ptr< ofi::Controller > c)
Set up the Switch's controller connection.
ns3::OpenFlowSwitchNetDevice::IsLinkUp
virtual bool IsLinkUp(void) const
ns3::OpenFlowSwitchNetDevice::StatsDump
int StatsDump(ofi::StatsDumpCallback *cb_)
Stats callback is ready for a dump.
ns3::OpenFlowSwitchNetDevice::IsBroadcast
virtual bool IsBroadcast(void) const
ns3::OpenFlowSwitchNetDevice::GetAddress
virtual Address GetAddress(void) const
ns3::OpenFlowSwitchNetDevice::FlowTableLookup
void FlowTableLookup(sw_flow_key key, ofpbuf *buffer, uint32_t packet_uid, int port, bool send_to_controller)
Called by RunThroughFlowTable on a scheduled delay to account for the flow table lookup overhead.
ns3::OpenFlowSwitchNetDevice::SendOpenflowBuffer
int SendOpenflowBuffer(ofpbuf *buffer)
Send a message to the controller.
ns3::OpenFlowSwitchNetDevice::PacketData_t
std::map< uint32_t, ofi::SwitchPacketMetadata > PacketData_t
Definition: openflow-switch-net-device.h:497
ns3::OpenFlowSwitchNetDevice::ReceiveFlow
int ReceiveFlow(const void *msg)
ns3::OpenFlowSwitchNetDevice::ReceiveEchoRequest
int ReceiveEchoRequest(const void *oh)
ns3::OpenFlowSwitchNetDevice::GetSerialNumber
static const char * GetSerialNumber()
ns3::OpenFlowSwitchNetDevice::GetChain
sw_chain * GetChain()
ns3::OpenFlowSwitchNetDevice::ReceiveVPortMod
int ReceiveVPortMod(const void *msg)
ns3::NetDevice::PacketType
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:297
ns3::OpenFlowSwitchNetDevice::Ports_t
std::vector< ofi::Port > Ports_t
Definition: openflow-switch-net-device.h:500
ns3::OpenFlowSwitchNetDevice::m_ifIndex
uint32_t m_ifIndex
Interface Index.
Definition: openflow-switch-net-device.h:494
ns3::OpenFlowSwitchNetDevice::AddLinkChangeCallback
virtual void AddLinkChangeCallback(Callback< void > callback)
ns3::OpenFlowSwitchNetDevice::OutputPort
void OutputPort(uint32_t packet_uid, int in_port, int out_port, bool ignore_no_fwd)
Seeks to send out a Packet over the provided output port.
ns3::OpenFlowSwitchNetDevice::SendVPortTableFeatures
void SendVPortTableFeatures()
Send a reply about this OpenFlow switch's virtual port table features to the controller.
ns3::OpenFlowSwitchNetDevice::ReceiveGetConfigRequest
int ReceiveGetConfigRequest(const void *msg)
ns3::OpenFlowSwitchNetDevice::m_ports
Ports_t m_ports
Switch's ports.
Definition: openflow-switch-net-device.h:501
ns3::OpenFlowSwitchNetDevice::AddSwitchPort
int AddSwitchPort(Ptr< NetDevice > switchPort)
Add a 'port' to a switch device.
ns3::OpenFlowSwitchNetDevice::OutputControl
void OutputControl(uint32_t packet_uid, int in_port, size_t max_len, int reason)
Sends a copy of the Packet to the controller.
ns3::OpenFlowSwitchNetDevice::m_missSendLen
uint16_t m_missSendLen
Flow Table Miss Send Length; configurable by the controller.
Definition: openflow-switch-net-device.h:510
sample-rng-plot.n
n
Definition: sample-rng-plot.py:37
ns3::OpenFlowSwitchNetDevice::ReceiveEchoReply
int ReceiveEchoReply(const void *oh)
ns3::NetDevice
Network layer to device interface.
Definition: net-device.h:96
ns3::OpenFlowSwitchNetDevice::GetMtu
virtual uint16_t GetMtu(void) const
port
uint16_t port
Definition: dsdv-manet.cc:45
ns3::ofi::StatsDumpCallback
Callback for a stats dump request.
Definition: openflow-interface.h:320
ns3::OpenFlowSwitchNetDevice::SetPromiscReceiveCallback
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
ns3::OpenFlowSwitchNetDevice::ReceivePortMod
int ReceivePortMod(const void *msg)