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 
94 {
95 public:
100  static TypeId GetTypeId (void);
101 
116  static const char * GetManufacturerDescription ();
117  static const char * GetHardwareDescription ();
118  static const char * GetSoftwareDescription ();
119  static const char * GetSerialNumber ();
124 
131 
148  int AddSwitchPort (Ptr<NetDevice> switchPort);
149 
163  int AddVPort (const ofp_vport_mod *ovpm);
164 
174 
183 
193  void DoOutput (uint32_t packet_uid, int in_port, size_t max_len, int out_port, bool ignore_no_fwd);
194 
202  int ForwardControlInput (const void *msg, size_t length);
203 
207  sw_chain* GetChain ();
208 
212  uint32_t GetNSwitchPorts (void) const;
213 
219 
224  ofi::Port GetSwitchPort (uint32_t n) const;
225 
229  vport_table_t GetVPortTable ();
230 
231  // From NetDevice
232  virtual void SetIfIndex (const uint32_t index);
233  virtual uint32_t GetIfIndex (void) const;
234  virtual Ptr<Channel> GetChannel (void) const;
235  virtual void SetAddress (Address address);
236  virtual Address GetAddress (void) const;
237  virtual bool SetMtu (const uint16_t mtu);
238  virtual uint16_t GetMtu (void) const;
239  virtual bool IsLinkUp (void) const;
240  virtual void AddLinkChangeCallback (Callback<void> callback);
241  virtual bool IsBroadcast (void) const;
242  virtual Address GetBroadcast (void) const;
243  virtual bool IsMulticast (void) const;
244  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
245  virtual bool IsPointToPoint (void) const;
246  virtual bool IsBridge (void) const;
247  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
248  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
249  virtual Ptr<Node> GetNode (void) const;
250  virtual void SetNode (Ptr<Node> node);
251  virtual bool NeedsArp (void) const;
254  virtual bool SupportsSendFrom () const;
255  virtual Address GetMulticast (Ipv6Address addr) const;
256 
257 protected:
258  virtual void DoDispose (void);
259 
270  void ReceiveFromDevice (Ptr<NetDevice> netdev, Ptr<const Packet> packet, uint16_t protocol, const Address& src, const Address& dst, PacketType packetType);
271 
282  ofpbuf * BufferFromPacket (Ptr<const Packet> packet, Address src, Address dst, int mtu, uint16_t protocol);
283 
284 private:
293  int AddFlow (const ofp_flow_mod *ofm);
294 
301  int ModFlow (const ofp_flow_mod *ofm);
302 
311  int OutputAll (uint32_t packet_uid, int in_port, bool flood);
312 
319  void OutputPacket (uint32_t packet_uid, int out_port);
320 
332  void OutputPort (uint32_t packet_uid, int in_port, int out_port, bool ignore_no_fwd);
333 
344  void OutputControl (uint32_t packet_uid, int in_port, size_t max_len, int reason);
345 
354  void SendErrorMsg (uint16_t type, uint16_t code, const void *data, size_t len);
355 
378 
385  void SendFlowExpired (sw_flow *flow, enum ofp_flow_expired_reason reason);
386 
393  void SendPortStatus (ofi::Port p, uint8_t status);
394 
399 
409  int SendOpenflowBuffer (ofpbuf *buffer);
410 
419  void RunThroughFlowTable (uint32_t packet_uid, int port, bool send_to_controller = true);
420 
430  int RunThroughVPortTable (uint32_t packet_uid, int port, uint32_t vport);
431 
442  void FlowTableLookup (sw_flow_key key, ofpbuf* buffer, uint32_t packet_uid, int port, bool send_to_controller);
443 
452 
459  void FillPortDesc (ofi::Port p, ofp_phy_port *desc);
460 
469  void* MakeOpenflowReply (size_t openflow_len, uint8_t type, ofpbuf **bufferp);
470 
482  int ReceiveFeaturesRequest (const void *msg);
483  int ReceiveGetConfigRequest (const void *msg);
484  int ReceiveSetConfig (const void *msg);
485  int ReceivePacketOut (const void *msg);
486  int ReceiveFlow (const void *msg);
487  int ReceivePortMod (const void *msg);
488  int ReceiveStatsRequest (const void *msg);
489  int ReceiveEchoRequest (const void *msg);
490  int ReceiveEchoReply (const void *msg);
491  int ReceiveVPortMod (const void *msg);
492  int ReceiveVPortTableFeaturesRequest (const void *msg);
499 
503  uint32_t m_ifIndex;
504  uint16_t m_mtu;
505 
507  typedef std::map<uint32_t,ofi::SwitchPacketMetadata> PacketData_t;
509 
511  typedef std::vector<ofi::Port> Ports_t;
513 
515 
516  uint64_t m_id;
518 
520  uint16_t m_flags;
521  uint16_t m_missSendLen;
522 
523  sw_chain *m_chain;
524  vport_table_t m_vportTable;
525 };
526 
527 } // namespace ns3
528 
529 #endif /* OPENFLOW_SWITCH_NET_DEVICE_H */
a polymophic address class
Definition: address.h:91
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Describes an IPv6 address.
Definition: ipv6-address.h:50
an EUI-48 address
Definition: mac48-address.h:44
Network layer to device interface.
Definition: net-device.h:96
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:297
A net device that switches multiple LAN segments via an OpenFlow-compatible flow table.
int ReceiveStatsRequest(const void *msg)
void OutputControl(uint32_t packet_uid, int in_port, size_t max_len, int reason)
Sends a copy of the Packet to the controller.
Mac48Address m_address
Address of this device.
ofi::Port GetSwitchPort(uint32_t n) const
int ReceiveFeaturesRequest(const void *msg)
Ptr< Node > m_node
Node this device is installed on.
uint64_t m_id
Unique identifier for this switch, needed for OpenFlow.
int ReceiveGetConfigRequest(const void *msg)
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual bool SetMtu(const uint16_t mtu)
Ptr< BridgeChannel > m_channel
Collection of port channels into the Switch Channel.
int ReceiveVPortMod(const void *msg)
uint32_t GetNSwitchPorts(void) const
int ReceiveSetConfig(const void *msg)
void SendPortStatus(ofi::Port p, uint8_t status)
Send a reply about a Port's status to the controller.
uint16_t m_mtu
Maximum Transmission Unit.
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.
static const char * GetSerialNumber()
virtual void AddLinkChangeCallback(Callback< void > callback)
void RunThroughFlowTable(uint32_t packet_uid, int port, bool send_to_controller=true)
Run the packet through the flow table.
virtual uint32_t GetIfIndex(void) const
void SendFlowExpired(sw_flow *flow, enum ofp_flow_expired_reason reason)
Send a reply to the controller that a specific flow has expired.
int ReceiveEchoReply(const void *msg)
virtual void SetAddress(Address address)
Set the address of this interface.
virtual Address GetMulticast(Ipv6Address addr) const
Get the MAC multicast address corresponding to the IPv6 address provided.
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.
virtual Address GetAddress(void) const
int ModFlow(const ofp_flow_mod *ofm)
Modify a flow.
virtual bool IsMulticast(void) const
vport_table_t m_vportTable
Virtual Port Table.
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...
void SendFeaturesReply()
Send a reply about this OpenFlow switch's features to the controller.
void SendVPortTableFeatures()
Send a reply about this OpenFlow switch's virtual port table features to the controller.
Time m_lastExecute
Last time the periodic execution occurred.
int ForwardControlInput(const void *msg, size_t length)
The registered controller calls this method when sending a message to the switch.
void * MakeOpenflowReply(size_t openflow_len, uint8_t type, ofpbuf **bufferp)
Generates an OpenFlow reply message based on the type.
virtual uint16_t GetMtu(void) const
int UpdatePortStatus(ofi::Port &p)
Update the port status field of the switch port.
static const char * GetSoftwareDescription()
uint16_t m_flags
Flags; configurable by the controller.
virtual Ptr< Channel > GetChannel(void) const
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual void SetNode(Ptr< Node > node)
static const char * GetManufacturerDescription()
virtual bool IsLinkUp(void) const
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.
int ReceivePacketOut(const void *msg)
uint16_t m_missSendLen
Flow Table Miss Send Length; configurable by the controller.
int ReceivePortMod(const void *msg)
virtual void DoDispose(void)
Destructor implementation.
virtual void SetIfIndex(const uint32_t index)
static const char * GetHardwareDescription()
vport_table_t GetVPortTable()
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.
void StatsDone(ofi::StatsDumpCallback *cb_)
Stats callback is done.
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.
void OutputPacket(uint32_t packet_uid, int out_port)
Sends a copy of the Packet over the provided output port.
static TypeId GetTypeId(void)
Register this type.
int AddSwitchPort(Ptr< NetDevice > switchPort)
Add a 'port' to a switch device.
int SendOpenflowBuffer(ofpbuf *buffer)
Send a message to the controller.
void SetController(Ptr< ofi::Controller > c)
Set up the Switch's controller connection.
NetDevice::PromiscReceiveCallback m_promiscRxCallback
Promiscuopus Rx Callback.
std::map< uint32_t, ofi::SwitchPacketMetadata > PacketData_t
PacketData type.
int StatsDump(ofi::StatsDumpCallback *cb_)
Stats callback is ready for a dump.
Time m_lookupDelay
Flow Table Lookup Delay [overhead].
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
int ReceiveEchoRequest(const void *msg)
int AddFlow(const ofp_flow_mod *ofm)
Add a flow.
virtual Ptr< Node > GetNode(void) const
int RunThroughVPortTable(uint32_t packet_uid, int port, uint32_t vport)
Run the packet through the vport table.
virtual bool NeedsArp(void) const
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
NetDevice::ReceiveCallback m_rxCallback
Rx Callback.
int OutputAll(uint32_t packet_uid, int in_port, bool flood)
Send packets out all the ports except the originating one.
int AddVPort(const ofp_vport_mod *ovpm)
Add a virtual port to a switch device.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Ptr< ofi::Controller > m_controller
Connection to controller.
std::vector< ofi::Port > Ports_t
Switch's port type.
void FillPortDesc(ofi::Port p, ofp_phy_port *desc)
Fill out a description of the switch port.
virtual bool SupportsSendFrom() const
int ReceiveVPortTableFeaturesRequest(const void *msg)
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
sw_chain * m_chain
Flow Table; forwarding rules.
virtual Address GetBroadcast(void) const
int ReceiveFlow(const void *msg)
int GetSwitchPortIndex(ofi::Port p)
virtual bool IsBroadcast(void) const
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
a unique identifier for an interface.
Definition: type-id.h:59
uint16_t port
Definition: dsdv-manet.cc:45
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]
Port and its metadata.
Callback for a stats dump request.