Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #include "bgp/extended-community/mac_mobility.h" 6 : 7 : #include <stdio.h> 8 : 9 : #include <algorithm> 10 : #include <string> 11 : 12 : 13 : using std::copy; 14 : using std::string; 15 : 16 557 : MacMobility::MacMobility(uint32_t seq, bool sticky) { 17 557 : data_[0] = BgpExtendedCommunityType::Evpn; 18 557 : data_[1] = BgpExtendedCommunityEvpnSubType::MacMobility; 19 557 : data_[2] = (sticky ? 0x01 : 0x0); // sticky 20 557 : data_[3] = 0x00; // Reserved 21 557 : put_value(&data_[4], 4, seq); 22 557 : } 23 : 24 7589 : MacMobility::MacMobility(const bytes_type &data) { 25 7589 : copy(data.begin(), data.end(), data_.begin()); 26 7589 : } 27 : 28 3268 : bool MacMobility::sticky() const { 29 3268 : return (data_[2] & 0x1); 30 : } 31 : 32 5411 : uint32_t MacMobility::sequence_number() const { 33 : uint8_t data[MacMobility::kSize]; 34 5411 : copy(data_.begin(), data_.end(), &data[0]); 35 5411 : if (data[0] == BgpExtendedCommunityType::Evpn && 36 5411 : data[1] == BgpExtendedCommunityEvpnSubType::MacMobility) { 37 5411 : uint32_t num = get_value(data + 4, 4); 38 5411 : return num; 39 : } 40 0 : return 0; 41 : } 42 : 43 7 : std::string MacMobility::ToString() { 44 : char temp[50]; 45 14 : snprintf(temp, sizeof(temp), "mobility:%s:%d", 46 7 : (sticky() ? "sticky" : "non-sticky"), sequence_number()); 47 7 : return string(temp); 48 : }