McRouteActivationFrame.cpp
Go to the documentation of this file.
00001 /* 
00002  * File:   McRouteActivationFrame.cpp
00003  * Author: cwioro
00004  * 
00005  * Created on August 27, 2014, 12:20 PM
00006  */
00007 
00008 #include "McRouteActivationFrame.h"
00009 
00010 McRouteActivationFrame::McRouteActivationFrame(unsigned char* next_hop, std::string mc_g, uint32_t route_id, std::string source)
00011 {
00012     memcpy(header_.mac_destination, next_hop, 6);
00013     this->header_.frame_type = FRAME_TYPE_MC_ACTIVATION;
00014     this->mc_group_ = mc_g;
00015     this->header_.route_id = route_id;
00016     this->hostname_source_ = source;
00017     this->header_.id = McRouteActivationFrame::stat_id_count++;
00018 }
00019 
00020 McRouteActivationFrame::McRouteActivationFrame(unsigned char* buffer)
00021 {
00022 
00023 
00024     unsigned char* buffer_start = buffer;
00025 
00026     eh_header* eh = (struct eh_header *) buffer;
00027     buffer += sizeof (eh_header);
00028     mc_act_header* rfh = (struct mc_act_header *) buffer;
00029     buffer += sizeof (mc_act_header);
00030 
00031 
00032        /*hostname source*/
00033     hostname_source_ = "";
00034     if (rfh->hostname_source_len > 0)
00035         hostname_source_.append((const char*) buffer, rfh->hostname_source_len);
00036     buffer += rfh->hostname_source_len;
00037 
00038     /*group name*/
00039     mc_group_ = "";
00040     if (rfh->mc_group_name_len > 0)
00041         mc_group_.append((const char*) buffer, rfh->mc_group_name_len);
00042     buffer += rfh->mc_group_name_len;
00043 
00044 
00045     /*CRC */
00046     uint32_t crc = 0;
00047     memcpy((unsigned char*) &crc, (unsigned char*) buffer, 4); // get CRC
00048 
00049     std::string crc_data_string = "";
00050     uint32_t dynamic_field_len = rfh->mc_group_name_len +rfh->hostname_source_len;
00051     crc_data_string.append((const char*) buffer_start,
00052                            this->HEADER_FIXED_LEN + dynamic_field_len);
00053     correct_crc_ = (crc == (uint32_t) GetCrc32(crc_data_string));
00054 
00055 
00056     buffer_str_len_ = this->HEADER_FIXED_LEN + dynamic_field_len + sizeof (crc);
00057 
00058 
00059 
00060     /* COPY HEADER FIELDS */
00061     memcpy(&this->eh_h_, &(*eh), sizeof (eh_header));
00062     memcpy(&this->header_, &(*rfh), sizeof (mc_act_header));
00063 
00064 
00065 
00066 
00067 }
00068 
00069 std::string McRouteActivationFrame::getFrameAsNetworkString(unsigned char source_mac[6])
00070 {
00071     memcpy(this->eh_h_.eh_source, source_mac, ETH_ALEN);
00072     memcpy(this->eh_h_.eh_dest, bcast_mac, ETH_ALEN);
00073 
00074 
00075     /*LEN FIELD */
00076     this->header_.mc_group_name_len = mc_group_.length();
00077     this->header_.hostname_source_len = hostname_source_.length();
00078 
00079     unsigned char a_char[ETHER_MAX_LEN];
00080     unsigned char* buffer = a_char;
00081     unsigned char* buffer_start = a_char;
00082 
00083     /*ETHERNET FIELDS*/
00084     memcpy(buffer, &this->eh_h_, sizeof (eh_header));
00085     buffer += sizeof (eh_header);
00086 
00087     /*FIXED RF HEADER FIELDS*/
00088     memcpy(buffer, &this->header_, sizeof (mc_act_header));
00089     buffer += sizeof (mc_act_header);
00090 
00091  /*HOST SRC HOST */
00092     memcpy(buffer, this->hostname_source_.data(),this->mc_group_.length());
00093     buffer += this->hostname_source_.length();
00094 
00095 
00096     /*MC GROUP HOST */
00097     memcpy(buffer, this->mc_group_.data(),
00098            this->mc_group_.length());
00099     buffer += this->mc_group_.length();
00100     
00101     
00102 
00103     /*CRC*/
00104     int dynamic_field_len = this->mc_group_.length()+ this->hostname_source_.length();
00105     std::string crc_string = std::string((const char*) buffer_start, this->HEADER_FIXED_LEN + dynamic_field_len);
00106     uint32_t crc = GetCrc32(crc_string);
00107     memcpy(buffer, &crc, sizeof (uint32_t));
00108     buffer += sizeof (uint32_t);
00109 
00110 
00111 
00112     return std::string((const char*) buffer_start, this->HEADER_FIXED_LEN + dynamic_field_len + sizeof (crc));
00113 
00114 }
00115 
00116 McRouteActivationFrame::~McRouteActivationFrame()
00117 {
00118 }
00119 


adhoc_communication
Author(s): Guenter Cwioro , Torsten Andre
autogenerated on Thu Aug 27 2015 11:56:40