- free(this);
- }
-}
-
-static void
-send_control_hello(struct switch_ *this)
-{
- time_t now = time(0);
- if (now >= this->last_control_hello + 1) {
- struct buffer *b;
- struct ofp_control_hello *och;
-
- b = buffer_new(0);
- och = buffer_put_uninit(b, sizeof *och);
- memset(och, 0, sizeof *och);
- och->header.version = OFP_VERSION;
- och->header.length = htons(sizeof *och);
-
- och->version = htonl(OFP_VERSION);
- och->flags = htons(OFP_CHELLO_SEND_FLOW_EXP);
- och->miss_send_len = htons(OFP_DEFAULT_MISS_SEND_LEN);
- queue_tx(this, b);
-
- this->last_control_hello = now;
- }
-}
-
-static void
-check_txq(struct switch_ *this UNUSED)
-{
-#if 0
- struct buffer *iter;
- size_t n;
-
- assert(this->n_txq == 0
- ? this->txq == NULL && this->tx_tail == NULL
- : this->txq != NULL && this->tx_tail != NULL);
-
- n = 0;
- for (iter = this->txq; iter != NULL; iter = iter->next) {
- n++;
- assert((iter->next != NULL) == (iter != this->tx_tail));
- }
- assert(n == this->n_txq);
-#endif
-}
-
-static void
-queue_tx(struct switch_ *this, struct buffer *b)
-{
- check_txq(this);
-
- b->next = NULL;
- if (this->n_txq++) {
- this->tx_tail->next = b;
- } else {
- this->txq = b;
- }
- this->tx_tail = b;
-
- check_txq(this);
-}
-
-static void
-process_packet(struct switch_ *sw, struct buffer *msg)
-{
- static const size_t min_size[UINT8_MAX + 1] = {
- [0 ... UINT8_MAX] = SIZE_MAX,
- [OFPT_CONTROL_HELLO] = sizeof (struct ofp_control_hello),
- [OFPT_DATA_HELLO] = sizeof (struct ofp_data_hello),
- [OFPT_PACKET_IN] = offsetof (struct ofp_packet_in, data),
- [OFPT_PACKET_OUT] = sizeof (struct ofp_packet_out),
- [OFPT_FLOW_MOD] = sizeof (struct ofp_flow_mod),
- [OFPT_FLOW_EXPIRED] = sizeof (struct ofp_flow_expired),
- [OFPT_TABLE] = sizeof (struct ofp_table),
- [OFPT_PORT_MOD] = sizeof (struct ofp_port_mod),
- [OFPT_PORT_STATUS] = sizeof (struct ofp_port_status),
- [OFPT_FLOW_STAT_REQUEST] = sizeof (struct ofp_flow_stat_request),
- [OFPT_FLOW_STAT_REPLY] = sizeof (struct ofp_flow_stat_reply),
- };
- struct ofp_header *oh;
-
- oh = msg->data;
- if (msg->size < min_size[oh->type]) {
- VLOG_WARN("%s: too short (%zu bytes) for type %"PRIu8" (min %zu)",
- sw->name, msg->size, oh->type, min_size[oh->type]);
- return;
- }
-
- if (oh->type == OFPT_DATA_HELLO) {
- struct ofp_data_hello *odh = msg->data;
- sw->datapath_id = odh->datapath_id;
- } else if (sw->datapath_id == 0) {
- send_control_hello(sw);
- return;
- }
-
- if (oh->type == OFPT_PACKET_IN) {
- if (sw->n_txq >= MAX_TXQ) {
- VLOG_WARN("%s: tx queue overflow", sw->name);
- } else if (noflow) {
- process_noflow(sw, msg->data);
- } else if (hub) {
- process_hub(sw, msg->data);
- } else {
- process_switch(sw, msg->data);