Exemple #1
1
//
// handle_input
//
int CUTS_TCPIP_Event_Handler::handle_input (ACE_HANDLE fd)
{
  // Set the ACE_HANDLE as a socket stream.
  ACE_SOCK_Stream stream (fd);


  // @todo Since the header size is constant, we can create free list
  //       of the message blocks that are used to read the header from
  //       the stream.

  // Read the event from the stream. The first chunk of the event
  // is be the header information, which is of constrant size.
  static const ssize_t header_size = 4 +        // magic
                                     4 +        // byte order
                                     2 +        // version (x.x)
                                     2 +        // padding
                                     16 +       // UUID
                                     4 +        // event id
                                     4;         // payload size

  ACE_Message_Block header (header_size);
  ssize_t retcode = stream.recv_n (header.wr_ptr (), header_size);

  if (retcode != header_size)
    ACE_ERROR_RETURN ((LM_ERROR,
           "%T (%t) - %M - invalid TCP/IP header\n"),
          -1);

  // Reflect the number of bytes read from the stream.
  header.wr_ptr (header_size);

  // Extract the header from the message block.
  CUTS_TCPIP_SPEC spec;
  ACE_CDR::ULong datasize;

  ACE_InputCDR input (header.rd_ptr (), header_size);

  // Read the SPEC and the datasize from the packet.
  input >> spec;
  input >> datasize;

  if (!input.good_bit ())
    ACE_ERROR_RETURN ((LM_ERROR,
           "%T (%t) - %M - failed to read TCP/IP header\n"),
          -1);

  // Construct a chain of message blocks to read the payload associated
  // with the received event.
  ACE_Message_Block * mb = 0;
  ACE_NEW_RETURN (mb, ACE_Message_Block (ACE_CDR::DEFAULT_BUFSIZE), -1);

  ssize_t read_count;
  ACE_Message_Block * head = mb;
  ACE_Auto_Ptr <ACE_Message_Block> auto_clean (head);

  for (size_t remaining = datasize; 0 != remaining; )
  {
    // Determine how much should be read in this attempt.
    read_count =
      ACE_CDR::DEFAULT_BUFSIZE < remaining ?
      ACE_CDR::DEFAULT_BUFSIZE : remaining;

    // Read the data from the stream.
    retcode = stream.recv_n (mb->wr_ptr (), read_count);

    if (retcode != read_count)
      ACE_ERROR_RETURN ((LM_ERROR,
                          "%T - %M - %m\n"),
                          -1);


    // Substract the amount from the remaining count.
    mb->wr_ptr (read_count);
    remaining -= read_count;

    if (0 != remaining)
    {
      // Allocate a new block for the chain.
      ACE_Message_Block * temp = 0;

      ACE_NEW_RETURN (temp,
                      ACE_Message_Block (ACE_CDR::DEFAULT_BUFSIZE),
                      -1);

      // Insert new block in the chain and move forward.
      mb->cont (temp);
      mb = temp;
    }
  }

  // Since we have made it this far, we have successfully read the
  // event and its payload from the socket. Now, pass the message
  // the object manger, so it can dispatch it accordingly.

  if (this->obj_mgr_ != 0)
  {
    iCCM::TCPIP_Servant * svnt = 0;
    int retval = this->obj_mgr_->find_object (spec.uuid_, svnt);

    if (0 == retval)
    {
      // Signal the object to handle the event.
      ACE_InputCDR ev (head, input.byte_order ());
      retval = svnt->handle_event (spec.event_id_, ev);

      if (-1 == retval)
        ACE_ERROR ((LM_ERROR,
                    "%T (%t) - %M - failed to handle event [%s]\n",
                    spec.uuid_.to_string ()->c_str ()));
    }
    else
      ACE_ERROR ((LM_ERROR,
                  "%T (%t) - %M - failed to locate object with id [%s]\n",
                  spec.uuid_.to_string ()->c_str ()));
  }

  // Release the message block.
  // head->release ();

  return 0;
}
//COFP13MPAggregateFlowStatsRequestMsg
CmResult COFP13MPAggregateFlowStatsRequestMsg::
StreamFrom(ACE_InputCDR &is)
{
    if (COFP13MultipartMsg::StreamFrom(is) != CM_OK)
    {
        return CM_ERROR_FAILURE;
    }

    is>>m_stats_request.table_id;
    is.read_octet_array(m_stats_request.pad,sizeof(m_stats_request.pad));

    is>>m_stats_request.out_port;
    is>>m_stats_request.out_group;

    is.read_octet_array(m_stats_request.pad2,sizeof(m_stats_request.pad2));

    
    is>>m_stats_request.cookie;
    is>>m_stats_request.cookie_mask;

    bool bGood = is.good_bit();
    CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE);
    return m_match.StreamFrom(is);

}
Exemple #3
0
int Logging_Handler::recv_log_record (ACE_Message_Block *&mblk)
{
  // Put <logging_peer>'s hostname in new message block.
  ACE_INET_Addr peer_addr;
  logging_peer_.get_remote_addr (peer_addr);
  mblk = new ACE_Message_Block (MAXHOSTNAMELEN + 1);
  peer_addr.get_host_name (mblk->wr_ptr (), MAXHOSTNAMELEN);
  mblk->wr_ptr (ACE_OS::strlen (mblk->wr_ptr ()) + 1); // Go past name

  // Allocate a message block for the payload; initially at least
  // large enough to hold the header, but needs some room for
  // alignment.
  ACE_Message_Block *payload =
    new ACE_Message_Block (ACE_DEFAULT_CDR_BUFSIZE);
  // Align the Message Block for a CDR stream
  ACE_CDR::mb_align (payload);
  if (logging_peer_.recv_n (payload->wr_ptr (), 8) == 8) {
    payload->wr_ptr (8);               // Reflect addition of 8 bytes

    // Create a CDR stream to parse the 8-byte header.
    ACE_InputCDR cdr (payload);

    // Extract the byte-order and use helper methods to
    // disambiguate octet, booleans, and chars.
    ACE_CDR::Boolean byte_order;
    cdr >> ACE_InputCDR::to_boolean (byte_order);

    // Set the byte-order on the stream...
    cdr.reset_byte_order (byte_order);

    // Extract the length
    ACE_CDR::ULong length;
    cdr >> length;

    // Ensure there's sufficient room for log record payload.
    ACE_CDR::grow (payload, 8 + ACE_CDR::MAX_ALIGNMENT + length);

    // Use <recv_n> to obtain the contents.
    if (logging_peer_.recv_n (payload->wr_ptr (), length) > 0) {
      payload->wr_ptr (length);   // Reflect additional bytes
      // Chain the payload to mblk via the contination field.
      mblk->cont (payload);
      return length;
    }
  }
CmResult COFP13MPAggregateFlowStatsReplyMsg::
StreamFrom(ACE_InputCDR &is)
{
    if (COFP13MultipartMsg::StreamFrom(is) != CM_OK)
    {
        return CM_ERROR_FAILURE;
    }

    is>>m_flowstats.packet_count;
    is>>m_flowstats.byte_count;
    is>>m_flowstats.flow_count;

    is.read_octet_array(m_flowstats.pad,sizeof(m_flowstats.pad));

    bool bGood = is.good_bit();
    CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE);
    return CM_OK;

}
ACE_CDR::Boolean
UTF16_UCS2_Translator::read_wstring (ACE_InputCDR &cdr,
                                    ACE_CDR::WChar *&x)
{
  ACE_CDR::ULong len;
  if (!this->read_4 (cdr, &len))
    return 0;

  // A check for the length being too great is done later in the
  // call to read_char_array but we want to have it done before
  // the memory is allocated.
  if (len > 0 && len <= cdr.length())
    {
      if (static_cast <ACE_CDR::Short> (this->major_version(cdr)) == 1
          && static_cast <ACE_CDR::Short> (this->minor_version(cdr)) == 2)
        {
          len /= ACE_UTF16_CODEPOINT_SIZE;

          //allocating one extra for the null character needed by applications
          ACE_NEW_RETURN (x,
                          ACE_CDR::WChar [len + 1],
                          0);

          x[len] = L'\x00';
          if (this->read_wchar_array_i (cdr, x, len, 1))
            {
              // Since reading the array may have adjusted the length,
              // we simply rewrite the null terminator
              x[len] = L'\x00';
              return 1;
            }
        }
      else
        {
          ACE_NEW_RETURN (x,
                          ACE_CDR::WChar [len],
                          0);
          if (this->read_wchar_array (cdr, x, len))
            return 1;
        }
      delete [] x;
    }
  else if (len == 0)
    {
      // Convert any null strings to empty strings since empty
      // strings can cause crashes. (See bug 58.)
      ACE_NEW_RETURN (x,
                      ACE_CDR::WChar[1],
                      0);
      x[0] = '\x00';
      return 1;
    }
  x = 0;
  return 0;
}
void AIO_Input_Handler::handle_read_stream
    (const ACE_Asynch_Read_Stream::Result &result) {
  if (!result.success () || result.bytes_transferred () == 0)
    delete this;
  else if (result.bytes_transferred () < result.bytes_to_read ())
    reader_.read (*mblk_, result.bytes_to_read () -
                  result.bytes_transferred ());
  else if (mblk_->length () == LOG_HEADER_SIZE) {
    ACE_InputCDR cdr (mblk_);

    ACE_CDR::Boolean byte_order;
    cdr >> ACE_InputCDR::to_boolean (byte_order);
    cdr.reset_byte_order (byte_order);

    ACE_CDR::ULong length;
    cdr >> length;

    mblk_->size (length + LOG_HEADER_SIZE);
    reader_.read (*mblk_, length);
  }
Exemple #7
0
CmResult COFPSwitchConfig::StreamFrom(ACE_InputCDR &is)
{
    CmResult lRet = CM_ERROR_FAILURE;

    lRet = COFPMessage::StreamFrom(is);
    if (CM_FAILED(lRet))
    {
        ACE_ERROR((LM_ERROR, ACE_TEXT("COFPSwitchConfig::StreamFrom, COFPMessage::StreamFrom fail\n")));
        return lRet;
    }

    is>>m_wFlags;
    is>>m_wMissSendLen;

    bool bGood = is.good_bit();
    CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE);
    return CM_OK;
}
Exemple #8
0
ACE_CDR::Boolean
ACE_ISO8859_IBM1047::read_string (ACE_InputCDR &in,
                                  ACE_CDR::Char *&x)
{
  ACE_CDR::ULong len;

  in.read_ulong (len);

  if (len > 0)
    {
      ACE_NEW_RETURN (x,
                      ACE_CDR::Char[len],
                      0);

      if (this->read_char_array (in, x, len))
        return 1;

      delete [] x;
    }

  x = 0;
  return 0;
}
ACE_CDR::Boolean
UTF16_UCS2_Translator::read_wchar_array_i (ACE_InputCDR & cdr,
                                           ACE_CDR::WChar *x,
                                           ACE_CDR::ULong &length,
                                           int)
{
  int must_swap = 0;
  char* buf;
  static const size_t align = ACE_CDR::SHORT_ALIGN;
  if (cdr.adjust (ACE_UTF16_CODEPOINT_SIZE * length, align, buf) == 0)
    {
      ACE_UTF16_T *sb = reinterpret_cast <ACE_UTF16_T *> (buf);
#if defined (ACE_LITTLE_ENDIAN)
          must_swap = 1;
#endif // ACE_LITTLE_ENDIAN

      for (size_t i = 0; i < length; ++i)
#if defined (ACE_DISABLE_SWAP_ON_READ)
        x[i] = static_cast <ACE_CDR::WChar> (sb[i]);
#else
      if (!must_swap)
        {
          x[i] = static_cast <ACE_CDR::WChar> (sb[i]);
        }
      else
        {
          ACE_CDR::UShort sx;
          ACE_CDR::swap_2 (&buf[i*2], reinterpret_cast <char *> (&sx));
          x[i] = static_cast <ACE_CDR::WChar> (sx);
        }
#endif /* ACE_DISABLE_SWAP_ON_READ */

      return 1;
    }
  return 0;
}
CmResult COFP13TableFeatureProp::DecodeMPTFP(ACE_InputCDR &is, COFP13TableFeatureProp * &prop)
{
    ACE_UINT16 type;
    bool bGood = is.pre_read(&type, sizeof(type));
    CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE);
    ACE_CDR::swap_2(reinterpret_cast<const char *>(&type), reinterpret_cast<char *>(&type));

    COFP13TableFeatureProp *propData = nullptr;
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("COFP13TableFeatureProp::DecodeMPTFP, type=%u\n"), type));

    switch (type)
    {
        case OFPTFPT_INSTRUCTIONS:
        case OFPTFPT_INSTRUCTIONS_MISS:
        {
            propData = new COFP13TableFeaturePropInstruct(type);
            break;
        }
        case OFPTFPT_EXPERIMENTER:
        case OFPTFPT_EXPERIMENTER_MISS:
        {
            propData = new COFP13TableFeaturePropExperimenter(type);
            break;
        }
        case OFPTFPT_NEXT_TABLES:
        case OFPTFPT_NEXT_TABLES_MISS:
        {
            propData = new COFP13TableFeaturePropNextTables(type);
        }
        case OFPTFPT_WRITE_ACTIONS:
        case OFPTFPT_WRITE_ACTIONS_MISS:
        case OFPTFPT_APPLY_ACTIONS:
        case OFPTFPT_APPLY_ACTIONS_MISS:
        {
            propData = new COFP13TableFeaturePropActions(type);
        }
        case OFPTFPT_MATCH:
        case OFPTFPT_WILDCARDS:
        case OFPTFPT_WRITE_SETFIELD:
        case OFPTFPT_WRITE_SETFIELD_MISS:
        case OFPTFPT_APPLY_SETFIELD:
        case OFPTFPT_APPLY_SETFIELD_MISS:
        {
            propData = new COFP13TableFeaturePropOXM(type);
        }
        default:
        {
            break;
        }
    }
    CM_ASSERT_RETURN(propData != nullptr, CM_ERROR_OUT_OF_MEMORY);

    CmResult rv = propData->StreamFrom(is);
    if (CM_FAILED(rv))
    {
        ACE_ERROR((LM_ERROR, ACE_TEXT("COFP13TableFeatureProp::DecodeMPTFP error\n")));
        return CM_ERROR_FAILURE;
    }

    prop = propData;

    return CM_OK;
}
Exemple #11
0
static int
short_stream (void)
{
  // counter
  u_int i;

  // Build an output stream
  ACE_OutputCDR os;

  // Basic types for output
  ACE_CDR::Char ch = 'A';
  ACE_CDR::Char wchtmp[] = {"\xF3"};
  ACE_CDR::WChar wch = *wchtmp;
  ACE_CString str ("Test String");
  ACE_CDR::Short s = -123;
  ACE_CDR::UShort us =  123;
  ACE_CDR::Long l = -65800L;
  ACE_CDR::ULong ul =  65800UL;
  ACE_CDR::Float f =  1.23f;
  ACE_CDR::Double d =  123.456789;

  // Arrays for output
  ACE_CDR::Short s_array[3] = { -1, 0, 1 };
  ACE_CDR::Long l_array[3] = { -345678, 0, 345678 };
  ACE_CDR::Float f_array[3] = { -1.23f, 0.0f, 1.23f };
  ACE_CDR::Double d_array[3] = { -123.456789, 0.0, 123.456789 };

  ACE_OutputCDR::from_char fc (ch);
  os << fc;
  ACE_OutputCDR::from_wchar fwc (wch);
  os << fwc;
  os << str;
  os << s;
  os << us;
  os << l;
  os << ul;
  os << f;
  os << d;
  os.write_short_array (s_array, 3);
  os.write_long_array (l_array, 3);
  os.write_float_array (f_array, 3);
  os.write_double_array (d_array, 3);

  const ACE_Message_Block *out_mb = os.begin ();
  u_int len = out_mb->length ();

  // Create an input stream (copy constructor)
  ACE_InputCDR is (os);
  const ACE_Message_Block *in_mb = is.start ();

  if (in_mb->length () != len)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("buffer length not preserved")),
                      1);

  u_long in_chunk, out_chunk;

  for (i = 0; i < len; i++)
    {
      in_chunk = u_long (* (in_mb->rd_ptr () + i));
      out_chunk = u_long (* (out_mb->rd_ptr () + i));
      if (in_chunk != out_chunk )
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("%p\n"),
                           ACE_TEXT ("buffer contents not preserved")),
                          1);
    }

  // Basic types for input
  ACE_CDR::Char ch1 = '\0';
  ACE_CDR::WChar wch1 = '\x00';
  ACE_CString str1;
  ACE_CDR::Short s1 = 0;
  ACE_CDR::UShort us1 = 0;
  ACE_CDR::Long l1 = 0L;
  ACE_CDR::ULong ul1 = 0UL;
  ACE_CDR::Float f1 = 0.0f;
  ACE_CDR::Double d1 = 0.0;

  // Arrays for input
  ACE_CDR::Short s_array1[3];
  ACE_CDR::Long l_array1[3];
  ACE_CDR::Float f_array1[3];
  ACE_CDR::Double d_array1[3];

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Checking operators and arrays\n\n")));

  ACE_InputCDR::to_char tc (ch1);
  is >> tc;
  ACE_InputCDR::to_wchar twc (wch1);
  is >> twc;
  is >> str1;
  is >> s1;
  is >> us1;
  is >> l1;
  is >> ul1;
  is >> f1;
  is >> d1;
  is.read_short_array (s_array1, 3);
  is.read_long_array (l_array1, 3);
  is.read_float_array (f_array1, 3);
  is.read_double_array (d_array1, 3);

  if (ch1 != ch)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("char transfer error")),
                      1);

  if (wch1 != wch)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("wchar transfer error")),
                      1);

  if (str1 != str)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("string transfer error")),
                      1);

  if (s1 != s)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("short transfer error")),
                      1);

  if (us1 != us)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("ushort transfer error")),
                      1);

  if (l1 != l)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("long transfer error")),
                      1);

  if (ul1 != ul)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("ulong transfer error")),
                      1);

  if (f1 != f)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("float transfer error")),
                      1);

  if (d1 != d)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("double transfer error")),
                      1);

  for (i = 0 ; i < 3; i++)
    if (s_array1[i] != s_array[i])
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%p\n"),
                         ACE_TEXT ("short array transfer error")),
                        1);

  for (i = 0 ; i < 3; i++)
    if (l_array1[i] != l_array[i])
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%p\n"),
                         ACE_TEXT ("long array transfer error")),
                        1);

  for (i = 0 ; i < 3; i++)
    if (f_array1[i] != f_array[i])
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%p\n"),
                         ACE_TEXT ("float array transfer error")),
                        1);

  for (i = 0 ; i < 3; i++)
    if (d_array1[i] != d_array[i])
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%p\n"),
                         ACE_TEXT ("double array transfer error")),
                        1);

  return 0;
}
Exemple #12
0
int
main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("CDR_Test"));

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This is ACE Version %u.%u.%u\n\n"),
              ACE::major_version (),
              ACE::minor_version(),
              ACE::beta_version()));

  ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("dn:l:"));
  int opt;
  int debug = 0;

  while ((opt = get_opt ()) != EOF)
    {
      switch (opt)
        {
          case 'd':
            debug++;
            break;
          case 'n':
            n = ACE_OS::atoi (get_opt.optarg);
            break;
          case 'l':
            nloops = ACE_OS::atoi (get_opt.optarg);
            break;
          case '?':
          default:
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("Usage: %s ")
                        ACE_TEXT ("-d debug")
                        ACE_TEXT ("-n <num> ")
                        ACE_TEXT ("-l <loops> ")
                        ACE_TEXT ("\n"),
                        argv[0]));
            return -1;
        }
    }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Testing ACE CDR functions - short stream\n\n")));

  if (short_stream () != 0 )
    return 1;

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Short stream - no errors\n\n")
              ACE_TEXT ("Testing basic types - long stream\n\n")));

  for (int i = 0; i < nloops; ++i)
    {
      ACE_OutputCDR output;
      CDR_Test_Types test_types;

      if (test_types.test_put (output) != 0)
        return 1;

      ACE_InputCDR input (output);
      if (debug > 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("Output CDR: \n")));
          ACE_HEX_DUMP ((LM_DEBUG,
                         input.rd_ptr(),
                         64));
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("Input CDR: \n")));
          ACE_HEX_DUMP ((LM_DEBUG,
                         input.rd_ptr(),
                         64));
        }

      if (test_types.test_get (input) != 0)
        return 1;
    }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Long stream - no errors\n\n")
              ACE_TEXT ("Testing basic types - long stream[2]\n\n")));

  for (int j = 0; j < nloops; ++j)
    {
      ACE_OutputCDR output;
      CDR_Test_Types test_types;

      if (test_types.test_put (output) != 0)
        return 1;

      ACE_InputCDR input (output.begin ());
      if (debug > 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("Output CDR: \n")));
          ACE_HEX_DUMP ((LM_DEBUG,
                         input.rd_ptr(),
                         64));
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("Input CDR: \n")));
          ACE_HEX_DUMP ((LM_DEBUG,
                         input.rd_ptr(),
                         64));
        }

      if (test_types.test_get (input) != 0)
        return 1;
    }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Long stream[2] - no errors\n\n")));

  ACE_END_TEST;
  return 0;
}
Exemple #13
0
int
CDR_Test_Types::test_get (ACE_InputCDR &cdr) const
{
  ACE_CDR::Octet xo;
  ACE_CDR::Short xs;
  ACE_CDR::Long xl;

  for (int i = 0; i < n; ++i)
    {
      if (cdr.read_octet (xo) == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("read_octet[%d] failed\n"),
                           i),
                          1);
      if (xo != this->o)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("octet[%d] differs\n"),
                           i),
                          1);
      if (cdr.read_short (xs) == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("read_short[%d] failed\n"),
                           i), 1);
      if (xs != this->s)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("short[%d] differs\n"),
                           i),
                          1);
      if (cdr.read_octet (xo) == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("read_octet-2[%d] failed\n"),
                           i),
                          1);
      if (xo != this->o)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("octet-2[%d] differs\n"),
                           i),
                          1);
      if (cdr.read_long (xl) == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("read_long[%d] failed\n"),
                           i),
                          1);
      if (xl != this->l)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("long[%d] differs\n"),
                           i),
                          1);
      if (cdr.read_long (xl) == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("read_long-2[%d] failed\n"),
                           i),
                          1);
      if (xl != this->l)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("long-2[%d] differs\n"),
                           i),
                          1);

      ACE_CDR::Char *xstr;
      if (cdr.read_string (xstr) == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("read_string2[%d] failed\n"),
                           i),
                          1);
      ACE_Auto_Basic_Array_Ptr<ACE_CDR::Char> auto_xstr (xstr);
      if (ACE_OS::strcmp (auto_xstr.get (), this->str) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("string[%d] differs\n"),
                           i),
                          1);
    }
  return 0;
}
void
UDPGenerator::handle_read_dgram (const ACE_Asynch_Read_Dgram::Result &result)
{
    ACE_DEBUG ((LM_DEBUG, "handle_read_dgram called\n"));

    ACE_DEBUG ((LM_DEBUG, "********************\n"));/*{{{*/
    ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_to_read", result.bytes_to_read ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "handle", result.handle ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_transfered", result.bytes_transferred ()));
    ACE_INET_Addr peerAddr;
    result.remote_address (peerAddr);
    ACE_DEBUG ((LM_DEBUG, "%s = %s:%d\n", "peer_address", peerAddr.get_host_addr (), peerAddr.get_port_number ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "flags", result.flags ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "act", result.act ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "success", result.success ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "completion_key", result.completion_key ()));
    ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "error", result.error ()));
    ACE_DEBUG ((LM_DEBUG, "********************\n"));/*}}}*/

    if (result.success () && result.bytes_transferred () != 0)
    {
        const ACE_Message_Block * msg = result.message_block();

        ACE_InputCDR cdr (msg->cont());

        ACE_CDR::Boolean byte_order;
        cdr >> ACE_InputCDR::to_boolean (byte_order);
        cdr.reset_byte_order(byte_order);
        ACE_CDR::ULong length;
        cdr >> length;

        ACE_InputCDR cdrpayload(msg->cont());
        cdrpayload.reset_byte_order(byte_order);
        DataGloveData glovedata;
        cdrpayload >> glovedata;

        // loop through our message block and print out the contents/*{{{*/
        //for (const ACE_Message_Block* msg = result.message_block(); msg != 0; msg = msg->cont ())
        //  { // use msg->length() to get the number of bytes written to the message
        // block.
        //if (msg->length() == 8)
        //{
        //    ACE_InputCDR cdr (msg);

        //    ACE_CDR::Boolean byte_order;
        //    cdr >> ACE_InputCDR::to_boolean (byte_order);
        //    cdr.reset_byte_order(byte_order);
        //    ACE_CDR::ULong length;
        //    cdr >> length;

        //    ACE_InputCDR cdrpayload(msg->cont());
        //    cdrpayload.reset_byte_order(byte_order);
        //    DataGloveData glovedata;
        //    cdrpayload >> glovedata;
        //    continue;
        //}
        //else
        //{
        //       ACE_DEBUG ((LM_DEBUG, "Buf=[size=<%d>", msg->length ()));
        //      for (u_long i = 0; i < msg->length(); ++i)
        //         ACE_DEBUG ((LM_DEBUG, "%c", (msg->rd_ptr())[i]));
        //    ACE_DEBUG ((LM_DEBUG, "]\n"));
        //}/*}}}*/
        //}
    }

    ACE_DEBUG ((LM_DEBUG, "Receive completed\n"));

    // No need for this message block anymore.
    result.message_block ()->release ();
    readdatagram(4);

    // Note that we are done with the test.
    done++;
}
Exemple #15
0
CmResult COFP10PacketOutMsg::StreamFrom(ACE_InputCDR &is)
{
    CmResult lRet = CM_ERROR_FAILURE;

    lRet = COFPMessage::StreamFrom(is);
    if (CM_FAILED(lRet))
    {
        ACE_ERROR((LM_ERROR, ACE_TEXT("COFP10PacketOutMsg::StreamFrom, COFPMessage::StreamFrom fail\n")));
        return lRet;
    }

    is>>m_tMember.buffer_id;
    is>>m_tMember.in_port;
    is>>m_tMember.actions_len;
    
    bool bGood = is.good_bit();
    CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE);

    if (m_tMember.actions_len > 0)
    {
        ACE_INT16 swListLen = m_tMember.actions_len;
        ACE_UINT16 i = 0;
        while (swListLen > 0)
        {
            COFP10Action *action = nullptr;
            lRet = COFP10Action::DecodeAction(is, action);
            if (CM_SUCCEEDED(lRet))
            {
                m_action_list.push_back(action);
                ACE_DEBUG((LM_DEBUG, ACE_TEXT("action[%u], len=%u\n"), i++, action->GetActionLen()));
                swListLen -= action->GetActionLen();
            }
            else
            {
                ACE_ERROR((LM_ERROR, ACE_TEXT("COFP10PacketOutMsg::StreamFrom, COFP10Action::DecodeAction failed\n")));
                return CM_ERROR_FAILURE;
            }
        }
    }

    ACE_INT16 swDataLen = m_wLength - COFPMessage::GetStreamLen() - sizeof(m_tMember) - m_tMember.actions_len;
    if (swDataLen < 0)
    {
        ACE_ERROR((LM_ERROR, 
                   ACE_TEXT("COFP10PacketOutMsg::StreamFrom, packet data len(%d) is invalid\n"), 
                   swDataLen));
        ACE_ASSERT(0);
        return CM_ERROR_FAILURE;
    }

    if (swDataLen == 0)
    {
        m_wDataLen = 0;
        return CM_OK;
    }

    ACE_Message_Block Data(swDataLen);

    ACE_DEBUG((LM_DEBUG, 
               ACE_TEXT("COFP10PacketOutMsg::StreamFrom, wr_ptr = %p, space = %u\n"), 
               Data.wr_ptr(),
               Data.space()));

    bGood = is.read_char_array(Data.wr_ptr(), swDataLen);
    CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE);

    Data.wr_ptr((size_t)swDataLen);
    
    if (m_PacketData)
    {
        m_PacketData->append(Data.duplicate());
    }
    else
    {
        m_PacketData = Data.duplicate();
    }
    m_wDataLen += swDataLen;

    return CM_OK;
}
Exemple #16
0
template<class T, class H> void
CDR_Test<T, H>::do_test (int total, int niter, int use_array,
                         char* srcbuf, char* dstbuf,
                         int src_offset, int dst_offset)
{
  if (!use_array)
    {
      dst_offset = src_offset = 0;
    }

  ACE_DEBUG((LM_DEBUG,
             ACE_TEXT( "Starting Test for %s: %d elements " )
             ACE_TEXT( "%susing arrays.\n" ),
             H::name (),
             total,
             ((use_array) ? ACE_TEXT( "" ) : ACE_TEXT( "not " ))));


  if (!use_array && (total % 4) != 0)
    {
      int lasttotal = total;
      total -= (total % 4);
      ACE_DEBUG((LM_DEBUG,
                 ACE_TEXT( "Rounding from %d to %d elements.\n" ),
                 lasttotal,
                 total));
    }

  char* src = ACE_ptr_align_binary(srcbuf, H::size ());
  T* idata = reinterpret_cast<T*> (src);
  idata += src_offset;
  src = reinterpret_cast<char*> (idata);

  {
    int i;
    for (i = 0; i < total; i++)
      {
        idata[i] = CDR_Test<T, H>::checkval (i);
      }
  }

  ACE_DEBUG((LM_DEBUG,
             ACE_TEXT( "Writing data...\n" )));

  char* toread = 0;
  {
    ACE_TEST_ASSERT(use_array || total % 4 == 0);

    double totalsecs = 0.0;
    int n;
    for (n = 0; n < niter; n++)
      {
        size_t size = H::size () * (dst_offset + total) +
                      ACE_CDR::MAX_ALIGNMENT;
        ACE_OutputCDR os (dstbuf, size);

        // This is intrusive...
        char* const end = os.begin ()->wr_ptr() + size;

        do_seal (end);

        double secs = 0.0;
        if (use_array)
          {
            {
              int i;
              for (i = 0; i < dst_offset; i++)
                {
                  os << T(0);
                }
            }

            if (n == 0)
              {
                ACE_DEBUG((LM_DEBUG,
                           ACE_TEXT ("* src align = %d, dst align = %d\n"),
                           tellalign (src),
                           tellalign (os.begin ()->wr_ptr ())));
              }

            Crono crono;
            crono.start ();
            H::write_array (os, idata, total);
            crono.stop ();
            secs = crono.read_seconds ();
          }
        else
          {
            int i = 0;
            for (; i < dst_offset; i++)
              {
                os << T(0);
              }
            i = 0;

            Crono crono;
            crono.start();
            while (i < total)
              {
                os << idata[i++];
                os << idata[i++];
                os << idata[i++];
                os << idata[i++];
                // static char rs[32 + 1];
                // CDR_Test<T,H>::ttoh (idata[i], rs);
                // ACE_DEBUG ((LM_DEBUG, "Write idata[%d] = %s\n", i, rs));
                // os << idata[i];
                // i++;
              }
            crono.stop ();
            secs = crono.read_seconds ();
          }

        if (!check_seal(end))
          {
            ACE_ERROR((LM_ERROR,
                       ACE_TEXT( "Broken seal, aborting.\n" )));
            ACE_OS::exit(1);
          }

        totalsecs += secs;

        if (n == niter - 1)
          {
            toread = os.begin ()->rd_ptr ();
          }
      }

    totalsecs = totalsecs / niter;

    ACE_DEBUG((LM_DEBUG,
               ACE_TEXT ("Writing to stream %d %s values: %f seconds.\n"),
               total,
               H::name (),
               totalsecs));
  }

  {
    int i;
    for (i = 0; i < total; i++)
      {
        idata[i] = 0;
      }
  }

  ACE_DEBUG((LM_DEBUG,
             ACE_TEXT( "Reading them back in opposing byte order...\n" )));

  const int opposite_byte_order = 1 - ACE_CDR_BYTE_ORDER;

  {
    double totalsecs = 0.0;
    int n;
    for (n = 0; n < niter; n++)
      {
        ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("====== Read iteration %d\n"), n));

        size_t size = (total + dst_offset) * H::size ();
        ACE_InputCDR is (toread, size, opposite_byte_order);

        // This is intrusive...
        char* const end = is.rd_ptr () + size;

        do_seal (end);

        double secs = 0.0;
        if (use_array)
          {
            {
              int i;
              for (i = 0; i < dst_offset; i++)
                {
                  T v;
                  is >> v;
                }
            }

            if (n == 0)
              {
                ACE_DEBUG((LM_DEBUG,
                           ACE_TEXT ("* src align = %d, dst align = %d\n"),
                           tellalign (is.rd_ptr ()),
                           tellalign (src)));
              }

            Crono crono;
            crono.start ();
            H::read_array (is, idata, total);
            crono.stop ();
            secs = crono.read_seconds ();

            // Testing for good bit value. Try reading atleast 10
            // times the size of total. It should fail with good bit
            // set to 0.
            H::read_array (is, idata, 10 * total);

            if (is.good_bit () != 0)
              {
                ACE_ERROR ((LM_ERROR,
                            ACE_TEXT ("Test for good bit failed in %s Array_test\n"),
                            H::name ()));
              }
          }
        else
          {
            int i = 0;
            Crono crono;
            crono.start ();
            while (i < total)
              {
#if 0
                T v;
                is >> v;
                static char rs[32 + 1];
                CDR_Test<T,H>::ttoh (v, rs);
                ACE_DEBUG ((LM_DEBUG, "Read idata[%d] = %s\n", i, rs));
                idata[i] = v;
                i++;
#else
                is >> idata[i++];
                is >> idata[i++];
                is >> idata[i++];
                is >> idata[i++];
#endif /* 0 */
              }
            crono.stop ();
            secs = crono.read_seconds ();
          }
        totalsecs += secs;

        if (!check_seal (end))
          {
            ACE_ERROR((LM_ERROR,
                       ACE_TEXT( "Broken seal, aborting.\n" )));
            ACE_OS::exit(1);
          }
      }

    totalsecs = totalsecs / niter;

    ACE_DEBUG((LM_DEBUG,
               ACE_TEXT ("Reading from stream %d %s values")
               ACE_TEXT (" (byte swapping): %f seconds.\n"),
               total,
               H::name (),
               totalsecs));
  }
