18 #ifndef OPENFLOW_INTERFACE_H 
   19 #define OPENFLOW_INTERFACE_H 
   25 #include "ns3/simulator.h" 
   27 #include "ns3/net-device.h" 
   28 #include "ns3/packet.h" 
   29 #include "ns3/address.h" 
   30 #include "ns3/nstime.h" 
   31 #include "ns3/mac48-address.h" 
   38 #include "openflow/openflow.h" 
   39 #include "openflow/nicira-ext.h" 
   40 #include "openflow/ericsson-ext.h" 
   45 #define private _private 
   46 #define delete _delete 
   50 #include "openflow/private/csum.h" 
   51 #include "openflow/private/poll-loop.h" 
   52 #include "openflow/private/rconn.h" 
   53 #include "openflow/private/stp.h" 
   54 #include "openflow/private/vconn.h" 
   55 #include "openflow/private/xtoxll.h" 
   58 #include "openflow/private/chain.h" 
   59 #include "openflow/private/table.h" 
   60 #include "openflow/private/datapath.h"  
   61 uint32_t save_buffer (ofpbuf *);
 
   62 ofpbuf * retrieve_buffer (uint32_t 
id);
 
   63 void discard_buffer (uint32_t 
id);
 
   64 #include "openflow/private/dp_act.h"  
   65 void set_vlan_vid (ofpbuf *buffer, sw_flow_key *key, 
const ofp_action_header *ah);
 
   66 void set_vlan_pcp (ofpbuf *buffer, sw_flow_key *key, 
const ofp_action_header *ah);
 
   67 void strip_vlan (ofpbuf *buffer, sw_flow_key *key, 
const ofp_action_header *ah);
 
   68 void set_dl_addr (ofpbuf *buffer, sw_flow_key *key, 
const ofp_action_header *ah);
 
   69 void set_nw_addr (ofpbuf *buffer, sw_flow_key *key, 
const ofp_action_header *ah);
 
   70 void set_tp_port (ofpbuf *buffer, sw_flow_key *key, 
const ofp_action_header *ah);
 
   71 void set_mpls_label (ofpbuf *buffer, sw_flow_key *key, 
const ofp_action_header *ah);
 
   72 void set_mpls_exp (ofpbuf *buffer, sw_flow_key *key, 
const ofp_action_header *ah);
 
   73 #include "openflow/private/pt_act.h"  
   74 void update_checksums (ofpbuf *buffer, 
const sw_flow_key *key, uint32_t old_word, uint32_t new_word);
 
   82 #define OFP_SUPPORTED_CAPABILITIES ( OFPC_FLOW_STATS            \ 
   89 #define OFP_SUPPORTED_ACTIONS ( (1 << OFPAT_OUTPUT)             \ 
   90                                 | (1 << OFPAT_SET_VLAN_VID)     \ 
   91                                 | (1 << OFPAT_SET_VLAN_PCP)     \ 
   92                                 | (1 << OFPAT_STRIP_VLAN)       \ 
   93                                 | (1 << OFPAT_SET_DL_SRC)       \ 
   94                                 | (1 << OFPAT_SET_DL_DST)       \ 
   95                                 | (1 << OFPAT_SET_NW_SRC)       \ 
   96                                 | (1 << OFPAT_SET_NW_DST)       \ 
   97                                 | (1 << OFPAT_SET_TP_SRC)       \ 
   98                                 | (1 << OFPAT_SET_TP_DST)       \ 
   99                                 | (1 << OFPAT_SET_MPLS_LABEL)   \ 
  100                                 | (1 << OFPAT_SET_MPLS_EXP) ) 
  102 #define OFP_SUPPORTED_VPORT_TABLE_ACTIONS ( (1 << OFPPAT_OUTPUT)                \ 
  103                                             | (1 << OFPPAT_POP_MPLS)            \ 
  104                                             | (1 << OFPPAT_PUSH_MPLS)           \ 
  105                                             | (1 << OFPPAT_SET_MPLS_LABEL)      \ 
  106                                             | (1 << OFPPAT_SET_MPLS_EXP) )      \ 
  110 class OpenFlowSwitchNetDevice;
 
  132             mpls_ttl0_dropped (0)
 
  139   unsigned long long int rx_packets, tx_packets;
 
  140   unsigned long long int rx_bytes, tx_bytes;
 
  141   unsigned long long int tx_dropped;
 
  142   unsigned long long int mpls_ttl0_dropped;
 
  148   Stats (ofp_stats_types _type, 
size_t body_len);
 
  158   int DoInit (
const void *body, 
int body_len, 
void **state);
 
  185     sw_table_position position;
 
  186     ofp_flow_stats_request rq;
 
  201   ofp_stats_types type;
 
  203   int DescStatsDump (
void *state, ofpbuf *buffer);
 
  205   int FlowStatsInit (
const void *body, 
int body_len, 
void **state);
 
  206   int (*FlowDumpCallback)(sw_flow *flow, 
void *state);
 
  209   int AggregateStatsInit (
const void *body, 
int body_len, 
void **state);
 
  210   int (*AggregateDumpCallback)(sw_flow *flow, 
void *state);
 
  215   int PortStatsInit (
const void *body, 
int body_len, 
void **state);
 
  241   static uint16_t 
Validate (ofp_action_type type, 
size_t len, 
const sw_flow_key *key, 
const ofp_action_header *ah);
 
  251   static void Execute (ofp_action_type type, ofpbuf *buffer, sw_flow_key *key, 
const ofp_action_header *ah);
 
  263   static bool IsValidType (ofp_vport_action_type type);
 
  273   static uint16_t 
