40 std::numeric_limits<size_t>::max();
137 sizeof ods->mfr_desc);
144#define MAX_FLOW_STATS_BYTES 4096
149 const ofp_flow_stats_request*
fsr = (ofp_flow_stats_request*)
body;
152 s->table_idx =
fsr->table_id == 0xff ? 0 :
fsr->table_id;
153 memset(&s->position, 0,
sizeof s->position);
166 int length =
sizeof *
ofs +
flow->sf_acts->actions_len;
169 ofs->table_id = s->table_idx;
171 ofs->match.in_port =
flow->key.flow.in_port;
174 ofs->match.dl_vlan =
flow->key.flow.dl_vlan;
175 ofs->match.dl_type =
flow->key.flow.dl_type;
176 ofs->match.nw_src =
flow->key.flow.nw_src;
177 ofs->match.nw_dst =
flow->key.flow.nw_dst;
178 ofs->match.nw_proto =
flow->key.flow.nw_proto;
179 ofs->match.tp_src =
flow->key.flow.tp_src;
180 ofs->match.tp_dst =
flow->key.flow.tp_dst;
201 while (s->
table_idx < swtch->GetChain()->n_tables &&
206 if (table->iterate(table,
234 s->packet_count +=
flow->packet_count;
235 s->byte_count +=
flow->byte_count;
250 int table_idx = rq->table_id == 0xff ? 0 : rq->table_id;
252 sw_table_position position;
253 memset(&position, 0,
sizeof position);
256 (rq->table_id == 0xff || rq->table_id == table_idx))
258 sw_table* table = swtch->GetChain()->tables[table_idx];
259 int error = table->iterate(table,
271 memset(&position, 0,
sizeof position);
284 for (
int i = 0;
i <
ft->n_tables;
i++)
288 ft->tables[
i]->stats(
ft->tables[
i], &stats);
291 ots->wildcards =
htonl(stats.wildcards);
292 ots->max_entries =
htonl(stats.max_flows);
293 ots->active_count =
htonl(stats.n_flows);
294 ots->lookup_count =
htonll(stats.n_lookup);
295 ots->matched_count =
htonll(stats.n_matched);
305 opts->max_vports =
htonl(swtch->GetVPortTable().max_vports);
306 opts->active_vports =
htonl(swtch->GetVPortTable().active_vports);
307 opts->lookup_count =
htonll(swtch->GetVPortTable().lookup_count);
308 opts->port_match_count =
htonll(swtch->GetVPortTable().port_match_count);
309 opts->chain_match_count =
htonll(swtch->GetVPortTable().chain_match_count);
341 Port p = swtch->GetSwitchPort(
port);
349 ops->port_no =
htonl(swtch->GetSwitchPortIndex(p));
368 vport_table_t
vt = swtch->GetVPortTable();
441 if (oa->port ==
OFPP_NONE || oa->port == key->flow.in_port)
669 .SetGroupName(
"OpenFlow")
684 NS_LOG_INFO(
"This Controller has already registered this switch!");
697 NS_LOG_ERROR(
"Can't send to this switch, not registered to the Controller.");
701 swtch->ForwardControlInput(
msg, length);
724 ofm->match.wildcards = key.wildcards;
725 ofm->match.in_port = key.flow.in_port;
728 sizeof ofm->match.dl_src);
731 sizeof ofm->match.dl_dst);
732 ofm->match.dl_vlan = key.flow.dl_vlan;
733 ofm->match.dl_type = key.flow.dl_type;
734 ofm->match.nw_proto = key.flow.nw_proto;
735 ofm->match.nw_src = key.flow.nw_src;
736 ofm->match.nw_dst = key.flow.nw_dst;
737 ofm->match.tp_src = key.flow.tp_src;
738 ofm->match.tp_dst = key.flow.tp_dst;
739 ofm->match.mpls_label1 = key.flow.mpls_label1;
740 ofm->match.mpls_label2 =
741 key.flow.mpls_label1;
750 uint8_t type =
hdr->type;
763 error =
cb->swtch->StatsDump(
cb);
772 cb->swtch->StatsDone(
cb);
782 .SetGroupName(
"OpenFlow")
792 NS_LOG_ERROR(
"Can't receive from this switch, not registered to the Controller.");
826 TypeId(
"ns3::ofi::LearningController")
828 .SetGroupName(
"Openflow")
830 .AddAttribute(
"ExpirationTime",
831 "Time it takes for learned MAC state entry/created flow to expire.",
843 NS_LOG_ERROR(
"Can't receive from this switch, not registered to the Controller.");
878 <<
" is connected to");
883 NS_LOG_INFO(
"Setting to flood; this packet is a broadcast");
954 uint16_t
in_port = key->flow.in_port;
961 NS_LOG_INFO(
"No actions set to this flow. Dropping packet.");
989 uint16_t type =
ntohs(
ah->type);
void CopyFrom(const uint8_t buffer[6])
A base class which provides memory management and object aggregation.
static const char * GetManufacturerDescription()
static const char * GetSoftwareDescription()
static const char * GetHardwareDescription()
static const char * GetSerialNumber()
Smart pointer class similar to boost::intrusive_ptr.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
bool IsZero() const
Exactly equivalent to t == 0.
AttributeValue implementation for Time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
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.
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,...
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.
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.
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.
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time Seconds(double value)
Construct a Time in the indicated unit.
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.
int Stats_AggregateDumpCallback(sw_flow *flow, void *state)
int Stats_FlowDumpCallback(sw_flow *flow, void *state)
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.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
#define MAX_FLOW_STATS_BYTES
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)
void set_nw_addr(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
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)
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.
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.
unsigned long long int tx_dropped
Counter of Tx dropped packets.
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.
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)