Exemplo n.º 1
0
/* Features Request packet receive. */
lagopus_result_t
ofp_features_request_handle(struct channel *channel, struct pbuf *pbuf,
                            struct ofp_header *xid_header,
                            struct ofp_error *error) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct pbuf *send_pbuf = NULL;

  /* Parse packet. */
  ret = ofp_header_handle(channel, pbuf, error);
  if (ret == LAGOPUS_RESULT_OK) {
    /* Features request reply. */
    ret = ofp_features_reply_create(channel, &send_pbuf,
                                    xid_header);
    if (ret == LAGOPUS_RESULT_OK) {
      features_request_trace(xid_header);

      channel_send_packet(channel, send_pbuf);
      ret = LAGOPUS_RESULT_OK;
    } else {
      lagopus_msg_warning("FAILED (%s).\n", lagopus_error_get_string(ret));
    }
  }

  if (ret != LAGOPUS_RESULT_OK && send_pbuf != NULL) {
    channel_pbuf_list_unget(channel, send_pbuf);
  }

  return ret;
}
Exemplo n.º 2
0
/* Experimenter packet receive. */
lagopus_result_t
ofp_experimenter_request_handle(struct channel *channel, struct pbuf *pbuf,
                                struct ofp_header *xid_header) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct pbuf *send_pbuf = NULL;
  struct ofp_experimenter_header exper_req;

  if (channel != NULL && pbuf != NULL &&
      xid_header != NULL) {
    /* Parse packet. */
    ret = ofp_experimenter_header_decode(pbuf, &exper_req);
    if (ret == LAGOPUS_RESULT_OK) {
      /* Experimenter request reply. */
      ret = ofp_experimenter_reply_create(channel, &send_pbuf,
                                          xid_header, &exper_req);
      if (ret == LAGOPUS_RESULT_OK) {
        channel_send_packet(channel, send_pbuf);
        ret = LAGOPUS_RESULT_OK;
      } else {
        lagopus_msg_warning("FAILED (%s).\n", lagopus_error_get_string(ret));
      }
    } else {
      lagopus_msg_warning("FAILED (%s).\n", lagopus_error_get_string(ret));
      ret = LAGOPUS_RESULT_OFP_ERROR;
    }

    if (ret != LAGOPUS_RESULT_OK && send_pbuf != NULL) {
      channel_pbuf_list_unget(channel, send_pbuf);
    }
  } else {
    ret = LAGOPUS_RESULT_INVALID_ARGS;
  }

  return ret;
}
Exemplo n.º 3
0
void window_out_commit(
        window_t* window) 
{            
    debug_print("window_out_commit()\n");
    
    window_lock(window);
    
    if (!window->buffer->size) {
        window->size = 0;
        window->head = 0;
        window->tail = 0;
    } else {
        
        window->size = MIN(window->max_size, window->buffer->size);            
        window->head = queue_head(window->buffer);
        window->tail = window_get(window, window->size-1);                
        
        //printf("head: %p, tail: %p\n", window->head, window->tail);
        
        if (!window->tail || !window->head) {            
            return;
        }
        
        queue_node_t* node = window->head;
        packet_t* packet = (packet_t*) node->data;            
        
        while(node != window->tail) {
            packet = (packet_t*) node->data;
            
            if (!packet->transmission_time) {
                channel_send_packet(packet);
            }

            node = node->next;
        }
        
        if (node == window->tail) {
            if (!packet->transmission_time) {
                channel_send_packet(packet);
            }
        }        
    }

    window_unlock(window);
    success_print("window_out_commit() succeed\n");     
}
Exemplo n.º 4
0
lagopus_result_t
ofp_get_async_request_handle(struct channel *channel,
                             struct pbuf *pbuf,
                             struct ofp_header *xid_header,
                             struct ofp_error *error) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct pbuf *send_pbuf = NULL;

  /* check params */
  if (channel != NULL && pbuf != NULL &&
      xid_header != NULL && error != NULL) {

    ret = pbuf_plen_check(pbuf, xid_header->length);

    if (ret == LAGOPUS_RESULT_OK) {
      /* Parse packet. */
      ret = ofp_header_handle(channel, pbuf, error);

      if (ret == LAGOPUS_RESULT_OK) {
        /* dump trace. */
        get_async_request_trace(xid_header);

        /* Reply send.*/
        ret = ofp_get_async_reply_create(channel, &send_pbuf,
                                         xid_header);

        if (ret == LAGOPUS_RESULT_OK) {
          channel_send_packet(channel, send_pbuf);
        } else {
          lagopus_msg_warning("FAILED (%s).\n",
                              lagopus_error_get_string(ret));
        }
      } else {
        lagopus_msg_warning("FAILED (%s).\n", lagopus_error_get_string(ret));
        ofp_error_set(error, OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
        ret = LAGOPUS_RESULT_OFP_ERROR;
      }

      if (ret != LAGOPUS_RESULT_OK && send_pbuf != NULL) {
        channel_pbuf_list_unget(channel, send_pbuf);
      }
    } else {
      lagopus_msg_warning("bad length.\n");
      ofp_error_set(error, OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
      ret = LAGOPUS_RESULT_OFP_ERROR;
    }
  } else {
    ret = LAGOPUS_RESULT_INVALID_ARGS;
  }

  return ret;
}
Exemplo n.º 5
0
static lagopus_result_t
ofp_write_channel(struct channel *channel,
                  struct pbuf *pbuf) {
  lagopus_result_t ret = LAGOPUS_RESULT_OK;
  struct pbuf *send_pbuf = NULL;
  uint16_t len = 0;

  if (channel != NULL && pbuf != NULL) {
    ret = pbuf_length_get(pbuf, &len);

    if (ret == LAGOPUS_RESULT_OK) {
      send_pbuf = channel_pbuf_list_get(channel,
                                        (size_t) len);
      if (send_pbuf != NULL) {
        /* Copy pbuf. */
        ret = pbuf_copy(send_pbuf, pbuf);

        if (ret == LAGOPUS_RESULT_OK) {
          ret = ofp_header_packet_set(channel, send_pbuf);

          if (ret == LAGOPUS_RESULT_OK) {
            channel_send_packet(channel, send_pbuf);
            ret = LAGOPUS_RESULT_OK;
          } else {
            lagopus_msg_warning("FAILED (%s).\n",
                                lagopus_error_get_string(ret));
          }
        } else {
          lagopus_msg_warning("FAILED (%s).\n",
                              lagopus_error_get_string(ret));
        }
      } else {
        lagopus_msg_warning("Can't allocate pbuf.\n");
        ret = LAGOPUS_RESULT_NO_MEMORY;
      }
    } else {
      lagopus_msg_warning("FAILED (%s).\n",
                          lagopus_error_get_string(ret));
    }

    if (ret != LAGOPUS_RESULT_OK && send_pbuf != NULL) {
      channel_pbuf_list_unget(channel, send_pbuf);
    }
  } else {
    ret = LAGOPUS_RESULT_INVALID_ARGS;
  }

  return ret;
}
Exemplo n.º 6
0
lagopus_result_t
ofp_role_request_handle(struct channel *channel,
                        struct pbuf *pbuf,
                        struct ofp_header *xid_header,
                        struct ofp_error *error) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct ofp_role_request role_request;
  struct ofp_role_request modified_role_request;
  struct pbuf *send_pbuf = NULL;
  uint64_t dpid;

  if (channel != NULL && pbuf != NULL &&
      xid_header != NULL && error != NULL) {
    /* Parse packet. */
    ret = ofp_role_request_decode(pbuf, &role_request);

    if (ret == LAGOPUS_RESULT_OK) {
      /* dump trace. */
      role_request_trace(&role_request);

      ret = role_check(role_request.role, error);

      if (ret == LAGOPUS_RESULT_OK) {
        dpid = channel_dpid_get(channel);
        if (ofp_role_generation_id_check(dpid, role_request.role,
                                         role_request.generation_id) == true) {
          /* copy role request. */
          modified_role_request = role_request;
          ret = ofp_role_channel_update(channel,
                                        &modified_role_request,
                                        dpid);
          if (ret == LAGOPUS_RESULT_OK) {
            /* Reply send.*/
            ret = ofp_role_reply_create(channel, &send_pbuf,
                                        xid_header, &modified_role_request);
            if (ret == LAGOPUS_RESULT_OK) {
              channel_send_packet(channel, send_pbuf);
            } else {
              lagopus_msg_warning("FAILED (%s).\n",
                                  lagopus_error_get_string(ret));
            }
          } else {
            lagopus_msg_warning("FAILED (%s).\n",
                                lagopus_error_get_string(ret));
          }
        } else {
          lagopus_msg_warning("bad generation_id.\n");
          ofp_error_set(error, OFPET_ROLE_REQUEST_FAILED, OFPRRFC_STALE);
          ret = LAGOPUS_RESULT_OFP_ERROR;
        }

        if (ret != LAGOPUS_RESULT_OK && send_pbuf != NULL) {
          channel_pbuf_list_unget(channel, send_pbuf);
        }
      }
    } else {
      lagopus_msg_warning("FAILED (%s).\n", lagopus_error_get_string(ret));
      ofp_error_set(error, OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
      ret = LAGOPUS_RESULT_OFP_ERROR;
    }
  } else {
    ret = LAGOPUS_RESULT_INVALID_ARGS;
  }

  return ret;
}