A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
openflow-interface.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#ifndef OPENFLOW_INTERFACE_H
18#define OPENFLOW_INTERFACE_H
19
20#include <assert.h>
21#include <errno.h>
22
23// Include OFSI code
24#include "ns3/address.h"
25#include "ns3/log.h"
26#include "ns3/mac48-address.h"
27#include "ns3/net-device.h"
28#include "ns3/nstime.h"
29#include "ns3/packet.h"
30#include "ns3/simulator.h"
31
32#include <limits>
33#include <map>
34#include <set>
35
36// Include main header and Vendor Extension files
37#include "openflow/ericsson-ext.h"
38#include "openflow/nicira-ext.h"
39#include "openflow/openflow.h"
40
41extern "C"
42{
43// Inexplicably, the OpenFlow implementation uses these two reserved words as member names.
44#define private _private
45#define delete _delete
46#define list List
47
48// Include OFSI Library files
49#include "openflow/private/csum.h"
50#include "openflow/private/poll-loop.h"
51#include "openflow/private/rconn.h"
52#include "openflow/private/stp.h"
53#include "openflow/private/vconn.h"
54#include "openflow/private/xtoxll.h"
55
56// Include OFSI Switch files
57#include "openflow/private/chain.h"
58#include "openflow/private/datapath.h" // The functions below are defined in datapath.c
59#include "openflow/private/table.h"
63#include "openflow/private/dp_act.h" // The functions below are defined in dp_act.c
64 void set_vlan_vid(ofpbuf* buffer, sw_flow_key* key, const ofp_action_header* ah);
65 void set_vlan_pcp(ofpbuf* buffer, sw_flow_key* key, const ofp_action_header* ah);
66 void strip_vlan(ofpbuf* buffer, sw_flow_key* key, const ofp_action_header* ah);
67 void set_dl_addr(ofpbuf* buffer, sw_flow_key* key, const ofp_action_header* ah);
68 void set_nw_addr(ofpbuf* buffer, sw_flow_key* key, const ofp_action_header* ah);
69 void set_tp_port(ofpbuf* buffer, sw_flow_key* key, const ofp_action_header* ah);
70 void set_mpls_label(ofpbuf* buffer, sw_flow_key* key, const ofp_action_header* ah);
71 void set_mpls_exp(ofpbuf* buffer, sw_flow_key* key, const ofp_action_header* ah);
72#include "openflow/private/pt_act.h"
73
74#undef list
75#undef private
76#undef delete
77}
78
79// Capabilities supported by this implementation.
80#ifndef OFP_SUPPORTED_CAPABILITIES
81#define OFP_SUPPORTED_CAPABILITIES \
82 (OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS | OFPC_MULTI_PHY_TX | OFPC_VPORT_TABLE)
83#endif
84
85// Actions supported by this implementation.
86#ifndef OFP_SUPPORTED_ACTIONS
87#define OFP_SUPPORTED_ACTIONS \
88 ((1 << OFPAT_OUTPUT) | (1 << OFPAT_SET_VLAN_VID) | (1 << OFPAT_SET_VLAN_PCP) | \
89 (1 << OFPAT_STRIP_VLAN) | (1 << OFPAT_SET_DL_SRC) | (1 << OFPAT_SET_DL_DST) | \
90 (1 << OFPAT_SET_NW_SRC) | (1 << OFPAT_SET_NW_DST) | (1 << OFPAT_SET_TP_SRC) | \
91 (1 << OFPAT_SET_TP_DST) | (1 << OFPAT_SET_MPLS_LABEL) | (1 << OFPAT_SET_MPLS_EXP))
92#endif
93
94#ifndef OFP_SUPPORTED_VPORT_TABLE_ACTIONS
95#define OFP_SUPPORTED_VPORT_TABLE_ACTIONS \
96 ((1 << OFPPAT_OUTPUT) | (1 << OFPPAT_POP_MPLS) | (1 << OFPPAT_PUSH_MPLS) | \
97 (1 << OFPPAT_SET_MPLS_LABEL) | (1 << OFPPAT_SET_MPLS_EXP))
98#endif
99
100namespace ns3
101{
102
103class OpenFlowSwitchNetDevice;
104
105namespace ofi
106{
107
108/**
109 * \ingroup openflow
110 * \brief Port and its metadata.
111 *
112 * We need to store port metadata, because OpenFlow dictates that there
113 * exists a type of request where the Controller asks for data about a
114 * port, or multiple ports. Otherwise, we'd refer to it via Ptr<NetDevice>
115 * everywhere.
116 */
117struct Port
118{
120 : config(0),
121 state(0),
122 netdev(nullptr),
123 rx_packets(0),
124 tx_packets(0),
125 rx_bytes(0),
126 tx_bytes(0),
127 tx_dropped(0),
129 {
130 }
131
132 uint32_t config; ///< Some subset of OFPPC_* flags.
133 uint32_t state; ///< Some subset of OFPPS_* flags.
134 Ptr<NetDevice> netdev; ///< NetDevice pointer
135 unsigned long long int rx_packets; //!< Counter of Rx packets
136 unsigned long long int tx_packets; //!< Counter of Tx packets
137 unsigned long long int rx_bytes; //!< Counter of Rx bytes
138 unsigned long long int tx_bytes; //!< Counter of Tx bytes
139 unsigned long long int tx_dropped; //!< Counter of Tx dropped packets
140 unsigned long long int mpls_ttl0_dropped; //!< Counter of packets dropped due to MPLS TTL
141};
142
143/**
144 * \ingroup openflow
145 * OpenFlow statistics
146 */
147class Stats
148{
149 public:
150 /**
151 * Constructor
152 * \param _type OpenFlow stats type.
153 * \param body_len Stat body length.
154 */
155 Stats(ofp_stats_types _type, size_t body_len);
156
157 /**
158 * \brief Prepares to dump some kind of statistics on the connected OpenFlowSwitchNetDevice.
159 *
160 * \param body Body member of the struct ofp_stats_request.
161 * \param body_len Length of the body member.
162 * \param state State information.
163 * \return 0 if successful, otherwise a negative error code.
164 */
165 int DoInit(const void* body, int body_len, void** state);
166
167 /**
168 * \brief Appends statistics for OpenFlowSwitchNetDevice to 'buffer'.
169 *
170 * \param swtch The OpenFlowSwitchNetDevice this callback is associated with.
171 * \param state State information.
172 * \param buffer Buffer to append stats reply to.
173 * \return 1 if it should be called again later with another buffer, 0 if it is done, or a
174 * negative errno value on failure.
175 */
176 int DoDump(Ptr<OpenFlowSwitchNetDevice> swtch, void* state, ofpbuf* buffer);
177
178 /**
179 * \brief Cleans any state created by the init or dump functions.
180 *
181 * May not be implemented if no cleanup is required.
182 *
183 * \param state State information to clear.
184 */
185 void DoCleanup(void* state);
186
187 /**
188 * \brief State of the FlowStats request/reply.
189 */
191 {
192 int table_idx; //!< Table index
193 sw_table_position position; //!< Table position
194 ofp_flow_stats_request rq; //!< Stats requests
195 time_t now; //!< Actual time
196
197 ofpbuf* buffer; //!< Buffer
198 };
199
200 /**
201 * \ingroup openflow
202 * \brief State of the PortStats request/reply.
203 */
205 {
206 uint32_t num_ports; ///< Number of ports in host byte order
207 uint32_t* ports; ///< Array of ports in network byte order
208 };
209
210 ofp_stats_types type; //!< Status type
211 private:
212 /**
213 * Dumps the stats description
214 * \param [in] state The state.
215 * \param [out] buffer Output buffer.
216 * \return zero on success
217 */
218 int DescStatsDump(void* state, ofpbuf* buffer);
219
220 /**
221 * @{
222 * Initialize the stats.
223 * \param body Body member of the struct ofp_stats_request.
224 * \param body_len Length of the body member.
225 * \param state State information.
226 * \return 0 if successful, otherwise a negative error code.
227 */
228 int FlowStatsInit(const void* body, int body_len, void** state);
229 int AggregateStatsInit(const void* body, int body_len, void** state);
230 int PortStatsInit(const void* body, int body_len, void** state);
231 /** @} */
232
233 /// Flow dump callback functor
234 int (*FlowDumpCallback)(sw_flow* flow, void* state);
235 /// Aggregate dump callback functor
236 int (*AggregateDumpCallback)(sw_flow* flow, void* state);
237
238 /**
239 * @{
240 * Dump the stats.
241 * \param dp OpenFlow NetDevice.
242 * \param state State.
243 * \param [out] buffer output buffer.
244 * \return 0 if successful
245 */
246 int FlowStatsDump(Ptr<OpenFlowSwitchNetDevice> dp, FlowStatsState* state, ofpbuf* buffer);
248 ofp_aggregate_stats_request* state,
249 ofpbuf* buffer);
250 int TableStatsDump(Ptr<OpenFlowSwitchNetDevice> dp, void* state, ofpbuf* buffer);
251 int PortStatsDump(Ptr<OpenFlowSwitchNetDevice> dp, PortStatsState* state, ofpbuf* buffer);
252 int PortTableStatsDump(Ptr<OpenFlowSwitchNetDevice> dp, void* state, ofpbuf* buffer);
253 /** @} */
254};
255
256/**
257 * \ingroup openflow
258 * \brief Class for handling flow table actions.
259 */
260struct Action
261{
262 /**
263 * \param type Type of Flow Table Action.
264 * \return true if the provided type is a type of flow table action.
265 */
266 static bool IsValidType(ofp_action_type type);
267
268 /**
269 * \brief Validates the action on whether its data is valid or not.
270 *
271 * \param type Type of action to validate.
272 * \param len Length of the action data.
273 * \param key Matching key for the flow that is tied to this action.
274 * \param ah Action's data header.
275 * \return ACT_VALIDATION_OK if the action checks out, otherwise an error type.
276 */
277 static uint16_t Validate(ofp_action_type type,
278 size_t len,
279 const sw_flow_key* key,
280 const ofp_action_header* ah);
281
282 /**
283 * \brief Executes the action.
284 *
285 * \param type Type of action to execute.
286 * \param buffer Buffer of the Packet if it's needed for the action.
287 * \param key Matching key for the flow that is tied to this action.
288 * \param ah Action's data header.
289 */
290 static void Execute(ofp_action_type type,
291 ofpbuf* buffer,
292 sw_flow_key* key,
293 const ofp_action_header* ah);
294};
295
296/**
297 * \ingroup openflow
298 * \brief Class for handling virtual port table actions.
299 */
301{
302 /**
303 * \param type Type of virtual port table Action.
304 * \return true if the provided type is a type of virtual port table action.
305 */
306 static bool IsValidType(ofp_vport_action_type type);
307
308 /**
309 * \brief Validates the action on whether its data is valid or not.
310 *
311 * \param type Type of action to validate.
312 * \param len Length of the action data.
313 * \param ah Action's data header.
314 * \return ACT_VALIDATION_OK if the action checks out, otherwise an error type.
315 */
316 static uint16_t Validate(ofp_vport_action_type type, size_t len, const ofp_action_header* ah);
317
318 /**
319 * \brief Executes the action.
320 *
321 * \param type Type of action to execute.
322 * \param buffer Buffer of the Packet if it's needed for the action.
323 * \param key Matching key for the flow that is tied to this action.
324 * \param ah Action's data header.
325 */
326 static void Execute(ofp_vport_action_type type,
327 ofpbuf* buffer,
328 const sw_flow_key* key,
329 const ofp_action_header* ah);
330};
331
332/**
333 * \ingroup openflow
334 * \brief Class for handling Ericsson Vendor-defined actions.
335 */
337{
338 /**
339 * \param type Type of Ericsson Vendor-defined Action.
340 * \return true if the provided type is a type of Ericsson Vendor-defined action.
341 */
342 static bool IsValidType(er_action_type type);
343
344 /**
345 * \brief Validates the action on whether its data is valid or not.
346 *
347 * \param type Type of action to validate.
348 * \param len Length of the action data.
349 * \return ACT_VALIDATION_OK if the action checks out, otherwise an error type.
350 */
351 static uint16_t Validate(er_action_type type, size_t len);
352
353 /**
354 * \brief Executes the action.
355 *
356 * \param type Type of action to execute.
357 * \param buffer Buffer of the Packet if it's needed for the action.
358 * \param key Matching key for the flow that is tied to this action.
359 * \param ah Action's data header.
360 */
361 static void Execute(er_action_type type,
362 ofpbuf* buffer,
363 const sw_flow_key* key,
364 const er_action_header* ah);
365};
366
367/**
368 * \ingroup openflow
369 * \brief Callback for a stats dump request.
370 */
372{
373 bool done; ///< Whether we are done requesting stats.
374 ofp_stats_request* rq; ///< Current stats request.
375 Stats* s; ///< Handler of the stats request.
376 void* state; ///< Stats request state data.
377 Ptr<OpenFlowSwitchNetDevice> swtch; ///< The switch that we're requesting data from.
378};
379
380/**
381 * \ingroup openflow
382 * \brief Packet Metadata, allows us to track the packet's metadata as it passes through the switch.
383 */
385{
386 Ptr<Packet> packet; ///< The Packet itself.
387 ofpbuf* buffer; ///< The OpenFlow buffer as created from the Packet, with its data and headers.
388 uint16_t protocolNumber; ///< Protocol type of the Packet when the Packet is received
389 Address src; ///< Source Address of the Packet when the Packet is received
390 Address dst; ///< Destination Address of the Packet when the Packet is received.
391};
392
393/**
394 * \ingroup openflow
395 * \brief An interface for a Controller of OpenFlowSwitchNetDevices
396 *
397 * Follows the OpenFlow specification for a controller.
398 */
399class Controller : public Object
400{
401 public:
402 /**
403 * Register this type.
404 * \return The TypeId.
405 */
406 static TypeId GetTypeId();
407 /** Destructor. */
408 ~Controller() override;
409
410 /**
411 * Adds a switch to the controller.
412 *
413 * \param swtch The switch to register.
414 */
415 virtual void AddSwitch(Ptr<OpenFlowSwitchNetDevice> swtch);
416
417 /**
418 * A switch calls this method to pass a message on to the Controller.
419 *
420 * \param swtch The switch the message was received from.
421 * \param buffer The message.
422 */
423 virtual void ReceiveFromSwitch(Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* buffer)
424 {
425 }
426
427 /**
428 * \brief Starts a callback-based, reliable, possibly multi-message reply to a request made by
429 * the controller.
430 *
431 * If an incoming request needs to have a reliable reply that might
432 * require multiple messages, it can use StartDump() to set up
433 * a callback that will be called as buffer space for replies.
434 *
435 * A stats request made by the controller is processed by the switch,
436 * the switch then calls this method to tell the controller to start
437 * asking for information. By default (it can be overridden), the
438 * controller stops all work to run through the callback. ReceiveFromSwitch
439 * must be defined appropriately to handle the status reply messages
440 * generated by the switch, or otherwise the status reply messages will be sent
441 * and discarded.
442 *
443 * \param cb The callback data.
444 */
446
447 protected:
448 /**
449 * However the controller is implemented, this method is to
450 * be used to pass a message on to a switch.
451 *
452 * \param swtch The switch to receive the message.
453 * \param msg The message to send.
454 * \param length The length of the message.
455 */
456 virtual void SendToSwitch(Ptr<OpenFlowSwitchNetDevice> swtch, void* msg, size_t length);
457
458 /**
459 * Construct flow data from a matching key to build a flow
460 * entry for adding, modifying, or deleting a flow.
461 *
462 * \param key The matching key data; used to create a flow that matches the packet.
463 * \param buffer_id The OpenFlow Buffer ID; used to run the actions on the packet if we add or
464 * modify the flow.
465 * \param command Whether to add, modify, or delete this flow.
466 * \param acts List of actions to execute.
467 * \param actions_len Length of the actions buffer.
468 * \param idle_timeout Flow expires if left inactive for this amount of time (specify
469 * OFP_FLOW_PERMANENT to disable feature).
470 * \param hard_timeout Flow expires after this amount of time (specify OFP_FLOW_PERMANENT to
471 * disable feature).
472 * \return Flow data that when passed to SetFlow will add, modify, or delete a flow it defines.
473 */
474 ofp_flow_mod* BuildFlow(sw_flow_key key,
475 uint32_t buffer_id,
476 uint16_t command,
477 void* acts,
478 size_t actions_len,
479 int idle_timeout,
480 int hard_timeout);
481
482 /**
483 * Get the packet type on the buffer, which can then be used
484 * to determine how to handle the buffer.
485 *
486 * \param buffer The packet in OpenFlow buffer format.
487 * \return The packet type, as defined in the ofp_type struct.
488 */
489 uint8_t GetPacketType(ofpbuf* buffer);
490
491 /// OpenFlowSwitchNetDevice container type
492 typedef std::set<Ptr<OpenFlowSwitchNetDevice>> Switches_t;
493 Switches_t m_switches; ///< The collection of switches registered to this controller.
494};
495
496/**
497 * \ingroup openflow
498 * Demonstration of a Drop controller. When a connected switch
499 * passes it a packet the switch doesn't recognize, the controller
500 * configures the switch to make a flow that drops alike packets.
501 */
503{
504 public:
505 /**
506 * Register this type.
507 * \return The TypeId.
508 */
509 static TypeId GetTypeId();
510
511 void ReceiveFromSwitch(Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* buffer) override;
512};
513
514/**
515 * \ingroup openflow
516 * Demonstration of a Learning controller. When a connected switch
517 * passes it a packet the switch doesn't recognize, the controller
518 * delves into its learned states and figures out if we know what
519 * port the packet is supposed to go to, flooding if unknown, and
520 * adjusts the switch's flow table accordingly.
521 */
523{
524 public:
525 /**
526 * Register this type.
527 * \return The TypeId.
528 */
529 static TypeId GetTypeId();
530
532 {
533 m_learnState.clear();
534 }
535
536 void ReceiveFromSwitch(Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* buffer) override;
537
538 protected:
539 /// Learned state
541 {
542 uint32_t port; ///< Learned port.
543 };
544
545 Time m_expirationTime; ///< Time it takes for learned MAC state entry/created flow to expire.
546 /// Learned state type
547 typedef std::map<Mac48Address, LearnedState> LearnState_t;
548 LearnState_t m_learnState; ///< Learned state data.
549};
550
551/**
552 * \brief Executes a list of flow table actions.
553 *
554 * \param swtch OpenFlowSwitchNetDevice these actions are being executed on.
555 * \param packet_uid Packet UID; used to fetch the packet and its metadata.
556 * \param buffer The Packet OpenFlow buffer.
557 * \param key The matching key for the flow tied to this list of actions.
558 * \param actions A buffer of actions.
559 * \param actions_len Length of actions buffer.
560 * \param ignore_no_fwd If true, during port forwarding actions, ports that are set to not forward
561 * are forced to forward.
562 */
564 uint64_t packet_uid,
565 ofpbuf* buffer,
566 sw_flow_key* key,
567 const ofp_action_header* actions,
568 size_t actions_len,
569 int ignore_no_fwd);
570
571/**
572 * \brief Validates a list of flow table actions.
573 *
574 * \param key The matching key for the flow tied to this list of actions.
575 * \param actions A buffer of actions.
576 * \param actions_len Length of actions buffer.
577 * \return If the action list validates, ACT_VALIDATION_OK is returned. Otherwise, a code for the
578 * OFPET_BAD_ACTION error type is returned.
579 */
580uint16_t ValidateActions(const sw_flow_key* key,
581 const ofp_action_header* actions,
582 size_t actions_len);
583
584/**
585 * \brief Executes a list of virtual port table entry actions.
586 *
587 * \param swtch OpenFlowSwitchNetDevice these actions are being executed on.
588 * \param packet_uid Packet UID; used to fetch the packet and its metadata.
589 * \param buffer The Packet OpenFlow buffer.
590 * \param key The matching key for the flow tied to this list of actions.
591 * \param actions A buffer of actions.
592 * \param actions_len Length of actions buffer.
593 */
595 uint64_t packet_uid,
596 ofpbuf* buffer,
597 sw_flow_key* key,
598 const ofp_action_header* actions,
599 size_t actions_len);
600
601/**
602 * \brief Validates a list of virtual port table entry actions.
603 *
604 * \param actions A buffer of actions.
605 * \param actions_len Length of actions buffer.
606 * \return If the action list validates, ACT_VALIDATION_OK is returned. Otherwise, a code for the
607 * OFPET_BAD_ACTION error type is returned.
608 */
609uint16_t ValidateVPortActions(const ofp_action_header* actions, size_t actions_len);
610
611/**
612 * \brief Executes a vendor-defined action.
613 *
614 * \param buffer The Packet OpenFlow buffer.
615 * \param key The matching key for the flow tied to this list of actions.
616 * \param ah Header of the action.
617 */
618void ExecuteVendor(ofpbuf* buffer, const sw_flow_key* key, const ofp_action_header* ah);
619
620/**
621 * \brief Validates a vendor-defined action.
622 *
623 * \param key The matching key for the flow tied to this list of actions.
624 * \param ah Header of the action.
625 * \param len Length of the action.
626 * \return If the action list validates, ACT_VALIDATION_OK is returned. Otherwise, a code for the
627 * OFPET_BAD_ACTION error type is returned.
628 */
629uint16_t ValidateVendor(const sw_flow_key* key, const ofp_action_header* ah, uint16_t len);
630
631/*
632 * From datapath.c
633 * Buffers are identified to userspace by a 31-bit opaque ID. We divide the ID
634 * into a buffer number (low bits) and a cookie (high bits). The buffer number
635 * is an index into an array of buffers. The cookie distinguishes between
636 * different packets that have occupied a single buffer. Thus, the more
637 * buffers we have, the lower-quality the cookie...
638 */
639#define PKT_BUFFER_BITS 8
640#define N_PKT_BUFFERS (1 << PKT_BUFFER_BITS)
641#define PKT_BUFFER_MASK (N_PKT_BUFFERS - 1)
642#define PKT_COOKIE_BITS (32 - PKT_BUFFER_BITS)
643
644} // namespace ofi
645
646} // namespace ns3
647
648#endif /* OPENFLOW_INTERFACE_H */
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
a polymophic address class
Definition: address.h:101
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
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.
Time m_expirationTime
Time it takes for learned MAC state entry/created flow to expire.
LearnState_t m_learnState
Learned state data.
OpenFlow statistics.
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.
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.
Port and its metadata.
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.
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.
Packet Metadata, allows us to track the packet's metadata as it passes through the switch.
Address src
Source Address of the Packet when the Packet is received.
uint16_t protocolNumber
Protocol type of the Packet when the Packet is received.
Address dst
Destination Address of the Packet when the Packet is received.
ofpbuf * buffer
The OpenFlow buffer as created from the Packet, with its data and headers.
Ptr< Packet > packet
The Packet itself.
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)