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