Validate (ofp_vport_action_type type, 
size_t len, 
const ofp_action_header *ah);
 
  283   static void Execute (ofp_vport_action_type type, ofpbuf *buffer, 
const sw_flow_key *key, 
const ofp_action_header *ah);
 
  304   static uint16_t 
Validate (er_action_type type, 
size_t len);
 
  314   static void Execute (er_action_type type, ofpbuf *buffer, 
const sw_flow_key *key, 
const er_action_header *ah);
 
  323   ofp_stats_request *
rq;                
 
  349   static TypeId GetTypeId (
void)
 
  353       .AddConstructor<Controller> ()
 
  427   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);
 
  440   typedef std::set<Ptr<OpenFlowSwitchNetDevice> > Switches_t;
 
  465   static TypeId GetTypeId (
void);
 
  480   typedef std::map<Mac48Address, LearnedState> LearnState_t;
 
  495 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);
 
  505 uint16_t ValidateActions (
const sw_flow_key *key, 
const ofp_action_header *actions, 
size_t actions_len);
 
  517 void ExecuteVPortActions (
Ptr<OpenFlowSwitchNetDevice> swtch, uint64_t packet_uid, ofpbuf* buffer, sw_flow_key *key, 
const ofp_action_header *actions, 
size_t actions_len);
 
  526 uint16_t ValidateVPortActions (
const ofp_action_header *actions, 
size_t actions_len);
 
  535 void ExecuteVendor (ofpbuf *buffer, 
const sw_flow_key *key, 
const ofp_action_header *ah);
 
  545 uint16_t ValidateVendor (
const sw_flow_key *key, 
const ofp_action_header *ah, uint16_t len);
 
  555 #define PKT_BUFFER_BITS 8 
  556 #define N_PKT_BUFFERS (1 << PKT_BUFFER_BITS) 
  557 #define PKT_BUFFER_MASK (N_PKT_BUFFERS - 1) 
  558 #define PKT_COOKIE_BITS (32 - PKT_BUFFER_BITS) 
void StartDump(StatsDumpCallback *cb)
Starts a callback-based, reliable, possibly multi-message reply to a request made by the controller...
 
static bool IsValidType(ofp_action_type type)
 
smart pointer class similar to boost::intrusive_ptr 
 
Ptr< OpenFlowSwitchNetDevice > swtch
The switch that we're requesting data from. 
 
int DoInit(const void *body, int body_len, void **state)
Prepares to dump some kind of statistics on the connected OpenFlowSwitchNetDevice. 
 
uint32_t config
Some subset of OFPPC_* flags. 
 
void ReceiveFromSwitch(Ptr< OpenFlowSwitchNetDevice > swtch, ofpbuf *buffer)
 
void ReceiveFromSwitch(Ptr< OpenFlowSwitchNetDevice > swtch, ofpbuf *buffer)
 
virtual void ReceiveFromSwitch(Ptr< OpenFlowSwitchNetDevice > swtch, ofpbuf *buffer)
 
a polymophic address class 
 
bool done
Whether we are done requesting stats. 
 
Stats * s
Handler of the stats request. 
 
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(er_action_type type, ofpbuf *buffer, const sw_flow_key *key, const er_action_header *ah)
Executes the action. 
 
LearnState_t m_learnState
Learned state data. 
 
static bool IsValidType(er_action_type type)
 
void * state
Stats request state data. 
 
static void Execute(ofp_vport_action_type type, ofpbuf *buffer, const sw_flow_key *key, const ofp_action_header *ah)
Executes the action. 
 
Switches_t m_switches
The collection of switches registered to this controller. 
 
Callback for a stats dump request. 
 
static uint16_t Validate(er_action_type type, size_t len)
Validates the action on whether its data is valid or not. 
 
int DoDump(Ptr< OpenFlowSwitchNetDevice > swtch, void *state, ofpbuf *buffer)
Appends statistics for OpenFlowSwitchNetDevice to 'buffer'. 
 
uint32_t port
Learned port. 
 
An interface for a Controller of OpenFlowSwitchNetDevices. 
 
uint32_t num_ports
Number of ports in host byte order. 
 
virtual void SendToSwitch(Ptr< OpenFlowSwitchNetDevice > swtch, void *msg, size_t length)
 
ofp_stats_request * rq
Current stats request. 
 
Class for handling virtual port table actions. 
 
Class for handling Ericsson Vendor-defined actions. 
 
uint32_t * ports
Array of ports in network byte order. 
 
virtual void AddSwitch(Ptr< OpenFlowSwitchNetDevice > swtch)
 
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)
 
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. 
 
Time m_expirationTime
Time it takes for learned MAC state entry/created flow to expire. 
 
uint8_t GetPacketType(ofpbuf *buffer)
 
State of the FlowStats request/reply. 
 
a base class which provides memory management and object aggregation 
 
static bool IsValidType(ofp_vport_action_type type)
 
a unique identifier for an interface. 
 
uint32_t state
Some subset of OFPPS_* flags. 
 
static void Execute(ofp_action_type type, ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
Executes the action. 
 
TypeId SetParent(TypeId tid)
 
void DoCleanup(void *state)
Cleans any state created by the init or dump functions. 
 
State of the PortStats request/reply. 
 
Class for handling flow table actions.