A Discrete-Event Network Simulator
API
openflow-interface.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Author: Blake Hurd <naimorai@gmail.com>
17  */
18 #ifdef NS3_OPENFLOW
19 
20 #include "openflow-interface.h"
22 
23 namespace ns3 {
24 
25 NS_LOG_COMPONENT_DEFINE ("OpenFlowInterface");
26 
27 namespace ofi {
28 
29 Stats::Stats (ofp_stats_types _type, size_t body_len)
30 {
31  type = _type;
32  size_t min_body = 0, max_body = 0;
33 
34  switch (type)
35  {
36  case OFPST_DESC:
37  break;
38  case OFPST_FLOW:
39  min_body = max_body = sizeof(ofp_flow_stats_request);
40  break;
41  case OFPST_AGGREGATE:
42  min_body = max_body = sizeof(ofp_aggregate_stats_request);
43  break;
44  case OFPST_TABLE:
45  break;
46  case OFPST_PORT:
47  min_body = 0;
48  max_body = std::numeric_limits<size_t>::max (); // Not sure about this one. This would guarantee that the body_len is always acceptable.
49  break;
50  case OFPST_PORT_TABLE:
51  break;
52  default:
53  NS_LOG_ERROR ("received stats request of unknown type " << type);
54  return; // -EINVAL;
55  }
56 
57  if ((min_body != 0 || max_body != 0) && (body_len < min_body || body_len > max_body))
58  {
59  NS_LOG_ERROR ("stats request type " << type << " with bad body length " << body_len);
60  return; // -EINVAL;
61  }
62 }
63 
64 int
65 Stats::DoInit (const void *body, int body_len, void **state)
66 {
67  switch (type)
68  {
69  case OFPST_DESC:
70  return 0;
71  case OFPST_FLOW:
72  return FlowStatsInit (body, body_len, state);
73  case OFPST_AGGREGATE:
74  return AggregateStatsInit (body, body_len, state);
75  case OFPST_TABLE:
76  return 0;
77  case OFPST_PORT:
78  return PortStatsInit (body, body_len, state);
79  case OFPST_PORT_TABLE:
80  return 0;
81  case OFPST_VENDOR:
82  return 0;
83  }
84 
85  return 0;
86 }
87 
88 int
89 Stats::DoDump (Ptr<OpenFlowSwitchNetDevice> swtch, void *state, ofpbuf *buffer)
90 {
91  switch (type)
92  {
93  case OFPST_DESC:
94  return DescStatsDump (state, buffer);
95  case OFPST_FLOW:
96  return FlowStatsDump (swtch, (FlowStatsState *)state, buffer);
97  case OFPST_AGGREGATE:
98  return AggregateStatsDump (swtch, (ofp_aggregate_stats_request *)state, buffer);
99  case OFPST_TABLE:
100  return TableStatsDump (swtch, state, buffer);
101  case OFPST_PORT:
102  return PortStatsDump (swtch, (PortStatsState *)state, buffer);
103  case OFPST_PORT_TABLE:
104  return PortTableStatsDump (swtch, state, buffer);
105  case OFPST_VENDOR:
106  return 0;
107  }
108 
109  return 0;
110 }
111 
112 void
113 Stats::DoCleanup (void *state)
114 {
115  switch (type)
116  {
117  case OFPST_DESC:
118  break;
119  case OFPST_FLOW:
120  free ((FlowStatsState *)state);
121  break;
122  case OFPST_AGGREGATE:
123  free ((ofp_aggregate_stats_request *)state);
124  break;
125  case OFPST_TABLE:
126  break;
127  case OFPST_PORT:
128  free (((PortStatsState *)state)->ports);
129  free ((PortStatsState *)state);
130  break;
131  case OFPST_PORT_TABLE:
132  break;
133  case OFPST_VENDOR:
134  break;
135  }
136 }
137 
138 int
139 Stats::DescStatsDump (void *state, ofpbuf *buffer)
140 {
141  ofp_desc_stats *ods = (ofp_desc_stats*)ofpbuf_put_zeros (buffer, sizeof *ods);
142  strncpy (ods->mfr_desc, OpenFlowSwitchNetDevice::GetManufacturerDescription (), sizeof ods->mfr_desc);
143  strncpy (ods->hw_desc, OpenFlowSwitchNetDevice::GetHardwareDescription (), sizeof ods->hw_desc);
144  strncpy (ods->sw_desc, OpenFlowSwitchNetDevice::GetSoftwareDescription (), sizeof ods->sw_desc);
145  strncpy (ods->serial_num, OpenFlowSwitchNetDevice::GetSerialNumber (), sizeof ods->serial_num);
146  return 0;
147 }
148 
149 #define MAX_FLOW_STATS_BYTES 4096
150 
151 int
152 Stats::FlowStatsInit (const void *body, int body_len, void **state)
153 {
154  const ofp_flow_stats_request *fsr = (ofp_flow_stats_request*)body;
155  FlowStatsState *s = (FlowStatsState*)xmalloc (sizeof *s);
156 
157  s->table_idx = fsr->table_id == 0xff ? 0 : fsr->table_id;
158  memset (&s->position, 0, sizeof s->position);
159  s->rq = *fsr;
160  *state = s;
161  return 0;
162 }
163 
164 int
165 Stats_FlowDumpCallback (sw_flow *flow, void* state)
166 {
167  Stats::FlowStatsState *s = (Stats::FlowStatsState*)state;
168 
169  // Fill Flow Stats
170  ofp_flow_stats *ofs;
171  int length = sizeof *ofs + flow->sf_acts->actions_len;
172  ofs = (ofp_flow_stats*)ofpbuf_put_zeros (s->buffer, length);
173  ofs->length = htons (length);
174  ofs->table_id = s->table_idx;
175  ofs->match.wildcards = htonl (flow->key.wildcards);
176  ofs->match.in_port = flow->key.flow.in_port;
177  memcpy (ofs->match.dl_src, flow->key.flow.dl_src, ETH_ADDR_LEN);
178  memcpy (ofs->match.dl_dst, flow->key.flow.dl_dst, ETH_ADDR_LEN);
179  ofs->match.dl_vlan = flow->key.flow.dl_vlan;
180  ofs->match.dl_type = flow->key.flow.dl_type;
181  ofs->match.nw_src = flow->key.flow.nw_src;
182  ofs->match.nw_dst = flow->key.flow.nw_dst;
183  ofs->match.nw_proto = flow->key.flow.nw_proto;
184  ofs->match.tp_src = flow->key.flow.tp_src;
185  ofs->match.tp_dst = flow->key.flow.tp_dst;
186  ofs->duration = htonl (s->now - flow->created);
187  ofs->priority = htons (flow->priority);
188  ofs->idle_timeout = htons (flow->idle_timeout);
189  ofs->hard_timeout = htons (flow->hard_timeout);
190  ofs->packet_count = htonll (flow->packet_count);
191  ofs->byte_count = htonll (flow->byte_count);
192  memcpy (ofs->actions, flow->sf_acts->actions, flow->sf_acts->actions_len);
193 
194  return s->buffer->size >= MAX_FLOW_STATS_BYTES;
195 }
196 
197 int
198 Stats::FlowStatsDump (Ptr<OpenFlowSwitchNetDevice> swtch, FlowStatsState* s, ofpbuf *buffer)
199 {
200  sw_flow_key match_key;
201 
202  flow_extract_match (&match_key, &s->rq.match);
203 
204  s->buffer = buffer;
205  s->now = time_now ();
206  while (s->table_idx < swtch->GetChain ()->n_tables
207  && (s->rq.table_id == 0xff || s->rq.table_id == s->table_idx))
208  {
209  sw_table *table = swtch->GetChain ()->tables[s->table_idx];
210 
211  if (table->iterate (table, &match_key, s->rq.out_port, &s->position, Stats::FlowDumpCallback, s))
212  {
213  break;
214  }
215 
216  s->table_idx++;
217  memset (&s->position, 0, sizeof s->position);
218  }
219  return s->buffer->size >= MAX_FLOW_STATS_BYTES;
220 }
221 
222 int
223 Stats::AggregateStatsInit (const void *body, int body_len, void **state)
224 {
225  //ofp_aggregate_stats_request *s = (ofp_aggregate_stats_request*)body;
226  *state = (ofp_aggregate_stats_request*)body;
227  return 0;
228 }
229 
230 int
231 Stats_AggregateDumpCallback (sw_flow *flow, void *state)
232 {
233  ofp_aggregate_stats_reply *s = (ofp_aggregate_stats_reply*)state;
234  s->packet_count += flow->packet_count;
235  s->byte_count += flow->byte_count;
236  s->flow_count++;
237  return 0;
238 }
239 
240 int
241 Stats::AggregateStatsDump (Ptr<OpenFlowSwitchNetDevice> swtch, ofp_aggregate_stats_request *s, ofpbuf *buffer)
242 {
243  ofp_aggregate_stats_request *rq = s;
244  ofp_aggregate_stats_reply *rpy = (ofp_aggregate_stats_reply*)ofpbuf_put_zeros (buffer, sizeof *rpy);
245  sw_flow_key match_key;
246  flow_extract_match (&match_key, &rq->match);
247  int table_idx = rq->table_id == 0xff ? 0 : rq->table_id;
248 
249  sw_table_position position;
250  memset (&position, 0, sizeof position);
251 
252  while (table_idx < swtch->GetChain ()->n_tables
253  && (rq->table_id == 0xff || rq->table_id == table_idx))
254  {
255  sw_table *table = swtch->GetChain ()->tables[table_idx];
256  int error = table->iterate (table, &match_key, rq->out_port, &position, Stats::AggregateDumpCallback, rpy);
257  if (error)
258  {
259  return error;
260  }
261 
262  table_idx++;
263  memset (&position, 0, sizeof position);
264  }
265 
266  rpy->packet_count = htonll (rpy->packet_count);
267  rpy->byte_count = htonll (rpy->byte_count);
268  rpy->flow_count = htonl (rpy->flow_count);
269  return 0;
270 }
271 
272 int
273 Stats::TableStatsDump (Ptr<OpenFlowSwitchNetDevice> swtch, void *state, ofpbuf *buffer)
274 {
275  sw_chain* ft = swtch->GetChain ();
276  for (int i = 0; i < ft->n_tables; i++)
277  {
278  ofp_table_stats *ots = (ofp_table_stats*)ofpbuf_put_zeros (buffer, sizeof *ots);
279  sw_table_stats stats;
280  ft->tables[i]->stats (ft->tables[i], &stats);
281  strncpy (ots->name, stats.name, sizeof ots->name);
282  ots->table_id = i;
283  ots->wildcards = htonl (stats.wildcards);
284  ots->max_entries = htonl (stats.max_flows);
285  ots->active_count = htonl (stats.n_flows);
286  ots->lookup_count = htonll (stats.n_lookup);
287  ots->matched_count = htonll (stats.n_matched);
288  }
289  return 0;
290 }
291 
292 // stats for the port table which is similar to stats for the flow tables
293 int
294 Stats::PortTableStatsDump (Ptr<OpenFlowSwitchNetDevice> swtch, void *state, ofpbuf *buffer)
295 {
296  ofp_vport_table_stats *opts = (ofp_vport_table_stats*)ofpbuf_put_zeros (buffer, sizeof *opts);
297  opts->max_vports = htonl (swtch->GetVPortTable ().max_vports);
298  opts->active_vports = htonl (swtch->GetVPortTable ().active_vports);
299  opts->lookup_count = htonll (swtch->GetVPortTable ().lookup_count);
300  opts->port_match_count = htonll (swtch->GetVPortTable ().port_match_count);
301  opts->chain_match_count = htonll (swtch->GetVPortTable ().chain_match_count);
302 
303  return 0;
304 }
305 
306 int
307 Stats::PortStatsInit (const void *body, int body_len, void **state)
308 {
309  PortStatsState *s = (PortStatsState*)xmalloc (sizeof *s);
310 
311  // the body contains a list of port numbers
312  s->ports = (uint32_t*)xmalloc (body_len);
313  memcpy (s->ports, body, body_len);
314  s->num_ports = body_len / sizeof(uint32_t);
315 
316  *state = s;
317  return 0;
318 }
319 
320 int
321 Stats::PortStatsDump (Ptr<OpenFlowSwitchNetDevice> swtch, PortStatsState *s, ofpbuf *buffer)
322 {
323  ofp_port_stats *ops;
324  uint32_t port;
325 
326  // port stats are different depending on whether port is physical or virtual
327  for (size_t i = 0; i < s->num_ports; i++)
328  {
329  port = ntohl (s->ports[i]);
330  // physical port?
331  if (port <= OFPP_MAX)
332  {
333  Port p = swtch->GetSwitchPort (port);
334 
335  if (p.netdev == 0)
336  {
337  continue;
338  }
339 
340  ops = (ofp_port_stats*)ofpbuf_put_zeros (buffer, sizeof *ops);
341  ops->port_no = htonl (swtch->GetSwitchPortIndex (p));
342  ops->rx_packets = htonll (p.rx_packets);
343  ops->tx_packets = htonll (p.tx_packets);
344  ops->rx_bytes = htonll (p.rx_bytes);
345  ops->tx_bytes = htonll (p.tx_bytes);
346  ops->rx_dropped = htonll (-1);
347  ops->tx_dropped = htonll (p.tx_dropped);
348  ops->rx_errors = htonll (-1);
349  ops->tx_errors = htonll (-1);
350  ops->rx_frame_err = htonll (-1);
351  ops->rx_over_err = htonll (-1);
352  ops->rx_crc_err = htonll (-1);
353  ops->collisions = htonll (-1);
354  ops->mpls_ttl0_dropped = htonll (p.mpls_ttl0_dropped);
355  ops++;
356  }
357  else if (port >= OFPP_VP_START && port <= OFPP_VP_END) // virtual port?
358  {
359  // lookup the virtual port
360  vport_table_t vt = swtch->GetVPortTable ();
361  vport_table_entry *vpe = vport_table_lookup (&vt, port);
362  if (vpe == 0)
363  {
364  NS_LOG_ERROR ("vport entry not found!");
365  continue;
366  }
367  // only tx_packets and tx_bytes are really relevant for virtual ports
368  ops = (ofp_port_stats*)ofpbuf_put_zeros (buffer, sizeof *ops);
369  ops->port_no = htonl (vpe->vport);
370  ops->rx_packets = htonll (-1);
371  ops->tx_packets = htonll (vpe->packet_count);
372  ops->rx_bytes = htonll (-1);
373  ops->tx_bytes = htonll (vpe->byte_count);
374  ops->rx_dropped = htonll (-1);
375  ops->tx_dropped = htonll (-1);
376  ops->rx_errors = htonll (-1);
377  ops->tx_errors = htonll (-1);
378  ops->rx_frame_err = htonll (-1);
379  ops->rx_over_err = htonll (-1);
380  ops->rx_crc_err = htonll (-1);
381  ops->collisions = htonll (-1);
382  ops->mpls_ttl0_dropped = htonll (-1);
383  ops++;
384  }
385  }
386  return 0;
387 }
388 
389 bool
390 Action::IsValidType (ofp_action_type type)
391 {
392  switch (type)
393  {
394  case OFPAT_OUTPUT:
395  case OFPAT_SET_VLAN_VID:
396  case OFPAT_SET_VLAN_PCP:
397  case OFPAT_STRIP_VLAN:
398  case OFPAT_SET_DL_SRC:
399  case OFPAT_SET_DL_DST:
400  case OFPAT_SET_NW_SRC:
401  case OFPAT_SET_NW_DST:
402  case OFPAT_SET_TP_SRC:
403  case OFPAT_SET_TP_DST:
404  case OFPAT_SET_MPLS_LABEL:
405  case OFPAT_SET_MPLS_EXP:
406  return true;
407  default:
408  return false;
409  }
410 }
411 
412 uint16_t
413 Action::Validate (ofp_action_type type, size_t len, const sw_flow_key *key, const ofp_action_header *ah)
414 {
415  size_t size = 0;
416 
417  switch (type)
418  {
419  case OFPAT_OUTPUT:
420  {
421  if (len != sizeof(ofp_action_output))
422  {
423  return OFPBAC_BAD_LEN;
424  }
425 
426  ofp_action_output *oa = (ofp_action_output *)ah;
427 
428  // To prevent loops, make sure there's no action to send to the OFP_TABLE virtual port.
429 
430  // port is now 32-bit
431  if (oa->port == OFPP_NONE || oa->port == key->flow.in_port) // htonl(OFPP_NONE);
432  { // if (oa->port == htons(OFPP_NONE) || oa->port == key->flow.in_port)
433  return OFPBAC_BAD_OUT_PORT;
434  }
435 
436  return ACT_VALIDATION_OK;
437  }
438  case OFPAT_SET_VLAN_VID:
439  size = sizeof(ofp_action_vlan_vid);
440  break;
441  case OFPAT_SET_VLAN_PCP:
442  size = sizeof(ofp_action_vlan_pcp);
443  break;
444  case OFPAT_STRIP_VLAN:
445  size = sizeof(ofp_action_header);
446  break;
447  case OFPAT_SET_DL_SRC:
448  case OFPAT_SET_DL_DST:
449  size = sizeof(ofp_action_dl_addr);
450  break;
451  case OFPAT_SET_NW_SRC:
452  case OFPAT_SET_NW_DST:
453  size = sizeof(ofp_action_nw_addr);
454  break;
455  case OFPAT_SET_TP_SRC:
456  case OFPAT_SET_TP_DST:
457  size = sizeof(ofp_action_tp_port);
458  break;
459  case OFPAT_SET_MPLS_LABEL:
460  size = sizeof(ofp_action_mpls_label);
461  break;
462  case OFPAT_SET_MPLS_EXP:
463  size = sizeof(ofp_action_mpls_exp);
464  break;
465  default:
466  break;
467  }
468 
469  if (len != size)
470  {
471  return OFPBAC_BAD_LEN;
472  }
473  return ACT_VALIDATION_OK;
474 }
475 
476 void
477 Action::Execute (ofp_action_type type, ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
478 {
479  switch (type)
480  {
481  case OFPAT_OUTPUT:
482  break;
483  case OFPAT_SET_VLAN_VID:
484  set_vlan_vid (buffer, key, ah);
485  break;
486  case OFPAT_SET_VLAN_PCP:
487  set_vlan_pcp (buffer, key, ah);
488  break;
489  case OFPAT_STRIP_VLAN:
490  strip_vlan (buffer, key, ah);
491  break;
492  case OFPAT_SET_DL_SRC:
493  case OFPAT_SET_DL_DST:
494  set_dl_addr (buffer, key, ah);
495  break;
496  case OFPAT_SET_NW_SRC:
497  case OFPAT_SET_NW_DST:
498  set_nw_addr (buffer, key, ah);
499  break;
500  case OFPAT_SET_TP_SRC:
501  case OFPAT_SET_TP_DST:
502  set_tp_port (buffer, key, ah);
503  break;
504  case OFPAT_SET_MPLS_LABEL:
505  set_mpls_label (buffer, key, ah);
506  break;
507  case OFPAT_SET_MPLS_EXP:
508  set_mpls_exp (buffer, key, ah);
509  break;
510  default:
511  break;
512  }
513 }
514 
515 bool
516 VPortAction::IsValidType (ofp_vport_action_type type)
517 {
518  switch (type)
519  {
520  case OFPPAT_POP_MPLS:
521  case OFPPAT_PUSH_MPLS:
522  case OFPPAT_SET_MPLS_LABEL:
523  case OFPPAT_SET_MPLS_EXP:
524  return true;
525  default:
526  return false;
527  }
528 }
529 
530 uint16_t
531 VPortAction::Validate (ofp_vport_action_type type, size_t len, const ofp_action_header *ah)
532 {
533  size_t size = 0;
534 
535  switch (type)
536  {
537  case OFPPAT_POP_MPLS:
538  size = sizeof(ofp_vport_action_pop_mpls);
539  break;
540  case OFPPAT_PUSH_MPLS:
541  size = sizeof(ofp_vport_action_push_mpls);
542  break;
543  case OFPPAT_SET_MPLS_LABEL:
544  size = sizeof(ofp_vport_action_set_mpls_label);
545  break;
546  case OFPPAT_SET_MPLS_EXP:
547  size = sizeof(ofp_vport_action_set_mpls_exp);
548  break;
549  default:
550  break;
551  }
552 
553  if (len != size)
554  {
555  return OFPBAC_BAD_LEN;
556  }
557  return ACT_VALIDATION_OK;
558 }
559 
560 void
561 VPortAction::Execute (ofp_vport_action_type type, ofpbuf *buffer, const sw_flow_key *key, const ofp_action_header *ah)
562 {
563  switch (type)
564  {
565  case OFPPAT_POP_MPLS:
566  {
567  ofp_vport_action_pop_mpls *opapm = (ofp_vport_action_pop_mpls *)ah;
568  pop_mpls_act (0, buffer, key, &opapm->apm);
569  break;
570  }
571  case OFPPAT_PUSH_MPLS:
572  {
573  ofp_vport_action_push_mpls *opapm = (ofp_vport_action_push_mpls *)ah;
574  push_mpls_act (0, buffer, key, &opapm->apm);
575  break;
576  }
577  case OFPPAT_SET_MPLS_LABEL:
578  {
579  ofp_vport_action_set_mpls_label *oparml = (ofp_vport_action_set_mpls_label *)ah;
580  set_mpls_label_act (buffer, key, oparml->label_out);
581  break;
582  }
583  case OFPPAT_SET_MPLS_EXP:
584  {
585  ofp_vport_action_set_mpls_exp *oparme = (ofp_vport_action_set_mpls_exp *)ah;
586  set_mpls_exp_act (buffer, key, oparme->exp);
587  break;
588  }
589  default:
590  break;
591  }
592 }
593 
594 bool
595 EricssonAction::IsValidType (er_action_type type)
596 {
597  switch (type)
598  {
599  case ERXT_POP_MPLS:
600  case ERXT_PUSH_MPLS:
601  return true;
602  default:
603  return false;
604  }
605 }
606 
607 uint16_t
608 EricssonAction::Validate (er_action_type type, size_t len)
609 {
610  size_t size = 0;
611 
612  switch (type)
613  {
614  case ERXT_POP_MPLS:
615  size = sizeof(er_action_pop_mpls);
616  break;
617  case ERXT_PUSH_MPLS:
618  size = sizeof(er_action_push_mpls);
619  break;
620  default:
621  break;
622  }
623 
624  if (len != size)
625  {
626  return OFPBAC_BAD_LEN;
627  }
628  return ACT_VALIDATION_OK;
629 }
630 
631 void
632 EricssonAction::Execute (er_action_type type, ofpbuf *buffer, const sw_flow_key *key, const er_action_header *ah)
633 {
634  switch (type)
635  {
636  case ERXT_POP_MPLS:
637  {
638  er_action_pop_mpls *erapm = (er_action_pop_mpls *)ah;
639  pop_mpls_act (0, buffer, key, &erapm->apm);
640  break;
641  }
642  case ERXT_PUSH_MPLS:
643  {
644  er_action_push_mpls *erapm = (er_action_push_mpls *)ah;
645  push_mpls_act (0, buffer, key, &erapm->apm);
646  break;
647  }
648  default:
649  break;
650  }
651 }
652 
653 void
654 Controller::AddSwitch (Ptr<OpenFlowSwitchNetDevice> swtch)
655 {
656  if (m_switches.find (swtch) != m_switches.end ())
657  {
658  NS_LOG_INFO ("This Controller has already registered this switch!");
659  }
660  else
661  {
662  m_switches.insert (swtch);
663  }
664 }
665 
666 void
667 Controller::SendToSwitch (Ptr<OpenFlowSwitchNetDevice> swtch, void * msg, size_t length)
668 {
669  if (m_switches.find (swtch) == m_switches.end ())
670  {
671  NS_LOG_ERROR ("Can't send to this switch, not registered to the Controller.");
672  return;
673  }
674 
675  swtch->ForwardControlInput (msg, length);
676 }
677 
678 ofp_flow_mod*
679 Controller::BuildFlow (sw_flow_key key, uint32_t buffer_id, uint16_t command, void* acts, size_t actions_len, int idle_timeout, int hard_timeout)
680 {
681  ofp_flow_mod* ofm = (ofp_flow_mod*)malloc (sizeof(ofp_flow_mod) + actions_len);
682  ofm->header.version = OFP_VERSION;
683  ofm->header.type = OFPT_FLOW_MOD;
684  ofm->header.length = htons (sizeof(ofp_flow_mod) + actions_len);
685  ofm->command = htons (command);
686  ofm->idle_timeout = htons (idle_timeout);
687  ofm->hard_timeout = htons (hard_timeout);
688  ofm->buffer_id = htonl (buffer_id);
689  ofm->priority = OFP_DEFAULT_PRIORITY;
690  memcpy (ofm->actions,acts,actions_len);
691 
692  ofm->match.wildcards = key.wildcards; // Wildcard fields
693  ofm->match.in_port = key.flow.in_port; // Input switch port
694  memcpy (ofm->match.dl_src, key.flow.dl_src, sizeof ofm->match.dl_src); // Ethernet source address.
695  memcpy (ofm->match.dl_dst, key.flow.dl_dst, sizeof ofm->match.dl_dst); // Ethernet destination address.
696  ofm->match.dl_vlan = key.flow.dl_vlan; // Input VLAN OFP_VLAN_NONE;
697  ofm->match.dl_type = key.flow.dl_type; // Ethernet frame type ETH_TYPE_IP;
698  ofm->match.nw_proto = key.flow.nw_proto; // IP Protocol
699  ofm->match.nw_src = key.flow.nw_src; // IP source address
700  ofm->match.nw_dst = key.flow.nw_dst; // IP destination address
701  ofm->match.tp_src = key.flow.tp_src; // TCP/UDP source port
702  ofm->match.tp_dst = key.flow.tp_dst; // TCP/UDP destination port
703  ofm->match.mpls_label1 = key.flow.mpls_label1; // Top of label stack htonl(MPLS_INVALID_LABEL);
704  ofm->match.mpls_label2 = key.flow.mpls_label1; // Second label (if available) htonl(MPLS_INVALID_LABEL);
705 
706  return ofm;
707 }
708 
709 uint8_t
710 Controller::GetPacketType (ofpbuf* buffer)
711 {
712  ofp_header* hdr = (ofp_header*)ofpbuf_try_pull (buffer, sizeof (ofp_header));
713  uint8_t type = hdr->type;
714  ofpbuf_push_uninit (buffer, sizeof (ofp_header));
715  return type;
716 }
717 
718 void
719 Controller::StartDump (StatsDumpCallback* cb)
720 {
721  if (cb != 0)
722  {
723  int error = 1;
724  while (error > 0) // Switch's StatsDump returns 1 if the reply isn't complete.
725  {
726  error = cb->swtch->StatsDump (cb);
727  }
728 
729  if (error != 0) // When the reply is complete, error will equal zero if there's no errors.
730  {
731  NS_LOG_WARN ("Dump Callback Error: " << strerror (-error));
732  }
733 
734  // Clean up
735  cb->swtch->StatsDone (cb);
736  }
737 }
738 
739 void
740 DropController::ReceiveFromSwitch (Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* buffer)
741 {
742  if (m_switches.find (swtch) == m_switches.end ())
743  {
744  NS_LOG_ERROR ("Can't receive from this switch, not registered to the Controller.");
745  return;
746  }
747 
748  // We have received any packet at this point, so we pull the header to figure out what type of packet we're handling.
749  uint8_t type = GetPacketType (buffer);
750 
751  if (type == OFPT_PACKET_IN) // The switch didn't understand the packet it received, so it forwarded it to the controller.
752  {
753  ofp_packet_in * opi = (ofp_packet_in*)ofpbuf_try_pull (buffer, offsetof (ofp_packet_in, data));
754  int port = ntohs (opi->in_port);
755 
756  // Create matching key.
757  sw_flow_key key;
758  key.wildcards = 0;
759  flow_extract (buffer, port != -1 ? port : OFPP_NONE, &key.flow);
760 
761  ofp_flow_mod* ofm = BuildFlow (key, opi->buffer_id, OFPFC_ADD, 0, 0, OFP_FLOW_PERMANENT, OFP_FLOW_PERMANENT);
762  SendToSwitch (swtch, ofm, ofm->header.length);
763  }
764 }
765 
766 TypeId LearningController::GetTypeId (void)
767 {
768  static TypeId tid = TypeId ("ns3::ofi::LearningController")
770  .SetGroupName ("Openflow")
771  .AddConstructor<LearningController> ()
772  .AddAttribute ("ExpirationTime",
773  "Time it takes for learned MAC state entry/created flow to expire.",
774  TimeValue (Seconds (0)),
776  MakeTimeChecker ())
777  ;
778  return tid;
779 }
780 
781 void
782 LearningController::ReceiveFromSwitch (Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* buffer)
783 {
784  if (m_switches.find (swtch) == m_switches.end ())
785  {
786  NS_LOG_ERROR ("Can't receive from this switch, not registered to the Controller.");
787  return;
788  }
789 
790  // We have received any packet at this point, so we pull the header to figure out what type of packet we're handling.
791  uint8_t type = GetPacketType (buffer);
792 
793  if (type == OFPT_PACKET_IN) // The switch didn't understand the packet it received, so it forwarded it to the controller.
794  {
795  ofp_packet_in * opi = (ofp_packet_in*)ofpbuf_try_pull (buffer, offsetof (ofp_packet_in, data));
796  int port = ntohs (opi->in_port);
797 
798  // Create matching key.
799  sw_flow_key key;
800  key.wildcards = 0;
801  flow_extract (buffer, port != -1 ? port : OFPP_NONE, &key.flow);
802 
803  uint16_t out_port = OFPP_FLOOD;
804  uint16_t in_port = ntohs (key.flow.in_port);
805 
806  // If the destination address is learned to a specific port, find it.
807  Mac48Address dst_addr;
808  dst_addr.CopyFrom (key.flow.dl_dst);
809  if (!dst_addr.IsBroadcast ())
810  {
811  LearnState_t::iterator st = m_learnState.find (dst_addr);
812  if (st != m_learnState.end ())
813  {
814  out_port = st->second.port;
815  }
816  else
817  {
818  NS_LOG_INFO ("Setting to flood; don't know yet what port " << dst_addr << " is connected to");
819  }
820  }
821  else
822  {
823  NS_LOG_INFO ("Setting to flood; this packet is a broadcast");
824  }
825 
826  // Create output-to-port action
827  ofp_action_output x[1];
828  x[0].type = htons (OFPAT_OUTPUT);
829  x[0].len = htons (sizeof(ofp_action_output));
830  x[0].port = out_port;
831 
832  // Create a new flow that outputs matched packets to a learned port, OFPP_FLOOD if there's no learned port.
833  ofp_flow_mod* ofm = BuildFlow (key, opi->buffer_id, OFPFC_ADD, x, sizeof(x), OFP_FLOW_PERMANENT, m_expirationTime.IsZero () ? OFP_FLOW_PERMANENT : m_expirationTime.GetSeconds ());
834  SendToSwitch (swtch, ofm, ofm->header.length);
835 
836  // We can learn a specific port for the source address for future use.
837  Mac48Address src_addr;
838  src_addr.CopyFrom (key.flow.dl_src);
839  LearnState_t::iterator st = m_learnState.find (src_addr);
840  if (st == m_learnState.end ()) // We haven't learned our source MAC yet.
841  {
842  LearnedState ls;
843  ls.port = in_port;
844  m_learnState.insert (std::make_pair (src_addr,ls));
845  NS_LOG_INFO ("Learned that " << src_addr << " can be found over port " << in_port);
846 
847  // Learn src_addr goes to a certain port.
848  ofp_action_output x2[1];
849  x2[0].type = htons (OFPAT_OUTPUT);
850  x2[0].len = htons (sizeof(ofp_action_output));
851  x2[0].port = in_port;
852 
853  // Switch MAC Addresses and ports to the flow we're modifying
854  src_addr.CopyTo (key.flow.dl_dst);
855  dst_addr.CopyTo (key.flow.dl_src);
856  key.flow.in_port = out_port;
857  ofp_flow_mod* ofm2 = BuildFlow (key, -1, OFPFC_MODIFY, x2, sizeof(x2), OFP_FLOW_PERMANENT, m_expirationTime.IsZero () ? OFP_FLOW_PERMANENT : m_expirationTime.GetSeconds ());
858  SendToSwitch (swtch, ofm2, ofm2->header.length);
859  }
860  }
861 }
862 
863 void
864 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)
865 {
867  /* Every output action needs a separate clone of 'buffer', but the common
868  * case is just a single output action, so that doing a clone and then
869  * freeing the original buffer is wasteful. So the following code is
870  * slightly obscure just to avoid that. */
871  int prev_port;
872  size_t max_len = 0; // Initialze to make compiler happy
873  uint16_t in_port = key->flow.in_port; // ntohs(key->flow.in_port);
874  uint8_t *p = (uint8_t *)actions;
875 
876  prev_port = -1;
877 
878  if (actions_len == 0)
879  {
880  NS_LOG_INFO ("No actions set to this flow. Dropping packet.");
881  return;
882  }
883 
884  /* The action list was already validated, so we can be a bit looser
885  * in our sanity-checking. */
886  while (actions_len > 0)
887  {
888  ofp_action_header *ah = (ofp_action_header *)p;
889  size_t len = htons (ah->len);
890 
891  if (prev_port != -1)
892  {
893  swtch->DoOutput (packet_uid, in_port, max_len, prev_port, ignore_no_fwd);
894  prev_port = -1;
895  }
896 
897  if (ah->type == htons (OFPAT_OUTPUT))
898  {
899  ofp_action_output *oa = (ofp_action_output *)p;
900 
901  // port is now 32-bits
902  prev_port = oa->port; // ntohl(oa->port);
903  // prev_port = ntohs(oa->port);
904  max_len = ntohs (oa->max_len);
905  }
906  else
907  {
908  uint16_t type = ntohs (ah->type);
909  if (Action::IsValidType ((ofp_action_type)type)) // Execute a built-in OpenFlow action against 'buffer'.
910  {
911  Action::Execute ((ofp_action_type)type, buffer, key, ah);
912  }
913  else if (type == OFPAT_VENDOR)
914  {
915  ExecuteVendor (buffer, key, ah);
916  }
917  }
918 
919  p += len;
920  actions_len -= len;
921  }
922 
923  if (prev_port != -1)
924  {
925  swtch->DoOutput (packet_uid, in_port, max_len, prev_port, ignore_no_fwd);
926  }
927 }
928 
929 uint16_t
930 ValidateActions (const sw_flow_key *key, const ofp_action_header *actions, size_t actions_len)
931 {
932  uint8_t *p = (uint8_t *)actions;
933  int err;
934 
935  while (actions_len >= sizeof(ofp_action_header))
936  {
937  ofp_action_header *ah = (ofp_action_header *)p;
938  size_t len = ntohs (ah->len);
939  uint16_t type;
940 
941  /* Make there's enough remaining data for the specified length
942  * and that the action length is a multiple of 64 bits. */
943  if ((actions_len < len) || (len % 8) != 0)
944  {
945  return OFPBAC_BAD_LEN;
946  }
947 
948  type = ntohs (ah->type);
949  if (Action::IsValidType ((ofp_action_type)type)) // Validate built-in OpenFlow actions.
950  {
951  err = Action::Validate ((ofp_action_type)type, len, key, ah);
952  if (err != ACT_VALIDATION_OK)
953  {
954  return err;
955  }
956  }
957  else if (type == OFPAT_VENDOR)
958  {
959  err = ValidateVendor (key, ah, len);
960  if (err != ACT_VALIDATION_OK)
961  {
962  return err;
963  }
964  }
965  else
966  {
967  return OFPBAC_BAD_TYPE;
968  }
969 
970  p += len;
971  actions_len -= len;
972  }
973 
974  // Check if there's any trailing garbage.
975  if (actions_len != 0)
976  {
977  return OFPBAC_BAD_LEN;
978  }
979 
980  return ACT_VALIDATION_OK;
981 }
982 
983 void
984 ExecuteVPortActions (Ptr<OpenFlowSwitchNetDevice> swtch, uint64_t packet_uid, ofpbuf* buffer, sw_flow_key *key, const ofp_action_header *actions, size_t actions_len)
985 {
986  /* Every output action needs a separate clone of 'buffer', but the common
987  * case is just a single output action, so that doing a clone and then
988  * freeing the original buffer is wasteful. So the following code is
989  * slightly obscure just to avoid that. */
990  int prev_port;
991  size_t max_len = 0; // Initialize to make compiler happy
992  uint16_t in_port = ntohs (key->flow.in_port);
993  uint8_t *p = (uint8_t *)actions;
994  uint16_t type;
995  ofp_action_output *oa;
996 
997  prev_port = -1;
998  /* The action list was already validated, so we can be a bit looser
999  * in our sanity-checking. */
1000  while (actions_len > 0)
1001  {
1002  ofp_action_header *ah = (ofp_action_header *)p;
1003  size_t len = htons (ah->len);
1004  if (prev_port != -1)
1005  {
1006  swtch->DoOutput (packet_uid, in_port, max_len, prev_port, false);
1007  prev_port = -1;
1008  }
1009 
1010  if (ah->type == htons (OFPAT_OUTPUT))
1011  {
1012  oa = (ofp_action_output *)p;
1013  prev_port = ntohl (oa->port);
1014  max_len = ntohs (oa->max_len);
1015  }
1016  else
1017  {
1018  type = ah->type; // ntohs(ah->type);
1019  VPortAction::Execute ((ofp_vport_action_type)type, buffer, key, ah);
1020  }
1021 
1022  p += len;
1023  actions_len -= len;
1024  }
1025 
1026  if (prev_port != -1)
1027  {
1028  swtch->DoOutput (packet_uid, in_port, max_len, prev_port, false);
1029  }
1030 }
1031 
1032 uint16_t
1033 ValidateVPortActions (const ofp_action_header *actions, size_t actions_len)
1034 {
1035  uint8_t *p = (uint8_t *)actions;
1036  int err;
1037 
1038  while (actions_len >= sizeof(ofp_action_header))
1039  {
1040  ofp_action_header *ah = (ofp_action_header *)p;
1041  size_t len = ntohs (ah->len);
1042  uint16_t type;
1043 
1044  /* Make there's enough remaining data for the specified length
1045  * and that the action length is a multiple of 64 bits. */
1046  if ((actions_len < len) || (len % 8) != 0)
1047  {
1048  return OFPBAC_BAD_LEN;
1049  }
1050 
1051  type = ntohs (ah->type);
1052  if (VPortAction::IsValidType ((ofp_vport_action_type)type)) // Validate "built-in" OpenFlow port table actions.
1053  {
1054  err = VPortAction::Validate ((ofp_vport_action_type)type, len, ah);
1055  if (err != ACT_VALIDATION_OK)
1056  {
1057  return err;
1058  }
1059  }
1060  else
1061  {
1062  return OFPBAC_BAD_TYPE;
1063  }
1064 
1065  p += len;
1066  actions_len -= len;
1067  }
1068 
1069  // Check if there's any trailing garbage.
1070  if (actions_len != 0)
1071  {
1072  return OFPBAC_BAD_LEN;
1073  }
1074 
1075  return ACT_VALIDATION_OK;
1076 }
1077 
1078 void
1079 ExecuteVendor (ofpbuf *buffer, const sw_flow_key *key, const ofp_action_header *ah)
1080 {
1081  ofp_action_vendor_header *avh = (ofp_action_vendor_header *)ah;
1082 
1083  switch (ntohl (avh->vendor))
1084  {
1085  case NX_VENDOR_ID:
1086  // Nothing to execute yet.
1087  break;
1088  case ER_VENDOR_ID:
1089  {
1090  const er_action_header *erah = (const er_action_header *)avh;
1091  EricssonAction::Execute ((er_action_type)ntohs (erah->subtype), buffer, key, erah);
1092  break;
1093  }
1094  default:
1095  // This should not be possible due to prior validation.
1096  NS_LOG_INFO ("attempt to execute action with unknown vendor: " << ntohl (avh->vendor));
1097  break;
1098  }
1099 }
1100 
1101 uint16_t
1102 ValidateVendor (const sw_flow_key *key, const ofp_action_header *ah, uint16_t len)
1103 {
1104  ofp_action_vendor_header *avh;
1105  int ret = ACT_VALIDATION_OK;
1106 
1107  if (len < sizeof(ofp_action_vendor_header))
1108  {
1109  return OFPBAC_BAD_LEN;
1110  }
1111 
1112  avh = (ofp_action_vendor_header *)ah;
1113 
1114  switch (ntohl (avh->vendor))
1115  {
1116  case NX_VENDOR_ID: // Validate Nicara OpenFlow actions.
1117  ret = OFPBAC_BAD_VENDOR_TYPE; // Nothing to validate yet.
1118  break;
1119  case ER_VENDOR_ID: // Validate Ericsson OpenFlow actions.
1120  {
1121  const er_action_header *erah = (const er_action_header *)avh;
1122  ret = EricssonAction::Validate ((er_action_type)ntohs (erah->subtype), len);
1123  break;
1124  }
1125  default:
1126  return OFPBAC_BAD_VENDOR;
1127  }
1128 
1129  return ret;
1130 }
1131 
1132 }
1133 
1134 }
1135 
1136 #endif // NS3_OPENFLOW
void StartDump(StatsDumpCallback *cb)
Starts a callback-based, reliable, possibly multi-message reply to a request made by the controller...
void strip_vlan(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
static bool IsValidType(ofp_action_type type)
TypeId AddConstructor(void)
Definition: type-id.h:460
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.
static const char * GetSerialNumber()
static TypeId GetTypeId(void)
bool IsZero(void) const
Definition: nstime.h:276
int(* AggregateDumpCallback)(sw_flow *flow, void *state)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
int DoInit(const void *body, int body_len, void **state)
Prepares to dump some kind of statistics on the connected OpenFlowSwitchNetDevice.
int(* FlowDumpCallback)(sw_flow *flow, void *state)
int AggregateStatsInit(const void *body, int body_len, void **state)
static const char * GetHardwareDescription()
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
void ReceiveFromSwitch(Ptr< OpenFlowSwitchNetDevice > swtch, ofpbuf *buffer)
A switch calls this method to pass a message on to the Controller.
int AggregateStatsDump(Ptr< OpenFlowSwitchNetDevice > dp, ofp_aggregate_stats_request *s, ofpbuf *buffer)
void ReceiveFromSwitch(Ptr< OpenFlowSwitchNetDevice > swtch, ofpbuf *buffer)
A switch calls this method to pass a message on to the Controller.
Stats(ofp_stats_types _type, size_t body_len)
int PortTableStatsDump(Ptr< OpenFlowSwitchNetDevice > dp, void *state, ofpbuf *buffer)
void set_dl_addr(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
uint16_t port
Definition: dsdv-manet.cc:44
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
int TableStatsDump(Ptr< OpenFlowSwitchNetDevice > dp, void *state, ofpbuf *buffer)
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:334
ofp_stats_types type
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 const char * GetManufacturerDescription()
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.
uint8_t data[writeSize]
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)
static void Execute(ofp_vport_action_type type, ofpbuf *buffer, const sw_flow_key *key, const ofp_action_header *ah)
Executes the action.
static TypeId GetTypeId(void)
Switches_t m_switches
The collection of switches registered to this controller.
static uint16_t Validate(er_action_type type, size_t len)
Validates the action on whether its data is valid or not.
TypeId SetGroupName(std::string groupName)
Definition: type-id.cc:645
static const char * GetSoftwareDescription()
int DoDump(Ptr< OpenFlowSwitchNetDevice > swtch, void *state, ofpbuf *buffer)
Appends statistics for OpenFlowSwitchNetDevice to 'buffer'.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void set_tp_port(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
int PortStatsDump(Ptr< OpenFlowSwitchNetDevice > dp, PortStatsState *s, ofpbuf *buffer)
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...
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:929
void set_mpls_exp(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
int FlowStatsInit(const void *body, int body_len, void **state)
uint16_t ValidateActions(const sw_flow_key *key, const ofp_action_header *actions, size_t actions_len)
Validates a list of flow table actions.
virtual void AddSwitch(Ptr< OpenFlowSwitchNetDevice > swtch)
Adds a switch to the controller.
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, or deleting a flow.
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.
void set_vlan_pcp(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:228
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:866
void set_nw_addr(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
Time m_expirationTime
Time it takes for learned MAC state entry/created flow to expire.
uint8_t GetPacketType(ofpbuf *buffer)
Get the packet type on the buffer, which can then be used to determine how to handle the buffer...
int DescStatsDump(void *state, ofpbuf *buffer)
int PortStatsInit(const void *body, int body_len, void **state)
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:220
void set_mpls_label(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)
static bool IsValidType(ofp_vport_action_type type)
uint16_t ValidateVPortActions(const ofp_action_header *actions, size_t actions_len)
Validates a list of virtual port table entry actions.
void ExecuteVendor(ofpbuf *buffer, const sw_flow_key *key, const ofp_action_header *ah)
Executes a vendor-defined action.
int FlowStatsDump(Ptr< OpenFlowSwitchNetDevice > dp, FlowStatsState *s, ofpbuf *buffer)
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)
Definition: type-id.cc:638
void DoCleanup(void *state)
Cleans any state created by the init or dump functions.
uint16_t ValidateVendor(const sw_flow_key *key, const ofp_action_header *ah, uint16_t len)
Validates a vendor-defined action.
void set_vlan_vid(ofpbuf *buffer, sw_flow_key *key, const ofp_action_header *ah)