Exemple #17
0
  virtual int svc () {
    const size_t FileReadSize = 8 * 1024;
    ACE_Message_Block mblk (FileReadSize);

    for (;; mblk.crunch ()) {
      // Read as much as will fit in the message block.
      ssize_t bytes_read = logfile_.recv (mblk.wr_ptr (),
                                          mblk.space ());
      if (bytes_read <= 0)
        break;
      mblk.wr_ptr (static_cast<size_t> (bytes_read));

      // We have a bunch of data from the log file. The data is
      // arranged like so:
      //    hostname\0
      //    CDR-encoded log record
      // So, first we scan for the end of the host name, then
      // initialize another ACE_Message_Block aligned for CDR
      // demarshaling and copy the remainder of the block into it. We
      // can't use duplicate() because we need to be sure the data
      // pointer is aligned properly for CDR demarshaling.  If at any
      // point, there's not enough data left in the message block to
      // extract what's needed, crunch the block to move all remaining
      // data to the beginning and read more from the file.
      for (;;) {
        size_t name_len = ACE_OS::strnlen
                             (mblk.rd_ptr (), mblk.length ());
        if (name_len == mblk.length ()) break;

        char *name_p = mblk.rd_ptr ();
        ACE_Message_Block *rec, *head, *temp;
        ACE_NEW_RETURN
          (head, ACE_Message_Block (name_len, MB_CLIENT), 0);
        head->copy (name_p, name_len);
        mblk.rd_ptr (name_len + 1);   // Skip nul also

        size_t need = mblk.length () + ACE_CDR::MAX_ALIGNMENT;
        ACE_NEW_RETURN (rec, ACE_Message_Block (need), 0);
        ACE_CDR::mb_align (rec);
        rec->copy (mblk.rd_ptr (), mblk.length ());

        // Now rec contains the remaining data we've read so far from
        // the file. Create an ACE_InputCDR to start demarshaling the
        // log record, header first to find the length, then the data.
        // Since the ACE_InputCDR constructor increases the reference count
        // on rec, we release it upon return to prevent leaks.
        // The cdr 'read' methods return 0 on failure, 1 on success.
        ACE_InputCDR cdr (rec); rec->release ();
        ACE_CDR::Boolean byte_order;
        if (!cdr.read_boolean (byte_order)) {
          head->release (); rec->release (); break;
        }
        cdr.reset_byte_order (byte_order);

        // Now read the length of the record. From there, we'll know
        // if rec contains the complete record or not.
        ACE_CDR::ULong length;
        if (!cdr.read_ulong (length)) {
          head->release (); mblk.rd_ptr (name_p); break;
        }
        if (length > cdr.length ()) {
          head->release (); mblk.rd_ptr (name_p); break;
        }

        // The complete record is in rec... grab all the fields into
        // separate, chained message blocks.
        ACE_NEW_RETURN (temp,
                        ACE_Message_Block (length, MB_TEXT),
                        0);
        ACE_NEW_RETURN
          (temp,
           ACE_Message_Block (2 * sizeof (ACE_CDR::Long),
                              MB_TIME, temp),
           0);
        ACE_NEW_RETURN
          (temp,
           ACE_Message_Block (sizeof (ACE_CDR::Long),
                              MB_PID, temp),
           0);
        ACE_NEW_RETURN
          (temp,
           ACE_Message_Block (sizeof (ACE_CDR::Long),
                              MB_TYPE, temp),
           0);
        head->cont (temp);

        // Extract the type
        ACE_CDR::Long *lp;
        lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ());
        cdr >> *lp;
        temp->wr_ptr (sizeof (ACE_CDR::Long));
        temp = temp->cont ();

        // Extract the pid
        lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ());
        cdr >> *lp;
        temp->wr_ptr (sizeof (ACE_CDR::Long));
        temp = temp->cont ();

        // Extract the timestamp (2 Longs)
        lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ());
        cdr >> *lp; ++lp; cdr >> *lp;
        temp->wr_ptr (2 * sizeof (ACE_CDR::Long));
        temp = temp->cont ();

        // Demarshal the length of the message text, then demarshal
        // the text into the block.
        ACE_CDR::ULong text_len;
        cdr >> text_len;
        cdr.read_char_array (temp->wr_ptr (), text_len);
        temp->wr_ptr (text_len);

        // Forward the whole lot to the next module.
        if (put_next (head) == -1) break;

        // Move the file-content block's read pointer up past whatever
        // was just processed. Although the mblk's rd_ptr has not been
        // moved, cdr's has.  Therefore, use its length() to determine
        // how much is left.
        mblk.rd_ptr (mblk.length () - cdr.length ());
      }
    }

    // Now that the file is done, send a block down the stream to tell
    // the other modules to stop.
    ACE_Message_Block *stop;
    ACE_NEW_RETURN
      (stop, ACE_Message_Block (0, ACE_Message_Block::MB_STOP),
       0);
    put_next (stop);
    return 0;
  }
