6#ifndef OPENFLOW_INTERFACE_H
7#define OPENFLOW_INTERFACE_H
13#include "ns3/address.h"
15#include "ns3/mac48-address.h"
16#include "ns3/net-device.h"
17#include "ns3/nstime.h"
18#include "ns3/packet.h"
19#include "ns3/simulator.h"
26#include "openflow/ericsson-ext.h"
27#include "openflow/nicira-ext.h"
28#include "openflow/openflow.h"
33#define private _private
38#include "openflow/private/csum.h"
39#include "openflow/private/poll-loop.h"
40#include "openflow/private/rconn.h"
41#include "openflow/private/stp.h"
42#include "openflow/private/vconn.h"
43#include "openflow/private/xtoxll.h"
46#include "openflow/private/chain.h"
47#include "openflow/private/datapath.h"
48#include "openflow/private/table.h"
52#include "openflow/private/dp_act.h"
53 void set_vlan_vid(ofpbuf* buffer, sw_flow_key* key,
const ofp_action_header* ah);
54 void set_vlan_pcp(ofpbuf* buffer, sw_flow_key* key,
const ofp_action_header* ah);
55 void strip_vlan(ofpbuf* buffer, sw_flow_key* key,
const ofp_action_header* ah);
56 void set_dl_addr(ofpbuf* buffer, sw_flow_key* key,
const ofp_action_header* ah);
57 void set_nw_addr(ofpbuf* buffer, sw_flow_key* key,
const ofp_action_header* ah);
58 void set_tp_port(ofpbuf* buffer, sw_flow_key* key,
const ofp_action_header* ah);
59 void set_mpls_label(ofpbuf* buffer, sw_flow_key* key,
const ofp_action_header* ah);
60 void set_mpls_exp(ofpbuf* buffer, sw_flow_key* key,
const ofp_action_header* ah);
61#include "openflow/private/pt_act.h"
69#ifndef OFP_SUPPORTED_CAPABILITIES
70#define OFP_SUPPORTED_CAPABILITIES \
71 (OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS | OFPC_MULTI_PHY_TX | OFPC_VPORT_TABLE)
75#ifndef OFP_SUPPORTED_ACTIONS
76#define OFP_SUPPORTED_ACTIONS \
77 ((1 << OFPAT_OUTPUT) | (1 << OFPAT_SET_VLAN_VID) | (1 << OFPAT_SET_VLAN_PCP) | \
78 (1 << OFPAT_STRIP_VLAN) | (1 << OFPAT_SET_DL_SRC) | (1 << OFPAT_SET_DL_DST) | \
79 (1 << OFPAT_SET_NW_SRC) | (1 << OFPAT_SET_NW_DST) | (1 << OFPAT_SET_TP_SRC) | \
80 (1 << OFPAT_SET_TP_DST) | (1 << OFPAT_SET_MPLS_LABEL) | (1 << OFPAT_SET_MPLS_EXP))
83#ifndef OFP_SUPPORTED_VPORT_TABLE_ACTIONS
84#define OFP_SUPPORTED_VPORT_TABLE_ACTIONS \
85 ((1 << OFPPAT_OUTPUT) | (1 << OFPPAT_POP_MPLS) | (1 << OFPPAT_PUSH_MPLS) | \
86 (1 << OFPPAT_SET_MPLS_LABEL) | (1 << OFPPAT_SET_MPLS_EXP))
92class OpenFlowSwitchNetDevice;
144 Stats(ofp_stats_types _type,
size_t body_len);
154 int DoInit(
const void* body,
int body_len,
void** state);
183 ofp_flow_stats_request
rq;
217 int FlowStatsInit(
const void* body,
int body_len,
void** state);
219 int PortStatsInit(
const void* body,
int body_len,
void** state);
237 ofp_aggregate_stats_request* state,
266 static uint16_t
Validate(ofp_action_type type,
268 const sw_flow_key* key,
269 const ofp_action_header* ah);
279 static void Execute(ofp_action_type type,
282 const ofp_action_header* ah);
295 static bool IsValidType(ofp_vport_action_type type);
305 static uint16_t
Validate(ofp_vport_action_type type,
size_t len,
const ofp_action_header* ah);
315 static void Execute(ofp_vport_action_type type,
317 const sw_flow_key* key,
318 const ofp_action_header* ah);
340 static uint16_t
Validate(er_action_type type,
size_t len);
350 static void Execute(er_action_type type,
352 const sw_flow_key* key,
353 const er_action_header* ah);
363 ofp_stats_request*
rq;
556 const ofp_action_header* actions,
570 const ofp_action_header* actions,
587 const ofp_action_header* actions,
607void ExecuteVendor(ofpbuf* buffer,
const sw_flow_key* key,
const ofp_action_header* ah);
618uint16_t
ValidateVendor(
const sw_flow_key* key,
const ofp_action_header* ah, uint16_t len);
628#define PKT_BUFFER_BITS 8
629#define N_PKT_BUFFERS (1 << PKT_BUFFER_BITS)
630#define PKT_BUFFER_MASK (N_PKT_BUFFERS - 1)
631#define PKT_COOKIE_BITS (32 - PKT_BUFFER_BITS)
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
a polymophic address class
A base class which provides memory management and object aggregation.
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
An interface for a Controller of OpenFlowSwitchNetDevices.
virtual void SendToSwitch(Ptr< OpenFlowSwitchNetDevice > swtch, void *msg, size_t length)
However the controller is implemented, this method is to be used to pass a message on to a switch.
uint8_t GetPacketType(ofpbuf *buffer)
Get the packet type on the buffer, which can then be used to determine how to handle the buffer.
Switches_t m_switches
The collection of switches registered to this controller.
~Controller() override
Destructor.
virtual void ReceiveFromSwitch(Ptr< OpenFlowSwitchNetDevice > swtch, ofpbuf *buffer)
A switch calls this method to pass a message on to the Controller.
static TypeId GetTypeId()
Register this type.
ofp_flow_mod * BuildFlow(sw_flow_key key, uint32_t buffer_id, uint16_t command, void *acts, size_t actions_len, int idle_timeout, int hard_timeout)
Construct flow data from a matching key to build a flow entry for adding, modifying,...
std::set< Ptr< OpenFlowSwitchNetDevice > > Switches_t
OpenFlowSwitchNetDevice container type.
void StartDump(StatsDumpCallback *cb)
Starts a callback-based, reliable, possibly multi-message reply to a request made by the controller.
virtual void AddSwitch(Ptr< OpenFlowSwitchNetDevice > swtch)
Adds a switch to the controller.
Demonstration of a Drop controller.
void ReceiveFromSwitch(Ptr< OpenFlowSwitchNetDevice > swtch, ofpbuf *buffer) override
A switch calls this method to pass a message on to the Controller.
static TypeId GetTypeId()
Register this type.
Demonstration of a Learning controller.
static TypeId GetTypeId()
Register this type.
std::map< Mac48Address, LearnedState > LearnState_t
Learned state type.
void ReceiveFromSwitch(Ptr< OpenFlowSwitchNetDevice > swtch, ofpbuf *buffer) override
A switch calls this method to pass a message on to the Controller.
~LearningController() override
Time m_expirationTime
Time it takes for learned MAC state entry/created flow to expire.
LearnState_t m_learnState
Learned state data.
int PortStatsInit(const void *body, int body_len, void **state)
Initialize the stats.
int PortTableStatsDump(Ptr< OpenFlowSwitchNetDevice > dp, void *state, ofpbuf *buffer)
Dump the stats.
int FlowStatsDump(Ptr< OpenFlowSwitchNetDevice > dp, FlowStatsState *state, ofpbuf *buffer)
Dump the stats.
int(* AggregateDumpCallback)(sw_flow *flow, void *state)
Aggregate dump callback functor.
Stats(ofp_stats_types _type, size_t body_len)
Constructor.
void DoCleanup(void *state)
Cleans any state created by the init or dump functions.
int AggregateStatsInit(const void *body, int body_len, void **state)
Initialize the stats.
int DoDump(Ptr< OpenFlowSwitchNetDevice > swtch, void *state, ofpbuf *buffer)
Appends statistics for OpenFlowSwitchNetDevice to 'buffer'.
int DoInit(const void *body, int body_len, void **state)
Prepares to dump some kind of statistics on the connected OpenFlowSwitchNetDevice.
int AggregateStatsDump(Ptr< OpenFlowSwitchNetDevice > dp, ofp_aggregate_stats_request *state, ofpbuf *buffer)
Dump the stats.
int TableStatsDump(Ptr< OpenFlowSwitchNetDevice > dp, void *state, ofpbuf *buffer)
Dump the stats.
int PortStatsDump(Ptr< OpenFlowSwitchNetDevice > dp, PortStatsState *state, ofpbuf *buffer)
Dump the stats.
ofp_stats_types type
Status type.
int FlowStatsInit(const void *body, int body_len, void **state)
Initialize the stats.
int DescStatsDump(void *state, ofpbuf *buffer)
Dumps the stats description.
int(* FlowDumpCallback)(sw_flow *flow, void *state)
Flow dump callback functor.
void ExecuteVPortActions(Ptr< OpenFlowSwitchNetDevice > swtch, uint64_t packet_uid, ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *actions, size_t actions_len)
Executes a list of virtual port table entry actions.
void ExecuteActions(Ptr< OpenFlowSwitchNetDevice > swtch, uint64_t packet_uid, ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *actions, size_t actions_len, int ignore_no_fwd)
Executes a list of flow table actions.
uint16_t ValidateVendor(const sw_flow_key *key, const ofp_action_header *ah, uint16_t len)
Validates a vendor-defined action.
void ExecuteVendor(ofpbuf *buffer, const sw_flow_key *key, const ofp_action_header *ah)
Executes a vendor-defined action.
uint16_t ValidateActions(const sw_flow_key *key, const ofp_action_header *actions, size_t actions_len)
Validates a list of flow table actions.
uint16_t ValidateVPortActions(const ofp_action_header *actions, size_t actions_len)
Validates a list of virtual port table entry actions.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void discard_buffer(uint32_t id)
void strip_vlan(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
void set_mpls_label(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
void set_dl_addr(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
uint32_t save_buffer(ofpbuf *)
void set_nw_addr(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
ofpbuf * retrieve_buffer(uint32_t id)
void set_vlan_pcp(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
void set_tp_port(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
void set_mpls_exp(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
void set_vlan_vid(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
Class for handling flow table actions.
static bool IsValidType(ofp_action_type type)
static void Execute(ofp_action_type type, ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
Executes the action.
static uint16_t Validate(ofp_action_type type, size_t len, const sw_flow_key *key, const ofp_action_header *ah)
Validates the action on whether its data is valid or not.
Class for handling Ericsson Vendor-defined actions.
static bool IsValidType(er_action_type type)
static void Execute(er_action_type type, ofpbuf *buffer, const sw_flow_key *key, const er_action_header *ah)
Executes the action.
static uint16_t Validate(er_action_type type, size_t len)
Validates the action on whether its data is valid or not.
uint32_t port
Learned port.
Ptr< NetDevice > netdev
NetDevice pointer.
unsigned long long int mpls_ttl0_dropped
Counter of packets dropped due to MPLS TTL.
unsigned long long int tx_packets
Counter of Tx packets.
unsigned long long int tx_bytes
Counter of Tx bytes.
unsigned long long int rx_packets
Counter of Rx packets.
unsigned long long int rx_bytes
Counter of Rx bytes.
uint32_t config
Some subset of OFPPC_* flags.
unsigned long long int tx_dropped
Counter of Tx dropped packets.
uint32_t state
Some subset of OFPPS_* flags.
State of the FlowStats request/reply.
ofp_flow_stats_request rq
Stats requests.
sw_table_position position
Table position.
int table_idx
Table index.
State of the PortStats request/reply.
uint32_t * ports
Array of ports in network byte order.
uint32_t num_ports
Number of ports in host byte order.
Callback for a stats dump request.
ofp_stats_request * rq
Current stats request.
Stats * s
Handler of the stats request.
void * state
Stats request state data.
Ptr< OpenFlowSwitchNetDevice > swtch
The switch that we're requesting data from.
bool done
Whether we are done requesting stats.
Class for handling virtual port table actions.
static uint16_t Validate(ofp_vport_action_type type, size_t len, const ofp_action_header *ah)
Validates the action on whether its data is valid or not.
static void Execute(ofp_vport_action_type type, ofpbuf *buffer, const sw_flow_key *key, const ofp_action_header *ah)
Executes the action.
static bool IsValidType(ofp_vport_action_type type)