diff options
author | 2016-11-23 10:32:25 +0200 | |
---|---|---|
committer | 2016-11-23 10:32:25 +0200 | |
commit | 5472a2937363370d8632bb0e53757bc66a0b2403 (patch) | |
tree | 62ce490e03aa83886d0b78c9299173e4784d958e /src/common | |
parent | fc35e10dc4acd5149b465b8f1959aae941ff198e (diff) | |
parent | 31a4ef5afc56c5d6ff6870da71a954e4bcbee057 (diff) |
Merge branch 'master'
Signed-off-by: imarom <imarom@cisco.com>
Conflicts:
src/main_dpdk.cpp
Diffstat (limited to 'src/common')
-rwxr-xr-x | src/common/Network/Packet/MacAddress.h | 128 | ||||
-rwxr-xr-x | src/common/basic_utils.cpp | 7 | ||||
-rwxr-xr-x | src/common/basic_utils.h | 1 |
3 files changed, 86 insertions, 50 deletions
diff --git a/src/common/Network/Packet/MacAddress.h b/src/common/Network/Packet/MacAddress.h index 7e872fd6..5dc4a9ea 100755 --- a/src/common/Network/Packet/MacAddress.h +++ b/src/common/Network/Packet/MacAddress.h @@ -29,7 +29,7 @@ public: MacAddress() { - set(0xca, 0xfe, 0xde, 0xad, 0xbe, 0xef); + set(0xff, 0xff, 0xff, 0xff, 0xff, 0xff); }; MacAddress(uint8_t a0, @@ -47,15 +47,15 @@ public: a5); }; - MacAddress(uint8_t macAddr[ETHER_ADDR_LEN]) - { - set(macAddr[0], - macAddr[1], - macAddr[2], - macAddr[3], - macAddr[4], - macAddr[5] ); - }; + MacAddress(uint8_t macAddr[ETHER_ADDR_LEN]) + { + set(macAddr[0], + macAddr[1], + macAddr[2], + macAddr[3], + macAddr[4], + macAddr[5] ); + }; void set(uint8_t a0, uint8_t a1, @@ -81,50 +81,78 @@ public: data[5]=val; } + void set(uint64_t val) { + for (int i = 0; i < 6; i++) { + data[i] = ( val >> ((5 - i) * 8) ) & 0xFF; + } + } + + bool isDefaultAddress() const + { + static MacAddress defaultMac; + return (*this == defaultMac); + } + + bool isInvalidAddress() const + { + static MacAddress allZeros(0,0,0,0,0,0); + static MacAddress defaultMac; + return (*this == allZeros || *this == defaultMac); + } + void setIdentifierAsBogusAddr(uint32_t identifier) + { + *(uint32_t*)data = identifier; + } + + uint32_t getIdentifierFromBogusAddr() + { + return *(uint32_t*)data; + } + + MacAddress& operator+=(const int& val) { + uint64_t tmp = 0; + + for (int i = 0; i < 6; i++) { + tmp <<= 8; + tmp |= data[i]; + } - bool isInvalidAddress() const - { - static MacAddress allZeros(0,0,0,0,0,0); - static MacAddress cafeDeadBeef; - return (*this == allZeros || *this == cafeDeadBeef); - } - void setIdentifierAsBogusAddr(uint32_t identifier) - { - *(uint32_t*)data = identifier; - } - - uint32_t getIdentifierFromBogusAddr() - { - return *(uint32_t*)data; - } - - bool operator == (const MacAddress& rhs) const - { - for(int i = 0; i < ETHER_ADDR_LEN; i++) - { - if(data[i] != rhs.data[i]) - return false; - } - - return true; - } - - uint8_t* GetBuffer() - { - return data; - } - - const uint8_t* GetConstBuffer() const - { - return data; - } + tmp += val; + + for (int i = 0; i < 6; i++) { + data[i] = ( tmp >> ((5 - i) * 8) ) & 0xFF; + } + + return *this; + } + + bool operator == (const MacAddress& rhs) const + { + for(int i = 0; i < ETHER_ADDR_LEN; i++) + { + if(data[i] != rhs.data[i]) + return false; + } + + return true; + } + + uint8_t* GetBuffer() + { + return data; + } + + const uint8_t* GetConstBuffer() const + { + return data; + } void dump(FILE *fd) const; - void copyToArray(uint8_t *arrayToFill) const - { + void copyToArray(uint8_t *arrayToFill) const + { ((uint32_t*)arrayToFill)[0] = ((uint32_t*)data)[0];//Copy first 32bit - ((uint16_t*)arrayToFill)[2] = ((uint16_t*)data)[2];//Copy last 16bit - } + ((uint16_t*)arrayToFill)[2] = ((uint16_t*)data)[2];//Copy last 16bit + } public: uint8_t data[ETHER_ADDR_LEN]; diff --git a/src/common/basic_utils.cpp b/src/common/basic_utils.cpp index dfd3b183..d8a95b53 100755 --- a/src/common/basic_utils.cpp +++ b/src/common/basic_utils.cpp @@ -178,6 +178,13 @@ void TestDump(void){ utl_DumpBuffer2(stdout,buffer,31,1,4,SHOW_BUFFER_ADDR_EN |SHOW_BUFFER_CHAR); } +std::string +utl_macaddr_to_str(const uint8_t *mac) { + std::string tmp; + utl_macaddr_to_str(mac, tmp); + return tmp; +} + void utl_macaddr_to_str(const uint8_t *macaddr, std::string &output) { for (int i = 0; i < 6; i++) { diff --git a/src/common/basic_utils.h b/src/common/basic_utils.h index ab0ff1ec..ce2da691 100755 --- a/src/common/basic_utils.h +++ b/src/common/basic_utils.h @@ -85,6 +85,7 @@ inline void utl_swap(T& a, T& b) { bool utl_is_file_exists (const std::string& name) ; void utl_macaddr_to_str(const uint8_t *macaddr, std::string &output); +std::string utl_macaddr_to_str(const uint8_t *macaddr); std::string utl_macaddr_to_str(const uint8_t *macaddr); bool utl_str_to_macaddr(const std::string &s, uint8_t *mac); |