Exemple #18
0
CmResult COFP13HelloMsg::StreamFrom(ACE_InputCDR &is)
{
    CmResult lRet = CM_ERROR_FAILURE;
    ACE_UINT16 i = 0;
    bool bGood;

    lRet = COFPMessage::StreamFrom(is);
    if (CM_FAILED(lRet))
    {
        ACE_ERROR((LM_ERROR, ACE_TEXT("COFP13HelloMsg::StreamFrom(), COFPMessage::StreamFrom fail\n")));
        return lRet;
    }
    
    if (m_wLength < COFPMessage::GetStreamLen())
    {
        ACE_ERROR((LM_ERROR, 
                   ACE_TEXT("COFP13HelloMsg::StreamFrom(): "),
                   ACE_TEXT("m_wLength(%u) is less than COFPMessage::GetStreamLen()(%u).\n"), 
                   m_wLength,
                   COFPMessage::GetStreamLen()));
        return CM_ERROR_FAILURE;
    }

    ACE_UINT16 wElemListLen = m_wLength - COFPMessage::GetStreamLen();
    ACE_UINT16 data_size    = wElemListLen;
    ACE_UINT16 iter_size    = 0;
    ACE_CDR::Octet  *pElem        = m_pElemList;

    while (iter_size < wElemListLen)
    {
        ACE_UINT16 elem_type = 0;
        ACE_UINT16 elem_size = 0;  // length of the element, excluding paddings
        
        is>>elem_type;
        is>>elem_size;
        
        bGood = is.good_bit();
        CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE);
        
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("COFP13HelloMsg::StreamFrom(): parse hello elem %u.\n"), i++));
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("elem_type=%u, elem_size=%u\n"), elem_type, elem_size));

        SetHelloElemType(pElem, elem_type);
        SetHelloElemLen(pElem, elem_size);
        
        if (elem_size < 4)
        {
            ACE_ERROR((LM_ERROR, 
                       ACE_TEXT("COFP13HelloMsg::StreamFrom(): elem_size(%u) error, less than 4.\n"),
                       elem_size));
            return CM_ERROR_FAILURE;
        }

        if (((elem_size + 7)/8*8) > data_size)
        {
            ACE_ERROR((LM_ERROR, 
                       ACE_TEXT("COFP13HelloMsg::StreamFrom(): "),
                       ACE_TEXT("((elem_size + 7)/8*8)=%u, greater than data_size(%u)\n"),
                       ((elem_size + 7)/8*8),
                       data_size));
            return CM_ERROR_FAILURE;
        }
        
        if (elem_type != OFPHET_VERSIONBITMAP)
        {
            ACE_ERROR((LM_ERROR, 
                       ACE_TEXT("COFP13HelloMsg::StreamFrom(): elem_type(%u) isnot OFPHET_VERSIONBITMAP(%u)\n"),
                       elem_type,
                       OFPHET_VERSIONBITMAP));
            return CM_ERROR_FAILURE;
        }

        ACE_UINT16 bitmap_size      = elem_size-4;
        CM_ASSERT_RETURN((bitmap_size/4*4 == bitmap_size), CM_ERROR_INVALID_ARG);
        
        ACE_UINT16 iter_bitmap_size = 0;
        ACE_UINT16 bitmap_index     = 0;

        while (iter_bitmap_size < bitmap_size)//(bitmap_size > 0)
        {
            ACE_UINT32 bitmap = 0;
            is>>bitmap;
            bGood = is.good_bit();
            CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE);
            ACE_DEBUG((LM_DEBUG, ACE_TEXT("bitmap[%u]=%u\n"), bitmap_index, bitmap));

            SetVerBMHelloElemBitmap(pElem, bitmap_index++, bitmap);
            //bitmap_size -= sizeof(bitmap);
            iter_bitmap_size += sizeof(bitmap);
        }

        // deal with paddings
        ACE_UINT16 pad_size = (elem_size + 7)/8*8 - elem_size;
        is.read_octet_array(pElem + 4 + bitmap_index * sizeof(ACE_UINT32), pad_size);
        bGood = is.good_bit();
        CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE);
        
        data_size      -= (elem_size + pad_size);
        iter_size      += (elem_size + pad_size);
        pElem          += (elem_size + pad_size);
        m_wElemListLen += (elem_size + pad_size);
    }

    return CM_OK;
}
Exemple #19
0
CmResult COFP13PacketOutMsg::StreamFrom(ACE_InputCDR &is)
{
    ACE_INT32 remainActLen = 0;
    ACE_INT32 packet_length = 0;
    ACE_CDR::Octet pad[6];
    CmResult lRet = CM_ERROR_FAILURE;
    
    lRet = COFPMessage::StreamFrom(is);
    if (CM_FAILED(lRet))
    {
        ACE_ERROR((LM_ERROR, ACE_TEXT("COFP13PacketOutMsg::StreamFrom(), COFPMessage::StreamFrom fail\n")));
        return lRet;
    }

    ACE_DEBUG((LM_DEBUG, ACE_TEXT("COFP13PacketOutMsg::StreamFrom(): \n")));
    
    is>>m_buffer_id;
    is>>m_in_port;
    is>>m_actions_len;
    is.read_octet_array(pad, sizeof(pad));
    
    bool bGood = is.good_bit();
    CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE);

    ACE_DEBUG((LM_DEBUG, ACE_TEXT("m_actions_len=%u\n"), m_actions_len));
    
    if (m_actions_len>0)
    {
        remainActLen = m_actions_len;
        ACE_UINT16 i = 0;
        while (remainActLen > 0)
        {
            COFP13Action *action = nullptr;
            CmResult result = COFP13Action::DecodeAction(is, action);
            if (CM_SUCCEEDED(result))
            {
                m_action_list.push_back(action);
                ACE_DEBUG((LM_DEBUG, ACE_TEXT("action[%u], len=%u\n"), i++, action->GetStreamLen()));
                remainActLen = remainActLen - (action->GetStreamLen());
            }
            else
            {
                ACE_ERROR((LM_ERROR, ACE_TEXT("COFP13Action::DecodeAction failed.\n")));
                return CM_ERROR_FAILURE;
            }
        }
    }

    ACE_UINT32 length = sizeof(m_buffer_id)+sizeof(m_in_port)+sizeof(m_actions_len)+sizeof(m_pad);
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("length=%u\n"), length));

    packet_length = m_wLength-COFPMessage::GetStreamLen()-length-m_actions_len;
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("packet_length=%d, GetStreamLen=%u\n"), packet_length, GetStreamLen()));
    if (packet_length < 0)
    {
        ACE_ERROR((LM_ERROR, 
                   ACE_TEXT("COFP13PacketOutMsg::StreamFrom, error, length=%u, actionlength=%u\n"), 
                   length, 
                   m_actions_len));
        return CM_ERROR_FAILURE;
    }

    ACE_Message_Block data(packet_length);

    ACE_DEBUG((LM_DEBUG, 
               ACE_TEXT("COFP13PacketOutMsg::StreamFrom, wr_ptr=%p, space=%u\n"),
               data.wr_ptr(),
               data.space()));
    
    bGood = is.read_char_array(data.wr_ptr(), packet_length);
    CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE);

    data.wr_ptr((size_t)packet_length);
    
    if (m_PacketData)
    {
        m_PacketData->append(data.duplicate());
    }
    else
    {
        m_PacketData = data.duplicate();
    }

    return CM_OK;
}
Exemple #20
0
CmResult COFP10Action::
DecodeAction(ACE_InputCDR& is, COFP10Action * &apAction)
{
    CmResult      lRet  = CM_ERROR_FAILURE;
    ACE_UINT16    wType = 0;
    COFP10Action *pAct  = nullptr;
    
    bool bGood = is.pre_read(&wType, sizeof(wType));
    CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE);
    
	ACE_CDR::swap_2(reinterpret_cast<const char *>(&wType), reinterpret_cast<char *>(&wType));

    switch (wType)
    {
        case OFPAT_OUTPUT:
        {
            pAct = new COFP10ActOutput();
            break;
        }
        case OFPAT_SET_VLAN_VID:
        {
            pAct = new COFP10ActSetVlanVid();
            break;
        }
        case OFPAT_SET_VLAN_PCP:
        {
            pAct = new COFP10ActSetVlanPcp();
            break;
        }
        case OFPAT_STRIP_VLAN:
        {
            pAct = new COFP10ActStripVlan();
            break;
        }
        case OFPAT_SET_DL_SRC:
        case OFPAT_SET_DL_DST:
        {
            pAct = new COFP10ActSetDlAddr(wType);
            break;
        }
        case OFPAT_SET_NW_SRC:
        case OFPAT_SET_NW_DST:
        {
            pAct = new COFP10ActSetNwAddr(wType);
            break;
        }
        case OFPAT_SET_NW_TOS:
        {
            pAct = new COFP10ActSetNwTos();
            break;
        }
        case OFPAT_SET_TP_SRC:
        case OFPAT_SET_TP_DST:
        {
            pAct = new COFP10ActSetTpPort(wType);
            break;
        }
        case OFPAT_ENQUEUE:
        {
            pAct = new COFP10ActEnqueue();
            break;
        }
        default:
        {
            break;
        }
    }
    
    CM_ASSERT_RETURN(pAct != nullptr, CM_ERROR_OUT_OF_MEMORY);

    lRet = pAct->StreamFrom(is);
    if (CM_FAILED(lRet))
    {
        ACE_ERROR((LM_ERROR, ACE_TEXT("COFP10Action::DecodeAction(): fail in StreamFrom(), lRet=%d\n"), lRet));
        return lRet;
    }

    apAction = pAct;
    
    return CM_OK;
}