A Discrete-Event Network Simulator
API
openflow-switch-net-device.h
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation;
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 *
15 * Author: Blake Hurd <naimorai@gmail.com>
16 */
17
24#ifndef OPENFLOW_SWITCH_NET_DEVICE_H
25#define OPENFLOW_SWITCH_NET_DEVICE_H
26
27#include "openflow-interface.h"
28
29#include "ns3/arp-header.h"
30#include "ns3/arp-l3-protocol.h"
31#include "ns3/bridge-channel.h"
32#include "ns3/enum.h"
33#include "ns3/ethernet-header.h"
34#include "ns3/integer.h"
35#include "ns3/ipv4-l3-protocol.h"
36#include "ns3/log.h"
37#include "ns3/mac48-address.h"
38#include "ns3/node.h"
39#include "ns3/simulator.h"
40#include "ns3/string.h"
41#include "ns3/tcp-header.h"
42#include "ns3/udp-header.h"
43#include "ns3/uinteger.h"
44
45#include <map>
46#include <set>
47
48namespace ns3
49{
50
91{
92 public:
97 static TypeId GetTypeId();
98
113 static const char* GetManufacturerDescription();
114 static const char* GetHardwareDescription();
115 static const char* GetSoftwareDescription();
116 static const char* GetSerialNumber();
121
128
146
160 int AddVPort(const ofp_vport_mod* ovpm);
161
171
180
192 void DoOutput(uint32_t packet_uid,
193 int in_port,
194 size_t max_len,
195 int out_port,
196 bool ignore_no_fwd);
197
205 int ForwardControlInput(const void* msg, size_t length);
206
210 sw_chain* GetChain();
211
216
222
228
232 vport_table_t GetVPortTable();
233
234 // From NetDevice
235 void SetIfIndex(const uint32_t index) override;
236 uint32_t GetIfIndex() const override;
237 Ptr<Channel> GetChannel() const override;
238 void SetAddress(Address address) override;
239 Address GetAddress() const override;
240 bool SetMtu(const uint16_t mtu) override;
241 uint16_t GetMtu() const override;
242 bool IsLinkUp() const override;
243 void AddLinkChangeCallback(Callback<void> callback) override;
244 bool IsBroadcast() const override;
245 Address GetBroadcast() const override;
246 bool IsMulticast() const override;
247 Address GetMulticast(Ipv4Address multicastGroup) const override;
248 bool IsPointToPoint() const override;
249 bool IsBridge() const override;
250 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
252 const Address& source,
253 const Address& dest,
254 uint16_t protocolNumber) override;
255 Ptr<Node> GetNode() const override;
256 void SetNode(Ptr<Node> node) override;
257 bool NeedsArp() const override;
260 bool SupportsSendFrom() const override;
261 Address GetMulticast(Ipv6Address addr) const override;
262
263 protected:
264 void DoDispose() override;
265
277 Ptr<const Packet> packet,
278 uint16_t protocol,
279 const Address& src,
280 const Address& dst,
281 PacketType packetType);
282
295 Address src,
296 Address dst,
297 int mtu,
298 uint16_t protocol);
299
300 private:
309 int AddFlow(const ofp_flow_mod* ofm);
310
317 int ModFlow(const ofp_flow_mod* ofm);
318
328 int OutputAll(uint32_t packet_uid, int in_port, bool flood);
329
336 void OutputPacket(uint32_t packet_uid, int out_port);
337
349 void OutputPort(uint32_t packet_uid, int in_port, int out_port, bool ignore_no_fwd);
350
362 void OutputControl(uint32_t packet_uid, int in_port, size_t max_len, int reason);
363
372 void SendErrorMsg(uint16_t type, uint16_t code, const void* data, size_t len);
373
396
403 void SendFlowExpired(sw_flow* flow, enum ofp_flow_expired_reason reason);
404
411 void SendPortStatus(ofi::Port p, uint8_t status);
412
417
427 int SendOpenflowBuffer(ofpbuf* buffer);
428
437 void RunThroughFlowTable(uint32_t packet_uid, int port, bool send_to_controller = true);
438
448 int RunThroughVPortTable(uint32_t packet_uid, int port, uint32_t vport);
449
460 void FlowTableLookup(sw_flow_key key,
461 ofpbuf* buffer,
462 uint32_t packet_uid,
463 int port,
464 bool send_to_controller);
465
475
483 void FillPortDesc(ofi::Port p, ofp_phy_port* desc);
484
493 void* MakeOpenflowReply(size_t openflow_len, uint8_t type, ofpbuf** bufferp);
494
506 int ReceiveFeaturesRequest(const void* msg);
507 int ReceiveGetConfigRequest(const void* msg);
508 int ReceiveSetConfig(const void* msg);
509 int ReceivePacketOut(const void* msg);
510 int ReceiveFlow(const void* msg);
511 int ReceivePortMod(const void* msg);
512 int ReceiveStatsRequest(const void* msg);
513 int ReceiveEchoRequest(const void* msg);
514 int ReceiveEchoReply(const void* msg);
515 int ReceiveVPortMod(const void* msg);
523
528 uint16_t m_mtu;
529
531 typedef std::map<uint32_t, ofi::SwitchPacketMetadata> PacketData_t;
533
535 typedef std::vector<ofi::Port> Ports_t;
537
539
540 uint64_t m_id;
542
544 uint16_t m_flags;
545 uint16_t m_missSendLen;
546
547 sw_chain* m_chain;
548 vport_table_t m_vportTable;
549};
550
551} // namespace ns3
552
553#endif /* OPENFLOW_SWITCH_NET_DEVICE_H */
a polymophic address class
Definition: address.h:92
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
Describes an IPv6 address.
Definition: ipv6-address.h:50
an EUI-48 address
Definition: mac48-address.h:46
Network layer to device interface.
Definition: net-device.h:98
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:300
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.
Address GetBroadcast() const override
Mac48Address m_address
Address of this device.
ofi::Port GetSwitchPort(uint32_t n) const
bool IsBroadcast() const override
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.
uint32_t GetNSwitchPorts() const
int ReceiveGetConfigRequest(const void *msg)
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
uint32_t GetIfIndex() const override
void * MakeOpenflowReply(size_t openflow_len, uint8_t type, ofpbuf **bufferp)
Generates an OpenFlow reply message based on the type.
Ptr< Channel > GetChannel() const override
static const char * GetSoftwareDescription()
Ptr< BridgeChannel > m_channel
Collection of port channels into the Switch Channel.
void SetNode(Ptr< Node > node) override
int ReceiveVPortMod(const void *msg)
int ReceiveSetConfig(const void *msg)
bool IsLinkUp() const override
void SendPortStatus(ofi::Port p, uint8_t status)
Send a reply about a Port's status to the controller.
Ptr< Node > GetNode() const override
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 * GetManufacturerDescription()
void RunThroughFlowTable(uint32_t packet_uid, int port, bool send_to_controller=true)
Run the packet through the flow table.
static const char * GetHardwareDescription()
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)
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.
int ModFlow(const ofp_flow_mod *ofm)
Modify a flow.
vport_table_t m_vportTable
Virtual Port Table.
bool IsBridge() const override
Return true if the net device is acting as a bridge.
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.
bool SetMtu(const uint16_t mtu) override
int UpdatePortStatus(ofi::Port &p)
Update the port status field of the switch port.
static const char * GetSerialNumber()
uint16_t m_flags
Flags; configurable by the controller.
void SetAddress(Address address) override
Set the address of this interface.
uint16_t GetMtu() const override
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)
void AddLinkChangeCallback(Callback< void > callback) override
uint16_t m_missSendLen
Flow Table Miss Send Length; configurable by the controller.
int ReceivePortMod(const void *msg)
static TypeId GetTypeId()
Register this type.
bool NeedsArp() const override
Address GetMulticast(Ipv6Address addr) const override
Get the MAC multicast address corresponding to the IPv6 address provided.
bool SupportsSendFrom() const override
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
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.
std::map< uint32_t, ofi::SwitchPacketMetadata > PacketData_t
PacketData type.
int AddSwitchPort(Ptr< NetDevice > switchPort)
Add a 'port' to a switch device.
Address GetAddress() const override
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.
void DoDispose() override
Destructor implementation.
int StatsDump(ofi::StatsDumpCallback *cb_)
Stats callback is ready for a dump.
Time m_lookupDelay
Flow Table Lookup Delay [overhead].
int ReceiveEchoRequest(const void *msg)
int AddFlow(const ofp_flow_mod *ofm)
Add a flow.
int RunThroughVPortTable(uint32_t packet_uid, int port, uint32_t vport)
Run the packet through the vport table.
NetDevice::ReceiveCallback m_rxCallback
Rx Callback.
void SetIfIndex(const uint32_t index) override
void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb) override
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.
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...
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
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.
bool IsMulticast() const override
int ReceiveVPortTableFeaturesRequest(const void *msg)
sw_chain * m_chain
Flow Table; forwarding rules.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
int ReceiveFlow(const void *msg)
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
int GetSwitchPortIndex(ofi::Port p)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:60
uint16_t port
Definition: dsdv-manet.cc:45
address
Definition: first.py:40
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.