extern "C" { #include } #include "ArtsCflowdCustomData.hh" //------------------------------------------------------------------------- // ArtsCflowdCustomDataKey::ArtsCflowdCustomDataKey(uint32_t index) //......................................................................... // //------------------------------------------------------------------------- ArtsCflowdCustomDataKey::ArtsCflowdCustomDataKey(uint32_t index) { this->_index = index; this->_value = (caddr_t)calloc(this->KeyLength(),1); assert(this->_value != (caddr_t)0); } //---------------------------------------------------------------------------- // ArtsCflowdCustomDataKey:: // ArtsCflowdCustomDataKey(const ArtsCflowdCustomDataKey & key) //............................................................................ // //---------------------------------------------------------------------------- ArtsCflowdCustomDataKey:: ArtsCflowdCustomDataKey(const ArtsCflowdCustomDataKey & key) { this->_index = key.Index(); this->_value = (caddr_t)calloc(this->KeyLength(),1); assert(this->_value != (caddr_t)0); memcpy(this->_value,key._value,this->KeyLength()); } //------------------------------------------------------------------------- // uint32_t ArtsCflowdCustomDataKey::FieldOffset(uint32_t fieldBit) const //......................................................................... // //------------------------------------------------------------------------- uint32_t ArtsCflowdCustomDataKey::FieldOffset(uint32_t fieldBit) const { assert((this->_index & (((uint32_t)1) << fieldBit)) != 0); uint32_t offset = 0; uint32_t bit; uint32_t bitMask; for (bit = 0; bit < fieldBit; bit++) { if ((((uint32_t)1) << bit) & this->_index) { offset += this->k_fieldSizes[bit]; } } return(offset); } //------------------------------------------------------------------------- // uint8_t ArtsCflowdCustomDataKey::KeyLength() const //......................................................................... // //------------------------------------------------------------------------- uint8_t ArtsCflowdCustomDataKey::KeyLength() const { uint8_t length = 0; for (uint32_t bit = 0; bit < k_maxBit; bit++) { if ((((uint32_t)1) << bit) & this->_index) { length += ArtsCflowdCustomDataKey::k_fieldSizes[bit]; } } return(length); } //---------------------------------------------------------------------------- // uint8_t ArtsCflowdCustomDataKey::IndexLength() const //............................................................................ // //---------------------------------------------------------------------------- uint8_t ArtsCflowdCustomDataKey::IndexLength() const { uint8_t length = 0; for (uint8_t bit = 0; bit < k_maxBit; bit++) { if ((((uint32_t)1) << bit) & this->_index) { length = bit + 1; } } return(length); } //---------------------------------------------------------------------------- // bool ArtsCflowdCustomDataKey:: // operator < (const ArtsCflowdCustomDataKey & key) const //............................................................................ // //---------------------------------------------------------------------------- bool ArtsCflowdCustomDataKey:: operator < (const ArtsCflowdCustomDataKey & key) const { bool rc = false; if (this->_index < key.Index()) { rc = true; } else { if (this->_index > key.Index()) { rc = false; } else { for (uint32_t bit = 0; bit <= this->IndexLength(); bit++) { if ((((uint32_t)1) << bit) & this->_index) { int compareResult = memcmp(&(this->_value[FieldOffset(bit)]), &(key._value[FieldOffset(bit)]), this->KeyLength()); if (compareResult < 0) { rc = true; break; } else { if (compareResult > 0) { rc = false; break; } } } } } } return(rc); } const uint8_t ArtsCflowdCustomDataKey::k_fieldSizes[ArtsCflowdCustomDataKey::k_maxBit + 1] = { 4, // router IP address 4, // source IP address 4, // destination IP address 2, // input ifIndex 2, // output ifIndex 2, // source port 2, // destination port 4, // IP nexthop 1, // IP protocol 1, // IP TOS 2, // source AS 2, // destination AS 1, // source netmask length 1, // destination netmask length 1, // TCP flags 1, // flow engine type 1 // flow engine ID };