Parent: [6ccca6] (diff)

Download this file

PDU.cc    128 lines (119 with data), 4.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// The MIT License (MIT)
//
// Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/**
* @file PDU.cc
* @author Marcel Marek (imarek@fit.vutbr.cz)
* @date Apr 30, 2014
* @brief
* @detail
*/
#include <PDU.h>
Register_Class(PDU);
//void PDU::addUserData(const unsigned char* userData, unsigned int size, bool *fragment){
//
// if(userData_arraysize == 0){
// userData_var= new unsigned char[size];
// memcpy(userData_var, userData, size);
// *fragment = false;
//
//
// }else{
//
// if(*fragment){
//// if(pduLen_var - PDU_HEADER_LEN == userData_arraysize){
// //allocate new space
// unsigned char * tmp = new unsigned char[userData_arraysize + SDU_FRAG_LEN];
// //put size of the exising segment/SDU in the PDU
// tmp[0] = userData_arraysize & 0xFF;
// tmp[1] = (userData_arraysize << 8) & 0xFF;
// //update size of the userData array
// userData_arraysize += SDU_FRAG_LEN;
// //copy existing data
// memcpy(&tmp[SDU_FRAG_LEN], userData_var, userData_arraysize);
//
// delete [] userData_var;
// //assign pointer
// userData_var = tmp;
//
// *fragment = true;
// }
//
// //allocate new space
// unsigned char * tmp = new unsigned char [size + this->userData_arraysize + SDU_FRAG_LEN];
// //put size of the exising segment/SDU in the PDU
// tmp[this->userData_arraysize] = size & 0xFF;
// tmp[this->userData_arraysize +1 ] = (size << 8) & 0xFF;
// this->userData_arraysize += SDU_FRAG_LEN;
// //copy existing data
// memcpy(tmp, this->userData_var, this->userData_arraysize);
// //copy new data
// memcpy(&tmp[this->userData_arraysize], userData, size);
// delete [] this->userData_var;
// this->userData_var = tmp;
//
// }
//
// this->userData_arraysize += size;
//
// pduLen_var = PDU_HEADER_LEN + userData_arraysize;
//
//}
/*
* @param sduSeqNum is unused for the moment because its usage is not clear to me (yet)
*/
//void PDU::putDelimitFlags(int delimitFlags, bool fragment, int sduSeqNum){
// //TODO B2 Incorporate size of the delimiter flag field into process of delimiting SDUs/PDUs
// if(sduSeqNum != -1){
// //SDU Sequence Number present
//
// //TODO B2 add support for SDU Seq Number
// }
//
// flags_var |= 0x08 & (sduSeqNum == -1) ? 0x00: 0xFF;
// flags_var |= delimitFlags;
//
//
// unsigned char * tmp = new unsigned char[userData_arraysize + SDU_DELIMITER_FLAG_LEN];
// //put size of the exising segment/SDU in the PDU
// tmp[0] = 0x08 & (sduSeqNum == -1) ? 0x00: 0xFF;
// tmp[0] |= delimitFlags;
//
// //update size of the userData array
// userData_arraysize += SDU_DELIMITER_FLAG_LEN;
// //copy existing data
// memcpy(&tmp[SDU_DELIMITER_FLAG_LEN], userData_var, userData_arraysize);
//
// delete [] userData_var;
// //assign pointer
// userData_var = tmp;
//}
unsigned int PDU::getHeaderSize(){
return PDU_HEADER_LEN;
}
unsigned int PDU::getSize(){
return getPduLen() + getHeaderSize();
}
//std::string PDU::info() const {
// std::stringstream os;
// os << "srcAddr: " << srcAddr_var;
// return os.str();
//}