A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
89  static TypeId GetTypeId (void);
90 
100  //\{
101  static const char * GetManufacturerDescription ();
102  static const char * GetHardwareDescription ();
103  static const char * GetSoftwareDescription ();
104  static const char * GetSerialNumber ();
105  //\}
106 
108  virtual ~OpenFlowSwitchNetDevice ();
109 
116 
133  int AddSwitchPort (Ptr<NetDevice> switchPort);
134 
148  int AddVPort (const ofp_vport_mod *ovpm);
149 
159 
167  void StatsDone (ofi::StatsDumpCallback *cb_);
168 
178  void DoOutput (uint32_t packet_uid, int in_port, size_t max_len, int out_port, bool ignore_no_fwd);
179 
187  int ForwardControlInput (const void *msg, size_t length);
188 
192  sw_chain* GetChain ();
193 
197  uint32_t GetNSwitchPorts (void) const;
198 
204 
209  ofi::Port GetSwitchPort (uint32_t n) const;
210 
214  vport_table_t GetVPortTable ();
215 
217  //\{
218  virtual void SetIfIndex (const uint32_t index);
219  virtual uint32_t GetIfIndex (void) const;
220  virtual Ptr<Channel> GetChannel (void) const;
221  virtual void SetAddress (Address address);
222  virtual Address GetAddress (void) const;
223  virtual bool SetMtu (const uint16_t mtu);
224  virtual uint16_t GetMtu (void) const;
225  virtual bool IsLinkUp (void) const;
226  virtual void AddLinkChangeCallback (Callback<void> callback);
227  virtual bool IsBroadcast (void) const;
228  virtual Address GetBroadcast (void) const;
229  virtual bool IsMulticast (void) const;
230  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
231  virtual bool IsPointToPoint (void) const;
232  virtual bool IsBridge (void) const;
233  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
234  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
235  virtual Ptr<Node> GetNode (void) const;
236  virtual void SetNode (Ptr<Node> node);
237  virtual bool NeedsArp (void) const;
240  virtual bool SupportsSendFrom () const;
241  virtual Address GetMulticast (Ipv6Address addr) const;
242  //\}
243 
244 protected:
245  virtual void DoDispose (void);
246 
259  void ReceiveFromDevice (Ptr<NetDevice> netdev, Ptr<const Packet> packet, uint16_t protocol, const Address& src, const Address& dst, PacketType packetType);
260 
273  ofpbuf * BufferFromPacket (Ptr<Packet> packet, Address src, Address dst, int mtu, uint16_t protocol);
274 
275 private:
286  int AddFlow (const ofp_flow_mod *ofm);
287 
296  int ModFlow (const ofp_flow_mod *ofm);
297 
308  int OutputAll (uint32_t packet_uid, int in_port, bool flood);
309 
317  void OutputPacket (uint32_t packet_uid, int out_port);
318 
332  void OutputPort (uint32_t packet_uid, int in_port, int out_port, bool ignore_no_fwd);
333 
346  void OutputControl (uint32_t packet_uid, int in_port, size_t max_len, int reason);
347 
358  void SendErrorMsg (uint16_t type, uint16_t code, const void *data, size_t len);
359 
383  void SendFeaturesReply ();
384 
393  void SendFlowExpired (sw_flow *flow, enum ofp_flow_expired_reason reason);
394 
403  void SendPortStatus (ofi::Port p, uint8_t status);
404 
410  void SendVPortTableFeatures ();
411 
423  int SendOpenflowBuffer (ofpbuf *buffer);
424 
435  void RunThroughFlowTable (uint32_t packet_uid, int port, bool send_to_controller = true);
436 
448  int RunThroughVPortTable (uint32_t packet_uid, int port, uint32_t vport);
449 
462  void FlowTableLookup (sw_flow_key key, ofpbuf* buffer, uint32_t packet_uid, int port, bool send_to_controller);
463 
473  int UpdatePortStatus (ofi::Port& p);
474 
483  void FillPortDesc (ofi::Port p, ofp_phy_port *desc);
484 
495  void* MakeOpenflowReply (size_t openflow_len, uint8_t type, ofpbuf **bufferp);
496 
506  //\{
507  int ReceiveFeaturesRequest (const void *msg);
508  int ReceiveGetConfigRequest (const void *msg);
509  int ReceiveSetConfig (const void *msg);
510  int ReceivePacketOut (const void *msg);
511  int ReceiveFlow (const void *msg);
512  int ReceivePortMod (const void *msg);
513  int ReceiveStatsRequest (const void *oh);
514  int ReceiveEchoRequest (const void *oh);
515  int ReceiveEchoReply (const void *oh);
516  int ReceiveVPortMod (const void *msg);
517  int ReceiveVPortTableFeaturesRequest (const void *msg);
518  //\}
519 
523 
527  uint32_t m_ifIndex;
528  uint16_t m_mtu;
529 
530  typedef std::map<uint32_t,ofi::SwitchPacketMetadata> PacketData_t;
532 
533  typedef std::vector<ofi::Port> Ports_t;
535 
537 
538  uint64_t m_id;
540 
542  uint16_t m_flags;
543  uint16_t m_missSendLen;
544 
545  sw_chain *m_chain;
546  vport_table_t m_vportTable;
547 };
548 
549 } // namespace ns3
550 
551 #endif /* OPENFLOW_SWITCH_NET_DEVICE_H */